Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2018-10-12 17:42:34 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-12-13 21:25:46 +0300
commitf527ce5b2f5bb300a7fe55db33d1e3a4da8051c7 (patch)
treedf1226d253b2a7c2e66cba75b37f9ec0a475c288 /source/blender/imbuf
parent6601a89650f92454aa57bc01bedebd4086f6d98d (diff)
Color management: add OCIO aware utility functions for transform to/from XYZ.
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/IMB_colormanagement.h5
-rw-r--r--source/blender/imbuf/intern/IMB_colormanagement_intern.h2
-rw-r--r--source/blender/imbuf/intern/colormanagement.c38
-rw-r--r--source/blender/imbuf/intern/colormanagement_inline.c10
4 files changed, 51 insertions, 4 deletions
diff --git a/source/blender/imbuf/IMB_colormanagement.h b/source/blender/imbuf/IMB_colormanagement.h
index 29e54158f4b..437a699208b 100644
--- a/source/blender/imbuf/IMB_colormanagement.h
+++ b/source/blender/imbuf/IMB_colormanagement.h
@@ -71,6 +71,8 @@ const char *IMB_colormanagement_get_rect_colorspace(struct ImBuf *ibuf);
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3]);
BLI_INLINE unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char[3]);
+BLI_INLINE void IMB_colormangement_xyz_to_rgb(float rgb[3], const float xyz[3]);
+BLI_INLINE void IMB_colormangement_rgb_to_xyz(float xyz[3], const float rgb[3]);
/* ** Color space transformation functions ** */
void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
@@ -99,6 +101,9 @@ void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, in
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_srgb_v3(float pixel[3]);
+void IMB_colormanagement_srgb_to_scene_linear_v3(float pixel[3]);
+
void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], struct ColorManagedDisplay *display);
void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], struct ColorManagedDisplay *display);
diff --git a/source/blender/imbuf/intern/IMB_colormanagement_intern.h b/source/blender/imbuf/intern/IMB_colormanagement_intern.h
index 84e0bd6c599..ee3d207a8db 100644
--- a/source/blender/imbuf/intern/IMB_colormanagement_intern.h
+++ b/source/blender/imbuf/intern/IMB_colormanagement_intern.h
@@ -42,6 +42,8 @@ struct OCIO_ConstProcessorRcPtr;
struct ImBuf;
extern float imbuf_luma_coefficients[3];
+extern float imbuf_xyz_to_rgb[3][3];
+extern float imbuf_rgb_to_xyz[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 f2244b6ab5c..395bb90d686 100644
--- a/source/blender/imbuf/intern/colormanagement.c
+++ b/source/blender/imbuf/intern/colormanagement.c
@@ -93,10 +93,12 @@ static int global_tot_display = 0;
static int global_tot_view = 0;
static int global_tot_looks = 0;
-/* Set to ITU-BT.709 / sRGB primaries weight. Brute force stupid, but only
- * option with no colormanagement in place.
- */
-float imbuf_luma_coefficients[3] = { 0.2126f, 0.7152f, 0.0722f };
+/* 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_linear_srgb[3][3] = {{0.0f}};
+float imbuf_linear_srgb_to_xyz[3][3] = {{0.0f}};
/* lock used by pre-cached processors getters, so processor wouldn't
* be created several times
@@ -563,6 +565,10 @@ static void colormanage_load_config(OCIO_ConstConfigRcPtr *config)
/* Load luminance coefficients. */
OCIO_configGetDefaultLumaCoefs(config, imbuf_luma_coefficients);
+ OCIO_configGetXYZtoRGB(config, imbuf_xyz_to_rgb);
+ invert_m3_m3(imbuf_rgb_to_xyz, imbuf_xyz_to_rgb);
+ copy_m3_m3(imbuf_xyz_to_linear_srgb, OCIO_XYZ_TO_LINEAR_SRGB);
+ invert_m3_m3(imbuf_linear_srgb_to_xyz, imbuf_xyz_to_linear_srgb);
}
static void colormanage_free_config(void)
@@ -1927,6 +1933,14 @@ void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, in
}
}
+/* Conversion between color picking role. Typically we would expect such a
+ * requirements:
+ * - It is approximately perceptually linear, so that the HSV numbers and
+ * the HSV cube/circle have an intuitive distribution.
+ * - It has the same gamut as the scene linear color space.
+ * - 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])
{
if (!global_color_picking_state.processor_to && !global_color_picking_state.failed) {
@@ -1975,6 +1989,22 @@ void IMB_colormanagement_color_picking_to_scene_linear_v3(float pixel[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])
+{
+ mul_m3_v3(imbuf_rgb_to_xyz, pixel);
+ mul_m3_v3(imbuf_xyz_to_linear_srgb, 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_linear_srgb_to_xyz, pixel);
+ mul_m3_v3(imbuf_xyz_to_rgb, pixel);
+}
+
/* convert pixel from scene linear to display space using default view
* used by performance-critical areas such as color-related widgets where we want to reduce
* amount of per-widget allocations
diff --git a/source/blender/imbuf/intern/colormanagement_inline.c b/source/blender/imbuf/intern/colormanagement_inline.c
index 4a55f8f86ae..37ef8779f58 100644
--- a/source/blender/imbuf/intern/colormanagement_inline.c
+++ b/source/blender/imbuf/intern/colormanagement_inline.c
@@ -62,4 +62,14 @@ unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char rgb[3])
return unit_float_to_uchar_clamp(val);
}
+void IMB_colormangement_xyz_to_rgb(float rgb[3], const float xyz[3])
+{
+ mul_v3_m3v3(rgb, imbuf_xyz_to_rgb, xyz);
+}
+
+void IMB_colormangement_rgb_to_xyz(float xyz[3], const float rgb[3])
+{
+ mul_v3_m3v3(xyz, imbuf_rgb_to_xyz, rgb);
+}
+
#endif /* __IMB_COLORMANAGEMENT_INLINE_H__ */