kernel32/tests: Use todo_wine_if() in tests.
[wine.git] / dlls / gdiplus / brush.c
blobb8a686637256fd0321339504e627600b3a984123
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winuser.h"
24 #include "wingdi.h"
26 #define COBJMACROS
27 #include "objbase.h"
28 #include "olectl.h"
29 #include "ole2.h"
31 #include "gdiplus.h"
32 #include "gdiplus_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
37 /******************************************************************************
38 * GdipCloneBrush [GDIPLUS.@]
40 GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone)
42 TRACE("(%p, %p)\n", brush, clone);
44 if(!brush || !clone)
45 return InvalidParameter;
47 switch(brush->bt){
48 case BrushTypeSolidColor:
50 *clone = heap_alloc_zero(sizeof(GpSolidFill));
51 if (!*clone) return OutOfMemory;
52 memcpy(*clone, brush, sizeof(GpSolidFill));
53 break;
55 case BrushTypeHatchFill:
57 GpHatch *hatch = (GpHatch*)brush;
59 return GdipCreateHatchBrush(hatch->hatchstyle, hatch->forecol, hatch->backcol, (GpHatch**)clone);
61 case BrushTypePathGradient:{
62 GpPathGradient *src, *dest;
63 INT count, pcount;
64 GpStatus stat;
66 *clone = heap_alloc_zero(sizeof(GpPathGradient));
67 if (!*clone) return OutOfMemory;
69 src = (GpPathGradient*) brush,
70 dest = (GpPathGradient*) *clone;
72 memcpy(dest, src, sizeof(GpPathGradient));
74 stat = GdipClonePath(src->path, &dest->path);
76 if(stat != Ok){
77 heap_free(dest);
78 return stat;
81 dest->transform = src->transform;
83 /* blending */
84 count = src->blendcount;
85 dest->blendcount = count;
86 dest->blendfac = heap_alloc_zero(count * sizeof(REAL));
87 dest->blendpos = heap_alloc_zero(count * sizeof(REAL));
88 dest->surroundcolors = heap_alloc_zero(dest->surroundcolorcount * sizeof(ARGB));
89 pcount = dest->pblendcount;
90 if (pcount)
92 dest->pblendcolor = heap_alloc_zero(pcount * sizeof(ARGB));
93 dest->pblendpos = heap_alloc_zero(pcount * sizeof(REAL));
96 if(!dest->blendfac || !dest->blendpos || !dest->surroundcolors ||
97 (pcount && (!dest->pblendcolor || !dest->pblendpos))){
98 GdipDeletePath(dest->path);
99 heap_free(dest->blendfac);
100 heap_free(dest->blendpos);
101 heap_free(dest->surroundcolors);
102 heap_free(dest->pblendcolor);
103 heap_free(dest->pblendpos);
104 heap_free(dest);
105 return OutOfMemory;
108 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
109 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
110 memcpy(dest->surroundcolors, src->surroundcolors, dest->surroundcolorcount * sizeof(ARGB));
112 if (pcount)
114 memcpy(dest->pblendcolor, src->pblendcolor, pcount * sizeof(ARGB));
115 memcpy(dest->pblendpos, src->pblendpos, pcount * sizeof(REAL));
118 break;
120 case BrushTypeLinearGradient:{
121 GpLineGradient *dest, *src;
122 INT count, pcount;
124 dest = heap_alloc_zero(sizeof(GpLineGradient));
125 if(!dest) return OutOfMemory;
127 src = (GpLineGradient*)brush;
129 memcpy(dest, src, sizeof(GpLineGradient));
131 count = dest->blendcount;
132 dest->blendfac = heap_alloc_zero(count * sizeof(REAL));
133 dest->blendpos = heap_alloc_zero(count * sizeof(REAL));
134 pcount = dest->pblendcount;
135 if (pcount)
137 dest->pblendcolor = heap_alloc_zero(pcount * sizeof(ARGB));
138 dest->pblendpos = heap_alloc_zero(pcount * sizeof(REAL));
141 if (!dest->blendfac || !dest->blendpos ||
142 (pcount && (!dest->pblendcolor || !dest->pblendpos)))
144 heap_free(dest->blendfac);
145 heap_free(dest->blendpos);
146 heap_free(dest->pblendcolor);
147 heap_free(dest->pblendpos);
148 heap_free(dest);
149 return OutOfMemory;
152 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
153 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
155 if (pcount)
157 memcpy(dest->pblendcolor, src->pblendcolor, pcount * sizeof(ARGB));
158 memcpy(dest->pblendpos, src->pblendpos, pcount * sizeof(REAL));
161 *clone = &dest->brush;
162 break;
164 case BrushTypeTextureFill:
166 GpStatus stat;
167 GpTexture *texture = (GpTexture*)brush;
168 GpTexture *new_texture;
169 UINT width, height;
171 stat = GdipGetImageWidth(texture->image, &width);
172 if (stat != Ok) return stat;
173 stat = GdipGetImageHeight(texture->image, &height);
174 if (stat != Ok) return stat;
176 stat = GdipCreateTextureIA(texture->image, texture->imageattributes, 0, 0, width, height, &new_texture);
178 if (stat == Ok)
180 new_texture->transform = texture->transform;
181 *clone = (GpBrush*)new_texture;
183 else
184 *clone = NULL;
186 return stat;
188 default:
189 ERR("not implemented for brush type %d\n", brush->bt);
190 return NotImplemented;
193 TRACE("<-- %p\n", *clone);
194 return Ok;
197 static const char HatchBrushes[][8] = {
198 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HatchStyleHorizontal */
199 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleVertical */
200 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HatchStyleForwardDiagonal */
201 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HatchStyleBackwardDiagonal */
202 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleCross */
203 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }, /* HatchStyleDiagonalCross */
204 { 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x80 }, /* HatchStyle05Percent */
205 { 0x00, 0x02, 0x00, 0x88, 0x00, 0x20, 0x00, 0x88 }, /* HatchStyle10Percent */
206 { 0x00, 0x22, 0x00, 0xcc, 0x00, 0x22, 0x00, 0xcc }, /* HatchStyle20Percent */
207 { 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc }, /* HatchStyle25Percent */
208 { 0x00, 0xcc, 0x04, 0xcc, 0x00, 0xcc, 0x40, 0xcc }, /* HatchStyle30Percent */
209 { 0x44, 0xcc, 0x22, 0xcc, 0x44, 0xcc, 0x22, 0xcc }, /* HatchStyle40Percent */
210 { 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc }, /* HatchStyle50Percent */
211 { 0x55, 0xcd, 0x55, 0xee, 0x55, 0xdc, 0x55, 0xee }, /* HatchStyle60Percent */
212 { 0x55, 0xdd, 0x55, 0xff, 0x55, 0xdd, 0x55, 0xff }, /* HatchStyle70Percent */
213 { 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff }, /* HatchStyle75Percent */
214 { 0x55, 0xff, 0x59, 0xff, 0x55, 0xff, 0x99, 0xff }, /* HatchStyle80Percent */
215 { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xfd, 0xff }, /* HatchStyle90Percent */
216 { 0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88 }, /* HatchStyleLightDownwardDiagonal */
217 { 0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11 }, /* HatchStyleLightUpwardDiagonal */
218 { 0x99, 0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc }, /* HatchStyleDarkDownwardDiagonal */
219 { 0xcc, 0x66, 0x33, 0x99, 0xcc, 0x66, 0x33, 0x99 }, /* HatchStyleDarkUpwardDiagonal */
220 { 0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0 }, /* HatchStyleWideDownwardDiagonal */
221 { 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x83, 0xc1 }, /* HatchStyleWideUpwardDiagonal */
222 { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 }, /* HatchStyleLightVertical */
223 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff }, /* HatchStyleLightHorizontal */
224 { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }, /* HatchStyleNarrowVertical */
225 { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, /* HatchStyleNarrowHorizontal */
226 { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }, /* HatchStyleDarkVertical */
227 { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff }, /* HatchStyleDarkHorizontal */
230 GpStatus get_hatch_data(HatchStyle hatchstyle, const char **result)
232 if (hatchstyle < sizeof(HatchBrushes) / sizeof(HatchBrushes[0]))
234 *result = HatchBrushes[hatchstyle];
235 return Ok;
237 else
238 return NotImplemented;
241 /******************************************************************************
242 * GdipCreateHatchBrush [GDIPLUS.@]
244 GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle hatchstyle, ARGB forecol, ARGB backcol, GpHatch **brush)
246 TRACE("(%d, %d, %d, %p)\n", hatchstyle, forecol, backcol, brush);
248 if(!brush) return InvalidParameter;
250 *brush = heap_alloc_zero(sizeof(GpHatch));
251 if (!*brush) return OutOfMemory;
253 (*brush)->brush.bt = BrushTypeHatchFill;
254 (*brush)->forecol = forecol;
255 (*brush)->backcol = backcol;
256 (*brush)->hatchstyle = hatchstyle;
257 TRACE("<-- %p\n", *brush);
259 return Ok;
262 /******************************************************************************
263 * GdipCreateLineBrush [GDIPLUS.@]
265 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
266 GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
267 GpWrapMode wrap, GpLineGradient **line)
269 TRACE("(%s, %s, %x, %x, %d, %p)\n", debugstr_pointf(startpoint),
270 debugstr_pointf(endpoint), startcolor, endcolor, wrap, line);
272 if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
273 return InvalidParameter;
275 if (startpoint->X == endpoint->X && startpoint->Y == endpoint->Y)
276 return OutOfMemory;
278 *line = heap_alloc_zero(sizeof(GpLineGradient));
279 if(!*line) return OutOfMemory;
281 (*line)->brush.bt = BrushTypeLinearGradient;
283 (*line)->startpoint.X = startpoint->X;
284 (*line)->startpoint.Y = startpoint->Y;
285 (*line)->endpoint.X = endpoint->X;
286 (*line)->endpoint.Y = endpoint->Y;
287 (*line)->startcolor = startcolor;
288 (*line)->endcolor = endcolor;
289 (*line)->wrap = wrap;
290 (*line)->gamma = FALSE;
292 (*line)->rect.X = (startpoint->X < endpoint->X ? startpoint->X: endpoint->X);
293 (*line)->rect.Y = (startpoint->Y < endpoint->Y ? startpoint->Y: endpoint->Y);
294 (*line)->rect.Width = fabs(startpoint->X - endpoint->X);
295 (*line)->rect.Height = fabs(startpoint->Y - endpoint->Y);
297 if ((*line)->rect.Width == 0)
299 (*line)->rect.X -= (*line)->rect.Height / 2.0f;
300 (*line)->rect.Width = (*line)->rect.Height;
302 else if ((*line)->rect.Height == 0)
304 (*line)->rect.Y -= (*line)->rect.Width / 2.0f;
305 (*line)->rect.Height = (*line)->rect.Width;
308 (*line)->blendcount = 1;
309 (*line)->blendfac = heap_alloc_zero(sizeof(REAL));
310 (*line)->blendpos = heap_alloc_zero(sizeof(REAL));
312 if (!(*line)->blendfac || !(*line)->blendpos)
314 heap_free((*line)->blendfac);
315 heap_free((*line)->blendpos);
316 heap_free(*line);
317 *line = NULL;
318 return OutOfMemory;
321 (*line)->blendfac[0] = 1.0f;
322 (*line)->blendpos[0] = 1.0f;
324 (*line)->pblendcolor = NULL;
325 (*line)->pblendpos = NULL;
326 (*line)->pblendcount = 0;
328 TRACE("<-- %p\n", *line);
330 return Ok;
333 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
334 GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
335 GpWrapMode wrap, GpLineGradient **line)
337 GpPointF stF;
338 GpPointF endF;
340 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
341 startcolor, endcolor, wrap, line);
343 if(!startpoint || !endpoint)
344 return InvalidParameter;
346 stF.X = (REAL)startpoint->X;
347 stF.Y = (REAL)startpoint->Y;
348 endF.X = (REAL)endpoint->X;
349 endF.Y = (REAL)endpoint->Y;
351 return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
354 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
355 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
356 GpLineGradient **line)
358 GpPointF start, end;
359 GpStatus stat;
361 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
362 wrap, line);
364 if(!line || !rect)
365 return InvalidParameter;
367 switch (mode)
369 case LinearGradientModeHorizontal:
370 start.X = rect->X;
371 start.Y = rect->Y;
372 end.X = rect->X + rect->Width;
373 end.Y = rect->Y;
374 break;
375 case LinearGradientModeVertical:
376 start.X = rect->X;
377 start.Y = rect->Y;
378 end.X = rect->X;
379 end.Y = rect->Y + rect->Height;
380 break;
381 case LinearGradientModeForwardDiagonal:
382 start.X = rect->X;
383 start.Y = rect->Y;
384 end.X = rect->X + rect->Width;
385 end.Y = rect->Y + rect->Height;
386 break;
387 case LinearGradientModeBackwardDiagonal:
388 start.X = rect->X + rect->Width;
389 start.Y = rect->Y;
390 end.X = rect->X;
391 end.Y = rect->Y + rect->Height;
392 break;
393 default:
394 return InvalidParameter;
397 stat = GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
399 if (stat == Ok)
400 (*line)->rect = *rect;
402 return stat;
405 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
406 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
407 GpLineGradient **line)
409 GpRectF rectF;
411 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
412 wrap, line);
414 rectF.X = (REAL) rect->X;
415 rectF.Y = (REAL) rect->Y;
416 rectF.Width = (REAL) rect->Width;
417 rectF.Height = (REAL) rect->Height;
419 return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
422 /******************************************************************************
423 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
425 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
426 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
427 GpLineGradient **line)
429 GpStatus stat;
430 LinearGradientMode mode;
431 REAL width, height, exofs, eyofs;
432 REAL sin_angle, cos_angle, sin_cos_angle;
434 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
435 wrap, line);
437 sin_angle = sinf(deg2rad(angle));
438 cos_angle = cosf(deg2rad(angle));
439 sin_cos_angle = sin_angle * cos_angle;
441 if (isAngleScalable)
443 width = height = 1.0;
445 else
447 width = rect->Width;
448 height = rect->Height;
451 if (sin_cos_angle >= 0)
452 mode = LinearGradientModeForwardDiagonal;
453 else
454 mode = LinearGradientModeBackwardDiagonal;
456 stat = GdipCreateLineBrushFromRect(rect, startcolor, endcolor, mode, wrap, line);
458 if (stat == Ok)
460 if (sin_cos_angle >= 0)
462 exofs = width * sin_cos_angle + height * cos_angle * cos_angle;
463 eyofs = width * sin_angle * sin_angle + height * sin_cos_angle;
465 else
467 exofs = width * sin_angle * sin_angle + height * sin_cos_angle;
468 eyofs = -width * sin_cos_angle + height * sin_angle * sin_angle;
471 if (isAngleScalable)
473 exofs = exofs * rect->Width;
474 eyofs = eyofs * rect->Height;
477 if (sin_angle >= 0)
479 (*line)->endpoint.X = rect->X + exofs;
480 (*line)->endpoint.Y = rect->Y + eyofs;
482 else
484 (*line)->endpoint.X = (*line)->startpoint.X;
485 (*line)->endpoint.Y = (*line)->startpoint.Y;
486 (*line)->startpoint.X = rect->X + exofs;
487 (*line)->startpoint.Y = rect->Y + eyofs;
491 return stat;
494 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
495 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
496 GpLineGradient **line)
498 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
499 wrap, line);
501 return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
502 wrap, line);
505 static GpStatus create_path_gradient(GpPath *path, ARGB centercolor, GpPathGradient **grad)
507 GpRectF bounds;
509 if(!path || !grad)
510 return InvalidParameter;
512 if (path->pathdata.Count < 2)
513 return OutOfMemory;
515 GdipGetPathWorldBounds(path, &bounds, NULL, NULL);
517 *grad = heap_alloc_zero(sizeof(GpPathGradient));
518 if (!*grad)
520 return OutOfMemory;
523 GdipSetMatrixElements(&(*grad)->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
525 (*grad)->blendfac = heap_alloc_zero(sizeof(REAL));
526 (*grad)->blendpos = heap_alloc_zero(sizeof(REAL));
527 (*grad)->surroundcolors = heap_alloc_zero(sizeof(ARGB));
528 if(!(*grad)->blendfac || !(*grad)->blendpos || !(*grad)->surroundcolors){
529 heap_free((*grad)->blendfac);
530 heap_free((*grad)->blendpos);
531 heap_free((*grad)->surroundcolors);
532 heap_free(*grad);
533 *grad = NULL;
534 return OutOfMemory;
536 (*grad)->blendfac[0] = 1.0;
537 (*grad)->blendpos[0] = 1.0;
538 (*grad)->blendcount = 1;
540 (*grad)->path = path;
542 (*grad)->brush.bt = BrushTypePathGradient;
543 (*grad)->centercolor = centercolor;
544 (*grad)->wrap = WrapModeClamp;
545 (*grad)->gamma = FALSE;
546 /* FIXME: this should be set to the "centroid" of the path by default */
547 (*grad)->center.X = bounds.X + bounds.Width / 2;
548 (*grad)->center.Y = bounds.Y + bounds.Height / 2;
549 (*grad)->focus.X = 0.0;
550 (*grad)->focus.Y = 0.0;
551 (*grad)->surroundcolors[0] = 0xffffffff;
552 (*grad)->surroundcolorcount = 1;
554 TRACE("<-- %p\n", *grad);
556 return Ok;
559 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
560 INT count, GpWrapMode wrap, GpPathGradient **grad)
562 GpStatus stat;
563 GpPath *path;
565 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
567 if(!grad)
568 return InvalidParameter;
570 if(!points || count <= 0)
571 return OutOfMemory;
573 stat = GdipCreatePath(FillModeAlternate, &path);
575 if (stat == Ok)
577 stat = GdipAddPathLine2(path, points, count);
579 if (stat == Ok)
580 stat = create_path_gradient(path, 0xff000000, grad);
582 if (stat != Ok)
583 GdipDeletePath(path);
586 if (stat == Ok)
587 (*grad)->wrap = wrap;
589 return stat;
592 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
593 INT count, GpWrapMode wrap, GpPathGradient **grad)
595 GpStatus stat;
596 GpPath *path;
598 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
600 if(!grad)
601 return InvalidParameter;
603 if(!points || count <= 0)
604 return OutOfMemory;
606 stat = GdipCreatePath(FillModeAlternate, &path);
608 if (stat == Ok)
610 stat = GdipAddPathLine2I(path, points, count);
612 if (stat == Ok)
613 stat = create_path_gradient(path, 0xff000000, grad);
615 if (stat != Ok)
616 GdipDeletePath(path);
619 if (stat == Ok)
620 (*grad)->wrap = wrap;
622 return stat;
625 /******************************************************************************
626 * GdipCreatePathGradientFromPath [GDIPLUS.@]
628 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
629 GpPathGradient **grad)
631 GpStatus stat;
632 GpPath *new_path;
634 TRACE("(%p, %p)\n", path, grad);
636 if(!grad)
637 return InvalidParameter;
639 if (!path)
640 return OutOfMemory;
642 stat = GdipClonePath((GpPath*)path, &new_path);
644 if (stat == Ok)
646 stat = create_path_gradient(new_path, 0xffffffff, grad);
648 if (stat != Ok)
649 GdipDeletePath(new_path);
652 return stat;
655 /******************************************************************************
656 * GdipCreateSolidFill [GDIPLUS.@]
658 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
660 TRACE("(%x, %p)\n", color, sf);
662 if(!sf) return InvalidParameter;
664 *sf = heap_alloc_zero(sizeof(GpSolidFill));
665 if (!*sf) return OutOfMemory;
667 (*sf)->brush.bt = BrushTypeSolidColor;
668 (*sf)->color = color;
670 TRACE("<-- %p\n", *sf);
672 return Ok;
675 /******************************************************************************
676 * GdipCreateTexture [GDIPLUS.@]
678 * PARAMS
679 * image [I] image to use
680 * wrapmode [I] optional
681 * texture [O] pointer to the resulting texturebrush
683 * RETURNS
684 * SUCCESS: Ok
685 * FAILURE: element of GpStatus
687 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
688 GpTexture **texture)
690 UINT width, height;
691 GpImageAttributes *attributes;
692 GpStatus stat;
694 TRACE("%p, %d %p\n", image, wrapmode, texture);
696 if (!(image && texture))
697 return InvalidParameter;
699 stat = GdipGetImageWidth(image, &width);
700 if (stat != Ok) return stat;
701 stat = GdipGetImageHeight(image, &height);
702 if (stat != Ok) return stat;
704 stat = GdipCreateImageAttributes(&attributes);
706 if (stat == Ok)
708 attributes->wrap = wrapmode;
710 stat = GdipCreateTextureIA(image, attributes, 0, 0, width, height,
711 texture);
713 GdipDisposeImageAttributes(attributes);
716 return stat;
719 /******************************************************************************
720 * GdipCreateTexture2 [GDIPLUS.@]
722 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
723 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
725 GpImageAttributes *attributes;
726 GpStatus stat;
728 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
729 x, y, width, height, texture);
731 stat = GdipCreateImageAttributes(&attributes);
733 if (stat == Ok)
735 attributes->wrap = wrapmode;
737 stat = GdipCreateTextureIA(image, attributes, x, y, width, height,
738 texture);
740 GdipDisposeImageAttributes(attributes);
743 return stat;
746 /******************************************************************************
747 * GdipCreateTextureIA [GDIPLUS.@]
749 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
750 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
751 REAL height, GpTexture **texture)
753 GpStatus status;
754 GpImage *new_image=NULL;
756 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
757 texture);
759 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
760 return InvalidParameter;
762 *texture = NULL;
764 if(image->type != ImageTypeBitmap){
765 FIXME("not implemented for image type %d\n", image->type);
766 return NotImplemented;
769 status = GdipCloneBitmapArea(x, y, width, height, PixelFormatDontCare, (GpBitmap*)image, (GpBitmap**)&new_image);
770 if (status != Ok)
771 return status;
773 *texture = heap_alloc_zero(sizeof(GpTexture));
774 if (!*texture){
775 status = OutOfMemory;
776 goto exit;
779 GdipSetMatrixElements(&(*texture)->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
781 if (imageattr)
783 status = GdipCloneImageAttributes(imageattr, &(*texture)->imageattributes);
785 else
787 status = GdipCreateImageAttributes(&(*texture)->imageattributes);
788 if (status == Ok)
789 (*texture)->imageattributes->wrap = WrapModeTile;
791 if (status == Ok)
793 (*texture)->brush.bt = BrushTypeTextureFill;
794 (*texture)->image = new_image;
797 exit:
798 if (status == Ok)
800 TRACE("<-- %p\n", *texture);
802 else
804 if (*texture)
806 GdipDisposeImageAttributes((*texture)->imageattributes);
807 heap_free(*texture);
808 *texture = NULL;
810 GdipDisposeImage(new_image);
811 TRACE("<-- error %u\n", status);
814 return status;
817 /******************************************************************************
818 * GdipCreateTextureIAI [GDIPLUS.@]
820 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
821 INT x, INT y, INT width, INT height, GpTexture **texture)
823 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
824 texture);
826 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
829 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
830 INT x, INT y, INT width, INT height, GpTexture **texture)
832 GpImageAttributes *imageattr;
833 GpStatus stat;
835 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
836 texture);
838 stat = GdipCreateImageAttributes(&imageattr);
840 if (stat == Ok)
842 imageattr->wrap = wrapmode;
844 stat = GdipCreateTextureIA(image, imageattr, x, y, width, height, texture);
845 GdipDisposeImageAttributes(imageattr);
848 return stat;
851 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
853 TRACE("(%p, %p)\n", brush, type);
855 if(!brush || !type) return InvalidParameter;
857 *type = brush->bt;
859 return Ok;
862 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
864 TRACE("(%p, %p)\n", brush, backcol);
866 if(!brush || !backcol) return InvalidParameter;
868 *backcol = brush->backcol;
870 return Ok;
873 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
875 TRACE("(%p, %p)\n", brush, forecol);
877 if(!brush || !forecol) return InvalidParameter;
879 *forecol = brush->forecol;
881 return Ok;
884 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
886 TRACE("(%p, %p)\n", brush, hatchstyle);
888 if(!brush || !hatchstyle) return InvalidParameter;
890 *hatchstyle = brush->hatchstyle;
892 return Ok;
895 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
897 TRACE("(%p)\n", brush);
899 if(!brush) return InvalidParameter;
901 switch(brush->bt)
903 case BrushTypePathGradient:
904 GdipDeletePath(((GpPathGradient*) brush)->path);
905 heap_free(((GpPathGradient*) brush)->blendfac);
906 heap_free(((GpPathGradient*) brush)->blendpos);
907 heap_free(((GpPathGradient*) brush)->surroundcolors);
908 heap_free(((GpPathGradient*) brush)->pblendcolor);
909 heap_free(((GpPathGradient*) brush)->pblendpos);
910 break;
911 case BrushTypeLinearGradient:
912 heap_free(((GpLineGradient*)brush)->blendfac);
913 heap_free(((GpLineGradient*)brush)->blendpos);
914 heap_free(((GpLineGradient*)brush)->pblendcolor);
915 heap_free(((GpLineGradient*)brush)->pblendpos);
916 break;
917 case BrushTypeTextureFill:
918 GdipDisposeImage(((GpTexture*)brush)->image);
919 GdipDisposeImageAttributes(((GpTexture*)brush)->imageattributes);
920 heap_free(((GpTexture*)brush)->bitmap_bits);
921 break;
922 default:
923 break;
926 heap_free(brush);
928 return Ok;
931 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
932 BOOL *usinggamma)
934 TRACE("(%p, %p)\n", line, usinggamma);
936 if(!line || !usinggamma)
937 return InvalidParameter;
939 *usinggamma = line->gamma;
941 return Ok;
944 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
946 TRACE("(%p, %p)\n", brush, wrapmode);
948 if(!brush || !wrapmode || brush->brush.bt != BrushTypeLinearGradient)
949 return InvalidParameter;
951 *wrapmode = brush->wrap;
953 return Ok;
956 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
957 REAL *positions, INT count)
959 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
961 if(!brush || !blend || !positions || count <= 0 || brush->brush.bt != BrushTypePathGradient)
962 return InvalidParameter;
964 if(count < brush->blendcount)
965 return InsufficientBuffer;
967 memcpy(blend, brush->blendfac, count*sizeof(REAL));
968 if(brush->blendcount > 1){
969 memcpy(positions, brush->blendpos, count*sizeof(REAL));
972 return Ok;
975 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
977 TRACE("(%p, %p)\n", brush, count);
979 if(!brush || !count || brush->brush.bt != BrushTypePathGradient)
980 return InvalidParameter;
982 *count = brush->blendcount;
984 return Ok;
987 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
988 GpPointF *point)
990 TRACE("(%p, %p)\n", grad, point);
992 if(!grad || !point || grad->brush.bt != BrushTypePathGradient)
993 return InvalidParameter;
995 point->X = grad->center.X;
996 point->Y = grad->center.Y;
998 return Ok;
1001 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
1002 GpPoint *point)
1004 GpStatus ret;
1005 GpPointF ptf;
1007 TRACE("(%p, %p)\n", grad, point);
1009 if(!point)
1010 return InvalidParameter;
1012 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
1014 if(ret == Ok){
1015 point->X = gdip_round(ptf.X);
1016 point->Y = gdip_round(ptf.Y);
1019 return ret;
1022 GpStatus WINGDIPAPI GdipGetPathGradientCenterColor(GpPathGradient *grad,
1023 ARGB *colors)
1025 TRACE("(%p,%p)\n", grad, colors);
1027 if (!grad || !colors || grad->brush.bt != BrushTypePathGradient)
1028 return InvalidParameter;
1030 *colors = grad->centercolor;
1032 return Ok;
1035 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
1036 REAL *x, REAL *y)
1038 TRACE("(%p, %p, %p)\n", grad, x, y);
1040 if(!grad || !x || !y || grad->brush.bt != BrushTypePathGradient)
1041 return InvalidParameter;
1043 *x = grad->focus.X;
1044 *y = grad->focus.Y;
1046 return Ok;
1049 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1050 BOOL *gamma)
1052 TRACE("(%p, %p)\n", grad, gamma);
1054 if(!grad || !gamma || grad->brush.bt != BrushTypePathGradient)
1055 return InvalidParameter;
1057 *gamma = grad->gamma;
1059 return Ok;
1062 GpStatus WINGDIPAPI GdipGetPathGradientPath(GpPathGradient *grad, GpPath *path)
1064 static int calls;
1066 TRACE("(%p, %p)\n", grad, path);
1068 if (!(calls++))
1069 FIXME("not implemented\n");
1071 return NotImplemented;
1074 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1075 INT *count)
1077 TRACE("(%p, %p)\n", grad, count);
1079 if(!grad || !count || grad->brush.bt != BrushTypePathGradient)
1080 return InvalidParameter;
1082 *count = grad->path->pathdata.Count;
1084 return Ok;
1087 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1089 GpStatus stat;
1091 TRACE("(%p, %p)\n", brush, rect);
1093 if(!brush || !rect || brush->brush.bt != BrushTypePathGradient)
1094 return InvalidParameter;
1096 stat = GdipGetPathWorldBounds(brush->path, rect, NULL, NULL);
1098 return stat;
1101 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1103 GpRectF rectf;
1104 GpStatus stat;
1106 TRACE("(%p, %p)\n", brush, rect);
1108 if(!brush || !rect)
1109 return InvalidParameter;
1111 stat = GdipGetPathGradientRect(brush, &rectf);
1112 if(stat != Ok) return stat;
1114 rect->X = gdip_round(rectf.X);
1115 rect->Y = gdip_round(rectf.Y);
1116 rect->Width = gdip_round(rectf.Width);
1117 rect->Height = gdip_round(rectf.Height);
1119 return Ok;
1122 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1123 *grad, ARGB *argb, INT *count)
1125 INT i;
1127 TRACE("(%p,%p,%p)\n", grad, argb, count);
1129 if(!grad || !argb || !count || (*count < grad->path->pathdata.Count) || grad->brush.bt != BrushTypePathGradient)
1130 return InvalidParameter;
1132 for (i=0; i<grad->path->pathdata.Count; i++)
1134 if (i < grad->surroundcolorcount)
1135 argb[i] = grad->surroundcolors[i];
1136 else
1137 argb[i] = grad->surroundcolors[grad->surroundcolorcount-1];
1140 *count = grad->surroundcolorcount;
1142 return Ok;
1145 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorCount(GpPathGradient *brush, INT *count)
1147 TRACE("(%p, %p)\n", brush, count);
1149 if (!brush || !count || brush->brush.bt != BrushTypePathGradient)
1150 return InvalidParameter;
1152 /* Yes, this actually returns the number of points in the path (which is the
1153 * required size of a buffer to get the surround colors), rather than the
1154 * number of surround colors. The real count is returned when getting the
1155 * colors. */
1156 *count = brush->path->pathdata.Count;
1158 return Ok;
1161 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1162 GpWrapMode *wrapmode)
1164 TRACE("(%p, %p)\n", brush, wrapmode);
1166 if(!brush || !wrapmode || brush->brush.bt != BrushTypePathGradient)
1167 return InvalidParameter;
1169 *wrapmode = brush->wrap;
1171 return Ok;
1174 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1176 TRACE("(%p, %p)\n", sf, argb);
1178 if(!sf || !argb)
1179 return InvalidParameter;
1181 *argb = sf->color;
1183 return Ok;
1186 /******************************************************************************
1187 * GdipGetTextureImage [GDIPLUS.@]
1189 GpStatus WINGDIPAPI GdipGetTextureImage(GpTexture *brush, GpImage **image)
1191 TRACE("(%p, %p)\n", brush, image);
1193 if(!brush || !image)
1194 return InvalidParameter;
1196 return GdipCloneImage(brush->image, image);
1199 /******************************************************************************
1200 * GdipGetTextureTransform [GDIPLUS.@]
1202 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1204 TRACE("(%p, %p)\n", brush, matrix);
1206 if(!brush || !matrix)
1207 return InvalidParameter;
1209 *matrix = brush->transform;
1211 return Ok;
1214 /******************************************************************************
1215 * GdipGetTextureWrapMode [GDIPLUS.@]
1217 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1219 TRACE("(%p, %p)\n", brush, wrapmode);
1221 if(!brush || !wrapmode)
1222 return InvalidParameter;
1224 *wrapmode = brush->imageattributes->wrap;
1226 return Ok;
1229 /******************************************************************************
1230 * GdipMultiplyTextureTransform [GDIPLUS.@]
1232 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1233 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1235 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1237 if(!brush || !matrix)
1238 return InvalidParameter;
1240 return GdipMultiplyMatrix(&brush->transform, matrix, order);
1243 /******************************************************************************
1244 * GdipResetTextureTransform [GDIPLUS.@]
1246 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1248 TRACE("(%p)\n", brush);
1250 if(!brush)
1251 return InvalidParameter;
1253 return GdipSetMatrixElements(&brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1256 /******************************************************************************
1257 * GdipScaleTextureTransform [GDIPLUS.@]
1259 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1260 REAL sx, REAL sy, GpMatrixOrder order)
1262 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1264 if(!brush)
1265 return InvalidParameter;
1267 return GdipScaleMatrix(&brush->transform, sx, sy, order);
1270 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1271 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1273 REAL *new_blendfac, *new_blendpos;
1275 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1277 if(!brush || !factors || !positions || count <= 0 || brush->brush.bt != BrushTypeLinearGradient ||
1278 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1279 return InvalidParameter;
1281 new_blendfac = heap_alloc_zero(count * sizeof(REAL));
1282 new_blendpos = heap_alloc_zero(count * sizeof(REAL));
1284 if (!new_blendfac || !new_blendpos)
1286 heap_free(new_blendfac);
1287 heap_free(new_blendpos);
1288 return OutOfMemory;
1291 memcpy(new_blendfac, factors, count * sizeof(REAL));
1292 memcpy(new_blendpos, positions, count * sizeof(REAL));
1294 heap_free(brush->blendfac);
1295 heap_free(brush->blendpos);
1297 brush->blendcount = count;
1298 brush->blendfac = new_blendfac;
1299 brush->blendpos = new_blendpos;
1301 return Ok;
1304 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1305 REAL *positions, INT count)
1307 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1309 if (!brush || !factors || !positions || count <= 0 || brush->brush.bt != BrushTypeLinearGradient)
1310 return InvalidParameter;
1312 if (count < brush->blendcount)
1313 return InsufficientBuffer;
1315 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1316 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1318 return Ok;
1321 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1323 TRACE("(%p, %p)\n", brush, count);
1325 if (!brush || !count || brush->brush.bt != BrushTypeLinearGradient)
1326 return InvalidParameter;
1328 *count = brush->blendcount;
1330 return Ok;
1333 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1334 BOOL usegamma)
1336 TRACE("(%p, %d)\n", line, usegamma);
1338 if(!line || line->brush.bt != BrushTypeLinearGradient)
1339 return InvalidParameter;
1341 line->gamma = usegamma;
1343 return Ok;
1346 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1347 REAL scale)
1349 REAL factors[33];
1350 REAL positions[33];
1351 int num_points = 0;
1352 int i;
1353 const int precision = 16;
1354 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1355 REAL min_erf;
1356 REAL scale_erf;
1358 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1360 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0 || line->brush.bt != BrushTypeLinearGradient)
1361 return InvalidParameter;
1363 /* we want 2 standard deviations */
1364 erf_range = 2.0 / sqrt(2);
1366 /* calculate the constants we need to normalize the error function to be
1367 between 0.0 and scale over the range we need */
1368 min_erf = erf(-erf_range);
1369 scale_erf = scale / (-2.0 * min_erf);
1371 if (focus != 0.0)
1373 positions[0] = 0.0;
1374 factors[0] = 0.0;
1375 for (i=1; i<precision; i++)
1377 positions[i] = focus * i / precision;
1378 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1380 num_points += precision;
1383 positions[num_points] = focus;
1384 factors[num_points] = scale;
1385 num_points += 1;
1387 if (focus != 1.0)
1389 for (i=1; i<precision; i++)
1391 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1392 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1394 num_points += precision;
1395 positions[num_points-1] = 1.0;
1396 factors[num_points-1] = 0.0;
1399 return GdipSetLineBlend(line, factors, positions, num_points);
1402 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1403 GpWrapMode wrap)
1405 TRACE("(%p, %d)\n", line, wrap);
1407 if(!line || wrap == WrapModeClamp || line->brush.bt != BrushTypeLinearGradient)
1408 return InvalidParameter;
1410 line->wrap = wrap;
1412 return Ok;
1415 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1416 GDIPCONST REAL *pos, INT count)
1418 REAL *new_blendfac, *new_blendpos;
1420 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1422 if(!brush || !blend || !pos || count <= 0 || brush->brush.bt != BrushTypePathGradient ||
1423 (count >= 2 && (pos[0] != 0.0f || pos[count-1] != 1.0f)))
1424 return InvalidParameter;
1426 new_blendfac = heap_alloc_zero(count * sizeof(REAL));
1427 new_blendpos = heap_alloc_zero(count * sizeof(REAL));
1429 if (!new_blendfac || !new_blendpos)
1431 heap_free(new_blendfac);
1432 heap_free(new_blendpos);
1433 return OutOfMemory;
1436 memcpy(new_blendfac, blend, count * sizeof(REAL));
1437 memcpy(new_blendpos, pos, count * sizeof(REAL));
1439 heap_free(brush->blendfac);
1440 heap_free(brush->blendpos);
1442 brush->blendcount = count;
1443 brush->blendfac = new_blendfac;
1444 brush->blendpos = new_blendpos;
1446 return Ok;
1449 GpStatus WINGDIPAPI GdipSetPathGradientLinearBlend(GpPathGradient *brush,
1450 REAL focus, REAL scale)
1452 REAL factors[3];
1453 REAL positions[3];
1454 int num_points = 0;
1456 TRACE("(%p,%0.2f,%0.2f)\n", brush, focus, scale);
1458 if (!brush || brush->brush.bt != BrushTypePathGradient)
1459 return InvalidParameter;
1461 if (focus != 0.0)
1463 factors[num_points] = 0.0;
1464 positions[num_points] = 0.0;
1465 num_points++;
1468 factors[num_points] = scale;
1469 positions[num_points] = focus;
1470 num_points++;
1472 if (focus != 1.0)
1474 factors[num_points] = 0.0;
1475 positions[num_points] = 1.0;
1476 num_points++;
1479 return GdipSetPathGradientBlend(brush, factors, positions, num_points);
1482 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1483 GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1485 ARGB *new_color;
1486 REAL *new_pos;
1487 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1489 if (!brush || !blend || !pos || count < 2 || brush->brush.bt != BrushTypePathGradient ||
1490 pos[0] != 0.0f || pos[count-1] != 1.0f)
1492 return InvalidParameter;
1495 new_color = heap_alloc_zero(count * sizeof(ARGB));
1496 new_pos = heap_alloc_zero(count * sizeof(REAL));
1497 if (!new_color || !new_pos)
1499 heap_free(new_color);
1500 heap_free(new_pos);
1501 return OutOfMemory;
1504 memcpy(new_color, blend, sizeof(ARGB) * count);
1505 memcpy(new_pos, pos, sizeof(REAL) * count);
1507 heap_free(brush->pblendcolor);
1508 heap_free(brush->pblendpos);
1510 brush->pblendcolor = new_color;
1511 brush->pblendpos = new_pos;
1512 brush->pblendcount = count;
1514 return Ok;
1517 GpStatus WINGDIPAPI GdipGetPathGradientPresetBlend(GpPathGradient *brush,
1518 ARGB *blend, REAL *pos, INT count)
1520 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1522 if (count < 0)
1523 return OutOfMemory;
1525 if (!brush || !blend || !pos || count < 2 || brush->brush.bt != BrushTypePathGradient)
1526 return InvalidParameter;
1528 if (brush->pblendcount == 0)
1529 return GenericError;
1531 if (count != brush->pblendcount)
1533 /* Native lines up the ends of each array, and copies the destination size. */
1534 FIXME("Braindead behavior on wrong-sized buffer not implemented.\n");
1535 return InvalidParameter;
1538 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1539 memcpy(pos, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1541 return Ok;
1544 GpStatus WINGDIPAPI GdipGetPathGradientPresetBlendCount(GpPathGradient *brush,
1545 INT *count)
1547 TRACE("(%p,%p)\n", brush, count);
1549 if (!brush || !count || brush->brush.bt != BrushTypePathGradient)
1550 return InvalidParameter;
1552 *count = brush->pblendcount;
1554 return Ok;
1557 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1558 ARGB argb)
1560 TRACE("(%p, %x)\n", grad, argb);
1562 if(!grad || grad->brush.bt != BrushTypePathGradient)
1563 return InvalidParameter;
1565 grad->centercolor = argb;
1566 return Ok;
1569 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1570 GpPointF *point)
1572 TRACE("(%p, %s)\n", grad, debugstr_pointf(point));
1574 if(!grad || !point || grad->brush.bt != BrushTypePathGradient)
1575 return InvalidParameter;
1577 grad->center.X = point->X;
1578 grad->center.Y = point->Y;
1580 return Ok;
1583 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1584 GpPoint *point)
1586 GpPointF ptf;
1588 TRACE("(%p, %p)\n", grad, point);
1590 if(!point)
1591 return InvalidParameter;
1593 ptf.X = (REAL)point->X;
1594 ptf.Y = (REAL)point->Y;
1596 return GdipSetPathGradientCenterPoint(grad,&ptf);
1599 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1600 REAL x, REAL y)
1602 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1604 if(!grad || grad->brush.bt != BrushTypePathGradient)
1605 return InvalidParameter;
1607 grad->focus.X = x;
1608 grad->focus.Y = y;
1610 return Ok;
1613 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1614 BOOL gamma)
1616 TRACE("(%p, %d)\n", grad, gamma);
1618 if(!grad || grad->brush.bt != BrushTypePathGradient)
1619 return InvalidParameter;
1621 grad->gamma = gamma;
1623 return Ok;
1626 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1627 REAL focus, REAL scale)
1629 REAL factors[33];
1630 REAL positions[33];
1631 int num_points = 0;
1632 int i;
1633 const int precision = 16;
1634 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1635 REAL min_erf;
1636 REAL scale_erf;
1638 TRACE("(%p,%0.2f,%0.2f)\n", grad, focus, scale);
1640 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0 || grad->brush.bt != BrushTypePathGradient)
1641 return InvalidParameter;
1643 /* we want 2 standard deviations */
1644 erf_range = 2.0 / sqrt(2);
1646 /* calculate the constants we need to normalize the error function to be
1647 between 0.0 and scale over the range we need */
1648 min_erf = erf(-erf_range);
1649 scale_erf = scale / (-2.0 * min_erf);
1651 if (focus != 0.0)
1653 positions[0] = 0.0;
1654 factors[0] = 0.0;
1655 for (i=1; i<precision; i++)
1657 positions[i] = focus * i / precision;
1658 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1660 num_points += precision;
1663 positions[num_points] = focus;
1664 factors[num_points] = scale;
1665 num_points += 1;
1667 if (focus != 1.0)
1669 for (i=1; i<precision; i++)
1671 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1672 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1674 num_points += precision;
1675 positions[num_points-1] = 1.0;
1676 factors[num_points-1] = 0.0;
1679 return GdipSetPathGradientBlend(grad, factors, positions, num_points);
1682 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1683 *grad, GDIPCONST ARGB *argb, INT *count)
1685 ARGB *new_surroundcolors;
1686 INT i, num_colors;
1688 TRACE("(%p,%p,%p)\n", grad, argb, count);
1690 if(!grad || !argb || !count || (*count <= 0) || grad->brush.bt != BrushTypePathGradient ||
1691 (*count > grad->path->pathdata.Count))
1692 return InvalidParameter;
1694 num_colors = *count;
1696 /* If all colors are the same, only store 1 color. */
1697 if (*count > 1)
1699 for (i=1; i < num_colors; i++)
1700 if (argb[i] != argb[i-1])
1701 break;
1703 if (i == num_colors)
1704 num_colors = 1;
1707 new_surroundcolors = heap_alloc_zero(num_colors * sizeof(ARGB));
1708 if (!new_surroundcolors)
1709 return OutOfMemory;
1711 memcpy(new_surroundcolors, argb, num_colors * sizeof(ARGB));
1713 heap_free(grad->surroundcolors);
1715 grad->surroundcolors = new_surroundcolors;
1716 grad->surroundcolorcount = num_colors;
1718 return Ok;
1721 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1722 GpWrapMode wrap)
1724 TRACE("(%p, %d)\n", grad, wrap);
1726 if(!grad || grad->brush.bt != BrushTypePathGradient)
1727 return InvalidParameter;
1729 grad->wrap = wrap;
1731 return Ok;
1734 GpStatus WINGDIPAPI GdipSetPathGradientTransform(GpPathGradient *grad,
1735 GpMatrix *matrix)
1737 TRACE("(%p,%p)\n", grad, matrix);
1739 if (!grad || !matrix || grad->brush.bt != BrushTypePathGradient)
1740 return InvalidParameter;
1742 grad->transform = *matrix;
1744 return Ok;
1747 GpStatus WINGDIPAPI GdipGetPathGradientTransform(GpPathGradient *grad,
1748 GpMatrix *matrix)
1750 TRACE("(%p,%p)\n", grad, matrix);
1752 if (!grad || !matrix || grad->brush.bt != BrushTypePathGradient)
1753 return InvalidParameter;
1755 *matrix = grad->transform;
1757 return Ok;
1760 GpStatus WINGDIPAPI GdipMultiplyPathGradientTransform(GpPathGradient *grad,
1761 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1763 TRACE("(%p,%p,%i)\n", grad, matrix, order);
1765 if (!grad || grad->brush.bt != BrushTypePathGradient)
1766 return InvalidParameter;
1768 return GdipMultiplyMatrix(&grad->transform, matrix, order);
1771 GpStatus WINGDIPAPI GdipResetPathGradientTransform(GpPathGradient *grad)
1773 TRACE("(%p)\n", grad);
1775 if (!grad || grad->brush.bt != BrushTypePathGradient)
1776 return InvalidParameter;
1778 return GdipSetMatrixElements(&grad->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1781 GpStatus WINGDIPAPI GdipRotatePathGradientTransform(GpPathGradient *grad,
1782 REAL angle, GpMatrixOrder order)
1784 TRACE("(%p,%0.2f,%i)\n", grad, angle, order);
1786 if (!grad || grad->brush.bt != BrushTypePathGradient)
1787 return InvalidParameter;
1789 return GdipRotateMatrix(&grad->transform, angle, order);
1792 GpStatus WINGDIPAPI GdipScalePathGradientTransform(GpPathGradient *grad,
1793 REAL sx, REAL sy, GpMatrixOrder order)
1795 TRACE("(%p,%0.2f,%0.2f,%i)\n", grad, sx, sy, order);
1797 if (!grad || grad->brush.bt != BrushTypePathGradient)
1798 return InvalidParameter;
1800 return GdipScaleMatrix(&grad->transform, sx, sy, order);
1803 GpStatus WINGDIPAPI GdipTranslatePathGradientTransform(GpPathGradient *grad,
1804 REAL dx, REAL dy, GpMatrixOrder order)
1806 TRACE("(%p,%0.2f,%0.2f,%i)\n", grad, dx, dy, order);
1808 if (!grad || grad->brush.bt != BrushTypePathGradient)
1809 return InvalidParameter;
1811 return GdipTranslateMatrix(&grad->transform, dx, dy, order);
1814 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1816 TRACE("(%p, %x)\n", sf, argb);
1818 if(!sf)
1819 return InvalidParameter;
1821 sf->color = argb;
1822 return Ok;
1825 /******************************************************************************
1826 * GdipSetTextureTransform [GDIPLUS.@]
1828 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1829 GDIPCONST GpMatrix *matrix)
1831 TRACE("(%p, %p)\n", texture, matrix);
1833 if(!texture || !matrix)
1834 return InvalidParameter;
1836 texture->transform = *matrix;
1838 return Ok;
1841 /******************************************************************************
1842 * GdipSetTextureWrapMode [GDIPLUS.@]
1844 * WrapMode not used, only stored
1846 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1848 TRACE("(%p, %d)\n", brush, wrapmode);
1850 if(!brush)
1851 return InvalidParameter;
1853 brush->imageattributes->wrap = wrapmode;
1855 return Ok;
1858 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1859 ARGB color2)
1861 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1863 if(!brush || brush->brush.bt != BrushTypeLinearGradient)
1864 return InvalidParameter;
1866 brush->startcolor = color1;
1867 brush->endcolor = color2;
1869 return Ok;
1872 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1874 TRACE("(%p, %p)\n", brush, colors);
1876 if(!brush || !colors || brush->brush.bt != BrushTypeLinearGradient)
1877 return InvalidParameter;
1879 colors[0] = brush->startcolor;
1880 colors[1] = brush->endcolor;
1882 return Ok;
1885 /******************************************************************************
1886 * GdipRotateTextureTransform [GDIPLUS.@]
1888 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1889 GpMatrixOrder order)
1891 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1893 if(!brush)
1894 return InvalidParameter;
1896 return GdipRotateMatrix(&brush->transform, angle, order);
1899 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1900 REAL scale)
1902 REAL factors[3];
1903 REAL positions[3];
1904 int num_points = 0;
1906 TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1908 if (!brush) return InvalidParameter;
1910 if (focus != 0.0)
1912 factors[num_points] = 0.0;
1913 positions[num_points] = 0.0;
1914 num_points++;
1917 factors[num_points] = scale;
1918 positions[num_points] = focus;
1919 num_points++;
1921 if (focus != 1.0)
1923 factors[num_points] = 0.0;
1924 positions[num_points] = 1.0;
1925 num_points++;
1928 return GdipSetLineBlend(brush, factors, positions, num_points);
1931 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1932 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1934 ARGB *new_color;
1935 REAL *new_pos;
1936 TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1938 if (!brush || !blend || !positions || count < 2 || brush->brush.bt != BrushTypeLinearGradient ||
1939 positions[0] != 0.0f || positions[count-1] != 1.0f)
1941 return InvalidParameter;
1944 new_color = heap_alloc_zero(count * sizeof(ARGB));
1945 new_pos = heap_alloc_zero(count * sizeof(REAL));
1946 if (!new_color || !new_pos)
1948 heap_free(new_color);
1949 heap_free(new_pos);
1950 return OutOfMemory;
1953 memcpy(new_color, blend, sizeof(ARGB) * count);
1954 memcpy(new_pos, positions, sizeof(REAL) * count);
1956 heap_free(brush->pblendcolor);
1957 heap_free(brush->pblendpos);
1959 brush->pblendcolor = new_color;
1960 brush->pblendpos = new_pos;
1961 brush->pblendcount = count;
1963 return Ok;
1966 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1967 ARGB *blend, REAL* positions, INT count)
1969 if (!brush || !blend || !positions || count < 2 || brush->brush.bt != BrushTypeLinearGradient)
1970 return InvalidParameter;
1972 if (brush->pblendcount == 0)
1973 return GenericError;
1975 if (count < brush->pblendcount)
1976 return InsufficientBuffer;
1978 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1979 memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1981 return Ok;
1984 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1985 INT *count)
1987 if (!brush || !count || brush->brush.bt != BrushTypeLinearGradient)
1988 return InvalidParameter;
1990 *count = brush->pblendcount;
1992 return Ok;
1995 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1997 static int calls;
1999 TRACE("(%p)\n", brush);
2001 if(!(calls++))
2002 FIXME("not implemented\n");
2004 return NotImplemented;
2007 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
2008 GDIPCONST GpMatrix *matrix)
2010 static int calls;
2012 TRACE("(%p,%p)\n", brush, matrix);
2014 if(!(calls++))
2015 FIXME("not implemented\n");
2017 return NotImplemented;
2020 GpStatus WINGDIPAPI GdipGetLineTransform(GpLineGradient *brush, GpMatrix *matrix)
2022 static int calls;
2024 TRACE("(%p,%p)\n", brush, matrix);
2026 if(!(calls++))
2027 FIXME("not implemented\n");
2029 return NotImplemented;
2032 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
2033 GpMatrixOrder order)
2035 static int calls;
2037 TRACE("(%p,%0.2f,%0.2f,%u)\n", brush, sx, sy, order);
2039 if(!(calls++))
2040 FIXME("not implemented\n");
2042 return NotImplemented;
2045 GpStatus WINGDIPAPI GdipMultiplyLineTransform(GpLineGradient *brush,
2046 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
2048 static int calls;
2050 TRACE("(%p,%p,%u)\n", brush, matrix, order);
2052 if(!(calls++))
2053 FIXME("not implemented\n");
2055 return NotImplemented;
2058 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
2059 REAL dx, REAL dy, GpMatrixOrder order)
2061 static int calls;
2063 TRACE("(%p,%f,%f,%d)\n", brush, dx, dy, order);
2065 if(!(calls++))
2066 FIXME("not implemented\n");
2068 return Ok;
2071 /******************************************************************************
2072 * GdipTranslateTextureTransform [GDIPLUS.@]
2074 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
2075 GpMatrixOrder order)
2077 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
2079 if(!brush)
2080 return InvalidParameter;
2082 return GdipTranslateMatrix(&brush->transform, dx, dy, order);
2085 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
2087 TRACE("(%p, %p)\n", brush, rect);
2089 if(!brush || !rect || brush->brush.bt != BrushTypeLinearGradient)
2090 return InvalidParameter;
2092 *rect = brush->rect;
2094 return Ok;
2097 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
2099 GpRectF rectF;
2100 GpStatus ret;
2102 TRACE("(%p, %p)\n", brush, rect);
2104 if(!rect)
2105 return InvalidParameter;
2107 ret = GdipGetLineRect(brush, &rectF);
2109 if(ret == Ok){
2110 rect->X = gdip_round(rectF.X);
2111 rect->Y = gdip_round(rectF.Y);
2112 rect->Width = gdip_round(rectF.Width);
2113 rect->Height = gdip_round(rectF.Height);
2116 return ret;
2119 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
2120 REAL angle, GpMatrixOrder order)
2122 static int calls;
2124 TRACE("(%p,%0.2f,%u)\n", brush, angle, order);
2126 if(!brush || brush->brush.bt != BrushTypeLinearGradient)
2127 return InvalidParameter;
2129 if(!(calls++))
2130 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
2132 return NotImplemented;