summaryrefslogtreecommitdiff
path: root/draw/draw_simple_scale.c
diff options
context:
space:
mode:
Diffstat (limited to 'draw/draw_simple_scale.c')
-rw-r--r--draw/draw_simple_scale.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/draw/draw_simple_scale.c b/draw/draw_simple_scale.c
index b3a76565..1329b0e0 100644
--- a/draw/draw_simple_scale.c
+++ b/draw/draw_simple_scale.c
@@ -1192,15 +1192,13 @@ fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, float w, floa
/* 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.
- * The (x,y) position given describes where the bottom left corner
- * of the source image should be mapped to (i.e. where (0,h) in image
- * space ends up, not the more logical and sane (0,0)). Also there
- * are differences in the 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.
+ /* The (x,y) position given describes where the top left corner of the
+ * source image should be mapped to (i.e. where (0,0) in image space ends
+ * up). Also there are differences in the 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 rectangle 'r' to which the image is mapped,
* and the (possibly) larger rectangle 'R', given by expanding 'r' to
@@ -1218,7 +1216,7 @@ fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, float w, floa
{
float tmp;
w = -w;
- dst_x_int = floor(x-w);
+ dst_x_int = floorf(x-w);
tmp = ceilf(x);
dst_w_int = (int)tmp;
x = tmp - x;
@@ -1226,27 +1224,31 @@ fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, float w, floa
}
else
{
- dst_x_int = floor(x);
+ dst_x_int = floorf(x);
x -= (float)dst_x_int;
dst_w_int = (int)ceilf(x + w);
}
- flip_y = (h < 0);
- /* dst_y_int is calculated to be the bottom of the scaled image, but
- * y (the sub pixel offset) has to end up being the value at the top.
+ /* dst_y_int is calculated to be the top of the scaled image, and
+ * y (the sub_pixel_offset) is the distance in from either the top
+ * or bottom pixel expanded edge.
*/
+ flip_y = (h < 0);
if (flip_y)
{
+ float tmp;
h = -h;
- dst_y_int = floor(y-h);
- dst_h_int = (int)ceilf(y) - dst_y_int;
- } else {
- dst_y_int = floor(y);
- y += h;
- dst_h_int = (int)ceilf(y) - dst_y_int;
+ dst_y_int = floorf(y-h);
+ tmp = ceilf(y);
+ dst_h_int = (int)tmp;
+ y = tmp - y;
+ dst_h_int -= dst_y_int;
+ }
+ else
+ {
+ dst_y_int = floorf(y);
+ y -= (float)dst_y_int;
+ dst_h_int = (int)ceilf(y + h);
}
- /* y is the top edge position in floats. We want it to be the
- * distance down from the next pixel boundary. */
- y = ceilf(y) - y;
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));