Pal set

From Bennu Wiki
Jump to navigation Jump to search


INT pal_set ( [<INT paletteID>] , <INT first_color> , <INT num_colors> , <POINTER palette_data>)


Changes the color palette of an 8 bit (256 color) graphic, with the palette that is loaded with Pal_load(). This palette can also be loaded from MAP's, FPG's, FNT's and other image formats, provided that they are 8 bit images. Unlike Pal_map_assign(), the change is not immediately visible, and the function Pal_refresh() has to be called afterwards to make the change visible. The difference however, is that it not replaces the whole palette, but allows a specified number of colors to be changed, so it's a bit more flexible.

Also called colors_set(). The previous name set_colors() is deprecated.


INT paletteID - The handle of the color palette loaded with Pal_load(). This paramter is optional.
INT first_color - The first color number of the palette. This doesn't necessarily have be the first color.
INT num_colors - The number of colors you want to replace, wich counts from the first_color to the num_colors. See notes.
POINTER palette_data - Pointer (Offset) to an array with the color values, that where obtained with Pal_get().


The maximum number of colors cannot be bigger the 255. The num_colors starts counting from first_color, so if the first_color is 7, and num_colors is 7, the color value's 7-13 are changed. So logically, the value num_colors can only be 255 when first_color is 0. This range gives you all the colors. To be safe, the formula for the number of colors to modified is: num_colors-first_color.

I.e. num_colors: 55 - first_color: 4 = 51 colors are changed, the range from color index 4 up to color index 55.


INT : Error.

0 - Error: could not open file; corrupt or truncated file; file doesn't contain palette information.
1 - No error: palette was set with success.


/* original bennupack example FROM: \2 Medium\fenix test\palettes\rbear8-2.prg (from bomberlink) */

/* this program demonstrates the use of the functions: pal_load(), pal_clone(), pal_get(),       */
/* pal_map_assign(), pal_set() and pal_refresh().                                                */

IMPORT "mod_debug";
IMPORT "mod_say";
IMPORT "mod_map";
IMPORT "mod_key";
IMPORT "mod_video";
IMPORT "mod_text";

   // palette identifiers
   int pal_orange;
   int pal_green;
   int pal_normal;
   int status1;
   int status2;
   // identifier of the fpg archive
   int fpg_id;
   // arrays for the data of the two color palettes.
   byte pal_orange_data[255]; 
   byte pal_green_data[255];  
   int map_count;

PROCESS main();


    set_mode(320,200,16);  // we use a 16 bit color mode

    // load two color palettes and duplicate one
    // pal_clone (int pal_id);
    pal_normal=pal_clone(pal_orange); // duplicate palette, i.e. make a copy of it.

    // load the fpg file

    write(0,10,20,0,"F1/F2 - change palette");

    x = 160;
    y = 120;

    // pal_get (int pal_id, int start_color, int num_colors, pointer pal_data);
    pal_get(pal_green,7,7,&pal_green_data);    // get colors 7 - 13 and store them in the array

    FROM map_count=1 TO 102; // there are 102 frames in the animation
        // pal_map_assign (int fileid, int graph, int pal_id);
        pal_map_assign(fpg_id,map_count,pal_normal); // assign the "normal (original source)" color 
                                                     // palette that we duplicated earlier.

    WHILE (NOT key(_ESC))
        FROM graph=1 TO 13;
            IF (key(_F1))
                say("switched to green palette");
                // pal_set (int pal_id, int start_color, int num_colors, pointer pal_data);
                status1=pal_set(pal_normal,7,7,&pal_green_data); // change colors 7 - 13 in the "normal" 
                                                                 // palette, by using the values from the
                                                                 // "green" color palette.

                say("pal_set_status: "+status1);                                                                 
                // pal_refresh (int pal_id);
                status2=pal_refresh(pal_normal); // apply the modified color palette to the graphics.
                                                 // this function is required to make the change visible.  

                say("pal_refresh_status: "+status2);                                                   

                // conclusion: the difference between pal_map_assign() and pal_set() is that pal_map_assign()
                // works immediately, and that pal_set() requires the palette to be refreshed to make the 
                // change visible.                
            IF (key(_F2))
                say("switched to orange palette");
                pal_set(pal_normal,7,7,&pal_orange_data);  // colors 7 - 13
            IF (key(_ESC)) 


Used in example: Pal_load(), pal_clone(), Pal_get(), Pal_map_assign(), Pal_refresh(), Say(), Set_fps(), Set_mode(), Write(), Write_int()

Functions Bdfload()Centerset()Colorfind()Colorsget()Colorsset()Fade()Fadeoff()Fadeon()Fntload()Fntnew()Fntsave()Fntunload()Fpgadd()Fpgdel()Fpgexists()Fpgload()Fpgnew()Fpgsave()Fpgunload()Getpixel()Glyphget()Glyphset()Graphicinfo()Graphicset()Mapblockcopy()Mapbuffer()Mapclear()Mapclone()Mapdel()Mapexists()Mapgetpixel()Mapinfo()Mapinfoget()Mapinfoset()Mapload()Mapname()Mapnew()Mapput()Mapputpixel()Mapsave()Mapsetname()Mapunload()Mapxput()Mapxputnp()Palclone()Paldel()Palget()Palload()Palmapassign()Palmapgetid()Palmapremove()Palnew()Palrefresh()Palsave()Palset()Palunload()Paletteconvert()Paletteroll()Pcxload()Pngload()Pngsave()Pointget()Pointset()Putpixel()Rgb()Rgbget()Rgba()Rgbaget()