@@ -40,7 +40,7 @@ For further information see the following mailing list threads:
4040OIIO_PLUGIN_NAMESPACE_BEGIN
4141
4242#define ICC_PROFILE_ATTR " ICCProfile"
43-
43+ # define CICP_ATTR " oiio:CICP "
4444
4545namespace PNG_pvt {
4646
@@ -326,6 +326,16 @@ read_info(png_structp& sp, png_infop& ip, int& bit_depth, int& color_type,
326326
327327 interlace_type = png_get_interlace_type (sp, ip);
328328
329+ #ifdef PNG_cICP_SUPPORTED
330+ {
331+ png_byte cp = 0 , tf = 0 , mc = 0 , fr = 0 ;
332+ if (png_get_cICP (sp, ip, &cp, &tf, &mc, &fr)) {
333+ uint8_t cicp[4 ] = { cp, tf, mc, fr };
334+ spec.attribute (CICP_ATTR , TypeDesc (TypeDesc::UINT8 , 4 ), cicp);
335+ }
336+ }
337+ #endif
338+
329339#ifdef PNG_eXIf_SUPPORTED
330340 // Recent version of PNG and libpng (>= 1.6.32, I think) have direct
331341 // support for Exif chunks. Older versions don't support it, and I'm not
@@ -698,6 +708,17 @@ write_info(png_structp& sp, png_infop& ip, int& color_type, ImageSpec& spec,
698708 (png_uint_32)(yres * scale), unittype);
699709 }
700710
711+ #ifdef PNG_cICP_SUPPORTED
712+ const ParamValue* p = spec.find_attribute (CICP_ATTR ,
713+ TypeDesc (TypeDesc::UINT8 , 4 ));
714+ if (p) {
715+ const png_byte* vals = static_cast <const png_byte*>(p->data ());
716+ if (setjmp (png_jmpbuf (sp))) // NOLINT(cert-err52-cpp)
717+ return " Could not set PNG cICP chunk" ;
718+ png_set_cICP (sp, ip, vals[0 ], vals[1 ], vals[2 ], vals[3 ]);
719+ }
720+ #endif
721+
701722#ifdef PNG_eXIf_SUPPORTED
702723 std::vector<char > exifBlob;
703724 encode_exif (spec, exifBlob, endian::big);
0 commit comments