SDL_yuv_c.h File Reference
`#include "../SDL_internal.h"`
Include dependency graph for SDL_yuv_c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions

int | SDL_ConvertPixels_YUV_to_RGB (int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
int | SDL_ConvertPixels_RGB_to_YUV (int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
int | SDL_ConvertPixels_YUV_to_YUV (int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)

## Function Documentation

## SDL_ConvertPixels_RGB_to_YUV()

int SDL_ConvertPixels_RGB_to_YUV | ( | int | width,
|  | int | height,
|  | Uint32 | src_format,
|  | const void * | src,
|  | int | src_pitch,
|  | Uint32 | dst_format,
|  | void * | dst,
|  | int | dst_pitch
| ) |  |

Definition at line 783 of file SDL_yuv.c.

References GetYUVConversionType(), GetYUVPlanes(), NULL, rgb24_yuv420_std(), SDL_ConvertPixels, SDL_ConvertPixels_ARGB8888_to_YUV(), SDL_free, SDL_malloc, SDL_OutOfMemory, SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB24, RGB2YUVFactors::u, RGB2YUVFactors::v, and RGB2YUVFactors::y.

Referenced by SDL_ConvertPixels().

{
#if 0 /* Doesn't handle odd widths */
/* RGB24 to FOURCC */
if (src_format == SDL_PIXELFORMAT_RGB24) {
Uint8 *y;
Uint8 *u;
Uint8 *v;
Uint32 y_stride;
Uint32 uv_stride;
YCbCrType yuv_type;
if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch, (const Uint8 **)&y, (const Uint8 **)&u, (const Uint8 **)&v, &y_stride, &uv_stride) < 0) {
return -1;
}
if (GetYUVConversionType(width, height, &yuv_type) < 0) {
return -1;
}
rgb24_yuv420_std(width, height, src, src_pitch, y, u, v, y_stride, uv_stride, yuv_type);
return 0;
}
#endif
/* ARGB8888 to FOURCC */
if (src_format == SDL_PIXELFORMAT_ARGB8888) {
return SDL_ConvertPixels_ARGB8888_to_YUV(width, height, src, src_pitch, dst_format, dst, dst_pitch);
}
/* not ARGB8888 to FOURCC : need an intermediate conversion */
{
int ret;
void *tmp;
int tmp_pitch = (width * sizeof(Uint32));
tmp = SDL_malloc(tmp_pitch * height);
if (tmp == NULL) {
return SDL_OutOfMemory();
}
/* convert src/src_format to tmp/ARGB8888 */
ret = SDL_ConvertPixels(width, height, src_format, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch);
if (ret == -1) {
SDL_free(tmp);
return ret;
}
/* convert tmp/ARGB8888 to dst/FOURCC */
ret = SDL_ConvertPixels_ARGB8888_to_YUV(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch);
SDL_free(tmp);
return ret;
}
}
SDL_PIXELFORMAT_ARGB8888
Definition: SDL_pixels.h:248
v
const GLdouble * v
Definition: SDL_opengl.h:2064
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1737
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:181
src
GLenum src
Definition: SDL_opengl_glext.h:1737
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: yuv_rgb.c:186
RGB2YUVFactors::u
float u[3]
Definition: SDL_yuv.c:452
GetYUVPlanes
static int GetYUVPlanes(int width, int height, Uint32 format, const void *yuv, int yuv_pitch, const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride)
Definition: SDL_yuv.c:91
width
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
SDL_ConvertPixels_ARGB8888_to_YUV
static int SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
Definition: SDL_yuv.c:457
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:157
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
GetYUVConversionType
static int GetYUVConversionType(int width, int height, YCbCrType *yuv_type)
Definition: SDL_yuv.c:58
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
YCbCrType
YCbCrType
Definition: yuv_rgb.h:22
NULL
#define NULL
Definition: begin_code.h:164
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
height
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
SDL_PIXELFORMAT_RGB24
Definition: SDL_pixels.h:230
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
SDL_ConvertPixels
#define SDL_ConvertPixels
Definition: SDL_dynapi_overrides.h:465

## SDL_ConvertPixels_YUV_to_RGB()

int SDL_ConvertPixels_YUV_to_RGB | ( | int | width,
|  | int | height,
|  | Uint32 | src_format,
|  | const void * | src,
|  | int | src_pitch,
|  | Uint32 | dst_format,
|  | void * | dst,
|  | int | dst_pitch
| ) |  |

Definition at line 394 of file SDL_yuv.c.

References GetYUVConversionType(), GetYUVPlanes(), NULL, SDL_ConvertPixels, SDL_ConvertPixels_YUV_to_RGB(), SDL_free, SDL_malloc, SDL_OutOfMemory, SDL_PIXELFORMAT_ARGB8888, SDL_SetError, YCBCR_601, yuv_rgb_sse(), and yuv_rgb_std().

Referenced by SDL_ConvertPixels(), and SDL_ConvertPixels_YUV_to_RGB().

{
const Uint8 *y = NULL;
const Uint8 *u = NULL;
const Uint8 *v = NULL;
Uint32 y_stride = 0;
Uint32 uv_stride = 0;
YCbCrType yuv_type = YCBCR_601;
if (GetYUVPlanes(width, height, src_format, src, src_pitch, &y, &u, &v, &y_stride, &uv_stride) < 0) {
return -1;
}
if (GetYUVConversionType(width, height, &yuv_type) < 0) {
return -1;
}
if (yuv_rgb_sse(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8*)dst, dst_pitch, yuv_type)) {
return 0;
}
if (yuv_rgb_std(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8*)dst, dst_pitch, yuv_type)) {
return 0;
}
/* No fast path for the RGB format, instead convert using an intermediate buffer */
if (dst_format != SDL_PIXELFORMAT_ARGB8888) {
int ret;
void *tmp;
int tmp_pitch = (width * sizeof(Uint32));
tmp = SDL_malloc(tmp_pitch * height);
if (tmp == NULL) {
return SDL_OutOfMemory();
}
/* convert src/src_format to tmp/ARGB8888 */
ret = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch);
if (ret < 0) {
SDL_free(tmp);
return ret;
}
/* convert tmp/ARGB8888 to dst/RGB */
ret = SDL_ConvertPixels(width, height, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch, dst_format, dst, dst_pitch);
SDL_free(tmp);
return ret;
}
return SDL_SetError("Unsupported YUV conversion");
}
SDL_PIXELFORMAT_ARGB8888
Definition: SDL_pixels.h:248
v
const GLdouble * v
Definition: SDL_opengl.h:2064
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1737
yuv_rgb_std
static SDL_bool yuv_rgb_std(Uint32 src_format, Uint32 dst_format, Uint32 width, Uint32 height, const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride, Uint8 *rgb, Uint32 rgb_stride, YCbCrType yuv_type)
Definition: SDL_yuv.c:290
YCBCR_601
Definition: yuv_rgb.h:25
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:181
src
GLenum src
Definition: SDL_opengl_glext.h:1737
RGB2YUVFactors::u
float u[3]
Definition: SDL_yuv.c:452
GetYUVPlanes
static int GetYUVPlanes(int width, int height, Uint32 format, const void *yuv, int yuv_pitch, const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride)
Definition: SDL_yuv.c:91
SDL_ConvertPixels_YUV_to_RGB
int SDL_ConvertPixels_YUV_to_RGB(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
Definition: SDL_yuv.c:394
width
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:157
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
GetYUVConversionType
static int GetYUVConversionType(int width, int height, YCbCrType *yuv_type)
Definition: SDL_yuv.c:58
yuv_rgb_sse
static SDL_bool yuv_rgb_sse(Uint32 src_format, Uint32 dst_format, Uint32 width, Uint32 height, const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride, Uint8 *rgb, Uint32 rgb_stride, YCbCrType yuv_type)
Definition: SDL_yuv.c:181
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
YCbCrType
YCbCrType
Definition: yuv_rgb.h:22
NULL
#define NULL
Definition: begin_code.h:164
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
height
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
SDL_ConvertPixels
#define SDL_ConvertPixels
Definition: SDL_dynapi_overrides.h:465

## SDL_ConvertPixels_YUV_to_YUV()

int SDL_ConvertPixels_YUV_to_YUV | ( | int | width,
|  | int | height,
|  | Uint32 | src_format,
|  | const void * | src,
|  | int | src_pitch,
|  | Uint32 | dst_format,
|  | void * | dst,
|  | int | dst_pitch
| ) |  |

Definition at line 1809 of file SDL_yuv.c.

References IsPacked4Format(), IsPlanar2x2Format(), SDL_ConvertPixels_Packed4_to_Packed4(), SDL_ConvertPixels_Packed4_to_Planar2x2(), SDL_ConvertPixels_Planar2x2_to_Packed4(), SDL_ConvertPixels_Planar2x2_to_Planar2x2(), SDL_ConvertPixels_YUV_to_YUV_Copy(), SDL_GetPixelFormatName, and SDL_SetError.

Referenced by SDL_ConvertPixels().

{
if (src_format == dst_format) {
if (src == dst) {
/* Nothing to do */
return 0;
}
return SDL_ConvertPixels_YUV_to_YUV_Copy(width, height, src_format, src, src_pitch, dst, dst_pitch);
}
if (IsPlanar2x2Format(src_format) && IsPlanar2x2Format(dst_format)) {
return SDL_ConvertPixels_Planar2x2_to_Planar2x2(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
} else if (IsPacked4Format(src_format) && IsPacked4Format(dst_format)) {
return SDL_ConvertPixels_Packed4_to_Packed4(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
} else if (IsPlanar2x2Format(src_format) && IsPacked4Format(dst_format)) {
return SDL_ConvertPixels_Planar2x2_to_Packed4(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
} else if (IsPacked4Format(src_format) && IsPlanar2x2Format(dst_format)) {
return SDL_ConvertPixels_Packed4_to_Planar2x2(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
} else {
return SDL_SetError("SDL_ConvertPixels_YUV_to_YUV: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), SDL_GetPixelFormatName(dst_format));
}
}
SDL_ConvertPixels_Planar2x2_to_Packed4
static int SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
Definition: SDL_yuv.c:1534
IsPacked4Format
static SDL_bool IsPacked4Format(Uint32 format)
Definition: SDL_yuv.c:84
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1737
SDL_ConvertPixels_Packed4_to_Planar2x2
static int SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
Definition: SDL_yuv.c:1677
src
GLenum src
Definition: SDL_opengl_glext.h:1737
width
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
IsPlanar2x2Format
static SDL_bool IsPlanar2x2Format(Uint32 format)
Definition: SDL_yuv.c:76
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
height
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
SDL_ConvertPixels_Packed4_to_Packed4
static int SDL_ConvertPixels_Packed4_to_Packed4(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
Definition: SDL_yuv.c:1492
SDL_ConvertPixels_Planar2x2_to_Planar2x2
static int SDL_ConvertPixels_Planar2x2_to_Planar2x2(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
Definition: SDL_yuv.c:1152
SDL_ConvertPixels_YUV_to_YUV_Copy
static int SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, Uint32 format, const void *src, int src_pitch, void *dst, int dst_pitch)
Definition: SDL_yuv.c:841
SDL_GetPixelFormatName
#define SDL_GetPixelFormatName
Definition: SDL_dynapi_overrides.h:277