Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / gdiplus / brush.c
blob0f6d70770195ec098ecccb8a73719445e33bb521
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winuser.h"
24 #include "wingdi.h"
26 #define COBJMACROS
27 #include "objbase.h"
28 #include "olectl.h"
29 #include "ole2.h"
31 #include "gdiplus.h"
32 #include "gdiplus_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
37 /******************************************************************************
38 * GdipCloneBrush [GDIPLUS.@]
40 GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone)
42 TRACE("(%p, %p)\n", brush, clone);
44 if(!brush || !clone)
45 return InvalidParameter;
47 switch(brush->bt){
48 case BrushTypeSolidColor:
50 GpSolidFill *fill;
51 *clone = GdipAlloc(sizeof(GpSolidFill));
52 if (!*clone) return OutOfMemory;
54 fill = (GpSolidFill*)*clone;
56 memcpy(*clone, brush, sizeof(GpSolidFill));
58 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
59 fill->bmp = ARGB2BMP(fill->color);
60 break;
62 case BrushTypeHatchFill:
63 *clone = GdipAlloc(sizeof(GpHatch));
64 if (!*clone) return OutOfMemory;
66 memcpy(*clone, brush, sizeof(GpHatch));
68 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
69 break;
70 case BrushTypePathGradient:{
71 GpPathGradient *src, *dest;
72 INT count;
74 *clone = GdipAlloc(sizeof(GpPathGradient));
75 if (!*clone) return OutOfMemory;
77 src = (GpPathGradient*) brush,
78 dest = (GpPathGradient*) *clone;
79 count = src->pathdata.Count;
81 memcpy(dest, src, sizeof(GpPathGradient));
83 dest->pathdata.Count = count;
84 dest->pathdata.Points = GdipAlloc(count * sizeof(PointF));
85 dest->pathdata.Types = GdipAlloc(count);
87 if(!dest->pathdata.Points || !dest->pathdata.Types){
88 GdipFree(dest->pathdata.Points);
89 GdipFree(dest->pathdata.Types);
90 GdipFree(dest);
91 return OutOfMemory;
94 memcpy(dest->pathdata.Points, src->pathdata.Points, count * sizeof(PointF));
95 memcpy(dest->pathdata.Types, src->pathdata.Types, count);
97 /* blending */
98 count = src->blendcount;
99 dest->blendcount = count;
100 dest->blendfac = GdipAlloc(count * sizeof(REAL));
101 dest->blendpos = GdipAlloc(count * sizeof(REAL));
103 if(!dest->blendfac || !dest->blendpos){
104 GdipFree(dest->pathdata.Points);
105 GdipFree(dest->pathdata.Types);
106 GdipFree(dest->blendfac);
107 GdipFree(dest->blendpos);
108 GdipFree(dest);
109 return OutOfMemory;
112 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
113 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
115 break;
117 case BrushTypeLinearGradient:{
118 GpLineGradient *dest, *src;
119 INT count, pcount;
121 dest = GdipAlloc(sizeof(GpLineGradient));
122 if(!dest) return OutOfMemory;
124 src = (GpLineGradient*)brush;
126 memcpy(dest, src, sizeof(GpLineGradient));
128 dest->brush.gdibrush = CreateSolidBrush(dest->brush.lb.lbColor);
130 count = dest->blendcount;
131 dest->blendfac = GdipAlloc(count * sizeof(REAL));
132 dest->blendpos = GdipAlloc(count * sizeof(REAL));
133 pcount = dest->pblendcount;
134 if (pcount)
136 dest->pblendcolor = GdipAlloc(pcount * sizeof(ARGB));
137 dest->pblendpos = GdipAlloc(pcount * sizeof(REAL));
140 if (!dest->blendfac || !dest->blendpos ||
141 (pcount && (!dest->pblendcolor || !dest->pblendpos)))
143 GdipFree(dest->blendfac);
144 GdipFree(dest->blendpos);
145 GdipFree(dest->pblendcolor);
146 GdipFree(dest->pblendpos);
147 DeleteObject(dest->brush.gdibrush);
148 GdipFree(dest);
149 return OutOfMemory;
152 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
153 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
155 if (pcount)
157 memcpy(dest->pblendcolor, src->pblendcolor, pcount * sizeof(ARGB));
158 memcpy(dest->pblendpos, src->pblendpos, pcount * sizeof(REAL));
161 *clone = &dest->brush;
162 break;
164 case BrushTypeTextureFill:
165 *clone = GdipAlloc(sizeof(GpTexture));
166 if(!*clone) return OutOfMemory;
168 memcpy(*clone, brush, sizeof(GpTexture));
170 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
171 break;
172 default:
173 ERR("not implemented for brush type %d\n", brush->bt);
174 return NotImplemented;
177 TRACE("<-- %p\n", *clone);
178 return Ok;
181 static const char HatchBrushes[][8] = {
182 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HatchStyleHorizontal */
183 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleVertical */
184 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HatchStyleForwardDiagonal */
185 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HatchStyleBackwardDiagonal */
186 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleCross */
187 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }, /* HatchStyleDiagonalCross */
188 { 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x80 }, /* HatchStyle05Percent */
189 { 0x00, 0x02, 0x00, 0x88, 0x00, 0x20, 0x00, 0x88 }, /* HatchStyle10Percent */
190 { 0x00, 0x22, 0x00, 0xcc, 0x00, 0x22, 0x00, 0xcc }, /* HatchStyle20Percent */
191 { 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc }, /* HatchStyle25Percent */
192 { 0x00, 0xcc, 0x04, 0xcc, 0x00, 0xcc, 0x40, 0xcc }, /* HatchStyle30Percent */
193 { 0x44, 0xcc, 0x22, 0xcc, 0x44, 0xcc, 0x22, 0xcc }, /* HatchStyle40Percent */
194 { 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc }, /* HatchStyle50Percent */
195 { 0x55, 0xcd, 0x55, 0xee, 0x55, 0xdc, 0x55, 0xee }, /* HatchStyle60Percent */
196 { 0x55, 0xdd, 0x55, 0xff, 0x55, 0xdd, 0x55, 0xff }, /* HatchStyle70Percent */
197 { 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff }, /* HatchStyle75Percent */
198 { 0x55, 0xff, 0x59, 0xff, 0x55, 0xff, 0x99, 0xff }, /* HatchStyle80Percent */
199 { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xfd, 0xff }, /* HatchStyle90Percent */
200 { 0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88 }, /* HatchStyleLightDownwardDiagonal */
201 { 0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11 }, /* HatchStyleLightUpwardDiagonal */
202 { 0x99, 0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc }, /* HatchStyleDarkDownwardDiagonal */
203 { 0xcc, 0x66, 0x33, 0x99, 0xcc, 0x66, 0x33, 0x99 }, /* HatchStyleDarkUpwardDiagonal */
204 { 0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0 }, /* HatchStyleWideDownwardDiagonal */
205 { 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x83, 0xc1 }, /* HatchStyleWideUpwardDiagonal */
206 { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 }, /* HatchStyleLightVertical */
207 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff }, /* HatchStyleLightHorizontal */
208 { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }, /* HatchStyleNarrowVertical */
209 { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, /* HatchStyleNarrowHorizontal */
210 { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }, /* HatchStyleDarkVertical */
211 { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff }, /* HatchStyleDarkHorizontal */
214 /******************************************************************************
215 * GdipCreateHatchBrush [GDIPLUS.@]
217 GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle hatchstyle, ARGB forecol, ARGB backcol, GpHatch **brush)
219 COLORREF fgcol = ARGB2COLORREF(forecol);
220 GpStatus stat = Ok;
222 TRACE("(%d, %d, %d, %p)\n", hatchstyle, forecol, backcol, brush);
224 if(!brush) return InvalidParameter;
226 *brush = GdipAlloc(sizeof(GpHatch));
227 if (!*brush) return OutOfMemory;
229 if (hatchstyle < sizeof(HatchBrushes) / sizeof(HatchBrushes[0]))
231 HBITMAP hbmp;
232 HDC hdc;
233 BITMAPINFOHEADER bmih;
234 DWORD* bits;
235 int x, y;
237 hdc = CreateCompatibleDC(0);
239 if (hdc)
241 bmih.biSize = sizeof(bmih);
242 bmih.biWidth = 8;
243 bmih.biHeight = 8;
244 bmih.biPlanes = 1;
245 bmih.biBitCount = 32;
246 bmih.biCompression = BI_RGB;
247 bmih.biSizeImage = 0;
249 hbmp = CreateDIBSection(hdc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
251 if (hbmp)
253 for (y=0; y<8; y++)
254 for (x=0; x<8; x++)
255 if ((HatchBrushes[hatchstyle][y] & (0x80 >> x)) != 0)
256 bits[y*8+x] = forecol;
257 else
258 bits[y*8+x] = backcol;
260 else
261 stat = GenericError;
263 DeleteDC(hdc);
265 else
266 stat = GenericError;
268 if (stat == Ok)
270 (*brush)->brush.lb.lbStyle = BS_PATTERN;
271 (*brush)->brush.lb.lbColor = 0;
272 (*brush)->brush.lb.lbHatch = (ULONG_PTR)hbmp;
273 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
275 DeleteObject(hbmp);
278 else
280 FIXME("Unimplemented hatch style %d\n", hatchstyle);
282 (*brush)->brush.lb.lbStyle = BS_SOLID;
283 (*brush)->brush.lb.lbColor = fgcol;
284 (*brush)->brush.lb.lbHatch = 0;
285 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
288 if (stat == Ok)
290 (*brush)->brush.bt = BrushTypeHatchFill;
291 (*brush)->forecol = forecol;
292 (*brush)->backcol = backcol;
293 (*brush)->hatchstyle = hatchstyle;
294 TRACE("<-- %p\n", *brush);
296 else
298 GdipFree(*brush);
299 *brush = NULL;
302 return stat;
305 /******************************************************************************
306 * GdipCreateLineBrush [GDIPLUS.@]
308 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
309 GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
310 GpWrapMode wrap, GpLineGradient **line)
312 COLORREF col = ARGB2COLORREF(startcolor);
314 TRACE("(%s, %s, %x, %x, %d, %p)\n", debugstr_pointf(startpoint),
315 debugstr_pointf(endpoint), startcolor, endcolor, wrap, line);
317 if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
318 return InvalidParameter;
320 *line = GdipAlloc(sizeof(GpLineGradient));
321 if(!*line) return OutOfMemory;
323 (*line)->brush.lb.lbStyle = BS_SOLID;
324 (*line)->brush.lb.lbColor = col;
325 (*line)->brush.lb.lbHatch = 0;
326 (*line)->brush.gdibrush = CreateSolidBrush(col);
327 (*line)->brush.bt = BrushTypeLinearGradient;
329 (*line)->startpoint.X = startpoint->X;
330 (*line)->startpoint.Y = startpoint->Y;
331 (*line)->endpoint.X = endpoint->X;
332 (*line)->endpoint.Y = endpoint->Y;
333 (*line)->startcolor = startcolor;
334 (*line)->endcolor = endcolor;
335 (*line)->wrap = wrap;
336 (*line)->gamma = FALSE;
338 (*line)->rect.X = (startpoint->X < endpoint->X ? startpoint->X: endpoint->X);
339 (*line)->rect.Y = (startpoint->Y < endpoint->Y ? startpoint->Y: endpoint->Y);
340 (*line)->rect.Width = fabs(startpoint->X - endpoint->X);
341 (*line)->rect.Height = fabs(startpoint->Y - endpoint->Y);
343 if ((*line)->rect.Width == 0)
345 (*line)->rect.X -= (*line)->rect.Height / 2.0f;
346 (*line)->rect.Width = (*line)->rect.Height;
348 else if ((*line)->rect.Height == 0)
350 (*line)->rect.Y -= (*line)->rect.Width / 2.0f;
351 (*line)->rect.Height = (*line)->rect.Width;
354 (*line)->blendcount = 1;
355 (*line)->blendfac = GdipAlloc(sizeof(REAL));
356 (*line)->blendpos = GdipAlloc(sizeof(REAL));
358 if (!(*line)->blendfac || !(*line)->blendpos)
360 GdipFree((*line)->blendfac);
361 GdipFree((*line)->blendpos);
362 DeleteObject((*line)->brush.gdibrush);
363 GdipFree(*line);
364 *line = NULL;
365 return OutOfMemory;
368 (*line)->blendfac[0] = 1.0f;
369 (*line)->blendpos[0] = 1.0f;
371 (*line)->pblendcolor = NULL;
372 (*line)->pblendpos = NULL;
373 (*line)->pblendcount = 0;
375 TRACE("<-- %p\n", *line);
377 return Ok;
380 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
381 GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
382 GpWrapMode wrap, GpLineGradient **line)
384 GpPointF stF;
385 GpPointF endF;
387 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
388 startcolor, endcolor, wrap, line);
390 if(!startpoint || !endpoint)
391 return InvalidParameter;
393 stF.X = (REAL)startpoint->X;
394 stF.Y = (REAL)startpoint->Y;
395 endF.X = (REAL)endpoint->X;
396 endF.X = (REAL)endpoint->Y;
398 return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
401 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
402 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
403 GpLineGradient **line)
405 GpPointF start, end;
406 GpStatus stat;
408 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
409 wrap, line);
411 if(!line || !rect)
412 return InvalidParameter;
414 switch (mode)
416 case LinearGradientModeHorizontal:
417 start.X = rect->X;
418 start.Y = rect->Y;
419 end.X = rect->X + rect->Width;
420 end.Y = rect->Y;
421 break;
422 case LinearGradientModeVertical:
423 start.X = rect->X;
424 start.Y = rect->Y;
425 end.X = rect->X;
426 end.Y = rect->Y + rect->Height;
427 break;
428 case LinearGradientModeForwardDiagonal:
429 start.X = rect->X;
430 start.Y = rect->Y;
431 end.X = rect->X + rect->Width;
432 end.Y = rect->Y + rect->Height;
433 break;
434 case LinearGradientModeBackwardDiagonal:
435 start.X = rect->X + rect->Width;
436 start.Y = rect->Y;
437 end.X = rect->X;
438 end.Y = rect->Y + rect->Height;
439 break;
440 default:
441 return InvalidParameter;
444 stat = GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
446 if (stat == Ok)
447 (*line)->rect = *rect;
449 return stat;
452 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
453 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
454 GpLineGradient **line)
456 GpRectF rectF;
458 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
459 wrap, line);
461 rectF.X = (REAL) rect->X;
462 rectF.Y = (REAL) rect->Y;
463 rectF.Width = (REAL) rect->Width;
464 rectF.Height = (REAL) rect->Height;
466 return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
469 /******************************************************************************
470 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
472 * FIXME: angle value completely ignored. Don't know how to use it since native
473 * always set Brush rectangle to rect (independetly of this angle).
474 * Maybe it's used only on drawing.
476 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
477 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
478 GpLineGradient **line)
480 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
481 wrap, line);
483 return GdipCreateLineBrushFromRect(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
484 wrap, line);
487 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
488 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
489 GpLineGradient **line)
491 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
492 wrap, line);
494 return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
495 wrap, line);
498 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
499 INT count, GpWrapMode wrap, GpPathGradient **grad)
501 COLORREF col = ARGB2COLORREF(0xffffffff);
503 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
505 if(!points || !grad)
506 return InvalidParameter;
508 if(count <= 0)
509 return OutOfMemory;
511 *grad = GdipAlloc(sizeof(GpPathGradient));
512 if (!*grad) return OutOfMemory;
514 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
515 if(!(*grad)->blendfac){
516 GdipFree(*grad);
517 return OutOfMemory;
519 (*grad)->blendfac[0] = 1.0;
520 (*grad)->blendpos = NULL;
521 (*grad)->blendcount = 1;
523 (*grad)->pathdata.Count = count;
524 (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
525 (*grad)->pathdata.Types = GdipAlloc(count);
527 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
528 GdipFree((*grad)->pathdata.Points);
529 GdipFree((*grad)->pathdata.Types);
530 GdipFree(*grad);
531 return OutOfMemory;
534 memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
535 memset((*grad)->pathdata.Types, PathPointTypeLine, count);
537 (*grad)->brush.lb.lbStyle = BS_SOLID;
538 (*grad)->brush.lb.lbColor = col;
539 (*grad)->brush.lb.lbHatch = 0;
541 (*grad)->brush.gdibrush = CreateSolidBrush(col);
542 (*grad)->brush.bt = BrushTypePathGradient;
543 (*grad)->centercolor = 0xffffffff;
544 (*grad)->wrap = wrap;
545 (*grad)->gamma = FALSE;
546 (*grad)->center.X = 0.0;
547 (*grad)->center.Y = 0.0;
548 (*grad)->focus.X = 0.0;
549 (*grad)->focus.Y = 0.0;
551 TRACE("<-- %p\n", *grad);
553 return Ok;
556 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
557 INT count, GpWrapMode wrap, GpPathGradient **grad)
559 GpPointF *pointsF;
560 GpStatus ret;
561 INT i;
563 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
565 if(!points || !grad)
566 return InvalidParameter;
568 if(count <= 0)
569 return OutOfMemory;
571 pointsF = GdipAlloc(sizeof(GpPointF) * count);
572 if(!pointsF)
573 return OutOfMemory;
575 for(i = 0; i < count; i++){
576 pointsF[i].X = (REAL)points[i].X;
577 pointsF[i].Y = (REAL)points[i].Y;
580 ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
581 GdipFree(pointsF);
583 return ret;
586 /******************************************************************************
587 * GdipCreatePathGradientFromPath [GDIPLUS.@]
589 * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
591 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
592 GpPathGradient **grad)
594 COLORREF col = ARGB2COLORREF(0xffffffff);
596 TRACE("(%p, %p)\n", path, grad);
598 if(!path || !grad)
599 return InvalidParameter;
601 *grad = GdipAlloc(sizeof(GpPathGradient));
602 if (!*grad) return OutOfMemory;
604 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
605 if(!(*grad)->blendfac){
606 GdipFree(*grad);
607 return OutOfMemory;
609 (*grad)->blendfac[0] = 1.0;
610 (*grad)->blendpos = NULL;
611 (*grad)->blendcount = 1;
613 (*grad)->pathdata.Count = path->pathdata.Count;
614 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
615 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
617 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
618 GdipFree((*grad)->pathdata.Points);
619 GdipFree((*grad)->pathdata.Types);
620 GdipFree(*grad);
621 return OutOfMemory;
624 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
625 path->pathdata.Count * sizeof(PointF));
626 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
628 (*grad)->brush.lb.lbStyle = BS_SOLID;
629 (*grad)->brush.lb.lbColor = col;
630 (*grad)->brush.lb.lbHatch = 0;
632 (*grad)->brush.gdibrush = CreateSolidBrush(col);
633 (*grad)->brush.bt = BrushTypePathGradient;
634 (*grad)->centercolor = 0xffffffff;
635 (*grad)->wrap = WrapModeClamp;
636 (*grad)->gamma = FALSE;
637 /* FIXME: this should be set to the "centroid" of the path by default */
638 (*grad)->center.X = 0.0;
639 (*grad)->center.Y = 0.0;
640 (*grad)->focus.X = 0.0;
641 (*grad)->focus.Y = 0.0;
643 TRACE("<-- %p\n", *grad);
645 return Ok;
648 /******************************************************************************
649 * GdipCreateSolidFill [GDIPLUS.@]
651 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
653 COLORREF col = ARGB2COLORREF(color);
655 TRACE("(%x, %p)\n", color, sf);
657 if(!sf) return InvalidParameter;
659 *sf = GdipAlloc(sizeof(GpSolidFill));
660 if (!*sf) return OutOfMemory;
662 (*sf)->brush.lb.lbStyle = BS_SOLID;
663 (*sf)->brush.lb.lbColor = col;
664 (*sf)->brush.lb.lbHatch = 0;
666 (*sf)->brush.gdibrush = CreateSolidBrush(col);
667 (*sf)->brush.bt = BrushTypeSolidColor;
668 (*sf)->color = color;
669 (*sf)->bmp = ARGB2BMP(color);
671 TRACE("<-- %p\n", *sf);
673 return Ok;
676 /******************************************************************************
677 * GdipCreateTexture [GDIPLUS.@]
679 * PARAMS
680 * image [I] image to use
681 * wrapmode [I] optional
682 * texture [O] pointer to the resulting texturebrush
684 * RETURNS
685 * SUCCESS: Ok
686 * FAILURE: element of GpStatus
688 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
689 GpTexture **texture)
691 UINT width, height;
692 GpImageAttributes attributes;
693 GpStatus stat;
695 TRACE("%p, %d %p\n", image, wrapmode, texture);
697 if (!(image && texture))
698 return InvalidParameter;
700 stat = GdipGetImageWidth(image, &width);
701 if (stat != Ok) return stat;
702 stat = GdipGetImageHeight(image, &height);
703 if (stat != Ok) return stat;
704 attributes.wrap = wrapmode;
706 return GdipCreateTextureIA(image, &attributes, 0, 0, width, height,
707 texture);
710 /******************************************************************************
711 * GdipCreateTexture2 [GDIPLUS.@]
713 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
714 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
716 GpImageAttributes attributes;
718 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
719 x, y, width, height, texture);
721 attributes.wrap = wrapmode;
722 return GdipCreateTextureIA(image, &attributes, x, y, width, height,
723 texture);
726 /******************************************************************************
727 * GdipCreateTextureIA [GDIPLUS.@]
729 * FIXME: imageattr ignored
731 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
732 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
733 REAL height, GpTexture **texture)
735 HDC hdc;
736 HBITMAP hbm, old = NULL;
737 BITMAPINFO *pbmi;
738 BITMAPINFOHEADER *bmih;
739 INT n_x, n_y, n_width, n_height, abs_height, stride, image_stride, i, bytespp;
740 BOOL bm_is_selected;
741 BYTE *dibits, *buff, *textbits;
742 GpStatus status;
744 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
745 texture);
747 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
748 return InvalidParameter;
750 if(image->type != ImageTypeBitmap){
751 FIXME("not implemented for image type %d\n", image->type);
752 return NotImplemented;
755 n_x = roundr(x);
756 n_y = roundr(y);
757 n_width = roundr(width);
758 n_height = roundr(height);
760 if(n_x + n_width > ((GpBitmap*)image)->width ||
761 n_y + n_height > ((GpBitmap*)image)->height)
762 return InvalidParameter;
764 hbm = ((GpBitmap*)image)->hbitmap;
765 if(!hbm) return GenericError;
766 hdc = ((GpBitmap*)image)->hdc;
767 bm_is_selected = (hdc != 0);
769 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
770 if (!pbmi)
771 return OutOfMemory;
772 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
773 pbmi->bmiHeader.biBitCount = 0;
775 if(!bm_is_selected){
776 hdc = CreateCompatibleDC(0);
777 old = SelectObject(hdc, hbm);
780 /* fill out bmi */
781 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
783 bytespp = pbmi->bmiHeader.biBitCount / 8;
784 abs_height = abs(pbmi->bmiHeader.biHeight);
786 if(n_x > pbmi->bmiHeader.biWidth || n_x + n_width > pbmi->bmiHeader.biWidth ||
787 n_y > abs_height || n_y + n_height > abs_height){
788 GdipFree(pbmi);
789 return InvalidParameter;
792 dibits = GdipAlloc(pbmi->bmiHeader.biSizeImage);
794 if(dibits) /* this is not a good place to error out */
795 GetDIBits(hdc, hbm, 0, abs_height, dibits, pbmi, DIB_RGB_COLORS);
797 if(!bm_is_selected){
798 SelectObject(hdc, old);
799 DeleteDC(hdc);
802 if(!dibits){
803 GdipFree(pbmi);
804 return OutOfMemory;
807 image_stride = (pbmi->bmiHeader.biWidth * bytespp + 3) & ~3;
808 stride = (n_width * bytespp + 3) & ~3;
809 buff = GdipAlloc(sizeof(BITMAPINFOHEADER) + stride * n_height);
810 if(!buff){
811 GdipFree(pbmi);
812 GdipFree(dibits);
813 return OutOfMemory;
816 bmih = (BITMAPINFOHEADER*)buff;
817 textbits = (BYTE*) (bmih + 1);
818 bmih->biSize = sizeof(BITMAPINFOHEADER);
819 bmih->biWidth = n_width;
820 bmih->biHeight = n_height;
821 bmih->biCompression = BI_RGB;
822 bmih->biSizeImage = stride * n_height;
823 bmih->biBitCount = pbmi->bmiHeader.biBitCount;
824 bmih->biClrUsed = 0;
825 bmih->biPlanes = 1;
827 /* image is flipped */
828 if(pbmi->bmiHeader.biHeight > 0){
829 dibits += image_stride * (pbmi->bmiHeader.biHeight - 1);
830 image_stride *= -1;
831 textbits += stride * (n_height - 1);
832 stride *= -1;
835 GdipFree(pbmi);
837 for(i = 0; i < n_height; i++)
838 memcpy(&textbits[i * stride],
839 &dibits[n_x * bytespp + (n_y + i) * image_stride],
840 abs(stride));
842 *texture = GdipAlloc(sizeof(GpTexture));
843 if (!*texture){
844 GdipFree(dibits);
845 GdipFree(buff);
846 return OutOfMemory;
849 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
850 GdipFree(*texture);
851 GdipFree(dibits);
852 GdipFree(buff);
853 return status;
856 (*texture)->brush.lb.lbStyle = BS_DIBPATTERNPT;
857 (*texture)->brush.lb.lbColor = DIB_RGB_COLORS;
858 (*texture)->brush.lb.lbHatch = (ULONG_PTR)buff;
860 (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
861 (*texture)->brush.bt = BrushTypeTextureFill;
862 (*texture)->wrap = imageattr->wrap;
864 GdipFree(dibits);
865 GdipFree(buff);
867 TRACE("<-- %p\n", *texture);
869 return Ok;
872 /******************************************************************************
873 * GdipCreateTextureIAI [GDIPLUS.@]
875 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
876 INT x, INT y, INT width, INT height, GpTexture **texture)
878 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
879 texture);
881 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
884 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
885 INT x, INT y, INT width, INT height, GpTexture **texture)
887 GpImageAttributes imageattr;
889 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
890 texture);
892 imageattr.wrap = wrapmode;
894 return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
897 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
899 TRACE("(%p, %p)\n", brush, type);
901 if(!brush || !type) return InvalidParameter;
903 *type = brush->bt;
905 return Ok;
908 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
910 TRACE("(%p, %p)\n", brush, backcol);
912 if(!brush || !backcol) return InvalidParameter;
914 *backcol = brush->backcol;
916 return Ok;
919 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
921 TRACE("(%p, %p)\n", brush, forecol);
923 if(!brush || !forecol) return InvalidParameter;
925 *forecol = brush->forecol;
927 return Ok;
930 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
932 TRACE("(%p, %p)\n", brush, hatchstyle);
934 if(!brush || !hatchstyle) return InvalidParameter;
936 *hatchstyle = brush->hatchstyle;
938 return Ok;
941 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
943 TRACE("(%p)\n", brush);
945 if(!brush) return InvalidParameter;
947 switch(brush->bt)
949 case BrushTypePathGradient:
950 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
951 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
952 GdipFree(((GpPathGradient*) brush)->blendfac);
953 GdipFree(((GpPathGradient*) brush)->blendpos);
954 break;
955 case BrushTypeSolidColor:
956 if (((GpSolidFill*)brush)->bmp)
957 DeleteObject(((GpSolidFill*)brush)->bmp);
958 break;
959 case BrushTypeLinearGradient:
960 GdipFree(((GpLineGradient*)brush)->blendfac);
961 GdipFree(((GpLineGradient*)brush)->blendpos);
962 GdipFree(((GpLineGradient*)brush)->pblendcolor);
963 GdipFree(((GpLineGradient*)brush)->pblendpos);
964 break;
965 case BrushTypeTextureFill:
966 GdipDeleteMatrix(((GpTexture*)brush)->transform);
967 break;
968 default:
969 break;
972 DeleteObject(brush->gdibrush);
973 GdipFree(brush);
975 return Ok;
978 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
979 BOOL *usinggamma)
981 TRACE("(%p, %p)\n", line, usinggamma);
983 if(!line || !usinggamma)
984 return InvalidParameter;
986 *usinggamma = line->gamma;
988 return Ok;
991 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
993 TRACE("(%p, %p)\n", brush, wrapmode);
995 if(!brush || !wrapmode)
996 return InvalidParameter;
998 *wrapmode = brush->wrap;
1000 return Ok;
1003 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
1004 REAL *positions, INT count)
1006 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
1008 if(!brush || !blend || !positions || count <= 0)
1009 return InvalidParameter;
1011 if(count < brush->blendcount)
1012 return InsufficientBuffer;
1014 memcpy(blend, brush->blendfac, count*sizeof(REAL));
1015 if(brush->blendcount > 1){
1016 memcpy(positions, brush->blendpos, count*sizeof(REAL));
1019 return Ok;
1022 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
1024 TRACE("(%p, %p)\n", brush, count);
1026 if(!brush || !count)
1027 return InvalidParameter;
1029 *count = brush->blendcount;
1031 return Ok;
1034 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
1035 GpPointF *point)
1037 TRACE("(%p, %p)\n", grad, point);
1039 if(!grad || !point)
1040 return InvalidParameter;
1042 point->X = grad->center.X;
1043 point->Y = grad->center.Y;
1045 return Ok;
1048 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
1049 GpPoint *point)
1051 GpStatus ret;
1052 GpPointF ptf;
1054 TRACE("(%p, %p)\n", grad, point);
1056 if(!point)
1057 return InvalidParameter;
1059 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
1061 if(ret == Ok){
1062 point->X = roundr(ptf.X);
1063 point->Y = roundr(ptf.Y);
1066 return ret;
1069 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
1070 REAL *x, REAL *y)
1072 TRACE("(%p, %p, %p)\n", grad, x, y);
1074 if(!grad || !x || !y)
1075 return InvalidParameter;
1077 *x = grad->focus.X;
1078 *y = grad->focus.Y;
1080 return Ok;
1083 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1084 BOOL *gamma)
1086 TRACE("(%p, %p)\n", grad, gamma);
1088 if(!grad || !gamma)
1089 return InvalidParameter;
1091 *gamma = grad->gamma;
1093 return Ok;
1096 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1097 INT *count)
1099 TRACE("(%p, %p)\n", grad, count);
1101 if(!grad || !count)
1102 return InvalidParameter;
1104 *count = grad->pathdata.Count;
1106 return Ok;
1109 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1111 GpRectF r;
1112 GpPath* path;
1113 GpStatus stat;
1115 TRACE("(%p, %p)\n", brush, rect);
1117 if(!brush || !rect)
1118 return InvalidParameter;
1120 stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
1121 brush->pathdata.Count, FillModeAlternate, &path);
1122 if(stat != Ok) return stat;
1124 stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
1125 if(stat != Ok){
1126 GdipDeletePath(path);
1127 return stat;
1130 memcpy(rect, &r, sizeof(GpRectF));
1132 GdipDeletePath(path);
1134 return Ok;
1137 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1139 GpRectF rectf;
1140 GpStatus stat;
1142 TRACE("(%p, %p)\n", brush, rect);
1144 if(!brush || !rect)
1145 return InvalidParameter;
1147 stat = GdipGetPathGradientRect(brush, &rectf);
1148 if(stat != Ok) return stat;
1150 rect->X = roundr(rectf.X);
1151 rect->Y = roundr(rectf.Y);
1152 rect->Width = roundr(rectf.Width);
1153 rect->Height = roundr(rectf.Height);
1155 return Ok;
1158 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1159 *grad, ARGB *argb, INT *count)
1161 static int calls;
1163 TRACE("(%p,%p,%p)\n", grad, argb, count);
1165 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
1166 return InvalidParameter;
1168 if(!(calls++))
1169 FIXME("not implemented\n");
1171 return NotImplemented;
1174 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1175 GpWrapMode *wrapmode)
1177 TRACE("(%p, %p)\n", brush, wrapmode);
1179 if(!brush || !wrapmode)
1180 return InvalidParameter;
1182 *wrapmode = brush->wrap;
1184 return Ok;
1187 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1189 TRACE("(%p, %p)\n", sf, argb);
1191 if(!sf || !argb)
1192 return InvalidParameter;
1194 *argb = sf->color;
1196 return Ok;
1199 /******************************************************************************
1200 * GdipGetTextureTransform [GDIPLUS.@]
1202 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1204 TRACE("(%p, %p)\n", brush, matrix);
1206 if(!brush || !matrix)
1207 return InvalidParameter;
1209 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1211 return Ok;
1214 /******************************************************************************
1215 * GdipGetTextureWrapMode [GDIPLUS.@]
1217 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1219 TRACE("(%p, %p)\n", brush, wrapmode);
1221 if(!brush || !wrapmode)
1222 return InvalidParameter;
1224 *wrapmode = brush->wrap;
1226 return Ok;
1229 /******************************************************************************
1230 * GdipMultiplyTextureTransform [GDIPLUS.@]
1232 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1233 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1235 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1237 if(!brush || !matrix)
1238 return InvalidParameter;
1240 return GdipMultiplyMatrix(brush->transform, matrix, order);
1243 /******************************************************************************
1244 * GdipResetTextureTransform [GDIPLUS.@]
1246 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1248 TRACE("(%p)\n", brush);
1250 if(!brush)
1251 return InvalidParameter;
1253 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1256 /******************************************************************************
1257 * GdipScaleTextureTransform [GDIPLUS.@]
1259 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1260 REAL sx, REAL sy, GpMatrixOrder order)
1262 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1264 if(!brush)
1265 return InvalidParameter;
1267 return GdipScaleMatrix(brush->transform, sx, sy, order);
1270 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1271 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1273 REAL *new_blendfac, *new_blendpos;
1275 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1277 if(!brush || !factors || !positions || count <= 0 ||
1278 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1279 return InvalidParameter;
1281 new_blendfac = GdipAlloc(count * sizeof(REAL));
1282 new_blendpos = GdipAlloc(count * sizeof(REAL));
1284 if (!new_blendfac || !new_blendpos)
1286 GdipFree(new_blendfac);
1287 GdipFree(new_blendpos);
1288 return OutOfMemory;
1291 memcpy(new_blendfac, factors, count * sizeof(REAL));
1292 memcpy(new_blendpos, positions, count * sizeof(REAL));
1294 GdipFree(brush->blendfac);
1295 GdipFree(brush->blendpos);
1297 brush->blendcount = count;
1298 brush->blendfac = new_blendfac;
1299 brush->blendpos = new_blendpos;
1301 return Ok;
1304 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1305 REAL *positions, INT count)
1307 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1309 if (!brush || !factors || !positions || count <= 0)
1310 return InvalidParameter;
1312 if (count < brush->blendcount)
1313 return InsufficientBuffer;
1315 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1316 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1318 return Ok;
1321 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1323 TRACE("(%p, %p)\n", brush, count);
1325 if (!brush || !count)
1326 return InvalidParameter;
1328 *count = brush->blendcount;
1330 return Ok;
1333 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1334 BOOL usegamma)
1336 TRACE("(%p, %d)\n", line, usegamma);
1338 if(!line)
1339 return InvalidParameter;
1341 line->gamma = usegamma;
1343 return Ok;
1346 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1347 REAL scale)
1349 REAL factors[33];
1350 REAL positions[33];
1351 int num_points = 0;
1352 int i;
1353 const int precision = 16;
1354 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1355 REAL min_erf;
1356 REAL scale_erf;
1358 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1360 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1361 return InvalidParameter;
1363 /* we want 2 standard deviations */
1364 erf_range = 2.0 / sqrt(2);
1366 /* calculate the constants we need to normalize the error function to be
1367 between 0.0 and scale over the range we need */
1368 min_erf = erf(-erf_range);
1369 scale_erf = scale / (-2.0 * min_erf);
1371 if (focus != 0.0)
1373 positions[0] = 0.0;
1374 factors[0] = 0.0;
1375 for (i=1; i<precision; i++)
1377 positions[i] = focus * i / precision;
1378 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1380 num_points += precision;
1383 positions[num_points] = focus;
1384 factors[num_points] = scale;
1385 num_points += 1;
1387 if (focus != 1.0)
1389 for (i=1; i<precision; i++)
1391 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1392 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1394 num_points += precision;
1395 positions[num_points-1] = 1.0;
1396 factors[num_points-1] = 0.0;
1399 return GdipSetLineBlend(line, factors, positions, num_points);
1402 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1403 GpWrapMode wrap)
1405 TRACE("(%p, %d)\n", line, wrap);
1407 if(!line || wrap == WrapModeClamp)
1408 return InvalidParameter;
1410 line->wrap = wrap;
1412 return Ok;
1415 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1416 GDIPCONST REAL *pos, INT count)
1418 static int calls;
1420 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1422 if(!(calls++))
1423 FIXME("not implemented\n");
1425 return NotImplemented;
1428 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1429 GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1431 FIXME("(%p,%p,%p,%i): stub\n", brush, blend, pos, count);
1432 return NotImplemented;
1435 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1436 ARGB argb)
1438 TRACE("(%p, %x)\n", grad, argb);
1440 if(!grad)
1441 return InvalidParameter;
1443 grad->centercolor = argb;
1444 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1446 DeleteObject(grad->brush.gdibrush);
1447 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1449 return Ok;
1452 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1453 GpPointF *point)
1455 TRACE("(%p, %s)\n", grad, debugstr_pointf(point));
1457 if(!grad || !point)
1458 return InvalidParameter;
1460 grad->center.X = point->X;
1461 grad->center.Y = point->Y;
1463 return Ok;
1466 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1467 GpPoint *point)
1469 GpPointF ptf;
1471 TRACE("(%p, %p)\n", grad, point);
1473 if(!point)
1474 return InvalidParameter;
1476 ptf.X = (REAL)point->X;
1477 ptf.Y = (REAL)point->Y;
1479 return GdipSetPathGradientCenterPoint(grad,&ptf);
1482 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1483 REAL x, REAL y)
1485 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1487 if(!grad)
1488 return InvalidParameter;
1490 grad->focus.X = x;
1491 grad->focus.Y = y;
1493 return Ok;
1496 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1497 BOOL gamma)
1499 TRACE("(%p, %d)\n", grad, gamma);
1501 if(!grad)
1502 return InvalidParameter;
1504 grad->gamma = gamma;
1506 return Ok;
1509 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1510 REAL focus, REAL scale)
1512 static int calls;
1514 TRACE("(%p,%0.2f,%0.2f)\n", grad, focus, scale);
1516 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1517 return InvalidParameter;
1519 if(!(calls++))
1520 FIXME("not implemented\n");
1522 return NotImplemented;
1525 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1526 *grad, ARGB *argb, INT *count)
1528 static int calls;
1530 TRACE("(%p,%p,%p)\n", grad, argb, count);
1532 if(!grad || !argb || !count || (*count <= 0) ||
1533 (*count > grad->pathdata.Count))
1534 return InvalidParameter;
1536 if(!(calls++))
1537 FIXME("not implemented\n");
1539 return NotImplemented;
1542 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1543 GpWrapMode wrap)
1545 TRACE("(%p, %d)\n", grad, wrap);
1547 if(!grad)
1548 return InvalidParameter;
1550 grad->wrap = wrap;
1552 return Ok;
1555 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1557 TRACE("(%p, %x)\n", sf, argb);
1559 if(!sf)
1560 return InvalidParameter;
1562 sf->color = argb;
1563 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1565 DeleteObject(sf->brush.gdibrush);
1566 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1568 return Ok;
1571 /******************************************************************************
1572 * GdipSetTextureTransform [GDIPLUS.@]
1574 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1575 GDIPCONST GpMatrix *matrix)
1577 TRACE("(%p, %p)\n", texture, matrix);
1579 if(!texture || !matrix)
1580 return InvalidParameter;
1582 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1584 return Ok;
1587 /******************************************************************************
1588 * GdipSetTextureWrapMode [GDIPLUS.@]
1590 * WrapMode not used, only stored
1592 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1594 TRACE("(%p, %d)\n", brush, wrapmode);
1596 if(!brush)
1597 return InvalidParameter;
1599 brush->wrap = wrapmode;
1601 return Ok;
1604 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1605 ARGB color2)
1607 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1609 if(!brush)
1610 return InvalidParameter;
1612 brush->startcolor = color1;
1613 brush->endcolor = color2;
1615 return Ok;
1618 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1620 TRACE("(%p, %p)\n", brush, colors);
1622 if(!brush || !colors)
1623 return InvalidParameter;
1625 colors[0] = brush->startcolor;
1626 colors[1] = brush->endcolor;
1628 return Ok;
1631 /******************************************************************************
1632 * GdipRotateTextureTransform [GDIPLUS.@]
1634 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1635 GpMatrixOrder order)
1637 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1639 if(!brush)
1640 return InvalidParameter;
1642 return GdipRotateMatrix(brush->transform, angle, order);
1645 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1646 REAL scale)
1648 REAL factors[3];
1649 REAL positions[3];
1650 int num_points = 0;
1652 TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1654 if (!brush) return InvalidParameter;
1656 if (focus != 0.0)
1658 factors[num_points] = 0.0;
1659 positions[num_points] = 0.0;
1660 num_points++;
1663 factors[num_points] = scale;
1664 positions[num_points] = focus;
1665 num_points++;
1667 if (focus != 1.0)
1669 factors[num_points] = 0.0;
1670 positions[num_points] = 1.0;
1671 num_points++;
1674 return GdipSetLineBlend(brush, factors, positions, num_points);
1677 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1678 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1680 ARGB *new_color;
1681 REAL *new_pos;
1682 TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1684 if (!brush || !blend || !positions || count < 2 ||
1685 positions[0] != 0.0f || positions[count-1] != 1.0f)
1687 return InvalidParameter;
1690 new_color = GdipAlloc(count * sizeof(ARGB));
1691 new_pos = GdipAlloc(count * sizeof(REAL));
1692 if (!new_color || !new_pos)
1694 GdipFree(new_color);
1695 GdipFree(new_pos);
1696 return OutOfMemory;
1699 memcpy(new_color, blend, sizeof(ARGB) * count);
1700 memcpy(new_pos, positions, sizeof(REAL) * count);
1702 GdipFree(brush->pblendcolor);
1703 GdipFree(brush->pblendpos);
1705 brush->pblendcolor = new_color;
1706 brush->pblendpos = new_pos;
1707 brush->pblendcount = count;
1709 return Ok;
1712 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1713 ARGB *blend, REAL* positions, INT count)
1715 if (!brush || !blend || !positions || count < 2)
1716 return InvalidParameter;
1718 if (brush->pblendcount == 0)
1719 return GenericError;
1721 if (count < brush->pblendcount)
1722 return InsufficientBuffer;
1724 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1725 memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1727 return Ok;
1730 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1731 INT *count)
1733 if (!brush || !count)
1734 return InvalidParameter;
1736 *count = brush->pblendcount;
1738 return Ok;
1741 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1743 static int calls;
1745 TRACE("(%p)\n", brush);
1747 if(!(calls++))
1748 FIXME("not implemented\n");
1750 return NotImplemented;
1753 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1754 GDIPCONST GpMatrix *matrix)
1756 static int calls;
1758 TRACE("(%p,%p)\n", brush, matrix);
1760 if(!(calls++))
1761 FIXME("not implemented\n");
1763 return NotImplemented;
1766 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
1767 GpMatrixOrder order)
1769 static int calls;
1771 TRACE("(%p,%0.2f,%0.2f,%u)\n", brush, sx, sy, order);
1773 if(!(calls++))
1774 FIXME("not implemented\n");
1776 return NotImplemented;
1779 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1780 REAL dx, REAL dy, GpMatrixOrder order)
1782 FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1784 return NotImplemented;
1787 /******************************************************************************
1788 * GdipTranslateTextureTransform [GDIPLUS.@]
1790 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1791 GpMatrixOrder order)
1793 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1795 if(!brush)
1796 return InvalidParameter;
1798 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1801 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1803 TRACE("(%p, %p)\n", brush, rect);
1805 if(!brush || !rect)
1806 return InvalidParameter;
1808 *rect = brush->rect;
1810 return Ok;
1813 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1815 GpRectF rectF;
1816 GpStatus ret;
1818 TRACE("(%p, %p)\n", brush, rect);
1820 if(!rect)
1821 return InvalidParameter;
1823 ret = GdipGetLineRect(brush, &rectF);
1825 if(ret == Ok){
1826 rect->X = roundr(rectF.X);
1827 rect->Y = roundr(rectF.Y);
1828 rect->Width = roundr(rectF.Width);
1829 rect->Height = roundr(rectF.Height);
1832 return ret;
1835 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1836 REAL angle, GpMatrixOrder order)
1838 static int calls;
1840 TRACE("(%p,%0.2f,%u)\n", brush, angle, order);
1842 if(!brush)
1843 return InvalidParameter;
1845 if(!(calls++))
1846 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1848 return NotImplemented;