Mercurial > sdl-ios-xcode
diff src/video/SDL_video.c @ 3427:36cf454ba065
Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 09 Nov 2009 05:20:11 +0000 |
parents | 25ccea045c9f |
children | 9f62f47d989b |
line wrap: on
line diff
--- a/src/video/SDL_video.c Mon Nov 09 04:13:51 2009 +0000 +++ b/src/video/SDL_video.c Mon Nov 09 05:20:11 2009 +0000 @@ -2486,6 +2486,82 @@ &real_dstrect); } +int +SDL_RenderReadPixels(const SDL_Rect * rect, void * pixels, int pitch) +{ + SDL_Renderer *renderer; + SDL_Window *window; + SDL_Rect real_rect; + + renderer = SDL_GetCurrentRenderer(); + if (!renderer) { + return -1; + } + if (!renderer->RenderReadPixels) { + SDL_Unsupported(); + return -1; + } + window = SDL_GetWindowFromID(renderer->window); + + real_rect.x = 0; + real_rect.y = 0; + real_rect.w = window->w; + real_rect.h = window->h; + if (rect) { + if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) { + return 0; + } + if (real_rect.y > rect->y) { + pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y); + } + if (real_rect.x > rect->x) { + Uint32 format = SDL_CurrentDisplay.current_mode.format; + int bpp = SDL_BYTESPERPIXEL(format); + pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x); + } + } + + return renderer->RenderReadPixels(renderer, &real_rect, pixels, pitch); +} + +int +SDL_RenderWritePixels(const SDL_Rect * rect, const void * pixels, int pitch) +{ + SDL_Renderer *renderer; + SDL_Window *window; + SDL_Rect real_rect; + + renderer = SDL_GetCurrentRenderer(); + if (!renderer) { + return -1; + } + if (!renderer->RenderWritePixels) { + SDL_Unsupported(); + return -1; + } + window = SDL_GetWindowFromID(renderer->window); + + real_rect.x = 0; + real_rect.y = 0; + real_rect.w = window->w; + real_rect.h = window->h; + if (rect) { + if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) { + return 0; + } + if (real_rect.y > rect->y) { + pixels = (const Uint8 *)pixels + pitch * (real_rect.y - rect->y); + } + if (real_rect.x > rect->x) { + Uint32 format = SDL_CurrentDisplay.current_mode.format; + int bpp = SDL_BYTESPERPIXEL(format); + pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x); + } + } + + return renderer->RenderWritePixels(renderer, &real_rect, pixels, pitch); +} + void SDL_RenderPresent(void) {