msi: Handle signature filenames in short|long notation.
[wine] / dlls / gdiplus / brush.c
1 /*
2  * Copyright (C) 2007 Google (Evan Stade)
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winuser.h"
24 #include "wingdi.h"
25
26 #define COBJMACROS
27 #include "objbase.h"
28 #include "olectl.h"
29 #include "ole2.h"
30
31 #include "gdiplus.h"
32 #include "gdiplus_private.h"
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
36
37 /******************************************************************************
38  * GdipCloneBrush [GDIPLUS.@]
39  */
40 GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone)
41 {
42     TRACE("(%p, %p)\n", brush, clone);
43
44     if(!brush || !clone)
45         return InvalidParameter;
46
47     switch(brush->bt){
48         case BrushTypeSolidColor:
49         {
50             GpSolidFill *fill;
51             *clone = GdipAlloc(sizeof(GpSolidFill));
52             if (!*clone) return OutOfMemory;
53
54             fill = (GpSolidFill*)*clone;
55
56             memcpy(*clone, brush, sizeof(GpSolidFill));
57
58             (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
59             fill->bmp = ARGB2BMP(fill->color);
60             break;
61         }
62         case BrushTypeHatchFill:
63         {
64             GpHatch *hatch = (GpHatch*)brush;
65
66             return GdipCreateHatchBrush(hatch->hatchstyle, hatch->forecol, hatch->backcol, (GpHatch**)clone);
67         }
68         case BrushTypePathGradient:{
69             GpPathGradient *src, *dest;
70             INT count;
71
72             *clone = GdipAlloc(sizeof(GpPathGradient));
73             if (!*clone) return OutOfMemory;
74
75             src = (GpPathGradient*) brush,
76             dest = (GpPathGradient*) *clone;
77             count = src->pathdata.Count;
78
79             memcpy(dest, src, sizeof(GpPathGradient));
80
81             dest->pathdata.Count = count;
82             dest->pathdata.Points = GdipAlloc(count * sizeof(PointF));
83             dest->pathdata.Types = GdipAlloc(count);
84
85             if(!dest->pathdata.Points || !dest->pathdata.Types){
86                 GdipFree(dest->pathdata.Points);
87                 GdipFree(dest->pathdata.Types);
88                 GdipFree(dest);
89                 return OutOfMemory;
90             }
91
92             memcpy(dest->pathdata.Points, src->pathdata.Points, count * sizeof(PointF));
93             memcpy(dest->pathdata.Types, src->pathdata.Types, count);
94
95             /* blending */
96             count = src->blendcount;
97             dest->blendcount = count;
98             dest->blendfac = GdipAlloc(count * sizeof(REAL));
99             dest->blendpos = GdipAlloc(count * sizeof(REAL));
100
101             if(!dest->blendfac || !dest->blendpos){
102                 GdipFree(dest->pathdata.Points);
103                 GdipFree(dest->pathdata.Types);
104                 GdipFree(dest->blendfac);
105                 GdipFree(dest->blendpos);
106                 GdipFree(dest);
107                 return OutOfMemory;
108             }
109
110             memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
111             memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
112
113             break;
114         }
115         case BrushTypeLinearGradient:{
116             GpLineGradient *dest, *src;
117             INT count, pcount;
118
119             dest = GdipAlloc(sizeof(GpLineGradient));
120             if(!dest)    return OutOfMemory;
121
122             src = (GpLineGradient*)brush;
123
124             memcpy(dest, src, sizeof(GpLineGradient));
125
126             dest->brush.gdibrush = CreateSolidBrush(dest->brush.lb.lbColor);
127
128             count = dest->blendcount;
129             dest->blendfac = GdipAlloc(count * sizeof(REAL));
130             dest->blendpos = GdipAlloc(count * sizeof(REAL));
131             pcount = dest->pblendcount;
132             if (pcount)
133             {
134                 dest->pblendcolor = GdipAlloc(pcount * sizeof(ARGB));
135                 dest->pblendpos = GdipAlloc(pcount * sizeof(REAL));
136             }
137
138             if (!dest->blendfac || !dest->blendpos ||
139                 (pcount && (!dest->pblendcolor || !dest->pblendpos)))
140             {
141                 GdipFree(dest->blendfac);
142                 GdipFree(dest->blendpos);
143                 GdipFree(dest->pblendcolor);
144                 GdipFree(dest->pblendpos);
145                 DeleteObject(dest->brush.gdibrush);
146                 GdipFree(dest);
147                 return OutOfMemory;
148             }
149
150             memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
151             memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
152
153             if (pcount)
154             {
155                 memcpy(dest->pblendcolor, src->pblendcolor, pcount * sizeof(ARGB));
156                 memcpy(dest->pblendpos, src->pblendpos, pcount * sizeof(REAL));
157             }
158
159             *clone = &dest->brush;
160             break;
161         }
162         case BrushTypeTextureFill:
163         {
164             GpStatus stat;
165             GpTexture *texture = (GpTexture*)brush;
166             GpTexture *new_texture;
167
168             stat = GdipCreateTexture(texture->image, texture->wrap, &new_texture);
169
170             if (stat == Ok)
171             {
172                 memcpy(new_texture->transform, texture->transform, sizeof(GpMatrix));
173                 *clone = (GpBrush*)new_texture;
174             }
175             else
176                 *clone = NULL;
177
178             return stat;
179         }
180         default:
181             ERR("not implemented for brush type %d\n", brush->bt);
182             return NotImplemented;
183     }
184
185     TRACE("<-- %p\n", *clone);
186     return Ok;
187 }
188
189 static const char HatchBrushes[][8] = {
190     { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HatchStyleHorizontal */
191     { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleVertical */
192     { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HatchStyleForwardDiagonal */
193     { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HatchStyleBackwardDiagonal */
194     { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleCross */
195     { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }, /* HatchStyleDiagonalCross */
196     { 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x80 }, /* HatchStyle05Percent */
197     { 0x00, 0x02, 0x00, 0x88, 0x00, 0x20, 0x00, 0x88 }, /* HatchStyle10Percent */
198     { 0x00, 0x22, 0x00, 0xcc, 0x00, 0x22, 0x00, 0xcc }, /* HatchStyle20Percent */
199     { 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc }, /* HatchStyle25Percent */
200     { 0x00, 0xcc, 0x04, 0xcc, 0x00, 0xcc, 0x40, 0xcc }, /* HatchStyle30Percent */
201     { 0x44, 0xcc, 0x22, 0xcc, 0x44, 0xcc, 0x22, 0xcc }, /* HatchStyle40Percent */
202     { 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc }, /* HatchStyle50Percent */
203     { 0x55, 0xcd, 0x55, 0xee, 0x55, 0xdc, 0x55, 0xee }, /* HatchStyle60Percent */
204     { 0x55, 0xdd, 0x55, 0xff, 0x55, 0xdd, 0x55, 0xff }, /* HatchStyle70Percent */
205     { 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff }, /* HatchStyle75Percent */
206     { 0x55, 0xff, 0x59, 0xff, 0x55, 0xff, 0x99, 0xff }, /* HatchStyle80Percent */
207     { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xfd, 0xff }, /* HatchStyle90Percent */
208     { 0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88 }, /* HatchStyleLightDownwardDiagonal */
209     { 0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11 }, /* HatchStyleLightUpwardDiagonal */
210     { 0x99, 0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc }, /* HatchStyleDarkDownwardDiagonal */
211     { 0xcc, 0x66, 0x33, 0x99, 0xcc, 0x66, 0x33, 0x99 }, /* HatchStyleDarkUpwardDiagonal */
212     { 0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0 }, /* HatchStyleWideDownwardDiagonal */
213     { 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x83, 0xc1 }, /* HatchStyleWideUpwardDiagonal */
214     { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 }, /* HatchStyleLightVertical */
215     { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff }, /* HatchStyleLightHorizontal */
216     { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }, /* HatchStyleNarrowVertical */
217     { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, /* HatchStyleNarrowHorizontal */
218     { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }, /* HatchStyleDarkVertical */
219     { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff }, /* HatchStyleDarkHorizontal */
220 };
221
222 /******************************************************************************
223  * GdipCreateHatchBrush [GDIPLUS.@]
224  */
225 GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle hatchstyle, ARGB forecol, ARGB backcol, GpHatch **brush)
226 {
227     COLORREF fgcol = ARGB2COLORREF(forecol);
228     GpStatus stat = Ok;
229
230     TRACE("(%d, %d, %d, %p)\n", hatchstyle, forecol, backcol, brush);
231
232     if(!brush)  return InvalidParameter;
233
234     *brush = GdipAlloc(sizeof(GpHatch));
235     if (!*brush) return OutOfMemory;
236
237     if (hatchstyle < sizeof(HatchBrushes) / sizeof(HatchBrushes[0]))
238     {
239         HBITMAP hbmp;
240         HDC hdc;
241         BITMAPINFOHEADER bmih;
242         DWORD* bits;
243         int x, y;
244
245         hdc = CreateCompatibleDC(0);
246
247         if (hdc)
248         {
249             bmih.biSize = sizeof(bmih);
250             bmih.biWidth = 8;
251             bmih.biHeight = 8;
252             bmih.biPlanes = 1;
253             bmih.biBitCount = 32;
254             bmih.biCompression = BI_RGB;
255             bmih.biSizeImage = 0;
256
257             hbmp = CreateDIBSection(hdc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
258
259             if (hbmp)
260             {
261                 for (y=0; y<8; y++)
262                     for (x=0; x<8; x++)
263                         if ((HatchBrushes[hatchstyle][y] & (0x80 >> x)) != 0)
264                             bits[y*8+x] = forecol;
265                         else
266                             bits[y*8+x] = backcol;
267             }
268             else
269                 stat = GenericError;
270
271             DeleteDC(hdc);
272         }
273         else
274             stat = GenericError;
275
276         if (stat == Ok)
277         {
278             (*brush)->brush.lb.lbStyle = BS_PATTERN;
279             (*brush)->brush.lb.lbColor = 0;
280             (*brush)->brush.lb.lbHatch = (ULONG_PTR)hbmp;
281             (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
282
283             DeleteObject(hbmp);
284         }
285     }
286     else
287     {
288         FIXME("Unimplemented hatch style %d\n", hatchstyle);
289
290         (*brush)->brush.lb.lbStyle = BS_SOLID;
291         (*brush)->brush.lb.lbColor = fgcol;
292         (*brush)->brush.lb.lbHatch = 0;
293         (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
294     }
295
296     if (stat == Ok)
297     {
298         (*brush)->brush.bt = BrushTypeHatchFill;
299         (*brush)->forecol = forecol;
300         (*brush)->backcol = backcol;
301         (*brush)->hatchstyle = hatchstyle;
302         TRACE("<-- %p\n", *brush);
303     }
304     else
305     {
306         GdipFree(*brush);
307         *brush = NULL;
308     }
309
310     return stat;
311 }
312
313 /******************************************************************************
314  * GdipCreateLineBrush [GDIPLUS.@]
315  */
316 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
317     GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
318     GpWrapMode wrap, GpLineGradient **line)
319 {
320     COLORREF col = ARGB2COLORREF(startcolor);
321
322     TRACE("(%s, %s, %x, %x, %d, %p)\n", debugstr_pointf(startpoint),
323           debugstr_pointf(endpoint), startcolor, endcolor, wrap, line);
324
325     if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
326         return InvalidParameter;
327
328     *line = GdipAlloc(sizeof(GpLineGradient));
329     if(!*line)  return OutOfMemory;
330
331     (*line)->brush.lb.lbStyle = BS_SOLID;
332     (*line)->brush.lb.lbColor = col;
333     (*line)->brush.lb.lbHatch = 0;
334     (*line)->brush.gdibrush = CreateSolidBrush(col);
335     (*line)->brush.bt = BrushTypeLinearGradient;
336
337     (*line)->startpoint.X = startpoint->X;
338     (*line)->startpoint.Y = startpoint->Y;
339     (*line)->endpoint.X = endpoint->X;
340     (*line)->endpoint.Y = endpoint->Y;
341     (*line)->startcolor = startcolor;
342     (*line)->endcolor = endcolor;
343     (*line)->wrap = wrap;
344     (*line)->gamma = FALSE;
345
346     (*line)->rect.X = (startpoint->X < endpoint->X ? startpoint->X: endpoint->X);
347     (*line)->rect.Y = (startpoint->Y < endpoint->Y ? startpoint->Y: endpoint->Y);
348     (*line)->rect.Width  = fabs(startpoint->X - endpoint->X);
349     (*line)->rect.Height = fabs(startpoint->Y - endpoint->Y);
350
351     if ((*line)->rect.Width == 0)
352     {
353         (*line)->rect.X -= (*line)->rect.Height / 2.0f;
354         (*line)->rect.Width = (*line)->rect.Height;
355     }
356     else if ((*line)->rect.Height == 0)
357     {
358         (*line)->rect.Y -= (*line)->rect.Width / 2.0f;
359         (*line)->rect.Height = (*line)->rect.Width;
360     }
361
362     (*line)->blendcount = 1;
363     (*line)->blendfac = GdipAlloc(sizeof(REAL));
364     (*line)->blendpos = GdipAlloc(sizeof(REAL));
365
366     if (!(*line)->blendfac || !(*line)->blendpos)
367     {
368         GdipFree((*line)->blendfac);
369         GdipFree((*line)->blendpos);
370         DeleteObject((*line)->brush.gdibrush);
371         GdipFree(*line);
372         *line = NULL;
373         return OutOfMemory;
374     }
375
376     (*line)->blendfac[0] = 1.0f;
377     (*line)->blendpos[0] = 1.0f;
378
379     (*line)->pblendcolor = NULL;
380     (*line)->pblendpos = NULL;
381     (*line)->pblendcount = 0;
382
383     TRACE("<-- %p\n", *line);
384
385     return Ok;
386 }
387
388 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
389     GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
390     GpWrapMode wrap, GpLineGradient **line)
391 {
392     GpPointF stF;
393     GpPointF endF;
394
395     TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
396           startcolor, endcolor, wrap, line);
397
398     if(!startpoint || !endpoint)
399         return InvalidParameter;
400
401     stF.X  = (REAL)startpoint->X;
402     stF.Y  = (REAL)startpoint->Y;
403     endF.X = (REAL)endpoint->X;
404     endF.X = (REAL)endpoint->Y;
405
406     return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
407 }
408
409 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
410     ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
411     GpLineGradient **line)
412 {
413     GpPointF start, end;
414     GpStatus stat;
415
416     TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
417           wrap, line);
418
419     if(!line || !rect)
420         return InvalidParameter;
421
422     switch (mode)
423     {
424     case LinearGradientModeHorizontal:
425         start.X = rect->X;
426         start.Y = rect->Y;
427         end.X = rect->X + rect->Width;
428         end.Y = rect->Y;
429         break;
430     case LinearGradientModeVertical:
431         start.X = rect->X;
432         start.Y = rect->Y;
433         end.X = rect->X;
434         end.Y = rect->Y + rect->Height;
435         break;
436     case LinearGradientModeForwardDiagonal:
437         start.X = rect->X;
438         start.Y = rect->Y;
439         end.X = rect->X + rect->Width;
440         end.Y = rect->Y + rect->Height;
441         break;
442     case LinearGradientModeBackwardDiagonal:
443         start.X = rect->X + rect->Width;
444         start.Y = rect->Y;
445         end.X = rect->X;
446         end.Y = rect->Y + rect->Height;
447         break;
448     default:
449         return InvalidParameter;
450     }
451
452     stat = GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
453
454     if (stat == Ok)
455         (*line)->rect = *rect;
456
457     return stat;
458 }
459
460 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
461     ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
462     GpLineGradient **line)
463 {
464     GpRectF rectF;
465
466     TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
467           wrap, line);
468
469     rectF.X      = (REAL) rect->X;
470     rectF.Y      = (REAL) rect->Y;
471     rectF.Width  = (REAL) rect->Width;
472     rectF.Height = (REAL) rect->Height;
473
474     return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
475 }
476
477 /******************************************************************************
478  * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
479  */
480 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
481     ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
482     GpLineGradient **line)
483 {
484     GpStatus stat;
485     LinearGradientMode mode;
486     REAL width, height, exofs, eyofs;
487     REAL sin_angle, cos_angle, sin_cos_angle;
488
489     TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
490           wrap, line);
491
492     sin_angle = sinf(deg2rad(angle));
493     cos_angle = cosf(deg2rad(angle));
494     sin_cos_angle = sin_angle * cos_angle;
495
496     if (isAngleScalable)
497     {
498         width = height = 1.0;
499     }
500     else
501     {
502         width = rect->Width;
503         height = rect->Height;
504     }
505
506     if (sin_cos_angle >= 0)
507         mode = LinearGradientModeForwardDiagonal;
508     else
509         mode = LinearGradientModeBackwardDiagonal;
510
511     stat = GdipCreateLineBrushFromRect(rect, startcolor, endcolor, mode, wrap, line);
512
513     if (stat == Ok)
514     {
515         if (sin_cos_angle >= 0)
516         {
517             exofs = width * sin_cos_angle + height * cos_angle * cos_angle;
518             eyofs = width * sin_angle * sin_angle + height * sin_cos_angle;
519         }
520         else
521         {
522             exofs = width * sin_angle * sin_angle + height * sin_cos_angle;
523             eyofs = -width * sin_cos_angle + height * sin_angle * sin_angle;
524         }
525
526         if (isAngleScalable)
527         {
528             exofs = exofs * rect->Width;
529             eyofs = eyofs * rect->Height;
530         }
531
532         if (sin_angle >= 0)
533         {
534             (*line)->endpoint.X = rect->X + exofs;
535             (*line)->endpoint.Y = rect->Y + eyofs;
536         }
537         else
538         {
539             (*line)->endpoint.X = (*line)->startpoint.X;
540             (*line)->endpoint.Y = (*line)->startpoint.Y;
541             (*line)->startpoint.X = rect->X + exofs;
542             (*line)->startpoint.Y = rect->Y + eyofs;
543         }
544     }
545
546     return stat;
547 }
548
549 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
550     ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
551     GpLineGradient **line)
552 {
553     TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
554           wrap, line);
555
556     return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
557                                         wrap, line);
558 }
559
560 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
561     INT count, GpWrapMode wrap, GpPathGradient **grad)
562 {
563     COLORREF col = ARGB2COLORREF(0xffffffff);
564
565     TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
566
567     if(!points || !grad)
568         return InvalidParameter;
569
570     if(count <= 0)
571         return OutOfMemory;
572
573     *grad = GdipAlloc(sizeof(GpPathGradient));
574     if (!*grad) return OutOfMemory;
575
576     (*grad)->blendfac = GdipAlloc(sizeof(REAL));
577     (*grad)->blendpos = GdipAlloc(sizeof(REAL));
578     if(!(*grad)->blendfac || !(*grad)->blendpos){
579         GdipFree((*grad)->blendfac);
580         GdipFree((*grad)->blendpos);
581         GdipFree(*grad);
582         *grad = NULL;
583         return OutOfMemory;
584     }
585     (*grad)->blendfac[0] = 1.0;
586     (*grad)->blendpos[0] = 1.0;
587     (*grad)->blendcount  = 1;
588
589     (*grad)->pathdata.Count = count;
590     (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
591     (*grad)->pathdata.Types = GdipAlloc(count);
592
593     if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
594         GdipFree((*grad)->pathdata.Points);
595         GdipFree((*grad)->pathdata.Types);
596         GdipFree(*grad);
597         return OutOfMemory;
598     }
599
600     memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
601     memset((*grad)->pathdata.Types, PathPointTypeLine, count);
602
603     (*grad)->brush.lb.lbStyle = BS_SOLID;
604     (*grad)->brush.lb.lbColor = col;
605     (*grad)->brush.lb.lbHatch = 0;
606
607     (*grad)->brush.gdibrush = CreateSolidBrush(col);
608     (*grad)->brush.bt = BrushTypePathGradient;
609     (*grad)->centercolor = 0xffffffff;
610     (*grad)->wrap = wrap;
611     (*grad)->gamma = FALSE;
612     (*grad)->center.X = 0.0;
613     (*grad)->center.Y = 0.0;
614     (*grad)->focus.X = 0.0;
615     (*grad)->focus.Y = 0.0;
616
617     TRACE("<-- %p\n", *grad);
618
619     return Ok;
620 }
621
622 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
623     INT count, GpWrapMode wrap, GpPathGradient **grad)
624 {
625     GpPointF *pointsF;
626     GpStatus ret;
627     INT i;
628
629     TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
630
631     if(!points || !grad)
632         return InvalidParameter;
633
634     if(count <= 0)
635         return OutOfMemory;
636
637     pointsF = GdipAlloc(sizeof(GpPointF) * count);
638     if(!pointsF)
639         return OutOfMemory;
640
641     for(i = 0; i < count; i++){
642         pointsF[i].X = (REAL)points[i].X;
643         pointsF[i].Y = (REAL)points[i].Y;
644     }
645
646     ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
647     GdipFree(pointsF);
648
649     return ret;
650 }
651
652 /******************************************************************************
653  * GdipCreatePathGradientFromPath [GDIPLUS.@]
654  *
655  * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
656  */
657 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
658     GpPathGradient **grad)
659 {
660     COLORREF col = ARGB2COLORREF(0xffffffff);
661
662     TRACE("(%p, %p)\n", path, grad);
663
664     if(!path || !grad)
665         return InvalidParameter;
666
667     *grad = GdipAlloc(sizeof(GpPathGradient));
668     if (!*grad) return OutOfMemory;
669
670     (*grad)->blendfac = GdipAlloc(sizeof(REAL));
671     (*grad)->blendpos = GdipAlloc(sizeof(REAL));
672     if(!(*grad)->blendfac || !(*grad)->blendpos){
673         GdipFree((*grad)->blendfac);
674         GdipFree((*grad)->blendpos);
675         GdipFree(*grad);
676         *grad = NULL;
677         return OutOfMemory;
678     }
679     (*grad)->blendfac[0] = 1.0;
680     (*grad)->blendpos[0] = 1.0;
681     (*grad)->blendcount  = 1;
682
683     (*grad)->pathdata.Count = path->pathdata.Count;
684     (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
685     (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
686
687     if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
688         GdipFree((*grad)->pathdata.Points);
689         GdipFree((*grad)->pathdata.Types);
690         GdipFree(*grad);
691         return OutOfMemory;
692     }
693
694     memcpy((*grad)->pathdata.Points, path->pathdata.Points,
695            path->pathdata.Count * sizeof(PointF));
696     memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
697
698     (*grad)->brush.lb.lbStyle = BS_SOLID;
699     (*grad)->brush.lb.lbColor = col;
700     (*grad)->brush.lb.lbHatch = 0;
701
702     (*grad)->brush.gdibrush = CreateSolidBrush(col);
703     (*grad)->brush.bt = BrushTypePathGradient;
704     (*grad)->centercolor = 0xffffffff;
705     (*grad)->wrap = WrapModeClamp;
706     (*grad)->gamma = FALSE;
707     /* FIXME: this should be set to the "centroid" of the path by default */
708     (*grad)->center.X = 0.0;
709     (*grad)->center.Y = 0.0;
710     (*grad)->focus.X = 0.0;
711     (*grad)->focus.Y = 0.0;
712
713     TRACE("<-- %p\n", *grad);
714
715     return Ok;
716 }
717
718 /******************************************************************************
719  * GdipCreateSolidFill [GDIPLUS.@]
720  */
721 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
722 {
723     COLORREF col = ARGB2COLORREF(color);
724
725     TRACE("(%x, %p)\n", color, sf);
726
727     if(!sf)  return InvalidParameter;
728
729     *sf = GdipAlloc(sizeof(GpSolidFill));
730     if (!*sf) return OutOfMemory;
731
732     (*sf)->brush.lb.lbStyle = BS_SOLID;
733     (*sf)->brush.lb.lbColor = col;
734     (*sf)->brush.lb.lbHatch = 0;
735
736     (*sf)->brush.gdibrush = CreateSolidBrush(col);
737     (*sf)->brush.bt = BrushTypeSolidColor;
738     (*sf)->color = color;
739     (*sf)->bmp = ARGB2BMP(color);
740
741     TRACE("<-- %p\n", *sf);
742
743     return Ok;
744 }
745
746 /******************************************************************************
747  * GdipCreateTexture [GDIPLUS.@]
748  *
749  * PARAMS
750  *  image       [I] image to use
751  *  wrapmode    [I] optional
752  *  texture     [O] pointer to the resulting texturebrush
753  *
754  * RETURNS
755  *  SUCCESS: Ok
756  *  FAILURE: element of GpStatus
757  */
758 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
759         GpTexture **texture)
760 {
761     UINT width, height;
762     GpImageAttributes attributes;
763     GpStatus stat;
764
765     TRACE("%p, %d %p\n", image, wrapmode, texture);
766
767     if (!(image && texture))
768         return InvalidParameter;
769
770     stat = GdipGetImageWidth(image, &width);
771     if (stat != Ok) return stat;
772     stat = GdipGetImageHeight(image, &height);
773     if (stat != Ok) return stat;
774     attributes.wrap = wrapmode;
775
776     return GdipCreateTextureIA(image, &attributes, 0, 0, width, height,
777             texture);
778 }
779
780 /******************************************************************************
781  * GdipCreateTexture2 [GDIPLUS.@]
782  */
783 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
784         REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
785 {
786     GpImageAttributes attributes;
787
788     TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
789             x, y, width, height, texture);
790
791     attributes.wrap = wrapmode;
792     return GdipCreateTextureIA(image, &attributes, x, y, width, height,
793             texture);
794 }
795
796 /******************************************************************************
797  * GdipCreateTextureIA [GDIPLUS.@]
798  *
799  * FIXME: imageattr ignored
800  */
801 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
802     GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
803     REAL height, GpTexture **texture)
804 {
805     HBITMAP hbm=NULL;
806     GpStatus status;
807     GpImage *new_image=NULL;
808
809     TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
810            texture);
811
812     if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
813         return InvalidParameter;
814
815     *texture = NULL;
816
817     if(image->type != ImageTypeBitmap){
818         FIXME("not implemented for image type %d\n", image->type);
819         return NotImplemented;
820     }
821
822     status = GdipCloneBitmapArea(x, y, width, height, PixelFormatDontCare, (GpBitmap*)image, (GpBitmap**)&new_image);
823     if (status != Ok)
824         return status;
825
826     status = GdipCreateHBITMAPFromBitmap((GpBitmap*)new_image, &hbm, 0);
827     if(!hbm)
828     {
829         status = GenericError;
830         goto exit;
831     }
832
833     *texture = GdipAlloc(sizeof(GpTexture));
834     if (!*texture){
835         status = OutOfMemory;
836         goto exit;
837     }
838
839     if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
840         goto exit;
841     }
842
843     (*texture)->brush.lb.lbStyle = BS_PATTERN;
844     (*texture)->brush.lb.lbColor = 0;
845     (*texture)->brush.lb.lbHatch = (ULONG_PTR)hbm;
846
847     (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
848     (*texture)->brush.bt = BrushTypeTextureFill;
849     if (imageattr)
850         (*texture)->wrap = imageattr->wrap;
851     else
852         (*texture)->wrap = WrapModeTile;
853     (*texture)->image = new_image;
854
855 exit:
856     if (status == Ok)
857     {
858         TRACE("<-- %p\n", *texture);
859     }
860     else
861     {
862         if (*texture)
863         {
864             GdipDeleteMatrix((*texture)->transform);
865             GdipFree(*texture);
866             *texture = NULL;
867         }
868         GdipDisposeImage(new_image);
869         TRACE("<-- error %u\n", status);
870     }
871
872     DeleteObject(hbm);
873
874     return status;
875 }
876
877 /******************************************************************************
878  * GdipCreateTextureIAI [GDIPLUS.@]
879  */
880 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
881     INT x, INT y, INT width, INT height, GpTexture **texture)
882 {
883     TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
884            texture);
885
886     return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
887 }
888
889 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
890         INT x, INT y, INT width, INT height, GpTexture **texture)
891 {
892     GpImageAttributes imageattr;
893
894     TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
895             texture);
896
897     imageattr.wrap = wrapmode;
898
899     return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
900 }
901
902 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
903 {
904     TRACE("(%p, %p)\n", brush, type);
905
906     if(!brush || !type)  return InvalidParameter;
907
908     *type = brush->bt;
909
910     return Ok;
911 }
912
913 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
914 {
915     TRACE("(%p, %p)\n", brush, backcol);
916
917     if(!brush || !backcol)  return InvalidParameter;
918
919     *backcol = brush->backcol;
920
921     return Ok;
922 }
923
924 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
925 {
926     TRACE("(%p, %p)\n", brush, forecol);
927
928     if(!brush || !forecol)  return InvalidParameter;
929
930     *forecol = brush->forecol;
931
932     return Ok;
933 }
934
935 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
936 {
937     TRACE("(%p, %p)\n", brush, hatchstyle);
938
939     if(!brush || !hatchstyle)  return InvalidParameter;
940
941     *hatchstyle = brush->hatchstyle;
942
943     return Ok;
944 }
945
946 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
947 {
948     TRACE("(%p)\n", brush);
949
950     if(!brush)  return InvalidParameter;
951
952     switch(brush->bt)
953     {
954         case BrushTypePathGradient:
955             GdipFree(((GpPathGradient*) brush)->pathdata.Points);
956             GdipFree(((GpPathGradient*) brush)->pathdata.Types);
957             GdipFree(((GpPathGradient*) brush)->blendfac);
958             GdipFree(((GpPathGradient*) brush)->blendpos);
959             break;
960         case BrushTypeSolidColor:
961             if (((GpSolidFill*)brush)->bmp)
962                 DeleteObject(((GpSolidFill*)brush)->bmp);
963             break;
964         case BrushTypeLinearGradient:
965             GdipFree(((GpLineGradient*)brush)->blendfac);
966             GdipFree(((GpLineGradient*)brush)->blendpos);
967             GdipFree(((GpLineGradient*)brush)->pblendcolor);
968             GdipFree(((GpLineGradient*)brush)->pblendpos);
969             break;
970         case BrushTypeTextureFill:
971             GdipDeleteMatrix(((GpTexture*)brush)->transform);
972             GdipDisposeImage(((GpTexture*)brush)->image);
973             break;
974         default:
975             break;
976     }
977
978     DeleteObject(brush->gdibrush);
979     GdipFree(brush);
980
981     return Ok;
982 }
983
984 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
985     BOOL *usinggamma)
986 {
987     TRACE("(%p, %p)\n", line, usinggamma);
988
989     if(!line || !usinggamma)
990         return InvalidParameter;
991
992     *usinggamma = line->gamma;
993
994     return Ok;
995 }
996
997 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
998 {
999     TRACE("(%p, %p)\n", brush, wrapmode);
1000
1001     if(!brush || !wrapmode)
1002         return InvalidParameter;
1003
1004     *wrapmode = brush->wrap;
1005
1006     return Ok;
1007 }
1008
1009 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
1010     REAL *positions, INT count)
1011 {
1012     TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
1013
1014     if(!brush || !blend || !positions || count <= 0)
1015         return InvalidParameter;
1016
1017     if(count < brush->blendcount)
1018         return InsufficientBuffer;
1019
1020     memcpy(blend, brush->blendfac, count*sizeof(REAL));
1021     if(brush->blendcount > 1){
1022         memcpy(positions, brush->blendpos, count*sizeof(REAL));
1023     }
1024
1025     return Ok;
1026 }
1027
1028 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
1029 {
1030     TRACE("(%p, %p)\n", brush, count);
1031
1032     if(!brush || !count)
1033         return InvalidParameter;
1034
1035     *count = brush->blendcount;
1036
1037     return Ok;
1038 }
1039
1040 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
1041     GpPointF *point)
1042 {
1043     TRACE("(%p, %p)\n", grad, point);
1044
1045     if(!grad || !point)
1046         return InvalidParameter;
1047
1048     point->X = grad->center.X;
1049     point->Y = grad->center.Y;
1050
1051     return Ok;
1052 }
1053
1054 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
1055     GpPoint *point)
1056 {
1057     GpStatus ret;
1058     GpPointF ptf;
1059
1060     TRACE("(%p, %p)\n", grad, point);
1061
1062     if(!point)
1063         return InvalidParameter;
1064
1065     ret = GdipGetPathGradientCenterPoint(grad,&ptf);
1066
1067     if(ret == Ok){
1068         point->X = roundr(ptf.X);
1069         point->Y = roundr(ptf.Y);
1070     }
1071
1072     return ret;
1073 }
1074
1075 GpStatus WINGDIPAPI GdipGetPathGradientCenterColor(GpPathGradient *grad,
1076     ARGB *colors)
1077 {
1078     static int calls;
1079
1080     TRACE("(%p,%p)\n", grad, colors);
1081
1082     if(!(calls++))
1083         FIXME("not implemented\n");
1084
1085     return NotImplemented;
1086 }
1087
1088 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
1089     REAL *x, REAL *y)
1090 {
1091     TRACE("(%p, %p, %p)\n", grad, x, y);
1092
1093     if(!grad || !x || !y)
1094         return InvalidParameter;
1095
1096     *x = grad->focus.X;
1097     *y = grad->focus.Y;
1098
1099     return Ok;
1100 }
1101
1102 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1103     BOOL *gamma)
1104 {
1105     TRACE("(%p, %p)\n", grad, gamma);
1106
1107     if(!grad || !gamma)
1108         return InvalidParameter;
1109
1110     *gamma = grad->gamma;
1111
1112     return Ok;
1113 }
1114
1115 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1116     INT *count)
1117 {
1118     TRACE("(%p, %p)\n", grad, count);
1119
1120     if(!grad || !count)
1121         return InvalidParameter;
1122
1123     *count = grad->pathdata.Count;
1124
1125     return Ok;
1126 }
1127
1128 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1129 {
1130     GpRectF r;
1131     GpPath* path;
1132     GpStatus stat;
1133
1134     TRACE("(%p, %p)\n", brush, rect);
1135
1136     if(!brush || !rect)
1137         return InvalidParameter;
1138
1139     stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
1140                            brush->pathdata.Count, FillModeAlternate, &path);
1141     if(stat != Ok)  return stat;
1142
1143     stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
1144     if(stat != Ok){
1145         GdipDeletePath(path);
1146         return stat;
1147     }
1148
1149     memcpy(rect, &r, sizeof(GpRectF));
1150
1151     GdipDeletePath(path);
1152
1153     return Ok;
1154 }
1155
1156 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1157 {
1158     GpRectF rectf;
1159     GpStatus stat;
1160
1161     TRACE("(%p, %p)\n", brush, rect);
1162
1163     if(!brush || !rect)
1164         return InvalidParameter;
1165
1166     stat = GdipGetPathGradientRect(brush, &rectf);
1167     if(stat != Ok)  return stat;
1168
1169     rect->X = roundr(rectf.X);
1170     rect->Y = roundr(rectf.Y);
1171     rect->Width  = roundr(rectf.Width);
1172     rect->Height = roundr(rectf.Height);
1173
1174     return Ok;
1175 }
1176
1177 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1178     *grad, ARGB *argb, INT *count)
1179 {
1180     static int calls;
1181
1182     TRACE("(%p,%p,%p)\n", grad, argb, count);
1183
1184     if(!grad || !argb || !count || (*count < grad->pathdata.Count))
1185         return InvalidParameter;
1186
1187     if(!(calls++))
1188         FIXME("not implemented\n");
1189
1190     return NotImplemented;
1191 }
1192
1193 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorCount(GpPathGradient *brush, INT *count)
1194 {
1195     TRACE("(%p, %p)\n", brush, count);
1196
1197     if (!brush || !count)
1198        return InvalidParameter;
1199
1200     return NotImplemented;
1201 }
1202
1203 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1204     GpWrapMode *wrapmode)
1205 {
1206     TRACE("(%p, %p)\n", brush, wrapmode);
1207
1208     if(!brush || !wrapmode)
1209         return InvalidParameter;
1210
1211     *wrapmode = brush->wrap;
1212
1213     return Ok;
1214 }
1215
1216 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1217 {
1218     TRACE("(%p, %p)\n", sf, argb);
1219
1220     if(!sf || !argb)
1221         return InvalidParameter;
1222
1223     *argb = sf->color;
1224
1225     return Ok;
1226 }
1227
1228 /******************************************************************************
1229  * GdipGetTextureImage [GDIPLUS.@]
1230  */
1231 GpStatus WINGDIPAPI GdipGetTextureImage(GpTexture *brush, GpImage **image)
1232 {
1233     TRACE("(%p, %p)\n", brush, image);
1234
1235     if(!brush || !image)
1236         return InvalidParameter;
1237
1238     return GdipCloneImage(brush->image, image);
1239 }
1240
1241 /******************************************************************************
1242  * GdipGetTextureTransform [GDIPLUS.@]
1243  */
1244 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1245 {
1246     TRACE("(%p, %p)\n", brush, matrix);
1247
1248     if(!brush || !matrix)
1249         return InvalidParameter;
1250
1251     memcpy(matrix, brush->transform, sizeof(GpMatrix));
1252
1253     return Ok;
1254 }
1255
1256 /******************************************************************************
1257  * GdipGetTextureWrapMode [GDIPLUS.@]
1258  */
1259 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1260 {
1261     TRACE("(%p, %p)\n", brush, wrapmode);
1262
1263     if(!brush || !wrapmode)
1264         return InvalidParameter;
1265
1266     *wrapmode = brush->wrap;
1267
1268     return Ok;
1269 }
1270
1271 /******************************************************************************
1272  * GdipMultiplyTextureTransform [GDIPLUS.@]
1273  */
1274 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1275     GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1276 {
1277     TRACE("(%p, %p, %d)\n", brush, matrix, order);
1278
1279     if(!brush || !matrix)
1280         return InvalidParameter;
1281
1282     return GdipMultiplyMatrix(brush->transform, matrix, order);
1283 }
1284
1285 /******************************************************************************
1286  * GdipResetTextureTransform [GDIPLUS.@]
1287  */
1288 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1289 {
1290     TRACE("(%p)\n", brush);
1291
1292     if(!brush)
1293         return InvalidParameter;
1294
1295     return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1296 }
1297
1298 /******************************************************************************
1299  * GdipScaleTextureTransform [GDIPLUS.@]
1300  */
1301 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1302     REAL sx, REAL sy, GpMatrixOrder order)
1303 {
1304     TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1305
1306     if(!brush)
1307         return InvalidParameter;
1308
1309     return GdipScaleMatrix(brush->transform, sx, sy, order);
1310 }
1311
1312 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1313     GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1314 {
1315     REAL *new_blendfac, *new_blendpos;
1316
1317     TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1318
1319     if(!brush || !factors || !positions || count <= 0 ||
1320        (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1321         return InvalidParameter;
1322
1323     new_blendfac = GdipAlloc(count * sizeof(REAL));
1324     new_blendpos = GdipAlloc(count * sizeof(REAL));
1325
1326     if (!new_blendfac || !new_blendpos)
1327     {
1328         GdipFree(new_blendfac);
1329         GdipFree(new_blendpos);
1330         return OutOfMemory;
1331     }
1332
1333     memcpy(new_blendfac, factors, count * sizeof(REAL));
1334     memcpy(new_blendpos, positions, count * sizeof(REAL));
1335
1336     GdipFree(brush->blendfac);
1337     GdipFree(brush->blendpos);
1338
1339     brush->blendcount = count;
1340     brush->blendfac = new_blendfac;
1341     brush->blendpos = new_blendpos;
1342
1343     return Ok;
1344 }
1345
1346 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1347     REAL *positions, INT count)
1348 {
1349     TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1350
1351     if (!brush || !factors || !positions || count <= 0)
1352         return InvalidParameter;
1353
1354     if (count < brush->blendcount)
1355         return InsufficientBuffer;
1356
1357     memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1358     memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1359
1360     return Ok;
1361 }
1362
1363 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1364 {
1365     TRACE("(%p, %p)\n", brush, count);
1366
1367     if (!brush || !count)
1368         return InvalidParameter;
1369
1370     *count = brush->blendcount;
1371
1372     return Ok;
1373 }
1374
1375 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1376     BOOL usegamma)
1377 {
1378     TRACE("(%p, %d)\n", line, usegamma);
1379
1380     if(!line)
1381         return InvalidParameter;
1382
1383     line->gamma = usegamma;
1384
1385     return Ok;
1386 }
1387
1388 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1389     REAL scale)
1390 {
1391     REAL factors[33];
1392     REAL positions[33];
1393     int num_points = 0;
1394     int i;
1395     const int precision = 16;
1396     REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1397     REAL min_erf;
1398     REAL scale_erf;
1399
1400     TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1401
1402     if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1403         return InvalidParameter;
1404
1405     /* we want 2 standard deviations */
1406     erf_range = 2.0 / sqrt(2);
1407
1408     /* calculate the constants we need to normalize the error function to be
1409         between 0.0 and scale over the range we need */
1410     min_erf = erf(-erf_range);
1411     scale_erf = scale / (-2.0 * min_erf);
1412
1413     if (focus != 0.0)
1414     {
1415         positions[0] = 0.0;
1416         factors[0] = 0.0;
1417         for (i=1; i<precision; i++)
1418         {
1419             positions[i] = focus * i / precision;
1420             factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1421         }
1422         num_points += precision;
1423     }
1424
1425     positions[num_points] = focus;
1426     factors[num_points] = scale;
1427     num_points += 1;
1428
1429     if (focus != 1.0)
1430     {
1431         for (i=1; i<precision; i++)
1432         {
1433             positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1434             factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1435         }
1436         num_points += precision;
1437         positions[num_points-1] = 1.0;
1438         factors[num_points-1] = 0.0;
1439     }
1440
1441     return GdipSetLineBlend(line, factors, positions, num_points);
1442 }
1443
1444 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1445     GpWrapMode wrap)
1446 {
1447     TRACE("(%p, %d)\n", line, wrap);
1448
1449     if(!line || wrap == WrapModeClamp)
1450         return InvalidParameter;
1451
1452     line->wrap = wrap;
1453
1454     return Ok;
1455 }
1456
1457 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1458     GDIPCONST REAL *pos, INT count)
1459 {
1460     static int calls;
1461
1462     TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1463
1464     if(!(calls++))
1465         FIXME("not implemented\n");
1466
1467     return NotImplemented;
1468 }
1469
1470 GpStatus WINGDIPAPI GdipSetPathGradientLinearBlend(GpPathGradient *brush,
1471     REAL focus, REAL scale)
1472 {
1473     static int calls;
1474
1475     TRACE("(%p,%0.2f,%0.2f)\n", brush, focus, scale);
1476
1477     if(!(calls++))
1478         FIXME("not implemented\n");
1479
1480     return NotImplemented;
1481 }
1482
1483 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1484     GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1485 {
1486     FIXME("(%p,%p,%p,%i): stub\n", brush, blend, pos, count);
1487     return NotImplemented;
1488 }
1489
1490 GpStatus WINGDIPAPI GdipGetPathGradientPresetBlendCount(GpPathGradient *brush,
1491     INT *count)
1492 {
1493     FIXME("(%p,%p): stub\n", brush, count);
1494     return NotImplemented;
1495 }
1496
1497 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1498     ARGB argb)
1499 {
1500     TRACE("(%p, %x)\n", grad, argb);
1501
1502     if(!grad)
1503         return InvalidParameter;
1504
1505     grad->centercolor = argb;
1506     grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1507
1508     DeleteObject(grad->brush.gdibrush);
1509     grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1510
1511     return Ok;
1512 }
1513
1514 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1515     GpPointF *point)
1516 {
1517     TRACE("(%p, %s)\n", grad, debugstr_pointf(point));
1518
1519     if(!grad || !point)
1520         return InvalidParameter;
1521
1522     grad->center.X = point->X;
1523     grad->center.Y = point->Y;
1524
1525     return Ok;
1526 }
1527
1528 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1529     GpPoint *point)
1530 {
1531     GpPointF ptf;
1532
1533     TRACE("(%p, %p)\n", grad, point);
1534
1535     if(!point)
1536         return InvalidParameter;
1537
1538     ptf.X = (REAL)point->X;
1539     ptf.Y = (REAL)point->Y;
1540
1541     return GdipSetPathGradientCenterPoint(grad,&ptf);
1542 }
1543
1544 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1545     REAL x, REAL y)
1546 {
1547     TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1548
1549     if(!grad)
1550         return InvalidParameter;
1551
1552     grad->focus.X = x;
1553     grad->focus.Y = y;
1554
1555     return Ok;
1556 }
1557
1558 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1559     BOOL gamma)
1560 {
1561     TRACE("(%p, %d)\n", grad, gamma);
1562
1563     if(!grad)
1564         return InvalidParameter;
1565
1566     grad->gamma = gamma;
1567
1568     return Ok;
1569 }
1570
1571 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1572     REAL focus, REAL scale)
1573 {
1574     static int calls;
1575
1576     TRACE("(%p,%0.2f,%0.2f)\n", grad, focus, scale);
1577
1578     if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1579         return InvalidParameter;
1580
1581     if(!(calls++))
1582         FIXME("not implemented\n");
1583
1584     return NotImplemented;
1585 }
1586
1587 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1588     *grad, GDIPCONST ARGB *argb, INT *count)
1589 {
1590     static int calls;
1591
1592     TRACE("(%p,%p,%p)\n", grad, argb, count);
1593
1594     if(!grad || !argb || !count || (*count <= 0) ||
1595         (*count > grad->pathdata.Count))
1596         return InvalidParameter;
1597
1598     if(!(calls++))
1599         FIXME("not implemented\n");
1600
1601     return NotImplemented;
1602 }
1603
1604 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1605     GpWrapMode wrap)
1606 {
1607     TRACE("(%p, %d)\n", grad, wrap);
1608
1609     if(!grad)
1610         return InvalidParameter;
1611
1612     grad->wrap = wrap;
1613
1614     return Ok;
1615 }
1616
1617 GpStatus WINGDIPAPI GdipSetPathGradientTransform(GpPathGradient *grad,
1618     GpMatrix *matrix)
1619 {
1620     static int calls;
1621
1622     TRACE("(%p,%p)\n", grad, matrix);
1623
1624     if(!(calls++))
1625         FIXME("not implemented\n");
1626
1627     return NotImplemented;
1628 }
1629
1630 GpStatus WINGDIPAPI GdipGetPathGradientTransform(GpPathGradient *grad,
1631     GpMatrix *matrix)
1632 {
1633     static int calls;
1634
1635     TRACE("(%p,%p)\n", grad, matrix);
1636
1637     if(!(calls++))
1638         FIXME("not implemented\n");
1639
1640     return NotImplemented;
1641 }
1642
1643 GpStatus WINGDIPAPI GdipMultiplyPathGradientTransform(GpPathGradient *grad,
1644     GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1645 {
1646     static int calls;
1647
1648     TRACE("(%p,%p,%i)\n", grad, matrix, order);
1649
1650     if(!(calls++))
1651         FIXME("not implemented\n");
1652
1653     return NotImplemented;
1654 }
1655
1656 GpStatus WINGDIPAPI GdipRotatePathGradientTransform(GpPathGradient *grad,
1657     REAL angle, GpMatrixOrder order)
1658 {
1659     static int calls;
1660
1661     TRACE("(%p,%0.2f,%i)\n", grad, angle, order);
1662
1663     if(!(calls++))
1664         FIXME("not implemented\n");
1665
1666     return NotImplemented;
1667 }
1668
1669 GpStatus WINGDIPAPI GdipScalePathGradientTransform(GpPathGradient *grad,
1670     REAL sx, REAL sy, GpMatrixOrder order)
1671 {
1672     static int calls;
1673
1674     TRACE("(%p,%0.2f,%0.2f,%i)\n", grad, sx, sy, order);
1675
1676     if(!(calls++))
1677         FIXME("not implemented\n");
1678
1679     return NotImplemented;
1680 }
1681
1682 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1683 {
1684     TRACE("(%p, %x)\n", sf, argb);
1685
1686     if(!sf)
1687         return InvalidParameter;
1688
1689     sf->color = argb;
1690     sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1691
1692     DeleteObject(sf->brush.gdibrush);
1693     sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1694
1695     return Ok;
1696 }
1697
1698 /******************************************************************************
1699  * GdipSetTextureTransform [GDIPLUS.@]
1700  */
1701 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1702     GDIPCONST GpMatrix *matrix)
1703 {
1704     TRACE("(%p, %p)\n", texture, matrix);
1705
1706     if(!texture || !matrix)
1707         return InvalidParameter;
1708
1709     memcpy(texture->transform, matrix, sizeof(GpMatrix));
1710
1711     return Ok;
1712 }
1713
1714 /******************************************************************************
1715  * GdipSetTextureWrapMode [GDIPLUS.@]
1716  *
1717  * WrapMode not used, only stored
1718  */
1719 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1720 {
1721     TRACE("(%p, %d)\n", brush, wrapmode);
1722
1723     if(!brush)
1724         return InvalidParameter;
1725
1726     brush->wrap = wrapmode;
1727
1728     return Ok;
1729 }
1730
1731 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1732     ARGB color2)
1733 {
1734     TRACE("(%p, %x, %x)\n", brush, color1, color2);
1735
1736     if(!brush)
1737         return InvalidParameter;
1738
1739     brush->startcolor = color1;
1740     brush->endcolor   = color2;
1741
1742     return Ok;
1743 }
1744
1745 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1746 {
1747     TRACE("(%p, %p)\n", brush, colors);
1748
1749     if(!brush || !colors)
1750         return InvalidParameter;
1751
1752     colors[0] = brush->startcolor;
1753     colors[1] = brush->endcolor;
1754
1755     return Ok;
1756 }
1757
1758 /******************************************************************************
1759  * GdipRotateTextureTransform [GDIPLUS.@]
1760  */
1761 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1762     GpMatrixOrder order)
1763 {
1764     TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1765
1766     if(!brush)
1767         return InvalidParameter;
1768
1769     return GdipRotateMatrix(brush->transform, angle, order);
1770 }
1771
1772 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1773     REAL scale)
1774 {
1775     REAL factors[3];
1776     REAL positions[3];
1777     int num_points = 0;
1778
1779     TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1780
1781     if (!brush) return InvalidParameter;
1782
1783     if (focus != 0.0)
1784     {
1785         factors[num_points] = 0.0;
1786         positions[num_points] = 0.0;
1787         num_points++;
1788     }
1789
1790     factors[num_points] = scale;
1791     positions[num_points] = focus;
1792     num_points++;
1793
1794     if (focus != 1.0)
1795     {
1796         factors[num_points] = 0.0;
1797         positions[num_points] = 1.0;
1798         num_points++;
1799     }
1800
1801     return GdipSetLineBlend(brush, factors, positions, num_points);
1802 }
1803
1804 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1805     GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1806 {
1807     ARGB *new_color;
1808     REAL *new_pos;
1809     TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1810
1811     if (!brush || !blend || !positions || count < 2 ||
1812         positions[0] != 0.0f || positions[count-1] != 1.0f)
1813     {
1814         return InvalidParameter;
1815     }
1816
1817     new_color = GdipAlloc(count * sizeof(ARGB));
1818     new_pos = GdipAlloc(count * sizeof(REAL));
1819     if (!new_color || !new_pos)
1820     {
1821         GdipFree(new_color);
1822         GdipFree(new_pos);
1823         return OutOfMemory;
1824     }
1825
1826     memcpy(new_color, blend, sizeof(ARGB) * count);
1827     memcpy(new_pos, positions, sizeof(REAL) * count);
1828
1829     GdipFree(brush->pblendcolor);
1830     GdipFree(brush->pblendpos);
1831
1832     brush->pblendcolor = new_color;
1833     brush->pblendpos = new_pos;
1834     brush->pblendcount = count;
1835
1836     return Ok;
1837 }
1838
1839 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1840     ARGB *blend, REAL* positions, INT count)
1841 {
1842     if (!brush || !blend || !positions || count < 2)
1843         return InvalidParameter;
1844
1845     if (brush->pblendcount == 0)
1846         return GenericError;
1847
1848     if (count < brush->pblendcount)
1849         return InsufficientBuffer;
1850
1851     memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1852     memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1853
1854     return Ok;
1855 }
1856
1857 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1858     INT *count)
1859 {
1860     if (!brush || !count)
1861         return InvalidParameter;
1862
1863     *count = brush->pblendcount;
1864
1865     return Ok;
1866 }
1867
1868 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1869 {
1870     static int calls;
1871
1872     TRACE("(%p)\n", brush);
1873
1874     if(!(calls++))
1875         FIXME("not implemented\n");
1876
1877     return NotImplemented;
1878 }
1879
1880 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1881     GDIPCONST GpMatrix *matrix)
1882 {
1883     static int calls;
1884
1885     TRACE("(%p,%p)\n", brush,  matrix);
1886
1887     if(!(calls++))
1888         FIXME("not implemented\n");
1889
1890     return NotImplemented;
1891 }
1892
1893 GpStatus WINGDIPAPI GdipGetLineTransform(GpLineGradient *brush, GpMatrix *matrix)
1894 {
1895     static int calls;
1896
1897     TRACE("(%p,%p)\n", brush, matrix);
1898
1899     if(!(calls++))
1900         FIXME("not implemented\n");
1901
1902     return NotImplemented;
1903 }
1904
1905 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
1906     GpMatrixOrder order)
1907 {
1908     static int calls;
1909
1910     TRACE("(%p,%0.2f,%0.2f,%u)\n", brush, sx, sy, order);
1911
1912     if(!(calls++))
1913         FIXME("not implemented\n");
1914
1915     return NotImplemented;
1916 }
1917
1918 GpStatus WINGDIPAPI GdipMultiplyLineTransform(GpLineGradient *brush,
1919     GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1920 {
1921     static int calls;
1922
1923     TRACE("(%p,%p,%u)\n", brush, matrix, order);
1924
1925     if(!(calls++))
1926         FIXME("not implemented\n");
1927
1928     return NotImplemented;
1929 }
1930
1931 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1932         REAL dx, REAL dy, GpMatrixOrder order)
1933 {
1934     FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1935
1936     return NotImplemented;
1937 }
1938
1939 /******************************************************************************
1940  * GdipTranslateTextureTransform [GDIPLUS.@]
1941  */
1942 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1943     GpMatrixOrder order)
1944 {
1945     TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1946
1947     if(!brush)
1948         return InvalidParameter;
1949
1950     return GdipTranslateMatrix(brush->transform, dx, dy, order);
1951 }
1952
1953 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1954 {
1955     TRACE("(%p, %p)\n", brush, rect);
1956
1957     if(!brush || !rect)
1958         return InvalidParameter;
1959
1960     *rect = brush->rect;
1961
1962     return Ok;
1963 }
1964
1965 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1966 {
1967     GpRectF  rectF;
1968     GpStatus ret;
1969
1970     TRACE("(%p, %p)\n", brush, rect);
1971
1972     if(!rect)
1973         return InvalidParameter;
1974
1975     ret = GdipGetLineRect(brush, &rectF);
1976
1977     if(ret == Ok){
1978         rect->X      = roundr(rectF.X);
1979         rect->Y      = roundr(rectF.Y);
1980         rect->Width  = roundr(rectF.Width);
1981         rect->Height = roundr(rectF.Height);
1982     }
1983
1984     return ret;
1985 }
1986
1987 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1988     REAL angle, GpMatrixOrder order)
1989 {
1990     static int calls;
1991
1992     TRACE("(%p,%0.2f,%u)\n", brush, angle, order);
1993
1994     if(!brush)
1995         return InvalidParameter;
1996
1997     if(!(calls++))
1998         FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1999
2000     return NotImplemented;
2001 }