[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 |   32 ++++++++++++++++++++++++++++++--
 goo/PNGWriter.h  |   10 +++++++++-
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/goo/PNGWriter.cc b/goo/PNGWriter.cc
index 1cabfc5..9828a62 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);
+  /* 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 1d2b7ca..ba7fd1e 100644
--- a/goo/PNGWriter.h
+++ b/goo/PNGWriter.h
@@ -36,8 +36,12 @@ class PNGWriter : public ImgWriter
    */
   enum Format { RGB, RGBA, GRAY, MONOCHROME };
 
-		PNGWriter(Format format = RGB);
+  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


--------------010100010407070709080108
Content-Type: text/x-patch;
 name="0005-pdftocairo-utility-for-creating-png-jpeg-ps-eps-pdf-.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0005-pdftocairo-utility-for-creating-png-jpeg-ps-eps-pdf-.pa";
 filename*1="tch"



More information about the poppler mailing list