SDL  2.0
SDL_yuv_sw_c.h File Reference
#include "../SDL_internal.h"
#include "SDL_video.h"
+ Include dependency graph for SDL_yuv_sw_c.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_SW_YUVTexture
 

Functions

SDL_SW_YUVTextureSDL_SW_CreateYUVTexture (Uint32 format, int w, int h)
 
int SDL_SW_QueryYUVTexturePixels (SDL_SW_YUVTexture *swdata, void **pixels, int *pitch)
 
int SDL_SW_UpdateYUVTexture (SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, const void *pixels, int pitch)
 
int SDL_SW_UpdateYUVTexturePlanar (SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch)
 
int SDL_SW_LockYUVTexture (SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, void **pixels, int *pitch)
 
void SDL_SW_UnlockYUVTexture (SDL_SW_YUVTexture *swdata)
 
int SDL_SW_CopyYUVToRGB (SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, Uint32 target_format, int w, int h, void *pixels, int pitch)
 
void SDL_SW_DestroyYUVTexture (SDL_SW_YUVTexture *swdata)
 

Function Documentation

◆ SDL_SW_CopyYUVToRGB()

int SDL_SW_CopyYUVToRGB ( SDL_SW_YUVTexture swdata,
const SDL_Rect srcrect,
Uint32  target_format,
int  w,
int  h,
void pixels,
int  pitch 
)

Definition at line 1273 of file SDL_yuv_sw.c.

References SDL_SW_YUVTexture::colortab, SDL_SW_YUVTexture::display, SDL_SW_YUVTexture::Display1X, SDL_SW_YUVTexture::Display2X, SDL_SW_YUVTexture::format, SDL_SW_YUVTexture::h, SDL_Rect::h, SDL_Surface::h, NULL, SDL_Surface::pitch, SDL_Surface::pixels, SDL_SW_YUVTexture::planes, rect, SDL_SW_YUVTexture::rgb_2_pix, SDL_BYTESPERPIXEL, SDL_CreateRGBSurface, SDL_CreateRGBSurfaceFrom, SDL_PIXELFORMAT_IYUV, SDL_PIXELFORMAT_UYVY, SDL_PIXELFORMAT_YUY2, SDL_PIXELFORMAT_YV12, SDL_PIXELFORMAT_YVYU, SDL_PixelFormatEnumToMasks, SDL_SetError, SDL_SoftStretch, SDL_SW_SetupYUVDisplay(), SDL_SW_YUVTexture::stretch, SDL_SW_YUVTexture::target_format, SDL_SW_YUVTexture::w, SDL_Rect::w, SDL_Surface::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_UnlockTextureYUV(), SDL_UpdateTextureYUV(), and SDL_UpdateTextureYUVPlanar().

1276 {
1277  const int targetbpp = SDL_BYTESPERPIXEL(target_format);
1278  int stretch;
1279  int scale_2x;
1280  Uint8 *lum, *Cr, *Cb;
1281  int mod;
1282 
1283  if (targetbpp == 0) {
1284  return SDL_SetError("Invalid target pixel format");
1285  }
1286 
1287  /* Make sure we're set up to display in the desired format */
1288  if (target_format != swdata->target_format) {
1289  if (SDL_SW_SetupYUVDisplay(swdata, target_format) < 0) {
1290  return -1;
1291  }
1292  }
1293 
1294  stretch = 0;
1295  scale_2x = 0;
1296  if (srcrect->x || srcrect->y || srcrect->w < swdata->w
1297  || srcrect->h < swdata->h) {
1298  /* The source rectangle has been clipped.
1299  Using a scratch surface is easier than adding clipped
1300  source support to all the blitters, plus that would
1301  slow them down in the general unclipped case.
1302  */
1303  stretch = 1;
1304  } else if ((srcrect->w != w) || (srcrect->h != h)) {
1305  if ((w == 2 * srcrect->w) && (h == 2 * srcrect->h)) {
1306  scale_2x = 1;
1307  } else {
1308  stretch = 1;
1309  }
1310  }
1311  if (stretch) {
1312  int bpp;
1313  Uint32 Rmask, Gmask, Bmask, Amask;
1314 
1315  if (swdata->display) {
1316  swdata->display->w = w;
1317  swdata->display->h = h;
1318  swdata->display->pixels = pixels;
1319  swdata->display->pitch = pitch;
1320  } else {
1321  /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */
1322  SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask,
1323  &Bmask, &Amask);
1324  swdata->display =
1325  SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask,
1326  Gmask, Bmask, Amask);
1327  if (!swdata->display) {
1328  return (-1);
1329  }
1330  }
1331  if (!swdata->stretch) {
1332  /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */
1333  SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask,
1334  &Bmask, &Amask);
1335  swdata->stretch =
1336  SDL_CreateRGBSurface(0, swdata->w, swdata->h, bpp, Rmask,
1337  Gmask, Bmask, Amask);
1338  if (!swdata->stretch) {
1339  return (-1);
1340  }
1341  }
1342  pixels = swdata->stretch->pixels;
1343  pitch = swdata->stretch->pitch;
1344  }
1345  switch (swdata->format) {
1346  case SDL_PIXELFORMAT_YV12:
1347  lum = swdata->planes[0];
1348  Cr = swdata->planes[1];
1349  Cb = swdata->planes[2];
1350  break;
1351  case SDL_PIXELFORMAT_IYUV:
1352  lum = swdata->planes[0];
1353  Cr = swdata->planes[2];
1354  Cb = swdata->planes[1];
1355  break;
1356  case SDL_PIXELFORMAT_YUY2:
1357  lum = swdata->planes[0];
1358  Cr = lum + 3;
1359  Cb = lum + 1;
1360  break;
1361  case SDL_PIXELFORMAT_UYVY:
1362  lum = swdata->planes[0] + 1;
1363  Cr = lum + 1;
1364  Cb = lum - 1;
1365  break;
1366  case SDL_PIXELFORMAT_YVYU:
1367  lum = swdata->planes[0];
1368  Cr = lum + 1;
1369  Cb = lum + 3;
1370  break;
1371  default:
1372  return SDL_SetError("Unsupported YUV format in copy");
1373  }
1374  mod = (pitch / targetbpp);
1375 
1376  if (scale_2x) {
1377  mod -= (swdata->w * 2);
1378  swdata->Display2X(swdata->colortab, swdata->rgb_2_pix,
1379  lum, Cr, Cb, pixels, swdata->h, swdata->w, mod);
1380  } else {
1381  mod -= swdata->w;
1382  swdata->Display1X(swdata->colortab, swdata->rgb_2_pix,
1383  lum, Cr, Cb, pixels, swdata->h, swdata->w, mod);
1384  }
1385  if (stretch) {
1386  SDL_Rect rect = *srcrect;
1387  SDL_SoftStretch(swdata->stretch, &rect, swdata->display, NULL);
1388  }
1389  return 0;
1390 }
void(* Display1X)(int *colortab, Uint32 *rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, int rows, int cols, int mod)
Definition: SDL_yuv_sw_c.h:35
static int SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture *swdata, Uint32 target_format)
Definition: SDL_yuv_sw.c:889
#define SDL_SoftStretch
SDL_Rect rect
Definition: testrelative.c:27
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
#define SDL_CreateRGBSurfaceFrom
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
Uint32 * rgb_2_pix
Definition: SDL_yuv_sw_c.h:34
#define SDL_PixelFormatEnumToMasks
int x
Definition: SDL_rect.h:66
SDL_Surface * stretch
Definition: SDL_yuv_sw_c.h:49
int w
Definition: SDL_rect.h:67
Uint8 * planes[3]
Definition: SDL_yuv_sw_c.h:46
void(* Display2X)(int *colortab, Uint32 *rgb_2_pix, unsigned char *lum, unsigned char *cr, unsigned char *cb, unsigned char *out, int rows, int cols, int mod)
Definition: SDL_yuv_sw_c.h:39
#define NULL
Definition: begin_code.h:143
#define SDL_SetError
#define SDL_CreateRGBSurface
int h
Definition: SDL_rect.h:67
GLubyte GLubyte GLubyte GLubyte w
SDL_Surface * display
Definition: SDL_yuv_sw_c.h:50
int y
Definition: SDL_rect.h:66
GLfloat GLfloat GLfloat GLfloat h
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_SW_CreateYUVTexture()

SDL_SW_YUVTexture* SDL_SW_CreateYUVTexture ( Uint32  format,
int  w,
int  h 
)

Definition at line 1021 of file SDL_yuv_sw.c.

References SDL_SW_YUVTexture::colortab, SDL_SW_YUVTexture::format, SDL_SW_YUVTexture::h, i, NULL, SDL_SW_YUVTexture::pitches, SDL_SW_YUVTexture::pixels, SDL_SW_YUVTexture::planes, SDL_SW_YUVTexture::rgb_2_pix, SDL_assert, SDL_calloc(), SDL_malloc, SDL_OutOfMemory, SDL_PIXELFORMAT_IYUV, SDL_PIXELFORMAT_UNKNOWN, SDL_PIXELFORMAT_UYVY, SDL_PIXELFORMAT_YUY2, SDL_PIXELFORMAT_YV12, SDL_PIXELFORMAT_YVYU, SDL_SetError, SDL_SW_DestroyYUVTexture(), SDL_SW_YUVTexture::target_format, and SDL_SW_YUVTexture::w.

Referenced by SDL_CreateTexture().

1022 {
1023  SDL_SW_YUVTexture *swdata;
1024  int *Cr_r_tab;
1025  int *Cr_g_tab;
1026  int *Cb_g_tab;
1027  int *Cb_b_tab;
1028  int i;
1029  int CR, CB;
1030 
1031  switch (format) {
1032  case SDL_PIXELFORMAT_YV12:
1033  case SDL_PIXELFORMAT_IYUV:
1034  case SDL_PIXELFORMAT_YUY2:
1035  case SDL_PIXELFORMAT_UYVY:
1036  case SDL_PIXELFORMAT_YVYU:
1037  break;
1038  default:
1039  SDL_SetError("Unsupported YUV format");
1040  return NULL;
1041  }
1042 
1043  swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata));
1044  if (!swdata) {
1045  SDL_OutOfMemory();
1046  return NULL;
1047  }
1048 
1049  swdata->format = format;
1051  swdata->w = w;
1052  swdata->h = h;
1053  swdata->pixels = (Uint8 *) SDL_malloc(w * h * 2);
1054  swdata->colortab = (int *) SDL_malloc(4 * 256 * sizeof(int));
1055  swdata->rgb_2_pix = (Uint32 *) SDL_malloc(3 * 768 * sizeof(Uint32));
1056  if (!swdata->pixels || !swdata->colortab || !swdata->rgb_2_pix) {
1057  SDL_SW_DestroyYUVTexture(swdata);
1058  SDL_OutOfMemory();
1059  return NULL;
1060  }
1061 
1062  /* Generate the tables for the display surface */
1063  Cr_r_tab = &swdata->colortab[0 * 256];
1064  Cr_g_tab = &swdata->colortab[1 * 256];
1065  Cb_g_tab = &swdata->colortab[2 * 256];
1066  Cb_b_tab = &swdata->colortab[3 * 256];
1067  for (i = 0; i < 256; i++) {
1068  /* Gamma correction (luminescence table) and chroma correction
1069  would be done here. See the Berkeley mpeg_play sources.
1070  */
1071  CB = CR = (i - 128);
1072  Cr_r_tab[i] = (int) ((0.419 / 0.299) * CR);
1073  Cr_g_tab[i] = (int) (-(0.299 / 0.419) * CR);
1074  Cb_g_tab[i] = (int) (-(0.114 / 0.331) * CB);
1075  Cb_b_tab[i] = (int) ((0.587 / 0.331) * CB);
1076  }
1077 
1078  /* Find the pitch and offset values for the overlay */
1079  switch (format) {
1080  case SDL_PIXELFORMAT_YV12:
1081  case SDL_PIXELFORMAT_IYUV:
1082  swdata->pitches[0] = w;
1083  swdata->pitches[1] = swdata->pitches[0] / 2;
1084  swdata->pitches[2] = swdata->pitches[0] / 2;
1085  swdata->planes[0] = swdata->pixels;
1086  swdata->planes[1] = swdata->planes[0] + swdata->pitches[0] * h;
1087  swdata->planes[2] = swdata->planes[1] + swdata->pitches[1] * h / 2;
1088  break;
1089  case SDL_PIXELFORMAT_YUY2:
1090  case SDL_PIXELFORMAT_UYVY:
1091  case SDL_PIXELFORMAT_YVYU:
1092  swdata->pitches[0] = w * 2;
1093  swdata->planes[0] = swdata->pixels;
1094  break;
1095  default:
1096  SDL_assert(0 && "We should never get here (caught above)");
1097  break;
1098  }
1099 
1100  /* We're all done.. */
1101  return (swdata);
1102 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
void * SDL_calloc(size_t nmemb, size_t size)
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
Uint32 * rgb_2_pix
Definition: SDL_yuv_sw_c.h:34
void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata)
Definition: SDL_yuv_sw.c:1393
Uint8 * planes[3]
Definition: SDL_yuv_sw_c.h:46
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_SetError
Uint16 pitches[3]
Definition: SDL_yuv_sw_c.h:45
#define SDL_malloc
GLubyte GLubyte GLubyte GLubyte w
GLfloat GLfloat GLfloat GLfloat h

◆ SDL_SW_DestroyYUVTexture()

void SDL_SW_DestroyYUVTexture ( SDL_SW_YUVTexture swdata)

Definition at line 1393 of file SDL_yuv_sw.c.

References SDL_SW_YUVTexture::colortab, SDL_SW_YUVTexture::display, SDL_SW_YUVTexture::pixels, SDL_SW_YUVTexture::rgb_2_pix, SDL_free(), SDL_FreeSurface, and SDL_SW_YUVTexture::stretch.

Referenced by SDL_DestroyTexture(), and SDL_SW_CreateYUVTexture().

1394 {
1395  if (swdata) {
1396  SDL_free(swdata->pixels);
1397  SDL_free(swdata->colortab);
1398  SDL_free(swdata->rgb_2_pix);
1399  SDL_FreeSurface(swdata->stretch);
1400  SDL_FreeSurface(swdata->display);
1401  SDL_free(swdata);
1402  }
1403 }
#define SDL_FreeSurface
void SDL_free(void *mem)
Uint32 * rgb_2_pix
Definition: SDL_yuv_sw_c.h:34
SDL_Surface * stretch
Definition: SDL_yuv_sw_c.h:49
SDL_Surface * display
Definition: SDL_yuv_sw_c.h:50

◆ SDL_SW_LockYUVTexture()

int SDL_SW_LockYUVTexture ( SDL_SW_YUVTexture swdata,
const SDL_Rect rect,
void **  pixels,
int *  pitch 
)

Definition at line 1243 of file SDL_yuv_sw.c.

References SDL_SW_YUVTexture::format, SDL_SW_YUVTexture::h, SDL_Rect::h, SDL_SW_YUVTexture::pitches, SDL_SW_YUVTexture::planes, SDL_PIXELFORMAT_IYUV, SDL_PIXELFORMAT_YV12, SDL_SetError, SDL_SW_YUVTexture::w, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_LockTextureYUV().

1245 {
1246  switch (swdata->format) {
1247  case SDL_PIXELFORMAT_YV12:
1248  case SDL_PIXELFORMAT_IYUV:
1249  if (rect
1250  && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w
1251  || rect->h != swdata->h)) {
1252  return SDL_SetError
1253  ("YV12 and IYUV textures only support full surface locks");
1254  }
1255  break;
1256  }
1257 
1258  if (rect) {
1259  *pixels = swdata->planes[0] + rect->y * swdata->pitches[0] + rect->x * 2;
1260  } else {
1261  *pixels = swdata->planes[0];
1262  }
1263  *pitch = swdata->pitches[0];
1264  return 0;
1265 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
Uint8 * planes[3]
Definition: SDL_yuv_sw_c.h:46
#define SDL_SetError
Uint16 pitches[3]
Definition: SDL_yuv_sw_c.h:45
int h
Definition: SDL_rect.h:67
int y
Definition: SDL_rect.h:66

◆ SDL_SW_QueryYUVTexturePixels()

int SDL_SW_QueryYUVTexturePixels ( SDL_SW_YUVTexture swdata,
void **  pixels,
int *  pitch 
)

Definition at line 1105 of file SDL_yuv_sw.c.

References SDL_SW_YUVTexture::pitches, and SDL_SW_YUVTexture::planes.

1107 {
1108  *pixels = swdata->planes[0];
1109  *pitch = swdata->pitches[0];
1110  return 0;
1111 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
Uint8 * planes[3]
Definition: SDL_yuv_sw_c.h:46
Uint16 pitches[3]
Definition: SDL_yuv_sw_c.h:45

◆ SDL_SW_UnlockYUVTexture()

void SDL_SW_UnlockYUVTexture ( SDL_SW_YUVTexture swdata)

Definition at line 1268 of file SDL_yuv_sw.c.

1269 {
1270 }

◆ SDL_SW_UpdateYUVTexture()

int SDL_SW_UpdateYUVTexture ( SDL_SW_YUVTexture swdata,
const SDL_Rect rect,
const void pixels,
int  pitch 
)

Definition at line 1114 of file SDL_yuv_sw.c.

References SDL_SW_YUVTexture::format, SDL_SW_YUVTexture::h, SDL_Rect::h, SDL_SW_YUVTexture::pitches, SDL_SW_YUVTexture::pixels, SDL_SW_YUVTexture::planes, SDL_memcpy, SDL_PIXELFORMAT_IYUV, SDL_PIXELFORMAT_UYVY, SDL_PIXELFORMAT_YUY2, SDL_PIXELFORMAT_YV12, SDL_PIXELFORMAT_YVYU, SDL_SW_YUVTexture::w, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_UpdateTextureYUV().

1116 {
1117  switch (swdata->format) {
1118  case SDL_PIXELFORMAT_YV12:
1119  case SDL_PIXELFORMAT_IYUV:
1120  if (rect->x == 0 && rect->y == 0 &&
1121  rect->w == swdata->w && rect->h == swdata->h) {
1122  SDL_memcpy(swdata->pixels, pixels,
1123  (swdata->h * swdata->w) + (swdata->h * swdata->w) / 2);
1124  } else {
1125  Uint8 *src, *dst;
1126  int row;
1127  size_t length;
1128 
1129  /* Copy the Y plane */
1130  src = (Uint8 *) pixels;
1131  dst = swdata->pixels + rect->y * swdata->w + rect->x;
1132  length = rect->w;
1133  for (row = 0; row < rect->h; ++row) {
1134  SDL_memcpy(dst, src, length);
1135  src += pitch;
1136  dst += swdata->w;
1137  }
1138 
1139  /* Copy the next plane */
1140  src = (Uint8 *) pixels + rect->h * pitch;
1141  dst = swdata->pixels + swdata->h * swdata->w;
1142  dst += rect->y/2 * swdata->w/2 + rect->x/2;
1143  length = rect->w / 2;
1144  for (row = 0; row < rect->h/2; ++row) {
1145  SDL_memcpy(dst, src, length);
1146  src += pitch/2;
1147  dst += swdata->w/2;
1148  }
1149 
1150  /* Copy the next plane */
1151  src = (Uint8 *) pixels + rect->h * pitch + (rect->h * pitch) / 4;
1152  dst = swdata->pixels + swdata->h * swdata->w +
1153  (swdata->h * swdata->w) / 4;
1154  dst += rect->y/2 * swdata->w/2 + rect->x/2;
1155  length = rect->w / 2;
1156  for (row = 0; row < rect->h/2; ++row) {
1157  SDL_memcpy(dst, src, length);
1158  src += pitch/2;
1159  dst += swdata->w/2;
1160  }
1161  }
1162  break;
1163  case SDL_PIXELFORMAT_YUY2:
1164  case SDL_PIXELFORMAT_UYVY:
1165  case SDL_PIXELFORMAT_YVYU:
1166  {
1167  Uint8 *src, *dst;
1168  int row;
1169  size_t length;
1170 
1171  src = (Uint8 *) pixels;
1172  dst =
1173  swdata->planes[0] + rect->y * swdata->pitches[0] +
1174  rect->x * 2;
1175  length = rect->w * 2;
1176  for (row = 0; row < rect->h; ++row) {
1177  SDL_memcpy(dst, src, length);
1178  src += pitch;
1179  dst += swdata->pitches[0];
1180  }
1181  }
1182  break;
1183  }
1184  return 0;
1185 }
GLenum GLenum dst
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
#define SDL_memcpy
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
Uint8 * planes[3]
Definition: SDL_yuv_sw_c.h:46
Uint16 pitches[3]
Definition: SDL_yuv_sw_c.h:45
int h
Definition: SDL_rect.h:67
GLuint GLsizei GLsizei * length
GLenum src
GLenum GLenum void * row
int y
Definition: SDL_rect.h:66

◆ SDL_SW_UpdateYUVTexturePlanar()

int SDL_SW_UpdateYUVTexturePlanar ( SDL_SW_YUVTexture swdata,
const SDL_Rect rect,
const Uint8 Yplane,
int  Ypitch,
const Uint8 Uplane,
int  Upitch,
const Uint8 Vplane,
int  Vpitch 
)

Definition at line 1188 of file SDL_yuv_sw.c.

References SDL_SW_YUVTexture::format, SDL_SW_YUVTexture::h, SDL_Rect::h, SDL_SW_YUVTexture::pixels, SDL_memcpy, SDL_PIXELFORMAT_IYUV, SDL_PIXELFORMAT_YV12, SDL_SW_YUVTexture::w, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_UpdateTextureYUVPlanar().

1192 {
1193  const Uint8 *src;
1194  Uint8 *dst;
1195  int row;
1196  size_t length;
1197 
1198  /* Copy the Y plane */
1199  src = Yplane;
1200  dst = swdata->pixels + rect->y * swdata->w + rect->x;
1201  length = rect->w;
1202  for (row = 0; row < rect->h; ++row) {
1203  SDL_memcpy(dst, src, length);
1204  src += Ypitch;
1205  dst += swdata->w;
1206  }
1207 
1208  /* Copy the U plane */
1209  src = Uplane;
1210  if (swdata->format == SDL_PIXELFORMAT_IYUV) {
1211  dst = swdata->pixels + swdata->h * swdata->w;
1212  } else {
1213  dst = swdata->pixels + swdata->h * swdata->w +
1214  (swdata->h * swdata->w) / 4;
1215  }
1216  dst += rect->y/2 * swdata->w/2 + rect->x/2;
1217  length = rect->w / 2;
1218  for (row = 0; row < rect->h/2; ++row) {
1219  SDL_memcpy(dst, src, length);
1220  src += Upitch;
1221  dst += swdata->w/2;
1222  }
1223 
1224  /* Copy the V plane */
1225  src = Vplane;
1226  if (swdata->format == SDL_PIXELFORMAT_YV12) {
1227  dst = swdata->pixels + swdata->h * swdata->w;
1228  } else {
1229  dst = swdata->pixels + swdata->h * swdata->w +
1230  (swdata->h * swdata->w) / 4;
1231  }
1232  dst += rect->y/2 * swdata->w/2 + rect->x/2;
1233  length = rect->w / 2;
1234  for (row = 0; row < rect->h/2; ++row) {
1235  SDL_memcpy(dst, src, length);
1236  src += Vpitch;
1237  dst += swdata->w/2;
1238  }
1239  return 0;
1240 }
GLenum GLenum dst
#define SDL_memcpy
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
int h
Definition: SDL_rect.h:67
GLuint GLsizei GLsizei * length
GLenum src
GLenum GLenum void * row
int y
Definition: SDL_rect.h:66