Commit 8f466775 authored by Adrian Johnson's avatar Adrian Johnson
Browse files

Change PNGWriter monochrome format to be 8 pixels/byte

to be consistent with TiffWriter and NetPBMWriter
parent e53aec2c
......@@ -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;
}
......
......@@ -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 };
......
......@@ -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);
}
......
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment