diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2015-03-17 17:20:33 +0300 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2015-03-17 17:20:33 +0300 |
commit | dd38dce7f0ae604396d1e96bc49500369fdedf29 (patch) | |
tree | 2b32e776f0bb972705d2c884cb6d5ec77deaf714 /source/blender/imbuf | |
parent | 42aac45d7f0e0f43725093e97ebb8175a95aa247 (diff) |
Part 2 of D1082 by Troy Sobotka, remove our functions that do luma
calculations and use the OCIO one instead.
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/IMB_colormanagement.h | 3 | ||||
-rw-r--r-- | source/blender/imbuf/intern/colormanagement.c | 36 | ||||
-rw-r--r-- | source/blender/imbuf/intern/divers.c | 4 | ||||
-rw-r--r-- | source/blender/imbuf/intern/png.c | 4 |
4 files changed, 43 insertions, 4 deletions
diff --git a/source/blender/imbuf/IMB_colormanagement.h b/source/blender/imbuf/IMB_colormanagement.h index 262e87bedf5..9407750c039 100644 --- a/source/blender/imbuf/IMB_colormanagement.h +++ b/source/blender/imbuf/IMB_colormanagement.h @@ -71,6 +71,9 @@ void IMB_colormanagement_assign_rect_colorspace(struct ImBuf *ibuf, const char * const char *IMB_colormanagement_get_float_colorspace(struct ImBuf *ibuf); const char *IMB_colormanagement_get_rect_colorspace(struct ImBuf *ibuf); +float IMB_colormanagement_get_luminance(const float rgb[3]); +unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char[3]); + /* ** Color space transformation functions ** */ void IMB_colormanagement_transform(float *buffer, int width, int height, int channels, const char *from_colorspace, const char *to_colorspace, bool predivide); diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index 95e166b2f8b..588d81f9a75 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -90,6 +90,11 @@ 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. + */ +static float luma_coefficients[3] = { 0.2126729f, 0.7151522f, 0.0721750f }; + /* lock used by pre-cached processors getters, so processor wouldn't * be created several times * LOCK_COLORMANAGE can not be used since this mutex could be needed to @@ -545,6 +550,9 @@ static void colormanage_load_config(OCIO_ConstConfigRcPtr *config) colormanage_look_add(name, process_space, false); } + + /* Load luminance coefficients. */ + OCIO_configGetDefaultLumaCoefs(config, luma_coefficients); } static void colormanage_free_config(void) @@ -1222,6 +1230,34 @@ const char *IMB_colormanagement_get_rect_colorspace(ImBuf *ibuf) return ibuf->rect_colorspace->name; } +/* Convert a float RGB triplet to the correct luminance weighted average. + * + * Grayscale, or Luma is a distillation of RGB data values down to a weighted average + * based on the luminance positions of the red, green, and blue primaries. + * Given that the internal reference space may be arbitrarily set, any + * effort to glean the luminance coefficients must be aware of the reference + * space primaries. + * + * See http://wiki.blender.org/index.php/User:Nazg-gul/ColorManagement#Luminance + */ + +float IMB_colormanagement_get_luminance(const float rgb[3]) +{ + return dot_v3v3(luma_coefficients, rgb); +} + +/* Byte equivalent of IMB_colormanagement_get_luminance(). */ +unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char rgb[3]) +{ + float rgbf[3]; + + rgbf[0] = (float) rgb[0] / 255.0f; + rgbf[1] = (float) rgb[1] / 255.0f; + rgbf[2] = (float) rgb[2] / 255.0f; + + return FTOCHAR(dot_v3v3(luma_coefficients, rgbf)); +} + /*********************** Threaded display buffer transform routines *************************/ typedef struct DisplayBufferThread { diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c index 65abf22ff2c..3417fe2fc1d 100644 --- a/source/blender/imbuf/intern/divers.c +++ b/source/blender/imbuf/intern/divers.c @@ -775,12 +775,12 @@ void IMB_color_to_bw(ImBuf *ibuf) if (rct_fl) { for (i = ibuf->x * ibuf->y; i > 0; i--, rct_fl += 4) - rct_fl[0] = rct_fl[1] = rct_fl[2] = rgb_to_grayscale(rct_fl); + rct_fl[0] = rct_fl[1] = rct_fl[2] = IMB_colormanagement_get_luminance(rct_fl); } if (rct) { for (i = ibuf->x * ibuf->y; i > 0; i--, rct += 4) - rct[0] = rct[1] = rct[2] = rgb_to_grayscale_byte(rct); + rct[0] = rct[1] = rct[2] = IMB_colormanagement_get_luminance_byte(rct); } } diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index 683bdabcd6c..f3ff6659e1c 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -312,7 +312,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) rgb[0] = chanel_colormanage_cb(from_straight[0]); rgb[1] = chanel_colormanage_cb(from_straight[1]); rgb[2] = chanel_colormanage_cb(from_straight[2]); - to16[0] = ftoshort(rgb_to_bw(rgb)); + to16[0] = ftoshort(IMB_colormanagement_get_luminance(rgb)); to16++; from_float += 4; } } @@ -321,7 +321,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) rgb[0] = chanel_colormanage_cb(from_float[0]); rgb[1] = chanel_colormanage_cb(from_float[1]); rgb[2] = chanel_colormanage_cb(from_float[2]); - to16[0] = ftoshort(rgb_to_bw(rgb)); + to16[0] = ftoshort(IMB_colormanagement_get_luminance(rgb)); to16++; from_float += 3; } } |