Sync with trunk head
[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 if(!(*grad)->blendfac){
605 GdipFree(*grad);
606 return OutOfMemory;
607 }
608 (*grad)->blendfac[0] = 1.0;
609 (*grad)->blendpos = NULL;
610 (*grad)->blendcount = 1;
611
612 (*grad)->pathdata.Count = count;
613 (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
614 (*grad)->pathdata.Types = GdipAlloc(count);
615
616 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
617 GdipFree((*grad)->pathdata.Points);
618 GdipFree((*grad)->pathdata.Types);
619 GdipFree(*grad);
620 return OutOfMemory;
621 }
622
623 memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
624 memset((*grad)->pathdata.Types, PathPointTypeLine, count);
625
626 (*grad)->brush.lb.lbStyle = BS_SOLID;
627 (*grad)->brush.lb.lbColor = col;
628 (*grad)->brush.lb.lbHatch = 0;
629
630 (*grad)->brush.gdibrush = CreateSolidBrush(col);
631 (*grad)->brush.bt = BrushTypePathGradient;
632 (*grad)->centercolor = 0xffffffff;
633 (*grad)->wrap = wrap;
634 (*grad)->gamma = FALSE;
635 (*grad)->center.X = 0.0;
636 (*grad)->center.Y = 0.0;
637 (*grad)->focus.X = 0.0;
638 (*grad)->focus.Y = 0.0;
639
640 TRACE("<-- %p\n", *grad);
641
642 return Ok;
643 }
644
645 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
646 INT count, GpWrapMode wrap, GpPathGradient **grad)
647 {
648 GpPointF *pointsF;
649 GpStatus ret;
650 INT i;
651
652 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
653
654 if(!points || !grad)
655 return InvalidParameter;
656
657 if(count <= 0)
658 return OutOfMemory;
659
660 pointsF = GdipAlloc(sizeof(GpPointF) * count);
661 if(!pointsF)
662 return OutOfMemory;
663
664 for(i = 0; i < count; i++){
665 pointsF[i].X = (REAL)points[i].X;
666 pointsF[i].Y = (REAL)points[i].Y;
667 }
668
669 ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
670 GdipFree(pointsF);
671
672 return ret;
673 }
674
675 /******************************************************************************
676 * GdipCreatePathGradientFromPath [GDIPLUS.@]
677 *
678 * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
679 */
680 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
681 GpPathGradient **grad)
682 {
683 COLORREF col = ARGB2COLORREF(0xffffffff);
684
685 TRACE("(%p, %p)\n", path, grad);
686
687 if(!path || !grad)
688 return InvalidParameter;
689
690 *grad = GdipAlloc(sizeof(GpPathGradient));
691 if (!*grad) return OutOfMemory;
692
693 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
694 if(!(*grad)->blendfac){
695 GdipFree(*grad);
696 return OutOfMemory;
697 }
698 (*grad)->blendfac[0] = 1.0;
699 (*grad)->blendpos = NULL;
700 (*grad)->blendcount = 1;
701
702 (*grad)->pathdata.Count = path->pathdata.Count;
703 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
704 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
705
706 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
707 GdipFree((*grad)->pathdata.Points);
708 GdipFree((*grad)->pathdata.Types);
709 GdipFree(*grad);
710 return OutOfMemory;
711 }
712
713 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
714 path->pathdata.Count * sizeof(PointF));
715 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
716
717 (*grad)->brush.lb.lbStyle = BS_SOLID;
718 (*grad)->brush.lb.lbColor = col;
719 (*grad)->brush.lb.lbHatch = 0;
720
721 (*grad)->brush.gdibrush = CreateSolidBrush(col);
722 (*grad)->brush.bt = BrushTypePathGradient;
723 (*grad)->centercolor = 0xffffffff;
724 (*grad)->wrap = WrapModeClamp;
725 (*grad)->gamma = FALSE;
726 /* FIXME: this should be set to the "centroid" of the path by default */
727 (*grad)->center.X = 0.0;
728 (*grad)->center.Y = 0.0;
729 (*grad)->focus.X = 0.0;
730 (*grad)->focus.Y = 0.0;
731
732 TRACE("<-- %p\n", *grad);
733
734 return Ok;
735 }
736
737 /******************************************************************************
738 * GdipCreateSolidFill [GDIPLUS.@]
739 */
740 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
741 {
742 COLORREF col = ARGB2COLORREF(color);
743
744 TRACE("(%x, %p)\n", color, sf);
745
746 if(!sf) return InvalidParameter;
747
748 *sf = GdipAlloc(sizeof(GpSolidFill));
749 if (!*sf) return OutOfMemory;
750
751 (*sf)->brush.lb.lbStyle = BS_SOLID;
752 (*sf)->brush.lb.lbColor = col;
753 (*sf)->brush.lb.lbHatch = 0;
754
755 (*sf)->brush.gdibrush = CreateSolidBrush(col);
756 (*sf)->brush.bt = BrushTypeSolidColor;
757 (*sf)->color = color;
758 (*sf)->bmp = ARGB2BMP(color);
759
760 TRACE("<-- %p\n", *sf);
761
762 return Ok;
763 }
764
765 /******************************************************************************
766 * GdipCreateTexture [GDIPLUS.@]
767 *
768 * PARAMS
769 * image [I] image to use
770 * wrapmode [I] optional
771 * texture [O] pointer to the resulting texturebrush
772 *
773 * RETURNS
774 * SUCCESS: Ok
775 * FAILURE: element of GpStatus
776 */
777 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
778 GpTexture **texture)
779 {
780 UINT width, height;
781 GpImageAttributes attributes;
782 GpStatus stat;
783
784 TRACE("%p, %d %p\n", image, wrapmode, texture);
785
786 if (!(image && texture))
787 return InvalidParameter;
788
789 stat = GdipGetImageWidth(image, &width);
790 if (stat != Ok) return stat;
791 stat = GdipGetImageHeight(image, &height);
792 if (stat != Ok) return stat;
793 attributes.wrap = wrapmode;
794
795 return GdipCreateTextureIA(image, &attributes, 0, 0, width, height,
796 texture);
797 }
798
799 /******************************************************************************
800 * GdipCreateTexture2 [GDIPLUS.@]
801 */
802 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
803 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
804 {
805 GpImageAttributes attributes;
806
807 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
808 x, y, width, height, texture);
809
810 attributes.wrap = wrapmode;
811 return GdipCreateTextureIA(image, &attributes, x, y, width, height,
812 texture);
813 }
814
815 /******************************************************************************
816 * GdipCreateTextureIA [GDIPLUS.@]
817 *
818 * FIXME: imageattr ignored
819 */
820 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
821 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
822 REAL height, GpTexture **texture)
823 {
824 HBITMAP hbm;
825 GpStatus status;
826 GpImage *new_image=NULL;
827
828 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
829 texture);
830
831 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
832 return InvalidParameter;
833
834 *texture = NULL;
835
836 if(image->type != ImageTypeBitmap){
837 FIXME("not implemented for image type %d\n", image->type);
838 return NotImplemented;
839 }
840
841 status = GdipCloneBitmapArea(x, y, width, height, PixelFormatDontCare, (GpBitmap*)image, (GpBitmap**)&new_image);
842 if (status != Ok)
843 return status;
844
845 hbm = ((GpBitmap*)new_image)->hbitmap;
846 if(!hbm)
847 {
848 status = GenericError;
849 goto exit;
850 }
851
852 *texture = GdipAlloc(sizeof(GpTexture));
853 if (!*texture){
854 status = OutOfMemory;
855 goto exit;
856 }
857
858 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
859 goto exit;
860 }
861
862 (*texture)->brush.lb.lbStyle = BS_PATTERN;
863 (*texture)->brush.lb.lbColor = 0;
864 (*texture)->brush.lb.lbHatch = (ULONG_PTR)hbm;
865
866 (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
867 (*texture)->brush.bt = BrushTypeTextureFill;
868 (*texture)->wrap = imageattr->wrap;
869 (*texture)->image = new_image;
870
871 exit:
872 if (status == Ok)
873 {
874 TRACE("<-- %p\n", *texture);
875 }
876 else
877 {
878 if (*texture)
879 {
880 GdipDeleteMatrix((*texture)->transform);
881 GdipFree(*texture);
882 *texture = NULL;
883 }
884 GdipDisposeImage(new_image);
885 TRACE("<-- error %u\n", status);
886 }
887
888 return status;
889 }
890
891 /******************************************************************************
892 * GdipCreateTextureIAI [GDIPLUS.@]
893 */
894 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
895 INT x, INT y, INT width, INT height, GpTexture **texture)
896 {
897 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
898 texture);
899
900 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
901 }
902
903 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
904 INT x, INT y, INT width, INT height, GpTexture **texture)
905 {
906 GpImageAttributes imageattr;
907
908 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
909 texture);
910
911 imageattr.wrap = wrapmode;
912
913 return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
914 }
915
916 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
917 {
918 TRACE("(%p, %p)\n", brush, type);
919
920 if(!brush || !type) return InvalidParameter;
921
922 *type = brush->bt;
923
924 return Ok;
925 }
926
927 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
928 {
929 TRACE("(%p, %p)\n", brush, backcol);
930
931 if(!brush || !backcol) return InvalidParameter;
932
933 *backcol = brush->backcol;
934
935 return Ok;
936 }
937
938 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
939 {
940 TRACE("(%p, %p)\n", brush, forecol);
941
942 if(!brush || !forecol) return InvalidParameter;
943
944 *forecol = brush->forecol;
945
946 return Ok;
947 }
948
949 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
950 {
951 TRACE("(%p, %p)\n", brush, hatchstyle);
952
953 if(!brush || !hatchstyle) return InvalidParameter;
954
955 *hatchstyle = brush->hatchstyle;
956
957 return Ok;
958 }
959
960 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
961 {
962 TRACE("(%p)\n", brush);
963
964 if(!brush) return InvalidParameter;
965
966 switch(brush->bt)
967 {
968 case BrushTypePathGradient:
969 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
970 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
971 GdipFree(((GpPathGradient*) brush)->blendfac);
972 GdipFree(((GpPathGradient*) brush)->blendpos);
973 break;
974 case BrushTypeSolidColor:
975 if (((GpSolidFill*)brush)->bmp)
976 DeleteObject(((GpSolidFill*)brush)->bmp);
977 break;
978 case BrushTypeLinearGradient:
979 GdipFree(((GpLineGradient*)brush)->blendfac);
980 GdipFree(((GpLineGradient*)brush)->blendpos);
981 GdipFree(((GpLineGradient*)brush)->pblendcolor);
982 GdipFree(((GpLineGradient*)brush)->pblendpos);
983 break;
984 case BrushTypeTextureFill:
985 GdipDeleteMatrix(((GpTexture*)brush)->transform);
986 GdipDisposeImage(((GpTexture*)brush)->image);
987 break;
988 default:
989 break;
990 }
991
992 DeleteObject(brush->gdibrush);
993 GdipFree(brush);
994
995 return Ok;
996 }
997
998 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
999 BOOL *usinggamma)
1000 {
1001 TRACE("(%p, %p)\n", line, usinggamma);
1002
1003 if(!line || !usinggamma)
1004 return InvalidParameter;
1005
1006 *usinggamma = line->gamma;
1007
1008 return Ok;
1009 }
1010
1011 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
1012 {
1013 TRACE("(%p, %p)\n", brush, wrapmode);
1014
1015 if(!brush || !wrapmode)
1016 return InvalidParameter;
1017
1018 *wrapmode = brush->wrap;
1019
1020 return Ok;
1021 }
1022
1023 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
1024 REAL *positions, INT count)
1025 {
1026 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
1027
1028 if(!brush || !blend || !positions || count <= 0)
1029 return InvalidParameter;
1030
1031 if(count < brush->blendcount)
1032 return InsufficientBuffer;
1033
1034 memcpy(blend, brush->blendfac, count*sizeof(REAL));
1035 if(brush->blendcount > 1){
1036 memcpy(positions, brush->blendpos, count*sizeof(REAL));
1037 }
1038
1039 return Ok;
1040 }
1041
1042 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
1043 {
1044 TRACE("(%p, %p)\n", brush, count);
1045
1046 if(!brush || !count)
1047 return InvalidParameter;
1048
1049 *count = brush->blendcount;
1050
1051 return Ok;
1052 }
1053
1054 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
1055 GpPointF *point)
1056 {
1057 TRACE("(%p, %p)\n", grad, point);
1058
1059 if(!grad || !point)
1060 return InvalidParameter;
1061
1062 point->X = grad->center.X;
1063 point->Y = grad->center.Y;
1064
1065 return Ok;
1066 }
1067
1068 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
1069 GpPoint *point)
1070 {
1071 GpStatus ret;
1072 GpPointF ptf;
1073
1074 TRACE("(%p, %p)\n", grad, point);
1075
1076 if(!point)
1077 return InvalidParameter;
1078
1079 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
1080
1081 if(ret == Ok){
1082 point->X = roundr(ptf.X);
1083 point->Y = roundr(ptf.Y);
1084 }
1085
1086 return ret;
1087 }
1088
1089 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
1090 REAL *x, REAL *y)
1091 {
1092 TRACE("(%p, %p, %p)\n", grad, x, y);
1093
1094 if(!grad || !x || !y)
1095 return InvalidParameter;
1096
1097 *x = grad->focus.X;
1098 *y = grad->focus.Y;
1099
1100 return Ok;
1101 }
1102
1103 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1104 BOOL *gamma)
1105 {
1106 TRACE("(%p, %p)\n", grad, gamma);
1107
1108 if(!grad || !gamma)
1109 return InvalidParameter;
1110
1111 *gamma = grad->gamma;
1112
1113 return Ok;
1114 }
1115
1116 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1117 INT *count)
1118 {
1119 TRACE("(%p, %p)\n", grad, count);
1120
1121 if(!grad || !count)
1122 return InvalidParameter;
1123
1124 *count = grad->pathdata.Count;
1125
1126 return Ok;
1127 }
1128
1129 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1130 {
1131 GpRectF r;
1132 GpPath* path;
1133 GpStatus stat;
1134
1135 TRACE("(%p, %p)\n", brush, rect);
1136
1137 if(!brush || !rect)
1138 return InvalidParameter;
1139
1140 stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
1141 brush->pathdata.Count, FillModeAlternate, &path);
1142 if(stat != Ok) return stat;
1143
1144 stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
1145 if(stat != Ok){
1146 GdipDeletePath(path);
1147 return stat;
1148 }
1149
1150 memcpy(rect, &r, sizeof(GpRectF));
1151
1152 GdipDeletePath(path);
1153
1154 return Ok;
1155 }
1156
1157 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1158 {
1159 GpRectF rectf;
1160 GpStatus stat;
1161
1162 TRACE("(%p, %p)\n", brush, rect);
1163
1164 if(!brush || !rect)
1165 return InvalidParameter;
1166
1167 stat = GdipGetPathGradientRect(brush, &rectf);
1168 if(stat != Ok) return stat;
1169
1170 rect->X = roundr(rectf.X);
1171 rect->Y = roundr(rectf.Y);
1172 rect->Width = roundr(rectf.Width);
1173 rect->Height = roundr(rectf.Height);
1174
1175 return Ok;
1176 }
1177
1178 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1179 *grad, ARGB *argb, INT *count)
1180 {
1181 static int calls;
1182
1183 TRACE("(%p,%p,%p)\n", grad, argb, count);
1184
1185 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
1186 return InvalidParameter;
1187
1188 if(!(calls++))
1189 FIXME("not implemented\n");
1190
1191 return NotImplemented;
1192 }
1193
1194 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1195 GpWrapMode *wrapmode)
1196 {
1197 TRACE("(%p, %p)\n", brush, wrapmode);
1198
1199 if(!brush || !wrapmode)
1200 return InvalidParameter;
1201
1202 *wrapmode = brush->wrap;
1203
1204 return Ok;
1205 }
1206
1207 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1208 {
1209 TRACE("(%p, %p)\n", sf, argb);
1210
1211 if(!sf || !argb)
1212 return InvalidParameter;
1213
1214 *argb = sf->color;
1215
1216 return Ok;
1217 }
1218
1219 /******************************************************************************
1220 * GdipGetTextureImage [GDIPLUS.@]
1221 */
1222 GpStatus WINGDIPAPI GdipGetTextureImage(GpTexture *brush, GpImage **image)
1223 {
1224 TRACE("(%p, %p)\n", brush, image);
1225
1226 if(!brush || !image)
1227 return InvalidParameter;
1228
1229 return GdipCloneImage(brush->image, image);
1230 }
1231
1232 /******************************************************************************
1233 * GdipGetTextureTransform [GDIPLUS.@]
1234 */
1235 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1236 {
1237 TRACE("(%p, %p)\n", brush, matrix);
1238
1239 if(!brush || !matrix)
1240 return InvalidParameter;
1241
1242 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1243
1244 return Ok;
1245 }
1246
1247 /******************************************************************************
1248 * GdipGetTextureWrapMode [GDIPLUS.@]
1249 */
1250 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1251 {
1252 TRACE("(%p, %p)\n", brush, wrapmode);
1253
1254 if(!brush || !wrapmode)
1255 return InvalidParameter;
1256
1257 *wrapmode = brush->wrap;
1258
1259 return Ok;
1260 }
1261
1262 /******************************************************************************
1263 * GdipMultiplyTextureTransform [GDIPLUS.@]
1264 */
1265 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1266 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1267 {
1268 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1269
1270 if(!brush || !matrix)
1271 return InvalidParameter;
1272
1273 return GdipMultiplyMatrix(brush->transform, matrix, order);
1274 }
1275
1276 /******************************************************************************
1277 * GdipResetTextureTransform [GDIPLUS.@]
1278 */
1279 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1280 {
1281 TRACE("(%p)\n", brush);
1282
1283 if(!brush)
1284 return InvalidParameter;
1285
1286 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1287 }
1288
1289 /******************************************************************************
1290 * GdipScaleTextureTransform [GDIPLUS.@]
1291 */
1292 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1293 REAL sx, REAL sy, GpMatrixOrder order)
1294 {
1295 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1296
1297 if(!brush)
1298 return InvalidParameter;
1299
1300 return GdipScaleMatrix(brush->transform, sx, sy, order);
1301 }
1302
1303 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1304 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1305 {
1306 REAL *new_blendfac, *new_blendpos;
1307
1308 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1309
1310 if(!brush || !factors || !positions || count <= 0 ||
1311 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1312 return InvalidParameter;
1313
1314 new_blendfac = GdipAlloc(count * sizeof(REAL));
1315 new_blendpos = GdipAlloc(count * sizeof(REAL));
1316
1317 if (!new_blendfac || !new_blendpos)
1318 {
1319 GdipFree(new_blendfac);
1320 GdipFree(new_blendpos);
1321 return OutOfMemory;
1322 }
1323
1324 memcpy(new_blendfac, factors, count * sizeof(REAL));
1325 memcpy(new_blendpos, positions, count * sizeof(REAL));
1326
1327 GdipFree(brush->blendfac);
1328 GdipFree(brush->blendpos);
1329
1330 brush->blendcount = count;
1331 brush->blendfac = new_blendfac;
1332 brush->blendpos = new_blendpos;
1333
1334 return Ok;
1335 }
1336
1337 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1338 REAL *positions, INT count)
1339 {
1340 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1341
1342 if (!brush || !factors || !positions || count <= 0)
1343 return InvalidParameter;
1344
1345 if (count < brush->blendcount)
1346 return InsufficientBuffer;
1347
1348 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1349 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1350
1351 return Ok;
1352 }
1353
1354 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1355 {
1356 TRACE("(%p, %p)\n", brush, count);
1357
1358 if (!brush || !count)
1359 return InvalidParameter;
1360
1361 *count = brush->blendcount;
1362
1363 return Ok;
1364 }
1365
1366 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1367 BOOL usegamma)
1368 {
1369 TRACE("(%p, %d)\n", line, usegamma);
1370
1371 if(!line)
1372 return InvalidParameter;
1373
1374 line->gamma = usegamma;
1375
1376 return Ok;
1377 }
1378
1379 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1380 REAL scale)
1381 {
1382 REAL factors[33];
1383 REAL positions[33];
1384 int num_points = 0;
1385 int i;
1386 const int precision = 16;
1387 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1388 REAL min_erf;
1389 REAL scale_erf;
1390
1391 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1392
1393 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1394 return InvalidParameter;
1395
1396 /* we want 2 standard deviations */
1397 erf_range = 2.0 / sqrt(2);
1398
1399 /* calculate the constants we need to normalize the error function to be
1400 between 0.0 and scale over the range we need */
1401 min_erf = erf(-erf_range);
1402 scale_erf = scale / (-2.0 * min_erf);
1403
1404 if (focus != 0.0)
1405 {
1406 positions[0] = 0.0;
1407 factors[0] = 0.0;
1408 for (i=1; i<precision; i++)
1409 {
1410 positions[i] = focus * i / precision;
1411 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1412 }
1413 num_points += precision;
1414 }
1415
1416 positions[num_points] = focus;
1417 factors[num_points] = scale;
1418 num_points += 1;
1419
1420 if (focus != 1.0)
1421 {
1422 for (i=1; i<precision; i++)
1423 {
1424 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1425 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1426 }
1427 num_points += precision;
1428 positions[num_points-1] = 1.0;
1429 factors[num_points-1] = 0.0;
1430 }
1431
1432 return GdipSetLineBlend(line, factors, positions, num_points);
1433 }
1434
1435 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1436 GpWrapMode wrap)
1437 {
1438 TRACE("(%p, %d)\n", line, wrap);
1439
1440 if(!line || wrap == WrapModeClamp)
1441 return InvalidParameter;
1442
1443 line->wrap = wrap;
1444
1445 return Ok;
1446 }
1447
1448 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1449 GDIPCONST REAL *pos, INT count)
1450 {
1451 static int calls;
1452
1453 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1454
1455 if(!(calls++))
1456 FIXME("not implemented\n");
1457
1458 return NotImplemented;
1459 }
1460
1461 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1462 GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1463 {
1464 FIXME("(%p,%p,%p,%i): stub\n", brush, blend, pos, count);
1465 return NotImplemented;
1466 }
1467
1468 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1469 ARGB argb)
1470 {
1471 TRACE("(%p, %x)\n", grad, argb);
1472
1473 if(!grad)
1474 return InvalidParameter;
1475
1476 grad->centercolor = argb;
1477 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1478
1479 DeleteObject(grad->brush.gdibrush);
1480 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1481
1482 return Ok;
1483 }
1484
1485 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1486 GpPointF *point)
1487 {
1488 TRACE("(%p, %s)\n", grad, debugstr_pointf(point));
1489
1490 if(!grad || !point)
1491 return InvalidParameter;
1492
1493 grad->center.X = point->X;
1494 grad->center.Y = point->Y;
1495
1496 return Ok;
1497 }
1498
1499 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1500 GpPoint *point)
1501 {
1502 GpPointF ptf;
1503
1504 TRACE("(%p, %p)\n", grad, point);
1505
1506 if(!point)
1507 return InvalidParameter;
1508
1509 ptf.X = (REAL)point->X;
1510 ptf.Y = (REAL)point->Y;
1511
1512 return GdipSetPathGradientCenterPoint(grad,&ptf);
1513 }
1514
1515 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1516 REAL x, REAL y)
1517 {
1518 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1519
1520 if(!grad)
1521 return InvalidParameter;
1522
1523 grad->focus.X = x;
1524 grad->focus.Y = y;
1525
1526 return Ok;
1527 }
1528
1529 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1530 BOOL gamma)
1531 {
1532 TRACE("(%p, %d)\n", grad, gamma);
1533
1534 if(!grad)
1535 return InvalidParameter;
1536
1537 grad->gamma = gamma;
1538
1539 return Ok;
1540 }
1541
1542 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1543 REAL focus, REAL scale)
1544 {
1545 static int calls;
1546
1547 TRACE("(%p,%0.2f,%0.2f)\n", grad, focus, scale);
1548
1549 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1550 return InvalidParameter;
1551
1552 if(!(calls++))
1553 FIXME("not implemented\n");
1554
1555 return NotImplemented;
1556 }
1557
1558 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1559 *grad, ARGB *argb, INT *count)
1560 {
1561 static int calls;
1562
1563 TRACE("(%p,%p,%p)\n", grad, argb, count);
1564
1565 if(!grad || !argb || !count || (*count <= 0) ||
1566 (*count > grad->pathdata.Count))
1567 return InvalidParameter;
1568
1569 if(!(calls++))
1570 FIXME("not implemented\n");
1571
1572 return NotImplemented;
1573 }
1574
1575 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1576 GpWrapMode wrap)
1577 {
1578 TRACE("(%p, %d)\n", grad, wrap);
1579
1580 if(!grad)
1581 return InvalidParameter;
1582
1583 grad->wrap = wrap;
1584
1585 return Ok;
1586 }
1587
1588 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1589 {
1590 TRACE("(%p, %x)\n", sf, argb);
1591
1592 if(!sf)
1593 return InvalidParameter;
1594
1595 sf->color = argb;
1596 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1597
1598 DeleteObject(sf->brush.gdibrush);
1599 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1600
1601 return Ok;
1602 }
1603
1604 /******************************************************************************
1605 * GdipSetTextureTransform [GDIPLUS.@]
1606 */
1607 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1608 GDIPCONST GpMatrix *matrix)
1609 {
1610 TRACE("(%p, %p)\n", texture, matrix);
1611
1612 if(!texture || !matrix)
1613 return InvalidParameter;
1614
1615 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1616
1617 return Ok;
1618 }
1619
1620 /******************************************************************************
1621 * GdipSetTextureWrapMode [GDIPLUS.@]
1622 *
1623 * WrapMode not used, only stored
1624 */
1625 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1626 {
1627 TRACE("(%p, %d)\n", brush, wrapmode);
1628
1629 if(!brush)
1630 return InvalidParameter;
1631
1632 brush->wrap = wrapmode;
1633
1634 return Ok;
1635 }
1636
1637 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1638 ARGB color2)
1639 {
1640 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1641
1642 if(!brush)
1643 return InvalidParameter;
1644
1645 brush->startcolor = color1;
1646 brush->endcolor = color2;
1647
1648 return Ok;
1649 }
1650
1651 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1652 {
1653 TRACE("(%p, %p)\n", brush, colors);
1654
1655 if(!brush || !colors)
1656 return InvalidParameter;
1657
1658 colors[0] = brush->startcolor;
1659 colors[1] = brush->endcolor;
1660
1661 return Ok;
1662 }
1663
1664 /******************************************************************************
1665 * GdipRotateTextureTransform [GDIPLUS.@]
1666 */
1667 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1668 GpMatrixOrder order)
1669 {
1670 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1671
1672 if(!brush)
1673 return InvalidParameter;
1674
1675 return GdipRotateMatrix(brush->transform, angle, order);
1676 }
1677
1678 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1679 REAL scale)
1680 {
1681 REAL factors[3];
1682 REAL positions[3];
1683 int num_points = 0;
1684
1685 TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1686
1687 if (!brush) return InvalidParameter;
1688
1689 if (focus != 0.0)
1690 {
1691 factors[num_points] = 0.0;
1692 positions[num_points] = 0.0;
1693 num_points++;
1694 }
1695
1696 factors[num_points] = scale;
1697 positions[num_points] = focus;
1698 num_points++;
1699
1700 if (focus != 1.0)
1701 {
1702 factors[num_points] = 0.0;
1703 positions[num_points] = 1.0;
1704 num_points++;
1705 }
1706
1707 return GdipSetLineBlend(brush, factors, positions, num_points);
1708 }
1709
1710 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1711 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1712 {
1713 ARGB *new_color;
1714 REAL *new_pos;
1715 TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1716
1717 if (!brush || !blend || !positions || count < 2 ||
1718 positions[0] != 0.0f || positions[count-1] != 1.0f)
1719 {
1720 return InvalidParameter;
1721 }
1722
1723 new_color = GdipAlloc(count * sizeof(ARGB));
1724 new_pos = GdipAlloc(count * sizeof(REAL));
1725 if (!new_color || !new_pos)
1726 {
1727 GdipFree(new_color);
1728 GdipFree(new_pos);
1729 return OutOfMemory;
1730 }
1731
1732 memcpy(new_color, blend, sizeof(ARGB) * count);
1733 memcpy(new_pos, positions, sizeof(REAL) * count);
1734
1735 GdipFree(brush->pblendcolor);
1736 GdipFree(brush->pblendpos);
1737
1738 brush->pblendcolor = new_color;
1739 brush->pblendpos = new_pos;
1740 brush->pblendcount = count;
1741
1742 return Ok;
1743 }
1744
1745 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1746 ARGB *blend, REAL* positions, INT count)
1747 {
1748 if (!brush || !blend || !positions || count < 2)
1749 return InvalidParameter;
1750
1751 if (brush->pblendcount == 0)
1752 return GenericError;
1753
1754 if (count < brush->pblendcount)
1755 return InsufficientBuffer;
1756
1757 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1758 memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1759
1760 return Ok;
1761 }
1762
1763 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1764 INT *count)
1765 {
1766 if (!brush || !count)
1767 return InvalidParameter;
1768
1769 *count = brush->pblendcount;
1770
1771 return Ok;
1772 }
1773
1774 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1775 {
1776 static int calls;
1777
1778 TRACE("(%p)\n", brush);
1779
1780 if(!(calls++))
1781 FIXME("not implemented\n");
1782
1783 return NotImplemented;
1784 }
1785
1786 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1787 GDIPCONST GpMatrix *matrix)
1788 {
1789 static int calls;
1790
1791 TRACE("(%p,%p)\n", brush, matrix);
1792
1793 if(!(calls++))
1794 FIXME("not implemented\n");
1795
1796 return NotImplemented;
1797 }
1798
1799 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
1800 GpMatrixOrder order)
1801 {
1802 static int calls;
1803
1804 TRACE("(%p,%0.2f,%0.2f,%u)\n", brush, sx, sy, order);
1805
1806 if(!(calls++))
1807 FIXME("not implemented\n");
1808
1809 return NotImplemented;
1810 }
1811
1812 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1813 REAL dx, REAL dy, GpMatrixOrder order)
1814 {
1815 FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1816
1817 return NotImplemented;
1818 }
1819
1820 /******************************************************************************
1821 * GdipTranslateTextureTransform [GDIPLUS.@]
1822 */
1823 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1824 GpMatrixOrder order)
1825 {
1826 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1827
1828 if(!brush)
1829 return InvalidParameter;
1830
1831 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1832 }
1833
1834 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1835 {
1836 TRACE("(%p, %p)\n", brush, rect);
1837
1838 if(!brush || !rect)
1839 return InvalidParameter;
1840
1841 *rect = brush->rect;
1842
1843 return Ok;
1844 }
1845
1846 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1847 {
1848 GpRectF rectF;
1849 GpStatus ret;
1850
1851 TRACE("(%p, %p)\n", brush, rect);
1852
1853 if(!rect)
1854 return InvalidParameter;
1855
1856 ret = GdipGetLineRect(brush, &rectF);
1857
1858 if(ret == Ok){
1859 rect->X = roundr(rectF.X);
1860 rect->Y = roundr(rectF.Y);
1861 rect->Width = roundr(rectF.Width);
1862 rect->Height = roundr(rectF.Height);
1863 }
1864
1865 return ret;
1866 }
1867
1868 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1869 REAL angle, GpMatrixOrder order)
1870 {
1871 static int calls;
1872
1873 TRACE("(%p,%0.2f,%u)\n", brush, angle, order);
1874
1875 if(!brush)
1876 return InvalidParameter;
1877
1878 if(!(calls++))
1879 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1880
1881 return NotImplemented;
1882 }