[poppler] splash/SplashBitmap.cc splash/SplashBitmap.h
Albert Astals Cid
aacid at kemper.freedesktop.org
Fri Nov 25 16:21:38 UTC 2016
splash/SplashBitmap.cc | 93 ++++++++++++++++++++++++++++++++++++-------------
splash/SplashBitmap.h | 3 +
2 files changed, 71 insertions(+), 25 deletions(-)
New commits:
commit b4e93c374deaaf31121a666c987a35bc9554beb3
Author: Kenji Uno <ku at digitaldolphins.jp>
Date: Thu Nov 3 10:19:06 2016 +0900
Fix pdftoppm -tiff -gray/-mono incorrect output.
- SplashBitmap has imageWriterFormat that ImgWriter
should accept.
diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc
index 7c14b31..e9b2be4 100644
--- a/splash/SplashBitmap.cc
+++ b/splash/SplashBitmap.cc
@@ -22,6 +22,7 @@
// Copyright (C) 2011-2013 Thomas Freitag <Thomas.Freitag at alfa.de>
// Copyright (C) 2012 Anthony Wesley <awesley at smartnetworks.com.au>
// Copyright (C) 2015 Adam Reichold <adamreichold at myopera.com>
+// Copyright (C) 2016 Kenji Uno <ku at digitaldolphins.jp>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -354,6 +355,8 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, in
ImgWriter *writer;
SplashError e;
+ SplashColorMode imageWriterFormat = splashModeRGB8;
+
switch (format) {
#ifdef ENABLE_LIBPNG
case splashFormatPng:
@@ -377,9 +380,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:
@@ -408,7 +413,7 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, in
return splashErrGeneric;
}
- e = writeImgFile(writer, f, hDPI, vDPI);
+ e = writeImgFile(writer, f, hDPI, vDPI, imageWriterFormat);
delete writer;
return e;
}
@@ -617,7 +622,7 @@ void SplashBitmap::getCMYKLine(int yl, SplashColorPtr line) {
}
#endif
-SplashError SplashBitmap::writeImgFile(ImgWriter *writer, FILE *f, int hDPI, int vDPI) {
+SplashError SplashBitmap::writeImgFile(ImgWriter *writer, FILE *f, int hDPI, int vDPI, SplashColorMode imageWriterFormat) {
if (mode != splashModeRGB8 && mode != splashModeMono8 && mode != splashModeMono1 && mode != splashModeXBGR8 && mode != splashModeBGR8
#if SPLASH_CMYK
&& mode != splashModeCMYK8 && mode != splashModeDeviceN8
@@ -744,41 +749,81 @@ 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 4417af7..6858f90 100644
--- a/splash/SplashBitmap.h
+++ b/splash/SplashBitmap.h
@@ -21,6 +21,7 @@
// Copyright (C) 2010 William Bader <williambader at hotmail.com>
// Copyright (C) 2012 Thomas Freitag <Thomas.Freitag at alfa.de>
// Copyright (C) 2015 Adam Reichold <adamreichold at myopera.com>
+// Copyright (C) 2016 Kenji Uno <ku at digitaldolphins.jp>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -74,7 +75,7 @@ public:
SplashError writeImgFile(SplashImageFileFormat format, char *fileName, int hDPI, int vDPI, const char *compressionString = "");
SplashError writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI, const char *compressionString = "");
- SplashError writeImgFile(ImgWriter *writer, FILE *f, int hDPI, int vDPI);
+ SplashError writeImgFile(ImgWriter *writer, FILE *f, int hDPI, int vDPI, SplashColorMode imageWriterFormat);
enum ConversionMode
{
More information about the poppler
mailing list