FFmpeg
Macros | Functions | Variables
palette.c File Reference
#include "libavutil/common.h"
#include "palette.h"

Go to the source code of this file.

Macros

#define K   ((1 << 16) - 1)
 
#define K2   ((int64_t)K*K)
 
#define P   ((1 << 9) - 1)
 

Functions

int32_t ff_srgb_u8_to_linear_int (uint8_t x)
 Map sRGB 8-bit color component to a 16-bit linear value (gamma expand from electrical to optical value). More...
 
uint8_t ff_linear_int_to_srgb_u8 (int32_t x)
 Map a 16-bit linear value to a sRGB 8-bit color component (gamma compressed from optical to electrical value). More...
 
static int32_t cbrt01_int (int32_t x)
 
static int64_t div_round64 (int64_t a, int64_t b)
 
struct Lab ff_srgb_u8_to_oklab_int (uint32_t srgb)
 sRGB (non-linear) to OkLab conversion More...
 
uint32_t ff_oklab_int_to_srgb_u8 (struct Lab c)
 OkLab to sRGB (non-linear) conversion. More...
 
uint32_t ff_lowbias32 (uint32_t x)
 

Variables

static const uint16_t srgb2linear [256]
 Table mapping formula: f(x) = x < 0.04045 ? x/12.92 : ((x+0.055)/1.055)^2.4 (sRGB EOTF) Where x is the normalized index in the table and f(x) the value in the table. More...
 
static const uint8_t linear2srgb [P+1]
 Table mapping formula: f(x) = x < 0.0031308 ? x*12.92 : 1.055*x^(1/2.4)-0.055 (sRGB OETF) Where x is the normalized index in the table and f(x) the value in the table. More...
 

Macro Definition Documentation

◆ K

#define K   ((1 << 16) - 1)

Definition at line 25 of file palette.c.

◆ K2

#define K2   ((int64_t)K*K)

Definition at line 26 of file palette.c.

◆ P

#define P   ((1 << 9) - 1)

Definition at line 27 of file palette.c.

Function Documentation

◆ ff_srgb_u8_to_linear_int()

int32_t ff_srgb_u8_to_linear_int ( uint8_t  x)

Map sRGB 8-bit color component to a 16-bit linear value (gamma expand from electrical to optical value).

Definition at line 113 of file palette.c.

◆ ff_linear_int_to_srgb_u8()

uint8_t ff_linear_int_to_srgb_u8 ( int32_t  x)

Map a 16-bit linear value to a sRGB 8-bit color component (gamma compressed from optical to electrical value).

Definition at line 118 of file palette.c.

Referenced by ff_oklab_int_to_srgb_u8().

◆ cbrt01_int()

static int32_t cbrt01_int ( int32_t  x)
static

Definition at line 135 of file palette.c.

Referenced by ff_srgb_u8_to_oklab_int().

◆ div_round64()

static int64_t div_round64 ( int64_t  a,
int64_t  b 
)
static

Definition at line 168 of file palette.c.

Referenced by ff_oklab_int_to_srgb_u8(), and ff_srgb_u8_to_oklab_int().

◆ ff_srgb_u8_to_oklab_int()

struct Lab ff_srgb_u8_to_oklab_int ( uint32_t  srgb)

sRGB (non-linear) to OkLab conversion

See also
https://bottosson.github.io/posts/oklab/

Definition at line 170 of file palette.c.

Referenced by color_inc(), get_color_from_srgb(), and get_next_color().

◆ ff_oklab_int_to_srgb_u8()

uint32_t ff_oklab_int_to_srgb_u8 ( struct Lab  c)

OkLab to sRGB (non-linear) conversion.

See also
https://bottosson.github.io/posts/oklab/

Definition at line 194 of file palette.c.

Referenced by get_palette_frame().

◆ ff_lowbias32()

uint32_t ff_lowbias32 ( uint32_t  x)

Definition at line 211 of file palette.c.

Referenced by color_get(), and color_inc().

Variable Documentation

◆ srgb2linear

const uint16_t srgb2linear[256]
static

Table mapping formula: f(x) = x < 0.04045 ? x/12.92 : ((x+0.055)/1.055)^2.4 (sRGB EOTF) Where x is the normalized index in the table and f(x) the value in the table.

f(x) is remapped to [0;K] and rounded.

Definition at line 35 of file palette.c.

Referenced by ff_srgb_u8_to_linear_int(), and ff_srgb_u8_to_oklab_int().

◆ linear2srgb

const uint8_t linear2srgb[P+1]
static

Table mapping formula: f(x) = x < 0.0031308 ? x*12.92 : 1.055*x^(1/2.4)-0.055 (sRGB OETF) Where x is the normalized index in the table and f(x) the value in the table.

f(x) is remapped to [0;0xff] and rounded.

Since a 16-bit table is too large, we reduce its precision to 9-bit.

Definition at line 78 of file palette.c.

Referenced by ff_linear_int_to_srgb_u8().