Skip to content

Commit 06451cb

Browse files
fix: objects bounds rounded now
1 parent 3c38b4d commit 06451cb

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

system/lib/objects/renderable/renderable_movie_clip.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ def calculate_bounds(self, matrix: Matrix2x3) -> Rect:
8181
for child in self._frame_children:
8282
rect.merge_bounds(child.calculate_bounds(matrix_multiplied))
8383

84+
rect = Rect(
85+
left=round(rect.left),
86+
top=round(rect.top),
87+
right=round(rect.right),
88+
bottom=round(rect.bottom),
89+
)
90+
8491
return rect
8592

8693
def set_frame(self, frame_index: int):

system/lib/objects/renderable/renderable_shape.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,11 @@ def calculate_bounds(self, matrix: Matrix2x3) -> Rect:
4343
for region in self._regions:
4444
rect.merge_bounds(region.calculate_bounds(matrix_multiplied))
4545

46+
rect = Rect(
47+
left=round(rect.left),
48+
top=round(rect.top),
49+
right=round(rect.right),
50+
bottom=round(rect.bottom),
51+
)
52+
4653
return rect

system/lib/objects/shape/region.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def load(self, swf: SupercellSWF, tag: int):
5959
def render(self, matrix: Matrix2x3) -> Image.Image:
6060
transformed_points = apply_matrix(self._xy_points, matrix)
6161

62-
rect = get_rect(transformed_points)
62+
rect = self.calculate_bounds(matrix)
6363
width, height = max(int(rect.width), 1), max(int(rect.height), 1)
6464

6565
rendered_region = self.get_image()
@@ -135,4 +135,11 @@ def get_y(self, index: int):
135135
return self._xy_points[index].y
136136

137137
def calculate_bounds(self, matrix: Matrix2x3 | None = None) -> Rect:
138-
return get_rect(apply_matrix(self._xy_points, matrix))
138+
rect = get_rect(apply_matrix(self._xy_points, matrix))
139+
rect = Rect(
140+
left=round(rect.left),
141+
top=round(rect.top),
142+
right=round(rect.right),
143+
bottom=round(rect.bottom),
144+
)
145+
return rect

system/lib/pixel_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ def _write_rgb5a1(pixel: PixelChannels) -> bytes:
8686
return struct.pack("<H", a >> 7 | b >> 3 << 1 | g >> 3 << 6 | r >> 3 << 11)
8787

8888

89+
# TODO: rewrite with numpy https://qna.habr.com/q/298153
90+
# rgb888 = numpy.asarray(Image.open(filename))
91+
# # check that image have 3 color components, each of 8 bits
92+
# assert rgb888.shape[-1] == 3 and rgb888.dtype == numpy.uint8
93+
# r5 = (rgb888[..., 0] >> 3 & 0x1f).astype(numpy.uint16)
94+
# g6 = (rgb888[..., 1] >> 2 & 0x3f).astype(numpy.uint16)
95+
# b5 = (rgb888[..., 2] >> 3 & 0x1f).astype(numpy.uint16)
96+
# rgb565 = r5 << 11 | g6 << 5 | b5
97+
# return rgb565.tobytes()
8998
def _write_rgb565(pixel: PixelChannels) -> bytes:
9099
r, g, b = pixel
91100
return struct.pack("<H", b >> 3 | g >> 2 << 5 | r >> 3 << 11)

0 commit comments

Comments
 (0)