push 8b07bf1f08b23b9893a622b47d2be359556765b1
[wine/hacks.git] / dlls / gdiplus / brush.c
blob3bce1d3cc91b9883e05a25df573132f20af64244
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 return Ok;
180 static const char HatchBrushes[][8] = {
181 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HatchStyleHorizontal */
182 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleVertical */
183 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HatchStyleForwardDiagonal */
184 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HatchStyleBackwardDiagonal */
185 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleCross */
186 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }, /* HatchStyleDiagonalCross */
187 { 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x80 }, /* HatchStyle05Percent */
188 { 0x00, 0x02, 0x00, 0x88, 0x00, 0x20, 0x00, 0x88 }, /* HatchStyle10Percent */
189 { 0x00, 0x22, 0x00, 0xcc, 0x00, 0x22, 0x00, 0xcc }, /* HatchStyle20Percent */
190 { 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc }, /* HatchStyle25Percent */
191 { 0x00, 0xcc, 0x04, 0xcc, 0x00, 0xcc, 0x40, 0xcc }, /* HatchStyle30Percent */
192 { 0x44, 0xcc, 0x22, 0xcc, 0x44, 0xcc, 0x22, 0xcc }, /* HatchStyle40Percent */
193 { 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc }, /* HatchStyle50Percent */
194 { 0x55, 0xcd, 0x55, 0xee, 0x55, 0xdc, 0x55, 0xee }, /* HatchStyle60Percent */
195 { 0x55, 0xdd, 0x55, 0xff, 0x55, 0xdd, 0x55, 0xff }, /* HatchStyle70Percent */
196 { 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff }, /* HatchStyle75Percent */
197 { 0x55, 0xff, 0x59, 0xff, 0x55, 0xff, 0x99, 0xff }, /* HatchStyle80Percent */
198 { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xfd, 0xff }, /* HatchStyle90Percent */
199 { 0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88 }, /* HatchStyleLightDownwardDiagonal */
200 { 0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11 }, /* HatchStyleLightUpwardDiagonal */
201 { 0x99, 0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc }, /* HatchStyleDarkDownwardDiagonal */
202 { 0xcc, 0x66, 0x33, 0x99, 0xcc, 0x66, 0x33, 0x99 }, /* HatchStyleDarkUpwardDiagonal */
203 { 0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0 }, /* HatchStyleWideDownwardDiagonal */
204 { 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x83, 0xc1 }, /* HatchStyleWideUpwardDiagonal */
205 { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 }, /* HatchStyleLightVertical */
206 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff }, /* HatchStyleLightHorizontal */
207 { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }, /* HatchStyleNarrowVertical */
208 { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, /* HatchStyleNarrowHorizontal */
209 { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }, /* HatchStyleDarkVertical */
210 { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff }, /* HatchStyleDarkHorizontal */
213 /******************************************************************************
214 * GdipCreateHatchBrush [GDIPLUS.@]
216 GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle hatchstyle, ARGB forecol, ARGB backcol, GpHatch **brush)
218 COLORREF fgcol = ARGB2COLORREF(forecol);
219 GpStatus stat = Ok;
221 TRACE("(%d, %d, %d, %p)\n", hatchstyle, forecol, backcol, brush);
223 if(!brush) return InvalidParameter;
225 *brush = GdipAlloc(sizeof(GpHatch));
226 if (!*brush) return OutOfMemory;
228 if (hatchstyle < sizeof(HatchBrushes) / sizeof(HatchBrushes[0]))
230 HBITMAP hbmp;
231 HDC hdc;
232 BITMAPINFOHEADER bmih;
233 DWORD* bits;
234 int x, y;
236 hdc = CreateCompatibleDC(0);
238 if (hdc)
240 bmih.biSize = sizeof(bmih);
241 bmih.biWidth = 8;
242 bmih.biHeight = 8;
243 bmih.biPlanes = 1;
244 bmih.biBitCount = 32;
245 bmih.biCompression = BI_RGB;
246 bmih.biSizeImage = 0;
248 hbmp = CreateDIBSection(hdc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
250 if (hbmp)
252 for (y=0; y<8; y++)
253 for (x=0; x<8; x++)
254 if ((HatchBrushes[hatchstyle][y] & (0x80 >> x)) != 0)
255 bits[y*8+x] = forecol;
256 else
257 bits[y*8+x] = backcol;
259 else
260 stat = GenericError;
262 DeleteDC(hdc);
264 else
265 stat = GenericError;
267 if (stat == Ok)
269 (*brush)->brush.lb.lbStyle = BS_PATTERN;
270 (*brush)->brush.lb.lbColor = 0;
271 (*brush)->brush.lb.lbHatch = (ULONG_PTR)hbmp;
272 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
274 DeleteObject(hbmp);
277 else
279 FIXME("Unimplemented hatch style %d\n", hatchstyle);
281 (*brush)->brush.lb.lbStyle = BS_SOLID;
282 (*brush)->brush.lb.lbColor = fgcol;
283 (*brush)->brush.lb.lbHatch = 0;
284 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
287 if (stat == Ok)
289 (*brush)->brush.bt = BrushTypeHatchFill;
290 (*brush)->forecol = forecol;
291 (*brush)->backcol = backcol;
292 (*brush)->hatchstyle = hatchstyle;
294 else
296 GdipFree(*brush);
297 *brush = NULL;
300 return stat;
303 /******************************************************************************
304 * GdipCreateLineBrush [GDIPLUS.@]
306 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
307 GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
308 GpWrapMode wrap, GpLineGradient **line)
310 COLORREF col = ARGB2COLORREF(startcolor);
312 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
313 startcolor, endcolor, wrap, line);
315 if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
316 return InvalidParameter;
318 *line = GdipAlloc(sizeof(GpLineGradient));
319 if(!*line) return OutOfMemory;
321 (*line)->brush.lb.lbStyle = BS_SOLID;
322 (*line)->brush.lb.lbColor = col;
323 (*line)->brush.lb.lbHatch = 0;
324 (*line)->brush.gdibrush = CreateSolidBrush(col);
325 (*line)->brush.bt = BrushTypeLinearGradient;
327 (*line)->startpoint.X = startpoint->X;
328 (*line)->startpoint.Y = startpoint->Y;
329 (*line)->endpoint.X = endpoint->X;
330 (*line)->endpoint.Y = endpoint->Y;
331 (*line)->startcolor = startcolor;
332 (*line)->endcolor = endcolor;
333 (*line)->wrap = wrap;
334 (*line)->gamma = FALSE;
336 (*line)->rect.X = (startpoint->X < endpoint->X ? startpoint->X: endpoint->X);
337 (*line)->rect.Y = (startpoint->Y < endpoint->Y ? startpoint->Y: endpoint->Y);
338 (*line)->rect.Width = fabs(startpoint->X - endpoint->X);
339 (*line)->rect.Height = fabs(startpoint->Y - endpoint->Y);
341 if ((*line)->rect.Width == 0)
343 (*line)->rect.X -= (*line)->rect.Height / 2.0f;
344 (*line)->rect.Width = (*line)->rect.Height;
346 else if ((*line)->rect.Height == 0)
348 (*line)->rect.Y -= (*line)->rect.Width / 2.0f;
349 (*line)->rect.Height = (*line)->rect.Width;
352 (*line)->blendcount = 1;
353 (*line)->blendfac = GdipAlloc(sizeof(REAL));
354 (*line)->blendpos = GdipAlloc(sizeof(REAL));
356 if (!(*line)->blendfac || !(*line)->blendpos)
358 GdipFree((*line)->blendfac);
359 GdipFree((*line)->blendpos);
360 DeleteObject((*line)->brush.gdibrush);
361 GdipFree(*line);
362 *line = NULL;
363 return OutOfMemory;
366 (*line)->blendfac[0] = 1.0f;
367 (*line)->blendpos[0] = 1.0f;
369 (*line)->pblendcolor = NULL;
370 (*line)->pblendpos = NULL;
371 (*line)->pblendcount = 0;
373 return Ok;
376 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
377 GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
378 GpWrapMode wrap, GpLineGradient **line)
380 GpPointF stF;
381 GpPointF endF;
383 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
384 startcolor, endcolor, wrap, line);
386 if(!startpoint || !endpoint)
387 return InvalidParameter;
389 stF.X = (REAL)startpoint->X;
390 stF.Y = (REAL)startpoint->Y;
391 endF.X = (REAL)endpoint->X;
392 endF.X = (REAL)endpoint->Y;
394 return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
397 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
398 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
399 GpLineGradient **line)
401 GpPointF start, end;
402 GpStatus stat;
404 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
405 wrap, line);
407 if(!line || !rect)
408 return InvalidParameter;
410 switch (mode)
412 case LinearGradientModeHorizontal:
413 start.X = rect->X;
414 start.Y = rect->Y;
415 end.X = rect->X + rect->Width;
416 end.Y = rect->Y;
417 break;
418 case LinearGradientModeVertical:
419 start.X = rect->X;
420 start.Y = rect->Y;
421 end.X = rect->X;
422 end.Y = rect->Y + rect->Height;
423 break;
424 case LinearGradientModeForwardDiagonal:
425 start.X = rect->X;
426 start.Y = rect->Y;
427 end.X = rect->X + rect->Width;
428 end.Y = rect->Y + rect->Height;
429 break;
430 case LinearGradientModeBackwardDiagonal:
431 start.X = rect->X + rect->Width;
432 start.Y = rect->Y;
433 end.X = rect->X;
434 end.Y = rect->Y + rect->Height;
435 break;
436 default:
437 return InvalidParameter;
440 stat = GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
442 if (stat == Ok)
443 (*line)->rect = *rect;
445 return stat;
448 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
449 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
450 GpLineGradient **line)
452 GpRectF rectF;
454 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
455 wrap, line);
457 rectF.X = (REAL) rect->X;
458 rectF.Y = (REAL) rect->Y;
459 rectF.Width = (REAL) rect->Width;
460 rectF.Height = (REAL) rect->Height;
462 return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
465 /******************************************************************************
466 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
468 * FIXME: angle value completely ignored. Don't know how to use it since native
469 * always set Brush rectangle to rect (independetly of this angle).
470 * Maybe it's used only on drawing.
472 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
473 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
474 GpLineGradient **line)
476 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
477 wrap, line);
479 return GdipCreateLineBrushFromRect(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
480 wrap, line);
483 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
484 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
485 GpLineGradient **line)
487 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
488 wrap, line);
490 return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
491 wrap, line);
494 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
495 INT count, GpWrapMode wrap, GpPathGradient **grad)
497 COLORREF col = ARGB2COLORREF(0xffffffff);
499 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
501 if(!points || !grad)
502 return InvalidParameter;
504 if(count <= 0)
505 return OutOfMemory;
507 *grad = GdipAlloc(sizeof(GpPathGradient));
508 if (!*grad) return OutOfMemory;
510 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
511 if(!(*grad)->blendfac){
512 GdipFree(*grad);
513 return OutOfMemory;
515 (*grad)->blendfac[0] = 1.0;
516 (*grad)->blendpos = NULL;
517 (*grad)->blendcount = 1;
519 (*grad)->pathdata.Count = count;
520 (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
521 (*grad)->pathdata.Types = GdipAlloc(count);
523 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
524 GdipFree((*grad)->pathdata.Points);
525 GdipFree((*grad)->pathdata.Types);
526 GdipFree(*grad);
527 return OutOfMemory;
530 memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
531 memset((*grad)->pathdata.Types, PathPointTypeLine, count);
533 (*grad)->brush.lb.lbStyle = BS_SOLID;
534 (*grad)->brush.lb.lbColor = col;
535 (*grad)->brush.lb.lbHatch = 0;
537 (*grad)->brush.gdibrush = CreateSolidBrush(col);
538 (*grad)->brush.bt = BrushTypePathGradient;
539 (*grad)->centercolor = 0xffffffff;
540 (*grad)->wrap = wrap;
541 (*grad)->gamma = FALSE;
542 (*grad)->center.X = 0.0;
543 (*grad)->center.Y = 0.0;
544 (*grad)->focus.X = 0.0;
545 (*grad)->focus.Y = 0.0;
547 return Ok;
550 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
551 INT count, GpWrapMode wrap, GpPathGradient **grad)
553 GpPointF *pointsF;
554 GpStatus ret;
555 INT i;
557 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
559 if(!points || !grad)
560 return InvalidParameter;
562 if(count <= 0)
563 return OutOfMemory;
565 pointsF = GdipAlloc(sizeof(GpPointF) * count);
566 if(!pointsF)
567 return OutOfMemory;
569 for(i = 0; i < count; i++){
570 pointsF[i].X = (REAL)points[i].X;
571 pointsF[i].Y = (REAL)points[i].Y;
574 ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
575 GdipFree(pointsF);
577 return ret;
580 /******************************************************************************
581 * GdipCreatePathGradientFromPath [GDIPLUS.@]
583 * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
585 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
586 GpPathGradient **grad)
588 COLORREF col = ARGB2COLORREF(0xffffffff);
590 TRACE("(%p, %p)\n", path, grad);
592 if(!path || !grad)
593 return InvalidParameter;
595 *grad = GdipAlloc(sizeof(GpPathGradient));
596 if (!*grad) return OutOfMemory;
598 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
599 if(!(*grad)->blendfac){
600 GdipFree(*grad);
601 return OutOfMemory;
603 (*grad)->blendfac[0] = 1.0;
604 (*grad)->blendpos = NULL;
605 (*grad)->blendcount = 1;
607 (*grad)->pathdata.Count = path->pathdata.Count;
608 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
609 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
611 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
612 GdipFree((*grad)->pathdata.Points);
613 GdipFree((*grad)->pathdata.Types);
614 GdipFree(*grad);
615 return OutOfMemory;
618 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
619 path->pathdata.Count * sizeof(PointF));
620 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
622 (*grad)->brush.lb.lbStyle = BS_SOLID;
623 (*grad)->brush.lb.lbColor = col;
624 (*grad)->brush.lb.lbHatch = 0;
626 (*grad)->brush.gdibrush = CreateSolidBrush(col);
627 (*grad)->brush.bt = BrushTypePathGradient;
628 (*grad)->centercolor = 0xffffffff;
629 (*grad)->wrap = WrapModeClamp;
630 (*grad)->gamma = FALSE;
631 /* FIXME: this should be set to the "centroid" of the path by default */
632 (*grad)->center.X = 0.0;
633 (*grad)->center.Y = 0.0;
634 (*grad)->focus.X = 0.0;
635 (*grad)->focus.Y = 0.0;
637 return Ok;
640 /******************************************************************************
641 * GdipCreateSolidFill [GDIPLUS.@]
643 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
645 COLORREF col = ARGB2COLORREF(color);
647 TRACE("(%x, %p)\n", color, sf);
649 if(!sf) return InvalidParameter;
651 *sf = GdipAlloc(sizeof(GpSolidFill));
652 if (!*sf) return OutOfMemory;
654 (*sf)->brush.lb.lbStyle = BS_SOLID;
655 (*sf)->brush.lb.lbColor = col;
656 (*sf)->brush.lb.lbHatch = 0;
658 (*sf)->brush.gdibrush = CreateSolidBrush(col);
659 (*sf)->brush.bt = BrushTypeSolidColor;
660 (*sf)->color = color;
661 (*sf)->bmp = ARGB2BMP(color);
663 return Ok;
666 /******************************************************************************
667 * GdipCreateTexture [GDIPLUS.@]
669 * PARAMS
670 * image [I] image to use
671 * wrapmode [I] optional
672 * texture [O] pointer to the resulting texturebrush
674 * RETURNS
675 * SUCCESS: Ok
676 * FAILURE: element of GpStatus
678 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
679 GpTexture **texture)
681 UINT width, height;
682 GpImageAttributes attributes;
683 GpStatus stat;
685 TRACE("%p, %d %p\n", image, wrapmode, texture);
687 if (!(image && texture))
688 return InvalidParameter;
690 stat = GdipGetImageWidth(image, &width);
691 if (stat != Ok) return stat;
692 stat = GdipGetImageHeight(image, &height);
693 if (stat != Ok) return stat;
694 attributes.wrap = wrapmode;
696 return GdipCreateTextureIA(image, &attributes, 0, 0, width, height,
697 texture);
700 /******************************************************************************
701 * GdipCreateTexture2 [GDIPLUS.@]
703 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
704 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
706 GpImageAttributes attributes;
708 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
709 x, y, width, height, texture);
711 attributes.wrap = wrapmode;
712 return GdipCreateTextureIA(image, &attributes, x, y, width, height,
713 texture);
716 /******************************************************************************
717 * GdipCreateTextureIA [GDIPLUS.@]
719 * FIXME: imageattr ignored
721 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
722 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
723 REAL height, GpTexture **texture)
725 HDC hdc;
726 HBITMAP hbm, old = NULL;
727 BITMAPINFO *pbmi;
728 BITMAPINFOHEADER *bmih;
729 INT n_x, n_y, n_width, n_height, abs_height, stride, image_stride, i, bytespp;
730 BOOL bm_is_selected;
731 BYTE *dibits, *buff, *textbits;
732 GpStatus status;
734 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
735 texture);
737 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
738 return InvalidParameter;
740 if(image->type != ImageTypeBitmap){
741 FIXME("not implemented for image type %d\n", image->type);
742 return NotImplemented;
745 n_x = roundr(x);
746 n_y = roundr(y);
747 n_width = roundr(width);
748 n_height = roundr(height);
750 if(n_x + n_width > ((GpBitmap*)image)->width ||
751 n_y + n_height > ((GpBitmap*)image)->height)
752 return InvalidParameter;
754 hbm = ((GpBitmap*)image)->hbitmap;
755 if(!hbm) return GenericError;
756 hdc = ((GpBitmap*)image)->hdc;
757 bm_is_selected = (hdc != 0);
759 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
760 if (!pbmi)
761 return OutOfMemory;
762 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
763 pbmi->bmiHeader.biBitCount = 0;
765 if(!bm_is_selected){
766 hdc = CreateCompatibleDC(0);
767 old = SelectObject(hdc, hbm);
770 /* fill out bmi */
771 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
773 bytespp = pbmi->bmiHeader.biBitCount / 8;
774 abs_height = abs(pbmi->bmiHeader.biHeight);
776 if(n_x > pbmi->bmiHeader.biWidth || n_x + n_width > pbmi->bmiHeader.biWidth ||
777 n_y > abs_height || n_y + n_height > abs_height){
778 GdipFree(pbmi);
779 return InvalidParameter;
782 dibits = GdipAlloc(pbmi->bmiHeader.biSizeImage);
784 if(dibits) /* this is not a good place to error out */
785 GetDIBits(hdc, hbm, 0, abs_height, dibits, pbmi, DIB_RGB_COLORS);
787 if(!bm_is_selected){
788 SelectObject(hdc, old);
789 DeleteDC(hdc);
792 if(!dibits){
793 GdipFree(pbmi);
794 return OutOfMemory;
797 image_stride = (pbmi->bmiHeader.biWidth * bytespp + 3) & ~3;
798 stride = (n_width * bytespp + 3) & ~3;
799 buff = GdipAlloc(sizeof(BITMAPINFOHEADER) + stride * n_height);
800 if(!buff){
801 GdipFree(pbmi);
802 GdipFree(dibits);
803 return OutOfMemory;
806 bmih = (BITMAPINFOHEADER*)buff;
807 textbits = (BYTE*) (bmih + 1);
808 bmih->biSize = sizeof(BITMAPINFOHEADER);
809 bmih->biWidth = n_width;
810 bmih->biHeight = n_height;
811 bmih->biCompression = BI_RGB;
812 bmih->biSizeImage = stride * n_height;
813 bmih->biBitCount = pbmi->bmiHeader.biBitCount;
814 bmih->biClrUsed = 0;
815 bmih->biPlanes = 1;
817 /* image is flipped */
818 if(pbmi->bmiHeader.biHeight > 0){
819 dibits += image_stride * (pbmi->bmiHeader.biHeight - 1);
820 image_stride *= -1;
821 textbits += stride * (n_height - 1);
822 stride *= -1;
825 GdipFree(pbmi);
827 for(i = 0; i < n_height; i++)
828 memcpy(&textbits[i * stride],
829 &dibits[n_x * bytespp + (n_y + i) * image_stride],
830 abs(stride));
832 *texture = GdipAlloc(sizeof(GpTexture));
833 if (!*texture){
834 GdipFree(dibits);
835 GdipFree(buff);
836 return OutOfMemory;
839 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
840 GdipFree(*texture);
841 GdipFree(dibits);
842 GdipFree(buff);
843 return status;
846 (*texture)->brush.lb.lbStyle = BS_DIBPATTERNPT;
847 (*texture)->brush.lb.lbColor = DIB_RGB_COLORS;
848 (*texture)->brush.lb.lbHatch = (ULONG_PTR)buff;
850 (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
851 (*texture)->brush.bt = BrushTypeTextureFill;
852 (*texture)->wrap = imageattr->wrap;
854 GdipFree(dibits);
855 GdipFree(buff);
857 return Ok;
860 /******************************************************************************
861 * GdipCreateTextureIAI [GDIPLUS.@]
863 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
864 INT x, INT y, INT width, INT height, GpTexture **texture)
866 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
867 texture);
869 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
872 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
873 INT x, INT y, INT width, INT height, GpTexture **texture)
875 GpImageAttributes imageattr;
877 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
878 texture);
880 imageattr.wrap = wrapmode;
882 return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
885 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
887 TRACE("(%p, %p)\n", brush, type);
889 if(!brush || !type) return InvalidParameter;
891 *type = brush->bt;
893 return Ok;
896 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
898 TRACE("(%p, %p)\n", brush, backcol);
900 if(!brush || !backcol) return InvalidParameter;
902 *backcol = brush->backcol;
904 return Ok;
907 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
909 TRACE("(%p, %p)\n", brush, forecol);
911 if(!brush || !forecol) return InvalidParameter;
913 *forecol = brush->forecol;
915 return Ok;
918 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
920 TRACE("(%p, %p)\n", brush, hatchstyle);
922 if(!brush || !hatchstyle) return InvalidParameter;
924 *hatchstyle = brush->hatchstyle;
926 return Ok;
929 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
931 TRACE("(%p)\n", brush);
933 if(!brush) return InvalidParameter;
935 switch(brush->bt)
937 case BrushTypePathGradient:
938 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
939 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
940 GdipFree(((GpPathGradient*) brush)->blendfac);
941 GdipFree(((GpPathGradient*) brush)->blendpos);
942 break;
943 case BrushTypeSolidColor:
944 if (((GpSolidFill*)brush)->bmp)
945 DeleteObject(((GpSolidFill*)brush)->bmp);
946 break;
947 case BrushTypeLinearGradient:
948 GdipFree(((GpLineGradient*)brush)->blendfac);
949 GdipFree(((GpLineGradient*)brush)->blendpos);
950 GdipFree(((GpLineGradient*)brush)->pblendcolor);
951 GdipFree(((GpLineGradient*)brush)->pblendpos);
952 break;
953 case BrushTypeTextureFill:
954 GdipDeleteMatrix(((GpTexture*)brush)->transform);
955 break;
956 default:
957 break;
960 DeleteObject(brush->gdibrush);
961 GdipFree(brush);
963 return Ok;
966 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
967 BOOL *usinggamma)
969 TRACE("(%p, %p)\n", line, usinggamma);
971 if(!line || !usinggamma)
972 return InvalidParameter;
974 *usinggamma = line->gamma;
976 return Ok;
979 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
981 TRACE("(%p, %p)\n", brush, wrapmode);
983 if(!brush || !wrapmode)
984 return InvalidParameter;
986 *wrapmode = brush->wrap;
988 return Ok;
991 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
992 REAL *positions, INT count)
994 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
996 if(!brush || !blend || !positions || count <= 0)
997 return InvalidParameter;
999 if(count < brush->blendcount)
1000 return InsufficientBuffer;
1002 memcpy(blend, brush->blendfac, count*sizeof(REAL));
1003 if(brush->blendcount > 1){
1004 memcpy(positions, brush->blendpos, count*sizeof(REAL));
1007 return Ok;
1010 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
1012 TRACE("(%p, %p)\n", brush, count);
1014 if(!brush || !count)
1015 return InvalidParameter;
1017 *count = brush->blendcount;
1019 return Ok;
1022 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
1023 GpPointF *point)
1025 TRACE("(%p, %p)\n", grad, point);
1027 if(!grad || !point)
1028 return InvalidParameter;
1030 point->X = grad->center.X;
1031 point->Y = grad->center.Y;
1033 return Ok;
1036 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
1037 GpPoint *point)
1039 GpStatus ret;
1040 GpPointF ptf;
1042 TRACE("(%p, %p)\n", grad, point);
1044 if(!point)
1045 return InvalidParameter;
1047 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
1049 if(ret == Ok){
1050 point->X = roundr(ptf.X);
1051 point->Y = roundr(ptf.Y);
1054 return ret;
1057 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
1058 REAL *x, REAL *y)
1060 TRACE("(%p, %p, %p)\n", grad, x, y);
1062 if(!grad || !x || !y)
1063 return InvalidParameter;
1065 *x = grad->focus.X;
1066 *y = grad->focus.Y;
1068 return Ok;
1071 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1072 BOOL *gamma)
1074 TRACE("(%p, %p)\n", grad, gamma);
1076 if(!grad || !gamma)
1077 return InvalidParameter;
1079 *gamma = grad->gamma;
1081 return Ok;
1084 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1085 INT *count)
1087 TRACE("(%p, %p)\n", grad, count);
1089 if(!grad || !count)
1090 return InvalidParameter;
1092 *count = grad->pathdata.Count;
1094 return Ok;
1097 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1099 GpRectF r;
1100 GpPath* path;
1101 GpStatus stat;
1103 TRACE("(%p, %p)\n", brush, rect);
1105 if(!brush || !rect)
1106 return InvalidParameter;
1108 stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
1109 brush->pathdata.Count, FillModeAlternate, &path);
1110 if(stat != Ok) return stat;
1112 stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
1113 if(stat != Ok){
1114 GdipDeletePath(path);
1115 return stat;
1118 memcpy(rect, &r, sizeof(GpRectF));
1120 GdipDeletePath(path);
1122 return Ok;
1125 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1127 GpRectF rectf;
1128 GpStatus stat;
1130 TRACE("(%p, %p)\n", brush, rect);
1132 if(!brush || !rect)
1133 return InvalidParameter;
1135 stat = GdipGetPathGradientRect(brush, &rectf);
1136 if(stat != Ok) return stat;
1138 rect->X = roundr(rectf.X);
1139 rect->Y = roundr(rectf.Y);
1140 rect->Width = roundr(rectf.Width);
1141 rect->Height = roundr(rectf.Height);
1143 return Ok;
1146 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1147 *grad, ARGB *argb, INT *count)
1149 static int calls;
1151 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
1152 return InvalidParameter;
1154 if(!(calls++))
1155 FIXME("not implemented\n");
1157 return NotImplemented;
1160 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1161 GpWrapMode *wrapmode)
1163 TRACE("(%p, %p)\n", brush, wrapmode);
1165 if(!brush || !wrapmode)
1166 return InvalidParameter;
1168 *wrapmode = brush->wrap;
1170 return Ok;
1173 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1175 TRACE("(%p, %p)\n", sf, argb);
1177 if(!sf || !argb)
1178 return InvalidParameter;
1180 *argb = sf->color;
1182 return Ok;
1185 /******************************************************************************
1186 * GdipGetTextureTransform [GDIPLUS.@]
1188 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1190 TRACE("(%p, %p)\n", brush, matrix);
1192 if(!brush || !matrix)
1193 return InvalidParameter;
1195 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1197 return Ok;
1200 /******************************************************************************
1201 * GdipGetTextureWrapMode [GDIPLUS.@]
1203 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1205 TRACE("(%p, %p)\n", brush, wrapmode);
1207 if(!brush || !wrapmode)
1208 return InvalidParameter;
1210 *wrapmode = brush->wrap;
1212 return Ok;
1215 /******************************************************************************
1216 * GdipMultiplyTextureTransform [GDIPLUS.@]
1218 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1219 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1221 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1223 if(!brush || !matrix)
1224 return InvalidParameter;
1226 return GdipMultiplyMatrix(brush->transform, matrix, order);
1229 /******************************************************************************
1230 * GdipResetTextureTransform [GDIPLUS.@]
1232 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1234 TRACE("(%p)\n", brush);
1236 if(!brush)
1237 return InvalidParameter;
1239 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1242 /******************************************************************************
1243 * GdipScaleTextureTransform [GDIPLUS.@]
1245 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1246 REAL sx, REAL sy, GpMatrixOrder order)
1248 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1250 if(!brush)
1251 return InvalidParameter;
1253 return GdipScaleMatrix(brush->transform, sx, sy, order);
1256 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1257 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1259 REAL *new_blendfac, *new_blendpos;
1261 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1263 if(!brush || !factors || !positions || count <= 0 ||
1264 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1265 return InvalidParameter;
1267 new_blendfac = GdipAlloc(count * sizeof(REAL));
1268 new_blendpos = GdipAlloc(count * sizeof(REAL));
1270 if (!new_blendfac || !new_blendpos)
1272 GdipFree(new_blendfac);
1273 GdipFree(new_blendpos);
1274 return OutOfMemory;
1277 memcpy(new_blendfac, factors, count * sizeof(REAL));
1278 memcpy(new_blendpos, positions, count * sizeof(REAL));
1280 GdipFree(brush->blendfac);
1281 GdipFree(brush->blendpos);
1283 brush->blendcount = count;
1284 brush->blendfac = new_blendfac;
1285 brush->blendpos = new_blendpos;
1287 return Ok;
1290 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1291 REAL *positions, INT count)
1293 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1295 if (!brush || !factors || !positions || count <= 0)
1296 return InvalidParameter;
1298 if (count < brush->blendcount)
1299 return InsufficientBuffer;
1301 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1302 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1304 return Ok;
1307 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1309 TRACE("(%p, %p)\n", brush, count);
1311 if (!brush || !count)
1312 return InvalidParameter;
1314 *count = brush->blendcount;
1316 return Ok;
1319 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1320 BOOL usegamma)
1322 TRACE("(%p, %d)\n", line, usegamma);
1324 if(!line)
1325 return InvalidParameter;
1327 line->gamma = usegamma;
1329 return Ok;
1332 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1333 REAL scale)
1335 REAL factors[33];
1336 REAL positions[33];
1337 int num_points = 0;
1338 int i;
1339 const int precision = 16;
1340 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1341 REAL min_erf;
1342 REAL scale_erf;
1344 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1346 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1347 return InvalidParameter;
1349 /* we want 2 standard deviations */
1350 erf_range = 2.0 / sqrt(2);
1352 /* calculate the constants we need to normalize the error function to be
1353 between 0.0 and scale over the range we need */
1354 min_erf = erf(-erf_range);
1355 scale_erf = scale / (-2.0 * min_erf);
1357 if (focus != 0.0)
1359 positions[0] = 0.0;
1360 factors[0] = 0.0;
1361 for (i=1; i<precision; i++)
1363 positions[i] = focus * i / precision;
1364 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1366 num_points += precision;
1369 positions[num_points] = focus;
1370 factors[num_points] = scale;
1371 num_points += 1;
1373 if (focus != 1.0)
1375 for (i=1; i<precision; i++)
1377 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1378 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1380 num_points += precision;
1381 positions[num_points-1] = 1.0;
1382 factors[num_points-1] = 0.0;
1385 return GdipSetLineBlend(line, factors, positions, num_points);
1388 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1389 GpWrapMode wrap)
1391 TRACE("(%p, %d)\n", line, wrap);
1393 if(!line || wrap == WrapModeClamp)
1394 return InvalidParameter;
1396 line->wrap = wrap;
1398 return Ok;
1401 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1402 GDIPCONST REAL *pos, INT count)
1404 static int calls;
1406 if(!(calls++))
1407 FIXME("not implemented\n");
1409 return NotImplemented;
1412 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1413 GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1415 FIXME("(%p,%p,%p,%i): stub\n", brush, blend, pos, count);
1416 return NotImplemented;
1419 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1420 ARGB argb)
1422 TRACE("(%p, %x)\n", grad, argb);
1424 if(!grad)
1425 return InvalidParameter;
1427 grad->centercolor = argb;
1428 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1430 DeleteObject(grad->brush.gdibrush);
1431 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1433 return Ok;
1436 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1437 GpPointF *point)
1439 TRACE("(%p, %p)\n", grad, point);
1441 if(!grad || !point)
1442 return InvalidParameter;
1444 grad->center.X = point->X;
1445 grad->center.Y = point->Y;
1447 return Ok;
1450 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1451 GpPoint *point)
1453 GpPointF ptf;
1455 TRACE("(%p, %p)\n", grad, point);
1457 if(!point)
1458 return InvalidParameter;
1460 ptf.X = (REAL)point->X;
1461 ptf.Y = (REAL)point->Y;
1463 return GdipSetPathGradientCenterPoint(grad,&ptf);
1466 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1467 REAL x, REAL y)
1469 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1471 if(!grad)
1472 return InvalidParameter;
1474 grad->focus.X = x;
1475 grad->focus.Y = y;
1477 return Ok;
1480 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1481 BOOL gamma)
1483 TRACE("(%p, %d)\n", grad, gamma);
1485 if(!grad)
1486 return InvalidParameter;
1488 grad->gamma = gamma;
1490 return Ok;
1493 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1494 REAL focus, REAL scale)
1496 static int calls;
1498 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1499 return InvalidParameter;
1501 if(!(calls++))
1502 FIXME("not implemented\n");
1504 return NotImplemented;
1507 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1508 *grad, ARGB *argb, INT *count)
1510 static int calls;
1512 if(!grad || !argb || !count || (*count <= 0) ||
1513 (*count > grad->pathdata.Count))
1514 return InvalidParameter;
1516 if(!(calls++))
1517 FIXME("not implemented\n");
1519 return NotImplemented;
1522 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1523 GpWrapMode wrap)
1525 TRACE("(%p, %d)\n", grad, wrap);
1527 if(!grad)
1528 return InvalidParameter;
1530 grad->wrap = wrap;
1532 return Ok;
1535 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1537 TRACE("(%p, %x)\n", sf, argb);
1539 if(!sf)
1540 return InvalidParameter;
1542 sf->color = argb;
1543 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1545 DeleteObject(sf->brush.gdibrush);
1546 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1548 return Ok;
1551 /******************************************************************************
1552 * GdipSetTextureTransform [GDIPLUS.@]
1554 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1555 GDIPCONST GpMatrix *matrix)
1557 TRACE("(%p, %p)\n", texture, matrix);
1559 if(!texture || !matrix)
1560 return InvalidParameter;
1562 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1564 return Ok;
1567 /******************************************************************************
1568 * GdipSetTextureWrapMode [GDIPLUS.@]
1570 * WrapMode not used, only stored
1572 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1574 TRACE("(%p, %d)\n", brush, wrapmode);
1576 if(!brush)
1577 return InvalidParameter;
1579 brush->wrap = wrapmode;
1581 return Ok;
1584 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1585 ARGB color2)
1587 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1589 if(!brush)
1590 return InvalidParameter;
1592 brush->startcolor = color1;
1593 brush->endcolor = color2;
1595 return Ok;
1598 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1600 TRACE("(%p, %p)\n", brush, colors);
1602 if(!brush || !colors)
1603 return InvalidParameter;
1605 colors[0] = brush->startcolor;
1606 colors[1] = brush->endcolor;
1608 return Ok;
1611 /******************************************************************************
1612 * GdipRotateTextureTransform [GDIPLUS.@]
1614 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1615 GpMatrixOrder order)
1617 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1619 if(!brush)
1620 return InvalidParameter;
1622 return GdipRotateMatrix(brush->transform, angle, order);
1625 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1626 REAL scale)
1628 REAL factors[3];
1629 REAL positions[3];
1630 int num_points = 0;
1632 TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1634 if (!brush) return InvalidParameter;
1636 if (focus != 0.0)
1638 factors[num_points] = 0.0;
1639 positions[num_points] = 0.0;
1640 num_points++;
1643 factors[num_points] = scale;
1644 positions[num_points] = focus;
1645 num_points++;
1647 if (focus != 1.0)
1649 factors[num_points] = 0.0;
1650 positions[num_points] = 1.0;
1651 num_points++;
1654 return GdipSetLineBlend(brush, factors, positions, num_points);
1657 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1658 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1660 ARGB *new_color;
1661 REAL *new_pos;
1662 TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1664 if (!brush || !blend || !positions || count < 2 ||
1665 positions[0] != 0.0f || positions[count-1] != 1.0f)
1667 return InvalidParameter;
1670 new_color = GdipAlloc(count * sizeof(ARGB));
1671 new_pos = GdipAlloc(count * sizeof(REAL));
1672 if (!new_color || !new_pos)
1674 GdipFree(new_color);
1675 GdipFree(new_pos);
1676 return OutOfMemory;
1679 memcpy(new_color, blend, sizeof(ARGB) * count);
1680 memcpy(new_pos, positions, sizeof(REAL) * count);
1682 GdipFree(brush->pblendcolor);
1683 GdipFree(brush->pblendpos);
1685 brush->pblendcolor = new_color;
1686 brush->pblendpos = new_pos;
1687 brush->pblendcount = count;
1689 return Ok;
1692 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1693 ARGB *blend, REAL* positions, INT count)
1695 if (!brush || !blend || !positions || count < 2)
1696 return InvalidParameter;
1698 if (brush->pblendcount == 0)
1699 return GenericError;
1701 if (count < brush->pblendcount)
1702 return InsufficientBuffer;
1704 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1705 memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1707 return Ok;
1710 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1711 INT *count)
1713 if (!brush || !count)
1714 return InvalidParameter;
1716 *count = brush->pblendcount;
1718 return Ok;
1721 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1723 static int calls;
1725 if(!(calls++))
1726 FIXME("not implemented\n");
1728 return NotImplemented;
1731 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1732 GDIPCONST GpMatrix *matrix)
1734 static int calls;
1736 if(!(calls++))
1737 FIXME("not implemented\n");
1739 return NotImplemented;
1742 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
1743 GpMatrixOrder order)
1745 static int calls;
1747 if(!(calls++))
1748 FIXME("not implemented\n");
1750 return NotImplemented;
1753 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1754 REAL dx, REAL dy, GpMatrixOrder order)
1756 FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1758 return NotImplemented;
1761 /******************************************************************************
1762 * GdipTranslateTextureTransform [GDIPLUS.@]
1764 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1765 GpMatrixOrder order)
1767 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1769 if(!brush)
1770 return InvalidParameter;
1772 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1775 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1777 TRACE("(%p, %p)\n", brush, rect);
1779 if(!brush || !rect)
1780 return InvalidParameter;
1782 *rect = brush->rect;
1784 return Ok;
1787 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1789 GpRectF rectF;
1790 GpStatus ret;
1792 TRACE("(%p, %p)\n", brush, rect);
1794 if(!rect)
1795 return InvalidParameter;
1797 ret = GdipGetLineRect(brush, &rectF);
1799 if(ret == Ok){
1800 rect->X = roundr(rectF.X);
1801 rect->Y = roundr(rectF.Y);
1802 rect->Width = roundr(rectF.Width);
1803 rect->Height = roundr(rectF.Height);
1806 return ret;
1809 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1810 REAL angle, GpMatrixOrder order)
1812 static int calls;
1814 if(!brush)
1815 return InvalidParameter;
1817 if(!(calls++))
1818 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1820 return NotImplemented;