comparison src/video/SDL_video.c @ 3435:9f62f47d989b

You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels() This code still doesn't quite work yet. :)
author Sam Lantinga <slouken@libsdl.org>
date Mon, 16 Nov 2009 07:13:07 +0000
parents 36cf454ba065
children bc27e1fdd3a7
comparison
equal deleted inserted replaced
3434:147d6ef5be03 3435:9f62f47d989b
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 2489 int
2490 SDL_RenderReadPixels(const SDL_Rect * rect, void * pixels, int pitch) 2490 SDL_RenderReadPixels(const SDL_Rect * rect, Uint32 format,
2491 void * pixels, int pitch)
2491 { 2492 {
2492 SDL_Renderer *renderer; 2493 SDL_Renderer *renderer;
2493 SDL_Window *window; 2494 SDL_Window *window;
2494 SDL_Rect real_rect; 2495 SDL_Rect real_rect;
2495 2496
2500 if (!renderer->RenderReadPixels) { 2501 if (!renderer->RenderReadPixels) {
2501 SDL_Unsupported(); 2502 SDL_Unsupported();
2502 return -1; 2503 return -1;
2503 } 2504 }
2504 window = SDL_GetWindowFromID(renderer->window); 2505 window = SDL_GetWindowFromID(renderer->window);
2506
2507 if (!format) {
2508 format = SDL_GetDisplayFromWindow(window)->current_mode.format;
2509 }
2505 2510
2506 real_rect.x = 0; 2511 real_rect.x = 0;
2507 real_rect.y = 0; 2512 real_rect.y = 0;
2508 real_rect.w = window->w; 2513 real_rect.w = window->w;
2509 real_rect.h = window->h; 2514 real_rect.h = window->h;
2519 int bpp = SDL_BYTESPERPIXEL(format); 2524 int bpp = SDL_BYTESPERPIXEL(format);
2520 pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x); 2525 pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
2521 } 2526 }
2522 } 2527 }
2523 2528
2524 return renderer->RenderReadPixels(renderer, &real_rect, pixels, pitch); 2529 return renderer->RenderReadPixels(renderer, &real_rect,
2525 } 2530 format, pixels, pitch);
2526 2531 }
2527 int 2532
2528 SDL_RenderWritePixels(const SDL_Rect * rect, const void * pixels, int pitch) 2533 int
2534 SDL_RenderWritePixels(const SDL_Rect * rect, Uint32 format,
2535 const void * pixels, int pitch)
2529 { 2536 {
2530 SDL_Renderer *renderer; 2537 SDL_Renderer *renderer;
2531 SDL_Window *window; 2538 SDL_Window *window;
2532 SDL_Rect real_rect; 2539 SDL_Rect real_rect;
2533 2540
2538 if (!renderer->RenderWritePixels) { 2545 if (!renderer->RenderWritePixels) {
2539 SDL_Unsupported(); 2546 SDL_Unsupported();
2540 return -1; 2547 return -1;
2541 } 2548 }
2542 window = SDL_GetWindowFromID(renderer->window); 2549 window = SDL_GetWindowFromID(renderer->window);
2550
2551 if (!format) {
2552 format = SDL_GetDisplayFromWindow(window)->current_mode.format;
2553 }
2543 2554
2544 real_rect.x = 0; 2555 real_rect.x = 0;
2545 real_rect.y = 0; 2556 real_rect.y = 0;
2546 real_rect.w = window->w; 2557 real_rect.w = window->w;
2547 real_rect.h = window->h; 2558 real_rect.h = window->h;
2557 int bpp = SDL_BYTESPERPIXEL(format); 2568 int bpp = SDL_BYTESPERPIXEL(format);
2558 pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x); 2569 pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x);
2559 } 2570 }
2560 } 2571 }
2561 2572
2562 return renderer->RenderWritePixels(renderer, &real_rect, pixels, pitch); 2573 return renderer->RenderWritePixels(renderer, &real_rect,
2574 format, pixels, pitch);
2563 } 2575 }
2564 2576
2565 void 2577 void
2566 SDL_RenderPresent(void) 2578 SDL_RenderPresent(void)
2567 { 2579 {