Add support for 512 palette, new deepmhasis method
- Increase palette table from 256 to 1024. the 1st 256 colors are used by FCEUmm internally and for compatibility (PS2/PSP will use the old emphasis located in this area). New 512 colors with emphasis will be read from offset 256 of this palette table. - Support loading of 512 palette, this will still use the same nes.pal filename.
This commit is contained in:
committed by
LibretroAdmin
parent
ac798e1ba4
commit
f72dac45e8
119
src/palette.c
119
src/palette.c
@@ -34,15 +34,18 @@
|
||||
#include "palettes/palettes.h"
|
||||
|
||||
/* These are dynamically filled/generated palettes: */
|
||||
pal palettei[64]; /* Custom palette for an individual game. */
|
||||
pal palettec[64]; /* Custom "global" palette. */
|
||||
static pal palette_game[512]; /* Custom palette for an individual game. */
|
||||
static pal palette_user[512]; /* Custom "global" palette. */
|
||||
|
||||
uint8 palette_game_available = false;
|
||||
uint8 palette_user_available = false;
|
||||
|
||||
static void ChoosePalette(void);
|
||||
static void WritePalette(void);
|
||||
uint8 pale = 0;
|
||||
uint8 default_palette_selected = 0;
|
||||
|
||||
pal *palo;
|
||||
static pal *palpoint[8] =
|
||||
static pal *default_palette[8] =
|
||||
{
|
||||
palette,
|
||||
rp2c04_0001,
|
||||
@@ -52,16 +55,57 @@ static pal *palpoint[8] =
|
||||
rp2c03,
|
||||
};
|
||||
|
||||
void FCEUI_SetPaletteArray(uint8 *pal) {
|
||||
if (!pal)
|
||||
palpoint[0] = palette;
|
||||
static void ApplyDeemphasisClassic(int entry, uint8 *r, uint8 *g, uint8 *b) {
|
||||
static const float rtmul[] = { 1.239f, 0.794f, 1.019f, 0.905f, 1.023f, 0.741f, 0.75f };
|
||||
static const float gtmul[] = { 0.915f, 1.086f, 0.98f, 1.026f, 0.908f, 0.987f, 0.75f };
|
||||
static const float btmul[] = { 0.743f, 0.882f, 0.653f, 1.277f, 0.979f, 0.101f, 0.75f };
|
||||
|
||||
int nr, ng, nb, d;
|
||||
int deemph_bits = entry >> 6;
|
||||
|
||||
if (deemph_bits == 0) return;
|
||||
|
||||
d = deemph_bits - 1;
|
||||
nr = *r;
|
||||
ng = *g;
|
||||
nb = *b;
|
||||
nr = (int)(nr * rtmul[d]);
|
||||
ng = (int)(ng * gtmul[d]);
|
||||
nb = (int)(nb * btmul[d]);
|
||||
if (nr > 0xFF) nr = 0xFF;
|
||||
if (ng > 0xFF) ng = 0xFF;
|
||||
if (nb > 0xFF) nb = 0xFF;
|
||||
*r = (uint8)nr;
|
||||
*g = (uint8)ng;
|
||||
*b = (uint8)nb;
|
||||
}
|
||||
|
||||
static void ApplyDeemphasisComplete(pal *pal512) {
|
||||
int i, p, idx;
|
||||
|
||||
/* for each deemph level beyond 0 */
|
||||
for (i = 0, idx = 0; i < 8; i++) {
|
||||
/* for each palette entry */
|
||||
for (p = 0; p < 64; p++, idx++) {
|
||||
pal512[idx] = pal512[p];
|
||||
ApplyDeemphasisClassic(idx, &pal512[idx].r, &pal512[idx].g, &pal512[idx].b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FCEUI_SetPaletteArray(uint8 *pal, int nEntries) {
|
||||
if (!pal || !nEntries)
|
||||
palette_user_available = false;
|
||||
else {
|
||||
int x;
|
||||
palpoint[0] = palettec;
|
||||
for (x = 0; x < 64; x++) {
|
||||
palpoint[0][x].r = *((uint8*)pal + x + x + x);
|
||||
palpoint[0][x].g = *((uint8*)pal + x + x + x + 1);
|
||||
palpoint[0][x].b = *((uint8*)pal + x + x + x + 2);
|
||||
palette_user_available = true;
|
||||
for (x = 0; x < nEntries; x++) {
|
||||
palette_user[x].r = *((uint8*)pal + x + x + x);
|
||||
palette_user[x].g = *((uint8*)pal + x + x + x + 1);
|
||||
palette_user[x].b = *((uint8*)pal + x + x + x + 2);
|
||||
}
|
||||
if (nEntries != 512) {
|
||||
ApplyDeemphasisComplete(palette_user);
|
||||
}
|
||||
}
|
||||
FCEU_ResetPalette();
|
||||
@@ -124,14 +168,12 @@ void SetNESDeemph(uint8 d, int force) {
|
||||
lastd = d;
|
||||
}
|
||||
|
||||
int ipalette = 0;
|
||||
|
||||
void FCEU_LoadGamePalette(void) {
|
||||
uint8 ptmp[192];
|
||||
uint8 ptmp[64 * 8 * 3];
|
||||
RFILE *fp = NULL;
|
||||
char *fn = NULL;
|
||||
|
||||
ipalette = 0;
|
||||
palette_game_available = false;
|
||||
|
||||
fn = FCEU_MakeFName(FCEUMKF_PALETTE, 0, 0);
|
||||
|
||||
@@ -142,14 +184,18 @@ void FCEU_LoadGamePalette(void) {
|
||||
|
||||
if (fp) {
|
||||
int x;
|
||||
filestream_read(fp, ptmp, 192);
|
||||
int ssize = filestream_get_size(fp);
|
||||
int nEntries = ssize / 3;
|
||||
filestream_read(fp, ptmp, nEntries);
|
||||
filestream_close(fp);
|
||||
for (x = 0; x < 64; x++) {
|
||||
palettei[x].r = ptmp[x + x + x];
|
||||
palettei[x].g = ptmp[x + x + x + 1];
|
||||
palettei[x].b = ptmp[x + x + x + 2];
|
||||
palette_game[x].r = ptmp[x + x + x];
|
||||
palette_game[x].g = ptmp[x + x + x + 1];
|
||||
palette_game[x].b = ptmp[x + x + x + 2];
|
||||
}
|
||||
ipalette = 1;
|
||||
if (nEntries != 512)
|
||||
ApplyDeemphasisComplete(palette_game);
|
||||
palette_game_available = true;
|
||||
}
|
||||
free(fn);
|
||||
}
|
||||
@@ -162,23 +208,30 @@ void FCEU_ResetPalette(void) {
|
||||
}
|
||||
|
||||
static void ChoosePalette(void) {
|
||||
if (GameInfo->type == GIT_NSF)
|
||||
palo = 0;
|
||||
else if (ipalette)
|
||||
palo = palettei;
|
||||
else
|
||||
palo = palpoint[pale];
|
||||
if (GameInfo->type == GIT_NSF) {
|
||||
palo = default_palette[0];
|
||||
} else if (palette_user_available) {
|
||||
palo = palette_user;
|
||||
} else if (palette_game_available) {
|
||||
palo = palette_game;
|
||||
} else {
|
||||
palo = default_palette[default_palette_selected];
|
||||
ApplyDeemphasisComplete(palo);
|
||||
}
|
||||
}
|
||||
|
||||
void WritePalette(void) {
|
||||
int x;
|
||||
int unvaried = sizeof(unvpalette) / sizeof(unvpalette[0]);
|
||||
|
||||
for (x = 0; x < 7; x++)
|
||||
for (x = 0; x < unvaried; x++)
|
||||
FCEUD_SetPalette(x, unvpalette[x].r, unvpalette[x].g, unvpalette[x].b);
|
||||
if (GameInfo->type == GIT_NSF) {
|
||||
} else {
|
||||
for (x = 0; x < 64; x++)
|
||||
FCEUD_SetPalette(128 + x, palo[x].r, palo[x].g, palo[x].b);
|
||||
SetNESDeemph(lastd, 1);
|
||||
for (x = unvaried; x < 256; x++)
|
||||
FCEUD_SetPalette(x, 205, 205, 205);
|
||||
for (x = 0; x < 64; x++)
|
||||
FCEUD_SetPalette(128 + x, palo[x].r, palo[x].g, palo[x].b);
|
||||
SetNESDeemph(lastd, 1);
|
||||
for (x = 0; x < 512; x++) {
|
||||
FCEUD_SetPalette(256 + x, palo[x].r, palo[x].g, palo[x].b);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user