- x *= self._absolute_transform.dx
- y *= self._absolute_transform.dy
- x += self._absolute_transform.x
- y += self._absolute_transform.y
- buffer.alpha_composite(image, (x, y))
+ x *= absolute_transform.dx
+ y *= absolute_transform.dy
+ x += absolute_transform.x
+ y += absolute_transform.y
+
+ source_x = source_y = 0
+ if x < 0:
+ source_x = round(0 - x)
+ x = 0
+ if y < 0:
+ source_y = round(0 - y)
+ y = 0
+
+ x = round(x)
+ y = round(y)
+
+ if (
+ x <= buffer.width
+ and y <= buffer.height
+ and source_x <= image.width
+ and source_y <= image.height
+ ):
+ buffer.alpha_composite(image, (x, y), source=(source_x, source_y))