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

789 {
790 #if 0 /* Doesn't handle odd widths */
791  /* RGB24 to FOURCC */
792  if (src_format == SDL_PIXELFORMAT_RGB24) {
793  Uint8 *y;
794  Uint8 *u;
795  Uint8 *v;
796  Uint32 y_stride;
797  Uint32 uv_stride;
798  YCbCrType yuv_type;
799 
800  if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch, (const Uint8 **)&y, (const Uint8 **)&u, (const Uint8 **)&v, &y_stride, &uv_stride) < 0) {
801  return -1;
802  }
803 
804  if (GetYUVConversionType(width, height, &yuv_type) < 0) {
805  return -1;
806  }
807 
808  rgb24_yuv420_std(width, height, src, src_pitch, y, u, v, y_stride, uv_stride, yuv_type);
809  return 0;
810  }
811 #endif
812 
813  /* ARGB8888 to FOURCC */
814  if (src_format == SDL_PIXELFORMAT_ARGB8888) {
815  return SDL_ConvertPixels_ARGB8888_to_YUV(width, height, src, src_pitch, dst_format, dst, dst_pitch);
816  }
817 
818  /* not ARGB8888 to FOURCC : need an intermediate conversion */
819  {
820  int ret;
821  void *tmp;
822  int tmp_pitch = (width * sizeof(Uint32));
823 
824  tmp = SDL_malloc(tmp_pitch * height);
825  if (tmp == NULL) {
826  return SDL_OutOfMemory();
827  }
828 
829  /* convert src/src_format to tmp/ARGB8888 */
830  ret = SDL_ConvertPixels(width, height, src_format, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch);
831  if (ret == -1) {
832  SDL_free(tmp);
833  return ret;
834  }
835 
836  /* convert tmp/ARGB8888 to dst/FOURCC */
837  ret = SDL_ConvertPixels_ARGB8888_to_YUV(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch);
838  SDL_free(tmp);
839  return ret;
840  }
841 }

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

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

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

1820 {
1821 #if SDL_HAVE_YUV
1822  if (src_format == dst_format) {
1823  if (src == dst) {
1824  /* Nothing to do */
1825  return 0;
1826  }
1827  return SDL_ConvertPixels_YUV_to_YUV_Copy(width, height, src_format, src, src_pitch, dst, dst_pitch);
1828  }
1829 
1830  if (IsPlanar2x2Format(src_format) && IsPlanar2x2Format(dst_format)) {
1831  return SDL_ConvertPixels_Planar2x2_to_Planar2x2(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1832  } else if (IsPacked4Format(src_format) && IsPacked4Format(dst_format)) {
1833  return SDL_ConvertPixels_Packed4_to_Packed4(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1834  } else if (IsPlanar2x2Format(src_format) && IsPacked4Format(dst_format)) {
1835  return SDL_ConvertPixels_Planar2x2_to_Packed4(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1836  } else if (IsPacked4Format(src_format) && IsPlanar2x2Format(dst_format)) {
1837  return SDL_ConvertPixels_Packed4_to_Planar2x2(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1838  } else {
1839  return SDL_SetError("SDL_ConvertPixels_YUV_to_YUV: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), SDL_GetPixelFormatName(dst_format));
1840  }
1841 #else
1842  return SDL_SetError("SDL not built with YUV support");
1843 #endif
1844 }

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

Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179
GetYUVConversionType
static int GetYUVConversionType(int width, int height, YCbCrType *yuv_type)
Definition: SDL_yuv.c:61
SDL_GetPixelFormatName
#define SDL_GetPixelFormatName
Definition: SDL_dynapi_overrides.h:277
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:1498
NULL
#define NULL
Definition: begin_code.h:167
width
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
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:188
RGB2YUVFactors::u
float u[3]
Definition: SDL_yuv.c:455
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
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:460
v
const GLdouble * v
Definition: SDL_opengl.h:2064
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:94
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1740
YCBCR_601
@ YCBCR_601
Definition: yuv_rgb.h:25
IsPlanar2x2Format
static SDL_bool IsPlanar2x2Format(Uint32 format)
Definition: SDL_yuv.c:79
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
height
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
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:184
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:293
SDL_PIXELFORMAT_ARGB8888
@ SDL_PIXELFORMAT_ARGB8888
Definition: SDL_pixels.h:251
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
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:1540
src
GLenum src
Definition: SDL_opengl_glext.h:1740
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_PIXELFORMAT_RGB24
@ SDL_PIXELFORMAT_RGB24
Definition: SDL_pixels.h:233
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:1155
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:1683
YCbCrType
YCbCrType
Definition: yuv_rgb.h:23
SDL_ConvertPixels
#define SDL_ConvertPixels
Definition: SDL_dynapi_overrides.h:465
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:844
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
IsPacked4Format
static SDL_bool IsPacked4Format(Uint32 format)
Definition: SDL_yuv.c:87
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:397