Skip to content

Commit 46394b6

Browse files
brechtvllgritz
authored andcommitted
feat(exr): Write OpenEXR colorInteropID metadata based on oiio:ColorSpace (#4967)
If the colorspace exists and has an interop ID in an OCIO 2.5 config, use that. Otherwise check if the colorspace is equivalent to a known color interop ID. Tests were added. Signed-off-by: Brecht Van Lommel <[email protected]>
1 parent 5060dd3 commit 46394b6

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/openexr.imageio/exroutput.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <numeric>
1414

1515
#include <OpenImageIO/Imath.h>
16+
#include <OpenImageIO/color.h>
1617
#include <OpenImageIO/platform.h>
1718

1819
#include <OpenEXR/IlmThreadPool.h>
@@ -1026,6 +1027,15 @@ OpenEXROutput::spec_to_header(ImageSpec& spec, int subimage,
10261027
}
10271028
}
10281029

1030+
// Set color interop ID from colorspace
1031+
if (spec.get_string_attribute("colorInteropID").empty()) {
1032+
const ColorConfig& colorconfig(ColorConfig::default_colorconfig());
1033+
string_view colorspace = spec.get_string_attribute("oiio:ColorSpace");
1034+
string_view interop_id = colorconfig.get_color_interop_id(colorspace);
1035+
if (!interop_id.empty())
1036+
spec.attribute("colorInteropID", interop_id);
1037+
}
1038+
10291039
// Deal with all other params
10301040
for (const auto& p : spec.extra_attribs)
10311041
put_parameter(p.name().string(), p.type(), p.data(), header);

testsuite/openexr-suite/ref/out.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,37 @@ Full command line was:
369369
oiiotool ERROR: -o : Cannot output non-compliant ACES Container in 'strict' mode. REASON: EXR data type is not 'HALF' as required for an ACES Container.
370370
Full command line was:
371371
> oiiotool --create 4x4 3 -d float --compression none -sattrib openexr:ACESContainerPolicy strict -o strict-fail.exr
372+
Reading color_interop_id_scene_linear.exr
373+
color_interop_id_scene_linear.exr : 4 x 4, 3 channel, float openexr
374+
SHA-1: D7699308C38CD04EEB732577A82D31D04E05A339
375+
channel list: R, G, B
376+
colorInteropID: "lin_ap1_scene"
377+
compression: "zip"
378+
PixelAspectRatio: 1
379+
screenWindowCenter: 0, 0
380+
screenWindowWidth: 1
381+
oiio:ColorSpace: "lin_ap1_scene"
382+
oiio:subimages: 1
383+
openexr:lineOrder: "increasingY"
384+
Reading color_interop_id_linear_adobergb.exr
385+
color_interop_id_linear_adobergb.exr : 4 x 4, 3 channel, float openexr
386+
SHA-1: D7699308C38CD04EEB732577A82D31D04E05A339
387+
channel list: R, G, B
388+
colorInteropID: "lin_adobergb_scene"
389+
compression: "zip"
390+
PixelAspectRatio: 1
391+
screenWindowCenter: 0, 0
392+
screenWindowWidth: 1
393+
oiio:ColorSpace: "lin_adobergb_scene"
394+
oiio:subimages: 1
395+
openexr:lineOrder: "increasingY"
396+
Reading color_interop_id_unknown.exr
397+
color_interop_id_unknown.exr : 4 x 4, 3 channel, float openexr
398+
SHA-1: D7699308C38CD04EEB732577A82D31D04E05A339
399+
channel list: R, G, B
400+
compression: "zip"
401+
PixelAspectRatio: 1
402+
screenWindowCenter: 0, 0
403+
screenWindowWidth: 1
404+
oiio:subimages: 1
405+
openexr:lineOrder: "increasingY"

testsuite/openexr-suite/run.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,11 @@
8383

8484
# Invalid data type
8585
command += oiiotool("--create 4x4 3 -d float --compression none -sattrib openexr:ACESContainerPolicy strict -o strict-fail.exr", failureok=True)
86+
87+
# Check color interop ID output
88+
command += oiiotool("--create 4x4 3 --attrib oiio:ColorSpace scene_linear -o color_interop_id_scene_linear.exr")
89+
command += info_command("color_interop_id_scene_linear.exr", safematch=True)
90+
command += oiiotool("--create 4x4 3 --attrib oiio:ColorSpace lin_adobergb_scene -o color_interop_id_linear_adobergb.exr")
91+
command += info_command("color_interop_id_linear_adobergb.exr", safematch=True)
92+
command += oiiotool("--create 4x4 3 --attrib oiio:ColorSpace unknown_interop_id -o color_interop_id_unknown.exr")
93+
command += info_command("color_interop_id_unknown.exr", safematch=True)

0 commit comments

Comments
 (0)