Fixes for windows directx and windbi drivers on version of libsdl
[sdlgit/SDL_perl.git] / src / Core / Video.xs
index a01aa2c..a8a9a1e 100644 (file)
@@ -8,6 +8,36 @@
 
 #include <SDL.h>
 
+
+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
@@ -143,7 +173,9 @@ video_set_colors ( surface, start, ... )
        CODE:
                SDL_Color *colors,*temp;
                int i, length;
-               if ( items < 3 ) { RETVAL = 0;  goto all_done; }
+               if ( items < 3 ) { RETVAL = 0;}
+               else
+               {
                length = items - 2;
                colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
                for ( i = 0; i < length ; i++ ) {
@@ -154,9 +186,64 @@ video_set_colors ( surface, start, ... )
                }
                RETVAL = SDL_SetColors(surface, colors, start, length );
                safefree(colors);
+               }       
+
+       OUTPUT: 
+               RETVAL
+
+int
+video_set_palette ( surface, flags, start, ... )
+       SDL_Surface *surface
+       int flags
+       int start
+
+       CODE:
+               SDL_Color *colors,*temp;
+               int i, length;
+               if ( items < 4 ) { 
+               RETVAL = 0;
+                       }
+               else
+               {               
+               length = items - 3;
+               colors = (SDL_Color *)safemalloc(sizeof(SDL_Color)*(length+1));
+               for ( i = 0; i < length ; i++ ){ 
+                       temp = (SDL_Color *)SvIV(ST(i+3));
+                       colors[i].r = temp->r;
+                       colors[i].g = temp->g;
+                       colors[i].b = temp->b;
+               }
+               RETVAL = SDL_SetPalette(surface, flags, colors, start, length );
+               safefree(colors);
+               }
+       OUTPUT: 
+               RETVAL
 
-       all_done:
+int
+video_set_gamma(r, g, b)
+       float r;
+       float g;
+       float b;
+       CODE:
+               RETVAL = SDL_SetGamma(r,g,b);
        OUTPUT: 
                RETVAL
 
+       
+int
+video_set_gamma_ramp( rt, gt, bt )
+       AV* rt;
+       AV* gt;
+       AV* bt;
+       CODE:
+               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); } 
+       OUTPUT:
+               RETVAL