2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Palman/PalMan.cpp $
15 * Palette manager routines
18 * Revision 1.5 2005/10/01 22:04:58 taylor
19 * fix FS1 (de)briefing voices, the directory names are different in FS1
20 * hard code the table values so that the fs1.vp file isn't needed
21 * hard code a mission fix for sm2-08a since a have no idea how to fix it otherwise
22 * generally cleanup some FS1 code
23 * fix volume sliders in the options screen that never went all the way up
25 * Revision 1.4 2004/07/04 11:39:06 taylor
26 * fix missing debrief text, crash on exit, path separator's, warning fixes, no GR_SOFT
28 * Revision 1.3 2002/06/09 04:41:25 relnev
29 * added copyright header
31 * Revision 1.2 2002/05/07 03:16:48 theoddone33
32 * The Great Newline Fix
34 * Revision 1.1.1.1 2002/05/03 03:28:10 root
38 * 5 3/31/99 8:24p Dave
39 * Beefed up all kinds of stuff, incluging beam weapons, nebula effects
40 * and background nebulae. Added per-ship non-dimming pixel colors.
42 * 4 2/05/99 12:52p Dave
43 * Fixed Glide nondarkening textures.
45 * 3 2/03/99 6:06p Dave
46 * Groundwork for FS2 PXO usertracker support. Gametracker support next.
48 * 2 10/07/98 10:53a Dave
51 * 1 10/07/98 10:50a Dave
53 * 55 5/20/98 9:46p John
54 * added code so the places in code that change half the palette don't
55 * have to clear the screen.
57 * 54 5/16/98 4:37p John
59 * 53 5/16/98 4:34p John
60 * fixed bug where only colors divisible by 4 would work.
62 * 52 5/15/98 3:28p John
63 * fixed bug with blue nondarkening colors
65 * 51 5/14/98 3:38p John
66 * Added in more non-darkening colors for Adam. Had to fix some bugs in
67 * BmpMan and Ani stuff to get this to work.
69 * 50 5/13/98 10:22p John
70 * Added cfile functions to read/write rle compressed blocks of data.
71 * Made palman use it for .clr files. Made alphacolors calculate on the
72 * fly rather than caching to/from disk.
74 * 49 4/30/98 4:53p John
75 * Restructured and cleaned up cfile code. Added capability to read off
76 * of CD-ROM drive and out of multiple pack files.
78 * 48 4/20/98 4:44p John
79 * Fixed problems with black being xparent on model cache rneders. Made
80 * model cache key off of detail level setting and framerate.
82 * 47 4/15/98 5:44p John
83 * Made no colors except green map to 0,255,0
85 * 46 4/09/98 11:04p John
86 * Changed ID's in output files to make more sense.
88 * 45 4/01/98 5:35p John
89 * Made only the used POFs page in for a level. Reduced some interp
90 * arrays. Made custom detail level work differently.
92 * 44 3/25/98 8:08p John
93 * Restructured software rendering into two modules; One for windowed
94 * debug mode and one for DirectX fullscreen.
96 * 43 3/24/98 3:58p John
97 * Put in (hopefully) final gamma setting code.
99 * 42 2/24/98 1:59p John
100 * Made fade table use a gamma
102 * 41 1/29/98 8:18a John
103 * Put in some commented out hooks for RGB lighting
105 * 40 1/19/98 6:15p John
106 * Fixed all my Optimized Build compiler warnings
108 * 39 1/10/98 1:14p John
109 * Added explanation to debug console commands
111 * 38 12/21/97 4:33p John
112 * Made debug console functions a class that registers itself
113 * automatically, so you don't need to add the function to
114 * debugfunctions.cpp.
116 * 37 12/17/97 5:11p John
117 * Added brightening back into fade table. Added code for doing the fast
118 * dynamic gun flashes and thruster flashes.
120 * 36 12/17/97 1:16p John
121 * Made bright white not fade.
123 * 35 12/03/97 4:48p Adam
124 * JOHN: Made engine glow scale, made thrust blend be additive.
126 * 34 12/02/97 4:00p John
127 * Added first rev of thruster glow, along with variable levels of
128 * translucency, which retquired some restructing of palman.
130 * 33 11/22/97 1:05p John
131 * added back in reverse palette lookup table.
133 * 32 11/21/97 1:32p John
134 * made palette caching work on game palette better.
136 * 31 11/21/97 11:32a John
137 * Added nebulas. Fixed some warpout bugs.
139 * 30 11/14/97 12:31p John
140 * Fixed some DirectX bugs. Moved the 8-16 xlat tables into Graphics
141 * libs. Made 16-bpp DirectX modes know what bitmap format they're in.
143 * 29 10/31/97 10:48a John
144 * upped clr version to force rebuild after changing palette code.
146 * 28 10/14/97 8:08a John
147 * added a bunch more 16 bit support
149 * 27 10/03/97 9:10a John
150 * added better antialiased line drawer
152 * 26 9/20/97 8:16a John
153 * Made .clr files go into the Cache directory. Replaced cfopen(name,NULL)
154 * to delete a file with cf_delete.
156 * 25 9/09/97 3:39p Sandeep
157 * warning level 4 bugs
159 * 24 7/28/97 5:08p John
160 * changed the color blending calculations.
162 * 23 7/17/97 11:37a John
163 * made the fullscreen and windowed use separate palette cache files.
165 * 22 7/16/97 5:29p John
166 * added palette table caching and made scaler and liner no light tmapper
167 * do alpha blending in 8 bpp mode.
169 * 21 7/16/97 3:07p John
171 * 20 7/10/97 2:06p John
172 * added code to specify alphablending type for bitmaps.
174 * 19 6/11/97 6:00p John
175 * sped up alpha matching a bit.
177 * 18 6/11/97 5:49p John
178 * Changed palette code to only recalculate alphacolors when needed, not
179 * when palette changes.
181 * 17 6/11/97 1:13p John
182 * Started fixing all the text colors in the game.
184 * 16 5/21/97 11:06a Lawrance
185 * added user_palette_find()
187 * 15 5/14/97 10:53a John
188 * fixed some discrepencies between d3d and software palette setting.
190 * 14 5/12/97 12:27p John
191 * Restructured Graphics Library to add support for multiple renderers.
193 * 13 4/10/97 4:47p John
194 * used .3R .5G .1B for color matching. Made palette brightening not be
197 * 12 4/08/97 5:18p John
198 * First rev of decent (dynamic, correct) lighting in FreeSpace.
200 * 11 11/26/96 6:50p John
201 * Added some more hicolor primitives. Made windowed mode run as current
202 * bpp, if bpp is 8,16,or 32.
204 * 10 11/26/96 2:53p Allender
205 * simplify restore palette code
207 * 9 11/26/96 9:44a Allender
208 * allow for use of different bitmap palettes
218 #include "pcxutils.h"
220 #include "grinternal.h"
222 #define SQUARE(x) ((x)*(x))
224 #define NUM_BLEND_TABLES 3
225 float blend_table_factors[NUM_BLEND_TABLES] = { 0.5f, 1.0f, 1.2f };
227 ubyte palette_org[256*3];
228 ubyte gr_palette[256*3];
229 ubyte gr_fade_table[(256*34)*2];
230 static ubyte palette_blend_table[NUM_BLEND_TABLES*256*256];
232 int palette_blend_table_calculated = 0;
233 int palette_fade_table_calculated = 0;
235 uint gr_palette_checksum = 0;
237 uint palman_screen_signature = 0;
239 #define LOOKUP_SIZE (64*64*64)
240 ubyte palette_lookup[64*64*64];
242 static char palette_name[128] = { "none" };
244 static int Palman_restrict_colors = 0;
246 //extern ubyte palette_org[256*3];
248 int Palman_num_nondarkening_default = 0;
249 ubyte Palman_non_darkening_default[MAX_NONDARK_COLORS][3];
251 int Palman_num_nondarkening = 0;
252 ubyte Palman_non_darkening[MAX_NONDARK_COLORS][3];
254 int palman_is_nondarkening(int r,int g, int b)
258 for (i=0; i<Palman_num_nondarkening; i++ ) {
259 if ( (r==Palman_non_darkening[i][0]) && (g==Palman_non_darkening[i][1]) && (b==Palman_non_darkening[i][2]) ) {
266 void palman_load_pixels()
271 read_file_text("pixels.tbl");
275 while(!optional_string("#END")){
276 // nondarkening pixel
277 if(required_string("+ND")){
278 stuff_byte(&Palman_non_darkening_default[Palman_num_nondarkening_default][0]);
279 stuff_byte(&Palman_non_darkening_default[Palman_num_nondarkening_default][1]);
280 stuff_byte(&Palman_non_darkening_default[Palman_num_nondarkening_default++][2]);
283 } catch (parse_error_t rval) {
284 Error(LOCATION, "Unable to parse pixels.tbl! Code = %i.\n", (int)rval);
288 // hard-coded FS1 values
289 Palman_non_darkening_default[Palman_num_nondarkening_default][0] = 255;
290 Palman_non_darkening_default[Palman_num_nondarkening_default][1] = 255;
291 Palman_non_darkening_default[Palman_num_nondarkening_default++][2] = 255;
293 Palman_non_darkening_default[Palman_num_nondarkening_default][0] = 41;
294 Palman_non_darkening_default[Palman_num_nondarkening_default][1] = 41;
295 Palman_non_darkening_default[Palman_num_nondarkening_default++][2] = 255;
297 Palman_non_darkening_default[Palman_num_nondarkening_default][0] = 255;
298 Palman_non_darkening_default[Palman_num_nondarkening_default][1] = 0;
299 Palman_non_darkening_default[Palman_num_nondarkening_default++][2] = 0;
301 Palman_non_darkening_default[Palman_num_nondarkening_default][0] = 0;
302 Palman_non_darkening_default[Palman_num_nondarkening_default][1] = 255;
303 Palman_non_darkening_default[Palman_num_nondarkening_default++][2] = 0;
305 Palman_non_darkening_default[Palman_num_nondarkening_default][0] = 255;
306 Palman_non_darkening_default[Palman_num_nondarkening_default][1] = 244;
307 Palman_non_darkening_default[Palman_num_nondarkening_default++][2] = 126;
310 // set this to be the active table
311 palman_set_nondarkening(Palman_non_darkening_default, Palman_num_nondarkening_default);
314 void palman_set_nondarkening(ubyte colors[MAX_NONDARK_COLORS][3], int size)
316 // if we're supposed to use the passed table
317 memcpy(Palman_non_darkening, colors, MAX_NONDARK_COLORS * 3);
318 Palman_num_nondarkening = size;
321 void palette_cache_clear()
325 for (i=0; i<LOOKUP_SIZE; i++ ) {
326 palette_lookup[i] = 255;
330 int palette_cache_find( int r, int g, int b )
332 if ( !palman_is_nondarkening(r,g,b)) {
333 int value = ((r/4)<<12)+((g/4)<<6)+(b/4);
334 if ( palette_lookup[value] != 255 ) {
335 return palette_lookup[value];
341 void palette_cache_add( int r, int g, int b, int index )
343 int value = ((r/4)<<12)+((g/4)<<6)+(b/4);
345 if ( !palman_is_nondarkening(r,g,b)) {
346 palette_lookup[value] = (ubyte)index;
350 char palette_base_filename[128] = { "default" };
351 int palette_base_loaded = 0;
353 void palette_load_table( const char * filename )
359 SDL_strlcpy( palette_base_filename, filename, SDL_arraysize(palette_base_filename) );
360 char * p = SDL_strchr(palette_base_filename,'.');
365 pcx_error = pcx_read_header(palette_base_filename, &w, &h, palette_org );
366 if ( pcx_error != PCX_ERROR_NONE ) {
367 // Read the old .256 file
370 fp = cfopen( palette_base_filename, "rb" );
372 Error( LOCATION, "Can't open palette file <%s>",palette_base_filename);
374 fsize = cfilelength( fp );
375 SDL_assert( fsize == 9472 );
376 cfread( palette_org, 256*3, 1, fp );
379 for (i=0; i<768; i++ ) {
380 palette_org[i] = ubyte((palette_org[i]*255)/63);
384 palette_base_loaded = 1;
386 gr_set_palette(palette_base_filename, palette_org);
390 DCF(palette,"Loads a new palette")
393 dc_get_arg(ARG_STRING|ARG_NONE);
394 if ( Dc_arg_type == ARG_NONE ) {
396 palette_load_table( Dc_arg );
400 dc_printf( "Usage: palette filename\nLoads the palette file.\n" );
405 int Palman_allow_any_color = 0;
408 uint palette_find( int r, int g, int b )
411 int best_value, best_index, value;
413 int is_transparent = 0;
414 if ( (r == 0) && (g==255) && (b==0) ) {
419 if ( Palman_restrict_colors && (!Palman_allow_any_color) ) {
423 // int rgb = ((r/4)<<12)+((g/4)<<6)+(b/4);
425 i = palette_cache_find(r,g,b);
436 best_value = 1000000000;
439 int bottom_color = 0;
446 for (i=bottom_color; i<255; i++ ) {
450 pg = gr_palette[j+1];
451 pb = gr_palette[j+2];
453 value = SQUARE(r-pr) + SQUARE(g-pg) + SQUARE(b-pb);
455 if ( (best_index==-1) || (value < best_value) ) {
456 // Don't map anything to 0,255,0 (transparent) ever, except 0,255,0
458 palette_cache_add( r, g, b, i );
461 // Not an exact match, so don't let anything map to a nondarkening color.
462 if ( (!is_transparent) && (!palman_is_nondarkening( pr, pg, pb )) ) {
470 if ( best_index == -1 ) {
471 best_index = bottom_color;
474 palette_cache_add( r, g, b, best_index );
478 // version 0 - initial revision
479 // version 2 - changed 16-bpp fade table to include the 1.5 brightening factor
480 // version 3 - changed to put black in color 0 all the time
481 // version 4 - took out all truecolor lookup tables
482 // version 5 - changed palette to use 254 entries for nebula, made color mapping different
483 // version 6 - took out 1.5 brightness
484 // version 7 - added blending tables
485 // version 8 - made glows use additive blending
486 // version 9 - made 255,255,255 not fade
487 // version 10 - made fade table go to white again for anything l above 0.75.
488 // version 11 - made fade table go from 0-1 instead of 0-0.75
489 // version 12 - added variable gamma
490 // version 13 - Reduced blending tables from 5 to 3. Save 128KB RAM.
491 // version 14 - made palette never map anything to green.
492 // version 15 - made green blending with anything be black
493 // version 16 - added compression
494 // version 17 - added more nondarkening colors
495 // version 18 - fixed bug with blue nondarkening colors
496 // version 19 - fixed bug where only colors divisible by 4 got used.
497 // version 20 - added flag to only use lower 128 colors for palette.
498 #define PAL_ID 0x4c415056 // LAPV, VPAL (Volition Palette)
499 #define PAL_VERSION 20
500 #define PAL_LAST_COMPATIBLE_VERSION 20
502 void palette_write_cached1( const char *name )
507 SDL_strlcpy( new_name, name, SDL_arraysize(new_name) );
508 SDL_strlcat( new_name, ".clr", SDL_arraysize(new_name) );
510 // mprintf(( "Writing palette cache file '%s'\n", new_name ));
512 fp = cfopen( new_name, "wb", CFILE_NORMAL, CF_TYPE_CACHE );
515 cfwrite_uint( PAL_ID, fp );
516 cfwrite_int(PAL_VERSION, fp );
517 cfwrite( &gr_palette_checksum, 4, 1, fp );
519 cfwrite_compressed( &gr_palette, 256*3, 1, fp ); // < 1 KB
521 cfwrite_compressed( &palette_lookup, LOOKUP_SIZE, 1, fp ); // 256KB
523 if ( palette_fade_table_calculated ) {
525 cfwrite_int(Gr_gamma_int,fp);
526 cfwrite_compressed( &gr_fade_table, 256*34*2, 1, fp ); // 17KB
531 if ( palette_blend_table_calculated ) {
532 cfwrite_int(NUM_BLEND_TABLES,fp);
533 cfwrite_compressed( &palette_blend_table, 256*256, NUM_BLEND_TABLES, fp ); //64KB*
539 // mprintf(( "Done.\n" ));
542 // Returns TRUE if successful, else 0
544 int palette_read_cached( const char *name )
549 uint id, new_checksum;
550 ubyte new_palette[768];
552 SDL_strlcpy( new_name, name, SDL_arraysize(new_name) );
553 SDL_strlcat( new_name, ".clr", SDL_arraysize(new_name) );
555 // mprintf(( "Reading palette '%s'\n", name ));
557 fp = cfopen( new_name, "rb", CFILE_NORMAL, CF_TYPE_CACHE );
559 // Couldn't find file
561 mprintf(( "No cached palette file\n" ));
565 id = cfread_uint( fp );
566 if ( id != PAL_ID ) {
567 mprintf(( "Cached palette file has incorrect ID\n" ));
571 version = cfread_int( fp );
572 if ( version < PAL_LAST_COMPATIBLE_VERSION ) {
573 mprintf(( "Cached palette file is an older incompatible version\n" ));
578 cfread( &new_checksum, 4, 1, fp );
579 if ( gr_palette_checksum != new_checksum ) {
580 mprintf(( "Cached palette file is out of date (Checksum)\n" ));
585 cfread_compressed( &new_palette, 256*3, 1, fp );
586 if ( memcmp( new_palette, gr_palette, 768 ) ) {
587 mprintf(( "Cached palette file is out of date (Contents)\n" ));
592 cfread_compressed( &palette_lookup, LOOKUP_SIZE, 1, fp ); // 256KB
594 int fade_table_saved = cfread_int(fp);
596 if ( fade_table_saved ) {
598 cfread( &new_gamma, 4, 1, fp );
599 cfread_compressed( &gr_fade_table, 256*34*2, 1, fp ); // 17KB
600 if ( new_gamma == Gr_gamma_int ) {
601 palette_fade_table_calculated = 1;
603 palette_fade_table_calculated = 0;
606 palette_fade_table_calculated = 0;
609 int num_blend_tables_saved = cfread_int(fp);
610 if ( (num_blend_tables_saved == NUM_BLEND_TABLES) && (num_blend_tables_saved>0)) {
611 palette_blend_table_calculated = 1;
612 cfread_compressed( &palette_blend_table, 256*256, NUM_BLEND_TABLES, fp ); //64KB*
614 palette_blend_table_calculated = 0;
619 // mprintf(( "Done.\n" ));
624 void palman_create_blend_table(float factor, ubyte *table)
628 // Make the blending table
629 for (i=0; i<256; i++ ) {
631 float si, fr, fg, fb, br, bg, bb;
634 fr = i2fl(gr_palette[i*3+0]);
635 fg = i2fl(gr_palette[i*3+1]);
636 fb = i2fl(gr_palette[i*3+2]);
638 // Make everything blended with Xparent be black
643 si = (( fr+fg+fb ) / (256.0f*3.0f)) * factor;
645 if ( factor > 1.0f ) {
667 for (j=0; j<256; j++ ) {
668 br = i2fl(gr_palette[j*3+0]);
669 bg = i2fl(gr_palette[j*3+1]);
670 bb = i2fl(gr_palette[j*3+2]);
672 // Make all things on top of Xparent be black
677 r = fl2i( fr*Sf + br*Df );
678 g = fl2i( fg*Sf + bg*Df );
679 b = fl2i( fb*Sf + bb*Df );
682 if ( g > max ) max = g;
683 if ( b > max ) max = b;
689 if ( r > 255 ) r = 255; else if ( r < 0 ) r = 0;
690 if ( g > 255 ) g = 255; else if ( g < 0 ) g = 0;
691 if ( b > 255 ) b = 255; else if ( b < 0 ) b = 0;
694 table[i*256+j] = (unsigned char)j;
696 // If background transparent, and color isn't bright, call it transparent.
697 if ( j == 255 && ((r+g+b) < 110)) {
698 table[i*256+j] = 255;
700 table[i*256+j] = (unsigned char)palette_find(r,g,b);
709 // DB 2/3/99 - I think this was causing some wacky unhandled exceptions at game shutdown. Since we don't use palettes anymore.....
711 if ( SDL_strcasecmp( palette_name, "none" ) ) {
712 palette_write_cached1( palette_name );
718 // When gr_set_palette is called, it fills in gr_palette and then calls this
719 // function, which should update all the tables.
720 // Pass NULL to flush current palette.
721 void palette_update(const char *name_with_extension, int restrict_font_to_128)
727 Palman_restrict_colors = restrict_font_to_128;
729 // mprintf(( "<<<<<<<<< PALETTE UPDATE (%s) >>>>>>>>>>>\n", (name_with_extension?name_with_extension:"null") ));
731 SDL_strlcpy( name, name_with_extension, SDL_arraysize(name) );
732 char *p = SDL_strchr( name, '.' );
735 SDL_strlcpy( palette_name, name, SDL_arraysize(palette_name) );
737 tmp_checksum = palette_compute_checksum( gr_palette );
738 if ( tmp_checksum == gr_palette_checksum ) return;
740 gr_palette_checksum = tmp_checksum;
742 // Clear the lookup cache, since the palette has changed
743 palette_cache_clear();
744 palette_blend_table_calculated = 0;
745 palette_fade_table_calculated = 0;
747 // For "none" palettes, don't calculate tables
748 if ( !SDL_strcasecmp( name, "none" ) ) {
749 bm_update(); // update the bitmap palette's
753 // Read in the cached info if there is any.
754 if ( palette_read_cached( name ) ) {
755 bm_update(); // update the bitmap palette's
759 bm_update(); // update the bitmap palette's
762 ubyte *palette_get_fade_table()
766 if ( palman_screen_signature != gr_screen.signature ) {
767 palman_screen_signature = gr_screen.signature;
768 palette_fade_table_calculated = 0;
772 if ( !palette_fade_table_calculated ) {
773 //mprintf(( "Creating fading table..." ));
775 for (i=0; i<256; i++ ) {
778 r = gr_palette[i*3+0];
779 g = gr_palette[i*3+1];
780 b = gr_palette[i*3+2];
782 if ( palman_is_nondarkening(r,g,b)) {
783 // Make pure white not fade
784 for (l=0; l<32; l++ ) {
785 gr_fade_table[((l+1)*256)+i] = (unsigned char)i;
788 for (l=0; l<32; l++ ) {
791 float f = (float)pow(i2fl(l)/23.0f, 1.0f/Gr_gamma);
792 ur = fl2i(i2fl(r)*f); if ( ur > 255 ) ur = 255;
793 ug = fl2i(i2fl(g)*f); if ( ug > 255 ) ug = 255;
794 ub = fl2i(i2fl(b)*f); if ( ub > 255 ) ub = 255;
803 x = l-24; // x goes from 0 to 7
804 y = 31-l; // y goes from 7 to 0
806 ur = ((gr*x)+(r*y))/7; if ( ur > 255 ) ur = 255;
807 ug = ((gg*x)+(g*y))/7; if ( ug > 255 ) ug = 255;
808 ub = ((gb*x)+(b*y))/7; if ( ub > 255 ) ub = 255;
810 gr_fade_table[((l+1)*256)+i] = (unsigned char)palette_find( ur, ug, ub );
814 gr_fade_table[ (0*256)+i ] = gr_fade_table[ (1*256)+i ];
815 gr_fade_table[ (33*256)+i ] = gr_fade_table[ (32*256)+i ];
818 // Mirror the fade table
819 for (i=0; i<34; i++ ) {
820 for ( l = 0; l < 256; l++ ) {
821 gr_fade_table[ ((67-i)*256)+l ] = gr_fade_table[ (i*256)+l ];
825 // mprintf(( "done\n" ));
826 palette_fade_table_calculated = 1;
829 return &gr_fade_table[0];
833 ubyte *palette_get_blend_table(float alpha)
837 if ( !palette_blend_table_calculated ) {
838 // mprintf(( "Creating blending table..." ));
839 for (i=0; i<NUM_BLEND_TABLES; i++ ) {
840 palman_create_blend_table(blend_table_factors[i], &palette_blend_table[i*256*256] );
842 // mprintf(( "done\n" ));
843 palette_blend_table_calculated = 1;
846 for (i=0; i<NUM_BLEND_TABLES; i++ ) {
847 if ( alpha <= blend_table_factors[i] )
851 if ( i>NUM_BLEND_TABLES-1 ) i = NUM_BLEND_TABLES-1;
853 return &palette_blend_table[i*256*256];
858 // compute a simple checksum on the given palette. Used by the bitmap manager
859 // to determine if we need to reload a new palette for a bitmap. Code liberally
860 // stolen from descent networking checksum code
861 uint palette_compute_checksum( ubyte *pal )
868 for (i = 0; i < 768; i++) {
869 sum1 += (uint)pal[i];
870 if ( sum1 >= 255 ) sum1 -= 255;
875 return ((sum1<<8)+sum2);
878 // this function takes a bitmap number and sets the game palette to the palette of this
880 void palette_use_bm_palette(int n)
885 bm_get_palette(n, tmp, name, SDL_arraysize(name)); // get the palette for this bitmap
887 gr_set_palette(name, tmp); // load the new palette.
890 void palette_restore_palette()
893 memcpy(tmp, palette_org, 3*256);
895 if ( palette_base_loaded ) {
896 gr_set_palette(palette_base_filename, tmp);