Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.

Commit 1900e53

Browse files
committed
Merge branch 'bugfix-10910' into release-6.0.2
2 parents bc8524e + b5b425a commit 1900e53

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

engine/src/imagebitmap.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ static bool check_bounds(MCImageBitmap *p_bitmap, int32_t x, int32_t y, uint32_t
4242

4343
static void clamp_region(MCImageBitmap *p_bitmap, int32_t &x, int32_t &y, uint32_t &width, uint32_t &height)
4444
{
45-
x = MCMax(0, x);
46-
y = MCMax(0, y);
45+
int32_t t_x1, t_y1, t_x2, t_y2;
4746

48-
width = MCMin((int32_t)p_bitmap->width - x, (int32_t)width);
49-
height = MCMin((int32_t)p_bitmap->height - y, (int32_t)height);
47+
t_x1 = MCMax(0, MCMin((int32_t)p_bitmap->width, x));
48+
t_y1 = MCMax(0, MCMin((int32_t)p_bitmap->height, y));
49+
t_x2 = MCMax(0, MCMin((int32_t)p_bitmap->width, x + (int32_t)width));
50+
t_y2 = MCMax(0, MCMin((int32_t)p_bitmap->height, y + (int32_t)height));
51+
52+
x = t_x1;
53+
y = t_y1;
54+
width = t_x2 - t_x1;
55+
height = t_y2 - t_y1;
5056
}
5157

5258
bool MCImageBitmapCreate(uindex_t p_width, uindex_t p_height, MCImageBitmap *&r_bitmap)
@@ -173,17 +179,20 @@ void MCImageBitmapCopyRegionToBitmap(MCImageBitmap *p_dst, MCImageBitmap *p_src,
173179
int32_t t_dst_x, t_dst_y;
174180
uint32_t t_width, t_height;
175181

176-
t_src_x = MCMax(0, p_src_rect.x);
177-
t_src_y = MCMax(0, p_src_rect.y);
182+
t_src_x = p_src_rect.x;
183+
t_src_y = p_src_rect.y;
184+
185+
t_width = p_src_rect.width;
186+
t_height = p_src_rect.height;
178187

179-
t_dst_x = MCMax(0, p_dst_offset.x);
180-
t_dst_y = MCMax(0, p_dst_offset.y);
188+
t_dst_x = p_dst_offset.x;
189+
t_dst_y = p_dst_offset.y;
181190

182-
t_width = MCMin((int32_t)p_src->width - t_src_x, (int32_t)p_src_rect.width);
183-
t_height = MCMin((int32_t)p_src->height - t_src_y, (int32_t)p_src_rect.height);
191+
clamp_region(p_src, t_src_x, t_src_y, t_width, t_height);
192+
clamp_region(p_dst, t_dst_x, t_dst_y, t_width, t_height);
184193

185-
t_width = MCMin((int32_t)p_dst->width - t_dst_x, (int32_t)t_width);
186-
t_height = MCMin((int32_t)p_dst->height - t_dst_y, (int32_t)t_height);
194+
if (t_width == 0 || t_height == 0)
195+
return;
187196

188197
copy_bitmap_data((uint8_t*)p_dst->data + p_dst->stride * t_dst_y + t_dst_x * sizeof(uint32_t), p_dst->stride, (uint8_t*)p_src->data + p_src->stride * t_src_y + t_src_x * sizeof(uint32_t), p_src->stride, t_width, t_height);
189198

0 commit comments

Comments
 (0)