From 5e5d9490984b1424751687fd6d96ef81d76180e5 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 17 Jun 2016 13:22:27 +0100 Subject: Fix fz_write_pam code. It was incorrectly missing the alpha in the header writing code. --- include/mupdf/fitz/output-pnm.h | 2 +- source/fitz/output-pnm.c | 11 ++++++----- source/tools/mudraw.c | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/mupdf/fitz/output-pnm.h b/include/mupdf/fitz/output-pnm.h index 65d0f566..09cad4ef 100644 --- a/include/mupdf/fitz/output-pnm.h +++ b/include/mupdf/fitz/output-pnm.h @@ -23,7 +23,7 @@ void fz_save_pixmap_as_pam(fz_context *ctx, fz_pixmap *pixmap, char *filename); void fz_write_pixmap_as_pam(fz_context *ctx, fz_output *out, fz_pixmap *pixmap); void fz_write_pam_header(fz_context *ctx, fz_output *out, int w, int h, int n, int alpha); -void fz_write_pam_band(fz_context *ctx, fz_output *out, int w, int h, int n, int stride, int band_start, int bandheight, unsigned char *sp); +void fz_write_pam_band(fz_context *ctx, fz_output *out, int w, int h, int n, int alpha, int stride, int band_start, int bandheight, unsigned char *sp); /* fz_save_bitmap_as_pbm: Save a bitmap as a PBM image file. diff --git a/source/fitz/output-pnm.c b/source/fitz/output-pnm.c index 99edc24d..b2bc2387 100644 --- a/source/fitz/output-pnm.c +++ b/source/fitz/output-pnm.c @@ -125,16 +125,16 @@ fz_write_pam_header(fz_context *ctx, fz_output *out, int w, int h, int n, int al fz_printf(ctx, out, "DEPTH %d\n", n); fz_printf(ctx, out, "MAXVAL 255\n"); if (n == 1) fz_printf(ctx, out, "TUPLTYPE GRAYSCALE\n"); - else if (n == 2) fz_printf(ctx, out, "TUPLTYPE GRAYSCALE_ALPHA\n"); + else if (n == 1 && alpha) fz_printf(ctx, out, "TUPLTYPE GRAYSCALE_ALPHA\n"); else if (n == 3) fz_printf(ctx, out, "TUPLTYPE RGB\n"); - else if (n == 4 && alpha) fz_printf(ctx, out, "TUPLTYPE RGB_ALPHA\n"); + else if (n == 3 && alpha) fz_printf(ctx, out, "TUPLTYPE RGB_ALPHA\n"); else if (n == 4 && !alpha) fz_printf(ctx, out, "TUPLTYPE CMYK\n"); else if (n == 5) fz_printf(ctx, out, "TUPLTYPE CMYK_ALPHA\n"); fz_printf(ctx, out, "ENDHDR\n"); } void -fz_write_pam_band(fz_context *ctx, fz_output *out, int w, int h, int n, int stride, int band_start, int bandheight, unsigned char *sp) +fz_write_pam_band(fz_context *ctx, fz_output *out, int w, int h, int n, int alpha, int stride, int band_start, int bandheight, unsigned char *sp) { int y; int end = band_start + bandheight; @@ -142,6 +142,7 @@ fz_write_pam_band(fz_context *ctx, fz_output *out, int w, int h, int n, int stri if (!out) return; + n += alpha; if (end > h) end = h; end -= band_start; @@ -157,7 +158,7 @@ void fz_write_pixmap_as_pam(fz_context *ctx, fz_output *out, fz_pixmap *pixmap) { fz_write_pam_header(ctx, out, pixmap->w, pixmap->h, pixmap->n, pixmap->alpha); - fz_write_pam_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, pixmap->stride, 0, pixmap->h, pixmap->samples); + fz_write_pam_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, pixmap->alpha, pixmap->stride, 0, pixmap->h, pixmap->samples); } void @@ -167,7 +168,7 @@ fz_save_pixmap_as_pam(fz_context *ctx, fz_pixmap *pixmap, char *filename) fz_try(ctx) { fz_write_pam_header(ctx, out, pixmap->w, pixmap->h, pixmap->n, pixmap->alpha); - fz_write_pam_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, pixmap->stride, 0, pixmap->h, pixmap->samples); + fz_write_pam_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, pixmap->alpha, pixmap->stride, 0, pixmap->h, pixmap->samples); } fz_always(ctx) fz_drop_output(ctx, out); diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c index 7d17336b..6c27fc28 100644 --- a/source/tools/mudraw.c +++ b/source/tools/mudraw.c @@ -910,7 +910,7 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in if (output_format == OUT_PGM || output_format == OUT_PPM || output_format == OUT_PNM) fz_write_pnm_band(ctx, out, pix->w, totalheight, pix->n, pix->alpha, pix->stride, band, drawheight, pix->samples); else if (output_format == OUT_PAM) - fz_write_pam_band(ctx, out, pix->w, totalheight, pix->n, pix->stride, band, drawheight, pix->samples); + fz_write_pam_band(ctx, out, pix->w, totalheight, pix->n, pix->alpha, pix->stride, band, drawheight, pix->samples); else if (output_format == OUT_PNG) fz_write_png_band(ctx, out, poc, pix->stride, band, drawheight, pix->samples); else if (output_format == OUT_PWG) -- cgit v1.2.3