home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ST-Computer Leser 2002 January
/
STC_CD_01_2002.iso
/
JAGUAR
/
JAG_SRC
/
SOURCE
/
COLOR.C
< prev
next >
Wrap
C/C++ Source or Header
|
2001-08-15
|
9KB
|
204 lines
////////////////////////////////////////////////////////////////////////////////
// Jagulator: Atari Jaguar Console Emulation Project (color.c)
// -----------------------------------------------------------------------------
// Jagulator is the Copyright (c) RealityMan 1998-2001 and is provided "as is"
// without any expressed or implied warranty. I have no Trademarks, Legal or
// otherwise. Atari, Jaguar and the Atari Logo are copyright Hasbro Inc. All
// other Copyrights and Trademarks are acknowledged. This project is in no way
// linked to Atari/Hasbro or other associated Atari companies.
#include "core.h"
////////////////////////////////////////////////////////////////////////////////
// Red Color Values for CrY<->RGB Color Conversion
byte redcv[16][16] = {
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
// ----------------------------------------------------------------------
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0
34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 19, 0, // 1
68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 64, 43, 21, 0, // 2
102,102,102,102,102,102,102,102,102,102,102,95, 71, 47, 23, 0, // 3
135,135,135,135,135,135,135,135,135,135,130,104,78, 52, 26, 0, // 4
169,169,169,169,169,169,169,169,169,170,141,113,85, 56, 28, 0, // 5
203,203,203,203,203,203,203,203,203,183,153,122,91, 61, 30, 0, // 6
237,237,237,237,237,237,237,237,230,197,164,131,98, 65, 32, 0, // 7
255,255,255,255,255,255,255,255,247,214,181,148,15, 82, 49, 7, // 8
255,255,255,255,255,255,255,255,255,235,204,173,143,112,81, 51, // 9
255,255,255,255,255,255,255,255,255,255,227,198,170,141,113,85, // A
255,255,255,255,255,255,255,255,255,255,249,223,197,171,145,119, // B
255,255,255,255,255,255,255,255,255,255,255,248,224,200,177,153, // C
255,255,255,255,255,255,255,255,255,255,255,255,252,230,208,187, // D
255,255,255,255,255,255,255,255,255,255,255,255,255,255,240,221, // E
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 // F
};
////////////////////////////////////////////////////////////////////////////////
// Green Color Values for CrY<->RGB Color Conversion
byte greencv[16][16] = {
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
// ----------------------------------------------------------------------
0, 17, 34, 51,68, 85, 102,119,136,153,170,187,204,221,238,255, // 0
0, 19, 38, 57,77, 96, 115,134,154,173,192,211,231,250,255,255, // 1
0, 21, 43, 64,86, 107,129,150,172,193,215,236,255,255,255,255, // 2
0, 23, 47, 71,95, 119,142,166,190,214,238,255,255,255,255,255, // 3
0, 26, 52, 78,104,130,156,182,208,234,255,255,255,255,255,255, // 4
0, 28, 56, 85,113,141,170,198,226,255,255,255,255,255,255,255, // 5
0, 30, 61, 91,122,153,183,214,244,255,255,255,255,255,255,255, // 6
0, 32, 65, 98,131,164,197,230,255,255,255,255,255,255,255,255, // 7
0, 32, 65, 98,131,164,197,230,255,255,255,255,255,255,255,255, // 8
0, 30, 61, 91,122,153,183,214,244,255,255,255,255,255,255,255, // 9
0, 28, 56, 85,113,141,170,198,226,255,255,255,255,255,255,255, // A
0, 26, 52, 78,104,130,156,182,208,234,255,255,255,255,255,255, // B
0, 23, 47, 71,95, 119,142,166,190,214,238,255,255,255,255,255, // C
0, 21, 43, 64,86, 107,129,150,172,193,215,236,255,255,255,255, // D
0, 19, 38, 57,77, 96, 115,134,154,173,192,211,231,250,255,255, // E
0, 17, 34, 51,68, 85, 102,119,136,153,170,187,204,221,238,255 // F
};
////////////////////////////////////////////////////////////////////////////////
// Blue Color Values for CrY<->RGB Color Conversion
byte bluecv[16][16] = {
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
// ----------------------------------------------------------------------
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, // 0
255,255,255,255,255,255,255,255,255,255,255,255,255,255,240,221, // 1
255,255,255,255,255,255,255,255,255,255,255,255,252,230,208,187, // 2
255,255,255,255,255,255,255,255,255,255,255,248,224,200,177,153, // 3
255,255,255,255,255,255,255,255,255,255,249,223,197,171,145,119, // 4
255,255,255,255,255,255,255,255,255,255,227,198,170,141,113,85, // 5
255,255,255,255,255,255,255,255,255,235,204,173,143,112,81, 51, // 6
255,255,255,255,255,255,255,255,247,214,181,148,115,82, 49, 17, // 7
237,237,237,237,237,237,237,237,230,197,164,131,98, 65, 32, 0, // 8
203,203,203,203,203,203,203,203,203,183,153,122,91, 61, 30, 0, // 9
169,169,169,169,169,169,169,169,169,170,141,113,85, 56, 28, 0, // A
135,135,135,135,135,135,135,135,135,135,130,104,78, 52, 26, 0, // B
102,102,102,102,102,102,102,102,102,102,102,95, 71, 47, 23, 0, // C
68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 64, 43, 21, 0, // D
34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 19, 0, // E
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // F
};
////////////////////////////////////////////////////////////////////////////////
// Globals
GLuint clut[256]; // RGBA Translation of CrY CLUT Table
////////////////////////////////////////////////////////////////////////////////
// When CrY CLUT is Updated Create a RGBA Entry in Translated CLUT
void color_ccry( unsigned addr, unsigned data )
{
dword chrm, chrl; // R,G,B Cry Color Table Coordinates
dword y; // Luminance
float r, g, b; // RGB Values
dword cli; // CLUT Index
chrm = (data & 0xF000) >> 12; // Get CrY Values
chrl = (data & 0x0F00) >> 8;
y = (data & 0x00FF);
// Calculate RGB Values
r = (((float)( redcv[chrm][chrl]) / 255 ) * y);
g = (((float)(greencv[chrm][chrl]) / 255 ) * y);
b = (((float)( bluecv[chrm][chrl]) / 255 ) * y);
// Store in Internal RGBA Color Lookup Table
if( addr >= 0xF00600 ) addr -= 0x200;
cli = (addr - 0xF00400) / 2;
clut[cli] = (dword)r;
clut[cli] |= (dword)(g) << 8;
clut[cli] |= (dword)(b) << 16;
// Make all Colors Opaque - OP Will Remove for Transparency
clut[cli] |= 0xFF000000;
#ifdef DBGCLR
print( BROWN"CLUT[%03i]: CrY(0x%04X) --> R(%03i), G(%03i), B(%03i), A(%03i)\n",
cli, data, (dword)r, (dword)g, (dword)b, (clut[cli] & 0xFF000000) >> 24 );
#endif
}
////////////////////////////////////////////////////////////////////////////////
// When RGB16 CLUT is Updated Create a RGBA Entry in Translated CLUT
void color_crgb( unsigned addr, unsigned data )
{
dword cli; // CLUT Index
static dword r, g, b; // RGB Values
r = (data & 0xF800) >> 8;
b = (data & 0x07C0) >> 3;
g = (data & 0x003F) << 2;
// Store in Internal RGBA Color Lookup Table
if( addr >= 0xF00600 ) addr -= 0x200;
cli = (addr - 0xF00400) / 2;
clut[cli] = (dword)r;
clut[cli] |= (dword)(g) << 8;
clut[cli] |= (dword)(b) << 16;
// Make all Colors Opaque - OP Will Remove for Transparency
clut[cli] |= 0xFF000000;
#ifdef DBGCLR
print( BROWN"CLUT[%03i]: RGB16(0x%04X) --> R(%03i), G(%03i), B(%03i), A(%03i)\n",
cli, data, (dword)r, (dword)g, (dword)b, (clut[cli] & 0xFF000000) >> 24 );
#endif
}
////////////////////////////////////////////////////////////////////////////////
// Convert RGB16 to RGB32
dword rgb16_rgb32( dword rgb16, int trans )
{
static dword rgb32;
static dword r, g, b; // RGB Values
r = (rgb16 & 0xF800) >> 8;
b = (rgb16 & 0x07C0) >> 3;
g = (rgb16 & 0x003F) << 2;
rgb32 = r;
rgb32 |= g << 8;
rgb32 |= b << 16;
if( !rgb32 && trans ) return( rgb32 );
rgb32 |= 0xFF000000;
return( rgb32 );
}
////////////////////////////////////////////////////////////////////////////////
// Convert CRY16 to RGB32
dword cry16_rgb32( dword cry16, int trans )
{
dword chrm, chrl; // R,G,B Cry Color Table Coordinates
dword y; // Luminance
float r, g, b; // RGB Values
dword rgb32;
chrm = (cry16 & 0xF000) >> 12; // Get CrY Values
chrl = (cry16 & 0x0F00) >> 8;
y = (cry16 & 0x00FF);
// Calculate RGB Values
r = (((float)( redcv[chrm][chrl]) / 255 ) * y);
g = (((float)(greencv[chrm][chrl]) / 255 ) * y);
b = (((float)( bluecv[chrm][chrl]) / 255 ) * y);
rgb32 = (dword)r;
rgb32 |= (dword)(g) << 8;
rgb32 |= (dword)(b) << 16;
if( !rgb32 && trans ) return( rgb32 );
rgb32 |= 0xFF000000;
return( rgb32 );
}