Add blend filters in blit.cpp

This commit is contained in:
zones 2011-02-24 21:22:19 +09:00
parent b65f18fa84
commit 41dc2fbb61
8 changed files with 7267 additions and 7176 deletions

View File

@ -181,11 +181,12 @@
#define ALL_COLOR_MASK (FIRST_COLOR_MASK | SECOND_COLOR_MASK | THIRD_COLOR_MASK) #define ALL_COLOR_MASK (FIRST_COLOR_MASK | SECOND_COLOR_MASK | THIRD_COLOR_MASK)
#ifdef GFX_MULTI_FORMAT #ifdef GFX_MULTI_FORMAT
static uint16 lowPixelMask = 0, qlowPixelMask = 0; static uint16 lowPixelMask = 0, qlowPixelMask = 0, highBitsMask = 0;
static uint32 colorMask = 0; static uint32 colorMask = 0;
#else #else
#define lowPixelMask (RGB_LOW_BITS_MASK) #define lowPixelMask (RGB_LOW_BITS_MASK)
#define qlowPixelMask ((RGB_HI_BITS_MASK >> 3) | TWO_LOW_BITS_MASK) #define qlowPixelMask ((RGB_HI_BITS_MASK >> 3) | TWO_LOW_BITS_MASK)
#define highBitsMask (ALL_COLOR_MASK & RGB_REMOVE_LOW_BITS_MASK)
#define colorMask (((~RGB_HI_BITS_MASK & ALL_COLOR_MASK) << 16) | (~RGB_HI_BITS_MASK & ALL_COLOR_MASK)) #define colorMask (((~RGB_HI_BITS_MASK & ALL_COLOR_MASK) << 16) | (~RGB_HI_BITS_MASK & ALL_COLOR_MASK))
#endif #endif
@ -204,6 +205,7 @@ bool8 S9xBlitFilterInit (void)
#ifdef GFX_MULTI_FORMAT #ifdef GFX_MULTI_FORMAT
lowPixelMask = RGB_LOW_BITS_MASK; lowPixelMask = RGB_LOW_BITS_MASK;
qlowPixelMask = (RGB_HI_BITS_MASK >> 3) | TWO_LOW_BITS_MASK; qlowPixelMask = (RGB_HI_BITS_MASK >> 3) | TWO_LOW_BITS_MASK;
highBitsMask = ALL_COLOR_MASK & RGB_REMOVE_LOW_BITS_MASK;
colorMask = ((~RGB_HI_BITS_MASK & ALL_COLOR_MASK) << 16) | (~RGB_HI_BITS_MASK & ALL_COLOR_MASK); colorMask = ((~RGB_HI_BITS_MASK & ALL_COLOR_MASK) << 16) | (~RGB_HI_BITS_MASK & ALL_COLOR_MASK);
#endif #endif
@ -252,7 +254,7 @@ void S9xBlitNTSCFilterSet (const snes_ntsc_setup_t *setup)
snes_ntsc_init(ntsc, setup); snes_ntsc_init(ntsc, setup);
} }
void S9xBlitPixSmall16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height) void S9xBlitPixSimple1x1 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height)
{ {
width <<= 1; width <<= 1;
@ -264,7 +266,41 @@ void S9xBlitPixSmall16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRo
} }
} }
void S9xBlitPixScaled16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height) void S9xBlitPixSimple1x2 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height)
{
width <<= 1;
for (; height; height--)
{
memcpy(dstPtr, srcPtr, width);
dstPtr += dstRowBytes;
memcpy(dstPtr, srcPtr, width);
srcPtr += srcRowBytes;
dstPtr += dstRowBytes;
}
}
void S9xBlitPixSimple2x1 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height)
{
for (; height; height--)
{
uint16 *dP = (uint16 *) dstPtr, *bP = (uint16 *) srcPtr;
for (int i = 0; i < (width >> 1); i++)
{
*dP++ = *bP;
*dP++ = *bP++;
*dP++ = *bP;
*dP++ = *bP++;
}
srcPtr += srcRowBytes;
dstPtr += dstRowBytes;
}
}
void S9xBlitPixSimple2x2 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height)
{ {
uint8 *dstPtr2 = dstPtr + dstRowBytes, *deltaPtr = XDelta; uint8 *dstPtr2 = dstPtr + dstRowBytes, *deltaPtr = XDelta;
dstRowBytes <<= 1; dstRowBytes <<= 1;
@ -313,30 +349,24 @@ void S9xBlitPixScaled16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstR
} }
} }
void S9xBlitPixHiRes16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height) void S9xBlitPixBlend1x1 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height)
{
width <<= 1;
for (; height; height--)
{
memcpy(dstPtr, srcPtr, width);
dstPtr += dstRowBytes;
memcpy(dstPtr, srcPtr, width);
srcPtr += srcRowBytes;
dstPtr += dstRowBytes;
}
}
void S9xBlitPixDoubled16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height)
{ {
for (; height; height--) for (; height; height--)
{ {
uint16 *dP = (uint16 *) dstPtr, *bP = (uint16 *) srcPtr; uint16 *dP = (uint16 *) dstPtr, *bP = (uint16 *) srcPtr;
uint16 prev, curr;
for (int i = 0; i < width; i++) prev = *bP;
for (int i = 0; i < (width >> 1); i++)
{ {
*dP++ = *bP; curr = *bP++;
*dP++ = *bP++; *dP++ = (prev & curr) + (((prev ^ curr) & highBitsMask) >> 1);
prev = curr;
curr = *bP++;
*dP++ = (prev & curr) + (((prev ^ curr) & highBitsMask) >> 1);
prev = curr;
} }
srcPtr += srcRowBytes; srcPtr += srcRowBytes;
@ -344,7 +374,58 @@ void S9xBlitPixDoubled16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dst
} }
} }
void S9xBlitPixScaledTV16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height) void S9xBlitPixBlend2x1 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height)
{
for (; height; height--)
{
uint16 *dP = (uint16 *) dstPtr, *bP = (uint16 *) srcPtr;
uint16 prev, curr;
prev = *bP;
for (int i = 0; i < (width >> 1); i++)
{
curr = *bP++;
*dP++ = (prev & curr) + (((prev ^ curr) & highBitsMask) >> 1);
*dP++ = curr;
prev = curr;
curr = *bP++;
*dP++ = (prev & curr) + (((prev ^ curr) & highBitsMask) >> 1);
*dP++ = curr;
prev = curr;
}
srcPtr += srcRowBytes;
dstPtr += dstRowBytes;
}
}
void S9xBlitPixTV1x2 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height)
{
uint8 *dstPtr2 = dstPtr + dstRowBytes;
dstRowBytes <<= 1;
for (; height; height--)
{
uint32 *dP1 = (uint32 *) dstPtr, *dP2 = (uint32 *) dstPtr2, *bP = (uint32 *) srcPtr;
uint32 product, darkened;
for (int i = 0; i < (width >> 1); i++)
{
product = *dP1++ = *bP++;
darkened = (product = (product >> 1) & colorMask);
darkened += (product = (product >> 1) & colorMask);
*dP2++ = darkened;
}
srcPtr += srcRowBytes;
dstPtr += dstRowBytes;
dstPtr2 += dstRowBytes;
}
}
void S9xBlitPixTV2x2 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height)
{ {
uint8 *dstPtr2 = dstPtr + dstRowBytes, *deltaPtr = XDelta; uint8 *dstPtr2 = dstPtr + dstRowBytes, *deltaPtr = XDelta;
dstRowBytes <<= 1; dstRowBytes <<= 1;
@ -455,31 +536,7 @@ void S9xBlitPixScaledTV16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int ds
} }
} }
void S9xBlitPixHiResTV16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height) void S9xBlitPixMixedTV1x2 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height)
{
uint8 *dstPtr2 = dstPtr + dstRowBytes;
dstRowBytes <<= 1;
for (; height; height--)
{
uint32 *dP1 = (uint32 *) dstPtr, *dP2 = (uint32 *) dstPtr2, *bP = (uint32 *) srcPtr;
uint32 product, darkened;
for (int i = 0; i < (width >> 1); i++)
{
product = *dP1++ = *bP++;
darkened = (product = (product >> 1) & colorMask);
darkened += (product = (product >> 1) & colorMask);
*dP2++ = darkened;
}
srcPtr += srcRowBytes;
dstPtr += dstRowBytes;
dstPtr2 += dstRowBytes;
}
}
void S9xBlitPixHiResMixedTV16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height)
{ {
uint8 *dstPtr2 = dstPtr + dstRowBytes, *srcPtr2 = srcPtr + srcRowBytes; uint8 *dstPtr2 = dstPtr + dstRowBytes, *srcPtr2 = srcPtr + srcRowBytes;
dstRowBytes <<= 1; dstRowBytes <<= 1;
@ -520,7 +577,7 @@ void S9xBlitPixHiResMixedTV16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, in
} }
} }
void S9xBlitPixSmooth16 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height) void S9xBlitPixSmooth2x2 (uint8 *srcPtr, int srcRowBytes, uint8 *dstPtr, int dstRowBytes, int width, int height)
{ {
uint8 *dstPtr2 = dstPtr + dstRowBytes, *deltaPtr = XDelta; uint8 *dstPtr2 = dstPtr + dstRowBytes, *deltaPtr = XDelta;
uint32 lastLinePix[SNES_WIDTH << 1]; uint32 lastLinePix[SNES_WIDTH << 1];

View File

@ -189,14 +189,16 @@ void S9xBlitClearDelta (void);
bool8 S9xBlitNTSCFilterInit (void); bool8 S9xBlitNTSCFilterInit (void);
void S9xBlitNTSCFilterDeinit (void); void S9xBlitNTSCFilterDeinit (void);
void S9xBlitNTSCFilterSet (const snes_ntsc_setup_t *); void S9xBlitNTSCFilterSet (const snes_ntsc_setup_t *);
void S9xBlitPixSmall16 (uint8 *, int, uint8 *, int, int, int); void S9xBlitPixSimple1x1 (uint8 *, int, uint8 *, int, int, int);
void S9xBlitPixScaled16 (uint8 *, int, uint8 *, int, int, int); void S9xBlitPixSimple1x2 (uint8 *, int, uint8 *, int, int, int);
void S9xBlitPixHiRes16 (uint8 *, int, uint8 *, int, int, int); void S9xBlitPixSimple2x1 (uint8 *, int, uint8 *, int, int, int);
void S9xBlitPixDoubled16 (uint8 *, int, uint8 *, int, int, int); void S9xBlitPixSimple2x2 (uint8 *, int, uint8 *, int, int, int);
void S9xBlitPixScaledTV16 (uint8 *, int, uint8 *, int, int, int); void S9xBlitPixBlend1x1 (uint8 *, int, uint8 *, int, int, int);
void S9xBlitPixHiResTV16 (uint8 *, int, uint8 *, int, int, int); void S9xBlitPixBlend2x1 (uint8 *, int, uint8 *, int, int, int);
void S9xBlitPixHiResMixedTV16 (uint8 *, int, uint8 *, int, int, int); void S9xBlitPixTV1x2 (uint8 *, int, uint8 *, int, int, int);
void S9xBlitPixSmooth16 (uint8 *, int, uint8 *, int, int, int); void S9xBlitPixTV2x2 (uint8 *, int, uint8 *, int, int, int);
void S9xBlitPixMixedTV1x2 (uint8 *, int, uint8 *, int, int, int);
void S9xBlitPixSmooth2x2 (uint8 *, int, uint8 *, int, int, int);
void S9xBlitPixSuperEagle16 (uint8 *, int, uint8 *, int, int, int); void S9xBlitPixSuperEagle16 (uint8 *, int, uint8 *, int, int, int);
void S9xBlitPix2xSaI16 (uint8 *, int, uint8 *, int, int, int); void S9xBlitPix2xSaI16 (uint8 *, int, uint8 *, int, int, int);
void S9xBlitPixSuper2xSaI16 (uint8 *, int, uint8 *, int, int, int); void S9xBlitPixSuper2xSaI16 (uint8 *, int, uint8 *, int, int, int);

View File

@ -5,7 +5,7 @@
<key>IBFramework Version</key> <key>IBFramework Version</key>
<string>823</string> <string>823</string>
<key>IBLastKnownRelativeProjectPath</key> <key>IBLastKnownRelativeProjectPath</key>
<string>../macpdate.xcodeproj</string> <string>../snes9x.xcodeproj</string>
<key>IBOldestOS</key> <key>IBOldestOS</key>
<integer>6</integer> <integer>6</integer>
<key>IBOpenObjects</key> <key>IBOpenObjects</key>

File diff suppressed because it is too large Load Diff

View File

@ -238,6 +238,7 @@ enum
VIDEOMODE_BLOCKY, VIDEOMODE_BLOCKY,
VIDEOMODE_TV, VIDEOMODE_TV,
VIDEOMODE_SMOOTH, VIDEOMODE_SMOOTH,
VIDEOMODE_BLEND,
VIDEOMODE_SUPEREAGLE, VIDEOMODE_SUPEREAGLE,
VIDEOMODE_2XSAI, VIDEOMODE_2XSAI,
VIDEOMODE_SUPER2XSAI, VIDEOMODE_SUPER2XSAI,

View File

@ -267,6 +267,7 @@ enum
iOpenGLBlocky = 1, iOpenGLBlocky = 1,
iOpenGLTVMode, iOpenGLTVMode,
iOpenGLSmoothMode, iOpenGLSmoothMode,
iOpenGLBlendMode,
iOpenGLEagleMode, iOpenGLEagleMode,
iOpenGL2xSAIMode, iOpenGL2xSAIMode,
iOpenGLSuper2xSAIMode, iOpenGLSuper2xSAIMode,
@ -308,7 +309,7 @@ static PrefList prefList[] =
{ 'gl32', &gl32bit, sizeof(bool8 ) }, { 'gl32', &gl32bit, sizeof(bool8 ) },
{ 'glst', &glstretch, sizeof(bool8 ) }, { 'glst', &glstretch, sizeof(bool8 ) },
{ 'draw', &drawingMethod, sizeof(long ) }, { 'draw', &drawingMethod, sizeof(long ) },
{ 'vmod', &videoMode, sizeof(int ) }, { 'Vmod', &videoMode, sizeof(int ) },
{ 'MPmt', &multiprocessor, sizeof(bool8 ) }, { 'MPmt', &multiprocessor, sizeof(bool8 ) },
{ 'VSNC', &vsync, sizeof(bool8 ) }, { 'VSNC', &vsync, sizeof(bool8 ) },
{ 'H239', &drawoverscan, sizeof(bool8 ) }, { 'H239', &drawoverscan, sizeof(bool8 ) },
@ -592,6 +593,10 @@ void ConfigurePreferences (void)
SetControl32BitValue(ctl, iOpenGLSmoothMode); SetControl32BitValue(ctl, iOpenGLSmoothMode);
break; break;
case VIDEOMODE_BLEND:
SetControl32BitValue(ctl, iOpenGLBlendMode);
break;
case VIDEOMODE_SUPEREAGLE: case VIDEOMODE_SUPEREAGLE:
SetControl32BitValue(ctl, iOpenGLEagleMode); SetControl32BitValue(ctl, iOpenGLEagleMode);
break; break;
@ -954,6 +959,11 @@ void ConfigurePreferences (void)
videoMode = VIDEOMODE_SMOOTH; videoMode = VIDEOMODE_SMOOTH;
break; break;
case iOpenGLBlendMode:
drawingMethod = kDrawingBlitGL;
videoMode = VIDEOMODE_BLEND;
break;
case iOpenGLEagleMode: case iOpenGLEagleMode:
drawingMethod = kDrawingBlitGL; drawingMethod = kDrawingBlitGL;
videoMode = VIDEOMODE_SUPEREAGLE; videoMode = VIDEOMODE_SUPEREAGLE;

View File

@ -1245,7 +1245,7 @@ static inline void RenderBlitScreen (Blitter Fn, int x, int sW, int sH, int cW,
uint8 *tmpBuffer = blitGLBuffer + (1024 * 512 * 2); uint8 *tmpBuffer = blitGLBuffer + (1024 * 512 * 2);
int aligned = ((ntsc_width + 2) >> 1) << 1; int aligned = ((ntsc_width + 2) >> 1) << 1;
(Fn) ((uint8 *) buf, sW * 2, tmpBuffer, 1024 * 2, sW, sH); (Fn) ((uint8 *) buf, sW * 2, tmpBuffer, 1024 * 2, sW, sH);
S9xBlitPixHiResMixedTV16(tmpBuffer, 1024 * 2, blitGLBuffer, 1024 * 2, aligned, cH); S9xBlitPixMixedTV1x2(tmpBuffer, 1024 * 2, blitGLBuffer, 1024 * 2, aligned, cH);
cH *= 2; cH *= 2;
} }
@ -1581,6 +1581,22 @@ static void S9xPutImageBlitGL (int width, int height)
{ {
default: default:
case 2: case 2:
if (videoMode == VIDEOMODE_BLEND)
{
if (width <= 256)
{
copyWidth = width * 2;
copyHeight = height;
blitFn = S9xBlitPixBlend2x1;
}
else
{
copyWidth = width;
copyHeight = height;
blitFn = S9xBlitPixBlend1x1;
}
}
else
if (height <= 256) if (height <= 256)
{ {
if (width <= 256) if (width <= 256)
@ -1591,7 +1607,7 @@ static void S9xPutImageBlitGL (int width, int height)
switch (videoMode) switch (videoMode)
{ {
default: default:
case VIDEOMODE_TV: blitFn = S9xBlitPixScaledTV16; break; case VIDEOMODE_TV: blitFn = S9xBlitPixTV2x2; break;
case VIDEOMODE_SUPEREAGLE: blitFn = S9xBlitPixSuperEagle16; break; case VIDEOMODE_SUPEREAGLE: blitFn = S9xBlitPixSuperEagle16; break;
case VIDEOMODE_2XSAI: blitFn = S9xBlitPix2xSaI16; break; case VIDEOMODE_2XSAI: blitFn = S9xBlitPix2xSaI16; break;
case VIDEOMODE_SUPER2XSAI: blitFn = S9xBlitPixSuper2xSaI16; break; case VIDEOMODE_SUPER2XSAI: blitFn = S9xBlitPixSuper2xSaI16; break;
@ -1605,13 +1621,13 @@ static void S9xPutImageBlitGL (int width, int height)
{ {
copyWidth = width; copyWidth = width;
copyHeight = height * 2; copyHeight = height * 2;
blitFn = S9xBlitPixHiResTV16; blitFn = S9xBlitPixTV1x2;
} }
else else
{ {
copyWidth = width; copyWidth = width;
copyHeight = height; copyHeight = height;
blitFn = S9xBlitPixSmall16; blitFn = S9xBlitPixSimple1x1;
} }
} }
} }
@ -1619,7 +1635,7 @@ static void S9xPutImageBlitGL (int width, int height)
{ {
copyWidth = width; copyWidth = width;
copyHeight = height; copyHeight = height;
blitFn = S9xBlitPixSmall16; blitFn = S9xBlitPixSimple1x1;
} }
break; break;
@ -1635,7 +1651,7 @@ static void S9xPutImageBlitGL (int width, int height)
{ {
copyWidth = width; copyWidth = width;
copyHeight = height; copyHeight = height;
blitFn = S9xBlitPixSmall16; blitFn = S9xBlitPixSimple1x1;
} }
break; break;
@ -1658,7 +1674,7 @@ static void S9xPutImageBlitGL (int width, int height)
{ {
copyWidth = width; copyWidth = width;
copyHeight = height; copyHeight = height;
blitFn = S9xBlitPixSmall16; blitFn = S9xBlitPixSimple1x1;
} }
break; break;

View File

@ -793,7 +793,7 @@ void S9xPutImage (int width, int height)
{ {
copyWidth = width * 2; copyWidth = width * 2;
copyHeight = height; copyHeight = height;
blitFn = S9xBlitPixDoubled16; blitFn = S9xBlitPixSimple2x1;
} }
else else
{ {
@ -802,9 +802,9 @@ void S9xPutImage (int width, int height)
switch (GUI.video_mode) switch (GUI.video_mode)
{ {
case VIDEOMODE_BLOCKY: blitFn = S9xBlitPixScaled16; break; case VIDEOMODE_BLOCKY: blitFn = S9xBlitPixSimple2x2; break;
case VIDEOMODE_TV: blitFn = S9xBlitPixScaledTV16; break; case VIDEOMODE_TV: blitFn = S9xBlitPixTV2x2; break;
case VIDEOMODE_SMOOTH: blitFn = S9xBlitPixSmooth16; break; case VIDEOMODE_SMOOTH: blitFn = S9xBlitPixSmooth2x2; break;
case VIDEOMODE_SUPEREAGLE: blitFn = S9xBlitPixSuperEagle16; break; case VIDEOMODE_SUPEREAGLE: blitFn = S9xBlitPixSuperEagle16; break;
case VIDEOMODE_2XSAI: blitFn = S9xBlitPix2xSaI16; break; case VIDEOMODE_2XSAI: blitFn = S9xBlitPix2xSaI16; break;
case VIDEOMODE_SUPER2XSAI: blitFn = S9xBlitPixSuper2xSaI16; break; case VIDEOMODE_SUPER2XSAI: blitFn = S9xBlitPixSuper2xSaI16; break;
@ -821,16 +821,15 @@ void S9xPutImage (int width, int height)
switch (GUI.video_mode) switch (GUI.video_mode)
{ {
default: blitFn = S9xBlitPixHiRes16; break; default: blitFn = S9xBlitPixSimple1x2; break;
case VIDEOMODE_TV: blitFn = S9xBlitPixHiResTV16; break; case VIDEOMODE_TV: blitFn = S9xBlitPixTV1x2; break;
} }
} }
else else
{ {
copyWidth = width; copyWidth = width;
copyHeight = height; copyHeight = height;
blitFn = S9xBlitPixSimple1x1;
blitFn = S9xBlitPixSmall16;
} }
blitFn((uint8 *) GFX.Screen, GFX.Pitch, GUI.blit_screen, GUI.blit_screen_pitch, width, height); blitFn((uint8 *) GFX.Screen, GFX.Pitch, GUI.blit_screen, GUI.blit_screen_pitch, width, height);