Blender V5.0
math_color.cc File Reference
#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 <algorithm>
#include <cstring>
#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)
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 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 592 of file math_color.cc.

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

Referenced by _bli_math_fastpow24(), and _bli_math_fastpow512().

◆ _bli_math_fastpow24()

MALWAYS_INLINE float _bli_math_fastpow24 ( const float arg)

◆ _bli_math_fastpow512()

MALWAYS_INLINE float _bli_math_fastpow512 ( const float arg)

Definition at line 626 of file math_color.cc.

References _bli_math_fastpow(), _bli_math_rsqrt(), and MALWAYS_INLINE.

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

References MALWAYS_INLINE, and x.

Referenced by _bli_math_fastpow24().

◆ _bli_math_rsqrt()

MALWAYS_INLINE float _bli_math_rsqrt ( float in)

Definition at line 621 of file math_color.cc.

References in, MALWAYS_INLINE, and sqrtf.

Referenced by _bli_math_fastpow512().

◆ BLI_init_srgb_conversion()

◆ cpack_to_rgb()

void cpack_to_rgb ( uint 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().

◆ float_as_int()

MALWAYS_INLINE int32_t float_as_int ( float v)

Definition at line 585 of file math_color.cc.

References i, MALWAYS_INLINE, MINLINE, and 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()

ushort hipart ( const float f)
static

Definition at line 709 of file math_color.cc.

Referenced by BLI_init_srgb_conversion().

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

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

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

◆ hsv_to_rgb()

◆ hsv_to_rgb_v()

◆ index_to_float()

float index_to_float ( const ushort i)
static

Definition at line 722 of file math_color.cc.

References FLT_MAX, and i.

Referenced by BLI_init_srgb_conversion().

◆ int_as_float()

◆ linearrgb_to_srgb()

◆ linearrgb_to_srgb_approx()

MALWAYS_INLINE float linearrgb_to_srgb_approx ( float c)

Definition at line 648 of file math_color.cc.

References _bli_math_fastpow512(), and MALWAYS_INLINE.

Referenced by linearrgb_to_srgb_v3_v3().

◆ linearrgb_to_srgb_v3_v3()

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

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

MALWAYS_INLINE float srgb_to_linearrgb_approx ( float c)

Definition at line 639 of file math_color.cc.

References _bli_math_fastpow24(), and MALWAYS_INLINE.

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

Referenced by BLI_init_srgb_conversion(), and to_srgb_table_lookup().