win32: clear extra line when doubling for blargg so that mixing does not

access random bytes (fixes #332)
This commit is contained in:
OV2 2018-06-13 14:55:38 +02:00
parent 094cb425b8
commit 6c4954c5be
1 changed files with 22 additions and 19 deletions

View File

@ -2929,23 +2929,26 @@ void RenderBlarggNTSC( SSurface Src, SSurface Dst, RECT *rect)
snes_ntsc_blit( ntsc, (unsigned short *)Src.Surface, srcRowPixels, 0,Src.Width, Src.Height, Dst.Surface, Dst.Pitch ); snes_ntsc_blit( ntsc, (unsigned short *)Src.Surface, srcRowPixels, 0,Src.Width, Src.Height, Dst.Surface, Dst.Pitch );
//Blargg's filter produces half-height output, so we have to double the height again (unless we have double height hi-res) //Blargg's filter produces half-height output, so we have to double the height again (unless we have double height hi-res)
if(Src.Height <= SNES_HEIGHT_EXTENDED) if(Src.Height <= SNES_HEIGHT_EXTENDED)
for (int y = rect->bottom / 2; --y >= 0; ) {
{ int last_blargg_line = rect->bottom / 2;
unsigned char const* in = Dst.Surface + y * Dst.Pitch; memset(Dst.Surface + last_blargg_line * Dst.Pitch, 0, Dst.Pitch);
unsigned char* out = Dst.Surface + y * 2 * Dst.Pitch; for(int y = last_blargg_line; --y >= 0; )
for (int n = rect->right; n; --n ) {
{ unsigned char const* in = Dst.Surface + y * Dst.Pitch;
unsigned prev = *(unsigned short*) in; unsigned char* out = Dst.Surface + y * 2 * Dst.Pitch;
unsigned next = *(unsigned short*) (in + Dst.Pitch); for(int n = rect->right; n; --n)
/* mix 16-bit rgb without losing low bits */ {
unsigned mixed = prev + next + ((prev ^ next) & 0x0821); unsigned prev = *(unsigned short*)in;
/* darken by 12% */ unsigned next = *(unsigned short*)(in + Dst.Pitch);
*(unsigned short*) out = prev; /* mix 16-bit rgb without losing low bits */
*(unsigned short*) (out + Dst.Pitch) = (mixed >> 1) - (mixed >> 4 & 0x18E3); unsigned mixed = prev + next + ((prev ^ next) & 0x0821);
in += 2; /* darken by 12% */
out += 2; *(unsigned short*)out = prev;
} *(unsigned short*)(out + Dst.Pitch) = (mixed >> 1) - (mixed >> 4 & 0x18E3);
} in += 2;
out += 2;
}
}
}
} }