@@ -49,7 +49,7 @@ static const Imath::C3f test_colors[n_test_colors]
49
49
} // namespace
50
50
51
51
52
- #if 0 /* allow color configuration debugging */
52
+ #if 0 || !defined(NDEBUG) /* allow color configuration debugging */
53
53
static bool colordebug = Strutil::stoi(Sysutil::getenv("OIIO_COLOR_DEBUG"));
54
54
# define DBG(...) \
55
55
if (colordebug) \
@@ -403,6 +403,13 @@ class ColorConfig::Impl {
403
403
}
404
404
}
405
405
406
+ void debug_print_aliases ()
407
+ {
408
+ DBG (" Aliases: scene_linear={} lin_srgb={} srgb={} ACEScg={} Rec709={}\n " ,
409
+ scene_linear_alias, lin_srgb_alias, srgb_alias, ACEScg_alias,
410
+ Rec709_alias);
411
+ }
412
+
406
413
// For OCIO 2.3+, we can ask for the equivalent of some built-in
407
414
// color spaces.
408
415
void identify_builtin_equivalents ();
@@ -490,10 +497,15 @@ OCIO::ConstCPUProcessorRcPtr
490
497
ColorConfig::Impl::get_to_builtin_cpu_proc (const char * my_from,
491
498
const char * builtin_to) const
492
499
{
493
- auto proc = OCIO::Config::GetProcessorToBuiltinColorSpace (config_, my_from,
494
- builtin_to);
495
- return proc ? proc->getDefaultCPUProcessor ()
496
- : OCIO::ConstCPUProcessorRcPtr ();
500
+ try {
501
+ auto proc = OCIO::Config::GetProcessorToBuiltinColorSpace (config_,
502
+ my_from,
503
+ builtin_to);
504
+ return proc ? proc->getDefaultCPUProcessor ()
505
+ : OCIO::ConstCPUProcessorRcPtr ();
506
+ } catch (...) {
507
+ return {};
508
+ }
497
509
}
498
510
499
511
#endif
@@ -592,6 +604,16 @@ ColorConfig::Impl::classify_by_name(CSInfo& cs)
592
604
cs.setflag (CSInfo::is_ACEScg | CSInfo::is_linear_response,
593
605
ACEScg_alias);
594
606
}
607
+ #ifdef OIIO_SITE_spi
608
+ // Ugly SPI-specific hacks, so sorry
609
+ else if (Strutil::starts_with (cs.name , " cgln" )) {
610
+ cs.setflag (CSInfo::is_ACEScg | CSInfo::is_linear_response,
611
+ ACEScg_alias);
612
+ } else if (cs.name == " srgbf" || cs.name == " srgbh" || cs.name == " srgb16"
613
+ || cs.name == " srgb8" ) {
614
+ cs.setflag (CSInfo::is_srgb, srgb_alias);
615
+ }
616
+ #endif
595
617
596
618
// Set up some canonical names
597
619
if (cs.flags () & CSInfo::is_srgb)
@@ -602,13 +624,19 @@ ColorConfig::Impl::classify_by_name(CSInfo& cs)
602
624
cs.canonical = " lin_srgb" ;
603
625
else if (cs.flags () & CSInfo::is_ACEScg)
604
626
cs.canonical = " ACEScg" ;
627
+ if (cs.canonical .size ()) {
628
+ DBG (" classify by name identified '{}' as canonical {}\n " , cs.name ,
629
+ cs.canonical );
630
+ cs.examined = true ;
631
+ }
605
632
}
606
633
607
634
608
635
609
636
void
610
637
ColorConfig::Impl::classify_by_conversions (CSInfo& cs)
611
638
{
639
+ DBG (" classifying by conversions {}\n " , cs.name );
612
640
if (cs.examined )
613
641
return ; // Already classified
614
642
@@ -698,26 +726,36 @@ void
698
726
ColorConfig::Impl::identify_builtin_equivalents ()
699
727
{
700
728
#if OCIO_VERSION_HEX >= MAKE_OCIO_VERSION_HEX(2, 3, 0)
729
+ Timer timer;
701
730
if (auto n = IdentifyBuiltinColorSpace (" srgb_tx" )) {
702
731
if (CSInfo* cs = find (n)) {
703
732
cs->setflag (CSInfo::is_srgb, srgb_alias);
704
733
DBG (" Identified {} = builtin '{}'\n " , " srgb" , cs->name );
705
734
}
735
+ } else {
736
+ DBG (" No config space identified as srgb\n " );
706
737
}
738
+ DBG (" identify_builtin_equivalents srgb took {:0.2f}s\n " , timer.lap ());
707
739
if (auto n = IdentifyBuiltinColorSpace (" lin_srgb" )) {
708
740
if (CSInfo* cs = find (n)) {
709
741
cs->setflag (CSInfo::is_lin_srgb | CSInfo::is_linear_response,
710
742
lin_srgb_alias);
711
743
DBG (" Identified {} = builtin '{}'\n " , " lin_srgb" , cs->name );
712
744
}
745
+ } else {
746
+ DBG (" No config space identified as lin_srgb\n " );
713
747
}
748
+ DBG (" identify_builtin_equivalents lin_srgb took {:0.2f}s\n " , timer.lap ());
714
749
if (auto n = IdentifyBuiltinColorSpace (" ACEScg" )) {
715
750
if (CSInfo* cs = find (n)) {
716
751
cs->setflag (CSInfo::is_ACEScg | CSInfo::is_linear_response,
717
752
ACEScg_alias);
718
753
DBG (" Identified {} = builtin '{}'\n " , " ACEScg" , cs->name );
719
754
}
755
+ } else {
756
+ DBG (" No config space identified as acescg\n " );
720
757
}
758
+ DBG (" identify_builtin_equivalents acescg took {:0.2f}s\n " , timer.lap ());
721
759
#endif
722
760
}
723
761
@@ -798,23 +836,26 @@ ColorConfig::Impl::init(string_view filename)
798
836
799
837
ok = config_.get () != nullptr ;
800
838
801
- if (timer () > 0 .1f )
802
- DBG (" OCIO config {} loaded in {:0.2f} seconds\n " , filename,
803
- timer.lap ());
839
+ DBG (" OCIO config {} loaded in {:0.2f} seconds\n " , filename, timer.lap ());
804
840
#endif
805
841
806
842
inventory ();
807
- identify_builtin_equivalents ();
843
+ // NOTE: inventory already does classify_by_name
844
+
808
845
#if OCIO_VERSION_HEX < MAKE_OCIO_VERSION_HEX(2, 2, 0)
809
846
// Prior to 2.2, there are some other heuristics we use
810
847
for (auto && cs : colorspaces)
811
848
reclassify_heuristics (cs);
812
849
#endif
813
- if (timer () > 0 .1f )
814
- DBG (" OCIO config classified in {:0.2f} seconds\n " , timer.lap ());
850
+ #if OCIO_VERSION_HEX >= MAKE_OCIO_VERSION_HEX(2, 3, 0)
851
+ DBG (" \n IDENTIFY BUILTIN EQUIVALENTS\n " );
852
+ identify_builtin_equivalents (); // OCIO 2.3+ only
853
+ DBG (" OCIO 2.3+ builtin equivalents in {:0.2f} seconds\n " , timer.lap ());
854
+ #endif
815
855
816
856
#if 1
817
857
for (auto && cs : colorspaces) {
858
+ // examine(&cs);
818
859
DBG (" Color space '{}':\n " , cs.name );
819
860
if (cs.flags () & CSInfo::is_srgb)
820
861
DBG (" '{}' is srgb\n " , cs.name );
@@ -832,9 +873,9 @@ ColorConfig::Impl::init(string_view filename)
832
873
DBG (" \n " );
833
874
}
834
875
#endif
835
- DBG ( " Aliases: scene_linear={} lin_srgb={} srgb={} ACEScg={} Rec709={} \n " ,
836
- scene_linear_alias, lin_srgb_alias, srgb_alias, ACEScg_alias ,
837
- Rec709_alias );
876
+ debug_print_aliases ();
877
+ DBG ( " OCIO config {} classified in {:0.2f} seconds \n " , filename ,
878
+ timer. lap () );
838
879
839
880
return ok;
840
881
}
@@ -845,7 +886,10 @@ bool
845
886
ColorConfig::reset (string_view filename)
846
887
{
847
888
pvt::LoggedTimer logtime (" ColorConfig::reset" );
848
- if (m_impl && filename == getImpl ()->configname ()) {
889
+ if (m_impl
890
+ && (filename == getImpl ()->configname ()
891
+ || (filename == " "
892
+ && getImpl ()->configname () == " ocio://default" ))) {
849
893
// Request to reset to the config we're already using. Just return,
850
894
// don't do anything expensive.
851
895
return true ;
@@ -1063,8 +1107,8 @@ ColorConfig::getColorSpaceNameByRole(string_view role) const
1063
1107
using Strutil::print;
1064
1108
OCIO::ConstColorSpaceRcPtr c = getImpl ()->config_ ->getColorSpace (
1065
1109
std::string (role).c_str ());
1066
- // print ("looking first for named color space {} -> {}\n", role,
1067
- // c ? c->getName() : "not found");
1110
+ // DBG ("looking first for named color space {} -> {}\n", role,
1111
+ // c ? c->getName() : "not found");
1068
1112
// Catch special case of obvious name synonyms
1069
1113
if (!c
1070
1114
&& (Strutil::iequals (role, " RGB" )
0 commit comments