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 1397 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_SW_YUVTexture::pitches, SDL_Surface::pixels, SDL_SW_YUVTexture::planes, rect, SDL_SW_YUVTexture::rgb_2_pix, SDL_BYTESPERPIXEL, SDL_ConvertPixels, SDL_CreateRGBSurface, SDL_CreateRGBSurfaceFrom, SDL_PIXELFORMAT_IYUV, SDL_PIXELFORMAT_NV12, SDL_PIXELFORMAT_NV21, 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().

1400 {
1401  const int targetbpp = SDL_BYTESPERPIXEL(target_format);
1402  int stretch;
1403  int scale_2x;
1404  Uint8 *lum, *Cr, *Cb;
1405  int mod;
1406 
1407  if (targetbpp == 0) {
1408  return SDL_SetError("Invalid target pixel format");
1409  }
1410 
1411  /* Make sure we're set up to display in the desired format */
1412  if (target_format != swdata->target_format) {
1413  if (SDL_SW_SetupYUVDisplay(swdata, target_format) < 0) {
1414  return -1;
1415  }
1416  }
1417 
1418  stretch = 0;
1419  scale_2x = 0;
1420  if (srcrect->x || srcrect->y || srcrect->w < swdata->w
1421  || srcrect->h < swdata->h) {
1422  /* The source rectangle has been clipped.
1423  Using a scratch surface is easier than adding clipped
1424  source support to all the blitters, plus that would
1425  slow them down in the general unclipped case.
1426  */
1427  stretch = 1;
1428  } else if ((srcrect->w != w) || (srcrect->h != h)) {
1429  if ((w == 2 * srcrect->w) && (h == 2 * srcrect->h)) {
1430  scale_2x = 1;
1431  } else {
1432  stretch = 1;
1433  }
1434  }
1435  if (stretch) {
1436  int bpp;
1437  Uint32 Rmask, Gmask, Bmask, Amask;
1438 
1439  if (swdata->display) {
1440  swdata->display->w = w;
1441  swdata->display->h = h;
1442  swdata->display->pixels = pixels;
1443  swdata->display->pitch = pitch;
1444  } else {
1445  /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */
1446  SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask,
1447  &Bmask, &Amask);
1448  swdata->display =
1449  SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask,
1450  Gmask, Bmask, Amask);
1451  if (!swdata->display) {
1452  return (-1);
1453  }
1454  }
1455  if (!swdata->stretch) {
1456  /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */
1457  SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask,
1458  &Bmask, &Amask);
1459  swdata->stretch =
1460  SDL_CreateRGBSurface(0, swdata->w, swdata->h, bpp, Rmask,
1461  Gmask, Bmask, Amask);
1462  if (!swdata->stretch) {
1463  return (-1);
1464  }
1465  }
1466  pixels = swdata->stretch->pixels;
1467  pitch = swdata->stretch->pitch;
1468  }
1469  switch (swdata->format) {
1470  case SDL_PIXELFORMAT_YV12:
1471  lum = swdata->planes[0];
1472  Cr = swdata->planes[1];
1473  Cb = swdata->planes[2];
1474  break;
1475  case SDL_PIXELFORMAT_IYUV:
1476  lum = swdata->planes[0];
1477  Cr = swdata->planes[2];
1478  Cb = swdata->planes[1];
1479  break;
1480  case SDL_PIXELFORMAT_YUY2:
1481  lum = swdata->planes[0];
1482  Cr = lum + 3;
1483  Cb = lum + 1;
1484  break;
1485  case SDL_PIXELFORMAT_UYVY:
1486  lum = swdata->planes[0] + 1;
1487  Cr = lum + 1;
1488  Cb = lum - 1;
1489  break;
1490  case SDL_PIXELFORMAT_YVYU:
1491  lum = swdata->planes[0];
1492  Cr = lum + 1;
1493  Cb = lum + 3;
1494  break;
1495  case SDL_PIXELFORMAT_NV12:
1496  case SDL_PIXELFORMAT_NV21:
1497  return SDL_ConvertPixels(swdata->w, swdata->h,
1498  swdata->format, swdata->planes[0], swdata->pitches[0],
1499  target_format, pixels, pitch);
1500  break;
1501  default:
1502  return SDL_SetError("Unsupported YUV format in copy");
1503  }
1504  mod = (pitch / targetbpp);
1505 
1506  if (scale_2x) {
1507  mod -= (swdata->w * 2);
1508  swdata->Display2X(swdata->colortab, swdata->rgb_2_pix,
1509  lum, Cr, Cb, pixels, swdata->h, swdata->w, mod);
1510  } else {
1511  mod -= swdata->w;
1512  swdata->Display1X(swdata->colortab, swdata->rgb_2_pix,
1513  lum, Cr, Cb, pixels, swdata->h, swdata->w, mod);
1514  }
1515  if (stretch) {
1516  SDL_Rect rect = *srcrect;
1517  SDL_SoftStretch(swdata->stretch, &rect, swdata->display, NULL);
1518  }
1519  return 0;
1520 }
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:917
#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
Definition: SDL_stdinc.h:181
#define SDL_CreateRGBSurfaceFrom
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
Definition: SDL_stdinc.h:157
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
Uint16 pitches[3]
Definition: SDL_yuv_sw_c.h:45
#define SDL_CreateRGBSurface
int h
Definition: SDL_rect.h:67
#define SDL_ConvertPixels
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 
)

< Planar mode: Y + V + U (3 planes)

< Planar mode: Y + U + V (3 planes)

< Packed mode: Y0+U0+Y1+V0 (1 plane)

< Packed mode: U0+Y0+V0+Y1 (1 plane)

< Packed mode: Y0+V0+Y1+U0 (1 plane)

< Planar mode: Y + U/V interleaved (2 planes)

< Planar mode: Y + V/U interleaved (2 planes)

Definition at line 1068 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_NV12, SDL_PIXELFORMAT_NV21, 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().

1069 {
1070  SDL_SW_YUVTexture *swdata;
1071  int *Cr_r_tab;
1072  int *Cr_g_tab;
1073  int *Cb_g_tab;
1074  int *Cb_b_tab;
1075  int i;
1076  int CR, CB;
1077 
1078  switch (format) {
1079  case SDL_PIXELFORMAT_YV12:
1080  case SDL_PIXELFORMAT_IYUV:
1081  case SDL_PIXELFORMAT_YUY2:
1082  case SDL_PIXELFORMAT_UYVY:
1083  case SDL_PIXELFORMAT_YVYU:
1084  case SDL_PIXELFORMAT_NV12:
1085  case SDL_PIXELFORMAT_NV21:
1086  break;
1087  default:
1088  SDL_SetError("Unsupported YUV format");
1089  return NULL;
1090  }
1091 
1092  swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata));
1093  if (!swdata) {
1094  SDL_OutOfMemory();
1095  return NULL;
1096  }
1097 
1098  swdata->format = format;
1100  swdata->w = w;
1101  swdata->h = h;
1102  {
1103  const int sz_plane = w * h;
1104  const int sz_plane_chroma = ((w + 1) / 2) * ((h + 1) / 2);
1105  const int sz_plane_packed = ((w + 1) / 2) * h;
1106  int dst_size = 0;
1107  switch(format)
1108  {
1109  case SDL_PIXELFORMAT_YV12: /**< Planar mode: Y + V + U (3 planes) */
1110  case SDL_PIXELFORMAT_IYUV: /**< Planar mode: Y + U + V (3 planes) */
1111  dst_size = sz_plane + sz_plane_chroma + sz_plane_chroma;
1112  break;
1113 
1114  case SDL_PIXELFORMAT_YUY2: /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
1115  case SDL_PIXELFORMAT_UYVY: /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
1116  case SDL_PIXELFORMAT_YVYU: /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
1117  dst_size = 4 * sz_plane_packed;
1118  break;
1119 
1120  case SDL_PIXELFORMAT_NV12: /**< Planar mode: Y + U/V interleaved (2 planes) */
1121  case SDL_PIXELFORMAT_NV21: /**< Planar mode: Y + V/U interleaved (2 planes) */
1122  dst_size = sz_plane + sz_plane_chroma + sz_plane_chroma;
1123  break;
1124 
1125  default:
1126  SDL_assert(0 && "We should never get here (caught above)");
1127  break;
1128  }
1129  swdata->pixels = (Uint8 *) SDL_malloc(dst_size);
1130  }
1131  swdata->colortab = (int *) SDL_malloc(4 * 256 * sizeof(int));
1132  swdata->rgb_2_pix = (Uint32 *) SDL_malloc(3 * 768 * sizeof(Uint32));
1133  if (!swdata->pixels || !swdata->colortab || !swdata->rgb_2_pix) {
1134  SDL_SW_DestroyYUVTexture(swdata);
1135  SDL_OutOfMemory();
1136  return NULL;
1137  }
1138 
1139  /* Generate the tables for the display surface */
1140  Cr_r_tab = &swdata->colortab[0 * 256];
1141  Cr_g_tab = &swdata->colortab[1 * 256];
1142  Cb_g_tab = &swdata->colortab[2 * 256];
1143  Cb_b_tab = &swdata->colortab[3 * 256];
1144  for (i = 0; i < 256; i++) {
1145  /* Gamma correction (luminescence table) and chroma correction
1146  would be done here. See the Berkeley mpeg_play sources.
1147  */
1148  CB = CR = (i - 128);
1149  Cr_r_tab[i] = (int) ((0.419 / 0.299) * CR);
1150  Cr_g_tab[i] = (int) (-(0.299 / 0.419) * CR);
1151  Cb_g_tab[i] = (int) (-(0.114 / 0.331) * CB);
1152  Cb_b_tab[i] = (int) ((0.587 / 0.331) * CB);
1153  }
1154 
1155  /* Find the pitch and offset values for the overlay */
1156  switch (format) {
1157  case SDL_PIXELFORMAT_YV12:
1158  case SDL_PIXELFORMAT_IYUV:
1159  swdata->pitches[0] = w;
1160  swdata->pitches[1] = (swdata->pitches[0] + 1) / 2;
1161  swdata->pitches[2] = (swdata->pitches[0] + 1) / 2;
1162  swdata->planes[0] = swdata->pixels;
1163  swdata->planes[1] = swdata->planes[0] + swdata->pitches[0] * h;
1164  swdata->planes[2] = swdata->planes[1] + swdata->pitches[1] * ((h + 1) / 2);
1165  break;
1166  case SDL_PIXELFORMAT_YUY2:
1167  case SDL_PIXELFORMAT_UYVY:
1168  case SDL_PIXELFORMAT_YVYU:
1169  swdata->pitches[0] = ((w + 1) / 2) * 4;
1170  swdata->planes[0] = swdata->pixels;
1171  break;
1172 
1173  case SDL_PIXELFORMAT_NV12:
1174  case SDL_PIXELFORMAT_NV21:
1175  swdata->pitches[0] = w;
1176  swdata->pitches[1] = 2 * ((swdata->pitches[0] + 1) / 2);
1177  swdata->planes[0] = swdata->pixels;
1178  swdata->planes[1] = swdata->planes[0] + swdata->pitches[0] * h;
1179  break;
1180 
1181  default:
1182  SDL_assert(0 && "We should never get here (caught above)");
1183  break;
1184  }
1185 
1186  /* We're all done.. */
1187  return (swdata);
1188 }
GLfloat GLfloat GLfloat GLfloat h
uint32_t Uint32
Definition: SDL_stdinc.h:181
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
uint8_t Uint8
Definition: SDL_stdinc.h:157
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:1523
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_calloc
#define SDL_malloc

◆ SDL_SW_DestroyYUVTexture()

void SDL_SW_DestroyYUVTexture ( SDL_SW_YUVTexture swdata)

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

1524 {
1525  if (swdata) {
1526  SDL_free(swdata->pixels);
1527  SDL_free(swdata->colortab);
1528  SDL_free(swdata->rgb_2_pix);
1529  SDL_FreeSurface(swdata->stretch);
1530  SDL_FreeSurface(swdata->display);
1531  SDL_free(swdata);
1532  }
1533 }
#define SDL_FreeSurface
#define SDL_free
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 1365 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_NV12, SDL_PIXELFORMAT_NV21, SDL_PIXELFORMAT_YV12, SDL_SetError, SDL_SW_YUVTexture::w, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_LockTextureYUV().

1367 {
1368  switch (swdata->format) {
1369  case SDL_PIXELFORMAT_YV12:
1370  case SDL_PIXELFORMAT_IYUV:
1371  case SDL_PIXELFORMAT_NV12:
1372  case SDL_PIXELFORMAT_NV21:
1373  if (rect
1374  && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w
1375  || rect->h != swdata->h)) {
1376  return SDL_SetError
1377  ("YV12, IYUV, NV12, NV21 textures only support full surface locks");
1378  }
1379  break;
1380  }
1381 
1382  if (rect) {
1383  *pixels = swdata->planes[0] + rect->y * swdata->pitches[0] + rect->x * 2;
1384  } else {
1385  *pixels = swdata->planes[0];
1386  }
1387  *pitch = swdata->pitches[0];
1388  return 0;
1389 }
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 1191 of file SDL_yuv_sw.c.

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

1193 {
1194  *pixels = swdata->planes[0];
1195  *pitch = swdata->pitches[0];
1196  return 0;
1197 }
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 1392 of file SDL_yuv_sw.c.

1393 {
1394 }

◆ SDL_SW_UpdateYUVTexture()

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

Definition at line 1200 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_NV12, SDL_PIXELFORMAT_NV21, 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().

1202 {
1203  switch (swdata->format) {
1204  case SDL_PIXELFORMAT_YV12:
1205  case SDL_PIXELFORMAT_IYUV:
1206  if (rect->x == 0 && rect->y == 0 &&
1207  rect->w == swdata->w && rect->h == swdata->h) {
1208  SDL_memcpy(swdata->pixels, pixels,
1209  (swdata->h * swdata->w) + 2* ((swdata->h + 1) /2) * ((swdata->w + 1) / 2));
1210  } else {
1211  Uint8 *src, *dst;
1212  int row;
1213  size_t length;
1214 
1215  /* Copy the Y plane */
1216  src = (Uint8 *) pixels;
1217  dst = swdata->pixels + rect->y * swdata->w + rect->x;
1218  length = rect->w;
1219  for (row = 0; row < rect->h; ++row) {
1220  SDL_memcpy(dst, src, length);
1221  src += pitch;
1222  dst += swdata->w;
1223  }
1224 
1225  /* Copy the next plane */
1226  src = (Uint8 *) pixels + rect->h * pitch;
1227  dst = swdata->pixels + swdata->h * swdata->w;
1228  dst += rect->y/2 * ((swdata->w + 1) / 2) + rect->x/2;
1229  length = (rect->w + 1) / 2;
1230  for (row = 0; row < (rect->h + 1)/2; ++row) {
1231  SDL_memcpy(dst, src, length);
1232  src += (pitch + 1)/2;
1233  dst += (swdata->w + 1)/2;
1234  }
1235 
1236  /* Copy the next plane */
1237  src = (Uint8 *) pixels + rect->h * pitch + ((rect->h + 1) / 2) * ((pitch + 1) / 2);
1238  dst = swdata->pixels + swdata->h * swdata->w +
1239  ((swdata->h + 1)/2) * ((swdata->w+1) / 2);
1240  dst += rect->y/2 * ((swdata->w + 1)/2) + rect->x/2;
1241  length = (rect->w + 1) / 2;
1242  for (row = 0; row < (rect->h + 1)/2; ++row) {
1243  SDL_memcpy(dst, src, length);
1244  src += (pitch + 1)/2;
1245  dst += (swdata->w + 1)/2;
1246  }
1247  }
1248  break;
1249  case SDL_PIXELFORMAT_YUY2:
1250  case SDL_PIXELFORMAT_UYVY:
1251  case SDL_PIXELFORMAT_YVYU:
1252  {
1253  Uint8 *src, *dst;
1254  int row;
1255  size_t length;
1256 
1257  src = (Uint8 *) pixels;
1258  dst =
1259  swdata->planes[0] + rect->y * swdata->pitches[0] +
1260  rect->x * 2;
1261  length = 4 * ((rect->w + 1) / 2);
1262  for (row = 0; row < rect->h; ++row) {
1263  SDL_memcpy(dst, src, length);
1264  src += pitch;
1265  dst += swdata->pitches[0];
1266  }
1267  }
1268  break;
1269  case SDL_PIXELFORMAT_NV12:
1270  case SDL_PIXELFORMAT_NV21:
1271  {
1272  if (rect->x == 0 && rect->y == 0 && rect->w == swdata->w && rect->h == swdata->h) {
1273  SDL_memcpy(swdata->pixels, pixels,
1274  (swdata->h * swdata->w) + 2* ((swdata->h + 1) /2) * ((swdata->w + 1) / 2));
1275  } else {
1276 
1277  Uint8 *src, *dst;
1278  int row;
1279  size_t length;
1280 
1281  /* Copy the Y plane */
1282  src = (Uint8 *) pixels;
1283  dst = swdata->pixels + rect->y * swdata->w + rect->x;
1284  length = rect->w;
1285  for (row = 0; row < rect->h; ++row) {
1286  SDL_memcpy(dst, src, length);
1287  src += pitch;
1288  dst += swdata->w;
1289  }
1290 
1291  /* Copy the next plane */
1292  src = (Uint8 *) pixels + rect->h * pitch;
1293  dst = swdata->pixels + swdata->h * swdata->w;
1294  dst += 2 * ((rect->y + 1)/2) * ((swdata->w + 1) / 2) + 2 * (rect->x/2);
1295  length = 2 * ((rect->w + 1) / 2);
1296  for (row = 0; row < (rect->h + 1)/2; ++row) {
1297  SDL_memcpy(dst, src, length);
1298  src += 2 * ((pitch + 1)/2);
1299  dst += 2 * ((swdata->w + 1)/2);
1300  }
1301  }
1302  }
1303  break;
1304 
1305  }
1306  return 0;
1307 }
GLenum GLenum dst
GLenum src
#define SDL_memcpy
uint8_t Uint8
Definition: SDL_stdinc.h:157
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 1310 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().

1314 {
1315  const Uint8 *src;
1316  Uint8 *dst;
1317  int row;
1318  size_t length;
1319 
1320  /* Copy the Y plane */
1321  src = Yplane;
1322  dst = swdata->pixels + rect->y * swdata->w + rect->x;
1323  length = rect->w;
1324  for (row = 0; row < rect->h; ++row) {
1325  SDL_memcpy(dst, src, length);
1326  src += Ypitch;
1327  dst += swdata->w;
1328  }
1329 
1330  /* Copy the U plane */
1331  src = Uplane;
1332  if (swdata->format == SDL_PIXELFORMAT_IYUV) {
1333  dst = swdata->pixels + swdata->h * swdata->w;
1334  } else {
1335  dst = swdata->pixels + swdata->h * swdata->w +
1336  ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2);
1337  }
1338  dst += rect->y/2 * ((swdata->w + 1)/2) + rect->x/2;
1339  length = (rect->w + 1) / 2;
1340  for (row = 0; row < (rect->h + 1)/2; ++row) {
1341  SDL_memcpy(dst, src, length);
1342  src += Upitch;
1343  dst += (swdata->w + 1)/2;
1344  }
1345 
1346  /* Copy the V plane */
1347  src = Vplane;
1348  if (swdata->format == SDL_PIXELFORMAT_YV12) {
1349  dst = swdata->pixels + swdata->h * swdata->w;
1350  } else {
1351  dst = swdata->pixels + swdata->h * swdata->w +
1352  ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2);
1353  }
1354  dst += rect->y/2 * ((swdata->w + 1)/2) + rect->x/2;
1355  length = (rect->w + 1) / 2;
1356  for (row = 0; row < (rect->h + 1)/2; ++row) {
1357  SDL_memcpy(dst, src, length);
1358  src += Vpitch;
1359  dst += (swdata->w + 1)/2;
1360  }
1361  return 0;
1362 }
GLenum GLenum dst
GLenum src
#define SDL_memcpy
uint8_t Uint8
Definition: SDL_stdinc.h:157
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