Fix crash on image_scale_tpl() and rotsprite_image()

This commit is contained in:
David Capello 2016-03-22 17:05:45 -03:00
parent 66e3cacbd0
commit 14262c270c
2 changed files with 12 additions and 6 deletions

View File

@ -47,16 +47,22 @@ static void image_scale_tpl(
{
LockImageBits<ImageTraits> dst_bits(dst, gfx::Rect(dst_x, dst_y, dst_w, dst_h));
typename LockImageBits<ImageTraits>::iterator dst_it = dst_bits.begin();
fixed x;
fixed y = itofix(src_y);
fixed dx = fixdiv(itofix(src_w-1), itofix(dst_w-1));
fixed dy = fixdiv(itofix(src_h-1), itofix(dst_h-1));
for (int v=0; v<dst_h; ++v) {
x = itofix(src_x);
for (int u=0; u<dst_w; ++u) {
color_t src_color =
get_pixel_fast<ImageTraits>(src,
src_w*(src_x+u)/dst_w,
src_h*(src_y+v)/dst_h);
ASSERT(dst_it != dst_bits.end());
color_t src_color = get_pixel_fast<ImageTraits>(src, fixtoi(x), fixtoi(y));
*dst_it = blend(*dst_it, src_color);
++dst_it;
x = fixadd(x, dx);
}
y = fixadd(y, dy);
}
}

View File

@ -176,8 +176,8 @@ void rotsprite_image(Image* bmp, const Image* spr, const Image* mask,
int xmax = MAX(x1, MAX(x2, MAX(x3, x4)));
int ymin = MIN(y1, MIN(y2, MIN(y3, y4)));
int ymax = MAX(y1, MAX(y2, MAX(y3, y4)));
int rot_width = xmax - xmin + 1;
int rot_height = ymax - ymin + 1;
int rot_width = xmax - xmin;
int rot_height = ymax - ymin;
int scale = 8;
base::UniquePtr<Image> bmp_copy(Image::create(bmp->pixelFormat(), rot_width*scale, rot_height*scale, buf[0]));