From 07e6d886ae575d94c13c22bed4c9b9f907fb3def Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Thu, 6 Jan 2011 12:07:39 +0000 Subject: Solve subpixel positioning problems when scaling rotated images. --- draw/imagesmooth.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/draw/imagesmooth.c b/draw/imagesmooth.c index c564ccbf..3807de9b 100644 --- a/draw/imagesmooth.c +++ b/draw/imagesmooth.c @@ -27,6 +27,7 @@ static void debug_print(const char *fmt, ...) vsprintf(text, fmt, args); va_end(args); OutputDebugStringA(text); + printf(text); } #else static void debug_print(const char *fmt, ...) @@ -1003,6 +1004,21 @@ fz_smoothscalepixmap(fz_pixmap *src, float x, float y, float w, float h) /* Find the destination bbox, width/height, and sub pixel offset, * allowing for whether we're flipping or not. */ + /* Note that the x and y sub pixel offsets here are different, due to + * the different way we scale horizontally and vertically. When scaling + * rows horizontally, we always read forwards through the source, and + * store either forwards or in reverse as required. When scaling + * vertically, we always store out forwards, but may feed source rows + * in in a different order. + * + * Consider the image rectange 'r' to which the image is mapped, + * and the (possibly) larger rectangle 'R', given by expanding 'r' to + * complete pixels. + * + * x can either be r.xmin-R.xmin or R.xmax-r.xmax depending on whether + * the image is x flipped or not. Whatever happens 0 <= x < 1. + * y is always r.ymin - R.ymin. + */ flip_x = (w < 0); if (flip_x) { @@ -1023,20 +1039,12 @@ fz_smoothscalepixmap(fz_pixmap *src, float x, float y, float w, float h) flip_y = (h < 0); if (flip_y) { - float tmp; h = -h; - dst_y_int = floor(y-h); - tmp = ceilf(y); - dst_h_int = (int)tmp; - y = tmp - y; - dst_h_int -= dst_y_int; - } - else - { - dst_y_int = floor(y); - y -= (float)dst_y_int; - dst_h_int = (int)ceilf(y + h); - } + y -= h; + } + dst_y_int = floor(y); + y -= (float)dst_y_int; + dst_h_int = (int)ceilf(y + h); DBUG(("Result image: (%d,%d) at (%d,%d) (subpix=%g,%g)\n", dst_w_int, dst_h_int, dst_x_int, dst_y_int, x, y)); -- cgit v1.2.3