namespace BizHawk.Emulation.Cores.Nintendo.NES
{
public static class Palettes
{
static float[] rtmul = { 1.239f, 0.794f, 1.019f, 0.905f, 1.023f, 0.741f, 0.75f };
static float[] gtmul = { 0.915f, 1.086f, 0.98f, 1.026f, 0.908f, 0.987f, 0.75f };
static float[] btmul = { 0.743f, 0.882f, 0.653f, 1.277f, 0.979f, 0.101f, 0.75f };
public static void ApplyDeemphasis(ref int r, ref int g, ref int b, int deemph_bits)
{
//DEEMPH BITS MAY BE ORDERED WRONG. PLEASE CHECK
if (deemph_bits == 0) return;
int d = deemph_bits - 1;
r = (int)(r * rtmul[d]);
g = (int)(g * gtmul[d]);
b = (int)(b * btmul[d]);
if (r > 0xFF) r = 0xFF;
if (g > 0xFF) g = 0xFF;
if (b > 0xFF) b = 0xFF;
}
///
/// Loads a simple 192 byte (64 entry RGB888) or 1536 byte (64*8 = 512 entry) palette. FCEUX uses these, as do almost every NES emulator.
///
/// 192 or 1536 bytes, the contents of the palette file
public static byte[,] Load_FCEUX_Palette(byte[] fileContents)
{
int nColors;
//'validate' file, solely by length
if (fileContents.Length == 1536)
{
nColors = 512;
}
else if (fileContents.Length == 192)
{
nColors = 64;
}
else
{
return null;
}
byte[,] ret = new byte[nColors, 3];
int i = 0;
for (int c = 0; c < nColors; c++)
{
for (int z = 0; z < 3; z++)
ret[c, z] = fileContents[i++];
}
return ret;
}
const int SHIFT = 2;
public static byte[,] FCEUX_Standard = new byte[,]
{
{ 0x1D<