Skip to content

Commit 8d84f27

Browse files
committed
Add CICP support to PNG plugin
Signed-off-by: Zach Lewis <zachcanbereached@gmail.com>
1 parent 51020ab commit 8d84f27

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/png.imageio/png_pvt.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ For further information see the following mailing list threads:
4040
OIIO_PLUGIN_NAMESPACE_BEGIN
4141

4242
#define ICC_PROFILE_ATTR "ICCProfile"
43-
43+
#define CICP_ATTR "oiio:CICP"
4444

4545
namespace 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);

src/png.imageio/pnginput.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ class PNGInput final : public ImageInput {
1818
const char* format_name(void) const override { return "png"; }
1919
int supports(string_view feature) const override
2020
{
21-
return (feature == "ioproxy" || feature == "exif");
21+
return (feature == "ioproxy"
22+
#ifdef PNG_eXIf_SUPPORTED
23+
|| feature == "exif"
24+
#endif
25+
#ifdef PNG_cICP_SUPPORTED
26+
|| feature == "cicp"
27+
#endif
28+
);
2229
}
2330
bool valid_file(Filesystem::IOProxy* ioproxy) const override;
2431
bool open(const std::string& name, ImageSpec& newspec) override;

src/png.imageio/pngoutput.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class PNGOutput final : public ImageOutput {
2424
return (feature == "alpha" || feature == "ioproxy"
2525
#ifdef PNG_eXIf_SUPPORTED
2626
|| feature == "exif"
27+
#endif
28+
#ifdef PNG_cICP_SUPPORTED
29+
|| feature == "cicp"
2730
#endif
2831
);
2932
}

0 commit comments

Comments
 (0)