Skip to content

Commit

Permalink
Extract embedded ICC profile from PNG images
Browse files Browse the repository at this point in the history
Fixes #4260
  • Loading branch information
agriggio committed Dec 27, 2017
1 parent a31f522 commit 0e9aab5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions rtengine/imageio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ int ImageIO::loadPNG (Glib::ustring fname)
return IMIO_HEADERERROR;
}

// silence the warning about "invalid" sRGB profiles -- see #4260
#if defined(PNG_SKIP_sRGB_CHECK_PROFILE) && defined(PNG_SET_OPTION_SUPPORTED)
png_set_option(png, PNG_SKIP_sRGB_CHECK_PROFILE, PNG_OPTION_ON);
#endif

png_infop info = png_create_info_struct (png);
png_infop end_info = png_create_info_struct (png);

Expand Down Expand Up @@ -356,6 +361,22 @@ int ImageIO::loadPNG (Glib::ustring fname)
png_set_strip_alpha(png);
}

// reading the embedded ICC profile if any
if (png_get_valid(png, info, PNG_INFO_iCCP)) {
png_charp name;
int compression_type;
#if PNG_LIBPNG_VER_MAJOR > 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR > 4)
png_bytep profdata;
#else
png_charp profdata;
#endif
png_uint_32 proflen;
png_get_iCCP(png, info, &name, &compression_type, &profdata, &proflen);
embProfile = cmsOpenProfileFromMem(profdata, proflen);
loadedProfileData = new char[proflen];
memcpy(loadedProfileData, profdata, proflen);
}

//setting gamma
double gamma;

Expand Down

0 comments on commit 0e9aab5

Please sign in to comment.