2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation, either version 3 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ////////////////////////////////////////////////////////////////////////////////
26 extern SDL_Surface
*screen
;
27 extern SDL_Surface
*backbuf
; // 'background' buffer
28 extern Uint32 palette
[256]; // converted
29 extern Uint8 font
[256][8];
32 ////////////////////////////////////////////////////////////////////////////////
33 extern void sdlInit (void);
34 extern void initVideo (void);
37 ////////////////////////////////////////////////////////////////////////////////
38 // create 24bpp surface with color key
39 extern SDL_Surface
*createSurface (int w
, int h
);
42 ////////////////////////////////////////////////////////////////////////////////
44 static inline void putPixelC32 (SDL_Surface
*s
, int x
, int y
, Uint32 col
) {
45 if (s
&& x
>= s
->clip_rect
.x
&& y
>= s
->clip_rect
.y
&& x
< s
->clip_rect
.x
+s
->clip_rect
.w
&& y
< s
->clip_rect
.y
+s
->clip_rect
.h
) {
46 Uint8 bpp
= s
->format
->BytesPerPixel
;
47 Uint8
*bits
= ((Uint8
*)s
->pixels
)+(y
*s
->pitch
)+(x
*bpp
);
52 *((Uint8 *)(bits)) = (Uint8)col;
55 *((Uint16 *)(bits)) = (Uint16)col;
58 *((bits)+s->format->Rshift/8) = (col>>s->format->Rshift)&0xFF;
59 *((bits)+s->format->Gshift/8) = (col>>s->format->Gshift)&0xFF;
60 *((bits)+s->format->Bshift/8) = (col>>s->format->Bshift)&0xFF;
64 *((Uint32
*)(bits
)) = col
;
71 static inline void putPixel2x (SDL_Surface
*s
, int x
, int y
, Uint8 col
) {
74 if (s
&& x
>= s
->clip_rect
.x
&& y
>= s
->clip_rect
.y
&& x
< s
->clip_rect
.x
+s
->clip_rect
.w
&& y
< s
->clip_rect
.y
+s
->clip_rect
.h
) {
75 Uint8 bpp
= s
->format
->BytesPerPixel
;
76 Uint32
*bits
= (Uint32
*)(((Uint8
*)s
->pixels
)+(y
*s
->pitch
)+(x
*bpp
));
77 Uint32 pix
= palette
[col
];
80 if (x
+1 < s
->clip_rect
.x
+s
->clip_rect
.w
) bits
[1] = pix
;
81 if (y
+1 < s
->clip_rect
.y
+s
->clip_rect
.h
) {
82 bits
= (Uint32
*)((Uint8
*)bits
+s
->pitch
);
84 if (x
+1 < s
->clip_rect
.x
+s
->clip_rect
.w
) bits
[1] = pix
;
90 static inline void hlineC32 (SDL_Surface
*s
, int x
, int y
, int len
, Uint32 col
) {
91 if (s
&& y
>= s
->clip_rect
.y
&& x
< s
->clip_rect
.x
+s
->clip_rect
.w
&& y
< s
->clip_rect
.y
+s
->clip_rect
.h
) {
92 if (x
< s
->clip_rect
.x
) {
93 len
-= s
->clip_rect
.x
-x
;
96 if (x
+len
> s
->clip_rect
.x
+s
->clip_rect
.w
) len
= s
->clip_rect
.x
+s
->clip_rect
.w
-x
;
98 Uint8 bpp
= s
->format
->BytesPerPixel
;
99 Uint32
*bits
= (Uint32
*)(((Uint8
*)s
->pixels
)+(y
*s
->pitch
)+(x
*bpp
));
101 for (; len
> 0; --len
) *bits
++ = col
;
107 static inline void hline2x (SDL_Surface
*s
, int x
, int y
, int len
, Uint8 col
) {
111 hlineC32(s
, x
, y
, len
, palette
[col
]);
112 hlineC32(s
, x
, y
+1, len
, palette
[col
]);
116 static inline void putPixelA32 (SDL_Surface
*s
, int x
, int y
, Uint32 col
, Uint8 alpha
) {
117 if (s
&& x
>= s
->clip_rect
.x
&& y
>= s
->clip_rect
.y
&& x
< s
->clip_rect
.x
+s
->clip_rect
.w
&& y
< s
->clip_rect
.y
+s
->clip_rect
.h
) {
118 Uint8 bpp
= s
->format
->BytesPerPixel
;
119 Uint8
*bits
= ((Uint8
*)s
->pixels
)+(y
*s
->pitch
)+(x
*bpp
);
121 unsigned char r
, pr
, g
, pg
, b
, pb
;
123 SDL_GetRGB(col
, s
->format
, &pr
, &pg
, &pb
);
124 pixel
= *((Uint32
*)(bits
));
125 // get RGB values from pixel
126 r
= (((pixel
&s
->format
->Rmask
)>>s
->format
->Rshift
)<<s
->format
->Rloss
);
127 g
= (((pixel
&s
->format
->Gmask
)>>s
->format
->Gshift
)<<s
->format
->Gloss
);
128 b
= (((pixel
&s
->format
->Bmask
)>>s
->format
->Bshift
)<<s
->format
->Bloss
);
130 r
= (((pr
-r
)*alpha
)>>8)+r
;
131 g
= (((pg
-g
)*alpha
)>>8)+g
;
132 b
= (((pb
-b
)*alpha
)>>8)+b
;
134 pixel
= SDL_MapRGB(s
->format
, r
, g
, b
);
135 *((Uint32
*)(bits
)) = pixel
;
140 static inline void putPixelA2x (SDL_Surface
*s
, int x
, int y
, Uint8 clr
, Uint8 alpha
) {
145 putPixelA32(s
, x
+0, y
+0, palette
[clr
], alpha
);
146 putPixelA32(s
, x
+1, y
+0, palette
[clr
], alpha
);
148 putPixelA32(s
, x
+0, y
+1, palette
[clr
], alpha
);
149 putPixelA32(s
, x
+1, y
+1, palette
[clr
], alpha
);
151 putPixel2x(s
, x
, y
, clr
);
158 static inline void putPixel2xC32 (SDL_Surface
*s
, int x
, int y
, Uint32 clr
) {
161 putPixelC32(s
, x
+0, y
+0, clr
);
162 putPixelC32(s
, x
+1, y
+0, clr
);
164 putPixelC32(s
, x
+0, y
, clr
);
165 putPixelC32(s
, x
+1, y
, clr
);
169 static inline void putPixel (SDL_Surface
*s
, int x
, int y
, Uint8 clr
) {
170 putPixelC32(s
, x
, y
, palette
[clr
]);
174 ////////////////////////////////////////////////////////////////////////////////
175 extern void blitSurfaceEx (SDL_Surface
*dests
, int destx
, int desty
, SDL_Surface
*srcs
, int srcx
, int srcy
, int srcw
, int srch
);
178 static inline void blitSurface (SDL_Surface
*dests
, int destx
, int desty
, SDL_Surface
*srcs
) {
179 blitSurfaceEx(dests
, destx
, desty
, srcs
, 0, 0, -1, -1);
183 static inline void blitSurface2x (SDL_Surface
*dests
, int destx
, int desty
, SDL_Surface
*srcs
) {
184 blitSurfaceEx(dests
, destx
*2, desty
*2, srcs
, 0, 0, -1, -1);
188 ////////////////////////////////////////////////////////////////////////////////
195 extern void lockSurface (SurfaceLock
*lock
, SDL_Surface
*s
);
196 extern void unlockSurface (SurfaceLock
*lock
);
199 ////////////////////////////////////////////////////////////////////////////////
200 // surface must be locked!
201 extern void drawChar (SDL_Surface
*s
, char ch
, int x
, int y
, Uint8 clr
);
202 extern void drawString (SDL_Surface
*s
, const char *str
, int x
, int y
, Uint8 clr
);