From 05feb601c8e5d652cc090f2f54f187673bbce534 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 29 Aug 2013 22:42:34 +0930 Subject: [PATCH] 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. --- utils/ImageOutputDev.cc | 33 ++++++++++++++++++++++++++++++++- utils/ImageOutputDev.h | 3 ++- utils/pdfimages.1 | 13 ++++++++----- utils/pdfimages.cc | 3 ++- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/utils/ImageOutputDev.cc b/utils/ImageOutputDev.cc index 3ec3074..373bbea 100644 --- a/utils/ImageOutputDev.cc +++ b/utils/ImageOutputDev.cc @@ -357,6 +357,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; @@ -418,6 +419,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; @@ -543,7 +565,12 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str, if (inlineImg) embedStr->restore(); - } 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 @@ -577,6 +604,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 33002e4..ea7348a 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); -- 1.8.1.2