gdiplus: Default path gradient center color depends on the constructor.
[wine/multimedia.git] / dlls / gdiplus / brush.c
blob41b38a0e427e922117a3bb162b8948eb035b87a4
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 return stat;
603 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
604 INT count, GpWrapMode wrap, GpPathGradient **grad)
606 GpStatus stat;
607 GpPath *path;
609 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
611 if(!points || !grad)
612 return InvalidParameter;
614 if(count <= 0)
615 return OutOfMemory;
617 stat = GdipCreatePath(FillModeAlternate, &path);
619 if (stat == Ok)
621 stat = GdipAddPathLine2I(path, points, count);
623 if (stat == Ok)
624 stat = create_path_gradient(path, 0xff000000, grad);
626 if (stat != Ok)
627 GdipDeletePath(path);
630 return stat;
633 /******************************************************************************
634 * GdipCreatePathGradientFromPath [GDIPLUS.@]
636 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
637 GpPathGradient **grad)
639 GpStatus stat;
640 GpPath *new_path;
642 TRACE("(%p, %p)\n", path, grad);
644 if(!path || !grad)
645 return InvalidParameter;
647 stat = GdipClonePath((GpPath*)path, &new_path);
649 if (stat == Ok)
651 stat = create_path_gradient(new_path, 0xffffffff, grad);
653 if (stat != Ok)
654 GdipDeletePath(new_path);
657 return stat;
660 /******************************************************************************
661 * GdipCreateSolidFill [GDIPLUS.@]
663 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
665 TRACE("(%x, %p)\n", color, sf);
667 if(!sf) return InvalidParameter;
669 *sf = GdipAlloc(sizeof(GpSolidFill));
670 if (!*sf) return OutOfMemory;
672 (*sf)->brush.bt = BrushTypeSolidColor;
673 (*sf)->color = color;
675 TRACE("<-- %p\n", *sf);
677 return Ok;
680 /******************************************************************************
681 * GdipCreateTexture [GDIPLUS.@]
683 * PARAMS
684 * image [I] image to use
685 * wrapmode [I] optional
686 * texture [O] pointer to the resulting texturebrush
688 * RETURNS
689 * SUCCESS: Ok
690 * FAILURE: element of GpStatus
692 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
693 GpTexture **texture)
695 UINT width, height;
696 GpImageAttributes *attributes;
697 GpStatus stat;
699 TRACE("%p, %d %p\n", image, wrapmode, texture);
701 if (!(image && texture))
702 return InvalidParameter;
704 stat = GdipGetImageWidth(image, &width);
705 if (stat != Ok) return stat;
706 stat = GdipGetImageHeight(image, &height);
707 if (stat != Ok) return stat;
709 stat = GdipCreateImageAttributes(&attributes);
711 if (stat == Ok)
713 attributes->wrap = wrapmode;
715 stat = GdipCreateTextureIA(image, attributes, 0, 0, width, height,
716 texture);
718 GdipDisposeImageAttributes(attributes);
721 return stat;
724 /******************************************************************************
725 * GdipCreateTexture2 [GDIPLUS.@]
727 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
728 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
730 GpImageAttributes *attributes;
731 GpStatus stat;
733 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
734 x, y, width, height, texture);
736 stat = GdipCreateImageAttributes(&attributes);
738 if (stat == Ok)
740 attributes->wrap = wrapmode;
742 stat = GdipCreateTextureIA(image, attributes, x, y, width, height,
743 texture);
745 GdipDisposeImageAttributes(attributes);
748 return stat;
751 /******************************************************************************
752 * GdipCreateTextureIA [GDIPLUS.@]
754 * FIXME: imageattr ignored
756 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
757 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
758 REAL height, GpTexture **texture)
760 GpStatus status;
761 GpImage *new_image=NULL;
763 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
764 texture);
766 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
767 return InvalidParameter;
769 *texture = NULL;
771 if(image->type != ImageTypeBitmap){
772 FIXME("not implemented for image type %d\n", image->type);
773 return NotImplemented;
776 status = GdipCloneBitmapArea(x, y, width, height, PixelFormatDontCare, (GpBitmap*)image, (GpBitmap**)&new_image);
777 if (status != Ok)
778 return status;
780 *texture = GdipAlloc(sizeof(GpTexture));
781 if (!*texture){
782 status = OutOfMemory;
783 goto exit;
786 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
787 goto exit;
790 if (imageattr)
792 status = GdipCloneImageAttributes(imageattr, &(*texture)->imageattributes);
794 else
796 status = GdipCreateImageAttributes(&(*texture)->imageattributes);
797 if (status == Ok)
798 (*texture)->imageattributes->wrap = WrapModeTile;
800 if (status == Ok)
802 (*texture)->brush.bt = BrushTypeTextureFill;
803 (*texture)->image = new_image;
806 exit:
807 if (status == Ok)
809 TRACE("<-- %p\n", *texture);
811 else
813 if (*texture)
815 GdipDeleteMatrix((*texture)->transform);
816 GdipDisposeImageAttributes((*texture)->imageattributes);
817 GdipFree(*texture);
818 *texture = NULL;
820 GdipDisposeImage(new_image);
821 TRACE("<-- error %u\n", status);
824 return status;
827 /******************************************************************************
828 * GdipCreateTextureIAI [GDIPLUS.@]
830 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
831 INT x, INT y, INT width, INT height, GpTexture **texture)
833 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
834 texture);
836 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
839 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
840 INT x, INT y, INT width, INT height, GpTexture **texture)
842 GpImageAttributes *imageattr;
843 GpStatus stat;
845 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
846 texture);
848 stat = GdipCreateImageAttributes(&imageattr);
850 if (stat == Ok)
852 imageattr->wrap = wrapmode;
854 stat = GdipCreateTextureIA(image, imageattr, x, y, width, height, texture);
857 return stat;
860 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
862 TRACE("(%p, %p)\n", brush, type);
864 if(!brush || !type) return InvalidParameter;
866 *type = brush->bt;
868 return Ok;
871 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
873 TRACE("(%p, %p)\n", brush, backcol);
875 if(!brush || !backcol) return InvalidParameter;
877 *backcol = brush->backcol;
879 return Ok;
882 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
884 TRACE("(%p, %p)\n", brush, forecol);
886 if(!brush || !forecol) return InvalidParameter;
888 *forecol = brush->forecol;
890 return Ok;
893 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
895 TRACE("(%p, %p)\n", brush, hatchstyle);
897 if(!brush || !hatchstyle) return InvalidParameter;
899 *hatchstyle = brush->hatchstyle;
901 return Ok;
904 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
906 TRACE("(%p)\n", brush);
908 if(!brush) return InvalidParameter;
910 switch(brush->bt)
912 case BrushTypePathGradient:
913 GdipDeletePath(((GpPathGradient*) brush)->path);
914 GdipDeleteMatrix(((GpPathGradient*) brush)->transform);
915 GdipFree(((GpPathGradient*) brush)->blendfac);
916 GdipFree(((GpPathGradient*) brush)->blendpos);
917 GdipFree(((GpPathGradient*) brush)->surroundcolors);
918 GdipFree(((GpPathGradient*) brush)->pblendcolor);
919 GdipFree(((GpPathGradient*) brush)->pblendpos);
920 break;
921 case BrushTypeLinearGradient:
922 GdipFree(((GpLineGradient*)brush)->blendfac);
923 GdipFree(((GpLineGradient*)brush)->blendpos);
924 GdipFree(((GpLineGradient*)brush)->pblendcolor);
925 GdipFree(((GpLineGradient*)brush)->pblendpos);
926 break;
927 case BrushTypeTextureFill:
928 GdipDeleteMatrix(((GpTexture*)brush)->transform);
929 GdipDisposeImage(((GpTexture*)brush)->image);
930 GdipDisposeImageAttributes(((GpTexture*)brush)->imageattributes);
931 GdipFree(((GpTexture*)brush)->bitmap_bits);
932 break;
933 default:
934 break;
937 GdipFree(brush);
939 return Ok;
942 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
943 BOOL *usinggamma)
945 TRACE("(%p, %p)\n", line, usinggamma);
947 if(!line || !usinggamma)
948 return InvalidParameter;
950 *usinggamma = line->gamma;
952 return Ok;
955 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
957 TRACE("(%p, %p)\n", brush, wrapmode);
959 if(!brush || !wrapmode)
960 return InvalidParameter;
962 *wrapmode = brush->wrap;
964 return Ok;
967 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
968 REAL *positions, INT count)
970 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
972 if(!brush || !blend || !positions || count <= 0)
973 return InvalidParameter;
975 if(count < brush->blendcount)
976 return InsufficientBuffer;
978 memcpy(blend, brush->blendfac, count*sizeof(REAL));
979 if(brush->blendcount > 1){
980 memcpy(positions, brush->blendpos, count*sizeof(REAL));
983 return Ok;
986 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
988 TRACE("(%p, %p)\n", brush, count);
990 if(!brush || !count)
991 return InvalidParameter;
993 *count = brush->blendcount;
995 return Ok;
998 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
999 GpPointF *point)
1001 TRACE("(%p, %p)\n", grad, point);
1003 if(!grad || !point)
1004 return InvalidParameter;
1006 point->X = grad->center.X;
1007 point->Y = grad->center.Y;
1009 return Ok;
1012 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
1013 GpPoint *point)
1015 GpStatus ret;
1016 GpPointF ptf;
1018 TRACE("(%p, %p)\n", grad, point);
1020 if(!point)
1021 return InvalidParameter;
1023 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
1025 if(ret == Ok){
1026 point->X = roundr(ptf.X);
1027 point->Y = roundr(ptf.Y);
1030 return ret;
1033 GpStatus WINGDIPAPI GdipGetPathGradientCenterColor(GpPathGradient *grad,
1034 ARGB *colors)
1036 TRACE("(%p,%p)\n", grad, colors);
1038 if (!grad || !colors)
1039 return InvalidParameter;
1041 *colors = grad->centercolor;
1043 return Ok;
1046 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
1047 REAL *x, REAL *y)
1049 TRACE("(%p, %p, %p)\n", grad, x, y);
1051 if(!grad || !x || !y)
1052 return InvalidParameter;
1054 *x = grad->focus.X;
1055 *y = grad->focus.Y;
1057 return Ok;
1060 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1061 BOOL *gamma)
1063 TRACE("(%p, %p)\n", grad, gamma);
1065 if(!grad || !gamma)
1066 return InvalidParameter;
1068 *gamma = grad->gamma;
1070 return Ok;
1073 GpStatus WINGDIPAPI GdipGetPathGradientPath(GpPathGradient *grad, GpPath *path)
1075 static int calls;
1077 TRACE("(%p, %p)\n", grad, path);
1079 if (!(calls++))
1080 FIXME("not implemented\n");
1082 return NotImplemented;
1085 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1086 INT *count)
1088 TRACE("(%p, %p)\n", grad, count);
1090 if(!grad || !count)
1091 return InvalidParameter;
1093 *count = grad->path->pathdata.Count;
1095 return Ok;
1098 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1100 GpStatus stat;
1102 TRACE("(%p, %p)\n", brush, rect);
1104 if(!brush || !rect)
1105 return InvalidParameter;
1107 stat = GdipGetPathWorldBounds(brush->path, rect, NULL, NULL);
1109 return stat;
1112 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1114 GpRectF rectf;
1115 GpStatus stat;
1117 TRACE("(%p, %p)\n", brush, rect);
1119 if(!brush || !rect)
1120 return InvalidParameter;
1122 stat = GdipGetPathGradientRect(brush, &rectf);
1123 if(stat != Ok) return stat;
1125 rect->X = roundr(rectf.X);
1126 rect->Y = roundr(rectf.Y);
1127 rect->Width = roundr(rectf.Width);
1128 rect->Height = roundr(rectf.Height);
1130 return Ok;
1133 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1134 *grad, ARGB *argb, INT *count)
1136 INT i;
1138 TRACE("(%p,%p,%p)\n", grad, argb, count);
1140 if(!grad || !argb || !count || (*count < grad->path->pathdata.Count))
1141 return InvalidParameter;
1143 for (i=0; i<grad->path->pathdata.Count; i++)
1145 if (i < grad->surroundcolorcount)
1146 argb[i] = grad->surroundcolors[i];
1147 else
1148 argb[i] = grad->surroundcolors[grad->surroundcolorcount-1];
1151 *count = grad->surroundcolorcount;
1153 return Ok;
1156 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorCount(GpPathGradient *brush, INT *count)
1158 TRACE("(%p, %p)\n", brush, count);
1160 if (!brush || !count)
1161 return InvalidParameter;
1163 /* Yes, this actually returns the number of points in the path (which is the
1164 * required size of a buffer to get the surround colors), rather than the
1165 * number of surround colors. The real count is returned when getting the
1166 * colors. */
1167 *count = brush->path->pathdata.Count;
1169 return Ok;
1172 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1173 GpWrapMode *wrapmode)
1175 TRACE("(%p, %p)\n", brush, wrapmode);
1177 if(!brush || !wrapmode)
1178 return InvalidParameter;
1180 *wrapmode = brush->wrap;
1182 return Ok;
1185 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1187 TRACE("(%p, %p)\n", sf, argb);
1189 if(!sf || !argb)
1190 return InvalidParameter;
1192 *argb = sf->color;
1194 return Ok;
1197 /******************************************************************************
1198 * GdipGetTextureImage [GDIPLUS.@]
1200 GpStatus WINGDIPAPI GdipGetTextureImage(GpTexture *brush, GpImage **image)
1202 TRACE("(%p, %p)\n", brush, image);
1204 if(!brush || !image)
1205 return InvalidParameter;
1207 return GdipCloneImage(brush->image, image);
1210 /******************************************************************************
1211 * GdipGetTextureTransform [GDIPLUS.@]
1213 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1215 TRACE("(%p, %p)\n", brush, matrix);
1217 if(!brush || !matrix)
1218 return InvalidParameter;
1220 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1222 return Ok;
1225 /******************************************************************************
1226 * GdipGetTextureWrapMode [GDIPLUS.@]
1228 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1230 TRACE("(%p, %p)\n", brush, wrapmode);
1232 if(!brush || !wrapmode)
1233 return InvalidParameter;
1235 *wrapmode = brush->imageattributes->wrap;
1237 return Ok;
1240 /******************************************************************************
1241 * GdipMultiplyTextureTransform [GDIPLUS.@]
1243 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1244 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1246 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1248 if(!brush || !matrix)
1249 return InvalidParameter;
1251 return GdipMultiplyMatrix(brush->transform, matrix, order);
1254 /******************************************************************************
1255 * GdipResetTextureTransform [GDIPLUS.@]
1257 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1259 TRACE("(%p)\n", brush);
1261 if(!brush)
1262 return InvalidParameter;
1264 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1267 /******************************************************************************
1268 * GdipScaleTextureTransform [GDIPLUS.@]
1270 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1271 REAL sx, REAL sy, GpMatrixOrder order)
1273 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1275 if(!brush)
1276 return InvalidParameter;
1278 return GdipScaleMatrix(brush->transform, sx, sy, order);
1281 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1282 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1284 REAL *new_blendfac, *new_blendpos;
1286 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1288 if(!brush || !factors || !positions || count <= 0 ||
1289 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1290 return InvalidParameter;
1292 new_blendfac = GdipAlloc(count * sizeof(REAL));
1293 new_blendpos = GdipAlloc(count * sizeof(REAL));
1295 if (!new_blendfac || !new_blendpos)
1297 GdipFree(new_blendfac);
1298 GdipFree(new_blendpos);
1299 return OutOfMemory;
1302 memcpy(new_blendfac, factors, count * sizeof(REAL));
1303 memcpy(new_blendpos, positions, count * sizeof(REAL));
1305 GdipFree(brush->blendfac);
1306 GdipFree(brush->blendpos);
1308 brush->blendcount = count;
1309 brush->blendfac = new_blendfac;
1310 brush->blendpos = new_blendpos;
1312 return Ok;
1315 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1316 REAL *positions, INT count)
1318 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1320 if (!brush || !factors || !positions || count <= 0)
1321 return InvalidParameter;
1323 if (count < brush->blendcount)
1324 return InsufficientBuffer;
1326 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1327 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1329 return Ok;
1332 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1334 TRACE("(%p, %p)\n", brush, count);
1336 if (!brush || !count)
1337 return InvalidParameter;
1339 *count = brush->blendcount;
1341 return Ok;
1344 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1345 BOOL usegamma)
1347 TRACE("(%p, %d)\n", line, usegamma);
1349 if(!line)
1350 return InvalidParameter;
1352 line->gamma = usegamma;
1354 return Ok;
1357 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1358 REAL scale)
1360 REAL factors[33];
1361 REAL positions[33];
1362 int num_points = 0;
1363 int i;
1364 const int precision = 16;
1365 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1366 REAL min_erf;
1367 REAL scale_erf;
1369 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1371 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1372 return InvalidParameter;
1374 /* we want 2 standard deviations */
1375 erf_range = 2.0 / sqrt(2);
1377 /* calculate the constants we need to normalize the error function to be
1378 between 0.0 and scale over the range we need */
1379 min_erf = erf(-erf_range);
1380 scale_erf = scale / (-2.0 * min_erf);
1382 if (focus != 0.0)
1384 positions[0] = 0.0;
1385 factors[0] = 0.0;
1386 for (i=1; i<precision; i++)
1388 positions[i] = focus * i / precision;
1389 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1391 num_points += precision;
1394 positions[num_points] = focus;
1395 factors[num_points] = scale;
1396 num_points += 1;
1398 if (focus != 1.0)
1400 for (i=1; i<precision; i++)
1402 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1403 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1405 num_points += precision;
1406 positions[num_points-1] = 1.0;
1407 factors[num_points-1] = 0.0;
1410 return GdipSetLineBlend(line, factors, positions, num_points);
1413 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1414 GpWrapMode wrap)
1416 TRACE("(%p, %d)\n", line, wrap);
1418 if(!line || wrap == WrapModeClamp)
1419 return InvalidParameter;
1421 line->wrap = wrap;
1423 return Ok;
1426 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1427 GDIPCONST REAL *pos, INT count)
1429 static int calls;
1431 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1433 if(!(calls++))
1434 FIXME("not implemented\n");
1436 return NotImplemented;
1439 GpStatus WINGDIPAPI GdipSetPathGradientLinearBlend(GpPathGradient *brush,
1440 REAL focus, REAL scale)
1442 static int calls;
1444 TRACE("(%p,%0.2f,%0.2f)\n", brush, focus, scale);
1446 if(!(calls++))
1447 FIXME("not implemented\n");
1449 return NotImplemented;
1452 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1453 GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1455 ARGB *new_color;
1456 REAL *new_pos;
1457 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1459 if (!brush || !blend || !pos || count < 2 ||
1460 pos[0] != 0.0f || pos[count-1] != 1.0f)
1462 return InvalidParameter;
1465 new_color = GdipAlloc(count * sizeof(ARGB));
1466 new_pos = GdipAlloc(count * sizeof(REAL));
1467 if (!new_color || !new_pos)
1469 GdipFree(new_color);
1470 GdipFree(new_pos);
1471 return OutOfMemory;
1474 memcpy(new_color, blend, sizeof(ARGB) * count);
1475 memcpy(new_pos, pos, sizeof(REAL) * count);
1477 GdipFree(brush->pblendcolor);
1478 GdipFree(brush->pblendpos);
1480 brush->pblendcolor = new_color;
1481 brush->pblendpos = new_pos;
1482 brush->pblendcount = count;
1484 return Ok;
1487 GpStatus WINGDIPAPI GdipGetPathGradientPresetBlend(GpPathGradient *brush,
1488 ARGB *blend, REAL *pos, INT count)
1490 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1492 if (count < 0)
1493 return OutOfMemory;
1495 if (!brush || !blend || !pos || count < 2)
1496 return InvalidParameter;
1498 if (brush->pblendcount == 0)
1499 return GenericError;
1501 if (count != brush->pblendcount)
1503 /* Native lines up the ends of each array, and copies the destination size. */
1504 FIXME("Braindead behavior on wrong-sized buffer not implemented.\n");
1505 return InvalidParameter;
1508 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1509 memcpy(pos, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1511 return Ok;
1514 GpStatus WINGDIPAPI GdipGetPathGradientPresetBlendCount(GpPathGradient *brush,
1515 INT *count)
1517 FIXME("(%p,%p): stub\n", brush, count);
1519 if (!brush || !count)
1520 return InvalidParameter;
1522 *count = brush->pblendcount;
1524 return Ok;
1527 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1528 ARGB argb)
1530 TRACE("(%p, %x)\n", grad, argb);
1532 if(!grad)
1533 return InvalidParameter;
1535 grad->centercolor = argb;
1536 return Ok;
1539 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1540 GpPointF *point)
1542 TRACE("(%p, %s)\n", grad, debugstr_pointf(point));
1544 if(!grad || !point)
1545 return InvalidParameter;
1547 grad->center.X = point->X;
1548 grad->center.Y = point->Y;
1550 return Ok;
1553 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1554 GpPoint *point)
1556 GpPointF ptf;
1558 TRACE("(%p, %p)\n", grad, point);
1560 if(!point)
1561 return InvalidParameter;
1563 ptf.X = (REAL)point->X;
1564 ptf.Y = (REAL)point->Y;
1566 return GdipSetPathGradientCenterPoint(grad,&ptf);
1569 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1570 REAL x, REAL y)
1572 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1574 if(!grad)
1575 return InvalidParameter;
1577 grad->focus.X = x;
1578 grad->focus.Y = y;
1580 return Ok;
1583 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1584 BOOL gamma)
1586 TRACE("(%p, %d)\n", grad, gamma);
1588 if(!grad)
1589 return InvalidParameter;
1591 grad->gamma = gamma;
1593 return Ok;
1596 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1597 REAL focus, REAL scale)
1599 static int calls;
1601 TRACE("(%p,%0.2f,%0.2f)\n", grad, focus, scale);
1603 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1604 return InvalidParameter;
1606 if(!(calls++))
1607 FIXME("not implemented\n");
1609 return NotImplemented;
1612 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1613 *grad, GDIPCONST ARGB *argb, INT *count)
1615 ARGB *new_surroundcolors;
1617 TRACE("(%p,%p,%p)\n", grad, argb, count);
1619 if(!grad || !argb || !count || (*count <= 0) ||
1620 (*count > grad->path->pathdata.Count))
1621 return InvalidParameter;
1623 new_surroundcolors = GdipAlloc(*count * sizeof(ARGB));
1624 if (!new_surroundcolors)
1625 return OutOfMemory;
1627 memcpy(new_surroundcolors, argb, *count * sizeof(ARGB));
1629 GdipFree(grad->surroundcolors);
1631 grad->surroundcolors = new_surroundcolors;
1632 grad->surroundcolorcount = *count;
1634 return Ok;
1637 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1638 GpWrapMode wrap)
1640 TRACE("(%p, %d)\n", grad, wrap);
1642 if(!grad)
1643 return InvalidParameter;
1645 grad->wrap = wrap;
1647 return Ok;
1650 GpStatus WINGDIPAPI GdipSetPathGradientTransform(GpPathGradient *grad,
1651 GpMatrix *matrix)
1653 static int calls;
1655 TRACE("(%p,%p)\n", grad, matrix);
1657 if(!(calls++))
1658 FIXME("not implemented\n");
1660 return NotImplemented;
1663 GpStatus WINGDIPAPI GdipGetPathGradientTransform(GpPathGradient *grad,
1664 GpMatrix *matrix)
1666 TRACE("(%p,%p)\n", grad, matrix);
1668 if (!grad || !matrix)
1669 return InvalidParameter;
1671 memcpy(matrix, grad->transform, sizeof(GpMatrix));
1673 return Ok;
1676 GpStatus WINGDIPAPI GdipMultiplyPathGradientTransform(GpPathGradient *grad,
1677 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1679 static int calls;
1681 TRACE("(%p,%p,%i)\n", grad, matrix, order);
1683 if(!(calls++))
1684 FIXME("not implemented\n");
1686 return NotImplemented;
1689 GpStatus WINGDIPAPI GdipRotatePathGradientTransform(GpPathGradient *grad,
1690 REAL angle, GpMatrixOrder order)
1692 static int calls;
1694 TRACE("(%p,%0.2f,%i)\n", grad, angle, order);
1696 if(!(calls++))
1697 FIXME("not implemented\n");
1699 return NotImplemented;
1702 GpStatus WINGDIPAPI GdipScalePathGradientTransform(GpPathGradient *grad,
1703 REAL sx, REAL sy, GpMatrixOrder order)
1705 static int calls;
1707 TRACE("(%p,%0.2f,%0.2f,%i)\n", grad, sx, sy, order);
1709 if(!(calls++))
1710 FIXME("not implemented\n");
1712 return NotImplemented;
1715 GpStatus WINGDIPAPI GdipTranslatePathGradientTransform(GpPathGradient *grad,
1716 REAL dx, REAL dy, GpMatrixOrder order)
1718 static int calls;
1720 TRACE("(%p,%0.2f,%0.2f,%i)\n", grad, dx, dy, order);
1722 if(!(calls++))
1723 FIXME("not implemented\n");
1725 return NotImplemented;
1728 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1730 TRACE("(%p, %x)\n", sf, argb);
1732 if(!sf)
1733 return InvalidParameter;
1735 sf->color = argb;
1736 return Ok;
1739 /******************************************************************************
1740 * GdipSetTextureTransform [GDIPLUS.@]
1742 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1743 GDIPCONST GpMatrix *matrix)
1745 TRACE("(%p, %p)\n", texture, matrix);
1747 if(!texture || !matrix)
1748 return InvalidParameter;
1750 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1752 return Ok;
1755 /******************************************************************************
1756 * GdipSetTextureWrapMode [GDIPLUS.@]
1758 * WrapMode not used, only stored
1760 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1762 TRACE("(%p, %d)\n", brush, wrapmode);
1764 if(!brush)
1765 return InvalidParameter;
1767 brush->imageattributes->wrap = wrapmode;
1769 return Ok;
1772 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1773 ARGB color2)
1775 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1777 if(!brush)
1778 return InvalidParameter;
1780 brush->startcolor = color1;
1781 brush->endcolor = color2;
1783 return Ok;
1786 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1788 TRACE("(%p, %p)\n", brush, colors);
1790 if(!brush || !colors)
1791 return InvalidParameter;
1793 colors[0] = brush->startcolor;
1794 colors[1] = brush->endcolor;
1796 return Ok;
1799 /******************************************************************************
1800 * GdipRotateTextureTransform [GDIPLUS.@]
1802 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1803 GpMatrixOrder order)
1805 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1807 if(!brush)
1808 return InvalidParameter;
1810 return GdipRotateMatrix(brush->transform, angle, order);
1813 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1814 REAL scale)
1816 REAL factors[3];
1817 REAL positions[3];
1818 int num_points = 0;
1820 TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1822 if (!brush) return InvalidParameter;
1824 if (focus != 0.0)
1826 factors[num_points] = 0.0;
1827 positions[num_points] = 0.0;
1828 num_points++;
1831 factors[num_points] = scale;
1832 positions[num_points] = focus;
1833 num_points++;
1835 if (focus != 1.0)
1837 factors[num_points] = 0.0;
1838 positions[num_points] = 1.0;
1839 num_points++;
1842 return GdipSetLineBlend(brush, factors, positions, num_points);
1845 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1846 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1848 ARGB *new_color;
1849 REAL *new_pos;
1850 TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1852 if (!brush || !blend || !positions || count < 2 ||
1853 positions[0] != 0.0f || positions[count-1] != 1.0f)
1855 return InvalidParameter;
1858 new_color = GdipAlloc(count * sizeof(ARGB));
1859 new_pos = GdipAlloc(count * sizeof(REAL));
1860 if (!new_color || !new_pos)
1862 GdipFree(new_color);
1863 GdipFree(new_pos);
1864 return OutOfMemory;
1867 memcpy(new_color, blend, sizeof(ARGB) * count);
1868 memcpy(new_pos, positions, sizeof(REAL) * count);
1870 GdipFree(brush->pblendcolor);
1871 GdipFree(brush->pblendpos);
1873 brush->pblendcolor = new_color;
1874 brush->pblendpos = new_pos;
1875 brush->pblendcount = count;
1877 return Ok;
1880 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1881 ARGB *blend, REAL* positions, INT count)
1883 if (!brush || !blend || !positions || count < 2)
1884 return InvalidParameter;
1886 if (brush->pblendcount == 0)
1887 return GenericError;
1889 if (count < brush->pblendcount)
1890 return InsufficientBuffer;
1892 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1893 memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1895 return Ok;
1898 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1899 INT *count)
1901 if (!brush || !count)
1902 return InvalidParameter;
1904 *count = brush->pblendcount;
1906 return Ok;
1909 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1911 static int calls;
1913 TRACE("(%p)\n", brush);
1915 if(!(calls++))
1916 FIXME("not implemented\n");
1918 return NotImplemented;
1921 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1922 GDIPCONST GpMatrix *matrix)
1924 static int calls;
1926 TRACE("(%p,%p)\n", brush, matrix);
1928 if(!(calls++))
1929 FIXME("not implemented\n");
1931 return NotImplemented;
1934 GpStatus WINGDIPAPI GdipGetLineTransform(GpLineGradient *brush, GpMatrix *matrix)
1936 static int calls;
1938 TRACE("(%p,%p)\n", brush, matrix);
1940 if(!(calls++))
1941 FIXME("not implemented\n");
1943 return NotImplemented;
1946 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
1947 GpMatrixOrder order)
1949 static int calls;
1951 TRACE("(%p,%0.2f,%0.2f,%u)\n", brush, sx, sy, order);
1953 if(!(calls++))
1954 FIXME("not implemented\n");
1956 return NotImplemented;
1959 GpStatus WINGDIPAPI GdipMultiplyLineTransform(GpLineGradient *brush,
1960 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1962 static int calls;
1964 TRACE("(%p,%p,%u)\n", brush, matrix, order);
1966 if(!(calls++))
1967 FIXME("not implemented\n");
1969 return NotImplemented;
1972 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1973 REAL dx, REAL dy, GpMatrixOrder order)
1975 static int calls;
1977 TRACE("(%p,%f,%f,%d)\n", brush, dx, dy, order);
1979 if(!(calls++))
1980 FIXME("not implemented\n");
1982 return Ok;
1985 /******************************************************************************
1986 * GdipTranslateTextureTransform [GDIPLUS.@]
1988 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1989 GpMatrixOrder order)
1991 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1993 if(!brush)
1994 return InvalidParameter;
1996 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1999 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
2001 TRACE("(%p, %p)\n", brush, rect);
2003 if(!brush || !rect)
2004 return InvalidParameter;
2006 *rect = brush->rect;
2008 return Ok;
2011 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
2013 GpRectF rectF;
2014 GpStatus ret;
2016 TRACE("(%p, %p)\n", brush, rect);
2018 if(!rect)
2019 return InvalidParameter;
2021 ret = GdipGetLineRect(brush, &rectF);
2023 if(ret == Ok){
2024 rect->X = roundr(rectF.X);
2025 rect->Y = roundr(rectF.Y);
2026 rect->Width = roundr(rectF.Width);
2027 rect->Height = roundr(rectF.Height);
2030 return ret;
2033 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
2034 REAL angle, GpMatrixOrder order)
2036 static int calls;
2038 TRACE("(%p,%0.2f,%u)\n", brush, angle, order);
2040 if(!brush)
2041 return InvalidParameter;
2043 if(!(calls++))
2044 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
2046 return NotImplemented;