comparison 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
comparison
equal deleted inserted replaced
3426:ee0178f1c507 3427:36cf454ba065
2484 2484
2485 return renderer->RenderCopy(renderer, texture, &real_srcrect, 2485 return renderer->RenderCopy(renderer, texture, &real_srcrect,
2486 &real_dstrect); 2486 &real_dstrect);
2487 } 2487 }
2488 2488
2489 int
2490 SDL_RenderReadPixels(const SDL_Rect * rect, void * pixels, int pitch)
2491 {
2492 SDL_Renderer *renderer;
2493 SDL_Window *window;
2494 SDL_Rect real_rect;
2495
2496 renderer = SDL_GetCurrentRenderer();
2497 if (!renderer) {
2498 return -1;
2499 }
2500 if (!renderer->RenderReadPixels) {
2501 SDL_Unsupported();
2502 return -1;
2503 }
2504 window = SDL_GetWindowFromID(renderer->window);
2505
2506 real_rect.x = 0;
2507 real_rect.y = 0;
2508 real_rect.w = window->w;
2509 real_rect.h = window->h;
2510 if (rect) {
2511 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
2512 return 0;
2513 }
2514 if (real_rect.y > rect->y) {
2515 pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
2516 }
2517 if (real_rect.x > rect->x) {
2518 Uint32 format = SDL_CurrentDisplay.current_mode.format;
2519 int bpp = SDL_BYTESPERPIXEL(format);
2520 pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
2521 }
2522 }
2523
2524 return renderer->RenderReadPixels(renderer, &real_rect, pixels, pitch);
2525 }
2526
2527 int
2528 SDL_RenderWritePixels(const SDL_Rect * rect, const void * pixels, int pitch)
2529 {
2530 SDL_Renderer *renderer;
2531 SDL_Window *window;
2532 SDL_Rect real_rect;
2533
2534 renderer = SDL_GetCurrentRenderer();
2535 if (!renderer) {
2536 return -1;
2537 }
2538 if (!renderer->RenderWritePixels) {
2539 SDL_Unsupported();
2540 return -1;
2541 }
2542 window = SDL_GetWindowFromID(renderer->window);
2543
2544 real_rect.x = 0;
2545 real_rect.y = 0;
2546 real_rect.w = window->w;
2547 real_rect.h = window->h;
2548 if (rect) {
2549 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
2550 return 0;
2551 }
2552 if (real_rect.y > rect->y) {
2553 pixels = (const Uint8 *)pixels + pitch * (real_rect.y - rect->y);
2554 }
2555 if (real_rect.x > rect->x) {
2556 Uint32 format = SDL_CurrentDisplay.current_mode.format;
2557 int bpp = SDL_BYTESPERPIXEL(format);
2558 pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x);
2559 }
2560 }
2561
2562 return renderer->RenderWritePixels(renderer, &real_rect, pixels, pitch);
2563 }
2564
2489 void 2565 void
2490 SDL_RenderPresent(void) 2566 SDL_RenderPresent(void)
2491 { 2567 {
2492 SDL_Renderer *renderer; 2568 SDL_Renderer *renderer;
2493 2569