[poppler] utils/ImageOutputDev.cc utils/ImageOutputDev.h utils/pdfimages.1 utils/pdfimages.cc
Adrian Johnson
ajohnson at kemper.freedesktop.org
Thu Aug 29 21:05:27 PDT 2013
utils/ImageOutputDev.cc | 32 +++++++++++++++++++++++++++++++-
utils/ImageOutputDev.h | 3 ++-
utils/pdfimages.1 | 13 ++++++++-----
utils/pdfimages.cc | 3 ++-
4 files changed, 43 insertions(+), 8 deletions(-)
New commits:
commit a87a11ee6bbd0f5707a3ac34ac2b9cc79f4e92d0
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Thu Aug 29 22:42:34 2013 +0930
pdfimages: support cmyk tiff output
If -tiff is specified, CMYK images will be written as CMYK TIFF files
instead of converting to RGB. If both -png and -tiff are specified (as
is the case with the -all option), CMYK images are written as TIFF and
all other types as PNG.
diff --git a/utils/ImageOutputDev.cc b/utils/ImageOutputDev.cc
index ae7d309..68327a2 100644
--- a/utils/ImageOutputDev.cc
+++ b/utils/ImageOutputDev.cc
@@ -318,6 +318,7 @@ void ImageOutputDev::writeImageFile(ImgWriter *writer, ImageFormat format, const
unsigned char *rowp;
Guchar *p;
GfxRGB rgb;
+ GfxCMYK cmyk;
GfxGray gray;
Guchar zero = 0;
int invert_bits;
@@ -379,6 +380,27 @@ void ImageOutputDev::writeImageFile(ImgWriter *writer, ImageFormat format, const
writer->writeRow(&row);
break;
+ case imgCMYK:
+ p = imgStr->getLine();
+ rowp = row;
+ for (int x = 0; x < width; ++x) {
+ if (p) {
+ colorMap->getCMYK(p, &cmyk);
+ *rowp++ = colToByte(cmyk.c);
+ *rowp++ = colToByte(cmyk.m);
+ *rowp++ = colToByte(cmyk.y);
+ *rowp++ = colToByte(cmyk.k);
+ p += colorMap->getNumPixelComps();
+ } else {
+ *rowp++ = 0;
+ *rowp++ = 0;
+ *rowp++ = 0;
+ *rowp++ = 0;
+ }
+ }
+ writer->writeRow(&row);
+ break;
+
case imgGray:
p = imgStr->getLine();
rowp = row;
@@ -489,7 +511,11 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
// dump CCITT file
writeRawImage(str, "ccitt");
- } else if (outputPNG) {
+ } else if (outputPNG && !(outputTiff && colorMap &&
+ (colorMap->getColorSpace()->getMode() == csDeviceCMYK ||
+ (colorMap->getColorSpace()->getMode() == csICCBased &&
+ colorMap->getNumPixelComps() == 4)))) {
+
// output in PNG format
#if ENABLE_LIBPNG
@@ -523,6 +549,10 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
colorMap->getColorSpace()->getMode() == csCalGray) {
writer = new TiffWriter(TiffWriter::GRAY);
format = imgGray;
+ } else if (colorMap->getColorSpace()->getMode() == csDeviceCMYK ||
+ (colorMap->getColorSpace()->getMode() == csICCBased && colorMap->getNumPixelComps() == 4)) {
+ writer = new TiffWriter(TiffWriter::CMYK);
+ format = imgCMYK;
} else {
writer = new TiffWriter(TiffWriter::RGB);
format = imgRGB;
diff --git a/utils/ImageOutputDev.h b/utils/ImageOutputDev.h
index 8d0785c..14918ea 100644
--- a/utils/ImageOutputDev.h
+++ b/utils/ImageOutputDev.h
@@ -56,7 +56,8 @@ public:
enum ImageFormat {
imgRGB,
imgGray,
- imgMonochrome
+ imgMonochrome,
+ imgCMYK
};
// Create an OutputDev which will write images to files named
diff --git a/utils/pdfimages.1 b/utils/pdfimages.1
index 9da4c08..d754195 100644
--- a/utils/pdfimages.1
+++ b/utils/pdfimages.1
@@ -23,9 +23,12 @@ is the image number and
.I xxx
is the image type (.ppm, .pbm, .png, .tif, .jpg, jp2, jb2e, or jb2g).
.PP
-The default output format is PBM (for monochrome images) or PPM for non-monochrome. The
-\-png or \-tiff options change to default output to PNG or TIFF respectively. In addition the \-j,
-\-jp2, and \-jbig2 options will cause JPEG, JPEG2000, and JBIG2, respectively, images in the PDF file
+The default output format is PBM (for monochrome images) or PPM for
+non-monochrome. The \-png or \-tiff options change to default output
+to PNG or TIFF respectively. If both \-png and \-tiff are specified,
+CMYK images will be written as TIFF and all other images will be
+written as PNG. In addition the \-j, \-jp2, and \-jbig2 options will
+cause JPEG, JPEG2000, and JBIG2, respectively, images in the PDF file
to be written in their native format.
.SH OPTIONS
.TP
@@ -88,8 +91,8 @@ Input data fills from most significant bit to least significant bit.
.RE
.TP
.B \-all
-Write JPEG, JPEG2000, JBIG2, and CCITT images in their native format. All other images are written as PNG files.
-This is equivalent to specifying the options \-png \-j \-jp2 \-jbig2 \-ccitt.
+Write JPEG, JPEG2000, JBIG2, and CCITT images in their native format. CMYK files are written as TIFF files. All other images are written as PNG files.
+This is equivalent to specifying the options \-png \-tiff \-j \-jp2 \-jbig2 \-ccitt.
.TP
.B \-list
Instead of writing the images, list the images along with various information for each image. Do not specify an
diff --git a/utils/pdfimages.cc b/utils/pdfimages.cc
index ae05c8b..96709ed 100644
--- a/utils/pdfimages.cc
+++ b/utils/pdfimages.cc
@@ -86,7 +86,7 @@ static const ArgDesc argDesc[] = {
{"-ccitt", argFlag, &dumpCCITT, 0,
"write CCITT images as CCITT files"},
{"-all", argFlag, &allFormats, 0,
- "equivalent to -png -j -jp2 -jbig2 -ccitt"},
+ "equivalent to -png -tiff -j -jp2 -jbig2 -ccitt"},
{"-list", argFlag, &listImages, 0,
"print list of images instead of saving"},
{"-opw", argString, ownerPassword, sizeof(ownerPassword),
@@ -194,6 +194,7 @@ int main(int argc, char *argv[]) {
if (imgOut->isOk()) {
if (allFormats) {
imgOut->enablePNG(gTrue);
+ imgOut->enableTiff(gTrue);
imgOut->enableJpeg(gTrue);
imgOut->enableJpeg2000(gTrue);
imgOut->enableJBig2(gTrue);
More information about the poppler
mailing list