summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Johnson <ajohnson@redneon.com>2012-12-02 09:34:35 +1030
committerAdrian Johnson <ajohnson@redneon.com>2012-12-09 09:00:19 +1030
commitf6741d9242bf2d9c13c8d534c50c8e4d404afc7f (patch)
treeb3fd669d18ea3f9a93faabd32129eed271177ee0
parente78dbb1b7dbd20c3ae547b02270ab0648c1bfc61 (diff)
jpegwriter: move #include "jpeglib.h" into .cc file
On cygwin pdftocairo -v shows the wrong version due to jpeglib.h defining PACKAGE_VERSION. Avoid polluting our header files by moving libjpeg.h and libjpeg types into JpegWriter.cc Bug 57687
-rw-r--r--goo/JpegWriter.cc120
-rw-r--r--goo/JpegWriter.h25
-rw-r--r--splash/SplashBitmap.cc2
-rw-r--r--utils/pdftocairo.cc4
4 files changed, 95 insertions, 56 deletions
diff --git a/goo/JpegWriter.cc b/goo/JpegWriter.cc
index fc9557f4..09f9b7b6 100644
--- a/goo/JpegWriter.cc
+++ b/goo/JpegWriter.cc
@@ -15,8 +15,20 @@
#ifdef ENABLE_LIBJPEG
+extern "C" {
+#include <jpeglib.h>
+}
+
#include "poppler/Error.h"
+struct JpegWriterPrivate {
+ bool progressive;
+ int quality;
+ JpegWriter::Format format;
+ struct jpeg_compress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+};
+
void outputMessage(j_common_ptr cinfo)
{
char buffer[JMSG_LENGTH_MAX];
@@ -28,85 +40,103 @@ void outputMessage(j_common_ptr cinfo)
error(errInternal, -1, "{0:s}", buffer);
}
-JpegWriter::JpegWriter(int q, bool p, J_COLOR_SPACE cm)
- : progressive(p), quality(q), colorMode(cm)
+JpegWriter::JpegWriter(int q, bool p, Format formatA)
{
+ priv = new JpegWriterPrivate;
+ priv->progressive = p;
+ priv->quality = q;
+ priv->format = formatA;
}
-JpegWriter::JpegWriter(J_COLOR_SPACE cm)
- : progressive(false), quality(-1), colorMode(cm)
+JpegWriter::JpegWriter(Format formatA)
{
+ priv = new JpegWriterPrivate;
+ priv->progressive = false;
+ priv->quality = -1;
+ priv->format = formatA;
}
JpegWriter::~JpegWriter()
{
// cleanup
- jpeg_destroy_compress(&cinfo);
+ jpeg_destroy_compress(&priv->cinfo);
+ delete priv;
}
bool JpegWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
{
// Setup error handler
- cinfo.err = jpeg_std_error(&jerr);
- jerr.output_message = &outputMessage;
+ priv->cinfo.err = jpeg_std_error(&priv->jerr);
+ priv->jerr.output_message = &outputMessage;
// Initialize libjpeg
- jpeg_create_compress(&cinfo);
-
- // Set colorspace and initialise defaults
- cinfo.in_color_space = colorMode; /* colorspace of input image */
- jpeg_set_defaults(&cinfo);
+ jpeg_create_compress(&priv->cinfo);
+
+ // First set colorspace and call jpeg_set_defaults() since
+ // jpeg_set_defaults() sets default values for all fields in
+ // cinfo based on the colorspace.
+ switch (priv->format) {
+ case RGB:
+ priv->cinfo.in_color_space = JCS_RGB;
+ break;
+ case GRAY:
+ priv->cinfo.in_color_space = JCS_GRAYSCALE;
+ break;
+ case CMYK:
+ priv->cinfo.in_color_space = JCS_CMYK;
+ break;
+ default:
+ return false;
+ }
+ jpeg_set_defaults(&priv->cinfo);
// Set destination file
- jpeg_stdio_dest(&cinfo, f);
+ jpeg_stdio_dest(&priv->cinfo, f);
// Set libjpeg configuration
- cinfo.image_width = width;
- cinfo.image_height = height;
- cinfo.density_unit = 1; // dots per inch
- cinfo.X_density = hDPI;
- cinfo.Y_density = vDPI;
- /* # of color components per pixel */
- switch (colorMode) {
- case JCS_GRAYSCALE:
- cinfo.input_components = 1;
+ priv->cinfo.image_width = width;
+ priv->cinfo.image_height = height;
+ priv->cinfo.density_unit = 1; // dots per inch
+ priv->cinfo.X_density = hDPI;
+ priv->cinfo.Y_density = vDPI;
+ switch (priv->format) {
+ case GRAY:
+ priv->cinfo.input_components = 1;
break;
- case JCS_RGB:
- cinfo.input_components = 3;
+ case RGB:
+ priv->cinfo.input_components = 3;
break;
- case JCS_CMYK:
- cinfo.input_components = 4;
+ case CMYK:
+ priv->cinfo.input_components = 4;
+ jpeg_set_colorspace(&priv->cinfo, JCS_YCCK);
+ priv->cinfo.write_JFIF_header = TRUE;
break;
default:
return false;
}
- if (cinfo.in_color_space == JCS_CMYK) {
- jpeg_set_colorspace(&cinfo, JCS_YCCK);
- cinfo.write_JFIF_header = TRUE;
- }
// Set quality
- if( quality >= 0 && quality <= 100 ) {
- jpeg_set_quality(&cinfo, quality, true);
+ if (priv->quality >= 0 && priv->quality <= 100) {
+ jpeg_set_quality(&priv->cinfo, priv->quality, true);
}
// Use progressive mode
- if( progressive) {
- jpeg_simple_progression(&cinfo);
+ if (priv->progressive) {
+ jpeg_simple_progression(&priv->cinfo);
}
// Get ready for data
- jpeg_start_compress(&cinfo, TRUE);
+ jpeg_start_compress(&priv->cinfo, TRUE);
return true;
}
bool JpegWriter::writePointers(unsigned char **rowPointers, int rowCount)
{
- if (colorMode == JCS_CMYK) {
+ if (priv->format == CMYK) {
for (int y = 0; y < rowCount; y++) {
unsigned char *row = rowPointers[y];
- for (unsigned int x = 0; x < cinfo.image_width; x++) {
+ for (unsigned int x = 0; x < priv->cinfo.image_width; x++) {
for (int n = 0; n < 4; n++) {
*row = 0xff - *row;
row++;
@@ -115,16 +145,16 @@ bool JpegWriter::writePointers(unsigned char **rowPointers, int rowCount)
}
}
// Write all rows to the file
- jpeg_write_scanlines(&cinfo, rowPointers, rowCount);
+ jpeg_write_scanlines(&priv->cinfo, rowPointers, rowCount);
return true;
}
bool JpegWriter::writeRow(unsigned char **rowPointer)
{
- if (colorMode == JCS_CMYK) {
+ if (priv->format == CMYK) {
unsigned char *row = rowPointer[0];
- for (unsigned int x = 0; x < cinfo.image_width; x++) {
+ for (unsigned int x = 0; x < priv->cinfo.image_width; x++) {
for (int n = 0; n < 4; n++) {
*row = 0xff - *row;
row++;
@@ -132,16 +162,22 @@ bool JpegWriter::writeRow(unsigned char **rowPointer)
}
}
// Write the row to the file
- jpeg_write_scanlines(&cinfo, rowPointer, 1);
+ jpeg_write_scanlines(&priv->cinfo, rowPointer, 1);
return true;
}
bool JpegWriter::close()
{
- jpeg_finish_compress(&cinfo);
+ jpeg_finish_compress(&priv->cinfo);
return true;
}
+bool JpegWriter::supportCMYK()
+{
+ return priv->format == CMYK;
+}
+
+
#endif
diff --git a/goo/JpegWriter.h b/goo/JpegWriter.h
index d451bf33..66b89597 100644
--- a/goo/JpegWriter.h
+++ b/goo/JpegWriter.h
@@ -24,15 +24,19 @@
#include <sys/types.h>
#include "ImgWriter.h"
-extern "C" {
-#include <jpeglib.h>
-}
+struct JpegWriterPrivate;
class JpegWriter : public ImgWriter
{
public:
- JpegWriter(int quality, bool progressive, J_COLOR_SPACE colorMode = JCS_RGB);
- JpegWriter(J_COLOR_SPACE colorMode = JCS_RGB);
+ /* RGB - 3 bytes/pixel
+ * GRAY - 1 byte/pixel
+ * CMYK - 4 bytes/pixel
+ */
+ enum Format { RGB, GRAY, CMYK };
+
+ JpegWriter(int quality, bool progressive, Format format = RGB);
+ JpegWriter(Format format = RGB);
~JpegWriter();
bool init(FILE *f, int width, int height, int hDPI, int vDPI);
@@ -41,14 +45,13 @@ public:
bool writeRow(unsigned char **row);
bool close();
- bool supportCMYK() { return colorMode == JCS_CMYK; }
+ bool supportCMYK();
private:
- bool progressive;
- int quality;
- J_COLOR_SPACE colorMode;
- struct jpeg_compress_struct cinfo;
- struct jpeg_error_mgr jerr;
+ JpegWriter(const JpegWriter &other);
+ JpegWriter& operator=(const JpegWriter &other);
+
+ JpegWriterPrivate *priv;
};
#endif
diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc
index ca1dee7b..93d2da8a 100644
--- a/splash/SplashBitmap.cc
+++ b/splash/SplashBitmap.cc
@@ -363,7 +363,7 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, in
#ifdef ENABLE_LIBJPEG
#ifdef SPLASH_CMYK
case splashFormatJpegCMYK:
- writer = new JpegWriter(JCS_CMYK);
+ writer = new JpegWriter(JpegWriter::CMYK);
break;
#endif
case splashFormatJpeg:
diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc
index 258d939c..192d2957 100644
--- a/utils/pdftocairo.cc
+++ b/utils/pdftocairo.cc
@@ -293,9 +293,9 @@ void writePageImage(GooString *filename)
} else if (jpeg) {
#if ENABLE_LIBJPEG
if (gray)
- writer = new JpegWriter(JCS_GRAYSCALE);
+ writer = new JpegWriter(JpegWriter::GRAY);
else
- writer = new JpegWriter(JCS_RGB);
+ writer = new JpegWriter(JpegWriter::RGB);
#endif
} else if (tiff) {
#if ENABLE_LIBTIFF