[5/5] gdiplus: Store only one surround color if all colors are the same.

Vincent Povirk madewokherd at gmail.com
Tue Apr 24 17:14:41 CDT 2012


-------------- next part --------------
From d5b7acbcb0dfacedc9feb35aca8ef5ff1cbfb8aa Mon Sep 17 00:00:00 2001
From: Vincent Povirk <vincent at codeweavers.com>
Date: Tue, 24 Apr 2012 10:14:35 -0500
Subject: [PATCH 05/13] 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);
-- 
1.7.9.5


More information about the wine-patches mailing list