gdiplus: Store a real path in path gradient brushes.
[wine.git] / dlls / gdiplus / brush.c
blob963aa74220d8bf9b38f83962e553de0bbc53da9b
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;
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 /* blending */
82 count = src->blendcount;
83 dest->blendcount = count;
84 dest->blendfac = GdipAlloc(count * sizeof(REAL));
85 dest->blendpos = GdipAlloc(count * sizeof(REAL));
87 if(!dest->blendfac || !dest->blendpos){
88 GdipDeletePath(dest->path);
89 GdipFree(dest->blendfac);
90 GdipFree(dest->blendpos);
91 GdipFree(dest);
92 return OutOfMemory;
95 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
96 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
98 break;
100 case BrushTypeLinearGradient:{
101 GpLineGradient *dest, *src;
102 INT count, pcount;
104 dest = GdipAlloc(sizeof(GpLineGradient));
105 if(!dest) return OutOfMemory;
107 src = (GpLineGradient*)brush;
109 memcpy(dest, src, sizeof(GpLineGradient));
111 count = dest->blendcount;
112 dest->blendfac = GdipAlloc(count * sizeof(REAL));
113 dest->blendpos = GdipAlloc(count * sizeof(REAL));
114 pcount = dest->pblendcount;
115 if (pcount)
117 dest->pblendcolor = GdipAlloc(pcount * sizeof(ARGB));
118 dest->pblendpos = GdipAlloc(pcount * sizeof(REAL));
121 if (!dest->blendfac || !dest->blendpos ||
122 (pcount && (!dest->pblendcolor || !dest->pblendpos)))
124 GdipFree(dest->blendfac);
125 GdipFree(dest->blendpos);
126 GdipFree(dest->pblendcolor);
127 GdipFree(dest->pblendpos);
128 GdipFree(dest);
129 return OutOfMemory;
132 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
133 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
135 if (pcount)
137 memcpy(dest->pblendcolor, src->pblendcolor, pcount * sizeof(ARGB));
138 memcpy(dest->pblendpos, src->pblendpos, pcount * sizeof(REAL));
141 *clone = &dest->brush;
142 break;
144 case BrushTypeTextureFill:
146 GpStatus stat;
147 GpTexture *texture = (GpTexture*)brush;
148 GpTexture *new_texture;
149 UINT width, height;
151 stat = GdipGetImageWidth(texture->image, &width);
152 if (stat != Ok) return stat;
153 stat = GdipGetImageHeight(texture->image, &height);
154 if (stat != Ok) return stat;
156 stat = GdipCreateTextureIA(texture->image, texture->imageattributes, 0, 0, width, height, &new_texture);
158 if (stat == Ok)
160 memcpy(new_texture->transform, texture->transform, sizeof(GpMatrix));
161 *clone = (GpBrush*)new_texture;
163 else
164 *clone = NULL;
166 return stat;
168 default:
169 ERR("not implemented for brush type %d\n", brush->bt);
170 return NotImplemented;
173 TRACE("<-- %p\n", *clone);
174 return Ok;
177 static const char HatchBrushes[][8] = {
178 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HatchStyleHorizontal */
179 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleVertical */
180 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HatchStyleForwardDiagonal */
181 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HatchStyleBackwardDiagonal */
182 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleCross */
183 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }, /* HatchStyleDiagonalCross */
184 { 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x80 }, /* HatchStyle05Percent */
185 { 0x00, 0x02, 0x00, 0x88, 0x00, 0x20, 0x00, 0x88 }, /* HatchStyle10Percent */
186 { 0x00, 0x22, 0x00, 0xcc, 0x00, 0x22, 0x00, 0xcc }, /* HatchStyle20Percent */
187 { 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc }, /* HatchStyle25Percent */
188 { 0x00, 0xcc, 0x04, 0xcc, 0x00, 0xcc, 0x40, 0xcc }, /* HatchStyle30Percent */
189 { 0x44, 0xcc, 0x22, 0xcc, 0x44, 0xcc, 0x22, 0xcc }, /* HatchStyle40Percent */
190 { 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc }, /* HatchStyle50Percent */
191 { 0x55, 0xcd, 0x55, 0xee, 0x55, 0xdc, 0x55, 0xee }, /* HatchStyle60Percent */
192 { 0x55, 0xdd, 0x55, 0xff, 0x55, 0xdd, 0x55, 0xff }, /* HatchStyle70Percent */
193 { 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff }, /* HatchStyle75Percent */
194 { 0x55, 0xff, 0x59, 0xff, 0x55, 0xff, 0x99, 0xff }, /* HatchStyle80Percent */
195 { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xfd, 0xff }, /* HatchStyle90Percent */
196 { 0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88 }, /* HatchStyleLightDownwardDiagonal */
197 { 0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11 }, /* HatchStyleLightUpwardDiagonal */
198 { 0x99, 0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc }, /* HatchStyleDarkDownwardDiagonal */
199 { 0xcc, 0x66, 0x33, 0x99, 0xcc, 0x66, 0x33, 0x99 }, /* HatchStyleDarkUpwardDiagonal */
200 { 0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0 }, /* HatchStyleWideDownwardDiagonal */
201 { 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x83, 0xc1 }, /* HatchStyleWideUpwardDiagonal */
202 { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 }, /* HatchStyleLightVertical */
203 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff }, /* HatchStyleLightHorizontal */
204 { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }, /* HatchStyleNarrowVertical */
205 { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, /* HatchStyleNarrowHorizontal */
206 { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }, /* HatchStyleDarkVertical */
207 { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff }, /* HatchStyleDarkHorizontal */
210 GpStatus get_hatch_data(HatchStyle hatchstyle, const char **result)
212 if (hatchstyle < sizeof(HatchBrushes) / sizeof(HatchBrushes[0]))
214 *result = HatchBrushes[hatchstyle];
215 return Ok;
217 else
218 return NotImplemented;
221 /******************************************************************************
222 * GdipCreateHatchBrush [GDIPLUS.@]
224 GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle hatchstyle, ARGB forecol, ARGB backcol, GpHatch **brush)
226 TRACE("(%d, %d, %d, %p)\n", hatchstyle, forecol, backcol, brush);
228 if(!brush) return InvalidParameter;
230 *brush = GdipAlloc(sizeof(GpHatch));
231 if (!*brush) return OutOfMemory;
233 (*brush)->brush.bt = BrushTypeHatchFill;
234 (*brush)->forecol = forecol;
235 (*brush)->backcol = backcol;
236 (*brush)->hatchstyle = hatchstyle;
237 TRACE("<-- %p\n", *brush);
239 return Ok;
242 /******************************************************************************
243 * GdipCreateLineBrush [GDIPLUS.@]
245 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
246 GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
247 GpWrapMode wrap, GpLineGradient **line)
249 TRACE("(%s, %s, %x, %x, %d, %p)\n", debugstr_pointf(startpoint),
250 debugstr_pointf(endpoint), startcolor, endcolor, wrap, line);
252 if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
253 return InvalidParameter;
255 if (startpoint->X == endpoint->X && startpoint->Y == endpoint->Y)
256 return OutOfMemory;
258 *line = GdipAlloc(sizeof(GpLineGradient));
259 if(!*line) return OutOfMemory;
261 (*line)->brush.bt = BrushTypeLinearGradient;
263 (*line)->startpoint.X = startpoint->X;
264 (*line)->startpoint.Y = startpoint->Y;
265 (*line)->endpoint.X = endpoint->X;
266 (*line)->endpoint.Y = endpoint->Y;
267 (*line)->startcolor = startcolor;
268 (*line)->endcolor = endcolor;
269 (*line)->wrap = wrap;
270 (*line)->gamma = FALSE;
272 (*line)->rect.X = (startpoint->X < endpoint->X ? startpoint->X: endpoint->X);
273 (*line)->rect.Y = (startpoint->Y < endpoint->Y ? startpoint->Y: endpoint->Y);
274 (*line)->rect.Width = fabs(startpoint->X - endpoint->X);
275 (*line)->rect.Height = fabs(startpoint->Y - endpoint->Y);
277 if ((*line)->rect.Width == 0)
279 (*line)->rect.X -= (*line)->rect.Height / 2.0f;
280 (*line)->rect.Width = (*line)->rect.Height;
282 else if ((*line)->rect.Height == 0)
284 (*line)->rect.Y -= (*line)->rect.Width / 2.0f;
285 (*line)->rect.Height = (*line)->rect.Width;
288 (*line)->blendcount = 1;
289 (*line)->blendfac = GdipAlloc(sizeof(REAL));
290 (*line)->blendpos = GdipAlloc(sizeof(REAL));
292 if (!(*line)->blendfac || !(*line)->blendpos)
294 GdipFree((*line)->blendfac);
295 GdipFree((*line)->blendpos);
296 GdipFree(*line);
297 *line = NULL;
298 return OutOfMemory;
301 (*line)->blendfac[0] = 1.0f;
302 (*line)->blendpos[0] = 1.0f;
304 (*line)->pblendcolor = NULL;
305 (*line)->pblendpos = NULL;
306 (*line)->pblendcount = 0;
308 TRACE("<-- %p\n", *line);
310 return Ok;
313 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
314 GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
315 GpWrapMode wrap, GpLineGradient **line)
317 GpPointF stF;
318 GpPointF endF;
320 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
321 startcolor, endcolor, wrap, line);
323 if(!startpoint || !endpoint)
324 return InvalidParameter;
326 stF.X = (REAL)startpoint->X;
327 stF.Y = (REAL)startpoint->Y;
328 endF.X = (REAL)endpoint->X;
329 endF.Y = (REAL)endpoint->Y;
331 return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
334 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
335 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
336 GpLineGradient **line)
338 GpPointF start, end;
339 GpStatus stat;
341 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
342 wrap, line);
344 if(!line || !rect)
345 return InvalidParameter;
347 switch (mode)
349 case LinearGradientModeHorizontal:
350 start.X = rect->X;
351 start.Y = rect->Y;
352 end.X = rect->X + rect->Width;
353 end.Y = rect->Y;
354 break;
355 case LinearGradientModeVertical:
356 start.X = rect->X;
357 start.Y = rect->Y;
358 end.X = rect->X;
359 end.Y = rect->Y + rect->Height;
360 break;
361 case LinearGradientModeForwardDiagonal:
362 start.X = rect->X;
363 start.Y = rect->Y;
364 end.X = rect->X + rect->Width;
365 end.Y = rect->Y + rect->Height;
366 break;
367 case LinearGradientModeBackwardDiagonal:
368 start.X = rect->X + rect->Width;
369 start.Y = rect->Y;
370 end.X = rect->X;
371 end.Y = rect->Y + rect->Height;
372 break;
373 default:
374 return InvalidParameter;
377 stat = GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
379 if (stat == Ok)
380 (*line)->rect = *rect;
382 return stat;
385 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
386 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
387 GpLineGradient **line)
389 GpRectF rectF;
391 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
392 wrap, line);
394 rectF.X = (REAL) rect->X;
395 rectF.Y = (REAL) rect->Y;
396 rectF.Width = (REAL) rect->Width;
397 rectF.Height = (REAL) rect->Height;
399 return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
402 /******************************************************************************
403 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
405 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
406 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
407 GpLineGradient **line)
409 GpStatus stat;
410 LinearGradientMode mode;
411 REAL width, height, exofs, eyofs;
412 REAL sin_angle, cos_angle, sin_cos_angle;
414 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
415 wrap, line);
417 sin_angle = sinf(deg2rad(angle));
418 cos_angle = cosf(deg2rad(angle));
419 sin_cos_angle = sin_angle * cos_angle;
421 if (isAngleScalable)
423 width = height = 1.0;
425 else
427 width = rect->Width;
428 height = rect->Height;
431 if (sin_cos_angle >= 0)
432 mode = LinearGradientModeForwardDiagonal;
433 else
434 mode = LinearGradientModeBackwardDiagonal;
436 stat = GdipCreateLineBrushFromRect(rect, startcolor, endcolor, mode, wrap, line);
438 if (stat == Ok)
440 if (sin_cos_angle >= 0)
442 exofs = width * sin_cos_angle + height * cos_angle * cos_angle;
443 eyofs = width * sin_angle * sin_angle + height * sin_cos_angle;
445 else
447 exofs = width * sin_angle * sin_angle + height * sin_cos_angle;
448 eyofs = -width * sin_cos_angle + height * sin_angle * sin_angle;
451 if (isAngleScalable)
453 exofs = exofs * rect->Width;
454 eyofs = eyofs * rect->Height;
457 if (sin_angle >= 0)
459 (*line)->endpoint.X = rect->X + exofs;
460 (*line)->endpoint.Y = rect->Y + eyofs;
462 else
464 (*line)->endpoint.X = (*line)->startpoint.X;
465 (*line)->endpoint.Y = (*line)->startpoint.Y;
466 (*line)->startpoint.X = rect->X + exofs;
467 (*line)->startpoint.Y = rect->Y + eyofs;
471 return stat;
474 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
475 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
476 GpLineGradient **line)
478 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
479 wrap, line);
481 return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
482 wrap, line);
485 static GpStatus create_path_gradient(GpPath *path, GpPathGradient **grad)
487 if(!path || !grad)
488 return InvalidParameter;
490 *grad = GdipAlloc(sizeof(GpPathGradient));
491 if (!*grad)
493 return OutOfMemory;
496 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
497 (*grad)->blendpos = GdipAlloc(sizeof(REAL));
498 if(!(*grad)->blendfac || !(*grad)->blendpos){
499 GdipFree((*grad)->blendfac);
500 GdipFree((*grad)->blendpos);
501 GdipFree(*grad);
502 *grad = NULL;
503 return OutOfMemory;
505 (*grad)->blendfac[0] = 1.0;
506 (*grad)->blendpos[0] = 1.0;
507 (*grad)->blendcount = 1;
509 (*grad)->path = path;
511 (*grad)->brush.bt = BrushTypePathGradient;
512 (*grad)->centercolor = 0xffffffff;
513 (*grad)->wrap = WrapModeClamp;
514 (*grad)->gamma = FALSE;
515 /* FIXME: this should be set to the "centroid" of the path by default */
516 (*grad)->center.X = 0.0;
517 (*grad)->center.Y = 0.0;
518 (*grad)->focus.X = 0.0;
519 (*grad)->focus.Y = 0.0;
521 TRACE("<-- %p\n", *grad);
523 return Ok;
526 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
527 INT count, GpWrapMode wrap, GpPathGradient **grad)
529 GpStatus stat;
530 GpPath *path;
532 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
534 if(!points || !grad)
535 return InvalidParameter;
537 if(count <= 0)
538 return OutOfMemory;
540 stat = GdipCreatePath(FillModeAlternate, &path);
542 if (stat == Ok)
544 stat = GdipAddPathLine2(path, points, count);
546 if (stat == Ok)
547 stat = create_path_gradient(path, grad);
549 if (stat != Ok)
550 GdipDeletePath(path);
553 return stat;
556 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
557 INT count, GpWrapMode wrap, GpPathGradient **grad)
559 GpStatus stat;
560 GpPath *path;
562 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
564 if(!points || !grad)
565 return InvalidParameter;
567 if(count <= 0)
568 return OutOfMemory;
570 stat = GdipCreatePath(FillModeAlternate, &path);
572 if (stat == Ok)
574 stat = GdipAddPathLine2I(path, points, count);
576 if (stat == Ok)
577 stat = create_path_gradient(path, grad);
579 if (stat != Ok)
580 GdipDeletePath(path);
583 return stat;
586 /******************************************************************************
587 * GdipCreatePathGradientFromPath [GDIPLUS.@]
589 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
590 GpPathGradient **grad)
592 GpStatus stat;
593 GpPath *new_path;
595 TRACE("(%p, %p)\n", path, grad);
597 if(!path || !grad)
598 return InvalidParameter;
600 stat = GdipClonePath((GpPath*)path, &new_path);
602 if (stat == Ok)
604 stat = create_path_gradient(new_path, grad);
606 if (stat != Ok)
607 GdipDeletePath(new_path);
610 return stat;
613 /******************************************************************************
614 * GdipCreateSolidFill [GDIPLUS.@]
616 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
618 TRACE("(%x, %p)\n", color, sf);
620 if(!sf) return InvalidParameter;
622 *sf = GdipAlloc(sizeof(GpSolidFill));
623 if (!*sf) return OutOfMemory;
625 (*sf)->brush.bt = BrushTypeSolidColor;
626 (*sf)->color = color;
628 TRACE("<-- %p\n", *sf);
630 return Ok;
633 /******************************************************************************
634 * GdipCreateTexture [GDIPLUS.@]
636 * PARAMS
637 * image [I] image to use
638 * wrapmode [I] optional
639 * texture [O] pointer to the resulting texturebrush
641 * RETURNS
642 * SUCCESS: Ok
643 * FAILURE: element of GpStatus
645 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
646 GpTexture **texture)
648 UINT width, height;
649 GpImageAttributes *attributes;
650 GpStatus stat;
652 TRACE("%p, %d %p\n", image, wrapmode, texture);
654 if (!(image && texture))
655 return InvalidParameter;
657 stat = GdipGetImageWidth(image, &width);
658 if (stat != Ok) return stat;
659 stat = GdipGetImageHeight(image, &height);
660 if (stat != Ok) return stat;
662 stat = GdipCreateImageAttributes(&attributes);
664 if (stat == Ok)
666 attributes->wrap = wrapmode;
668 stat = GdipCreateTextureIA(image, attributes, 0, 0, width, height,
669 texture);
671 GdipDisposeImageAttributes(attributes);
674 return stat;
677 /******************************************************************************
678 * GdipCreateTexture2 [GDIPLUS.@]
680 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
681 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
683 GpImageAttributes *attributes;
684 GpStatus stat;
686 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
687 x, y, width, height, texture);
689 stat = GdipCreateImageAttributes(&attributes);
691 if (stat == Ok)
693 attributes->wrap = wrapmode;
695 stat = GdipCreateTextureIA(image, attributes, x, y, width, height,
696 texture);
698 GdipDisposeImageAttributes(attributes);
701 return stat;
704 /******************************************************************************
705 * GdipCreateTextureIA [GDIPLUS.@]
707 * FIXME: imageattr ignored
709 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
710 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
711 REAL height, GpTexture **texture)
713 GpStatus status;
714 GpImage *new_image=NULL;
716 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
717 texture);
719 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
720 return InvalidParameter;
722 *texture = NULL;
724 if(image->type != ImageTypeBitmap){
725 FIXME("not implemented for image type %d\n", image->type);
726 return NotImplemented;
729 status = GdipCloneBitmapArea(x, y, width, height, PixelFormatDontCare, (GpBitmap*)image, (GpBitmap**)&new_image);
730 if (status != Ok)
731 return status;
733 *texture = GdipAlloc(sizeof(GpTexture));
734 if (!*texture){
735 status = OutOfMemory;
736 goto exit;
739 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
740 goto exit;
743 if (imageattr)
745 status = GdipCloneImageAttributes(imageattr, &(*texture)->imageattributes);
747 else
749 status = GdipCreateImageAttributes(&(*texture)->imageattributes);
750 if (status == Ok)
751 (*texture)->imageattributes->wrap = WrapModeTile;
753 if (status == Ok)
755 (*texture)->brush.bt = BrushTypeTextureFill;
756 (*texture)->image = new_image;
759 exit:
760 if (status == Ok)
762 TRACE("<-- %p\n", *texture);
764 else
766 if (*texture)
768 GdipDeleteMatrix((*texture)->transform);
769 GdipDisposeImageAttributes((*texture)->imageattributes);
770 GdipFree(*texture);
771 *texture = NULL;
773 GdipDisposeImage(new_image);
774 TRACE("<-- error %u\n", status);
777 return status;
780 /******************************************************************************
781 * GdipCreateTextureIAI [GDIPLUS.@]
783 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
784 INT x, INT y, INT width, INT height, GpTexture **texture)
786 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
787 texture);
789 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
792 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
793 INT x, INT y, INT width, INT height, GpTexture **texture)
795 GpImageAttributes *imageattr;
796 GpStatus stat;
798 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
799 texture);
801 stat = GdipCreateImageAttributes(&imageattr);
803 if (stat == Ok)
805 imageattr->wrap = wrapmode;
807 stat = GdipCreateTextureIA(image, imageattr, x, y, width, height, texture);
810 return stat;
813 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
815 TRACE("(%p, %p)\n", brush, type);
817 if(!brush || !type) return InvalidParameter;
819 *type = brush->bt;
821 return Ok;
824 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
826 TRACE("(%p, %p)\n", brush, backcol);
828 if(!brush || !backcol) return InvalidParameter;
830 *backcol = brush->backcol;
832 return Ok;
835 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
837 TRACE("(%p, %p)\n", brush, forecol);
839 if(!brush || !forecol) return InvalidParameter;
841 *forecol = brush->forecol;
843 return Ok;
846 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
848 TRACE("(%p, %p)\n", brush, hatchstyle);
850 if(!brush || !hatchstyle) return InvalidParameter;
852 *hatchstyle = brush->hatchstyle;
854 return Ok;
857 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
859 TRACE("(%p)\n", brush);
861 if(!brush) return InvalidParameter;
863 switch(brush->bt)
865 case BrushTypePathGradient:
866 GdipDeletePath(((GpPathGradient*) brush)->path);
867 GdipFree(((GpPathGradient*) brush)->blendfac);
868 GdipFree(((GpPathGradient*) brush)->blendpos);
869 break;
870 case BrushTypeLinearGradient:
871 GdipFree(((GpLineGradient*)brush)->blendfac);
872 GdipFree(((GpLineGradient*)brush)->blendpos);
873 GdipFree(((GpLineGradient*)brush)->pblendcolor);
874 GdipFree(((GpLineGradient*)brush)->pblendpos);
875 break;
876 case BrushTypeTextureFill:
877 GdipDeleteMatrix(((GpTexture*)brush)->transform);
878 GdipDisposeImage(((GpTexture*)brush)->image);
879 GdipDisposeImageAttributes(((GpTexture*)brush)->imageattributes);
880 GdipFree(((GpTexture*)brush)->bitmap_bits);
881 break;
882 default:
883 break;
886 GdipFree(brush);
888 return Ok;
891 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
892 BOOL *usinggamma)
894 TRACE("(%p, %p)\n", line, usinggamma);
896 if(!line || !usinggamma)
897 return InvalidParameter;
899 *usinggamma = line->gamma;
901 return Ok;
904 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
906 TRACE("(%p, %p)\n", brush, wrapmode);
908 if(!brush || !wrapmode)
909 return InvalidParameter;
911 *wrapmode = brush->wrap;
913 return Ok;
916 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
917 REAL *positions, INT count)
919 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
921 if(!brush || !blend || !positions || count <= 0)
922 return InvalidParameter;
924 if(count < brush->blendcount)
925 return InsufficientBuffer;
927 memcpy(blend, brush->blendfac, count*sizeof(REAL));
928 if(brush->blendcount > 1){
929 memcpy(positions, brush->blendpos, count*sizeof(REAL));
932 return Ok;
935 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
937 TRACE("(%p, %p)\n", brush, count);
939 if(!brush || !count)
940 return InvalidParameter;
942 *count = brush->blendcount;
944 return Ok;
947 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
948 GpPointF *point)
950 TRACE("(%p, %p)\n", grad, point);
952 if(!grad || !point)
953 return InvalidParameter;
955 point->X = grad->center.X;
956 point->Y = grad->center.Y;
958 return Ok;
961 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
962 GpPoint *point)
964 GpStatus ret;
965 GpPointF ptf;
967 TRACE("(%p, %p)\n", grad, point);
969 if(!point)
970 return InvalidParameter;
972 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
974 if(ret == Ok){
975 point->X = roundr(ptf.X);
976 point->Y = roundr(ptf.Y);
979 return ret;
982 GpStatus WINGDIPAPI GdipGetPathGradientCenterColor(GpPathGradient *grad,
983 ARGB *colors)
985 static int calls;
987 TRACE("(%p,%p)\n", grad, colors);
989 if(!(calls++))
990 FIXME("not implemented\n");
992 return NotImplemented;
995 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
996 REAL *x, REAL *y)
998 TRACE("(%p, %p, %p)\n", grad, x, y);
1000 if(!grad || !x || !y)
1001 return InvalidParameter;
1003 *x = grad->focus.X;
1004 *y = grad->focus.Y;
1006 return Ok;
1009 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1010 BOOL *gamma)
1012 TRACE("(%p, %p)\n", grad, gamma);
1014 if(!grad || !gamma)
1015 return InvalidParameter;
1017 *gamma = grad->gamma;
1019 return Ok;
1022 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1023 INT *count)
1025 TRACE("(%p, %p)\n", grad, count);
1027 if(!grad || !count)
1028 return InvalidParameter;
1030 *count = grad->path->pathdata.Count;
1032 return Ok;
1035 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1037 GpStatus stat;
1039 TRACE("(%p, %p)\n", brush, rect);
1041 if(!brush || !rect)
1042 return InvalidParameter;
1044 stat = GdipGetPathWorldBounds(brush->path, rect, NULL, NULL);
1046 return stat;
1049 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1051 GpRectF rectf;
1052 GpStatus stat;
1054 TRACE("(%p, %p)\n", brush, rect);
1056 if(!brush || !rect)
1057 return InvalidParameter;
1059 stat = GdipGetPathGradientRect(brush, &rectf);
1060 if(stat != Ok) return stat;
1062 rect->X = roundr(rectf.X);
1063 rect->Y = roundr(rectf.Y);
1064 rect->Width = roundr(rectf.Width);
1065 rect->Height = roundr(rectf.Height);
1067 return Ok;
1070 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1071 *grad, ARGB *argb, INT *count)
1073 static int calls;
1075 TRACE("(%p,%p,%p)\n", grad, argb, count);
1077 if(!grad || !argb || !count || (*count < grad->path->pathdata.Count))
1078 return InvalidParameter;
1080 if(!(calls++))
1081 FIXME("not implemented\n");
1083 return NotImplemented;
1086 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorCount(GpPathGradient *brush, INT *count)
1088 static int calls;
1090 TRACE("(%p, %p)\n", brush, count);
1092 if (!brush || !count)
1093 return InvalidParameter;
1095 if(!(calls++))
1096 FIXME("not implemented\n");
1098 return NotImplemented;
1101 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1102 GpWrapMode *wrapmode)
1104 TRACE("(%p, %p)\n", brush, wrapmode);
1106 if(!brush || !wrapmode)
1107 return InvalidParameter;
1109 *wrapmode = brush->wrap;
1111 return Ok;
1114 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1116 TRACE("(%p, %p)\n", sf, argb);
1118 if(!sf || !argb)
1119 return InvalidParameter;
1121 *argb = sf->color;
1123 return Ok;
1126 /******************************************************************************
1127 * GdipGetTextureImage [GDIPLUS.@]
1129 GpStatus WINGDIPAPI GdipGetTextureImage(GpTexture *brush, GpImage **image)
1131 TRACE("(%p, %p)\n", brush, image);
1133 if(!brush || !image)
1134 return InvalidParameter;
1136 return GdipCloneImage(brush->image, image);
1139 /******************************************************************************
1140 * GdipGetTextureTransform [GDIPLUS.@]
1142 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1144 TRACE("(%p, %p)\n", brush, matrix);
1146 if(!brush || !matrix)
1147 return InvalidParameter;
1149 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1151 return Ok;
1154 /******************************************************************************
1155 * GdipGetTextureWrapMode [GDIPLUS.@]
1157 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1159 TRACE("(%p, %p)\n", brush, wrapmode);
1161 if(!brush || !wrapmode)
1162 return InvalidParameter;
1164 *wrapmode = brush->imageattributes->wrap;
1166 return Ok;
1169 /******************************************************************************
1170 * GdipMultiplyTextureTransform [GDIPLUS.@]
1172 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1173 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1175 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1177 if(!brush || !matrix)
1178 return InvalidParameter;
1180 return GdipMultiplyMatrix(brush->transform, matrix, order);
1183 /******************************************************************************
1184 * GdipResetTextureTransform [GDIPLUS.@]
1186 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1188 TRACE("(%p)\n", brush);
1190 if(!brush)
1191 return InvalidParameter;
1193 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1196 /******************************************************************************
1197 * GdipScaleTextureTransform [GDIPLUS.@]
1199 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1200 REAL sx, REAL sy, GpMatrixOrder order)
1202 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1204 if(!brush)
1205 return InvalidParameter;
1207 return GdipScaleMatrix(brush->transform, sx, sy, order);
1210 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1211 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1213 REAL *new_blendfac, *new_blendpos;
1215 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1217 if(!brush || !factors || !positions || count <= 0 ||
1218 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1219 return InvalidParameter;
1221 new_blendfac = GdipAlloc(count * sizeof(REAL));
1222 new_blendpos = GdipAlloc(count * sizeof(REAL));
1224 if (!new_blendfac || !new_blendpos)
1226 GdipFree(new_blendfac);
1227 GdipFree(new_blendpos);
1228 return OutOfMemory;
1231 memcpy(new_blendfac, factors, count * sizeof(REAL));
1232 memcpy(new_blendpos, positions, count * sizeof(REAL));
1234 GdipFree(brush->blendfac);
1235 GdipFree(brush->blendpos);
1237 brush->blendcount = count;
1238 brush->blendfac = new_blendfac;
1239 brush->blendpos = new_blendpos;
1241 return Ok;
1244 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1245 REAL *positions, INT count)
1247 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1249 if (!brush || !factors || !positions || count <= 0)
1250 return InvalidParameter;
1252 if (count < brush->blendcount)
1253 return InsufficientBuffer;
1255 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1256 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1258 return Ok;
1261 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1263 TRACE("(%p, %p)\n", brush, count);
1265 if (!brush || !count)
1266 return InvalidParameter;
1268 *count = brush->blendcount;
1270 return Ok;
1273 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1274 BOOL usegamma)
1276 TRACE("(%p, %d)\n", line, usegamma);
1278 if(!line)
1279 return InvalidParameter;
1281 line->gamma = usegamma;
1283 return Ok;
1286 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1287 REAL scale)
1289 REAL factors[33];
1290 REAL positions[33];
1291 int num_points = 0;
1292 int i;
1293 const int precision = 16;
1294 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1295 REAL min_erf;
1296 REAL scale_erf;
1298 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1300 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1301 return InvalidParameter;
1303 /* we want 2 standard deviations */
1304 erf_range = 2.0 / sqrt(2);
1306 /* calculate the constants we need to normalize the error function to be
1307 between 0.0 and scale over the range we need */
1308 min_erf = erf(-erf_range);
1309 scale_erf = scale / (-2.0 * min_erf);
1311 if (focus != 0.0)
1313 positions[0] = 0.0;
1314 factors[0] = 0.0;
1315 for (i=1; i<precision; i++)
1317 positions[i] = focus * i / precision;
1318 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1320 num_points += precision;
1323 positions[num_points] = focus;
1324 factors[num_points] = scale;
1325 num_points += 1;
1327 if (focus != 1.0)
1329 for (i=1; i<precision; i++)
1331 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1332 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1334 num_points += precision;
1335 positions[num_points-1] = 1.0;
1336 factors[num_points-1] = 0.0;
1339 return GdipSetLineBlend(line, factors, positions, num_points);
1342 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1343 GpWrapMode wrap)
1345 TRACE("(%p, %d)\n", line, wrap);
1347 if(!line || wrap == WrapModeClamp)
1348 return InvalidParameter;
1350 line->wrap = wrap;
1352 return Ok;
1355 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1356 GDIPCONST REAL *pos, INT count)
1358 static int calls;
1360 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1362 if(!(calls++))
1363 FIXME("not implemented\n");
1365 return NotImplemented;
1368 GpStatus WINGDIPAPI GdipSetPathGradientLinearBlend(GpPathGradient *brush,
1369 REAL focus, REAL scale)
1371 static int calls;
1373 TRACE("(%p,%0.2f,%0.2f)\n", brush, focus, scale);
1375 if(!(calls++))
1376 FIXME("not implemented\n");
1378 return NotImplemented;
1381 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1382 GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1384 FIXME("(%p,%p,%p,%i): stub\n", brush, blend, pos, count);
1385 return NotImplemented;
1388 GpStatus WINGDIPAPI GdipGetPathGradientPresetBlend(GpPathGradient *brush,
1389 ARGB *blend, REAL *pos, INT count)
1391 FIXME("(%p,%p,%p,%i): stub\n", brush, blend, pos, count);
1392 return NotImplemented;
1395 GpStatus WINGDIPAPI GdipGetPathGradientPresetBlendCount(GpPathGradient *brush,
1396 INT *count)
1398 FIXME("(%p,%p): stub\n", brush, count);
1399 return NotImplemented;
1402 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1403 ARGB argb)
1405 TRACE("(%p, %x)\n", grad, argb);
1407 if(!grad)
1408 return InvalidParameter;
1410 grad->centercolor = argb;
1411 return Ok;
1414 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1415 GpPointF *point)
1417 TRACE("(%p, %s)\n", grad, debugstr_pointf(point));
1419 if(!grad || !point)
1420 return InvalidParameter;
1422 grad->center.X = point->X;
1423 grad->center.Y = point->Y;
1425 return Ok;
1428 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1429 GpPoint *point)
1431 GpPointF ptf;
1433 TRACE("(%p, %p)\n", grad, point);
1435 if(!point)
1436 return InvalidParameter;
1438 ptf.X = (REAL)point->X;
1439 ptf.Y = (REAL)point->Y;
1441 return GdipSetPathGradientCenterPoint(grad,&ptf);
1444 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1445 REAL x, REAL y)
1447 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1449 if(!grad)
1450 return InvalidParameter;
1452 grad->focus.X = x;
1453 grad->focus.Y = y;
1455 return Ok;
1458 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1459 BOOL gamma)
1461 TRACE("(%p, %d)\n", grad, gamma);
1463 if(!grad)
1464 return InvalidParameter;
1466 grad->gamma = gamma;
1468 return Ok;
1471 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1472 REAL focus, REAL scale)
1474 static int calls;
1476 TRACE("(%p,%0.2f,%0.2f)\n", grad, focus, scale);
1478 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1479 return InvalidParameter;
1481 if(!(calls++))
1482 FIXME("not implemented\n");
1484 return NotImplemented;
1487 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1488 *grad, GDIPCONST ARGB *argb, INT *count)
1490 static int calls;
1492 TRACE("(%p,%p,%p)\n", grad, argb, count);
1494 if(!grad || !argb || !count || (*count <= 0) ||
1495 (*count > grad->path->pathdata.Count))
1496 return InvalidParameter;
1498 if(!(calls++))
1499 FIXME("not implemented\n");
1501 return NotImplemented;
1504 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1505 GpWrapMode wrap)
1507 TRACE("(%p, %d)\n", grad, wrap);
1509 if(!grad)
1510 return InvalidParameter;
1512 grad->wrap = wrap;
1514 return Ok;
1517 GpStatus WINGDIPAPI GdipSetPathGradientTransform(GpPathGradient *grad,
1518 GpMatrix *matrix)
1520 static int calls;
1522 TRACE("(%p,%p)\n", grad, matrix);
1524 if(!(calls++))
1525 FIXME("not implemented\n");
1527 return NotImplemented;
1530 GpStatus WINGDIPAPI GdipGetPathGradientTransform(GpPathGradient *grad,
1531 GpMatrix *matrix)
1533 static int calls;
1535 TRACE("(%p,%p)\n", grad, matrix);
1537 if(!(calls++))
1538 FIXME("not implemented\n");
1540 return NotImplemented;
1543 GpStatus WINGDIPAPI GdipMultiplyPathGradientTransform(GpPathGradient *grad,
1544 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1546 static int calls;
1548 TRACE("(%p,%p,%i)\n", grad, matrix, order);
1550 if(!(calls++))
1551 FIXME("not implemented\n");
1553 return NotImplemented;
1556 GpStatus WINGDIPAPI GdipRotatePathGradientTransform(GpPathGradient *grad,
1557 REAL angle, GpMatrixOrder order)
1559 static int calls;
1561 TRACE("(%p,%0.2f,%i)\n", grad, angle, order);
1563 if(!(calls++))
1564 FIXME("not implemented\n");
1566 return NotImplemented;
1569 GpStatus WINGDIPAPI GdipScalePathGradientTransform(GpPathGradient *grad,
1570 REAL sx, REAL sy, GpMatrixOrder order)
1572 static int calls;
1574 TRACE("(%p,%0.2f,%0.2f,%i)\n", grad, sx, sy, order);
1576 if(!(calls++))
1577 FIXME("not implemented\n");
1579 return NotImplemented;
1582 GpStatus WINGDIPAPI GdipTranslatePathGradientTransform(GpPathGradient *grad,
1583 REAL dx, REAL dy, GpMatrixOrder order)
1585 static int calls;
1587 TRACE("(%p,%0.2f,%0.2f,%i)\n", grad, dx, dy, order);
1589 if(!(calls++))
1590 FIXME("not implemented\n");
1592 return NotImplemented;
1595 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1597 TRACE("(%p, %x)\n", sf, argb);
1599 if(!sf)
1600 return InvalidParameter;
1602 sf->color = argb;
1603 return Ok;
1606 /******************************************************************************
1607 * GdipSetTextureTransform [GDIPLUS.@]
1609 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1610 GDIPCONST GpMatrix *matrix)
1612 TRACE("(%p, %p)\n", texture, matrix);
1614 if(!texture || !matrix)
1615 return InvalidParameter;
1617 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1619 return Ok;
1622 /******************************************************************************
1623 * GdipSetTextureWrapMode [GDIPLUS.@]
1625 * WrapMode not used, only stored
1627 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1629 TRACE("(%p, %d)\n", brush, wrapmode);
1631 if(!brush)
1632 return InvalidParameter;
1634 brush->imageattributes->wrap = wrapmode;
1636 return Ok;
1639 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1640 ARGB color2)
1642 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1644 if(!brush)
1645 return InvalidParameter;
1647 brush->startcolor = color1;
1648 brush->endcolor = color2;
1650 return Ok;
1653 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1655 TRACE("(%p, %p)\n", brush, colors);
1657 if(!brush || !colors)
1658 return InvalidParameter;
1660 colors[0] = brush->startcolor;
1661 colors[1] = brush->endcolor;
1663 return Ok;
1666 /******************************************************************************
1667 * GdipRotateTextureTransform [GDIPLUS.@]
1669 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1670 GpMatrixOrder order)
1672 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1674 if(!brush)
1675 return InvalidParameter;
1677 return GdipRotateMatrix(brush->transform, angle, order);
1680 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1681 REAL scale)
1683 REAL factors[3];
1684 REAL positions[3];
1685 int num_points = 0;
1687 TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1689 if (!brush) return InvalidParameter;
1691 if (focus != 0.0)
1693 factors[num_points] = 0.0;
1694 positions[num_points] = 0.0;
1695 num_points++;
1698 factors[num_points] = scale;
1699 positions[num_points] = focus;
1700 num_points++;
1702 if (focus != 1.0)
1704 factors[num_points] = 0.0;
1705 positions[num_points] = 1.0;
1706 num_points++;
1709 return GdipSetLineBlend(brush, factors, positions, num_points);
1712 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1713 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1715 ARGB *new_color;
1716 REAL *new_pos;
1717 TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1719 if (!brush || !blend || !positions || count < 2 ||
1720 positions[0] != 0.0f || positions[count-1] != 1.0f)
1722 return InvalidParameter;
1725 new_color = GdipAlloc(count * sizeof(ARGB));
1726 new_pos = GdipAlloc(count * sizeof(REAL));
1727 if (!new_color || !new_pos)
1729 GdipFree(new_color);
1730 GdipFree(new_pos);
1731 return OutOfMemory;
1734 memcpy(new_color, blend, sizeof(ARGB) * count);
1735 memcpy(new_pos, positions, sizeof(REAL) * count);
1737 GdipFree(brush->pblendcolor);
1738 GdipFree(brush->pblendpos);
1740 brush->pblendcolor = new_color;
1741 brush->pblendpos = new_pos;
1742 brush->pblendcount = count;
1744 return Ok;
1747 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1748 ARGB *blend, REAL* positions, INT count)
1750 if (!brush || !blend || !positions || count < 2)
1751 return InvalidParameter;
1753 if (brush->pblendcount == 0)
1754 return GenericError;
1756 if (count < brush->pblendcount)
1757 return InsufficientBuffer;
1759 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1760 memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1762 return Ok;
1765 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1766 INT *count)
1768 if (!brush || !count)
1769 return InvalidParameter;
1771 *count = brush->pblendcount;
1773 return Ok;
1776 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1778 static int calls;
1780 TRACE("(%p)\n", brush);
1782 if(!(calls++))
1783 FIXME("not implemented\n");
1785 return NotImplemented;
1788 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1789 GDIPCONST GpMatrix *matrix)
1791 static int calls;
1793 TRACE("(%p,%p)\n", brush, matrix);
1795 if(!(calls++))
1796 FIXME("not implemented\n");
1798 return NotImplemented;
1801 GpStatus WINGDIPAPI GdipGetLineTransform(GpLineGradient *brush, GpMatrix *matrix)
1803 static int calls;
1805 TRACE("(%p,%p)\n", brush, matrix);
1807 if(!(calls++))
1808 FIXME("not implemented\n");
1810 return NotImplemented;
1813 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
1814 GpMatrixOrder order)
1816 static int calls;
1818 TRACE("(%p,%0.2f,%0.2f,%u)\n", brush, sx, sy, order);
1820 if(!(calls++))
1821 FIXME("not implemented\n");
1823 return NotImplemented;
1826 GpStatus WINGDIPAPI GdipMultiplyLineTransform(GpLineGradient *brush,
1827 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1829 static int calls;
1831 TRACE("(%p,%p,%u)\n", brush, matrix, order);
1833 if(!(calls++))
1834 FIXME("not implemented\n");
1836 return NotImplemented;
1839 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1840 REAL dx, REAL dy, GpMatrixOrder order)
1842 static int calls;
1844 TRACE("(%p,%f,%f,%d)\n", brush, dx, dy, order);
1846 if(!(calls++))
1847 FIXME("not implemented\n");
1849 return Ok;
1852 /******************************************************************************
1853 * GdipTranslateTextureTransform [GDIPLUS.@]
1855 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1856 GpMatrixOrder order)
1858 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1860 if(!brush)
1861 return InvalidParameter;
1863 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1866 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1868 TRACE("(%p, %p)\n", brush, rect);
1870 if(!brush || !rect)
1871 return InvalidParameter;
1873 *rect = brush->rect;
1875 return Ok;
1878 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1880 GpRectF rectF;
1881 GpStatus ret;
1883 TRACE("(%p, %p)\n", brush, rect);
1885 if(!rect)
1886 return InvalidParameter;
1888 ret = GdipGetLineRect(brush, &rectF);
1890 if(ret == Ok){
1891 rect->X = roundr(rectF.X);
1892 rect->Y = roundr(rectF.Y);
1893 rect->Width = roundr(rectF.Width);
1894 rect->Height = roundr(rectF.Height);
1897 return ret;
1900 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1901 REAL angle, GpMatrixOrder order)
1903 static int calls;
1905 TRACE("(%p,%0.2f,%u)\n", brush, angle, order);
1907 if(!brush)
1908 return InvalidParameter;
1910 if(!(calls++))
1911 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1913 return NotImplemented;