diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2011-07-26 16:09:55 +0100 |
---|---|---|
committer | Robin Watts <robin@ghostscript.com> | 2011-07-26 19:33:43 +0000 |
commit | 93701ab27b4d50f5d27da43f34d432e1963ce337 (patch) | |
tree | 58e3d91238e9866d3aecb8fb8c4047dc2c093bf0 /draw/draw_scale.c | |
parent | 9aba12aaa87f1da7b9047d1a86ad0d02298193ff (diff) | |
download | mupdf-93701ab27b4d50f5d27da43f34d432e1963ce337.tar.xz |
Fix bug 692354: Horizontal white lines in images.
The problem is due to abutting images showing gaps between them.
These gaps are due to a combination of rounding errors, and anti-aliasing
effects on the edge of images.
The solution is to selectively 'grid fit' images.
If an image is part of a type 3 font, we do NOT want to grid fit it, as
this is where the sub pixel positioning makes a huge difference.
If an image is displayed with alpha, then we don't want to grid fit it
(as grid fitting will tend to make the edges of images overlap by 1
pixel, and will hence produce nasty effects).
Otherwise, we will grid fit; Grid fit in this sense is where we expand
an image to completely fill the pixel grid that it touches (i.e. the
extents for the image are expanded to pixel boundaries; no half full
pixels are left around the edges).
The only real change of note here is in how we detect that we are in a
type 3 charproc; we add a new draw device creation function that we call
in the type3 charproc case that sets a flag that the drawing functions
can check.
Diffstat (limited to 'draw/draw_scale.c')
-rw-r--r-- | draw/draw_scale.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/draw/draw_scale.c b/draw/draw_scale.c index 9b94702e..40a5deff 100644 --- a/draw/draw_scale.c +++ b/draw/draw_scale.c @@ -989,6 +989,65 @@ scale_single_col(unsigned char *dst, unsigned char *src, fz_weights *weights, in #endif /* SINGLE_PIXEL_SPECIALS */ fz_pixmap * +fz_scale_pixmap_gridfit(fz_pixmap *src, float x, float y, float w, float h, int gridfit) +{ + if (gridfit) { + float n; + if (w > 0) { + /* Adjust the left hand edge, leftwards to a pixel boundary */ + n = (float)(int)x; /* n is now on a pixel boundary */ + if (n > x) /* Ensure it's the pixel boundary BELOW x */ + n -= 1.0f; + w += x-n; /* width gets wider as x >= n */ + x = n; + /* Adjust the right hand edge rightwards to a pixel boundary */ + n = (float)(int)w; /* n is now the integer width <= w */ + if (n != w) /* If w isn't an integer already, bump it */ + w = 1.0f + n;/* up to the next integer. */ + } else { + /* Adjust the right hand edge, rightwards to a pixel boundary */ + n = (float)(int)x; /* n is now on a pixel boundary */ + if (n > x) /* Ensure it's the pixel boundary <= x */ + n -= 1.0f; + if (n != x) /* If x isn't on a pixel boundary already, */ + n += 1.0f; /* make n be the pixel boundary above x. */ + w -= n-x; /* Expand width (more negative!) as n >= x */ + x = n; + /* Adjust the left hand edge leftwards to a pixel boundary */ + n = (float)(int)w; + if (n != w) + w = n - 1.0f; + } + if (h > 0) { + /* Adjust the bottom edge, downwards to a pixel boundary */ + n = (float)(int)y; /* n is now on a pixel boundary */ + if (n > y) /* Ensure it's the pixel boundary BELOW y */ + n -= 1.0f; + h += y-n; /* height gets larger as y >= n */ + y = n; + /* Adjust the top edge upwards to a pixel boundary */ + n = (float)(int)h; /* n is now the integer height <= h */ + if (n != h) /* If h isn't an integer already, bump it */ + h = 1.0f + n;/* up to the next integer. */ + } else { + /* Adjust the top edge, upwards to a pixel boundary */ + n = (float)(int)y; /* n is now on a pixel boundary */ + if (n > y) /* Ensure it's the pixel boundary <= y */ + n -= 1.0f; + if (n != y) /* If y isn't on a pixel boundary already, */ + n += 1.0f; /* make n be the pixel boundary above y. */ + h -= n-y; /* Expand height (more negative!) as n >= y */ + y = n; + /* Adjust the bottom edge downwards to a pixel boundary */ + n = (float)(int)h; + if (n != h) + h = n - 1.0f; + } + } + return fz_scale_pixmap(src, x, y, w, h); +} + +fz_pixmap * fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h) { fz_scale_filter *filter = &fz_scale_filter_simple; |