Blender V4.3
BLI_math_color.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11#include "BLI_math_inline.h"
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17/* -------------------------------------------------------------------- */
21/* YCbCr */
22#define BLI_YCC_ITU_BT601 0
23#define BLI_YCC_ITU_BT709 1
24#define BLI_YCC_JFIF_0_255 2
25
26/* YUV */
27#define BLI_YUV_ITU_BT601 0
28#define BLI_YUV_ITU_BT709 1
29
32/* -------------------------------------------------------------------- */
36void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b);
37void hsv_to_rgb_v(const float hsv[3], float r_rgb[3]);
38void hsl_to_rgb(float h, float s, float l, float *r_r, float *r_g, float *r_b);
39void hsl_to_rgb_v(const float hsl[3], float r_rgb[3]);
40void hex_to_rgb(const char *hexcol, float *r_r, float *r_g, float *r_b);
41void yuv_to_rgb(float y, float u, float v, float *r_r, float *r_g, float *r_b, int colorspace);
42void ycc_to_rgb(float y, float cb, float cr, float *r_r, float *r_g, float *r_b, int colorspace);
43void cpack_to_rgb(unsigned int col, float *r_r, float *r_g, float *r_b);
44
47/* -------------------------------------------------------------------- */
51void hex_to_rgba(const char *hexcol, float *r_r, float *r_g, float *r_b, float *r_a);
52
55/* -------------------------------------------------------------------- */
59void rgb_to_yuv(float r, float g, float b, float *r_y, float *r_u, float *r_v, int colorspace);
65void rgb_to_ycc(float r, float g, float b, float *r_y, float *r_cb, float *r_cr, int colorspace);
66void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v);
67void rgb_to_hsv_v(const float rgb[3], float r_hsv[3]);
68void rgb_to_hsl(float r, float g, float b, float *r_h, float *r_s, float *r_l);
69void rgb_to_hsl_v(const float rgb[3], float r_hsl[3]);
70void rgb_to_hsl_compat(float r, float g, float b, float *r_h, float *r_s, float *r_l);
71void rgb_to_hsl_compat_v(const float rgb[3], float r_hsl[3]);
72void rgb_to_hsv_compat(float r, float g, float b, float *r_h, float *r_s, float *r_v);
73void rgb_to_hsv_compat_v(const float rgb[3], float r_hsv[3]);
74unsigned int rgb_to_cpack(float r, float g, float b);
81unsigned int hsv_to_cpack(float h, float s, float v);
82
85/* -------------------------------------------------------------------- */
89float srgb_to_linearrgb(float c);
90float linearrgb_to_srgb(float c);
91
92void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3]);
93void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3]);
94
95MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4]);
96MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4]);
97
98MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[4]);
99MINLINE void linearrgb_to_srgb_predivide_v4(float srgb[4], const float linear[4]);
100
101MINLINE unsigned short to_srgb_table_lookup(float f);
102MINLINE void linearrgb_to_srgb_ushort4(unsigned short srgb[4], const float linear[4]);
103MINLINE void srgb_to_linearrgb_uchar4(float linear[4], const unsigned char srgb[4]);
104MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned char srgb[4]);
105
106MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[3]);
107MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4]);
108
109void BLI_init_srgb_conversion(void);
110
113/* -------------------------------------------------------------------- */
117MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4]);
118MINLINE void premul_to_straight_v4(float color[4]);
119MINLINE void straight_to_premul_v4_v4(float premul[4], const float straight[4]);
120MINLINE void straight_to_premul_v4(float color[4]);
121MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4]);
122MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4]);
123
126/* -------------------------------------------------------------------- */
138int constrain_rgb(float *r, float *g, float *b);
139void minmax_rgb(short c[3]);
143void hsv_clamp_v(float hsv[3], float v_max);
144
148void rgb_float_set_hue_float_offset(float rgb[3], float hue_offset);
152void rgb_byte_set_hue_float_offset(unsigned char rgb[3], float hue_offset);
153
154void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3]);
155void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4]);
156void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3]);
157void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4]);
158
173MINLINE float rgb_to_grayscale(const float rgb[3]);
174MINLINE unsigned char rgb_to_grayscale_byte(const unsigned char rgb[3]);
175
176MINLINE int compare_rgb_uchar(const unsigned char col_a[3],
177 const unsigned char col_b[3],
178 int limit);
179
183MINLINE float dither_random_value(float s, float t);
185 unsigned char b[3], const float f[3], float dither, float s, float t);
186
187#define rgba_char_args_set_fl(col, r, g, b, a) \
188 rgba_char_args_set(col, (r) * 255, (g) * 255, (b) * 255, (a) * 255)
189
190#define rgba_float_args_set_ch(col, r, g, b, a) \
191 rgba_float_args_set(col, (r) / 255.0f, (g) / 255.0f, (b) / 255.0f, (a) / 255.0f)
192
194 unsigned char col[4], unsigned char r, unsigned char g, unsigned char b, unsigned char a);
195MINLINE void rgba_float_args_set(float col[4], float r, float g, float b, float a);
197 unsigned char col[4], unsigned char r, unsigned char g, unsigned char b, unsigned char a);
198MINLINE void cpack_cpy_3ub(unsigned char r_col[3], unsigned int pack);
199
202/* -------------------------------------------------------------------- */
206void lift_gamma_gain_to_asc_cdl(const float *lift,
207 const float *gamma,
208 const float *gain,
209 float *offset,
210 float *slope,
211 float *power);
212
215#ifdef __cplusplus
216}
217#endif
218
219#if BLI_MATH_DO_INLINE
221#endif
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
Definition math_color.cc:57
MINLINE void straight_to_premul_v4_v4(float premul[4], const float straight[4])
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned char srgb[4])
MINLINE int compare_rgb_uchar(const unsigned char col_a[3], const unsigned char col_b[3], int limit)
void rgb_to_hsl(float r, float g, float b, float *r_h, float *r_s, float *r_l)
void rgb_to_hsl_compat(float r, float g, float b, float *r_h, float *r_s, float *r_l)
void rgb_to_hsv_compat_v(const float rgb[3], float r_hsv[3])
MINLINE void rgba_float_args_set(float col[4], float r, float g, float b, float a)
MINLINE unsigned char rgb_to_grayscale_byte(const unsigned char rgb[3])
unsigned int rgb_to_cpack(float r, float g, float b)
MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4])
MINLINE void premul_to_straight_v4(float color[4])
int constrain_rgb(float *r, float *g, float *b)
void hex_to_rgba(const char *hexcol, float *r_r, float *r_g, float *r_b, float *r_a)
MINLINE void straight_to_premul_v4(float color[4])
MINLINE void rgba_uchar_args_set(unsigned char col[4], unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
MINLINE void linearrgb_to_srgb_ushort4(unsigned short srgb[4], const float linear[4])
MINLINE float rgb_to_grayscale(const float rgb[3])
unsigned int hsv_to_cpack(float h, float s, float v)
void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
MINLINE void linearrgb_to_srgb_predivide_v4(float srgb[4], const float linear[4])
void hsl_to_rgb_v(const float hsl[3], float r_rgb[3])
Definition math_color.cc:62
MINLINE void rgba_uchar_args_test_set(unsigned char col[4], unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void BLI_init_srgb_conversion(void)
void ycc_to_rgb(float y, float cb, float cr, float *r_r, float *r_g, float *r_b, int colorspace)
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:21
void minmax_rgb(short c[3])
MINLINE void srgb_to_linearrgb_uchar4(float linear[4], const unsigned char srgb[4])
void rgb_to_ycc(float r, float g, float b, float *r_y, float *r_cb, float *r_cr, int colorspace)
void rgb_to_yuv(float r, float g, float b, float *r_y, float *r_u, float *r_v, int colorspace)
Definition math_color.cc:67
void rgb_to_hsv_compat(float r, float g, float b, float *r_h, float *r_s, float *r_v)
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
MINLINE void float_to_byte_dither_v3(unsigned char b[3], const float f[3], float dither, float s, float t)
MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4])
void hsv_clamp_v(float hsv[3], float v_max)
MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4])
void hsl_to_rgb(float h, float s, float l, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:38
void rgb_byte_set_hue_float_offset(unsigned char rgb[3], float hue_offset)
float srgb_to_linearrgb(float c)
void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3])
void hex_to_rgb(const char *hexcol, float *r_r, float *r_g, float *r_b)
MINLINE void cpack_cpy_3ub(unsigned char r_col[3], unsigned int pack)
float linearrgb_to_srgb(float c)
void lift_gamma_gain_to_asc_cdl(const float *lift, const float *gamma, const float *gain, float *offset, float *slope, float *power)
MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4])
void yuv_to_rgb(float y, float u, float v, float *r_r, float *r_g, float *r_b, int colorspace)
Definition math_color.cc:91
void rgb_to_hsl_v(const float rgb[3], float r_hsl[3])
void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[3])
void cpack_to_rgb(unsigned int col, float *r_r, float *r_g, float *r_b)
void rgb_to_hsl_compat_v(const float rgb[3], float r_hsl[3])
MINLINE unsigned short to_srgb_table_lookup(float f)
void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3])
MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[4])
MINLINE float dither_random_value(float s, float t)
void rgb_float_set_hue_float_offset(float rgb[3], float hue_offset)
MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4])
#define MINLINE
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert * v
local_group_size(16, 16) .push_constant(Type b
uint col
ccl_device_inline float2 power(float2 v, float e)