diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-01-06 12:07:39 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-01-06 12:07:39 +0000 |
commit | 07e6d886ae575d94c13c22bed4c9b9f907fb3def (patch) | |
tree | 465a2551d43f6540d00847c342b3d5219bd029ad | |
parent | 56eed7c5e97f89368fd838c49f714e5498582460 (diff) | |
download | mupdf-07e6d886ae575d94c13c22bed4c9b9f907fb3def.tar.xz |
Solve subpixel positioning problems when scaling rotated images.
-rw-r--r-- | draw/imagesmooth.c | 34 |
1 files 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)); |