Added optimized YUV texture upload path with SDL_UpdateYUVTexture()

This commit is contained in:
Sam Lantinga 2013-09-28 14:06:47 -07:00
parent 45bd5e2b83
commit 43cc5c1cbb
6 changed files with 229 additions and 0 deletions

View file

@ -1184,6 +1184,60 @@ SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
return 0;
}
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)
{
Uint8 *src, *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;
}
int
SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
void **pixels, int *pitch)