2 * PROJECT: Win32 subsystem
3 * LICENSE: See COPYING in the top level directory
4 * FILE: subsystems/win32/win32k/dib/stretchblt.c
5 * PURPOSE: AlphaBlend implementation suitable for all bit depths
6 * PROGRAMMERS: Jérôme Gardou
29 return (val
> 255) ? 255 : (UCHAR
)val
;
33 DIB_XXBPP_AlphaBlend(SURFOBJ
* Dest
, SURFOBJ
* Source
, RECTL
* DestRect
,
34 RECTL
* SourceRect
, CLIPOBJ
* ClipRegion
,
35 XLATEOBJ
* ColorTranslation
, BLENDOBJ
* BlendObj
)
37 INT DstX
, DstY
, SrcX
, SrcY
;
38 BLENDFUNCTION BlendFunc
;
39 register NICEPIXEL32 DstPixel32
;
40 register NICEPIXEL32 SrcPixel32
;
41 UCHAR Alpha
, SrcBpp
= BitsPerFormat(Source
->iBitmapFormat
);
43 EXLATEOBJ exloSrcRGB
, exloDstRGB
, exloRGBSrc
;
44 PFN_DIB_PutPixel pfnDibPutPixel
= DibFunctionsForBitmapFormat
[Dest
->iBitmapFormat
].DIB_PutPixel
;
46 DPRINT("DIB_16BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
47 SourceRect
->left
, SourceRect
->top
, SourceRect
->right
, SourceRect
->bottom
,
48 DestRect
->left
, DestRect
->top
, DestRect
->right
, DestRect
->bottom
);
50 BlendFunc
= BlendObj
->BlendFunction
;
51 if (BlendFunc
.BlendOp
!= AC_SRC_OVER
)
53 DPRINT1("BlendOp != AC_SRC_OVER\n");
56 if (BlendFunc
.BlendFlags
!= 0)
58 DPRINT1("BlendFlags != 0\n");
61 if ((BlendFunc
.AlphaFormat
& ~AC_SRC_ALPHA
) != 0)
63 DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc
.AlphaFormat
);
66 if ((BlendFunc
.AlphaFormat
& AC_SRC_ALPHA
) != 0 &&
69 DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
73 if (!ColorTranslation
)
75 DPRINT1("ColorTranslation must not be NULL!\n");
79 pexlo
= CONTAINING_RECORD(ColorTranslation
, EXLATEOBJ
, xlo
);
80 EXLATEOBJ_vInitialize(&exloSrcRGB
, pexlo
->ppalSrc
, &gpalRGB
, 0, 0, 0);
81 EXLATEOBJ_vInitialize(&exloDstRGB
, pexlo
->ppalDst
, &gpalRGB
, 0, 0, 0);
82 EXLATEOBJ_vInitialize(&exloRGBSrc
, &gpalRGB
, pexlo
->ppalSrc
, 0, 0, 0);
84 SrcY
= SourceRect
->top
;
86 while ( DstY
< DestRect
->bottom
)
88 SrcX
= SourceRect
->left
;
89 DstX
= DestRect
->left
;
90 while(DstX
< DestRect
->right
)
92 SrcPixel32
.ul
= DIB_GetSource(Source
, SrcX
, SrcY
, &exloSrcRGB
.xlo
);
93 SrcPixel32
.col
.red
= (SrcPixel32
.col
.red
* BlendFunc
.SourceConstantAlpha
) / 255;
94 SrcPixel32
.col
.green
= (SrcPixel32
.col
.green
* BlendFunc
.SourceConstantAlpha
) / 255;
95 SrcPixel32
.col
.blue
= (SrcPixel32
.col
.blue
* BlendFunc
.SourceConstantAlpha
) / 255;
97 Alpha
= ((BlendFunc
.AlphaFormat
& AC_SRC_ALPHA
) != 0) ?
98 (SrcPixel32
.col
.alpha
* BlendFunc
.SourceConstantAlpha
) / 255 :
99 BlendFunc
.SourceConstantAlpha
;
101 DstPixel32
.ul
= DIB_GetSource(Dest
, DstX
, DstY
, &exloDstRGB
.xlo
);
102 DstPixel32
.col
.red
= Clamp8((DstPixel32
.col
.red
* (255 - Alpha
)) / 255 + SrcPixel32
.col
.red
) ;
103 DstPixel32
.col
.green
= Clamp8((DstPixel32
.col
.green
* (255 - Alpha
)) / 255 + SrcPixel32
.col
.green
) ;
104 DstPixel32
.col
.blue
= Clamp8((DstPixel32
.col
.blue
* (255 - Alpha
)) / 255 + SrcPixel32
.col
.blue
) ;
105 DstPixel32
.ul
= XLATEOBJ_iXlate(&exloRGBSrc
.xlo
, DstPixel32
.ul
);
106 pfnDibPutPixel(Dest
, DstX
, DstY
, XLATEOBJ_iXlate(ColorTranslation
, DstPixel32
.ul
));
109 SrcX
= SourceRect
->left
+ ((DstX
-DestRect
->left
)*(SourceRect
->right
- SourceRect
->left
))
110 /(DestRect
->right
-DestRect
->left
);
113 SrcY
= SourceRect
->top
+ ((DstY
-DestRect
->top
)*(SourceRect
->bottom
- SourceRect
->top
))
114 /(DestRect
->bottom
-DestRect
->top
);
117 EXLATEOBJ_vCleanup(&exloDstRGB
);
118 EXLATEOBJ_vCleanup(&exloRGBSrc
);
119 EXLATEOBJ_vCleanup(&exloSrcRGB
);