Fixed the pod path in archive
[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
871d7fa3 48SDL_Surface *
49surface_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
50d9130a 72SDL_PixelFormat *
73surface_format ( surface )
74 SDL_Surface *surface
4510df28 75 PREINIT:
50d9130a 76 char* CLASS = "SDL::PixelFormat";
4510df28 77 CODE:
50d9130a 78 RETVAL = surface->format;
79 OUTPUT:
80 RETVAL
81
88a46efc 82Uint16
18ef5a29 83surface_pitch( surface )
84 SDL_Surface *surface
85 CODE:
86 RETVAL = surface->pitch;
87 OUTPUT:
88 RETVAL
89
90Uint16
88a46efc 91surface_w ( surface )
92 SDL_Surface *surface
93 CODE:
94 RETVAL = surface->w;
95 OUTPUT:
96 RETVAL
97
98Uint16
99surface_h ( surface )
100 SDL_Surface *surface
101 CODE:
102 RETVAL = surface->h;
103 OUTPUT:
104 RETVAL
105
18ef5a29 106IV
107surface_get_pixels(surface)
108 SDL_Surface *surface
109 CODE:
b7ed9095 110 if(!surface->pixels) croak("Incomplete surface");
793e8806 111 RETVAL = PTR2IV(surface->pixels);
18ef5a29 112 OUTPUT:
793e8806 113 RETVAL
18ef5a29 114
115void
116surface_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
88a46efc 131void
132surface_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);