src/video/SDL_video.c
changeset 3427 36cf454ba065
parent 3425 25ccea045c9f
child 3435 9f62f47d989b
     1.1 --- a/src/video/SDL_video.c	Mon Nov 09 04:13:51 2009 +0000
     1.2 +++ b/src/video/SDL_video.c	Mon Nov 09 05:20:11 2009 +0000
     1.3 @@ -2486,6 +2486,82 @@
     1.4                                  &real_dstrect);
     1.5  }
     1.6  
     1.7 +int
     1.8 +SDL_RenderReadPixels(const SDL_Rect * rect, void * pixels, int pitch)
     1.9 +{
    1.10 +    SDL_Renderer *renderer;
    1.11 +    SDL_Window *window;
    1.12 +    SDL_Rect real_rect;
    1.13 +
    1.14 +    renderer = SDL_GetCurrentRenderer();
    1.15 +    if (!renderer) {
    1.16 +        return -1;
    1.17 +    }
    1.18 +    if (!renderer->RenderReadPixels) {
    1.19 +        SDL_Unsupported();
    1.20 +        return -1;
    1.21 +    }
    1.22 +    window = SDL_GetWindowFromID(renderer->window);
    1.23 +
    1.24 +    real_rect.x = 0;
    1.25 +    real_rect.y = 0;
    1.26 +    real_rect.w = window->w;
    1.27 +    real_rect.h = window->h;
    1.28 +    if (rect) {
    1.29 +        if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
    1.30 +            return 0;
    1.31 +        }
    1.32 +        if (real_rect.y > rect->y) {
    1.33 +            pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
    1.34 +        }
    1.35 +        if (real_rect.x > rect->x) {
    1.36 +            Uint32 format = SDL_CurrentDisplay.current_mode.format;
    1.37 +            int bpp = SDL_BYTESPERPIXEL(format);
    1.38 +            pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
    1.39 +        }
    1.40 +    }
    1.41 +
    1.42 +    return renderer->RenderReadPixels(renderer, &real_rect, pixels, pitch);
    1.43 +}
    1.44 +
    1.45 +int
    1.46 +SDL_RenderWritePixels(const SDL_Rect * rect, const void * pixels, int pitch)
    1.47 +{
    1.48 +    SDL_Renderer *renderer;
    1.49 +    SDL_Window *window;
    1.50 +    SDL_Rect real_rect;
    1.51 +
    1.52 +    renderer = SDL_GetCurrentRenderer();
    1.53 +    if (!renderer) {
    1.54 +        return -1;
    1.55 +    }
    1.56 +    if (!renderer->RenderWritePixels) {
    1.57 +        SDL_Unsupported();
    1.58 +        return -1;
    1.59 +    }
    1.60 +    window = SDL_GetWindowFromID(renderer->window);
    1.61 +
    1.62 +    real_rect.x = 0;
    1.63 +    real_rect.y = 0;
    1.64 +    real_rect.w = window->w;
    1.65 +    real_rect.h = window->h;
    1.66 +    if (rect) {
    1.67 +        if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
    1.68 +            return 0;
    1.69 +        }
    1.70 +        if (real_rect.y > rect->y) {
    1.71 +            pixels = (const Uint8 *)pixels + pitch * (real_rect.y - rect->y);
    1.72 +        }
    1.73 +        if (real_rect.x > rect->x) {
    1.74 +            Uint32 format = SDL_CurrentDisplay.current_mode.format;
    1.75 +            int bpp = SDL_BYTESPERPIXEL(format);
    1.76 +            pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x);
    1.77 +        }
    1.78 +    }
    1.79 +
    1.80 +    return renderer->RenderWritePixels(renderer, &real_rect, pixels, pitch);
    1.81 +}
    1.82 +
    1.83  void
    1.84  SDL_RenderPresent(void)
    1.85  {