summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorAdrian Johnson <ajohnson@redneon.com>2013-08-18 16:08:02 +0930
committerAdrian Johnson <ajohnson@redneon.com>2013-08-26 06:40:34 +0930
commit8f466775c77b09a7114c688004317e6db05bcd3f (patch)
tree9c0c18373f8fe368f5f81c15b59bd2d67c29e7e2 /utils
parente53aec2c61ba42cf0635dc05f8e27e3503c1eaac (diff)
Change PNGWriter monochrome format to be 8 pixels/byte
to be consistent with TiffWriter and NetPBMWriter
Diffstat (limited to 'utils')
-rw-r--r--utils/HtmlOutputDev.cc31
-rw-r--r--utils/ImageOutputDev.cc9
-rw-r--r--utils/pdftocairo.cc2
3 files changed, 26 insertions, 16 deletions
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 7926674e..39261787 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -1413,32 +1413,39 @@ 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;
+
+ // PDF masks use 0 = draw current color, 1 = leave unchanged.
+ // We invert this to provide the standard interpretation of alpha
+ // (0 = transparent, 1 = opaque). If the colorMap already inverts
+ // the mask we leave the data unchanged.
+ int invert_bits = 0xff;
+ if (colorMap) {
+ GfxGray gray;
+ Guchar zero = 0;
+ colorMap->getGray(&zero, &gray);
+ if (colToByte(gray) == 0)
+ invert_bits = 0x00;
+ }
- 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() ^ invert_bits;
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/ImageOutputDev.cc b/utils/ImageOutputDev.cc
index 58f3cd84..110ba21f 100644
--- a/utils/ImageOutputDev.cc
+++ b/utils/ImageOutputDev.cc
@@ -315,7 +315,7 @@ void ImageOutputDev::writeImageFile(ImgWriter *writer, ImageFormat format, const
GfxRGB rgb;
GfxGray gray;
Guchar zero = 0;
- int invert_bits = 0xff;
+ int invert_bits;
setFilename(ext);
++imgNum;
@@ -341,8 +341,11 @@ void ImageOutputDev::writeImageFile(ImgWriter *writer, ImageFormat format, const
row = (unsigned char *) gmallocn(width, sizeof(unsigned int));
- // if 0 comes out as 0 in the color map, the we _flip_ stream bits
- // otherwise we pass through stream bits unmolested
+ // PDF masks use 0 = draw current color, 1 = leave unchanged.
+ // We invert this to provide the standard interpretation of alpha
+ // (0 = transparent, 1 = opaque). If the colorMap already inverts
+ // the mask we leave the data unchanged.
+ invert_bits = 0xff;
if (colorMap) {
colorMap->getGray(&zero, &gray);
if (colToByte(gray) == 0)
diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc
index 192d2957..841c3880 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)