21 #define SQUARE(x) ((x)*(x))
23 #define NUM_BLEND_TABLES 3
38 #define LOOKUP_SIZE (64*64*64)
41 static char palette_name[128] = {
"none" };
43 static int Palman_restrict_colors = 0;
88 mprintf((
"TABLES: Unable to parse '%s'! Error message = %s.\n",
"pixels.tbl", e.what()));
112 int value = ((r/4)<<12)+((g/4)<<6)+(b/4);
122 int value = ((r/4)<<12)+((g/4)<<6)+(b/4);
158 for (i=0; i<768; i++ ) {
169 DCF(palette,
"Loads a new palette")
174 dc_printf(
"Usage: palette <filename>\nLoads the palette file.\n" );
187 int best_value, best_index,
value;
189 int is_transparent = 0;
190 if ( (r == 0) && (g==255) && (b==0) ) {
212 best_value = 1000000000;
215 int bottom_color = 0;
222 for (i=bottom_color; i<255; i++ ) {
231 if ( (best_index==-1) || (value < best_value) ) {
246 if ( best_index == -1 ) {
247 best_index = bottom_color;
274 #define PAL_ID 0x4c415056 // "LAPV" in file = VPAL (Volition Palette)
275 #define PAL_VERSION 20
276 #define PAL_LAST_COMPATIBLE_VERSION 20
326 ubyte new_palette[768];
337 mprintf((
"No cached palette file\n" ));
343 mprintf((
"Cached palette file has incorrect ID\n" ));
349 mprintf((
"Cached palette file is an older incompatible version\n" ));
354 cfread( &new_checksum, 4, 1, fp );
356 mprintf((
"Cached palette file is out of date (Checksum)\n" ));
362 if ( memcmp( new_palette,
gr_palette, 768 ) ) {
363 mprintf((
"Cached palette file is out of date (Contents)\n" ));
372 if ( fade_table_saved ) {
374 cfread( &new_gamma, 4, 1, fp );
386 if ( (num_blend_tables_saved ==
NUM_BLEND_TABLES) && (num_blend_tables_saved>0)) {
405 for (i=0; i<256; i++ ) {
407 float si, fr, fg, fb, br, bg, bb;
419 si = (( fr+fg+fb ) / (256.0
f*3.0
f)) * factor;
421 if ( factor > 1.0f ) {
443 for (j=0; j<256; j++ ) {
453 r =
fl2i( fr*Sf + br*Df );
454 g =
fl2i( fg*Sf + bg*Df );
455 b =
fl2i( fb*Sf + bb*Df );
458 if ( g > max ) max =
g;
459 if ( b > max ) max =
b;
465 if ( r > 255 ) r = 255;
else if ( r < 0 ) r = 0;
466 if ( g > 255 ) g = 255;
else if ( g < 0 ) g = 0;
467 if ( b > 255 ) b = 255;
else if ( b < 0 ) b = 0;
470 table[i*256+j] = (
unsigned char)j;
473 if ( j == 255 && ((r+g+b) < 110)) {
474 table[i*256+j] = 255;
502 Palman_restrict_colors = restrict_font_to_128;
504 strcpy_s( name, name_with_extension );
505 char *
p = strchr( name,
'.' );
521 if ( !
stricmp( name,
"none" ) ) {
549 if ( i>NUM_BLEND_TABLES-1 ) i = NUM_BLEND_TABLES-1;
551 return &palette_blend_table[i*256*256];
566 for (i = 0; i < 768; i++) {
567 sum1 += (
uint)pal[i];
568 if ( sum1 >= 255 ) sum1 -= 255;
573 return ((sum1<<8)+sum2);
int cfwrite_compressed(void *param_buf, int param_elsize, int param_nelem, CFILE *cfile)
GLfloat GLfloat GLfloat GLfloat h
float blend_table_factors[NUM_BLEND_TABLES]
int palette_cache_find(int r, int g, int b)
int Palman_num_nondarkening
int cfread(void *buf, int elsize, int nelem, CFILE *fp)
GLsizei const GLfloat * value
int cfwrite_uint(uint i, CFILE *file)
int Palman_allow_any_color
void palman_set_nondarkening(ubyte colors[MAX_NONDARK_COLORS][3], int size)
void palette_cache_clear()
int palette_fade_table_calculated
GLenum GLsizei GLenum GLenum const GLvoid * table
DCF(palette,"Loads a new palette")
GLdouble GLdouble GLdouble r
char palette_base_filename[128]
ubyte gr_fade_table[(256 *34)*2]
int palette_read_cached(char *name)
int required_string(const char *pstr)
void palette_write_cached1(char *name)
int optional_string(const char *pstr)
int cfwrite(const void *buf, int elsize, int nelem, CFILE *cfile)
bool dc_optional_string_either(const char *str1, const char *str2)
Searches for an optional string and it's alias.
int pcx_read_header(const char *real_filename, CFILE *img_cfp, int *w, int *h, int *bpp, ubyte *pal)
void read_file_text(const char *filename, int mode, char *processed_text, char *raw_text)
#define MAX_NONDARK_COLORS
uint palette_compute_checksum(ubyte *pal)
uint palette_find(int r, int g, int b)
void bm_get_palette(int handle, ubyte *pal, char *name)
Gets the palette for a given bitmap indexed by handle, and optionally the filename.
int cfwrite_int(int i, CFILE *file)
void gr_set_palette(const char *name, ubyte *palette, int restrict_font_to_128)
ubyte palette_org[256 *3]
void palette_update(const char *name_with_extension, int restrict_font_to_128)
void _cdecl void void _cdecl Error(const char *filename, int line, SCP_FORMAT_STRING const char *format,...) SCP_FORMAT_STRING_ARGS(3
uint palman_screen_signature
void reset_parse(char *text)
GLuint const GLchar * name
void dc_stuff_string_white(char *out_str, size_t maxlen)
Stuffs a whitespace delimited string to out_str from the command line, stopping at the end of the com...
ubyte palette_lookup[64 *64 *64]
GLboolean GLboolean GLboolean b
#define PAL_LAST_COMPATIBLE_VERSION
ubyte Palman_non_darkening_default[MAX_NONDARK_COLORS][3]
void palette_cache_add(int r, int g, int b, int index)
void palman_load_pixels()
void palette_use_bm_palette(int n)
void palman_create_blend_table(float factor, ubyte *table)
ubyte Palman_non_darkening[MAX_NONDARK_COLORS][3]
void palette_restore_palette()
int palman_is_nondarkening(int r, int g, int b)
An overhauled/updated debug console to allow monitoring, testing, and general debugging of new featur...
int palette_blend_table_calculated
int Palman_num_nondarkening_default
int cfread_int(CFILE *file, int ver, int deflt)
void dc_printf(const char *format,...)
Prints the given char string to the debug console.
void stuff_ubyte(ubyte *i)
int cfread_compressed(void *buf, int elsize, int nelem, CFILE *cfile)
int cfclose(CFILE *cfile)
GLclampf GLclampf GLclampf alpha
ubyte * palette_get_blend_table(float alpha)
int cfilelength(CFILE *cfile)
uint cfread_uint(CFILE *file, int ver, uint deflt)
void palette_load_table(const char *filename)