From: Leon Brocard Date: Fri, 16 Oct 2009 09:25:46 +0000 (+0100) Subject: Wrap PixelFormat X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=50d9130aee9a6ce88a9d0d8af2087d941d3d12e3;p=sdlgit%2FSDL_perl.git Wrap PixelFormat --- diff --git a/Build.PL b/Build.PL index 85bbabf..142b973 100644 --- a/Build.PL +++ b/Build.PL @@ -62,6 +62,13 @@ my %subsystems = }, libraries => [qw( SDL SDL_image )], }, + PixelFormat => { + file => { + from => 'src/Core/objects/PixelFormat.xs', + to => 'lib/SDL/PixelFormat.xs', + }, + libraries => [qw( SDL SDL_image )], + }, OpenGL => { file => { from => 'src/OpenGL.xs', diff --git a/MANIFEST b/MANIFEST index 50eb90d..7647b9e 100644 --- a/MANIFEST +++ b/MANIFEST @@ -19,6 +19,7 @@ lib/SDL/Music.pm lib/SDL/OpenGL.pm lib/SDL/OpenGL/Constants.pm lib/SDL/Palette.pm +lib/SDL/PixelFormat.pm lib/SDL/Rect.pm lib/SDL/SFont.pm lib/SDL/Sound.pm diff --git a/src/Core/objects/PixelFormat.xs b/src/Core/objects/PixelFormat.xs index e69de29..76ab6d1 100644 --- a/src/Core/objects/PixelFormat.xs +++ b/src/Core/objects/PixelFormat.xs @@ -0,0 +1,156 @@ +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#ifndef aTHX_ +#define aTHX_ +#endif + +#include + +MODULE = SDL::PixelFormat PACKAGE = SDL::PixelFormat PREFIX = pixelformat_ + +=for documentation + +SDL_PixelFormat -- Stores surface format information + + typedef struct SDL_PixelFormat { + SDL_Palette *palette; + Uint8 BitsPerPixel; + Uint8 BytesPerPixel; + Uint8 Rloss, Gloss, Bloss, Aloss; + Uint8 Rshift, Gshift, Bshift, Ashift; + Uint32 Rmask, Gmask, Bmask, Amask; + Uint32 colorkey; + Uint8 alpha; + } SDL_PixelFormat; + +=cut + +Uint8 +pixelformat_BitsPerPixel( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->BitsPerPixel; + OUTPUT: + RETVAL + +Uint8 +pixelformat_BytesPerPixel( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->BytesPerPixel; + OUTPUT: + RETVAL + +Uint8 +pixelformat_Rloss( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->Rloss; + OUTPUT: + RETVAL + +Uint8 +pixelformat_Bloss( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->Bloss; + OUTPUT: + RETVAL + +Uint8 +pixelformat_Gloss( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->Gloss; + OUTPUT: + RETVAL + +Uint8 +pixelformat_Aloss( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->Aloss; + OUTPUT: + RETVAL + +Uint8 +pixelformat_Rshift( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->Rshift; + OUTPUT: + RETVAL + +Uint8 +pixelformat_Bshift( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->Bshift; + OUTPUT: + RETVAL + +Uint8 +pixelformat_Gshift( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->Gshift; + OUTPUT: + RETVAL + +Uint8 +pixelformat_Ashift( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->Ashift; + OUTPUT: + RETVAL + +Uint32 +pixelformat_Rmask( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->Rmask; + OUTPUT: + RETVAL + +Uint32 +pixelformat_Bmask( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->Bmask; + OUTPUT: + RETVAL + +Uint32 +pixelformat_Gmask( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->Gmask; + OUTPUT: + RETVAL + +Uint32 +pixelformat_Amask( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->Amask; + OUTPUT: + RETVAL + +Uint32 +pixelformat_colorkey( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->colorkey; + OUTPUT: + RETVAL + +Uint8 +pixelformat_alpha( pixelformat ) + SDL_PixelFormat *pixelformat + CODE: + RETVAL = pixelformat->alpha; + OUTPUT: + RETVAL diff --git a/src/Core/objects/Surface.xs b/src/Core/objects/Surface.xs index b35484a..587ddc5 100644 --- a/src/Core/objects/Surface.xs +++ b/src/Core/objects/Surface.xs @@ -45,6 +45,15 @@ surface_new (CLASS, flags, width, height, depth, Rmask, Gmask, Bmask, Amask ) OUTPUT: RETVAL +SDL_PixelFormat * +surface_format ( surface ) + SDL_Surface *surface + CODE: + char* CLASS = "SDL::PixelFormat"; + RETVAL = surface->format; + OUTPUT: + RETVAL + int surface_fill_rect ( dest, dest_rect, color ) SDL_Surface *dest diff --git a/t/core_surface.t b/t/core_surface.t index 298a42d..ab0603e 100644 --- a/t/core_surface.t +++ b/t/core_surface.t @@ -15,7 +15,8 @@ use SDL::Surface; use SDL::App; use SDL::Rect; use SDL::Color; -use Test::More tests => 17; +use SDL::PixelFormat; +use Test::More tests => 34; my $surface = SDL::Surface->new( SDL::SDL_ANYFORMAT(), 640, 320, 8, 0, 0, 0, 0 ); @@ -35,6 +36,25 @@ my $image = SDL::IMG_Load('test/data/logo.png'); 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'); + $surface->fill_rect( SDL::Rect->new( 0, 0, 32, 32 ), SDL::Color->new( 200, 200, 200 ) ); ok( 1, 'Managed to fill_rect' ); diff --git a/typemap b/typemap index 574a878..f457b4d 100644 --- a/typemap +++ b/typemap @@ -22,7 +22,7 @@ SDL_TimerCallback T_PTR SDL_Rect * O_OBJECT SDL_Color * O_OBJECT SDL_Palette * T_PTR -SDL_PixelFormat * T_PTR +SDL_PixelFormat * O_OBJECT SDL_Cursor * T_PTR SDL_AudioSpec * T_PTR SDL_AudioCVT * T_PTR