Blender V5.3
BLI_math_color_c.hh
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
10
11#include "BLI_math_inline.hh"
12
13namespace blender {
14
15/* -------------------------------------------------------------------- */
18
19/* YCbCr */
20#define BLI_YCC_ITU_BT601 0
21#define BLI_YCC_ITU_BT709 1
22#define BLI_YCC_JFIF_0_255 2
23
24/* YUV */
25#define BLI_YUV_ITU_BT601 0
26#define BLI_YUV_ITU_BT709 1
27
29
30/* -------------------------------------------------------------------- */
33
34void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b);
35void hsv_to_rgb_v(const float hsv[3], float r_rgb[3]);
36void hsl_to_rgb(float h, float s, float l, float *r_r, float *r_g, float *r_b);
37void hsl_to_rgb_v(const float hsl[3], float r_rgb[3]);
38void hex_to_rgb(const char *hexcol, float *r_r, float *r_g, float *r_b);
39void yuv_to_rgb(float y, float u, float v, float *r_r, float *r_g, float *r_b, int colorspace);
40void ycc_to_rgb(float y, float cb, float cr, float *r_r, float *r_g, float *r_b, int colorspace);
41void cpack_to_rgb(unsigned int col, float *r_r, float *r_g, float *r_b);
42
44
45/* -------------------------------------------------------------------- */
48
49bool hex_to_rgba(const char *hexcol, float *r_r, float *r_g, float *r_b, float *r_a);
50
52
53/* -------------------------------------------------------------------- */
56
57void rgb_to_yuv(float r, float g, float b, float *r_y, float *r_u, float *r_v, int colorspace);
63void rgb_to_ycc(float r, float g, float b, float *r_y, float *r_cb, float *r_cr, int colorspace);
64void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v);
65void rgb_to_hsv_v(const float rgb[3], float r_hsv[3]);
66void rgb_to_hsl(float r, float g, float b, float *r_h, float *r_s, float *r_l);
67void rgb_to_hsl_v(const float rgb[3], float r_hsl[3]);
68void rgb_to_hsl_compat(float r, float g, float b, float *r_h, float *r_s, float *r_l);
69void rgb_to_hsl_compat_v(const float rgb[3], float r_hsl[3]);
70void rgb_to_hsv_compat(float r, float g, float b, float *r_h, float *r_s, float *r_v);
71void rgb_to_hsv_compat_v(const float rgb[3], float r_hsv[3]);
72unsigned int rgb_to_cpack(float r, float g, float b);
79unsigned int hsv_to_cpack(float h, float s, float v);
80
82
83/* -------------------------------------------------------------------- */
86
87float srgb_to_linearrgb(float c);
88float linearrgb_to_srgb(float c);
89
90void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3]);
91void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3]);
92
93MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4]);
94MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4]);
95
96MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[4]);
97MINLINE void linearrgb_to_srgb_predivide_v4(float srgb[4], const float linear[4]);
98
99MINLINE void srgb_to_linearrgb_uchar4(float linear[4], const unsigned char srgb[4]);
100MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned char srgb[4]);
101
102MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[3]);
103MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4]);
104
105/* Convert an array with optional 3x3 matrix transform, for additional SIMD optimizations. */
106void linearrgb_to_srgb_uchar4_n(unsigned char (*srgb)[4],
107 const float (*linear)[4],
108 int size,
109 const float (*matrix)[3] = nullptr);
110
112
114
115/* -------------------------------------------------------------------- */
118
119MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4]);
120MINLINE void premul_to_straight_v4(float color[4]);
121MINLINE void straight_to_premul_v4_v4(float premul[4], const float straight[4]);
122MINLINE void straight_to_premul_v4(float color[4]);
123MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4]);
124MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4]);
125
127
128/* -------------------------------------------------------------------- */
131
135void hsv_clamp_v(float hsv[3], float v_max);
136
140void rgb_float_set_hue_float_offset(float rgb[3], float hue_offset);
144void rgb_byte_set_hue_float_offset(unsigned char rgb[3], float hue_offset);
145
146MINLINE void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3]);
147MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4]);
148MINLINE void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3]);
149MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4]);
150
157MINLINE float srgb_to_grayscale(const float rgb[3]);
158MINLINE unsigned char srgb_to_grayscale_byte(const unsigned char rgb[3]);
159
160MINLINE int compare_rgb_uchar(const unsigned char col_a[3],
161 const unsigned char col_b[3],
162 int limit);
163
170MINLINE float dither_random_value(int x, int y);
172 unsigned char b[3], const float f[3], float dither, int x, int y);
173
174#define rgba_char_args_set_fl(col, r, g, b, a) \
175 rgba_char_args_set(col, (r) * 255, (g) * 255, (b) * 255, (a) * 255)
176
177#define rgba_float_args_set_ch(col, r, g, b, a) \
178 rgba_float_args_set(col, (r) / 255.0f, (g) / 255.0f, (b) / 255.0f, (a) / 255.0f)
179
181 unsigned char col[4], unsigned char r, unsigned char g, unsigned char b, unsigned char a);
182MINLINE void rgba_float_args_set(float col[4], float r, float g, float b, float a);
184 unsigned char col[4], unsigned char r, unsigned char g, unsigned char b, unsigned char a);
185MINLINE void cpack_cpy_3ub(unsigned char r_col[3], unsigned int pack);
186
188
189} // namespace blender
190
191#if BLI_MATH_DO_INLINE
193#endif
#define MINLINE
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
float linearrgb_to_srgb(float c)
void hsl_to_rgb(float4 hsl, float4 &outcol)
void rgb_to_hsv(float4 rgb, float4 &outcol)
void hsv_to_rgb(float4 hsv, float4 &outcol)
void rgb_to_hsl(float4 rgb, float4 &outcol)
BMesh Iterators.
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[3])
void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
void rgb_float_set_hue_float_offset(float rgb[3], float hue_offset)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void cpack_to_rgb(unsigned int col, float *r_r, float *r_g, float *r_b)
MINLINE unsigned char srgb_to_grayscale_byte(const unsigned char rgb[3])
float srgb_to_linearrgb(float c)
MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4])
void ycc_to_rgb(float y, float cb, float cr, float *r_r, float *r_g, float *r_b, int colorspace)
MINLINE void srgb_to_linearrgb_uchar4(float linear[4], const unsigned char srgb[4])
void rgb_byte_set_hue_float_offset(unsigned char rgb[3], float hue_offset)
void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3])
void rgb_to_hsl_v(const float rgb[3], float r_hsl[3])
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_v(const float rgb[3], float r_hsv[3])
void BLI_init_srgb_conversion()
void rgb_to_hsv_compat_v(const float rgb[3], float r_hsv[3])
unsigned int hsv_to_cpack(float h, float s, float v)
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
MINLINE void straight_to_premul_v4_v4(float premul[4], const float straight[4])
ATTR_WARN_UNUSED_RESULT const BMVert * v
unsigned int rgb_to_cpack(float r, float g, float b)
MINLINE void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3])
MINLINE float srgb_to_grayscale(const float rgb[3])
void rgb_to_ycc(float r, float g, float b, float *r_y, float *r_cb, float *r_cr, int colorspace)
MINLINE float dither_random_value(int x, int y)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
Definition math_color.cc:61
void hsv_clamp_v(float hsv[3], float v_max)
MINLINE void premul_to_straight_v4(float color[4])
MINLINE void linearrgb_to_srgb_predivide_v4(float srgb[4], const float linear[4])
void rgb_to_hsl_compat_v(const float rgb[3], float r_hsl[3])
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:71
MINLINE void float_to_byte_dither_v3(unsigned char b[3], const float f[3], float dither, int x, int y)
void hsl_to_rgb_v(const float hsl[3], float r_rgb[3])
Definition math_color.cc:66
MINLINE void cpack_cpy_3ub(unsigned char r_col[3], unsigned int pack)
MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4])
MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[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:95
bool hex_to_rgba(const char *hexcol, float *r_r, float *r_g, float *r_b, float *r_a)
void rgb_to_hsl_compat(float r, float g, float b, float *r_h, float *r_s, float *r_l)
void hex_to_rgb(const char *hexcol, float *r_r, float *r_g, float *r_b)
MINLINE void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
void rgb_to_hsv_compat(float r, float g, float b, float *r_h, float *r_s, float *r_v)
MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4])
MINLINE int compare_rgb_uchar(const unsigned char col_a[3], const unsigned char col_b[3], int limit)
MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4])
MINLINE void rgba_uchar_args_test_set(unsigned char col[4], unsigned char r, unsigned char g, unsigned char b, unsigned char a)
MINLINE void straight_to_premul_v4(float color[4])
void linearrgb_to_srgb_uchar4_n(unsigned char(*srgb)[4], const float(*linear)[4], int size, const float(*matrix)[3]=nullptr)
MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned char srgb[4])
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4])
MINLINE void rgba_float_args_set(float col[4], float r, float g, float b, float a)