summaryrefslogtreecommitdiff
path: root/source/fitz/draw-blend.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2017-07-15 16:10:09 +0100
committerRobin Watts <robin.watts@artifex.com>2017-07-17 19:32:50 +0100
commit244f297e9a0d0a7a3ff712cbbb21b7795ae64fab (patch)
tree75274255c70ece6e86aafdfe6998a27c2bd98939 /source/fitz/draw-blend.c
parent8e4682ed85477a1243ff9c91bfc10578b58d7ec2 (diff)
downloadmupdf-244f297e9a0d0a7a3ff712cbbb21b7795ae64fab.tar.xz
Debug blending
Diffstat (limited to 'source/fitz/draw-blend.c')
-rw-r--r--source/fitz/draw-blend.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/source/fitz/draw-blend.c b/source/fitz/draw-blend.c
index d819107a..0a339157 100644
--- a/source/fitz/draw-blend.c
+++ b/source/fitz/draw-blend.c
@@ -7,6 +7,10 @@
/* PDF 1.4 blend modes. These are slow. */
+/* Define PARANOID_PREMULTIPLY to check premultiplied values are
+ * properly in range. */
+#undef PARANOID_PREMULTIPLY
+
typedef unsigned char byte;
static const char *fz_blendmode_names[] =
@@ -793,6 +797,33 @@ fz_blend_nonseparable_nonisolated(byte * restrict bp, int bal, const byte * rest
while (--w);
}
+#ifdef PARANOID_PREMULTIPLY
+static void
+verify_premultiply(fz_context *ctx, const fz_pixmap * restrict dst)
+{
+ unsigned char *dp = dst->samples;
+ int w = dst->w;
+ int h = dst->h;
+ int n = dst->n;
+ int x, y, i;
+ int s = dst->stride - n * w;
+ void (*crash)(void) = NULL;
+
+ for (y = h; y > 0; y--)
+ {
+ for (x = w; x > 0; x--)
+ {
+ int a = dp[n-1];
+ for (i = n-1; i > 0; i--)
+ if (*dp++ > a)
+ crash();
+ dp++;
+ }
+ dp += s;
+ }
+}
+#endif
+
void
fz_blend_pixmap(fz_context *ctx, fz_pixmap * restrict dst, fz_pixmap * restrict src, int alpha, int blendmode, int isolated, const fz_pixmap * restrict shape)
{
@@ -843,6 +874,13 @@ fz_blend_pixmap(fz_context *ctx, fz_pixmap * restrict dst, fz_pixmap * restrict
dp = dst->samples + (unsigned int)((y - dst->y) * dst->stride + (x - dst->x) * dst->n);
da = dst->alpha;
+#ifdef PARANOID_PREMULTIPLY
+ if (sa)
+ verify_premultiply(ctx, src);
+ if (da)
+ verify_premultiply(ctx, dst);
+#endif
+
n -= sa;
assert(n == dst->n - da);
@@ -950,4 +988,9 @@ fz_blend_pixmap(fz_context *ctx, fz_pixmap * restrict dst, fz_pixmap * restrict
dp += dst->stride;
}
}
+
+#ifdef PARANOID_PREMULTIPLY
+ if (da)
+ verify_premultiply(ctx, dst);
+#endif
}