Vincent Povirk : gdiplus: Store only one surround color if all colors are the same.
Alexandre Julliard
julliard at winehq.org
Wed Apr 25 13:40:25 CDT 2012
Module: wine
Branch: master
Commit: e2b59a87b05968f5fd9cdbd2f6df4ce4de36b6b6
URL: http://source.winehq.org/git/wine.git/?a=commit;h=e2b59a87b05968f5fd9cdbd2f6df4ce4de36b6b6
Author: Vincent Povirk <vincent at codeweavers.com>
Date: Tue Apr 24 10:14:35 2012 -0500
gdiplus: Store only one surround color if all colors are the same.
---
dlls/gdiplus/brush.c | 20 +++++++++++++++++---
dlls/gdiplus/tests/brush.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/dlls/gdiplus/brush.c b/dlls/gdiplus/brush.c
index a2cf1f9..c11dea6 100644
--- a/dlls/gdiplus/brush.c
+++ b/dlls/gdiplus/brush.c
@@ -1699,6 +1699,7 @@ GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
*grad, GDIPCONST ARGB *argb, INT *count)
{
ARGB *new_surroundcolors;
+ INT i, num_colors;
TRACE("(%p,%p,%p)\n", grad, argb, count);
@@ -1706,16 +1707,29 @@ GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
(*count > grad->path->pathdata.Count))
return InvalidParameter;
- new_surroundcolors = GdipAlloc(*count * sizeof(ARGB));
+ num_colors = *count;
+
+ /* If all colors are the same, only store 1 color. */
+ if (*count > 1)
+ {
+ for (i=1; i < num_colors; i++)
+ if (argb[i] != argb[i-1])
+ break;
+
+ if (i == num_colors)
+ num_colors = 1;
+ }
+
+ new_surroundcolors = GdipAlloc(num_colors * sizeof(ARGB));
if (!new_surroundcolors)
return OutOfMemory;
- memcpy(new_surroundcolors, argb, *count * sizeof(ARGB));
+ memcpy(new_surroundcolors, argb, num_colors * sizeof(ARGB));
GdipFree(grad->surroundcolors);
grad->surroundcolors = new_surroundcolors;
- grad->surroundcolorcount = *count;
+ grad->surroundcolorcount = num_colors;
return Ok;
}
diff --git a/dlls/gdiplus/tests/brush.c b/dlls/gdiplus/tests/brush.c
index 354d60d..cde7b56 100644
--- a/dlls/gdiplus/tests/brush.c
+++ b/dlls/gdiplus/tests/brush.c
@@ -876,6 +876,37 @@ static void test_gradientsurroundcolorcount(void)
expect(Ok, status);
expect(2, count);
+ /* If all colors are the same, count is set to 1. */
+ color[0] = color[1] = 0;
+ count = 2;
+ status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count);
+ expect(Ok, status);
+ expect(2, count);
+
+ color[0] = color[1] = color[2] = 0xdeadbeef;
+ count = 2;
+ status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count);
+ expect(Ok, status);
+ expect(1, count);
+ expect(0x00000000, color[0]);
+ expect(0x00000000, color[1]);
+ expect(0xdeadbeef, color[2]);
+
+ color[0] = color[1] = 0xff00ff00;
+ count = 2;
+ status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count);
+ expect(Ok, status);
+ expect(2, count);
+
+ color[0] = color[1] = color[2] = 0xdeadbeef;
+ count = 2;
+ status = GdipGetPathGradientSurroundColorsWithCount(grad, color, &count);
+ expect(Ok, status);
+ expect(1, count);
+ expect(0xff00ff00, color[0]);
+ expect(0xff00ff00, color[1]);
+ expect(0xdeadbeef, color[2]);
+
count = 0;
status = GdipSetPathGradientSurroundColorsWithCount(grad, color, &count);
expect(InvalidParameter, status);
More information about the wine-cvs
mailing list