Commit 423d50eb authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

gdiplus: Use clipping region in alpha_blend_pixels.

parent e2da590a
......@@ -359,12 +359,15 @@ static void gdi_alpha_blend(GpGraphics *graphics, INT dst_x, INT dst_y, INT dst_
}
}
static GpStatus get_clip_hrgn(GpGraphics *graphics, HRGN *hrgn)
{
return GdipGetRegionHRgn(graphics->clip, graphics, hrgn);
}
/* Draw non-premultiplied ARGB data to the given graphics object */
static GpStatus alpha_blend_pixels(GpGraphics *graphics, INT dst_x, INT dst_y,
static GpStatus alpha_blend_bmp_pixels(GpGraphics *graphics, INT dst_x, INT dst_y,
const BYTE *src, INT src_width, INT src_height, INT src_stride)
{
if (graphics->image && graphics->image->type == ImageTypeBitmap)
{
GpBitmap *dst_bitmap = (GpBitmap*)graphics->image;
INT x, y;
......@@ -380,14 +383,11 @@ static GpStatus alpha_blend_pixels(GpGraphics *graphics, INT dst_x, INT dst_y,
}
return Ok;
}
else if (graphics->image && graphics->image->type == ImageTypeMetafile)
{
ERR("This should not be used for metafiles; fix caller\n");
return NotImplemented;
}
else
{
}
static GpStatus alpha_blend_hdc_pixels(GpGraphics *graphics, INT dst_x, INT dst_y,
const BYTE *src, INT src_width, INT src_height, INT src_stride)
{
HDC hdc;
HBITMAP hbitmap;
BITMAPINFOHEADER bih;
......@@ -420,7 +420,6 @@ static GpStatus alpha_blend_pixels(GpGraphics *graphics, INT dst_x, INT dst_y,
DeleteObject(hbitmap);
return Ok;
}
}
static GpStatus alpha_blend_pixels_hrgn(GpGraphics *graphics, INT dst_x, INT dst_y,
......@@ -433,20 +432,44 @@ static GpStatus alpha_blend_pixels_hrgn(GpGraphics *graphics, INT dst_x, INT dst
int i, size;
RGNDATA *rgndata;
RECT *rects;
HRGN hrgn, visible_rgn;
hrgn = CreateRectRgn(dst_x, dst_y, dst_x + src_width, dst_y + src_height);
if (!hrgn)
return OutOfMemory;
stat = get_clip_hrgn(graphics, &visible_rgn);
if (stat != Ok)
{
DeleteObject(hrgn);
return stat;
}
size = GetRegionData(hregion, 0, NULL);
if (visible_rgn)
{
CombineRgn(hrgn, hrgn, visible_rgn, RGN_AND);
DeleteObject(visible_rgn);
}
if (hregion)
CombineRgn(hrgn, hrgn, hregion, RGN_AND);
size = GetRegionData(hrgn, 0, NULL);
rgndata = GdipAlloc(size);
if (!rgndata)
{
DeleteObject(hrgn);
return OutOfMemory;
}
GetRegionData(hregion, size, rgndata);
GetRegionData(hrgn, size, rgndata);
rects = (RECT*)&rgndata->Buffer;
for (i=0; stat == Ok && i<rgndata->rdh.nCount; i++)
{
stat = alpha_blend_pixels(graphics, rects[i].left, rects[i].top,
stat = alpha_blend_bmp_pixels(graphics, rects[i].left, rects[i].top,
&src[(rects[i].left - dst_x) * 4 + (rects[i].top - dst_y) * src_stride],
rects[i].right - rects[i].left, rects[i].bottom - rects[i].top,
src_stride);
......@@ -454,6 +477,8 @@ static GpStatus alpha_blend_pixels_hrgn(GpGraphics *graphics, INT dst_x, INT dst
GdipFree(rgndata);
DeleteObject(hrgn);
return stat;
}
else if (graphics->image && graphics->image->type == ImageTypeMetafile)
......@@ -463,21 +488,39 @@ static GpStatus alpha_blend_pixels_hrgn(GpGraphics *graphics, INT dst_x, INT dst
}
else
{
HRGN hrgn;
int save;
stat = get_clip_hrgn(graphics, &hrgn);
if (stat != Ok)
return stat;
save = SaveDC(graphics->hdc);
if (hrgn)
ExtSelectClipRgn(graphics->hdc, hrgn, RGN_AND);
if (hregion)
ExtSelectClipRgn(graphics->hdc, hregion, RGN_AND);
stat = alpha_blend_pixels(graphics, dst_x, dst_y, src, src_width,
stat = alpha_blend_hdc_pixels(graphics, dst_x, dst_y, src, src_width,
src_height, src_stride);
RestoreDC(graphics->hdc, save);
DeleteObject(hrgn);
return stat;
}
}
static GpStatus alpha_blend_pixels(GpGraphics *graphics, INT dst_x, INT dst_y,
const BYTE *src, INT src_width, INT src_height, INT src_stride)
{
return alpha_blend_pixels_hrgn(graphics, dst_x, dst_y, src, src_width, src_height, src_stride, NULL);
}
static ARGB blend_colors(ARGB start, ARGB end, REAL position)
{
ARGB result=0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment