Blender  V3.3
Macros | Functions | Variables
math_color_inline.c File Reference
#include "BLI_math_base.h"
#include "BLI_math_color.h"
#include "BLI_utildefines.h"
#include <math.h>

Go to the source code of this file.

Macros

#define __MATH_COLOR_INLINE_C__
 

Functions

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 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])
 
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 rgba_uchar_args_set (uchar col[4], const uchar r, const uchar g, const uchar b, const uchar 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 (uchar col[4], const uchar r, const uchar g, const uchar b, const uchar a)
 
MINLINE void cpack_cpy_3ub (unsigned char r_col[3], const unsigned int pack)
 
MINLINE int compare_rgb_uchar (const unsigned char col_a[3], const unsigned char col_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 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])
 
RGB/Gray-Scale Functions
Warning
These are only an approximation, in almost all cases, IMB_colormanagement_get_luminance should be used instead. However for screen-only colors which don't depend on the currently loaded profile - this is preferred. Checking theme colors for contrast, etc. Basically anything outside the render pipeline.
MINLINE float rgb_to_grayscale (const float rgb[3])
 
MINLINE unsigned char rgb_to_grayscale_byte (const unsigned char rgb[3])
 

Variables

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

Macro Definition Documentation

◆ __MATH_COLOR_INLINE_C__

#define __MATH_COLOR_INLINE_C__

Definition at line 15 of file math_color_inline.c.

Function Documentation

◆ compare_rgb_uchar()

MINLINE int compare_rgb_uchar ( const unsigned char  col_a[3],
const unsigned char  col_b[3],
const int  limit 
)

Definition at line 270 of file math_color_inline.c.

References blender::math::abs(), usdtokens::b(), usdtokens::g(), and r.

◆ cpack_cpy_3ub()

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

Definition at line 238 of file math_color_inline.c.

◆ dither_random_value()

MINLINE float dither_random_value ( float  s,
float  t 
)

Return triangle noise in [-0.5..1.5] range.

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

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

◆ 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_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 256 of file math_color_inline.c.

References usdtokens::rgb().

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

◆ rgb_to_grayscale_byte()

MINLINE unsigned char rgb_to_grayscale_byte ( const unsigned char  rgb[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 
)

◆ rgba_uchar_args_set()

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

Definition at line 209 of file math_color_inline.c.

References Freestyle::a, usdtokens::b(), col, usdtokens::g(), and r.

Referenced by action_group_colors_sync().

◆ rgba_uchar_args_test_set()

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

Definition at line 227 of file math_color_inline.c.

References Freestyle::a, usdtokens::b(), col, usdtokens::g(), and r.

◆ 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 161 of file math_color_inline.c.

References BLI_color_to_srgb_table.

Referenced by linearrgb_to_srgb_ushort4().

Variable Documentation

◆ BLI_color_from_srgb_table

float BLI_color_from_srgb_table[256]
extern

◆ BLI_color_to_srgb_table

unsigned short BLI_color_to_srgb_table[0x10000]
extern

Definition at line 518 of file math_color.c.

Referenced by BLI_init_srgb_conversion(), and to_srgb_table_lookup().