/* Copyright (C) 1995-2002 FSGames. Ported by Sean Ford and Yan Shosh * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // // Palette.cpp file -- holds (what else?) palette routines // // Created: 02-05-95 // /* ChangeLog buffers: 8/14/02: *added our_pal_lookup func so we don't need our.pal Zardus: 8/20/02: added return 0 for save_pallete so VC++ is happy */ #include "pal32.h" #include #include "SDL_types.h" char temppal[768]; // for loading, setting, etc. char gammapal[768]; // for gamma-correction //buffers: PORT: we need a palette to store the current palette char curpal[768]; char our_pal_lookup(int index); // // load_and_set_palette // Loads palette from file FILENAME, // stores palette info in NEWPALETTE, and // sets the current palette to this. // short load_and_set_palette(char *filename, char *newpalette) { short i; //buffers: don't need this file stuff since we use our_pal_lookup instead /* if ( (infile = fopen(filename, "rb")) == NULL ) // open for read { printf("Error in reading palette file %s\n", filename); return 0; } if (fread(temppal, 1, 768, infile) != 768 || ferror(infile)) { printf("Error: Corrupt palette file %s!\n", filename); return 0; } fclose(infile); */ // Copy back the palette info .. for (i=0; i < 768; i++) //newpalette[i] = temppal[i]; newpalette[i] = our_pal_lookup(i); //set_palette(temppal); set_palette(newpalette); return 1; } // // save_palette // save the dos palette so we can restore it when done // short save_palette(char * whatpalette) { //buffers: PORT: we don't have a palette to save :P return 0; } // // load_palette // Loads palette from file FILENAME shorto NEWPALETTE // short load_palette(char *filename, char *newpalette) { short i; /* buffers: we don't need this since we use our_pal_lookup() now if ( (infile = fopen(filename, "rb")) == NULL ) // open for read { printf("Error in reading palette file %s\n", filename); return 0; } if (fread(temppal, 1, 768, infile) != 768 || ferror(infile)) { printf("Error: Corrupt palette file %s!\n", filename); return 0; } fclose(infile); */ // Copy back the palette info .. for (i=0; i < 768; i++) //newpalette[i] = temppal[i]; newpalette[i] = our_pal_lookup(i); return 1; } // // set_palette // Sets the current palette to NEWPALETTE. // short set_palette(char *newpalette) { short i; // Copy over the palette info .. for (i=0; i < 768; i++) curpal[i] = newpalette[i]; return 1; } // // adjust_palette // Performs gamma correction (lightening/darkening) // on whichpal based on a positive or negative amount; // displays new palette, but does NOT affect whichpal // void adjust_palette(char *whichpal, short amount) { short i; short tempcol; short multiple = (short) (amount * 10); // Copy whichpal to temppal for setting .. for (i=0; i < 768; i++) { tempcol = whichpal[i]; // Now modify the current color bit based on 'amount' // Convert the 'amount' to = x*10% + x; ie, 2=(20% +2) increase tempcol = (short) ( ( ( tempcol * (100+multiple) ) / 100) + amount); if (tempcol < 0) tempcol = 0; if (tempcol > 63) tempcol = 63; // Now set the current palette index to modified bit value curpal[i] = (char) tempcol; } } // // cycle_palette // Cycle and display newpalette // void cycle_palette(char *newpalette, short start, short end, short shift) { short i; short length = (short) (end-start); short newval; short colorspot; // Copy over the palette info .. for (i=0; i < 768; i+=3) { colorspot = (short) (i/3); if ( (colorspot>= start) && (colorspot <= end) ) { newval = (short) (colorspot-shift); if (newval