Created
August 19, 2013 10:31
-
-
Save mtyaka/6267779 to your computer and use it in GitHub Desktop.
Patches poppler's pdftocairo to be able to set zlib compression level when generating png files. Tested with pdftocairo 0.22.5.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/goo/PNGWriter.cc b/goo/PNGWriter.cc | |
index b775600..d484991 100644 | |
--- a/goo/PNGWriter.cc | |
+++ b/goo/PNGWriter.cc | |
@@ -35,8 +35,20 @@ struct PNGWriterPrivate { | |
int icc_data_size; | |
char *icc_name; | |
bool sRGB_profile; | |
+ int zlib_compression_level; | |
}; | |
+PNGWriter::PNGWriter(int zlib_compression_level, Format formatA) | |
+{ | |
+ priv = new PNGWriterPrivate; | |
+ priv->format = formatA; | |
+ priv->icc_data = NULL; | |
+ priv->icc_data_size = 0; | |
+ priv->icc_name = NULL; | |
+ priv->sRGB_profile = false; | |
+ priv->zlib_compression_level = zlib_compression_level; | |
+} | |
+ | |
PNGWriter::PNGWriter(Format formatA) | |
{ | |
priv = new PNGWriterPrivate; | |
@@ -45,6 +57,7 @@ PNGWriter::PNGWriter(Format formatA) | |
priv->icc_data_size = 0; | |
priv->icc_name = NULL; | |
priv->sRGB_profile = false; | |
+ priv->zlib_compression_level = Z_BEST_COMPRESSION; | |
} | |
PNGWriter::~PNGWriter() | |
@@ -107,7 +120,7 @@ bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI) | |
} | |
// Set up the type of PNG image and the compression level | |
- png_set_compression_level(priv->png_ptr, Z_BEST_COMPRESSION); | |
+ png_set_compression_level(priv->png_ptr, priv->zlib_compression_level); | |
// Silence silly gcc | |
png_byte bit_depth = -1; | |
diff --git a/goo/PNGWriter.h b/goo/PNGWriter.h | |
index c73c964..9bfcdd2 100644 | |
--- a/goo/PNGWriter.h | |
+++ b/goo/PNGWriter.h | |
@@ -35,6 +35,7 @@ public: | |
*/ | |
enum Format { RGB, RGBA, GRAY, MONOCHROME }; | |
+ PNGWriter(int compression_level, Format format = RGB); | |
PNGWriter(Format format = RGB); | |
~PNGWriter(); | |
diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc | |
index 2fa0af7..24faab3 100644 | |
--- a/utils/pdftocairo.cc | |
+++ b/utils/pdftocairo.cc | |
@@ -100,6 +100,7 @@ static GBool gray = gFalse; | |
static GBool transp = gFalse; | |
static GooString icc; | |
static int jpegQuality = -1; | |
+static int pngCompression = 9; | |
static GBool level2 = gFalse; | |
static GBool level3 = gFalse; | |
@@ -124,6 +125,8 @@ static const ArgDesc argDesc[] = { | |
#if ENABLE_LIBPNG | |
{"-png", argFlag, &png, 0, | |
"generate a PNG file"}, | |
+ {"-pngcompression", argInt, &pngCompression, 0, | |
+ "zlib compression level to use when generating PNG files (0 - 9)"}, | |
#endif | |
#if ENABLE_LIBJPEG | |
{"-jpeg", argFlag, &jpeg, 0, | |
@@ -265,13 +268,13 @@ void writePageImage(GooString *filename) | |
if (png) { | |
#if ENABLE_LIBPNG | |
if (transp) | |
- writer = new PNGWriter(PNGWriter::RGBA); | |
+ writer = new PNGWriter(pngCompression, PNGWriter::RGBA); | |
else if (gray) | |
- writer = new PNGWriter(PNGWriter::GRAY); | |
+ writer = new PNGWriter(pngCompression, PNGWriter::GRAY); | |
else if (mono) | |
- writer = new PNGWriter(PNGWriter::MONOCHROME); | |
+ writer = new PNGWriter(pngCompression, PNGWriter::MONOCHROME); | |
else | |
- writer = new PNGWriter(PNGWriter::RGB); | |
+ writer = new PNGWriter(pngCompression, PNGWriter::RGB); | |
#if USE_CMS | |
#ifdef USE_LCMS1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment