Implement load_BMP and save_BMP
Leon Brocard [Mon, 2 Nov 2009 16:17:53 +0000 (16:17 +0000)]
src/Core/Video.xs
src/SDL.xs
t/core_video.t

index 8b49408..b6af462 100644 (file)
@@ -364,3 +364,22 @@ get_RGBA ( pixel_format, pixel )
                av_push(RETVAL,newSViv(a));
        OUTPUT:
                RETVAL
+
+SDL_Surface*
+load_BMP ( filename )
+       char *filename
+       PREINIT:
+               char* CLASS = "SDL::Surface";
+       CODE:
+               RETVAL = SDL_LoadBMP(filename);
+       OUTPUT:
+               RETVAL
+
+int
+save_BMP ( surface, filename )
+       SDL_Surface *surface
+       char *filename
+       CODE:
+               RETVAL = SDL_SaveBMP(surface,filename);
+       OUTPUT:
+               RETVAL
index ccfa83c..d96bb7a 100644 (file)
@@ -1193,16 +1193,6 @@ BlitSurface ( src, src_rect, dest, dest_rect )
 
 Comment out for now as it does not compile
 
-
-int
-SaveBMP ( surface, filename )
-       SDL_Surface *surface
-       char *filename
-       CODE:
-               RETVAL = SDL_SaveBMP(surface,filename);
-       OUTPUT:
-               RETVAL  
-
 SDL_Surface*
 ConvertRGB ( surface )
        SDL_Surface * surface
index a0e8b0d..eadce44 100644 (file)
@@ -9,7 +9,7 @@ use Data::Dumper;
 use Test::More;
 use SDL::Rect;
 
-plan ( tests => 30);
+plan ( tests => 32);
 
 use_ok( 'SDL::Video' ); 
 
@@ -39,6 +39,8 @@ my @done =
        set_alpha
        get_RGB
        get_RGBA
+       load_BMP
+       save_BMP
        /;
 
 can_ok ('SDL::Video', @done); 
@@ -143,10 +145,16 @@ is_deeply(SDL::Video::get_RGB($display->format, 0), [0,0,0], '[get_RGB] returns
 
 is_deeply(SDL::Video::get_RGBA($display->format, 0), [0,0,0,255], '[get_RGBA] returns r,g,b,a');
 
+my $bmp = 't/core_video.bmp';
+unlink($bmp) if -f $bmp;
+SDL::Video::save_BMP($display, $bmp);
+ok(-f $bmp, '[save_BMP] creates a file');
+my $bmp_surface = SDL::Video::load_BMP($bmp);
+isa_ok($bmp_surface, 'SDL::Surface', '[load_BMP] returns an SDL::Surface');
+unlink($bmp) if -f $bmp;
+
 my @left = qw/
        get_gamma_ramp
-       load_BMP
-       save_BMP
        set_clip_rect
        get_clip_rect
        blit_surface