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_YUVTexture * | SDL_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

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

{
const int targetbpp = SDL_BYTESPERPIXEL(target_format);
int stretch;
int scale_2x;
Uint8 *lum, *Cr, *Cb;
int mod;
if (targetbpp == 0) {
return SDL_SetError("Invalid target pixel format");
}
/* Make sure we're set up to display in the desired format */
if (target_format != swdata->target_format) {
if (SDL_SW_SetupYUVDisplay(swdata, target_format) < 0) {
return -1;
}
}
stretch = 0;
scale_2x = 0;
if (srcrect->x || srcrect->y || srcrect->w < swdata->w
|| srcrect->h < swdata->h) {
/* The source rectangle has been clipped.
Using a scratch surface is easier than adding clipped
source support to all the blitters, plus that would
slow them down in the general unclipped case.
*/
stretch = 1;
} else if ((srcrect->w != w) || (srcrect->h != h)) {
if ((w == 2 * srcrect->w) && (h == 2 * srcrect->h)) {
scale_2x = 1;
} else {
stretch = 1;
}
}
if (stretch) {
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
if (swdata->display) {
swdata->display->w = w;
swdata->display->h = h;
swdata->display->pixels = pixels;
swdata->display->pitch = pitch;
} else {
/* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */
SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask,
&Bmask, &Amask);
swdata->display =
SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask,
Gmask, Bmask, Amask);
if (!swdata->display) {
return (-1);
}
}
if (!swdata->stretch) {
/* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */
SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask,
&Bmask, &Amask);
swdata->stretch =
SDL_CreateRGBSurface(0, swdata->w, swdata->h, bpp, Rmask,
Gmask, Bmask, Amask);
if (!swdata->stretch) {
return (-1);
}
}
pixels = swdata->stretch->pixels;
pitch = swdata->stretch->pitch;
}
switch (swdata->format) {
case SDL_PIXELFORMAT_YV12:
lum = swdata->planes[0];
Cr = swdata->planes[1];
Cb = swdata->planes[2];
break;
case SDL_PIXELFORMAT_IYUV:
lum = swdata->planes[0];
Cr = swdata->planes[2];
Cb = swdata->planes[1];
break;
case SDL_PIXELFORMAT_YUY2:
lum = swdata->planes[0];
Cr = lum + 3;
Cb = lum + 1;
break;
case SDL_PIXELFORMAT_UYVY:
lum = swdata->planes[0] + 1;
Cr = lum + 1;
Cb = lum - 1;
break;
case SDL_PIXELFORMAT_YVYU:
lum = swdata->planes[0];
Cr = lum + 1;
Cb = lum + 3;
break;
default:
return SDL_SetError("Unsupported YUV format in copy");
}
mod = (pitch / targetbpp);
if (scale_2x) {
mod -= (swdata->w * 2);
swdata->Display2X(swdata->colortab, swdata->rgb_2_pix,
lum, Cr, Cb, pixels, swdata->h, swdata->w, mod);
} else {
mod -= swdata->w;
swdata->Display1X(swdata->colortab, swdata->rgb_2_pix,
lum, Cr, Cb, pixels, swdata->h, swdata->w, mod);
}
if (stretch) {
SDL_Rect rect = *srcrect;
SDL_SoftStretch(swdata->stretch, &rect, swdata->display, NULL);
}
return 0;
}
SDL_SW_YUVTexture::Display1X
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
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:157
SDL_Surface::h
int h
Definition: SDL_surface.h:73
SDL_SW_SetupYUVDisplay
static int SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture *swdata, Uint32 target_format)
Definition: SDL_yuv_sw.c:889
SDL_SoftStretch
#define SDL_SoftStretch
Definition: SDL_dynapi_overrides.h:474
SDL_SW_YUVTexture::target_format
Uint32 target_format
Definition: SDL_yuv_sw_c.h:30
rect
SDL_Rect rect
Definition: testrelative.c:27
SDL_BYTESPERPIXEL
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:127
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
SDL_Surface::w
int w
Definition: SDL_surface.h:73
SDL_CreateRGBSurfaceFrom
#define SDL_CreateRGBSurfaceFrom
Definition: SDL_dynapi_overrides.h:449
SDL_PIXELFORMAT_YVYU
Definition: SDL_pixels.h:271
SDL_SW_YUVTexture::w
int w
Definition: SDL_yuv_sw_c.h:31
SDL_Surface::pixels
void * pixels
Definition: SDL_surface.h:75
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_SW_YUVTexture::h
int h
Definition: SDL_yuv_sw_c.h:31
SDL_SW_YUVTexture::rgb_2_pix
Uint32 * rgb_2_pix
Definition: SDL_yuv_sw_c.h:34
SDL_PixelFormatEnumToMasks
#define SDL_PixelFormatEnumToMasks
Definition: SDL_dynapi_overrides.h:284
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_SW_YUVTexture::stretch
SDL_Surface * stretch
Definition: SDL_yuv_sw_c.h:49
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_SW_YUVTexture::planes
Uint8 * planes[3]
Definition: SDL_yuv_sw_c.h:46
SDL_SW_YUVTexture::Display2X
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
SDL_SW_YUVTexture::colortab
int * colortab
Definition: SDL_yuv_sw_c.h:33
NULL
#define NULL
Definition: begin_code.h:143
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36
SDL_CreateRGBSurface
#define SDL_CreateRGBSurface
Definition: SDL_dynapi_overrides.h:448
SDL_PIXELFORMAT_YV12
Definition: SDL_pixels.h:263
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_PIXELFORMAT_IYUV
Definition: SDL_pixels.h:265
SDL_SW_YUVTexture::format
Uint32 format
Definition: SDL_yuv_sw_c.h:29
SDL_Surface::pitch
int pitch
Definition: SDL_surface.h:74
SDL_PIXELFORMAT_UYVY
Definition: SDL_pixels.h:269
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
SDL_PIXELFORMAT_YUY2
Definition: SDL_pixels.h:267
SDL_SW_YUVTexture::display
SDL_Surface * display
Definition: SDL_yuv_sw_c.h:50
SDL_Rect::y
int y
Definition: SDL_rect.h:66
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

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

{
SDL_SW_YUVTexture *swdata;
int *Cr_r_tab;
int *Cr_g_tab;
int *Cb_g_tab;
int *Cb_b_tab;
int i;
int CR, CB;
switch (format) {
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
case SDL_PIXELFORMAT_YUY2:
case SDL_PIXELFORMAT_UYVY:
case SDL_PIXELFORMAT_YVYU:
break;
default:
SDL_SetError("Unsupported YUV format");
return NULL;
}
swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata));
if (!swdata) {
SDL_OutOfMemory();
return NULL;
}
swdata->format = format;
swdata->target_format = SDL_PIXELFORMAT_UNKNOWN;
swdata->w = w;
swdata->h = h;
swdata->pixels = (Uint8 *) SDL_malloc(w * h * 2);
swdata->colortab = (int *) SDL_malloc(4 * 256 * sizeof(int));
swdata->rgb_2_pix = (Uint32 *) SDL_malloc(3 * 768 * sizeof(Uint32));
if (!swdata->pixels || !swdata->colortab || !swdata->rgb_2_pix) {
SDL_SW_DestroyYUVTexture(swdata);
SDL_OutOfMemory();
return NULL;
}
/* Generate the tables for the display surface */
Cr_r_tab = &swdata->colortab[0 * 256];
Cr_g_tab = &swdata->colortab[1 * 256];
Cb_g_tab = &swdata->colortab[2 * 256];
Cb_b_tab = &swdata->colortab[3 * 256];
for (i = 0; i < 256; i++) {
/* Gamma correction (luminescence table) and chroma correction
would be done here. See the Berkeley mpeg_play sources.
*/
CB = CR = (i - 128);
Cr_r_tab[i] = (int) ((0.419 / 0.299) * CR);
Cr_g_tab[i] = (int) (-(0.299 / 0.419) * CR);
Cb_g_tab[i] = (int) (-(0.114 / 0.331) * CB);
Cb_b_tab[i] = (int) ((0.587 / 0.331) * CB);
}
/* Find the pitch and offset values for the overlay */
switch (format) {
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
swdata->pitches[0] = w;
swdata->pitches[1] = swdata->pitches[0] / 2;
swdata->pitches[2] = swdata->pitches[0] / 2;
swdata->planes[0] = swdata->pixels;
swdata->planes[1] = swdata->planes[0] + swdata->pitches[0] * h;
swdata->planes[2] = swdata->planes[1] + swdata->pitches[1] * h / 2;
break;
case SDL_PIXELFORMAT_YUY2:
case SDL_PIXELFORMAT_UYVY:
case SDL_PIXELFORMAT_YVYU:
swdata->pitches[0] = w * 2;
swdata->planes[0] = swdata->pixels;
break;
default:
SDL_assert(0 && "We should never get here (caught above)");
break;
}
/* We're all done.. */
return (swdata);
}
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:157
SDL_SW_YUVTexture::target_format
Uint32 target_format
Definition: SDL_yuv_sw_c.h:30
SDL_SW_YUVTexture::pixels
Uint8 * pixels
Definition: SDL_yuv_sw_c.h:32
SDL_SW_YUVTexture
Definition: SDL_yuv_sw_c.h:27
SDL_PIXELFORMAT_YVYU
Definition: SDL_pixels.h:271
SDL_SW_YUVTexture::w
int w
Definition: SDL_yuv_sw_c.h:31
SDL_calloc
void * SDL_calloc(size_t nmemb, size_t size)
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_PIXELFORMAT_UNKNOWN
Definition: SDL_pixels.h:172
SDL_SW_YUVTexture::h
int h
Definition: SDL_yuv_sw_c.h:31
SDL_SW_YUVTexture::rgb_2_pix
Uint32 * rgb_2_pix
Definition: SDL_yuv_sw_c.h:34
SDL_SW_DestroyYUVTexture
void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata)
Definition: SDL_yuv_sw.c:1393
SDL_SW_YUVTexture::planes
Uint8 * planes[3]
Definition: SDL_yuv_sw_c.h:46
SDL_SW_YUVTexture::colortab
int * colortab
Definition: SDL_yuv_sw_c.h:33
i
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:42
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:167
NULL
#define NULL
Definition: begin_code.h:143
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36
SDL_SW_YUVTexture::pitches
Uint16 pitches[3]
Definition: SDL_yuv_sw_c.h:45
SDL_PIXELFORMAT_YV12
Definition: SDL_pixels.h:263
SDL_PIXELFORMAT_IYUV
Definition: SDL_pixels.h:265
SDL_SW_YUVTexture::format
Uint32 format
Definition: SDL_yuv_sw_c.h:29
SDL_PIXELFORMAT_UYVY
Definition: SDL_pixels.h:269
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:380
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
SDL_PIXELFORMAT_YUY2
Definition: SDL_pixels.h:267
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946

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

{
if (swdata) {
SDL_free(swdata->pixels);
SDL_free(swdata->colortab);
SDL_free(swdata->rgb_2_pix);
SDL_FreeSurface(swdata->stretch);
SDL_FreeSurface(swdata->display);
SDL_free(swdata);
}
}
SDL_SW_YUVTexture::pixels
Uint8 * pixels
Definition: SDL_yuv_sw_c.h:32
SDL_FreeSurface
#define SDL_FreeSurface
Definition: SDL_dynapi_overrides.h:450
SDL_free
void SDL_free(void *mem)
SDL_SW_YUVTexture::rgb_2_pix
Uint32 * rgb_2_pix
Definition: SDL_yuv_sw_c.h:34
SDL_SW_YUVTexture::stretch
SDL_Surface * stretch
Definition: SDL_yuv_sw_c.h:49
SDL_SW_YUVTexture::colortab
int * colortab
Definition: SDL_yuv_sw_c.h:33
SDL_SW_YUVTexture::display
SDL_Surface * display
Definition: SDL_yuv_sw_c.h:50

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

{
switch (swdata->format) {
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
if (rect
&& (rect->x != 0 || rect->y != 0 || rect->w != swdata->w
|| rect->h != swdata->h)) {
return SDL_SetError
("YV12 and IYUV textures only support full surface locks");
}
break;
}
if (rect) {
*pixels = swdata->planes[0] + rect->y * swdata->pitches[0] + rect->x * 2;
} else {
*pixels = swdata->planes[0];
}
*pitch = swdata->pitches[0];
return 0;
}
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
SDL_SW_YUVTexture::w
int w
Definition: SDL_yuv_sw_c.h:31
SDL_SW_YUVTexture::h
int h
Definition: SDL_yuv_sw_c.h:31
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_SW_YUVTexture::planes
Uint8 * planes[3]
Definition: SDL_yuv_sw_c.h:46
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36
SDL_SW_YUVTexture::pitches
Uint16 pitches[3]
Definition: SDL_yuv_sw_c.h:45
SDL_PIXELFORMAT_YV12
Definition: SDL_pixels.h:263
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_PIXELFORMAT_IYUV
Definition: SDL_pixels.h:265
SDL_SW_YUVTexture::format
Uint32 format
Definition: SDL_yuv_sw_c.h:29
SDL_Rect::y
int y
Definition: SDL_rect.h:66

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.

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

void SDL_SW_UnlockYUVTexture | ( | SDL_SW_YUVTexture * | swdata | ) |

Definition at line 1268 of file SDL_yuv_sw.c.

{
}

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

{
switch (swdata->format) {
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
if (rect->x == 0 && rect->y == 0 &&
rect->w == swdata->w && rect->h == swdata->h) {
SDL_memcpy(swdata->pixels, pixels,
(swdata->h * swdata->w) + (swdata->h * swdata->w) / 2);
} else {
Uint8 *src, *dst;
int row;
size_t length;
/* Copy the Y plane */
src = (Uint8 *) pixels;
dst = swdata->pixels + rect->y * swdata->w + rect->x;
length = rect->w;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
dst += swdata->w;
}
/* Copy the next plane */
src = (Uint8 *) pixels + rect->h * pitch;
dst = swdata->pixels + swdata->h * swdata->w;
dst += rect->y/2 * swdata->w/2 + rect->x/2;
length = rect->w / 2;
for (row = 0; row < rect->h/2; ++row) {
SDL_memcpy(dst, src, length);
src += pitch/2;
dst += swdata->w/2;
}
/* Copy the next plane */
src = (Uint8 *) pixels + rect->h * pitch + (rect->h * pitch) / 4;
dst = swdata->pixels + swdata->h * swdata->w +
(swdata->h * swdata->w) / 4;
dst += rect->y/2 * swdata->w/2 + rect->x/2;
length = rect->w / 2;
for (row = 0; row < rect->h/2; ++row) {
SDL_memcpy(dst, src, length);
src += pitch/2;
dst += swdata->w/2;
}
}
break;
case SDL_PIXELFORMAT_YUY2:
case SDL_PIXELFORMAT_UYVY:
case SDL_PIXELFORMAT_YVYU:
{
Uint8 *src, *dst;
int row;
size_t length;
src = (Uint8 *) pixels;
dst =
swdata->planes[0] + rect->y * swdata->pitches[0] +
rect->x * 2;
length = rect->w * 2;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
dst += swdata->pitches[0];
}
}
break;
}
return 0;
}
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1737
SDL_SW_YUVTexture::pixels
Uint8 * pixels
Definition: SDL_yuv_sw_c.h:32
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
SDL_PIXELFORMAT_YVYU
Definition: SDL_pixels.h:271
SDL_SW_YUVTexture::w
int w
Definition: SDL_yuv_sw_c.h:31
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:393
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_SW_YUVTexture::h
int h
Definition: SDL_yuv_sw_c.h:31
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_SW_YUVTexture::planes
Uint8 * planes[3]
Definition: SDL_yuv_sw_c.h:46
SDL_SW_YUVTexture::pitches
Uint16 pitches[3]
Definition: SDL_yuv_sw_c.h:45
SDL_PIXELFORMAT_YV12
Definition: SDL_pixels.h:263
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_PIXELFORMAT_IYUV
Definition: SDL_pixels.h:265
SDL_SW_YUVTexture::format
Uint32 format
Definition: SDL_yuv_sw_c.h:29
SDL_PIXELFORMAT_UYVY
Definition: SDL_pixels.h:269
SDL_PIXELFORMAT_YUY2
Definition: SDL_pixels.h:267
length
GLuint GLsizei GLsizei * length
Definition: SDL_opengl_glext.h:669
src
GLenum src
Definition: SDL_opengl_glext.h:1737
row
GLenum GLenum void * row
Definition: SDL_opengl_glext.h:3138
SDL_Rect::y
int y
Definition: SDL_rect.h:66

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

{
const Uint8 *src;
Uint8 *dst;
int row;
size_t length;
/* Copy the Y plane */
src = Yplane;
dst = swdata->pixels + rect->y * swdata->w + rect->x;
length = rect->w;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += Ypitch;
dst += swdata->w;
}
/* Copy the U plane */
src = Uplane;
if (swdata->format == SDL_PIXELFORMAT_IYUV) {
dst = swdata->pixels + swdata->h * swdata->w;
} else {
dst = swdata->pixels + swdata->h * swdata->w +
(swdata->h * swdata->w) / 4;
}
dst += rect->y/2 * swdata->w/2 + rect->x/2;
length = rect->w / 2;
for (row = 0; row < rect->h/2; ++row) {
SDL_memcpy(dst, src, length);
src += Upitch;
dst += swdata->w/2;
}
/* Copy the V plane */
src = Vplane;
if (swdata->format == SDL_PIXELFORMAT_YV12) {
dst = swdata->pixels + swdata->h * swdata->w;
} else {
dst = swdata->pixels + swdata->h * swdata->w +
(swdata->h * swdata->w) / 4;
}
dst += rect->y/2 * swdata->w/2 + rect->x/2;
length = rect->w / 2;
for (row = 0; row < rect->h/2; ++row) {
SDL_memcpy(dst, src, length);
src += Vpitch;
dst += swdata->w/2;
}
return 0;
}
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1737
SDL_SW_YUVTexture::pixels
Uint8 * pixels
Definition: SDL_yuv_sw_c.h:32
SDL_SW_YUVTexture::w
int w
Definition: SDL_yuv_sw_c.h:31
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:393
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_SW_YUVTexture::h
int h
Definition: SDL_yuv_sw_c.h:31
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_PIXELFORMAT_YV12
Definition: SDL_pixels.h:263
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_PIXELFORMAT_IYUV
Definition: SDL_pixels.h:265
SDL_SW_YUVTexture::format
Uint32 format
Definition: SDL_yuv_sw_c.h:29
length
GLuint GLsizei GLsizei * length
Definition: SDL_opengl_glext.h:669
src
GLenum src
Definition: SDL_opengl_glext.h:1737
row
GLenum GLenum void * row
Definition: SDL_opengl_glext.h:3138
SDL_Rect::y
int y
Definition: SDL_rect.h:66