Blender V5.0
BLI_math_color.h File Reference

Go to the source code of this file.

Macros

Defines
#define BLI_YCC_ITU_BT601   0
#define BLI_YCC_ITU_BT709   1
#define BLI_YCC_JFIF_0_255   2
#define BLI_YUV_ITU_BT601   0
#define BLI_YUV_ITU_BT709   1

Functions

Conversion to RGB
void hsv_to_rgb (float h, float s, float v, float *r_r, float *r_g, float *r_b)
void hsv_to_rgb_v (const float hsv[3], float r_rgb[3])
void hsl_to_rgb (float h, float s, float l, float *r_r, float *r_g, float *r_b)
void hsl_to_rgb_v (const float hsl[3], float r_rgb[3])
void hex_to_rgb (const char *hexcol, float *r_r, float *r_g, float *r_b)
void yuv_to_rgb (float y, float u, float v, float *r_r, float *r_g, float *r_b, int colorspace)
void ycc_to_rgb (float y, float cb, float cr, float *r_r, float *r_g, float *r_b, int colorspace)
void cpack_to_rgb (unsigned int col, float *r_r, float *r_g, float *r_b)
Conversion to RGBA
void hex_to_rgba (const char *hexcol, float *r_r, float *r_g, float *r_b, float *r_a)
Conversion from RGB
void rgb_to_yuv (float r, float g, float b, float *r_y, float *r_u, float *r_v, int colorspace)
void rgb_to_ycc (float r, float g, float b, float *r_y, float *r_cb, float *r_cr, int colorspace)
void rgb_to_hsv (float r, float g, float b, float *r_h, float *r_s, float *r_v)
void rgb_to_hsv_v (const float rgb[3], float r_hsv[3])
void rgb_to_hsl (float r, float g, float b, float *r_h, float *r_s, float *r_l)
void rgb_to_hsl_v (const float rgb[3], float r_hsl[3])
void rgb_to_hsl_compat (float r, float g, float b, float *r_h, float *r_s, float *r_l)
void rgb_to_hsl_compat_v (const float rgb[3], float r_hsl[3])
void rgb_to_hsv_compat (float r, float g, float b, float *r_h, float *r_s, float *r_v)
void rgb_to_hsv_compat_v (const float rgb[3], float r_hsv[3])
unsigned int rgb_to_cpack (float r, float g, float b)
unsigned int hsv_to_cpack (float h, float s, float v)
Profile Transformations
float srgb_to_linearrgb (float c)
float linearrgb_to_srgb (float c)
void srgb_to_linearrgb_v3_v3 (float linear[3], const float srgb[3])
void linearrgb_to_srgb_v3_v3 (float srgb[3], const float linear[3])
MINLINE void srgb_to_linearrgb_v4 (float linear[4], const float srgb[4])
MINLINE void linearrgb_to_srgb_v4 (float srgb[4], const float linear[4])
MINLINE void srgb_to_linearrgb_predivide_v4 (float linear[4], const float srgb[4])
MINLINE void linearrgb_to_srgb_predivide_v4 (float srgb[4], const float linear[4])
MINLINE unsigned short to_srgb_table_lookup (float f)
MINLINE void linearrgb_to_srgb_ushort4 (unsigned short srgb[4], const float linear[4])
MINLINE void srgb_to_linearrgb_uchar4 (float linear[4], const unsigned char srgb[4])
MINLINE void srgb_to_linearrgb_uchar4_predivide (float linear[4], const unsigned char srgb[4])
MINLINE void linearrgb_to_srgb_uchar3 (unsigned char srgb[3], const float linear[3])
MINLINE void linearrgb_to_srgb_uchar4 (unsigned char srgb[4], const float linear[4])
void BLI_init_srgb_conversion (void)
Alpha Transformations
MINLINE void premul_to_straight_v4_v4 (float straight[4], const float premul[4])
MINLINE void premul_to_straight_v4 (float color[4])
MINLINE void straight_to_premul_v4_v4 (float premul[4], const float straight[4])
MINLINE void straight_to_premul_v4 (float color[4])
MINLINE void straight_uchar_to_premul_float (float result[4], const unsigned char color[4])
MINLINE void premul_float_to_straight_uchar (unsigned char *result, const float color[4])

Other

#define rgba_char_args_set_fl(col, r, g, b, a)
#define rgba_float_args_set_ch(col, r, g, b, a)
void hsv_clamp_v (float hsv[3], float v_max)
void rgb_float_set_hue_float_offset (float rgb[3], float hue_offset)
void rgb_byte_set_hue_float_offset (unsigned char rgb[3], float hue_offset)
MINLINE void rgb_uchar_to_float (float r_col[3], const unsigned char col_ub[3])
MINLINE void rgba_uchar_to_float (float r_col[4], const unsigned char col_ub[4])
MINLINE void rgb_float_to_uchar (unsigned char r_col[3], const float col_f[3])
MINLINE void rgba_float_to_uchar (unsigned char r_col[4], const float col_f[4])
MINLINE float srgb_to_grayscale (const float rgb[3])
MINLINE unsigned char srgb_to_grayscale_byte (const unsigned char rgb[3])
MINLINE int compare_rgb_uchar (const unsigned char col_a[3], const unsigned char col_b[3], int limit)
MINLINE float dither_random_value (int x, int y)
MINLINE void float_to_byte_dither_v3 (unsigned char b[3], const float f[3], float dither, int x, int y)
MINLINE void rgba_uchar_args_set (unsigned char col[4], unsigned char r, unsigned char g, unsigned char b, unsigned char a)
MINLINE void rgba_float_args_set (float col[4], float r, float g, float b, float a)
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 cpack_cpy_3ub (unsigned char r_col[3], unsigned int pack)

Macro Definition Documentation

◆ BLI_YCC_ITU_BT601

◆ BLI_YCC_ITU_BT709

◆ BLI_YCC_JFIF_0_255

◆ BLI_YUV_ITU_BT601

#define BLI_YUV_ITU_BT601   0

Definition at line 23 of file BLI_math_color.h.

Referenced by rgb_to_yuv(), and yuv_to_rgb().

◆ BLI_YUV_ITU_BT709

◆ rgba_char_args_set_fl

#define rgba_char_args_set_fl ( col,
r,
g,
b,
a )
Value:
rgba_char_args_set(col, (r) * 255, (g) * 255, (b) * 255, (a) * 255)
uint col

Definition at line 168 of file BLI_math_color.h.

◆ rgba_float_args_set_ch

#define rgba_float_args_set_ch ( col,
r,
g,
b,
a )
Value:
rgba_float_args_set(col, (r) / 255.0f, (g) / 255.0f, (b) / 255.0f, (a) / 255.0f)
MINLINE void rgba_float_args_set(float col[4], float r, float g, float b, float a)

Definition at line 171 of file BLI_math_color.h.

Referenced by widgetbase_set_uniform_colors_ubv().

Function Documentation

◆ BLI_init_srgb_conversion()

◆ compare_rgb_uchar()

MINLINE int compare_rgb_uchar ( const unsigned char col_a[3],
const unsigned char col_b[3],
int limit )

Definition at line 240 of file math_color_inline.cc.

References abs, b, and MINLINE.

◆ cpack_cpy_3ub()

MINLINE void cpack_cpy_3ub ( unsigned char r_col[3],
unsigned int pack )

Definition at line 202 of file math_color_inline.cc.

References MINLINE.

◆ cpack_to_rgb()

void cpack_to_rgb ( unsigned int col,
float * r_r,
float * r_g,
float * r_b )

Definition at line 408 of file math_color.cc.

References col, and float.

Referenced by BKE_palette_from_hash().

◆ dither_random_value()

MINLINE float dither_random_value ( int x,
int y )

Returns triangle noise in [-1..+1) range, given integer pixel coordinates. Triangle distribution which gives a more final uniform noise, see "Banding in Games: A Noisy Rant" by Mikkel Gjoel (slide 27) https://loopit.dk/banding_in_games.pdf

Definition at line 268 of file math_color_inline.cc.

References fabsf, hash_iqint3_f(), MINLINE, signf(), sqrtf, v, x, and y.

Referenced by float_to_byte_dither_v3(), float_to_byte_dither_v4(), and ushort_to_byte_dither_v4().

◆ float_to_byte_dither_v3()

MINLINE void float_to_byte_dither_v3 ( unsigned char b[3],
const float f[3],
float dither,
int x,
int y )

◆ hex_to_rgb()

void hex_to_rgb ( const char * hexcol,
float * r_r,
float * r_g,
float * r_b )

Definition at line 185 of file math_color.cc.

References hex_to_rgba().

Referenced by BKE_gpencil_palette_ensure().

◆ hex_to_rgba()

void hex_to_rgba ( const char * hexcol,
float * r_r,
float * r_g,
float * r_b,
float * r_a )

Definition at line 190 of file math_color.cc.

References CLAMP, and float.

Referenced by hex_to_rgb(), and ui_colorpicker_hex_rna_cb().

◆ hsl_to_rgb()

◆ hsl_to_rgb_v()

void hsl_to_rgb_v ( const float hsl[3],
float r_rgb[3] )

◆ hsv_clamp_v()

void hsv_clamp_v ( float hsv[3],
float v_max )

Clamp hsv to usable values.

Definition at line 368 of file math_color.cc.

References CLAMP, floorf, and UNLIKELY.

◆ hsv_to_cpack()

unsigned int hsv_to_cpack ( float h,
float s,
float v )

We define a 'cpack' here as a (3 byte color code) number that can be expressed like 0xFFAA66 or so. For that reason it is sensitive for endianness... with this function it works correctly.

See also
imm_cpack

Definition at line 377 of file math_color.cc.

References b, col, hsv_to_rgb(), and v.

◆ hsv_to_rgb()

◆ hsv_to_rgb_v()

◆ linearrgb_to_srgb()

◆ linearrgb_to_srgb_predivide_v4()

MINLINE void linearrgb_to_srgb_predivide_v4 ( float srgb[4],
const float linear[4] )

◆ linearrgb_to_srgb_uchar3()

MINLINE void linearrgb_to_srgb_uchar3 ( unsigned char srgb[3],
const float linear[3] )

◆ linearrgb_to_srgb_uchar4()

◆ linearrgb_to_srgb_ushort4()

MINLINE void linearrgb_to_srgb_ushort4 ( unsigned short srgb[4],
const float linear[4] )

◆ linearrgb_to_srgb_v3_v3()

◆ linearrgb_to_srgb_v4()

◆ premul_float_to_straight_uchar()

◆ premul_to_straight_v4()

MINLINE void premul_to_straight_v4 ( float color[4])

Definition at line 307 of file math_color_inline.cc.

References MINLINE, and premul_to_straight_v4_v4().

Referenced by project_paint_uvpixel_init().

◆ premul_to_straight_v4_v4()

◆ rgb_byte_set_hue_float_offset()

void rgb_byte_set_hue_float_offset ( unsigned char rgb[3],
float hue_offset )

Applies an HUE offset to a byte RGB color.

Definition at line 692 of file math_color.cc.

References rgb_float_set_hue_float_offset(), rgb_float_to_uchar(), and rgb_uchar_to_float().

Referenced by blender::ed::vse::color3ubv_from_seq().

◆ rgb_float_set_hue_float_offset()

void rgb_float_set_hue_float_offset ( float rgb[3],
float hue_offset )

Applies an HUE offset to a float RGB color.

Definition at line 675 of file math_color.cc.

References hsv_to_rgb(), and rgb_to_hsv().

Referenced by rgb_byte_set_hue_float_offset().

◆ rgb_float_to_uchar()

◆ rgb_to_cpack()

◆ rgb_to_hsl()

◆ rgb_to_hsl_compat()

void rgb_to_hsl_compat ( float r,
float g,
float b,
float * r_h,
float * r_s,
float * r_l )

Definition at line 292 of file math_color.cc.

References b, fabsf, and rgb_to_hsl().

Referenced by rgb_to_hsl_compat_v().

◆ rgb_to_hsl_compat_v()

void rgb_to_hsl_compat_v ( const float rgb[3],
float r_hsl[3] )

◆ rgb_to_hsl_v()

◆ rgb_to_hsv()

◆ rgb_to_hsv_compat()

void rgb_to_hsv_compat ( float r,
float g,
float b,
float * r_h,
float * r_s,
float * r_v )

Definition at line 333 of file math_color.cc.

References b, fabsf, and rgb_to_hsv().

Referenced by rgb_to_hsv_compat_v().

◆ rgb_to_hsv_compat_v()

void rgb_to_hsv_compat_v ( const float rgb[3],
float r_hsv[3] )

◆ rgb_to_hsv_v()

◆ rgb_to_ycc()

void rgb_to_ycc ( float r,
float g,
float b,
float * r_y,
float * r_cb,
float * r_cr,
int colorspace )

The RGB inputs are supposed gamma corrected and in the range 0 - 1.0f

Output YCC have a range of 16-235 and 16-240 except with JFIF_0_255 where the range is 0-255.

Definition at line 115 of file math_color.cc.

References b, BLI_assert_msg, BLI_YCC_ITU_BT601, BLI_YCC_ITU_BT709, BLI_YCC_JFIF_0_255, and y.

Referenced by blender::nodes::node_composite_chroma_matte_cc::chroma_matte(), blender::nodes::node_composite_channel_matte_cc::compute_channels(), blender::nodes::node_composite_distance_matte_cc::distance_key(), blender::nodes::node_composite_separate_color_cc::node_build_multi_function(), scopes_update_cb(), and TEST().

◆ rgb_to_yuv()

◆ rgb_uchar_to_float()

◆ rgba_float_args_set()

◆ rgba_float_to_uchar()

◆ rgba_uchar_args_set()

MINLINE void rgba_uchar_args_set ( unsigned char col[4],
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a )

Definition at line 173 of file math_color_inline.cc.

References b, col, and MINLINE.

Referenced by action_group_colors_sync().

◆ rgba_uchar_args_test_set()

MINLINE void rgba_uchar_args_test_set ( unsigned char col[4],
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a )

Definition at line 191 of file math_color_inline.cc.

References b, col, and MINLINE.

◆ rgba_uchar_to_float()

MINLINE void rgba_uchar_to_float ( float r_col[4],
const unsigned char col_ub[4] )

◆ srgb_to_grayscale()

MINLINE float srgb_to_grayscale ( const float rgb[3])

Compute luminance using Rec.709 primaries, for sRGB and linear Rec.709.

Only use for colors known to be in sRGB space, like user interface and themes. Scene colors should use IMB_colormanagement_get_luminance instead.

Definition at line 218 of file math_color_inline.cc.

References MINLINE.

Referenced by button2d_draw_intern(), ED_view3d_text_colors_get(), file_draw_preview(), file_draw_special_image(), ui_tooltip_region_draw_cb(), and widget_swatch().

◆ srgb_to_grayscale_byte()

◆ srgb_to_linearrgb()

float srgb_to_linearrgb ( float c)

Definition at line 417 of file math_color.cc.

References powf.

Referenced by BLI_init_srgb_conversion(), image_buf_fill_checker_slice(), imb_save_openexr_half(), and TEST().

◆ srgb_to_linearrgb_predivide_v4()

MINLINE void srgb_to_linearrgb_predivide_v4 ( float linear[4],
const float srgb[4] )

◆ srgb_to_linearrgb_uchar4()

◆ srgb_to_linearrgb_uchar4_predivide()

MINLINE void srgb_to_linearrgb_uchar4_predivide ( float linear[4],
const unsigned char srgb[4] )

◆ srgb_to_linearrgb_v3_v3()

◆ srgb_to_linearrgb_v4()

◆ straight_to_premul_v4()

◆ straight_to_premul_v4_v4()

MINLINE void straight_to_premul_v4_v4 ( float premul[4],
const float straight[4] )

◆ straight_uchar_to_premul_float()

◆ to_srgb_table_lookup()

MINLINE unsigned short to_srgb_table_lookup ( float f)

Definition at line 103 of file math_color_inline.cc.

References BLI_color_to_srgb_table, and MINLINE.

Referenced by linearrgb_to_srgb_ushort4().

◆ ycc_to_rgb()

void ycc_to_rgb ( float y,
float cb,
float cr,
float * r_r,
float * r_g,
float * r_b,
int colorspace )

◆ yuv_to_rgb()