[PATCH 4/9] png: add support for embedding ICC profile
Adrian Johnson
ajohnson at redneon.com
Thu Aug 11 05:02:53 PDT 2011
---
goo/PNGWriter.cc | 28 ++++++++++++++++++++++++++++
goo/PNGWriter.h | 8 ++++++++
2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/goo/PNGWriter.cc b/goo/PNGWriter.cc
index 7883c56..1e78de5 100644
--- a/goo/PNGWriter.cc
+++ b/goo/PNGWriter.cc
@@ -18,17 +18,40 @@
#ifdef ENABLE_LIBPNG
#include <zlib.h>
+#include <stdlib.h>
#include "poppler/Error.h"
+#include "goo/gmem.h"
PNGWriter::PNGWriter(Format formatA) : format(formatA)
{
+ 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);
+ }
+}
+
+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);
+}
+
+void PNGWriter::setSRGBProfile()
+{
+ sRGB_profile = true;
}
bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
@@ -87,6 +110,11 @@ bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
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, (char*)icc_data, 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(-1, "error during writing png info bytes");
diff --git a/goo/PNGWriter.h b/goo/PNGWriter.h
index dc06e1c..ce4bbaa 100644
--- a/goo/PNGWriter.h
+++ b/goo/PNGWriter.h
@@ -38,6 +38,10 @@ class PNGWriter : public ImgWriter
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);
@@ -50,6 +54,10 @@ class PNGWriter : public ImgWriter
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
--
1.7.4.1
--------------010201060309050309080107--
More information about the poppler
mailing list