diff options
author | Tor Andersson <tor@ghostscript.com> | 2009-07-30 17:37:35 +0200 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2009-07-30 17:37:35 +0200 |
commit | ca2f6cb0dfc25b944230a503da471c61ff763f7b (patch) | |
tree | f0965030b53c6c2fb62dbb680f066eea367a392a /fitzdraw | |
parent | a8e2a88a4b56c1e3d3e49e80cc85e8a194b75603 (diff) | |
download | mupdf-ca2f6cb0dfc25b944230a503da471c61ff763f7b.tar.xz |
Clamp to edge when sampling outside the edge of an image. Solves many bugs with 1x1 sized images used as rectangles that got rendered like gradients.
Diffstat (limited to 'fitzdraw')
-rw-r--r-- | fitzdraw/imagedraw.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/fitzdraw/imagedraw.c b/fitzdraw/imagedraw.c index ad488431..8a7cf2cc 100644 --- a/fitzdraw/imagedraw.c +++ b/fitzdraw/imagedraw.c @@ -8,8 +8,10 @@ typedef unsigned char byte; static inline byte getcomp(byte *s, int w, int h, int u, int v, int n, int k) { - if (u < 0 || u >= w) return 0; - if (v < 0 || v >= h) return 0; + if (u < 0) u = 0; + if (v < 0) v = 0; + if (u >= w) u = w - 1; + if (v >= h) v = h - 1; return s[(w * v + u) * n + k]; } @@ -30,8 +32,10 @@ static inline int samplecomp(byte *s, int w, int h, int u, int v, int n, int k) static inline byte getmask(byte *s, int w, int h, int u, int v) { - if (u < 0 || u >= w) return 0; - if (v < 0 || v >= h) return 0; + if (u < 0) u = 0; + if (v < 0) v = 0; + if (u >= w) u = w - 1; + if (v >= h) v = h - 1; return s[w * v + u]; } @@ -60,9 +64,10 @@ static inline void lerpargb(byte *dst, byte *a, byte *b, int t) static inline byte *getargb(byte *s, int w, int h, int u, int v) { - static byte zero[4] = { 0, 0, 0, 0 }; - if (u < 0 || u >= w) return zero; - if (v < 0 || v >= h) return zero; + if (u < 0) u = 0; + if (v < 0) v = 0; + if (u >= w) u = w - 1; + if (v >= h) v = h - 1; return s + ((w * v + u) << 2); } |