From 544a07bffa0bf9cd593b56b3e79a3a41f66dc1ba Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 3 Mar 2013 01:03:33 +0000 Subject: [PATCH] Move */2d/palette.c -> similar/2d/palette.c --- SConstruct | 3 +- d1x-rebirth/2d/palette.c | 222 -------------------------- {d2x-rebirth => similar}/2d/palette.c | 23 +-- 3 files changed, 14 insertions(+), 234 deletions(-) delete mode 100644 d1x-rebirth/2d/palette.c rename {d2x-rebirth => similar}/2d/palette.c (94%) diff --git a/SConstruct b/SConstruct index b9a0ca5f2..2581246a0 100644 --- a/SConstruct +++ b/SConstruct @@ -441,6 +441,7 @@ class DXXProgram(DXXCommon): objects_common = DXXCommon.create_lazy_object_property([{ 'source':[os.path.join('similar', f) for f in [ '2d/font.c', +'2d/palette.c', '2d/pcx.c', '3d/interp.c', 'arch/sdl/event.c', @@ -703,7 +704,6 @@ class D1XProgram(DXXProgram): # general source files __objects_common = DXXCommon.create_lazy_object_property([{ 'source':[os.path.join(srcdir, f) for f in [ -'2d/palette.c', 'arch/sdl/digi.c', 'arch/sdl/digi_audio.c', 'iff/iff.c', @@ -790,7 +790,6 @@ class D2XProgram(DXXProgram): # general source files __objects_common = DXXCommon.create_lazy_object_property([{ 'source':[os.path.join(srcdir, f) for f in [ -'2d/palette.c', 'arch/sdl/digi.c', 'arch/sdl/digi_audio.c', 'iff/iff.c', diff --git a/d1x-rebirth/2d/palette.c b/d1x-rebirth/2d/palette.c deleted file mode 100644 index 090413f39..000000000 --- a/d1x-rebirth/2d/palette.c +++ /dev/null @@ -1,222 +0,0 @@ -/* -THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ - -/* - * - * Graphical routines for setting the palette - * - */ - -#include -#include - -#include "physfsx.h" -#include "pstypes.h" -#include "u_mem.h" -#include "gr.h" -#include "grdef.h" -#include "dxxerror.h" -#include "fix.h" - -extern int gr_installed; - -ubyte gr_palette[256*3]; -ubyte gr_current_pal[256*3]; -ubyte gr_fade_table[256*34]; - -ubyte gr_palette_gamma = 0; -int gr_palette_gamma_param = 0; - -extern void gr_palette_load( ubyte * pal ); - -void gr_palette_set_gamma( int gamma ) -{ - if ( gamma < 0 ) gamma = 0; - if ( gamma > 16 ) gamma = 16; //was 8 - - if (gr_palette_gamma_param != gamma ) { - gr_palette_gamma_param = gamma; - gr_palette_gamma = gamma; - gr_palette_load( gr_palette ); - } -} - -int gr_palette_get_gamma() -{ - return gr_palette_gamma_param; -} - - -void gr_use_palette_table( char * filename ) -{ - PHYSFS_file *fp; - int i,fsize; - - fp = PHYSFSX_openReadBuffered( filename ); - if ( fp==NULL) - Error("Can't open palette file <%s>",filename); - - fsize = PHYSFS_fileLength( fp ); - Assert( fsize == 9472 ); - (void)fsize; - PHYSFS_read( fp, gr_palette, 256*3, 1 ); - PHYSFS_read( fp, gr_fade_table, 256*34, 1 ); - PHYSFS_close(fp); - - // This is the TRANSPARENCY COLOR - for (i=0; i> 15; - - Computed_colors[add_index].r = r; - Computed_colors[add_index].g = g; - Computed_colors[add_index].b = b; - Computed_colors[add_index].color_num = color_num; -} - -void init_computed_colors(void) -{ - int i; - - for (i=0; i 4) { - color_record trec; - trec = Computed_colors[i-1]; - Computed_colors[i-1] = Computed_colors[i]; - Computed_colors[i] = trec; - return Computed_colors[i-1].color_num; - } - return Computed_colors[i].color_num; - } - -// r &= 63; -// g &= 63; -// b &= 63; - - best_value = SQUARE(r-gr_palette[0])+SQUARE(g-gr_palette[1])+SQUARE(b-gr_palette[2]); - best_index = 0; - if (best_value==0) { - add_computed_color(r, g, b, best_index); - return best_index; - } - j=0; - // only go to 255, 'cause we dont want to check the transparent color. - for (i=1; i<254; i++ ) { - j += 3; - value = SQUARE(r-gr_palette[j])+SQUARE(g-gr_palette[j+1])+SQUARE(b-gr_palette[j+2]); - if ( value < best_value ) { - if (value==0) { - add_computed_color(r, g, b, i); - return i; - } - best_value = value; - best_index = i; - } - } - add_computed_color(r, g, b, best_index); - return best_index; -} - -int gr_find_closest_color_15bpp( int rgb ) -{ - return gr_find_closest_color( ((rgb>>10)&31)*2, ((rgb>>5)&31)*2, (rgb&31)*2 ); -} - - -int gr_find_closest_color_current( int r, int g, int b ) -{ - int i, j; - int best_value, best_index, value; - -// r &= 63; -// g &= 63; -// b &= 63; - - best_value = SQUARE(r-gr_current_pal[0])+SQUARE(g-gr_current_pal[1])+SQUARE(b-gr_current_pal[2]); - best_index = 0; - if (best_value==0) - return best_index; - - j=0; - // only go to 255, 'cause we dont want to check the transparent color. - for (i=1; i<254; i++ ) { - j += 3; - value = SQUARE(r-gr_current_pal[j])+SQUARE(g-gr_current_pal[j+1])+SQUARE(b-gr_current_pal[j+2]); - if ( value < best_value ) { - if (value==0) - return i; - best_value = value; - best_index = i; - } - } - return best_index; -} - -void gr_make_cthru_table(ubyte * table, ubyte r, ubyte g, ubyte b ) -{ - int i; - ubyte r1, g1, b1; - - for (i=0; i<256; i++ ) { - r1 = gr_palette[i*3+0] + r; - if ( r1 > 63 ) r1 = 63; - g1 = gr_palette[i*3+1] + g; - if ( g1 > 63 ) g1 = 63; - b1 = gr_palette[i*3+2] + b; - if ( b1 > 63 ) b1 = 63; - table[i] = gr_find_closest_color( r1, g1, b1 ); - } -} - diff --git a/d2x-rebirth/2d/palette.c b/similar/2d/palette.c similarity index 94% rename from d2x-rebirth/2d/palette.c rename to similar/2d/palette.c index 72485c9d3..3dc85a6d7 100644 --- a/d2x-rebirth/2d/palette.c +++ b/similar/2d/palette.c @@ -69,35 +69,34 @@ int gr_palette_get_gamma() } +#if defined(DXX_BUILD_DESCENT_II) void gr_copy_palette(ubyte *gr_palette, ubyte *pal, int size) { memcpy(gr_palette, pal, size); Num_computed_colors = 0; } - +#endif void gr_use_palette_table( char * filename ) { PHYSFS_file *fp; int i,fsize; -#ifdef SWAP_0_255 - ubyte c; -#endif fp = PHYSFSX_openReadBuffered( filename ); - +#if defined(DXX_BUILD_DESCENT_I) +#define FAILURE_FORMAT "Can't open palette file <%s>" +#elif defined(DXX_BUILD_DESCENT_II) +#define FAILURE_FORMAT "Can open neither palette file <%s> nor default palette file <" DEFAULT_LEVEL_PALETTE ">" // the following is a hack to enable the loading of d2 levels // even if only the d2 mac shareware datafiles are present. // However, if the pig file is present but the palette file isn't, // the textures in the level will look wierd... if ( fp==NULL) fp = PHYSFSX_openReadBuffered( DEFAULT_LEVEL_PALETTE ); +#endif if ( fp==NULL) - Error("Can open neither palette file <%s> " - "nor default palette file <" - DEFAULT_LEVEL_PALETTE - ">.\n", + Error(FAILURE_FORMAT, filename); fsize = PHYSFS_fileLength( fp ); @@ -111,12 +110,13 @@ void gr_use_palette_table( char * filename ) for (i=0; i