From: Leon Brocard Date: Fri, 16 Oct 2009 09:29:18 +0000 (+0100) Subject: Expose SDL::MapRGB X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2e2fd270bb6786a1bec87b18b0c648a5ceb0991e;p=sdlgit%2FSDL_perl.git Expose SDL::MapRGB --- diff --git a/src/SDL.xs b/src/SDL.xs index 2577e40..6e07fe1 100644 --- a/src/SDL.xs +++ b/src/SDL.xs @@ -1273,6 +1273,17 @@ BlitSurface ( src, src_rect, dest, dest_rect ) OUTPUT: RETVAL +Uint32 +MapRGB ( pixel_format, r, g, b ) + SDL_PixelFormat *pixel_format + Uint8 r + Uint8 g + Uint8 b + CODE: + RETVAL = SDL_MapRGB(pixel_format,r,g,b); + OUTPUT: + RETVAL + =for comment Comment out for now as it does not compile @@ -1376,17 +1387,6 @@ all_done: RETVAL Uint32 -MapRGB ( surface, r, g, b ) - SDL_Surface *surface - Uint8 r - Uint8 g - Uint8 b - CODE: - RETVAL = SDL_MapRGB(surface->format,r,g,b); - OUTPUT: - RETVAL - -Uint32 MapRGBA ( surface, r, g, b, a ) SDL_Surface *surface Uint8 r diff --git a/t/core_surface.t b/t/core_surface.t index ab0603e..bfdf4e8 100644 --- a/t/core_surface.t +++ b/t/core_surface.t @@ -16,7 +16,7 @@ use SDL::App; use SDL::Rect; use SDL::Color; use SDL::PixelFormat; -use Test::More tests => 34; +use Test::More tests => 35; my $surface = SDL::Surface->new( SDL::SDL_ANYFORMAT(), 640, 320, 8, 0, 0, 0, 0 ); @@ -37,30 +37,33 @@ is( $image->w, 608, 'image has width' ); is( $image->h, 126, 'image has height' ); my $pixel_format = $image->format; -isa_ok($pixel_format, 'SDL::PixelFormat'); -is($pixel_format->BitsPerPixel, 24, '24 BitsPerPixel'); -is($pixel_format->BytesPerPixel, 3, '3 BytesPerPixel'); -is($pixel_format->Rloss, 0, '0 Rloss'); -is($pixel_format->Gloss, 0, '0 Gloss'); -is($pixel_format->Bloss, 0, '0 Bloss'); -is($pixel_format->Aloss, 8, '8 Aloss'); -is($pixel_format->Rshift, 0, '0 Rshift'); -is($pixel_format->Gshift, 8, '8 Gshift'); -is($pixel_format->Bshift, 16, '16 Bshift'); -is($pixel_format->Ashift, 0, '0 Ashift'); -is($pixel_format->Rmask, 255, '255 Rmask'); -is($pixel_format->Gmask, 65280, '65280 Gmask'); -is($pixel_format->Bmask, 16711680, '16711680 Bmask'); -is($pixel_format->Amask, 0, '0 Amask'); -is($pixel_format->colorkey, 0, '0 colorkey'); -is($pixel_format->alpha, 255, '255 alpha'); +isa_ok( $pixel_format, 'SDL::PixelFormat' ); +is( $pixel_format->BitsPerPixel, 24, '24 BitsPerPixel' ); +is( $pixel_format->BytesPerPixel, 3, '3 BytesPerPixel' ); +is( $pixel_format->Rloss, 0, '0 Rloss' ); +is( $pixel_format->Gloss, 0, '0 Gloss' ); +is( $pixel_format->Bloss, 0, '0 Bloss' ); +is( $pixel_format->Aloss, 8, '8 Aloss' ); +is( $pixel_format->Rshift, 0, '0 Rshift' ); +is( $pixel_format->Gshift, 8, '8 Gshift' ); +is( $pixel_format->Bshift, 16, '16 Bshift' ); +is( $pixel_format->Ashift, 0, '0 Ashift' ); +is( $pixel_format->Rmask, 255, '255 Rmask' ); +is( $pixel_format->Gmask, 65280, '65280 Gmask' ); +is( $pixel_format->Bmask, 16711680, '16711680 Bmask' ); +is( $pixel_format->Amask, 0, '0 Amask' ); +is( $pixel_format->colorkey, 0, '0 colorkey' ); +is( $pixel_format->alpha, 255, '255 alpha' ); + +my $pixel = SDL::MapRGB( $pixel_format, 255, 127, 0 ); +is( $pixel, 32767, '32767 pixel' ); $surface->fill_rect( SDL::Rect->new( 0, 0, 32, 32 ), SDL::Color->new( 200, 200, 200 ) ); ok( 1, 'Managed to fill_rect' ); my $small_rect = SDL::Rect->new( 0, 0, 64, 64 ); -SDL::BlitSurface($image, $small_rect, $surface, $small_rect ); +SDL::BlitSurface( $image, $small_rect, $surface, $small_rect ); ok( 1, 'Managed to blit' ); #my $image_format = $surface->display;