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