📄 directdraw.cpp
字号:
}
lpwImageSrc++, lpwImageDst++;
}
}
lpSurfaceSrc->Unlock( NULL );
lpSurfaceDst->Unlock( NULL );
}
int
TransAlpha( LPDIRECTDRAWSURFACE lpSurfaceDst, LPDIRECTDRAWSURFACE lpSurfaceSrc, LONG x, LONG y, RECT rectSrc, WORD wAlphaValue )
{
DDSURFACEDESC ddsdSrc, ddsdDst;
register int i, j;
int height, width;
LPBYTE lpSrc, lpDst;
WORD wSrcPitch, wDstPitch;
DWORD dwSrcTemp, dwDstTemp;
DWORD dwSrcRed, dwSrcGreen, dwSrcBlue, dwDstRed, dwDstGreen, dwDstBlue;
WORD wSrcPadding, wDstPadding;
DWORD dwResult;
BOOL bOdd = FALSE;
DWORD dwColorKey;
if ( wAlphaValue < 0 )
{
wAlphaValue = 0;
}
else if ( wAlphaValue > 256 )
{
wAlphaValue = 256;
}
height = rectSrc.bottom - rectSrc.top;
width = rectSrc.right - rectSrc.left;
ZeroMemory( &ddsdSrc, sizeof( ddsdSrc ) );
ddsdSrc.dwSize = sizeof( ddsdSrc );
ddsdSrc.dwFlags = DDSD_PIXELFORMAT;
if ( FAILED( lpSurfaceSrc->GetSurfaceDesc( &ddsdSrc ) ) )
{
return -1;
}
ZeroMemory( &ddsdDst, sizeof( ddsdDst ) );
ddsdDst.dwSize = sizeof( ddsdDst );
if ( FAILED( lpSurfaceDst->GetSurfaceDesc( &ddsdDst ) ) )
{
return -1;
}
DDPIXELFORMAT ddpfSrc;
ZeroMemory( &ddpfSrc, sizeof( ddpfSrc ) );
ddpfSrc.dwSize = sizeof( ddpfSrc );
lpSurfaceSrc->GetPixelFormat( &ddpfSrc );
switch ( ddpfSrc.dwRBitMask )
{
case 0x7C00: // RGB 5:5:5
dwColorKey = ( 255 >> 3 ); // Blue
dwColorKey += ( 0 >> 3 ) << 5; // Green
dwColorKey += ( 255 >> 3 ) << 10; // Red
break;
case 0xF800: // RGB 5:6:5
dwColorKey = ( 255 >> 3 ); // Blue
dwColorKey += ( 0 >> 2 ) << 5; // Green
dwColorKey += ( 255 >> 3 ) << 11; // Red
break;
}
if ( FAILED( lpSurfaceSrc->Lock( NULL, &ddsdSrc, DDLOCK_WAIT, NULL ) ) )
{
return -1;
}
if ( FAILED( lpSurfaceDst->Lock( NULL, &ddsdDst, DDLOCK_WAIT, NULL ) ) )
{
lpSurfaceSrc->Unlock( NULL );
return -1;
}
wSrcPitch = ( WORD )ddsdSrc.lPitch;
wDstPitch = ( WORD )ddsdDst.lPitch;
lpSrc = ( LPBYTE )ddsdSrc.lpSurface;
lpDst = ( LPBYTE )ddsdDst.lpSurface;
switch ( ddpfSrc.dwRBitMask )
{
case 0x7C00:
lpSrc += ( rectSrc.top * wSrcPitch ) + ( rectSrc.left * 2 );
lpDst += ( y * wDstPitch) + ( x * 2 );
wSrcPadding = ( WORD )( wSrcPitch - ( width * 2 ) );
wDstPadding = ( WORD )( wDstPitch - ( width * 2 ) );
if ( width % 2 == 1 )
{
bOdd = TRUE;
width = ( width - 1 ) / 2;
}
else
{
width = width / 2;
}
i = height;
do
{
if ( bOdd )
{
dwSrcTemp = *( ( LPWORD )lpSrc );
if ( dwSrcTemp != dwColorKey )
{
dwDstTemp = *( ( LPWORD )lpDst );
dwSrcBlue = dwSrcTemp & 0x1f;
dwDstBlue = dwDstTemp & 0x1f;
dwSrcGreen = ( dwSrcTemp >> 5 ) & 0x1f;
dwDstGreen = ( dwDstTemp >> 5 ) & 0x1f;
dwSrcRed = ( dwSrcTemp >> 10 ) & 0x1f;
dwDstRed = ( dwDstTemp >> 10 ) & 0x1f;
*( ( LPWORD )lpDst ) = ( WORD )( ( wAlphaValue * ( dwSrcBlue - dwDstBlue ) >> 8 ) + dwDstBlue |
( ( wAlphaValue * ( dwSrcGreen - dwDstGreen ) >> 8 ) + dwDstGreen ) << 5 |
( ( wAlphaValue * ( dwSrcRed - dwDstRed ) >> 8 ) + dwDstRed ) << 10 );
}
lpSrc += 2, lpDst += 2;
}
j = width;
do
{
dwSrcTemp = *( ( LPDWORD )lpSrc );
if ( dwSrcTemp != ( ( DWORD )dwColorKey | ( ( DWORD )dwColorKey << 16 ) ) )
{
dwDstTemp = *( ( LPDWORD )lpDst );
dwResult = dwDstTemp;
if ( ( dwSrcTemp & 0xffff ) != dwColorKey )
{
dwSrcBlue = dwSrcTemp & 0x1f;
dwDstBlue = dwDstTemp & 0x1f;
dwSrcGreen = ( dwSrcTemp >> 5 ) & 0x1f;
dwDstGreen = ( dwDstTemp >> 5 ) & 0x1f;
dwSrcRed = ( dwSrcTemp >> 10 ) & 0x1f;
dwDstRed = ( dwDstTemp >> 10 ) & 0x1f;
dwResult = dwResult & 0xffff0000;
dwResult |= ( DWORD )( ( wAlphaValue * ( dwSrcBlue - dwDstBlue ) >> 8 ) + dwDstBlue |
( ( wAlphaValue * ( dwSrcGreen - dwDstGreen ) >> 8 ) + dwDstGreen ) << 5 |
( ( wAlphaValue * ( dwSrcRed - dwDstRed ) >> 8 ) + dwDstRed ) << 10 );
}
if ( ( ( dwSrcTemp >> 16 ) & 0xffff ) != dwColorKey )
{
dwSrcBlue = ( dwSrcTemp >> 16 ) & 0x1f;
dwDstBlue = ( dwDstTemp >> 16 ) & 0x1f;
dwSrcGreen = ( dwSrcTemp >> 21 ) & 0x1f;
dwDstGreen = ( dwDstTemp >> 21 ) & 0x1f;
dwSrcRed = ( dwSrcTemp >> 26 ) & 0x1f;
dwDstRed = ( dwDstTemp >> 26 ) & 0x1f;
dwResult = dwResult & 0xffff;
dwResult |= ( DWORD )( ( wAlphaValue * ( dwSrcBlue - dwDstBlue ) >> 8 ) + dwDstBlue |
( ( wAlphaValue * ( dwSrcGreen - dwDstGreen ) >> 8 ) + dwDstGreen ) << 5 |
( ( wAlphaValue * ( dwSrcRed - dwDstRed ) >> 8 ) + dwDstRed ) << 10 ) << 16;
}
*( ( LPDWORD )lpDst ) = dwResult;
}
lpSrc += 4, lpDst += 4;
} while ( --j > 0 );
lpSrc += wSrcPadding, lpDst += wDstPadding;
} while ( --i > 0 );
break;
case 0xF800:
lpSrc += ( rectSrc.top * wSrcPitch ) + ( rectSrc.left * 2 );
lpDst += ( y * wDstPitch) + ( x * 2 );
wSrcPadding = ( WORD )( wSrcPitch - ( width * 2 ) );
wDstPadding = ( WORD )( wDstPitch - ( width * 2 ) );
if ( width % 2 == 1 )
{
bOdd = TRUE;
width = ( width - 1 ) / 2;
}
else
{
width = width / 2;
}
i = height;
do
{
if ( bOdd )
{
dwSrcTemp = *( ( LPWORD )lpSrc );
if ( dwSrcTemp != dwColorKey )
{
dwDstTemp = *( ( LPWORD )lpDst );
dwSrcBlue = dwSrcTemp & 0x1f;
dwDstBlue = dwDstTemp & 0x1f;
dwSrcGreen = ( dwSrcTemp >> 5 ) & 0x3f;
dwDstGreen = ( dwDstTemp >> 5 ) & 0x3f;
dwSrcRed = ( dwSrcTemp >> 11 ) & 0x1f;
dwDstRed = ( dwDstTemp >> 11 ) & 0x1f;
*( ( LPWORD )lpDst ) = ( WORD )( ( wAlphaValue * ( dwSrcBlue - dwDstBlue ) >> 8 ) + dwDstBlue |
( ( wAlphaValue * ( dwSrcGreen - dwDstGreen ) >> 8 ) + dwDstGreen ) << 5 |
( ( wAlphaValue * ( dwSrcRed - dwDstRed ) >> 8 ) + dwDstRed ) << 11 );
}
lpSrc += 2, lpDst += 2;
}
j = width;
do
{
dwSrcTemp = *( ( LPDWORD )lpSrc );
if ( dwSrcTemp != ( ( DWORD )dwColorKey | ( ( DWORD )dwColorKey << 16 ) ) )
{
dwDstTemp = *( ( LPDWORD )lpDst );
dwResult = dwDstTemp;
if ( ( dwSrcTemp & 0xffff ) != dwColorKey )
{
dwSrcBlue = dwSrcTemp & 0x1f;
dwDstBlue = dwDstTemp & 0x1f;
dwSrcGreen = ( dwSrcTemp >> 5 ) & 0x3f;
dwDstGreen = ( dwDstTemp >> 5 ) & 0x3f;
dwSrcRed = ( dwSrcTemp >> 11 ) & 0x1f;
dwDstRed = ( dwDstTemp >> 11 ) & 0x1f;
dwResult = dwResult & 0xffff0000;
dwResult |= ( DWORD )( ( wAlphaValue * ( dwSrcBlue - dwDstBlue ) >> 8 ) + dwDstBlue |
( ( wAlphaValue * ( dwSrcGreen - dwDstGreen ) >> 8 ) + dwDstGreen ) << 5 |
( ( wAlphaValue * ( dwSrcRed - dwDstRed ) >> 8 ) + dwDstRed ) << 11 );
}
if ( ( ( dwSrcTemp >> 16 ) & 0xffff ) != dwColorKey )
{
dwSrcBlue = ( dwSrcTemp >> 16 ) & 0x1f;
dwDstBlue = ( dwDstTemp >> 16 ) & 0x1f;
dwSrcGreen = ( dwSrcTemp >> 21 ) & 0x3f;
dwDstGreen = ( dwDstTemp >> 21 ) & 0x3f;
dwSrcRed = ( dwSrcTemp >> 27 ) & 0x1f;
dwDstRed = ( dwDstTemp >> 27 ) & 0x1f;
dwResult = dwResult & 0xffff;
dwResult |= ( DWORD )( ( wAlphaValue * ( dwSrcBlue - dwDstBlue ) >> 8 ) + dwDstBlue |
( ( wAlphaValue * ( dwSrcGreen - dwDstGreen ) >> 8 ) + dwDstGreen ) << 5 |
( ( wAlphaValue * ( dwSrcRed - dwDstRed ) >> 8 ) + dwDstRed ) << 11 ) << 16;
}
*( ( LPDWORD )lpDst ) = dwResult;
}
lpSrc += 4, lpDst += 4;
} while ( --j > 0 );
lpSrc += wSrcPadding, lpDst += wDstPadding;
} while ( --i > 0 );
break;
}
lpSurfaceSrc->Unlock( NULL );
lpSurfaceDst->Unlock( NULL );
return 0;
}
//--------------------------- Gamma Control------------------------
/*******************************************************************
HRESULT GetColorControls(
LPDDCOLORCONTROL lpColorControl
);
typedef struct _DDCOLORCONTROL {
DWORD dwSize;
-> sizeof( DDCOLORCONTROL );
DWORD dwFlags;
-> DDCOLOR_BRIGHTNESS
The lBrightness member contains valid data.
DDCOLOR_COLORENABLE
The lColorEnable member contains valid data.
DDCOLOR_CONTRAST
The lContrast member contains valid data.
DDCOLOR_GAMMA
The lGamma member contains valid data.
DDCOLOR_HUE
The lHue member contains valid data.
DDCOLOR_SATURATION
The lSaturation member contains valid data.
DDCOLOR_SHARPNESS
The lSharpness member contains valid data.
LONG lBrightness;
LONG lContrast;
LONG lHue;
LONG lSaturation;
LONG lSharpness;
LONG lGamma;
LONG lColorEnable;
DWORD dwReserved1;
} DDCOLORCONTROL, FAR *LPDDCOLORCONTROL;
*******************************************************************/
DDCOLORCONTROL g_DisplayGamma, g_OldDisplayGamma;
// 霸烙傈狼 蔼阑 佬绢 历厘茄促.
void InitGammaControl( void )
{
g_DisplayGamma.dwSize = sizeof( DDCOLORCONTROL );
g_DisplayGamma.dwFlags = DDCOLOR_BRIGHTNESS;
// GetColorControls( &g_DisplayGamma );
g_OldDisplayGamma = g_DisplayGamma;
}
// 霸烙傈狼 蔼阑 促矫 Setting茄促.
void ResetGammaCtrl( void )
{
// g_DirectDrawInfo.lpColorCtrl-> lpColorControl->SetColorControls( &g_OldDisplayGamma );
}
// 0 - 10000
int ColorCtrlBrightness( long v )
{
g_DisplayGamma.dwSize = sizeof( DDCOLORCONTROL );
g_DisplayGamma.dwFlags = DDCOLOR_BRIGHTNESS;
g_DisplayGamma.lBrightness = v;
// SetColorControls( &g_DisplayGamma );
return v;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -