1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4 #include "ppport.h"
5 #include "helper.h"
6 
7 #ifndef aTHX_
8 #define aTHX_
9 #endif
10 
11 #include <SDL.h>
12 
13 MODULE = SDL::Palette 	PACKAGE = SDL::Palette    PREFIX = palette_
14 
15 =for documentation
16 
17 SDL_Palette -- Color palette for 8-bit pixel formats
18 
19   typedef struct{
20 	int ncolors;
21 	SDL_Color *colors
22   } SDL_Palette;
23 
24 =cut
25 
26 int
27 palette_ncolors ( palette )
28 	SDL_Palette *palette
29 	CODE:
30 		RETVAL = palette->ncolors;
31 	OUTPUT:
32 		RETVAL
33 
34 AV *
35 palette_colors ( palette )
36 	SDL_Palette *palette
37 	CODE:
38 		RETVAL = (AV*)sv_2mortal((SV*)newAV());
39 		int i;
40 		for(i = 0; i < palette->ncolors; i++)
41 			av_push( RETVAL, cpy2bag( (SDL_Color *)(palette->colors + i), sizeof(SDL_Color *), sizeof(SDL_Color), "SDL::Color" ) );
42 	OUTPUT:
43 		RETVAL
44 
45 SV *
46 palette_color_index ( palette, index )
47 	SDL_Palette *palette
48 	int index
49 	PREINIT:
50 		char * CLASS = "SDL::Color";
51 	CODE:
52 		RETVAL = cpy2bag( (SDL_Color *)(palette->colors + index), sizeof(SDL_Color *), sizeof(SDL_Color), "SDL::Color" );
53 	OUTPUT:
54 		RETVAL
55 
56 void
57 palette_DESTROY ( bag )
58 	SV *bag
59 	CODE:
60 		objDESTROY(bag, safefree);
61