Skip to content

Commit

Permalink
Fix pdftoppm -tiff -gray/-mono incorrect output.
Browse files Browse the repository at this point in the history
- SplashBitmap has imageWriterFormat that ImgWriter
  should accept.
  • Loading branch information
kenjiuno committed Nov 3, 2016
1 parent 6c01a48 commit ec4fcfc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 22 deletions.
90 changes: 68 additions & 22 deletions splash/SplashBitmap.cc
Expand Up @@ -354,6 +354,8 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, in
ImgWriter *writer;
SplashError e;

imageWriterFormat = splashModeRGB8;

switch (format) {
#ifdef ENABLE_LIBPNG
case splashFormatPng:
Expand All @@ -377,9 +379,11 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, in
switch (mode) {
case splashModeMono1:
writer = new TiffWriter(TiffWriter::MONOCHROME);
imageWriterFormat = splashModeMono1;
break;
case splashModeMono8:
writer = new TiffWriter(TiffWriter::GRAY);
imageWriterFormat = splashModeMono8;
break;
case splashModeRGB8:
case splashModeBGR8:
Expand Down Expand Up @@ -744,41 +748,83 @@ SplashError SplashBitmap::writeImgFile(ImgWriter *writer, FILE *f, int hDPI, int

case splashModeMono8:
{
unsigned char *row = new unsigned char[3 * width];
for (int y = 0; y < height; y++) {
// Convert into a PNG row
for (int x = 0; x < width; x++) {
row[3*x] = data[y * rowSize + x];
row[3*x+1] = data[y * rowSize + x];
row[3*x+2] = data[y * rowSize + x];
}
if (imageWriterFormat == splashModeMono8) {
SplashColorPtr row;
unsigned char **row_pointers = new unsigned char*[height];
row = data;

if (!writer->writeRow(&row)) {
delete[] row;
for (int y = 0; y < height; ++y) {
row_pointers[y] = row;
row += rowSize;
}
if (!writer->writePointers(row_pointers, height)) {
delete[] row_pointers;
return splashErrGeneric;
}
delete[] row_pointers;
}
else if (imageWriterFormat == splashModeRGB8) {
unsigned char *row = new unsigned char[3 * width];
for (int y = 0; y < height; y++) {
// Convert into a PNG row
for (int x = 0; x < width; x++) {
row[3*x] = data[y * rowSize + x];
row[3*x+1] = data[y * rowSize + x];
row[3*x+2] = data[y * rowSize + x];
}

if (!writer->writeRow(&row)) {
delete[] row;
return splashErrGeneric;
}
}
delete[] row;
}
else {
// only splashModeMono8 or splashModeRGB8
return splashErrGeneric;
}
delete[] row;
}
break;

case splashModeMono1:
{
unsigned char *row = new unsigned char[3 * width];
for (int y = 0; y < height; y++) {
// Convert into a PNG row
for (int x = 0; x < width; x++) {
getPixel(x, y, &row[3*x]);
row[3*x+1] = row[3*x];
row[3*x+2] = row[3*x];
}
if (imageWriterFormat == splashModeMono1) {
SplashColorPtr row;
unsigned char **row_pointers = new unsigned char*[height];
row = data;

if (!writer->writeRow(&row)) {
delete[] row;
for (int y = 0; y < height; ++y) {
row_pointers[y] = row;
row += rowSize;
}
if (!writer->writePointers(row_pointers, height)) {
delete[] row_pointers;
return splashErrGeneric;
}
delete[] row_pointers;
}
else if (imageWriterFormat == splashModeRGB8) {
unsigned char *row = new unsigned char[3 * width];
for (int y = 0; y < height; y++) {
// Convert into a PNG row
for (int x = 0; x < width; x++) {
getPixel(x, y, &row[3*x]);
row[3*x+1] = row[3*x];
row[3*x+2] = row[3*x];
}

if (!writer->writeRow(&row)) {
delete[] row;
return splashErrGeneric;
}
}
delete[] row;
}
else {
// only splashModeMono1 or splashModeRGB8
return splashErrGeneric;
}
delete[] row;
}
break;

Expand Down
1 change: 1 addition & 0 deletions splash/SplashBitmap.h
Expand Up @@ -109,6 +109,7 @@ class SplashBitmap {
Guchar *alpha; // pointer to row zero of the alpha data
// (always top-down)
GooList *separationList; // list of spot colorants and their mapping functions
SplashColorMode imageWriterFormat; // input format of ImgWriter

friend class Splash;
};
Expand Down

0 comments on commit ec4fcfc

Please sign in to comment.