summaryrefslogtreecommitdiff
path: root/source/fitz
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2017-08-09 18:10:37 +0100
committerRobin Watts <robin.watts@artifex.com>2017-10-24 15:16:36 +0100
commitf2e0ab5afee63d9f446f37201291010e68282cc4 (patch)
tree64c8092a02ee898db2ce19452c912d9806e390d3 /source/fitz
parentedcac9b62fd9034f3901c2b23467be9632c07b99 (diff)
downloadmupdf-f2e0ab5afee63d9f446f37201291010e68282cc4.tar.xz
Fix fz_paint_pixmap alpha blending.
We were failing to allow for the fact that the source pixmap is premultiplied, meaning we were squaring the alpha each time.
Diffstat (limited to 'source/fitz')
-rw-r--r--source/fitz/draw-paint.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/source/fitz/draw-paint.c b/source/fitz/draw-paint.c
index 0a58fd58..5735f615 100644
--- a/source/fitz/draw-paint.c
+++ b/source/fitz/draw-paint.c
@@ -1357,11 +1357,12 @@ template_span_1_with_alpha_general(byte * restrict dp, int da, const byte * rest
do
{
int masa = (sa ? FZ_COMBINE(sp[1], alpha) : alpha);
- *dp = FZ_BLEND(*sp, *dp, masa);
+ int t = FZ_EXPAND(255-masa);
+ *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
dp++; sp++;
if (da)
{
- *dp = FZ_BLEND((sa ? *sp : 255), *dp, masa);
+ *dp = masa + FZ_COMBINE(*dp, t);
dp++;
}
if (sa)
@@ -1378,15 +1379,16 @@ template_span_3_with_alpha_general(byte * restrict dp, int da, const byte * rest
do
{
int masa = (sa ? FZ_COMBINE(sp[3], alpha) : alpha);
- *dp = FZ_BLEND(*sp, *dp, masa);
+ int t = FZ_EXPAND(255-masa);
+ *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
sp++; dp++;
- *dp = FZ_BLEND(*sp, *dp, masa);
+ *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
sp++; dp++;
- *dp = FZ_BLEND(*sp, *dp, masa);
+ *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
sp++; dp++;
if (da)
{
- *dp = FZ_BLEND((sa ? *sp : 255), *dp, masa);
+ *dp = masa + FZ_COMBINE(*dp, t);
dp++;
}
if (sa)
@@ -1403,17 +1405,18 @@ template_span_4_with_alpha_general(byte * restrict dp, int da, const byte * rest
do
{
int masa = (sa ? FZ_COMBINE(sp[4], alpha) : alpha);
- *dp = FZ_BLEND(*sp, *dp, masa);
+ int t = FZ_EXPAND(255-masa);
+ *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
sp++; dp++;
- *dp = FZ_BLEND(*sp, *dp, masa);
+ *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
sp++; dp++;
- *dp = FZ_BLEND(*sp, *dp, masa);
+ *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
sp++; dp++;
- *dp = FZ_BLEND(*sp, *dp, masa);
+ *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
sp++; dp++;
if (da)
{
- *dp = FZ_BLEND((sa ? *sp : 255), *dp, masa);
+ *dp = masa + FZ_COMBINE(*dp, t);
dp++;
}
if (sa)
@@ -1431,15 +1434,16 @@ template_span_N_with_alpha_general(byte * restrict dp, int da, const byte * rest
do
{
int masa = (sa ? FZ_COMBINE(sp[n1], alpha) : alpha);
+ int t = FZ_EXPAND(255-masa);
int k;
for (k = 0; k < n1; k++)
{
- *dp = FZ_BLEND(*sp, *dp, masa);
+ *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
sp++; dp++;
}
if (da)
{
- *dp = FZ_BLEND((sa ? *sp : 255), *dp, masa);
+ *dp = masa + FZ_COMBINE(*dp, t);
dp++;
}
if (sa)
@@ -1456,17 +1460,18 @@ template_span_N_with_alpha_general_op(byte * restrict dp, int da, const byte * r
do
{
int masa = (sa ? FZ_COMBINE(sp[n1], alpha) : alpha);
+ int t = FZ_EXPAND(255-masa);
int k;
for (k = 0; k < n1; k++)
{
if (fz_overprint_component(eop, k))
- *dp = FZ_BLEND(*sp, *dp, masa);
+ *dp = FZ_COMBINE(*sp, alpha) + FZ_COMBINE(*dp, t);
sp++;
dp++;
}
if (da)
{
- *dp = FZ_BLEND((sa ? *sp : 255), *dp, masa);
+ *dp = masa + FZ_COMBINE(*dp, t);
dp++;
}
if (sa)
@@ -1731,7 +1736,8 @@ paint_span_0_da_sa_alpha(byte * restrict dp, int da, const byte * restrict sp, i
do
{
int masa = FZ_COMBINE(sp[0], alpha);
- *dp = FZ_BLEND(*sp, *dp, masa);
+ int t = FZ_EXPAND(255-masa);
+ *dp = masa + FZ_COMBINE(*dp, t);
dp++;
sp++;
}