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

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

397 {
398  const Uint8 *y = NULL;
399  const Uint8 *u = NULL;
400  const Uint8 *v = NULL;
401  Uint32 y_stride = 0;
402  Uint32 uv_stride = 0;
403  YCbCrType yuv_type = YCBCR_601;
404 
405  if (GetYUVPlanes(width, height, src_format, src, src_pitch, &y, &u, &v, &y_stride, &uv_stride) < 0) {
406  return -1;
407  }
408 
409  if (GetYUVConversionType(width, height, &yuv_type) < 0) {
410  return -1;
411  }
412 
413  if (yuv_rgb_sse(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8*)dst, dst_pitch, yuv_type)) {
414  return 0;
415  }
416 
417  if (yuv_rgb_std(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8*)dst, dst_pitch, yuv_type)) {
418  return 0;
419  }
420 
421  /* No fast path for the RGB format, instead convert using an intermediate buffer */
422  if (dst_format != SDL_PIXELFORMAT_ARGB8888) {
423  int ret;
424  void *tmp;
425  int tmp_pitch = (width * sizeof(Uint32));
426 
427  tmp = SDL_malloc(tmp_pitch * height);
428  if (tmp == NULL) {
429  return SDL_OutOfMemory();
430  }
431 
432  /* convert src/src_format to tmp/ARGB8888 */
433  ret = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch);
434  if (ret < 0) {
435  SDL_free(tmp);
436  return ret;
437  }
438 
439  /* convert tmp/ARGB8888 to dst/RGB */
440  ret = SDL_ConvertPixels(width, height, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch, dst_format, dst, dst_pitch);
441  SDL_free(tmp);
442  return ret;
443  }
444 
445  return SDL_SetError("Unsupported YUV conversion");
446 }
const GLdouble * v
Definition: SDL_opengl.h:2064
GLenum GLenum dst
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
uint32_t Uint32
Definition: SDL_stdinc.h:181
GLenum src
float u[3]
Definition: SDL_yuv.c:452
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
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
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
uint8_t Uint8
Definition: SDL_stdinc.h:157
#define SDL_free
static int GetYUVConversionType(int width, int height, YCbCrType *yuv_type)
Definition: SDL_yuv.c:58
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
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
YCbCrType
Definition: yuv_rgb.h:22
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_SetError
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
#define SDL_malloc
#define SDL_ConvertPixels

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

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