yuv_rgb.c File Reference
`#include "../../SDL_internal.h"`
`#include "yuv_rgb.h"`
`#include "SDL_cpuinfo.h"`
`#include "yuv_rgb_std_func.h"`
Include dependency graph for yuv_rgb.c:

Go to the source code of this file.

## Data Structures

struct | RGB2YUVParam
struct | YUV2RGBParam

## Macros

#define | PRECISION 6
#define | PRECISION_FACTOR (1<<PRECISION)
#define | V(value) (int16_t)((value*PRECISION_FACTOR)+0.5)
#define | YUV_FORMAT_420 1
#define | YUV_FORMAT_422 2
#define | YUV_FORMAT_NV12 3
#define | RGB_FORMAT_RGB565 1
#define | RGB_FORMAT_RGB24 2
#define | RGB_FORMAT_RGBA 3
#define | RGB_FORMAT_BGRA 4
#define | RGB_FORMAT_ARGB 5
#define | RGB_FORMAT_ABGR 6
#define | STD_FUNCTION_NAME yuv420_rgb565_std
#define | YUV_FORMAT YUV_FORMAT_420
#define | RGB_FORMAT RGB_FORMAT_RGB565
#define | STD_FUNCTION_NAME yuv420_rgb24_std
#define | YUV_FORMAT YUV_FORMAT_420
#define | RGB_FORMAT RGB_FORMAT_RGB24
#define | STD_FUNCTION_NAME yuv420_rgba_std
#define | YUV_FORMAT YUV_FORMAT_420
#define | RGB_FORMAT RGB_FORMAT_RGBA
#define | STD_FUNCTION_NAME yuv420_bgra_std
#define | YUV_FORMAT YUV_FORMAT_420
#define | RGB_FORMAT RGB_FORMAT_BGRA
#define | STD_FUNCTION_NAME yuv420_argb_std
#define | YUV_FORMAT YUV_FORMAT_420
#define | RGB_FORMAT RGB_FORMAT_ARGB
#define | STD_FUNCTION_NAME yuv420_abgr_std
#define | YUV_FORMAT YUV_FORMAT_420
#define | RGB_FORMAT RGB_FORMAT_ABGR
#define | STD_FUNCTION_NAME yuv422_rgb565_std
#define | YUV_FORMAT YUV_FORMAT_422
#define | RGB_FORMAT RGB_FORMAT_RGB565
#define | STD_FUNCTION_NAME yuv422_rgb24_std
#define | YUV_FORMAT YUV_FORMAT_422
#define | RGB_FORMAT RGB_FORMAT_RGB24
#define | STD_FUNCTION_NAME yuv422_rgba_std
#define | YUV_FORMAT YUV_FORMAT_422
#define | RGB_FORMAT RGB_FORMAT_RGBA
#define | STD_FUNCTION_NAME yuv422_bgra_std
#define | YUV_FORMAT YUV_FORMAT_422
#define | RGB_FORMAT RGB_FORMAT_BGRA
#define | STD_FUNCTION_NAME yuv422_argb_std
#define | YUV_FORMAT YUV_FORMAT_422
#define | RGB_FORMAT RGB_FORMAT_ARGB
#define | STD_FUNCTION_NAME yuv422_abgr_std
#define | YUV_FORMAT YUV_FORMAT_422
#define | RGB_FORMAT RGB_FORMAT_ABGR
#define | STD_FUNCTION_NAME yuvnv12_rgb565_std
#define | YUV_FORMAT YUV_FORMAT_NV12
#define | RGB_FORMAT RGB_FORMAT_RGB565
#define | STD_FUNCTION_NAME yuvnv12_rgb24_std
#define | YUV_FORMAT YUV_FORMAT_NV12
#define | RGB_FORMAT RGB_FORMAT_RGB24
#define | STD_FUNCTION_NAME yuvnv12_rgba_std
#define | YUV_FORMAT YUV_FORMAT_NV12
#define | RGB_FORMAT RGB_FORMAT_RGBA
#define | STD_FUNCTION_NAME yuvnv12_bgra_std
#define | YUV_FORMAT YUV_FORMAT_NV12
#define | RGB_FORMAT RGB_FORMAT_BGRA
#define | STD_FUNCTION_NAME yuvnv12_argb_std
#define | YUV_FORMAT YUV_FORMAT_NV12
#define | RGB_FORMAT RGB_FORMAT_ARGB
#define | STD_FUNCTION_NAME yuvnv12_abgr_std
#define | YUV_FORMAT YUV_FORMAT_NV12
#define | RGB_FORMAT RGB_FORMAT_ABGR

## Functions

static uint8_t | clampU8 (int32_t v)
void | rgb24_yuv420_std (uint32_t width, uint32_t height, const uint8_t *RGB, uint32_t RGB_stride, uint8_t *Y, uint8_t *U, uint8_t *V, uint32_t Y_stride, uint32_t UV_stride, YCbCrType yuv_type)

## Variables

static const YUV2RGBParam | YUV2RGB [3]
static const RGB2YUVParam | RGB2YUV [3]

## Macro Definition Documentation

## PRECISION

#define PRECISION 6

Definition at line 10 of file yuv_rgb.c.

## PRECISION_FACTOR

#define PRECISION_FACTOR (1<<PRECISION)

Definition at line 11 of file yuv_rgb.c.

## RGB_FORMAT [1/18]

#define RGB_FORMAT RGB_FORMAT_RGB565

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [2/18]

#define RGB_FORMAT RGB_FORMAT_RGB24

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [3/18]

#define RGB_FORMAT RGB_FORMAT_RGBA

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [4/18]

#define RGB_FORMAT RGB_FORMAT_BGRA

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [5/18]

#define RGB_FORMAT RGB_FORMAT_ARGB

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [6/18]

#define RGB_FORMAT RGB_FORMAT_ABGR

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [7/18]

#define RGB_FORMAT RGB_FORMAT_RGB565

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [8/18]

#define RGB_FORMAT RGB_FORMAT_RGB24

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [9/18]

#define RGB_FORMAT RGB_FORMAT_RGBA

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [10/18]

#define RGB_FORMAT RGB_FORMAT_BGRA

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [11/18]

#define RGB_FORMAT RGB_FORMAT_ARGB

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [12/18]

#define RGB_FORMAT RGB_FORMAT_ABGR

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [13/18]

#define RGB_FORMAT RGB_FORMAT_RGB565

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [14/18]

#define RGB_FORMAT RGB_FORMAT_RGB24

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [15/18]

#define RGB_FORMAT RGB_FORMAT_RGBA

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [16/18]

#define RGB_FORMAT RGB_FORMAT_BGRA

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [17/18]

#define RGB_FORMAT RGB_FORMAT_ARGB

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT [18/18]

#define RGB_FORMAT RGB_FORMAT_ABGR

Definition at line 183 of file yuv_rgb.c.

## RGB_FORMAT_ABGR

#define RGB_FORMAT_ABGR 6

Definition at line 71 of file yuv_rgb.c.

## RGB_FORMAT_ARGB

#define RGB_FORMAT_ARGB 5

Definition at line 70 of file yuv_rgb.c.

## RGB_FORMAT_BGRA

#define RGB_FORMAT_BGRA 4

Definition at line 69 of file yuv_rgb.c.

## RGB_FORMAT_RGB24

#define RGB_FORMAT_RGB24 2

Definition at line 67 of file yuv_rgb.c.

## RGB_FORMAT_RGB565

#define RGB_FORMAT_RGB565 1

Definition at line 66 of file yuv_rgb.c.

## RGB_FORMAT_RGBA

#define RGB_FORMAT_RGBA 3

Definition at line 68 of file yuv_rgb.c.

## STD_FUNCTION_NAME [1/18]

#define STD_FUNCTION_NAME yuv420_rgb565_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [2/18]

#define STD_FUNCTION_NAME yuv420_rgb24_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [3/18]

#define STD_FUNCTION_NAME yuv420_rgba_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [4/18]

#define STD_FUNCTION_NAME yuv420_bgra_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [5/18]

#define STD_FUNCTION_NAME yuv420_argb_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [6/18]

#define STD_FUNCTION_NAME yuv420_abgr_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [7/18]

#define STD_FUNCTION_NAME yuv422_rgb565_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [8/18]

#define STD_FUNCTION_NAME yuv422_rgb24_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [9/18]

#define STD_FUNCTION_NAME yuv422_rgba_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [10/18]

#define STD_FUNCTION_NAME yuv422_bgra_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [11/18]

#define STD_FUNCTION_NAME yuv422_argb_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [12/18]

#define STD_FUNCTION_NAME yuv422_abgr_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [13/18]

#define STD_FUNCTION_NAME yuvnv12_rgb565_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [14/18]

#define STD_FUNCTION_NAME yuvnv12_rgb24_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [15/18]

#define STD_FUNCTION_NAME yuvnv12_rgba_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [16/18]

#define STD_FUNCTION_NAME yuvnv12_bgra_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [17/18]

#define STD_FUNCTION_NAME yuvnv12_argb_std

Definition at line 181 of file yuv_rgb.c.

## STD_FUNCTION_NAME [18/18]

#define STD_FUNCTION_NAME yuvnv12_abgr_std

Definition at line 181 of file yuv_rgb.c.

## V

#define V | ( |  | value | ) | (int16_t)((value*PRECISION_FACTOR)+0.5)

Definition at line 35 of file yuv_rgb.c.

## YUV_FORMAT [1/18]

#define YUV_FORMAT YUV_FORMAT_420

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [2/18]

#define YUV_FORMAT YUV_FORMAT_420

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [3/18]

#define YUV_FORMAT YUV_FORMAT_420

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [4/18]

#define YUV_FORMAT YUV_FORMAT_420

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [5/18]

#define YUV_FORMAT YUV_FORMAT_420

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [6/18]

#define YUV_FORMAT YUV_FORMAT_420

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [7/18]

#define YUV_FORMAT YUV_FORMAT_422

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [8/18]

#define YUV_FORMAT YUV_FORMAT_422

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [9/18]

#define YUV_FORMAT YUV_FORMAT_422

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [10/18]

#define YUV_FORMAT YUV_FORMAT_422

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [11/18]

#define YUV_FORMAT YUV_FORMAT_422

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [12/18]

#define YUV_FORMAT YUV_FORMAT_422

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [13/18]

#define YUV_FORMAT YUV_FORMAT_NV12

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [14/18]

#define YUV_FORMAT YUV_FORMAT_NV12

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [15/18]

#define YUV_FORMAT YUV_FORMAT_NV12

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [16/18]

#define YUV_FORMAT YUV_FORMAT_NV12

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [17/18]

#define YUV_FORMAT YUV_FORMAT_NV12

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT [18/18]

#define YUV_FORMAT YUV_FORMAT_NV12

Definition at line 182 of file yuv_rgb.c.

## YUV_FORMAT_420

#define YUV_FORMAT_420 1

Definition at line 61 of file yuv_rgb.c.

## YUV_FORMAT_422

#define YUV_FORMAT_422 2

Definition at line 62 of file yuv_rgb.c.

## YUV_FORMAT_NV12

#define YUV_FORMAT_NV12 3

Definition at line 63 of file yuv_rgb.c.

## Function Documentation

## clampU8()

static uint8_t clampU8 | ( | int32_t | v | ) |

static

Definition at line 75 of file yuv_rgb.c.

{
static const uint8_t lut[512] =
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,
47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,
126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,
159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,
225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
};
return lut[(v+128*PRECISION_FACTOR)>>PRECISION];
}

References PRECISION, and PRECISION_FACTOR.

Referenced by rgb24_yuv420_std().

## rgb24_yuv420_std()

void rgb24_yuv420_std | ( | uint32_t | width,
|  | uint32_t | height,
|  | const uint8_t * | RGB,
|  | uint32_t | RGB_stride,
|  | uint8_t * | Y,
|  | uint8_t * | U,
|  | uint8_t * | V,
|  | uint32_t | Y_stride,
|  | uint32_t | UV_stride,
|  | YCbCrType | yuv_type
| ) |  |

Definition at line 186 of file yuv_rgb.c.

{
const RGB2YUVParam *const param = &(RGB2YUV[yuv_type]);
uint32_t x, y;
for(y=0; y<(height-1); y+=2)
{
const uint8_t *rgb_ptr1=RGB+y*RGB_stride,
*rgb_ptr2=RGB+(y+1)*RGB_stride;
uint8_t *y_ptr1=Y+y*Y_stride,
*y_ptr2=Y+(y+1)*Y_stride,
*u_ptr=U+(y/2)*UV_stride,
*v_ptr=V+(y/2)*UV_stride;
for(x=0; x<(width-1); x+=2)
{
// compute yuv for the four pixels, u and v values are summed
int32_t y_tmp, u_tmp, v_tmp;
y_tmp = param->matrix[0][0]*rgb_ptr1[0] + param->matrix[0][1]*rgb_ptr1[1] + param->matrix[0][2]*rgb_ptr1[2];
u_tmp = param->matrix[1][0]*rgb_ptr1[0] + param->matrix[1][1]*rgb_ptr1[1] + param->matrix[1][2]*rgb_ptr1[2];
v_tmp = param->matrix[2][0]*rgb_ptr1[0] + param->matrix[2][1]*rgb_ptr1[1] + param->matrix[2][2]*rgb_ptr1[2];
y_ptr1[0]=clampU8(y_tmp+((param->y_shift)<<PRECISION));
y_tmp = param->matrix[0][0]*rgb_ptr1[3] + param->matrix[0][1]*rgb_ptr1[4] + param->matrix[0][2]*rgb_ptr1[5];
u_tmp += param->matrix[1][0]*rgb_ptr1[3] + param->matrix[1][1]*rgb_ptr1[4] + param->matrix[1][2]*rgb_ptr1[5];
v_tmp += param->matrix[2][0]*rgb_ptr1[3] + param->matrix[2][1]*rgb_ptr1[4] + param->matrix[2][2]*rgb_ptr1[5];
y_ptr1[1]=clampU8(y_tmp+((param->y_shift)<<PRECISION));
y_tmp = param->matrix[0][0]*rgb_ptr2[0] + param->matrix[0][1]*rgb_ptr2[1] + param->matrix[0][2]*rgb_ptr2[2];
u_tmp += param->matrix[1][0]*rgb_ptr2[0] + param->matrix[1][1]*rgb_ptr2[1] + param->matrix[1][2]*rgb_ptr2[2];
v_tmp += param->matrix[2][0]*rgb_ptr2[0] + param->matrix[2][1]*rgb_ptr2[1] + param->matrix[2][2]*rgb_ptr2[2];
y_ptr2[0]=clampU8(y_tmp+((param->y_shift)<<PRECISION));
y_tmp = param->matrix[0][0]*rgb_ptr2[3] + param->matrix[0][1]*rgb_ptr2[4] + param->matrix[0][2]*rgb_ptr2[5];
u_tmp += param->matrix[1][0]*rgb_ptr2[3] + param->matrix[1][1]*rgb_ptr2[4] + param->matrix[1][2]*rgb_ptr2[5];
v_tmp += param->matrix[2][0]*rgb_ptr2[3] + param->matrix[2][1]*rgb_ptr2[4] + param->matrix[2][2]*rgb_ptr2[5];
y_ptr2[1]=clampU8(y_tmp+((param->y_shift)<<PRECISION));
u_ptr[0] = clampU8(u_tmp/4+(128<<PRECISION));
v_ptr[0] = clampU8(v_tmp/4+(128<<PRECISION));
rgb_ptr1 += 6;
rgb_ptr2 += 6;
y_ptr1 += 2;
y_ptr2 += 2;
u_ptr += 1;
v_ptr += 1;
}
}
}

References clampU8(), PRECISION, RGB, RGB2YUV, and V.

Referenced by SDL_ConvertPixels_RGB_to_YUV().

## Variable Documentation

## RGB2YUV

const RGB2YUVParam RGB2YUV[3]

static

Initial value:
= {
{ 0, {{V(0.299), V(0.587), V(0.114)}, {-V(0.1687), -V(0.3313), V(0.5)}, {V(0.5), -V(0.4187), -V(0.0813)}}},
{ 16, {{V(0.2568), V(0.5041), V(0.0979)}, {-V(0.1482), -V(0.291), V(0.4392)}, {V(0.4392), -V(0.3678), -V(0.0714)}}},
{ 16, {{V(0.1826), V(0.6142), V(0.062)}, {-V(0.1006), -V(0.3386), V(0.4392)}, {V(0.4392), -V(0.3989), -V(0.0403)}}}
}

Definition at line 51 of file yuv_rgb.c.

Referenced by rgb24_yuv420_std().

## YUV2RGB

const YUV2RGBParam YUV2RGB[3]

static

Initial value:
= {
{ 0, V(1.0), V(1.402), -V(0.3441), -V(0.7141), V(1.772)},
{ 16, V(1.1644), V(1.596), -V(0.3918), -V(0.813), V(2.0172)},
{ 16, V(1.1644), V(1.7927), -V(0.2132), -V(0.5329), V(2.1124)}
}

Definition at line 42 of file yuv_rgb.c.

Referenced by SSE_FUNCTION_NAME(), and STD_FUNCTION_NAME().

clampU8
static uint8_t clampU8(int32_t v)
Definition: yuv_rgb.c:75
width
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
RGB
@ RGB
Definition: edid.h:20
v
const GLdouble * v
Definition: SDL_opengl.h:2064
RGB2YUV
static const RGB2YUVParam RGB2YUV[3]
Definition: yuv_rgb.c:51
RGB2YUVParam
Definition: yuv_rgb.c:13
V
#define V(value)
Definition: yuv_rgb.c:35
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
int32_t
signed int int32_t
Definition: SDL_config_windows.h:62
height
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
param
GLfloat param
Definition: SDL_opengl_glext.h:370
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
PRECISION
#define PRECISION
Definition: yuv_rgb.c:10
uint32_t
unsigned int uint32_t
Definition: SDL_config_windows.h:63
uint8_t
unsigned char uint8_t
Definition: SDL_config_windows.h:59
PRECISION_FACTOR
#define PRECISION_FACTOR
Definition: yuv_rgb.c:11