wintrust: Use helper function for setting confidence in SoftpubCheckCert.
[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             *clone = GdipAlloc(sizeof(GpSolidFill));
50             if (!*clone) return OutOfMemory;
51
52             memcpy(*clone, brush, sizeof(GpSolidFill));
53
54             (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
55             break;
56         case BrushTypePathGradient:{
57             GpPathGradient *src, *dest;
58             INT count;
59
60             *clone = GdipAlloc(sizeof(GpPathGradient));
61             if (!*clone) return OutOfMemory;
62
63             src = (GpPathGradient*) brush,
64             dest = (GpPathGradient*) *clone;
65             count = src->pathdata.Count;
66
67             memcpy(dest, src, sizeof(GpPathGradient));
68
69             dest->pathdata.Count = count;
70             dest->pathdata.Points = GdipAlloc(count * sizeof(PointF));
71             dest->pathdata.Types = GdipAlloc(count);
72
73             if(!dest->pathdata.Points || !dest->pathdata.Types){
74                 GdipFree(dest->pathdata.Points);
75                 GdipFree(dest->pathdata.Types);
76                 GdipFree(dest);
77                 return OutOfMemory;
78             }
79
80             memcpy(dest->pathdata.Points, src->pathdata.Points, count * sizeof(PointF));
81             memcpy(dest->pathdata.Types, src->pathdata.Types, count);
82
83             /* blending */
84             count = src->blendcount;
85             dest->blendcount = count;
86             dest->blendfac = GdipAlloc(count * sizeof(REAL));
87             dest->blendpos = GdipAlloc(count * sizeof(REAL));
88
89             if(!dest->blendfac || !dest->blendpos){
90                 GdipFree(dest->pathdata.Points);
91                 GdipFree(dest->pathdata.Types);
92                 GdipFree(dest->blendfac);
93                 GdipFree(dest->blendpos);
94                 GdipFree(dest);
95                 return OutOfMemory;
96             }
97
98             memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
99             memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
100
101             break;
102         }
103         case BrushTypeLinearGradient:
104             *clone = GdipAlloc(sizeof(GpLineGradient));
105             if(!*clone)    return OutOfMemory;
106
107             memcpy(*clone, brush, sizeof(GpLineGradient));
108
109             (*clone)->gdibrush = CreateSolidBrush((*clone)->lb.lbColor);
110             break;
111         case BrushTypeTextureFill:
112             *clone = GdipAlloc(sizeof(GpTexture));
113             if(!*clone)    return OutOfMemory;
114
115             memcpy(*clone, brush, sizeof(GpTexture));
116
117             (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
118             break;
119         default:
120             ERR("not implemented for brush type %d\n", brush->bt);
121             return NotImplemented;
122     }
123
124     return Ok;
125 }
126
127 /******************************************************************************
128  * GdipCreateLineBrush [GDIPLUS.@]
129  */
130 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
131     GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
132     GpWrapMode wrap, GpLineGradient **line)
133 {
134     COLORREF col = ARGB2COLORREF(startcolor);
135
136     TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
137           startcolor, endcolor, wrap, line);
138
139     if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
140         return InvalidParameter;
141
142     *line = GdipAlloc(sizeof(GpLineGradient));
143     if(!*line)  return OutOfMemory;
144
145     (*line)->brush.lb.lbStyle = BS_SOLID;
146     (*line)->brush.lb.lbColor = col;
147     (*line)->brush.lb.lbHatch = 0;
148     (*line)->brush.gdibrush = CreateSolidBrush(col);
149     (*line)->brush.bt = BrushTypeLinearGradient;
150
151     (*line)->startpoint.X = startpoint->X;
152     (*line)->startpoint.Y = startpoint->Y;
153     (*line)->endpoint.X = endpoint->X;
154     (*line)->endpoint.Y = endpoint->Y;
155     (*line)->startcolor = startcolor;
156     (*line)->endcolor = endcolor;
157     (*line)->wrap = wrap;
158     (*line)->gamma = FALSE;
159
160     return Ok;
161 }
162
163 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
164     GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
165     GpWrapMode wrap, GpLineGradient **line)
166 {
167     GpPointF stF;
168     GpPointF endF;
169
170     TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
171           startcolor, endcolor, wrap, line);
172
173     if(!startpoint || !endpoint)
174         return InvalidParameter;
175
176     stF.X  = (REAL)startpoint->X;
177     stF.Y  = (REAL)startpoint->Y;
178     endF.X = (REAL)endpoint->X;
179     endF.X = (REAL)endpoint->Y;
180
181     return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
182 }
183
184 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
185     ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
186     GpLineGradient **line)
187 {
188     GpPointF start, end;
189
190     TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
191           wrap, line);
192
193     if(!line || !rect)
194         return InvalidParameter;
195
196     start.X = rect->X;
197     start.Y = rect->Y;
198     end.X = rect->X + rect->Width;
199     end.Y = rect->Y + rect->Height;
200
201     return GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
202 }
203
204 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
205     ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
206     GpLineGradient **line)
207 {
208     GpRectF rectF;
209
210     TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
211           wrap, line);
212
213     rectF.X      = (REAL) rect->X;
214     rectF.Y      = (REAL) rect->Y;
215     rectF.Width  = (REAL) rect->Width;
216     rectF.Height = (REAL) rect->Height;
217
218     return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
219 }
220
221 /******************************************************************************
222  * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
223  *
224  * FIXME: angle value completely ignored. Don't know how to use it since native
225  *        always set Brush rectangle to rect (independetly of this angle).
226  *        Maybe it's used only on drawing.
227  */
228 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
229     ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
230     GpLineGradient **line)
231 {
232     TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
233           wrap, line);
234
235     return GdipCreateLineBrushFromRect(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
236                                        wrap, line);
237 }
238
239 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
240     ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
241     GpLineGradient **line)
242 {
243     TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
244           wrap, line);
245
246     return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
247                                         wrap, line);
248 }
249
250 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
251     INT count, GpWrapMode wrap, GpPathGradient **grad)
252 {
253     COLORREF col = ARGB2COLORREF(0xffffffff);
254
255     TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
256
257     if(!points || !grad)
258         return InvalidParameter;
259
260     if(count <= 0)
261         return OutOfMemory;
262
263     *grad = GdipAlloc(sizeof(GpPathGradient));
264     if (!*grad) return OutOfMemory;
265
266     (*grad)->blendfac = GdipAlloc(sizeof(REAL));
267     if(!(*grad)->blendfac){
268         GdipFree(*grad);
269         return OutOfMemory;
270     }
271     (*grad)->blendfac[0] = 1.0;
272     (*grad)->blendpos    = NULL;
273     (*grad)->blendcount  = 1;
274
275     (*grad)->pathdata.Count = count;
276     (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
277     (*grad)->pathdata.Types = GdipAlloc(count);
278
279     if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
280         GdipFree((*grad)->pathdata.Points);
281         GdipFree((*grad)->pathdata.Types);
282         GdipFree(*grad);
283         return OutOfMemory;
284     }
285
286     memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
287     memset((*grad)->pathdata.Types, PathPointTypeLine, count);
288
289     (*grad)->brush.lb.lbStyle = BS_SOLID;
290     (*grad)->brush.lb.lbColor = col;
291     (*grad)->brush.lb.lbHatch = 0;
292
293     (*grad)->brush.gdibrush = CreateSolidBrush(col);
294     (*grad)->brush.bt = BrushTypePathGradient;
295     (*grad)->centercolor = 0xffffffff;
296     (*grad)->wrap = wrap;
297     (*grad)->gamma = FALSE;
298     (*grad)->center.X = 0.0;
299     (*grad)->center.Y = 0.0;
300     (*grad)->focus.X = 0.0;
301     (*grad)->focus.Y = 0.0;
302
303     return Ok;
304 }
305
306 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
307     INT count, GpWrapMode wrap, GpPathGradient **grad)
308 {
309     GpPointF *pointsF;
310     GpStatus ret;
311     INT i;
312
313     TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
314
315     if(!points || !grad)
316         return InvalidParameter;
317
318     if(count <= 0)
319         return OutOfMemory;
320
321     pointsF = GdipAlloc(sizeof(GpPointF) * count);
322     if(!pointsF)
323         return OutOfMemory;
324
325     for(i = 0; i < count; i++){
326         pointsF[i].X = (REAL)points[i].X;
327         pointsF[i].Y = (REAL)points[i].Y;
328     }
329
330     ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
331     GdipFree(pointsF);
332
333     return ret;
334 }
335
336 /******************************************************************************
337  * GdipCreatePathGradientFromPath [GDIPLUS.@]
338  *
339  * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
340  */
341 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
342     GpPathGradient **grad)
343 {
344     COLORREF col = ARGB2COLORREF(0xffffffff);
345
346     TRACE("(%p, %p)\n", path, grad);
347
348     if(!path || !grad)
349         return InvalidParameter;
350
351     *grad = GdipAlloc(sizeof(GpPathGradient));
352     if (!*grad) return OutOfMemory;
353
354     (*grad)->blendfac = GdipAlloc(sizeof(REAL));
355     if(!(*grad)->blendfac){
356         GdipFree(*grad);
357         return OutOfMemory;
358     }
359     (*grad)->blendfac[0] = 1.0;
360     (*grad)->blendpos    = NULL;
361     (*grad)->blendcount  = 1;
362
363     (*grad)->pathdata.Count = path->pathdata.Count;
364     (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
365     (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
366
367     if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
368         GdipFree((*grad)->pathdata.Points);
369         GdipFree((*grad)->pathdata.Types);
370         GdipFree(*grad);
371         return OutOfMemory;
372     }
373
374     memcpy((*grad)->pathdata.Points, path->pathdata.Points,
375            path->pathdata.Count * sizeof(PointF));
376     memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
377
378     (*grad)->brush.lb.lbStyle = BS_SOLID;
379     (*grad)->brush.lb.lbColor = col;
380     (*grad)->brush.lb.lbHatch = 0;
381
382     (*grad)->brush.gdibrush = CreateSolidBrush(col);
383     (*grad)->brush.bt = BrushTypePathGradient;
384     (*grad)->centercolor = 0xffffffff;
385     (*grad)->wrap = WrapModeClamp;
386     (*grad)->gamma = FALSE;
387     /* FIXME: this should be set to the "centroid" of the path by default */
388     (*grad)->center.X = 0.0;
389     (*grad)->center.Y = 0.0;
390     (*grad)->focus.X = 0.0;
391     (*grad)->focus.Y = 0.0;
392
393     return Ok;
394 }
395
396 /******************************************************************************
397  * GdipCreateSolidFill [GDIPLUS.@]
398  */
399 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
400 {
401     COLORREF col = ARGB2COLORREF(color);
402
403     TRACE("(%x, %p)\n", color, sf);
404
405     if(!sf)  return InvalidParameter;
406
407     *sf = GdipAlloc(sizeof(GpSolidFill));
408     if (!*sf) return OutOfMemory;
409
410     (*sf)->brush.lb.lbStyle = BS_SOLID;
411     (*sf)->brush.lb.lbColor = col;
412     (*sf)->brush.lb.lbHatch = 0;
413
414     (*sf)->brush.gdibrush = CreateSolidBrush(col);
415     (*sf)->brush.bt = BrushTypeSolidColor;
416     (*sf)->color = color;
417
418     return Ok;
419 }
420
421 /******************************************************************************
422  * GdipCreateTexture [GDIPLUS.@]
423  *
424  * PARAMS
425  *  image       [I] image to use
426  *  wrapmode    [I] optional
427  *  texture     [O] pointer to the resulting texturebrush
428  *
429  * RETURNS
430  *  SUCCESS: Ok
431  *  FAILURE: element of GpStatus
432  */
433 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
434         GpTexture **texture)
435 {
436     UINT width, height;
437     GpImageAttributes attributes;
438     GpStatus stat;
439
440     TRACE("%p, %d %p\n", image, wrapmode, texture);
441
442     if (!(image && texture))
443         return InvalidParameter;
444
445     stat = GdipGetImageWidth(image, &width);
446     if (stat != Ok) return stat;
447     stat = GdipGetImageHeight(image, &height);
448     if (stat != Ok) return stat;
449     attributes.wrap = wrapmode;
450
451     return GdipCreateTextureIA(image, &attributes, 0, 0, width, height,
452             texture);
453 }
454
455 /******************************************************************************
456  * GdipCreateTexture2 [GDIPLUS.@]
457  */
458 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
459         REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
460 {
461     GpImageAttributes attributes;
462
463     TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
464             x, y, width, height, texture);
465
466     attributes.wrap = wrapmode;
467     return GdipCreateTextureIA(image, &attributes, x, y, width, height,
468             texture);
469 }
470
471 /******************************************************************************
472  * GdipCreateTextureIA [GDIPLUS.@]
473  *
474  * FIXME: imageattr ignored
475  */
476 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
477     GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
478     REAL height, GpTexture **texture)
479 {
480     HDC hdc;
481     OLE_HANDLE hbm;
482     HBITMAP old = NULL;
483     BITMAPINFO bmi;
484     BITMAPINFOHEADER *bmih;
485     INT n_x, n_y, n_width, n_height, abs_height, stride, image_stride, i, bytespp;
486     BOOL bm_is_selected;
487     BYTE *dibits, *buff, *textbits;
488     GpStatus status;
489
490     TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
491            texture);
492
493     if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
494         return InvalidParameter;
495
496     if(image->type != ImageTypeBitmap){
497         FIXME("not implemented for image type %d\n", image->type);
498         return NotImplemented;
499     }
500
501     n_x = roundr(x);
502     n_y = roundr(y);
503     n_width = roundr(width);
504     n_height = roundr(height);
505
506     if(n_x + n_width > ((GpBitmap*)image)->width ||
507        n_y + n_height > ((GpBitmap*)image)->height)
508         return InvalidParameter;
509
510     IPicture_get_Handle(image->picture, &hbm);
511     if(!hbm)   return GenericError;
512     IPicture_get_CurDC(image->picture, &hdc);
513     bm_is_selected = (hdc != 0);
514
515     bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
516     bmi.bmiHeader.biBitCount = 0;
517
518     if(!bm_is_selected){
519         hdc = CreateCompatibleDC(0);
520         old = SelectObject(hdc, (HBITMAP)hbm);
521     }
522
523     /* fill out bmi */
524     GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
525
526     bytespp = bmi.bmiHeader.biBitCount / 8;
527     abs_height = abs(bmi.bmiHeader.biHeight);
528
529     if(n_x > bmi.bmiHeader.biWidth || n_x + n_width > bmi.bmiHeader.biWidth ||
530        n_y > abs_height || n_y + n_height > abs_height)
531         return InvalidParameter;
532
533     dibits = GdipAlloc(bmi.bmiHeader.biSizeImage);
534
535     if(dibits)  /* this is not a good place to error out */
536         GetDIBits(hdc, (HBITMAP)hbm, 0, abs_height, dibits, &bmi, DIB_RGB_COLORS);
537
538     if(!bm_is_selected){
539         SelectObject(hdc, old);
540         DeleteDC(hdc);
541     }
542
543     if(!dibits)
544         return OutOfMemory;
545
546     image_stride = (bmi.bmiHeader.biWidth * bytespp + 3) & ~3;
547     stride = (n_width * bytespp + 3) & ~3;
548     buff = GdipAlloc(sizeof(BITMAPINFOHEADER) + stride * n_height);
549     if(!buff){
550         GdipFree(dibits);
551         return OutOfMemory;
552     }
553
554     bmih = (BITMAPINFOHEADER*)buff;
555     textbits = (BYTE*) (bmih + 1);
556     bmih->biSize = sizeof(BITMAPINFOHEADER);
557     bmih->biWidth = n_width;
558     bmih->biHeight = n_height;
559     bmih->biCompression = BI_RGB;
560     bmih->biSizeImage = stride * n_height;
561     bmih->biBitCount = bmi.bmiHeader.biBitCount;
562     bmih->biClrUsed = 0;
563     bmih->biPlanes = 1;
564
565     /* image is flipped */
566     if(bmi.bmiHeader.biHeight > 0){
567         dibits += bmi.bmiHeader.biSizeImage;
568         image_stride *= -1;
569         textbits += stride * (n_height - 1);
570         stride *= -1;
571     }
572
573     for(i = 0; i < n_height; i++)
574         memcpy(&textbits[i * stride],
575                &dibits[n_x * bytespp + (n_y + i) * image_stride],
576                abs(stride));
577
578     *texture = GdipAlloc(sizeof(GpTexture));
579     if (!*texture) return OutOfMemory;
580
581     if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
582         GdipFree(*texture);
583         GdipFree(dibits);
584         GdipFree(buff);
585         return status;
586     }
587
588     (*texture)->brush.lb.lbStyle = BS_DIBPATTERNPT;
589     (*texture)->brush.lb.lbColor = DIB_RGB_COLORS;
590     (*texture)->brush.lb.lbHatch = (ULONG_PTR)buff;
591
592     (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
593     (*texture)->brush.bt = BrushTypeTextureFill;
594
595     GdipFree(dibits);
596     GdipFree(buff);
597
598     return Ok;
599 }
600
601 /******************************************************************************
602  * GdipCreateTextureIAI [GDIPLUS.@]
603  */
604 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
605     INT x, INT y, INT width, INT height, GpTexture **texture)
606 {
607     TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
608            texture);
609
610     return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
611 }
612
613 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
614         INT x, INT y, INT width, INT height, GpTexture **texture)
615 {
616     GpImageAttributes imageattr;
617
618     TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
619             texture);
620
621     imageattr.wrap = wrapmode;
622
623     return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
624 }
625
626 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
627 {
628     TRACE("(%p, %p)\n", brush, type);
629
630     if(!brush || !type)  return InvalidParameter;
631
632     *type = brush->bt;
633
634     return Ok;
635 }
636
637 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
638 {
639     TRACE("(%p)\n", brush);
640
641     if(!brush)  return InvalidParameter;
642
643     switch(brush->bt)
644     {
645         case BrushTypePathGradient:
646             GdipFree(((GpPathGradient*) brush)->pathdata.Points);
647             GdipFree(((GpPathGradient*) brush)->pathdata.Types);
648             GdipFree(((GpPathGradient*) brush)->blendfac);
649             GdipFree(((GpPathGradient*) brush)->blendpos);
650             break;
651         case BrushTypeSolidColor:
652         case BrushTypeLinearGradient:
653             break;
654         case BrushTypeTextureFill:
655             GdipDeleteMatrix(((GpTexture*)brush)->transform);
656             break;
657         default:
658             break;
659     }
660
661     DeleteObject(brush->gdibrush);
662     GdipFree(brush);
663
664     return Ok;
665 }
666
667 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
668     BOOL *usinggamma)
669 {
670     TRACE("(%p, %p)\n", line, usinggamma);
671
672     if(!line || !usinggamma)
673         return InvalidParameter;
674
675     *usinggamma = line->gamma;
676
677     return Ok;
678 }
679
680 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
681 {
682     TRACE("(%p, %p)\n", brush, wrapmode);
683
684     if(!brush || !wrapmode)
685         return InvalidParameter;
686
687     *wrapmode = brush->wrap;
688
689     return Ok;
690 }
691
692 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
693     REAL *positions, INT count)
694 {
695     TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
696
697     if(!brush || !blend || !positions || count <= 0)
698         return InvalidParameter;
699
700     if(count < brush->blendcount)
701         return InsufficientBuffer;
702
703     memcpy(blend, brush->blendfac, count*sizeof(REAL));
704     if(brush->blendcount > 1){
705         memcpy(positions, brush->blendpos, count*sizeof(REAL));
706     }
707
708     return Ok;
709 }
710
711 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
712 {
713     TRACE("(%p, %p)\n", brush, count);
714
715     if(!brush || !count)
716         return InvalidParameter;
717
718     *count = brush->blendcount;
719
720     return Ok;
721 }
722
723 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
724     GpPointF *point)
725 {
726     TRACE("(%p, %p)\n", grad, point);
727
728     if(!grad || !point)
729         return InvalidParameter;
730
731     point->X = grad->center.X;
732     point->Y = grad->center.Y;
733
734     return Ok;
735 }
736
737 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
738     GpPoint *point)
739 {
740     GpStatus ret;
741     GpPointF ptf;
742
743     TRACE("(%p, %p)\n", grad, point);
744
745     if(!point)
746         return InvalidParameter;
747
748     ret = GdipGetPathGradientCenterPoint(grad,&ptf);
749
750     if(ret == Ok){
751         point->X = roundr(ptf.X);
752         point->Y = roundr(ptf.Y);
753     }
754
755     return ret;
756 }
757
758 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
759     REAL *x, REAL *y)
760 {
761     TRACE("(%p, %p, %p)\n", grad, x, y);
762
763     if(!grad || !x || !y)
764         return InvalidParameter;
765
766     *x = grad->focus.X;
767     *y = grad->focus.Y;
768
769     return Ok;
770 }
771
772 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
773     BOOL *gamma)
774 {
775     TRACE("(%p, %p)\n", grad, gamma);
776
777     if(!grad || !gamma)
778         return InvalidParameter;
779
780     *gamma = grad->gamma;
781
782     return Ok;
783 }
784
785 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
786     INT *count)
787 {
788     TRACE("(%p, %p)\n", grad, count);
789
790     if(!grad || !count)
791         return InvalidParameter;
792
793     *count = grad->pathdata.Count;
794
795     return Ok;
796 }
797
798 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
799 {
800     GpRectF r;
801     GpPath* path;
802     GpStatus stat;
803
804     TRACE("(%p, %p)\n", brush, rect);
805
806     if(!brush || !rect)
807         return InvalidParameter;
808
809     stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
810                            brush->pathdata.Count, FillModeAlternate, &path);
811     if(stat != Ok)  return stat;
812
813     stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
814     if(stat != Ok){
815         GdipDeletePath(path);
816         return stat;
817     }
818
819     memcpy(rect, &r, sizeof(GpRectF));
820
821     GdipDeletePath(path);
822
823     return Ok;
824 }
825
826 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
827 {
828     GpRectF rectf;
829     GpStatus stat;
830
831     TRACE("(%p, %p)\n", brush, rect);
832
833     if(!brush || !rect)
834         return InvalidParameter;
835
836     stat = GdipGetPathGradientRect(brush, &rectf);
837     if(stat != Ok)  return stat;
838
839     rect->X = roundr(rectf.X);
840     rect->Y = roundr(rectf.Y);
841     rect->Width  = roundr(rectf.Width);
842     rect->Height = roundr(rectf.Height);
843
844     return Ok;
845 }
846
847 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
848     *grad, ARGB *argb, INT *count)
849 {
850     static int calls;
851
852     if(!grad || !argb || !count || (*count < grad->pathdata.Count))
853         return InvalidParameter;
854
855     if(!(calls++))
856         FIXME("not implemented\n");
857
858     return NotImplemented;
859 }
860
861 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
862     GpWrapMode *wrapmode)
863 {
864     TRACE("(%p, %p)\n", brush, wrapmode);
865
866     if(!brush || !wrapmode)
867         return InvalidParameter;
868
869     *wrapmode = brush->wrap;
870
871     return Ok;
872 }
873
874 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
875 {
876     TRACE("(%p, %p)\n", sf, argb);
877
878     if(!sf || !argb)
879         return InvalidParameter;
880
881     *argb = sf->color;
882
883     return Ok;
884 }
885
886 /******************************************************************************
887  * GdipGetTextureTransform [GDIPLUS.@]
888  */
889 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
890 {
891     TRACE("(%p, %p)\n", brush, matrix);
892
893     if(!brush || !matrix)
894         return InvalidParameter;
895
896     memcpy(matrix, brush->transform, sizeof(GpMatrix));
897
898     return Ok;
899 }
900
901 /******************************************************************************
902  * GdipResetTextureTransform [GDIPLUS.@]
903  */
904 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
905 {
906     TRACE("(%p)\n", brush);
907
908     if(!brush)
909         return InvalidParameter;
910
911     return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
912 }
913
914 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
915     GDIPCONST REAL *blend, GDIPCONST REAL* positions, INT count)
916 {
917     static int calls;
918
919     if(!brush || !blend || !positions || count <= 0)
920         return InvalidParameter;
921
922     if(!(calls++))
923         FIXME("not implemented\n");
924
925     return Ok;
926 }
927
928 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
929     BOOL usegamma)
930 {
931     TRACE("(%p, %d)\n", line, usegamma);
932
933     if(!line)
934         return InvalidParameter;
935
936     line->gamma = usegamma;
937
938     return Ok;
939 }
940
941 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
942     REAL scale)
943 {
944     static int calls;
945
946     if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
947         return InvalidParameter;
948
949     if(!(calls++))
950         FIXME("not implemented\n");
951
952     return NotImplemented;
953 }
954
955 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
956     GpWrapMode wrap)
957 {
958     TRACE("(%p, %d)\n", line, wrap);
959
960     if(!line || wrap == WrapModeClamp)
961         return InvalidParameter;
962
963     line->wrap = wrap;
964
965     return Ok;
966 }
967
968 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
969     GDIPCONST REAL *pos, INT count)
970 {
971     static int calls;
972
973     if(!(calls++))
974         FIXME("not implemented\n");
975
976     return NotImplemented;
977 }
978
979 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
980     ARGB argb)
981 {
982     TRACE("(%p, %x)\n", grad, argb);
983
984     if(!grad)
985         return InvalidParameter;
986
987     grad->centercolor = argb;
988     grad->brush.lb.lbColor = ARGB2COLORREF(argb);
989
990     DeleteObject(grad->brush.gdibrush);
991     grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
992
993     return Ok;
994 }
995
996 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
997     GpPointF *point)
998 {
999     TRACE("(%p, %p)\n", grad, point);
1000
1001     if(!grad || !point)
1002         return InvalidParameter;
1003
1004     grad->center.X = point->X;
1005     grad->center.Y = point->Y;
1006
1007     return Ok;
1008 }
1009
1010 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1011     GpPoint *point)
1012 {
1013     GpPointF ptf;
1014
1015     TRACE("(%p, %p)\n", grad, point);
1016
1017     if(!point)
1018         return InvalidParameter;
1019
1020     ptf.X = (REAL)point->X;
1021     ptf.Y = (REAL)point->Y;
1022
1023     return GdipSetPathGradientCenterPoint(grad,&ptf);
1024 }
1025
1026 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1027     REAL x, REAL y)
1028 {
1029     TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1030
1031     if(!grad)
1032         return InvalidParameter;
1033
1034     grad->focus.X = x;
1035     grad->focus.Y = y;
1036
1037     return Ok;
1038 }
1039
1040 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1041     BOOL gamma)
1042 {
1043     TRACE("(%p, %d)\n", grad, gamma);
1044
1045     if(!grad)
1046         return InvalidParameter;
1047
1048     grad->gamma = gamma;
1049
1050     return Ok;
1051 }
1052
1053 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1054     REAL focus, REAL scale)
1055 {
1056     static int calls;
1057
1058     if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1059         return InvalidParameter;
1060
1061     if(!(calls++))
1062         FIXME("not implemented\n");
1063
1064     return NotImplemented;
1065 }
1066
1067 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1068     *grad, ARGB *argb, INT *count)
1069 {
1070     static int calls;
1071
1072     if(!grad || !argb || !count || (*count <= 0) ||
1073         (*count > grad->pathdata.Count))
1074         return InvalidParameter;
1075
1076     if(!(calls++))
1077         FIXME("not implemented\n");
1078
1079     return NotImplemented;
1080 }
1081
1082 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1083     GpWrapMode wrap)
1084 {
1085     TRACE("(%p, %d)\n", grad, wrap);
1086
1087     if(!grad)
1088         return InvalidParameter;
1089
1090     grad->wrap = wrap;
1091
1092     return Ok;
1093 }
1094
1095 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1096 {
1097     TRACE("(%p, %x)\n", sf, argb);
1098
1099     if(!sf)
1100         return InvalidParameter;
1101
1102     sf->color = argb;
1103     sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1104
1105     DeleteObject(sf->brush.gdibrush);
1106     sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1107
1108     return Ok;
1109 }
1110
1111 /******************************************************************************
1112  * GdipSetTextureTransform [GDIPLUS.@]
1113  */
1114 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1115     GDIPCONST GpMatrix *matrix)
1116 {
1117     TRACE("(%p, %p)\n", texture, matrix);
1118
1119     if(!texture || !matrix)
1120         return InvalidParameter;
1121
1122     memcpy(texture->transform, matrix, sizeof(GpMatrix));
1123
1124     return Ok;
1125 }
1126
1127 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1128     ARGB color2)
1129 {
1130     TRACE("(%p, %x, %x)\n", brush, color1, color2);
1131
1132     if(!brush)
1133         return InvalidParameter;
1134
1135     brush->startcolor = color1;
1136     brush->endcolor   = color2;
1137
1138     return Ok;
1139 }
1140
1141 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1142 {
1143     TRACE("(%p, %p)\n", brush, colors);
1144
1145     if(!brush || !colors)
1146         return InvalidParameter;
1147
1148     colors[0] = brush->startcolor;
1149     colors[1] = brush->endcolor;
1150
1151     return Ok;
1152 }
1153
1154 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1155     REAL scale)
1156 {
1157     static int calls;
1158
1159     if(!(calls++))
1160         FIXME("not implemented\n");
1161
1162     return NotImplemented;
1163 }
1164
1165 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1166     GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1167 {
1168     static int calls;
1169
1170     if(!(calls++))
1171         FIXME("not implemented\n");
1172
1173     return NotImplemented;
1174 }
1175
1176 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1177     GDIPCONST GpMatrix *matrix)
1178 {
1179     static int calls;
1180
1181     if(!(calls++))
1182         FIXME("not implemented\n");
1183
1184     return NotImplemented;
1185 }
1186
1187 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1188         REAL dx, REAL dy, GpMatrixOrder order)
1189 {
1190     FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1191
1192     return NotImplemented;
1193 }
1194
1195 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1196 {
1197     TRACE("(%p, %p)\n", brush, rect);
1198
1199     if(!brush || !rect)
1200         return InvalidParameter;
1201
1202     rect->X = (brush->startpoint.X < brush->endpoint.X ? brush->startpoint.X: brush->endpoint.X);
1203     rect->Y = (brush->startpoint.Y < brush->endpoint.Y ? brush->startpoint.Y: brush->endpoint.Y);
1204
1205     rect->Width  = fabs(brush->startpoint.X - brush->endpoint.X);
1206     rect->Height = fabs(brush->startpoint.Y - brush->endpoint.Y);
1207
1208     return Ok;
1209 }
1210
1211 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1212 {
1213     GpRectF  rectF;
1214     GpStatus ret;
1215
1216     TRACE("(%p, %p)\n", brush, rect);
1217
1218     if(!rect)
1219         return InvalidParameter;
1220
1221     ret = GdipGetLineRect(brush, &rectF);
1222
1223     if(ret == Ok){
1224         rect->X      = roundr(rectF.X);
1225         rect->Y      = roundr(rectF.Y);
1226         rect->Width  = roundr(rectF.Width);
1227         rect->Height = roundr(rectF.Height);
1228     }
1229
1230     return ret;
1231 }