diff options
author | Brecht Van Lommel <brecht@blender.org> | 2022-05-20 18:54:43 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-05-23 16:34:50 +0300 |
commit | eb5e7d0a31eed698909c23ab0ca89c8fd4929365 (patch) | |
tree | 6332d3f66107492795254d4fbc0f8f3beccfb156 /source/blender/imbuf | |
parent | 469ee7ff1529a1b28ce0b300835ebc42d5c5362f (diff) |
Cleanup: clarify what is scene linear color space in conversion conversion
* Rename ambiguous rgb to scene_linear in some places
* Precompute matrices to directly go to scene instead of through XYZ
* Make function signatures more consistent
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/IMB_colormanagement.h | 30 | ||||
-rw-r--r-- | source/blender/imbuf/intern/IMB_colormanagement_intern.h | 12 | ||||
-rw-r--r-- | source/blender/imbuf/intern/colormanagement.c | 58 | ||||
-rw-r--r-- | source/blender/imbuf/intern/colormanagement_inline.c | 40 |
4 files changed, 75 insertions, 65 deletions
diff --git a/source/blender/imbuf/IMB_colormanagement.h b/source/blender/imbuf/IMB_colormanagement.h index 94036da9d22..50af946cd95 100644 --- a/source/blender/imbuf/IMB_colormanagement.h +++ b/source/blender/imbuf/IMB_colormanagement.h @@ -76,13 +76,17 @@ BLI_INLINE unsigned char IMB_colormanagement_get_luminance_byte(const unsigned c /** * Conversion between scene linear and other color spaces. */ -BLI_INLINE void IMB_colormanagement_xyz_to_rgb(float rgb[3], const float xyz[3]); -BLI_INLINE void IMB_colormanagement_rgb_to_xyz(float xyz[3], const float rgb[3]); -BLI_INLINE void IMB_colormanagement_rec709_to_rgb(float rgb[3], const float rec709[3]); -BLI_INLINE void IMB_colormanagement_rgb_to_rec709(float rec709[3], const float rgb[3]); -BLI_INLINE void IMB_colormanagement_aces_to_rgb(float rgb[3], const float aces[3]); -BLI_INLINE void IMB_colormanagement_rgb_to_aces(float aces[3], const float rgb[3]); -const float *IMB_colormanagement_get_xyz_to_rgb(void); +BLI_INLINE void IMB_colormanagement_xyz_to_scene_linear(float scene_linear[3], const float xyz[3]); +BLI_INLINE void IMB_colormanagement_scene_linear_to_xyz(float xyz[3], const float scene_linear[3]); +BLI_INLINE void IMB_colormanagement_rec709_to_scene_linear(float scene_linear[3], + const float rec709[3]); +BLI_INLINE void IMB_colormanagement_scene_linear_to_rec709(float rec709[3], + const float scene_linear[3]); +BLI_INLINE void IMB_colormanagement_aces_to_scene_linear(float scene_linear[3], + const float aces[3]); +BLI_INLINE void IMB_colormanagement_scene_linear_to_aces(float aces[3], + const float scene_linear[3]); +const float *IMB_colormanagement_get_xyz_to_scene_linear(void); /** \} */ @@ -196,15 +200,19 @@ void IMB_colormanagement_imbuf_to_float_texture(float *out_buffer, * - Color picking values 0..1 map to scene linear values in the 0..1 range, * so that picked albedo values are energy conserving. */ -void IMB_colormanagement_scene_linear_to_color_picking_v3(float pixel[3]); -void IMB_colormanagement_color_picking_to_scene_linear_v3(float pixel[3]); +void IMB_colormanagement_scene_linear_to_color_picking_v3(float color_picking[3], + const float scene_linear[3]); +void IMB_colormanagement_color_picking_to_scene_linear_v3(float scene_linear[3], + const float color_picking[3]); /** * Conversion between sRGB, for rare cases like hex color or copy/pasting * between UI theme and scene linear colors. */ -void IMB_colormanagement_scene_linear_to_srgb_v3(float pixel[3]); -void IMB_colormanagement_srgb_to_scene_linear_v3(float pixel[3]); +BLI_INLINE void IMB_colormanagement_scene_linear_to_srgb_v3(float srgb[3], + const float scene_linear[3]); +BLI_INLINE void IMB_colormanagement_srgb_to_scene_linear_v3(float scene_linear[3], + const float srgb[3]); /** * Convert pixel from scene linear to display space using default view diff --git a/source/blender/imbuf/intern/IMB_colormanagement_intern.h b/source/blender/imbuf/intern/IMB_colormanagement_intern.h index fd70c633f83..23b3f0191b7 100644 --- a/source/blender/imbuf/intern/IMB_colormanagement_intern.h +++ b/source/blender/imbuf/intern/IMB_colormanagement_intern.h @@ -18,12 +18,12 @@ struct ImBuf; struct OCIO_ConstCPUProcessorRcPtr; extern float imbuf_luma_coefficients[3]; -extern float imbuf_xyz_to_rgb[3][3]; -extern float imbuf_rgb_to_xyz[3][3]; -extern float imbuf_xyz_to_aces[3][3]; -extern float imbuf_aces_to_xyz[3][3]; -extern float imbuf_xyz_to_rec709[3][3]; -extern float imbuf_rec709_to_xyz[3][3]; +extern float imbuf_scene_linear_to_xyz[3][3]; +extern float imbuf_xyz_to_scene_linear[3][3]; +extern float imbuf_scene_linear_to_aces[3][3]; +extern float imbuf_aces_to_scene_linear[3][3]; +extern float imbuf_scene_linear_to_rec709[3][3]; +extern float imbuf_rec709_to_scene_linear[3][3]; #define MAX_COLORSPACE_NAME 64 #define MAX_COLORSPACE_DESCRIPTION 512 diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index f189614e61c..35601abab6e 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -73,12 +73,12 @@ static int global_tot_looks = 0; /* Luma coefficients and XYZ to RGB to be initialized by OCIO. */ float imbuf_luma_coefficients[3] = {0.0f}; -float imbuf_xyz_to_rgb[3][3] = {{0.0f}}; -float imbuf_rgb_to_xyz[3][3] = {{0.0f}}; -float imbuf_xyz_to_rec709[3][3] = {{0.0f}}; -float imbuf_rec709_to_xyz[3][3] = {{0.0f}}; -float imbuf_xyz_to_aces[3][3] = {{0.0f}}; -float imbuf_aces_to_xyz[3][3] = {{0.0f}}; +float imbuf_scene_linear_to_xyz[3][3] = {{0.0f}}; +float imbuf_xyz_to_scene_linear[3][3] = {{0.0f}}; +float imbuf_scene_linear_to_rec709[3][3] = {{0.0f}}; +float imbuf_rec709_to_scene_linear[3][3] = {{0.0f}}; +float imbuf_scene_linear_to_aces[3][3] = {{0.0f}}; +float imbuf_aces_to_scene_linear[3][3] = {{0.0f}}; /* lock used by pre-cached processors getters, so processor wouldn't * be created several times @@ -577,12 +577,14 @@ static void colormanage_load_config(OCIO_ConstConfigRcPtr *config) OCIO_configGetDefaultLumaCoefs(config, imbuf_luma_coefficients); /* Load standard color spaces. */ - OCIO_configGetXYZtoRGB(config, imbuf_xyz_to_rgb); - invert_m3_m3(imbuf_rgb_to_xyz, imbuf_xyz_to_rgb); - copy_m3_m3(imbuf_xyz_to_rec709, OCIO_XYZ_TO_REC709); - invert_m3_m3(imbuf_rec709_to_xyz, imbuf_xyz_to_rec709); - copy_m3_m3(imbuf_aces_to_xyz, OCIO_ACES_TO_XYZ); - invert_m3_m3(imbuf_xyz_to_aces, imbuf_aces_to_xyz); + OCIO_configGetXYZtoSceneLinear(config, imbuf_xyz_to_scene_linear); + invert_m3_m3(imbuf_scene_linear_to_xyz, imbuf_xyz_to_scene_linear); + + mul_m3_m3m3(imbuf_scene_linear_to_rec709, OCIO_XYZ_TO_REC709, imbuf_scene_linear_to_xyz); + invert_m3_m3(imbuf_rec709_to_scene_linear, imbuf_scene_linear_to_rec709); + + mul_m3_m3m3(imbuf_aces_to_scene_linear, imbuf_xyz_to_scene_linear, OCIO_ACES_TO_XYZ); + invert_m3_m3(imbuf_scene_linear_to_aces, imbuf_aces_to_scene_linear); } static void colormanage_free_config(void) @@ -1424,9 +1426,9 @@ bool IMB_colormanagement_space_name_is_srgb(const char *name) return (colorspace && IMB_colormanagement_space_is_srgb(colorspace)); } -const float *IMB_colormanagement_get_xyz_to_rgb() +const float *IMB_colormanagement_get_xyz_to_scene_linear() { - return &imbuf_xyz_to_rgb[0][0]; + return &imbuf_xyz_to_scene_linear[0][0]; } /** \} */ @@ -2319,7 +2321,8 @@ void IMB_colormanagement_imbuf_to_float_texture(float *out_buffer, } } -void IMB_colormanagement_scene_linear_to_color_picking_v3(float pixel[3]) +void IMB_colormanagement_scene_linear_to_color_picking_v3(float color_picking[3], + const float scene_linear[3]) { if (!global_color_picking_state.cpu_processor_to && !global_color_picking_state.failed) { /* Create processor if none exists. */ @@ -2341,12 +2344,15 @@ void IMB_colormanagement_scene_linear_to_color_picking_v3(float pixel[3]) BLI_mutex_unlock(&processor_lock); } + copy_v3_v3(color_picking, scene_linear); + if (global_color_picking_state.cpu_processor_to) { - OCIO_cpuProcessorApplyRGB(global_color_picking_state.cpu_processor_to, pixel); + OCIO_cpuProcessorApplyRGB(global_color_picking_state.cpu_processor_to, color_picking); } } -void IMB_colormanagement_color_picking_to_scene_linear_v3(float pixel[3]) +void IMB_colormanagement_color_picking_to_scene_linear_v3(float scene_linear[3], + const float color_picking[3]) { if (!global_color_picking_state.cpu_processor_from && !global_color_picking_state.failed) { /* Create processor if none exists. */ @@ -2368,25 +2374,13 @@ void IMB_colormanagement_color_picking_to_scene_linear_v3(float pixel[3]) BLI_mutex_unlock(&processor_lock); } + copy_v3_v3(scene_linear, color_picking); + if (global_color_picking_state.cpu_processor_from) { - OCIO_cpuProcessorApplyRGB(global_color_picking_state.cpu_processor_from, pixel); + OCIO_cpuProcessorApplyRGB(global_color_picking_state.cpu_processor_from, scene_linear); } } -void IMB_colormanagement_scene_linear_to_srgb_v3(float pixel[3]) -{ - mul_m3_v3(imbuf_rgb_to_xyz, pixel); - mul_m3_v3(imbuf_xyz_to_rec709, pixel); - linearrgb_to_srgb_v3_v3(pixel, pixel); -} - -void IMB_colormanagement_srgb_to_scene_linear_v3(float pixel[3]) -{ - srgb_to_linearrgb_v3_v3(pixel, pixel); - mul_m3_v3(imbuf_rec709_to_xyz, pixel); - mul_m3_v3(imbuf_xyz_to_rgb, pixel); -} - void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], ColorManagedDisplay *display) { OCIO_ConstCPUProcessorRcPtr *processor = display_from_scene_linear_processor(display); diff --git a/source/blender/imbuf/intern/colormanagement_inline.c b/source/blender/imbuf/intern/colormanagement_inline.c index 4c632da1520..668307ec802 100644 --- a/source/blender/imbuf/intern/colormanagement_inline.c +++ b/source/blender/imbuf/intern/colormanagement_inline.c @@ -27,38 +27,46 @@ unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char rgb[3]) return unit_float_to_uchar_clamp(val); } -void IMB_colormanagement_xyz_to_rgb(float rgb[3], const float xyz[3]) +void IMB_colormanagement_xyz_to_scene_linear(float scene_linear[3], const float xyz[3]) { - mul_v3_m3v3(rgb, imbuf_xyz_to_rgb, xyz); + mul_v3_m3v3(scene_linear, imbuf_xyz_to_scene_linear, xyz); } -void IMB_colormanagement_rgb_to_xyz(float xyz[3], const float rgb[3]) +void IMB_colormanagement_scene_linear_to_xyz(float xyz[3], const float scene_linear[3]) { - mul_v3_m3v3(xyz, imbuf_rgb_to_xyz, rgb); + mul_v3_m3v3(xyz, imbuf_scene_linear_to_xyz, scene_linear); } -void IMB_colormanagement_rec709_to_rgb(float rgb[3], const float rec709[3]) +void IMB_colormanagement_rec709_to_scene_linear(float scene_linear[3], const float rec709[3]) { - mul_v3_m3v3(rgb, imbuf_rec709_to_xyz, rec709); - mul_v3_m3v3(rgb, imbuf_xyz_to_rgb, rgb); + mul_v3_m3v3(scene_linear, imbuf_rec709_to_scene_linear, rec709); } -void IMB_colormanagement_rgb_to_rec709(float rec709[3], const float rgb[3]) +void IMB_colormanagement_scene_linear_to_rec709(float rec709[3], const float scene_linear[3]) { - mul_v3_m3v3(rec709, imbuf_rgb_to_xyz, rgb); - mul_v3_m3v3(rec709, imbuf_xyz_to_rec709, rec709); + mul_v3_m3v3(rec709, imbuf_scene_linear_to_rec709, scene_linear); } -void IMB_colormanagement_aces_to_rgb(float rgb[3], const float aces[3]) +void IMB_colormanagement_scene_linear_to_srgb_v3(float srgb[3], const float scene_linear[3]) { - mul_v3_m3v3(rgb, imbuf_aces_to_xyz, aces); - mul_v3_m3v3(rgb, imbuf_xyz_to_rgb, rgb); + mul_v3_m3v3(srgb, imbuf_scene_linear_to_rec709, scene_linear); + linearrgb_to_srgb_v3_v3(srgb, srgb); } -void IMB_colormanagement_rgb_to_aces(float aces[3], const float rgb[3]) +void IMB_colormanagement_srgb_to_scene_linear_v3(float scene_linear[3], const float srgb[3]) { - mul_v3_m3v3(aces, imbuf_rgb_to_xyz, rgb); - mul_v3_m3v3(aces, imbuf_xyz_to_aces, aces); + srgb_to_linearrgb_v3_v3(scene_linear, srgb); + mul_m3_v3(imbuf_rec709_to_scene_linear, scene_linear); +} + +void IMB_colormanagement_aces_to_scene_linear(float scene_linear[3], const float aces[3]) +{ + mul_v3_m3v3(scene_linear, imbuf_aces_to_scene_linear, aces); +} + +void IMB_colormanagement_scene_linear_to_aces(float aces[3], const float scene_linear[3]) +{ + mul_v3_m3v3(aces, imbuf_scene_linear_to_aces, scene_linear); } #endif /* __IMB_COLORMANAGEMENT_INLINE_H__ */ |