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
This commit is contained in:
Brecht Van Lommel 2022-05-20 17:54:43 +02:00
parent 469ee7ff15
commit eb5e7d0a31
20 changed files with 119 additions and 109 deletions

@ -241,10 +241,11 @@ void FallbackImpl::configGetDefaultLumaCoefs(OCIO_ConstConfigRcPtr * /*config*/,
rgb[2] = 0.0722f; rgb[2] = 0.0722f;
} }
void FallbackImpl::configGetXYZtoRGB(OCIO_ConstConfigRcPtr * /*config*/, float xyz_to_rgb[3][3]) void FallbackImpl::configGetXYZtoSceneLinear(OCIO_ConstConfigRcPtr * /*config*/,
float xyz_to_scene_linear[3][3])
{ {
/* Default to ITU-BT.709. */ /* Default to ITU-BT.709. */
memcpy(xyz_to_rgb, OCIO_XYZ_TO_REC709, sizeof(OCIO_XYZ_TO_REC709)); memcpy(xyz_to_scene_linear, OCIO_XYZ_TO_REC709, sizeof(OCIO_XYZ_TO_REC709));
} }
int FallbackImpl::configGetNumLooks(OCIO_ConstConfigRcPtr * /*config*/) int FallbackImpl::configGetNumLooks(OCIO_ConstConfigRcPtr * /*config*/)

@ -118,9 +118,9 @@ void OCIO_configGetDefaultLumaCoefs(OCIO_ConstConfigRcPtr *config, float *rgb)
impl->configGetDefaultLumaCoefs(config, rgb); impl->configGetDefaultLumaCoefs(config, rgb);
} }
void OCIO_configGetXYZtoRGB(OCIO_ConstConfigRcPtr *config, float xyz_to_rgb[3][3]) void OCIO_configGetXYZtoSceneLinear(OCIO_ConstConfigRcPtr *config, float xyz_to_scene_linear[3][3])
{ {
impl->configGetXYZtoRGB(config, xyz_to_rgb); impl->configGetXYZtoSceneLinear(config, xyz_to_scene_linear);
} }
int OCIO_configGetNumLooks(OCIO_ConstConfigRcPtr *config) int OCIO_configGetNumLooks(OCIO_ConstConfigRcPtr *config)

@ -135,7 +135,8 @@ const char *OCIO_configGetDisplayColorSpaceName(OCIO_ConstConfigRcPtr *config,
const char *view); const char *view);
void OCIO_configGetDefaultLumaCoefs(OCIO_ConstConfigRcPtr *config, float *rgb); void OCIO_configGetDefaultLumaCoefs(OCIO_ConstConfigRcPtr *config, float *rgb);
void OCIO_configGetXYZtoRGB(OCIO_ConstConfigRcPtr *config, float xyz_to_rgb[3][3]); void OCIO_configGetXYZtoSceneLinear(OCIO_ConstConfigRcPtr *config,
float xyz_to_scene_linear[3][3]);
int OCIO_configGetNumLooks(OCIO_ConstConfigRcPtr *config); int OCIO_configGetNumLooks(OCIO_ConstConfigRcPtr *config);
const char *OCIO_configGetLookNameByIndex(OCIO_ConstConfigRcPtr *config, int index); const char *OCIO_configGetLookNameByIndex(OCIO_ConstConfigRcPtr *config, int index);

@ -311,13 +311,14 @@ static bool to_scene_linear_matrix(ConstConfigRcPtr &config,
return true; return true;
} }
void OCIOImpl::configGetXYZtoRGB(OCIO_ConstConfigRcPtr *config_, float xyz_to_rgb[3][3]) void OCIOImpl::configGetXYZtoSceneLinear(OCIO_ConstConfigRcPtr *config_,
float xyz_to_scene_linear[3][3])
{ {
ConstConfigRcPtr config = (*(ConstConfigRcPtr *)config_); ConstConfigRcPtr config = (*(ConstConfigRcPtr *)config_);
/* Default to ITU-BT.709 in case no appropriate transform found. /* Default to ITU-BT.709 in case no appropriate transform found.
* Note XYZ is defined here as having a D65 white point. */ * Note XYZ is defined here as having a D65 white point. */
memcpy(xyz_to_rgb, OCIO_XYZ_TO_REC709, sizeof(OCIO_XYZ_TO_REC709)); memcpy(xyz_to_scene_linear, OCIO_XYZ_TO_REC709, sizeof(OCIO_XYZ_TO_REC709));
/* Get from OpenColorO config if it has the required roles. */ /* Get from OpenColorO config if it has the required roles. */
if (!config->hasRole(ROLE_SCENE_LINEAR)) { if (!config->hasRole(ROLE_SCENE_LINEAR)) {
@ -326,17 +327,17 @@ void OCIOImpl::configGetXYZtoRGB(OCIO_ConstConfigRcPtr *config_, float xyz_to_rg
if (config->hasRole("aces_interchange")) { if (config->hasRole("aces_interchange")) {
/* Standard OpenColorIO role, defined as ACES AP0 (ACES2065-1). */ /* Standard OpenColorIO role, defined as ACES AP0 (ACES2065-1). */
float aces_to_rgb[3][3]; float aces_to_scene_linear[3][3];
if (to_scene_linear_matrix(config, "aces_interchange", aces_to_rgb)) { if (to_scene_linear_matrix(config, "aces_interchange", aces_to_scene_linear)) {
float xyz_to_aces[3][3]; float xyz_to_aces[3][3];
invert_m3_m3(xyz_to_aces, OCIO_ACES_TO_XYZ); invert_m3_m3(xyz_to_aces, OCIO_ACES_TO_XYZ);
mul_m3_m3m3(xyz_to_rgb, aces_to_rgb, xyz_to_aces); mul_m3_m3m3(xyz_to_scene_linear, aces_to_scene_linear, xyz_to_aces);
} }
} }
else if (config->hasRole("XYZ")) { else if (config->hasRole("XYZ")) {
/* Custom role used before the standard existed. */ /* Custom role used before the standard existed. */
to_scene_linear_matrix(config, "XYZ", xyz_to_rgb); to_scene_linear_matrix(config, "XYZ", xyz_to_scene_linear);
} }
} }

@ -48,7 +48,8 @@ class IOCIOImpl {
const char *view) = 0; const char *view) = 0;
virtual void configGetDefaultLumaCoefs(OCIO_ConstConfigRcPtr *config, float *rgb) = 0; virtual void configGetDefaultLumaCoefs(OCIO_ConstConfigRcPtr *config, float *rgb) = 0;
virtual void configGetXYZtoRGB(OCIO_ConstConfigRcPtr *config, float xyz_to_rgb[3][3]) = 0; virtual void configGetXYZtoSceneLinear(OCIO_ConstConfigRcPtr *config,
float xyz_to_scene_linear[3][3]) = 0;
virtual int configGetNumLooks(OCIO_ConstConfigRcPtr *config) = 0; virtual int configGetNumLooks(OCIO_ConstConfigRcPtr *config) = 0;
virtual const char *configGetLookNameByIndex(OCIO_ConstConfigRcPtr *config, int index) = 0; virtual const char *configGetLookNameByIndex(OCIO_ConstConfigRcPtr *config, int index) = 0;
@ -167,7 +168,7 @@ class FallbackImpl : public IOCIOImpl {
const char *view); const char *view);
void configGetDefaultLumaCoefs(OCIO_ConstConfigRcPtr *config, float *rgb); void configGetDefaultLumaCoefs(OCIO_ConstConfigRcPtr *config, float *rgb);
void configGetXYZtoRGB(OCIO_ConstConfigRcPtr *config, float xyz_to_rgb[3][3]); void configGetXYZtoSceneLinear(OCIO_ConstConfigRcPtr *config, float xyz_to_scene_linear[3][3]);
int configGetNumLooks(OCIO_ConstConfigRcPtr *config); int configGetNumLooks(OCIO_ConstConfigRcPtr *config);
const char *configGetLookNameByIndex(OCIO_ConstConfigRcPtr *config, int index); const char *configGetLookNameByIndex(OCIO_ConstConfigRcPtr *config, int index);
@ -257,7 +258,7 @@ class OCIOImpl : public IOCIOImpl {
const char *view); const char *view);
void configGetDefaultLumaCoefs(OCIO_ConstConfigRcPtr *config, float *rgb); void configGetDefaultLumaCoefs(OCIO_ConstConfigRcPtr *config, float *rgb);
void configGetXYZtoRGB(OCIO_ConstConfigRcPtr *config, float xyz_to_rgb[3][3]); void configGetXYZtoSceneLinear(OCIO_ConstConfigRcPtr *config, float xyz_to_scene_linear[3][3]);
int configGetNumLooks(OCIO_ConstConfigRcPtr *config); int configGetNumLooks(OCIO_ConstConfigRcPtr *config);
const char *configGetLookNameByIndex(OCIO_ConstConfigRcPtr *config, int index); const char *configGetLookNameByIndex(OCIO_ConstConfigRcPtr *config, int index);

@ -6277,7 +6277,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co
if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) { if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target); RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target);
IMB_colormanagement_srgb_to_scene_linear_v3(target); IMB_colormanagement_srgb_to_scene_linear_v3(target, target);
} }
else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) { else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target); RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target);
@ -6294,7 +6294,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co
} }
else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) { else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color); RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color);
IMB_colormanagement_scene_linear_to_srgb_v3(color); IMB_colormanagement_scene_linear_to_srgb_v3(color, color);
BKE_brush_color_set(scene, brush, color); BKE_brush_color_set(scene, brush, color);
updated = true; updated = true;
} }

@ -1895,14 +1895,14 @@ static int drop_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) { if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
if (!gamma) { if (!gamma) {
IMB_colormanagement_scene_linear_to_srgb_v3(color); IMB_colormanagement_scene_linear_to_srgb_v3(color, color);
} }
RNA_property_float_set_array(&but->rnapoin, but->rnaprop, color); RNA_property_float_set_array(&but->rnapoin, but->rnaprop, color);
RNA_property_update(C, &but->rnapoin, but->rnaprop); RNA_property_update(C, &but->rnapoin, but->rnaprop);
} }
else if (RNA_property_subtype(but->rnaprop) == PROP_COLOR) { else if (RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
if (gamma) { if (gamma) {
IMB_colormanagement_srgb_to_scene_linear_v3(color); IMB_colormanagement_srgb_to_scene_linear_v3(color, color);
} }
RNA_property_float_set_array(&but->rnapoin, but->rnaprop, color); RNA_property_float_set_array(&but->rnapoin, but->rnaprop, color);
RNA_property_update(C, &but->rnapoin, but->rnaprop); RNA_property_update(C, &but->rnapoin, but->rnaprop);

@ -116,7 +116,7 @@ void ui_scene_linear_to_perceptual_space(uiBut *but, float rgb[3])
* assuming it is more perceptually linear than the scene linear * assuming it is more perceptually linear than the scene linear
* space for intuitive color picking. */ * space for intuitive color picking. */
if (!ui_but_is_color_gamma(but)) { if (!ui_but_is_color_gamma(but)) {
IMB_colormanagement_scene_linear_to_color_picking_v3(rgb); IMB_colormanagement_scene_linear_to_color_picking_v3(rgb, rgb);
ui_color_picker_rgb_round(rgb); ui_color_picker_rgb_round(rgb);
} }
} }
@ -124,7 +124,7 @@ void ui_scene_linear_to_perceptual_space(uiBut *but, float rgb[3])
void ui_perceptual_to_scene_linear_space(uiBut *but, float rgb[3]) void ui_perceptual_to_scene_linear_space(uiBut *but, float rgb[3])
{ {
if (!ui_but_is_color_gamma(but)) { if (!ui_but_is_color_gamma(but)) {
IMB_colormanagement_color_picking_to_scene_linear_v3(rgb); IMB_colormanagement_color_picking_to_scene_linear_v3(rgb, rgb);
ui_color_picker_rgb_round(rgb); ui_color_picker_rgb_round(rgb);
} }
} }
@ -208,7 +208,7 @@ static void ui_update_color_picker_buts_rgb(uiBut *from_but,
* (coming from other applications, web, etc) */ * (coming from other applications, web, etc) */
copy_v3_v3(rgb_hex, rgb_scene_linear); copy_v3_v3(rgb_hex, rgb_scene_linear);
if (from_but && !ui_but_is_color_gamma(from_but)) { if (from_but && !ui_but_is_color_gamma(from_but)) {
IMB_colormanagement_scene_linear_to_srgb_v3(rgb_hex); IMB_colormanagement_scene_linear_to_srgb_v3(rgb_hex, rgb_hex);
ui_color_picker_rgb_round(rgb_hex); ui_color_picker_rgb_round(rgb_hex);
} }
@ -291,7 +291,7 @@ static void ui_colorpicker_hex_rna_cb(bContext *UNUSED(C), void *bt1, void *hexc
/* Hex code is assumed to be in sRGB space (coming from other applications, web, etc) */ /* Hex code is assumed to be in sRGB space (coming from other applications, web, etc) */
if (!ui_but_is_color_gamma(but)) { if (!ui_but_is_color_gamma(but)) {
IMB_colormanagement_srgb_to_scene_linear_v3(rgb); IMB_colormanagement_srgb_to_scene_linear_v3(rgb, rgb);
ui_color_picker_rgb_round(rgb); ui_color_picker_rgb_round(rgb);
} }
@ -777,7 +777,7 @@ static void ui_block_colorpicker(uiBlock *block,
copy_v3_v3(rgb_hex, rgba_scene_linear); copy_v3_v3(rgb_hex, rgba_scene_linear);
if (!ui_but_is_color_gamma(from_but)) { if (!ui_but_is_color_gamma(from_but)) {
IMB_colormanagement_scene_linear_to_srgb_v3(rgb_hex); IMB_colormanagement_scene_linear_to_srgb_v3(rgb_hex, rgb_hex);
ui_color_picker_rgb_round(rgb_hex); ui_color_picker_rgb_round(rgb_hex);
} }

@ -359,9 +359,7 @@ void paint_brush_color_get(struct Scene *scene,
} }
/* Gradient / Color-band colors are not considered #PROP_COLOR_GAMMA. /* Gradient / Color-band colors are not considered #PROP_COLOR_GAMMA.
* Brush colors are expected to be in sRGB though. */ * Brush colors are expected to be in sRGB though. */
IMB_colormanagement_scene_linear_to_srgb_v3(color_gr); IMB_colormanagement_scene_linear_to_srgb_v3(color, color_gr);
copy_v3_v3(color, color_gr);
} }
else { else {
copy_v3_v3(color, BKE_brush_color_get(scene, br)); copy_v3_v3(color, BKE_brush_color_get(scene, br));

@ -331,8 +331,7 @@ static Color vpaint_get_current_col(Scene *scene, VPaint *vp, bool secondary)
float color[4]; float color[4];
const float *brush_color = secondary ? BKE_brush_secondary_color_get(scene, brush) : const float *brush_color = secondary ? BKE_brush_secondary_color_get(scene, brush) :
BKE_brush_color_get(scene, brush); BKE_brush_color_get(scene, brush);
copy_v3_v3(color, brush_color); IMB_colormanagement_srgb_to_scene_linear_v3(color, brush_color);
IMB_colormanagement_srgb_to_scene_linear_v3(color);
color[3] = 1.0f; /* alpha isn't used, could even be removed to speedup paint a little */ color[3] = 1.0f; /* alpha isn't used, could even be removed to speedup paint a little */

@ -2001,7 +2001,7 @@ static void sculpt_expand_cache_initial_config_set(bContext *C,
BKE_curvemapping_init(expand_cache->brush->curve); BKE_curvemapping_init(expand_cache->brush->curve);
copy_v4_fl(expand_cache->fill_color, 1.0f); copy_v4_fl(expand_cache->fill_color, 1.0f);
copy_v3_v3(expand_cache->fill_color, BKE_brush_color_get(ss->scene, expand_cache->brush)); copy_v3_v3(expand_cache->fill_color, BKE_brush_color_get(ss->scene, expand_cache->brush));
IMB_colormanagement_srgb_to_scene_linear_v3(expand_cache->fill_color); IMB_colormanagement_srgb_to_scene_linear_v3(expand_cache->fill_color, expand_cache->fill_color);
expand_cache->scene = CTX_data_scene(C); expand_cache->scene = CTX_data_scene(C);
expand_cache->mtex = &expand_cache->brush->mtex; expand_cache->mtex = &expand_cache->brush->mtex;

@ -298,7 +298,7 @@ static int sculpt_color_filter_modal(bContext *C, wmOperator *op, const wmEvent
float fill_color[3]; float fill_color[3];
RNA_float_get_array(op->ptr, "fill_color", fill_color); RNA_float_get_array(op->ptr, "fill_color", fill_color);
IMB_colormanagement_srgb_to_scene_linear_v3(fill_color); IMB_colormanagement_srgb_to_scene_linear_v3(fill_color, fill_color);
if (filter_strength < 0.0 && !ss->filter_cache->pre_smoothed_color) { if (filter_strength < 0.0 && !ss->filter_cache->pre_smoothed_color) {
sculpt_color_presmooth_init(ss); sculpt_color_presmooth_init(ss);

@ -780,8 +780,7 @@ static int sculpt_sample_color_invoke(bContext *C, wmOperator *op, const wmEvent
} }
float color_srgb[3]; float color_srgb[3];
copy_v3_v3(color_srgb, active_vertex_color); IMB_colormanagement_scene_linear_to_srgb_v3(color_srgb, active_vertex_color);
IMB_colormanagement_scene_linear_to_srgb_v3(color_srgb);
BKE_brush_color_set(scene, brush, color_srgb); BKE_brush_color_set(scene, brush, color_srgb);
WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush); WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);

@ -124,7 +124,7 @@ static void do_paint_brush_task_cb_ex(void *__restrict userdata,
copy_v3_v3(brush_color, copy_v3_v3(brush_color,
ss->cache->invert ? BKE_brush_secondary_color_get(ss->scene, brush) : ss->cache->invert ? BKE_brush_secondary_color_get(ss->scene, brush) :
BKE_brush_color_get(ss->scene, brush)); BKE_brush_color_get(ss->scene, brush));
IMB_colormanagement_srgb_to_scene_linear_v3(brush_color); IMB_colormanagement_srgb_to_scene_linear_v3(brush_color, brush_color);
BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
SCULPT_orig_vert_data_update(&orig_data, &vd); SCULPT_orig_vert_data_update(&orig_data, &vd);

@ -76,13 +76,17 @@ BLI_INLINE unsigned char IMB_colormanagement_get_luminance_byte(const unsigned c
/** /**
* Conversion between scene linear and other color spaces. * 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_xyz_to_scene_linear(float scene_linear[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_scene_linear_to_xyz(float xyz[3], const float scene_linear[3]);
BLI_INLINE void IMB_colormanagement_rec709_to_rgb(float rgb[3], const float rec709[3]); BLI_INLINE void IMB_colormanagement_rec709_to_scene_linear(float scene_linear[3],
BLI_INLINE void IMB_colormanagement_rgb_to_rec709(float rec709[3], const float rgb[3]); const float rec709[3]);
BLI_INLINE void IMB_colormanagement_aces_to_rgb(float rgb[3], const float aces[3]); BLI_INLINE void IMB_colormanagement_scene_linear_to_rec709(float rec709[3],
BLI_INLINE void IMB_colormanagement_rgb_to_aces(float aces[3], const float rgb[3]); const float scene_linear[3]);
const float *IMB_colormanagement_get_xyz_to_rgb(void); 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, * - Color picking values 0..1 map to scene linear values in the 0..1 range,
* so that picked albedo values are energy conserving. * so that picked albedo values are energy conserving.
*/ */
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],
void IMB_colormanagement_color_picking_to_scene_linear_v3(float pixel[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 * Conversion between sRGB, for rare cases like hex color or copy/pasting
* between UI theme and scene linear colors. * between UI theme and scene linear colors.
*/ */
void IMB_colormanagement_scene_linear_to_srgb_v3(float pixel[3]); BLI_INLINE void IMB_colormanagement_scene_linear_to_srgb_v3(float srgb[3],
void IMB_colormanagement_srgb_to_scene_linear_v3(float pixel[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 * Convert pixel from scene linear to display space using default view

@ -18,12 +18,12 @@ struct ImBuf;
struct OCIO_ConstCPUProcessorRcPtr; struct OCIO_ConstCPUProcessorRcPtr;
extern float imbuf_luma_coefficients[3]; extern float imbuf_luma_coefficients[3];
extern float imbuf_xyz_to_rgb[3][3]; extern float imbuf_scene_linear_to_xyz[3][3];
extern float imbuf_rgb_to_xyz[3][3]; extern float imbuf_xyz_to_scene_linear[3][3];
extern float imbuf_xyz_to_aces[3][3]; extern float imbuf_scene_linear_to_aces[3][3];
extern float imbuf_aces_to_xyz[3][3]; extern float imbuf_aces_to_scene_linear[3][3];
extern float imbuf_xyz_to_rec709[3][3]; extern float imbuf_scene_linear_to_rec709[3][3];
extern float imbuf_rec709_to_xyz[3][3]; extern float imbuf_rec709_to_scene_linear[3][3];
#define MAX_COLORSPACE_NAME 64 #define MAX_COLORSPACE_NAME 64
#define MAX_COLORSPACE_DESCRIPTION 512 #define MAX_COLORSPACE_DESCRIPTION 512

@ -73,12 +73,12 @@ static int global_tot_looks = 0;
/* Luma coefficients and XYZ to RGB to be initialized by OCIO. */ /* Luma coefficients and XYZ to RGB to be initialized by OCIO. */
float imbuf_luma_coefficients[3] = {0.0f}; float imbuf_luma_coefficients[3] = {0.0f};
float imbuf_xyz_to_rgb[3][3] = {{0.0f}}; float imbuf_scene_linear_to_xyz[3][3] = {{0.0f}};
float imbuf_rgb_to_xyz[3][3] = {{0.0f}}; float imbuf_xyz_to_scene_linear[3][3] = {{0.0f}};
float imbuf_xyz_to_rec709[3][3] = {{0.0f}}; float imbuf_scene_linear_to_rec709[3][3] = {{0.0f}};
float imbuf_rec709_to_xyz[3][3] = {{0.0f}}; float imbuf_rec709_to_scene_linear[3][3] = {{0.0f}};
float imbuf_xyz_to_aces[3][3] = {{0.0f}}; float imbuf_scene_linear_to_aces[3][3] = {{0.0f}};
float imbuf_aces_to_xyz[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 /* lock used by pre-cached processors getters, so processor wouldn't
* be created several times * be created several times
@ -577,12 +577,14 @@ static void colormanage_load_config(OCIO_ConstConfigRcPtr *config)
OCIO_configGetDefaultLumaCoefs(config, imbuf_luma_coefficients); OCIO_configGetDefaultLumaCoefs(config, imbuf_luma_coefficients);
/* Load standard color spaces. */ /* Load standard color spaces. */
OCIO_configGetXYZtoRGB(config, imbuf_xyz_to_rgb); OCIO_configGetXYZtoSceneLinear(config, imbuf_xyz_to_scene_linear);
invert_m3_m3(imbuf_rgb_to_xyz, imbuf_xyz_to_rgb); invert_m3_m3(imbuf_scene_linear_to_xyz, imbuf_xyz_to_scene_linear);
copy_m3_m3(imbuf_xyz_to_rec709, OCIO_XYZ_TO_REC709);
invert_m3_m3(imbuf_rec709_to_xyz, imbuf_xyz_to_rec709); mul_m3_m3m3(imbuf_scene_linear_to_rec709, OCIO_XYZ_TO_REC709, imbuf_scene_linear_to_xyz);
copy_m3_m3(imbuf_aces_to_xyz, OCIO_ACES_TO_XYZ); invert_m3_m3(imbuf_rec709_to_scene_linear, imbuf_scene_linear_to_rec709);
invert_m3_m3(imbuf_xyz_to_aces, imbuf_aces_to_xyz);
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) 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)); 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) { if (!global_color_picking_state.cpu_processor_to && !global_color_picking_state.failed) {
/* Create processor if none exists. */ /* 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); BLI_mutex_unlock(&processor_lock);
} }
copy_v3_v3(color_picking, scene_linear);
if (global_color_picking_state.cpu_processor_to) { 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) { if (!global_color_picking_state.cpu_processor_from && !global_color_picking_state.failed) {
/* Create processor if none exists. */ /* 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); BLI_mutex_unlock(&processor_lock);
} }
copy_v3_v3(scene_linear, color_picking);
if (global_color_picking_state.cpu_processor_from) { 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) void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], ColorManagedDisplay *display)
{ {
OCIO_ConstCPUProcessorRcPtr *processor = display_from_scene_linear_processor(display); OCIO_ConstCPUProcessorRcPtr *processor = display_from_scene_linear_processor(display);

@ -27,38 +27,46 @@ unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char rgb[3])
return unit_float_to_uchar_clamp(val); 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(scene_linear, imbuf_rec709_to_scene_linear, rec709);
mul_v3_m3v3(rgb, imbuf_xyz_to_rgb, rgb);
} }
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_scene_linear_to_rec709, scene_linear);
mul_v3_m3v3(rec709, imbuf_xyz_to_rec709, rec709);
} }
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(srgb, imbuf_scene_linear_to_rec709, scene_linear);
mul_v3_m3v3(rgb, imbuf_xyz_to_rgb, rgb); 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); srgb_to_linearrgb_v3_v3(scene_linear, srgb);
mul_v3_m3v3(aces, imbuf_xyz_to_aces, aces); 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__ */ #endif /* __IMB_COLORMANAGEMENT_INLINE_H__ */

@ -329,7 +329,7 @@ void node_shader_gpu_tex_mapping(GPUMaterial *mat,
void get_XYZ_to_RGB_for_gpu(XYZ_to_RGB *data) void get_XYZ_to_RGB_for_gpu(XYZ_to_RGB *data)
{ {
const float *xyz_to_rgb = IMB_colormanagement_get_xyz_to_rgb(); const float *xyz_to_rgb = IMB_colormanagement_get_xyz_to_scene_linear();
data->r[0] = xyz_to_rgb[0]; data->r[0] = xyz_to_rgb[0];
data->r[1] = xyz_to_rgb[3]; data->r[1] = xyz_to_rgb[3];
data->r[2] = xyz_to_rgb[6]; data->r[2] = xyz_to_rgb[6];

@ -87,8 +87,8 @@ PyDoc_STRVAR(Color_from_scene_linear_to_srgb_doc,
" :rtype: :class:`Color`\n"); " :rtype: :class:`Color`\n");
static PyObject *Color_from_scene_linear_to_srgb(ColorObject *self) static PyObject *Color_from_scene_linear_to_srgb(ColorObject *self)
{ {
float col[3] = {self->col[0], self->col[1], self->col[2]}; float col[3];
IMB_colormanagement_scene_linear_to_srgb_v3(col); IMB_colormanagement_scene_linear_to_srgb_v3(col, self->col);
return Color_CreatePyObject(col, Py_TYPE(self)); return Color_CreatePyObject(col, Py_TYPE(self));
} }
@ -101,8 +101,8 @@ PyDoc_STRVAR(Color_from_srgb_to_scene_linear_doc,
" :rtype: :class:`Color`\n"); " :rtype: :class:`Color`\n");
static PyObject *Color_from_srgb_to_scene_linear(ColorObject *self) static PyObject *Color_from_srgb_to_scene_linear(ColorObject *self)
{ {
float col[3] = {self->col[0], self->col[1], self->col[2]}; float col[3];
IMB_colormanagement_srgb_to_scene_linear_v3(col); IMB_colormanagement_srgb_to_scene_linear_v3(col, self->col);
return Color_CreatePyObject(col, Py_TYPE(self)); return Color_CreatePyObject(col, Py_TYPE(self));
} }
@ -116,7 +116,7 @@ PyDoc_STRVAR(Color_from_scene_linear_to_xyz_d65_doc,
static PyObject *Color_from_scene_linear_to_xyz_d65(ColorObject *self) static PyObject *Color_from_scene_linear_to_xyz_d65(ColorObject *self)
{ {
float col[3]; float col[3];
IMB_colormanagement_rgb_to_xyz(col, self->col); IMB_colormanagement_scene_linear_to_xyz(col, self->col);
return Color_CreatePyObject(col, Py_TYPE(self)); return Color_CreatePyObject(col, Py_TYPE(self));
} }
@ -130,7 +130,7 @@ PyDoc_STRVAR(Color_from_xyz_d65_to_scene_linear_doc,
static PyObject *Color_from_xyz_d65_to_scene_linear(ColorObject *self) static PyObject *Color_from_xyz_d65_to_scene_linear(ColorObject *self)
{ {
float col[3]; float col[3];
IMB_colormanagement_xyz_to_rgb(col, self->col); IMB_colormanagement_xyz_to_scene_linear(col, self->col);
return Color_CreatePyObject(col, Py_TYPE(self)); return Color_CreatePyObject(col, Py_TYPE(self));
} }
@ -144,7 +144,7 @@ PyDoc_STRVAR(Color_from_scene_linear_to_aces_doc,
static PyObject *Color_from_scene_linear_to_aces(ColorObject *self) static PyObject *Color_from_scene_linear_to_aces(ColorObject *self)
{ {
float col[3]; float col[3];
IMB_colormanagement_rgb_to_aces(col, self->col); IMB_colormanagement_scene_linear_to_aces(col, self->col);
return Color_CreatePyObject(col, Py_TYPE(self)); return Color_CreatePyObject(col, Py_TYPE(self));
} }
@ -158,7 +158,7 @@ PyDoc_STRVAR(Color_from_aces_to_scene_linear_doc,
static PyObject *Color_from_aces_to_scene_linear(ColorObject *self) static PyObject *Color_from_aces_to_scene_linear(ColorObject *self)
{ {
float col[3]; float col[3];
IMB_colormanagement_aces_to_rgb(col, self->col); IMB_colormanagement_aces_to_scene_linear(col, self->col);
return Color_CreatePyObject(col, Py_TYPE(self)); return Color_CreatePyObject(col, Py_TYPE(self));
} }
@ -172,7 +172,7 @@ PyDoc_STRVAR(Color_from_scene_linear_to_rec709_linear_doc,
static PyObject *Color_from_scene_linear_to_rec709_linear(ColorObject *self) static PyObject *Color_from_scene_linear_to_rec709_linear(ColorObject *self)
{ {
float col[3]; float col[3];
IMB_colormanagement_rgb_to_rec709(col, self->col); IMB_colormanagement_scene_linear_to_rec709(col, self->col);
return Color_CreatePyObject(col, Py_TYPE(self)); return Color_CreatePyObject(col, Py_TYPE(self));
} }
@ -186,7 +186,7 @@ PyDoc_STRVAR(Color_from_rec709_linear_to_scene_linear_doc,
static PyObject *Color_from_rec709_linear_to_scene_linear(ColorObject *self) static PyObject *Color_from_rec709_linear_to_scene_linear(ColorObject *self)
{ {
float col[3]; float col[3];
IMB_colormanagement_rec709_to_rgb(col, self->col); IMB_colormanagement_rec709_to_scene_linear(col, self->col);
return Color_CreatePyObject(col, Py_TYPE(self)); return Color_CreatePyObject(col, Py_TYPE(self));
} }