[PATCH] d3dx9: Add support for color-keying in filter_copy_simple_data
Tony Wasserka
tony.wasserka at freenet.de
Wed Jul 15 10:24:25 CDT 2009
---
dlls/d3dx9_36/surface.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c
index aec05a4..f9f31f9 100644
--- a/dlls/d3dx9_36/surface.c
+++ b/dlls/d3dx9_36/surface.c
@@ -356,6 +356,35 @@ void get_shifts(StaticPixelFormatDesc srcformat, StaticPixelFormatDesc destforma
}
/************************************************************
+ * convert_a8r8g8b8_to_format
+ *
+ * Converts the given A8R8G8B8 color to destformat and stores
+ * the color mask in mask.
+ *
+ */
+void convert_a8r8g8b8_to_format(DWORD *col, DWORD *mask, StaticPixelFormatDesc destformat)
+{
+ DWORD srcshifta, srcshiftr, srcshiftg, srcshiftb;
+ DWORD destshifta, destshiftr, destshiftg, destshiftb;
+ DWORD amask, rmask, gmask, bmask;
+
+ StaticPixelFormatDesc srcformat;
+ get_format_info(D3DFMT_A8R8G8B8, &srcformat);
+
+ get_shifts( srcformat, destformat, &srcshifta, &srcshiftr, &srcshiftg, &srcshiftb);
+ get_shifts(destformat, srcformat, &destshifta, &destshiftr, &destshiftg, &destshiftb);
+
+ get_masks(destformat, &amask, &rmask, &gmask, &bmask);
+
+ *col = (((*col >> srcshifta) << destshifta) & amask) +
+ (((*col >> srcshiftr) << destshiftr) & rmask) +
+ (((*col >> srcshiftg) << destshiftg) & gmask) +
+ (((*col >> srcshiftb) << destshiftb) & bmask);
+
+ *mask = amask + rmask + gmask + bmask;
+}
+
+/************************************************************
* filter_copy_simple_data
*
* Copies the source buffer to the destination buffer, performing
@@ -364,19 +393,21 @@ void get_shifts(StaticPixelFormatDesc srcformat, StaticPixelFormatDesc destforma
*/
void filter_copy_simple_data(LPBYTE pSrc, UINT SrcPitch, POINT SrcSize, StaticPixelFormatDesc SrcFormat,
LPBYTE pDest, UINT DestPitch, POINT DestSize, StaticPixelFormatDesc DestFormat,
- DWORD dwFilter)
+ DWORD dwFilter, DWORD dwColorKey)
{
DWORD SrcShiftA, SrcShiftR, SrcShiftG, SrcShiftB;
DWORD DestShiftA, DestShiftR, DestShiftG, DestShiftB;
DWORD MaskA, MaskR, MaskG, MaskB;
UINT MinWidth, MinHeight;
BYTE *pSrcPtr, *pDestPtr;
+ DWORD CK_Mask;
UINT x, y;
get_shifts( SrcFormat, DestFormat, &SrcShiftA, &SrcShiftR, &SrcShiftG, &SrcShiftB);
get_shifts(DestFormat, SrcFormat, &DestShiftA, &DestShiftR, &DestShiftG, &DestShiftB);
get_masks(DestFormat, &MaskA, &MaskR, &MaskG, &MaskB);
+ if(dwColorKey) convert_a8r8g8b8_to_format(&dwColorKey, &CK_Mask, SrcFormat);
MinWidth = (SrcSize.x < DestSize.x) ? SrcSize.x : DestSize.x;
MinHeight = (SrcSize.y < DestSize.y) ? SrcSize.y : DestSize.y;
@@ -388,6 +419,15 @@ void filter_copy_simple_data(LPBYTE pSrc, UINT SrcPitch, POINT SrcSize, Stati
DWORD Col = *(DWORD*)pSrcPtr;
DWORD *pPixel = (DWORD*)pDestPtr;
+ /* color keying */
+ if(dwColorKey)
+ if((Col & CK_Mask) == dwColorKey) {
+ *pPixel = 0;
+ pSrcPtr += SrcFormat.bpp;
+ pDestPtr += DestFormat.bpp;
+ continue;
+ }
+
/* convert bits per channel */
if(SrcFormat.abits) *pPixel = ((Col >> SrcShiftA) << DestShiftA) & MaskA;
else *pPixel = MaskA;
@@ -482,7 +522,7 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(LPDIRECT3DSURFACE9 pDestSurface,
filter_copy_simple_data((BYTE*)pSrcMemory, SrcPitch, SrcSize, SrcFormatDesc,
LockRect.pBits, LockRect.Pitch, DestSize, DestFormatDesc,
- dwFilter);
+ dwFilter, Colorkey);
IDirect3DSurface9_UnlockRect(pDestSurface);
return D3D_OK;
--
1.6.0.2
--------------000404030104020701070009--
More information about the wine-patches
mailing list