From 66e1ac0888722b673a5537f008447167d33ffbf7 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 18 Aug 2013 16:08:02 +0930 Subject: [PATCH 2/5] Change PNGWriter monochrome format to be 8 pixels/byte to be consistent with TiffWriter and NetPBMWriter --- goo/PNGWriter.cc | 4 ---- goo/PNGWriter.h | 2 +- utils/HtmlOutputDev.cc | 18 ++++++------------ utils/pdftocairo.cc | 2 +- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/goo/PNGWriter.cc b/goo/PNGWriter.cc index b775600..4370f28 100644 --- a/goo/PNGWriter.cc +++ b/goo/PNGWriter.cc @@ -147,10 +147,6 @@ bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI) return false; } - // pack 1 pixel/byte rows into 8 pixels/byte - if (priv->format == MONOCHROME) - png_set_packing(priv->png_ptr); - return true; } diff --git a/goo/PNGWriter.h b/goo/PNGWriter.h index ac8f95a..64b8833 100644 --- a/goo/PNGWriter.h +++ b/goo/PNGWriter.h @@ -31,7 +31,7 @@ public: /* RGB - 3 bytes/pixel * RGBA - 4 bytes/pixel * GRAY - 1 byte/pixel - * MONOCHROME - 1 byte/pixel. PNGWriter will bitpack to 8 pixels/byte + * MONOCHROME - 8 pixels/byte */ enum Format { RGB, RGBA, GRAY, MONOCHROME }; diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc index 7926674..0824bdb 100644 --- a/utils/HtmlOutputDev.cc +++ b/utils/HtmlOutputDev.cc @@ -1413,32 +1413,26 @@ void HtmlOutputDev::drawPngImage(GfxState *state, Stream *str, int width, int he delete imgStr; } else { // isMask == true - ImageStream *imgStr = new ImageStream(str, width, 1, 1); - imgStr->reset(); + int size = (width + 7)/8; - Guchar *png_row = (Guchar *)gmalloc( width ); + str->reset(); + Guchar *png_row = (Guchar *)gmalloc(size); for (int ri = 0; ri < height; ++ri) { - // read the row of the mask - Guchar *bit_row = imgStr->getLine(); - - // invert for PNG - for(int i = 0; i < width; i++) - png_row[i] = bit_row[i] ? 0xff : 0x00; + for(int i = 0; i < size; i++) + png_row[i] = str->getChar(); if (!writer->writeRow( &png_row )) { error(errIO, -1, "Failed to write into PNG '%s'", fName->getCString()); delete writer; fclose(f1); - delete imgStr; gfree(png_row); return; } } - imgStr->close(); - delete imgStr; + str->close(); gfree(png_row); } diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc index 192d295..841c388 100644 --- a/utils/pdftocairo.cc +++ b/utils/pdftocairo.cc @@ -370,7 +370,7 @@ void writePageImage(GooString *filename) int b = (*pixel & 0x000000ff) >> 0; // an arbitrary integer approximation of .3*r + .59*g + .11*b int y = (r*19661+g*38666+b*7209 + 32829)>>16; - if (tiff && mono) { + if (mono) { if (bit == 7) *rowp = 0; if (y > 127) -- 1.8.1.2