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