Commit a87a11ee authored by Adrian Johnson's avatar Adrian Johnson

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.
parent 63da26f8
......@@ -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;
......
......@@ -56,7 +56,8 @@ public:
enum ImageFormat {
imgRGB,
imgGray,
imgMonochrome
imgMonochrome,
imgCMYK
};
// Create an OutputDev which will write images to files named
......
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment