added Notch slider to PAL filter. code is nonsense, but it appears to do the job when saturation is max and notch is ~60.

need to find a way to mix 3 colors better with bigger notch values.
This commit is contained in:
feos-tas 2015-09-17 20:47:09 +00:00
parent 52d00c97b7
commit 9e33ab76f7
5 changed files with 90 additions and 44 deletions

View File

@ -51,7 +51,8 @@ static uint8 *ntscblit = NULL; // For nes_ntsc
static uint32 *prescalebuf = NULL; // Prescale pointresizes to 2x-4x to allow less blur with hardware acceleration.
static uint32 *palrgb = NULL; // PAL filter buffer for lookup values of RGB with applied moir phases
static float *moire = NULL;
int palhue = 100;
int palsaturation = 100;
int palnotch = 0;
bool palhdtv = 0;
bool palmonochrome = 0;
bool palupdate = 1;
@ -574,7 +575,7 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
uint8 *source = (uint8 *)palettetranslate;
int16 R,G,B;
float Y,U,V;
float hue = (float) palhue/100;
float sat = (float) palsaturation/100;
bool hdtv = palhdtv;
bool monochrome = palmonochrome;
@ -614,17 +615,17 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
moire[15] = (U == 0 && V == 0) ? 1 : (Y + U)/Y;
if (monochrome)
hue = 0;
sat = 0;
for (int j=0; j<16; j++) {
if (hdtv) { // HDTV BT.709
R = Round((Y + 1.28033*V*hue)*moire[j]);
G = Round((Y - 0.21482*U*hue - 0.38059*V*hue)*moire[j]);
B = Round((Y + 2.12798*U*hue )*moire[j]);
R = Round((Y + 1.28033*V*sat)*moire[j]);
G = Round((Y - 0.21482*U*sat - 0.38059*V*sat)*moire[j]);
B = Round((Y + 2.12798*U*sat )*moire[j]);
} else { // SDTV BT.601
R = Round((Y + 1.13983*V*hue)*moire[j]);
G = Round((Y - 0.39465*U*hue - 0.58060*V*hue)*moire[j]);
B = Round((Y + 2.03211*U*hue )*moire[j]);
R = Round((Y + 1.13983*V*sat)*moire[j]);
G = Round((Y - 0.39465*U*sat - 0.58060*V*sat)*moire[j]);
B = Round((Y + 2.03211*U*sat )*moire[j]);
}
if (R > 0xff) R = 0xff; else if (R < 0) R = 0;
@ -639,14 +640,23 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
if (Bpp == 4) {
uint32 *d = (uint32 *)dest;
uint8 xsub = 0;
uint8 xabs = 0;
uint8 xsub = 0;
uint8 xabs = 0;
uint32 index = 0;
uint32 color;
uint32 lastindex = 0;
uint32 lastindex2 = 0;
uint32 color, lastcolor, lastcolor2;
int notch = palnotch;
int notch2 = notch/2;
int unnotch = 100 - palnotch;
int rmask = 0xff0000;
int gmask = 0x00ff00;
int bmask = 0x0000ff;
for (y=0; y<yr; y++) {
lastcolor = 0;
lastcolor2 = 0;
for (x=0; x<xr; x++) {
//find out which deemph bitplane value we're on
int ofs = src-XBuf;
uint8 deemph = XDBuf[ofs];
@ -654,7 +664,6 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
//get combined index from basic value and preemph bitplane
index = (*src&63) | (deemph*64);
index += 256;
src++;
for (int xsub = 0; xsub < 3; xsub++) {
@ -694,7 +703,25 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale,
}
break;
}
if (notch)
{
if (index == lastindex == lastindex2) {
int r = ((color&rmask)*unnotch + (lastcolor&rmask)*notch2 + (lastcolor2&rmask)*notch2)/100;
int g = ((color&gmask)*unnotch + (lastcolor&gmask)*notch2 + (lastcolor2&gmask)*notch2)/100;
int b = ((color&bmask)*unnotch + (lastcolor&bmask)*notch2 + (lastcolor2&bmask)*notch2)/100;
color = r&rmask | g&gmask | b&bmask;
} else {
int r = ((color&rmask)*unnotch + (lastcolor&rmask)*notch)/100;
int g = ((color&gmask)*unnotch + (lastcolor&gmask)*notch)/100;
int b = ((color&bmask)*unnotch + (lastcolor&bmask)*notch)/100;
color = r&rmask | g&gmask | b&bmask;
}
}
*d++ = color;
lastcolor2 = lastcolor;
lastcolor = color;
lastindex = index;
}
}
}

View File

@ -67,6 +67,8 @@ extern int frameSkipAmt;
extern int32 fps_scale_frameadvance;
extern bool symbDebugEnabled;
extern bool symbRegNames;
extern int palsaturation;
extern int palnotch;
extern TASEDITOR_CONFIG taseditorConfig;
extern char* recentProjectsArray[];
@ -180,6 +182,8 @@ static CFGSTRUCT fceuconfig[] =
AC(extrascanlines),
AC(overclocked),
AC(skip_7bit_overclocking),
AC(palsaturation),
AC(palnotch),
NAC("palyo",pal_emulation),
NAC("genie",genie),

View File

@ -6,9 +6,9 @@
int cpalette_count = 0;
u8 cpalette[64*8*3] = {0};
extern int palhue;
extern int palsaturation;
extern int palnotch;
extern bool palhdtv;
extern bool palprecision;
extern bool palmonochrome;
bool SetPalette(const char* nameo)
@ -68,7 +68,7 @@ int LoadPaletteFile()
**/
BOOL CALLBACK PaletteConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
char text[10];
char text[20];
switch(uMsg)
{
case WM_INITDIALOG:
@ -76,17 +76,21 @@ BOOL CALLBACK PaletteConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if(ntsccol_enable)
CheckDlgButton(hwndDlg, CHECK_PALETTE_ENABLED, BST_CHECKED);
SendDlgItemMessage(hwndDlg, CTL_TINT_TRACKBAR, TBM_SETRANGE, 1, MAKELONG(0, 128));
SendDlgItemMessage(hwndDlg, CTL_HUE_TRACKBAR, TBM_SETRANGE, 1, MAKELONG(0, 128));
SendDlgItemMessage(hwndDlg, CTL_PALHUE_TRACKBAR, TBM_SETRANGE, 1, MAKELONG(0, 200));
SendDlgItemMessage(hwndDlg, CTL_TINT_TRACKBAR, TBM_SETRANGE, 1, MAKELONG(0, 128));
SendDlgItemMessage(hwndDlg, CTL_HUE_TRACKBAR, TBM_SETRANGE, 1, MAKELONG(0, 128));
SendDlgItemMessage(hwndDlg, CTL_PALSAT_TRACKBAR, TBM_SETRANGE, 1, MAKELONG(0, 200));
SendDlgItemMessage(hwndDlg, CTL_PALNOTCH_TRACKBAR,TBM_SETRANGE, 1, MAKELONG(0, 100));
FCEUI_GetNTSCTH(&ntsctint, &ntschue);
sprintf(text, "Hue: %d%%", palhue);
SendDlgItemMessage(hwndDlg, STATIC_HUEVALUE, WM_SETTEXT, 0, (LPARAM) text);
sprintf(text, "Saturation: %d%%", palsaturation);
SendDlgItemMessage(hwndDlg, STATIC_SATVALUE, WM_SETTEXT, 0, (LPARAM) text);
sprintf(text, "Notch: %d%", palnotch);
SendDlgItemMessage(hwndDlg, STATIC_NOTCHVALUE, WM_SETTEXT, 0, (LPARAM) text);
SendDlgItemMessage(hwndDlg, CTL_TINT_TRACKBAR, TBM_SETPOS, 1, ntsctint);
SendDlgItemMessage(hwndDlg, CTL_HUE_TRACKBAR, TBM_SETPOS, 1, ntschue);
SendDlgItemMessage(hwndDlg, CTL_PALHUE_TRACKBAR, TBM_SETPOS, 1, palhue);
SendDlgItemMessage(hwndDlg, CTL_TINT_TRACKBAR, TBM_SETPOS, 1, ntsctint);
SendDlgItemMessage(hwndDlg, CTL_HUE_TRACKBAR, TBM_SETPOS, 1, ntschue);
SendDlgItemMessage(hwndDlg, CTL_PALSAT_TRACKBAR, TBM_SETPOS, 1, palsaturation);
SendDlgItemMessage(hwndDlg, CTL_PALNOTCH_TRACKBAR,TBM_SETPOS, 1, palnotch);
if(force_grayscale)
CheckDlgButton(hwndDlg, CHECK_PALETTE_GRAYSCALE, BST_CHECKED);
@ -105,12 +109,15 @@ BOOL CALLBACK PaletteConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
break;
case WM_HSCROLL:
ntsctint = SendDlgItemMessage(hwndDlg, CTL_TINT_TRACKBAR, TBM_GETPOS, 0, (LPARAM)(LPSTR)0);
ntschue = SendDlgItemMessage(hwndDlg, CTL_HUE_TRACKBAR, TBM_GETPOS, 0, (LPARAM)(LPSTR)0);
palhue = SendDlgItemMessage(hwndDlg, CTL_PALHUE_TRACKBAR, TBM_GETPOS, 0, (LPARAM)(LPSTR)0);
ntsctint = SendDlgItemMessage(hwndDlg, CTL_TINT_TRACKBAR, TBM_GETPOS, 0, (LPARAM)(LPSTR)0);
ntschue = SendDlgItemMessage(hwndDlg, CTL_HUE_TRACKBAR, TBM_GETPOS, 0, (LPARAM)(LPSTR)0);
palsaturation = SendDlgItemMessage(hwndDlg, CTL_PALSAT_TRACKBAR, TBM_GETPOS, 0, (LPARAM)(LPSTR)0);
palnotch = SendDlgItemMessage(hwndDlg, CTL_PALNOTCH_TRACKBAR,TBM_GETPOS, 0, (LPARAM)(LPSTR)0);
FCEUI_SetNTSCTH(ntsccol_enable, ntsctint, ntschue);
sprintf(text, "Hue: %d%%", palhue);
SendDlgItemMessage(hwndDlg, STATIC_HUEVALUE, WM_SETTEXT, 0, (LPARAM) text);
sprintf(text, "Saturation: %d%%", palsaturation);
SendDlgItemMessage(hwndDlg, STATIC_SATVALUE, WM_SETTEXT, 0, (LPARAM) text);
sprintf(text, "Notch: %d%", palnotch);
SendDlgItemMessage(hwndDlg, STATIC_NOTCHVALUE, WM_SETTEXT, 0, (LPARAM) text);
break;
case WM_CLOSE:
@ -138,10 +145,14 @@ BOOL CALLBACK PaletteConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
break;
case BTN_PALETTE_RESET:
palhue = 100;
SendDlgItemMessage(hwndDlg, CTL_PALHUE_TRACKBAR, TBM_SETPOS, 1, palhue);
sprintf(text, "Hue: %d%%", palhue);
SendDlgItemMessage(hwndDlg, STATIC_HUEVALUE, WM_SETTEXT, 0, (LPARAM) text);
palsaturation = 100;
SendDlgItemMessage(hwndDlg, CTL_PALSAT_TRACKBAR, TBM_SETPOS, 1, palsaturation);
sprintf(text, "Saturation: %d%%", palsaturation);
SendDlgItemMessage(hwndDlg, STATIC_SATVALUE, WM_SETTEXT, 0, (LPARAM) text);
palnotch = 0;
SendDlgItemMessage(hwndDlg, CTL_PALNOTCH_TRACKBAR, TBM_SETPOS, 1, palnotch);
sprintf(text, "Notch: %d%", palnotch);
SendDlgItemMessage(hwndDlg, STATIC_NOTCHVALUE, WM_SETTEXT, 0, (LPARAM) text);
FCEUI_SetNTSCTH(ntsccol_enable, ntsctint, ntschue);
break;

View File

@ -362,11 +362,13 @@ BEGIN
CONTROL "Force Grayscale",CHECK_PALETTE_GRAYSCALE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,19,67,85,12
CONTROL "Use Custom Palette",CHECK_PALETTE_CUSTOM,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,19,22,85,12
GROUPBOX "PAL Emulation",IDC_STATIC,10,89,208,61
CONTROL "",CTL_PALHUE_TRACKBAR,"msctls_trackbar32",WS_TABSTOP,15,111,86,15
LTEXT "Hue:",STATIC_HUEVALUE,41,102,46,8
PUSHBUTTON "Reset",BTN_PALETTE_RESET,35,128,50,14
CONTROL "Monochrome",CHECK_PALETTE_MONOCHROME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,114,101,57,10
CONTROL "HDTV Colormatrix",CHECK_PALETTE_HDTV,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,114,118,72,10
CONTROL "",CTL_PALSAT_TRACKBAR,"msctls_trackbar32",WS_TABSTOP,20,111,86,15
LTEXT "Saturation:",STATIC_SATVALUE,40,102,58,8
PUSHBUTTON "Reset",BTN_PALETTE_RESET,22,132,50,14
CONTROL "Monochrome",CHECK_PALETTE_MONOCHROME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,83,134,57,10
CONTROL "HDTV Colormatrix",CHECK_PALETTE_HDTV,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,146,135,72,10
CONTROL "",CTL_PALNOTCH_TRACKBAR,"msctls_trackbar32",WS_TABSTOP,116,110,86,15
LTEXT "Notch:",STATIC_NOTCHVALUE,142,101,46,8
LTEXT "NTSC Color Emulation overrides Internal default Palette.\nIndividual Game Palette overrides Internal+NTSC Palettes.\nCustom Palette overrides all of the above.\nPAL Emulation overrides other choices when PAL filter is selected",IDC_STATIC,10,156,208,33
END

View File

@ -763,10 +763,12 @@
#define ID_STATIC 1286
#define ID_CDL_OPTIONS 1287
#define ID_CDL_GENERATEROM 1288
#define CTL_PALHUE_TRACKBAR 1291
#define CTL_PALSAT_TRACKBAR 1291
#define CHECK_PALETTE_HDTV 1292
#define STATIC_HUEVALUE 1293
#define CB_SKIP_7BIT 1294
#define CB_SKIP_7BIT 1293
#define STATIC_SATVALUE 1294
#define CTL_PALNOTCH_TRACKBAR 1295
#define STATIC_NOTCHVALUE 1296
#define MENU_NETWORK 40040
#define MENU_PALETTE 40041
#define MENU_SOUND 40042