libgpac
Documentation of the core library of GPAC

Color tools. More...

+ Collaboration diagram for Color:

Data Structures

struct  GF_VideoSurface
 Video framebuffer object. More...
 
struct  GF_Window
 Video Window object. More...
 
struct  GF_ColorMatrix
 color matrix object More...
 
struct  GF_ColorKey
 Color Key descriptor. More...
 

Macros

#define GF_COL_ARGB(a, r, g, b)
 
#define GF_COL_ARGB_FIXED(_a, _r, _g, _b)
 
#define GF_COL_A(c)
 
#define GF_COL_R(c)
 
#define GF_COL_G(c)
 
#define GF_COL_B(c)
 
#define GF_COL_565(r, g, b)
 
#define GF_COL_555(r, g, b)
 
#define GF_COLW_A(c)
 
#define GF_COLW_R(c)
 
#define GF_COLW_G(c)
 
#define GF_COLW_B(c)
 

Typedefs

typedef u32 GF_Color
 ARGB color object. More...
 

Functions

GF_Color gf_color_parse (const char *name)
 
const char * gf_color_get_name (GF_Color col)
 
Bool gf_color_enum (u32 *idx, GF_Color *color, const char **color_name)
 
void gf_cmx_init (GF_ColorMatrix *_this)
 
void gf_cmx_set (GF_ColorMatrix *_this, Fixed mrr, Fixed mrg, Fixed mrb, Fixed mra, Fixed tr, Fixed mgr, Fixed mgg, Fixed mgb, Fixed mga, Fixed tg, Fixed mbr, Fixed mbg, Fixed mbb, Fixed mba, Fixed tb, Fixed mar, Fixed mag, Fixed mab, Fixed maa, Fixed ta)
 
void gf_cmx_copy (GF_ColorMatrix *_this, GF_ColorMatrix *from)
 
void gf_cmx_multiply (GF_ColorMatrix *_this, GF_ColorMatrix *with)
 color matrix multiplication More...
 
GF_Color gf_cmx_apply (GF_ColorMatrix *_this, GF_Color col)
 color matrix transform More...
 
void gf_cmx_apply_argb (GF_ColorMatrix *_this, u8 *a, u8 *r, u8 *g, u8 *b)
 color matrix transform More...
 
u64 gf_cmx_apply_wide (GF_ColorMatrix *_this, u64 col)
 color matrix transform on wide pixel (16 bit per component) More...
 
void gf_cmx_apply_fixed (GF_ColorMatrix *_this, Fixed *a, Fixed *r, Fixed *g, Fixed *b)
 color components matrix transform More...
 
GF_Err gf_stretch_bits (GF_VideoSurface *dst, GF_VideoSurface *src, GF_Window *dst_wnd, GF_Window *src_wnd, u8 alpha, Bool flip, GF_ColorKey *colorKey, GF_ColorMatrix *cmat)
 stretches two video surfaces More...
 

Detailed Description

This section documents color tools for image processing and color conversion


Data Structure Documentation

◆ GF_VideoSurface

struct GF_VideoSurface

The video framebuffer object represents uncompressed color data like images in a variety of formats. Data in the video framebuffer MUST be continuous.

Data Fields
u32 width

Width of the video framebuffer

u32 height

Height of the video framebuffer

s32 pitch_x

Horizontal pitch of the video framebuffer (number of bytes to skip to go to next (right) pixel in the buffer). May be negative for some framebuffers (embedded devices). 0 means linear frame buffer (pitch_x==bytes per pixel)

s32 pitch_y

Vertical pitch of the video framebuffer (number of bytes to skip to go down one line in the buffer). May be negative for some framebuffers (embedded devices)

u32 pixel_format

Pixel format of the video framebuffer

u8 * video_buffer

pointer to the beginning of the video memory (top-left corner)

Bool is_hardware_memory

indicates that the video data reside on systems memory or video card one

u8 * u_ptr

indicates U and V (and optional alpha) buffers in case of planar video with separated component. If not set, all components are in the video_buffer pointer

u8 * v_ptr
u8 * a_ptr
u8 global_alpha

alpha value for this surface

◆ GF_Window

struct GF_Window

The video window object represents a rectangle in framebuffer coordinate system

Data Fields
u32 x

left-most coordinate of the rectangle

u32 y

top-most coordinate of the rectangle

u32 w

width of the rectangle

u32 h

height of the rectangle

◆ GF_ColorMatrix

struct GF_ColorMatrix

The Color transformation matrix object allows complete color space transformation (shift, rotate, skew, add).
The matrix coefs are in rgba order, hence the color RGBA is transformed to:

R' m0 m1 m2 m3 m4 R
G' m5 m6 m7 m8 m9 G
B' = m10 m11 m12 m13 m14 x B
A' m15 m16 m17 m18 m19 A
0 0 0 0 0 1 0

Coeficients are in intensity scale, ranging from 0 to FIX_ONE.

Data Fields
Fixed m[20]

color matrix coefficient

u32 identity

internal flag to speed up things when matrix is identity. This is a read only flag, do not modify it

◆ GF_ColorKey

struct GF_ColorKey

The ColorKey object represents a ColorKey with low and high threshold keying

Data Fields
u8 r

color key R, G, and B components

u8 g
u8 b
u8 alpha

Alpha value for opaque (non-keyed) pixels

u8 low

low variance threshold

u8 high

high variance threshold

Macro Definition Documentation

◆ GF_COL_ARGB

#define GF_COL_ARGB (   a,
  r,
  g,
 
)

color formatting macro from alpha, red, green and blue components expressed as integers ranging from 0 to 255

◆ GF_COL_ARGB_FIXED

#define GF_COL_ARGB_FIXED (   _a,
  _r,
  _g,
  _b 
)

color formatting macro from alpha, red, green and blue components expressed as fixed numbers ranging from 0 to FIX_ONE

◆ GF_COL_A

#define GF_COL_A (   c)

gets alpha component of a color

◆ GF_COL_R

#define GF_COL_R (   c)

gets red component of a color

◆ GF_COL_G

#define GF_COL_G (   c)

gets green component of a color

◆ GF_COL_B

#define GF_COL_B (   c)

gets blue component of a color

◆ GF_COL_565

#define GF_COL_565 (   r,
  g,
 
)

16-bits color formatting macro from red, green and blue components

◆ GF_COL_555

#define GF_COL_555 (   r,
  g,
 
)

15-bits color formatting macro from red, green and blue components

◆ GF_COLW_A

#define GF_COLW_A (   c)

gets alpha component of a wide color

◆ GF_COLW_R

#define GF_COLW_R (   c)

gets red component of a wide color

◆ GF_COLW_G

#define GF_COLW_G (   c)

gets green component of a wide color

◆ GF_COLW_B

#define GF_COLW_B (   c)

gets blue component of a wide color

Typedef Documentation

◆ GF_Color

typedef u32 GF_Color

The color type used in the GPAC framework represents colors in the form 0xAARRGGBB, with each component ranging from 0 to 255

Function Documentation

◆ gf_color_parse()

GF_Color gf_color_parse ( const char *  name)

Parses color from HTML name or hexa representation

Parameters
namename of the color to parse
Returns
GF_Color value with alpha set to 0xFF if successful, 0 otherwise

◆ gf_color_get_name()

const char* gf_color_get_name ( GF_Color  col)

Gets color from HTML name or hexa representation

Parameters
colcolor to identify
Returns
name of the color if successful, NULL otherwise

◆ gf_color_enum()

Bool gf_color_enum ( u32 idx,
GF_Color color,
const char **  color_name 
)

Enumerates built-in colors

Parameters
idxindex of color to query, incremented by one on success
colorset to color value, can be NULL
color_nameset to color name, can be NULL
Returns
GF_TRUE if sucess, GF_FALSE otherwise

◆ gf_cmx_init()

void gf_cmx_init ( GF_ColorMatrix _this)

Inits a color matrix to identity

Parameters
_thisthe target color matrix to initialize

◆ gf_cmx_set()

void gf_cmx_set ( GF_ColorMatrix _this,
Fixed  mrr,
Fixed  mrg,
Fixed  mrb,
Fixed  mra,
Fixed  tr,
Fixed  mgr,
Fixed  mgg,
Fixed  mgb,
Fixed  mga,
Fixed  tg,
Fixed  mbr,
Fixed  mbg,
Fixed  mbb,
Fixed  mba,
Fixed  tb,
Fixed  mar,
Fixed  mag,
Fixed  mab,
Fixed  maa,
Fixed  ta 
)

Inits all coefficients of a color matrix

Parameters
_thiscolor matrix to initialize
mrrred-to-red multiplication factor
mrgred-to-green multiplication factor
mrbred-to-blue multiplication factor
mrared-to-alpha multiplication factor
trred translation factor
mgrgreen-to-red multiplication factor
mgggreen-to-green multiplication factor
mgbgreen-to-blue multiplication factor
mgagreen-to-alpha multiplication factor
tggreen translation factor
mbrblue-to-red multiplication factor
mbgblue-to-green multiplication factor
mbbblue-to-blue multiplication factor
mbablue-to-alpha multiplication factor
tbblue translation factor
maralpha-to-red multiplication factor
magalpha-to-green multiplication factor
mabalpha-to-blue multiplication factor
maaalpha-to-alpha multiplication factor
taalpha translation factor

◆ gf_cmx_copy()

void gf_cmx_copy ( GF_ColorMatrix _this,
GF_ColorMatrix from 
)

Inits a matrix from another matrix

Parameters
_thiscolor matrix to initialize
fromcolor matrix to copy from

◆ gf_cmx_multiply()

void gf_cmx_multiply ( GF_ColorMatrix _this,
GF_ColorMatrix with 
)

Multiplies a color matrix by another one. Result is _this*with

Parameters
_thiscolor matrix to transform. Once the function called, _this will contain the resulting color matrix
withcolor matrix to add

◆ gf_cmx_apply()

GF_Color gf_cmx_apply ( GF_ColorMatrix _this,
GF_Color  col 
)

Transforms a color with a given color matrix

Parameters
_thiscolor matrix to use.
colcolor to transform
Returns
transformed color

◆ gf_cmx_apply_argb()

void gf_cmx_apply_argb ( GF_ColorMatrix _this,
u8 a,
u8 r,
u8 g,
u8 b 
)

Transforms a color with a given color matrix

Parameters
_thiscolor matrix to use.
aalpha to transform (in/out)
rred to transform (in/out)
ggreen to transform (in/out)
bblue to transform (in/out)

◆ gf_cmx_apply_wide()

u64 gf_cmx_apply_wide ( GF_ColorMatrix _this,
u64  col 
)

Transforms a color with a given color matrix

Parameters
_thiscolor matrix to use.
colcolor to transform
Returns
transformed color

◆ gf_cmx_apply_fixed()

void gf_cmx_apply_fixed ( GF_ColorMatrix _this,
Fixed a,
Fixed r,
Fixed g,
Fixed b 
)

Transforms color components with a given color matrix

Parameters
_thiscolor matrix to use.
apointer to alpha component. Once the function is called, a contains the transformed alpha component
rpointer to red component. Once the function is called, r contains the transformed red component
gpointer to green component. Once the function is called, g contains the transformed green component
bpointer to blue component. Once the function is called, b contains the transformed blue component

◆ gf_stretch_bits()

GF_Err gf_stretch_bits ( GF_VideoSurface dst,
GF_VideoSurface src,
GF_Window dst_wnd,
GF_Window src_wnd,
u8  alpha,
Bool  flip,
GF_ColorKey colorKey,
GF_ColorMatrix cmat 
)

Software stretch of source surface onto destination surface.

Parameters
dstdestination surface
srcsource surface
dst_wnddestination rectangle. If null the entire destination surface is used
src_wndsource rectangle. If null the entire source surface is used
alphablend factor of source over alpha
flipflips the source
colorKeymakes source pixel matching the color key transparent
cmatapplies color matrix to the source
Returns
error code if any