Blender  V2.93
Functions | Variables
math_color.c File Reference
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Functions

void hsv_to_rgb (float h, float s, float v, float *r_r, float *r_g, float *r_b)
 
void hsl_to_rgb (float h, float s, float l, 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_v (const float hsl[3], float r_rgb[3])
 
void rgb_to_yuv (float r, float g, float b, float *r_y, float *r_u, float *r_v, int colorspace)
 
void yuv_to_rgb (float y, float u, float v, float *r_r, float *r_g, float *r_b, int colorspace)
 
void rgb_to_ycc (float r, float g, float b, float *r_y, float *r_cb, float *r_cr, int colorspace)
 
void ycc_to_rgb (float y, float cb, float cr, float *r_r, float *r_g, float *r_b, int colorspace)
 
void hex_to_rgb (const char *hexcol, float *r_r, float *r_g, float *r_b)
 
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_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_hsl_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])
 
void hsv_clamp_v (float hsv[3], float v_max)
 
unsigned int hsv_to_cpack (float h, float s, float v)
 
unsigned int rgb_to_cpack (float r, float g, float b)
 
void cpack_to_rgb (unsigned int col, float *r_r, float *r_g, float *r_b)
 
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])
 
float srgb_to_linearrgb (float c)
 
float linearrgb_to_srgb (float c)
 
void minmax_rgb (short c[3])
 
int constrain_rgb (float *r, float *g, float *b)
 
void lift_gamma_gain_to_asc_cdl (const float *lift, const float *gamma, const float *gain, float *offset, float *slope, float *power)
 
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)
 
static unsigned short hipart (const float f)
 
static float index_to_float (const unsigned short i)
 
void BLI_init_srgb_conversion (void)
 
static void blackbody_temperature_to_rgb (float rgb[3], float t)
 
void blackbody_temperature_to_rgb_table (float *r_table, int width, float min, float max)
 

Variables

float BLI_color_from_srgb_table [256]
 
unsigned short BLI_color_to_srgb_table [0x10000]
 
static const float blackbody_table_r [6][3]
 
static const float blackbody_table_g [6][3]
 
static const float blackbody_table_b [6][4]
 

Function Documentation

◆ blackbody_temperature_to_rgb()

static void blackbody_temperature_to_rgb ( float  rgb[3],
float  t 
)
static

Definition at line 675 of file math_color.c.

References blackbody_table_b, blackbody_table_g, blackbody_table_r, r, and t.

Referenced by blackbody_temperature_to_rgb_table().

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

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

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

◆ hipart()

static unsigned short hipart ( const float  f)
static

Definition at line 559 of file math_color.c.

Referenced by BLI_init_srgb_conversion().

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

◆ index_to_float()

static float index_to_float ( const unsigned short  i)
static

Definition at line 575 of file math_color.c.

Referenced by BLI_init_srgb_conversion().

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

◆ minmax_rgb()

void minmax_rgb ( short  c[3])

Definition at line 452 of file math_color.c.

References Freestyle::c.

◆ rgb_byte_set_hue_float_offset()

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

◆ rgb_float_set_hue_float_offset()

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

Definition at line 524 of file math_color.c.

References hsv_to_rgb(), and rgb_to_hsv().

Referenced by rgb_byte_set_hue_float_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_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_to_uchar()

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

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

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

Variable Documentation

◆ blackbody_table_b

const float blackbody_table_b[6][4]
static
Initial value:
= {
{0.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 0.0f},
{-2.02524603e-11f, 1.79435860e-07f, -2.60561875e-04f, -1.41761141e-02f},
{-2.22463426e-13f, -1.55078698e-08f, 3.81675160e-04f, -7.30646033e-01f},
{6.72595954e-13f, -2.73059993e-08f, 4.24068546e-04f, -7.52204323e-01f},
}

Definition at line 666 of file math_color.c.

Referenced by blackbody_temperature_to_rgb().

◆ blackbody_table_g

const float blackbody_table_g[6][3]
static
Initial value:
= {
{-7.50343014e+02f, 3.15679613e-04f, 4.73464526e-01f},
{-1.00402363e+03f, 1.29189794e-04f, 9.08181524e-01f},
{-1.22075471e+03f, 2.56245413e-05f, 1.20753416e+00f},
{-1.42546105e+03f, -4.01730887e-05f, 1.44002695e+00f},
{-1.18134453e+03f, -2.18913373e-05f, 1.30656109e+00f},
{-5.00279505e+02f, -4.59745390e-06f, 1.09090465e+00f},
}

Definition at line 657 of file math_color.c.

Referenced by blackbody_temperature_to_rgb().

◆ blackbody_table_r

const float blackbody_table_r[6][3]
static
Initial value:
= {
{2.52432244e+03f, -1.06185848e-03f, 3.11067539e+00f},
{3.37763626e+03f, -4.34581697e-04f, 1.64843306e+00f},
{4.10671449e+03f, -8.61949938e-05f, 6.41423749e-01f},
{4.66849800e+03f, 2.85655028e-05f, 1.29075375e-01f},
{4.60124770e+03f, 2.89727618e-05f, 1.48001316e-01f},
{3.78765709e+03f, 9.36026367e-06f, 3.98995841e-01f},
}

Definition at line 648 of file math_color.c.

Referenced by blackbody_temperature_to_rgb().

◆ BLI_color_from_srgb_table

float BLI_color_from_srgb_table[256]

◆ BLI_color_to_srgb_table

unsigned short BLI_color_to_srgb_table[0x10000]

Definition at line 557 of file math_color.c.

Referenced by BLI_init_srgb_conversion(), and to_srgb_table_lookup().