diff --git a/grub-core/video/bitmap_scale.c b/grub-core/video/bitmap_scale.c index 0b93d02..64bacbf 100644 --- a/grub-core/video/bitmap_scale.c +++ b/grub-core/video/bitmap_scale.c @@ -366,22 +366,31 @@ scale_nn (struct grub_video_bitmap *dst, struct grub_video_bitmap *src) /* bytes_per_pixel is the same for both src and dst. */ unsigned bytes_per_pixel = dst->mode_info.bytes_per_pixel; - unsigned dy; - for (dy = 0; dy < dh; dy++) + unsigned dy, sy, ystep, yfrac, yover; + unsigned dx, sx, xstep, xfrac, xover; + ystep = sw / dw; + yover = sw % dw; + xstep = sh / dh; + xover = sh % dh; + + for (dy = 0, sy = 0, yfrac = 0; dy < dh; dy++, sy += ystep, yfrac += yover) { - unsigned dx; - for (dx = 0; dx < dw; dx++) + if (yfrac > dw) + { + yfrac -= dw; + sy++; + } + for (dx = 0, sx = 0, xfrac = 0; dx < dw; dx++, sx += xstep, xfrac += xover) { grub_uint8_t *dptr; grub_uint8_t *sptr; - unsigned sx; - unsigned sy; unsigned comp; - /* Compute the source coordinate that the destination coordinate - maps to. Note: sx/sw = dx/dw => sx = sw*dx/dw. */ - sx = sw * dx / dw; - sy = sh * dy / dh; + if (xfrac > dh) + { + xfrac -= dh; + sx++; + } /* Get the address of the pixels in src and dst. */ dptr = ddata + dy * dstride + dx * bytes_per_pixel;