summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-05-27 19:14:07 +0100
committerRobin Watts <robin.watts@artifex.com>2016-05-29 10:11:36 +0100
commit28a1ee7561ae92dd38023be94076e684eb7e9e59 (patch)
tree80ffbc1c407e066cbd8bea196921339662232c6e
parent388e34e47dcf6132f63877d133d6d7679d1b8537 (diff)
downloadmupdf-28a1ee7561ae92dd38023be94076e684eb7e9e59.tar.xz
Tweak plotter code slightly for speed.
Use do {} while(--w) rather than while(w--) {} as this safes a test each time around the loop.
-rw-r--r--source/fitz/draw-affine.c56
-rw-r--r--source/fitz/draw-blend.c18
-rw-r--r--source/fitz/draw-mesh.c3
-rw-r--r--source/fitz/draw-paint.c95
-rw-r--r--source/fitz/image.c35
-rw-r--r--source/fitz/pixmap.c12
6 files changed, 140 insertions, 79 deletions
diff --git a/source/fitz/draw-affine.c b/source/fitz/draw-affine.c
index 9e029bc7..9e5c58cc 100644
--- a/source/fitz/draw-affine.c
+++ b/source/fitz/draw-affine.c
@@ -31,7 +31,7 @@ fz_paint_affine_alpha_N_lerp(byte * restrict dp, int da, const byte * restrict s
{
int k;
- while (w--)
+ do
{
if (u + 32768 >= 0 && u < sw && v + 32768 >= 0 && v < sh)
{
@@ -64,13 +64,14 @@ fz_paint_affine_alpha_N_lerp(byte * restrict dp, int da, const byte * restrict s
u += fa;
v += fb;
}
+ while (--w);
}
/* Special case code for gray -> rgb */
static inline void
fz_paint_affine_alpha_g2rgb_lerp(byte * restrict dp, int da, const byte * restrict sp, int sw, int sh, int ss, int sa, int u, int v, int fa, int fb, int w, int alpha, byte * restrict hp)
{
- while (w--)
+ do
{
if (u + 32768 >= 0 && u < sw && v + 32768 >= 0 && v < sh)
{
@@ -103,6 +104,7 @@ fz_paint_affine_alpha_g2rgb_lerp(byte * restrict dp, int da, const byte * restri
u += fa;
v += fb;
}
+ while (--w);
}
static inline void
@@ -114,7 +116,7 @@ fz_paint_affine_alpha_N_near_fa0(byte * restrict dp, int da, const byte * restri
if (ui < 0 || ui >= sw)
return;
sp += ui * (n1+sa);
- while (w--)
+ do
{
int vi = v >> 16;
if (vi >= 0 && vi < sh)
@@ -137,6 +139,7 @@ fz_paint_affine_alpha_N_near_fa0(byte * restrict dp, int da, const byte * restri
hp++;
v += fb;
}
+ while (--w);
}
static inline void
@@ -147,7 +150,7 @@ fz_paint_affine_alpha_N_near_fb0(byte * restrict dp, int da, const byte * restri
if (vi < 0 || vi >= sh)
return;
sp += vi * ss;
- while (w--)
+ do
{
int ui = u >> 16;
if (ui >= 0 && ui < sw)
@@ -170,6 +173,7 @@ fz_paint_affine_alpha_N_near_fb0(byte * restrict dp, int da, const byte * restri
hp++;
u += fa;
}
+ while (--w);
}
static inline void
@@ -177,7 +181,7 @@ fz_paint_affine_alpha_N_near(byte * restrict dp, int da, const byte * restrict s
{
int k;
- while (w--)
+ do
{
int ui = u >> 16;
int vi = v >> 16;
@@ -202,6 +206,7 @@ fz_paint_affine_alpha_N_near(byte * restrict dp, int da, const byte * restrict s
u += fa;
v += fb;
}
+ while (--w);
}
static inline void
@@ -211,7 +216,7 @@ fz_paint_affine_alpha_g2rgb_near_fa0(byte * restrict dp, int da, const byte * re
if (ui < 0 || ui >= sw)
return;
sp += ui * (1+sa);
- while (w--)
+ do
{
int vi = v >> 16;
if (vi >= 0 && vi < sh)
@@ -236,6 +241,7 @@ fz_paint_affine_alpha_g2rgb_near_fa0(byte * restrict dp, int da, const byte * re
hp++;
v += fb;
}
+ while (--w);
}
static inline void
@@ -245,7 +251,7 @@ fz_paint_affine_alpha_g2rgb_near_fb0(byte * restrict dp, int da, const byte * re
if (vi < 0 || vi >= sh)
return;
sp += vi * ss;
- while (w--)
+ do
{
int ui = u >> 16;
if (ui >= 0 && ui < sw)
@@ -270,12 +276,13 @@ fz_paint_affine_alpha_g2rgb_near_fb0(byte * restrict dp, int da, const byte * re
hp++;
u += fa;
}
+ while (--w);
}
static inline void
fz_paint_affine_alpha_g2rgb_near(byte * restrict dp, int da, const byte * restrict sp, int sw, int sh, int ss, int sa, int u, int v, int fa, int fb, int w, int alpha, byte * restrict hp)
{
- while (w--)
+ do
{
int ui = u >> 16;
int vi = v >> 16;
@@ -302,6 +309,7 @@ fz_paint_affine_alpha_g2rgb_near(byte * restrict dp, int da, const byte * restri
u += fa;
v += fb;
}
+ while (--w);
}
/* Blend premultiplied source image over destination */
@@ -310,7 +318,7 @@ fz_paint_affine_N_lerp(byte * restrict dp, int da, const byte * restrict sp, int
{
int k;
- while (w--)
+ do
{
if (u + 32768 >= 0 && u < sw && v + 32768 >= 0 && v < sh)
{
@@ -343,12 +351,13 @@ fz_paint_affine_N_lerp(byte * restrict dp, int da, const byte * restrict sp, int
u += fa;
v += fb;
}
+ while (--w);
}
static inline void
fz_paint_affine_solid_g2rgb_lerp(byte * restrict dp, int da, const byte * restrict sp, int sw, int sh, int ss, int sa, int u, int v, int fa, int fb, int w, byte * restrict hp)
{
- while (w--)
+ do
{
if (u + 32768 >= 0 && u < sw && v + 32768 >= 0 && v < sh)
{
@@ -380,6 +389,7 @@ fz_paint_affine_solid_g2rgb_lerp(byte * restrict dp, int da, const byte * restri
u += fa;
v += fb;
}
+ while (--w);
}
static inline void
@@ -390,7 +400,7 @@ fz_paint_affine_N_near_fa0(byte * restrict dp, int da, const byte * restrict sp,
if (ui < 0 || ui >= sw)
return;
sp += ui*(n1+sa);
- while (w--)
+ do
{
int vi = v >> 16;
if (vi >= 0 && vi < sh)
@@ -438,6 +448,7 @@ fz_paint_affine_N_near_fa0(byte * restrict dp, int da, const byte * restrict sp,
hp++;
v += fb;
}
+ while (--w);
}
static inline void
@@ -448,7 +459,7 @@ fz_paint_affine_N_near_fb0(byte * restrict dp, int da, const byte * restrict sp,
if (vi < 0 || vi >= sh)
return;
sp += vi * ss;
- while (w--)
+ do
{
int ui = u >> 16;
if (ui >= 0 && ui < sw)
@@ -496,13 +507,14 @@ fz_paint_affine_N_near_fb0(byte * restrict dp, int da, const byte * restrict sp,
hp++;
u += fa;
}
+ while (--w);
}
static inline void
fz_paint_affine_N_near(byte * restrict dp, int da, const byte * restrict sp, int sw, int sh, int ss, int sa, int u, int v, int fa, int fb, int w, int n1, byte * restrict hp)
{
int k;
- while (w--)
+ do
{
int ui = u >> 16;
int vi = v >> 16;
@@ -552,6 +564,7 @@ fz_paint_affine_N_near(byte * restrict dp, int da, const byte * restrict sp, int
u += fa;
v += fb;
}
+ while (--w);
}
static inline void
@@ -561,7 +574,7 @@ fz_paint_affine_solid_g2rgb_near_fa0(byte * restrict dp, int da, const byte * re
if (ui < 0 || ui >= sw)
return;
sp += ui * (1+sa);
- while (w--)
+ do
{
int vi = v >> 16;
if (vi >= 0 && vi < sh)
@@ -599,6 +612,7 @@ fz_paint_affine_solid_g2rgb_near_fa0(byte * restrict dp, int da, const byte * re
hp++;
v += fb;
}
+ while (--w);
}
static inline void
@@ -608,7 +622,7 @@ fz_paint_affine_solid_g2rgb_near_fb0(byte * restrict dp, int da, const byte * re
if (vi < 0 || vi >= sh)
return;
sp += vi * ss;
- while (w--)
+ do
{
int ui = u >> 16;
if (ui >= 0 && ui < sw)
@@ -646,12 +660,13 @@ fz_paint_affine_solid_g2rgb_near_fb0(byte * restrict dp, int da, const byte * re
hp++;
u += fa;
}
+ while (--w);
}
static inline void
fz_paint_affine_solid_g2rgb_near(byte * restrict dp, int da, const byte * restrict sp, int sw, int sh, int ss, int sa, int u, int v, int fa, int fb, int w, byte * restrict hp)
{
- while (w--)
+ do
{
int ui = u >> 16;
int vi = v >> 16;
@@ -691,6 +706,7 @@ fz_paint_affine_solid_g2rgb_near(byte * restrict dp, int da, const byte * restri
u += fa;
v += fb;
}
+ while (--w);
}
/* Blend non-premultiplied color in source image mask over destination */
@@ -701,7 +717,7 @@ fz_paint_affine_color_N_lerp(byte * restrict dp, int da, const byte * restrict s
int sa = color[n1];
int k;
- while (w--)
+ do
{
if (u + 32768 >= 0 && u < sw && v + 32768 >= 0 && v < sh)
{
@@ -731,6 +747,7 @@ fz_paint_affine_color_N_lerp(byte * restrict dp, int da, const byte * restrict s
u += fa;
v += fb;
}
+ while (--w);
}
static inline void
@@ -739,7 +756,7 @@ fz_paint_affine_color_N_near(byte * restrict dp, int da, const byte * restrict s
int sa = color[n1];
int k;
- while (w--)
+ do
{
int ui = u >> 16;
int vi = v >> 16;
@@ -763,6 +780,7 @@ fz_paint_affine_color_N_near(byte * restrict dp, int da, const byte * restrict s
u += fa;
v += fb;
}
+ while (--w);
}
/* LERP DA + SA Solid */
@@ -2962,7 +2980,7 @@ fz_paint_image_imp(fz_pixmap * restrict dst, const fz_irect *scissor, const fz_p
if (shape && shape->y + shape->h < h)
h = shape->y + shape->h;
h -= y;
- if (w < 0 || h < 0)
+ if (w <= 0 || h <= 0)
return;
/* map from screen space (x,y) to image space (u,v) */
diff --git a/source/fitz/draw-blend.c b/source/fitz/draw-blend.c
index 33f2c0c6..942481c1 100644
--- a/source/fitz/draw-blend.c
+++ b/source/fitz/draw-blend.c
@@ -272,7 +272,7 @@ static inline void
fz_blend_separable(byte * restrict bp, int bal, const byte * restrict sp, int sal, int n1, int w, int blendmode)
{
int k;
- while (w--)
+ do
{
int sa = (sal ? sp[n1] : 255);
int ba = (bal ? bp[n1] : 255);
@@ -314,12 +314,13 @@ fz_blend_separable(byte * restrict bp, int bal, const byte * restrict sp, int sa
sp += n1 + sal;
bp += n1 + bal;
}
+ while (--w);
}
static void
fz_blend_nonseparable(byte * restrict bp, int bal, const byte * restrict sp, int sal, int w, int blendmode)
{
- while (w--)
+ do
{
unsigned char rr, rg, rb;
@@ -365,6 +366,7 @@ fz_blend_nonseparable(byte * restrict bp, int bal, const byte * restrict sp, int
sp += 3 + sal;
bp += 3 + bal;
}
+ while (--w);
}
static inline void
@@ -378,7 +380,7 @@ fz_blend_separable_nonisolated(byte * restrict bp, int bal, const byte * restric
* cancel one another out, and it's just a simple copy. */
/* FIXME: Maybe we can avoid using the shape plane entirely
* and just copy? */
- while (w--)
+ do
{
int ha = fz_mul255(*hp++, alpha); /* ha = shape_alpha */
/* If ha == 0 then leave everything unchanged */
@@ -395,9 +397,10 @@ fz_blend_separable_nonisolated(byte * restrict bp, int bal, const byte * restric
sp += n1 + sal;
bp += n1 + bal;
}
+ while (--w);
return;
}
- while (w--)
+ do
{
int ha = *hp++;
int haa = fz_mul255(ha, alpha); /* ha = shape_alpha */
@@ -496,12 +499,13 @@ fz_blend_separable_nonisolated(byte * restrict bp, int bal, const byte * restric
sp += n1 + sal;
bp += n1 + bal;
}
+ while (--w);
}
static inline void
fz_blend_nonseparable_nonisolated(byte * restrict bp, int bal, const byte * restrict sp, int sal, int w, int blendmode, const byte * restrict hp, int alpha)
{
- while (w--)
+ do
{
int ha = *hp++;
int haa = fz_mul255(ha, alpha);
@@ -576,6 +580,7 @@ fz_blend_nonseparable_nonisolated(byte * restrict bp, int bal, const byte * rest
sp += 3 + sal;
bp += 3 + bal;
}
+ while (--w);
}
void
@@ -617,6 +622,9 @@ fz_blend_pixmap(fz_pixmap * restrict dst, fz_pixmap * restrict src, int alpha, i
w = bbox.x1 - bbox.x0;
h = bbox.y1 - bbox.y0;
+ if (w == 0 || h == 0)
+ return;
+
n = src->n;
sp = src->samples + (unsigned int)((y - src->y) * src->stride + (x - src->x) * src->n);
sa = src->alpha;
diff --git a/source/fitz/draw-mesh.c b/source/fitz/draw-mesh.c
index c4e54643..40f16734 100644
--- a/source/fitz/draw-mesh.c
+++ b/source/fitz/draw-mesh.c
@@ -43,7 +43,7 @@ static void paint_scan(fz_pixmap *restrict pix, int y, int fx0, int fx1, int cx0
p = pix->samples + ((x0 - pix->x) * pix->n) + ((y - pix->y) * pix->stride);
pa = pix->alpha;
- while (w--)
+ do
{
for (k = 0; k < n; k++)
{
@@ -53,6 +53,7 @@ static void paint_scan(fz_pixmap *restrict pix, int y, int fx0, int fx1, int cx0
if (pa)
*p++ = 255;
}
+ while (--w);
}
typedef struct edge_data_s edge_data;
diff --git a/source/fitz/draw-paint.c b/source/fitz/draw-paint.c
index 41f1a220..56bc29c4 100644
--- a/source/fitz/draw-paint.c
+++ b/source/fitz/draw-paint.c
@@ -84,21 +84,23 @@ fz_paint_solid_color_2_da(byte * restrict dp, int n, int w, const byte * restric
return;
if (sa == 256)
{
- while (w--)
+ do
{
dp[0] = color[0];
dp[1] = 255;
dp += 2;
}
+ while (--w);
}
else
{
- while (w--)
+ do
{
dp[0] = FZ_BLEND(color[0], dp[0], sa);
dp[1] = FZ_BLEND(255, dp[1], sa);
dp += 2;
}
+ while (--w);
}
}
@@ -122,18 +124,19 @@ fz_paint_solid_color_4_da(byte * restrict dp, int n, int w, const byte * restric
rgba |= 0xFF000000;
if (sa == 256)
{
- while (w--)
+ do
{
*(unsigned int *)dp = rgba;
dp += 4;
}
+ while (--w);
}
else
{
unsigned int mask = 0xFF00FF00;
unsigned int rb = rgba & (mask>>8);
unsigned int ga = (rgba & mask)>>8;
- while (w--)
+ do
{
unsigned int RGBA = *(unsigned int *)dp;
unsigned int RB = (RGBA<<8) & mask;
@@ -145,6 +148,7 @@ fz_paint_solid_color_4_da(byte * restrict dp, int n, int w, const byte * restric
*(unsigned int *)dp = (RB>>8) | GA;
dp += 4;
}
+ while (--w);
}
}
@@ -201,9 +205,11 @@ fz_paint_solid_color_5_da(byte * restrict dp, int n, int w, const byte * restric
while (w > 0);
}
w += 3;
+ if (w == 0)
+ return;
}
#endif
- while (w--)
+ do
{
dp[0] = color[0];
dp[1] = color[1];
@@ -212,10 +218,11 @@ fz_paint_solid_color_5_da(byte * restrict dp, int n, int w, const byte * restric
dp[4] = 255;
dp += 5;
}
+ while (--w);
}
else
{
- while (w--)
+ do
{
dp[0] = FZ_BLEND(color[0], dp[0], sa);
dp[1] = FZ_BLEND(color[1], dp[1], sa);
@@ -224,6 +231,7 @@ fz_paint_solid_color_5_da(byte * restrict dp, int n, int w, const byte * restric
dp[4] = FZ_BLEND(255, dp[5], sa);
dp += 5;
}
+ while (--w);
}
}
@@ -238,7 +246,7 @@ fz_paint_solid_color_N_general(byte * restrict dp, int n, int w, const byte * re
return;
if (sa == 256)
{
- while (w--)
+ do
{
dp[0] = color[0];
if (n1 > 1)
@@ -251,10 +259,11 @@ fz_paint_solid_color_N_general(byte * restrict dp, int n, int w, const byte * re
dp[n1] = 255;
dp += n;
}
+ while (--w);
}
else
{
- while (w--)
+ do
{
for (k = 0; k < n1; k++)
dp[k] = FZ_BLEND(color[k], dp[k], sa);
@@ -262,6 +271,7 @@ fz_paint_solid_color_N_general(byte * restrict dp, int n, int w, const byte * re
dp[k] = FZ_BLEND(255, dp[k], sa);
dp += n;
}
+ while (--w);
}
}
@@ -331,7 +341,7 @@ fz_paint_span_with_color_2_da(byte * restrict dp, const byte * restrict mp, int
TRACK_FN();
if (sa == 256)
{
- while (w--)
+ do
{
int ma = *mp++;
ma = FZ_EXPAND(ma);
@@ -350,10 +360,11 @@ fz_paint_span_with_color_2_da(byte * restrict dp, const byte * restrict mp, int
}
dp += 2;
}
+ while (--w);
}
else
{
- while (w--)
+ do
{
int ma = *mp++;
ma = FZ_EXPAND(ma);
@@ -368,6 +379,7 @@ fz_paint_span_with_color_2_da(byte * restrict dp, const byte * restrict mp, int
}
dp += 2;
}
+ while (--w);
}
}
@@ -389,7 +401,7 @@ fz_paint_span_with_color_4_da(byte * restrict dp, const byte * restrict mp, int
ga = (rgba & mask)>>8;
if (sa == 256)
{
- while (w--)
+ do
{
unsigned int ma = *mp++;
dp += 4;
@@ -413,10 +425,11 @@ fz_paint_span_with_color_4_da(byte * restrict dp, const byte * restrict mp, int
((unsigned int *)dp)[-1] = (RB>>8) | GA;
}
}
+ while (--w);
}
else
{
- while (w--)
+ do
{
unsigned int ma = *mp++;
ma = FZ_COMBINE(FZ_EXPAND(ma), sa);
@@ -433,6 +446,7 @@ fz_paint_span_with_color_4_da(byte * restrict dp, const byte * restrict mp, int
((unsigned int *)dp)[-1] = (RB>>8) | GA;
}
}
+ while (--w);
}
}
@@ -447,7 +461,7 @@ fz_paint_span_with_color_5_da(byte * restrict dp, const byte * restrict mp, int
TRACK_FN();
if (sa == 256)
{
- while (w--)
+ do
{
int ma = *mp++;
ma = FZ_EXPAND(ma);
@@ -472,10 +486,11 @@ fz_paint_span_with_color_5_da(byte * restrict dp, const byte * restrict mp, int
}
dp += 5;
}
+ while (--w);
}
else
{
- while (w--)
+ do
{
int ma = *mp++;
ma = FZ_EXPAND(ma);
@@ -493,6 +508,7 @@ fz_paint_span_with_color_5_da(byte * restrict dp, const byte * restrict mp, int
}
dp += 5;
}
+ while (--w);
}
}
@@ -506,7 +522,7 @@ fz_paint_span_with_color_N_general(byte * restrict dp, const byte * restrict mp,
return;
if (sa == 256)
{
- while (w--)
+ do
{
int ma = *mp++;
ma = FZ_EXPAND(ma);
@@ -535,10 +551,11 @@ fz_paint_span_with_color_N_general(byte * restrict dp, const byte * restrict mp,
}
dp += n;
}
+ while (--w);
}
else
{
- while (w--)
+ do
{
int ma = *mp++;
ma = FZ_COMBINE(FZ_EXPAND(ma), sa);
@@ -548,6 +565,7 @@ fz_paint_span_with_color_N_general(byte * restrict dp, const byte * restrict mp,
dp[k] = FZ_BLEND(255, dp[k], ma);
dp += n;
}
+ while (--w);
}
}
@@ -618,7 +636,7 @@ fz_get_span_color_painter(int n, int da, const byte * restrict color)
static inline void
fz_paint_span_with_mask_1_general(byte * restrict dp, int da, const byte * restrict sp, int sa, const byte * restrict mp, int w)
{
- while (w--)
+ do
{
int masa;
int ma = *mp++;
@@ -679,13 +697,14 @@ fz_paint_span_with_mask_1_general(byte * restrict dp, int da, const byte * restr
}
}
}
+ while (--w);
}
/* FIXME: There is potential for SWAR optimisation here */
static inline void
fz_paint_span_with_mask_3_general(byte * restrict dp, int da, const byte * restrict sp, int sa, const byte * restrict mp, int w)
{
- while (w--)
+ do
{
int masa;
int ma = *mp++;
@@ -771,13 +790,14 @@ fz_paint_span_with_mask_3_general(byte * restrict dp, int da, const byte * restr
}
}
}
+ while (--w);
}
/* FIXME: There is potential for SWAR optimisation here */
static inline void
fz_paint_span_with_mask_4_general(byte * restrict dp, int da, const byte * restrict sp, int sa, const byte * restrict mp, int w)
{
- while (w--)
+ do
{
int masa;
int ma = *mp++;
@@ -861,12 +881,13 @@ fz_paint_span_with_mask_4_general(byte * restrict dp, int da, const byte * restr
}
}
}
+ while (--w);
}
static inline void
fz_paint_span_with_mask_N_general(byte * restrict dp, int da, const byte * restrict sp, int sa, const byte * restrict mp, int n, int w)
{
- while (w--)
+ do
{
int ma = *mp++;
ma = FZ_EXPAND(ma);
@@ -943,6 +964,7 @@ fz_paint_span_with_mask_N_general(byte * restrict dp, int da, const byte * restr
}
}
}
+ while (--w);
}
static void
@@ -1118,7 +1140,7 @@ fz_paint_span_1_with_alpha_general(byte * restrict dp, int da, const byte * rest
{
if (sa)
alpha = FZ_EXPAND(alpha);
- while (w--)
+ do
{
int masa = (sa ? FZ_COMBINE(sp[1], alpha) : alpha);
*dp = FZ_BLEND(*sp, *dp, masa);
@@ -1131,6 +1153,7 @@ fz_paint_span_1_with_alpha_general(byte * restrict dp, int da, const byte * rest
if (sa)
sp++;
}
+ while (--w);
}
static inline void
@@ -1138,7 +1161,7 @@ fz_paint_span_3_with_alpha_general(byte * restrict dp, int da, const byte * rest
{
if (sa)
alpha = FZ_EXPAND(alpha);
- while (w--)
+ do
{
int masa = (sa ? FZ_COMBINE(sp[3], alpha) : alpha);
*dp = FZ_BLEND(*sp, *dp, masa);
@@ -1155,6 +1178,7 @@ fz_paint_span_3_with_alpha_general(byte * restrict dp, int da, const byte * rest
if (sa)
sp++;
}
+ while (--w);
}
static inline void
@@ -1162,7 +1186,7 @@ fz_paint_span_4_with_alpha_general(byte * restrict dp, int da, const byte * rest
{
if (sa)
alpha = FZ_EXPAND(alpha);
- while (w--)
+ do
{
int masa = (sa ? FZ_COMBINE(sp[4], alpha) : alpha);
*dp = FZ_BLEND(*sp, *dp, masa);
@@ -1181,6 +1205,7 @@ fz_paint_span_4_with_alpha_general(byte * restrict dp, int da, const byte * rest
if (sa)
sp++;
}
+ while (--w);
}
static inline void
@@ -1188,7 +1213,7 @@ fz_paint_span_N_with_alpha_general(byte * restrict dp, int da, const byte * rest
{
if (sa)
alpha = FZ_EXPAND(alpha);
- while (w--)
+ do
{
int masa = (sa ? FZ_COMBINE(sp[n1], alpha) : alpha);
int k = n1;
@@ -1205,6 +1230,7 @@ fz_paint_span_N_with_alpha_general(byte * restrict dp, int da, const byte * rest
if (sa)
sp++;
}
+ while (--w);
}
/* Blend source over destination */
@@ -1212,7 +1238,7 @@ fz_paint_span_N_with_alpha_general(byte * restrict dp, int da, const byte * rest
static inline void
fz_paint_span_1_general(byte * restrict dp, int da, const byte * restrict sp, int sa, int w)
{
- while (w--)
+ do
{
int t = (sa ? FZ_EXPAND(sp[1]): 256);
if (t == 0)
@@ -1244,12 +1270,13 @@ fz_paint_span_1_general(byte * restrict dp, int da, const byte * restrict sp, in
}
}
}
+ while (--w);
}
static inline void
fz_paint_span_3_general(byte * restrict dp, int da, const byte * restrict sp, int sa, int w)
{
- while (w--)
+ do
{
int t = (sa ? FZ_EXPAND(sp[3]) : 256);
if (t == 0)
@@ -1291,12 +1318,13 @@ fz_paint_span_3_general(byte * restrict dp, int da, const byte * restrict sp, in
}
}
}
+ while (--w);
}
static inline void
fz_paint_span_4_general(byte * restrict dp, int da, const byte * restrict sp, int sa, int w)
{
- while (w--)
+ do
{
int t = (sa ? FZ_EXPAND(sp[4]) : 256);
if (t == 0)
@@ -1336,12 +1364,13 @@ fz_paint_span_4_general(byte * restrict dp, int da, const byte * restrict sp, in
}
}
}
+ while (--w);
}
static inline void
fz_paint_span_N_general(byte * restrict dp, int da, const byte * restrict sp, int sa, int n1, int w)
{
- while (w--)
+ do
{
int t = (sa ? FZ_EXPAND(sp[n1]) : 256);
if (t == 0)
@@ -1381,17 +1410,19 @@ fz_paint_span_N_general(byte * restrict dp, int da, const byte * restrict sp, in
}
}
}
+ while (--w);
}
static void
fz_paint_span_0_da_sa(byte * restrict dp, int da, const byte * restrict sp, int sa, int n, int w, int alpha)
{
- while (w--)
+ do
{
int t = FZ_EXPAND(255 - sp[0]);
*dp = *sp++ + FZ_COMBINE(*dp, t);
dp ++;
}
+ while (--w);
}
static void
@@ -1747,7 +1778,7 @@ fz_paint_pixmap_with_bbox(fz_pixmap * restrict dst, const fz_pixmap * restrict s
y = bbox.y0;
w = bbox.x1 - bbox.x0;
h = bbox.y1 - bbox.y0;
- if ((w | h) == 0)
+ if (w == 0 || h == 0)
return;
n = src->n;
@@ -1789,7 +1820,7 @@ fz_paint_pixmap(fz_pixmap * restrict dst, const fz_pixmap * restrict src, int al
y = bbox.y0;
w = bbox.x1 - bbox.x0;
h = bbox.y1 - bbox.y0;
- if ((w | h) == 0)
+ if (w == 0 || h == 0)
return;
n = src->n;
@@ -1833,7 +1864,7 @@ fz_paint_pixmap_with_mask(fz_pixmap * restrict dst, const fz_pixmap * restrict s
y = bbox.y0;
w = bbox.x1 - bbox.x0;
h = bbox.y1 - bbox.y0;
- if ((w | h) == 0)
+ if (w == 0 || h == 0)
return;
n = src->n;
diff --git a/source/fitz/image.c b/source/fitz/image.c
index c49580bf..e28ba649 100644
--- a/source/fitz/image.c
+++ b/source/fitz/image.c
@@ -99,10 +99,12 @@ fz_mask_color_key(fz_pixmap *pix, int n, const int *colorkey)
int k, t;
int h = pix->h;
int stride = pix->stride - pix->w * pix->n;
+ if (pix->w == 0)
+ return;
while (h--)
{
w = pix->w;
- while (w--)
+ do
{
t = 1;
for (k = 0; k < n; k++)
@@ -113,6 +115,7 @@ fz_mask_color_key(fz_pixmap *pix, int n, const int *colorkey)
p[k] = 0;
p += pix->n;
}
+ while (--w);
p += stride;
}
}
@@ -136,22 +139,26 @@ fz_unblend_masked_tile(fz_context *ctx, fz_pixmap *tile, fz_image *image)
return;
}
- while (h--)
+ if (mask->w != 0)
{
- int w = mask->w;
- while (w--)
+ while (h--)
{
- if (*s == 0)
- for (k = 0; k < image->n; k++)
- d[k] = image->colorkey[k];
- else
- for (k = 0; k < image->n; k++)
- d[k] = fz_clampi(image->colorkey[k] + (d[k] - image->colorkey[k]) * 255 / *s, 0, 255);
- s++;
- d += n;
+ int w = mask->w;
+ do
+ {
+ if (*s == 0)
+ for (k = 0; k < image->n; k++)
+ d[k] = image->colorkey[k];
+ else
+ for (k = 0; k < image->n; k++)
+ d[k] = fz_clampi(image->colorkey[k] + (d[k] - image->colorkey[k]) * 255 / *s, 0, 255);
+ s++;
+ d += n;
+ }
+ while (--w);
+ s += sstride;
+ d += dstride;
}
- s += sstride;
- d += dstride;
}
fz_drop_pixmap(ctx, mask);
diff --git a/source/fitz/pixmap.c b/source/fitz/pixmap.c
index e2564c98..0016c003 100644
--- a/source/fitz/pixmap.c
+++ b/source/fitz/pixmap.c
@@ -705,19 +705,15 @@ fz_alpha_from_gray(fz_context *ctx, fz_pixmap *gray, int luminosity)
alpha = fz_new_pixmap_with_bbox(ctx, NULL, fz_pixmap_bbox(ctx, gray, &bbox), 1);
dp = alpha->samples;
- dstride = alpha->stride - alpha->w;
+ dstride = alpha->stride;
sp = gray->samples;
- sstride = gray->stride - gray->w;
+ sstride = gray->stride;
h = gray->h;
+ w = gray->w;
while (h--)
{
- w = gray->w;
- while (w--)
- {
- *dp++ = sp[0];
- sp++;
- }
+ memcpy(dp, sp, w);
sp += sstride;
dp += dstride;
}