1 
2 #include <string.h>
3 #include "GUI_loadimage.h"
4 
5 extern "C" {
6 
7 /************************************************************************/
8 /* C functions for image loading                                        */
9 /*                                                                      */
10 /************************************************************************/
11 
GUI_LoadImage(int w,int h,Uint8 * pal,Uint8 * data)12 SDL_Surface *GUI_LoadImage(int w, int h, Uint8 *pal, Uint8 *data)
13 {
14 	SDL_Surface *image;
15 
16 	image = SDL_AllocSurface(SDL_SWSURFACE, w, h, 8, 0, 0, 0, 0);
17 	if ( image ) {
18 		for ( int row=0; row<h; ++row ) {
19 			memcpy((Uint8 *)image->pixels + row * image->pitch,
20 								data, w);
21 			data += w;
22 		}
23 		for ( int i=0; i<256; ++i ) {
24 			image->format->palette->colors[i].r = *pal++;
25 			image->format->palette->colors[i].g = *pal++;
26 			image->format->palette->colors[i].b = *pal++;
27 		}
28 	}
29 	return(image);
30 }
31 
32 /************************************************************************/
33 /* C functions for default font support                                 */
34 /*                                                                      */
35 /************************************************************************/
36 
37 #include "the_font.h"
38 
39 static SDL_Surface *the_font = NULL;
40 
GUI_DefaultFont(void)41 SDL_Surface *GUI_DefaultFont(void)
42 {
43 	if ( the_font == NULL ) {
44 		the_font = GUI_LoadImage(font_w, font_h, font_pal, font_data);
45 	}
46 	return(the_font);
47 }
48 
49 
50 }; /* Extern C */
51