Blender  V3.3
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)
 

Variables

float BLI_color_from_srgb_table [256]
 
unsigned short BLI_color_to_srgb_table [0x10000]
 

Function Documentation

◆ BLI_init_srgb_conversion()

void BLI_init_srgb_conversion ( void  )

◆ constrain_rgb()

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

If the requested RGB shade contains a negative weight for one of the primaries, it lies outside the color gamut accessible from the given triple of primaries. Desaturate it by adding white, equal quantities of R, G, and B, enough to make RGB all positive. The function returns 1 if the components were modified, zero otherwise.

Definition at line 445 of file math_color.c.

References usdtokens::b(), usdtokens::g(), 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 369 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 177 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 520 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 
)

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

References usdtokens::b(), col, usdtokens::g(), 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 536 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 464 of file math_color.c.

References Freestyle::c, and offset.

◆ linearrgb_to_srgb()

float linearrgb_to_srgb ( float  c)

◆ minmax_rgb()

void minmax_rgb ( short  c[3])

Definition at line 421 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 
)

Applies an HUE offset to a byte RGB color.

Definition at line 503 of file math_color.c.

References usdtokens::rgb(), rgb_float_set_hue_float_offset(), rgb_float_to_uchar(), and rgb_uchar_to_float().

Referenced by 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 486 of file math_color.c.

References hsv_to_rgb(), usdtokens::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 
)

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

References usdtokens::b(), usdtokens::g(), 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 297 of file math_color.c.

References usdtokens::b(), e, usdtokens::g(), 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 
)

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

References usdtokens::b(), BLI_assert_msg, BLI_YCC_ITU_BT601, BLI_YCC_ITU_BT709, BLI_YCC_JFIF_0_255, usdtokens::g(), r, and y.

Referenced by blender::compositor::ConvertRGBToYCCOperation::execute_pixel_sampled(), scopes_update_cb(), TEST(), and blender::compositor::ConvertRGBToYCCOperation::update_memory_buffer_partial().

◆ 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

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

Referenced by BLI_init_srgb_conversion(), and to_srgb_table_lookup().