sync with trunk r46493
[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 if (imageattr)
869 (*texture)->wrap = imageattr->wrap;
870 else
871 (*texture)->wrap = WrapModeTile;
872 (*texture)->image = new_image;
873
874 exit:
875 if (status == Ok)
876 {
877 TRACE("<-- %p\n", *texture);
878 }
879 else
880 {
881 if (*texture)
882 {
883 GdipDeleteMatrix((*texture)->transform);
884 GdipFree(*texture);
885 *texture = NULL;
886 }
887 GdipDisposeImage(new_image);
888 TRACE("<-- error %u\n", status);
889 }
890
891 return status;
892 }
893
894 /******************************************************************************
895 * GdipCreateTextureIAI [GDIPLUS.@]
896 */
897 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
898 INT x, INT y, INT width, INT height, GpTexture **texture)
899 {
900 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
901 texture);
902
903 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
904 }
905
906 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
907 INT x, INT y, INT width, INT height, GpTexture **texture)
908 {
909 GpImageAttributes imageattr;
910
911 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
912 texture);
913
914 imageattr.wrap = wrapmode;
915
916 return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
917 }
918
919 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
920 {
921 TRACE("(%p, %p)\n", brush, type);
922
923 if(!brush || !type) return InvalidParameter;
924
925 *type = brush->bt;
926
927 return Ok;
928 }
929
930 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
931 {
932 TRACE("(%p, %p)\n", brush, backcol);
933
934 if(!brush || !backcol) return InvalidParameter;
935
936 *backcol = brush->backcol;
937
938 return Ok;
939 }
940
941 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
942 {
943 TRACE("(%p, %p)\n", brush, forecol);
944
945 if(!brush || !forecol) return InvalidParameter;
946
947 *forecol = brush->forecol;
948
949 return Ok;
950 }
951
952 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
953 {
954 TRACE("(%p, %p)\n", brush, hatchstyle);
955
956 if(!brush || !hatchstyle) return InvalidParameter;
957
958 *hatchstyle = brush->hatchstyle;
959
960 return Ok;
961 }
962
963 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
964 {
965 TRACE("(%p)\n", brush);
966
967 if(!brush) return InvalidParameter;
968
969 switch(brush->bt)
970 {
971 case BrushTypePathGradient:
972 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
973 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
974 GdipFree(((GpPathGradient*) brush)->blendfac);
975 GdipFree(((GpPathGradient*) brush)->blendpos);
976 break;
977 case BrushTypeSolidColor:
978 if (((GpSolidFill*)brush)->bmp)
979 DeleteObject(((GpSolidFill*)brush)->bmp);
980 break;
981 case BrushTypeLinearGradient:
982 GdipFree(((GpLineGradient*)brush)->blendfac);
983 GdipFree(((GpLineGradient*)brush)->blendpos);
984 GdipFree(((GpLineGradient*)brush)->pblendcolor);
985 GdipFree(((GpLineGradient*)brush)->pblendpos);
986 break;
987 case BrushTypeTextureFill:
988 GdipDeleteMatrix(((GpTexture*)brush)->transform);
989 GdipDisposeImage(((GpTexture*)brush)->image);
990 break;
991 default:
992 break;
993 }
994
995 DeleteObject(brush->gdibrush);
996 GdipFree(brush);
997
998 return Ok;
999 }
1000
1001 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
1002 BOOL *usinggamma)
1003 {
1004 TRACE("(%p, %p)\n", line, usinggamma);
1005
1006 if(!line || !usinggamma)
1007 return InvalidParameter;
1008
1009 *usinggamma = line->gamma;
1010
1011 return Ok;
1012 }
1013
1014 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
1015 {
1016 TRACE("(%p, %p)\n", brush, wrapmode);
1017
1018 if(!brush || !wrapmode)
1019 return InvalidParameter;
1020
1021 *wrapmode = brush->wrap;
1022
1023 return Ok;
1024 }
1025
1026 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
1027 REAL *positions, INT count)
1028 {
1029 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
1030
1031 if(!brush || !blend || !positions || count <= 0)
1032 return InvalidParameter;
1033
1034 if(count < brush->blendcount)
1035 return InsufficientBuffer;
1036
1037 memcpy(blend, brush->blendfac, count*sizeof(REAL));
1038 if(brush->blendcount > 1){
1039 memcpy(positions, brush->blendpos, count*sizeof(REAL));
1040 }
1041
1042 return Ok;
1043 }
1044
1045 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
1046 {
1047 TRACE("(%p, %p)\n", brush, count);
1048
1049 if(!brush || !count)
1050 return InvalidParameter;
1051
1052 *count = brush->blendcount;
1053
1054 return Ok;
1055 }
1056
1057 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
1058 GpPointF *point)
1059 {
1060 TRACE("(%p, %p)\n", grad, point);
1061
1062 if(!grad || !point)
1063 return InvalidParameter;
1064
1065 point->X = grad->center.X;
1066 point->Y = grad->center.Y;
1067
1068 return Ok;
1069 }
1070
1071 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
1072 GpPoint *point)
1073 {
1074 GpStatus ret;
1075 GpPointF ptf;
1076
1077 TRACE("(%p, %p)\n", grad, point);
1078
1079 if(!point)
1080 return InvalidParameter;
1081
1082 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
1083
1084 if(ret == Ok){
1085 point->X = roundr(ptf.X);
1086 point->Y = roundr(ptf.Y);
1087 }
1088
1089 return ret;
1090 }
1091
1092 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
1093 REAL *x, REAL *y)
1094 {
1095 TRACE("(%p, %p, %p)\n", grad, x, y);
1096
1097 if(!grad || !x || !y)
1098 return InvalidParameter;
1099
1100 *x = grad->focus.X;
1101 *y = grad->focus.Y;
1102
1103 return Ok;
1104 }
1105
1106 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1107 BOOL *gamma)
1108 {
1109 TRACE("(%p, %p)\n", grad, gamma);
1110
1111 if(!grad || !gamma)
1112 return InvalidParameter;
1113
1114 *gamma = grad->gamma;
1115
1116 return Ok;
1117 }
1118
1119 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1120 INT *count)
1121 {
1122 TRACE("(%p, %p)\n", grad, count);
1123
1124 if(!grad || !count)
1125 return InvalidParameter;
1126
1127 *count = grad->pathdata.Count;
1128
1129 return Ok;
1130 }
1131
1132 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1133 {
1134 GpRectF r;
1135 GpPath* path;
1136 GpStatus stat;
1137
1138 TRACE("(%p, %p)\n", brush, rect);
1139
1140 if(!brush || !rect)
1141 return InvalidParameter;
1142
1143 stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
1144 brush->pathdata.Count, FillModeAlternate, &path);
1145 if(stat != Ok) return stat;
1146
1147 stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
1148 if(stat != Ok){
1149 GdipDeletePath(path);
1150 return stat;
1151 }
1152
1153 memcpy(rect, &r, sizeof(GpRectF));
1154
1155 GdipDeletePath(path);
1156
1157 return Ok;
1158 }
1159
1160 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1161 {
1162 GpRectF rectf;
1163 GpStatus stat;
1164
1165 TRACE("(%p, %p)\n", brush, rect);
1166
1167 if(!brush || !rect)
1168 return InvalidParameter;
1169
1170 stat = GdipGetPathGradientRect(brush, &rectf);
1171 if(stat != Ok) return stat;
1172
1173 rect->X = roundr(rectf.X);
1174 rect->Y = roundr(rectf.Y);
1175 rect->Width = roundr(rectf.Width);
1176 rect->Height = roundr(rectf.Height);
1177
1178 return Ok;
1179 }
1180
1181 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1182 *grad, ARGB *argb, INT *count)
1183 {
1184 static int calls;
1185
1186 TRACE("(%p,%p,%p)\n", grad, argb, count);
1187
1188 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
1189 return InvalidParameter;
1190
1191 if(!(calls++))
1192 FIXME("not implemented\n");
1193
1194 return NotImplemented;
1195 }
1196
1197 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1198 GpWrapMode *wrapmode)
1199 {
1200 TRACE("(%p, %p)\n", brush, wrapmode);
1201
1202 if(!brush || !wrapmode)
1203 return InvalidParameter;
1204
1205 *wrapmode = brush->wrap;
1206
1207 return Ok;
1208 }
1209
1210 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1211 {
1212 TRACE("(%p, %p)\n", sf, argb);
1213
1214 if(!sf || !argb)
1215 return InvalidParameter;
1216
1217 *argb = sf->color;
1218
1219 return Ok;
1220 }
1221
1222 /******************************************************************************
1223 * GdipGetTextureImage [GDIPLUS.@]
1224 */
1225 GpStatus WINGDIPAPI GdipGetTextureImage(GpTexture *brush, GpImage **image)
1226 {
1227 TRACE("(%p, %p)\n", brush, image);
1228
1229 if(!brush || !image)
1230 return InvalidParameter;
1231
1232 return GdipCloneImage(brush->image, image);
1233 }
1234
1235 /******************************************************************************
1236 * GdipGetTextureTransform [GDIPLUS.@]
1237 */
1238 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1239 {
1240 TRACE("(%p, %p)\n", brush, matrix);
1241
1242 if(!brush || !matrix)
1243 return InvalidParameter;
1244
1245 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1246
1247 return Ok;
1248 }
1249
1250 /******************************************************************************
1251 * GdipGetTextureWrapMode [GDIPLUS.@]
1252 */
1253 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1254 {
1255 TRACE("(%p, %p)\n", brush, wrapmode);
1256
1257 if(!brush || !wrapmode)
1258 return InvalidParameter;
1259
1260 *wrapmode = brush->wrap;
1261
1262 return Ok;
1263 }
1264
1265 /******************************************************************************
1266 * GdipMultiplyTextureTransform [GDIPLUS.@]
1267 */
1268 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1269 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1270 {
1271 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1272
1273 if(!brush || !matrix)
1274 return InvalidParameter;
1275
1276 return GdipMultiplyMatrix(brush->transform, matrix, order);
1277 }
1278
1279 /******************************************************************************
1280 * GdipResetTextureTransform [GDIPLUS.@]
1281 */
1282 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1283 {
1284 TRACE("(%p)\n", brush);
1285
1286 if(!brush)
1287 return InvalidParameter;
1288
1289 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1290 }
1291
1292 /******************************************************************************
1293 * GdipScaleTextureTransform [GDIPLUS.@]
1294 */
1295 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1296 REAL sx, REAL sy, GpMatrixOrder order)
1297 {
1298 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1299
1300 if(!brush)
1301 return InvalidParameter;
1302
1303 return GdipScaleMatrix(brush->transform, sx, sy, order);
1304 }
1305
1306 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1307 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1308 {
1309 REAL *new_blendfac, *new_blendpos;
1310
1311 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1312
1313 if(!brush || !factors || !positions || count <= 0 ||
1314 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1315 return InvalidParameter;
1316
1317 new_blendfac = GdipAlloc(count * sizeof(REAL));
1318 new_blendpos = GdipAlloc(count * sizeof(REAL));
1319
1320 if (!new_blendfac || !new_blendpos)
1321 {
1322 GdipFree(new_blendfac);
1323 GdipFree(new_blendpos);
1324 return OutOfMemory;
1325 }
1326
1327 memcpy(new_blendfac, factors, count * sizeof(REAL));
1328 memcpy(new_blendpos, positions, count * sizeof(REAL));
1329
1330 GdipFree(brush->blendfac);
1331 GdipFree(brush->blendpos);
1332
1333 brush->blendcount = count;
1334 brush->blendfac = new_blendfac;
1335 brush->blendpos = new_blendpos;
1336
1337 return Ok;
1338 }
1339
1340 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1341 REAL *positions, INT count)
1342 {
1343 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1344
1345 if (!brush || !factors || !positions || count <= 0)
1346 return InvalidParameter;
1347
1348 if (count < brush->blendcount)
1349 return InsufficientBuffer;
1350
1351 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1352 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1353
1354 return Ok;
1355 }
1356
1357 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1358 {
1359 TRACE("(%p, %p)\n", brush, count);
1360
1361 if (!brush || !count)
1362 return InvalidParameter;
1363
1364 *count = brush->blendcount;
1365
1366 return Ok;
1367 }
1368
1369 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1370 BOOL usegamma)
1371 {
1372 TRACE("(%p, %d)\n", line, usegamma);
1373
1374 if(!line)
1375 return InvalidParameter;
1376
1377 line->gamma = usegamma;
1378
1379 return Ok;
1380 }
1381
1382 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1383 REAL scale)
1384 {
1385 REAL factors[33];
1386 REAL positions[33];
1387 int num_points = 0;
1388 int i;
1389 const int precision = 16;
1390 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1391 REAL min_erf;
1392 REAL scale_erf;
1393
1394 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1395
1396 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1397 return InvalidParameter;
1398
1399 /* we want 2 standard deviations */
1400 erf_range = 2.0 / sqrt(2);
1401
1402 /* calculate the constants we need to normalize the error function to be
1403 between 0.0 and scale over the range we need */
1404 min_erf = erf(-erf_range);
1405 scale_erf = scale / (-2.0 * min_erf);
1406
1407 if (focus != 0.0)
1408 {
1409 positions[0] = 0.0;
1410 factors[0] = 0.0;
1411 for (i=1; i<precision; i++)
1412 {
1413 positions[i] = focus * i / precision;
1414 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1415 }
1416 num_points += precision;
1417 }
1418
1419 positions[num_points] = focus;
1420 factors[num_points] = scale;
1421 num_points += 1;
1422
1423 if (focus != 1.0)
1424 {
1425 for (i=1; i<precision; i++)
1426 {
1427 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1428 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1429 }
1430 num_points += precision;
1431 positions[num_points-1] = 1.0;
1432 factors[num_points-1] = 0.0;
1433 }
1434
1435 return GdipSetLineBlend(line, factors, positions, num_points);
1436 }
1437
1438 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1439 GpWrapMode wrap)
1440 {
1441 TRACE("(%p, %d)\n", line, wrap);
1442
1443 if(!line || wrap == WrapModeClamp)
1444 return InvalidParameter;
1445
1446 line->wrap = wrap;
1447
1448 return Ok;
1449 }
1450
1451 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1452 GDIPCONST REAL *pos, INT count)
1453 {
1454 static int calls;
1455
1456 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1457
1458 if(!(calls++))
1459 FIXME("not implemented\n");
1460
1461 return NotImplemented;
1462 }
1463
1464 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1465 GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1466 {
1467 FIXME("(%p,%p,%p,%i): stub\n", brush, blend, pos, count);
1468 return NotImplemented;
1469 }
1470
1471 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1472 ARGB argb)
1473 {
1474 TRACE("(%p, %x)\n", grad, argb);
1475
1476 if(!grad)
1477 return InvalidParameter;
1478
1479 grad->centercolor = argb;
1480 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1481
1482 DeleteObject(grad->brush.gdibrush);
1483 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1484
1485 return Ok;
1486 }
1487
1488 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1489 GpPointF *point)
1490 {
1491 TRACE("(%p, %s)\n", grad, debugstr_pointf(point));
1492
1493 if(!grad || !point)
1494 return InvalidParameter;
1495
1496 grad->center.X = point->X;
1497 grad->center.Y = point->Y;
1498
1499 return Ok;
1500 }
1501
1502 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1503 GpPoint *point)
1504 {
1505 GpPointF ptf;
1506
1507 TRACE("(%p, %p)\n", grad, point);
1508
1509 if(!point)
1510 return InvalidParameter;
1511
1512 ptf.X = (REAL)point->X;
1513 ptf.Y = (REAL)point->Y;
1514
1515 return GdipSetPathGradientCenterPoint(grad,&ptf);
1516 }
1517
1518 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1519 REAL x, REAL y)
1520 {
1521 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1522
1523 if(!grad)
1524 return InvalidParameter;
1525
1526 grad->focus.X = x;
1527 grad->focus.Y = y;
1528
1529 return Ok;
1530 }
1531
1532 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1533 BOOL gamma)
1534 {
1535 TRACE("(%p, %d)\n", grad, gamma);
1536
1537 if(!grad)
1538 return InvalidParameter;
1539
1540 grad->gamma = gamma;
1541
1542 return Ok;
1543 }
1544
1545 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1546 REAL focus, REAL scale)
1547 {
1548 static int calls;
1549
1550 TRACE("(%p,%0.2f,%0.2f)\n", grad, focus, scale);
1551
1552 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1553 return InvalidParameter;
1554
1555 if(!(calls++))
1556 FIXME("not implemented\n");
1557
1558 return NotImplemented;
1559 }
1560
1561 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1562 *grad, ARGB *argb, INT *count)
1563 {
1564 static int calls;
1565
1566 TRACE("(%p,%p,%p)\n", grad, argb, count);
1567
1568 if(!grad || !argb || !count || (*count <= 0) ||
1569 (*count > grad->pathdata.Count))
1570 return InvalidParameter;
1571
1572 if(!(calls++))
1573 FIXME("not implemented\n");
1574
1575 return NotImplemented;
1576 }
1577
1578 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1579 GpWrapMode wrap)
1580 {
1581 TRACE("(%p, %d)\n", grad, wrap);
1582
1583 if(!grad)
1584 return InvalidParameter;
1585
1586 grad->wrap = wrap;
1587
1588 return Ok;
1589 }
1590
1591 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1592 {
1593 TRACE("(%p, %x)\n", sf, argb);
1594
1595 if(!sf)
1596 return InvalidParameter;
1597
1598 sf->color = argb;
1599 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1600
1601 DeleteObject(sf->brush.gdibrush);
1602 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1603
1604 return Ok;
1605 }
1606
1607 /******************************************************************************
1608 * GdipSetTextureTransform [GDIPLUS.@]
1609 */
1610 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1611 GDIPCONST GpMatrix *matrix)
1612 {
1613 TRACE("(%p, %p)\n", texture, matrix);
1614
1615 if(!texture || !matrix)
1616 return InvalidParameter;
1617
1618 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1619
1620 return Ok;
1621 }
1622
1623 /******************************************************************************
1624 * GdipSetTextureWrapMode [GDIPLUS.@]
1625 *
1626 * WrapMode not used, only stored
1627 */
1628 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1629 {
1630 TRACE("(%p, %d)\n", brush, wrapmode);
1631
1632 if(!brush)
1633 return InvalidParameter;
1634
1635 brush->wrap = wrapmode;
1636
1637 return Ok;
1638 }
1639
1640 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1641 ARGB color2)
1642 {
1643 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1644
1645 if(!brush)
1646 return InvalidParameter;
1647
1648 brush->startcolor = color1;
1649 brush->endcolor = color2;
1650
1651 return Ok;
1652 }
1653
1654 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1655 {
1656 TRACE("(%p, %p)\n", brush, colors);
1657
1658 if(!brush || !colors)
1659 return InvalidParameter;
1660
1661 colors[0] = brush->startcolor;
1662 colors[1] = brush->endcolor;
1663
1664 return Ok;
1665 }
1666
1667 /******************************************************************************
1668 * GdipRotateTextureTransform [GDIPLUS.@]
1669 */
1670 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1671 GpMatrixOrder order)
1672 {
1673 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1674
1675 if(!brush)
1676 return InvalidParameter;
1677
1678 return GdipRotateMatrix(brush->transform, angle, order);
1679 }
1680
1681 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1682 REAL scale)
1683 {
1684 REAL factors[3];
1685 REAL positions[3];
1686 int num_points = 0;
1687
1688 TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1689
1690 if (!brush) return InvalidParameter;
1691
1692 if (focus != 0.0)
1693 {
1694 factors[num_points] = 0.0;
1695 positions[num_points] = 0.0;
1696 num_points++;
1697 }
1698
1699 factors[num_points] = scale;
1700 positions[num_points] = focus;
1701 num_points++;
1702
1703 if (focus != 1.0)
1704 {
1705 factors[num_points] = 0.0;
1706 positions[num_points] = 1.0;
1707 num_points++;
1708 }
1709
1710 return GdipSetLineBlend(brush, factors, positions, num_points);
1711 }
1712
1713 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1714 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1715 {
1716 ARGB *new_color;
1717 REAL *new_pos;
1718 TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1719
1720 if (!brush || !blend || !positions || count < 2 ||
1721 positions[0] != 0.0f || positions[count-1] != 1.0f)
1722 {
1723 return InvalidParameter;
1724 }
1725
1726 new_color = GdipAlloc(count * sizeof(ARGB));
1727 new_pos = GdipAlloc(count * sizeof(REAL));
1728 if (!new_color || !new_pos)
1729 {
1730 GdipFree(new_color);
1731 GdipFree(new_pos);
1732 return OutOfMemory;
1733 }
1734
1735 memcpy(new_color, blend, sizeof(ARGB) * count);
1736 memcpy(new_pos, positions, sizeof(REAL) * count);
1737
1738 GdipFree(brush->pblendcolor);
1739 GdipFree(brush->pblendpos);
1740
1741 brush->pblendcolor = new_color;
1742 brush->pblendpos = new_pos;
1743 brush->pblendcount = count;
1744
1745 return Ok;
1746 }
1747
1748 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1749 ARGB *blend, REAL* positions, INT count)
1750 {
1751 if (!brush || !blend || !positions || count < 2)
1752 return InvalidParameter;
1753
1754 if (brush->pblendcount == 0)
1755 return GenericError;
1756
1757 if (count < brush->pblendcount)
1758 return InsufficientBuffer;
1759
1760 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1761 memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1762
1763 return Ok;
1764 }
1765
1766 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1767 INT *count)
1768 {
1769 if (!brush || !count)
1770 return InvalidParameter;
1771
1772 *count = brush->pblendcount;
1773
1774 return Ok;
1775 }
1776
1777 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1778 {
1779 static int calls;
1780
1781 TRACE("(%p)\n", brush);
1782
1783 if(!(calls++))
1784 FIXME("not implemented\n");
1785
1786 return NotImplemented;
1787 }
1788
1789 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1790 GDIPCONST GpMatrix *matrix)
1791 {
1792 static int calls;
1793
1794 TRACE("(%p,%p)\n", brush, matrix);
1795
1796 if(!(calls++))
1797 FIXME("not implemented\n");
1798
1799 return NotImplemented;
1800 }
1801
1802 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
1803 GpMatrixOrder order)
1804 {
1805 static int calls;
1806
1807 TRACE("(%p,%0.2f,%0.2f,%u)\n", brush, sx, sy, order);
1808
1809 if(!(calls++))
1810 FIXME("not implemented\n");
1811
1812 return NotImplemented;
1813 }
1814
1815 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1816 REAL dx, REAL dy, GpMatrixOrder order)
1817 {
1818 FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1819
1820 return NotImplemented;
1821 }
1822
1823 /******************************************************************************
1824 * GdipTranslateTextureTransform [GDIPLUS.@]
1825 */
1826 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1827 GpMatrixOrder order)
1828 {
1829 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1830
1831 if(!brush)
1832 return InvalidParameter;
1833
1834 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1835 }
1836
1837 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1838 {
1839 TRACE("(%p, %p)\n", brush, rect);
1840
1841 if(!brush || !rect)
1842 return InvalidParameter;
1843
1844 *rect = brush->rect;
1845
1846 return Ok;
1847 }
1848
1849 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1850 {
1851 GpRectF rectF;
1852 GpStatus ret;
1853
1854 TRACE("(%p, %p)\n", brush, rect);
1855
1856 if(!rect)
1857 return InvalidParameter;
1858
1859 ret = GdipGetLineRect(brush, &rectF);
1860
1861 if(ret == Ok){
1862 rect->X = roundr(rectF.X);
1863 rect->Y = roundr(rectF.Y);
1864 rect->Width = roundr(rectF.Width);
1865 rect->Height = roundr(rectF.Height);
1866 }
1867
1868 return ret;
1869 }
1870
1871 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1872 REAL angle, GpMatrixOrder order)
1873 {
1874 static int calls;
1875
1876 TRACE("(%p,%0.2f,%u)\n", brush, angle, order);
1877
1878 if(!brush)
1879 return InvalidParameter;
1880
1881 if(!(calls++))
1882 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1883
1884 return NotImplemented;
1885 }