Merge pull request #371 from ClusterM/grayscale-fix
Grayscale filter fix
This commit is contained in:
commit
d5e2087ce1
|
@ -51,7 +51,6 @@
|
||||||
|
|
||||||
// GLOBALS
|
// GLOBALS
|
||||||
extern Config *g_config;
|
extern Config *g_config;
|
||||||
extern bool force_grayscale;
|
|
||||||
|
|
||||||
// STATIC GLOBALS
|
// STATIC GLOBALS
|
||||||
static int s_curbpp = 0;
|
static int s_curbpp = 0;
|
||||||
|
@ -362,22 +361,10 @@ FCEUD_SetPalette(uint8 index,
|
||||||
uint8 r,
|
uint8 r,
|
||||||
uint8 g,
|
uint8 g,
|
||||||
uint8 b)
|
uint8 b)
|
||||||
{
|
|
||||||
if ( force_grayscale )
|
|
||||||
{
|
|
||||||
// convert the palette entry to grayscale
|
|
||||||
int gray = ((float)r * 0.299 + (float)g * 0.587 + (float)b * 0.114);
|
|
||||||
|
|
||||||
s_psdl[index].r = gray;
|
|
||||||
s_psdl[index].g = gray;
|
|
||||||
s_psdl[index].b = gray;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
s_psdl[index].r = r;
|
s_psdl[index].r = r;
|
||||||
s_psdl[index].g = g;
|
s_psdl[index].g = g;
|
||||||
s_psdl[index].b = b;
|
s_psdl[index].b = b;
|
||||||
}
|
|
||||||
|
|
||||||
s_paletterefresh = 1;
|
s_paletterefresh = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,20 +114,10 @@ int RestoreDD(int w)
|
||||||
}
|
}
|
||||||
|
|
||||||
void FCEUD_SetPalette(unsigned char index, unsigned char r, unsigned char g, unsigned char b)
|
void FCEUD_SetPalette(unsigned char index, unsigned char r, unsigned char g, unsigned char b)
|
||||||
{
|
|
||||||
if (force_grayscale)
|
|
||||||
{
|
|
||||||
// convert the palette entry to grayscale
|
|
||||||
int gray = ((float)r * 0.299 + (float)g * 0.587 + (float)b * 0.114);
|
|
||||||
color_palette[index].peRed = gray;
|
|
||||||
color_palette[index].peGreen = gray;
|
|
||||||
color_palette[index].peBlue = gray;
|
|
||||||
} else
|
|
||||||
{
|
{
|
||||||
color_palette[index].peRed = r;
|
color_palette[index].peRed = r;
|
||||||
color_palette[index].peGreen = g;
|
color_palette[index].peGreen = g;
|
||||||
color_palette[index].peBlue = b;
|
color_palette[index].peBlue = b;
|
||||||
}
|
|
||||||
PaletteChanged=1;
|
PaletteChanged=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
bool force_grayscale = false;
|
bool force_grayscale = false;
|
||||||
|
pal *grayscaled_palo = NULL;
|
||||||
|
|
||||||
pal palette_game[64*8]; //custom palette for an individual game. (formerly palettei)
|
pal palette_game[64*8]; //custom palette for an individual game. (formerly palettei)
|
||||||
pal palette_user[64*8]; //user's overridden palette (formerly palettec)
|
pal palette_user[64*8]; //user's overridden palette (formerly palettec)
|
||||||
|
@ -526,6 +527,29 @@ static void ChoosePalette(void)
|
||||||
//need to calcualte a deemph on the fly.. sorry. maybe support otherwise later
|
//need to calcualte a deemph on the fly.. sorry. maybe support otherwise later
|
||||||
ApplyDeemphasisComplete(palo);
|
ApplyDeemphasisComplete(palo);
|
||||||
}
|
}
|
||||||
|
if (force_grayscale)
|
||||||
|
{
|
||||||
|
// need to apply grayscale filter
|
||||||
|
// allocate memory for grayscale palette
|
||||||
|
if (grayscaled_palo == NULL)
|
||||||
|
grayscaled_palo = (pal*)malloc(sizeof(pal) * 64 * 8);
|
||||||
|
// make every color grayscale
|
||||||
|
for (int x = 0; x < 64 * 8; x++)
|
||||||
|
{
|
||||||
|
uint8 gray = ((float)palo[x].r * 0.299 + (float)palo[x].g * 0.587 + (float)palo[x].b * 0.114);
|
||||||
|
grayscaled_palo[x].r = gray;
|
||||||
|
grayscaled_palo[x].g = gray;
|
||||||
|
grayscaled_palo[x].b = gray;
|
||||||
|
}
|
||||||
|
// apply new palette
|
||||||
|
palo = grayscaled_palo;
|
||||||
|
}
|
||||||
|
else if (grayscaled_palo != NULL)
|
||||||
|
{
|
||||||
|
// free allocated memory if the grayscale filter is not used anymore
|
||||||
|
free(grayscaled_palo);
|
||||||
|
grayscaled_palo = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WritePalette(void)
|
void WritePalette(void)
|
||||||
|
|
Loading…
Reference in New Issue