f24d8db763a9f4570210c30c786ceff2c78693d7
[reactos.git] / reactos / 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 *clone = GdipAlloc(sizeof(GpSolidFill));
77 if (!*clone) return OutOfMemory;
78
79 memcpy(*clone, brush, sizeof(GpSolidFill));
80
81 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
82 break;
83 case BrushTypeHatchFill:
84 *clone = GdipAlloc(sizeof(GpHatch));
85 if (!*clone) return OutOfMemory;
86
87 memcpy(*clone, brush, sizeof(GpHatch));
88
89 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
90 break;
91 case BrushTypePathGradient:{
92 GpPathGradient *src, *dest;
93 INT count;
94
95 *clone = GdipAlloc(sizeof(GpPathGradient));
96 if (!*clone) return OutOfMemory;
97
98 src = (GpPathGradient*) brush,
99 dest = (GpPathGradient*) *clone;
100 count = src->pathdata.Count;
101
102 memcpy(dest, src, sizeof(GpPathGradient));
103
104 dest->pathdata.Count = count;
105 dest->pathdata.Points = GdipAlloc(count * sizeof(PointF));
106 dest->pathdata.Types = GdipAlloc(count);
107
108 if(!dest->pathdata.Points || !dest->pathdata.Types){
109 GdipFree(dest->pathdata.Points);
110 GdipFree(dest->pathdata.Types);
111 GdipFree(dest);
112 return OutOfMemory;
113 }
114
115 memcpy(dest->pathdata.Points, src->pathdata.Points, count * sizeof(PointF));
116 memcpy(dest->pathdata.Types, src->pathdata.Types, count);
117
118 /* blending */
119 count = src->blendcount;
120 dest->blendcount = count;
121 dest->blendfac = GdipAlloc(count * sizeof(REAL));
122 dest->blendpos = GdipAlloc(count * sizeof(REAL));
123
124 if(!dest->blendfac || !dest->blendpos){
125 GdipFree(dest->pathdata.Points);
126 GdipFree(dest->pathdata.Types);
127 GdipFree(dest->blendfac);
128 GdipFree(dest->blendpos);
129 GdipFree(dest);
130 return OutOfMemory;
131 }
132
133 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
134 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
135
136 break;
137 }
138 case BrushTypeLinearGradient:{
139 GpLineGradient *dest, *src;
140 INT count;
141
142 dest = GdipAlloc(sizeof(GpLineGradient));
143 if(!dest) return OutOfMemory;
144
145 src = (GpLineGradient*)brush;
146
147 memcpy(dest, src, sizeof(GpLineGradient));
148
149 dest->brush.gdibrush = CreateSolidBrush(dest->brush.lb.lbColor);
150
151 count = dest->blendcount;
152 dest->blendfac = GdipAlloc(count * sizeof(REAL));
153 dest->blendpos = GdipAlloc(count * sizeof(REAL));
154
155 if (!dest->blendfac || !dest->blendpos)
156 {
157 GdipFree(dest->blendfac);
158 GdipFree(dest->blendpos);
159 DeleteObject(dest->brush.gdibrush);
160 GdipFree(dest);
161 return OutOfMemory;
162 }
163
164 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
165 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
166
167 *clone = &dest->brush;
168 break;
169 }
170 case BrushTypeTextureFill:
171 *clone = GdipAlloc(sizeof(GpTexture));
172 if(!*clone) return OutOfMemory;
173
174 memcpy(*clone, brush, sizeof(GpTexture));
175
176 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
177 break;
178 default:
179 ERR("not implemented for brush type %d\n", brush->bt);
180 return NotImplemented;
181 }
182
183 return Ok;
184 }
185
186 static LONG HatchStyleToHatch(HatchStyle hatchstyle)
187 {
188 switch (hatchstyle)
189 {
190 case HatchStyleHorizontal: return HS_HORIZONTAL;
191 case HatchStyleVertical: return HS_VERTICAL;
192 case HatchStyleForwardDiagonal: return HS_FDIAGONAL;
193 case HatchStyleBackwardDiagonal: return HS_BDIAGONAL;
194 case HatchStyleCross: return HS_CROSS;
195 case HatchStyleDiagonalCross: return HS_DIAGCROSS;
196 default: return 0;
197 }
198 }
199
200 /******************************************************************************
201 * GdipCreateHatchBrush [GDIPLUS.@]
202 */
203 GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle hatchstyle, ARGB forecol, ARGB backcol, GpHatch **brush)
204 {
205 COLORREF fgcol = ARGB2COLORREF(forecol);
206
207 TRACE("(%d, %d, %d, %p)\n", hatchstyle, forecol, backcol, brush);
208
209 if(!brush) return InvalidParameter;
210
211 *brush = GdipAlloc(sizeof(GpHatch));
212 if (!*brush) return OutOfMemory;
213
214 switch (hatchstyle)
215 {
216 case HatchStyleHorizontal:
217 case HatchStyleVertical:
218 case HatchStyleForwardDiagonal:
219 case HatchStyleBackwardDiagonal:
220 case HatchStyleCross:
221 case HatchStyleDiagonalCross:
222 /* Brushes that map to BS_HATCHED */
223 (*brush)->brush.lb.lbStyle = BS_HATCHED;
224 (*brush)->brush.lb.lbColor = fgcol;
225 (*brush)->brush.lb.lbHatch = HatchStyleToHatch(hatchstyle);
226 break;
227
228 default:
229 FIXME("Unimplemented hatch style %d\n", hatchstyle);
230
231 (*brush)->brush.lb.lbStyle = BS_SOLID;
232 (*brush)->brush.lb.lbColor = fgcol;
233 (*brush)->brush.lb.lbHatch = 0;
234 break;
235 }
236
237
238 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
239 (*brush)->brush.bt = BrushTypeHatchFill;
240 (*brush)->forecol = forecol;
241 (*brush)->backcol = backcol;
242 (*brush)->hatchstyle = hatchstyle;
243
244 return Ok;
245 }
246
247 /******************************************************************************
248 * GdipCreateLineBrush [GDIPLUS.@]
249 */
250 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
251 GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
252 GpWrapMode wrap, GpLineGradient **line)
253 {
254 COLORREF col = ARGB2COLORREF(startcolor);
255
256 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
257 startcolor, endcolor, wrap, line);
258
259 if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
260 return InvalidParameter;
261
262 *line = GdipAlloc(sizeof(GpLineGradient));
263 if(!*line) return OutOfMemory;
264
265 (*line)->brush.lb.lbStyle = BS_SOLID;
266 (*line)->brush.lb.lbColor = col;
267 (*line)->brush.lb.lbHatch = 0;
268 (*line)->brush.gdibrush = CreateSolidBrush(col);
269 (*line)->brush.bt = BrushTypeLinearGradient;
270
271 (*line)->startpoint.X = startpoint->X;
272 (*line)->startpoint.Y = startpoint->Y;
273 (*line)->endpoint.X = endpoint->X;
274 (*line)->endpoint.Y = endpoint->Y;
275 (*line)->startcolor = startcolor;
276 (*line)->endcolor = endcolor;
277 (*line)->wrap = wrap;
278 (*line)->gamma = FALSE;
279
280 (*line)->rect.X = (startpoint->X < endpoint->X ? startpoint->X: endpoint->X);
281 (*line)->rect.Y = (startpoint->Y < endpoint->Y ? startpoint->Y: endpoint->Y);
282 (*line)->rect.Width = fabs(startpoint->X - endpoint->X);
283 (*line)->rect.Height = fabs(startpoint->Y - endpoint->Y);
284
285 (*line)->blendcount = 1;
286 (*line)->blendfac = GdipAlloc(sizeof(REAL));
287 (*line)->blendpos = GdipAlloc(sizeof(REAL));
288
289 if (!(*line)->blendfac || !(*line)->blendpos)
290 {
291 GdipFree((*line)->blendfac);
292 GdipFree((*line)->blendpos);
293 DeleteObject((*line)->brush.gdibrush);
294 GdipFree(*line);
295 *line = NULL;
296 return OutOfMemory;
297 }
298
299 (*line)->blendfac[0] = 1.0f;
300 (*line)->blendpos[0] = 1.0f;
301
302 return Ok;
303 }
304
305 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
306 GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
307 GpWrapMode wrap, GpLineGradient **line)
308 {
309 GpPointF stF;
310 GpPointF endF;
311
312 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
313 startcolor, endcolor, wrap, line);
314
315 if(!startpoint || !endpoint)
316 return InvalidParameter;
317
318 stF.X = (REAL)startpoint->X;
319 stF.Y = (REAL)startpoint->Y;
320 endF.X = (REAL)endpoint->X;
321 endF.X = (REAL)endpoint->Y;
322
323 return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
324 }
325
326 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
327 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
328 GpLineGradient **line)
329 {
330 GpPointF start, end;
331 GpStatus stat;
332
333 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
334 wrap, line);
335
336 if(!line || !rect)
337 return InvalidParameter;
338
339 switch (mode)
340 {
341 case LinearGradientModeHorizontal:
342 start.X = rect->X;
343 start.Y = rect->Y;
344 end.X = rect->X + rect->Width;
345 end.Y = rect->Y;
346 break;
347 case LinearGradientModeVertical:
348 start.X = rect->X;
349 start.Y = rect->Y;
350 end.X = rect->X;
351 end.Y = rect->Y + rect->Height;
352 break;
353 case LinearGradientModeForwardDiagonal:
354 start.X = rect->X;
355 start.Y = rect->Y;
356 end.X = rect->X + rect->Width;
357 end.Y = rect->Y + rect->Height;
358 break;
359 case LinearGradientModeBackwardDiagonal:
360 start.X = rect->X + rect->Width;
361 start.Y = rect->Y;
362 end.X = rect->X;
363 end.Y = rect->Y + rect->Height;
364 break;
365 default:
366 return InvalidParameter;
367 }
368
369 stat = GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
370
371 if (stat == Ok)
372 (*line)->rect = *rect;
373
374 return stat;
375 }
376
377 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
378 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
379 GpLineGradient **line)
380 {
381 GpRectF rectF;
382
383 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
384 wrap, line);
385
386 rectF.X = (REAL) rect->X;
387 rectF.Y = (REAL) rect->Y;
388 rectF.Width = (REAL) rect->Width;
389 rectF.Height = (REAL) rect->Height;
390
391 return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
392 }
393
394 /******************************************************************************
395 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
396 *
397 * FIXME: angle value completely ignored. Don't know how to use it since native
398 * always set Brush rectangle to rect (independetly of this angle).
399 * Maybe it's used only on drawing.
400 */
401 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
402 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
403 GpLineGradient **line)
404 {
405 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
406 wrap, line);
407
408 return GdipCreateLineBrushFromRect(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
409 wrap, line);
410 }
411
412 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
413 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
414 GpLineGradient **line)
415 {
416 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
417 wrap, line);
418
419 return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
420 wrap, line);
421 }
422
423 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
424 INT count, GpWrapMode wrap, GpPathGradient **grad)
425 {
426 COLORREF col = ARGB2COLORREF(0xffffffff);
427
428 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
429
430 if(!points || !grad)
431 return InvalidParameter;
432
433 if(count <= 0)
434 return OutOfMemory;
435
436 *grad = GdipAlloc(sizeof(GpPathGradient));
437 if (!*grad) return OutOfMemory;
438
439 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
440 if(!(*grad)->blendfac){
441 GdipFree(*grad);
442 return OutOfMemory;
443 }
444 (*grad)->blendfac[0] = 1.0;
445 (*grad)->blendpos = NULL;
446 (*grad)->blendcount = 1;
447
448 (*grad)->pathdata.Count = count;
449 (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
450 (*grad)->pathdata.Types = GdipAlloc(count);
451
452 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
453 GdipFree((*grad)->pathdata.Points);
454 GdipFree((*grad)->pathdata.Types);
455 GdipFree(*grad);
456 return OutOfMemory;
457 }
458
459 memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
460 memset((*grad)->pathdata.Types, PathPointTypeLine, count);
461
462 (*grad)->brush.lb.lbStyle = BS_SOLID;
463 (*grad)->brush.lb.lbColor = col;
464 (*grad)->brush.lb.lbHatch = 0;
465
466 (*grad)->brush.gdibrush = CreateSolidBrush(col);
467 (*grad)->brush.bt = BrushTypePathGradient;
468 (*grad)->centercolor = 0xffffffff;
469 (*grad)->wrap = wrap;
470 (*grad)->gamma = FALSE;
471 (*grad)->center.X = 0.0;
472 (*grad)->center.Y = 0.0;
473 (*grad)->focus.X = 0.0;
474 (*grad)->focus.Y = 0.0;
475
476 return Ok;
477 }
478
479 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
480 INT count, GpWrapMode wrap, GpPathGradient **grad)
481 {
482 GpPointF *pointsF;
483 GpStatus ret;
484 INT i;
485
486 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
487
488 if(!points || !grad)
489 return InvalidParameter;
490
491 if(count <= 0)
492 return OutOfMemory;
493
494 pointsF = GdipAlloc(sizeof(GpPointF) * count);
495 if(!pointsF)
496 return OutOfMemory;
497
498 for(i = 0; i < count; i++){
499 pointsF[i].X = (REAL)points[i].X;
500 pointsF[i].Y = (REAL)points[i].Y;
501 }
502
503 ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
504 GdipFree(pointsF);
505
506 return ret;
507 }
508
509 /******************************************************************************
510 * GdipCreatePathGradientFromPath [GDIPLUS.@]
511 *
512 * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
513 */
514 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
515 GpPathGradient **grad)
516 {
517 COLORREF col = ARGB2COLORREF(0xffffffff);
518
519 TRACE("(%p, %p)\n", path, grad);
520
521 if(!path || !grad)
522 return InvalidParameter;
523
524 *grad = GdipAlloc(sizeof(GpPathGradient));
525 if (!*grad) return OutOfMemory;
526
527 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
528 if(!(*grad)->blendfac){
529 GdipFree(*grad);
530 return OutOfMemory;
531 }
532 (*grad)->blendfac[0] = 1.0;
533 (*grad)->blendpos = NULL;
534 (*grad)->blendcount = 1;
535
536 (*grad)->pathdata.Count = path->pathdata.Count;
537 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
538 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
539
540 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
541 GdipFree((*grad)->pathdata.Points);
542 GdipFree((*grad)->pathdata.Types);
543 GdipFree(*grad);
544 return OutOfMemory;
545 }
546
547 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
548 path->pathdata.Count * sizeof(PointF));
549 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
550
551 (*grad)->brush.lb.lbStyle = BS_SOLID;
552 (*grad)->brush.lb.lbColor = col;
553 (*grad)->brush.lb.lbHatch = 0;
554
555 (*grad)->brush.gdibrush = CreateSolidBrush(col);
556 (*grad)->brush.bt = BrushTypePathGradient;
557 (*grad)->centercolor = 0xffffffff;
558 (*grad)->wrap = WrapModeClamp;
559 (*grad)->gamma = FALSE;
560 /* FIXME: this should be set to the "centroid" of the path by default */
561 (*grad)->center.X = 0.0;
562 (*grad)->center.Y = 0.0;
563 (*grad)->focus.X = 0.0;
564 (*grad)->focus.Y = 0.0;
565
566 return Ok;
567 }
568
569 /******************************************************************************
570 * GdipCreateSolidFill [GDIPLUS.@]
571 */
572 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
573 {
574 COLORREF col = ARGB2COLORREF(color);
575
576 TRACE("(%x, %p)\n", color, sf);
577
578 if(!sf) return InvalidParameter;
579
580 *sf = GdipAlloc(sizeof(GpSolidFill));
581 if (!*sf) return OutOfMemory;
582
583 (*sf)->brush.lb.lbStyle = BS_SOLID;
584 (*sf)->brush.lb.lbColor = col;
585 (*sf)->brush.lb.lbHatch = 0;
586
587 (*sf)->brush.gdibrush = CreateSolidBrush(col);
588 (*sf)->brush.bt = BrushTypeSolidColor;
589 (*sf)->color = color;
590
591 return Ok;
592 }
593
594 /******************************************************************************
595 * GdipCreateTexture [GDIPLUS.@]
596 *
597 * PARAMS
598 * image [I] image to use
599 * wrapmode [I] optional
600 * texture [O] pointer to the resulting texturebrush
601 *
602 * RETURNS
603 * SUCCESS: Ok
604 * FAILURE: element of GpStatus
605 */
606 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
607 GpTexture **texture)
608 {
609 UINT width, height;
610 GpImageAttributes attributes;
611 GpStatus stat;
612
613 TRACE("%p, %d %p\n", image, wrapmode, texture);
614
615 if (!(image && texture))
616 return InvalidParameter;
617
618 stat = GdipGetImageWidth(image, &width);
619 if (stat != Ok) return stat;
620 stat = GdipGetImageHeight(image, &height);
621 if (stat != Ok) return stat;
622 attributes.wrap = wrapmode;
623
624 return GdipCreateTextureIA(image, &attributes, 0, 0, width, height,
625 texture);
626 }
627
628 /******************************************************************************
629 * GdipCreateTexture2 [GDIPLUS.@]
630 */
631 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
632 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
633 {
634 GpImageAttributes attributes;
635
636 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
637 x, y, width, height, texture);
638
639 attributes.wrap = wrapmode;
640 return GdipCreateTextureIA(image, &attributes, x, y, width, height,
641 texture);
642 }
643
644 /******************************************************************************
645 * GdipCreateTextureIA [GDIPLUS.@]
646 *
647 * FIXME: imageattr ignored
648 */
649 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
650 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
651 REAL height, GpTexture **texture)
652 {
653 HDC hdc;
654 HBITMAP hbm, old = NULL;
655 BITMAPINFO *pbmi;
656 BITMAPINFOHEADER *bmih;
657 INT n_x, n_y, n_width, n_height, abs_height, stride, image_stride, i, bytespp;
658 BOOL bm_is_selected;
659 BYTE *dibits, *buff, *textbits;
660 GpStatus status;
661
662 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
663 texture);
664
665 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
666 return InvalidParameter;
667
668 if(image->type != ImageTypeBitmap){
669 FIXME("not implemented for image type %d\n", image->type);
670 return NotImplemented;
671 }
672
673 n_x = roundr(x);
674 n_y = roundr(y);
675 n_width = roundr(width);
676 n_height = roundr(height);
677
678 if(n_x + n_width > ((GpBitmap*)image)->width ||
679 n_y + n_height > ((GpBitmap*)image)->height)
680 return InvalidParameter;
681
682 IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbm);
683 if(!hbm) return GenericError;
684 IPicture_get_CurDC(image->picture, &hdc);
685 bm_is_selected = (hdc != 0);
686
687 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
688 if (!pbmi)
689 return OutOfMemory;
690 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
691 pbmi->bmiHeader.biBitCount = 0;
692
693 if(!bm_is_selected){
694 hdc = CreateCompatibleDC(0);
695 old = SelectObject(hdc, hbm);
696 }
697
698 /* fill out bmi */
699 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
700
701 bytespp = pbmi->bmiHeader.biBitCount / 8;
702 abs_height = abs(pbmi->bmiHeader.biHeight);
703
704 if(n_x > pbmi->bmiHeader.biWidth || n_x + n_width > pbmi->bmiHeader.biWidth ||
705 n_y > abs_height || n_y + n_height > abs_height){
706 GdipFree(pbmi);
707 return InvalidParameter;
708 }
709
710 dibits = GdipAlloc(pbmi->bmiHeader.biSizeImage);
711
712 if(dibits) /* this is not a good place to error out */
713 GetDIBits(hdc, hbm, 0, abs_height, dibits, pbmi, DIB_RGB_COLORS);
714
715 if(!bm_is_selected){
716 SelectObject(hdc, old);
717 DeleteDC(hdc);
718 }
719
720 if(!dibits){
721 GdipFree(pbmi);
722 return OutOfMemory;
723 }
724
725 image_stride = (pbmi->bmiHeader.biWidth * bytespp + 3) & ~3;
726 stride = (n_width * bytespp + 3) & ~3;
727 buff = GdipAlloc(sizeof(BITMAPINFOHEADER) + stride * n_height);
728 if(!buff){
729 GdipFree(pbmi);
730 GdipFree(dibits);
731 return OutOfMemory;
732 }
733
734 bmih = (BITMAPINFOHEADER*)buff;
735 textbits = (BYTE*) (bmih + 1);
736 bmih->biSize = sizeof(BITMAPINFOHEADER);
737 bmih->biWidth = n_width;
738 bmih->biHeight = n_height;
739 bmih->biCompression = BI_RGB;
740 bmih->biSizeImage = stride * n_height;
741 bmih->biBitCount = pbmi->bmiHeader.biBitCount;
742 bmih->biClrUsed = 0;
743 bmih->biPlanes = 1;
744
745 /* image is flipped */
746 if(pbmi->bmiHeader.biHeight > 0){
747 dibits += pbmi->bmiHeader.biSizeImage;
748 image_stride *= -1;
749 textbits += stride * (n_height - 1);
750 stride *= -1;
751 }
752
753 GdipFree(pbmi);
754
755 for(i = 0; i < n_height; i++)
756 memcpy(&textbits[i * stride],
757 &dibits[n_x * bytespp + (n_y + i) * image_stride],
758 abs(stride));
759
760 *texture = GdipAlloc(sizeof(GpTexture));
761 if (!*texture){
762 GdipFree(dibits);
763 GdipFree(buff);
764 return OutOfMemory;
765 }
766
767 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
768 GdipFree(*texture);
769 GdipFree(dibits);
770 GdipFree(buff);
771 return status;
772 }
773
774 (*texture)->brush.lb.lbStyle = BS_DIBPATTERNPT;
775 (*texture)->brush.lb.lbColor = DIB_RGB_COLORS;
776 (*texture)->brush.lb.lbHatch = (ULONG_PTR)buff;
777
778 (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
779 (*texture)->brush.bt = BrushTypeTextureFill;
780 (*texture)->wrap = imageattr->wrap;
781
782 GdipFree(dibits);
783 GdipFree(buff);
784
785 return Ok;
786 }
787
788 /******************************************************************************
789 * GdipCreateTextureIAI [GDIPLUS.@]
790 */
791 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
792 INT x, INT y, INT width, INT height, GpTexture **texture)
793 {
794 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
795 texture);
796
797 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
798 }
799
800 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
801 INT x, INT y, INT width, INT height, GpTexture **texture)
802 {
803 GpImageAttributes imageattr;
804
805 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
806 texture);
807
808 imageattr.wrap = wrapmode;
809
810 return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
811 }
812
813 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
814 {
815 TRACE("(%p, %p)\n", brush, type);
816
817 if(!brush || !type) return InvalidParameter;
818
819 *type = brush->bt;
820
821 return Ok;
822 }
823
824 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
825 {
826 TRACE("(%p, %p)\n", brush, backcol);
827
828 if(!brush || !backcol) return InvalidParameter;
829
830 *backcol = brush->backcol;
831
832 return Ok;
833 }
834
835 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
836 {
837 TRACE("(%p, %p)\n", brush, forecol);
838
839 if(!brush || !forecol) return InvalidParameter;
840
841 *forecol = brush->forecol;
842
843 return Ok;
844 }
845
846 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
847 {
848 TRACE("(%p, %p)\n", brush, hatchstyle);
849
850 if(!brush || !hatchstyle) return InvalidParameter;
851
852 *hatchstyle = brush->hatchstyle;
853
854 return Ok;
855 }
856
857 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
858 {
859 TRACE("(%p)\n", brush);
860
861 if(!brush) return InvalidParameter;
862
863 switch(brush->bt)
864 {
865 case BrushTypePathGradient:
866 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
867 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
868 GdipFree(((GpPathGradient*) brush)->blendfac);
869 GdipFree(((GpPathGradient*) brush)->blendpos);
870 break;
871 case BrushTypeSolidColor:
872 break;
873 case BrushTypeLinearGradient:
874 GdipFree(((GpLineGradient*)brush)->blendfac);
875 GdipFree(((GpLineGradient*)brush)->blendpos);
876 break;
877 case BrushTypeTextureFill:
878 GdipDeleteMatrix(((GpTexture*)brush)->transform);
879 break;
880 default:
881 break;
882 }
883
884 DeleteObject(brush->gdibrush);
885 GdipFree(brush);
886
887 return Ok;
888 }
889
890 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
891 BOOL *usinggamma)
892 {
893 TRACE("(%p, %p)\n", line, usinggamma);
894
895 if(!line || !usinggamma)
896 return InvalidParameter;
897
898 *usinggamma = line->gamma;
899
900 return Ok;
901 }
902
903 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
904 {
905 TRACE("(%p, %p)\n", brush, wrapmode);
906
907 if(!brush || !wrapmode)
908 return InvalidParameter;
909
910 *wrapmode = brush->wrap;
911
912 return Ok;
913 }
914
915 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
916 REAL *positions, INT count)
917 {
918 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
919
920 if(!brush || !blend || !positions || count <= 0)
921 return InvalidParameter;
922
923 if(count < brush->blendcount)
924 return InsufficientBuffer;
925
926 memcpy(blend, brush->blendfac, count*sizeof(REAL));
927 if(brush->blendcount > 1){
928 memcpy(positions, brush->blendpos, count*sizeof(REAL));
929 }
930
931 return Ok;
932 }
933
934 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
935 {
936 TRACE("(%p, %p)\n", brush, count);
937
938 if(!brush || !count)
939 return InvalidParameter;
940
941 *count = brush->blendcount;
942
943 return Ok;
944 }
945
946 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
947 GpPointF *point)
948 {
949 TRACE("(%p, %p)\n", grad, point);
950
951 if(!grad || !point)
952 return InvalidParameter;
953
954 point->X = grad->center.X;
955 point->Y = grad->center.Y;
956
957 return Ok;
958 }
959
960 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
961 GpPoint *point)
962 {
963 GpStatus ret;
964 GpPointF ptf;
965
966 TRACE("(%p, %p)\n", grad, point);
967
968 if(!point)
969 return InvalidParameter;
970
971 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
972
973 if(ret == Ok){
974 point->X = roundr(ptf.X);
975 point->Y = roundr(ptf.Y);
976 }
977
978 return ret;
979 }
980
981 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
982 REAL *x, REAL *y)
983 {
984 TRACE("(%p, %p, %p)\n", grad, x, y);
985
986 if(!grad || !x || !y)
987 return InvalidParameter;
988
989 *x = grad->focus.X;
990 *y = grad->focus.Y;
991
992 return Ok;
993 }
994
995 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
996 BOOL *gamma)
997 {
998 TRACE("(%p, %p)\n", grad, gamma);
999
1000 if(!grad || !gamma)
1001 return InvalidParameter;
1002
1003 *gamma = grad->gamma;
1004
1005 return Ok;
1006 }
1007
1008 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1009 INT *count)
1010 {
1011 TRACE("(%p, %p)\n", grad, count);
1012
1013 if(!grad || !count)
1014 return InvalidParameter;
1015
1016 *count = grad->pathdata.Count;
1017
1018 return Ok;
1019 }
1020
1021 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1022 {
1023 GpRectF r;
1024 GpPath* path;
1025 GpStatus stat;
1026
1027 TRACE("(%p, %p)\n", brush, rect);
1028
1029 if(!brush || !rect)
1030 return InvalidParameter;
1031
1032 stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
1033 brush->pathdata.Count, FillModeAlternate, &path);
1034 if(stat != Ok) return stat;
1035
1036 stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
1037 if(stat != Ok){
1038 GdipDeletePath(path);
1039 return stat;
1040 }
1041
1042 memcpy(rect, &r, sizeof(GpRectF));
1043
1044 GdipDeletePath(path);
1045
1046 return Ok;
1047 }
1048
1049 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1050 {
1051 GpRectF rectf;
1052 GpStatus stat;
1053
1054 TRACE("(%p, %p)\n", brush, rect);
1055
1056 if(!brush || !rect)
1057 return InvalidParameter;
1058
1059 stat = GdipGetPathGradientRect(brush, &rectf);
1060 if(stat != Ok) return stat;
1061
1062 rect->X = roundr(rectf.X);
1063 rect->Y = roundr(rectf.Y);
1064 rect->Width = roundr(rectf.Width);
1065 rect->Height = roundr(rectf.Height);
1066
1067 return Ok;
1068 }
1069
1070 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1071 *grad, ARGB *argb, INT *count)
1072 {
1073 static int calls;
1074
1075 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
1076 return InvalidParameter;
1077
1078 if(!(calls++))
1079 FIXME("not implemented\n");
1080
1081 return NotImplemented;
1082 }
1083
1084 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1085 GpWrapMode *wrapmode)
1086 {
1087 TRACE("(%p, %p)\n", brush, wrapmode);
1088
1089 if(!brush || !wrapmode)
1090 return InvalidParameter;
1091
1092 *wrapmode = brush->wrap;
1093
1094 return Ok;
1095 }
1096
1097 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1098 {
1099 TRACE("(%p, %p)\n", sf, argb);
1100
1101 if(!sf || !argb)
1102 return InvalidParameter;
1103
1104 *argb = sf->color;
1105
1106 return Ok;
1107 }
1108
1109 /******************************************************************************
1110 * GdipGetTextureTransform [GDIPLUS.@]
1111 */
1112 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1113 {
1114 TRACE("(%p, %p)\n", brush, matrix);
1115
1116 if(!brush || !matrix)
1117 return InvalidParameter;
1118
1119 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1120
1121 return Ok;
1122 }
1123
1124 /******************************************************************************
1125 * GdipGetTextureWrapMode [GDIPLUS.@]
1126 */
1127 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1128 {
1129 TRACE("(%p, %p)\n", brush, wrapmode);
1130
1131 if(!brush || !wrapmode)
1132 return InvalidParameter;
1133
1134 *wrapmode = brush->wrap;
1135
1136 return Ok;
1137 }
1138
1139 /******************************************************************************
1140 * GdipMultiplyTextureTransform [GDIPLUS.@]
1141 */
1142 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1143 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1144 {
1145 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1146
1147 if(!brush || !matrix)
1148 return InvalidParameter;
1149
1150 return GdipMultiplyMatrix(brush->transform, matrix, order);
1151 }
1152
1153 /******************************************************************************
1154 * GdipResetTextureTransform [GDIPLUS.@]
1155 */
1156 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1157 {
1158 TRACE("(%p)\n", brush);
1159
1160 if(!brush)
1161 return InvalidParameter;
1162
1163 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1164 }
1165
1166 /******************************************************************************
1167 * GdipScaleTextureTransform [GDIPLUS.@]
1168 */
1169 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1170 REAL sx, REAL sy, GpMatrixOrder order)
1171 {
1172 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1173
1174 if(!brush)
1175 return InvalidParameter;
1176
1177 return GdipScaleMatrix(brush->transform, sx, sy, order);
1178 }
1179
1180 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1181 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1182 {
1183 REAL *new_blendfac, *new_blendpos;
1184
1185 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1186
1187 if(!brush || !factors || !positions || count <= 0 ||
1188 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1189 return InvalidParameter;
1190
1191 new_blendfac = GdipAlloc(count * sizeof(REAL));
1192 new_blendpos = GdipAlloc(count * sizeof(REAL));
1193
1194 if (!new_blendfac || !new_blendpos)
1195 {
1196 GdipFree(new_blendfac);
1197 GdipFree(new_blendpos);
1198 return OutOfMemory;
1199 }
1200
1201 memcpy(new_blendfac, factors, count * sizeof(REAL));
1202 memcpy(new_blendpos, positions, count * sizeof(REAL));
1203
1204 GdipFree(brush->blendfac);
1205 GdipFree(brush->blendpos);
1206
1207 brush->blendcount = count;
1208 brush->blendfac = new_blendfac;
1209 brush->blendpos = new_blendpos;
1210
1211 return Ok;
1212 }
1213
1214 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1215 REAL *positions, INT count)
1216 {
1217 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1218
1219 if (!brush || !factors || !positions || count <= 0)
1220 return InvalidParameter;
1221
1222 if (count < brush->blendcount)
1223 return InsufficientBuffer;
1224
1225 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1226 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1227
1228 return Ok;
1229 }
1230
1231 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1232 {
1233 TRACE("(%p, %p)\n", brush, count);
1234
1235 if (!brush || !count)
1236 return InvalidParameter;
1237
1238 *count = brush->blendcount;
1239
1240 return Ok;
1241 }
1242
1243 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1244 BOOL usegamma)
1245 {
1246 TRACE("(%p, %d)\n", line, usegamma);
1247
1248 if(!line)
1249 return InvalidParameter;
1250
1251 line->gamma = usegamma;
1252
1253 return Ok;
1254 }
1255
1256 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1257 REAL scale)
1258 {
1259 REAL factors[33];
1260 REAL positions[33];
1261 int num_points = 0;
1262 int i;
1263 const int precision = 16;
1264 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1265 REAL min_erf;
1266 REAL scale_erf;
1267
1268 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1269
1270 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1271 return InvalidParameter;
1272
1273 /* we want 2 standard deviations */
1274 erf_range = 2.0 / sqrt(2);
1275
1276 /* calculate the constants we need to normalize the error function to be
1277 between 0.0 and scale over the range we need */
1278 min_erf = erf(-erf_range);
1279 scale_erf = scale / (-2.0 * min_erf);
1280
1281 if (focus != 0.0)
1282 {
1283 positions[0] = 0.0;
1284 factors[0] = 0.0;
1285 for (i=1; i<precision; i++)
1286 {
1287 positions[i] = focus * i / precision;
1288 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1289 }
1290 num_points += precision;
1291 }
1292
1293 positions[num_points] = focus;
1294 factors[num_points] = scale;
1295 num_points += 1;
1296
1297 if (focus != 1.0)
1298 {
1299 for (i=1; i<precision; i++)
1300 {
1301 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1302 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1303 }
1304 num_points += precision;
1305 positions[num_points-1] = 1.0;
1306 factors[num_points-1] = 0.0;
1307 }
1308
1309 return GdipSetLineBlend(line, factors, positions, num_points);
1310 }
1311
1312 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1313 GpWrapMode wrap)
1314 {
1315 TRACE("(%p, %d)\n", line, wrap);
1316
1317 if(!line || wrap == WrapModeClamp)
1318 return InvalidParameter;
1319
1320 line->wrap = wrap;
1321
1322 return Ok;
1323 }
1324
1325 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1326 GDIPCONST REAL *pos, INT count)
1327 {
1328 static int calls;
1329
1330 if(!(calls++))
1331 FIXME("not implemented\n");
1332
1333 return NotImplemented;
1334 }
1335
1336 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1337 ARGB argb)
1338 {
1339 TRACE("(%p, %x)\n", grad, argb);
1340
1341 if(!grad)
1342 return InvalidParameter;
1343
1344 grad->centercolor = argb;
1345 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1346
1347 DeleteObject(grad->brush.gdibrush);
1348 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1349
1350 return Ok;
1351 }
1352
1353 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1354 GpPointF *point)
1355 {
1356 TRACE("(%p, %p)\n", grad, point);
1357
1358 if(!grad || !point)
1359 return InvalidParameter;
1360
1361 grad->center.X = point->X;
1362 grad->center.Y = point->Y;
1363
1364 return Ok;
1365 }
1366
1367 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1368 GpPoint *point)
1369 {
1370 GpPointF ptf;
1371
1372 TRACE("(%p, %p)\n", grad, point);
1373
1374 if(!point)
1375 return InvalidParameter;
1376
1377 ptf.X = (REAL)point->X;
1378 ptf.Y = (REAL)point->Y;
1379
1380 return GdipSetPathGradientCenterPoint(grad,&ptf);
1381 }
1382
1383 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1384 REAL x, REAL y)
1385 {
1386 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1387
1388 if(!grad)
1389 return InvalidParameter;
1390
1391 grad->focus.X = x;
1392 grad->focus.Y = y;
1393
1394 return Ok;
1395 }
1396
1397 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1398 BOOL gamma)
1399 {
1400 TRACE("(%p, %d)\n", grad, gamma);
1401
1402 if(!grad)
1403 return InvalidParameter;
1404
1405 grad->gamma = gamma;
1406
1407 return Ok;
1408 }
1409
1410 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1411 REAL focus, REAL scale)
1412 {
1413 static int calls;
1414
1415 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1416 return InvalidParameter;
1417
1418 if(!(calls++))
1419 FIXME("not implemented\n");
1420
1421 return NotImplemented;
1422 }
1423
1424 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1425 *grad, ARGB *argb, INT *count)
1426 {
1427 static int calls;
1428
1429 if(!grad || !argb || !count || (*count <= 0) ||
1430 (*count > grad->pathdata.Count))
1431 return InvalidParameter;
1432
1433 if(!(calls++))
1434 FIXME("not implemented\n");
1435
1436 return NotImplemented;
1437 }
1438
1439 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1440 GpWrapMode wrap)
1441 {
1442 TRACE("(%p, %d)\n", grad, wrap);
1443
1444 if(!grad)
1445 return InvalidParameter;
1446
1447 grad->wrap = wrap;
1448
1449 return Ok;
1450 }
1451
1452 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1453 {
1454 TRACE("(%p, %x)\n", sf, argb);
1455
1456 if(!sf)
1457 return InvalidParameter;
1458
1459 sf->color = argb;
1460 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1461
1462 DeleteObject(sf->brush.gdibrush);
1463 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1464
1465 return Ok;
1466 }
1467
1468 /******************************************************************************
1469 * GdipSetTextureTransform [GDIPLUS.@]
1470 */
1471 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1472 GDIPCONST GpMatrix *matrix)
1473 {
1474 TRACE("(%p, %p)\n", texture, matrix);
1475
1476 if(!texture || !matrix)
1477 return InvalidParameter;
1478
1479 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1480
1481 return Ok;
1482 }
1483
1484 /******************************************************************************
1485 * GdipSetTextureWrapMode [GDIPLUS.@]
1486 *
1487 * WrapMode not used, only stored
1488 */
1489 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1490 {
1491 TRACE("(%p, %d)\n", brush, wrapmode);
1492
1493 if(!brush)
1494 return InvalidParameter;
1495
1496 brush->wrap = wrapmode;
1497
1498 return Ok;
1499 }
1500
1501 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1502 ARGB color2)
1503 {
1504 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1505
1506 if(!brush)
1507 return InvalidParameter;
1508
1509 brush->startcolor = color1;
1510 brush->endcolor = color2;
1511
1512 return Ok;
1513 }
1514
1515 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1516 {
1517 TRACE("(%p, %p)\n", brush, colors);
1518
1519 if(!brush || !colors)
1520 return InvalidParameter;
1521
1522 colors[0] = brush->startcolor;
1523 colors[1] = brush->endcolor;
1524
1525 return Ok;
1526 }
1527
1528 /******************************************************************************
1529 * GdipRotateTextureTransform [GDIPLUS.@]
1530 */
1531 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1532 GpMatrixOrder order)
1533 {
1534 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1535
1536 if(!brush)
1537 return InvalidParameter;
1538
1539 return GdipRotateMatrix(brush->transform, angle, order);
1540 }
1541
1542 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1543 REAL scale)
1544 {
1545 static int calls;
1546
1547 if(!(calls++))
1548 FIXME("not implemented\n");
1549
1550 return NotImplemented;
1551 }
1552
1553 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1554 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1555 {
1556 static int calls;
1557
1558 if(!(calls++))
1559 FIXME("not implemented\n");
1560
1561 return NotImplemented;
1562 }
1563
1564 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1565 GDIPCONST GpMatrix *matrix)
1566 {
1567 static int calls;
1568
1569 if(!(calls++))
1570 FIXME("not implemented\n");
1571
1572 return NotImplemented;
1573 }
1574
1575 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1576 REAL dx, REAL dy, GpMatrixOrder order)
1577 {
1578 FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1579
1580 return NotImplemented;
1581 }
1582
1583 /******************************************************************************
1584 * GdipTranslateTextureTransform [GDIPLUS.@]
1585 */
1586 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1587 GpMatrixOrder order)
1588 {
1589 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1590
1591 if(!brush)
1592 return InvalidParameter;
1593
1594 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1595 }
1596
1597 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1598 {
1599 TRACE("(%p, %p)\n", brush, rect);
1600
1601 if(!brush || !rect)
1602 return InvalidParameter;
1603
1604 *rect = brush->rect;
1605
1606 return Ok;
1607 }
1608
1609 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1610 {
1611 GpRectF rectF;
1612 GpStatus ret;
1613
1614 TRACE("(%p, %p)\n", brush, rect);
1615
1616 if(!rect)
1617 return InvalidParameter;
1618
1619 ret = GdipGetLineRect(brush, &rectF);
1620
1621 if(ret == Ok){
1622 rect->X = roundr(rectF.X);
1623 rect->Y = roundr(rectF.Y);
1624 rect->Width = roundr(rectF.Width);
1625 rect->Height = roundr(rectF.Height);
1626 }
1627
1628 return ret;
1629 }
1630
1631 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1632 REAL angle, GpMatrixOrder order)
1633 {
1634 static int calls;
1635
1636 if(!brush)
1637 return InvalidParameter;
1638
1639 if(!(calls++))
1640 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1641
1642 return NotImplemented;
1643 }