From 7e90dc3dc70b4c19b9f98c44e1279c9659287435 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Wed, 29 Feb 2012 15:23:38 -0600 Subject: [PATCH] gdiplus: Implement path gradient surround color accessors. --- dlls/gdiplus/brush.c | 54 +++++++++++++++++++++++++++++----------- dlls/gdiplus/gdiplus_private.h | 2 ++ dlls/gdiplus/tests/brush.c | 56 +++++++++++++++++++++++++----------------- 3 files changed, 74 insertions(+), 38 deletions(-) diff --git a/dlls/gdiplus/brush.c b/dlls/gdiplus/brush.c index 48dd14d74ae..b7dd1d5bafa 100644 --- a/dlls/gdiplus/brush.c +++ b/dlls/gdiplus/brush.c @@ -83,17 +83,20 @@ GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone) dest->blendcount = count; dest->blendfac = GdipAlloc(count * sizeof(REAL)); dest->blendpos = GdipAlloc(count * sizeof(REAL)); + dest->surroundcolors = GdipAlloc(dest->surroundcolorcount * sizeof(ARGB)); - if(!dest->blendfac || !dest->blendpos){ + if(!dest->blendfac || !dest->blendpos || !dest->surroundcolors){ GdipDeletePath(dest->path); GdipFree(dest->blendfac); GdipFree(dest->blendpos); + GdipFree(dest->surroundcolors); GdipFree(dest); return OutOfMemory; } memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL)); memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL)); + memcpy(dest->surroundcolors, src->surroundcolors, dest->surroundcolorcount * sizeof(ARGB)); break; } @@ -499,9 +502,11 @@ static GpStatus create_path_gradient(GpPath *path, GpPathGradient **grad) (*grad)->blendfac = GdipAlloc(sizeof(REAL)); (*grad)->blendpos = GdipAlloc(sizeof(REAL)); - if(!(*grad)->blendfac || !(*grad)->blendpos){ + (*grad)->surroundcolors = GdipAlloc(sizeof(ARGB)); + if(!(*grad)->blendfac || !(*grad)->blendpos || !(*grad)->surroundcolors){ GdipFree((*grad)->blendfac); GdipFree((*grad)->blendpos); + GdipFree((*grad)->surroundcolors); GdipFree(*grad); *grad = NULL; return OutOfMemory; @@ -521,6 +526,8 @@ static GpStatus create_path_gradient(GpPath *path, GpPathGradient **grad) (*grad)->center.Y = bounds.Y + bounds.Height / 2; (*grad)->focus.X = 0.0; (*grad)->focus.Y = 0.0; + (*grad)->surroundcolors[0] = 0xffffffff; + (*grad)->surroundcolorcount = 1; TRACE("<-- %p\n", *grad); @@ -870,6 +877,7 @@ GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush) GdipDeletePath(((GpPathGradient*) brush)->path); GdipFree(((GpPathGradient*) brush)->blendfac); GdipFree(((GpPathGradient*) brush)->blendpos); + GdipFree(((GpPathGradient*) brush)->surroundcolors); break; case BrushTypeLinearGradient: GdipFree(((GpLineGradient*)brush)->blendfac); @@ -1086,32 +1094,40 @@ GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient *grad, ARGB *argb, INT *count) { - static int calls; + INT i; TRACE("(%p,%p,%p)\n", grad, argb, count); if(!grad || !argb || !count || (*count < grad->path->pathdata.Count)) return InvalidParameter; - if(!(calls++)) - FIXME("not implemented\n"); + for (i=0; ipath->pathdata.Count; i++) + { + if (i < grad->surroundcolorcount) + argb[i] = grad->surroundcolors[i]; + else + argb[i] = grad->surroundcolors[grad->surroundcolorcount-1]; + } - return NotImplemented; + *count = grad->surroundcolorcount; + + return Ok; } GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorCount(GpPathGradient *brush, INT *count) { - static int calls; - TRACE("(%p, %p)\n", brush, count); if (!brush || !count) return InvalidParameter; - if(!(calls++)) - FIXME("not implemented\n"); + /* Yes, this actually returns the number of points in the path (which is the + * required size of a buffer to get the surround colors), rather than the + * number of surround colors. The real count is returned when getting the + * colors. */ + *count = brush->path->pathdata.Count; - return NotImplemented; + return Ok; } GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush, @@ -1503,7 +1519,7 @@ GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad, GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient *grad, GDIPCONST ARGB *argb, INT *count) { - static int calls; + ARGB *new_surroundcolors; TRACE("(%p,%p,%p)\n", grad, argb, count); @@ -1511,10 +1527,18 @@ GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient (*count > grad->path->pathdata.Count)) return InvalidParameter; - if(!(calls++)) - FIXME("not implemented\n"); + new_surroundcolors = GdipAlloc(*count * sizeof(ARGB)); + if (!new_surroundcolors) + return OutOfMemory; - return NotImplemented; + memcpy(new_surroundcolors, argb, *count * sizeof(ARGB)); + + GdipFree(grad->surroundcolors); + + grad->surroundcolors = new_surroundcolors; + grad->surroundcolorcount = *count; + + return Ok; } GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad, diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h index 909f48916e7..3cd01b4e170 100644 --- a/dlls/gdiplus/gdiplus_private.h +++ b/dlls/gdiplus/gdiplus_private.h @@ -196,6 +196,8 @@ struct GpPathGradient{ REAL* blendfac; /* blend factors */ REAL* blendpos; /* blend positions */ INT blendcount; + ARGB *surroundcolors; + INT surroundcolorcount; }; struct GpLineGradient{ diff --git a/dlls/gdiplus/tests/brush.c b/dlls/gdiplus/tests/brush.c index 44bb760e267..89dcac67b36 100644 --- a/dlls/gdiplus/tests/brush.c +++ b/dlls/gdiplus/tests/brush.c @@ -781,25 +781,25 @@ static void test_gradientsurroundcolorcount(void) count = 0; status = GdipGetPathGradientSurroundColorCount(grad, &count); - todo_wine expect(Ok, status); - todo_wine expect(2, count); + expect(Ok, status); + expect(2, count); color[0] = color[1] = color[2] = 0xdeadbeef; count = 3; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); - todo_wine expect(Ok, status); - todo_wine expect(1, count); - todo_wine expect(0xffffffff, color[0]); - todo_wine expect(0xffffffff, color[1]); + expect(Ok, status); + expect(1, count); + expect(0xffffffff, color[0]); + expect(0xffffffff, color[1]); expect(0xdeadbeef, color[2]); color[0] = color[1] = color[2] = 0xdeadbeef; count = 2; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); - todo_wine expect(Ok, status); - todo_wine expect(1, count); - todo_wine expect(0xffffffff, color[0]); - todo_wine expect(0xffffffff, color[1]); + expect(Ok, status); + expect(1, count); + expect(0xffffffff, color[0]); + expect(0xffffffff, color[1]); expect(0xdeadbeef, color[2]); color[0] = color[1] = color[2] = 0xdeadbeef; @@ -843,7 +843,7 @@ static void test_gradientsurroundcolorcount(void) } status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count); - todo_wine expect(Ok, status); + expect(Ok, status); expect(2, count); status = GdipGetPathGradientSurroundColorCount(NULL, &count); @@ -854,26 +854,31 @@ static void test_gradientsurroundcolorcount(void) count = 0; status = GdipGetPathGradientSurroundColorCount(grad, &count); - todo_wine expect(Ok, status); - todo_wine expect(2, count); + expect(Ok, status); + expect(2, count); color[0] = color[1] = color[2] = 0xdeadbeef; count = 2; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); - todo_wine expect(Ok, status); + expect(Ok, status); expect(2, count); - todo_wine expect(0x00ff0000, color[0]); - todo_wine expect(0x0000ff00, color[1]); + expect(0x00ff0000, color[0]); + expect(0x0000ff00, color[1]); expect(0xdeadbeef, color[2]); count = 1; status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count); - todo_wine expect(Ok, status); + expect(Ok, status); expect(1, count); count = 0; + status = GdipGetPathGradientSurroundColorCount(grad, &count); + expect(Ok, status); + expect(2, count); + + count = 0; status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count); - todo_wine expect(InvalidParameter, status); + expect(InvalidParameter, status); expect(0, count); GdipDeleteBrush((GpBrush*)grad); @@ -884,11 +889,11 @@ static void test_gradientsurroundcolorcount(void) color[0] = color[1] = color[2] = 0xdeadbeef; count = 3; status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count); - todo_wine expect(Ok, status); - todo_wine expect(1, count); - todo_wine expect(0xffffffff, color[0]); - todo_wine expect(0xffffffff, color[1]); - todo_wine expect(0xffffffff, color[2]); + expect(Ok, status); + expect(1, count); + expect(0xffffffff, color[0]); + expect(0xffffffff, color[1]); + expect(0xffffffff, color[2]); color[0] = color[1] = color[2] = 0xdeadbeef; count = 2; @@ -899,6 +904,11 @@ static void test_gradientsurroundcolorcount(void) expect(0xdeadbeef, color[1]); expect(0xdeadbeef, color[2]); + count = 0; + status = GdipGetPathGradientSurroundColorCount(grad, &count); + expect(Ok, status); + expect(3, count); + GdipDeleteBrush((GpBrush*)grad); } -- 2.11.4.GIT