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

879 {
880 #if 0 /* Doesn't handle odd widths */
881  /* RGB24 to FOURCC */
882  if (src_format == SDL_PIXELFORMAT_RGB24) {
883  Uint8 *y;
884  Uint8 *u;
885  Uint8 *v;
886  Uint32 y_stride;
887  Uint32 uv_stride;
888  YCbCrType yuv_type;
889 
890  if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch, (const Uint8 **)&y, (const Uint8 **)&u, (const Uint8 **)&v, &y_stride, &uv_stride) < 0) {
891  return -1;
892  }
893 
894  if (GetYUVConversionType(width, height, &yuv_type) < 0) {
895  return -1;
896  }
897 
898  rgb24_yuv420_std(width, height, src, src_pitch, y, u, v, y_stride, uv_stride, yuv_type);
899  return 0;
900  }
901 #endif
902 
903  /* ARGB8888 to FOURCC */
904  if (src_format == SDL_PIXELFORMAT_ARGB8888) {
905  return SDL_ConvertPixels_ARGB8888_to_YUV(width, height, src, src_pitch, dst_format, dst, dst_pitch);
906  }
907 
908  /* not ARGB8888 to FOURCC : need an intermediate conversion */
909  {
910  int ret;
911  void *tmp;
912  int tmp_pitch = (width * sizeof(Uint32));
913 
914  tmp = SDL_malloc(tmp_pitch * height);
915  if (tmp == NULL) {
916  return SDL_OutOfMemory();
917  }
918 
919  /* convert src/src_format to tmp/ARGB8888 */
920  ret = SDL_ConvertPixels(width, height, src_format, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch);
921  if (ret == -1) {
922  SDL_free(tmp);
923  return ret;
924  }
925 
926  /* convert tmp/ARGB8888 to dst/FOURCC */
927  ret = SDL_ConvertPixels_ARGB8888_to_YUV(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch);
928  SDL_free(tmp);
929  return ret;
930  }
931 }
const GLdouble * v
Definition: SDL_opengl.h:2064
GLenum GLenum dst
uint8_t Uint8
Definition: SDL_stdinc.h:179
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
uint32_t Uint32
Definition: SDL_stdinc.h:203
float u[3]
Definition: SDL_yuv.c:545
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
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:550
#define SDL_free
static int GetYUVConversionType(int width, int height, YCbCrType *yuv_type)
Definition: SDL_yuv.c:59
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 479 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_lsx(), yuv_rgb_msa(), yuv_rgb_sse(), and yuv_rgb_std().

Referenced by SDL_ConvertPixels(), and SDL_ConvertPixels_YUV_to_RGB().

482 {
483  const Uint8 *y = NULL;
484  const Uint8 *u = NULL;
485  const Uint8 *v = NULL;
486  Uint32 y_stride = 0;
487  Uint32 uv_stride = 0;
488  YCbCrType yuv_type = YCBCR_601;
489 
490  if (GetYUVPlanes(width, height, src_format, src, src_pitch, &y, &u, &v, &y_stride, &uv_stride) < 0) {
491  return -1;
492  }
493 
494  if (GetYUVConversionType(width, height, &yuv_type) < 0) {
495  return -1;
496  }
497 
498  if (yuv_rgb_sse(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8*)dst, dst_pitch, yuv_type)) {
499  return 0;
500  }
501 
502  if (yuv_rgb_msa(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8*)dst, dst_pitch, yuv_type)) {
503  return 0;
504  }
505 
506  if (yuv_rgb_lsx(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8*)dst, dst_pitch, yuv_type)) {
507  return 0;
508  }
509 
510  if (yuv_rgb_std(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8*)dst, dst_pitch, yuv_type)) {
511  return 0;
512  }
513 
514  /* No fast path for the RGB format, instead convert using an intermediate buffer */
515  if (dst_format != SDL_PIXELFORMAT_ARGB8888) {
516  int ret;
517  void *tmp;
518  int tmp_pitch = (width * sizeof(Uint32));
519 
520  tmp = SDL_malloc(tmp_pitch * height);
521  if (tmp == NULL) {
522  return SDL_OutOfMemory();
523  }
524 
525  /* convert src/src_format to tmp/ARGB8888 */
526  ret = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch);
527  if (ret < 0) {
528  SDL_free(tmp);
529  return ret;
530  }
531 
532  /* convert tmp/ARGB8888 to dst/RGB */
533  ret = SDL_ConvertPixels(width, height, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch, dst_format, dst, dst_pitch);
534  SDL_free(tmp);
535  return ret;
536  }
537 
538  return SDL_SetError("Unsupported YUV conversion");
539 }
const GLdouble * v
Definition: SDL_opengl.h:2064
GLenum GLenum dst
uint8_t Uint8
Definition: SDL_stdinc.h:179
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:375
GLenum src
uint32_t Uint32
Definition: SDL_stdinc.h:203
float u[3]
Definition: SDL_yuv.c:545
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
static SDL_bool yuv_rgb_msa(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:479
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
#define SDL_free
static SDL_bool yuv_rgb_lsx(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:333
static int GetYUVConversionType(int width, int height, YCbCrType *yuv_type)
Definition: SDL_yuv.c:59
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
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 1902 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().

1905 {
1906  if (src_format == dst_format) {
1907  if (src == dst) {
1908  /* Nothing to do */
1909  return 0;
1910  }
1911  return SDL_ConvertPixels_YUV_to_YUV_Copy(width, height, src_format, src, src_pitch, dst, dst_pitch);
1912  }
1913 
1914  if (IsPlanar2x2Format(src_format) && IsPlanar2x2Format(dst_format)) {
1915  return SDL_ConvertPixels_Planar2x2_to_Planar2x2(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1916  } else if (IsPacked4Format(src_format) && IsPacked4Format(dst_format)) {
1917  return SDL_ConvertPixels_Packed4_to_Packed4(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1918  } else if (IsPlanar2x2Format(src_format) && IsPacked4Format(dst_format)) {
1919  return SDL_ConvertPixels_Planar2x2_to_Packed4(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1920  } else if (IsPacked4Format(src_format) && IsPlanar2x2Format(dst_format)) {
1921  return SDL_ConvertPixels_Packed4_to_Planar2x2(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
1922  } else {
1923  return SDL_SetError("SDL_ConvertPixels_YUV_to_YUV: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), SDL_GetPixelFormatName(dst_format));
1924  }
1925 }
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:1627
static SDL_bool IsPacked4Format(Uint32 format)
Definition: SDL_yuv.c:85
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:1770
GLenum src
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
static SDL_bool IsPlanar2x2Format(Uint32 format)
Definition: SDL_yuv.c:77
#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:1585
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:1245
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:934
#define SDL_GetPixelFormatName