Blender  V2.93
colormanagement_inline.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2015 by Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #ifndef __IMB_COLORMANAGEMENT_INLINE_C__
25 #define __IMB_COLORMANAGEMENT_INLINE_C__
26 
27 #include "BLI_math_vector.h"
29 
30 /* Convert a float RGB triplet to the correct luminance weighted average.
31  *
32  * Grayscale, or Luma is a distillation of RGB data values down to a weighted average
33  * based on the luminance positions of the red, green, and blue primaries.
34  * Given that the internal reference space may be arbitrarily set, any
35  * effort to glean the luminance coefficients must be aware of the reference
36  * space primaries.
37  *
38  * See http://wiki.blender.org/index.php/User:Nazg-gul/ColorManagement#Luminance
39  */
40 
41 float IMB_colormanagement_get_luminance(const float rgb[3])
42 {
43  return dot_v3v3(imbuf_luma_coefficients, rgb);
44 }
45 
46 /* Byte equivalent of IMB_colormanagement_get_luminance(). */
47 unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char rgb[3])
48 {
49  float rgbf[3];
50  float val;
51 
52  rgb_uchar_to_float(rgbf, rgb);
53  val = dot_v3v3(imbuf_luma_coefficients, rgbf);
54 
55  return unit_float_to_uchar_clamp(val);
56 }
57 
58 void IMB_colormangement_xyz_to_rgb(float rgb[3], const float xyz[3])
59 {
60  mul_v3_m3v3(rgb, imbuf_xyz_to_rgb, xyz);
61 }
62 
63 void IMB_colormangement_rgb_to_xyz(float xyz[3], const float rgb[3])
64 {
65  mul_v3_m3v3(xyz, imbuf_rgb_to_xyz, rgb);
66 }
67 
68 #endif /* __IMB_COLORMANAGEMENT_INLINE_H__ */
void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
Definition: math_color.c:407
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
Definition: math_matrix.c:901
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
float imbuf_luma_coefficients[3]
float imbuf_rgb_to_xyz[3][3]
float imbuf_xyz_to_rgb[3][3]
float IMB_colormanagement_get_luminance(const float rgb[3])
unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char rgb[3])
void IMB_colormangement_xyz_to_rgb(float rgb[3], const float xyz[3])
void IMB_colormangement_rgb_to_xyz(float xyz[3], const float rgb[3])
MINLINE unsigned char unit_float_to_uchar_clamp(float val)