Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'experimental' of github.com:PerlGameDev/SDL into c-sdl-…

…rwops
  • Loading branch information...
commit 640ecab653eb740e4b7d34134456aaa86a412e08 2 parents a18e6fb + 7c1a31b
Tobias Leich authored
View
34 CHANGELOG
@@ -1,21 +1,27 @@
Revision history for Perl extension SDL_perl.
-* 2.534
+* 2.535_01 Nov 5 2011
+ - Merged in memory leak fixes [dod]
+
+* 2.534 October 27 2011
+ - Combined release of 2.534_*
+
+* 2.534_03 October 06 2011
- SDL::Palette fixed colors() to return an array [Blaizer]
- SDL::Video fixed set_colors, set_palette [FROGGS, Blaizer]
- - SDLx::Text improved error message [garu]
- - SDLx::Text new getter: font_filename() [garu]
- - SDLx::Text fixed size() accessor [garu]
- - SDLx::Text dynamic updating of text [garu]
- - SDLx::Text new options: shadow, shadow_offset and shadow_color [garu]
- - SDLx::Text new options: normal, bold, italic, underline, strikethrough [garu]
- - SDLx::Text examples (zoom, shadow, style) [garu]
- - SDLx::Text improved documentation [garu]
- - SDLx::TTF fixed loading error [FROGGS]
-
-* 2.534_03
- Documentation fixes:
- - SDL::Event: fixed SDL_EVENTMASK documentation [jtpalmer]
+ - SDLx::Text improved error message [garu]
+ - SDLx::Text new getter: font_filename() [garu]
+ - SDLx::Text fixed size() accessor [garu]
+ - SDLx::Text dynamic updating of text [garu]
+ - SDLx::Text new options: shadow, shadow_offset and shadow_color [garu]
+ - SDLx::Text new options: normal, bold, italic, underline, strikethrough [garu]
+ - SDLx::Text examples (zoom, shadow, style) [garu]
+ - SDLx::Text improved documentation [garu]
+ - SDLx::Text word wrapping support [garu]
+ - SDLx::TTF fixed loading error [FROGGS]
+ - SDL::Event fixed SDL_EVENTMASK documentation [jtpalmer]
+ - SDL::RWOps got SDL::RWOps->from_const_mem working, updated docs [FROGGS]
+ - SDL::Video updated xs and docs for blit_surface using undefined rects [FROGGS]
* 2.534_02 August 27 2011
New features:
View
2  lib/SDL.pm
@@ -54,7 +54,7 @@ our %EXPORT_TAGS = (
defaults => $SDL::Constants::EXPORT_TAGS{'SDL/defaults'}
);
-our $VERSION = '2.534_03';
+our $VERSION = '2.535_01';
$VERSION = eval $VERSION;
print "$VERSION" if ( defined( $ARGV[0] ) && ( $ARGV[0] eq '--SDLperl' ) );
View
2  src/Core/objects/Surface.xs
@@ -13,6 +13,8 @@
void _free_surface(void *object)
{
+ // Frees the resources used by a previously created SDL_Surface.
+ // If the surface was created using SDL_CreateRGBSurfaceFrom then the pixel data is not freed.
SDL_FreeSurface((SDL_Surface *)object);
}
View
16 src/SDL.xs
@@ -116,7 +116,12 @@ void handler(int sig) {
void
windows_force_driver()
{
- char *test = SDL_getenv("SDL_VIDEODRIVER");
+ char *test;
+#if SDL_MAJOR_VERSION >= 1 && SDL_MINOR_VERSION >= 2 && SDL_PATCHLEVEL >= 9
+ test = SDL_getenv("SDL_VIDEODRIVER");
+#else
+ test = getenv("SDL_VIDEODRIVER");
+#endif
if(!test || 0 != strcmp("dummy", test))
{
#if SDL_MAJOR_VERSION >= 1 && SDL_MINOR_VERSION >= 2 && SDL_PATCHLEVEL >= 14
@@ -265,7 +270,14 @@ char*
getenv (name)
char *name
CODE:
- RETVAL = SDL_getenv(name);
+ char *test;
+ /* SDL version 1.2.9 doesn't have SDL_getenv */
+#if SDL_MAJOR_VERSION >= 1 && SDL_MINOR_VERSION >= 2 && SDL_PATCHLEVEL >= 9
+ test = SDL_getenv(name);
+#else
+ test = getenv(name);
+#endif
+ RETVAL = test;
OUTPUT:
RETVAL
View
2  src/SDLx/Layer.xs
@@ -240,6 +240,8 @@ layerx_foreground( bag )
SvREFCNT_inc( bag );
RETVAL = newSVsv(bag);
SvREFCNT_inc(RETVAL);
+ OUTPUT:
+ RETVAL
void
layerx_DESTROY( layer )
View
296 src/SDLx/Surface.xs
@@ -18,187 +18,149 @@
SV * get_pixel32 (SDL_Surface *surface, int x, int y)
{
-
- /*Convert the pixels to 32 bit */
- Uint32 *pixels = (Uint32 *)surface->pixels;
- /*Get the requested pixel */
-
- void* s = pixels + _calc_offset(surface, x, y);
+ /* Convert the pixels to 32 bit */
+ Uint32 *pixels = (Uint32 *)surface->pixels;
+ /* Get the requested pixel */
- /*printf( " Pixel = %d, Ptr = %p \n", *((int*) s), s ); */
+ void* s = pixels + _calc_offset(surface, x, y);
- SV* sv = newSV_type(SVt_PV);
- SvPV_set(sv, s);
- SvPOK_on(sv);
- SvLEN_set(sv, 0);
- SvCUR_set(sv, surface->format->BytesPerPixel);
- return newRV_noinc(sv); /*make a modifiable reference using u_ptr's place as the memory :) */
+ /* printf( " Pixel = %d, Ptr = %p \n", *((int*) s), s ); */
+ SV* sv = newSV_type(SVt_PV);
+ SvPV_set(sv, s);
+ SvPOK_on(sv);
+ SvLEN_set(sv, 0);
+ SvCUR_set(sv, surface->format->BytesPerPixel);
+ return newRV_noinc(sv); /* make a modifiable reference using u_ptr's place as the memory :) */
}
-
SV * construct_p_matrix ( SDL_Surface *surface )
{
- /*return get_pixel32( surface, 0, 0); */
+ /* return get_pixel32( surface, 0, 0); */
AV * matrix = newAV();
- int i, j;
- i = 0;
- for( i =0 ; i < surface->w; i++)
- {
- AV * matrix_row = newAV();
- for( j =0 ; j < surface->h; j++)
- {
- av_push(matrix_row, get_pixel32(surface, i,j) );
- }
- av_push(matrix, newRV_noinc((SV *)matrix_row) );
-
- }
-
- return newRV_noinc((SV *)matrix);
+ int i, j;
+ i = 0;
+ for( i =0 ; i < surface->w; i++ )
+ {
+ AV * matrix_row = newAV();
+ for( j =0 ; j < surface->h; j++ )
+ av_push( matrix_row, get_pixel32(surface, i,j) );
+
+ av_push( matrix, newRV_noinc((SV *)matrix_row) );
+ }
+
+ return newRV_noinc((SV *)matrix);
}
-
int _calc_offset ( SDL_Surface* surface, int x, int y )
-{
- int offset;
- offset = (surface->pitch * y)/surface->format->BytesPerPixel;
- offset += x;
- return offset;
+{
+ int offset;
+ offset = (surface->pitch * y) / surface->format->BytesPerPixel;
+ offset += x;
+ return offset;
}
-
unsigned int _get_pixel(SDL_Surface * surface, int offset)
{
-
- unsigned int value;
- switch(surface->format->BytesPerPixel)
- {
- case 1: value = ((Uint8 *)surface->pixels)[offset];
- break;
- case 2: value = ((Uint16 *)surface->pixels)[offset];
- break;
- case 3: value = ((Uint32)((Uint8 *)surface->pixels)[offset * surface->format->BytesPerPixel] << 0)
- + ((Uint32)((Uint8 *)surface->pixels)[offset * surface->format->BytesPerPixel + 1] << 8)
- + ((Uint32)((Uint8 *)surface->pixels)[offset * surface->format->BytesPerPixel + 2] << 16);
- break;
- case 4: value = ((Uint32 *)surface->pixels)[offset];
- break;
-
- }
- return value;
+ unsigned int value;
+ switch(surface->format->BytesPerPixel)
+ {
+ case 1: value = ((Uint8 *)surface->pixels)[offset];
+ break;
+ case 2: value = ((Uint16 *)surface->pixels)[offset];
+ break;
+ case 3: value = ((Uint32)((Uint8 *)surface->pixels)[offset * surface->format->BytesPerPixel] << 0)
+ + ((Uint32)((Uint8 *)surface->pixels)[offset * surface->format->BytesPerPixel + 1] << 8)
+ + ((Uint32)((Uint8 *)surface->pixels)[offset * surface->format->BytesPerPixel + 2] << 16);
+ break;
+ case 4: value = ((Uint32 *)surface->pixels)[offset];
+ break;
+ }
+ return value;
}
-
MODULE = SDLx::Surface PACKAGE = SDLx::Surface PREFIX = surfacex_
SV *
surfacex_pixel_array ( surface )
- SDL_Surface *surface
- CODE:
- switch(surface->format->BytesPerPixel)
- {
- case 1: croak("Not implemented yet for 8bpp surfaces\n");
- break;
- case 2: croak("Not implemented yet for 16bpp surfaces\n");
- break;
- case 3: croak("Not implemented yet for 24bpp surfaces\n");
- break;
- case 4:
- RETVAL = construct_p_matrix (surface);
- break;
-
- }
-
-
- OUTPUT:
- RETVAL
+ SDL_Surface *surface
+ CODE:
+ switch(surface->format->BytesPerPixel)
+ {
+ case 1: croak("Not implemented yet for 8bpp surfaces\n");
+ break;
+ case 2: croak("Not implemented yet for 16bpp surfaces\n");
+ break;
+ case 3: croak("Not implemented yet for 24bpp surfaces\n");
+ break;
+ case 4:
+ RETVAL = construct_p_matrix (surface);
+ break;
+ }
+ OUTPUT:
+ RETVAL
unsigned int
surfacex_get_pixel_xs ( surface, x, y )
- SDL_Surface *surface
- int x
- int y
- CODE:
- if( x < 0 )
- x = 0;
- else if ( x > surface->w)
- x = surface->w;
-
- if ( y < 0 )
- y = 0;
- else if ( y > surface->h)
- y = surface->h;
-
- int offset;
- offset = _calc_offset( surface, x, y);
- RETVAL = _get_pixel( surface, offset );
-
- OUTPUT:
- RETVAL
+ SDL_Surface *surface
+ int x
+ int y
+ CODE:
+ _int_range( &x, 0, surface->w );
+ _int_range( &y, 0, surface->h );
+ int offset;
+ offset = _calc_offset( surface, x, y);
+ RETVAL = _get_pixel( surface, offset );
+ OUTPUT:
+ RETVAL
void
surfacex_set_pixel_xs ( surface, x, y, value )
- SDL_Surface *surface
- int x
- int y
- unsigned int value
- CODE:
- if( x < 0 )
- x = 0;
- else if ( x > surface->w)
- x = surface->w;
-
- if ( y < 0 )
- y = 0;
- else if ( y > surface->h)
- y = surface->h;
-
- int offset;
- offset = _calc_offset( surface, x, y);
- if(SDL_MUSTLOCK(surface))
- if ( SDL_LockSurface(surface) < 0)
- croak( "Locking surface in set_pixels failed: %s", SDL_GetError() );
- switch(surface->format->BytesPerPixel)
- {
- case 1: ((Uint8 *)surface->pixels)[offset] = (Uint8)value;
- break;
- case 2: ((Uint16 *)surface->pixels)[offset] = (Uint16)value;
- break;
- case 3: ((Uint8 *)surface->pixels)[offset * surface->format->BytesPerPixel] = (Uint8)( value & 0xFF);
- ((Uint8 *)surface->pixels)[offset * surface->format->BytesPerPixel + 1] = (Uint8)((value << 8) & 0xFF);
- ((Uint8 *)surface->pixels)[offset * surface->format->BytesPerPixel + 2] = (Uint8)((value << 16) & 0xFF);
- break;
- case 4: ((Uint32 *)surface->pixels)[offset] = (Uint32)value;
- break;
- }
- if(SDL_MUSTLOCK(surface))
- SDL_UnlockSurface(surface);
-
+ SDL_Surface *surface
+ int x
+ int y
+ unsigned int value
+ CODE:
+ _int_range( &x, 0, surface->w );
+ _int_range( &y, 0, surface->h );
+ int offset;
+ offset = _calc_offset( surface, x, y);
+ if(SDL_MUSTLOCK(surface) && SDL_LockSurface(surface) < 0)
+ croak( "Locking surface in set_pixels failed: %s", SDL_GetError() );
+ switch(surface->format->BytesPerPixel)
+ {
+ case 1: ((Uint8 *)surface->pixels)[offset] = (Uint8)value;
+ break;
+ case 2: ((Uint16 *)surface->pixels)[offset] = (Uint16)value;
+ break;
+ case 3: ((Uint8 *)surface->pixels)[offset * surface->format->BytesPerPixel] = (Uint8)( value & 0xFF);
+ ((Uint8 *)surface->pixels)[offset * surface->format->BytesPerPixel + 1] = (Uint8)((value << 8) & 0xFF);
+ ((Uint8 *)surface->pixels)[offset * surface->format->BytesPerPixel + 2] = (Uint8)((value << 16) & 0xFF);
+ break;
+ case 4: ((Uint32 *)surface->pixels)[offset] = (Uint32)value;
+ break;
+ }
+ if(SDL_MUSTLOCK(surface))
+ SDL_UnlockSurface(surface);
void
surfacex_draw_rect ( surface, rt, color )
- SDL_Surface *surface
- SV* rt
- SV* color
- CODE:
- Uint32 m_color = __map_rgba( color, surface->format );
- SDL_Rect r_rect;
+ SDL_Surface *surface
+ SV* rt
+ SV* color
+ CODE:
+ Uint32 m_color = __map_rgba( color, surface->format );
+ SDL_Rect r_rect;
- if( SvOK(rt) )
- {
- int newly_created_rect = 0;
- SV* foo = rect( rt, &newly_created_rect );
- r_rect = *(SDL_Rect*)bag2obj(foo);
- SDL_FillRect(surface, &r_rect, m_color);
- SvREFCNT_dec(foo);
- }
- else
- {
- r_rect.x = 0; r_rect.y = 0; r_rect.w = surface->w; r_rect.h = surface->h;
- SDL_FillRect(surface, &r_rect, m_color);
- }
+ if( SvOK(rt) )
+ r_rect = *(SDL_Rect*)bag2obj( create_mortal_rect( rt ) );
+ else
+ {
+ r_rect.x = 0; r_rect.y = 0; r_rect.w = surface->w; r_rect.h = surface->h;
+ }
+ SDL_FillRect(surface, &r_rect, m_color);
#ifdef HAVE_SDL_GFX_PRIMITIVES
@@ -209,17 +171,16 @@ surfacex_draw_polygon ( surface, vectors, color, ... )
Uint32 color
CODE:
SDL_Surface * _surface = (SDL_Surface *)bag2obj(surface);
- AV* vx = newAV();
- AV* vy = newAV();
+ AV* vx = newAV();
+ AV* vy = newAV();
AV* vertex;
- while (vertex = (AV*)SvRV(av_shift(vectors)))
+ while(vertex = (AV*)SvRV(av_shift(vectors)))
{
av_push(vx, av_shift(vertex));
av_push(vy, av_shift(vertex));
}
- int n = av_len(vx) + 1;
-
+ int n = av_len(vx) + 1;
Sint16 * _vx = av_to_sint16(vx);
Sint16 * _vy = av_to_sint16(vy);
if ( items > 3 && SvTRUE( ST(3) ) )
@@ -228,7 +189,7 @@ surfacex_draw_polygon ( surface, vectors, color, ... )
polygonColor( _surface, _vx, _vy, n, color );
_svinta_free( _vx, av_len(vx) );
_svinta_free( _vy, av_len(vy) );
- RETVAL = SvREFCNT_inc(surface);
+ RETVAL = SvREFCNT_inc(surface); // why SvREFCNT_inc?
OUTPUT:
RETVAL
@@ -239,22 +200,17 @@ surfacex_blit( src, dest, ... )
SV *src
SV *dest
CODE:
- src = surface(src);
- dest = surface(dest);
+ assert_surface(src);
+ assert_surface(dest);
+ /* just return the pointer stored in the bag */
SDL_Surface *_src = (SDL_Surface *)bag2obj(src);
SDL_Surface *_dest = (SDL_Surface *)bag2obj(dest);
SDL_Rect _src_rect;
SDL_Rect _dest_rect;
- int newly_created_rect = 0;
- SV* s_rect_sv, *d_rect_sv;
- int mall_sr = 0; int mall_dr = 0;
+
if( items > 2 && SvOK(ST(2)) )
- {
- s_rect_sv = rect(ST(2), &newly_created_rect);
- _src_rect = *(SDL_Rect *)bag2obj( s_rect_sv );
- mall_sr = 1;
- }
+ _src_rect = *(SDL_Rect *)bag2obj( create_mortal_rect( ST(2) ) );
else
{
_src_rect.x = 0;
@@ -264,11 +220,7 @@ surfacex_blit( src, dest, ... )
}
if( items > 3 && SvOK(ST(3)) )
- {
- d_rect_sv = rect(ST(3), &newly_created_rect);
- _dest_rect = *(SDL_Rect *)bag2obj( d_rect_sv );
- mall_dr = 1;
- }
+ _dest_rect = *(SDL_Rect *)bag2obj( create_mortal_rect( ST(3) ) );
else
{
_dest_rect.x = 0;
@@ -278,9 +230,3 @@ surfacex_blit( src, dest, ... )
}
SDL_BlitSurface( _src, &_src_rect, _dest, &_dest_rect );
- if ( mall_sr == 1 )
- SvREFCNT_dec( s_rect_sv);
- if ( mall_dr == 1 )
- SvREFCNT_dec( d_rect_sv );
-
-
View
111 src/SDLx/Validate.h
@@ -2,63 +2,60 @@
#include <SDL.h>
#include "helper.h"
-SV *rect( SV *rect, int* new_rect_made)
+/* SV input should be a mortal SV */
+SV *create_mortal_rect( SV *rect )
{
SV *retval = NULL;
- /*we hand this over to perl to handle */
if( !SvOK(rect) )
{
+ /* create a new zero sized rectangle */
SDL_Rect* r = safemalloc( sizeof(SDL_Rect) );
- (*new_rect_made) = 1;
r->x = 0;
r->y = 0;
r->w = 0;
r->h = 0;
retval = obj2bag( sizeof( SDL_Rect *), (void *)(r), "SDL::Rect" );
+ sv_2mortal(retval) ;
}
else if( sv_derived_from(rect, "ARRAY") )
{
- SDL_Rect* r = safemalloc( sizeof(SDL_Rect) );
- (*new_rect_made) = 1;
- int ra[4];
- int i = 0;
+ /* create a new rectangle from the array */
+ SDL_Rect* r = safemalloc( sizeof(SDL_Rect) );
AV* recta = (AV*)SvRV(rect);
int len = av_len(recta);
+ int i;
+ int ra[4];
for(i = 0; i < 4; i++)
{
SV* iv = i > len ? NULL : AvARRAY(recta)[i];
- if( iv == NULL || !SvOK( iv ) || iv == &PL_sv_undef )
- ra[i] = 0;
- else
- ra[i] = SvIV( iv );
+ ra[i] = ( iv == NULL || !SvOK( iv ) || iv == &PL_sv_undef )
+ ? 0
+ : SvIV( iv );
}
r->x = ra[0]; r->y = ra[1]; r->w = ra[2]; r->h= ra[3];
retval = obj2bag( sizeof( SDL_Rect *), (void *)(r), "SDL::Rect" );
+ sv_2mortal(retval) ;
}
else if( sv_isobject(rect) && sv_derived_from(rect, "SDL::Rect") )
{
- (*new_rect_made) = 0;
+ /* we already had a good mortal rect . Just pass it along */
retval = rect;
- SvREFCNT_inc(rect);
}
else
croak("Rect must be number or arrayref or SDL::Rect or undef");
- //SvREFCNT_inc(rect);
- return retval;
+ return retval;
}
-SV *surface( SV *surface )
+void assert_surface( SV *surface )
{
if( sv_isobject(surface) && sv_derived_from(surface, "SDL::Surface"))
- {
- SvREFCNT_inc(surface);
- return surface;
- }
+ return;
+
croak("Surface must be SDL::Surface or SDLx::Surface");
- return NULL;
+ /* does not return */
}
char *_color_format( SV *color )
@@ -69,9 +66,9 @@ char *_color_format( SV *color )
else if( sv_derived_from(color, "ARRAY") )
retval = "arrayref";
else if( sv_isobject(color) && sv_derived_from(color, "SDL::Color") )
- retval = "SDLx::Color";
+ retval = "SDL::Color";
else
- croak("Color must be number or arrayref or SDLx::Color");
+ croak("Color must be number or arrayref or SDL::Color");
return retval;
}
@@ -85,19 +82,21 @@ SV *_color_number( SV *color, SV *alpha )
if( !SvOK(color) || color < 0 )
{
if( color < 0 )
- croak("Color was a negative number");
- retval = a == 1 ? 0x000000FF : 0;
+ warn("Color was a negative number");
+ retval = a == 1
+ ? 0x000000FF
+ : 0;
}
else
{
if( a == 1 && (c > 0xFFFFFFFF) )
{
- croak("Color was number greater than maximum expected: 0xFFFFFFFF");
+ warn("Color was number greater than maximum expected: 0xFFFFFFFF");
retval = 0xFFFFFFFF;
}
else if ( a != 1 && ( c > 0xFFFFFF) )
{
- croak("Color was number greater than maximum expected: 0xFFFFFF");
+ warn("Color was number greater than maximum expected: 0xFFFFFF");
retval = 0xFFFFFF;
}
}
@@ -105,6 +104,7 @@ SV *_color_number( SV *color, SV *alpha )
return newSVuv(retval);
}
+/* returns a new mortal AV* */
AV *_color_arrayref( AV *color, SV *alpha )
{
AV *retval = (AV*)sv_2mortal((SV*)newAV());
@@ -119,12 +119,12 @@ AV *_color_arrayref( AV *color, SV *alpha )
int c = SvIV(AvARRAY(color)[i]);
if( c > 0xFF )
{
- croak("Number in color arrayref was greater than maximum expected: 0xFF");
+ warn("Number in color arrayref was greater than maximum expected: 0xFF");
av_push(retval, newSVuv(0xFF));
}
else if( c < 0 )
{
- croak("Number in color arrayref was negative");
+ warn("Number in color arrayref was negative");
av_push(retval, newSVuv(0));
}
else
@@ -135,14 +135,14 @@ AV *_color_arrayref( AV *color, SV *alpha )
return retval;
}
-
+/* returns a mortal AV* */
AV* __list_rgb( SV* color )
{
char *format = _color_format(color);
- AV* RETVAL = newAV();
+ AV* RETVAL ;
if ( 0 == strcmp("number", format) )
{
- RETVAL = (AV*)sv_2mortal((SV *)RETVAL);
+ RETVAL = (AV*)sv_2mortal( (SV *) newAV() );
unsigned int _color = SvUV(sv_2mortal(_color_number(color, newSVuv(0))));
av_push(RETVAL, newSVuv(_color >> 16 & 0xFF));
av_push(RETVAL, newSVuv(_color >> 8 & 0xFF));
@@ -150,11 +150,12 @@ AV* __list_rgb( SV* color )
}
else if ( 0 == strcmp("arrayref", format) )
{
+ /* _color_arrayref returns a mortal AV* */
RETVAL = _color_arrayref((AV *)SvRV(color), sv_2mortal(newSVuv(0)));
}
- else if ( 0 == strcmp("SDLx::Color", format) )
+ else if ( 0 == strcmp("SDL::Color", format) )
{
- RETVAL = (AV*)sv_2mortal((SV *)RETVAL);
+ RETVAL = (AV*)sv_2mortal((SV *) newAV() );
SDL_Color *_color = (SDL_Color *)bag2obj(color);
av_push(RETVAL, newSVuv(_color->r));
av_push(RETVAL, newSVuv(_color->g));
@@ -162,7 +163,7 @@ AV* __list_rgb( SV* color )
}
else
{
- RETVAL = (AV*)sv_2mortal((SV *)RETVAL);
+ RETVAL = (AV*)sv_2mortal((SV *) newAV() );
av_push(RETVAL, newSVuv(0));
av_push(RETVAL, newSVuv(0));
av_push(RETVAL, newSVuv(0));
@@ -171,14 +172,13 @@ AV* __list_rgb( SV* color )
return RETVAL;
}
-
AV* __list_rgba( SV* color )
{
char *format = _color_format(color);
- AV* RETVAL = newAV();
+ AV* RETVAL ;
if ( 0 == strcmp("number", format) )
{
- RETVAL = (AV*)sv_2mortal((SV *)RETVAL);
+ RETVAL = (AV*)sv_2mortal((SV *) newAV() );
unsigned int _color = SvUV(sv_2mortal(_color_number(color, sv_2mortal(newSVuv(1)))));
av_push(RETVAL, newSVuv(_color >> 24 & 0xFF));
av_push(RETVAL, newSVuv(_color >> 16 & 0xFF));
@@ -189,9 +189,9 @@ AV* __list_rgba( SV* color )
{
RETVAL = _color_arrayref((AV *)SvRV(color), sv_2mortal(newSVuv(1)));
}
- else if ( 0 == strcmp("SDLx::Color", format) )
+ else if ( 0 == strcmp("SDL::Color", format) )
{
- RETVAL = (AV*)sv_2mortal((SV *)RETVAL);
+ RETVAL = (AV*)sv_2mortal((SV *) newAV() );
SDL_Color *_color = (SDL_Color*)bag2obj(color);
av_push(RETVAL, newSVuv(_color->r));
av_push(RETVAL, newSVuv(_color->g));
@@ -200,7 +200,7 @@ AV* __list_rgba( SV* color )
}
else
{
- RETVAL = (AV*)sv_2mortal((SV *)RETVAL);
+ RETVAL = (AV*)sv_2mortal((SV *) newAV() );
av_push(RETVAL, newSVuv(0));
av_push(RETVAL, newSVuv(0));
av_push(RETVAL, newSVuv(0));
@@ -213,24 +213,23 @@ AV* __list_rgba( SV* color )
unsigned int __map_rgb( SV* color, SDL_PixelFormat* format )
{
- Uint8 r,g,b;
- AV* a = __list_rgb( color );
- r = SvUV(*av_fetch(a, 0, 0));
- g = SvUV(*av_fetch(a, 1, 0));
- b = SvUV(*av_fetch(a, 2, 0));
-
- return SDL_MapRGB( format, r, g, b );
+ Uint8 r, g, b;
+ AV* a = __list_rgb( color );
+ r = SvUV(*av_fetch(a, 0, 0));
+ g = SvUV(*av_fetch(a, 1, 0));
+ b = SvUV(*av_fetch(a, 2, 0));
+ return SDL_MapRGB( format, r, g, b );
}
unsigned int __map_rgba( SV* color, SDL_PixelFormat* format )
{
- int r,g,b,a;
- AV* ar = __list_rgba( color );
- r = SvUV(*av_fetch(ar, 0, 0));
- g = SvUV(*av_fetch(ar, 1, 0));
- b = SvUV(*av_fetch(ar, 2, 0));
- a = SvUV(*av_fetch(ar, 3, 0));
-
- return SDL_MapRGBA( format, r, g, b, a );
+ int r, g, b, a;
+ AV* ar = __list_rgba( color );
+ r = SvUV(*av_fetch(ar, 0, 0));
+ g = SvUV(*av_fetch(ar, 1, 0));
+ b = SvUV(*av_fetch(ar, 2, 0));
+ a = SvUV(*av_fetch(ar, 3, 0));
+
+ return SDL_MapRGBA( format, r, g, b, a );
}
View
57 src/SDLx/Validate.xs
@@ -38,7 +38,7 @@ val__color_arrayref( color, ... )
CODE:
RETVAL = items > 1
? _color_arrayref( color, ST(1) )
- : _color_arrayref( color, newSVuv(0) );
+ : _color_arrayref( color, sv_2mortal(newSVuv(0)) );
OUTPUT:
RETVAL
@@ -48,17 +48,17 @@ val_num_rgb( color )
CODE:
char *format = _color_format( color );
if( 0 == strcmp("number", format) )
- RETVAL = _color_number(color, newSVuv(0));
+ RETVAL = _color_number( color, sv_2mortal(newSVuv(0)) );
else if( 0 == strcmp("arrayref", format) )
{
- AV *c = _color_arrayref( (AV *)SvRV(color), newSVuv(0) );
- unsigned int v = (( SvUV(AvARRAY(c)[0]) << 16 ) + ( SvUV(AvARRAY(c)[1]) << 8 ) + SvUV(AvARRAY(c)[2]));
- RETVAL = newSVuv(v);
+ AV *c = _color_arrayref( (AV *)SvRV(color), sv_2mortal(newSVuv(0)) );
+ unsigned int v = (( SvUV(AvARRAY(c)[0]) << 16 ) + ( SvUV(AvARRAY(c)[1]) << 8 ) + SvUV(AvARRAY(c)[2]));
+ RETVAL = newSVuv(v);
}
- else if( 0 == strcmp("SDLx::Color", format) )
+ else if( 0 == strcmp("SDL::Color", format) )
{
SDL_Color *_color = (SDL_Color*) bag2obj( color );
- unsigned int v = ( (_color->r) << 16 ) + ( (_color->g) << 8 ) + _color->b;
+ unsigned int v = ( (_color->r) << 16 ) + ( (_color->g) << 8 ) + _color->b;
RETVAL = newSVuv( v );
}
else
@@ -72,16 +72,14 @@ val_num_rgba( color )
CODE:
char *format = _color_format( color );
if( 0 == strcmp("number", format) )
- {
- RETVAL = _color_number(color, newSVuv(1));
- }
+ RETVAL = _color_number( color, sv_2mortal(newSVuv(1)) );
else if( 0 == strcmp("arrayref", format) )
{
- AV *c = _color_arrayref( (AV *)SvRV(color), newSVuv(1) );
+ AV *c = _color_arrayref( (AV *)SvRV(color), sv_2mortal(newSVuv(1)) );
unsigned int v = (SvUV(AvARRAY(c)[0]) << 24) + (SvUV(AvARRAY(c)[1]) << 16) + (SvUV(AvARRAY(c)[2]) << 8) + SvUV(AvARRAY(c)[3] );
RETVAL = newSVuv(v);
}
- else if( 0 == strcmp("SDLx::Color", format) )
+ else if( 0 == strcmp("SDL::Color", format) )
{
SDL_Color *_color = (SDL_Color*)bag2obj( color );
unsigned int v = (((_color->r) << 24) + ((_color->g) << 16) + ((_color->b) << 8) + 0xFF) ;
@@ -96,7 +94,7 @@ AV *
val_list_rgb( color )
SV *color
CODE:
- RETVAL = __list_rgb( color );
+ RETVAL = __list_rgb( color );
OUTPUT:
RETVAL
@@ -108,39 +106,36 @@ val_list_rgba( color )
OUTPUT:
RETVAL
-SV *
+void
val_rect( r )
SV* r
- CODE:
- int new_ = 0;
- RETVAL = rect( r, &new_ );
- OUTPUT:
- RETVAL
+ PPCODE:
+ ST(0) = create_mortal_rect( r );
+ XSRETURN(1);
-SV *
+void *
val_surface( s )
- SV* s
- CODE:
- RETVAL = surface(s);
- if(NULL == RETVAL)
- XSRETURN_UNDEF;
- OUTPUT:
- RETVAL
+ SV *s
+ PPCODE:
+ assert_surface(s); /* ok or dead */
+ /* ret is already mortal */
+ ST(0) = s;
+ XSRETURN(1);
SV *
val_map_rgb( color, format)
SV* color
SDL_PixelFormat * format
CODE:
- RETVAL = newSVuv( __map_rgb( color, format ) );
+ RETVAL = newSVuv( __map_rgb( color, format ) );
OUTPUT:
- RETVAL
+ RETVAL
SV *
val_map_rgba( color, format)
SV* color
SDL_PixelFormat * format
CODE:
- RETVAL = newSVuv( __map_rgba( color, format ) );
+ RETVAL = newSVuv( __map_rgba( color, format ) );
OUTPUT:
- RETVAL
+ RETVAL
View
13 src/helper.h
@@ -51,7 +51,6 @@ SV *cpy2bag( void *object, int p_size, int s_size, char *package )
void objDESTROY(SV *bag, void (* callback)(void *object))
{
-
if( sv_isobject(bag) && (SvTYPE(SvRV(bag)) == SVt_PVMG) )
{
void** pointers = (void**)(SvIV((SV*)SvRV( bag )));
@@ -88,10 +87,10 @@ SV *_sv_ref( void *object, int p_size, int s_size, char *package )
void _svinta_free(Sint16* av, int len_from_av_len)
{
- if( av == NULL)
+ if( av == NULL )
return;
safefree( av ); /* we only need to free the malloc'd array. It is one block. */
- av = NULL;
+ av = NULL;
}
Sint16* av_to_sint16 (AV* av)
@@ -115,4 +114,12 @@ Sint16* av_to_sint16 (AV* av)
return NULL;
}
+void _int_range( int *val, int min, int max )
+{
+ if( *val < min )
+ *val = min;
+ else if ( *val > max )
+ *val = max;
+}
+
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.