|
20 | 20 | #include "scene/tables.h" |
21 | 21 |
|
22 | 22 | #include "util/foreach.h" |
| 23 | +#include "util/log.h" |
23 | 24 | #include "util/murmurhash.h" |
24 | 25 | #include "util/task.h" |
25 | 26 | #include "util/transform.h" |
@@ -897,61 +898,67 @@ void ShaderManager::init_xyz_transforms() |
897 | 898 | is_rec709 = true; |
898 | 899 |
|
899 | 900 | #ifdef WITH_OCIO |
900 | | - /* Get from OpenColorO config if it has the required roles. */ |
901 | | - OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig(); |
902 | | - if (!(config && config->hasRole("scene_linear"))) { |
903 | | - return; |
904 | | - } |
905 | | - |
906 | | - Transform xyz_to_rgb; |
907 | | - |
908 | | - if (config->hasRole("aces_interchange")) { |
909 | | - /* Standard OpenColorIO role, defined as ACES AP0 (ACES2065-1). */ |
910 | | - Transform aces_to_rgb; |
911 | | - if (!to_scene_linear_transform(config, "aces_interchange", aces_to_rgb)) { |
| 901 | + try { |
| 902 | + /* Get from OpenColorO config if it has the required roles. */ |
| 903 | + OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig(); |
| 904 | + if (!(config && config->hasRole("scene_linear"))) { |
912 | 905 | return; |
913 | 906 | } |
914 | 907 |
|
915 | | - /* This is the OpenColorIO builtin transform: |
916 | | - * UTILITY - ACES-AP0_to_CIE-XYZ-D65_BFD. */ |
917 | | - const Transform ACES_AP0_to_xyz_D65 = make_transform(0.938280f, |
918 | | - -0.004451f, |
919 | | - 0.016628f, |
920 | | - 0.000000f, |
921 | | - 0.337369f, |
922 | | - 0.729522f, |
923 | | - -0.066890f, |
924 | | - 0.000000f, |
925 | | - 0.001174f, |
926 | | - -0.003711f, |
927 | | - 1.091595f, |
928 | | - 0.000000f); |
929 | | - const Transform xyz_to_aces = transform_inverse(ACES_AP0_to_xyz_D65); |
930 | | - xyz_to_rgb = aces_to_rgb * xyz_to_aces; |
931 | | - } |
932 | | - else if (config->hasRole("XYZ")) { |
933 | | - /* Custom role used before the standard existed. */ |
934 | | - if (!to_scene_linear_transform(config, "XYZ", xyz_to_rgb)) { |
| 908 | + Transform xyz_to_rgb; |
| 909 | + |
| 910 | + if (config->hasRole("aces_interchange")) { |
| 911 | + /* Standard OpenColorIO role, defined as ACES AP0 (ACES2065-1). */ |
| 912 | + Transform aces_to_rgb; |
| 913 | + if (!to_scene_linear_transform(config, "aces_interchange", aces_to_rgb)) { |
| 914 | + return; |
| 915 | + } |
| 916 | + |
| 917 | + /* This is the OpenColorIO builtin transform: |
| 918 | + * UTILITY - ACES-AP0_to_CIE-XYZ-D65_BFD. */ |
| 919 | + const Transform ACES_AP0_to_xyz_D65 = make_transform(0.938280f, |
| 920 | + -0.004451f, |
| 921 | + 0.016628f, |
| 922 | + 0.000000f, |
| 923 | + 0.337369f, |
| 924 | + 0.729522f, |
| 925 | + -0.066890f, |
| 926 | + 0.000000f, |
| 927 | + 0.001174f, |
| 928 | + -0.003711f, |
| 929 | + 1.091595f, |
| 930 | + 0.000000f); |
| 931 | + const Transform xyz_to_aces = transform_inverse(ACES_AP0_to_xyz_D65); |
| 932 | + xyz_to_rgb = aces_to_rgb * xyz_to_aces; |
| 933 | + } |
| 934 | + else if (config->hasRole("XYZ")) { |
| 935 | + /* Custom role used before the standard existed. */ |
| 936 | + if (!to_scene_linear_transform(config, "XYZ", xyz_to_rgb)) { |
| 937 | + return; |
| 938 | + } |
| 939 | + } |
| 940 | + else { |
| 941 | + /* No reference role found to determine XYZ. */ |
935 | 942 | return; |
936 | 943 | } |
937 | | - } |
938 | | - else { |
939 | | - /* No reference role found to determine XYZ. */ |
940 | | - return; |
941 | | - } |
942 | 944 |
|
943 | | - xyz_to_r = float4_to_float3(xyz_to_rgb.x); |
944 | | - xyz_to_g = float4_to_float3(xyz_to_rgb.y); |
945 | | - xyz_to_b = float4_to_float3(xyz_to_rgb.z); |
| 945 | + xyz_to_r = float4_to_float3(xyz_to_rgb.x); |
| 946 | + xyz_to_g = float4_to_float3(xyz_to_rgb.y); |
| 947 | + xyz_to_b = float4_to_float3(xyz_to_rgb.z); |
946 | 948 |
|
947 | | - const Transform rgb_to_xyz = transform_inverse(xyz_to_rgb); |
948 | | - rgb_to_y = float4_to_float3(rgb_to_xyz.y); |
| 949 | + const Transform rgb_to_xyz = transform_inverse(xyz_to_rgb); |
| 950 | + rgb_to_y = float4_to_float3(rgb_to_xyz.y); |
949 | 951 |
|
950 | | - const Transform rec709_to_rgb = xyz_to_rgb * transform_inverse(xyz_to_rec709); |
951 | | - rec709_to_r = float4_to_float3(rec709_to_rgb.x); |
952 | | - rec709_to_g = float4_to_float3(rec709_to_rgb.y); |
953 | | - rec709_to_b = float4_to_float3(rec709_to_rgb.z); |
954 | | - is_rec709 = transform_equal_threshold(xyz_to_rgb, xyz_to_rec709, 0.0001f); |
| 952 | + const Transform rec709_to_rgb = xyz_to_rgb * transform_inverse(xyz_to_rec709); |
| 953 | + rec709_to_r = float4_to_float3(rec709_to_rgb.x); |
| 954 | + rec709_to_g = float4_to_float3(rec709_to_rgb.y); |
| 955 | + rec709_to_b = float4_to_float3(rec709_to_rgb.z); |
| 956 | + is_rec709 = transform_equal_threshold(xyz_to_rgb, xyz_to_rec709, 0.0001f); |
| 957 | + } |
| 958 | + catch (const OCIO::Exception &exception) { |
| 959 | + VLOG_WARNING << "OpenColorIO config could not be loaded during ShaderManager startup; " |
| 960 | + << "falling back to built-in Rec.709 transforms: " << exception.what(); |
| 961 | + } |
955 | 962 | #endif |
956 | 963 | } |
957 | 964 |
|
|
0 commit comments