improved copyImage function
split up copyImage to cpyImg16 and cpyImg32 unified D3D & DDraw copyImage behavior no pitch hacks for 16 bit necessary anymore
This commit is contained in:
parent
4a503ef5cf
commit
45f7eddcc5
|
@ -353,25 +353,43 @@ void Direct3DDisplay::render()
|
|||
DXTRACE_ERR_MSGBOX( _T("Can not lock texture"), hr );
|
||||
return;
|
||||
} else {
|
||||
if( !theApp.filterFunction ) {
|
||||
copyImage(
|
||||
pix,
|
||||
lr.pBits,
|
||||
(systemColorDepth == 32) ? theApp.sizeX
|
||||
: theApp.sizeX + 1, // TODO: workaround results in one pixel black border at right side
|
||||
theApp.sizeY,
|
||||
lr.Pitch,
|
||||
systemColorDepth
|
||||
);
|
||||
} else {
|
||||
u32 pitch = theApp.filterWidth * (systemColorDepth>>3) + 4;
|
||||
theApp.filterFunction( pix + pitch,
|
||||
unsigned short pitch = theApp.sizeX * ( systemColorDepth >> 3 ) + 4;
|
||||
if( theApp.filterFunction ) {
|
||||
// pixel filter enabled
|
||||
theApp.filterFunction(
|
||||
pix + pitch,
|
||||
pitch,
|
||||
(u8*)theApp.delta,
|
||||
(u8*)lr.pBits,
|
||||
lr.Pitch,
|
||||
theApp.filterWidth,
|
||||
theApp.filterHeight);
|
||||
theApp.sizeX,
|
||||
theApp.sizeY
|
||||
);
|
||||
} else {
|
||||
// pixel filter disabled
|
||||
switch( systemColorDepth )
|
||||
{
|
||||
case 32:
|
||||
cpyImg32(
|
||||
(unsigned char *)lr.pBits,
|
||||
lr.Pitch,
|
||||
pix + pitch,
|
||||
pitch,
|
||||
theApp.sizeX,
|
||||
theApp.sizeY
|
||||
);
|
||||
break;
|
||||
case 16:
|
||||
cpyImg16(
|
||||
(unsigned char *)lr.pBits,
|
||||
lr.Pitch,
|
||||
pix + pitch,
|
||||
pitch,
|
||||
theApp.sizeX,
|
||||
theApp.sizeY
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
emulatedImage->UnlockRect( 0 );
|
||||
}
|
||||
|
|
|
@ -569,7 +569,7 @@ void DirectDrawDisplay::render()
|
|||
if(hret == DD_OK) {
|
||||
hret = ddsOffscreen->Restore();
|
||||
|
||||
if(hret == DD_OK) {
|
||||
if(hret == DD_OK) {
|
||||
hret = ddsOffscreen->Lock(NULL,
|
||||
&ddsDesc,
|
||||
DDLOCK_WRITEONLY|
|
||||
|
@ -580,46 +580,49 @@ void DirectDrawDisplay::render()
|
|||
NULL);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(hret == DD_OK) {
|
||||
if(theApp.filterFunction) {
|
||||
if(systemColorDepth == 16)
|
||||
(*theApp.filterFunction)(pix+theApp.filterWidth*2+4,
|
||||
theApp.filterWidth*2+4,
|
||||
(u8*)theApp.delta,
|
||||
(u8*)ddsDesc.lpSurface,
|
||||
ddsDesc.lPitch,
|
||||
theApp.filterWidth,
|
||||
theApp.filterHeight);
|
||||
else
|
||||
(*theApp.filterFunction)(pix+theApp.filterWidth*4+4,
|
||||
theApp.filterWidth*4+4,
|
||||
(u8*)theApp.delta,
|
||||
(u8*)ddsDesc.lpSurface,
|
||||
ddsDesc.lPitch,
|
||||
theApp.filterWidth,
|
||||
theApp.filterHeight);
|
||||
|
||||
} else {
|
||||
int copyX = 240;
|
||||
int copyY = 160;
|
||||
|
||||
if(theApp.cartridgeType == 1) {
|
||||
if(gbBorderOn) {
|
||||
copyX = 256;
|
||||
copyY = 224;
|
||||
} else {
|
||||
copyX = 160;
|
||||
copyY = 144;
|
||||
}
|
||||
}
|
||||
if( systemColorDepth == 16 ) {
|
||||
copyX++; // TODO: workaround results in one pixel black border at right side
|
||||
unsigned short pitch = theApp.sizeX * ( systemColorDepth >> 3 ) + 4;
|
||||
if( theApp.filterFunction ) {
|
||||
// pixel filter enabled
|
||||
theApp.filterFunction(
|
||||
pix + pitch,
|
||||
pitch,
|
||||
(u8*)theApp.delta,
|
||||
(u8*)ddsDesc.lpSurface,
|
||||
ddsDesc.lPitch,
|
||||
theApp.sizeX,
|
||||
theApp.sizeY
|
||||
);
|
||||
} else {
|
||||
// pixel filter disabled
|
||||
switch( systemColorDepth )
|
||||
{
|
||||
case 32:
|
||||
cpyImg32(
|
||||
(unsigned char *)ddsDesc.lpSurface,
|
||||
ddsDesc.lPitch,
|
||||
pix + pitch,
|
||||
pitch,
|
||||
theApp.sizeX,
|
||||
theApp.sizeY
|
||||
);
|
||||
break;
|
||||
case 16:
|
||||
cpyImg16(
|
||||
(unsigned char *)ddsDesc.lpSurface,
|
||||
ddsDesc.lPitch,
|
||||
pix + pitch,
|
||||
pitch,
|
||||
theApp.sizeX,
|
||||
theApp.sizeY
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
copyImage( pix, ddsDesc.lpSurface, copyX, copyY, ddsDesc.lPitch, systemColorDepth );
|
||||
}
|
||||
|
||||
if(theApp.showSpeed && (theApp.videoOption > VIDEO_4X || theApp.skin != NULL)) {
|
||||
char buffer[30];
|
||||
if(theApp.showSpeed == 1)
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
enum DISPLAY_TYPE {
|
||||
DIRECT_DRAW = 0,
|
||||
DIRECT_3D = 1,
|
||||
|
@ -43,46 +45,27 @@ class IDisplay {
|
|||
virtual int selectFullScreenMode(GUID **) = 0;
|
||||
};
|
||||
|
||||
inline void copyImage( void *source, void *destination, unsigned int width, unsigned int height, unsigned int destinationPitch, unsigned int colorDepth )
|
||||
inline void cpyImg32( unsigned char *dst, unsigned int dstPitch, unsigned char *src, unsigned int srcPitch, unsigned short width, unsigned short height )
|
||||
{
|
||||
// fast, iterative C version
|
||||
register unsigned int lineSize;
|
||||
register unsigned char *src, *dst;
|
||||
switch(colorDepth)
|
||||
{
|
||||
case 16:
|
||||
lineSize = width<<1;
|
||||
src = ((unsigned char*)source) + lineSize + 4;
|
||||
dst = (unsigned char*)destination;
|
||||
do {
|
||||
MoveMemory( dst, src, lineSize );
|
||||
src+=lineSize;
|
||||
dst+=lineSize;
|
||||
src += 2;
|
||||
dst += (destinationPitch - lineSize);
|
||||
} while ( --height);
|
||||
break;
|
||||
case 32:
|
||||
lineSize = width<<2;
|
||||
src = ((unsigned char*)source) + lineSize + 4;
|
||||
dst = (unsigned char*)destination;
|
||||
do {
|
||||
MoveMemory( dst, src, lineSize );
|
||||
src+=lineSize;
|
||||
dst+=lineSize;
|
||||
src += 4;
|
||||
dst += (destinationPitch - lineSize);
|
||||
} while ( --height);
|
||||
break;
|
||||
}
|
||||
// copies an width*height array of visible pixels from src to dst
|
||||
// srcPitch and dstPitch are the number of garbage bytes after a scanline
|
||||
register unsigned short lineSize = width<<2;
|
||||
|
||||
// compact but slow C version
|
||||
//unsigned int nBytesPerPixel = colorDepth>>3;
|
||||
//unsigned int i, x, y, srcPitch = (width+1) * nBytesPerPixel;
|
||||
//unsigned char * src = ((unsigned char*)source)+srcPitch;
|
||||
//unsigned char * dst = (unsigned char*)destination;
|
||||
//for (y=0;y<height;y++) //Width
|
||||
//for (x=0;x<width;x++) //Height
|
||||
//for (i=0;i<nBytesPerPixel;i++) //Byte# Of Pixel
|
||||
//*(dst+i+(x*nBytesPerPixel)+(y*destinationPitch)) = *(src+i+(x*nBytesPerPixel)+(y*srcPitch));
|
||||
while( height-- ) {
|
||||
memcpy( dst, src, lineSize );
|
||||
src += srcPitch;
|
||||
dst += dstPitch;
|
||||
}
|
||||
}
|
||||
|
||||
inline void cpyImg16( unsigned char *dst, unsigned int dstPitch, unsigned char *src, unsigned int srcPitch, unsigned short width, unsigned short height )
|
||||
{
|
||||
register unsigned short lineSize = width<<1;
|
||||
|
||||
while( height-- ) {
|
||||
memcpy( dst, src, lineSize );
|
||||
src += srcPitch;
|
||||
dst += dstPitch;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue