Implement get_RGB and get_RGBA
Leon Brocard [Mon, 2 Nov 2009 16:08:03 +0000 (16:08 +0000)]
src/Core/Video.xs
src/SDL.xs
t/core_video.t

index b6bce90..8b49408 100644 (file)
@@ -336,4 +336,31 @@ video_set_alpha ( surface, flag, alpha )
        OUTPUT:
                RETVAL
 
+AV *
+get_RGB ( pixel_format, pixel )
+       SDL_PixelFormat *pixel_format
+       Uint32 pixel
+       CODE:
+               Uint8 r,g,b;
+               SDL_GetRGB(pixel,pixel_format,&r,&g,&b);
+               RETVAL = newAV();
+               av_push(RETVAL,newSViv(r));
+               av_push(RETVAL,newSViv(g));
+               av_push(RETVAL,newSViv(b));
+       OUTPUT:
+               RETVAL
 
+AV *
+get_RGBA ( pixel_format, pixel )
+       SDL_PixelFormat *pixel_format
+       Uint32 pixel
+       CODE:
+               Uint8 r,g,b,a;
+               SDL_GetRGBA(pixel,pixel_format,&r,&g,&b,&a);
+               RETVAL = newAV();
+               av_push(RETVAL,newSViv(r));
+               av_push(RETVAL,newSViv(g));
+               av_push(RETVAL,newSViv(b));
+               av_push(RETVAL,newSViv(a));
+       OUTPUT:
+               RETVAL
index d0260a6..bd939c6 100644 (file)
@@ -1194,20 +1194,6 @@ BlitSurface ( src, src_rect, dest, dest_rect )
 Comment out for now as it does not compile
 
 AV *
-GetRGB ( surface, pixel )
-       SDL_Surface *surface
-       Uint32 pixel
-       CODE:
-               Uint8 r,g,b;
-               SDL_GetRGB(pixel,surface->format,&r,&g,&b);
-               RETVAL = newAV();
-               av_push(RETVAL,newSViv(r));
-               av_push(RETVAL,newSViv(g));
-               av_push(RETVAL,newSViv(b));
-       OUTPUT:
-               RETVAL
-
-AV *
 GetRGBA ( surface, pixel )
        SDL_Surface *surface
        Uint32 pixel
index 2da9788..a0e8b0d 100644 (file)
@@ -9,7 +9,7 @@ use Data::Dumper;
 use Test::More;
 use SDL::Rect;
 
-plan ( tests => 28);
+plan ( tests => 30);
 
 use_ok( 'SDL::Video' ); 
 
@@ -37,6 +37,8 @@ my @done =
        display_format_alpha
        set_color_key
        set_alpha
+       get_RGB
+       get_RGBA
        /;
 
 can_ok ('SDL::Video', @done); 
@@ -137,12 +139,12 @@ is(  SDL::Video::set_alpha($display, SDL_SRCALPHA, 100 ),
    0,  '[set_alpha] Returns 0 on success' 
    ) ;
 
+is_deeply(SDL::Video::get_RGB($display->format, 0), [0,0,0], '[get_RGB] returns r,g,b');
 
+is_deeply(SDL::Video::get_RGBA($display->format, 0), [0,0,0,255], '[get_RGBA] returns r,g,b,a');
 
 my @left = qw/
        get_gamma_ramp
-       get_RGB
-       get_RGBA
        load_BMP
        save_BMP
        set_clip_rect