PageRenderTime 62ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Core/Video.xs

http://github.com/PerlGameDev/SDL
Unknown | 590 lines | 512 code | 78 blank | 0 comment | 0 complexity | 5f69212b6ad3e3a7b14a1863844760b2 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. #include "EXTERN.h"
  2. #include "perl.h"
  3. #include "XSUB.h"
  4. #include "ppport.h"
  5. #include "helper.h"
  6. #ifndef aTHX_
  7. #define aTHX_
  8. #endif
  9. #include <SDL.h>
  10. void _uinta_free(Uint16* av, int len_from_av_len)
  11. {
  12. if( av != NULL)
  13. return;
  14. safefree(av);
  15. }
  16. Uint16* av_to_uint16 (AV* av)
  17. {
  18. int len = av_len(av);
  19. if( len != -1)
  20. {
  21. int i;
  22. Uint16* table = (Uint16 *)safemalloc(sizeof(Uint16)*(len+1));
  23. for ( i = 0; i < len+1 ; i++ )
  24. {
  25. SV ** temp = av_fetch(av,i,0);
  26. if( temp != NULL )
  27. {
  28. table[i] = (Uint16) SvIV( *temp );
  29. }
  30. else
  31. {
  32. table[i] = 0;
  33. }
  34. }
  35. return table;
  36. }
  37. return NULL;
  38. }
  39. MODULE = SDL::Video PACKAGE = SDL::Video PREFIX = video_
  40. =for documentation
  41. The Following are XS bindings to the Video category in the SDL API v2.1.13
  42. Describe on the SDL API site.
  43. See: L<http:/*www.libsdl.org/cgi/docwiki.cgi/SDL_API#head-813f033ec44914f267f32195aba7d9aff8c410c0> */
  44. =cut
  45. SDL_Surface *
  46. video_get_video_surface()
  47. PREINIT:
  48. char* CLASS = "SDL::Surface";
  49. CODE:
  50. RETVAL = SDL_GetVideoSurface();
  51. OUTPUT:
  52. RETVAL
  53. SDL_VideoInfo*
  54. video_get_video_info()
  55. PREINIT:
  56. char* CLASS = "SDL::VideoInfo";
  57. CODE:
  58. RETVAL = (SDL_VideoInfo *) SDL_GetVideoInfo();
  59. OUTPUT:
  60. RETVAL
  61. SV *
  62. video_video_driver_name( )
  63. CODE:
  64. char buffer[1024];
  65. if ( SDL_VideoDriverName(buffer, 1024) != NULL )
  66. {
  67. RETVAL = newSVpv(buffer, 0);
  68. }
  69. else
  70. XSRETURN_UNDEF;
  71. OUTPUT:
  72. RETVAL
  73. AV*
  74. video_list_modes ( format, flags )
  75. Uint32 flags
  76. SDL_PixelFormat *format
  77. CODE:
  78. SDL_Rect **mode;
  79. RETVAL = newAV();
  80. sv_2mortal((SV*)RETVAL);
  81. mode = SDL_ListModes(format,flags);
  82. if (mode == (SDL_Rect**)-1 ) {
  83. av_push(RETVAL,newSVpv("all",0));
  84. } else if (! mode ) {
  85. av_push(RETVAL,newSVpv("none",0));
  86. } else {
  87. int i;
  88. for (i=0; mode[i]; ++i)
  89. av_push(RETVAL, cpy2bag( (void *)mode[i], sizeof(SDL_Rect *), sizeof(SDL_Rect), "SDL::Rect" ));
  90. }
  91. OUTPUT:
  92. RETVAL
  93. int
  94. video_video_mode_ok ( width, height, bpp, flags )
  95. int width
  96. int height
  97. int bpp
  98. Uint32 flags
  99. CODE:
  100. RETVAL = SDL_VideoModeOK(width,height,bpp,flags);
  101. OUTPUT:
  102. RETVAL
  103. SDL_Surface *
  104. video_set_video_mode ( width, height, bpp, flags )
  105. int width
  106. int height
  107. int bpp
  108. Uint32 flags
  109. PREINIT:
  110. char* CLASS = "SDL::Surface";
  111. CODE:
  112. RETVAL = SDL_SetVideoMode(width,height,bpp,flags);
  113. OUTPUT:
  114. RETVAL
  115. void
  116. video_update_rect ( surface, x, y, w ,h )
  117. SDL_Surface *surface
  118. int x
  119. int y
  120. int w
  121. int h
  122. CODE:
  123. SDL_UpdateRect(surface,x,y,w,h);
  124. void
  125. video_update_rects ( surface, ... )
  126. SDL_Surface *surface
  127. CODE:
  128. SDL_Rect* rects;
  129. int num_rects,i;
  130. if ( items < 2 ) return;
  131. num_rects = items - 1;
  132. rects = (SDL_Rect *)safemalloc(sizeof(SDL_Rect)*items);
  133. for(i=0;i<num_rects;i++) {
  134. void** pointers = (void**)INT2PTR(void *, SvIV((SV *)SvRV( ST(i + 1) )));
  135. rects[i] = *(SDL_Rect *)(pointers[0]);
  136. }
  137. SDL_UpdateRects(surface,num_rects,rects);
  138. safefree(rects);
  139. int
  140. video_flip ( surface )
  141. SDL_Surface *surface
  142. CODE:
  143. RETVAL = SDL_Flip(surface);
  144. OUTPUT:
  145. RETVAL
  146. int
  147. video_set_colors ( surface, start, ... )
  148. SDL_Surface *surface
  149. int start
  150. CODE:
  151. if ( items < 3 )
  152. RETVAL = 0;
  153. else
  154. {
  155. int i;
  156. int length = items - 2;
  157. SDL_Color *colors = (SDL_Color *)safemalloc(sizeof(SDL_Color) * (length + 1));
  158. for ( i = 0; i < length ; i++ ) {
  159. SDL_Color *temp = (SDL_Color *)bag2obj( ST(i + 2) );
  160. colors[i].r = temp->r;
  161. colors[i].g = temp->g;
  162. colors[i].b = temp->b;
  163. }
  164. RETVAL = SDL_SetColors(surface, colors, start, length);
  165. safefree(colors);
  166. }
  167. OUTPUT:
  168. RETVAL
  169. int
  170. video_set_palette ( surface, flags, start, ... )
  171. SDL_Surface *surface
  172. int flags
  173. int start
  174. CODE:
  175. if ( items < 4 )
  176. RETVAL = 0;
  177. else
  178. {
  179. int i;
  180. int length = items - 3;
  181. SDL_Color *colors = (SDL_Color *)safemalloc(sizeof(SDL_Color) * (length + 1));
  182. for ( i = 0; i < length ; i++ ) {
  183. SDL_Color *temp = (SDL_Color *)bag2obj( ST(i + 3) );
  184. colors[i].r = temp->r;
  185. colors[i].g = temp->g;
  186. colors[i].b = temp->b;
  187. }
  188. RETVAL = SDL_SetPalette(surface, flags, colors, start, length);
  189. safefree(colors);
  190. }
  191. OUTPUT:
  192. RETVAL
  193. int
  194. video_set_gamma(r, g, b)
  195. float r;
  196. float g;
  197. float b;
  198. CODE:
  199. RETVAL = SDL_SetGamma(r,g,b);
  200. OUTPUT:
  201. RETVAL
  202. int
  203. video_get_gamma_ramp( redtable, greentable, bluetable )
  204. AV* redtable;
  205. AV* greentable;
  206. AV* bluetable;
  207. CODE:
  208. Uint16 red_ramp[256];
  209. Uint16 green_ramp[256];
  210. Uint16 blue_ramp[256];
  211. int i;
  212. RETVAL = SDL_GetGammaRamp(red_ramp, green_ramp, blue_ramp);
  213. for ( i=0; i<256; ++i ) {
  214. av_push(redtable,newSViv(red_ramp[i]));
  215. av_push(greentable,newSViv(green_ramp[i]));
  216. av_push(bluetable,newSViv(blue_ramp[i]));
  217. }
  218. OUTPUT:
  219. RETVAL
  220. int
  221. video_set_gamma_ramp( rt, gt, bt )
  222. AV* rt;
  223. AV* gt;
  224. AV* bt;
  225. CODE:
  226. Uint16 *redtable, *greentable, *bluetable;
  227. redtable = av_to_uint16(rt);
  228. greentable = av_to_uint16(gt);
  229. bluetable = av_to_uint16(bt);
  230. RETVAL = SDL_SetGammaRamp(redtable, greentable, bluetable);
  231. _uinta_free(redtable, av_len(rt) );
  232. _uinta_free(greentable, av_len(gt) );
  233. _uinta_free(bluetable, av_len(bt) );
  234. OUTPUT:
  235. RETVAL
  236. Uint32
  237. video_map_RGB ( pixel_format, r, g, b )
  238. SDL_PixelFormat *pixel_format
  239. Uint8 r
  240. Uint8 g
  241. Uint8 b
  242. CODE:
  243. RETVAL = SDL_MapRGB(pixel_format, r,g,b);
  244. OUTPUT:
  245. RETVAL
  246. Uint32
  247. video_map_RGBA ( pixel_format, r, g, b, a )
  248. SDL_PixelFormat *pixel_format
  249. Uint8 r
  250. Uint8 g
  251. Uint8 b
  252. Uint8 a
  253. CODE:
  254. RETVAL = SDL_MapRGBA(pixel_format, r,g,b,a );
  255. OUTPUT:
  256. RETVAL
  257. int
  258. video_lock_surface ( surface )
  259. SDL_Surface *surface
  260. CODE:
  261. RETVAL = SDL_LockSurface(surface);
  262. OUTPUT:
  263. RETVAL
  264. void
  265. video_unlock_surface ( surface )
  266. SDL_Surface *surface
  267. CODE:
  268. SDL_UnlockSurface(surface);
  269. SDL_Surface *
  270. video_convert_surface( src, fmt, flags)
  271. SDL_Surface* src
  272. SDL_PixelFormat* fmt
  273. Uint32 flags
  274. PREINIT:
  275. char *CLASS = "SDL::Surface";
  276. CODE:
  277. RETVAL = SDL_ConvertSurface(src, fmt, flags);
  278. OUTPUT:
  279. RETVAL
  280. SDL_Surface *
  281. video_display_format ( surface )
  282. SDL_Surface *surface
  283. PREINIT:
  284. char* CLASS = "SDL::Surface";
  285. CODE:
  286. RETVAL = SDL_DisplayFormat(surface);
  287. OUTPUT:
  288. RETVAL
  289. SDL_Surface *
  290. video_display_format_alpha ( surface )
  291. SDL_Surface *surface
  292. PREINIT:
  293. char* CLASS = "SDL::Surface";
  294. CODE:
  295. RETVAL = SDL_DisplayFormatAlpha(surface);
  296. OUTPUT:
  297. RETVAL
  298. int
  299. video_set_color_key ( surface, flag, key )
  300. SDL_Surface *surface
  301. Uint32 flag
  302. SV *key
  303. CODE:
  304. Uint32 pixel;
  305. if(SvOK(key) && SvIOK(key))
  306. pixel = (Uint32)SvUV(key);
  307. else
  308. {
  309. SDL_Color *color = (SDL_Color *)bag2obj(key);
  310. pixel = SDL_MapRGB(surface->format, color->r, color->g, color->b);
  311. }
  312. RETVAL = SDL_SetColorKey(surface,flag,pixel);
  313. OUTPUT:
  314. RETVAL
  315. int
  316. video_set_alpha ( surface, flag, alpha )
  317. SDL_Surface *surface
  318. Uint32 flag
  319. Uint8 alpha
  320. CODE:
  321. RETVAL = SDL_SetAlpha(surface,flag,alpha);
  322. OUTPUT:
  323. RETVAL
  324. AV *
  325. video_get_RGB ( pixel_format, pixel )
  326. SDL_PixelFormat *pixel_format
  327. Uint32 pixel
  328. CODE:
  329. Uint8 r,g,b;
  330. SDL_GetRGB(pixel,pixel_format,&r,&g,&b);
  331. RETVAL = newAV();
  332. sv_2mortal((SV*)RETVAL);
  333. av_push(RETVAL,newSViv(r));
  334. av_push(RETVAL,newSViv(g));
  335. av_push(RETVAL,newSViv(b));
  336. OUTPUT:
  337. RETVAL
  338. AV *
  339. video_get_RGBA ( pixel_format, pixel )
  340. SDL_PixelFormat *pixel_format
  341. Uint32 pixel
  342. CODE:
  343. Uint8 r,g,b,a;
  344. SDL_GetRGBA(pixel,pixel_format,&r,&g,&b,&a);
  345. RETVAL = newAV();
  346. sv_2mortal((SV*)RETVAL);
  347. av_push(RETVAL,newSViv(r));
  348. av_push(RETVAL,newSViv(g));
  349. av_push(RETVAL,newSViv(b));
  350. av_push(RETVAL,newSViv(a));
  351. OUTPUT:
  352. RETVAL
  353. SDL_Surface*
  354. video_load_BMP ( filename )
  355. char *filename
  356. PREINIT:
  357. char* CLASS = "SDL::Surface";
  358. CODE:
  359. RETVAL = SDL_LoadBMP(filename);
  360. OUTPUT:
  361. RETVAL
  362. int
  363. save_BMP ( surface, filename )
  364. SDL_Surface *surface
  365. char *filename
  366. CODE:
  367. RETVAL = SDL_SaveBMP(surface,filename);
  368. OUTPUT:
  369. RETVAL
  370. int
  371. fill_rect ( dest, dest_rect, pixel )
  372. SDL_Surface *dest
  373. SDL_Rect *dest_rect
  374. Uint32 pixel
  375. CODE:
  376. RETVAL = SDL_FillRect(dest,dest_rect,pixel);
  377. OUTPUT:
  378. RETVAL
  379. int
  380. blit_surface ( src, src_rect_bag, dest, dest_rect_bag )
  381. SDL_Surface *src
  382. SDL_Surface *dest
  383. SV *src_rect_bag
  384. SV *dest_rect_bag
  385. CODE:
  386. SDL_Rect *src_rect = NULL;
  387. SDL_Rect *dest_rect = NULL;
  388. if(SvOK(src_rect_bag))
  389. src_rect = (SDL_Rect *)bag2obj(src_rect_bag);
  390. if(SvOK(dest_rect_bag))
  391. dest_rect = (SDL_Rect *)bag2obj(dest_rect_bag);
  392. RETVAL = SDL_BlitSurface(src,src_rect,dest,dest_rect);
  393. OUTPUT:
  394. RETVAL
  395. void
  396. set_clip_rect ( surface, rect )
  397. SDL_Surface *surface
  398. SDL_Rect *rect
  399. CODE:
  400. SDL_SetClipRect(surface,rect);
  401. void
  402. get_clip_rect ( surface, rect )
  403. SDL_Surface *surface
  404. SDL_Rect *rect;
  405. CODE:
  406. SDL_GetClipRect(surface, rect);
  407. int
  408. video_lock_YUV_overlay ( overlay )
  409. SDL_Overlay *overlay
  410. CODE:
  411. RETVAL = SDL_LockYUVOverlay(overlay);
  412. OUTPUT:
  413. RETVAL
  414. void
  415. video_unlock_YUV_overlay ( overlay )
  416. SDL_Overlay *overlay
  417. CODE:
  418. SDL_UnlockYUVOverlay(overlay);
  419. int
  420. video_display_YUV_overlay ( overlay, dstrect )
  421. SDL_Overlay *overlay
  422. SDL_Rect *dstrect
  423. CODE:
  424. RETVAL = SDL_DisplayYUVOverlay ( overlay, dstrect );
  425. OUTPUT:
  426. RETVAL
  427. int
  428. video_GL_load_library ( path )
  429. char *path
  430. CODE:
  431. RETVAL = SDL_GL_LoadLibrary(path);
  432. OUTPUT:
  433. RETVAL
  434. void*
  435. video_GL_get_proc_address ( proc )
  436. char *proc
  437. CODE:
  438. RETVAL = SDL_GL_GetProcAddress(proc);
  439. OUTPUT:
  440. RETVAL
  441. int
  442. video_GL_set_attribute ( attr, value )
  443. int attr
  444. int value
  445. CODE:
  446. RETVAL = SDL_GL_SetAttribute(attr, value);
  447. OUTPUT:
  448. RETVAL
  449. AV *
  450. video_GL_get_attribute ( attr )
  451. int attr
  452. CODE:
  453. int value;
  454. RETVAL = newAV();
  455. sv_2mortal((SV*)RETVAL);
  456. av_push(RETVAL,newSViv(SDL_GL_GetAttribute(attr, &value)));
  457. av_push(RETVAL,newSViv(value));
  458. OUTPUT:
  459. RETVAL
  460. void
  461. video_GL_swap_buffers ()
  462. CODE:
  463. SDL_GL_SwapBuffers ();
  464. void
  465. video_wm_set_caption ( title, icon )
  466. char *title
  467. char *icon
  468. CODE:
  469. SDL_WM_SetCaption(title,icon);
  470. AV *
  471. video_wm_get_caption ()
  472. CODE:
  473. char *title,*icon;
  474. SDL_WM_GetCaption(&title,&icon);
  475. RETVAL = newAV();
  476. sv_2mortal((SV*)RETVAL);
  477. av_push(RETVAL,newSVpv(title,0));
  478. av_push(RETVAL,newSVpv(icon,0));
  479. OUTPUT:
  480. RETVAL
  481. void
  482. video_wm_set_icon ( icon )
  483. SDL_Surface *icon
  484. CODE:
  485. SDL_WM_SetIcon(icon,NULL);
  486. Uint32
  487. video_wm_grab_input ( mode )
  488. Uint32 mode
  489. CODE:
  490. RETVAL = SDL_WM_GrabInput(mode);
  491. OUTPUT:
  492. RETVAL
  493. int
  494. video_wm_iconify_window ()
  495. CODE:
  496. RETVAL = SDL_WM_IconifyWindow();
  497. OUTPUT:
  498. RETVAL
  499. int
  500. video_wm_toggle_fullscreen ( surface )
  501. SDL_Surface *surface
  502. CODE:
  503. RETVAL = SDL_WM_ToggleFullScreen(surface);
  504. OUTPUT:
  505. RETVAL
  506. int
  507. video_MUSTLOCK ( surface )
  508. SDL_Surface *surface
  509. CODE:
  510. RETVAL = SDL_MUSTLOCK(surface);
  511. OUTPUT:
  512. RETVAL