Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenalphablend.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: Win32 subsystem 00003 * LICENSE: See COPYING in the top level directory 00004 * FILE: subsystems/win32/win32k/dib/stretchblt.c 00005 * PURPOSE: AlphaBlend implementation suitable for all bit depths 00006 * PROGRAMMERS: Jérôme Gardou 00007 */ 00008 00009 #include <win32k.h> 00010 00011 #define NDEBUG 00012 #include <debug.h> 00013 00014 typedef union 00015 { 00016 ULONG ul; 00017 struct 00018 { 00019 UCHAR red; 00020 UCHAR green; 00021 UCHAR blue; 00022 UCHAR alpha; 00023 } col; 00024 } NICEPIXEL32; 00025 00026 static __inline UCHAR 00027 Clamp8(ULONG val) 00028 { 00029 return (val > 255) ? 255 : (UCHAR)val; 00030 } 00031 00032 BOOLEAN 00033 DIB_XXBPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect, 00034 RECTL* SourceRect, CLIPOBJ* ClipRegion, 00035 XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj) 00036 { 00037 INT DstX, DstY, SrcX, SrcY; 00038 BLENDFUNCTION BlendFunc; 00039 register NICEPIXEL32 DstPixel32; 00040 register NICEPIXEL32 SrcPixel32; 00041 UCHAR Alpha, SrcBpp = BitsPerFormat(Source->iBitmapFormat); 00042 EXLATEOBJ* pexlo; 00043 EXLATEOBJ exloSrcRGB, exloDstRGB, exloRGBSrc; 00044 PFN_DIB_PutPixel pfnDibPutPixel = DibFunctionsForBitmapFormat[Dest->iBitmapFormat].DIB_PutPixel; 00045 00046 DPRINT("DIB_16BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n", 00047 SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom, 00048 DestRect->left, DestRect->top, DestRect->right, DestRect->bottom); 00049 00050 BlendFunc = BlendObj->BlendFunction; 00051 if (BlendFunc.BlendOp != AC_SRC_OVER) 00052 { 00053 DPRINT1("BlendOp != AC_SRC_OVER\n"); 00054 return FALSE; 00055 } 00056 if (BlendFunc.BlendFlags != 0) 00057 { 00058 DPRINT1("BlendFlags != 0\n"); 00059 return FALSE; 00060 } 00061 if ((BlendFunc.AlphaFormat & ~AC_SRC_ALPHA) != 0) 00062 { 00063 DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc.AlphaFormat); 00064 return FALSE; 00065 } 00066 if ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0 && 00067 SrcBpp != 32) 00068 { 00069 DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n"); 00070 return FALSE; 00071 } 00072 00073 if (!ColorTranslation) 00074 { 00075 DPRINT1("ColorTranslation must not be NULL!\n"); 00076 return FALSE; 00077 } 00078 00079 pexlo = CONTAINING_RECORD(ColorTranslation, EXLATEOBJ, xlo); 00080 EXLATEOBJ_vInitialize(&exloSrcRGB, pexlo->ppalSrc, &gpalRGB, 0, 0, 0); 00081 EXLATEOBJ_vInitialize(&exloDstRGB, pexlo->ppalDst, &gpalRGB, 0, 0, 0); 00082 EXLATEOBJ_vInitialize(&exloRGBSrc, &gpalRGB, pexlo->ppalSrc, 0, 0, 0); 00083 00084 SrcY = SourceRect->top; 00085 DstY = DestRect->top; 00086 while ( DstY < DestRect->bottom ) 00087 { 00088 SrcX = SourceRect->left; 00089 DstX = DestRect->left; 00090 while(DstX < DestRect->right) 00091 { 00092 SrcPixel32.ul = DIB_GetSource(Source, SrcX, SrcY, &exloSrcRGB.xlo); 00093 SrcPixel32.col.red = (SrcPixel32.col.red * BlendFunc.SourceConstantAlpha) / 255; 00094 SrcPixel32.col.green = (SrcPixel32.col.green * BlendFunc.SourceConstantAlpha) / 255; 00095 SrcPixel32.col.blue = (SrcPixel32.col.blue * BlendFunc.SourceConstantAlpha) / 255; 00096 00097 Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ? 00098 (SrcPixel32.col.alpha * BlendFunc.SourceConstantAlpha) / 255 : 00099 BlendFunc.SourceConstantAlpha ; 00100 00101 DstPixel32.ul = DIB_GetSource(Dest, DstX, DstY, &exloDstRGB.xlo); 00102 DstPixel32.col.red = Clamp8((DstPixel32.col.red * (255 - Alpha)) / 255 + SrcPixel32.col.red) ; 00103 DstPixel32.col.green = Clamp8((DstPixel32.col.green * (255 - Alpha)) / 255 + SrcPixel32.col.green) ; 00104 DstPixel32.col.blue = Clamp8((DstPixel32.col.blue * (255 - Alpha)) / 255 + SrcPixel32.col.blue) ; 00105 DstPixel32.ul = XLATEOBJ_iXlate(&exloRGBSrc.xlo, DstPixel32.ul); 00106 pfnDibPutPixel(Dest, DstX, DstY, XLATEOBJ_iXlate(ColorTranslation, DstPixel32.ul)); 00107 00108 DstX++; 00109 SrcX = SourceRect->left + ((DstX-DestRect->left)*(SourceRect->right - SourceRect->left)) 00110 /(DestRect->right-DestRect->left); 00111 } 00112 DstY++; 00113 SrcY = SourceRect->top + ((DstY-DestRect->top)*(SourceRect->bottom - SourceRect->top)) 00114 /(DestRect->bottom-DestRect->top); 00115 } 00116 00117 EXLATEOBJ_vCleanup(&exloDstRGB); 00118 EXLATEOBJ_vCleanup(&exloRGBSrc); 00119 EXLATEOBJ_vCleanup(&exloSrcRGB); 00120 00121 return TRUE; 00122 } 00123 Generated on Sat May 26 2012 04:36:59 for ReactOS by
1.7.6.1
|