--- poppler-git-28dec10-tiff/config.h.cmake- 2010-12-28 15:11:14.312526808 +0100 +++ poppler-git-28dec10-tiff/config.h.cmake 2010-12-28 15:12:37.240550595 +0100 @@ -9,6 +9,9 @@ /* Use libopenjpeg instead of builtin jpeg2000 decoder. */ #cmakedefine ENABLE_LIBOPENJPEG 1 +/* Build against libtiff. */ +#cmakedefine ENABLE_LIBTIFF 1 + /* Build against libpng. */ #cmakedefine ENABLE_LIBPNG 1 --- poppler-git-28dec10-tiff/configure.ac- 2010-12-28 15:11:14.312526808 +0100 +++ poppler-git-28dec10-tiff/configure.ac 2010-12-28 15:12:37.241550627 +0100 @@ -173,6 +173,37 @@ AH_TEMPLATE([ENABLE_LIBOPENJPEG], [Use libopenjpeg instead of builtin jpeg2000 decoder.]) +dnl ##### Test for libtiff +AC_ARG_ENABLE(libtiff, + AC_HELP_STRING([--disable-libtiff], + [Don't build against libtiff.]), + enable_libtiff=$enableval, + enable_libtiff="try") + +if test x$enable_libtiff = xyes; then + AC_CHECK_LIB([tiff], [TIFFOpen],, + AC_MSG_ERROR("*** libtiff library not found ***")) + AC_CHECK_HEADERS([tiffio.h],, + AC_MSG_ERROR("*** libtiff headers not found ***")) +elif test x$enable_libtiff = xtry; then + AC_CHECK_LIB([tiff], [TIFFOpen], + [enable_libtiff="yes"], + [enable_libtiff="no"]) + AC_CHECK_HEADERS([tiffio.h],, + [enable_libtiff="no"]) +fi + +if test x$enable_libtiff = xyes; then + LIBTIFF_LIBS="-ltiff" + AC_SUBST(LIBTIFF_LIBS) + AC_DEFINE(ENABLE_LIBTIFF) +fi + +AM_CONDITIONAL(BUILD_LIBTIFF, test x$enable_libtiff = xyes) +AH_TEMPLATE([ENABLE_LIBTIFF], [Build against libtiff.]) +if test x$enable_libtiff = xyes; then + AC_DEFINE(ENABLE_LIBTIFF, 1, [Build against libtiff.]) +fi dnl ##### Checks for library functions. AC_CHECK_FUNCS(popen mkstemp mkstemps) @@ -686,6 +717,7 @@ echo " use gtk-doc: $enable_gtk_doc" echo " use libjpeg: $enable_libjpeg" echo " use libpng: $enable_libpng" +echo " use libtiff: $enable_libtiff" echo " use zlib: $enable_zlib" echo " use libcurl: $enable_libcurl" echo " use libopenjpeg: $enable_libopenjpeg" --- poppler-git-28dec10-tiff/goo/Makefile.am- 2010-12-28 15:11:14.327526813 +0100 +++ poppler-git-28dec10-tiff/goo/Makefile.am 2010-12-28 15:12:37.242550657 +0100 @@ -15,6 +15,7 @@ FixedPoint.h \ PNGWriter.h \ JpegWriter.h \ + TiffWriter.h \ ImgWriter.h \ GooLikely.h \ gstrtod.h @@ -40,5 +41,6 @@ FixedPoint.cc \ PNGWriter.cc \ JpegWriter.cc \ + TiffWriter.cc \ ImgWriter.cc \ gstrtod.cc --- poppler-git-28dec10-tiff/goo/TiffWriter.cc- 2010-12-28 15:12:37.243550685 +0100 +++ poppler-git-28dec10-tiff/goo/TiffWriter.cc 2010-12-28 15:19:45.884699142 +0100 @@ -0,0 +1,205 @@ +//======================================================================== +// +// TiffWriter.cc +// +// This file is licensed under the GPLv2 or later +// +// Copyright (C) 2010 William Bader +// +//======================================================================== + +#include "TiffWriter.h" + +#if ENABLE_LIBTIFF + +#include + +TiffWriter::~TiffWriter() +{ + // no cleanup needed +} + +TiffWriter::TiffWriter() +{ + f = NULL; + numRows = 0; + curRow = 0; + compressionStr = NULL; + splashMode = splashModeRGB8; +} + +// Set the compression type + +void TiffWriter::setCompressionStr(const char *compressionStrArg) +{ + compressionStr = compressionStrArg; +} + +// Set the bitmap mode + +void TiffWriter::setSplashMode(enum SplashColorMode splashModeArg) +{ + splashMode = splashModeArg; +} + +// Write a TIFF file. + +bool TiffWriter::init(FILE *openedFile, int width, int height, int hDPI, int vDPI) +{ + int x, y; + unsigned int compression; + uint16 photometric; + uint32 rowsperstrip = (uint32) -1; + int bitspersample; + uint16 samplesperpixel; + static struct compression_name_tag { + const char *compressionName; // name of the compression option from the command line + unsigned int compressionCode; // internal libtiff code + const char *compressionDescription; // descriptive name + } compressionList[] = { + { "none", COMPRESSION_NONE, "no compression" }, + { "ccittrle", COMPRESSION_CCITTRLE, "CCITT modified Huffman RLE" }, + { "ccittfax3", COMPRESSION_CCITTFAX3,"CCITT Group 3 fax encoding" }, + { "ccittt4", COMPRESSION_CCITT_T4, "CCITT T.4 (TIFF 6 name)" }, + { "ccittfax4", COMPRESSION_CCITTFAX4, "CCITT Group 4 fax encoding" }, + { "ccittt6", COMPRESSION_CCITT_T6, "CCITT T.6 (TIFF 6 name)" }, + { "lzw", COMPRESSION_LZW, "Lempel-Ziv & Welch" }, + { "ojpeg", COMPRESSION_OJPEG, "!6.0 JPEG" }, + { "jpeg", COMPRESSION_JPEG, "%JPEG DCT compression" }, + { "next", COMPRESSION_NEXT, "NeXT 2-bit RLE" }, + { "packbits", COMPRESSION_PACKBITS, "Macintosh RLE" }, + { "ccittrlew", COMPRESSION_CCITTRLEW, "CCITT modified Huffman RLE w/ word alignment" }, + { "deflate", COMPRESSION_DEFLATE, "Deflate compression" }, + { "adeflate", COMPRESSION_ADOBE_DEFLATE, "Deflate compression, as recognized by Adobe" }, + { "dcs", COMPRESSION_DCS, "Kodak DCS encoding" }, + { "jbig", COMPRESSION_JBIG, "ISO JBIG" }, + { "jp2000", COMPRESSION_JP2000, "Leadtools JPEG2000" }, + { NULL, 0, NULL } + }; + + // Initialize + + f = NULL; + curRow = 0; + + // Store the number of rows + + numRows = height; + + // Set the compression + + compression = COMPRESSION_NONE; + + if (compressionStr == NULL || strcmp(compressionStr, "") == 0) { + compression = COMPRESSION_NONE; + } else { + int i; + for (i = 0; compressionList[i].compressionName != NULL; i++) { + if (strcmp(compressionStr, compressionList[i].compressionName) == 0) { + compression = compressionList[i].compressionCode; + break; + } + } + if (compressionList[i].compressionName == NULL) { + fprintf(stderr, "TiffWriter: Unknown compression type '%.10s', using 'none'.\n", compressionStr); + fprintf(stderr, "Known compression types (the tiff library might not support every type)\n"); + for (i = 0; compressionList[i].compressionName != NULL; i++) { + fprintf(stderr, "%10s %s\n", compressionList[i].compressionName, compressionList[i].compressionDescription); + } + } + } + + // Set bits per sample, samples per pixel, and photometric type from the splash mode + + bitspersample = (splashMode == splashModeMono1? 1: 8); + + switch (splashMode) { + + case splashModeMono1: + case splashModeMono8: + samplesperpixel = 1; + photometric = PHOTOMETRIC_MINISBLACK; + break; + + case splashModeRGB8: + case splashModeBGR8: + samplesperpixel = 3; + photometric = PHOTOMETRIC_RGB; + break; + + default: + fprintf(stderr, "TiffWriter: Mode %d not supported\n", splashMode); + return false; + } + + // Open the file + + if (openedFile == NULL) { + fprintf(stderr, "TiffWriter: No output file given.\n"); + return false; + } + + f = TIFFFdOpen(fileno(openedFile), "-", "w"); + + if (!f) { + return false; + } + + // Set TIFF tags + + TIFFSetField(f, TIFFTAG_IMAGEWIDTH, width); + TIFFSetField(f, TIFFTAG_IMAGELENGTH, height); + TIFFSetField(f, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); + TIFFSetField(f, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel); + TIFFSetField(f, TIFFTAG_BITSPERSAMPLE, bitspersample); + TIFFSetField(f, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); + TIFFSetField(f, TIFFTAG_PHOTOMETRIC, photometric); + TIFFSetField(f, TIFFTAG_COMPRESSION, (uint16) compression); + TIFFSetField(f, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(f, rowsperstrip)); + TIFFSetField(f, TIFFTAG_XRESOLUTION, (double) hDPI); + TIFFSetField(f, TIFFTAG_YRESOLUTION, (double) vDPI); + TIFFSetField(f, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); + + return true; +} + +bool TiffWriter::writePointers(unsigned char **rowPointers, int rowCount) +{ + // Write all rows to the file + + int row; + + for (row = 0; row < rowCount; row++) { + if (TIFFWriteScanline(f, rowPointers[row], row, 0) < 0) { + fprintf(stderr, "TiffWriter: Error writing tiff row %d\n", row); + return false; + } + } + + return true; +} + +bool TiffWriter::writeRow(unsigned char **rowData) +{ + // Add a single row + + if (TIFFWriteScanline(f, *rowData, curRow, 0) < 0) { + fprintf(stderr, "TiffWriter: Error writing tiff row %d\n", curRow); + return false; + } + + curRow++; + + return true; +} + +bool TiffWriter::close() +{ + // Close the file + + TIFFClose(f); + + return true; +} + +#endif --- poppler-git-28dec10-tiff/goo/TiffWriter.h- 2010-12-28 15:12:37.243550685 +0100 +++ poppler-git-28dec10-tiff/goo/TiffWriter.h 2010-12-28 15:19:47.201699685 +0100 @@ -0,0 +1,53 @@ +//======================================================================== +// +// TiffWriter.h +// +// This file is licensed under the GPLv2 or later +// +// Copyright (C) 2010 William Bader +// +//======================================================================== + +#ifndef TIFFWRITER_H +#define TIFFWRITER_H + +#include + +#ifdef ENABLE_LIBTIFF + +#include +#include "ImgWriter.h" +#include "splash/SplashTypes.h" + +extern "C" { +#include "tiffio.h" +} + +class TiffWriter : public ImgWriter +{ + public: + TiffWriter(); + ~TiffWriter(); + + void setCompressionStr(const char *compressionStr); + void setSplashMode(enum SplashColorMode splashModeArg); + + bool init(FILE *openedFile, int width, int height, int hDPI, int vDPI); + + bool writePointers(unsigned char **rowPointers, int rowCount); + bool writeRow(unsigned char **rowData); + + bool close(); + + private: + TIFF *f; // LibTiff file context + int numRows; // number of rows in the image + int curRow; // number of rows written + const char *compressionStr; // compression type + enum SplashColorMode splashMode; // format of image data + +}; + +#endif + +#endif --- poppler-git-28dec10-tiff/poppler/Makefile.am- 2010-12-28 15:11:14.345526819 +0100 +++ poppler-git-28dec10-tiff/poppler/Makefile.am 2010-12-28 15:12:37.244550712 +0100 @@ -73,6 +73,15 @@ endif +if BUILD_LIBTIFF + +libtiff_libs = \ + $(LIBTIFF_LIBS) +libtiff_includes = \ + $(LIBTIFF_CFLAGS) + +endif + if BUILD_LIBOPENJPEG libjpeg2000_sources = \ @@ -147,6 +156,7 @@ $(cairo_includes) \ $(arthur_includes) \ $(abiword_includes) \ + $(libtiff_includes) \ $(libpng_includes) \ $(libcurl_includes) \ $(FREETYPE_CFLAGS) \ @@ -165,6 +175,7 @@ $(top_builddir)/fofi/libfofi.la \ $(cms_libs) \ $(splash_libs) \ + $(libtiff_libs) \ $(libjpeg_libs) \ $(libpng_libs) \ $(zlib_libs) \ --- poppler-git-28dec10-tiff/splash/SplashBitmap.cc- 2010-12-28 15:11:14.369526825 +0100 +++ poppler-git-28dec10-tiff/splash/SplashBitmap.cc 2010-12-28 15:12:37.245550737 +0100 @@ -39,6 +39,7 @@ #include "poppler/Error.h" #include "goo/JpegWriter.h" #include "goo/PNGWriter.h" +#include "goo/TiffWriter.h" #include "goo/ImgWriter.h" //------------------------------------------------------------------------ @@ -274,7 +275,7 @@ return alpha[y * width + x]; } -SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, char *fileName, int hDPI, int vDPI) { +SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, char *fileName, int hDPI, int vDPI, const char *compressionStr) { FILE *f; SplashError e; @@ -282,13 +283,13 @@ return splashErrOpenFile; } - e = writeImgFile(format, f, hDPI, vDPI); + e = writeImgFile(format, f, hDPI, vDPI, compressionStr); fclose(f); return e; } -SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI) { +SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI, const char *compressionStr) { ImgWriter *writer; SplashError e; @@ -305,6 +306,16 @@ break; #endif + #ifdef ENABLE_LIBTIFF + case splashFormatTiff: + writer = new TiffWriter(); + if (writer) { + ((TiffWriter *)writer)->setCompressionStr(compressionStr); + ((TiffWriter *)writer)->setSplashMode(mode); + } + break; + #endif + default: // Not the greatest error message, but users of this function should // have already checked whether their desired format is compiled in. --- poppler-git-28dec10-tiff/splash/SplashBitmap.h- 2010-12-28 15:11:14.369526825 +0100 +++ poppler-git-28dec10-tiff/splash/SplashBitmap.h 2010-12-28 15:12:37.245550737 +0100 @@ -65,8 +65,8 @@ SplashError writePNMFile(char *fileName); SplashError writePNMFile(FILE *f); - SplashError writeImgFile(SplashImageFileFormat format, char *fileName, int hDPI, int vDPI); - SplashError writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI); + SplashError writeImgFile(SplashImageFileFormat format, char *fileName, int hDPI, int vDPI, const char *compressionStr); + SplashError writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI, const char *compressionStr); SplashError writeImgFile(ImgWriter *writer, FILE *f, int hDPI, int vDPI); void getPixel(int x, int y, SplashColorPtr pixel); --- poppler-git-28dec10-tiff/splash/SplashTypes.h- 2010-12-28 15:11:14.372526826 +0100 +++ poppler-git-28dec10-tiff/splash/SplashTypes.h 2010-12-28 15:12:37.246550760 +0100 @@ -160,7 +160,8 @@ enum SplashImageFileFormat { splashFormatJpeg, - splashFormatPng + splashFormatPng, + splashFormatTiff }; #endif --- poppler-git-28dec10-tiff/utils/Makefile.am- 2010-12-28 15:11:14.375526826 +0100 +++ poppler-git-28dec10-tiff/utils/Makefile.am 2010-12-28 15:12:37.246550760 +0100 @@ -22,6 +22,7 @@ LDADD = \ $(top_builddir)/poppler/libpoppler.la \ $(UTILS_LIBS) \ + $(LIBTIFF_LIBS) \ $(FONTCONFIG_LIBS) if BUILD_ABIWORD_OUTPUT --- poppler-git-28dec10-tiff/utils/pdftohtml.cc- 2010-12-28 15:11:14.000000000 +0100 +++ poppler-git-28dec10-tiff/utils/pdftohtml.cc 2010-12-28 15:13:29.374567329 +0100 @@ -430,7 +430,7 @@ htmlFileName->getCString(), pg, extension); bitmap->writeImgFile(format, imgFileName->getCString(), - 72 * scale, 72 * scale); + 72 * scale, 72 * scale, ""); delete imgFileName; } --- poppler-git-28dec10-tiff/utils/pdftoppm.1- 2010-12-28 15:11:14.375526827 +0100 +++ poppler-git-28dec10-tiff/utils/pdftoppm.1 2010-12-28 15:12:37.249550820 +0100 @@ -86,6 +86,12 @@ .B \-jpeg Generates a JPEG file instead a PPM file. .TP +.B \-tiff +Generates a TIFF file instead a PPM file. +.TP +.BI \-tiffcompression " none | packbits | jpeg | lzw | deflate" +Specifies the TIFF compression type. This defaults to "none". +.TP .BI \-freetype " yes | no" Enable or disable FreeType (a TrueType / Type 1 font rasterizer). This defaults to "yes". --- poppler-git-28dec10-tiff/utils/pdftoppm.cc- 2010-12-28 15:11:14.375526827 +0100 +++ poppler-git-28dec10-tiff/utils/pdftoppm.cc 2010-12-28 15:15:35.600606181 +0100 @@ -71,11 +71,13 @@ static GBool gray = gFalse; static GBool png = gFalse; static GBool jpeg = gFalse; +static GBool tiff = gFalse; static char enableFreeTypeStr[16] = ""; static char antialiasStr[16] = ""; static char vectorAntialiasStr[16] = ""; static char ownerPassword[33] = ""; static char userPassword[33] = ""; +static char TiffCompressionStr[16] = ""; static GBool quiet = gFalse; static GBool printVersion = gFalse; static GBool printHelp = gFalse; @@ -130,6 +132,12 @@ {"-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 HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H {"-freetype", argString, enableFreeTypeStr, sizeof(enableFreeTypeStr), "enable FreeType font rasterizer: yes, no"}, @@ -180,9 +188,13 @@ if (ppmFile != NULL) { if (png) { - bitmap->writeImgFile(splashFormatPng, ppmFile, x_resolution, y_resolution); + bitmap->writeImgFile(splashFormatPng, ppmFile, x_resolution, y_resolution, ""); } else if (jpeg) { - bitmap->writeImgFile(splashFormatJpeg, ppmFile, x_resolution, y_resolution); + bitmap->writeImgFile(splashFormatJpeg, ppmFile, x_resolution, y_resolution, ""); +#if ENABLE_LIBTIFF + } else if (tiff) { + bitmap->writeImgFile(splashFormatTiff, ppmFile, x_resolution, y_resolution, TiffCompressionStr); +#endif } else { bitmap->writePNMFile(ppmFile); } @@ -192,9 +204,13 @@ #endif if (png) { - bitmap->writeImgFile(splashFormatPng, stdout, x_resolution, y_resolution); + bitmap->writeImgFile(splashFormatPng, stdout, x_resolution, y_resolution, ""); } else if (jpeg) { - bitmap->writeImgFile(splashFormatJpeg, stdout, x_resolution, y_resolution); + bitmap->writeImgFile(splashFormatJpeg, stdout, x_resolution, y_resolution, ""); +#if ENABLE_LIBTIFF + } else if (tiff) { + bitmap->writeImgFile(splashFormatTiff, stdout, x_resolution, y_resolution, TiffCompressionStr); +#endif } else { bitmap->writePNMFile(stdout); } @@ -365,7 +381,7 @@ pg_h = tmp; } if (ppmRoot != NULL) { - const char *ext = png ? "png" : jpeg ? "jpg" : mono ? "pbm" : gray ? "pgm" : "ppm"; + const char *ext = png ? "png" : jpeg ? "jpg" : tiff ? "tif" : mono ? "pbm" : gray ? "pgm" : "ppm"; if (singleFile) { snprintf(ppmFile, PPM_FILE_SZ, "%.*s.%s", PPM_FILE_SZ - 32, ppmRoot, ext);