Fixed the pod path in archive
[sdlgit/SDL_perl.git] / src / Core / objects / Surface.xs
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
11 MODULE = SDL::Surface   PACKAGE = SDL::Surface    PREFIX = surface_
12
13 =for documentation
14
15 SDL_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
31 SDL_Surface *
32 surface_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
48 SDL_Surface *
49 surface_new_from (CLASS, pixels, width, height, depth, pitch, Rmask, Gmask, Bmask, Amask )
50         char *CLASS
51         char *pixels
52         int width
53         int height
54         int depth
55         int pitch
56         Uint32 Rmask
57         Uint32 Gmask
58         Uint32 Bmask
59         Uint32 Amask
60         CODE:
61                 void* pixeldata;
62                 int len = pitch * height;
63                 Newx(pixeldata,len,Uint8);
64                 Copy(pixels,pixeldata,len,Uint8);
65                 RETVAL = SDL_CreateRGBSurfaceFrom ( pixeldata, width, height,
66                                 depth, pitch, Rmask, Gmask, Bmask, Amask );
67         OUTPUT: 
68                 RETVAL
69
70
71
72 SDL_PixelFormat *
73 surface_format ( surface )
74         SDL_Surface *surface
75         PREINIT:
76                 char* CLASS = "SDL::PixelFormat";
77         CODE:
78                 RETVAL = surface->format;
79         OUTPUT:
80                 RETVAL
81
82 Uint16
83 surface_pitch( surface )
84         SDL_Surface *surface
85         CODE:
86                 RETVAL = surface->pitch;
87         OUTPUT:
88                 RETVAL
89
90 Uint16
91 surface_w ( surface )
92         SDL_Surface *surface
93         CODE:
94                 RETVAL = surface->w;
95         OUTPUT:
96                 RETVAL
97
98 Uint16
99 surface_h ( surface )
100         SDL_Surface *surface
101         CODE:
102                 RETVAL = surface->h;
103         OUTPUT:
104                 RETVAL
105
106 IV
107 surface_get_pixels(surface)
108         SDL_Surface *surface
109         CODE:
110           if(!surface->pixels) croak("Incomplete surface");
111           RETVAL = PTR2IV(surface->pixels);
112         OUTPUT:
113           RETVAL
114
115 void
116 surface_set_pixels(surface, pixels)
117         SDL_Surface *surface
118
119         SV *pixels
120
121         PREINIT:
122           STRLEN len;
123           void *p;
124
125         CODE:
126           p = SvPV(pixels, len);
127           if (len > surface->pitch*surface->h)
128                 len = surface->pitch*surface->h;
129           memcpy(surface->pixels, p, len);
130
131 void
132 surface_DESTROY(surface)
133         SDL_Surface *surface
134         CODE:
135                 Uint8* pixels = surface->pixels;
136                 Uint32 flags = surface->flags;
137                 SDL_FreeSurface(surface);
138                 if (flags & SDL_PREALLOC)
139                         Safefree(pixels);