Results 1 to 3 of 3

Thread: Pallet rotating procedure problem

  1. #1

    Pallet rotating procedure problem

    Hi,

    I've been fiddling around with SDL and tried to find a way to rotate the palette of a surface, the code below is what i've come up with.
    it works for 8 bit surfaces when not running fullscreen, but as soon as i use it on fullscreen, it crashes !
    Oh and is this copymemory call i use the good way ? thanks

    Code:
    procedure SDL_MovePalette(Surface : PSDL_Surface; Movedown : boolean);
    var
     Pal : TSDL_ColorArray;
     Temp : TSDL_Color;
     Tel : UInt32;
    begin
     // Get the current palette from the surface
     CopyMemory(@Pal,Surface.Format.Palette.Colors,Length(pal));
     
     if Movedown then
     begin
      Temp := Pal[Surface.Format.Palette.NColors-1];
      for Tel := Surface.Format.Palette.NColors -2 downto  0  do Pal[Tel+1] := Pal[Tel];
      Pal[0] := Temp;
     end
     else
     begin
      Temp := Pal[0];
      for Tel := 0 to Surface.Format.Palette.NColors -2 do Pal[tel] := Pal[tel+1];
      Pal[Surface.Format.Palette.NColors-1] := Temp;
     end;
     SDL_SetPalette(Surface,SDL_LOGPAL or SDL_PHYSPAL,@Pal,0,Surface.Format.Palette.NColors);
    end;

  2. #2

    Pallet rotating procedure problem

    solved it myself

    here's the function i use now, in case someone ever needs it. Is the function good written ? i really have no clue, i'm happy most of the time when it works If someone has some comments please tell !

    Code:
    function SDL_movepallete(Surface : PSDL_Surface; Movedown : boolean) : boolean;
    var
     Pal : TSDL_ColorArray;
     Temp : TSDL_Color;
     Tel : integer;
    begin
    
     //check if surface has 8 bits per pixel
     if surface.format.BitsPerPixel <> 8 then
     begin
      SDL_movepallete &#58;= false;
      exit;
     end;
    
     // Get the current palette from the surface
      CopyMemory&#40;@Pal,Surface.Format.Palette.Colors,256*sizeof&#40;TSDL_Color&#41;&#41;;
    
     if Movedown then
     begin
      Temp &#58;= Pal&#91;255&#93;;
      for Tel &#58;= 254 downto  0  do Pal&#91;Tel+1&#93; &#58;= Pal&#91;Tel&#93;;
      Pal&#91;0&#93; &#58;= Temp;
     end
     else
     begin
      Temp &#58;= Pal&#91;0&#93;;
      for Tel &#58;= 0 to 254 do Pal&#91;tel&#93; &#58;= Pal&#91;tel+1&#93;;
      Pal&#91;255&#93; &#58;= Temp;
     end;
    
     //return true if the pallete has been succesfully set & rotated
     SDL_movepallete &#58;= &#40;SDL_SetPalette&#40;Surface,SDL_LOGPAL or SDL_PHYSPAL,@Pal,0,256&#41; = 1&#41;
    
    end;

  3. #3

    Pallet rotating procedure problem

    I've uploaded some example code to my website.
    The sample code covers Palette rotating and a simple fading in & fading out routine. It has 3 functions for each of these 8bit palette routines which are fun to play around with !

    u can get the example on my site (see sig)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •