ddraw: Do not restore the display mode from inside SetCooperativeLevel.
[wine/multimedia.git] / dlls / gdiplus / brush.c
blob57db380f3a4cf9828b83e41f5b9426ba7548ab17
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 if(!(*grad)->blendfac){
578 GdipFree(*grad);
579 return OutOfMemory;
581 (*grad)->blendfac[0] = 1.0;
582 (*grad)->blendpos = NULL;
583 (*grad)->blendcount = 1;
585 (*grad)->pathdata.Count = count;
586 (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
587 (*grad)->pathdata.Types = GdipAlloc(count);
589 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
590 GdipFree((*grad)->pathdata.Points);
591 GdipFree((*grad)->pathdata.Types);
592 GdipFree(*grad);
593 return OutOfMemory;
596 memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
597 memset((*grad)->pathdata.Types, PathPointTypeLine, count);
599 (*grad)->brush.lb.lbStyle = BS_SOLID;
600 (*grad)->brush.lb.lbColor = col;
601 (*grad)->brush.lb.lbHatch = 0;
603 (*grad)->brush.gdibrush = CreateSolidBrush(col);
604 (*grad)->brush.bt = BrushTypePathGradient;
605 (*grad)->centercolor = 0xffffffff;
606 (*grad)->wrap = wrap;
607 (*grad)->gamma = FALSE;
608 (*grad)->center.X = 0.0;
609 (*grad)->center.Y = 0.0;
610 (*grad)->focus.X = 0.0;
611 (*grad)->focus.Y = 0.0;
613 TRACE("<-- %p\n", *grad);
615 return Ok;
618 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
619 INT count, GpWrapMode wrap, GpPathGradient **grad)
621 GpPointF *pointsF;
622 GpStatus ret;
623 INT i;
625 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
627 if(!points || !grad)
628 return InvalidParameter;
630 if(count <= 0)
631 return OutOfMemory;
633 pointsF = GdipAlloc(sizeof(GpPointF) * count);
634 if(!pointsF)
635 return OutOfMemory;
637 for(i = 0; i < count; i++){
638 pointsF[i].X = (REAL)points[i].X;
639 pointsF[i].Y = (REAL)points[i].Y;
642 ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
643 GdipFree(pointsF);
645 return ret;
648 /******************************************************************************
649 * GdipCreatePathGradientFromPath [GDIPLUS.@]
651 * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
653 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
654 GpPathGradient **grad)
656 COLORREF col = ARGB2COLORREF(0xffffffff);
658 TRACE("(%p, %p)\n", path, grad);
660 if(!path || !grad)
661 return InvalidParameter;
663 *grad = GdipAlloc(sizeof(GpPathGradient));
664 if (!*grad) return OutOfMemory;
666 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
667 if(!(*grad)->blendfac){
668 GdipFree(*grad);
669 return OutOfMemory;
671 (*grad)->blendfac[0] = 1.0;
672 (*grad)->blendpos = NULL;
673 (*grad)->blendcount = 1;
675 (*grad)->pathdata.Count = path->pathdata.Count;
676 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
677 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
679 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
680 GdipFree((*grad)->pathdata.Points);
681 GdipFree((*grad)->pathdata.Types);
682 GdipFree(*grad);
683 return OutOfMemory;
686 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
687 path->pathdata.Count * sizeof(PointF));
688 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
690 (*grad)->brush.lb.lbStyle = BS_SOLID;
691 (*grad)->brush.lb.lbColor = col;
692 (*grad)->brush.lb.lbHatch = 0;
694 (*grad)->brush.gdibrush = CreateSolidBrush(col);
695 (*grad)->brush.bt = BrushTypePathGradient;
696 (*grad)->centercolor = 0xffffffff;
697 (*grad)->wrap = WrapModeClamp;
698 (*grad)->gamma = FALSE;
699 /* FIXME: this should be set to the "centroid" of the path by default */
700 (*grad)->center.X = 0.0;
701 (*grad)->center.Y = 0.0;
702 (*grad)->focus.X = 0.0;
703 (*grad)->focus.Y = 0.0;
705 TRACE("<-- %p\n", *grad);
707 return Ok;
710 /******************************************************************************
711 * GdipCreateSolidFill [GDIPLUS.@]
713 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
715 COLORREF col = ARGB2COLORREF(color);
717 TRACE("(%x, %p)\n", color, sf);
719 if(!sf) return InvalidParameter;
721 *sf = GdipAlloc(sizeof(GpSolidFill));
722 if (!*sf) return OutOfMemory;
724 (*sf)->brush.lb.lbStyle = BS_SOLID;
725 (*sf)->brush.lb.lbColor = col;
726 (*sf)->brush.lb.lbHatch = 0;
728 (*sf)->brush.gdibrush = CreateSolidBrush(col);
729 (*sf)->brush.bt = BrushTypeSolidColor;
730 (*sf)->color = color;
731 (*sf)->bmp = ARGB2BMP(color);
733 TRACE("<-- %p\n", *sf);
735 return Ok;
738 /******************************************************************************
739 * GdipCreateTexture [GDIPLUS.@]
741 * PARAMS
742 * image [I] image to use
743 * wrapmode [I] optional
744 * texture [O] pointer to the resulting texturebrush
746 * RETURNS
747 * SUCCESS: Ok
748 * FAILURE: element of GpStatus
750 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
751 GpTexture **texture)
753 UINT width, height;
754 GpImageAttributes attributes;
755 GpStatus stat;
757 TRACE("%p, %d %p\n", image, wrapmode, texture);
759 if (!(image && texture))
760 return InvalidParameter;
762 stat = GdipGetImageWidth(image, &width);
763 if (stat != Ok) return stat;
764 stat = GdipGetImageHeight(image, &height);
765 if (stat != Ok) return stat;
766 attributes.wrap = wrapmode;
768 return GdipCreateTextureIA(image, &attributes, 0, 0, width, height,
769 texture);
772 /******************************************************************************
773 * GdipCreateTexture2 [GDIPLUS.@]
775 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
776 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
778 GpImageAttributes attributes;
780 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
781 x, y, width, height, texture);
783 attributes.wrap = wrapmode;
784 return GdipCreateTextureIA(image, &attributes, x, y, width, height,
785 texture);
788 /******************************************************************************
789 * GdipCreateTextureIA [GDIPLUS.@]
791 * FIXME: imageattr ignored
793 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
794 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
795 REAL height, GpTexture **texture)
797 HBITMAP hbm=NULL;
798 GpStatus status;
799 GpImage *new_image=NULL;
801 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
802 texture);
804 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
805 return InvalidParameter;
807 *texture = NULL;
809 if(image->type != ImageTypeBitmap){
810 FIXME("not implemented for image type %d\n", image->type);
811 return NotImplemented;
814 status = GdipCloneBitmapArea(x, y, width, height, PixelFormatDontCare, (GpBitmap*)image, (GpBitmap**)&new_image);
815 if (status != Ok)
816 return status;
818 status = GdipCreateHBITMAPFromBitmap((GpBitmap*)new_image, &hbm, 0);
819 if(!hbm)
821 status = GenericError;
822 goto exit;
825 *texture = GdipAlloc(sizeof(GpTexture));
826 if (!*texture){
827 status = OutOfMemory;
828 goto exit;
831 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
832 goto exit;
835 (*texture)->brush.lb.lbStyle = BS_PATTERN;
836 (*texture)->brush.lb.lbColor = 0;
837 (*texture)->brush.lb.lbHatch = (ULONG_PTR)hbm;
839 (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
840 (*texture)->brush.bt = BrushTypeTextureFill;
841 if (imageattr)
842 (*texture)->wrap = imageattr->wrap;
843 else
844 (*texture)->wrap = WrapModeTile;
845 (*texture)->image = new_image;
847 exit:
848 if (status == Ok)
850 TRACE("<-- %p\n", *texture);
852 else
854 if (*texture)
856 GdipDeleteMatrix((*texture)->transform);
857 GdipFree(*texture);
858 *texture = NULL;
860 GdipDisposeImage(new_image);
861 TRACE("<-- error %u\n", status);
864 DeleteObject(hbm);
866 return status;
869 /******************************************************************************
870 * GdipCreateTextureIAI [GDIPLUS.@]
872 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
873 INT x, INT y, INT width, INT height, GpTexture **texture)
875 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
876 texture);
878 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
881 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
882 INT x, INT y, INT width, INT height, GpTexture **texture)
884 GpImageAttributes imageattr;
886 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
887 texture);
889 imageattr.wrap = wrapmode;
891 return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
894 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
896 TRACE("(%p, %p)\n", brush, type);
898 if(!brush || !type) return InvalidParameter;
900 *type = brush->bt;
902 return Ok;
905 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
907 TRACE("(%p, %p)\n", brush, backcol);
909 if(!brush || !backcol) return InvalidParameter;
911 *backcol = brush->backcol;
913 return Ok;
916 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
918 TRACE("(%p, %p)\n", brush, forecol);
920 if(!brush || !forecol) return InvalidParameter;
922 *forecol = brush->forecol;
924 return Ok;
927 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
929 TRACE("(%p, %p)\n", brush, hatchstyle);
931 if(!brush || !hatchstyle) return InvalidParameter;
933 *hatchstyle = brush->hatchstyle;
935 return Ok;
938 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
940 TRACE("(%p)\n", brush);
942 if(!brush) return InvalidParameter;
944 switch(brush->bt)
946 case BrushTypePathGradient:
947 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
948 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
949 GdipFree(((GpPathGradient*) brush)->blendfac);
950 GdipFree(((GpPathGradient*) brush)->blendpos);
951 break;
952 case BrushTypeSolidColor:
953 if (((GpSolidFill*)brush)->bmp)
954 DeleteObject(((GpSolidFill*)brush)->bmp);
955 break;
956 case BrushTypeLinearGradient:
957 GdipFree(((GpLineGradient*)brush)->blendfac);
958 GdipFree(((GpLineGradient*)brush)->blendpos);
959 GdipFree(((GpLineGradient*)brush)->pblendcolor);
960 GdipFree(((GpLineGradient*)brush)->pblendpos);
961 break;
962 case BrushTypeTextureFill:
963 GdipDeleteMatrix(((GpTexture*)brush)->transform);
964 GdipDisposeImage(((GpTexture*)brush)->image);
965 break;
966 default:
967 break;
970 DeleteObject(brush->gdibrush);
971 GdipFree(brush);
973 return Ok;
976 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
977 BOOL *usinggamma)
979 TRACE("(%p, %p)\n", line, usinggamma);
981 if(!line || !usinggamma)
982 return InvalidParameter;
984 *usinggamma = line->gamma;
986 return Ok;
989 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
991 TRACE("(%p, %p)\n", brush, wrapmode);
993 if(!brush || !wrapmode)
994 return InvalidParameter;
996 *wrapmode = brush->wrap;
998 return Ok;
1001 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
1002 REAL *positions, INT count)
1004 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
1006 if(!brush || !blend || !positions || count <= 0)
1007 return InvalidParameter;
1009 if(count < brush->blendcount)
1010 return InsufficientBuffer;
1012 memcpy(blend, brush->blendfac, count*sizeof(REAL));
1013 if(brush->blendcount > 1){
1014 memcpy(positions, brush->blendpos, count*sizeof(REAL));
1017 return Ok;
1020 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
1022 TRACE("(%p, %p)\n", brush, count);
1024 if(!brush || !count)
1025 return InvalidParameter;
1027 *count = brush->blendcount;
1029 return Ok;
1032 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
1033 GpPointF *point)
1035 TRACE("(%p, %p)\n", grad, point);
1037 if(!grad || !point)
1038 return InvalidParameter;
1040 point->X = grad->center.X;
1041 point->Y = grad->center.Y;
1043 return Ok;
1046 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
1047 GpPoint *point)
1049 GpStatus ret;
1050 GpPointF ptf;
1052 TRACE("(%p, %p)\n", grad, point);
1054 if(!point)
1055 return InvalidParameter;
1057 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
1059 if(ret == Ok){
1060 point->X = roundr(ptf.X);
1061 point->Y = roundr(ptf.Y);
1064 return ret;
1067 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
1068 REAL *x, REAL *y)
1070 TRACE("(%p, %p, %p)\n", grad, x, y);
1072 if(!grad || !x || !y)
1073 return InvalidParameter;
1075 *x = grad->focus.X;
1076 *y = grad->focus.Y;
1078 return Ok;
1081 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1082 BOOL *gamma)
1084 TRACE("(%p, %p)\n", grad, gamma);
1086 if(!grad || !gamma)
1087 return InvalidParameter;
1089 *gamma = grad->gamma;
1091 return Ok;
1094 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1095 INT *count)
1097 TRACE("(%p, %p)\n", grad, count);
1099 if(!grad || !count)
1100 return InvalidParameter;
1102 *count = grad->pathdata.Count;
1104 return Ok;
1107 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1109 GpRectF r;
1110 GpPath* path;
1111 GpStatus stat;
1113 TRACE("(%p, %p)\n", brush, rect);
1115 if(!brush || !rect)
1116 return InvalidParameter;
1118 stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
1119 brush->pathdata.Count, FillModeAlternate, &path);
1120 if(stat != Ok) return stat;
1122 stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
1123 if(stat != Ok){
1124 GdipDeletePath(path);
1125 return stat;
1128 memcpy(rect, &r, sizeof(GpRectF));
1130 GdipDeletePath(path);
1132 return Ok;
1135 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1137 GpRectF rectf;
1138 GpStatus stat;
1140 TRACE("(%p, %p)\n", brush, rect);
1142 if(!brush || !rect)
1143 return InvalidParameter;
1145 stat = GdipGetPathGradientRect(brush, &rectf);
1146 if(stat != Ok) return stat;
1148 rect->X = roundr(rectf.X);
1149 rect->Y = roundr(rectf.Y);
1150 rect->Width = roundr(rectf.Width);
1151 rect->Height = roundr(rectf.Height);
1153 return Ok;
1156 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1157 *grad, ARGB *argb, INT *count)
1159 static int calls;
1161 TRACE("(%p,%p,%p)\n", grad, argb, count);
1163 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
1164 return InvalidParameter;
1166 if(!(calls++))
1167 FIXME("not implemented\n");
1169 return NotImplemented;
1172 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorCount(GpPathGradient *brush, INT *count)
1174 TRACE("(%p, %p)\n", brush, count);
1176 if (!brush || !count)
1177 return InvalidParameter;
1179 return NotImplemented;
1182 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1183 GpWrapMode *wrapmode)
1185 TRACE("(%p, %p)\n", brush, wrapmode);
1187 if(!brush || !wrapmode)
1188 return InvalidParameter;
1190 *wrapmode = brush->wrap;
1192 return Ok;
1195 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1197 TRACE("(%p, %p)\n", sf, argb);
1199 if(!sf || !argb)
1200 return InvalidParameter;
1202 *argb = sf->color;
1204 return Ok;
1207 /******************************************************************************
1208 * GdipGetTextureImage [GDIPLUS.@]
1210 GpStatus WINGDIPAPI GdipGetTextureImage(GpTexture *brush, GpImage **image)
1212 TRACE("(%p, %p)\n", brush, image);
1214 if(!brush || !image)
1215 return InvalidParameter;
1217 return GdipCloneImage(brush->image, image);
1220 /******************************************************************************
1221 * GdipGetTextureTransform [GDIPLUS.@]
1223 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1225 TRACE("(%p, %p)\n", brush, matrix);
1227 if(!brush || !matrix)
1228 return InvalidParameter;
1230 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1232 return Ok;
1235 /******************************************************************************
1236 * GdipGetTextureWrapMode [GDIPLUS.@]
1238 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1240 TRACE("(%p, %p)\n", brush, wrapmode);
1242 if(!brush || !wrapmode)
1243 return InvalidParameter;
1245 *wrapmode = brush->wrap;
1247 return Ok;
1250 /******************************************************************************
1251 * GdipMultiplyTextureTransform [GDIPLUS.@]
1253 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1254 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1256 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1258 if(!brush || !matrix)
1259 return InvalidParameter;
1261 return GdipMultiplyMatrix(brush->transform, matrix, order);
1264 /******************************************************************************
1265 * GdipResetTextureTransform [GDIPLUS.@]
1267 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1269 TRACE("(%p)\n", brush);
1271 if(!brush)
1272 return InvalidParameter;
1274 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1277 /******************************************************************************
1278 * GdipScaleTextureTransform [GDIPLUS.@]
1280 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1281 REAL sx, REAL sy, GpMatrixOrder order)
1283 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1285 if(!brush)
1286 return InvalidParameter;
1288 return GdipScaleMatrix(brush->transform, sx, sy, order);
1291 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1292 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1294 REAL *new_blendfac, *new_blendpos;
1296 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1298 if(!brush || !factors || !positions || count <= 0 ||
1299 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1300 return InvalidParameter;
1302 new_blendfac = GdipAlloc(count * sizeof(REAL));
1303 new_blendpos = GdipAlloc(count * sizeof(REAL));
1305 if (!new_blendfac || !new_blendpos)
1307 GdipFree(new_blendfac);
1308 GdipFree(new_blendpos);
1309 return OutOfMemory;
1312 memcpy(new_blendfac, factors, count * sizeof(REAL));
1313 memcpy(new_blendpos, positions, count * sizeof(REAL));
1315 GdipFree(brush->blendfac);
1316 GdipFree(brush->blendpos);
1318 brush->blendcount = count;
1319 brush->blendfac = new_blendfac;
1320 brush->blendpos = new_blendpos;
1322 return Ok;
1325 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1326 REAL *positions, INT count)
1328 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1330 if (!brush || !factors || !positions || count <= 0)
1331 return InvalidParameter;
1333 if (count < brush->blendcount)
1334 return InsufficientBuffer;
1336 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1337 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1339 return Ok;
1342 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1344 TRACE("(%p, %p)\n", brush, count);
1346 if (!brush || !count)
1347 return InvalidParameter;
1349 *count = brush->blendcount;
1351 return Ok;
1354 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1355 BOOL usegamma)
1357 TRACE("(%p, %d)\n", line, usegamma);
1359 if(!line)
1360 return InvalidParameter;
1362 line->gamma = usegamma;
1364 return Ok;
1367 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1368 REAL scale)
1370 REAL factors[33];
1371 REAL positions[33];
1372 int num_points = 0;
1373 int i;
1374 const int precision = 16;
1375 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1376 REAL min_erf;
1377 REAL scale_erf;
1379 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1381 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1382 return InvalidParameter;
1384 /* we want 2 standard deviations */
1385 erf_range = 2.0 / sqrt(2);
1387 /* calculate the constants we need to normalize the error function to be
1388 between 0.0 and scale over the range we need */
1389 min_erf = erf(-erf_range);
1390 scale_erf = scale / (-2.0 * min_erf);
1392 if (focus != 0.0)
1394 positions[0] = 0.0;
1395 factors[0] = 0.0;
1396 for (i=1; i<precision; i++)
1398 positions[i] = focus * i / precision;
1399 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1401 num_points += precision;
1404 positions[num_points] = focus;
1405 factors[num_points] = scale;
1406 num_points += 1;
1408 if (focus != 1.0)
1410 for (i=1; i<precision; i++)
1412 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1413 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1415 num_points += precision;
1416 positions[num_points-1] = 1.0;
1417 factors[num_points-1] = 0.0;
1420 return GdipSetLineBlend(line, factors, positions, num_points);
1423 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1424 GpWrapMode wrap)
1426 TRACE("(%p, %d)\n", line, wrap);
1428 if(!line || wrap == WrapModeClamp)
1429 return InvalidParameter;
1431 line->wrap = wrap;
1433 return Ok;
1436 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1437 GDIPCONST REAL *pos, INT count)
1439 static int calls;
1441 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1443 if(!(calls++))
1444 FIXME("not implemented\n");
1446 return NotImplemented;
1449 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1450 GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1452 FIXME("(%p,%p,%p,%i): stub\n", brush, blend, pos, count);
1453 return NotImplemented;
1456 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1457 ARGB argb)
1459 TRACE("(%p, %x)\n", grad, argb);
1461 if(!grad)
1462 return InvalidParameter;
1464 grad->centercolor = argb;
1465 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1467 DeleteObject(grad->brush.gdibrush);
1468 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1470 return Ok;
1473 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1474 GpPointF *point)
1476 TRACE("(%p, %s)\n", grad, debugstr_pointf(point));
1478 if(!grad || !point)
1479 return InvalidParameter;
1481 grad->center.X = point->X;
1482 grad->center.Y = point->Y;
1484 return Ok;
1487 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1488 GpPoint *point)
1490 GpPointF ptf;
1492 TRACE("(%p, %p)\n", grad, point);
1494 if(!point)
1495 return InvalidParameter;
1497 ptf.X = (REAL)point->X;
1498 ptf.Y = (REAL)point->Y;
1500 return GdipSetPathGradientCenterPoint(grad,&ptf);
1503 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1504 REAL x, REAL y)
1506 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1508 if(!grad)
1509 return InvalidParameter;
1511 grad->focus.X = x;
1512 grad->focus.Y = y;
1514 return Ok;
1517 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1518 BOOL gamma)
1520 TRACE("(%p, %d)\n", grad, gamma);
1522 if(!grad)
1523 return InvalidParameter;
1525 grad->gamma = gamma;
1527 return Ok;
1530 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1531 REAL focus, REAL scale)
1533 static int calls;
1535 TRACE("(%p,%0.2f,%0.2f)\n", grad, focus, scale);
1537 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1538 return InvalidParameter;
1540 if(!(calls++))
1541 FIXME("not implemented\n");
1543 return NotImplemented;
1546 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1547 *grad, GDIPCONST ARGB *argb, INT *count)
1549 static int calls;
1551 TRACE("(%p,%p,%p)\n", grad, argb, count);
1553 if(!grad || !argb || !count || (*count <= 0) ||
1554 (*count > grad->pathdata.Count))
1555 return InvalidParameter;
1557 if(!(calls++))
1558 FIXME("not implemented\n");
1560 return NotImplemented;
1563 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1564 GpWrapMode wrap)
1566 TRACE("(%p, %d)\n", grad, wrap);
1568 if(!grad)
1569 return InvalidParameter;
1571 grad->wrap = wrap;
1573 return Ok;
1576 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1578 TRACE("(%p, %x)\n", sf, argb);
1580 if(!sf)
1581 return InvalidParameter;
1583 sf->color = argb;
1584 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1586 DeleteObject(sf->brush.gdibrush);
1587 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1589 return Ok;
1592 /******************************************************************************
1593 * GdipSetTextureTransform [GDIPLUS.@]
1595 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1596 GDIPCONST GpMatrix *matrix)
1598 TRACE("(%p, %p)\n", texture, matrix);
1600 if(!texture || !matrix)
1601 return InvalidParameter;
1603 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1605 return Ok;
1608 /******************************************************************************
1609 * GdipSetTextureWrapMode [GDIPLUS.@]
1611 * WrapMode not used, only stored
1613 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1615 TRACE("(%p, %d)\n", brush, wrapmode);
1617 if(!brush)
1618 return InvalidParameter;
1620 brush->wrap = wrapmode;
1622 return Ok;
1625 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1626 ARGB color2)
1628 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1630 if(!brush)
1631 return InvalidParameter;
1633 brush->startcolor = color1;
1634 brush->endcolor = color2;
1636 return Ok;
1639 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1641 TRACE("(%p, %p)\n", brush, colors);
1643 if(!brush || !colors)
1644 return InvalidParameter;
1646 colors[0] = brush->startcolor;
1647 colors[1] = brush->endcolor;
1649 return Ok;
1652 /******************************************************************************
1653 * GdipRotateTextureTransform [GDIPLUS.@]
1655 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1656 GpMatrixOrder order)
1658 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1660 if(!brush)
1661 return InvalidParameter;
1663 return GdipRotateMatrix(brush->transform, angle, order);
1666 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1667 REAL scale)
1669 REAL factors[3];
1670 REAL positions[3];
1671 int num_points = 0;
1673 TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1675 if (!brush) return InvalidParameter;
1677 if (focus != 0.0)
1679 factors[num_points] = 0.0;
1680 positions[num_points] = 0.0;
1681 num_points++;
1684 factors[num_points] = scale;
1685 positions[num_points] = focus;
1686 num_points++;
1688 if (focus != 1.0)
1690 factors[num_points] = 0.0;
1691 positions[num_points] = 1.0;
1692 num_points++;
1695 return GdipSetLineBlend(brush, factors, positions, num_points);
1698 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1699 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1701 ARGB *new_color;
1702 REAL *new_pos;
1703 TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1705 if (!brush || !blend || !positions || count < 2 ||
1706 positions[0] != 0.0f || positions[count-1] != 1.0f)
1708 return InvalidParameter;
1711 new_color = GdipAlloc(count * sizeof(ARGB));
1712 new_pos = GdipAlloc(count * sizeof(REAL));
1713 if (!new_color || !new_pos)
1715 GdipFree(new_color);
1716 GdipFree(new_pos);
1717 return OutOfMemory;
1720 memcpy(new_color, blend, sizeof(ARGB) * count);
1721 memcpy(new_pos, positions, sizeof(REAL) * count);
1723 GdipFree(brush->pblendcolor);
1724 GdipFree(brush->pblendpos);
1726 brush->pblendcolor = new_color;
1727 brush->pblendpos = new_pos;
1728 brush->pblendcount = count;
1730 return Ok;
1733 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1734 ARGB *blend, REAL* positions, INT count)
1736 if (!brush || !blend || !positions || count < 2)
1737 return InvalidParameter;
1739 if (brush->pblendcount == 0)
1740 return GenericError;
1742 if (count < brush->pblendcount)
1743 return InsufficientBuffer;
1745 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1746 memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1748 return Ok;
1751 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1752 INT *count)
1754 if (!brush || !count)
1755 return InvalidParameter;
1757 *count = brush->pblendcount;
1759 return Ok;
1762 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1764 static int calls;
1766 TRACE("(%p)\n", brush);
1768 if(!(calls++))
1769 FIXME("not implemented\n");
1771 return NotImplemented;
1774 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1775 GDIPCONST GpMatrix *matrix)
1777 static int calls;
1779 TRACE("(%p,%p)\n", brush, matrix);
1781 if(!(calls++))
1782 FIXME("not implemented\n");
1784 return NotImplemented;
1787 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
1788 GpMatrixOrder order)
1790 static int calls;
1792 TRACE("(%p,%0.2f,%0.2f,%u)\n", brush, sx, sy, order);
1794 if(!(calls++))
1795 FIXME("not implemented\n");
1797 return NotImplemented;
1800 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1801 REAL dx, REAL dy, GpMatrixOrder order)
1803 FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1805 return NotImplemented;
1808 /******************************************************************************
1809 * GdipTranslateTextureTransform [GDIPLUS.@]
1811 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1812 GpMatrixOrder order)
1814 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1816 if(!brush)
1817 return InvalidParameter;
1819 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1822 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1824 TRACE("(%p, %p)\n", brush, rect);
1826 if(!brush || !rect)
1827 return InvalidParameter;
1829 *rect = brush->rect;
1831 return Ok;
1834 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1836 GpRectF rectF;
1837 GpStatus ret;
1839 TRACE("(%p, %p)\n", brush, rect);
1841 if(!rect)
1842 return InvalidParameter;
1844 ret = GdipGetLineRect(brush, &rectF);
1846 if(ret == Ok){
1847 rect->X = roundr(rectF.X);
1848 rect->Y = roundr(rectF.Y);
1849 rect->Width = roundr(rectF.Width);
1850 rect->Height = roundr(rectF.Height);
1853 return ret;
1856 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1857 REAL angle, GpMatrixOrder order)
1859 static int calls;
1861 TRACE("(%p,%0.2f,%u)\n", brush, angle, order);
1863 if(!brush)
1864 return InvalidParameter;
1866 if(!(calls++))
1867 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1869 return NotImplemented;