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

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

1037 {
1038  SDL_SW_YUVTexture *swdata;
1039  int *Cr_r_tab;
1040  int *Cr_g_tab;
1041  int *Cb_g_tab;
1042  int *Cb_b_tab;
1043  int i;
1044  int CR, CB;
1045 
1046  switch (format) {
1047  case SDL_PIXELFORMAT_YV12:
1048  case SDL_PIXELFORMAT_IYUV:
1049  case SDL_PIXELFORMAT_YUY2:
1050  case SDL_PIXELFORMAT_UYVY:
1051  case SDL_PIXELFORMAT_YVYU:
1052  break;
1053  default:
1054  SDL_SetError("Unsupported YUV format");
1055  return NULL;
1056  }
1057 
1058  swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata));
1059  if (!swdata) {
1060  SDL_OutOfMemory();
1061  return NULL;
1062  }
1063 
1064  swdata->format = format;
1066  swdata->w = w;
1067  swdata->h = h;
1068  swdata->pixels = (Uint8 *) SDL_malloc(w * h * 2);
1069  swdata->colortab = (int *) SDL_malloc(4 * 256 * sizeof(int));
1070  swdata->rgb_2_pix = (Uint32 *) SDL_malloc(3 * 768 * sizeof(Uint32));
1071  if (!swdata->pixels || !swdata->colortab || !swdata->rgb_2_pix) {
1072  SDL_SW_DestroyYUVTexture(swdata);
1073  SDL_OutOfMemory();
1074  return NULL;
1075  }
1076 
1077  /* Generate the tables for the display surface */
1078  Cr_r_tab = &swdata->colortab[0 * 256];
1079  Cr_g_tab = &swdata->colortab[1 * 256];
1080  Cb_g_tab = &swdata->colortab[2 * 256];
1081  Cb_b_tab = &swdata->colortab[3 * 256];
1082  for (i = 0; i < 256; i++) {
1083  /* Gamma correction (luminescence table) and chroma correction
1084  would be done here. See the Berkeley mpeg_play sources.
1085  */
1086  CB = CR = (i - 128);
1087  Cr_r_tab[i] = (int) ((0.419 / 0.299) * CR);
1088  Cr_g_tab[i] = (int) (-(0.299 / 0.419) * CR);
1089  Cb_g_tab[i] = (int) (-(0.114 / 0.331) * CB);
1090  Cb_b_tab[i] = (int) ((0.587 / 0.331) * CB);
1091  }
1092 
1093  /* Find the pitch and offset values for the overlay */
1094  switch (format) {
1095  case SDL_PIXELFORMAT_YV12:
1096  case SDL_PIXELFORMAT_IYUV:
1097  swdata->pitches[0] = w;
1098  swdata->pitches[1] = swdata->pitches[0] / 2;
1099  swdata->pitches[2] = swdata->pitches[0] / 2;
1100  swdata->planes[0] = swdata->pixels;
1101  swdata->planes[1] = swdata->planes[0] + swdata->pitches[0] * h;
1102  swdata->planes[2] = swdata->planes[1] + swdata->pitches[1] * h / 2;
1103  break;
1104  case SDL_PIXELFORMAT_YUY2:
1105  case SDL_PIXELFORMAT_UYVY:
1106  case SDL_PIXELFORMAT_YVYU:
1107  swdata->pitches[0] = w * 2;
1108  swdata->planes[0] = swdata->pixels;
1109  break;
1110  default:
1111  SDL_assert(0 && "We should never get here (caught above)");
1112  break;
1113  }
1114 
1115  /* We're all done.. */
1116  return (swdata);
1117 }
GLfloat GLfloat GLfloat GLfloat h
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:169
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
void * SDL_calloc(size_t nmemb, size_t size)
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:153
GLubyte GLubyte GLubyte GLubyte w
Uint32 * rgb_2_pix
Definition: SDL_yuv_sw_c.h:34
void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata)
Definition: SDL_yuv_sw.c:1408
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:169
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
#define SDL_SetError
Uint16 pitches[3]
Definition: SDL_yuv_sw_c.h:45
#define SDL_malloc

◆ SDL_SW_DestroyYUVTexture()

void SDL_SW_DestroyYUVTexture ( SDL_SW_YUVTexture swdata)

Definition at line 1408 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().

1409 {
1410  if (swdata) {
1411  SDL_free(swdata->pixels);
1412  SDL_free(swdata->colortab);
1413  SDL_free(swdata->rgb_2_pix);
1414  SDL_FreeSurface(swdata->stretch);
1415  SDL_FreeSurface(swdata->display);
1416  SDL_free(swdata);
1417  }
1418 }
#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 1258 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().

1260 {
1261  switch (swdata->format) {
1262  case SDL_PIXELFORMAT_YV12:
1263  case SDL_PIXELFORMAT_IYUV:
1264  if (rect
1265  && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w
1266  || rect->h != swdata->h)) {
1267  return SDL_SetError
1268  ("YV12 and IYUV textures only support full surface locks");
1269  }
1270  break;
1271  }
1272 
1273  if (rect) {
1274  *pixels = swdata->planes[0] + rect->y * swdata->pitches[0] + rect->x * 2;
1275  } else {
1276  *pixels = swdata->planes[0];
1277  }
1278  *pitch = swdata->pitches[0];
1279  return 0;
1280 }
int x
Definition: SDL_rect.h:66
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
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 1120 of file SDL_yuv_sw.c.

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

1122 {
1123  *pixels = swdata->planes[0];
1124  *pitch = swdata->pitches[0];
1125  return 0;
1126 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
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 1283 of file SDL_yuv_sw.c.

1284 {
1285 }

◆ SDL_SW_UpdateYUVTexture()

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

Definition at line 1129 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().

1131 {
1132  switch (swdata->format) {
1133  case SDL_PIXELFORMAT_YV12:
1134  case SDL_PIXELFORMAT_IYUV:
1135  if (rect->x == 0 && rect->y == 0 &&
1136  rect->w == swdata->w && rect->h == swdata->h) {
1137  SDL_memcpy(swdata->pixels, pixels,
1138  (swdata->h * swdata->w) + (swdata->h * swdata->w) / 2);
1139  } else {
1140  Uint8 *src, *dst;
1141  int row;
1142  size_t length;
1143 
1144  /* Copy the Y plane */
1145  src = (Uint8 *) pixels;
1146  dst = swdata->pixels + rect->y * swdata->w + rect->x;
1147  length = rect->w;
1148  for (row = 0; row < rect->h; ++row) {
1149  SDL_memcpy(dst, src, length);
1150  src += pitch;
1151  dst += swdata->w;
1152  }
1153 
1154  /* Copy the next plane */
1155  src = (Uint8 *) pixels + rect->h * pitch;
1156  dst = swdata->pixels + swdata->h * swdata->w;
1157  dst += rect->y/2 * swdata->w/2 + rect->x/2;
1158  length = rect->w / 2;
1159  for (row = 0; row < rect->h/2; ++row) {
1160  SDL_memcpy(dst, src, length);
1161  src += pitch/2;
1162  dst += swdata->w/2;
1163  }
1164 
1165  /* Copy the next plane */
1166  src = (Uint8 *) pixels + rect->h * pitch + (rect->h * pitch) / 4;
1167  dst = swdata->pixels + swdata->h * swdata->w +
1168  (swdata->h * swdata->w) / 4;
1169  dst += rect->y/2 * swdata->w/2 + rect->x/2;
1170  length = rect->w / 2;
1171  for (row = 0; row < rect->h/2; ++row) {
1172  SDL_memcpy(dst, src, length);
1173  src += pitch/2;
1174  dst += swdata->w/2;
1175  }
1176  }
1177  break;
1178  case SDL_PIXELFORMAT_YUY2:
1179  case SDL_PIXELFORMAT_UYVY:
1180  case SDL_PIXELFORMAT_YVYU:
1181  {
1182  Uint8 *src, *dst;
1183  int row;
1184  size_t length;
1185 
1186  src = (Uint8 *) pixels;
1187  dst =
1188  swdata->planes[0] + rect->y * swdata->pitches[0] +
1189  rect->x * 2;
1190  length = rect->w * 2;
1191  for (row = 0; row < rect->h; ++row) {
1192  SDL_memcpy(dst, src, length);
1193  src += pitch;
1194  dst += swdata->pitches[0];
1195  }
1196  }
1197  break;
1198  }
1199  return 0;
1200 }
GLenum GLenum dst
GLenum src
#define SDL_memcpy
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:153
int x
Definition: SDL_rect.h:66
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
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 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 1203 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().

1207 {
1208  const Uint8 *src;
1209  Uint8 *dst;
1210  int row;
1211  size_t length;
1212 
1213  /* Copy the Y plane */
1214  src = Yplane;
1215  dst = swdata->pixels + rect->y * swdata->w + rect->x;
1216  length = rect->w;
1217  for (row = 0; row < rect->h; ++row) {
1218  SDL_memcpy(dst, src, length);
1219  src += Ypitch;
1220  dst += swdata->w;
1221  }
1222 
1223  /* Copy the U plane */
1224  src = Uplane;
1225  if (swdata->format == SDL_PIXELFORMAT_IYUV) {
1226  dst = swdata->pixels + swdata->h * swdata->w;
1227  } else {
1228  dst = swdata->pixels + swdata->h * swdata->w +
1229  (swdata->h * swdata->w) / 4;
1230  }
1231  dst += rect->y/2 * swdata->w/2 + rect->x/2;
1232  length = rect->w / 2;
1233  for (row = 0; row < rect->h/2; ++row) {
1234  SDL_memcpy(dst, src, length);
1235  src += Upitch;
1236  dst += swdata->w/2;
1237  }
1238 
1239  /* Copy the V plane */
1240  src = Vplane;
1241  if (swdata->format == SDL_PIXELFORMAT_YV12) {
1242  dst = swdata->pixels + swdata->h * swdata->w;
1243  } else {
1244  dst = swdata->pixels + swdata->h * swdata->w +
1245  (swdata->h * swdata->w) / 4;
1246  }
1247  dst += rect->y/2 * swdata->w/2 + rect->x/2;
1248  length = rect->w / 2;
1249  for (row = 0; row < rect->h/2; ++row) {
1250  SDL_memcpy(dst, src, length);
1251  src += Vpitch;
1252  dst += swdata->w/2;
1253  }
1254  return 0;
1255 }
GLenum GLenum dst
GLenum src
#define SDL_memcpy
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:153
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 GLenum void * row
int y
Definition: SDL_rect.h:66