Video: added Prescale filters, that pointresize to 2x-4x to allow less blur at fullscreen + hardware acceleration. Only work at 32bpp.

fix to previous commit note: not bytes, bits!
This commit is contained in:
feos-tas 2015-05-01 16:13:22 +00:00
parent 21d94f7f27
commit 81cc9062f0
4 changed files with 878 additions and 821 deletions

View File

@ -34,14 +34,13 @@ static uint32 CBM[3];
static uint32 *palettetranslate=0;
static uint16 *specbuf=NULL; // 8bpp -> 16bpp, pre hq2x/hq3x
static uint32 *specbuf32bpp = NULL; // Buffer to hold output
// of hq2x/hq3x when converting
// to 16bpp and 24bpp
static uint32 *specbuf32bpp = NULL; // Buffer to hold output of hq2x/hq3x when converting to 16bpp and 24bpp
static int backBpp, backshiftr[3], backshiftl[3];
//static uint32 backmask[3];
static uint8 *specbuf8bpp = NULL; // For 2xscale, 3xscale.
uint8 *ntscblit = NULL; // For nes_ntsc
static uint8 *ntscblit = NULL; // For nes_ntsc
static uint32 *prescalebuf = NULL; // Prescale pointresizes to 2x-4x to allow less blur at fullscreen + hardware acceleration.
static int silt;
@ -82,12 +81,10 @@ static void CalculateShift(uint32 *CBM, int *cshiftr, int *cshiftl)
int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int specfilt, int specfilteropt)
{
// -Video Modes Tag-
if(specfilt == 3) // NTSC 2x
{
int multi = (2 * 2);
//nes_ntsc variables
nes_ntsc_setup_t ntsc_setup = nes_ntsc_composite;
@ -105,14 +102,13 @@ int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int
case 3: //Monochrome
ntsc_setup = nes_ntsc_monochrome;
break;
}
nes_ntsc = (nes_ntsc_t*) FCEU_dmalloc( sizeof (nes_ntsc_t) );
if ( nes_ntsc ) {
if ( nes_ntsc )
{
nes_ntsc_init( nes_ntsc, &ntsc_setup, b, 2 );
ntscblit = (uint8*)FCEU_dmalloc(256*257*b*multi); //Need to add multiplier for larger sizes
}
@ -120,9 +116,7 @@ int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int
else if(specfilt == 2 || specfilt == 5) // scale2x and scale3x
{
int multi = ((specfilt == 2) ? 2 * 2 : 3 * 3);
specbuf8bpp = (uint8*)FCEU_dmalloc(256*240*multi); //mbg merge 7/17/06 added cast
} // -Video Modes Tag-
else if(specfilt == 1 || specfilt == 4) // hq2x and hq3x
{
@ -157,8 +151,10 @@ int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int
// End iffy code
}
// -Video Modes Tag-
if(specfilt == 1) specbuf32bpp = (uint32*)FCEU_dmalloc(256*240*4*sizeof(uint32)); //mbg merge 7/17/06 added cast
else if(specfilt == 4) specbuf32bpp = (uint32*)FCEU_dmalloc(256*240*9*sizeof(uint32)); //mbg merge 7/17/06 added cast
if(specfilt == 1)
specbuf32bpp = (uint32*)FCEU_dmalloc(256*240*4*sizeof(uint32)); //mbg merge 7/17/06 added cast
else if(specfilt == 4)
specbuf32bpp = (uint32*)FCEU_dmalloc(256*240*9*sizeof(uint32)); //mbg merge 7/17/06 added cast
}
efx=0;
@ -175,11 +171,13 @@ int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int
specbuf=(uint16*)FCEU_dmalloc(256*240*sizeof(uint16)); //mbg merge 7/17/06 added cast
}
else if (specfilt >= 6 && specfilt <= 8)
{
int multi = specfilt - 4; // magic assuming prescales are specfilt >= 6
prescalebuf = (uint32 *)FCEU_dmalloc(256*240*multi*sizeof(uint32));
}
silt = specfilt;
Bpp=b;
highefx=efx;
if(Bpp<=1 || Bpp>4)
@ -191,7 +189,8 @@ int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int
palettetranslate=(uint32 *)FCEU_dmalloc(65536*4);
else if(Bpp>=3)
palettetranslate=(uint32 *)FCEU_dmalloc(65536*4);
} else
}
else
{
if(Bpp==2)
palettetranslate=(uint32*)FCEU_dmalloc(65536*4);
@ -244,6 +243,10 @@ void KillBlitToHigh(void)
free(ntscblit);
ntscblit = NULL;
}
if (prescalebuf) {
free(prescalebuf);
prescalebuf = NULL;
}
}
@ -276,8 +279,11 @@ void SetPaletteBlitToHigh(uint8 *src)
g/=100;
b/=100;
if(r>255) r=255; if(g>255) g=255; if(b>255) b=255;
palettetranslate[x|(y<<8)]=((r>>cshiftr[0])<<cshiftl[0])|
if(r>255) r=255;
if(g>255) g=255;
if(b>255) b=255;
palettetranslate[x|(y<<8)]=
((r>>cshiftr[0])<<cshiftl[0])|
((g>>cshiftr[1])<<cshiftl[1])|
((b>>cshiftr[2])<<cshiftl[2]);
}
@ -325,7 +331,9 @@ void SetPaletteBlitToHigh(uint8 *src)
r/=100;
g/=100;
b/=100;
if(r>255) r=255; if(g>255) g=255; if(b>255) b=255;
if(r>255) r=255;
if(g>255) g=255;
if(b>255) b=255;
palettetranslate[x|(y<<8)]=(r<<cshiftl[0])|(g<<cshiftl[1])|(b<<cshiftl[2]);
}
@ -355,9 +363,7 @@ void Blit32to24(uint32 *src, uint8 *dest, int xr, int yr, int dpitch)
}
}
void Blit32to16(uint32 *src, uint16 *dest, int xr, int yr, int dpitch,
int shiftr[3], int shiftl[3])
void Blit32to16(uint32 *src, uint16 *dest, int xr, int yr, int dpitch, int shiftr[3], int shiftl[3])
{
int x,y;
//printf("%d\n",shiftl[1]);
@ -443,10 +449,8 @@ void Blit8To8(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, in
} while(--doo);
//src-=xr*(yscale-(yscale>>1));
dest+=pitch*(yscale>>1);
src+=xr;
}
}
else
{
@ -470,7 +474,6 @@ void Blit8To8(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, in
src+=xr;
}
}
}
else
{
@ -482,8 +485,7 @@ void Blit8To8(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, in
/* Todo: Make sure 24bpp code works right with big-endian cpus */
void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch,
int xscale, int yscale)
void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, int yscale)
{
int x,y;
int pinc;
@ -559,7 +561,49 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch,
}
return;
}
else if(specbuf)
else if(prescalebuf) // bare prescale
{
destbackup = dest;
dest = (uint8 *)prescalebuf;
pitchbackup = pitch;
pitch = xr*sizeof(uint32);
pinc = pitch-(xr<<2);
for(y=yr; y; y--, src+=256-xr)
{
for(x=xr; x; x--)
{
*(uint32 *)dest = palettetranslate[(uint32)*src];
dest += 4;
src++;
}
dest += pinc;
}
if (Bpp == 4) // are other modes really needed?
{
int mult = silt - 4; // magic assuming prescales are silt >= 6
uint32 *s = prescalebuf; // use 32-bit pointers ftw
uint32 *d = (uint32 *)destbackup;
for (y=0; y<yr*yscale; y++)
{
for (x=0; x<xr; x++)
{
for (int subpixel=1; subpixel<=mult; subpixel++)
{
*d++ = *s++;
if (subpixel < mult)
s--; // repeat subpixel
}
}
if (x == 256 && (y+1)%mult != 0)
s -= 256; // repeat scanline
}
}
return;
}
else if(specbuf) // hq2x/hq3x
{
destbackup=dest;
dest=(uint8 *)specbuf;
@ -571,7 +615,8 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch,
}
if(highefx&FVB_BLUR) // DONE
{
{/*
// highefx is hardset to 0 by this function call anyway
if(xscale!=1 || yscale!=1 || (highefx&FVB_SCANLINES)) // DONE
{
switch(Bpp)
@ -721,7 +766,7 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch,
dest+=pinc;
}
break;
}
}*/
}
else // No blur effects.
{
@ -732,8 +777,7 @@ void Blit8ToHigh(uint8 *src, uint8 *dest, int xr, int yr, int pitch,
case 4:
if ( nes_ntsc ) {
burst_phase ^= 1;
nes_ntsc_blit( nes_ntsc, (unsigned char*)src, xr, burst_phase,
xr, yr, ntscblit, xr * Bpp * xscale );
nes_ntsc_blit( nes_ntsc, (unsigned char*)src, xr, burst_phase, xr, yr, ntscblit, xr * Bpp * xscale );
//Multiply 4 by the multiplier on output, because it's 4 bpp
//Top 2 lines = line 3, due to distracting flicker

View File

@ -147,7 +147,7 @@ int genie = 0;
int pal_emulation = 0;
int pal_setting_specified = 0;
int dendy = 0;
bool swapDuty = 0; // some dendy models had duty cycle bits swapped
bool swapDuty = 0; // some Famicom and NES clones had duty cycle bits swapped
int ntsccol = 0, ntsctint, ntschue;
std::string BaseDirectory;
int PauseAfterLoad;

View File

@ -1394,7 +1394,7 @@ BEGIN
LTEXT "First line:",65436,367,68,40,9
LTEXT "Last line:",65435,367,84,40,9
CTEXT "NTSC",65434,413,57,27,8
CTEXT "PAL/Dendy",65433,465,57,27,8
CTEXT "PAL/Dendy",65433,455,57,48,8
EDITTEXT IDC_SCANLINE_FIRST_NTSC,414,66,27,12,ES_RIGHT
EDITTEXT IDC_SCANLINE_LAST_NTSC,414,83,27,12,ES_RIGHT
EDITTEXT IDC_SCANLINE_FIRST_PAL,465,66,27,12,ES_RIGHT
@ -1659,6 +1659,10 @@ BEGIN
BEGIN
BOTTOMMARGIN, 188
END
"VIDEOCONFIG", DIALOG
BEGIN
END
END
#endif // APSTUDIO_INVOKED

View File

@ -337,6 +337,8 @@ int SetVideoMode(int fs)
specmul = 2;
else if(winspecial >= 4 && winspecial <= 5)
specmul = 3;
else if(winspecial >= 6)
specmul = winspecial - 4; // magic assuming prescales are winspecial >= 6
else
specmul = 1;
@ -424,7 +426,8 @@ int SetVideoMode(int fs)
windowedfailed=0;
SetMainWindowStuff();
} else
}
else
{
//Following is full-screen
if(vmod == 0) // Custom mode
@ -434,6 +437,8 @@ int SetVideoMode(int fs)
specmul = 2;
else if(vmodes[0].special >= 4 && vmodes[0].special <= 5)
specmul = 3;
else if(vmodes[0].special >= 6)
specmul = vmodes[0].special - 4; // magic assuming prescales are vmodes[0].special >= 6
else
specmul = 1;
}
@ -598,6 +603,8 @@ static void BlitScreenWindow(unsigned char *XBuf)
specialmul = 2;
else if(winspecial >= 4 && winspecial <= 5)
specialmul = 3;
else if(winspecial >= 6)
specialmul = winspecial - 4; // magic assuming prescales are winspecial >= 6
else specialmul = 1;
srect.top=srect.left=0;
@ -736,6 +743,8 @@ static void BlitScreenFull(uint8 *XBuf)
specmul = 2;
else if(vmodes[0].special >= 4 && vmodes[0].special <= 5)
specmul = 3;
else if(vmodes[0].special >= 6)
specmul = vmodes[0].special - 4; // magic assuming prescales are vmodes[0].special >= 6
else
specmul = 1;
@ -1257,9 +1266,9 @@ BOOL CALLBACK VideoConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
//CheckRadioButton(hwndDlg,IDC_RADIO_SCALE,IDC_RADIO_STRETCH,(vmodes[0].flags&VMDF_STRFS)?IDC_RADIO_STRETCH:IDC_RADIO_SCALE);
// -Video Modes Tag-
char *str[]={"<none>","hq2x","Scale2x","NTSC 2x","hq3x","Scale3x"};
char *str[]={"<none>","hq2x","Scale2x","NTSC 2x","hq3x","Scale3x","Prescale2x","Prescale3x","Prescale4x"};
int x;
for(x=0;x<6;x++)
for(x=0;x<9;x++)
{
SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SCALER_FS,CB_ADDSTRING,0,(LPARAM)(LPSTR)str[x]);
SendDlgItemMessage(hwndDlg,IDC_VIDEOCONFIG_SCALER_WIN,CB_ADDSTRING,0,(LPARAM)(LPSTR)str[x]);