Added the ability to update a subrect of a YV12/IYUV texture.
authorSam Lantinga <slouken@libsdl.org>
Fri, 30 Dec 2011 18:19:35 -0500
changeset 6136731cd0659cb5
parent 6135 b052a5882a47
child 6138 4c64952a58fb
Added the ability to update a subrect of a YV12/IYUV texture.
src/render/SDL_yuv_sw.c
     1.1 --- a/src/render/SDL_yuv_sw.c	Fri Dec 30 18:18:42 2011 -0500
     1.2 +++ b/src/render/SDL_yuv_sw.c	Fri Dec 30 18:19:35 2011 -0500
     1.3 @@ -1119,15 +1119,48 @@
     1.4      switch (swdata->format) {
     1.5      case SDL_PIXELFORMAT_YV12:
     1.6      case SDL_PIXELFORMAT_IYUV:
     1.7 -        if (rect
     1.8 -            && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w
     1.9 -                || rect->h != swdata->h)) {
    1.10 -            SDL_SetError
    1.11 -                ("YV12 and IYUV textures only support full surface updates");
    1.12 -            return -1;
    1.13 +        if (rect->x == 0 && rect->y == 0 &&
    1.14 +            rect->w == swdata->w && rect->h == swdata->h) {
    1.15 +                SDL_memcpy(swdata->pixels, pixels,
    1.16 +                           (swdata->h * swdata->w) + (swdata->h * swdata->w) / 2);
    1.17 +        } else {
    1.18 +            Uint8 *src, *dst;
    1.19 +            int row;
    1.20 +            size_t length;
    1.21 +
    1.22 +            /* Copy the Y plane */
    1.23 +            src = (Uint8 *) pixels;
    1.24 +            dst = swdata->pixels + rect->y * swdata->w + rect->x;
    1.25 +            length = rect->w;
    1.26 +            for (row = 0; row < rect->h; ++row) {
    1.27 +                SDL_memcpy(dst, src, length);
    1.28 +                src += pitch;
    1.29 +                dst += swdata->w;
    1.30 +            }
    1.31 +
    1.32 +            /* Copy the next plane */
    1.33 +            src = (Uint8 *) pixels + rect->h * pitch;
    1.34 +            dst = swdata->pixels + swdata->h * swdata->w;
    1.35 +            dst += rect->y/2 * swdata->w/2 + rect->x/2;
    1.36 +            length = rect->w / 2;
    1.37 +            for (row = 0; row < rect->h/2; ++row) {
    1.38 +                SDL_memcpy(dst, src, length);
    1.39 +                src += pitch/2;
    1.40 +                dst += swdata->w/2;
    1.41 +            }
    1.42 +
    1.43 +            /* Copy the next plane */
    1.44 +            src = (Uint8 *) pixels + rect->h * pitch + (rect->h * pitch) / 4;
    1.45 +            dst = swdata->pixels + swdata->h * swdata->w +
    1.46 +                  (swdata->h * swdata->w) / 4;
    1.47 +            dst += rect->y/2 * swdata->w/2 + rect->x/2;
    1.48 +            length = rect->w / 2;
    1.49 +            for (row = 0; row < rect->h/2; ++row) {
    1.50 +                SDL_memcpy(dst, src, length);
    1.51 +                src += pitch/2;
    1.52 +                dst += swdata->w/2;
    1.53 +            }
    1.54          }
    1.55 -        SDL_memcpy(swdata->pixels, pixels,
    1.56 -                   (swdata->h * swdata->w) + (swdata->h * swdata->w) / 2);
    1.57          break;
    1.58      case SDL_PIXELFORMAT_YUY2:
    1.59      case SDL_PIXELFORMAT_UYVY: