Convert RPI output to 32 bit as needed

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@95 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
DJRobX 2007-11-19 09:03:21 +00:00
parent c876a344d7
commit 7f21387290
2 changed files with 90 additions and 4 deletions

View File

@ -795,6 +795,7 @@ void VBA::updateFilter()
if (rpiInit(pluginName))
filterFunction = rpiFilter;
filterMagnification = rpiScaleFactor();
b16to32Video=true;
break;
case FILTER_TVMODE:
filterFunction = ScanlinesTV32;

View File

@ -10,6 +10,12 @@ static RENDER_PLUGIN_INFO MyPlugInfo;
static RENDER_PLUGIN_OUTP MyPlugOutput;
static int nScaleFactor;
extern int systemRedShift, systemGreenShift, systemBlueShift;
extern int realsystemRedShift, realsystemGreenShift, realsystemBlueShift;
extern int realsystemColorDepth;
u8 *pBuffer16 = NULL;
u32 Buffer16Size = 0;
bool rpiInit(const char *sPluginName)
{
rpiCleanup();
@ -71,20 +77,93 @@ bool rpiInit(const char *sPluginName)
void rpiFilter(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, u8 *dstPtr, u32 dstPitch, int width, int height)
{
u8 *pBuff;
if (realsystemColorDepth == 32)
{
// Kega filters are 16 bit only. Assumes we've forced 16 bit input
ASSERT(systemColorDepth == 16);
u32 bufferNeeded = dstPitch * (height + nScaleFactor) * nScaleFactor;
if (Buffer16Size < bufferNeeded)
{
Buffer16Size = bufferNeeded;
if (pBuffer16)
free(pBuffer16);
pBuffer16 = (u8 *)malloc(Buffer16Size);
}
pBuff = pBuffer16;
}
else
pBuff = dstPtr;
MyPlugOutput.Size = sizeof(MyPlugOutput);
MyPlugOutput.Flags = MyPlugInfo.Flags;
MyPlugOutput.SrcPtr = srcPtr;
MyPlugOutput.SrcPitch = srcPitch;
MyPlugOutput.SrcW = width;
MyPlugOutput.SrcH = height;
MyPlugOutput.DstPtr = dstPtr;
// Without this funky math on the height value, the RPI filter isn't fully
// rendering the frame. I don't like passing in values that seem
// to be greater than the buffer size, but it's the only way to get
// proper results.
MyPlugOutput.SrcH = height+(nScaleFactor/2);
MyPlugOutput.DstPtr = pBuff;
MyPlugOutput.DstPitch = dstPitch;
MyPlugOutput.DstW = width * nScaleFactor;
MyPlugOutput.DstH = height * nScaleFactor;
MyPlugOutput.DstH = (height+(nScaleFactor/2)) * nScaleFactor;
MyPlugOutput.OutW = width * nScaleFactor;
MyPlugOutput.OutH = height * nScaleFactor;
MyPlugOutput.OutH = (height+(nScaleFactor/2)) * nScaleFactor;
fnOutput(&MyPlugOutput);
if (realsystemColorDepth == 32)
{
register int i,j;
int rshiftDiff = realsystemRedShift - systemRedShift;
int gshiftDiff = realsystemGreenShift - systemGreenShift;
int bshiftDiff = realsystemBlueShift - systemBlueShift;
u16 *pI, *pICur;
u32 *pO, *pOCur;
pI = pICur = (u16 *)pBuff;
pO = pOCur = (u32 *)dstPtr;
if (rshiftDiff >= 0)
{
for(j=0;j<height*nScaleFactor;j++)
{
for(i=0;i<width*nScaleFactor;i++)
{
*(pOCur++) = ((*pICur & 0xF800) << rshiftDiff) |
((*pICur & 0x07E0) << gshiftDiff) |
((*pICur & 0x001F) << bshiftDiff);
*pICur++;
}
pI = pICur = (u16 *)((char *)pI + dstPitch);
pO = pOCur = (u32 *)((char *)pO + dstPitch);
}
}
else
{
// red shift is negative. That means we're most likely swapping RGB to BGR
// shift operators don't support negative values.
rshiftDiff = -rshiftDiff;
for(j=0;j<height*nScaleFactor;j++)
{
for(i=0;i<width*nScaleFactor;i++)
{
*(pOCur++) = ((*pICur & 0xF800) >> rshiftDiff) |
((*pICur & 0x07E0) << gshiftDiff) |
((*pICur & 0x001F) << bshiftDiff);
*pICur++;
}
pI = pICur = (u16 *)((char *)pI + dstPitch);
pO = pOCur = (u32 *)((char *)pO + dstPitch);
}
}
}
}
int rpiScaleFactor()
@ -99,4 +178,10 @@ void rpiCleanup()
FreeLibrary(rpiDLL);
rpiDLL = NULL;
}
if (pBuffer16)
{
free(pBuffer16);
pBuffer16 = NULL;
Buffer16Size = 0;
}
}