@@ -2656,96 +2656,86 @@ ColorConfig::set_colorspace_rec709_gamma(ImageSpec& spec, float gamma) const
26562656}
26572657
26582658namespace {
2659- // Primaries
2660- static const int cicp_primaries_rec709 = 1 ;
2661- static const int cicp_primaries_rec2020 = 9 ;
2662- static const int cicp_primaries_xyzd65 = 10 ;
2663- static const int cicp_primaries_p3d65 = 12 ;
2664- // Transfer functions
2665- static const int cicp_transfer_bt709 = 1 ;
2666- static const int cicp_transfer_g22 = 4 ;
2667- static const int cicp_transfer_linear = 8 ;
2668- static const int cicp_transfer_srgb = 13 ;
2669- static const int cicp_transfer_pq = 16 ;
2670- static const int cicp_transfer_g26 = 17 ;
2671- static const int cicp_transfer_hlg = 18 ;
2672- // Matrix
2673- static const int cicp_matrix_bt709 = 1 ;
2674- static const int cicp_matrix_unspecified = 2 ;
2675- static const int cicp_matrix_rec2020_ncl = 9 ;
2676- static const int cicp_matrix_rec2020_cl = 10 ;
2677- // Range
2678- static const int cicp_range_full = 1 ;
2659+ enum class CICPPrimaries {
2660+ Rec709 = 1 ,
2661+ Rec2020 = 9 ,
2662+ XYZD65 = 10 ,
2663+ P3D65 = 12 ,
2664+ };
2665+ enum class CICPTransfer {
2666+ BT709 = 1 ,
2667+ Gamma22 = 4 ,
2668+ Linear = 8 ,
2669+ sRGB = 13 ,
2670+ PQ = 16 ,
2671+ Gamma26 = 17 ,
2672+ HLG = 18 ,
2673+ };
2674+ enum class CICPMatrix {
2675+ RGB = 0 ,
2676+ BT709 = 1 ,
2677+ Unspecified = 2 ,
2678+ Rec2020_NCL = 9 ,
2679+ Rec2020_CL = 10 ,
2680+ };
2681+ enum class CICPRange {
2682+ Narrow = 0 ,
2683+ Full = 1 ,
2684+ };
26792685
26802686// Mapping between color interop ID and CICP, based on Color Interop Forum
26812687// recommendations.
26822688struct ColorSpaceCICP {
26832689 const char * interop_id;
2684- int cicp[4 ];
2690+ CICPPrimaries primaries;
2691+ CICPTransfer transfer;
2692+ CICPMatrix matrix;
26852693};
26862694
2687- static const ColorSpaceCICP color_space_cicp[] = {
2695+ constexpr ColorSpaceCICP color_space_cicp[] = {
26882696 // Scene referred interop IDs first so they are the default in automatic
26892697 // conversion from CICP to interop ID.
2690- { " srgb_rec709_scene" ,
2691- { cicp_primaries_rec709, cicp_transfer_srgb, cicp_matrix_bt709,
2692- cicp_range_full } },
2693- { " srgb_rec709_scene" ,
2694- { cicp_primaries_rec709, cicp_transfer_srgb, cicp_matrix_bt709,
2695- cicp_range_full } },
2696- { " srgb_p3d65_scene" ,
2697- { cicp_primaries_p3d65, cicp_transfer_srgb, cicp_matrix_bt709,
2698- cicp_range_full } },
2698+ { " srgb_rec709_scene" , CICPPrimaries::Rec709, CICPTransfer::sRGB ,
2699+ CICPMatrix::BT709 },
2700+ { " srgb_rec709_scene" , CICPPrimaries::Rec709, CICPTransfer::sRGB ,
2701+ CICPMatrix::BT709 },
2702+ { " srgb_p3d65_scene" , CICPPrimaries::P3D65, CICPTransfer::sRGB ,
2703+ CICPMatrix::BT709 },
26992704 // These are not display color spaces at all, but can be represented by CICP.
2700- { " lin_rec709_scene" ,
2701- { cicp_primaries_rec709, cicp_transfer_linear, cicp_matrix_bt709,
2702- cicp_range_full } },
2703- { " lin_p3d65_scene" ,
2704- { cicp_primaries_p3d65, cicp_transfer_linear, cicp_matrix_bt709,
2705- cicp_range_full } },
2706- { " lin_rec2020_scene" ,
2707- { cicp_primaries_rec2020, cicp_transfer_linear, cicp_matrix_rec2020_cl,
2708- cicp_range_full } },
2709- { " lin_ciexyzd65_scene" ,
2710- { cicp_primaries_xyzd65, cicp_transfer_linear, cicp_matrix_unspecified,
2711- cicp_range_full } },
2705+ { " lin_rec709_scene" , CICPPrimaries::Rec709, CICPTransfer::Linear,
2706+ CICPMatrix::BT709 },
2707+ { " lin_p3d65_scene" , CICPPrimaries::P3D65, CICPTransfer::Linear,
2708+ CICPMatrix::BT709 },
2709+ { " lin_rec2020_scene" , CICPPrimaries::Rec2020, CICPTransfer::Linear,
2710+ CICPMatrix::Rec2020_CL },
2711+ { " lin_ciexyzd65_scene" , CICPPrimaries::XYZD65, CICPTransfer::Linear,
2712+ CICPMatrix::Unspecified },
27122713
27132714 // Display referred interop IDs.
2714- { " srgb_rec709_display" ,
2715- { cicp_primaries_rec709, cicp_transfer_srgb, cicp_matrix_bt709,
2716- cicp_range_full } },
2717- { " g24_rec709_display" ,
2718- { cicp_primaries_rec709, cicp_transfer_bt709, cicp_matrix_bt709,
2719- cicp_range_full } },
2720- { " srgb_p3d65_display" ,
2721- { cicp_primaries_p3d65, cicp_transfer_srgb, cicp_matrix_bt709,
2722- cicp_range_full } },
2723- { " srgbe_p3d65_display" ,
2724- { cicp_primaries_p3d65, cicp_transfer_srgb, cicp_matrix_bt709,
2725- cicp_range_full } },
2726- { " pq_p3d65_display" ,
2727- { cicp_primaries_p3d65, cicp_transfer_pq, cicp_matrix_rec2020_ncl,
2728- cicp_range_full } },
2729- { " pq_rec2020_display" ,
2730- { cicp_primaries_rec2020, cicp_transfer_pq, cicp_matrix_rec2020_ncl,
2731- cicp_range_full } },
2732- { " hlg_rec2020_display" ,
2733- { cicp_primaries_rec2020, cicp_transfer_hlg, cicp_matrix_rec2020_ncl,
2734- cicp_range_full } },
2735- { " g22_rec709_display" ,
2736- { cicp_primaries_rec709, cicp_transfer_g22, cicp_matrix_bt709,
2737- cicp_range_full } },
2715+ { " srgb_rec709_display" , CICPPrimaries::Rec709, CICPTransfer::sRGB ,
2716+ CICPMatrix::BT709 },
2717+ { " g24_rec709_display" , CICPPrimaries::Rec709, CICPTransfer::BT709,
2718+ CICPMatrix::BT709 },
2719+ { " srgb_p3d65_display" , CICPPrimaries::P3D65, CICPTransfer::sRGB ,
2720+ CICPMatrix::BT709 },
2721+ { " srgbe_p3d65_display" , CICPPrimaries::P3D65, CICPTransfer::sRGB ,
2722+ CICPMatrix::BT709 },
2723+ { " pq_p3d65_display" , CICPPrimaries::P3D65, CICPTransfer::PQ,
2724+ CICPMatrix::Rec2020_NCL },
2725+ { " pq_rec2020_display" , CICPPrimaries::Rec2020, CICPTransfer::PQ,
2726+ CICPMatrix::Rec2020_NCL },
2727+ { " hlg_rec2020_display" , CICPPrimaries::Rec2020, CICPTransfer::HLG,
2728+ CICPMatrix::Rec2020_NCL },
2729+ { " g22_rec709_display" , CICPPrimaries::Rec709, CICPTransfer::Gamma22,
2730+ CICPMatrix::BT709 },
27382731 // No CICP code for Adobe RGB primaries.
27392732 // { "g22_adobergb_display" }
2740- { " g26_p3d65_display" ,
2741- { cicp_primaries_p3d65, cicp_transfer_g26, cicp_matrix_bt709,
2742- cicp_range_full } },
2743- { " g26_xyzd65_display" ,
2744- { cicp_primaries_xyzd65, cicp_transfer_g26, cicp_matrix_unspecified,
2745- cicp_range_full } },
2746- { " pq_xyzd65_display" ,
2747- { cicp_primaries_xyzd65, cicp_transfer_pq, cicp_matrix_unspecified,
2748- cicp_range_full } },
2733+ { " g26_p3d65_display" , CICPPrimaries::P3D65, CICPTransfer::Gamma26,
2734+ CICPMatrix::BT709 },
2735+ { " g26_xyzd65_display" , CICPPrimaries::XYZD65, CICPTransfer::Gamma26,
2736+ CICPMatrix::Unspecified },
2737+ { " pq_xyzd65_display" , CICPPrimaries::XYZD65, CICPTransfer::PQ,
2738+ CICPMatrix::Unspecified },
27492739};
27502740} // namespace
27512741
@@ -2755,7 +2745,7 @@ ColorConfig::set_colorspace_cicp(ImageSpec& spec, const int cicp[4]) const
27552745 spec.attribute (" CICP" , TypeDesc (TypeDesc::INT, 4 ), cicp);
27562746
27572747 for (const ColorSpaceCICP& space : color_space_cicp) {
2758- if (space.cicp [ 0 ] == cicp[0 ] && space.cicp [ 1 ] == cicp[1 ]) {
2748+ if (int ( space.primaries ) == cicp[0 ] && int ( space.transfer ) == cicp[1 ]) {
27592749 set_colorspace (spec, space.interop_id );
27602750 return ;
27612751 }
@@ -2781,7 +2771,10 @@ ColorConfig::get_colorspace_cicp(ImageSpec& spec, bool auto_cicp,
27812771 if (!colorspace.empty ()) {
27822772 for (const ColorSpaceCICP& space : color_space_cicp) {
27832773 if (equivalent (colorspace, space.interop_id )) {
2784- std::copy_n (space.cicp , 4 , cicp);
2774+ cicp[0 ] = int (space.primaries );
2775+ cicp[1 ] = int (space.transfer );
2776+ cicp[2 ] = int (space.matrix );
2777+ cicp[3 ] = int (CICPRange::Full);
27852778 return true ;
27862779 }
27872780 }
0 commit comments