mirror of
https://github.com/reactos/wine.git
synced 2024-11-25 20:59:54 +00:00
gdiplus: Store only one surround color if all colors are the same.
This commit is contained in:
parent
8273d58a96
commit
e2b59a87b0
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user