SDL 2.0
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 784 of file SDL_yuv.c.

787{
788#if 0 /* Doesn't handle odd widths */
789 /* RGB24 to FOURCC */
790 if (src_format == SDL_PIXELFORMAT_RGB24) {
791 Uint8 *y;
792 Uint8 *u;
793 Uint8 *v;
794 Uint32 y_stride;
795 Uint32 uv_stride;
796 YCbCrType yuv_type;
797
798 if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch, (const Uint8 **)&y, (const Uint8 **)&u, (const Uint8 **)&v, &y_stride, &uv_stride) < 0) {
799 return -1;
800 }
801
802 if (GetYUVConversionType(width, height, &yuv_type) < 0) {
803 return -1;
804 }
805
806 rgb24_yuv420_std(width, height, src, src_pitch, y, u, v, y_stride, uv_stride, yuv_type);
807 return 0;
808 }
809#endif
810
811 /* ARGB8888 to FOURCC */
812 if (src_format == SDL_PIXELFORMAT_ARGB8888) {
813 return SDL_ConvertPixels_ARGB8888_to_YUV(width, height, src, src_pitch, dst_format, dst, dst_pitch);
814 }
815
816 /* not ARGB8888 to FOURCC : need an intermediate conversion */
817 {
818 int ret;
819 void *tmp;
820 int tmp_pitch = (width * sizeof(Uint32));
821
822 tmp = SDL_malloc(tmp_pitch * height);
823 if (tmp == NULL) {
824 return SDL_OutOfMemory();
825 }
826
827 /* convert src/src_format to tmp/ARGB8888 */
828 ret = SDL_ConvertPixels(width, height, src_format, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch);
829 if (ret == -1) {
830 SDL_free(tmp);
831 return ret;
832 }
833
834 /* convert tmp/ARGB8888 to dst/FOURCC */
835 ret = SDL_ConvertPixels_ARGB8888_to_YUV(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch);
836 SDL_free(tmp);
837 return ret;
838 }
839}
#define SDL_malloc
#define SDL_free
#define SDL_ConvertPixels
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
const GLdouble * v
Definition: SDL_opengl.h:2064
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
GLenum src
GLenum GLenum dst
@ SDL_PIXELFORMAT_RGB24
Definition: SDL_pixels.h:230
@ SDL_PIXELFORMAT_ARGB8888
Definition: SDL_pixels.h:248
uint32_t Uint32
Definition: SDL_stdinc.h:203
uint8_t Uint8
Definition: SDL_stdinc.h:179
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:458
static int GetYUVConversionType(int width, int height, YCbCrType *yuv_type)
Definition: SDL_yuv.c:59
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:92
#define NULL
Definition: begin_code.h:167
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
YCbCrType
Definition: yuv_rgb.h:23

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, and RGB2YUVFactors::u.

Referenced by SDL_ConvertPixels().

◆ 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 395 of file SDL_yuv.c.

398{
399 const Uint8 *y = NULL;
400 const Uint8 *u = NULL;
401 const Uint8 *v = NULL;
402 Uint32 y_stride = 0;
403 Uint32 uv_stride = 0;
404 YCbCrType yuv_type = YCBCR_601;
405
406 if (GetYUVPlanes(width, height, src_format, src, src_pitch, &y, &u, &v, &y_stride, &uv_stride) < 0) {
407 return -1;
408 }
409
410 if (GetYUVConversionType(width, height, &yuv_type) < 0) {
411 return -1;
412 }
413
414 if (yuv_rgb_sse(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8*)dst, dst_pitch, yuv_type)) {
415 return 0;
416 }
417
418 if (yuv_rgb_std(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8*)dst, dst_pitch, yuv_type)) {
419 return 0;
420 }
421
422 /* No fast path for the RGB format, instead convert using an intermediate buffer */
423 if (dst_format != SDL_PIXELFORMAT_ARGB8888) {
424 int ret;
425 void *tmp;
426 int tmp_pitch = (width * sizeof(Uint32));
427
428 tmp = SDL_malloc(tmp_pitch * height);
429 if (tmp == NULL) {
430 return SDL_OutOfMemory();
431 }
432
433 /* convert src/src_format to tmp/ARGB8888 */
434 ret = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch);
435 if (ret < 0) {
436 SDL_free(tmp);
437 return ret;
438 }
439
440 /* convert tmp/ARGB8888 to dst/RGB */
441 ret = SDL_ConvertPixels(width, height, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch, dst_format, dst, dst_pitch);
442 SDL_free(tmp);
443 return ret;
444 }
445
446 return SDL_SetError("Unsupported YUV conversion");
447}
#define SDL_SetError
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:291
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:395
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:182
@ YCBCR_601
Definition: yuv_rgb.h:25

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().

◆ 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 1810 of file SDL_yuv.c.

1813{
1814 if (src_format == dst_format) {
1815 if (src == dst) {
1816 /* Nothing to do */
1817 return 0;
1818 }
1819 return SDL_ConvertPixels_YUV_to_YUV_Copy(width, height, src_format, src, src_pitch, dst, dst_pitch);
1820 }
1821
1822 if (IsPlanar2x2Format(src_format) && IsPlanar2x2Format(dst_format)) {
1823 return SDL_ConvertPixels_Planar2x2_to_Planar2x2(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1824 } else if (IsPacked4Format(src_format) && IsPacked4Format(dst_format)) {
1825 return SDL_ConvertPixels_Packed4_to_Packed4(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1826 } else if (IsPlanar2x2Format(src_format) && IsPacked4Format(dst_format)) {
1827 return SDL_ConvertPixels_Planar2x2_to_Packed4(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1828 } else if (IsPacked4Format(src_format) && IsPlanar2x2Format(dst_format)) {
1829 return SDL_ConvertPixels_Packed4_to_Planar2x2(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1830 } else {
1831 return SDL_SetError("SDL_ConvertPixels_YUV_to_YUV: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), SDL_GetPixelFormatName(dst_format));
1832 }
1833}
#define SDL_GetPixelFormatName
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:842
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:1535
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:1493
static SDL_bool IsPlanar2x2Format(Uint32 format)
Definition: SDL_yuv.c:77
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:1153
static SDL_bool IsPacked4Format(Uint32 format)
Definition: SDL_yuv.c:85
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:1678

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().