Sync with trunk (r48008)
[reactos.git] / dll / win32 / gdiplus / brush.c
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include <stdarg.h>
20
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winuser.h"
24 #include "wingdi.h"
25
26 #define COBJMACROS
27 #include "objbase.h"
28 #include "olectl.h"
29 #include "ole2.h"
30
31 #include "gdiplus.h"
32 #include "gdiplus_private.h"
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
36
37 /*
38 Unix stuff
39 Code from http://www.johndcook.com/blog/2009/01/19/stand-alone-error-function-erf/
40 */
41 double erf(double x)
42 {
43 const float a1 = 0.254829592;
44 const float a2 = -0.284496736;
45 const float a3 = 1.421413741;
46 const float a4 = -1.453152027;
47 const float a5 = 1.061405429;
48 const float p = 0.3275911;
49 float t, y, sign;
50
51 /* Save the sign of x */
52 sign = 1;
53 if (x < 0)
54 sign = -1;
55 x = abs(x);
56
57 /* A & S 7.1.26 */
58 t = 1.0/(1.0 + p*x);
59 y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x);
60
61 return sign*y;
62 }
63
64 /******************************************************************************
65 * GdipCloneBrush [GDIPLUS.@]
66 */
67 GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone)
68 {
69 TRACE("(%p, %p)\n", brush, clone);
70
71 if(!brush || !clone)
72 return InvalidParameter;
73
74 switch(brush->bt){
75 case BrushTypeSolidColor:
76 {
77 GpSolidFill *fill;
78 *clone = GdipAlloc(sizeof(GpSolidFill));
79 if (!*clone) return OutOfMemory;
80
81 fill = (GpSolidFill*)*clone;
82
83 memcpy(*clone, brush, sizeof(GpSolidFill));
84
85 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
86 fill->bmp = ARGB2BMP(fill->color);
87 break;
88 }
89 case BrushTypeHatchFill:
90 {
91 GpHatch *hatch = (GpHatch*)brush;
92
93 return GdipCreateHatchBrush(hatch->hatchstyle, hatch->forecol, hatch->backcol, (GpHatch**)clone);
94 }
95 case BrushTypePathGradient:{
96 GpPathGradient *src, *dest;
97 INT count;
98
99 *clone = GdipAlloc(sizeof(GpPathGradient));
100 if (!*clone) return OutOfMemory;
101
102 src = (GpPathGradient*) brush,
103 dest = (GpPathGradient*) *clone;
104 count = src->pathdata.Count;
105
106 memcpy(dest, src, sizeof(GpPathGradient));
107
108 dest->pathdata.Count = count;
109 dest->pathdata.Points = GdipAlloc(count * sizeof(PointF));
110 dest->pathdata.Types = GdipAlloc(count);
111
112 if(!dest->pathdata.Points || !dest->pathdata.Types){
113 GdipFree(dest->pathdata.Points);
114 GdipFree(dest->pathdata.Types);
115 GdipFree(dest);
116 return OutOfMemory;
117 }
118
119 memcpy(dest->pathdata.Points, src->pathdata.Points, count * sizeof(PointF));
120 memcpy(dest->pathdata.Types, src->pathdata.Types, count);
121
122 /* blending */
123 count = src->blendcount;
124 dest->blendcount = count;
125 dest->blendfac = GdipAlloc(count * sizeof(REAL));
126 dest->blendpos = GdipAlloc(count * sizeof(REAL));
127
128 if(!dest->blendfac || !dest->blendpos){
129 GdipFree(dest->pathdata.Points);
130 GdipFree(dest->pathdata.Types);
131 GdipFree(dest->blendfac);
132 GdipFree(dest->blendpos);
133 GdipFree(dest);
134 return OutOfMemory;
135 }
136
137 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
138 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
139
140 break;
141 }
142 case BrushTypeLinearGradient:{
143 GpLineGradient *dest, *src;
144 INT count, pcount;
145
146 dest = GdipAlloc(sizeof(GpLineGradient));
147 if(!dest) return OutOfMemory;
148
149 src = (GpLineGradient*)brush;
150
151 memcpy(dest, src, sizeof(GpLineGradient));
152
153 dest->brush.gdibrush = CreateSolidBrush(dest->brush.lb.lbColor);
154
155 count = dest->blendcount;
156 dest->blendfac = GdipAlloc(count * sizeof(REAL));
157 dest->blendpos = GdipAlloc(count * sizeof(REAL));
158 pcount = dest->pblendcount;
159 if (pcount)
160 {
161 dest->pblendcolor = GdipAlloc(pcount * sizeof(ARGB));
162 dest->pblendpos = GdipAlloc(pcount * sizeof(REAL));
163 }
164
165 if (!dest->blendfac || !dest->blendpos ||
166 (pcount && (!dest->pblendcolor || !dest->pblendpos)))
167 {
168 GdipFree(dest->blendfac);
169 GdipFree(dest->blendpos);
170 GdipFree(dest->pblendcolor);
171 GdipFree(dest->pblendpos);
172 DeleteObject(dest->brush.gdibrush);
173 GdipFree(dest);
174 return OutOfMemory;
175 }
176
177 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
178 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
179
180 if (pcount)
181 {
182 memcpy(dest->pblendcolor, src->pblendcolor, pcount * sizeof(ARGB));
183 memcpy(dest->pblendpos, src->pblendpos, pcount * sizeof(REAL));
184 }
185
186 *clone = &dest->brush;
187 break;
188 }
189 case BrushTypeTextureFill:
190 {
191 GpStatus stat;
192 GpTexture *texture = (GpTexture*)brush;
193 GpTexture *new_texture;
194
195 stat = GdipCreateTexture(texture->image, texture->wrap, &new_texture);
196
197 if (stat == Ok)
198 {
199 memcpy(new_texture->transform, texture->transform, sizeof(GpMatrix));
200 *clone = (GpBrush*)new_texture;
201 }
202 else
203 *clone = NULL;
204
205 return stat;
206 }
207 default:
208 ERR("not implemented for brush type %d\n", brush->bt);
209 return NotImplemented;
210 }
211
212 TRACE("<-- %p\n", *clone);
213 return Ok;
214 }
215
216 static const char HatchBrushes[][8] = {
217 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HatchStyleHorizontal */
218 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleVertical */
219 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HatchStyleForwardDiagonal */
220 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HatchStyleBackwardDiagonal */
221 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleCross */
222 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }, /* HatchStyleDiagonalCross */
223 { 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x80 }, /* HatchStyle05Percent */
224 { 0x00, 0x02, 0x00, 0x88, 0x00, 0x20, 0x00, 0x88 }, /* HatchStyle10Percent */
225 { 0x00, 0x22, 0x00, 0xcc, 0x00, 0x22, 0x00, 0xcc }, /* HatchStyle20Percent */
226 { 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc }, /* HatchStyle25Percent */
227 { 0x00, 0xcc, 0x04, 0xcc, 0x00, 0xcc, 0x40, 0xcc }, /* HatchStyle30Percent */
228 { 0x44, 0xcc, 0x22, 0xcc, 0x44, 0xcc, 0x22, 0xcc }, /* HatchStyle40Percent */
229 { 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc }, /* HatchStyle50Percent */
230 { 0x55, 0xcd, 0x55, 0xee, 0x55, 0xdc, 0x55, 0xee }, /* HatchStyle60Percent */
231 { 0x55, 0xdd, 0x55, 0xff, 0x55, 0xdd, 0x55, 0xff }, /* HatchStyle70Percent */
232 { 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff }, /* HatchStyle75Percent */
233 { 0x55, 0xff, 0x59, 0xff, 0x55, 0xff, 0x99, 0xff }, /* HatchStyle80Percent */
234 { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xfd, 0xff }, /* HatchStyle90Percent */
235 { 0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88 }, /* HatchStyleLightDownwardDiagonal */
236 { 0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11 }, /* HatchStyleLightUpwardDiagonal */
237 { 0x99, 0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc }, /* HatchStyleDarkDownwardDiagonal */
238 { 0xcc, 0x66, 0x33, 0x99, 0xcc, 0x66, 0x33, 0x99 }, /* HatchStyleDarkUpwardDiagonal */
239 { 0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0 }, /* HatchStyleWideDownwardDiagonal */
240 { 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x83, 0xc1 }, /* HatchStyleWideUpwardDiagonal */
241 { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 }, /* HatchStyleLightVertical */
242 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff }, /* HatchStyleLightHorizontal */
243 { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }, /* HatchStyleNarrowVertical */
244 { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, /* HatchStyleNarrowHorizontal */
245 { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }, /* HatchStyleDarkVertical */
246 { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff }, /* HatchStyleDarkHorizontal */
247 };
248
249 /******************************************************************************
250 * GdipCreateHatchBrush [GDIPLUS.@]
251 */
252 GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle hatchstyle, ARGB forecol, ARGB backcol, GpHatch **brush)
253 {
254 COLORREF fgcol = ARGB2COLORREF(forecol);
255 GpStatus stat = Ok;
256
257 TRACE("(%d, %d, %d, %p)\n", hatchstyle, forecol, backcol, brush);
258
259 if(!brush) return InvalidParameter;
260
261 *brush = GdipAlloc(sizeof(GpHatch));
262 if (!*brush) return OutOfMemory;
263
264 if (hatchstyle < sizeof(HatchBrushes) / sizeof(HatchBrushes[0]))
265 {
266 HBITMAP hbmp;
267 HDC hdc;
268 BITMAPINFOHEADER bmih;
269 DWORD* bits;
270 int x, y;
271
272 hdc = CreateCompatibleDC(0);
273
274 if (hdc)
275 {
276 bmih.biSize = sizeof(bmih);
277 bmih.biWidth = 8;
278 bmih.biHeight = 8;
279 bmih.biPlanes = 1;
280 bmih.biBitCount = 32;
281 bmih.biCompression = BI_RGB;
282 bmih.biSizeImage = 0;
283
284 hbmp = CreateDIBSection(hdc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
285
286 if (hbmp)
287 {
288 for (y=0; y<8; y++)
289 for (x=0; x<8; x++)
290 if ((HatchBrushes[hatchstyle][y] & (0x80 >> x)) != 0)
291 bits[y*8+x] = forecol;
292 else
293 bits[y*8+x] = backcol;
294 }
295 else
296 stat = GenericError;
297
298 DeleteDC(hdc);
299 }
300 else
301 stat = GenericError;
302
303 if (stat == Ok)
304 {
305 (*brush)->brush.lb.lbStyle = BS_PATTERN;
306 (*brush)->brush.lb.lbColor = 0;
307 (*brush)->brush.lb.lbHatch = (ULONG_PTR)hbmp;
308 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
309
310 DeleteObject(hbmp);
311 }
312 }
313 else
314 {
315 FIXME("Unimplemented hatch style %d\n", hatchstyle);
316
317 (*brush)->brush.lb.lbStyle = BS_SOLID;
318 (*brush)->brush.lb.lbColor = fgcol;
319 (*brush)->brush.lb.lbHatch = 0;
320 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
321 }
322
323 if (stat == Ok)
324 {
325 (*brush)->brush.bt = BrushTypeHatchFill;
326 (*brush)->forecol = forecol;
327 (*brush)->backcol = backcol;
328 (*brush)->hatchstyle = hatchstyle;
329 TRACE("<-- %p\n", *brush);
330 }
331 else
332 {
333 GdipFree(*brush);
334 *brush = NULL;
335 }
336
337 return stat;
338 }
339
340 /******************************************************************************
341 * GdipCreateLineBrush [GDIPLUS.@]
342 */
343 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
344 GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
345 GpWrapMode wrap, GpLineGradient **line)
346 {
347 COLORREF col = ARGB2COLORREF(startcolor);
348
349 TRACE("(%s, %s, %x, %x, %d, %p)\n", debugstr_pointf(startpoint),
350 debugstr_pointf(endpoint), startcolor, endcolor, wrap, line);
351
352 if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
353 return InvalidParameter;
354
355 *line = GdipAlloc(sizeof(GpLineGradient));
356 if(!*line) return OutOfMemory;
357
358 (*line)->brush.lb.lbStyle = BS_SOLID;
359 (*line)->brush.lb.lbColor = col;
360 (*line)->brush.lb.lbHatch = 0;
361 (*line)->brush.gdibrush = CreateSolidBrush(col);
362 (*line)->brush.bt = BrushTypeLinearGradient;
363
364 (*line)->startpoint.X = startpoint->X;
365 (*line)->startpoint.Y = startpoint->Y;
366 (*line)->endpoint.X = endpoint->X;
367 (*line)->endpoint.Y = endpoint->Y;
368 (*line)->startcolor = startcolor;
369 (*line)->endcolor = endcolor;
370 (*line)->wrap = wrap;
371 (*line)->gamma = FALSE;
372
373 (*line)->rect.X = (startpoint->X < endpoint->X ? startpoint->X: endpoint->X);
374 (*line)->rect.Y = (startpoint->Y < endpoint->Y ? startpoint->Y: endpoint->Y);
375 (*line)->rect.Width = fabs(startpoint->X - endpoint->X);
376 (*line)->rect.Height = fabs(startpoint->Y - endpoint->Y);
377
378 if ((*line)->rect.Width == 0)
379 {
380 (*line)->rect.X -= (*line)->rect.Height / 2.0f;
381 (*line)->rect.Width = (*line)->rect.Height;
382 }
383 else if ((*line)->rect.Height == 0)
384 {
385 (*line)->rect.Y -= (*line)->rect.Width / 2.0f;
386 (*line)->rect.Height = (*line)->rect.Width;
387 }
388
389 (*line)->blendcount = 1;
390 (*line)->blendfac = GdipAlloc(sizeof(REAL));
391 (*line)->blendpos = GdipAlloc(sizeof(REAL));
392
393 if (!(*line)->blendfac || !(*line)->blendpos)
394 {
395 GdipFree((*line)->blendfac);
396 GdipFree((*line)->blendpos);
397 DeleteObject((*line)->brush.gdibrush);
398 GdipFree(*line);
399 *line = NULL;
400 return OutOfMemory;
401 }
402
403 (*line)->blendfac[0] = 1.0f;
404 (*line)->blendpos[0] = 1.0f;
405
406 (*line)->pblendcolor = NULL;
407 (*line)->pblendpos = NULL;
408 (*line)->pblendcount = 0;
409
410 TRACE("<-- %p\n", *line);
411
412 return Ok;
413 }
414
415 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
416 GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
417 GpWrapMode wrap, GpLineGradient **line)
418 {
419 GpPointF stF;
420 GpPointF endF;
421
422 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
423 startcolor, endcolor, wrap, line);
424
425 if(!startpoint || !endpoint)
426 return InvalidParameter;
427
428 stF.X = (REAL)startpoint->X;
429 stF.Y = (REAL)startpoint->Y;
430 endF.X = (REAL)endpoint->X;
431 endF.X = (REAL)endpoint->Y;
432
433 return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
434 }
435
436 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
437 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
438 GpLineGradient **line)
439 {
440 GpPointF start, end;
441 GpStatus stat;
442
443 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
444 wrap, line);
445
446 if(!line || !rect)
447 return InvalidParameter;
448
449 switch (mode)
450 {
451 case LinearGradientModeHorizontal:
452 start.X = rect->X;
453 start.Y = rect->Y;
454 end.X = rect->X + rect->Width;
455 end.Y = rect->Y;
456 break;
457 case LinearGradientModeVertical:
458 start.X = rect->X;
459 start.Y = rect->Y;
460 end.X = rect->X;
461 end.Y = rect->Y + rect->Height;
462 break;
463 case LinearGradientModeForwardDiagonal:
464 start.X = rect->X;
465 start.Y = rect->Y;
466 end.X = rect->X + rect->Width;
467 end.Y = rect->Y + rect->Height;
468 break;
469 case LinearGradientModeBackwardDiagonal:
470 start.X = rect->X + rect->Width;
471 start.Y = rect->Y;
472 end.X = rect->X;
473 end.Y = rect->Y + rect->Height;
474 break;
475 default:
476 return InvalidParameter;
477 }
478
479 stat = GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
480
481 if (stat == Ok)
482 (*line)->rect = *rect;
483
484 return stat;
485 }
486
487 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
488 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
489 GpLineGradient **line)
490 {
491 GpRectF rectF;
492
493 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
494 wrap, line);
495
496 rectF.X = (REAL) rect->X;
497 rectF.Y = (REAL) rect->Y;
498 rectF.Width = (REAL) rect->Width;
499 rectF.Height = (REAL) rect->Height;
500
501 return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
502 }
503
504 /******************************************************************************
505 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
506 */
507 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
508 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
509 GpLineGradient **line)
510 {
511 GpStatus stat;
512 LinearGradientMode mode;
513 REAL width, height, exofs, eyofs;
514 REAL sin_angle, cos_angle, sin_cos_angle;
515
516 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
517 wrap, line);
518
519 sin_angle = sinf(deg2rad(angle));
520 cos_angle = cosf(deg2rad(angle));
521 sin_cos_angle = sin_angle * cos_angle;
522
523 if (isAngleScalable)
524 {
525 width = height = 1.0;
526 }
527 else
528 {
529 width = rect->Width;
530 height = rect->Height;
531 }
532
533 if (sin_cos_angle >= 0)
534 mode = LinearGradientModeForwardDiagonal;
535 else
536 mode = LinearGradientModeBackwardDiagonal;
537
538 stat = GdipCreateLineBrushFromRect(rect, startcolor, endcolor, mode, wrap, line);
539
540 if (stat == Ok)
541 {
542 if (sin_cos_angle >= 0)
543 {
544 exofs = width * sin_cos_angle + height * cos_angle * cos_angle;
545 eyofs = width * sin_angle * sin_angle + height * sin_cos_angle;
546 }
547 else
548 {
549 exofs = width * sin_angle * sin_angle + height * sin_cos_angle;
550 eyofs = -width * sin_cos_angle + height * sin_angle * sin_angle;
551 }
552
553 if (isAngleScalable)
554 {
555 exofs = exofs * rect->Width;
556 eyofs = eyofs * rect->Height;
557 }
558
559 if (sin_angle >= 0)
560 {
561 (*line)->endpoint.X = rect->X + exofs;
562 (*line)->endpoint.Y = rect->Y + eyofs;
563 }
564 else
565 {
566 (*line)->endpoint.X = (*line)->startpoint.X;
567 (*line)->endpoint.Y = (*line)->startpoint.Y;
568 (*line)->startpoint.X = rect->X + exofs;
569 (*line)->startpoint.Y = rect->Y + eyofs;
570 }
571 }
572
573 return stat;
574 }
575
576 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
577 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
578 GpLineGradient **line)
579 {
580 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
581 wrap, line);
582
583 return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
584 wrap, line);
585 }
586
587 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
588 INT count, GpWrapMode wrap, GpPathGradient **grad)
589 {
590 COLORREF col = ARGB2COLORREF(0xffffffff);
591
592 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
593
594 if(!points || !grad)
595 return InvalidParameter;
596
597 if(count <= 0)
598 return OutOfMemory;
599
600 *grad = GdipAlloc(sizeof(GpPathGradient));
601 if (!*grad) return OutOfMemory;
602
603 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
604 (*grad)->blendpos = GdipAlloc(sizeof(REAL));
605 if(!(*grad)->blendfac || !(*grad)->blendpos){
606 GdipFree((*grad)->blendfac);
607 GdipFree((*grad)->blendpos);
608 GdipFree(*grad);
609 return OutOfMemory;
610 }
611 (*grad)->blendfac[0] = 1.0;
612 (*grad)->blendpos[0] = 1.0;
613 (*grad)->blendcount = 1;
614
615 (*grad)->pathdata.Count = count;
616 (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
617 (*grad)->pathdata.Types = GdipAlloc(count);
618
619 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
620 GdipFree((*grad)->pathdata.Points);
621 GdipFree((*grad)->pathdata.Types);
622 GdipFree(*grad);
623 return OutOfMemory;
624 }
625
626 memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
627 memset((*grad)->pathdata.Types, PathPointTypeLine, count);
628
629 (*grad)->brush.lb.lbStyle = BS_SOLID;
630 (*grad)->brush.lb.lbColor = col;
631 (*grad)->brush.lb.lbHatch = 0;
632
633 (*grad)->brush.gdibrush = CreateSolidBrush(col);
634 (*grad)->brush.bt = BrushTypePathGradient;
635 (*grad)->centercolor = 0xffffffff;
636 (*grad)->wrap = wrap;
637 (*grad)->gamma = FALSE;
638 (*grad)->center.X = 0.0;
639 (*grad)->center.Y = 0.0;
640 (*grad)->focus.X = 0.0;
641 (*grad)->focus.Y = 0.0;
642
643 TRACE("<-- %p\n", *grad);
644
645 return Ok;
646 }
647
648 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
649 INT count, GpWrapMode wrap, GpPathGradient **grad)
650 {
651 GpPointF *pointsF;
652 GpStatus ret;
653 INT i;
654
655 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
656
657 if(!points || !grad)
658 return InvalidParameter;
659
660 if(count <= 0)
661 return OutOfMemory;
662
663 pointsF = GdipAlloc(sizeof(GpPointF) * count);
664 if(!pointsF)
665 return OutOfMemory;
666
667 for(i = 0; i < count; i++){
668 pointsF[i].X = (REAL)points[i].X;
669 pointsF[i].Y = (REAL)points[i].Y;
670 }
671
672 ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
673 GdipFree(pointsF);
674
675 return ret;
676 }
677
678 /******************************************************************************
679 * GdipCreatePathGradientFromPath [GDIPLUS.@]
680 *
681 * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
682 */
683 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
684 GpPathGradient **grad)
685 {
686 COLORREF col = ARGB2COLORREF(0xffffffff);
687
688 TRACE("(%p, %p)\n", path, grad);
689
690 if(!path || !grad)
691 return InvalidParameter;
692
693 *grad = GdipAlloc(sizeof(GpPathGradient));
694 if (!*grad) return OutOfMemory;
695
696 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
697 (*grad)->blendpos = GdipAlloc(sizeof(REAL));
698 if(!(*grad)->blendfac || !(*grad)->blendpos){
699 GdipFree((*grad)->blendfac);
700 GdipFree((*grad)->blendpos);
701 GdipFree(*grad);
702 return OutOfMemory;
703 }
704 (*grad)->blendfac[0] = 1.0;
705 (*grad)->blendpos[0] = 1.0;
706 (*grad)->blendcount = 1;
707
708 (*grad)->pathdata.Count = path->pathdata.Count;
709 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
710 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
711
712 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
713 GdipFree((*grad)->pathdata.Points);
714 GdipFree((*grad)->pathdata.Types);
715 GdipFree(*grad);
716 return OutOfMemory;
717 }
718
719 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
720 path->pathdata.Count * sizeof(PointF));
721 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
722
723 (*grad)->brush.lb.lbStyle = BS_SOLID;
724 (*grad)->brush.lb.lbColor = col;
725 (*grad)->brush.lb.lbHatch = 0;
726
727 (*grad)->brush.gdibrush = CreateSolidBrush(col);
728 (*grad)->brush.bt = BrushTypePathGradient;
729 (*grad)->centercolor = 0xffffffff;
730 (*grad)->wrap = WrapModeClamp;
731 (*grad)->gamma = FALSE;
732 /* FIXME: this should be set to the "centroid" of the path by default */
733 (*grad)->center.X = 0.0;
734 (*grad)->center.Y = 0.0;
735 (*grad)->focus.X = 0.0;
736 (*grad)->focus.Y = 0.0;
737
738 TRACE("<-- %p\n", *grad);
739
740 return Ok;
741 }
742
743 /******************************************************************************
744 * GdipCreateSolidFill [GDIPLUS.@]
745 */
746 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
747 {
748 COLORREF col = ARGB2COLORREF(color);
749
750 TRACE("(%x, %p)\n", color, sf);
751
752 if(!sf) return InvalidParameter;
753
754 *sf = GdipAlloc(sizeof(GpSolidFill));
755 if (!*sf) return OutOfMemory;
756
757 (*sf)->brush.lb.lbStyle = BS_SOLID;
758 (*sf)->brush.lb.lbColor = col;
759 (*sf)->brush.lb.lbHatch = 0;
760
761 (*sf)->brush.gdibrush = CreateSolidBrush(col);
762 (*sf)->brush.bt = BrushTypeSolidColor;
763 (*sf)->color = color;
764 (*sf)->bmp = ARGB2BMP(color);
765
766 TRACE("<-- %p\n", *sf);
767
768 return Ok;
769 }
770
771 /******************************************************************************
772 * GdipCreateTexture [GDIPLUS.@]
773 *
774 * PARAMS
775 * image [I] image to use
776 * wrapmode [I] optional
777 * texture [O] pointer to the resulting texturebrush
778 *
779 * RETURNS
780 * SUCCESS: Ok
781 * FAILURE: element of GpStatus
782 */
783 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
784 GpTexture **texture)
785 {
786 UINT width, height;
787 GpImageAttributes attributes;
788 GpStatus stat;
789
790 TRACE("%p, %d %p\n", image, wrapmode, texture);
791
792 if (!(image && texture))
793 return InvalidParameter;
794
795 stat = GdipGetImageWidth(image, &width);
796 if (stat != Ok) return stat;
797 stat = GdipGetImageHeight(image, &height);
798 if (stat != Ok) return stat;
799 attributes.wrap = wrapmode;
800
801 return GdipCreateTextureIA(image, &attributes, 0, 0, width, height,
802 texture);
803 }
804
805 /******************************************************************************
806 * GdipCreateTexture2 [GDIPLUS.@]
807 */
808 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
809 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
810 {
811 GpImageAttributes attributes;
812
813 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
814 x, y, width, height, texture);
815
816 attributes.wrap = wrapmode;
817 return GdipCreateTextureIA(image, &attributes, x, y, width, height,
818 texture);
819 }
820
821 /******************************************************************************
822 * GdipCreateTextureIA [GDIPLUS.@]
823 *
824 * FIXME: imageattr ignored
825 */
826 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
827 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
828 REAL height, GpTexture **texture)
829 {
830 HBITMAP hbm=NULL;
831 GpStatus status;
832 GpImage *new_image=NULL;
833
834 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
835 texture);
836
837 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
838 return InvalidParameter;
839
840 *texture = NULL;
841
842 if(image->type != ImageTypeBitmap){
843 FIXME("not implemented for image type %d\n", image->type);
844 return NotImplemented;
845 }
846
847 status = GdipCloneBitmapArea(x, y, width, height, PixelFormatDontCare, (GpBitmap*)image, (GpBitmap**)&new_image);
848 if (status != Ok)
849 return status;
850
851 status = GdipCreateHBITMAPFromBitmap((GpBitmap*)new_image, &hbm, 0);
852 if(!hbm)
853 {
854 status = GenericError;
855 goto exit;
856 }
857
858 *texture = GdipAlloc(sizeof(GpTexture));
859 if (!*texture){
860 status = OutOfMemory;
861 goto exit;
862 }
863
864 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
865 goto exit;
866 }
867
868 (*texture)->brush.lb.lbStyle = BS_PATTERN;
869 (*texture)->brush.lb.lbColor = 0;
870 (*texture)->brush.lb.lbHatch = (ULONG_PTR)hbm;
871
872 (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
873 (*texture)->brush.bt = BrushTypeTextureFill;
874 if (imageattr)
875 (*texture)->wrap = imageattr->wrap;
876 else
877 (*texture)->wrap = WrapModeTile;
878 (*texture)->image = new_image;
879
880 exit:
881 if (status == Ok)
882 {
883 TRACE("<-- %p\n", *texture);
884 }
885 else
886 {
887 if (*texture)
888 {
889 GdipDeleteMatrix((*texture)->transform);
890 GdipFree(*texture);
891 *texture = NULL;
892 }
893 GdipDisposeImage(new_image);
894 TRACE("<-- error %u\n", status);
895 }
896
897 DeleteObject(hbm);
898
899 return status;
900 }
901
902 /******************************************************************************
903 * GdipCreateTextureIAI [GDIPLUS.@]
904 */
905 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
906 INT x, INT y, INT width, INT height, GpTexture **texture)
907 {
908 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
909 texture);
910
911 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
912 }
913
914 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
915 INT x, INT y, INT width, INT height, GpTexture **texture)
916 {
917 GpImageAttributes imageattr;
918
919 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
920 texture);
921
922 imageattr.wrap = wrapmode;
923
924 return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
925 }
926
927 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
928 {
929 TRACE("(%p, %p)\n", brush, type);
930
931 if(!brush || !type) return InvalidParameter;
932
933 *type = brush->bt;
934
935 return Ok;
936 }
937
938 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
939 {
940 TRACE("(%p, %p)\n", brush, backcol);
941
942 if(!brush || !backcol) return InvalidParameter;
943
944 *backcol = brush->backcol;
945
946 return Ok;
947 }
948
949 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
950 {
951 TRACE("(%p, %p)\n", brush, forecol);
952
953 if(!brush || !forecol) return InvalidParameter;
954
955 *forecol = brush->forecol;
956
957 return Ok;
958 }
959
960 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
961 {
962 TRACE("(%p, %p)\n", brush, hatchstyle);
963
964 if(!brush || !hatchstyle) return InvalidParameter;
965
966 *hatchstyle = brush->hatchstyle;
967
968 return Ok;
969 }
970
971 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
972 {
973 TRACE("(%p)\n", brush);
974
975 if(!brush) return InvalidParameter;
976
977 switch(brush->bt)
978 {
979 case BrushTypePathGradient:
980 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
981 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
982 GdipFree(((GpPathGradient*) brush)->blendfac);
983 GdipFree(((GpPathGradient*) brush)->blendpos);
984 break;
985 case BrushTypeSolidColor:
986 if (((GpSolidFill*)brush)->bmp)
987 DeleteObject(((GpSolidFill*)brush)->bmp);
988 break;
989 case BrushTypeLinearGradient:
990 GdipFree(((GpLineGradient*)brush)->blendfac);
991 GdipFree(((GpLineGradient*)brush)->blendpos);
992 GdipFree(((GpLineGradient*)brush)->pblendcolor);
993 GdipFree(((GpLineGradient*)brush)->pblendpos);
994 break;
995 case BrushTypeTextureFill:
996 GdipDeleteMatrix(((GpTexture*)brush)->transform);
997 GdipDisposeImage(((GpTexture*)brush)->image);
998 break;
999 default:
1000 break;
1001 }
1002
1003 DeleteObject(brush->gdibrush);
1004 GdipFree(brush);
1005
1006 return Ok;
1007 }
1008
1009 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
1010 BOOL *usinggamma)
1011 {
1012 TRACE("(%p, %p)\n", line, usinggamma);
1013
1014 if(!line || !usinggamma)
1015 return InvalidParameter;
1016
1017 *usinggamma = line->gamma;
1018
1019 return Ok;
1020 }
1021
1022 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
1023 {
1024 TRACE("(%p, %p)\n", brush, wrapmode);
1025
1026 if(!brush || !wrapmode)
1027 return InvalidParameter;
1028
1029 *wrapmode = brush->wrap;
1030
1031 return Ok;
1032 }
1033
1034 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
1035 REAL *positions, INT count)
1036 {
1037 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
1038
1039 if(!brush || !blend || !positions || count <= 0)
1040 return InvalidParameter;
1041
1042 if(count < brush->blendcount)
1043 return InsufficientBuffer;
1044
1045 memcpy(blend, brush->blendfac, count*sizeof(REAL));
1046 if(brush->blendcount > 1){
1047 memcpy(positions, brush->blendpos, count*sizeof(REAL));
1048 }
1049
1050 return Ok;
1051 }
1052
1053 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
1054 {
1055 TRACE("(%p, %p)\n", brush, count);
1056
1057 if(!brush || !count)
1058 return InvalidParameter;
1059
1060 *count = brush->blendcount;
1061
1062 return Ok;
1063 }
1064
1065 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
1066 GpPointF *point)
1067 {
1068 TRACE("(%p, %p)\n", grad, point);
1069
1070 if(!grad || !point)
1071 return InvalidParameter;
1072
1073 point->X = grad->center.X;
1074 point->Y = grad->center.Y;
1075
1076 return Ok;
1077 }
1078
1079 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
1080 GpPoint *point)
1081 {
1082 GpStatus ret;
1083 GpPointF ptf;
1084
1085 TRACE("(%p, %p)\n", grad, point);
1086
1087 if(!point)
1088 return InvalidParameter;
1089
1090 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
1091
1092 if(ret == Ok){
1093 point->X = roundr(ptf.X);
1094 point->Y = roundr(ptf.Y);
1095 }
1096
1097 return ret;
1098 }
1099
1100 GpStatus WINGDIPAPI GdipGetPathGradientCenterColor(GpPathGradient *grad,
1101 ARGB *colors)
1102 {
1103 static int calls;
1104
1105 TRACE("(%p,%p)\n", grad, colors);
1106
1107 if(!(calls++))
1108 FIXME("not implemented\n");
1109
1110 return NotImplemented;
1111 }
1112
1113 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
1114 REAL *x, REAL *y)
1115 {
1116 TRACE("(%p, %p, %p)\n", grad, x, y);
1117
1118 if(!grad || !x || !y)
1119 return InvalidParameter;
1120
1121 *x = grad->focus.X;
1122 *y = grad->focus.Y;
1123
1124 return Ok;
1125 }
1126
1127 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1128 BOOL *gamma)
1129 {
1130 TRACE("(%p, %p)\n", grad, gamma);
1131
1132 if(!grad || !gamma)
1133 return InvalidParameter;
1134
1135 *gamma = grad->gamma;
1136
1137 return Ok;
1138 }
1139
1140 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1141 INT *count)
1142 {
1143 TRACE("(%p, %p)\n", grad, count);
1144
1145 if(!grad || !count)
1146 return InvalidParameter;
1147
1148 *count = grad->pathdata.Count;
1149
1150 return Ok;
1151 }
1152
1153 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1154 {
1155 GpRectF r;
1156 GpPath* path;
1157 GpStatus stat;
1158
1159 TRACE("(%p, %p)\n", brush, rect);
1160
1161 if(!brush || !rect)
1162 return InvalidParameter;
1163
1164 stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
1165 brush->pathdata.Count, FillModeAlternate, &path);
1166 if(stat != Ok) return stat;
1167
1168 stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
1169 if(stat != Ok){
1170 GdipDeletePath(path);
1171 return stat;
1172 }
1173
1174 memcpy(rect, &r, sizeof(GpRectF));
1175
1176 GdipDeletePath(path);
1177
1178 return Ok;
1179 }
1180
1181 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1182 {
1183 GpRectF rectf;
1184 GpStatus stat;
1185
1186 TRACE("(%p, %p)\n", brush, rect);
1187
1188 if(!brush || !rect)
1189 return InvalidParameter;
1190
1191 stat = GdipGetPathGradientRect(brush, &rectf);
1192 if(stat != Ok) return stat;
1193
1194 rect->X = roundr(rectf.X);
1195 rect->Y = roundr(rectf.Y);
1196 rect->Width = roundr(rectf.Width);
1197 rect->Height = roundr(rectf.Height);
1198
1199 return Ok;
1200 }
1201
1202 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1203 *grad, ARGB *argb, INT *count)
1204 {
1205 static int calls;
1206
1207 TRACE("(%p,%p,%p)\n", grad, argb, count);
1208
1209 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
1210 return InvalidParameter;
1211
1212 if(!(calls++))
1213 FIXME("not implemented\n");
1214
1215 return NotImplemented;
1216 }
1217
1218 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorCount(GpPathGradient *brush, INT *count)
1219 {
1220 TRACE("(%p, %p)\n", brush, count);
1221
1222 if (!brush || !count)
1223 return InvalidParameter;
1224
1225 return NotImplemented;
1226 }
1227
1228 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1229 GpWrapMode *wrapmode)
1230 {
1231 TRACE("(%p, %p)\n", brush, wrapmode);
1232
1233 if(!brush || !wrapmode)
1234 return InvalidParameter;
1235
1236 *wrapmode = brush->wrap;
1237
1238 return Ok;
1239 }
1240
1241 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1242 {
1243 TRACE("(%p, %p)\n", sf, argb);
1244
1245 if(!sf || !argb)
1246 return InvalidParameter;
1247
1248 *argb = sf->color;
1249
1250 return Ok;
1251 }
1252
1253 /******************************************************************************
1254 * GdipGetTextureImage [GDIPLUS.@]
1255 */
1256 GpStatus WINGDIPAPI GdipGetTextureImage(GpTexture *brush, GpImage **image)
1257 {
1258 TRACE("(%p, %p)\n", brush, image);
1259
1260 if(!brush || !image)
1261 return InvalidParameter;
1262
1263 return GdipCloneImage(brush->image, image);
1264 }
1265
1266 /******************************************************************************
1267 * GdipGetTextureTransform [GDIPLUS.@]
1268 */
1269 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1270 {
1271 TRACE("(%p, %p)\n", brush, matrix);
1272
1273 if(!brush || !matrix)
1274 return InvalidParameter;
1275
1276 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1277
1278 return Ok;
1279 }
1280
1281 /******************************************************************************
1282 * GdipGetTextureWrapMode [GDIPLUS.@]
1283 */
1284 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1285 {
1286 TRACE("(%p, %p)\n", brush, wrapmode);
1287
1288 if(!brush || !wrapmode)
1289 return InvalidParameter;
1290
1291 *wrapmode = brush->wrap;
1292
1293 return Ok;
1294 }
1295
1296 /******************************************************************************
1297 * GdipMultiplyTextureTransform [GDIPLUS.@]
1298 */
1299 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1300 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1301 {
1302 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1303
1304 if(!brush || !matrix)
1305 return InvalidParameter;
1306
1307 return GdipMultiplyMatrix(brush->transform, matrix, order);
1308 }
1309
1310 /******************************************************************************
1311 * GdipResetTextureTransform [GDIPLUS.@]
1312 */
1313 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1314 {
1315 TRACE("(%p)\n", brush);
1316
1317 if(!brush)
1318 return InvalidParameter;
1319
1320 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1321 }
1322
1323 /******************************************************************************
1324 * GdipScaleTextureTransform [GDIPLUS.@]
1325 */
1326 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1327 REAL sx, REAL sy, GpMatrixOrder order)
1328 {
1329 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1330
1331 if(!brush)
1332 return InvalidParameter;
1333
1334 return GdipScaleMatrix(brush->transform, sx, sy, order);
1335 }
1336
1337 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1338 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1339 {
1340 REAL *new_blendfac, *new_blendpos;
1341
1342 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1343
1344 if(!brush || !factors || !positions || count <= 0 ||
1345 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1346 return InvalidParameter;
1347
1348 new_blendfac = GdipAlloc(count * sizeof(REAL));
1349 new_blendpos = GdipAlloc(count * sizeof(REAL));
1350
1351 if (!new_blendfac || !new_blendpos)
1352 {
1353 GdipFree(new_blendfac);
1354 GdipFree(new_blendpos);
1355 return OutOfMemory;
1356 }
1357
1358 memcpy(new_blendfac, factors, count * sizeof(REAL));
1359 memcpy(new_blendpos, positions, count * sizeof(REAL));
1360
1361 GdipFree(brush->blendfac);
1362 GdipFree(brush->blendpos);
1363
1364 brush->blendcount = count;
1365 brush->blendfac = new_blendfac;
1366 brush->blendpos = new_blendpos;
1367
1368 return Ok;
1369 }
1370
1371 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1372 REAL *positions, INT count)
1373 {
1374 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1375
1376 if (!brush || !factors || !positions || count <= 0)
1377 return InvalidParameter;
1378
1379 if (count < brush->blendcount)
1380 return InsufficientBuffer;
1381
1382 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1383 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1384
1385 return Ok;
1386 }
1387
1388 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1389 {
1390 TRACE("(%p, %p)\n", brush, count);
1391
1392 if (!brush || !count)
1393 return InvalidParameter;
1394
1395 *count = brush->blendcount;
1396
1397 return Ok;
1398 }
1399
1400 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1401 BOOL usegamma)
1402 {
1403 TRACE("(%p, %d)\n", line, usegamma);
1404
1405 if(!line)
1406 return InvalidParameter;
1407
1408 line->gamma = usegamma;
1409
1410 return Ok;
1411 }
1412
1413 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1414 REAL scale)
1415 {
1416 REAL factors[33];
1417 REAL positions[33];
1418 int num_points = 0;
1419 int i;
1420 const int precision = 16;
1421 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1422 REAL min_erf;
1423 REAL scale_erf;
1424
1425 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1426
1427 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1428 return InvalidParameter;
1429
1430 /* we want 2 standard deviations */
1431 erf_range = 2.0 / sqrt(2);
1432
1433 /* calculate the constants we need to normalize the error function to be
1434 between 0.0 and scale over the range we need */
1435 min_erf = erf(-erf_range);
1436 scale_erf = scale / (-2.0 * min_erf);
1437
1438 if (focus != 0.0)
1439 {
1440 positions[0] = 0.0;
1441 factors[0] = 0.0;
1442 for (i=1; i<precision; i++)
1443 {
1444 positions[i] = focus * i / precision;
1445 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1446 }
1447 num_points += precision;
1448 }
1449
1450 positions[num_points] = focus;
1451 factors[num_points] = scale;
1452 num_points += 1;
1453
1454 if (focus != 1.0)
1455 {
1456 for (i=1; i<precision; i++)
1457 {
1458 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1459 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1460 }
1461 num_points += precision;
1462 positions[num_points-1] = 1.0;
1463 factors[num_points-1] = 0.0;
1464 }
1465
1466 return GdipSetLineBlend(line, factors, positions, num_points);
1467 }
1468
1469 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1470 GpWrapMode wrap)
1471 {
1472 TRACE("(%p, %d)\n", line, wrap);
1473
1474 if(!line || wrap == WrapModeClamp)
1475 return InvalidParameter;
1476
1477 line->wrap = wrap;
1478
1479 return Ok;
1480 }
1481
1482 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1483 GDIPCONST REAL *pos, INT count)
1484 {
1485 static int calls;
1486
1487 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1488
1489 if(!(calls++))
1490 FIXME("not implemented\n");
1491
1492 return NotImplemented;
1493 }
1494
1495 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1496 GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1497 {
1498 FIXME("(%p,%p,%p,%i): stub\n", brush, blend, pos, count);
1499 return NotImplemented;
1500 }
1501
1502 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1503 ARGB argb)
1504 {
1505 TRACE("(%p, %x)\n", grad, argb);
1506
1507 if(!grad)
1508 return InvalidParameter;
1509
1510 grad->centercolor = argb;
1511 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1512
1513 DeleteObject(grad->brush.gdibrush);
1514 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1515
1516 return Ok;
1517 }
1518
1519 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1520 GpPointF *point)
1521 {
1522 TRACE("(%p, %s)\n", grad, debugstr_pointf(point));
1523
1524 if(!grad || !point)
1525 return InvalidParameter;
1526
1527 grad->center.X = point->X;
1528 grad->center.Y = point->Y;
1529
1530 return Ok;
1531 }
1532
1533 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1534 GpPoint *point)
1535 {
1536 GpPointF ptf;
1537
1538 TRACE("(%p, %p)\n", grad, point);
1539
1540 if(!point)
1541 return InvalidParameter;
1542
1543 ptf.X = (REAL)point->X;
1544 ptf.Y = (REAL)point->Y;
1545
1546 return GdipSetPathGradientCenterPoint(grad,&ptf);
1547 }
1548
1549 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1550 REAL x, REAL y)
1551 {
1552 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1553
1554 if(!grad)
1555 return InvalidParameter;
1556
1557 grad->focus.X = x;
1558 grad->focus.Y = y;
1559
1560 return Ok;
1561 }
1562
1563 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1564 BOOL gamma)
1565 {
1566 TRACE("(%p, %d)\n", grad, gamma);
1567
1568 if(!grad)
1569 return InvalidParameter;
1570
1571 grad->gamma = gamma;
1572
1573 return Ok;
1574 }
1575
1576 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1577 REAL focus, REAL scale)
1578 {
1579 static int calls;
1580
1581 TRACE("(%p,%0.2f,%0.2f)\n", grad, focus, scale);
1582
1583 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1584 return InvalidParameter;
1585
1586 if(!(calls++))
1587 FIXME("not implemented\n");
1588
1589 return NotImplemented;
1590 }
1591
1592 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1593 *grad, GDIPCONST ARGB *argb, INT *count)
1594 {
1595 static int calls;
1596
1597 TRACE("(%p,%p,%p)\n", grad, argb, count);
1598
1599 if(!grad || !argb || !count || (*count <= 0) ||
1600 (*count > grad->pathdata.Count))
1601 return InvalidParameter;
1602
1603 if(!(calls++))
1604 FIXME("not implemented\n");
1605
1606 return NotImplemented;
1607 }
1608
1609 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1610 GpWrapMode wrap)
1611 {
1612 TRACE("(%p, %d)\n", grad, wrap);
1613
1614 if(!grad)
1615 return InvalidParameter;
1616
1617 grad->wrap = wrap;
1618
1619 return Ok;
1620 }
1621
1622 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1623 {
1624 TRACE("(%p, %x)\n", sf, argb);
1625
1626 if(!sf)
1627 return InvalidParameter;
1628
1629 sf->color = argb;
1630 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1631
1632 DeleteObject(sf->brush.gdibrush);
1633 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1634
1635 return Ok;
1636 }
1637
1638 /******************************************************************************
1639 * GdipSetTextureTransform [GDIPLUS.@]
1640 */
1641 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1642 GDIPCONST GpMatrix *matrix)
1643 {
1644 TRACE("(%p, %p)\n", texture, matrix);
1645
1646 if(!texture || !matrix)
1647 return InvalidParameter;
1648
1649 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1650
1651 return Ok;
1652 }
1653
1654 /******************************************************************************
1655 * GdipSetTextureWrapMode [GDIPLUS.@]
1656 *
1657 * WrapMode not used, only stored
1658 */
1659 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1660 {
1661 TRACE("(%p, %d)\n", brush, wrapmode);
1662
1663 if(!brush)
1664 return InvalidParameter;
1665
1666 brush->wrap = wrapmode;
1667
1668 return Ok;
1669 }
1670
1671 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1672 ARGB color2)
1673 {
1674 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1675
1676 if(!brush)
1677 return InvalidParameter;
1678
1679 brush->startcolor = color1;
1680 brush->endcolor = color2;
1681
1682 return Ok;
1683 }
1684
1685 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1686 {
1687 TRACE("(%p, %p)\n", brush, colors);
1688
1689 if(!brush || !colors)
1690 return InvalidParameter;
1691
1692 colors[0] = brush->startcolor;
1693 colors[1] = brush->endcolor;
1694
1695 return Ok;
1696 }
1697
1698 /******************************************************************************
1699 * GdipRotateTextureTransform [GDIPLUS.@]
1700 */
1701 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1702 GpMatrixOrder order)
1703 {
1704 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1705
1706 if(!brush)
1707 return InvalidParameter;
1708
1709 return GdipRotateMatrix(brush->transform, angle, order);
1710 }
1711
1712 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1713 REAL scale)
1714 {
1715 REAL factors[3];
1716 REAL positions[3];
1717 int num_points = 0;
1718
1719 TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1720
1721 if (!brush) return InvalidParameter;
1722
1723 if (focus != 0.0)
1724 {
1725 factors[num_points] = 0.0;
1726 positions[num_points] = 0.0;
1727 num_points++;
1728 }
1729
1730 factors[num_points] = scale;
1731 positions[num_points] = focus;
1732 num_points++;
1733
1734 if (focus != 1.0)
1735 {
1736 factors[num_points] = 0.0;
1737 positions[num_points] = 1.0;
1738 num_points++;
1739 }
1740
1741 return GdipSetLineBlend(brush, factors, positions, num_points);
1742 }
1743
1744 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1745 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1746 {
1747 ARGB *new_color;
1748 REAL *new_pos;
1749 TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1750
1751 if (!brush || !blend || !positions || count < 2 ||
1752 positions[0] != 0.0f || positions[count-1] != 1.0f)
1753 {
1754 return InvalidParameter;
1755 }
1756
1757 new_color = GdipAlloc(count * sizeof(ARGB));
1758 new_pos = GdipAlloc(count * sizeof(REAL));
1759 if (!new_color || !new_pos)
1760 {
1761 GdipFree(new_color);
1762 GdipFree(new_pos);
1763 return OutOfMemory;
1764 }
1765
1766 memcpy(new_color, blend, sizeof(ARGB) * count);
1767 memcpy(new_pos, positions, sizeof(REAL) * count);
1768
1769 GdipFree(brush->pblendcolor);
1770 GdipFree(brush->pblendpos);
1771
1772 brush->pblendcolor = new_color;
1773 brush->pblendpos = new_pos;
1774 brush->pblendcount = count;
1775
1776 return Ok;
1777 }
1778
1779 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1780 ARGB *blend, REAL* positions, INT count)
1781 {
1782 if (!brush || !blend || !positions || count < 2)
1783 return InvalidParameter;
1784
1785 if (brush->pblendcount == 0)
1786 return GenericError;
1787
1788 if (count < brush->pblendcount)
1789 return InsufficientBuffer;
1790
1791 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1792 memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1793
1794 return Ok;
1795 }
1796
1797 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1798 INT *count)
1799 {
1800 if (!brush || !count)
1801 return InvalidParameter;
1802
1803 *count = brush->pblendcount;
1804
1805 return Ok;
1806 }
1807
1808 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1809 {
1810 static int calls;
1811
1812 TRACE("(%p)\n", brush);
1813
1814 if(!(calls++))
1815 FIXME("not implemented\n");
1816
1817 return NotImplemented;
1818 }
1819
1820 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1821 GDIPCONST GpMatrix *matrix)
1822 {
1823 static int calls;
1824
1825 TRACE("(%p,%p)\n", brush, matrix);
1826
1827 if(!(calls++))
1828 FIXME("not implemented\n");
1829
1830 return NotImplemented;
1831 }
1832
1833 GpStatus WINGDIPAPI GdipGetLineTransform(GpLineGradient *brush, GpMatrix *matrix)
1834 {
1835 static int calls;
1836
1837 TRACE("(%p,%p)\n", brush, matrix);
1838
1839 if(!(calls++))
1840 FIXME("not implemented\n");
1841
1842 return NotImplemented;
1843 }
1844
1845 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
1846 GpMatrixOrder order)
1847 {
1848 static int calls;
1849
1850 TRACE("(%p,%0.2f,%0.2f,%u)\n", brush, sx, sy, order);
1851
1852 if(!(calls++))
1853 FIXME("not implemented\n");
1854
1855 return NotImplemented;
1856 }
1857
1858 GpStatus WINGDIPAPI GdipMultiplyLineTransform(GpLineGradient *brush,
1859 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1860 {
1861 static int calls;
1862
1863 TRACE("(%p,%p,%u)\n", brush, matrix, order);
1864
1865 if(!(calls++))
1866 FIXME("not implemented\n");
1867
1868 return NotImplemented;
1869 }
1870
1871 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1872 REAL dx, REAL dy, GpMatrixOrder order)
1873 {
1874 FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1875
1876 return NotImplemented;
1877 }
1878
1879 /******************************************************************************
1880 * GdipTranslateTextureTransform [GDIPLUS.@]
1881 */
1882 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1883 GpMatrixOrder order)
1884 {
1885 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1886
1887 if(!brush)
1888 return InvalidParameter;
1889
1890 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1891 }
1892
1893 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1894 {
1895 TRACE("(%p, %p)\n", brush, rect);
1896
1897 if(!brush || !rect)
1898 return InvalidParameter;
1899
1900 *rect = brush->rect;
1901
1902 return Ok;
1903 }
1904
1905 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1906 {
1907 GpRectF rectF;
1908 GpStatus ret;
1909
1910 TRACE("(%p, %p)\n", brush, rect);
1911
1912 if(!rect)
1913 return InvalidParameter;
1914
1915 ret = GdipGetLineRect(brush, &rectF);
1916
1917 if(ret == Ok){
1918 rect->X = roundr(rectF.X);
1919 rect->Y = roundr(rectF.Y);
1920 rect->Width = roundr(rectF.Width);
1921 rect->Height = roundr(rectF.Height);
1922 }
1923
1924 return ret;
1925 }
1926
1927 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1928 REAL angle, GpMatrixOrder order)
1929 {
1930 static int calls;
1931
1932 TRACE("(%p,%0.2f,%u)\n", brush, angle, order);
1933
1934 if(!brush)
1935 return InvalidParameter;
1936
1937 if(!(calls++))
1938 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1939
1940 return NotImplemented;
1941 }