Blender  V2.93
Macros | Functions
BLI_math_color.h File Reference
#include "BLI_math_inline.h"
#include "intern/math_color_inline.c"

Go to the source code of this file.

Macros

#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
 
#define rgba_char_args_set_fl(col, r, g, b, a)    rgba_char_args_set(col, (r)*255, (g)*255, (b)*255, (a)*255)
 
#define rgba_float_args_set_ch(col, r, g, b, a)    rgba_float_args_set(col, (r) / 255.0f, (g) / 255.0f, (b) / 255.0f, (a) / 255.0f)
 

Functions

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)
 
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)
 
float srgb_to_linearrgb (float c)
 
float linearrgb_to_srgb (float c)
 
MINLINE void srgb_to_linearrgb_v3_v3 (float linear[3], const float srgb[3])
 
MINLINE 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 (const 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)
 
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])
 
int constrain_rgb (float *r, float *g, float *b)
 
void minmax_rgb (short c[3])
 
void hsv_clamp_v (float hsv[3], float v_max)
 
void rgb_float_set_hue_float_offset (float *rgb, float hue_offset)
 
void rgb_byte_set_hue_float_offset (unsigned char *rgb, float hue_offset)
 
void rgb_uchar_to_float (float r_col[3], const unsigned char col_ub[3])
 
void rgba_uchar_to_float (float r_col[4], const unsigned char col_ub[4])
 
void rgb_float_to_uchar (unsigned char r_col[3], const float col_f[3])
 
void rgba_float_to_uchar (unsigned char r_col[4], const float col_f[4])
 
MINLINE float rgb_to_grayscale (const float rgb[3])
 
MINLINE unsigned char rgb_to_grayscale_byte (const unsigned char rgb[3])
 
MINLINE int compare_rgb_uchar (const unsigned char a[3], const unsigned char b[3], const int limit)
 
MINLINE float dither_random_value (float s, float t)
 
MINLINE void float_to_byte_dither_v3 (unsigned char b[3], const float f[3], float dither, float s, float t)
 
MINLINE void rgba_uchar_args_set (unsigned char col[4], const unsigned char r, const unsigned char g, const unsigned char b, const unsigned char a)
 
MINLINE void rgba_float_args_set (float col[4], const float r, const float g, const float b, const float a)
 
MINLINE void rgba_uchar_args_test_set (unsigned char col[4], const unsigned char r, const unsigned char g, const unsigned char b, const unsigned char a)
 
MINLINE void cpack_cpy_3ub (unsigned char r_col[3], const unsigned int pack)
 
void blackbody_temperature_to_rgb_table (float *r_table, int width, float min, float max)
 
void lift_gamma_gain_to_asc_cdl (const float *lift, const float *gamma, const float *gain, float *offset, float *slope, float *power)
 

Macro Definition Documentation

◆ BLI_YCC_ITU_BT601

#define BLI_YCC_ITU_BT601   0

Definition at line 35 of file BLI_math_color.h.

◆ BLI_YCC_ITU_BT709

#define BLI_YCC_ITU_BT709   1

Definition at line 36 of file BLI_math_color.h.

◆ BLI_YCC_JFIF_0_255

#define BLI_YCC_JFIF_0_255   2

Definition at line 37 of file BLI_math_color.h.

◆ BLI_YUV_ITU_BT601

#define BLI_YUV_ITU_BT601   0

Definition at line 40 of file BLI_math_color.h.

◆ BLI_YUV_ITU_BT709

#define BLI_YUV_ITU_BT709   1

Definition at line 41 of file BLI_math_color.h.

◆ rgba_char_args_set_fl

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

Definition at line 125 of file BLI_math_color.h.

◆ rgba_float_args_set_ch

#define rgba_float_args_set_ch (   col,
  r,
  g,
  b,
 
)     rgba_float_args_set(col, (r) / 255.0f, (g) / 255.0f, (b) / 255.0f, (a) / 255.0f)

Definition at line 128 of file BLI_math_color.h.

Function Documentation

◆ blackbody_temperature_to_rgb_table()

void blackbody_temperature_to_rgb_table ( float r_table,
int  width,
float  min,
float  max 
)

◆ BLI_init_srgb_conversion()

void BLI_init_srgb_conversion ( void  )

◆ compare_rgb_uchar()

MINLINE int compare_rgb_uchar ( const unsigned char  a[3],
const unsigned char  b[3],
const int  limit 
)

Definition at line 302 of file math_color_inline.c.

References abs(), and r.

◆ constrain_rgb()

int constrain_rgb ( float r,
float g,
float b 
)

Definition at line 482 of file math_color.c.

References min_ffff(), r, and w().

◆ cpack_cpy_3ub()

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

Definition at line 256 of file math_color_inline.c.

◆ cpack_to_rgb()

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

Definition at line 400 of file math_color.c.

References col, and float().

Referenced by BKE_palette_from_hash().

◆ dither_random_value()

MINLINE float dither_random_value ( float  s,
float  t 
)

Definition at line 323 of file math_color_inline.c.

References floorf, sinf, and t.

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,
float  s,
float  t 
)

◆ hex_to_rgb()

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

Definition at line 198 of file math_color.c.

References CLAMP, and float().

Referenced by BKE_gpencil_palette_ensure(), and ui_colorpicker_hex_rna_cb().

◆ hsl_to_rgb()

void hsl_to_rgb ( float  h,
float  s,
float  l,
float r_r,
float r_g,
float r_b 
)

Definition at line 48 of file math_color.c.

References CLAMP, fabsf, and l.

Referenced by BKE_icon_geom_invert_lightness(), and hsl_to_rgb_v().

◆ 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 
)

Definition at line 348 of file math_color.c.

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 363 of file math_color.c.

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

◆ hsv_to_rgb()

void hsv_to_rgb ( float  h,
float  s,
float  v,
float r_r,
float r_g,
float r_b 
)

◆ hsv_to_rgb_v()

void hsv_to_rgb_v ( const float  hsv[3],
float  r_rgb[3] 
)

◆ lift_gamma_gain_to_asc_cdl()

void lift_gamma_gain_to_asc_cdl ( const float lift,
const float gamma,
const float gain,
float offset,
float slope,
float power 
)

Definition at line 501 of file math_color.c.

References Freestyle::c.

◆ linearrgb_to_srgb()

float linearrgb_to_srgb ( float  c)

◆ 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()

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

◆ linearrgb_to_srgb_ushort4()

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

◆ linearrgb_to_srgb_v3_v3()

MINLINE void linearrgb_to_srgb_v3_v3 ( float  srgb[3],
const float  linear[3] 
)

◆ linearrgb_to_srgb_v4()

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

◆ minmax_rgb()

void minmax_rgb ( short  c[3])

Definition at line 452 of file math_color.c.

References Freestyle::c.

◆ premul_float_to_straight_uchar()

MINLINE void premul_float_to_straight_uchar ( unsigned char *  result,
const float  color[4] 
)

◆ premul_to_straight_v4()

MINLINE void premul_to_straight_v4 ( float  color[4])

◆ premul_to_straight_v4_v4()

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

◆ rgb_byte_set_hue_float_offset()

void rgb_byte_set_hue_float_offset ( unsigned char *  rgb,
float  hue_offset 
)

Referenced by color3ubv_from_seq().

◆ rgb_float_set_hue_float_offset()

void rgb_float_set_hue_float_offset ( float rgb,
float  hue_offset 
)

◆ rgb_float_to_uchar()

void rgb_float_to_uchar ( unsigned char  r_col[3],
const float  col_f[3] 
)

◆ rgb_to_cpack()

unsigned int rgb_to_cpack ( float  r,
float  g,
float  b 
)

◆ rgb_to_grayscale()

MINLINE float rgb_to_grayscale ( const float  rgb[3])

ITU-R BT.709 primaries https://en.wikipedia.org/wiki/Relative_luminance

Real values are: Y = 0.2126390059(R) + 0.7151686788(G) + 0.0721923154(B) according to: "Derivation of Basic Television Color Equations", RP 177-1993

As this sums slightly above 1.0, the document recommends to use: 0.2126(R) + 0.7152(G) + 0.0722(B), as used here.

The high precision values are used to calculate the rounded byte weights so they add up to 255: 54(R) + 182(G) + 19(B)

Definition at line 288 of file math_color_inline.c.

Referenced by button2d_draw_intern(), blender::nodes::color_to_bool(), blender::nodes::color_to_float(), blender::nodes::color_to_int(), file_draw_preview(), ui_tooltip_region_draw_cb(), and widget_swatch().

◆ rgb_to_grayscale_byte()

MINLINE unsigned char rgb_to_grayscale_byte ( const unsigned char  rgb[3])

◆ rgb_to_hsl()

void rgb_to_hsl ( float  r,
float  g,
float  b,
float r_h,
float r_s,
float r_l 
)

Definition at line 259 of file math_color.c.

References l, max_fff(), min_ff(), min_fff(), and r.

Referenced by rgb_to_hsl_compat(), and rgb_to_hsl_v().

◆ 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 288 of file math_color.c.

References r, 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()

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

◆ rgb_to_hsv()

void rgb_to_hsv ( float  r,
float  g,
float  b,
float r_h,
float r_s,
float r_v 
)

◆ 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 320 of file math_color.c.

References e, r, 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()

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

◆ rgb_to_ycc()

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

◆ rgb_to_yuv()

void rgb_to_yuv ( float  r,
float  g,
float  b,
float r_y,
float r_u,
float r_v,
int  colorspace 
)

◆ rgb_uchar_to_float()

void rgb_uchar_to_float ( float  r_col[3],
const unsigned char  col_ub[3] 
)

◆ rgba_float_args_set()

MINLINE void rgba_float_args_set ( float  col[4],
const float  r,
const float  g,
const float  b,
const float  a 
)

Definition at line 236 of file math_color_inline.c.

References Freestyle::a, col, and r.

Referenced by node_draw_basis(), node_draw_frame(), and proj_paint_default_color().

◆ rgba_float_to_uchar()

void rgba_float_to_uchar ( unsigned char  r_col[4],
const float  col_f[4] 
)

◆ rgba_uchar_args_set()

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

Definition at line 227 of file math_color_inline.c.

References Freestyle::a, col, and r.

Referenced by action_group_colors_sync().

◆ rgba_uchar_args_test_set()

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

Definition at line 245 of file math_color_inline.c.

References Freestyle::a, col, and r.

◆ rgba_uchar_to_float()

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

◆ srgb_to_linearrgb()

float srgb_to_linearrgb ( float  c)

◆ srgb_to_linearrgb_predivide_v4()

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

◆ srgb_to_linearrgb_uchar4()

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

◆ 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()

MINLINE void srgb_to_linearrgb_v3_v3 ( float  linear[3],
const float  srgb[3] 
)

◆ srgb_to_linearrgb_v4()

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

◆ straight_to_premul_v4()

MINLINE void straight_to_premul_v4 ( float  color[4])

◆ straight_to_premul_v4_v4()

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

◆ straight_uchar_to_premul_float()

MINLINE void straight_uchar_to_premul_float ( float  result[4],
const unsigned char  color[4] 
)

◆ to_srgb_table_lookup()

MINLINE unsigned short to_srgb_table_lookup ( const float  f)

Definition at line 179 of file math_color_inline.c.

References BLI_color_to_srgb_table.

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()

void yuv_to_rgb ( float  y,
float  u,
float  v,
float r_r,
float r_g,
float r_b,
int  colorspace 
)