summaryrefslogtreecommitdiff
path: root/source/fitz/output-psd.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-psd.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-psd.c')
-rw-r--r--source/fitz/output-psd.c73
1 files changed, 66 insertions, 7 deletions
diff --git a/source/fitz/output-psd.c b/source/fitz/output-psd.c
index 223a591e..e097e9a6 100644
--- a/source/fitz/output-psd.c
+++ b/source/fitz/output-psd.c
@@ -254,8 +254,41 @@ psd_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int band_st
plane_inc = w * (h - band_height);
line_skip = stride - w*n;
b = buffer;
- for (k = 0; k < n; k++)
+ if (writer->super.alpha)
{
+ const unsigned char *ap = &sp[n-1];
+ for (k = 0; k < n-1; k++)
+ {
+ for (y = 0; y < band_height; y++)
+ {
+ for (x = 0; x < w; x++)
+ {
+ int a = *ap;
+ ap += n;
+ *b++ = a != 0 ? (*sp * 255 + 128)/a : 0;
+ sp += n;
+ if (b == buffer_end)
+ {
+ if (k >= num_additive)
+ psd_invert_buffer(buffer, sizeof(buffer));
+ fz_write_data(ctx, out, buffer, sizeof(buffer));
+ b = buffer;
+ }
+ }
+ sp += line_skip;
+ ap += line_skip;
+ }
+ sp -= stride * band_height - 1;
+ ap -= stride * band_height;
+ if (b != buffer)
+ {
+ if (k >= num_additive)
+ psd_invert_buffer(buffer, sizeof(buffer));
+ fz_write_data(ctx, out, buffer, b - buffer);
+ b = buffer;
+ }
+ fz_seek_output(ctx, out, plane_inc, SEEK_CUR);
+ }
for (y = 0; y < band_height; y++)
{
for (x = 0; x < w; x++)
@@ -264,25 +297,51 @@ psd_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int band_st
sp += n;
if (b == buffer_end)
{
- if (k >= num_additive)
- psd_invert_buffer(buffer, sizeof(buffer));
fz_write_data(ctx, out, buffer, sizeof(buffer));
b = buffer;
}
}
sp += line_skip;
}
- sp -= stride * band_height - 1;
if (b != buffer)
{
- if (k >= num_additive)
- psd_invert_buffer(buffer, sizeof(buffer));
fz_write_data(ctx, out, buffer, b - buffer);
b = buffer;
}
fz_seek_output(ctx, out, plane_inc, SEEK_CUR);
}
- fz_seek_output(ctx, out, w * h * (1-n), SEEK_CUR);
+ else
+ {
+ for (k = 0; k < n; k++)
+ {
+ for (y = 0; y < band_height; y++)
+ {
+ for (x = 0; x < w; x++)
+ {
+ *b++ = *sp;
+ sp += n;
+ if (b == buffer_end)
+ {
+ if (k >= num_additive)
+ psd_invert_buffer(buffer, sizeof(buffer));
+ fz_write_data(ctx, out, buffer, sizeof(buffer));
+ b = buffer;
+ }
+ }
+ sp += line_skip;
+ }
+ sp -= stride * band_height - 1;
+ if (b != buffer)
+ {
+ if (k >= num_additive)
+ psd_invert_buffer(buffer, sizeof(buffer));
+ fz_write_data(ctx, out, buffer, b - buffer);
+ b = buffer;
+ }
+ fz_seek_output(ctx, out, plane_inc, SEEK_CUR);
+ }
+ }
+ fz_seek_output(ctx, out, w * (band_height - h * n), SEEK_CUR);
}
static void