Usermode/libc - Fix strchr and strrchr behavior
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / video_SDL.c
1 /*
2  * Acess2 GUI (AxWin3) WM
3  * - By John Hodge (thePowersGang)
4  *
5  * video_SDL.c
6  * - SDL build video output
7  */
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <SDL/SDL.h>
11
12 // === GLOBALS ===
13 SDL_Surface     *gScreen;
14  int    giScreenWidth = 1280;
15  int    giScreenHeight = 720;
16
17 // === CODE ===
18 void Video_Setup(void)
19 {
20         gScreen = SDL_SetVideoMode(giScreenWidth, giScreenHeight, 32, SDL_SWSURFACE);
21         if( !gScreen ) {
22                 fprintf(stderr, "Unable to set %ix%i video mode: %s\n",
23                         giScreenWidth, giScreenHeight,
24                         SDL_GetError());
25                 exit(1);
26         }
27         SDL_WM_SetCaption("Acess2 GUI v3", "AxWin3");
28 }
29
30 void Video_Update(void)
31 {
32         SDL_Flip(gScreen);
33 }
34
35 void Video_FillRect(int X, int Y, int W, int H, uint32_t Colour)
36 {
37         SDL_Rect        r = {.x = X, .y = Y, .w = W, .h = H};
38         SDL_FillRect(gScreen, &r, Colour);
39 }
40
41 void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H)
42 {
43         printf("Blit (%p, (%i,%i) %ix%i)\n",
44                 Source, DstX, DstY, W, H);
45         SDL_Rect        r = {.x = DstX, .y = DstY, .w = W, .h = H};
46         SDL_Surface     *tmps = SDL_CreateRGBSurfaceFrom(
47                 Source, W, H, 32, W*4,
48                 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000);
49         SDL_BlitSurface(tmps, NULL, gScreen, &r);
50 }
51
52 uint32_t Video_AlphaBlend(uint32_t _orig, uint32_t _new, uint8_t _alpha)
53 {
54         uint16_t        ao,ro,go,bo;
55         uint16_t        an,rn,gn,bn;
56         if( _alpha == 0 )       return _orig;
57         if( _alpha == 255 )     return _new;
58         
59         ao = (_orig >> 24) & 0xFF;
60         ro = (_orig >> 16) & 0xFF;
61         go = (_orig >>  8) & 0xFF;
62         bo = (_orig >>  0) & 0xFF;
63         
64         an = (_new >> 24) & 0xFF;
65         rn = (_new >> 16) & 0xFF;
66         gn = (_new >>  8) & 0xFF;
67         bn = (_new >>  0) & 0xFF;
68
69         if( _alpha == 0x80 ) {
70                 ao = (ao + an) / 2;
71                 ro = (ro + rn) / 2;
72                 go = (go + gn) / 2;
73                 bo = (bo + bn) / 2;
74         }
75         else {
76                 ao = ao*(255-_alpha) + an*_alpha;
77                 ro = ro*(255-_alpha) + rn*_alpha;
78                 go = go*(255-_alpha) + gn*_alpha;
79                 bo = bo*(255-_alpha) + bn*_alpha;
80                 ao /= 255*2;
81                 ro /= 255*2;
82                 go /= 255*2;
83                 bo /= 255*2;
84         }
85
86         return (ao << 24) | (ro << 16) | (go << 8) | bo;
87 }
88

UCC git Repository :: git.ucc.asn.au