palpic.h: fix file endian conversion bugs, and...
[rofl0r-openDOW.git] / video.c
blob291eed1a6835df5cae8002c1f84e9d61e64cbc95
1 #include "video.h"
2 #include <stdbool.h>
4 SDL_Surface *surface;
5 bool fullscreen_active;
6 struct vo_desc video;
8 void video_init(void) {
9 SDL_Init(SDL_INIT_VIDEO);
10 surface = SDL_SetVideoMode(VMODE_W, VMODE_H, 32, SDL_RESIZABLE | SDL_HWPALETTE);
11 video.mem = surface->pixels;
12 video.pitch = surface->pitch;
13 video.width = VMODE_W;
14 video.height = VMODE_H;
15 fullscreen_active = 0;
18 void video_cleanup(void) {
19 if(fullscreen_active) SDL_WM_ToggleFullScreen(surface);
20 SDL_QuitSubSystem(SDL_INIT_VIDEO);
23 void video_update_region(int x, int y, int w, int h) {
24 SDL_UpdateRect(surface, x, y, w, h);
27 void video_update(void) {
28 SDL_UpdateRect(surface, 0, 0, video.width, video.height);
31 #include "sdl_rgb.h"
33 void video_save_rect(int x, int y, int w, int h, void* buf) {
34 sdl_rgb_t *ptr = (sdl_rgb_t *) surface->pixels;
35 sdl_rgb_t *out = (sdl_rgb_t *) buf;
36 unsigned pitch = surface->pitch/4;
37 int ix, iy;
38 for(iy = y; iy < VMODE_H && iy < y+h; iy++) for (ix = x; ix < VMODE_W && ix < x+w; ix++) {
39 *out++ = ptr[iy*pitch + ix];
43 void video_restore_rect(int x, int y, int w, int h, const void* buf) {
44 sdl_rgb_t *ptr = (sdl_rgb_t *) surface->pixels;
45 const sdl_rgb_t *in = (const sdl_rgb_t *) buf;
46 unsigned pitch = surface->pitch/4;
47 int ix, iy;
48 for(iy = y; iy < VMODE_H && iy < y+h; iy++) for (ix = x; ix < VMODE_W && ix < x+w; ix++) {
49 ptr[iy*pitch + ix] = *in++;
53 void video_darken_screen(void) {
54 sdl_rgb_t *ptr = (sdl_rgb_t *) surface->pixels;
55 unsigned pitch = surface->pitch/4;
56 unsigned x, y;
57 for(y = 0; y < VMODE_H; y++) for (x = 0; x < VMODE_W; x++) {
58 sdl_rgb_t col = ptr[y*pitch + x];
59 col.colors.r /= 2;
60 col.colors.g /= 2;
61 col.colors.b /= 2;
62 ptr[y*pitch + x] = col;
66 void clear_screen(void) {
67 sdl_rgb_t *ptr = (sdl_rgb_t *) surface->pixels;
68 unsigned pitch = surface->pitch/4;
69 unsigned x, y;
70 for(y = 0; y < VMODE_H; y++) for (x = 0; x < VMODE_W; x++)
71 ptr[y*pitch + x] = SRGB_BLACK;
74 void toggle_fullscreen(void) {
75 fullscreen_active = !fullscreen_active;
76 SDL_WM_ToggleFullScreen(surface);
77 SDL_Delay(1);
78 clear_screen();
79 SDL_UpdateRect(surface,0,0,VMODE_W,VMODE_H);
80 SDL_Delay(1);