server: Return the total length of the target in query_symlink.
[wine/multimedia.git] / dlls / gdiplus / brush.c
blobb399fce30324f80ac4f819e9623bfabe5edcc362
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:
64 GpHatch *hatch = (GpHatch*)brush;
66 return GdipCreateHatchBrush(hatch->hatchstyle, hatch->forecol, hatch->backcol, (GpHatch**)clone);
68 case BrushTypePathGradient:{
69 GpPathGradient *src, *dest;
70 INT count;
72 *clone = GdipAlloc(sizeof(GpPathGradient));
73 if (!*clone) return OutOfMemory;
75 src = (GpPathGradient*) brush,
76 dest = (GpPathGradient*) *clone;
77 count = src->pathdata.Count;
79 memcpy(dest, src, sizeof(GpPathGradient));
81 dest->pathdata.Count = count;
82 dest->pathdata.Points = GdipAlloc(count * sizeof(PointF));
83 dest->pathdata.Types = GdipAlloc(count);
85 if(!dest->pathdata.Points || !dest->pathdata.Types){
86 GdipFree(dest->pathdata.Points);
87 GdipFree(dest->pathdata.Types);
88 GdipFree(dest);
89 return OutOfMemory;
92 memcpy(dest->pathdata.Points, src->pathdata.Points, count * sizeof(PointF));
93 memcpy(dest->pathdata.Types, src->pathdata.Types, count);
95 /* blending */
96 count = src->blendcount;
97 dest->blendcount = count;
98 dest->blendfac = GdipAlloc(count * sizeof(REAL));
99 dest->blendpos = GdipAlloc(count * sizeof(REAL));
101 if(!dest->blendfac || !dest->blendpos){
102 GdipFree(dest->pathdata.Points);
103 GdipFree(dest->pathdata.Types);
104 GdipFree(dest->blendfac);
105 GdipFree(dest->blendpos);
106 GdipFree(dest);
107 return OutOfMemory;
110 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
111 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
113 break;
115 case BrushTypeLinearGradient:{
116 GpLineGradient *dest, *src;
117 INT count, pcount;
119 dest = GdipAlloc(sizeof(GpLineGradient));
120 if(!dest) return OutOfMemory;
122 src = (GpLineGradient*)brush;
124 memcpy(dest, src, sizeof(GpLineGradient));
126 dest->brush.gdibrush = CreateSolidBrush(dest->brush.lb.lbColor);
128 count = dest->blendcount;
129 dest->blendfac = GdipAlloc(count * sizeof(REAL));
130 dest->blendpos = GdipAlloc(count * sizeof(REAL));
131 pcount = dest->pblendcount;
132 if (pcount)
134 dest->pblendcolor = GdipAlloc(pcount * sizeof(ARGB));
135 dest->pblendpos = GdipAlloc(pcount * sizeof(REAL));
138 if (!dest->blendfac || !dest->blendpos ||
139 (pcount && (!dest->pblendcolor || !dest->pblendpos)))
141 GdipFree(dest->blendfac);
142 GdipFree(dest->blendpos);
143 GdipFree(dest->pblendcolor);
144 GdipFree(dest->pblendpos);
145 DeleteObject(dest->brush.gdibrush);
146 GdipFree(dest);
147 return OutOfMemory;
150 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
151 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
153 if (pcount)
155 memcpy(dest->pblendcolor, src->pblendcolor, pcount * sizeof(ARGB));
156 memcpy(dest->pblendpos, src->pblendpos, pcount * sizeof(REAL));
159 *clone = &dest->brush;
160 break;
162 case BrushTypeTextureFill:
164 GpStatus stat;
165 GpTexture *texture = (GpTexture*)brush;
166 GpTexture *new_texture;
168 stat = GdipCreateTexture(texture->image, texture->wrap, &new_texture);
170 if (stat == Ok)
172 memcpy(new_texture->transform, texture->transform, sizeof(GpMatrix));
173 *clone = (GpBrush*)new_texture;
175 else
176 *clone = NULL;
178 return stat;
180 default:
181 ERR("not implemented for brush type %d\n", brush->bt);
182 return NotImplemented;
185 TRACE("<-- %p\n", *clone);
186 return Ok;
189 static const char HatchBrushes[][8] = {
190 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HatchStyleHorizontal */
191 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleVertical */
192 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HatchStyleForwardDiagonal */
193 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HatchStyleBackwardDiagonal */
194 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleCross */
195 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }, /* HatchStyleDiagonalCross */
196 { 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x80 }, /* HatchStyle05Percent */
197 { 0x00, 0x02, 0x00, 0x88, 0x00, 0x20, 0x00, 0x88 }, /* HatchStyle10Percent */
198 { 0x00, 0x22, 0x00, 0xcc, 0x00, 0x22, 0x00, 0xcc }, /* HatchStyle20Percent */
199 { 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc }, /* HatchStyle25Percent */
200 { 0x00, 0xcc, 0x04, 0xcc, 0x00, 0xcc, 0x40, 0xcc }, /* HatchStyle30Percent */
201 { 0x44, 0xcc, 0x22, 0xcc, 0x44, 0xcc, 0x22, 0xcc }, /* HatchStyle40Percent */
202 { 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc }, /* HatchStyle50Percent */
203 { 0x55, 0xcd, 0x55, 0xee, 0x55, 0xdc, 0x55, 0xee }, /* HatchStyle60Percent */
204 { 0x55, 0xdd, 0x55, 0xff, 0x55, 0xdd, 0x55, 0xff }, /* HatchStyle70Percent */
205 { 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff }, /* HatchStyle75Percent */
206 { 0x55, 0xff, 0x59, 0xff, 0x55, 0xff, 0x99, 0xff }, /* HatchStyle80Percent */
207 { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xfd, 0xff }, /* HatchStyle90Percent */
208 { 0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88 }, /* HatchStyleLightDownwardDiagonal */
209 { 0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11 }, /* HatchStyleLightUpwardDiagonal */
210 { 0x99, 0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc }, /* HatchStyleDarkDownwardDiagonal */
211 { 0xcc, 0x66, 0x33, 0x99, 0xcc, 0x66, 0x33, 0x99 }, /* HatchStyleDarkUpwardDiagonal */
212 { 0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0 }, /* HatchStyleWideDownwardDiagonal */
213 { 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x83, 0xc1 }, /* HatchStyleWideUpwardDiagonal */
214 { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 }, /* HatchStyleLightVertical */
215 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff }, /* HatchStyleLightHorizontal */
216 { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }, /* HatchStyleNarrowVertical */
217 { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, /* HatchStyleNarrowHorizontal */
218 { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }, /* HatchStyleDarkVertical */
219 { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff }, /* HatchStyleDarkHorizontal */
222 /******************************************************************************
223 * GdipCreateHatchBrush [GDIPLUS.@]
225 GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle hatchstyle, ARGB forecol, ARGB backcol, GpHatch **brush)
227 COLORREF fgcol = ARGB2COLORREF(forecol);
228 GpStatus stat = Ok;
230 TRACE("(%d, %d, %d, %p)\n", hatchstyle, forecol, backcol, brush);
232 if(!brush) return InvalidParameter;
234 *brush = GdipAlloc(sizeof(GpHatch));
235 if (!*brush) return OutOfMemory;
237 if (hatchstyle < sizeof(HatchBrushes) / sizeof(HatchBrushes[0]))
239 HBITMAP hbmp;
240 HDC hdc;
241 BITMAPINFOHEADER bmih;
242 DWORD* bits;
243 int x, y;
245 hdc = CreateCompatibleDC(0);
247 if (hdc)
249 bmih.biSize = sizeof(bmih);
250 bmih.biWidth = 8;
251 bmih.biHeight = 8;
252 bmih.biPlanes = 1;
253 bmih.biBitCount = 32;
254 bmih.biCompression = BI_RGB;
255 bmih.biSizeImage = 0;
257 hbmp = CreateDIBSection(hdc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
259 if (hbmp)
261 for (y=0; y<8; y++)
262 for (x=0; x<8; x++)
263 if ((HatchBrushes[hatchstyle][y] & (0x80 >> x)) != 0)
264 bits[y*8+x] = forecol;
265 else
266 bits[y*8+x] = backcol;
268 else
269 stat = GenericError;
271 DeleteDC(hdc);
273 else
274 stat = GenericError;
276 if (stat == Ok)
278 (*brush)->brush.lb.lbStyle = BS_PATTERN;
279 (*brush)->brush.lb.lbColor = 0;
280 (*brush)->brush.lb.lbHatch = (ULONG_PTR)hbmp;
281 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
283 DeleteObject(hbmp);
286 else
288 FIXME("Unimplemented hatch style %d\n", hatchstyle);
290 (*brush)->brush.lb.lbStyle = BS_SOLID;
291 (*brush)->brush.lb.lbColor = fgcol;
292 (*brush)->brush.lb.lbHatch = 0;
293 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
296 if (stat == Ok)
298 (*brush)->brush.bt = BrushTypeHatchFill;
299 (*brush)->forecol = forecol;
300 (*brush)->backcol = backcol;
301 (*brush)->hatchstyle = hatchstyle;
302 TRACE("<-- %p\n", *brush);
304 else
306 GdipFree(*brush);
307 *brush = NULL;
310 return stat;
313 /******************************************************************************
314 * GdipCreateLineBrush [GDIPLUS.@]
316 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
317 GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
318 GpWrapMode wrap, GpLineGradient **line)
320 COLORREF col = ARGB2COLORREF(startcolor);
322 TRACE("(%s, %s, %x, %x, %d, %p)\n", debugstr_pointf(startpoint),
323 debugstr_pointf(endpoint), startcolor, endcolor, wrap, line);
325 if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
326 return InvalidParameter;
328 *line = GdipAlloc(sizeof(GpLineGradient));
329 if(!*line) return OutOfMemory;
331 (*line)->brush.lb.lbStyle = BS_SOLID;
332 (*line)->brush.lb.lbColor = col;
333 (*line)->brush.lb.lbHatch = 0;
334 (*line)->brush.gdibrush = CreateSolidBrush(col);
335 (*line)->brush.bt = BrushTypeLinearGradient;
337 (*line)->startpoint.X = startpoint->X;
338 (*line)->startpoint.Y = startpoint->Y;
339 (*line)->endpoint.X = endpoint->X;
340 (*line)->endpoint.Y = endpoint->Y;
341 (*line)->startcolor = startcolor;
342 (*line)->endcolor = endcolor;
343 (*line)->wrap = wrap;
344 (*line)->gamma = FALSE;
346 (*line)->rect.X = (startpoint->X < endpoint->X ? startpoint->X: endpoint->X);
347 (*line)->rect.Y = (startpoint->Y < endpoint->Y ? startpoint->Y: endpoint->Y);
348 (*line)->rect.Width = fabs(startpoint->X - endpoint->X);
349 (*line)->rect.Height = fabs(startpoint->Y - endpoint->Y);
351 if ((*line)->rect.Width == 0)
353 (*line)->rect.X -= (*line)->rect.Height / 2.0f;
354 (*line)->rect.Width = (*line)->rect.Height;
356 else if ((*line)->rect.Height == 0)
358 (*line)->rect.Y -= (*line)->rect.Width / 2.0f;
359 (*line)->rect.Height = (*line)->rect.Width;
362 (*line)->blendcount = 1;
363 (*line)->blendfac = GdipAlloc(sizeof(REAL));
364 (*line)->blendpos = GdipAlloc(sizeof(REAL));
366 if (!(*line)->blendfac || !(*line)->blendpos)
368 GdipFree((*line)->blendfac);
369 GdipFree((*line)->blendpos);
370 DeleteObject((*line)->brush.gdibrush);
371 GdipFree(*line);
372 *line = NULL;
373 return OutOfMemory;
376 (*line)->blendfac[0] = 1.0f;
377 (*line)->blendpos[0] = 1.0f;
379 (*line)->pblendcolor = NULL;
380 (*line)->pblendpos = NULL;
381 (*line)->pblendcount = 0;
383 TRACE("<-- %p\n", *line);
385 return Ok;
388 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
389 GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
390 GpWrapMode wrap, GpLineGradient **line)
392 GpPointF stF;
393 GpPointF endF;
395 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
396 startcolor, endcolor, wrap, line);
398 if(!startpoint || !endpoint)
399 return InvalidParameter;
401 stF.X = (REAL)startpoint->X;
402 stF.Y = (REAL)startpoint->Y;
403 endF.X = (REAL)endpoint->X;
404 endF.X = (REAL)endpoint->Y;
406 return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
409 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
410 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
411 GpLineGradient **line)
413 GpPointF start, end;
414 GpStatus stat;
416 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
417 wrap, line);
419 if(!line || !rect)
420 return InvalidParameter;
422 switch (mode)
424 case LinearGradientModeHorizontal:
425 start.X = rect->X;
426 start.Y = rect->Y;
427 end.X = rect->X + rect->Width;
428 end.Y = rect->Y;
429 break;
430 case LinearGradientModeVertical:
431 start.X = rect->X;
432 start.Y = rect->Y;
433 end.X = rect->X;
434 end.Y = rect->Y + rect->Height;
435 break;
436 case LinearGradientModeForwardDiagonal:
437 start.X = rect->X;
438 start.Y = rect->Y;
439 end.X = rect->X + rect->Width;
440 end.Y = rect->Y + rect->Height;
441 break;
442 case LinearGradientModeBackwardDiagonal:
443 start.X = rect->X + rect->Width;
444 start.Y = rect->Y;
445 end.X = rect->X;
446 end.Y = rect->Y + rect->Height;
447 break;
448 default:
449 return InvalidParameter;
452 stat = GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
454 if (stat == Ok)
455 (*line)->rect = *rect;
457 return stat;
460 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
461 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
462 GpLineGradient **line)
464 GpRectF rectF;
466 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
467 wrap, line);
469 rectF.X = (REAL) rect->X;
470 rectF.Y = (REAL) rect->Y;
471 rectF.Width = (REAL) rect->Width;
472 rectF.Height = (REAL) rect->Height;
474 return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
477 /******************************************************************************
478 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
480 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
481 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
482 GpLineGradient **line)
484 GpStatus stat;
485 LinearGradientMode mode;
486 REAL width, height, exofs, eyofs;
487 REAL sin_angle, cos_angle, sin_cos_angle;
489 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
490 wrap, line);
492 sin_angle = sinf(deg2rad(angle));
493 cos_angle = cosf(deg2rad(angle));
494 sin_cos_angle = sin_angle * cos_angle;
496 if (isAngleScalable)
498 width = height = 1.0;
500 else
502 width = rect->Width;
503 height = rect->Height;
506 if (sin_cos_angle >= 0)
507 mode = LinearGradientModeForwardDiagonal;
508 else
509 mode = LinearGradientModeBackwardDiagonal;
511 stat = GdipCreateLineBrushFromRect(rect, startcolor, endcolor, mode, wrap, line);
513 if (stat == Ok)
515 if (sin_cos_angle >= 0)
517 exofs = width * sin_cos_angle + height * cos_angle * cos_angle;
518 eyofs = width * sin_angle * sin_angle + height * sin_cos_angle;
520 else
522 exofs = width * sin_angle * sin_angle + height * sin_cos_angle;
523 eyofs = -width * sin_cos_angle + height * sin_angle * sin_angle;
526 if (isAngleScalable)
528 exofs = exofs * rect->Width;
529 eyofs = eyofs * rect->Height;
532 if (sin_angle >= 0)
534 (*line)->endpoint.X = rect->X + exofs;
535 (*line)->endpoint.Y = rect->Y + eyofs;
537 else
539 (*line)->endpoint.X = (*line)->startpoint.X;
540 (*line)->endpoint.Y = (*line)->startpoint.Y;
541 (*line)->startpoint.X = rect->X + exofs;
542 (*line)->startpoint.Y = rect->Y + eyofs;
546 return stat;
549 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
550 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
551 GpLineGradient **line)
553 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
554 wrap, line);
556 return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
557 wrap, line);
560 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
561 INT count, GpWrapMode wrap, GpPathGradient **grad)
563 COLORREF col = ARGB2COLORREF(0xffffffff);
565 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
567 if(!points || !grad)
568 return InvalidParameter;
570 if(count <= 0)
571 return OutOfMemory;
573 *grad = GdipAlloc(sizeof(GpPathGradient));
574 if (!*grad) return OutOfMemory;
576 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
577 (*grad)->blendpos = GdipAlloc(sizeof(REAL));
578 if(!(*grad)->blendfac || !(*grad)->blendpos){
579 GdipFree((*grad)->blendfac);
580 GdipFree((*grad)->blendpos);
581 GdipFree(*grad);
582 return OutOfMemory;
584 (*grad)->blendfac[0] = 1.0;
585 (*grad)->blendpos[0] = 1.0;
586 (*grad)->blendcount = 1;
588 (*grad)->pathdata.Count = count;
589 (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
590 (*grad)->pathdata.Types = GdipAlloc(count);
592 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
593 GdipFree((*grad)->pathdata.Points);
594 GdipFree((*grad)->pathdata.Types);
595 GdipFree(*grad);
596 return OutOfMemory;
599 memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
600 memset((*grad)->pathdata.Types, PathPointTypeLine, count);
602 (*grad)->brush.lb.lbStyle = BS_SOLID;
603 (*grad)->brush.lb.lbColor = col;
604 (*grad)->brush.lb.lbHatch = 0;
606 (*grad)->brush.gdibrush = CreateSolidBrush(col);
607 (*grad)->brush.bt = BrushTypePathGradient;
608 (*grad)->centercolor = 0xffffffff;
609 (*grad)->wrap = wrap;
610 (*grad)->gamma = FALSE;
611 (*grad)->center.X = 0.0;
612 (*grad)->center.Y = 0.0;
613 (*grad)->focus.X = 0.0;
614 (*grad)->focus.Y = 0.0;
616 TRACE("<-- %p\n", *grad);
618 return Ok;
621 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
622 INT count, GpWrapMode wrap, GpPathGradient **grad)
624 GpPointF *pointsF;
625 GpStatus ret;
626 INT i;
628 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
630 if(!points || !grad)
631 return InvalidParameter;
633 if(count <= 0)
634 return OutOfMemory;
636 pointsF = GdipAlloc(sizeof(GpPointF) * count);
637 if(!pointsF)
638 return OutOfMemory;
640 for(i = 0; i < count; i++){
641 pointsF[i].X = (REAL)points[i].X;
642 pointsF[i].Y = (REAL)points[i].Y;
645 ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
646 GdipFree(pointsF);
648 return ret;
651 /******************************************************************************
652 * GdipCreatePathGradientFromPath [GDIPLUS.@]
654 * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
656 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
657 GpPathGradient **grad)
659 COLORREF col = ARGB2COLORREF(0xffffffff);
661 TRACE("(%p, %p)\n", path, grad);
663 if(!path || !grad)
664 return InvalidParameter;
666 *grad = GdipAlloc(sizeof(GpPathGradient));
667 if (!*grad) return OutOfMemory;
669 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
670 (*grad)->blendpos = GdipAlloc(sizeof(REAL));
671 if(!(*grad)->blendfac || !(*grad)->blendpos){
672 GdipFree((*grad)->blendfac);
673 GdipFree((*grad)->blendpos);
674 GdipFree(*grad);
675 return OutOfMemory;
677 (*grad)->blendfac[0] = 1.0;
678 (*grad)->blendpos[0] = 1.0;
679 (*grad)->blendcount = 1;
681 (*grad)->pathdata.Count = path->pathdata.Count;
682 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
683 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
685 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
686 GdipFree((*grad)->pathdata.Points);
687 GdipFree((*grad)->pathdata.Types);
688 GdipFree(*grad);
689 return OutOfMemory;
692 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
693 path->pathdata.Count * sizeof(PointF));
694 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
696 (*grad)->brush.lb.lbStyle = BS_SOLID;
697 (*grad)->brush.lb.lbColor = col;
698 (*grad)->brush.lb.lbHatch = 0;
700 (*grad)->brush.gdibrush = CreateSolidBrush(col);
701 (*grad)->brush.bt = BrushTypePathGradient;
702 (*grad)->centercolor = 0xffffffff;
703 (*grad)->wrap = WrapModeClamp;
704 (*grad)->gamma = FALSE;
705 /* FIXME: this should be set to the "centroid" of the path by default */
706 (*grad)->center.X = 0.0;
707 (*grad)->center.Y = 0.0;
708 (*grad)->focus.X = 0.0;
709 (*grad)->focus.Y = 0.0;
711 TRACE("<-- %p\n", *grad);
713 return Ok;
716 /******************************************************************************
717 * GdipCreateSolidFill [GDIPLUS.@]
719 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
721 COLORREF col = ARGB2COLORREF(color);
723 TRACE("(%x, %p)\n", color, sf);
725 if(!sf) return InvalidParameter;
727 *sf = GdipAlloc(sizeof(GpSolidFill));
728 if (!*sf) return OutOfMemory;
730 (*sf)->brush.lb.lbStyle = BS_SOLID;
731 (*sf)->brush.lb.lbColor = col;
732 (*sf)->brush.lb.lbHatch = 0;
734 (*sf)->brush.gdibrush = CreateSolidBrush(col);
735 (*sf)->brush.bt = BrushTypeSolidColor;
736 (*sf)->color = color;
737 (*sf)->bmp = ARGB2BMP(color);
739 TRACE("<-- %p\n", *sf);
741 return Ok;
744 /******************************************************************************
745 * GdipCreateTexture [GDIPLUS.@]
747 * PARAMS
748 * image [I] image to use
749 * wrapmode [I] optional
750 * texture [O] pointer to the resulting texturebrush
752 * RETURNS
753 * SUCCESS: Ok
754 * FAILURE: element of GpStatus
756 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
757 GpTexture **texture)
759 UINT width, height;
760 GpImageAttributes attributes;
761 GpStatus stat;
763 TRACE("%p, %d %p\n", image, wrapmode, texture);
765 if (!(image && texture))
766 return InvalidParameter;
768 stat = GdipGetImageWidth(image, &width);
769 if (stat != Ok) return stat;
770 stat = GdipGetImageHeight(image, &height);
771 if (stat != Ok) return stat;
772 attributes.wrap = wrapmode;
774 return GdipCreateTextureIA(image, &attributes, 0, 0, width, height,
775 texture);
778 /******************************************************************************
779 * GdipCreateTexture2 [GDIPLUS.@]
781 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
782 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
784 GpImageAttributes attributes;
786 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
787 x, y, width, height, texture);
789 attributes.wrap = wrapmode;
790 return GdipCreateTextureIA(image, &attributes, x, y, width, height,
791 texture);
794 /******************************************************************************
795 * GdipCreateTextureIA [GDIPLUS.@]
797 * FIXME: imageattr ignored
799 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
800 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
801 REAL height, GpTexture **texture)
803 HBITMAP hbm=NULL;
804 GpStatus status;
805 GpImage *new_image=NULL;
807 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
808 texture);
810 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
811 return InvalidParameter;
813 *texture = NULL;
815 if(image->type != ImageTypeBitmap){
816 FIXME("not implemented for image type %d\n", image->type);
817 return NotImplemented;
820 status = GdipCloneBitmapArea(x, y, width, height, PixelFormatDontCare, (GpBitmap*)image, (GpBitmap**)&new_image);
821 if (status != Ok)
822 return status;
824 status = GdipCreateHBITMAPFromBitmap((GpBitmap*)new_image, &hbm, 0);
825 if(!hbm)
827 status = GenericError;
828 goto exit;
831 *texture = GdipAlloc(sizeof(GpTexture));
832 if (!*texture){
833 status = OutOfMemory;
834 goto exit;
837 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
838 goto exit;
841 (*texture)->brush.lb.lbStyle = BS_PATTERN;
842 (*texture)->brush.lb.lbColor = 0;
843 (*texture)->brush.lb.lbHatch = (ULONG_PTR)hbm;
845 (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
846 (*texture)->brush.bt = BrushTypeTextureFill;
847 if (imageattr)
848 (*texture)->wrap = imageattr->wrap;
849 else
850 (*texture)->wrap = WrapModeTile;
851 (*texture)->image = new_image;
853 exit:
854 if (status == Ok)
856 TRACE("<-- %p\n", *texture);
858 else
860 if (*texture)
862 GdipDeleteMatrix((*texture)->transform);
863 GdipFree(*texture);
864 *texture = NULL;
866 GdipDisposeImage(new_image);
867 TRACE("<-- error %u\n", status);
870 DeleteObject(hbm);
872 return status;
875 /******************************************************************************
876 * GdipCreateTextureIAI [GDIPLUS.@]
878 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
879 INT x, INT y, INT width, INT height, GpTexture **texture)
881 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
882 texture);
884 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
887 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
888 INT x, INT y, INT width, INT height, GpTexture **texture)
890 GpImageAttributes imageattr;
892 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
893 texture);
895 imageattr.wrap = wrapmode;
897 return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
900 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
902 TRACE("(%p, %p)\n", brush, type);
904 if(!brush || !type) return InvalidParameter;
906 *type = brush->bt;
908 return Ok;
911 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
913 TRACE("(%p, %p)\n", brush, backcol);
915 if(!brush || !backcol) return InvalidParameter;
917 *backcol = brush->backcol;
919 return Ok;
922 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
924 TRACE("(%p, %p)\n", brush, forecol);
926 if(!brush || !forecol) return InvalidParameter;
928 *forecol = brush->forecol;
930 return Ok;
933 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
935 TRACE("(%p, %p)\n", brush, hatchstyle);
937 if(!brush || !hatchstyle) return InvalidParameter;
939 *hatchstyle = brush->hatchstyle;
941 return Ok;
944 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
946 TRACE("(%p)\n", brush);
948 if(!brush) return InvalidParameter;
950 switch(brush->bt)
952 case BrushTypePathGradient:
953 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
954 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
955 GdipFree(((GpPathGradient*) brush)->blendfac);
956 GdipFree(((GpPathGradient*) brush)->blendpos);
957 break;
958 case BrushTypeSolidColor:
959 if (((GpSolidFill*)brush)->bmp)
960 DeleteObject(((GpSolidFill*)brush)->bmp);
961 break;
962 case BrushTypeLinearGradient:
963 GdipFree(((GpLineGradient*)brush)->blendfac);
964 GdipFree(((GpLineGradient*)brush)->blendpos);
965 GdipFree(((GpLineGradient*)brush)->pblendcolor);
966 GdipFree(((GpLineGradient*)brush)->pblendpos);
967 break;
968 case BrushTypeTextureFill:
969 GdipDeleteMatrix(((GpTexture*)brush)->transform);
970 GdipDisposeImage(((GpTexture*)brush)->image);
971 break;
972 default:
973 break;
976 DeleteObject(brush->gdibrush);
977 GdipFree(brush);
979 return Ok;
982 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
983 BOOL *usinggamma)
985 TRACE("(%p, %p)\n", line, usinggamma);
987 if(!line || !usinggamma)
988 return InvalidParameter;
990 *usinggamma = line->gamma;
992 return Ok;
995 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
997 TRACE("(%p, %p)\n", brush, wrapmode);
999 if(!brush || !wrapmode)
1000 return InvalidParameter;
1002 *wrapmode = brush->wrap;
1004 return Ok;
1007 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
1008 REAL *positions, INT count)
1010 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
1012 if(!brush || !blend || !positions || count <= 0)
1013 return InvalidParameter;
1015 if(count < brush->blendcount)
1016 return InsufficientBuffer;
1018 memcpy(blend, brush->blendfac, count*sizeof(REAL));
1019 if(brush->blendcount > 1){
1020 memcpy(positions, brush->blendpos, count*sizeof(REAL));
1023 return Ok;
1026 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
1028 TRACE("(%p, %p)\n", brush, count);
1030 if(!brush || !count)
1031 return InvalidParameter;
1033 *count = brush->blendcount;
1035 return Ok;
1038 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
1039 GpPointF *point)
1041 TRACE("(%p, %p)\n", grad, point);
1043 if(!grad || !point)
1044 return InvalidParameter;
1046 point->X = grad->center.X;
1047 point->Y = grad->center.Y;
1049 return Ok;
1052 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
1053 GpPoint *point)
1055 GpStatus ret;
1056 GpPointF ptf;
1058 TRACE("(%p, %p)\n", grad, point);
1060 if(!point)
1061 return InvalidParameter;
1063 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
1065 if(ret == Ok){
1066 point->X = roundr(ptf.X);
1067 point->Y = roundr(ptf.Y);
1070 return ret;
1073 GpStatus WINGDIPAPI GdipGetPathGradientCenterColor(GpPathGradient *grad,
1074 ARGB *colors)
1076 static int calls;
1078 TRACE("(%p,%p)\n", grad, colors);
1080 if(!(calls++))
1081 FIXME("not implemented\n");
1083 return NotImplemented;
1086 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
1087 REAL *x, REAL *y)
1089 TRACE("(%p, %p, %p)\n", grad, x, y);
1091 if(!grad || !x || !y)
1092 return InvalidParameter;
1094 *x = grad->focus.X;
1095 *y = grad->focus.Y;
1097 return Ok;
1100 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1101 BOOL *gamma)
1103 TRACE("(%p, %p)\n", grad, gamma);
1105 if(!grad || !gamma)
1106 return InvalidParameter;
1108 *gamma = grad->gamma;
1110 return Ok;
1113 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1114 INT *count)
1116 TRACE("(%p, %p)\n", grad, count);
1118 if(!grad || !count)
1119 return InvalidParameter;
1121 *count = grad->pathdata.Count;
1123 return Ok;
1126 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1128 GpRectF r;
1129 GpPath* path;
1130 GpStatus stat;
1132 TRACE("(%p, %p)\n", brush, rect);
1134 if(!brush || !rect)
1135 return InvalidParameter;
1137 stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
1138 brush->pathdata.Count, FillModeAlternate, &path);
1139 if(stat != Ok) return stat;
1141 stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
1142 if(stat != Ok){
1143 GdipDeletePath(path);
1144 return stat;
1147 memcpy(rect, &r, sizeof(GpRectF));
1149 GdipDeletePath(path);
1151 return Ok;
1154 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1156 GpRectF rectf;
1157 GpStatus stat;
1159 TRACE("(%p, %p)\n", brush, rect);
1161 if(!brush || !rect)
1162 return InvalidParameter;
1164 stat = GdipGetPathGradientRect(brush, &rectf);
1165 if(stat != Ok) return stat;
1167 rect->X = roundr(rectf.X);
1168 rect->Y = roundr(rectf.Y);
1169 rect->Width = roundr(rectf.Width);
1170 rect->Height = roundr(rectf.Height);
1172 return Ok;
1175 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1176 *grad, ARGB *argb, INT *count)
1178 static int calls;
1180 TRACE("(%p,%p,%p)\n", grad, argb, count);
1182 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
1183 return InvalidParameter;
1185 if(!(calls++))
1186 FIXME("not implemented\n");
1188 return NotImplemented;
1191 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorCount(GpPathGradient *brush, INT *count)
1193 TRACE("(%p, %p)\n", brush, count);
1195 if (!brush || !count)
1196 return InvalidParameter;
1198 return NotImplemented;
1201 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1202 GpWrapMode *wrapmode)
1204 TRACE("(%p, %p)\n", brush, wrapmode);
1206 if(!brush || !wrapmode)
1207 return InvalidParameter;
1209 *wrapmode = brush->wrap;
1211 return Ok;
1214 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1216 TRACE("(%p, %p)\n", sf, argb);
1218 if(!sf || !argb)
1219 return InvalidParameter;
1221 *argb = sf->color;
1223 return Ok;
1226 /******************************************************************************
1227 * GdipGetTextureImage [GDIPLUS.@]
1229 GpStatus WINGDIPAPI GdipGetTextureImage(GpTexture *brush, GpImage **image)
1231 TRACE("(%p, %p)\n", brush, image);
1233 if(!brush || !image)
1234 return InvalidParameter;
1236 return GdipCloneImage(brush->image, image);
1239 /******************************************************************************
1240 * GdipGetTextureTransform [GDIPLUS.@]
1242 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1244 TRACE("(%p, %p)\n", brush, matrix);
1246 if(!brush || !matrix)
1247 return InvalidParameter;
1249 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1251 return Ok;
1254 /******************************************************************************
1255 * GdipGetTextureWrapMode [GDIPLUS.@]
1257 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1259 TRACE("(%p, %p)\n", brush, wrapmode);
1261 if(!brush || !wrapmode)
1262 return InvalidParameter;
1264 *wrapmode = brush->wrap;
1266 return Ok;
1269 /******************************************************************************
1270 * GdipMultiplyTextureTransform [GDIPLUS.@]
1272 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1273 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1275 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1277 if(!brush || !matrix)
1278 return InvalidParameter;
1280 return GdipMultiplyMatrix(brush->transform, matrix, order);
1283 /******************************************************************************
1284 * GdipResetTextureTransform [GDIPLUS.@]
1286 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1288 TRACE("(%p)\n", brush);
1290 if(!brush)
1291 return InvalidParameter;
1293 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1296 /******************************************************************************
1297 * GdipScaleTextureTransform [GDIPLUS.@]
1299 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1300 REAL sx, REAL sy, GpMatrixOrder order)
1302 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1304 if(!brush)
1305 return InvalidParameter;
1307 return GdipScaleMatrix(brush->transform, sx, sy, order);
1310 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1311 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1313 REAL *new_blendfac, *new_blendpos;
1315 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1317 if(!brush || !factors || !positions || count <= 0 ||
1318 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1319 return InvalidParameter;
1321 new_blendfac = GdipAlloc(count * sizeof(REAL));
1322 new_blendpos = GdipAlloc(count * sizeof(REAL));
1324 if (!new_blendfac || !new_blendpos)
1326 GdipFree(new_blendfac);
1327 GdipFree(new_blendpos);
1328 return OutOfMemory;
1331 memcpy(new_blendfac, factors, count * sizeof(REAL));
1332 memcpy(new_blendpos, positions, count * sizeof(REAL));
1334 GdipFree(brush->blendfac);
1335 GdipFree(brush->blendpos);
1337 brush->blendcount = count;
1338 brush->blendfac = new_blendfac;
1339 brush->blendpos = new_blendpos;
1341 return Ok;
1344 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1345 REAL *positions, INT count)
1347 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1349 if (!brush || !factors || !positions || count <= 0)
1350 return InvalidParameter;
1352 if (count < brush->blendcount)
1353 return InsufficientBuffer;
1355 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1356 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1358 return Ok;
1361 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1363 TRACE("(%p, %p)\n", brush, count);
1365 if (!brush || !count)
1366 return InvalidParameter;
1368 *count = brush->blendcount;
1370 return Ok;
1373 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1374 BOOL usegamma)
1376 TRACE("(%p, %d)\n", line, usegamma);
1378 if(!line)
1379 return InvalidParameter;
1381 line->gamma = usegamma;
1383 return Ok;
1386 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1387 REAL scale)
1389 REAL factors[33];
1390 REAL positions[33];
1391 int num_points = 0;
1392 int i;
1393 const int precision = 16;
1394 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1395 REAL min_erf;
1396 REAL scale_erf;
1398 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1400 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1401 return InvalidParameter;
1403 /* we want 2 standard deviations */
1404 erf_range = 2.0 / sqrt(2);
1406 /* calculate the constants we need to normalize the error function to be
1407 between 0.0 and scale over the range we need */
1408 min_erf = erf(-erf_range);
1409 scale_erf = scale / (-2.0 * min_erf);
1411 if (focus != 0.0)
1413 positions[0] = 0.0;
1414 factors[0] = 0.0;
1415 for (i=1; i<precision; i++)
1417 positions[i] = focus * i / precision;
1418 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1420 num_points += precision;
1423 positions[num_points] = focus;
1424 factors[num_points] = scale;
1425 num_points += 1;
1427 if (focus != 1.0)
1429 for (i=1; i<precision; i++)
1431 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1432 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1434 num_points += precision;
1435 positions[num_points-1] = 1.0;
1436 factors[num_points-1] = 0.0;
1439 return GdipSetLineBlend(line, factors, positions, num_points);
1442 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1443 GpWrapMode wrap)
1445 TRACE("(%p, %d)\n", line, wrap);
1447 if(!line || wrap == WrapModeClamp)
1448 return InvalidParameter;
1450 line->wrap = wrap;
1452 return Ok;
1455 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1456 GDIPCONST REAL *pos, INT count)
1458 static int calls;
1460 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1462 if(!(calls++))
1463 FIXME("not implemented\n");
1465 return NotImplemented;
1468 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1469 GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1471 FIXME("(%p,%p,%p,%i): stub\n", brush, blend, pos, count);
1472 return NotImplemented;
1475 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1476 ARGB argb)
1478 TRACE("(%p, %x)\n", grad, argb);
1480 if(!grad)
1481 return InvalidParameter;
1483 grad->centercolor = argb;
1484 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1486 DeleteObject(grad->brush.gdibrush);
1487 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1489 return Ok;
1492 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1493 GpPointF *point)
1495 TRACE("(%p, %s)\n", grad, debugstr_pointf(point));
1497 if(!grad || !point)
1498 return InvalidParameter;
1500 grad->center.X = point->X;
1501 grad->center.Y = point->Y;
1503 return Ok;
1506 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1507 GpPoint *point)
1509 GpPointF ptf;
1511 TRACE("(%p, %p)\n", grad, point);
1513 if(!point)
1514 return InvalidParameter;
1516 ptf.X = (REAL)point->X;
1517 ptf.Y = (REAL)point->Y;
1519 return GdipSetPathGradientCenterPoint(grad,&ptf);
1522 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1523 REAL x, REAL y)
1525 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1527 if(!grad)
1528 return InvalidParameter;
1530 grad->focus.X = x;
1531 grad->focus.Y = y;
1533 return Ok;
1536 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1537 BOOL gamma)
1539 TRACE("(%p, %d)\n", grad, gamma);
1541 if(!grad)
1542 return InvalidParameter;
1544 grad->gamma = gamma;
1546 return Ok;
1549 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1550 REAL focus, REAL scale)
1552 static int calls;
1554 TRACE("(%p,%0.2f,%0.2f)\n", grad, focus, scale);
1556 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1557 return InvalidParameter;
1559 if(!(calls++))
1560 FIXME("not implemented\n");
1562 return NotImplemented;
1565 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1566 *grad, GDIPCONST ARGB *argb, INT *count)
1568 static int calls;
1570 TRACE("(%p,%p,%p)\n", grad, argb, count);
1572 if(!grad || !argb || !count || (*count <= 0) ||
1573 (*count > grad->pathdata.Count))
1574 return InvalidParameter;
1576 if(!(calls++))
1577 FIXME("not implemented\n");
1579 return NotImplemented;
1582 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1583 GpWrapMode wrap)
1585 TRACE("(%p, %d)\n", grad, wrap);
1587 if(!grad)
1588 return InvalidParameter;
1590 grad->wrap = wrap;
1592 return Ok;
1595 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1597 TRACE("(%p, %x)\n", sf, argb);
1599 if(!sf)
1600 return InvalidParameter;
1602 sf->color = argb;
1603 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1605 DeleteObject(sf->brush.gdibrush);
1606 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1608 return Ok;
1611 /******************************************************************************
1612 * GdipSetTextureTransform [GDIPLUS.@]
1614 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1615 GDIPCONST GpMatrix *matrix)
1617 TRACE("(%p, %p)\n", texture, matrix);
1619 if(!texture || !matrix)
1620 return InvalidParameter;
1622 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1624 return Ok;
1627 /******************************************************************************
1628 * GdipSetTextureWrapMode [GDIPLUS.@]
1630 * WrapMode not used, only stored
1632 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1634 TRACE("(%p, %d)\n", brush, wrapmode);
1636 if(!brush)
1637 return InvalidParameter;
1639 brush->wrap = wrapmode;
1641 return Ok;
1644 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1645 ARGB color2)
1647 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1649 if(!brush)
1650 return InvalidParameter;
1652 brush->startcolor = color1;
1653 brush->endcolor = color2;
1655 return Ok;
1658 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1660 TRACE("(%p, %p)\n", brush, colors);
1662 if(!brush || !colors)
1663 return InvalidParameter;
1665 colors[0] = brush->startcolor;
1666 colors[1] = brush->endcolor;
1668 return Ok;
1671 /******************************************************************************
1672 * GdipRotateTextureTransform [GDIPLUS.@]
1674 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1675 GpMatrixOrder order)
1677 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1679 if(!brush)
1680 return InvalidParameter;
1682 return GdipRotateMatrix(brush->transform, angle, order);
1685 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1686 REAL scale)
1688 REAL factors[3];
1689 REAL positions[3];
1690 int num_points = 0;
1692 TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1694 if (!brush) return InvalidParameter;
1696 if (focus != 0.0)
1698 factors[num_points] = 0.0;
1699 positions[num_points] = 0.0;
1700 num_points++;
1703 factors[num_points] = scale;
1704 positions[num_points] = focus;
1705 num_points++;
1707 if (focus != 1.0)
1709 factors[num_points] = 0.0;
1710 positions[num_points] = 1.0;
1711 num_points++;
1714 return GdipSetLineBlend(brush, factors, positions, num_points);
1717 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1718 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1720 ARGB *new_color;
1721 REAL *new_pos;
1722 TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1724 if (!brush || !blend || !positions || count < 2 ||
1725 positions[0] != 0.0f || positions[count-1] != 1.0f)
1727 return InvalidParameter;
1730 new_color = GdipAlloc(count * sizeof(ARGB));
1731 new_pos = GdipAlloc(count * sizeof(REAL));
1732 if (!new_color || !new_pos)
1734 GdipFree(new_color);
1735 GdipFree(new_pos);
1736 return OutOfMemory;
1739 memcpy(new_color, blend, sizeof(ARGB) * count);
1740 memcpy(new_pos, positions, sizeof(REAL) * count);
1742 GdipFree(brush->pblendcolor);
1743 GdipFree(brush->pblendpos);
1745 brush->pblendcolor = new_color;
1746 brush->pblendpos = new_pos;
1747 brush->pblendcount = count;
1749 return Ok;
1752 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1753 ARGB *blend, REAL* positions, INT count)
1755 if (!brush || !blend || !positions || count < 2)
1756 return InvalidParameter;
1758 if (brush->pblendcount == 0)
1759 return GenericError;
1761 if (count < brush->pblendcount)
1762 return InsufficientBuffer;
1764 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1765 memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1767 return Ok;
1770 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1771 INT *count)
1773 if (!brush || !count)
1774 return InvalidParameter;
1776 *count = brush->pblendcount;
1778 return Ok;
1781 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1783 static int calls;
1785 TRACE("(%p)\n", brush);
1787 if(!(calls++))
1788 FIXME("not implemented\n");
1790 return NotImplemented;
1793 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1794 GDIPCONST GpMatrix *matrix)
1796 static int calls;
1798 TRACE("(%p,%p)\n", brush, matrix);
1800 if(!(calls++))
1801 FIXME("not implemented\n");
1803 return NotImplemented;
1806 GpStatus WINGDIPAPI GdipGetLineTransform(GpLineGradient *brush, GpMatrix *matrix)
1808 static int calls;
1810 TRACE("(%p,%p)\n", brush, matrix);
1812 if(!(calls++))
1813 FIXME("not implemented\n");
1815 return NotImplemented;
1818 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
1819 GpMatrixOrder order)
1821 static int calls;
1823 TRACE("(%p,%0.2f,%0.2f,%u)\n", brush, sx, sy, order);
1825 if(!(calls++))
1826 FIXME("not implemented\n");
1828 return NotImplemented;
1831 GpStatus WINGDIPAPI GdipMultiplyLineTransform(GpLineGradient *brush,
1832 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1834 static int calls;
1836 TRACE("(%p,%p,%u)\n", brush, matrix, order);
1838 if(!(calls++))
1839 FIXME("not implemented\n");
1841 return NotImplemented;
1844 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1845 REAL dx, REAL dy, GpMatrixOrder order)
1847 FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1849 return NotImplemented;
1852 /******************************************************************************
1853 * GdipTranslateTextureTransform [GDIPLUS.@]
1855 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1856 GpMatrixOrder order)
1858 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1860 if(!brush)
1861 return InvalidParameter;
1863 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1866 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1868 TRACE("(%p, %p)\n", brush, rect);
1870 if(!brush || !rect)
1871 return InvalidParameter;
1873 *rect = brush->rect;
1875 return Ok;
1878 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1880 GpRectF rectF;
1881 GpStatus ret;
1883 TRACE("(%p, %p)\n", brush, rect);
1885 if(!rect)
1886 return InvalidParameter;
1888 ret = GdipGetLineRect(brush, &rectF);
1890 if(ret == Ok){
1891 rect->X = roundr(rectF.X);
1892 rect->Y = roundr(rectF.Y);
1893 rect->Width = roundr(rectF.Width);
1894 rect->Height = roundr(rectF.Height);
1897 return ret;
1900 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1901 REAL angle, GpMatrixOrder order)
1903 static int calls;
1905 TRACE("(%p,%0.2f,%u)\n", brush, angle, order);
1907 if(!brush)
1908 return InvalidParameter;
1910 if(!(calls++))
1911 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1913 return NotImplemented;