src/render/SDL_render.c
changeset 7759 869583422e5a
parent 7746 6a05d7352575
child 7760 63b519624589
     1.1 --- a/src/render/SDL_render.c	Sat Sep 28 14:06:39 2013 -0700
     1.2 +++ b/src/render/SDL_render.c	Sat Sep 28 14:06:47 2013 -0700
     1.3 @@ -805,6 +805,106 @@
     1.4  }
     1.5  
     1.6  static int
     1.7 +SDL_UpdateTextureYUVPlanar(SDL_Texture * texture, 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 +    SDL_Texture *native = texture->native;
    1.13 +    SDL_Rect full_rect;
    1.14 +
    1.15 +    if (SDL_SW_UpdateYUVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch) < 0) {
    1.16 +        return -1;
    1.17 +    }
    1.18 +
    1.19 +    full_rect.x = 0;
    1.20 +    full_rect.y = 0;
    1.21 +    full_rect.w = texture->w;
    1.22 +    full_rect.h = texture->h;
    1.23 +    rect = &full_rect;
    1.24 +
    1.25 +    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
    1.26 +        /* We can lock the texture and copy to it */
    1.27 +        void *native_pixels;
    1.28 +        int native_pitch;
    1.29 +
    1.30 +        if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
    1.31 +            return -1;
    1.32 +        }
    1.33 +        SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
    1.34 +                            rect->w, rect->h, native_pixels, native_pitch);
    1.35 +        SDL_UnlockTexture(native);
    1.36 +    } else {
    1.37 +        /* Use a temporary buffer for updating */
    1.38 +        void *temp_pixels;
    1.39 +        int temp_pitch;
    1.40 +
    1.41 +        temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
    1.42 +        temp_pixels = SDL_malloc(rect->h * temp_pitch);
    1.43 +        if (!temp_pixels) {
    1.44 +            return SDL_OutOfMemory();
    1.45 +        }
    1.46 +        SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
    1.47 +                            rect->w, rect->h, temp_pixels, temp_pitch);
    1.48 +        SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
    1.49 +        SDL_free(temp_pixels);
    1.50 +    }
    1.51 +    return 0;
    1.52 +}
    1.53 +
    1.54 +int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect,
    1.55 +                         const Uint8 *Yplane, int Ypitch,
    1.56 +                         const Uint8 *Uplane, int Upitch,
    1.57 +                         const Uint8 *Vplane, int Vpitch)
    1.58 +{
    1.59 +    SDL_Renderer *renderer;
    1.60 +    SDL_Rect full_rect;
    1.61 +
    1.62 +    CHECK_TEXTURE_MAGIC(texture, -1);
    1.63 +
    1.64 +    if (!Yplane) {
    1.65 +        return SDL_InvalidParamError("Yplane");
    1.66 +    }
    1.67 +    if (!Ypitch) {
    1.68 +        return SDL_InvalidParamError("Ypitch");
    1.69 +    }
    1.70 +    if (!Uplane) {
    1.71 +        return SDL_InvalidParamError("Uplane");
    1.72 +    }
    1.73 +    if (!Upitch) {
    1.74 +        return SDL_InvalidParamError("Upitch");
    1.75 +    }
    1.76 +    if (!Vplane) {
    1.77 +        return SDL_InvalidParamError("Vplane");
    1.78 +    }
    1.79 +    if (!Vpitch) {
    1.80 +        return SDL_InvalidParamError("Vpitch");
    1.81 +    }
    1.82 +
    1.83 +    if (texture->format != SDL_PIXELFORMAT_YV12 &&
    1.84 +        texture->format != SDL_PIXELFORMAT_IYUV) {
    1.85 +        return SDL_SetError("Texture format must by YV12 or IYUV");
    1.86 +    }
    1.87 +
    1.88 +    if (!rect) {
    1.89 +        full_rect.x = 0;
    1.90 +        full_rect.y = 0;
    1.91 +        full_rect.w = texture->w;
    1.92 +        full_rect.h = texture->h;
    1.93 +        rect = &full_rect;
    1.94 +    }
    1.95 +
    1.96 +    if (texture->yuv) {
    1.97 +        return SDL_UpdateTextureYUVPlanar(texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
    1.98 +    } else {
    1.99 +        SDL_assert(!texture->native);
   1.100 +        renderer = texture->renderer;
   1.101 +        SDL_assert(renderer->UpdateTextureYUV);
   1.102 +        return renderer->UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
   1.103 +    }
   1.104 +}
   1.105 +
   1.106 +static int
   1.107  SDL_LockTextureYUV(SDL_Texture * texture, const SDL_Rect * rect,
   1.108                     void **pixels, int *pitch)
   1.109  {