Added lock and unlock surface for SDL::Video and added tests
[sdlgit/SDL_perl.git] / src / Core / Video.xs
CommitLineData
70fd0f8d 1#include "EXTERN.h"
2#include "perl.h"
3#include "XSUB.h"
4
5#ifndef aTHX_
6#define aTHX_
7#endif
8
9#include <SDL.h>
10
7b7e8017 11
12static Uint16* av_to_uint16 (AV* av)
13{
14 int len = av_len(av);
15 if( len != -1)
16 {
17 int i;
18 Uint16* table = (Uint16 *)safemalloc(sizeof(Uint16)*(len));
7b7e8017 19 for ( i = 0; i < len+1 ; i++ ){
20 SV ** temp = av_fetch(av,i,0);
21 if( temp != NULL)
22 {
2d2bb756 23 table[i] = (Uint16 *) SvIV( *temp );
7b7e8017 24 }
25 else { table[i] =0; }
26
27 }
7b7e8017 28 return table;
29 }
30 return NULL;
31}
32
33
34
70fd0f8d 35MODULE = SDL::Video PACKAGE = SDL::Video PREFIX = video_
36
37=for documentation
38
39The Following are XS bindings to the Video category in the SDL API v2.1.13
40
41Describe on the SDL API site.
42
43See: L<http://www.libsdl.org/cgi/docwiki.cgi/SDL_API#head-813f033ec44914f267f32195aba7d9aff8c410c0>
44
45=cut
46
47SDL_Surface *
95f5be30 48video_get_video_surface()
49 PREINIT:
50 char* CLASS = "SDL::Surface";
70fd0f8d 51 CODE:
52 RETVAL = SDL_GetVideoSurface();
53 OUTPUT:
54 RETVAL
55
56
20f544ea 57SDL_VideoInfo*
95f5be30 58video_get_video_info()
20f544ea 59 PREINIT:
60 char* CLASS = "SDL::VideoInfo";
95f5be30 61 CODE:
babb07ed 62 RETVAL = (SDL_VideoInfo *) SDL_GetVideoInfo();
8a2411d0 63
64 OUTPUT:
babb07ed 65 RETVAL
8a2411d0 66
7fa192d4 67SV *
68video_video_driver_name( )
69
8a2411d0 70 CODE:
7fa192d4 71 char buffer[1024];
72 if ( SDL_VideoDriverName(buffer, 1024) != NULL )
73 {
74 RETVAL = newSVpv(buffer, 0);
75 }
76 else
77 XSRETURN_UNDEF;
8a2411d0 78 OUTPUT:
79 RETVAL
7dda1934 80
81AV*
82list_modes ( format, flags )
83 Uint32 flags
84 SDL_PixelFormat *format
4510df28 85
7dda1934 86 CODE:
87 SDL_Rect **mode;
88 RETVAL = newAV();
89 mode = SDL_ListModes(format,flags);
90 if (mode == (SDL_Rect**)-1 ) {
91 av_push(RETVAL,newSVpv("all",0));
92 } else if (! mode ) {
93 av_push(RETVAL,newSVpv("none",0));
94 } else {
95 for (;*mode;mode++) {
96 av_push(RETVAL,newSViv(PTR2IV(*mode)));
97 }
98 }
99 OUTPUT:
100 RETVAL
101
102
218b5471 103int
104video_video_mode_ok ( width, height, bpp, flags )
105 int width
106 int height
107 int bpp
108 Uint32 flags
109 CODE:
110 RETVAL = SDL_VideoModeOK(width,height,bpp,flags);
111 OUTPUT:
112 RETVAL
7dda1934 113
bbe5d2f5 114
115SDL_Surface *
116video_set_video_mode ( width, height, bpp, flags )
117 int width
118 int height
119 int bpp
120 Uint32 flags
121 PREINIT:
122 char* CLASS = "SDL::Surface";
123 CODE:
124 RETVAL = SDL_SetVideoMode(width,height,bpp,flags);
125 OUTPUT:
126 RETVAL
127
128
eaf32d63 129void
130video_update_rect ( surface, x, y, w ,h )
131 SDL_Surface *surface
132 int x
133 int y
134 int w
135 int h
136 CODE:
137 SDL_UpdateRect(surface,x,y,w,h);
138
139void
140video_update_rects ( surface, ... )
141 SDL_Surface *surface
142 CODE:
143 SDL_Rect *rects;
144 int num_rects,i;
145 if ( items < 2 ) return;
146 num_rects = items - 1;
147 rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items);
148 for(i=0;i<num_rects;i++) {
149 rects[i] = *(SDL_Rect *)SvIV((SV*)SvRV( ST(i + 1) ));
150 }
151 SDL_UpdateRects(surface,num_rects,rects);
152 safefree(rects);
153
7dda1934 154
19f3ee7b 155int
156video_flip ( surface )
157 SDL_Surface *surface
158 CODE:
159 RETVAL = SDL_Flip(surface);
160 OUTPUT:
161 RETVAL
162
2739f940 163int
164video_set_colors ( surface, start, ... )
165 SDL_Surface *surface
166 int start
167 CODE:
168 SDL_Color *colors,*temp;
169 int i, length;
69341787 170 if ( items < 3 ) { RETVAL = 0;}
171 else
172 {
2739f940 173 length = items - 2;
174 colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
175 for ( i = 0; i < length ; i++ ) {
176 temp = (SDL_Color *)SvIV(ST(i+2));
177 colors[i].r = temp->r;
178 colors[i].g = temp->g;
179 colors[i].b = temp->b;
180 }
181 RETVAL = SDL_SetColors(surface, colors, start, length );
182 safefree(colors);
69341787 183 }
2739f940 184
2739f940 185 OUTPUT:
186 RETVAL
0a01cb9e 187
69341787 188int
189video_set_palette ( surface, flags, start, ... )
190 SDL_Surface *surface
191 int flags
192 int start
193
194 CODE:
195 SDL_Color *colors,*temp;
196 int i, length;
197 if ( items < 4 ) {
198 RETVAL = 0;
199 }
200 else
201 {
202 length = items - 3;
203 colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
204 for ( i = 0; i < length ; i++ ){
205 temp = (SDL_Color *)SvIV(ST(i+3));
206 colors[i].r = temp->r;
207 colors[i].g = temp->g;
208 colors[i].b = temp->b;
209 }
210 RETVAL = SDL_SetPalette(surface, flags, colors, start, length );
211 safefree(colors);
212 }
213 OUTPUT:
214 RETVAL
0a01cb9e 215
5e9f2784 216int
217video_set_gamma(r, g, b)
218 float r;
219 float g;
220 float b;
221 CODE:
222 RETVAL = SDL_SetGamma(r,g,b);
5e9f2784 223 OUTPUT:
224 RETVAL
7b7e8017 225
5e9f2784 226
227int
8b7c3ac8 228video_set_gamma_ramp( rt, gt, bt )
229 AV* rt;
230 AV* gt;
231 AV* bt;
5e9f2784 232 CODE:
7b7e8017 233 Uint16 *redtable, *greentable, *bluetable;
234 redtable = av_to_uint16(rt);
235 greentable = av_to_uint16(gt);
236 bluetable = av_to_uint16(bt);
237 RETVAL = SDL_SetGammaRamp(redtable, greentable, bluetable);
238 if( redtable != NULL) { safefree(redtable); }
239 if( greentable != NULL) { safefree(greentable); }
240 if( bluetable != NULL) { safefree(bluetable); }
5e9f2784 241 OUTPUT:
242 RETVAL
243
2d2bb756 244
245
246Uint32
247video_map_RGB ( pixel_format, r, g, b )
248 SDL_PixelFormat *pixel_format
249 Uint8 r
250 Uint8 g
251 Uint8 b
252 CODE:
253 RETVAL = SDL_MapRGB(pixel_format,r,g,b);
254 OUTPUT:
255 RETVAL
256
257Uint32
258video_map_RGBA ( pixel_format, r, g, b, a )
259 SDL_PixelFormat *pixel_format
260 Uint8 r
261 Uint8 g
262 Uint8 b
263 Uint8 a
264 CODE:
265 RETVAL = SDL_MapRGB(pixel_format,r,g,b);
266 OUTPUT:
267 RETVAL
268
1e72b6a4 269int
270video_lock_surface ( surface )
271 SDL_Surface *surface
272 CODE:
273 RETVAL = SDL_LockSurface(surface);
274 OUTPUT:
275 RETVAL
276
277void
278video_unlock_surface ( surface )
279 SDL_Surface *surface
280 CODE:
281 SDL_UnlockSurface(surface);
282