PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Image.xs

http://github.com/PerlGameDev/SDL
Unknown | 397 lines | 329 code | 68 blank | 0 comment | 0 complexity | 3525171e24d2ee39512d2446be487176 MD5 | raw file
  1#include "EXTERN.h"
  2#include "perl.h"
  3#include "XSUB.h"
  4#include "ppport.h"
  5
  6#ifndef aTHX_
  7#define aTHX_
  8#endif
  9
 10#include <SDL.h>
 11
 12#ifdef HAVE_SDL_IMAGE
 13#include <SDL_image.h>
 14#endif 
 15
 16void test( char** xpm)
 17{
 18
 19int x, y;
 20int w, h, ncolors, cpp;
 21char *line;
 22char ***xpmlines = NULL;
 23
 24
 25xpmlines = &xpm;
 26
 27line = *(*xpmlines)++;
 28
 29if(sscanf(line, "%d %d %d %d", &w, &h, &ncolors, &cpp) != 4
 30	   || w <= 0 || h <= 0 || ncolors <= 0 || cpp <= 0) {
 31		warn( "Invalid format description %s \n  %d %d %d %d", line, w, h, ncolors, cpp);
 32	}
 33
 34
 35}
 36
 37
 38
 39
 40MODULE = SDL::Image 	PACKAGE = SDL::Image    PREFIX = image_
 41
 42#ifdef HAVE_SDL_IMAGE
 43
 44const SDL_version*
 45image_linked_version()
 46	PREINIT:
 47		char* CLASS = "SDL::Version";
 48		SDL_version *version;
 49	CODE:
 50		version = (SDL_version *) safemalloc ( sizeof(SDL_version) );
 51		SDL_version* version_dont_free = (SDL_version *)IMG_Linked_Version();
 52
 53		version->major = version_dont_free->major;
 54		version->minor = version_dont_free->minor;
 55		version->patch = version_dont_free->patch;
 56		RETVAL = version;
 57	OUTPUT:
 58		RETVAL
 59
 60#if (SDL_IMAGE_MAJOR_VERSION >= 1) && (SDL_IMAGE_MINOR_VERSION >= 2) && (SDL_IMAGE_PATCHLEVEL >= 10)
 61
 62int
 63image_init(flags)
 64	int flags
 65	CODE:
 66		RETVAL = IMG_Init(flags);
 67	OUTPUT:
 68		RETVAL 
 69
 70void
 71image_quit()
 72	CODE:
 73		IMG_Quit();
 74
 75#endif
 76
 77SDL_Surface *
 78image_load ( filename )
 79	char *filename
 80	CODE:
 81		char* CLASS = "SDL::Surface";
 82		RETVAL = IMG_Load(filename);
 83	OUTPUT:
 84		RETVAL
 85
 86SDL_Surface *
 87image_load_rw ( rw_file, src )
 88	SDL_RWops *rw_file
 89	int src
 90	PREINIT:
 91		char* CLASS = "SDL::Surface";
 92	CODE:
 93		RETVAL = IMG_Load_RW(rw_file, src);
 94	OUTPUT:
 95		RETVAL  
 96
 97SDL_Surface * 
 98image_load_typed_rw(src, freesrc, type)
 99	SDL_RWops* src
100	int freesrc
101	char* type
102	PREINIT:
103		char* CLASS = "SDL::Surface";
104	CODE:
105		RETVAL = IMG_LoadTyped_RW(src, freesrc, type);
106	OUTPUT:
107		RETVAL
108
109#if (SDL_IMAGE_MAJOR_VERSION >= 1) && (SDL_IMAGE_MINOR_VERSION >= 2) && (SDL_IMAGE_PATCHLEVEL >= 10)
110
111SDL_Surface *
112image_load_ICO_rw(src)
113	SDL_RWops* src
114 	PREINIT:
115 	 	 char *CLASS = "SDL::Surface";
116 	CODE:
117		RETVAL = IMG_LoadICO_RW(src);
118	OUTPUT:
119		RETVAL
120
121
122SDL_Surface *
123image_load_CUR_rw(src)
124	SDL_RWops* src
125 	PREINIT:
126 	 	 char *CLASS = "SDL::Surface";
127 	CODE:
128		RETVAL = IMG_LoadCUR_RW(src);
129	OUTPUT:
130		RETVAL
131
132#endif
133
134SDL_Surface *
135image_load_BMP_rw(src)
136	SDL_RWops* src
137 	PREINIT:
138 	 	 char *CLASS = "SDL::Surface";
139 	CODE:
140		RETVAL = IMG_LoadBMP_RW(src);
141	OUTPUT:
142		RETVAL
143
144SDL_Surface *
145image_load_GIF_rw(src)
146	SDL_RWops* src
147 	PREINIT:
148 	 	 char *CLASS = "SDL::Surface";
149 	CODE:
150		RETVAL = IMG_LoadGIF_RW(src);
151	OUTPUT:
152		RETVAL
153
154SDL_Surface *
155image_load_JPG_rw(src)
156	SDL_RWops* src
157 	PREINIT:
158 	 	 char *CLASS = "SDL::Surface";
159 	CODE:
160		RETVAL = IMG_LoadJPG_RW(src);
161	OUTPUT:
162		RETVAL
163
164SDL_Surface *
165image_load_LBM_rw(src)
166	SDL_RWops* src
167 	PREINIT:
168 	 	 char *CLASS = "SDL::Surface";
169 	CODE:
170		RETVAL = IMG_LoadLBM_RW(src);
171	OUTPUT:
172		RETVAL
173
174SDL_Surface *
175image_load_PCX_rw(src)
176	SDL_RWops* src
177 	PREINIT:
178 	 	 char *CLASS = "SDL::Surface";
179 	CODE:
180		RETVAL = IMG_LoadPCX_RW(src);
181	OUTPUT:
182		RETVAL
183
184SDL_Surface *
185image_load_PNG_rw(src)
186	SDL_RWops* src
187 	PREINIT:
188 	 	 char *CLASS = "SDL::Surface";
189 	CODE:
190		RETVAL = IMG_LoadPNG_RW(src);
191	OUTPUT:
192		RETVAL
193
194SDL_Surface *
195image_load_PNM_rw(src)
196	SDL_RWops* src
197 	PREINIT:
198 	 	 char *CLASS = "SDL::Surface";
199 	CODE:
200		RETVAL = IMG_LoadPNM_RW(src);
201	OUTPUT:
202		RETVAL
203
204SDL_Surface *
205image_load_TGA_rw(src)
206	SDL_RWops* src
207 	PREINIT:
208 	 	 char *CLASS = "SDL::Surface";
209 	CODE:
210		RETVAL = IMG_LoadTGA_RW(src);
211	OUTPUT:
212		RETVAL
213
214SDL_Surface *
215image_load_TIF_rw(src)
216	SDL_RWops* src
217 	PREINIT:
218 	 	 char *CLASS = "SDL::Surface";
219 	CODE:
220		RETVAL = IMG_LoadTIF_RW(src);
221	OUTPUT:
222		RETVAL
223
224SDL_Surface *
225image_load_XCF_rw(src)
226	SDL_RWops* src
227	PREINIT:
228 	 	 char *CLASS = "SDL::Surface"; 
229 	CODE:
230		RETVAL = IMG_LoadXCF_RW(src);
231	OUTPUT:
232		RETVAL
233
234SDL_Surface *
235image_load_XPM_rw(src)
236	SDL_RWops* src
237	PREINIT:
238 	 	 char *CLASS = "SDL::Surface"; 
239 	CODE:
240		RETVAL = IMG_LoadXPM_RW(src);
241	OUTPUT:
242		RETVAL
243
244SDL_Surface *
245image_load_XV_rw(src)
246	SDL_RWops* src
247	PREINIT:
248	 	 char *CLASS = "SDL::Surface";
249 	CODE:
250		RETVAL = IMG_LoadXV_RW(src);
251	OUTPUT:
252		RETVAL
253
254
255int image_is_BMP(src)
256	SDL_RWops* src;
257	CODE:
258		RETVAL=IMG_isBMP(src);
259	OUTPUT:
260		RETVAL
261
262#if (SDL_IMAGE_MAJOR_VERSION >= 1) && (SDL_IMAGE_MINOR_VERSION >= 2) && (SDL_IMAGE_PATCHLEVEL >= 10)
263
264int image_is_CUR(src)
265	SDL_RWops* src;
266	CODE:
267		RETVAL=IMG_isCUR(src);
268	OUTPUT:
269		RETVAL
270
271
272int image_is_ICO(src)
273	SDL_RWops* src;
274	CODE:
275		RETVAL=IMG_isICO(src);
276	OUTPUT:
277		RETVAL
278
279#endif
280
281int 
282image_is_GIF(src)
283	 SDL_RWops * src;
284	CODE:
285		RETVAL=IMG_isGIF(src);
286	OUTPUT:
287		RETVAL
288
289int 
290image_is_JPG(src)
291	 SDL_RWops * src;
292	CODE:
293		RETVAL=IMG_isJPG(src);
294	OUTPUT:
295		RETVAL
296
297int 
298image_is_LBM(src)
299	 SDL_RWops * src;
300	CODE:
301		RETVAL=IMG_isLBM(src);
302	OUTPUT:
303		RETVAL
304
305int 
306image_is_PCX(src)
307	 SDL_RWops * src;
308	CODE:
309		RETVAL=IMG_isPCX(src);
310	OUTPUT:
311		RETVAL
312
313int 
314image_is_PNG(src)
315	 SDL_RWops * src;
316	CODE:
317		RETVAL=IMG_isPNG(src);
318	OUTPUT:
319		RETVAL
320
321int 
322image_is_PNM(src)
323	 SDL_RWops * src;
324	CODE:
325		RETVAL=IMG_isPNM(src);
326	OUTPUT:
327		RETVAL
328
329int 
330image_is_TIF(src)
331	 SDL_RWops * src;
332	CODE:
333		RETVAL=IMG_isTIF(src);
334	OUTPUT:
335		RETVAL
336
337int 
338image_is_XCF(src)
339	 SDL_RWops * src;
340	CODE:
341		RETVAL=IMG_isXCF(src);
342	OUTPUT:
343		RETVAL
344
345int 
346image_is_XPM(src)
347	 SDL_RWops * src;
348	CODE:
349		RETVAL=IMG_isXPM(src);
350	OUTPUT:
351		RETVAL
352
353int 
354image_is_XV(src)
355	 SDL_RWops * src;
356	CODE:
357		RETVAL=IMG_isXV(src);
358	OUTPUT:
359		RETVAL
360
361
362
363SDL_Surface *
364image_read_XPM_from_array(array, w)
365	int w
366	AV* array 
367	PREINIT:
368		char* CLASS = "SDL::Surface";
369	CODE:
370		/*make columns first */
371		int x, len;
372		SV ** elem;
373		len = av_len(array) + 1;
374		char** src_x = safemalloc( len * sizeof(char*));
375		char* temp;
376		for(x=0; x < len ; x++)
377		{
378			 elem =  av_fetch(array, x, 0) ;
379			 temp = SvPV_nolen(*elem);
380			src_x[x] = safemalloc(w * sizeof(char) );
381			memcpy( src_x[x], temp, w * sizeof(char) );
382			/*warn("put in %s", src_x[x]); */
383		}
384	  		/*test(src_x);  */
385		RETVAL = IMG_ReadXPMFromArray( src_x) ;
386		for(x=0; x < len; x++)
387		  safefree(src_x[x]);
388		safefree(src_x);
389	
390	OUTPUT:
391		RETVAL
392
393
394
395
396
397#endif