gdiplus: Implement GdipSetPathGradientSigmaBlend.
[wine/multimedia.git] / dlls / gdiplus / brush.c
bloba2cf1f9ee80ffadba497430b3e25d149b81a24bb
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 = GdipAlloc(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 = GdipAlloc(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 GdipFree(dest);
78 return stat;
81 stat = GdipCloneMatrix(src->transform, &dest->transform);
83 if(stat != Ok){
84 GdipDeletePath(dest->path);
85 GdipFree(dest);
86 return stat;
89 /* blending */
90 count = src->blendcount;
91 dest->blendcount = count;
92 dest->blendfac = GdipAlloc(count * sizeof(REAL));
93 dest->blendpos = GdipAlloc(count * sizeof(REAL));
94 dest->surroundcolors = GdipAlloc(dest->surroundcolorcount * sizeof(ARGB));
95 pcount = dest->pblendcount;
96 if (pcount)
98 dest->pblendcolor = GdipAlloc(pcount * sizeof(ARGB));
99 dest->pblendpos = GdipAlloc(pcount * sizeof(REAL));
102 if(!dest->blendfac || !dest->blendpos || !dest->surroundcolors ||
103 (pcount && (!dest->pblendcolor || !dest->pblendpos))){
104 GdipDeletePath(dest->path);
105 GdipDeleteMatrix(dest->transform);
106 GdipFree(dest->blendfac);
107 GdipFree(dest->blendpos);
108 GdipFree(dest->surroundcolors);
109 GdipFree(dest->pblendcolor);
110 GdipFree(dest->pblendpos);
111 GdipFree(dest);
112 return OutOfMemory;
115 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
116 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
117 memcpy(dest->surroundcolors, src->surroundcolors, dest->surroundcolorcount * sizeof(ARGB));
119 if (pcount)
121 memcpy(dest->pblendcolor, src->pblendcolor, pcount * sizeof(ARGB));
122 memcpy(dest->pblendpos, src->pblendpos, pcount * sizeof(REAL));
125 break;
127 case BrushTypeLinearGradient:{
128 GpLineGradient *dest, *src;
129 INT count, pcount;
131 dest = GdipAlloc(sizeof(GpLineGradient));
132 if(!dest) return OutOfMemory;
134 src = (GpLineGradient*)brush;
136 memcpy(dest, src, sizeof(GpLineGradient));
138 count = dest->blendcount;
139 dest->blendfac = GdipAlloc(count * sizeof(REAL));
140 dest->blendpos = GdipAlloc(count * sizeof(REAL));
141 pcount = dest->pblendcount;
142 if (pcount)
144 dest->pblendcolor = GdipAlloc(pcount * sizeof(ARGB));
145 dest->pblendpos = GdipAlloc(pcount * sizeof(REAL));
148 if (!dest->blendfac || !dest->blendpos ||
149 (pcount && (!dest->pblendcolor || !dest->pblendpos)))
151 GdipFree(dest->blendfac);
152 GdipFree(dest->blendpos);
153 GdipFree(dest->pblendcolor);
154 GdipFree(dest->pblendpos);
155 GdipFree(dest);
156 return OutOfMemory;
159 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
160 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
162 if (pcount)
164 memcpy(dest->pblendcolor, src->pblendcolor, pcount * sizeof(ARGB));
165 memcpy(dest->pblendpos, src->pblendpos, pcount * sizeof(REAL));
168 *clone = &dest->brush;
169 break;
171 case BrushTypeTextureFill:
173 GpStatus stat;
174 GpTexture *texture = (GpTexture*)brush;
175 GpTexture *new_texture;
176 UINT width, height;
178 stat = GdipGetImageWidth(texture->image, &width);
179 if (stat != Ok) return stat;
180 stat = GdipGetImageHeight(texture->image, &height);
181 if (stat != Ok) return stat;
183 stat = GdipCreateTextureIA(texture->image, texture->imageattributes, 0, 0, width, height, &new_texture);
185 if (stat == Ok)
187 memcpy(new_texture->transform, texture->transform, sizeof(GpMatrix));
188 *clone = (GpBrush*)new_texture;
190 else
191 *clone = NULL;
193 return stat;
195 default:
196 ERR("not implemented for brush type %d\n", brush->bt);
197 return NotImplemented;
200 TRACE("<-- %p\n", *clone);
201 return Ok;
204 static const char HatchBrushes[][8] = {
205 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HatchStyleHorizontal */
206 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleVertical */
207 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HatchStyleForwardDiagonal */
208 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HatchStyleBackwardDiagonal */
209 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleCross */
210 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }, /* HatchStyleDiagonalCross */
211 { 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x80 }, /* HatchStyle05Percent */
212 { 0x00, 0x02, 0x00, 0x88, 0x00, 0x20, 0x00, 0x88 }, /* HatchStyle10Percent */
213 { 0x00, 0x22, 0x00, 0xcc, 0x00, 0x22, 0x00, 0xcc }, /* HatchStyle20Percent */
214 { 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc }, /* HatchStyle25Percent */
215 { 0x00, 0xcc, 0x04, 0xcc, 0x00, 0xcc, 0x40, 0xcc }, /* HatchStyle30Percent */
216 { 0x44, 0xcc, 0x22, 0xcc, 0x44, 0xcc, 0x22, 0xcc }, /* HatchStyle40Percent */
217 { 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc }, /* HatchStyle50Percent */
218 { 0x55, 0xcd, 0x55, 0xee, 0x55, 0xdc, 0x55, 0xee }, /* HatchStyle60Percent */
219 { 0x55, 0xdd, 0x55, 0xff, 0x55, 0xdd, 0x55, 0xff }, /* HatchStyle70Percent */
220 { 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff }, /* HatchStyle75Percent */
221 { 0x55, 0xff, 0x59, 0xff, 0x55, 0xff, 0x99, 0xff }, /* HatchStyle80Percent */
222 { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xfd, 0xff }, /* HatchStyle90Percent */
223 { 0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88 }, /* HatchStyleLightDownwardDiagonal */
224 { 0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11 }, /* HatchStyleLightUpwardDiagonal */
225 { 0x99, 0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc }, /* HatchStyleDarkDownwardDiagonal */
226 { 0xcc, 0x66, 0x33, 0x99, 0xcc, 0x66, 0x33, 0x99 }, /* HatchStyleDarkUpwardDiagonal */
227 { 0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0 }, /* HatchStyleWideDownwardDiagonal */
228 { 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x83, 0xc1 }, /* HatchStyleWideUpwardDiagonal */
229 { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 }, /* HatchStyleLightVertical */
230 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff }, /* HatchStyleLightHorizontal */
231 { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }, /* HatchStyleNarrowVertical */
232 { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, /* HatchStyleNarrowHorizontal */
233 { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }, /* HatchStyleDarkVertical */
234 { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff }, /* HatchStyleDarkHorizontal */
237 GpStatus get_hatch_data(HatchStyle hatchstyle, const char **result)
239 if (hatchstyle < sizeof(HatchBrushes) / sizeof(HatchBrushes[0]))
241 *result = HatchBrushes[hatchstyle];
242 return Ok;
244 else
245 return NotImplemented;
248 /******************************************************************************
249 * GdipCreateHatchBrush [GDIPLUS.@]
251 GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle hatchstyle, ARGB forecol, ARGB backcol, GpHatch **brush)
253 TRACE("(%d, %d, %d, %p)\n", hatchstyle, forecol, backcol, brush);
255 if(!brush) return InvalidParameter;
257 *brush = GdipAlloc(sizeof(GpHatch));
258 if (!*brush) return OutOfMemory;
260 (*brush)->brush.bt = BrushTypeHatchFill;
261 (*brush)->forecol = forecol;
262 (*brush)->backcol = backcol;
263 (*brush)->hatchstyle = hatchstyle;
264 TRACE("<-- %p\n", *brush);
266 return Ok;
269 /******************************************************************************
270 * GdipCreateLineBrush [GDIPLUS.@]
272 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
273 GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
274 GpWrapMode wrap, GpLineGradient **line)
276 TRACE("(%s, %s, %x, %x, %d, %p)\n", debugstr_pointf(startpoint),
277 debugstr_pointf(endpoint), startcolor, endcolor, wrap, line);
279 if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
280 return InvalidParameter;
282 if (startpoint->X == endpoint->X && startpoint->Y == endpoint->Y)
283 return OutOfMemory;
285 *line = GdipAlloc(sizeof(GpLineGradient));
286 if(!*line) return OutOfMemory;
288 (*line)->brush.bt = BrushTypeLinearGradient;
290 (*line)->startpoint.X = startpoint->X;
291 (*line)->startpoint.Y = startpoint->Y;
292 (*line)->endpoint.X = endpoint->X;
293 (*line)->endpoint.Y = endpoint->Y;
294 (*line)->startcolor = startcolor;
295 (*line)->endcolor = endcolor;
296 (*line)->wrap = wrap;
297 (*line)->gamma = FALSE;
299 (*line)->rect.X = (startpoint->X < endpoint->X ? startpoint->X: endpoint->X);
300 (*line)->rect.Y = (startpoint->Y < endpoint->Y ? startpoint->Y: endpoint->Y);
301 (*line)->rect.Width = fabs(startpoint->X - endpoint->X);
302 (*line)->rect.Height = fabs(startpoint->Y - endpoint->Y);
304 if ((*line)->rect.Width == 0)
306 (*line)->rect.X -= (*line)->rect.Height / 2.0f;
307 (*line)->rect.Width = (*line)->rect.Height;
309 else if ((*line)->rect.Height == 0)
311 (*line)->rect.Y -= (*line)->rect.Width / 2.0f;
312 (*line)->rect.Height = (*line)->rect.Width;
315 (*line)->blendcount = 1;
316 (*line)->blendfac = GdipAlloc(sizeof(REAL));
317 (*line)->blendpos = GdipAlloc(sizeof(REAL));
319 if (!(*line)->blendfac || !(*line)->blendpos)
321 GdipFree((*line)->blendfac);
322 GdipFree((*line)->blendpos);
323 GdipFree(*line);
324 *line = NULL;
325 return OutOfMemory;
328 (*line)->blendfac[0] = 1.0f;
329 (*line)->blendpos[0] = 1.0f;
331 (*line)->pblendcolor = NULL;
332 (*line)->pblendpos = NULL;
333 (*line)->pblendcount = 0;
335 TRACE("<-- %p\n", *line);
337 return Ok;
340 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
341 GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
342 GpWrapMode wrap, GpLineGradient **line)
344 GpPointF stF;
345 GpPointF endF;
347 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
348 startcolor, endcolor, wrap, line);
350 if(!startpoint || !endpoint)
351 return InvalidParameter;
353 stF.X = (REAL)startpoint->X;
354 stF.Y = (REAL)startpoint->Y;
355 endF.X = (REAL)endpoint->X;
356 endF.Y = (REAL)endpoint->Y;
358 return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
361 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
362 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
363 GpLineGradient **line)
365 GpPointF start, end;
366 GpStatus stat;
368 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
369 wrap, line);
371 if(!line || !rect)
372 return InvalidParameter;
374 switch (mode)
376 case LinearGradientModeHorizontal:
377 start.X = rect->X;
378 start.Y = rect->Y;
379 end.X = rect->X + rect->Width;
380 end.Y = rect->Y;
381 break;
382 case LinearGradientModeVertical:
383 start.X = rect->X;
384 start.Y = rect->Y;
385 end.X = rect->X;
386 end.Y = rect->Y + rect->Height;
387 break;
388 case LinearGradientModeForwardDiagonal:
389 start.X = rect->X;
390 start.Y = rect->Y;
391 end.X = rect->X + rect->Width;
392 end.Y = rect->Y + rect->Height;
393 break;
394 case LinearGradientModeBackwardDiagonal:
395 start.X = rect->X + rect->Width;
396 start.Y = rect->Y;
397 end.X = rect->X;
398 end.Y = rect->Y + rect->Height;
399 break;
400 default:
401 return InvalidParameter;
404 stat = GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
406 if (stat == Ok)
407 (*line)->rect = *rect;
409 return stat;
412 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
413 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
414 GpLineGradient **line)
416 GpRectF rectF;
418 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
419 wrap, line);
421 rectF.X = (REAL) rect->X;
422 rectF.Y = (REAL) rect->Y;
423 rectF.Width = (REAL) rect->Width;
424 rectF.Height = (REAL) rect->Height;
426 return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
429 /******************************************************************************
430 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
432 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
433 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
434 GpLineGradient **line)
436 GpStatus stat;
437 LinearGradientMode mode;
438 REAL width, height, exofs, eyofs;
439 REAL sin_angle, cos_angle, sin_cos_angle;
441 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
442 wrap, line);
444 sin_angle = sinf(deg2rad(angle));
445 cos_angle = cosf(deg2rad(angle));
446 sin_cos_angle = sin_angle * cos_angle;
448 if (isAngleScalable)
450 width = height = 1.0;
452 else
454 width = rect->Width;
455 height = rect->Height;
458 if (sin_cos_angle >= 0)
459 mode = LinearGradientModeForwardDiagonal;
460 else
461 mode = LinearGradientModeBackwardDiagonal;
463 stat = GdipCreateLineBrushFromRect(rect, startcolor, endcolor, mode, wrap, line);
465 if (stat == Ok)
467 if (sin_cos_angle >= 0)
469 exofs = width * sin_cos_angle + height * cos_angle * cos_angle;
470 eyofs = width * sin_angle * sin_angle + height * sin_cos_angle;
472 else
474 exofs = width * sin_angle * sin_angle + height * sin_cos_angle;
475 eyofs = -width * sin_cos_angle + height * sin_angle * sin_angle;
478 if (isAngleScalable)
480 exofs = exofs * rect->Width;
481 eyofs = eyofs * rect->Height;
484 if (sin_angle >= 0)
486 (*line)->endpoint.X = rect->X + exofs;
487 (*line)->endpoint.Y = rect->Y + eyofs;
489 else
491 (*line)->endpoint.X = (*line)->startpoint.X;
492 (*line)->endpoint.Y = (*line)->startpoint.Y;
493 (*line)->startpoint.X = rect->X + exofs;
494 (*line)->startpoint.Y = rect->Y + eyofs;
498 return stat;
501 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
502 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
503 GpLineGradient **line)
505 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
506 wrap, line);
508 return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
509 wrap, line);
512 static GpStatus create_path_gradient(GpPath *path, ARGB centercolor, GpPathGradient **grad)
514 GpRectF bounds;
515 GpStatus stat;
517 if(!path || !grad)
518 return InvalidParameter;
520 if (path->pathdata.Count < 2)
521 return OutOfMemory;
523 GdipGetPathWorldBounds(path, &bounds, NULL, NULL);
525 *grad = GdipAlloc(sizeof(GpPathGradient));
526 if (!*grad)
528 return OutOfMemory;
531 stat = GdipCreateMatrix(&(*grad)->transform);
532 if (stat != Ok)
534 GdipFree(*grad);
535 return stat;
538 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
539 (*grad)->blendpos = GdipAlloc(sizeof(REAL));
540 (*grad)->surroundcolors = GdipAlloc(sizeof(ARGB));
541 if(!(*grad)->blendfac || !(*grad)->blendpos || !(*grad)->surroundcolors){
542 GdipDeleteMatrix((*grad)->transform);
543 GdipFree((*grad)->blendfac);
544 GdipFree((*grad)->blendpos);
545 GdipFree((*grad)->surroundcolors);
546 GdipFree(*grad);
547 *grad = NULL;
548 return OutOfMemory;
550 (*grad)->blendfac[0] = 1.0;
551 (*grad)->blendpos[0] = 1.0;
552 (*grad)->blendcount = 1;
554 (*grad)->path = path;
556 (*grad)->brush.bt = BrushTypePathGradient;
557 (*grad)->centercolor = centercolor;
558 (*grad)->wrap = WrapModeClamp;
559 (*grad)->gamma = FALSE;
560 /* FIXME: this should be set to the "centroid" of the path by default */
561 (*grad)->center.X = bounds.X + bounds.Width / 2;
562 (*grad)->center.Y = bounds.Y + bounds.Height / 2;
563 (*grad)->focus.X = 0.0;
564 (*grad)->focus.Y = 0.0;
565 (*grad)->surroundcolors[0] = 0xffffffff;
566 (*grad)->surroundcolorcount = 1;
568 TRACE("<-- %p\n", *grad);
570 return Ok;
573 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
574 INT count, GpWrapMode wrap, GpPathGradient **grad)
576 GpStatus stat;
577 GpPath *path;
579 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
581 if(!points || !grad)
582 return InvalidParameter;
584 if(count <= 0)
585 return OutOfMemory;
587 stat = GdipCreatePath(FillModeAlternate, &path);
589 if (stat == Ok)
591 stat = GdipAddPathLine2(path, points, count);
593 if (stat == Ok)
594 stat = create_path_gradient(path, 0xff000000, grad);
596 if (stat != Ok)
597 GdipDeletePath(path);
600 if (stat == Ok)
601 (*grad)->wrap = wrap;
603 return stat;
606 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
607 INT count, GpWrapMode wrap, GpPathGradient **grad)
609 GpStatus stat;
610 GpPath *path;
612 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
614 if(!points || !grad)
615 return InvalidParameter;
617 if(count <= 0)
618 return OutOfMemory;
620 stat = GdipCreatePath(FillModeAlternate, &path);
622 if (stat == Ok)
624 stat = GdipAddPathLine2I(path, points, count);
626 if (stat == Ok)
627 stat = create_path_gradient(path, 0xff000000, grad);
629 if (stat != Ok)
630 GdipDeletePath(path);
633 if (stat == Ok)
634 (*grad)->wrap = wrap;
636 return stat;
639 /******************************************************************************
640 * GdipCreatePathGradientFromPath [GDIPLUS.@]
642 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
643 GpPathGradient **grad)
645 GpStatus stat;
646 GpPath *new_path;
648 TRACE("(%p, %p)\n", path, grad);
650 if(!path || !grad)
651 return InvalidParameter;
653 stat = GdipClonePath((GpPath*)path, &new_path);
655 if (stat == Ok)
657 stat = create_path_gradient(new_path, 0xffffffff, grad);
659 if (stat != Ok)
660 GdipDeletePath(new_path);
663 return stat;
666 /******************************************************************************
667 * GdipCreateSolidFill [GDIPLUS.@]
669 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
671 TRACE("(%x, %p)\n", color, sf);
673 if(!sf) return InvalidParameter;
675 *sf = GdipAlloc(sizeof(GpSolidFill));
676 if (!*sf) return OutOfMemory;
678 (*sf)->brush.bt = BrushTypeSolidColor;
679 (*sf)->color = color;
681 TRACE("<-- %p\n", *sf);
683 return Ok;
686 /******************************************************************************
687 * GdipCreateTexture [GDIPLUS.@]
689 * PARAMS
690 * image [I] image to use
691 * wrapmode [I] optional
692 * texture [O] pointer to the resulting texturebrush
694 * RETURNS
695 * SUCCESS: Ok
696 * FAILURE: element of GpStatus
698 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
699 GpTexture **texture)
701 UINT width, height;
702 GpImageAttributes *attributes;
703 GpStatus stat;
705 TRACE("%p, %d %p\n", image, wrapmode, texture);
707 if (!(image && texture))
708 return InvalidParameter;
710 stat = GdipGetImageWidth(image, &width);
711 if (stat != Ok) return stat;
712 stat = GdipGetImageHeight(image, &height);
713 if (stat != Ok) return stat;
715 stat = GdipCreateImageAttributes(&attributes);
717 if (stat == Ok)
719 attributes->wrap = wrapmode;
721 stat = GdipCreateTextureIA(image, attributes, 0, 0, width, height,
722 texture);
724 GdipDisposeImageAttributes(attributes);
727 return stat;
730 /******************************************************************************
731 * GdipCreateTexture2 [GDIPLUS.@]
733 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
734 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
736 GpImageAttributes *attributes;
737 GpStatus stat;
739 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
740 x, y, width, height, texture);
742 stat = GdipCreateImageAttributes(&attributes);
744 if (stat == Ok)
746 attributes->wrap = wrapmode;
748 stat = GdipCreateTextureIA(image, attributes, x, y, width, height,
749 texture);
751 GdipDisposeImageAttributes(attributes);
754 return stat;
757 /******************************************************************************
758 * GdipCreateTextureIA [GDIPLUS.@]
760 * FIXME: imageattr ignored
762 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
763 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
764 REAL height, GpTexture **texture)
766 GpStatus status;
767 GpImage *new_image=NULL;
769 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
770 texture);
772 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
773 return InvalidParameter;
775 *texture = NULL;
777 if(image->type != ImageTypeBitmap){
778 FIXME("not implemented for image type %d\n", image->type);
779 return NotImplemented;
782 status = GdipCloneBitmapArea(x, y, width, height, PixelFormatDontCare, (GpBitmap*)image, (GpBitmap**)&new_image);
783 if (status != Ok)
784 return status;
786 *texture = GdipAlloc(sizeof(GpTexture));
787 if (!*texture){
788 status = OutOfMemory;
789 goto exit;
792 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
793 goto exit;
796 if (imageattr)
798 status = GdipCloneImageAttributes(imageattr, &(*texture)->imageattributes);
800 else
802 status = GdipCreateImageAttributes(&(*texture)->imageattributes);
803 if (status == Ok)
804 (*texture)->imageattributes->wrap = WrapModeTile;
806 if (status == Ok)
808 (*texture)->brush.bt = BrushTypeTextureFill;
809 (*texture)->image = new_image;
812 exit:
813 if (status == Ok)
815 TRACE("<-- %p\n", *texture);
817 else
819 if (*texture)
821 GdipDeleteMatrix((*texture)->transform);
822 GdipDisposeImageAttributes((*texture)->imageattributes);
823 GdipFree(*texture);
824 *texture = NULL;
826 GdipDisposeImage(new_image);
827 TRACE("<-- error %u\n", status);
830 return status;
833 /******************************************************************************
834 * GdipCreateTextureIAI [GDIPLUS.@]
836 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
837 INT x, INT y, INT width, INT height, GpTexture **texture)
839 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
840 texture);
842 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
845 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
846 INT x, INT y, INT width, INT height, GpTexture **texture)
848 GpImageAttributes *imageattr;
849 GpStatus stat;
851 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
852 texture);
854 stat = GdipCreateImageAttributes(&imageattr);
856 if (stat == Ok)
858 imageattr->wrap = wrapmode;
860 stat = GdipCreateTextureIA(image, imageattr, x, y, width, height, texture);
863 return stat;
866 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
868 TRACE("(%p, %p)\n", brush, type);
870 if(!brush || !type) return InvalidParameter;
872 *type = brush->bt;
874 return Ok;
877 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
879 TRACE("(%p, %p)\n", brush, backcol);
881 if(!brush || !backcol) return InvalidParameter;
883 *backcol = brush->backcol;
885 return Ok;
888 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
890 TRACE("(%p, %p)\n", brush, forecol);
892 if(!brush || !forecol) return InvalidParameter;
894 *forecol = brush->forecol;
896 return Ok;
899 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
901 TRACE("(%p, %p)\n", brush, hatchstyle);
903 if(!brush || !hatchstyle) return InvalidParameter;
905 *hatchstyle = brush->hatchstyle;
907 return Ok;
910 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
912 TRACE("(%p)\n", brush);
914 if(!brush) return InvalidParameter;
916 switch(brush->bt)
918 case BrushTypePathGradient:
919 GdipDeletePath(((GpPathGradient*) brush)->path);
920 GdipDeleteMatrix(((GpPathGradient*) brush)->transform);
921 GdipFree(((GpPathGradient*) brush)->blendfac);
922 GdipFree(((GpPathGradient*) brush)->blendpos);
923 GdipFree(((GpPathGradient*) brush)->surroundcolors);
924 GdipFree(((GpPathGradient*) brush)->pblendcolor);
925 GdipFree(((GpPathGradient*) brush)->pblendpos);
926 break;
927 case BrushTypeLinearGradient:
928 GdipFree(((GpLineGradient*)brush)->blendfac);
929 GdipFree(((GpLineGradient*)brush)->blendpos);
930 GdipFree(((GpLineGradient*)brush)->pblendcolor);
931 GdipFree(((GpLineGradient*)brush)->pblendpos);
932 break;
933 case BrushTypeTextureFill:
934 GdipDeleteMatrix(((GpTexture*)brush)->transform);
935 GdipDisposeImage(((GpTexture*)brush)->image);
936 GdipDisposeImageAttributes(((GpTexture*)brush)->imageattributes);
937 GdipFree(((GpTexture*)brush)->bitmap_bits);
938 break;
939 default:
940 break;
943 GdipFree(brush);
945 return Ok;
948 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
949 BOOL *usinggamma)
951 TRACE("(%p, %p)\n", line, usinggamma);
953 if(!line || !usinggamma)
954 return InvalidParameter;
956 *usinggamma = line->gamma;
958 return Ok;
961 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
963 TRACE("(%p, %p)\n", brush, wrapmode);
965 if(!brush || !wrapmode)
966 return InvalidParameter;
968 *wrapmode = brush->wrap;
970 return Ok;
973 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
974 REAL *positions, INT count)
976 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
978 if(!brush || !blend || !positions || count <= 0)
979 return InvalidParameter;
981 if(count < brush->blendcount)
982 return InsufficientBuffer;
984 memcpy(blend, brush->blendfac, count*sizeof(REAL));
985 if(brush->blendcount > 1){
986 memcpy(positions, brush->blendpos, count*sizeof(REAL));
989 return Ok;
992 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
994 TRACE("(%p, %p)\n", brush, count);
996 if(!brush || !count)
997 return InvalidParameter;
999 *count = brush->blendcount;
1001 return Ok;
1004 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
1005 GpPointF *point)
1007 TRACE("(%p, %p)\n", grad, point);
1009 if(!grad || !point)
1010 return InvalidParameter;
1012 point->X = grad->center.X;
1013 point->Y = grad->center.Y;
1015 return Ok;
1018 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
1019 GpPoint *point)
1021 GpStatus ret;
1022 GpPointF ptf;
1024 TRACE("(%p, %p)\n", grad, point);
1026 if(!point)
1027 return InvalidParameter;
1029 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
1031 if(ret == Ok){
1032 point->X = roundr(ptf.X);
1033 point->Y = roundr(ptf.Y);
1036 return ret;
1039 GpStatus WINGDIPAPI GdipGetPathGradientCenterColor(GpPathGradient *grad,
1040 ARGB *colors)
1042 TRACE("(%p,%p)\n", grad, colors);
1044 if (!grad || !colors)
1045 return InvalidParameter;
1047 *colors = grad->centercolor;
1049 return Ok;
1052 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
1053 REAL *x, REAL *y)
1055 TRACE("(%p, %p, %p)\n", grad, x, y);
1057 if(!grad || !x || !y)
1058 return InvalidParameter;
1060 *x = grad->focus.X;
1061 *y = grad->focus.Y;
1063 return Ok;
1066 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1067 BOOL *gamma)
1069 TRACE("(%p, %p)\n", grad, gamma);
1071 if(!grad || !gamma)
1072 return InvalidParameter;
1074 *gamma = grad->gamma;
1076 return Ok;
1079 GpStatus WINGDIPAPI GdipGetPathGradientPath(GpPathGradient *grad, GpPath *path)
1081 static int calls;
1083 TRACE("(%p, %p)\n", grad, path);
1085 if (!(calls++))
1086 FIXME("not implemented\n");
1088 return NotImplemented;
1091 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1092 INT *count)
1094 TRACE("(%p, %p)\n", grad, count);
1096 if(!grad || !count)
1097 return InvalidParameter;
1099 *count = grad->path->pathdata.Count;
1101 return Ok;
1104 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1106 GpStatus stat;
1108 TRACE("(%p, %p)\n", brush, rect);
1110 if(!brush || !rect)
1111 return InvalidParameter;
1113 stat = GdipGetPathWorldBounds(brush->path, rect, NULL, NULL);
1115 return stat;
1118 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1120 GpRectF rectf;
1121 GpStatus stat;
1123 TRACE("(%p, %p)\n", brush, rect);
1125 if(!brush || !rect)
1126 return InvalidParameter;
1128 stat = GdipGetPathGradientRect(brush, &rectf);
1129 if(stat != Ok) return stat;
1131 rect->X = roundr(rectf.X);
1132 rect->Y = roundr(rectf.Y);
1133 rect->Width = roundr(rectf.Width);
1134 rect->Height = roundr(rectf.Height);
1136 return Ok;
1139 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1140 *grad, ARGB *argb, INT *count)
1142 INT i;
1144 TRACE("(%p,%p,%p)\n", grad, argb, count);
1146 if(!grad || !argb || !count || (*count < grad->path->pathdata.Count))
1147 return InvalidParameter;
1149 for (i=0; i<grad->path->pathdata.Count; i++)
1151 if (i < grad->surroundcolorcount)
1152 argb[i] = grad->surroundcolors[i];
1153 else
1154 argb[i] = grad->surroundcolors[grad->surroundcolorcount-1];
1157 *count = grad->surroundcolorcount;
1159 return Ok;
1162 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorCount(GpPathGradient *brush, INT *count)
1164 TRACE("(%p, %p)\n", brush, count);
1166 if (!brush || !count)
1167 return InvalidParameter;
1169 /* Yes, this actually returns the number of points in the path (which is the
1170 * required size of a buffer to get the surround colors), rather than the
1171 * number of surround colors. The real count is returned when getting the
1172 * colors. */
1173 *count = brush->path->pathdata.Count;
1175 return Ok;
1178 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1179 GpWrapMode *wrapmode)
1181 TRACE("(%p, %p)\n", brush, wrapmode);
1183 if(!brush || !wrapmode)
1184 return InvalidParameter;
1186 *wrapmode = brush->wrap;
1188 return Ok;
1191 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1193 TRACE("(%p, %p)\n", sf, argb);
1195 if(!sf || !argb)
1196 return InvalidParameter;
1198 *argb = sf->color;
1200 return Ok;
1203 /******************************************************************************
1204 * GdipGetTextureImage [GDIPLUS.@]
1206 GpStatus WINGDIPAPI GdipGetTextureImage(GpTexture *brush, GpImage **image)
1208 TRACE("(%p, %p)\n", brush, image);
1210 if(!brush || !image)
1211 return InvalidParameter;
1213 return GdipCloneImage(brush->image, image);
1216 /******************************************************************************
1217 * GdipGetTextureTransform [GDIPLUS.@]
1219 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1221 TRACE("(%p, %p)\n", brush, matrix);
1223 if(!brush || !matrix)
1224 return InvalidParameter;
1226 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1228 return Ok;
1231 /******************************************************************************
1232 * GdipGetTextureWrapMode [GDIPLUS.@]
1234 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1236 TRACE("(%p, %p)\n", brush, wrapmode);
1238 if(!brush || !wrapmode)
1239 return InvalidParameter;
1241 *wrapmode = brush->imageattributes->wrap;
1243 return Ok;
1246 /******************************************************************************
1247 * GdipMultiplyTextureTransform [GDIPLUS.@]
1249 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1250 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1252 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1254 if(!brush || !matrix)
1255 return InvalidParameter;
1257 return GdipMultiplyMatrix(brush->transform, matrix, order);
1260 /******************************************************************************
1261 * GdipResetTextureTransform [GDIPLUS.@]
1263 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1265 TRACE("(%p)\n", brush);
1267 if(!brush)
1268 return InvalidParameter;
1270 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1273 /******************************************************************************
1274 * GdipScaleTextureTransform [GDIPLUS.@]
1276 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1277 REAL sx, REAL sy, GpMatrixOrder order)
1279 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1281 if(!brush)
1282 return InvalidParameter;
1284 return GdipScaleMatrix(brush->transform, sx, sy, order);
1287 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1288 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1290 REAL *new_blendfac, *new_blendpos;
1292 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1294 if(!brush || !factors || !positions || count <= 0 ||
1295 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1296 return InvalidParameter;
1298 new_blendfac = GdipAlloc(count * sizeof(REAL));
1299 new_blendpos = GdipAlloc(count * sizeof(REAL));
1301 if (!new_blendfac || !new_blendpos)
1303 GdipFree(new_blendfac);
1304 GdipFree(new_blendpos);
1305 return OutOfMemory;
1308 memcpy(new_blendfac, factors, count * sizeof(REAL));
1309 memcpy(new_blendpos, positions, count * sizeof(REAL));
1311 GdipFree(brush->blendfac);
1312 GdipFree(brush->blendpos);
1314 brush->blendcount = count;
1315 brush->blendfac = new_blendfac;
1316 brush->blendpos = new_blendpos;
1318 return Ok;
1321 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1322 REAL *positions, INT count)
1324 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1326 if (!brush || !factors || !positions || count <= 0)
1327 return InvalidParameter;
1329 if (count < brush->blendcount)
1330 return InsufficientBuffer;
1332 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1333 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1335 return Ok;
1338 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1340 TRACE("(%p, %p)\n", brush, count);
1342 if (!brush || !count)
1343 return InvalidParameter;
1345 *count = brush->blendcount;
1347 return Ok;
1350 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1351 BOOL usegamma)
1353 TRACE("(%p, %d)\n", line, usegamma);
1355 if(!line)
1356 return InvalidParameter;
1358 line->gamma = usegamma;
1360 return Ok;
1363 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1364 REAL scale)
1366 REAL factors[33];
1367 REAL positions[33];
1368 int num_points = 0;
1369 int i;
1370 const int precision = 16;
1371 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1372 REAL min_erf;
1373 REAL scale_erf;
1375 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1377 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1378 return InvalidParameter;
1380 /* we want 2 standard deviations */
1381 erf_range = 2.0 / sqrt(2);
1383 /* calculate the constants we need to normalize the error function to be
1384 between 0.0 and scale over the range we need */
1385 min_erf = erf(-erf_range);
1386 scale_erf = scale / (-2.0 * min_erf);
1388 if (focus != 0.0)
1390 positions[0] = 0.0;
1391 factors[0] = 0.0;
1392 for (i=1; i<precision; i++)
1394 positions[i] = focus * i / precision;
1395 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1397 num_points += precision;
1400 positions[num_points] = focus;
1401 factors[num_points] = scale;
1402 num_points += 1;
1404 if (focus != 1.0)
1406 for (i=1; i<precision; i++)
1408 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1409 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1411 num_points += precision;
1412 positions[num_points-1] = 1.0;
1413 factors[num_points-1] = 0.0;
1416 return GdipSetLineBlend(line, factors, positions, num_points);
1419 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1420 GpWrapMode wrap)
1422 TRACE("(%p, %d)\n", line, wrap);
1424 if(!line || wrap == WrapModeClamp)
1425 return InvalidParameter;
1427 line->wrap = wrap;
1429 return Ok;
1432 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1433 GDIPCONST REAL *pos, INT count)
1435 REAL *new_blendfac, *new_blendpos;
1437 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1439 if(!brush || !blend || !pos || count <= 0 ||
1440 (count >= 2 && (pos[0] != 0.0f || pos[count-1] != 1.0f)))
1441 return InvalidParameter;
1443 new_blendfac = GdipAlloc(count * sizeof(REAL));
1444 new_blendpos = GdipAlloc(count * sizeof(REAL));
1446 if (!new_blendfac || !new_blendpos)
1448 GdipFree(new_blendfac);
1449 GdipFree(new_blendpos);
1450 return OutOfMemory;
1453 memcpy(new_blendfac, blend, count * sizeof(REAL));
1454 memcpy(new_blendpos, pos, count * sizeof(REAL));
1456 GdipFree(brush->blendfac);
1457 GdipFree(brush->blendpos);
1459 brush->blendcount = count;
1460 brush->blendfac = new_blendfac;
1461 brush->blendpos = new_blendpos;
1463 return Ok;
1466 GpStatus WINGDIPAPI GdipSetPathGradientLinearBlend(GpPathGradient *brush,
1467 REAL focus, REAL scale)
1469 REAL factors[3];
1470 REAL positions[3];
1471 int num_points = 0;
1473 TRACE("(%p,%0.2f,%0.2f)\n", brush, focus, scale);
1475 if (!brush) return InvalidParameter;
1477 if (focus != 0.0)
1479 factors[num_points] = 0.0;
1480 positions[num_points] = 0.0;
1481 num_points++;
1484 factors[num_points] = scale;
1485 positions[num_points] = focus;
1486 num_points++;
1488 if (focus != 1.0)
1490 factors[num_points] = 0.0;
1491 positions[num_points] = 1.0;
1492 num_points++;
1495 return GdipSetPathGradientBlend(brush, factors, positions, num_points);
1498 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1499 GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1501 ARGB *new_color;
1502 REAL *new_pos;
1503 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1505 if (!brush || !blend || !pos || count < 2 ||
1506 pos[0] != 0.0f || pos[count-1] != 1.0f)
1508 return InvalidParameter;
1511 new_color = GdipAlloc(count * sizeof(ARGB));
1512 new_pos = GdipAlloc(count * sizeof(REAL));
1513 if (!new_color || !new_pos)
1515 GdipFree(new_color);
1516 GdipFree(new_pos);
1517 return OutOfMemory;
1520 memcpy(new_color, blend, sizeof(ARGB) * count);
1521 memcpy(new_pos, pos, sizeof(REAL) * count);
1523 GdipFree(brush->pblendcolor);
1524 GdipFree(brush->pblendpos);
1526 brush->pblendcolor = new_color;
1527 brush->pblendpos = new_pos;
1528 brush->pblendcount = count;
1530 return Ok;
1533 GpStatus WINGDIPAPI GdipGetPathGradientPresetBlend(GpPathGradient *brush,
1534 ARGB *blend, REAL *pos, INT count)
1536 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1538 if (count < 0)
1539 return OutOfMemory;
1541 if (!brush || !blend || !pos || count < 2)
1542 return InvalidParameter;
1544 if (brush->pblendcount == 0)
1545 return GenericError;
1547 if (count != brush->pblendcount)
1549 /* Native lines up the ends of each array, and copies the destination size. */
1550 FIXME("Braindead behavior on wrong-sized buffer not implemented.\n");
1551 return InvalidParameter;
1554 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1555 memcpy(pos, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1557 return Ok;
1560 GpStatus WINGDIPAPI GdipGetPathGradientPresetBlendCount(GpPathGradient *brush,
1561 INT *count)
1563 TRACE("(%p,%p)\n", brush, count);
1565 if (!brush || !count)
1566 return InvalidParameter;
1568 *count = brush->pblendcount;
1570 return Ok;
1573 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1574 ARGB argb)
1576 TRACE("(%p, %x)\n", grad, argb);
1578 if(!grad)
1579 return InvalidParameter;
1581 grad->centercolor = argb;
1582 return Ok;
1585 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1586 GpPointF *point)
1588 TRACE("(%p, %s)\n", grad, debugstr_pointf(point));
1590 if(!grad || !point)
1591 return InvalidParameter;
1593 grad->center.X = point->X;
1594 grad->center.Y = point->Y;
1596 return Ok;
1599 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1600 GpPoint *point)
1602 GpPointF ptf;
1604 TRACE("(%p, %p)\n", grad, point);
1606 if(!point)
1607 return InvalidParameter;
1609 ptf.X = (REAL)point->X;
1610 ptf.Y = (REAL)point->Y;
1612 return GdipSetPathGradientCenterPoint(grad,&ptf);
1615 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1616 REAL x, REAL y)
1618 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1620 if(!grad)
1621 return InvalidParameter;
1623 grad->focus.X = x;
1624 grad->focus.Y = y;
1626 return Ok;
1629 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1630 BOOL gamma)
1632 TRACE("(%p, %d)\n", grad, gamma);
1634 if(!grad)
1635 return InvalidParameter;
1637 grad->gamma = gamma;
1639 return Ok;
1642 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1643 REAL focus, REAL scale)
1645 REAL factors[33];
1646 REAL positions[33];
1647 int num_points = 0;
1648 int i;
1649 const int precision = 16;
1650 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1651 REAL min_erf;
1652 REAL scale_erf;
1654 TRACE("(%p,%0.2f,%0.2f)\n", grad, focus, scale);
1656 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1657 return InvalidParameter;
1659 /* we want 2 standard deviations */
1660 erf_range = 2.0 / sqrt(2);
1662 /* calculate the constants we need to normalize the error function to be
1663 between 0.0 and scale over the range we need */
1664 min_erf = erf(-erf_range);
1665 scale_erf = scale / (-2.0 * min_erf);
1667 if (focus != 0.0)
1669 positions[0] = 0.0;
1670 factors[0] = 0.0;
1671 for (i=1; i<precision; i++)
1673 positions[i] = focus * i / precision;
1674 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1676 num_points += precision;
1679 positions[num_points] = focus;
1680 factors[num_points] = scale;
1681 num_points += 1;
1683 if (focus != 1.0)
1685 for (i=1; i<precision; i++)
1687 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1688 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1690 num_points += precision;
1691 positions[num_points-1] = 1.0;
1692 factors[num_points-1] = 0.0;
1695 return GdipSetPathGradientBlend(grad, factors, positions, num_points);
1698 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1699 *grad, GDIPCONST ARGB *argb, INT *count)
1701 ARGB *new_surroundcolors;
1703 TRACE("(%p,%p,%p)\n", grad, argb, count);
1705 if(!grad || !argb || !count || (*count <= 0) ||
1706 (*count > grad->path->pathdata.Count))
1707 return InvalidParameter;
1709 new_surroundcolors = GdipAlloc(*count * sizeof(ARGB));
1710 if (!new_surroundcolors)
1711 return OutOfMemory;
1713 memcpy(new_surroundcolors, argb, *count * sizeof(ARGB));
1715 GdipFree(grad->surroundcolors);
1717 grad->surroundcolors = new_surroundcolors;
1718 grad->surroundcolorcount = *count;
1720 return Ok;
1723 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1724 GpWrapMode wrap)
1726 TRACE("(%p, %d)\n", grad, wrap);
1728 if(!grad)
1729 return InvalidParameter;
1731 grad->wrap = wrap;
1733 return Ok;
1736 GpStatus WINGDIPAPI GdipSetPathGradientTransform(GpPathGradient *grad,
1737 GpMatrix *matrix)
1739 TRACE("(%p,%p)\n", grad, matrix);
1741 if (!grad || !matrix)
1742 return InvalidParameter;
1744 memcpy(grad->transform, matrix, sizeof(GpMatrix));
1746 return Ok;
1749 GpStatus WINGDIPAPI GdipGetPathGradientTransform(GpPathGradient *grad,
1750 GpMatrix *matrix)
1752 TRACE("(%p,%p)\n", grad, matrix);
1754 if (!grad || !matrix)
1755 return InvalidParameter;
1757 memcpy(matrix, grad->transform, sizeof(GpMatrix));
1759 return Ok;
1762 GpStatus WINGDIPAPI GdipMultiplyPathGradientTransform(GpPathGradient *grad,
1763 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1765 TRACE("(%p,%p,%i)\n", grad, matrix, order);
1767 if (!grad)
1768 return InvalidParameter;
1770 return GdipMultiplyMatrix(grad->transform, matrix, order);
1773 GpStatus WINGDIPAPI GdipResetPathGradientTransform(GpPathGradient *grad)
1775 TRACE("(%p)\n", grad);
1777 if (!grad)
1778 return InvalidParameter;
1780 return GdipSetMatrixElements(grad->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1783 GpStatus WINGDIPAPI GdipRotatePathGradientTransform(GpPathGradient *grad,
1784 REAL angle, GpMatrixOrder order)
1786 TRACE("(%p,%0.2f,%i)\n", grad, angle, order);
1788 if (!grad)
1789 return InvalidParameter;
1791 return GdipRotateMatrix(grad->transform, angle, order);
1794 GpStatus WINGDIPAPI GdipScalePathGradientTransform(GpPathGradient *grad,
1795 REAL sx, REAL sy, GpMatrixOrder order)
1797 TRACE("(%p,%0.2f,%0.2f,%i)\n", grad, sx, sy, order);
1799 if (!grad)
1800 return InvalidParameter;
1802 return GdipScaleMatrix(grad->transform, sx, sy, order);
1805 GpStatus WINGDIPAPI GdipTranslatePathGradientTransform(GpPathGradient *grad,
1806 REAL dx, REAL dy, GpMatrixOrder order)
1808 TRACE("(%p,%0.2f,%0.2f,%i)\n", grad, dx, dy, order);
1810 if (!grad)
1811 return InvalidParameter;
1813 return GdipTranslateMatrix(grad->transform, dx, dy, order);
1816 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1818 TRACE("(%p, %x)\n", sf, argb);
1820 if(!sf)
1821 return InvalidParameter;
1823 sf->color = argb;
1824 return Ok;
1827 /******************************************************************************
1828 * GdipSetTextureTransform [GDIPLUS.@]
1830 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1831 GDIPCONST GpMatrix *matrix)
1833 TRACE("(%p, %p)\n", texture, matrix);
1835 if(!texture || !matrix)
1836 return InvalidParameter;
1838 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1840 return Ok;
1843 /******************************************************************************
1844 * GdipSetTextureWrapMode [GDIPLUS.@]
1846 * WrapMode not used, only stored
1848 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1850 TRACE("(%p, %d)\n", brush, wrapmode);
1852 if(!brush)
1853 return InvalidParameter;
1855 brush->imageattributes->wrap = wrapmode;
1857 return Ok;
1860 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1861 ARGB color2)
1863 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1865 if(!brush)
1866 return InvalidParameter;
1868 brush->startcolor = color1;
1869 brush->endcolor = color2;
1871 return Ok;
1874 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1876 TRACE("(%p, %p)\n", brush, colors);
1878 if(!brush || !colors)
1879 return InvalidParameter;
1881 colors[0] = brush->startcolor;
1882 colors[1] = brush->endcolor;
1884 return Ok;
1887 /******************************************************************************
1888 * GdipRotateTextureTransform [GDIPLUS.@]
1890 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1891 GpMatrixOrder order)
1893 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1895 if(!brush)
1896 return InvalidParameter;
1898 return GdipRotateMatrix(brush->transform, angle, order);
1901 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1902 REAL scale)
1904 REAL factors[3];
1905 REAL positions[3];
1906 int num_points = 0;
1908 TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1910 if (!brush) return InvalidParameter;
1912 if (focus != 0.0)
1914 factors[num_points] = 0.0;
1915 positions[num_points] = 0.0;
1916 num_points++;
1919 factors[num_points] = scale;
1920 positions[num_points] = focus;
1921 num_points++;
1923 if (focus != 1.0)
1925 factors[num_points] = 0.0;
1926 positions[num_points] = 1.0;
1927 num_points++;
1930 return GdipSetLineBlend(brush, factors, positions, num_points);
1933 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1934 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1936 ARGB *new_color;
1937 REAL *new_pos;
1938 TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1940 if (!brush || !blend || !positions || count < 2 ||
1941 positions[0] != 0.0f || positions[count-1] != 1.0f)
1943 return InvalidParameter;
1946 new_color = GdipAlloc(count * sizeof(ARGB));
1947 new_pos = GdipAlloc(count * sizeof(REAL));
1948 if (!new_color || !new_pos)
1950 GdipFree(new_color);
1951 GdipFree(new_pos);
1952 return OutOfMemory;
1955 memcpy(new_color, blend, sizeof(ARGB) * count);
1956 memcpy(new_pos, positions, sizeof(REAL) * count);
1958 GdipFree(brush->pblendcolor);
1959 GdipFree(brush->pblendpos);
1961 brush->pblendcolor = new_color;
1962 brush->pblendpos = new_pos;
1963 brush->pblendcount = count;
1965 return Ok;
1968 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1969 ARGB *blend, REAL* positions, INT count)
1971 if (!brush || !blend || !positions || count < 2)
1972 return InvalidParameter;
1974 if (brush->pblendcount == 0)
1975 return GenericError;
1977 if (count < brush->pblendcount)
1978 return InsufficientBuffer;
1980 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1981 memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1983 return Ok;
1986 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1987 INT *count)
1989 if (!brush || !count)
1990 return InvalidParameter;
1992 *count = brush->pblendcount;
1994 return Ok;
1997 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1999 static int calls;
2001 TRACE("(%p)\n", brush);
2003 if(!(calls++))
2004 FIXME("not implemented\n");
2006 return NotImplemented;
2009 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
2010 GDIPCONST GpMatrix *matrix)
2012 static int calls;
2014 TRACE("(%p,%p)\n", brush, matrix);
2016 if(!(calls++))
2017 FIXME("not implemented\n");
2019 return NotImplemented;
2022 GpStatus WINGDIPAPI GdipGetLineTransform(GpLineGradient *brush, GpMatrix *matrix)
2024 static int calls;
2026 TRACE("(%p,%p)\n", brush, matrix);
2028 if(!(calls++))
2029 FIXME("not implemented\n");
2031 return NotImplemented;
2034 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
2035 GpMatrixOrder order)
2037 static int calls;
2039 TRACE("(%p,%0.2f,%0.2f,%u)\n", brush, sx, sy, order);
2041 if(!(calls++))
2042 FIXME("not implemented\n");
2044 return NotImplemented;
2047 GpStatus WINGDIPAPI GdipMultiplyLineTransform(GpLineGradient *brush,
2048 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
2050 static int calls;
2052 TRACE("(%p,%p,%u)\n", brush, matrix, order);
2054 if(!(calls++))
2055 FIXME("not implemented\n");
2057 return NotImplemented;
2060 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
2061 REAL dx, REAL dy, GpMatrixOrder order)
2063 static int calls;
2065 TRACE("(%p,%f,%f,%d)\n", brush, dx, dy, order);
2067 if(!(calls++))
2068 FIXME("not implemented\n");
2070 return Ok;
2073 /******************************************************************************
2074 * GdipTranslateTextureTransform [GDIPLUS.@]
2076 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
2077 GpMatrixOrder order)
2079 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
2081 if(!brush)
2082 return InvalidParameter;
2084 return GdipTranslateMatrix(brush->transform, dx, dy, order);
2087 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
2089 TRACE("(%p, %p)\n", brush, rect);
2091 if(!brush || !rect)
2092 return InvalidParameter;
2094 *rect = brush->rect;
2096 return Ok;
2099 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
2101 GpRectF rectF;
2102 GpStatus ret;
2104 TRACE("(%p, %p)\n", brush, rect);
2106 if(!rect)
2107 return InvalidParameter;
2109 ret = GdipGetLineRect(brush, &rectF);
2111 if(ret == Ok){
2112 rect->X = roundr(rectF.X);
2113 rect->Y = roundr(rectF.Y);
2114 rect->Width = roundr(rectF.Width);
2115 rect->Height = roundr(rectF.Height);
2118 return ret;
2121 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
2122 REAL angle, GpMatrixOrder order)
2124 static int calls;
2126 TRACE("(%p,%0.2f,%u)\n", brush, angle, order);
2128 if(!brush)
2129 return InvalidParameter;
2131 if(!(calls++))
2132 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
2134 return NotImplemented;