summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorAdrian Johnson <ajohnson@redneon.com>2012-11-17 10:04:55 +1030
committerAdrian Johnson <ajohnson@redneon.com>2012-11-17 10:04:55 +1030
commitd1c509c48fc422649d0c2c2d70af5e13e3472874 (patch)
tree97a7cae5d7f4ea6e5fedee5245e6e9f33334df1d /utils
parent6d3fe48cf30b298b4436462904d781ea441c1f3d (diff)
pdftocairo: add tiff support
Bug 57006
Diffstat (limited to 'utils')
-rw-r--r--utils/pdftocairo.123
-rw-r--r--utils/pdftocairo.cc88
2 files changed, 83 insertions, 28 deletions
diff --git a/utils/pdftocairo.1 b/utils/pdftocairo.1
index 19b62efb..7d17eef4 100644
--- a/utils/pdftocairo.1
+++ b/utils/pdftocairo.1
@@ -1,6 +1,6 @@
.TH pdftoppm 1
.SH NAME
-pdftocairo \- Portable Document Format (PDF) to PNG/JPEG/PDF/PS/EPS/SVG using cairo
+pdftocairo \- Portable Document Format (PDF) to PNG/JPEG/TIFF/PDF/PS/EPS/SVG using cairo
.SH SYNOPSIS
.B pdftocairo
[options]
@@ -14,6 +14,8 @@ Portable Network Graphics (PNG)
.IP \(bu
JPEG Interchange Format (JPEG)
.IP \(bu
+Tagged Image File Format (TIFF)
+.IP \(bu
Portable Document Format (PDF)
.IP \(bu
PostScript (PS)
@@ -27,7 +29,7 @@ reads the PDF file,
.IR PDF-file ,
and writes to
.IR output-file .
-The image formats (PNG and JPEG) generate one file per page with the page number and file type appended to
+The image formats (PNG, JPEG, and TIFF) generate one file per page with the page number and file type appended to
.IR output-file
(except when \-singlefile is used).
When the output format is a vector format (PDF, PS, EPS, and SVG) or when \-singlefile is used,
@@ -46,7 +48,7 @@ is not used, the output filename will be derived from the
.IR PDF-file
filename.
.PP
-Not all options are valid with all output formats. One (and only one) of the output format options (\-png, \-jpeg, \-pdf, \-ps, \-eps, or \-svg) must be used.
+Not all options are valid with all output formats. One (and only one) of the output format options (\-png, \-jpeg, \-tiff, \-pdf, \-ps, \-eps, or \-svg) must be used.
.PP
The resolution options (\-r, \-rx, \-ry) set the resolution of the
image output formats. The image dimensions will depend on the PDF page
@@ -72,6 +74,9 @@ Generates a PNG file(s)
.BI \-jpeg
Generates a JPEG file(s)
.TP
+.BI \-tiff
+Generates a TIFF file(s)
+.TP
.BI \-pdf
Generates a PDF file
.TP
@@ -114,17 +119,17 @@ Specifies the Y resolution, in pixels per inch of image files (or rasterized reg
.BI \-scale-to " number"
Scales the long side of each page (width for landscape pages, height
for portrait pages) to fit in scale-to pixels. The size of the short
-side will be determined by the aspect ratio of the page (PNG/JPEG only).
+side will be determined by the aspect ratio of the page (PNG/JPEG/TIFF only).
.TP
.BI \-scale-to-x " number"
Scales each page horizontally to fit in scale-to-x pixels. If
scale-to-y is set to -1, the vertical size will determined by the
-aspect ratio of the page (PNG/JPEG only).
+aspect ratio of the page (PNG/JPEG/TIFF only).
.TP
.BI \-scale-to-y " number"
Scales each page vertically to fit in scale-to-y pixels. If scale-to-x
is set to -1, the horizontal size will determined by the aspect ratio
-of the page (PNG/JPEG only).
+of the page (PNG/JPEG/TIFF only).
.TP
.BI \-x " number"
Specifies the x-coordinate of the crop area top left corner in pixels (image output) or points (vector output)
@@ -145,13 +150,13 @@ Specifies the size of crop square in pixels (image output) or points (vector out
Uses the crop box rather than media box when generating the files
.TP
.B \-mono
-Generate a monochrome file (PNG only).
+Generate a monochrome file (PNG and TIFF only).
.TP
.B \-gray
-Generate a grayscale file (PNG and JPEG only).
+Generate a grayscale file (PNG, JPEG, and TIFF only).
.TP
.B \-transp
-Use a transparent page color instead of white (PNG only).
+Use a transparent page color instead of white (PNG and TIFF only).
.TP
.BI \-icc " icc-file"
Use the specified ICC file as the output profile (PNG only). The profile will be embedded in the PNG file.
diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc
index 8d13e316..258d939c 100644
--- a/utils/pdftocairo.cc
+++ b/utils/pdftocairo.cc
@@ -45,6 +45,7 @@
#include "goo/ImgWriter.h"
#include "goo/JpegWriter.h"
#include "goo/PNGWriter.h"
+#include "goo/TiffWriter.h"
#include "GlobalParams.h"
#include "Object.h"
#include "PDFDoc.h"
@@ -75,6 +76,7 @@ static GBool ps = gFalse;
static GBool eps = gFalse;
static GBool pdf = gFalse;
static GBool svg = gFalse;
+static GBool tiff = gFalse;
static int firstPage = 1;
static int lastPage = 0;
@@ -109,6 +111,7 @@ static GBool expand = gFalse;
static GBool noShrink = gFalse;
static GBool noCenter = gFalse;
static GBool duplex = gFalse;
+static char tiffCompressionStr[16] = "";
static char ownerPassword[33] = "";
static char userPassword[33] = "";
@@ -125,6 +128,12 @@ static const ArgDesc argDesc[] = {
{"-jpeg", argFlag, &jpeg, 0,
"generate a JPEG file"},
#endif
+#if ENABLE_LIBTIFF
+ {"-tiff", argFlag, &tiff, 0,
+ "generate a TIFF file"},
+ {"-tiffcompression", argString, tiffCompressionStr, sizeof(tiffCompressionStr),
+ "set TIFF compression: none, packbits, jpeg, lzw, deflate"},
+#endif
#if CAIRO_HAS_PS_SURFACE
{"-ps", argFlag, &ps, 0,
"generate PostScript file"},
@@ -288,6 +297,18 @@ void writePageImage(GooString *filename)
else
writer = new JpegWriter(JCS_RGB);
#endif
+ } else if (tiff) {
+#if ENABLE_LIBTIFF
+ if (transp)
+ writer = new TiffWriter(TiffWriter::RGBA_PREMULTIPLIED);
+ else if (gray)
+ writer = new TiffWriter(TiffWriter::GRAY);
+ else if (mono)
+ writer = new TiffWriter(TiffWriter::MONOCHROME);
+ else
+ writer = new TiffWriter(TiffWriter::RGB);
+ static_cast<TiffWriter*>(writer)->setCompressionString(tiffCompressionStr);
+#endif
}
if (!writer)
return;
@@ -316,21 +337,30 @@ void writePageImage(GooString *filename)
for (int y = 0; y < height; y++ ) {
uint32_t *pixel = (uint32_t *) (data + y*stride);
unsigned char *rowp = row;
+ int bit = 7;
for (int x = 0; x < width; x++, pixel++) {
if (transp) {
+ if (tiff) {
+ // RGBA premultipled format
+ *rowp++ = (*pixel & 0xff0000) >> 16;
+ *rowp++ = (*pixel & 0x00ff00) >> 8;
+ *rowp++ = (*pixel & 0x0000ff) >> 0;
+ *rowp++ = (*pixel & 0xff000000) >> 24;
+ } else {
// unpremultiply into RGBA format
- uint8_t a;
- a = (*pixel & 0xff000000) >> 24;
- if (a == 0) {
- *rowp++ = 0;
- *rowp++ = 0;
- *rowp++ = 0;
- } else {
- *rowp++ = (((*pixel & 0xff0000) >> 16) * 255 + a / 2) / a;
- *rowp++ = (((*pixel & 0x00ff00) >> 8) * 255 + a / 2) / a;
- *rowp++ = (((*pixel & 0x0000ff) >> 0) * 255 + a / 2) / a;
- }
- *rowp++ = a;
+ uint8_t a;
+ a = (*pixel & 0xff000000) >> 24;
+ if (a == 0) {
+ *rowp++ = 0;
+ *rowp++ = 0;
+ *rowp++ = 0;
+ } else {
+ *rowp++ = (((*pixel & 0xff0000) >> 16) * 255 + a / 2) / a;
+ *rowp++ = (((*pixel & 0x00ff00) >> 8) * 255 + a / 2) / a;
+ *rowp++ = (((*pixel & 0x0000ff) >> 0) * 255 + a / 2) / a;
+ }
+ *rowp++ = a;
+ }
} else if (gray || mono) {
// convert to gray
// The PDF Reference specifies the DeviceRGB to DeviceGray conversion as
@@ -340,7 +370,19 @@ void writePageImage(GooString *filename)
int b = (*pixel & 0x000000ff) >> 0;
// an arbitrary integer approximation of .3*r + .59*g + .11*b
int y = (r*19661+g*38666+b*7209 + 32829)>>16;
- *rowp++ = y;
+ if (tiff && mono) {
+ if (bit == 7)
+ *rowp = 0;
+ if (y > 127)
+ *rowp |= (1 << bit);
+ bit--;
+ if (bit < 0) {
+ bit = 7;
+ rowp++;
+ }
+ } else {
+ *rowp++ = y;
+ }
} else {
// copy into RGB format
*rowp++ = (*pixel & 0x00ff0000) >> 16;
@@ -630,6 +672,8 @@ static GooString *getImageFileName(GooString *outputFileName, int numDigits, int
imageName->append(".png");
else if (jpeg)
imageName->append(".jpg");
+ else if (tiff)
+ imageName->append(".tif");
return imageName;
}
@@ -702,7 +746,7 @@ static GooString *getOutputFileName(GooString *fileName, GooString *outputName)
static void checkInvalidPrintOption(GBool option, const char *option_name)
{
if (option) {
- fprintf(stderr, "Error: %s may only be used with the -png or -jpeg output options.\n", option_name);
+ fprintf(stderr, "Error: %s may only be used with the -png, -jpeg, or -tiff output options.\n", option_name);
exit(99);
}
}
@@ -752,6 +796,7 @@ int main(int argc, char *argv[]) {
num_outputs = (png ? 1 : 0) +
(jpeg ? 1 : 0) +
+ (tiff ? 1 : 0) +
(ps ? 1 : 0) +
(eps ? 1 : 0) +
(pdf ? 1 : 0) +
@@ -764,7 +809,7 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "Error: use only one of the output format options (-png, -jpeg, -ps, -eps, -pdf, -svg).\n");
exit(99);
}
- if (png || jpeg)
+ if (png || jpeg || tiff)
printing = gFalse;
else
printing = gTrue;
@@ -794,8 +839,8 @@ int main(int argc, char *argv[]) {
exit(99);
}
- if (transp && !png) {
- fprintf(stderr, "Error: -transp may only be used with png output.\n");
+ if (transp && !(png || tiff)) {
+ fprintf(stderr, "Error: -transp may only be used with png or tiff output.\n");
exit(99);
}
@@ -804,8 +849,13 @@ int main(int argc, char *argv[]) {
exit(99);
}
- if (mono && !png) {
- fprintf(stderr, "Error: -mono may only be used with png output.\n");
+ if (mono && !(png || tiff)) {
+ fprintf(stderr, "Error: -mono may only be used with png or tiff output.\n");
+ exit(99);
+ }
+
+ if (strlen(tiffCompressionStr) > 0 && !tiff) {
+ fprintf(stderr, "Error: -tiffcompression may only be used with tiff output.\n");
exit(99);
}