Added fix for SDL::Surface->format. Fixed test and typemap if SDL::NULL (0) is passed...
[sdlgit/SDL_perl.git] / src / Core / objects / Surface.xs
CommitLineData
88a46efc 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
11MODULE = SDL::Surface PACKAGE = SDL::Surface PREFIX = surface_
12
13=for documentation
14
15SDL_Surface -- Graphic surface structure
16
17 typedef struct SDL_Surface {
18 Uint32 flags; /* Read-only */
19 SDL_PixelFormat *format; /* Read-only */
20 int w, h; /* Read-only */
21 Uint16 pitch; /* Read-only */
22 void *pixels; /* Read-write */
23 SDL_Rect clip_rect; /* Read-only */
24 int refcount; /* Read-mostly */
25
26 /* This structure also contains private fields not shown here */
27 } SDL_Surface;
28
29=cut
30
31SDL_Surface *
32surface_new (CLASS, flags, width, height, depth, Rmask, Gmask, Bmask, Amask )
33 char* CLASS
34 Uint32 flags
35 int width
36 int height
37 int depth
38 Uint32 Rmask
39 Uint32 Gmask
40 Uint32 Bmask
41 Uint32 Amask
42 CODE:
43 RETVAL = SDL_CreateRGBSurface ( flags, width, height,
44 depth, Rmask, Gmask, Bmask, Amask );
45 OUTPUT:
46 RETVAL
47
50d9130a 48SDL_PixelFormat *
49surface_format ( surface )
50 SDL_Surface *surface
4510df28 51 PREINIT:
50d9130a 52 char* CLASS = "SDL::PixelFormat";
4510df28 53 CODE:
50d9130a 54 RETVAL = surface->format;
55 OUTPUT:
56 RETVAL
57
88a46efc 58Uint16
18ef5a29 59surface_pitch( surface )
60 SDL_Surface *surface
61 CODE:
62 RETVAL = surface->pitch;
63 OUTPUT:
64 RETVAL
65
66Uint16
88a46efc 67surface_w ( surface )
68 SDL_Surface *surface
69 CODE:
70 RETVAL = surface->w;
71 OUTPUT:
72 RETVAL
73
74Uint16
75surface_h ( surface )
76 SDL_Surface *surface
77 CODE:
78 RETVAL = surface->h;
79 OUTPUT:
80 RETVAL
81
18ef5a29 82IV
83surface_get_pixels(surface)
84 SDL_Surface *surface
85 CODE:
b7ed9095 86 if(!surface->pixels) croak("Incomplete surface");
793e8806 87 RETVAL = PTR2IV(surface->pixels);
18ef5a29 88 OUTPUT:
793e8806 89 RETVAL
18ef5a29 90
91void
92surface_set_pixels(surface, pixels)
93 SDL_Surface *surface
94
95 SV *pixels
96
97 PREINIT:
98 STRLEN len;
99 void *p;
100
101 CODE:
102 p = SvPV(pixels, len);
103 if (len > surface->pitch*surface->h)
104 len = surface->pitch*surface->h;
105 memcpy(surface->pixels, p, len);
106
88a46efc 107void
108surface_DESTROY(surface)
109 SDL_Surface *surface
110 CODE:
111 Uint8* pixels = surface->pixels;
112 Uint32 flags = surface->flags;
113 SDL_FreeSurface(surface);
114 if (flags & SDL_PREALLOC)
115 Safefree(pixels);