nuclear@0: /* nuclear@0: 256-color 3D graphics hack for real-mode DOS. nuclear@0: Copyright (C) 2011 John Tsiombikas nuclear@0: nuclear@0: This program is free software: you can redistribute it and/or modify nuclear@0: it under the terms of the GNU General Public License as published by nuclear@0: the Free Software Foundation, either version 3 of the License, or nuclear@0: (at your option) any later version. nuclear@0: nuclear@0: This program is distributed in the hope that it will be useful, nuclear@0: but WITHOUT ANY WARRANTY; without even the implied warranty of nuclear@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nuclear@0: GNU General Public License for more details. nuclear@0: nuclear@0: You should have received a copy of the GNU General Public License nuclear@0: along with this program. If not, see . nuclear@0: */ nuclear@0: nuclear@0: #include nuclear@0: #include "palman.h" nuclear@0: nuclear@0: #define MAX_COLORS 256 nuclear@0: static struct palm_color colors[MAX_COLORS]; nuclear@0: static int base_index[MAX_COLORS]; nuclear@0: nuclear@0: static struct palm_color pal[MAX_COLORS]; nuclear@0: static unsigned int ncol, pcol; nuclear@0: static int range; nuclear@0: nuclear@0: void palm_clear(void) nuclear@0: { nuclear@0: ncol = 0; nuclear@0: } nuclear@0: nuclear@0: int palm_add_color(unsigned char r, unsigned char g, unsigned char b) nuclear@0: { nuclear@0: if(ncol >= MAX_COLORS) { nuclear@0: return -1; nuclear@0: } nuclear@0: colors[ncol].r = r; nuclear@0: colors[ncol].g = g; nuclear@0: colors[ncol].b = b; nuclear@0: ncol++; nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: int palm_color_index(unsigned char r, unsigned char g, unsigned char b) nuclear@0: { nuclear@0: int i; nuclear@0: nuclear@0: for(i=0; i> 8); nuclear@0: pal[pcol].g = (unsigned char)(g >> 8); nuclear@0: pal[pcol].b = (unsigned char)(b >> 8); nuclear@0: pcol++; nuclear@0: r += dr; nuclear@0: g += dg; nuclear@0: b += db; nuclear@0: } nuclear@0: } nuclear@0: return pcol; nuclear@0: } nuclear@0: nuclear@0: struct palm_color *palm_palette(void) nuclear@0: { nuclear@0: return pal; nuclear@0: } nuclear@0: nuclear@0: int palm_palette_size(void) nuclear@0: { nuclear@0: return pcol; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: int palm_color_base(unsigned char r, unsigned char g, unsigned char b) nuclear@0: { nuclear@0: int c; nuclear@0: nuclear@0: if((c = palm_color_index(r, g, b)) == -1) { nuclear@0: return -1; nuclear@0: } nuclear@0: return base_index[c]; nuclear@0: } nuclear@0: nuclear@0: int palm_color_range(void) nuclear@0: { nuclear@0: return range; nuclear@0: }