From: Kartik Thakore Date: Wed, 28 Oct 2009 18:30:19 +0000 (-0400) Subject: Finished set_gamma_ramp! 30% for SDL::Video X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7b7e80171a75879620d43efd52a2cf1ab3810f2b;p=sdlgit%2FSDL_perl.git Finished set_gamma_ramp! 30% for SDL::Video --- diff --git a/src/Core/Video.xs b/src/Core/Video.xs index 14a0b28..2f6797c 100644 --- a/src/Core/Video.xs +++ b/src/Core/Video.xs @@ -8,6 +8,36 @@ #include + +static Uint16* av_to_uint16 (AV* av) +{ + int len = av_len(av); + if( len != -1) + { + int i; + Uint16* table = (Uint16 *)safemalloc(sizeof(Uint16)*(len)); + //fprintf( stderr, "Expecting 1,2,5,6 \n Length is %d \n", len); + for ( i = 0; i < len+1 ; i++ ){ + SV ** temp = av_fetch(av,i,0); + if( temp != NULL) + { + table[i] = (Uint16 *) SvIV( *temp ) ; + /* fprintf( stderr, "table[%d] = ", i); + if (table[i] == NULL) { fprintf ( stderr, " NULL\n"); } + else{ fprintf(stderr, " %d \n", table[i]); } */ + } + else { table[i] =0; } + + } +// warn("Got %d %d %d %d \n", table[0], table[1], table[2], table[3] ); + + return table; + } + return NULL; +} + + + MODULE = SDL::Video PACKAGE = SDL::Video PREFIX = video_ =for documentation @@ -199,6 +229,7 @@ video_set_gamma(r, g, b) OUTPUT: RETVAL + int video_set_gamma_ramp( rt, gt, bt ) @@ -206,26 +237,16 @@ video_set_gamma_ramp( rt, gt, bt ) AV* gt; AV* bt; CODE: - Uint16 *redtable, *greentable, *bluetable, *temp; - int srt = av_len(rt); - int sgt = av_len(gt); - int sbt = av_len(bt); - int i; - if( srt == -1 ) - { - redtable = NULL; - } - else - { - redtable = (Uint16 *)safemalloc(sizeof(Uint16)*(srt+1)); - for ( i = 0; i < srt ; i++ ){ - temp = (Uint16 *)ST(i); - redtable[i] = *temp; - } + Uint16 *redtable, *greentable, *bluetable; + redtable = av_to_uint16(rt); + greentable = av_to_uint16(gt); + bluetable = av_to_uint16(bt); + RETVAL = SDL_SetGammaRamp(redtable, greentable, bluetable); + if( redtable != NULL) { safefree(redtable); } + if( greentable != NULL) { safefree(greentable); } + if( bluetable != NULL) { safefree(bluetable); } + - } - - RETVAL = SDL_SetGammaRamp(redtable, NULL, NULL); OUTPUT: RETVAL diff --git a/t/core_video.t b/t/core_video.t index 3159925..f9a132e 100644 --- a/t/core_video.t +++ b/t/core_video.t @@ -27,6 +27,7 @@ my @done = set_colors set_palette set_gamma + set_gamma_ramp /; can_ok ('SDL::Video', @done); @@ -76,9 +77,8 @@ $value = SDL::Video::set_palette($display, SDL_LOGPAL|SDL_PHYSPAL, 0); is( $value , 0, '[set_palette] returns 0 trying to write to 32 bit surface' ); -my @redtable = (0,0,0,0); - -SDL::Video::set_gamma_ramp( \@redtable , [0,1,2,3], [2,3,4,5]); pass '[set_gamma_ramp] ran'; +my $zero = [0,0,0,0]; +SDL::Video::set_gamma_ramp($zero, $zero, $zero); pass '[set_gamma_ramp] ran'; SDL::Video::set_gamma( 1.0, 1.0, 1.0 ); pass '[set_gamma] ran '; @@ -114,7 +114,6 @@ is( $value , 1, '[set_palette] returns 1' ); my @left = qw/ get_gamma_ramp - set_gmmma_ramp map_RGB map_RGBA get_RGB