diff options
author | Adrian Johnson <ajohnson@redneon.com> | 2012-12-02 09:10:32 +1030 |
---|---|---|
committer | Adrian Johnson <ajohnson@redneon.com> | 2012-12-09 09:00:18 +1030 |
commit | e78dbb1b7dbd20c3ae547b02270ab0648c1bfc61 (patch) | |
tree | 054e828e6a4fa80f5c2cb85c4458a858afa7f063 /goo | |
parent | 1bfe4b22cf893dd498d6f306ee9cf942c72fe3ed (diff) |
Reformat goo/*Writer files to poppler style
Diffstat (limited to 'goo')
-rw-r--r-- | goo/ImgWriter.h | 20 | ||||
-rw-r--r-- | goo/JpegWriter.cc | 184 | ||||
-rw-r--r-- | goo/JpegWriter.h | 38 | ||||
-rw-r--r-- | goo/PNGWriter.cc | 224 | ||||
-rw-r--r-- | goo/PNGWriter.h | 62 | ||||
-rw-r--r-- | goo/TiffWriter.cc | 40 | ||||
-rw-r--r-- | goo/TiffWriter.h | 58 |
7 files changed, 313 insertions, 313 deletions
diff --git a/goo/ImgWriter.h b/goo/ImgWriter.h index 185c230e..8feb3511 100644 --- a/goo/ImgWriter.h +++ b/goo/ImgWriter.h @@ -16,18 +16,18 @@ #define IMGWRITER_H #include <stdio.h> - + class ImgWriter { - public: - virtual ~ImgWriter(); - virtual bool init(FILE *f, int width, int height, int hDPI, int vDPI) = 0; - - virtual bool writePointers(unsigned char **rowPointers, int rowCount) = 0; - virtual bool writeRow(unsigned char **row) = 0; - - virtual bool close() = 0; - virtual bool supportCMYK() { return false; } +public: + virtual ~ImgWriter(); + virtual bool init(FILE *f, int width, int height, int hDPI, int vDPI) = 0; + + virtual bool writePointers(unsigned char **rowPointers, int rowCount) = 0; + virtual bool writeRow(unsigned char **row) = 0; + + virtual bool close() = 0; + virtual bool supportCMYK() { return false; } }; #endif diff --git a/goo/JpegWriter.cc b/goo/JpegWriter.cc index 2fe3d327..fc9557f4 100644 --- a/goo/JpegWriter.cc +++ b/goo/JpegWriter.cc @@ -19,129 +19,129 @@ void outputMessage(j_common_ptr cinfo) { - char buffer[JMSG_LENGTH_MAX]; + char buffer[JMSG_LENGTH_MAX]; - // Create the message - (*cinfo->err->format_message) (cinfo, buffer); + // Create the message + (*cinfo->err->format_message) (cinfo, buffer); - // Send it to poppler's error handler - error(errInternal, -1, "{0:s}", buffer); + // Send it to poppler's error handler + error(errInternal, -1, "{0:s}", buffer); } JpegWriter::JpegWriter(int q, bool p, J_COLOR_SPACE cm) -: progressive(p), quality(q), colorMode(cm) + : progressive(p), quality(q), colorMode(cm) { } JpegWriter::JpegWriter(J_COLOR_SPACE cm) -: progressive(false), quality(-1), colorMode(cm) + : progressive(false), quality(-1), colorMode(cm) { } JpegWriter::~JpegWriter() { - // cleanup - jpeg_destroy_compress(&cinfo); + // cleanup + jpeg_destroy_compress(&cinfo); } 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; - - // Initialize libjpeg - jpeg_create_compress(&cinfo); - - // Set colorspace and initialise defaults - cinfo.in_color_space = colorMode; /* colorspace of input image */ - jpeg_set_defaults(&cinfo); - - // Set destination file - jpeg_stdio_dest(&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; - break; - case JCS_RGB: - cinfo.input_components = 3; - break; - case JCS_CMYK: - cinfo.input_components = 4; - 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); - } - - // Use progressive mode - if( progressive) { - jpeg_simple_progression(&cinfo); - } - - // Get ready for data - jpeg_start_compress(&cinfo, TRUE); - - return true; + // Setup error handler + cinfo.err = jpeg_std_error(&jerr); + 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); + + // Set destination file + jpeg_stdio_dest(&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; + break; + case JCS_RGB: + cinfo.input_components = 3; + break; + case JCS_CMYK: + cinfo.input_components = 4; + 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); + } + + // Use progressive mode + if( progressive) { + jpeg_simple_progression(&cinfo); + } + + // Get ready for data + jpeg_start_compress(&cinfo, TRUE); + + return true; } bool JpegWriter::writePointers(unsigned char **rowPointers, int rowCount) { - if (colorMode == JCS_CMYK) { - for (int y = 0; y < rowCount; y++) { - unsigned char *row = rowPointers[y]; - for (unsigned int x = 0; x < cinfo.image_width; x++) { - for (int n = 0; n < 4; n++) { - *row = 0xff - *row; - row++; - } - } - } + if (colorMode == JCS_CMYK) { + for (int y = 0; y < rowCount; y++) { + unsigned char *row = rowPointers[y]; + for (unsigned int x = 0; x < cinfo.image_width; x++) { + for (int n = 0; n < 4; n++) { + *row = 0xff - *row; + row++; } - // Write all rows to the file - jpeg_write_scanlines(&cinfo, rowPointers, rowCount); - - return true; + } + } + } + // Write all rows to the file + jpeg_write_scanlines(&cinfo, rowPointers, rowCount); + + return true; } bool JpegWriter::writeRow(unsigned char **rowPointer) { - if (colorMode == JCS_CMYK) { - unsigned char *row = rowPointer[0]; - for (unsigned int x = 0; x < cinfo.image_width; x++) { - for (int n = 0; n < 4; n++) { - *row = 0xff - *row; - row++; - } - } - } - // Write the row to the file - jpeg_write_scanlines(&cinfo, rowPointer, 1); - - return true; + if (colorMode == JCS_CMYK) { + unsigned char *row = rowPointer[0]; + for (unsigned int x = 0; x < cinfo.image_width; x++) { + for (int n = 0; n < 4; n++) { + *row = 0xff - *row; + row++; + } + } + } + // Write the row to the file + jpeg_write_scanlines(&cinfo, rowPointer, 1); + + return true; } bool JpegWriter::close() { - jpeg_finish_compress(&cinfo); - - return true; + jpeg_finish_compress(&cinfo); + + return true; } #endif diff --git a/goo/JpegWriter.h b/goo/JpegWriter.h index d076224e..d451bf33 100644 --- a/goo/JpegWriter.h +++ b/goo/JpegWriter.h @@ -30,25 +30,25 @@ extern "C" { class JpegWriter : public ImgWriter { - public: - JpegWriter(int quality, bool progressive, J_COLOR_SPACE colorMode = JCS_RGB); - JpegWriter(J_COLOR_SPACE colorMode = JCS_RGB); - ~JpegWriter(); - - bool init(FILE *f, int width, int height, int hDPI, int vDPI); - - bool writePointers(unsigned char **rowPointers, int rowCount); - bool writeRow(unsigned char **row); - - bool close(); - bool supportCMYK() { return colorMode == JCS_CMYK; } - - private: - bool progressive; - int quality; - J_COLOR_SPACE colorMode; - struct jpeg_compress_struct cinfo; - struct jpeg_error_mgr jerr; +public: + JpegWriter(int quality, bool progressive, J_COLOR_SPACE colorMode = JCS_RGB); + JpegWriter(J_COLOR_SPACE colorMode = JCS_RGB); + ~JpegWriter(); + + bool init(FILE *f, int width, int height, int hDPI, int vDPI); + + bool writePointers(unsigned char **rowPointers, int rowCount); + bool writeRow(unsigned char **row); + + bool close(); + bool supportCMYK() { return colorMode == JCS_CMYK; } + +private: + bool progressive; + int quality; + J_COLOR_SPACE colorMode; + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; }; #endif diff --git a/goo/PNGWriter.cc b/goo/PNGWriter.cc index fe8b79ed..63ef7c7d 100644 --- a/goo/PNGWriter.cc +++ b/goo/PNGWriter.cc @@ -26,151 +26,151 @@ PNGWriter::PNGWriter(Format formatA) : format(formatA) { - icc_data = NULL; - icc_data_size = 0; - icc_name = NULL; - sRGB_profile = false; + icc_data = NULL; + icc_data_size = 0; + icc_name = NULL; + sRGB_profile = false; } PNGWriter::~PNGWriter() { - /* cleanup heap allocation */ - png_destroy_write_struct(&png_ptr, &info_ptr); - if (icc_data) { - gfree(icc_data); - free(icc_name); - } + /* cleanup heap allocation */ + png_destroy_write_struct(&png_ptr, &info_ptr); + if (icc_data) { + gfree(icc_data); + free(icc_name); + } } void PNGWriter::setICCProfile(const char *name, unsigned char *data, int size) { - icc_data = (unsigned char *)gmalloc(size); - memcpy(icc_data, data, size); - icc_data_size = size; - icc_name = strdup(name); + icc_data = (unsigned char *)gmalloc(size); + memcpy(icc_data, data, size); + icc_data_size = size; + icc_name = strdup(name); } void PNGWriter::setSRGBProfile() { - sRGB_profile = true; + sRGB_profile = true; } bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI) { /* libpng changed the png_set_iCCP() prototype in 1.5.0 */ #if PNG_LIBPNG_VER < 10500 - png_charp icc_data_ptr = (png_charp)icc_data; + png_charp icc_data_ptr = (png_charp)icc_data; #else - png_const_bytep icc_data_ptr = (png_const_bytep)icc_data; + png_const_bytep icc_data_ptr = (png_const_bytep)icc_data; #endif - /* initialize stuff */ - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png_ptr) { - error(errInternal, -1, "png_create_write_struct failed"); - return false; - } - - info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) { - error(errInternal, -1, "png_create_info_struct failed"); - return false; - } - - if (setjmp(png_jmpbuf(png_ptr))) { - error(errInternal, -1, "png_jmpbuf failed"); - return false; - } - - /* write header */ - png_init_io(png_ptr, f); - if (setjmp(png_jmpbuf(png_ptr))) { - error(errInternal, -1, "Error during writing header"); - return false; - } - - // Set up the type of PNG image and the compression level - png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); - - // Silence silly gcc - png_byte bit_depth = -1; - png_byte color_type = -1; - switch (format) { - case RGB: - bit_depth = 8; - color_type = PNG_COLOR_TYPE_RGB; - break; - case RGBA: - bit_depth = 8; - color_type = PNG_COLOR_TYPE_RGB_ALPHA; - break; - case GRAY: - bit_depth = 8; - color_type = PNG_COLOR_TYPE_GRAY; - break; - case MONOCHROME: - bit_depth = 1; - color_type = PNG_COLOR_TYPE_GRAY; - break; - } - png_byte interlace_type = PNG_INTERLACE_NONE; - - png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, interlace_type, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - - png_set_pHYs(png_ptr, info_ptr, hDPI/0.0254, vDPI/0.0254, PNG_RESOLUTION_METER); - - if (icc_data) - png_set_iCCP(png_ptr, info_ptr, icc_name, PNG_COMPRESSION_TYPE_BASE, icc_data_ptr, icc_data_size); - else if (sRGB_profile) - png_set_sRGB(png_ptr, info_ptr, PNG_sRGB_INTENT_RELATIVE); - - png_write_info(png_ptr, info_ptr); - if (setjmp(png_jmpbuf(png_ptr))) { - error(errInternal, -1, "error during writing png info bytes"); - return false; - } - - // pack 1 pixel/byte rows into 8 pixels/byte - if (format == MONOCHROME) - png_set_packing(png_ptr); - - return true; + /* initialize stuff */ + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) { + error(errInternal, -1, "png_create_write_struct failed"); + return false; + } + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + error(errInternal, -1, "png_create_info_struct failed"); + return false; + } + + if (setjmp(png_jmpbuf(png_ptr))) { + error(errInternal, -1, "png_jmpbuf failed"); + return false; + } + + /* write header */ + png_init_io(png_ptr, f); + if (setjmp(png_jmpbuf(png_ptr))) { + error(errInternal, -1, "Error during writing header"); + return false; + } + + // Set up the type of PNG image and the compression level + png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); + + // Silence silly gcc + png_byte bit_depth = -1; + png_byte color_type = -1; + switch (format) { + case RGB: + bit_depth = 8; + color_type = PNG_COLOR_TYPE_RGB; + break; + case RGBA: + bit_depth = 8; + color_type = PNG_COLOR_TYPE_RGB_ALPHA; + break; + case GRAY: + bit_depth = 8; + color_type = PNG_COLOR_TYPE_GRAY; + break; + case MONOCHROME: + bit_depth = 1; + color_type = PNG_COLOR_TYPE_GRAY; + break; + } + png_byte interlace_type = PNG_INTERLACE_NONE; + + png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, interlace_type, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + + png_set_pHYs(png_ptr, info_ptr, hDPI/0.0254, vDPI/0.0254, PNG_RESOLUTION_METER); + + if (icc_data) + png_set_iCCP(png_ptr, info_ptr, icc_name, PNG_COMPRESSION_TYPE_BASE, icc_data_ptr, icc_data_size); + else if (sRGB_profile) + png_set_sRGB(png_ptr, info_ptr, PNG_sRGB_INTENT_RELATIVE); + + png_write_info(png_ptr, info_ptr); + if (setjmp(png_jmpbuf(png_ptr))) { + error(errInternal, -1, "error during writing png info bytes"); + return false; + } + + // pack 1 pixel/byte rows into 8 pixels/byte + if (format == MONOCHROME) + png_set_packing(png_ptr); + + return true; } bool PNGWriter::writePointers(unsigned char **rowPointers, int rowCount) { - png_write_image(png_ptr, rowPointers); - /* write bytes */ - if (setjmp(png_jmpbuf(png_ptr))) { - error(errInternal, -1, "Error during writing bytes"); - return false; - } - - return true; + png_write_image(png_ptr, rowPointers); + /* write bytes */ + if (setjmp(png_jmpbuf(png_ptr))) { + error(errInternal, -1, "Error during writing bytes"); + return false; + } + + return true; } bool PNGWriter::writeRow(unsigned char **row) { - // Write the row to the file - png_write_rows(png_ptr, row, 1); - if (setjmp(png_jmpbuf(png_ptr))) { - error(errInternal, -1, "error during png row write"); - return false; - } - - return true; + // Write the row to the file + png_write_rows(png_ptr, row, 1); + if (setjmp(png_jmpbuf(png_ptr))) { + error(errInternal, -1, "error during png row write"); + return false; + } + + return true; } bool PNGWriter::close() { - /* end write */ - png_write_end(png_ptr, info_ptr); - if (setjmp(png_jmpbuf(png_ptr))) { - error(errInternal, -1, "Error during end of write"); - return false; - } - - return true; + /* end write */ + png_write_end(png_ptr, info_ptr); + if (setjmp(png_jmpbuf(png_ptr))) { + error(errInternal, -1, "Error during end of write"); + return false; + } + + return true; } #endif diff --git a/goo/PNGWriter.h b/goo/PNGWriter.h index 9e412b4e..37df4273 100644 --- a/goo/PNGWriter.h +++ b/goo/PNGWriter.h @@ -25,37 +25,37 @@ class PNGWriter : public ImgWriter { - public: - - /* RGB - 3 bytes/pixel - * RGBA - 4 bytes/pixel - * GRAY - 1 byte/pixel - * MONOCHROME - 1 byte/pixel. PNGWriter will bitpack to 8 pixels/byte - */ - enum Format { RGB, RGBA, GRAY, MONOCHROME }; - - PNGWriter(Format format = RGB); - ~PNGWriter(); - - void setICCProfile(const char *name, unsigned char *data, int size); - void setSRGBProfile(); - - - bool init(FILE *f, int width, int height, int hDPI, int vDPI); - - bool writePointers(unsigned char **rowPointers, int rowCount); - bool writeRow(unsigned char **row); - - bool close(); - - private: - Format format; - png_structp png_ptr; - png_infop info_ptr; - unsigned char *icc_data; - int icc_data_size; - char *icc_name; - bool sRGB_profile; +public: + + /* RGB - 3 bytes/pixel + * RGBA - 4 bytes/pixel + * GRAY - 1 byte/pixel + * MONOCHROME - 1 byte/pixel. PNGWriter will bitpack to 8 pixels/byte + */ + enum Format { RGB, RGBA, GRAY, MONOCHROME }; + + PNGWriter(Format format = RGB); + ~PNGWriter(); + + void setICCProfile(const char *name, unsigned char *data, int size); + void setSRGBProfile(); + + + bool init(FILE *f, int width, int height, int hDPI, int vDPI); + + bool writePointers(unsigned char **rowPointers, int rowCount); + bool writeRow(unsigned char **row); + + bool close(); + +private: + Format format; + png_structp png_ptr; + png_infop info_ptr; + unsigned char *icc_data; + int icc_data_size; + char *icc_name; + bool sRGB_profile; }; #endif diff --git a/goo/TiffWriter.cc b/goo/TiffWriter.cc index 027cd9c6..048cea84 100644 --- a/goo/TiffWriter.cc +++ b/goo/TiffWriter.cc @@ -107,26 +107,26 @@ bool TiffWriter::init(FILE *openedFile, int width, int height, int hDPI, int vDP bitspersample = (format == MONOCHROME ? 1 : 8); switch (format) { - case MONOCHROME: - case GRAY: - samplesperpixel = 1; - photometric = PHOTOMETRIC_MINISBLACK; - break; - - case RGB: - samplesperpixel = 3; - photometric = PHOTOMETRIC_RGB; - break; - - case RGBA_PREMULTIPLIED: - samplesperpixel = 4; - photometric = PHOTOMETRIC_RGB; - break; - - case CMYK: - samplesperpixel = 4; - photometric = PHOTOMETRIC_SEPARATED; - break; + case MONOCHROME: + case GRAY: + samplesperpixel = 1; + photometric = PHOTOMETRIC_MINISBLACK; + break; + + case RGB: + samplesperpixel = 3; + photometric = PHOTOMETRIC_RGB; + break; + + case RGBA_PREMULTIPLIED: + samplesperpixel = 4; + photometric = PHOTOMETRIC_RGB; + break; + + case CMYK: + samplesperpixel = 4; + photometric = PHOTOMETRIC_SEPARATED; + break; } // Open the file diff --git a/goo/TiffWriter.h b/goo/TiffWriter.h index 26d0b761..0265c07b 100644 --- a/goo/TiffWriter.h +++ b/goo/TiffWriter.h @@ -27,35 +27,35 @@ extern "C" { class TiffWriter : public ImgWriter { - public: - /* RGB - 3 bytes/pixel - * RGBA_PREMULTIPLIED - 4 bytes/pixel premultiplied by alpha - * GRAY - 1 byte/pixel - * MONOCHROME - 8 pixels/byte - * CMYK - 4 bytes/pixel - */ - enum Format { RGB, RGBA_PREMULTIPLIED, GRAY, MONOCHROME, CMYK }; - - TiffWriter(Format format = RGB); - ~TiffWriter(); - - void setCompressionString(const char *compressionStringArg); - - 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 supportCMYK() { return true; } - - bool close(); - - private: - TIFF *f; // LibTiff file context - int numRows; // number of rows in the image - int curRow; // number of rows written - const char *compressionString; // compression type - Format format; // format of image data +public: + /* RGB - 3 bytes/pixel + * RGBA_PREMULTIPLIED - 4 bytes/pixel premultiplied by alpha + * GRAY - 1 byte/pixel + * MONOCHROME - 8 pixels/byte + * CMYK - 4 bytes/pixel + */ + enum Format { RGB, RGBA_PREMULTIPLIED, GRAY, MONOCHROME, CMYK }; + + TiffWriter(Format format = RGB); + ~TiffWriter(); + + void setCompressionString(const char *compressionStringArg); + + 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 supportCMYK() { return true; } + + bool close(); + +private: + TIFF *f; // LibTiff file context + int numRows; // number of rows in the image + int curRow; // number of rows written + const char *compressionString; // compression type + Format format; // format of image data }; |