Commit 4f2d7748 authored by Adrian Johnson's avatar Adrian Johnson Committed by Albert Astals Cid
Browse files

png: add support for embedding ICC profile

parent 1091f473
......@@ -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");
......
......@@ -36,6 +36,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);
......@@ -48,6 +52,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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment