@@ -2033,38 +2033,56 @@ enum class CICPRange : int {
20332033};
20342034
20352035struct ColorInteropID {
2036+ constexpr ColorInteropID (const char * interop_id)
2037+ : interop_id(interop_id)
2038+ , cicp({ 0 , 0 , 0 , 0 })
2039+ , have_cicp(false )
2040+ {
2041+ }
2042+
20362043 constexpr ColorInteropID (const char * interop_id, CICPPrimaries primaries,
20372044 CICPTransfer transfer, CICPMatrix matrix)
20382045 : interop_id(interop_id)
20392046 , cicp({ int (primaries), int (transfer), int (matrix),
20402047 int (CICPRange::Full) })
2048+ , have_cicp(true )
20412049 {
20422050 }
20432051
20442052 const char * interop_id;
20452053 std::array<int , 4 > cicp;
2054+ bool have_cicp;
20462055};
20472056
20482057// Mapping between color interop ID and CICP, based on Color Interop Forum
20492058// recommendations.
20502059constexpr ColorInteropID color_interop_ids[] = {
20512060 // Scene referred interop IDs first so they are the default in automatic
2052- // conversion from CICP to interop ID.
2053- { " srgb_rec709_scene" , CICPPrimaries::Rec709, CICPTransfer::sRGB ,
2054- CICPMatrix::BT709 },
2055- { " srgb_p3d65_scene" , CICPPrimaries::P3D65, CICPTransfer::sRGB ,
2056- CICPMatrix::BT709 },
2057- { " g22_rec709_scene" , CICPPrimaries::Rec709, CICPTransfer::Gamma22,
2058- CICPMatrix::BT709 },
2059- // These are not display color spaces at all, but can be represented by CICP.
2061+ // conversion from CICP to interop ID. Some are not display color spaces
2062+ // at all, but can be represented by CICP anyway.
2063+ { " lin_ap1_scene" },
2064+ { " lin_ap0_scene" },
20602065 { " lin_rec709_scene" , CICPPrimaries::Rec709, CICPTransfer::Linear,
20612066 CICPMatrix::BT709 },
20622067 { " lin_p3d65_scene" , CICPPrimaries::P3D65, CICPTransfer::Linear,
20632068 CICPMatrix::BT709 },
20642069 { " lin_rec2020_scene" , CICPPrimaries::Rec2020, CICPTransfer::Linear,
20652070 CICPMatrix::Rec2020_CL },
2071+ { " lin_adobergb_scene" },
20662072 { " lin_ciexyzd65_scene" , CICPPrimaries::XYZD65, CICPTransfer::Linear,
20672073 CICPMatrix::Unspecified },
2074+ { " srgb_rec709_scene" , CICPPrimaries::Rec709, CICPTransfer::sRGB ,
2075+ CICPMatrix::BT709 },
2076+ { " g22_rec709_scene" , CICPPrimaries::Rec709, CICPTransfer::Gamma22,
2077+ CICPMatrix::BT709 },
2078+ { " g18_rec709_scene" },
2079+ { " srgb_ap1_scene" },
2080+ { " g22_ap1_scene" },
2081+ { " srgb_p3d65_scene" , CICPPrimaries::P3D65, CICPTransfer::sRGB ,
2082+ CICPMatrix::BT709 },
2083+ { " g22_adobergb_scene" },
2084+ { " data" },
2085+ { " unknown" },
20682086
20692087 // Display referred interop IDs.
20702088 { " srgb_rec709_display" , CICPPrimaries::Rec709, CICPTransfer::sRGB ,
@@ -2084,7 +2102,7 @@ constexpr ColorInteropID color_interop_ids[] = {
20842102 { " g22_rec709_display" , CICPPrimaries::Rec709, CICPTransfer::Gamma22,
20852103 CICPMatrix::BT709 },
20862104 // No CICP code for Adobe RGB primaries.
2087- // { "g22_adobergb_display" }
2105+ { " g22_adobergb_display" },
20882106 { " g26_p3d65_display" , CICPPrimaries::P3D65, CICPTransfer::Gamma26,
20892107 CICPMatrix::BT709 },
20902108 { " g26_xyzd65_display" , CICPPrimaries::XYZD65, CICPTransfer::Gamma26,
@@ -2094,11 +2112,35 @@ constexpr ColorInteropID color_interop_ids[] = {
20942112};
20952113} // namespace
20962114
2115+ string_view
2116+ ColorConfig::get_color_interop_id (string_view colorspace) const
2117+ {
2118+ if (colorspace.empty ())
2119+ return " " ;
2120+ #if OCIO_VERSION_HEX >= MAKE_OCIO_VERSION_HEX(2, 5, 0)
2121+ if (getImpl ()->config_ && !disable_ocio) {
2122+ OCIO::ConstColorSpaceRcPtr c = getImpl ()->config_ ->getColorSpace (
2123+ std::string (resolve (colorspace)).c_str ());
2124+ const char * interop_id = (c) ? c->getInteropID () : nullptr ;
2125+ if (interop_id) {
2126+ return interop_id;
2127+ }
2128+ }
2129+ #endif
2130+ for (const ColorInteropID& interop : color_interop_ids) {
2131+ if (equivalent (colorspace, interop.interop_id )) {
2132+ return interop.interop_id ;
2133+ }
2134+ }
2135+ return " " ;
2136+ }
2137+
20972138string_view
20982139ColorConfig::get_color_interop_id (const int cicp[4 ]) const
20992140{
21002141 for (const ColorInteropID& interop : color_interop_ids) {
2101- if (interop.cicp [0 ] == cicp[0 ] && interop.cicp [1 ] == cicp[1 ]) {
2142+ if (interop.have_cicp && interop.cicp [0 ] == cicp[0 ]
2143+ && interop.cicp [1 ] == cicp[1 ]) {
21022144 return interop.interop_id ;
21032145 }
21042146 }
@@ -2110,7 +2152,8 @@ ColorConfig::get_cicp(string_view colorspace) const
21102152{
21112153 if (!colorspace.empty ()) {
21122154 for (const ColorInteropID& interop : color_interop_ids) {
2113- if (equivalent (colorspace, interop.interop_id )) {
2155+ if (interop.have_cicp
2156+ && equivalent (colorspace, interop.interop_id )) {
21142157 return interop.cicp ;
21152158 }
21162159 }
0 commit comments