Skip to content

Commit 3982143

Browse files
committed
testing: add tests for PNG, oiiotool, and python
Test `OpenImageIO.ImageSpec.set_cicp` Test `oiiotool --cicp` Test OIIO's ability to read and write the `cICP` chunk to PNG correctly. ("Correctly" in the sense that Preview on MacOs displays PQ-encoded P3D65 (cicp: 12, 16, 0, 1) 16-bit "HDR" PNGs as expected). Signed-off-by: Zach Lewis <zachcanbereached@gmail.com>
1 parent b0848db commit 3982143

11 files changed

Lines changed: 73 additions & 14 deletions

File tree

src/libOpenImageIO/formatspec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ ImageSpec::find_attribute(string_view name, ParamValue& tmpparam,
470470
auto iter = extra_attribs.find(name, searchtype, casesensitive);
471471
if (iter != extra_attribs.end())
472472
return &(*iter);
473-
// Check named items in the ImageSpec structs, not in extra_attrubs
473+
// Check named items in the ImageSpec structs, not in extra_attrubs
474474
#define MATCH(n, t) \
475475
(((!casesensitive && Strutil::iequals(name, n)) \
476476
|| (casesensitive && name == n)) \
@@ -1289,7 +1289,7 @@ ImageSpec::set_cicp(string_view cicp)
12891289
return;
12901290
}
12911291
auto vals = Strutil::extract_from_list_string<int>("0,0,0,1", 4, 0);
1292-
auto p = find_attribute("oiio:CICP", TypeDesc(TypeDesc::UINT8, 4));
1292+
auto p = find_attribute("oiio:CICP", TypeDesc(TypeDesc::UINT8, 4));
12931293
if (p) {
12941294
string_view existing_vals = metadata_val(*p);
12951295
Strutil::extract_from_list_string<int>(vals, existing_vals);

src/oiiotool/oiiotool.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,8 +2228,7 @@ class OpSetCICP final : public OiiotoolOp {
22282228
inplace(true); // This action operates in-place
22292229
cicp = args(1);
22302230
}
2231-
OpSetCICP(Oiiotool& ot, string_view opname, int argc,
2232-
const char* argv[])
2231+
OpSetCICP(Oiiotool& ot, string_view opname, int argc, const char* argv[])
22332232
: OpSetCICP(ot, opname, { argv, span_size_t(argc) })
22342233
{
22352234
}

src/png.imageio/png_pvt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ write_info(png_structp& sp, png_infop& ip, int& color_type, ImageSpec& spec,
716716
if (setjmp(png_jmpbuf(sp))) // NOLINT(cert-err52-cpp)
717717
return "Could not set PNG cICP chunk";
718718
// libpng will only write the chunk if the third byte is 0
719-
png_set_cICP(sp, ip, vals[0], vals[1], (png_byte) 0, vals[3]);
719+
png_set_cICP(sp, ip, vals[0], vals[1], (png_byte)0, vals[3]);
720720
}
721721
#endif
722722

src/python/py_imagespec.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,16 @@ declare_imagespec(py::module& m)
279279
},
280280
"name"_a)
281281
.def(
282-
"set_cicp", [](ImageSpec& self, int pri, int trc,
283-
int mtx, int vfr) {
282+
"set_cicp",
283+
[](ImageSpec& self, int pri, int trc, int mtx, int vfr) {
284284
self.set_cicp(pri, trc, mtx, vfr);
285285
},
286286
"pri"_a, "trc"_a, "mtx"_a = 0, "vfr"_a = 1)
287287
.def(
288288
"set_cicp",
289-
[](ImageSpec& self, const std::string& cicp) { self.set_cicp(cicp); },
289+
[](ImageSpec& self, const std::string& cicp) {
290+
self.set_cicp(cicp);
291+
},
290292
"cicp"_a)
291293
// __getitem__ is the dict-like `ImageSpec[key]` lookup
292294
.def("__getitem__",

testsuite/png/ref/out-libpng15.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Reading exif.png
2626
exif.png : 64 x 64, 3 channel, uint8 png
2727
SHA-1: 7CB41FEA50720B48BE0C145E1473982B23E9AB77
2828
channel list: R, G, B
29+
Exif:ExifVersion: "0230"
30+
Exif:FlashPixVersion: "0100"
31+
Exif:FocalLength: 45.7 (45.7 mm)
32+
Exif:WhiteBalance: 0 (auto)
2933
oiio:ColorSpace: "sRGB"
3034
alphagamma:
3135
1 x 1, 4 channel, float png
@@ -86,5 +90,10 @@ gimp_gradient:
8690
Monochrome: No
8791
smallalpha.png : 1 x 1, 4 channel, uint8 png
8892
Pixel (0, 0): 240 108 119 1 (0.94117653 0.42352945 0.4666667 0.003921569)
93+
cicp:
94+
16 x 16, 4 channel, float png
95+
channel list: R, G, B, A
96+
Software: "OpenImageIO 3.1.1.0dev : DC4B1085141AF19019744DC43B156DE981E3B465"
97+
oiio:ColorSpace: "sRGB"
8998
Comparing "test16.png" and "ref/test16.png"
9099
PASS

testsuite/png/ref/out.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,11 @@ gimp_gradient:
9090
Monochrome: No
9191
smallalpha.png : 1 x 1, 4 channel, uint8 png
9292
Pixel (0, 0): 240 108 119 1 (0.94117653 0.42352945 0.4666667 0.003921569)
93+
cicp:
94+
16 x 16, 4 channel, float png
95+
channel list: R, G, B, A
96+
Software: "OpenImageIO 3.1.1.0dev : DC4B1085141AF19019744DC43B156DE981E3B465"
97+
oiio:CICP: 1, 13, 0, 1
98+
oiio:ColorSpace: "sRGB"
9399
Comparing "test16.png" and "ref/test16.png"
94100
PASS

testsuite/png/ref/test16.png

17 Bytes
Loading

testsuite/png/run.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@
3232
command += oiiotool ("--pattern fill:color=0.00235,0.00106,0.00117,0.0025 1x1 4 -d uint8 -o smallalpha.png")
3333
command += oiiotool ("--no-autopremult --dumpdata smallalpha.png")
3434

35+
# Test embedding CICP metadata in PNG files
36+
command += oiiotool ("-i test16.png --cicp 1,13 -o test16.png")
37+
command += oiiotool ("-echo cicp: test16.png --printinfo")
38+
3539
outputs = [ "test16.png", "out.txt" ]
3640

testsuite/python-imagespec/ref/out-python3.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ Testing set_colorspace:
206206
after set_colorspace('sRGB'): sRGB
207207
after set_colorspace(''):
208208

209+
Testing set_cicp:
210+
after set_cicp('1,2,3,4'): [1 2 3 4]
211+
after set_cicp(''): None
212+
after set_cicp(1,2): [1 2 0 1]
213+
after set_cicp(1,2,3): [1 2 3 1]
214+
after set_cicp(1,2,3,4): [1 2 3 4]
215+
after set_cicp(',,,0'): [1 2 3 0]
216+
after set_cicp('1,13,1'): [ 1 13 1 0]
217+
after set_cicp(',4'): [1 4 1 0]
218+
209219
Testing global attribute store/retrieve:
210220
get_string_attribute plugin_searchpath : perfect
211221
get_int_attribute plugin_searchpath : 0

testsuite/python-imagespec/ref/out.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ channelformat(1) = uint8
7474
get_int_attribute('foo_int') retrieves 14
7575
get_int_attribute('foo_int',21) with default retrieves 14
7676
get_int_attribute('foo_no',23) retrieves 23
77-
get_float_attribute('foo_float') retrieves 3.1400001049
77+
get_float_attribute('foo_float') retrieves 3.140000104904175
7878
get_float_attribute('foo_float_no') retrieves 0.0
79-
get_float_attribute('foo_float_no',2.7) retrieves 2.70000004768
79+
get_float_attribute('foo_float_no',2.7) retrieves 2.700000047683716
8080
get_string_attribute('foo_str') retrieves blah
8181
get_string_attribute('foo_str_no') retrieves
8282
get_string_attribute('foo_str_no','xx') retrieves xx
8383

8484
getattribute('foo_int') retrieves 14
85-
getattribute('foo_float') retrieves 3.1400001049
85+
getattribute('foo_float') retrieves 3.140000104904175
8686
getattribute('foo_str') retrieves blah
8787
getattribute('foo_vector') retrieves (1.0, 0.0, 11.0)
8888
getattribute('foo_matrix') retrieves (1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0)
8989
getattribute('foo_no') retrieves None
90-
getattribute('smpte:TimeCode') retrieves (18356486L, 4294967295L)
90+
getattribute('smpte:TimeCode') retrieves (18356486, 4294967295)
9191
getattribute('ucarr') retrieves [49 50 51 0 0 97 98 99 1 88]
9292
getattribute('unknown') retrieves None
9393
s.get('foo_int') = 14
@@ -107,13 +107,13 @@ extra_attribs size is 10
107107
"blah"
108108
1 foo_int int 14
109109
14
110-
2 foo_float float 3.1400001049
110+
2 foo_float float 3.140000104904175
111111
3.14
112112
3 foo_vector vector (1.0, 0.0, 11.0)
113113
1, 0, 11
114114
4 foo_matrix matrix (1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0)
115115
1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1
116-
5 smpte:TimeCode timecode (18356486L, 4294967295L)
116+
5 smpte:TimeCode timecode (18356486, 4294967295)
117117
01:18:19:06
118118
6 ucarr uint8[10] [49 50 51 0 0 97 98 99 1 88]
119119
49, 50, 51, 0, 0, 97, 98, 99, 1, 88
@@ -206,6 +206,16 @@ Testing set_colorspace:
206206
after set_colorspace('sRGB'): sRGB
207207
after set_colorspace(''):
208208

209+
Testing set_cicp:
210+
after set_cicp('1,2,3,4'): [1 2 3 4]
211+
after set_cicp(''): None
212+
after set_cicp(1,2): [1 2 0 1]
213+
after set_cicp(1,2,3): [1 2 3 1]
214+
after set_cicp(1,2,3,4): [1 2 3 4]
215+
after set_cicp(',,,0'): [1 2 3 0]
216+
after set_cicp('1,13,1'): [ 1 13 1 0]
217+
after set_cicp(',4'): [1 4 1 0]
218+
209219
Testing global attribute store/retrieve:
210220
get_string_attribute plugin_searchpath : perfect
211221
get_int_attribute plugin_searchpath : 0

0 commit comments

Comments
 (0)