src/render/SDL_yuv_sw.c
changeset 7759 869583422e5a
parent 7720 f9a649383362
child 7777 d5489cec371b
     1.1 --- a/src/render/SDL_yuv_sw.c	Sat Sep 28 14:06:39 2013 -0700
     1.2 +++ b/src/render/SDL_yuv_sw.c	Sat Sep 28 14:06:47 2013 -0700
     1.3 @@ -1185,6 +1185,60 @@
     1.4  }
     1.5  
     1.6  int
     1.7 +SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
     1.8 +                              const Uint8 *Yplane, int Ypitch,
     1.9 +                              const Uint8 *Uplane, int Upitch,
    1.10 +                              const Uint8 *Vplane, int Vpitch)
    1.11 +{
    1.12 +    Uint8 *src, *dst;
    1.13 +    int row;
    1.14 +    size_t length;
    1.15 +
    1.16 +    /* Copy the Y plane */
    1.17 +    src = Yplane;
    1.18 +    dst = swdata->pixels + rect->y * swdata->w + rect->x;
    1.19 +    length = rect->w;
    1.20 +    for (row = 0; row < rect->h; ++row) {
    1.21 +        SDL_memcpy(dst, src, length);
    1.22 +        src += Ypitch;
    1.23 +        dst += swdata->w;
    1.24 +    }
    1.25 +
    1.26 +    /* Copy the U plane */
    1.27 +    src = Uplane;
    1.28 +    if (swdata->format == SDL_PIXELFORMAT_IYUV) {
    1.29 +        dst = swdata->pixels + swdata->h * swdata->w;
    1.30 +    } else {
    1.31 +        dst = swdata->pixels + swdata->h * swdata->w +
    1.32 +              (swdata->h * swdata->w) / 4;
    1.33 +    }
    1.34 +    dst += rect->y/2 * swdata->w/2 + rect->x/2;
    1.35 +    length = rect->w / 2;
    1.36 +    for (row = 0; row < rect->h/2; ++row) {
    1.37 +        SDL_memcpy(dst, src, length);
    1.38 +        src += Upitch;
    1.39 +        dst += swdata->w/2;
    1.40 +    }
    1.41 +
    1.42 +    /* Copy the V plane */
    1.43 +    src = Vplane;
    1.44 +    if (swdata->format == SDL_PIXELFORMAT_YV12) {
    1.45 +        dst = swdata->pixels + swdata->h * swdata->w;
    1.46 +    } else {
    1.47 +        dst = swdata->pixels + swdata->h * swdata->w +
    1.48 +              (swdata->h * swdata->w) / 4;
    1.49 +    }
    1.50 +    dst += rect->y/2 * swdata->w/2 + rect->x/2;
    1.51 +    length = rect->w / 2;
    1.52 +    for (row = 0; row < rect->h/2; ++row) {
    1.53 +        SDL_memcpy(dst, src, length);
    1.54 +        src += Vpitch;
    1.55 +        dst += swdata->w/2;
    1.56 +    }
    1.57 +    return 0;
    1.58 +}
    1.59 +
    1.60 +int
    1.61  SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
    1.62                        void **pixels, int *pitch)
    1.63  {