From: Leon Brocard Date: Mon, 2 Nov 2009 16:08:03 +0000 (+0000) Subject: Implement get_RGB and get_RGBA X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=27cc74e521b601eaf96cfd97b56eb32b7ca74b3e;p=sdlgit%2FSDL_perl.git Implement get_RGB and get_RGBA --- diff --git a/src/Core/Video.xs b/src/Core/Video.xs index b6bce90..8b49408 100644 --- a/src/Core/Video.xs +++ b/src/Core/Video.xs @@ -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 diff --git a/src/SDL.xs b/src/SDL.xs index d0260a6..bd939c6 100644 --- a/src/SDL.xs +++ b/src/SDL.xs @@ -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 diff --git a/t/core_video.t b/t/core_video.t index 2da9788..a0e8b0d 100644 --- a/t/core_video.t +++ b/t/core_video.t @@ -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