summaryrefslogtreecommitdiff
path: root/source/fitz/output-tga.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2017-11-07 17:32:15 +0000
committerRobin Watts <robin.watts@artifex.com>2017-11-08 12:57:18 +0000
commit3119f69dd9536cdaab0719fba2898be894e8fc01 (patch)
tree7e034de6e3d83ca163ce656b328e29c1b55a03e4 /source/fitz/output-tga.c
parent520cc26d18c9ee245b56e9e91f9d4fcae02be5f0 (diff)
downloadmupdf-3119f69dd9536cdaab0719fba2898be894e8fc01.tar.xz
Pixmap writers for formats with alpha should handle premultiplied data.
Any pixmap writers that can handle data with an alpha plane should accept that data in premultiplied form, and write it out appropriately for the file format. This avoids the need to unpremultiply data in mudraw, and solves the issue we were seeing where we want the png writer to be able to cope with premultiplied data (such as for the debug blending routines) and unpremultiplied data (such as that given after mudraw has unpremultiplied the data).
Diffstat (limited to 'source/fitz/output-tga.c')
-rw-r--r--source/fitz/output-tga.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/source/fitz/output-tga.c b/source/fitz/output-tga.c
index 3bee3640..0e7a213c 100644
--- a/source/fitz/output-tga.c
+++ b/source/fitz/output-tga.c
@@ -13,19 +13,22 @@ typedef struct {
static inline void tga_put_pixel(fz_context *ctx, fz_output *out, const unsigned char *data, int n, int is_bgr)
{
+ int a, inva;
switch(n)
{
case 4: /* RGBA or BGRA */
+ a = data[3];
+ inva = a ? 256 * 255 / a : 0;
if (!is_bgr) {
- fz_write_byte(ctx, out, data[2]);
- fz_write_byte(ctx, out, data[1]);
- fz_write_byte(ctx, out, data[0]);
+ fz_write_byte(ctx, out, (data[2] * inva + 128)>>8);
+ fz_write_byte(ctx, out, (data[1] * inva + 128)>>8);
+ fz_write_byte(ctx, out, (data[0] * inva + 128)>>8);
} else {
- fz_write_byte(ctx, out, data[0]);
- fz_write_byte(ctx, out, data[1]);
- fz_write_byte(ctx, out, data[2]);
+ fz_write_byte(ctx, out, (data[0] * inva + 128)>>8);
+ fz_write_byte(ctx, out, (data[1] * inva + 128)>>8);
+ fz_write_byte(ctx, out, (data[2] * inva + 128)>>8);
}
- fz_write_byte(ctx, out, data[3]);
+ fz_write_byte(ctx, out, a);
break;
case 3: /* RGB or BGR */
if (!is_bgr) {
@@ -39,10 +42,13 @@ static inline void tga_put_pixel(fz_context *ctx, fz_output *out, const unsigned
}
break;
case 2: /* GA */
- fz_write_byte(ctx, out, data[0]);
- fz_write_byte(ctx, out, data[0]);
- fz_write_byte(ctx, out, data[0]);
- fz_write_byte(ctx, out, data[1]);
+ a = data[1];
+ inva = a ? 256 * 255 / a : 0;
+ inva = (data[0] * inva + 128)>>8;
+ fz_write_byte(ctx, out, inva);
+ fz_write_byte(ctx, out, inva);
+ fz_write_byte(ctx, out, inva);
+ fz_write_byte(ctx, out, a);
break;
case 1: /* G */
fz_write_byte(ctx, out, data[0]);