Skip to content

Commit 70262a2

Browse files
committed
feat: Support display color space interop IDs in I/O
Previously only srgb_rec709_scene was recognized as sRGB for file metadata and display, now srgb_rec709_display and g22_rec709_display are treated as sRGB as well. g24_rec709_display is now recognized as gamma 2.4. The reason for g22_rec709_display behavior is that this type of display is often used to correct for the discrepancy where images are encoded as sRGB but usually decoded as gamma 2.2 by the physical display. Signed-off-by: Brecht Van Lommel <brecht@blender.org>
1 parent e7c95c5 commit 70262a2

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

src/libOpenImageIO/color_ocio.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,11 +2099,13 @@ constexpr ColorInteropID color_interop_ids[] = {
20992099
CICPMatrix::Rec2020_NCL },
21002100
{ "hlg_rec2020_display", CICPPrimaries::Rec2020, CICPTransfer::HLG,
21012101
CICPMatrix::Rec2020_NCL },
2102-
// No CICP mapping to keep previous behavior unchanged, as Gamma 2.2
2103-
// display is more likely meant to be written as sRGB. On read the
2104-
// scene referred interop ID will be used.
2105-
{ "g22_rec709_display",
2106-
/* CICPPrimaries::Rec709, CICPTransfer::Gamma22, CICPMatrix::BT709 */ },
2102+
// Mapped to sRGB as a gamma 2.2 display is more likely meant to be written
2103+
// as sRGB. This type of display is often used to correct for the discrepancy
2104+
// where images are encoded as sRGB but usually decoded as gamma 2.2 by the
2105+
// physical display.
2106+
// For read and write, g22_rec709_scene. still maps to Gamma 2.2.
2107+
{ "g22_rec709_display", CICPPrimaries::Rec709, CICPTransfer::sRGB,
2108+
CICPMatrix::BT709 },
21072109
// No CICP code for Adobe RGB primaries.
21082110
{ "g22_adobergb_display" },
21092111
{ "g26_p3d65_display", CICPPrimaries::P3D65, CICPTransfer::Gamma26,
@@ -2849,7 +2851,11 @@ pvt::is_colorspace_srgb(const ImageSpec& spec, bool default_to_srgb)
28492851

28502852
const ColorConfig& colorconfig(ColorConfig::default_colorconfig());
28512853
string_view interop_id = colorconfig.get_color_interop_id(colorspace);
2852-
return interop_id == "srgb_rec709_scene";
2854+
2855+
// See the interop table above for why g22_rec709_display is treated as sRGB
2856+
return (interop_id == "srgb_rec709_scene"
2857+
|| interop_id == "srgb_rec709_display"
2858+
|| interop_id == "g22_rec709_display");
28532859
}
28542860

28552861
float
@@ -2864,11 +2870,14 @@ pvt::get_colorspace_rec709_gamma(const ImageSpec& spec)
28642870
|| colorconfig.equivalent(colorspace, "scene_linear")
28652871
|| interop_id == "lin_rec709_scene")
28662872
return 1.0f;
2873+
// See the interop table above for why g22_rec709_display is not treated as gamma
28672874
else if (interop_id == "g22_rec709_scene")
28682875
return 2.2f;
2869-
// Note g24_rec709_scene is not a standard interop ID
2870-
else if (colorconfig.equivalent(colorspace, "g24_rec709_scene"))
2876+
// Note g24_rec709_scene is not a standard interop
2877+
else if (colorconfig.equivalent(colorspace, "g24_rec709_scene")
2878+
|| interop_id == "g24_rec709_display")
28712879
return 2.4f;
2880+
// Note g18_rec709_display is not an interop ID
28722881
else if (interop_id == "g18_rec709_scene")
28732882
return 1.8f;
28742883
// Back compatible, this is DEPRECATED(3.1)

src/raw.imageio/rawinput.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ RawInput::open_raw(bool unpack, bool process, const std::string& name,
577577
m_processor->imgdata.params.gamm[0] = 1.0;
578578
m_processor->imgdata.params.gamm[1] = 1.0;
579579
} else if (colorconfig.equivalent(cs, "srgb_rec709_scene")
580+
|| colorconfig.equivalent(cs, "srgb_rec709_display")
580581
|| Strutil::iequals(cs, "sRGB") /* Necessary? */) {
581582
// Request explicit sRGB, including usual sRGB response
582583
m_processor->imgdata.params.output_color = 1;

testsuite/png/ref/out-libpng15.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,16 @@ remove_cicp_via_set_colorspace:
102102
16 x 16, 4 channel, float png
103103
channel list: R, G, B, A
104104
oiio:ColorSpace: "g22_rec709_display"
105+
Reading g22_rec709_display.png
106+
g22_rec709_display.png : 64 x 64, 3 channel, uint8 png
107+
SHA-1: 7CB41FEA50720B48BE0C145E1473982B23E9AB77
108+
channel list: R, G, B
109+
oiio:ColorSpace: "g22_rec709_display"
110+
Reading g22_rec709_scene.png
111+
g22_rec709_scene.png : 64 x 64, 3 channel, uint8 png
112+
SHA-1: 7CB41FEA50720B48BE0C145E1473982B23E9AB77
113+
channel list: R, G, B
114+
oiio:ColorSpace: "g22_rec709_scene"
115+
oiio:Gamma: 2.2
105116
Comparing "test16.png" and "ref/test16.png"
106117
PASS

testsuite/png/ref/out.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,16 @@ remove_cicp_via_set_colorspace:
103103
16 x 16, 4 channel, float png
104104
channel list: R, G, B, A
105105
oiio:ColorSpace: "g22_rec709_display"
106+
Reading g22_rec709_display.png
107+
g22_rec709_display.png : 64 x 64, 3 channel, uint8 png
108+
SHA-1: 7CB41FEA50720B48BE0C145E1473982B23E9AB77
109+
channel list: R, G, B
110+
oiio:ColorSpace: "g22_rec709_display"
111+
Reading g22_rec709_scene.png
112+
g22_rec709_scene.png : 64 x 64, 3 channel, uint8 png
113+
SHA-1: 7CB41FEA50720B48BE0C145E1473982B23E9AB77
114+
channel list: R, G, B
115+
oiio:ColorSpace: "g22_rec709_scene"
116+
oiio:Gamma: 2.2
106117
Comparing "test16.png" and "ref/test16.png"
107118
PASS

testsuite/png/run.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,10 @@
4343
# Test that "set_colorspace" removes CICP metadata
4444
command += oiiotool ("-echo remove_cicp_via_set_colorspace: test16.png --eraseattrib Software --cicp 1,13 --iscolorspace g22_rec709_display --printinfo")
4545

46+
# Test g22_rec709_display being written as sRGB
47+
command += oiiotool ("--create 64x64 3 --iscolorspace g22_rec709_display -o g22_rec709_display.png")
48+
command += oiiotool ("--create 64x64 3 --iscolorspace g22_rec709_scene -o g22_rec709_scene.png")
49+
command += info_command ("g22_rec709_display.png", safematch=True)
50+
command += info_command ("g22_rec709_scene.png", safematch=True)
51+
4652
outputs = [ "test16.png", "out.txt" ]

0 commit comments

Comments
 (0)