Blender V4.3
math_color.cc File Reference
#include "BLI_array.hh"
#include "BLI_math_color.h"
#include "BLI_math_color.hh"
#include "BLI_math_matrix.hh"
#include "BLI_math_vector.hh"
#include "BLI_simd.hh"
#include "BLI_utildefines.h"
#include <string.h>
#include "BLI_strict_flags.h"

Go to the source code of this file.

Classes

struct  blender::math::locus_entry_t
 

Namespaces

namespace  blender
 
namespace  blender::math
 

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 hex_to_rgba (const char *hexcol, float *r_r, float *r_g, float *r_b, float *r_a)
 
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)
 
uint hsv_to_cpack (float h, float s, float v)
 
uint rgb_to_cpack (float r, float g, float b)
 
void cpack_to_rgb (uint col, float *r_r, float *r_g, float *r_b)
 
void rgb_uchar_to_float (float r_col[3], const uchar col_ub[3])
 
void rgba_uchar_to_float (float r_col[4], const uchar col_ub[4])
 
void rgb_float_to_uchar (uchar r_col[3], const float col_f[3])
 
void rgba_float_to_uchar (uchar r_col[4], const float col_f[4])
 
float srgb_to_linearrgb (float c)
 
float linearrgb_to_srgb (float c)
 
MALWAYS_INLINE float int_as_float (int32_t v)
 
MALWAYS_INLINE int32_t float_as_int (float v)
 
MALWAYS_INLINE float _bli_math_fastpow (const int exp, const int e2coeff, const float arg)
 
MALWAYS_INLINE float _bli_math_improve_5throot_solution (const float old_result, const float x)
 
MALWAYS_INLINE float _bli_math_fastpow24 (const float arg)
 
MALWAYS_INLINE float _bli_math_rsqrt (float in)
 
MALWAYS_INLINE float _bli_math_fastpow512 (const float arg)
 
MALWAYS_INLINE float srgb_to_linearrgb_approx (float c)
 
MALWAYS_INLINE float linearrgb_to_srgb_approx (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])
 
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 (uchar rgb[3], float hue_offset)
 
static ushort hipart (const float f)
 
static float index_to_float (const ushort i)
 
void BLI_init_srgb_conversion ()
 
bool blender::math::whitepoint_to_temp_tint (const float3 &white, float &temperature, float &tint)
 
float3 blender::math::whitepoint_from_temp_tint (float temperature, float tint)
 
float3x3 blender::math::chromatic_adaption_matrix (const float3 &from_XYZ, const float3 &to_XYZ)
 

Variables

float BLI_color_from_srgb_table [256]
 
ushort BLI_color_to_srgb_table [0x10000]
 
static const std::array< locus_entry_t, 31 > blender::math::planck_locus
 

Function Documentation

◆ _bli_math_fastpow()

MALWAYS_INLINE float _bli_math_fastpow ( const int exp,
const int e2coeff,
const float arg )

Definition at line 604 of file math_color.cc.

References exp(), float, float_as_int(), int_as_float(), and ret.

Referenced by _bli_math_fastpow24(), and _bli_math_fastpow512().

◆ _bli_math_fastpow24()

MALWAYS_INLINE float _bli_math_fastpow24 ( const float arg)

Definition at line 622 of file math_color.cc.

References _bli_math_fastpow(), _bli_math_improve_5throot_solution(), and x.

Referenced by srgb_to_linearrgb_approx().

◆ _bli_math_fastpow512()

MALWAYS_INLINE float _bli_math_fastpow512 ( const float arg)

Definition at line 638 of file math_color.cc.

References _bli_math_fastpow(), and _bli_math_rsqrt().

Referenced by linearrgb_to_srgb_approx().

◆ _bli_math_improve_5throot_solution()

MALWAYS_INLINE float _bli_math_improve_5throot_solution ( const float old_result,
const float x )

Definition at line 613 of file math_color.cc.

Referenced by _bli_math_fastpow24().

◆ _bli_math_rsqrt()

MALWAYS_INLINE float _bli_math_rsqrt ( float in)

Definition at line 633 of file math_color.cc.

References sqrtf.

Referenced by _bli_math_fastpow512().

◆ BLI_init_srgb_conversion()

◆ 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 709 of file math_color.cc.

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

◆ cpack_to_rgb()

void cpack_to_rgb ( uint col,
float * r_r,
float * r_g,
float * r_b )

Definition at line 395 of file math_color.cc.

References col, and float.

Referenced by BKE_palette_from_hash().

◆ float_as_int()

MALWAYS_INLINE int32_t float_as_int ( float v)

Definition at line 597 of file math_color.cc.

References v.

Referenced by _bli_math_fastpow(), and isect_ray_tri_watertight_v3().

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

◆ hipart()

static ushort hipart ( const float f)
static

Definition at line 784 of file math_color.cc.

Referenced by BLI_init_srgb_conversion().

◆ hsl_to_rgb()

◆ hsl_to_rgb_v()

◆ hsv_clamp_v()

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

Clamp hsv to usable values.

Definition at line 349 of file math_color.cc.

References CLAMP, floorf, and UNLIKELY.

◆ hsv_to_cpack()

uint 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 358 of file math_color.cc.

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

◆ hsv_to_rgb()

◆ hsv_to_rgb_v()

◆ index_to_float()

static float index_to_float ( const ushort i)
static

Definition at line 800 of file math_color.cc.

References FLT_MAX.

Referenced by BLI_init_srgb_conversion().

◆ int_as_float()

MALWAYS_INLINE float int_as_float ( int32_t v)

Definition at line 590 of file math_color.cc.

References v.

Referenced by _bli_math_fastpow().

◆ 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 728 of file math_color.cc.

References FLT_MAX, and power().

◆ linearrgb_to_srgb()

◆ linearrgb_to_srgb_approx()

MALWAYS_INLINE float linearrgb_to_srgb_approx ( float c)

Definition at line 660 of file math_color.cc.

References _bli_math_fastpow512().

Referenced by linearrgb_to_srgb_v3_v3().

◆ linearrgb_to_srgb_v3_v3()

◆ minmax_rgb()

void minmax_rgb ( short c[3])

Definition at line 685 of file math_color.cc.

◆ 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 767 of file math_color.cc.

References 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 750 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, 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 323 of file math_color.cc.

References b, e, 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 scopes_update_cb(), TEST(), and blender::compositor::ConvertRGBToYCCOperation::update_memory_buffer_partial().

◆ rgb_to_yuv()

◆ rgb_uchar_to_float()

◆ rgba_float_to_uchar()

◆ rgba_uchar_to_float()

◆ srgb_to_linearrgb()

◆ srgb_to_linearrgb_approx()

MALWAYS_INLINE float srgb_to_linearrgb_approx ( float c)

Definition at line 651 of file math_color.cc.

References _bli_math_fastpow24().

Referenced by srgb_to_linearrgb_v3_v3().

◆ srgb_to_linearrgb_v3_v3()

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

Variable Documentation

◆ BLI_color_from_srgb_table

◆ BLI_color_to_srgb_table

ushort BLI_color_to_srgb_table[0x10000]

Definition at line 782 of file math_color.cc.

Referenced by BLI_init_srgb_conversion(), and to_srgb_table_lookup().