diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc index 7c14b3161..22eaac90c 100644 --- a/splash/SplashBitmap.cc +++ b/splash/SplashBitmap.cc @@ -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: @@ -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: @@ -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; diff --git a/splash/SplashBitmap.h b/splash/SplashBitmap.h index 4417af733..555425804 100644 --- a/splash/SplashBitmap.h +++ b/splash/SplashBitmap.h @@ -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; };