gdiplus: Implement software rendering of texture brushes.
[wine/multimedia.git] / dlls / gdiplus / brush.c
blob88958a7e73a13019fc71f3aaa241a8684f97a1cf
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
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.
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.
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
19 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winuser.h"
24 #include "wingdi.h"
26 #define COBJMACROS
27 #include "objbase.h"
28 #include "olectl.h"
29 #include "ole2.h"
31 #include "gdiplus.h"
32 #include "gdiplus_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
37 /******************************************************************************
38 * GdipCloneBrush [GDIPLUS.@]
40 GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone)
42 TRACE("(%p, %p)\n", brush, clone);
44 if(!brush || !clone)
45 return InvalidParameter;
47 switch(brush->bt){
48 case BrushTypeSolidColor:
50 GpSolidFill *fill;
51 *clone = GdipAlloc(sizeof(GpSolidFill));
52 if (!*clone) return OutOfMemory;
54 fill = (GpSolidFill*)*clone;
56 memcpy(*clone, brush, sizeof(GpSolidFill));
58 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
59 fill->bmp = ARGB2BMP(fill->color);
60 break;
62 case BrushTypeHatchFill:
64 GpHatch *hatch = (GpHatch*)brush;
66 return GdipCreateHatchBrush(hatch->hatchstyle, hatch->forecol, hatch->backcol, (GpHatch**)clone);
68 case BrushTypePathGradient:{
69 GpPathGradient *src, *dest;
70 INT count;
72 *clone = GdipAlloc(sizeof(GpPathGradient));
73 if (!*clone) return OutOfMemory;
75 src = (GpPathGradient*) brush,
76 dest = (GpPathGradient*) *clone;
77 count = src->pathdata.Count;
79 memcpy(dest, src, sizeof(GpPathGradient));
81 dest->pathdata.Count = count;
82 dest->pathdata.Points = GdipAlloc(count * sizeof(PointF));
83 dest->pathdata.Types = GdipAlloc(count);
85 if(!dest->pathdata.Points || !dest->pathdata.Types){
86 GdipFree(dest->pathdata.Points);
87 GdipFree(dest->pathdata.Types);
88 GdipFree(dest);
89 return OutOfMemory;
92 memcpy(dest->pathdata.Points, src->pathdata.Points, count * sizeof(PointF));
93 memcpy(dest->pathdata.Types, src->pathdata.Types, count);
95 /* blending */
96 count = src->blendcount;
97 dest->blendcount = count;
98 dest->blendfac = GdipAlloc(count * sizeof(REAL));
99 dest->blendpos = GdipAlloc(count * sizeof(REAL));
101 if(!dest->blendfac || !dest->blendpos){
102 GdipFree(dest->pathdata.Points);
103 GdipFree(dest->pathdata.Types);
104 GdipFree(dest->blendfac);
105 GdipFree(dest->blendpos);
106 GdipFree(dest);
107 return OutOfMemory;
110 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
111 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
113 break;
115 case BrushTypeLinearGradient:{
116 GpLineGradient *dest, *src;
117 INT count, pcount;
119 dest = GdipAlloc(sizeof(GpLineGradient));
120 if(!dest) return OutOfMemory;
122 src = (GpLineGradient*)brush;
124 memcpy(dest, src, sizeof(GpLineGradient));
126 dest->brush.gdibrush = CreateSolidBrush(dest->brush.lb.lbColor);
128 count = dest->blendcount;
129 dest->blendfac = GdipAlloc(count * sizeof(REAL));
130 dest->blendpos = GdipAlloc(count * sizeof(REAL));
131 pcount = dest->pblendcount;
132 if (pcount)
134 dest->pblendcolor = GdipAlloc(pcount * sizeof(ARGB));
135 dest->pblendpos = GdipAlloc(pcount * sizeof(REAL));
138 if (!dest->blendfac || !dest->blendpos ||
139 (pcount && (!dest->pblendcolor || !dest->pblendpos)))
141 GdipFree(dest->blendfac);
142 GdipFree(dest->blendpos);
143 GdipFree(dest->pblendcolor);
144 GdipFree(dest->pblendpos);
145 DeleteObject(dest->brush.gdibrush);
146 GdipFree(dest);
147 return OutOfMemory;
150 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
151 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
153 if (pcount)
155 memcpy(dest->pblendcolor, src->pblendcolor, pcount * sizeof(ARGB));
156 memcpy(dest->pblendpos, src->pblendpos, pcount * sizeof(REAL));
159 *clone = &dest->brush;
160 break;
162 case BrushTypeTextureFill:
164 GpStatus stat;
165 GpTexture *texture = (GpTexture*)brush;
166 GpTexture *new_texture;
167 UINT width, height;
169 stat = GdipGetImageWidth(texture->image, &width);
170 if (stat != Ok) return stat;
171 stat = GdipGetImageHeight(texture->image, &height);
172 if (stat != Ok) return stat;
174 stat = GdipCreateTextureIA(texture->image, texture->imageattributes, 0, 0, width, height, &new_texture);
176 if (stat == Ok)
178 memcpy(new_texture->transform, texture->transform, sizeof(GpMatrix));
179 *clone = (GpBrush*)new_texture;
181 else
182 *clone = NULL;
184 return stat;
186 default:
187 ERR("not implemented for brush type %d\n", brush->bt);
188 return NotImplemented;
191 TRACE("<-- %p\n", *clone);
192 return Ok;
195 static const char HatchBrushes[][8] = {
196 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HatchStyleHorizontal */
197 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleVertical */
198 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HatchStyleForwardDiagonal */
199 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HatchStyleBackwardDiagonal */
200 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleCross */
201 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }, /* HatchStyleDiagonalCross */
202 { 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x80 }, /* HatchStyle05Percent */
203 { 0x00, 0x02, 0x00, 0x88, 0x00, 0x20, 0x00, 0x88 }, /* HatchStyle10Percent */
204 { 0x00, 0x22, 0x00, 0xcc, 0x00, 0x22, 0x00, 0xcc }, /* HatchStyle20Percent */
205 { 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc }, /* HatchStyle25Percent */
206 { 0x00, 0xcc, 0x04, 0xcc, 0x00, 0xcc, 0x40, 0xcc }, /* HatchStyle30Percent */
207 { 0x44, 0xcc, 0x22, 0xcc, 0x44, 0xcc, 0x22, 0xcc }, /* HatchStyle40Percent */
208 { 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc }, /* HatchStyle50Percent */
209 { 0x55, 0xcd, 0x55, 0xee, 0x55, 0xdc, 0x55, 0xee }, /* HatchStyle60Percent */
210 { 0x55, 0xdd, 0x55, 0xff, 0x55, 0xdd, 0x55, 0xff }, /* HatchStyle70Percent */
211 { 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff }, /* HatchStyle75Percent */
212 { 0x55, 0xff, 0x59, 0xff, 0x55, 0xff, 0x99, 0xff }, /* HatchStyle80Percent */
213 { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xfd, 0xff }, /* HatchStyle90Percent */
214 { 0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88 }, /* HatchStyleLightDownwardDiagonal */
215 { 0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11 }, /* HatchStyleLightUpwardDiagonal */
216 { 0x99, 0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc }, /* HatchStyleDarkDownwardDiagonal */
217 { 0xcc, 0x66, 0x33, 0x99, 0xcc, 0x66, 0x33, 0x99 }, /* HatchStyleDarkUpwardDiagonal */
218 { 0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0 }, /* HatchStyleWideDownwardDiagonal */
219 { 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x83, 0xc1 }, /* HatchStyleWideUpwardDiagonal */
220 { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 }, /* HatchStyleLightVertical */
221 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff }, /* HatchStyleLightHorizontal */
222 { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }, /* HatchStyleNarrowVertical */
223 { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, /* HatchStyleNarrowHorizontal */
224 { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }, /* HatchStyleDarkVertical */
225 { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff }, /* HatchStyleDarkHorizontal */
228 GpStatus get_hatch_data(HatchStyle hatchstyle, const char **result)
230 if (hatchstyle < sizeof(HatchBrushes) / sizeof(HatchBrushes[0]))
232 *result = HatchBrushes[hatchstyle];
233 return Ok;
235 else
236 return NotImplemented;
239 /******************************************************************************
240 * GdipCreateHatchBrush [GDIPLUS.@]
242 GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle hatchstyle, ARGB forecol, ARGB backcol, GpHatch **brush)
244 COLORREF fgcol = ARGB2COLORREF(forecol);
245 GpStatus stat = Ok;
247 TRACE("(%d, %d, %d, %p)\n", hatchstyle, forecol, backcol, brush);
249 if(!brush) return InvalidParameter;
251 *brush = GdipAlloc(sizeof(GpHatch));
252 if (!*brush) return OutOfMemory;
254 if (hatchstyle < sizeof(HatchBrushes) / sizeof(HatchBrushes[0]))
256 HBITMAP hbmp;
257 HDC hdc;
258 BITMAPINFOHEADER bmih;
259 DWORD* bits;
260 int x, y;
262 hdc = CreateCompatibleDC(0);
264 if (hdc)
266 bmih.biSize = sizeof(bmih);
267 bmih.biWidth = 8;
268 bmih.biHeight = 8;
269 bmih.biPlanes = 1;
270 bmih.biBitCount = 32;
271 bmih.biCompression = BI_RGB;
272 bmih.biSizeImage = 0;
274 hbmp = CreateDIBSection(hdc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
276 if (hbmp)
278 for (y=0; y<8; y++)
279 for (x=0; x<8; x++)
280 if ((HatchBrushes[hatchstyle][y] & (0x80 >> x)) != 0)
281 bits[y*8+x] = forecol;
282 else
283 bits[y*8+x] = backcol;
285 else
286 stat = GenericError;
288 DeleteDC(hdc);
290 else
291 stat = GenericError;
293 if (stat == Ok)
295 (*brush)->brush.lb.lbStyle = BS_PATTERN;
296 (*brush)->brush.lb.lbColor = 0;
297 (*brush)->brush.lb.lbHatch = (ULONG_PTR)hbmp;
298 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
300 DeleteObject(hbmp);
303 else
305 FIXME("Unimplemented hatch style %d\n", hatchstyle);
307 (*brush)->brush.lb.lbStyle = BS_SOLID;
308 (*brush)->brush.lb.lbColor = fgcol;
309 (*brush)->brush.lb.lbHatch = 0;
310 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
313 if (stat == Ok)
315 (*brush)->brush.bt = BrushTypeHatchFill;
316 (*brush)->forecol = forecol;
317 (*brush)->backcol = backcol;
318 (*brush)->hatchstyle = hatchstyle;
319 TRACE("<-- %p\n", *brush);
321 else
323 GdipFree(*brush);
324 *brush = NULL;
327 return stat;
330 /******************************************************************************
331 * GdipCreateLineBrush [GDIPLUS.@]
333 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
334 GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
335 GpWrapMode wrap, GpLineGradient **line)
337 COLORREF col = ARGB2COLORREF(startcolor);
339 TRACE("(%s, %s, %x, %x, %d, %p)\n", debugstr_pointf(startpoint),
340 debugstr_pointf(endpoint), startcolor, endcolor, wrap, line);
342 if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
343 return InvalidParameter;
345 if (startpoint->X == endpoint->X && startpoint->Y == endpoint->Y)
346 return OutOfMemory;
348 *line = GdipAlloc(sizeof(GpLineGradient));
349 if(!*line) return OutOfMemory;
351 (*line)->brush.lb.lbStyle = BS_SOLID;
352 (*line)->brush.lb.lbColor = col;
353 (*line)->brush.lb.lbHatch = 0;
354 (*line)->brush.gdibrush = CreateSolidBrush(col);
355 (*line)->brush.bt = BrushTypeLinearGradient;
357 (*line)->startpoint.X = startpoint->X;
358 (*line)->startpoint.Y = startpoint->Y;
359 (*line)->endpoint.X = endpoint->X;
360 (*line)->endpoint.Y = endpoint->Y;
361 (*line)->startcolor = startcolor;
362 (*line)->endcolor = endcolor;
363 (*line)->wrap = wrap;
364 (*line)->gamma = FALSE;
366 (*line)->rect.X = (startpoint->X < endpoint->X ? startpoint->X: endpoint->X);
367 (*line)->rect.Y = (startpoint->Y < endpoint->Y ? startpoint->Y: endpoint->Y);
368 (*line)->rect.Width = fabs(startpoint->X - endpoint->X);
369 (*line)->rect.Height = fabs(startpoint->Y - endpoint->Y);
371 if ((*line)->rect.Width == 0)
373 (*line)->rect.X -= (*line)->rect.Height / 2.0f;
374 (*line)->rect.Width = (*line)->rect.Height;
376 else if ((*line)->rect.Height == 0)
378 (*line)->rect.Y -= (*line)->rect.Width / 2.0f;
379 (*line)->rect.Height = (*line)->rect.Width;
382 (*line)->blendcount = 1;
383 (*line)->blendfac = GdipAlloc(sizeof(REAL));
384 (*line)->blendpos = GdipAlloc(sizeof(REAL));
386 if (!(*line)->blendfac || !(*line)->blendpos)
388 GdipFree((*line)->blendfac);
389 GdipFree((*line)->blendpos);
390 DeleteObject((*line)->brush.gdibrush);
391 GdipFree(*line);
392 *line = NULL;
393 return OutOfMemory;
396 (*line)->blendfac[0] = 1.0f;
397 (*line)->blendpos[0] = 1.0f;
399 (*line)->pblendcolor = NULL;
400 (*line)->pblendpos = NULL;
401 (*line)->pblendcount = 0;
403 TRACE("<-- %p\n", *line);
405 return Ok;
408 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
409 GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
410 GpWrapMode wrap, GpLineGradient **line)
412 GpPointF stF;
413 GpPointF endF;
415 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
416 startcolor, endcolor, wrap, line);
418 if(!startpoint || !endpoint)
419 return InvalidParameter;
421 stF.X = (REAL)startpoint->X;
422 stF.Y = (REAL)startpoint->Y;
423 endF.X = (REAL)endpoint->X;
424 endF.Y = (REAL)endpoint->Y;
426 return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
429 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
430 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
431 GpLineGradient **line)
433 GpPointF start, end;
434 GpStatus stat;
436 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
437 wrap, line);
439 if(!line || !rect)
440 return InvalidParameter;
442 switch (mode)
444 case LinearGradientModeHorizontal:
445 start.X = rect->X;
446 start.Y = rect->Y;
447 end.X = rect->X + rect->Width;
448 end.Y = rect->Y;
449 break;
450 case LinearGradientModeVertical:
451 start.X = rect->X;
452 start.Y = rect->Y;
453 end.X = rect->X;
454 end.Y = rect->Y + rect->Height;
455 break;
456 case LinearGradientModeForwardDiagonal:
457 start.X = rect->X;
458 start.Y = rect->Y;
459 end.X = rect->X + rect->Width;
460 end.Y = rect->Y + rect->Height;
461 break;
462 case LinearGradientModeBackwardDiagonal:
463 start.X = rect->X + rect->Width;
464 start.Y = rect->Y;
465 end.X = rect->X;
466 end.Y = rect->Y + rect->Height;
467 break;
468 default:
469 return InvalidParameter;
472 stat = GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
474 if (stat == Ok)
475 (*line)->rect = *rect;
477 return stat;
480 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
481 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
482 GpLineGradient **line)
484 GpRectF rectF;
486 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
487 wrap, line);
489 rectF.X = (REAL) rect->X;
490 rectF.Y = (REAL) rect->Y;
491 rectF.Width = (REAL) rect->Width;
492 rectF.Height = (REAL) rect->Height;
494 return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
497 /******************************************************************************
498 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
500 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
501 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
502 GpLineGradient **line)
504 GpStatus stat;
505 LinearGradientMode mode;
506 REAL width, height, exofs, eyofs;
507 REAL sin_angle, cos_angle, sin_cos_angle;
509 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
510 wrap, line);
512 sin_angle = sinf(deg2rad(angle));
513 cos_angle = cosf(deg2rad(angle));
514 sin_cos_angle = sin_angle * cos_angle;
516 if (isAngleScalable)
518 width = height = 1.0;
520 else
522 width = rect->Width;
523 height = rect->Height;
526 if (sin_cos_angle >= 0)
527 mode = LinearGradientModeForwardDiagonal;
528 else
529 mode = LinearGradientModeBackwardDiagonal;
531 stat = GdipCreateLineBrushFromRect(rect, startcolor, endcolor, mode, wrap, line);
533 if (stat == Ok)
535 if (sin_cos_angle >= 0)
537 exofs = width * sin_cos_angle + height * cos_angle * cos_angle;
538 eyofs = width * sin_angle * sin_angle + height * sin_cos_angle;
540 else
542 exofs = width * sin_angle * sin_angle + height * sin_cos_angle;
543 eyofs = -width * sin_cos_angle + height * sin_angle * sin_angle;
546 if (isAngleScalable)
548 exofs = exofs * rect->Width;
549 eyofs = eyofs * rect->Height;
552 if (sin_angle >= 0)
554 (*line)->endpoint.X = rect->X + exofs;
555 (*line)->endpoint.Y = rect->Y + eyofs;
557 else
559 (*line)->endpoint.X = (*line)->startpoint.X;
560 (*line)->endpoint.Y = (*line)->startpoint.Y;
561 (*line)->startpoint.X = rect->X + exofs;
562 (*line)->startpoint.Y = rect->Y + eyofs;
566 return stat;
569 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
570 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
571 GpLineGradient **line)
573 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
574 wrap, line);
576 return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
577 wrap, line);
580 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
581 INT count, GpWrapMode wrap, GpPathGradient **grad)
583 COLORREF col = ARGB2COLORREF(0xffffffff);
585 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
587 if(!points || !grad)
588 return InvalidParameter;
590 if(count <= 0)
591 return OutOfMemory;
593 *grad = GdipAlloc(sizeof(GpPathGradient));
594 if (!*grad) return OutOfMemory;
596 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
597 (*grad)->blendpos = GdipAlloc(sizeof(REAL));
598 if(!(*grad)->blendfac || !(*grad)->blendpos){
599 GdipFree((*grad)->blendfac);
600 GdipFree((*grad)->blendpos);
601 GdipFree(*grad);
602 *grad = NULL;
603 return OutOfMemory;
605 (*grad)->blendfac[0] = 1.0;
606 (*grad)->blendpos[0] = 1.0;
607 (*grad)->blendcount = 1;
609 (*grad)->pathdata.Count = count;
610 (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
611 (*grad)->pathdata.Types = GdipAlloc(count);
613 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
614 GdipFree((*grad)->pathdata.Points);
615 GdipFree((*grad)->pathdata.Types);
616 GdipFree(*grad);
617 return OutOfMemory;
620 memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
621 memset((*grad)->pathdata.Types, PathPointTypeLine, count);
623 (*grad)->brush.lb.lbStyle = BS_SOLID;
624 (*grad)->brush.lb.lbColor = col;
625 (*grad)->brush.lb.lbHatch = 0;
627 (*grad)->brush.gdibrush = CreateSolidBrush(col);
628 (*grad)->brush.bt = BrushTypePathGradient;
629 (*grad)->centercolor = 0xffffffff;
630 (*grad)->wrap = wrap;
631 (*grad)->gamma = FALSE;
632 (*grad)->center.X = 0.0;
633 (*grad)->center.Y = 0.0;
634 (*grad)->focus.X = 0.0;
635 (*grad)->focus.Y = 0.0;
637 TRACE("<-- %p\n", *grad);
639 return Ok;
642 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
643 INT count, GpWrapMode wrap, GpPathGradient **grad)
645 GpPointF *pointsF;
646 GpStatus ret;
647 INT i;
649 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
651 if(!points || !grad)
652 return InvalidParameter;
654 if(count <= 0)
655 return OutOfMemory;
657 pointsF = GdipAlloc(sizeof(GpPointF) * count);
658 if(!pointsF)
659 return OutOfMemory;
661 for(i = 0; i < count; i++){
662 pointsF[i].X = (REAL)points[i].X;
663 pointsF[i].Y = (REAL)points[i].Y;
666 ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
667 GdipFree(pointsF);
669 return ret;
672 /******************************************************************************
673 * GdipCreatePathGradientFromPath [GDIPLUS.@]
675 * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
677 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
678 GpPathGradient **grad)
680 COLORREF col = ARGB2COLORREF(0xffffffff);
682 TRACE("(%p, %p)\n", path, grad);
684 if(!path || !grad)
685 return InvalidParameter;
687 *grad = GdipAlloc(sizeof(GpPathGradient));
688 if (!*grad) return OutOfMemory;
690 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
691 (*grad)->blendpos = GdipAlloc(sizeof(REAL));
692 if(!(*grad)->blendfac || !(*grad)->blendpos){
693 GdipFree((*grad)->blendfac);
694 GdipFree((*grad)->blendpos);
695 GdipFree(*grad);
696 *grad = NULL;
697 return OutOfMemory;
699 (*grad)->blendfac[0] = 1.0;
700 (*grad)->blendpos[0] = 1.0;
701 (*grad)->blendcount = 1;
703 (*grad)->pathdata.Count = path->pathdata.Count;
704 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
705 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
707 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
708 GdipFree((*grad)->pathdata.Points);
709 GdipFree((*grad)->pathdata.Types);
710 GdipFree(*grad);
711 return OutOfMemory;
714 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
715 path->pathdata.Count * sizeof(PointF));
716 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
718 (*grad)->brush.lb.lbStyle = BS_SOLID;
719 (*grad)->brush.lb.lbColor = col;
720 (*grad)->brush.lb.lbHatch = 0;
722 (*grad)->brush.gdibrush = CreateSolidBrush(col);
723 (*grad)->brush.bt = BrushTypePathGradient;
724 (*grad)->centercolor = 0xffffffff;
725 (*grad)->wrap = WrapModeClamp;
726 (*grad)->gamma = FALSE;
727 /* FIXME: this should be set to the "centroid" of the path by default */
728 (*grad)->center.X = 0.0;
729 (*grad)->center.Y = 0.0;
730 (*grad)->focus.X = 0.0;
731 (*grad)->focus.Y = 0.0;
733 TRACE("<-- %p\n", *grad);
735 return Ok;
738 /******************************************************************************
739 * GdipCreateSolidFill [GDIPLUS.@]
741 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
743 COLORREF col = ARGB2COLORREF(color);
745 TRACE("(%x, %p)\n", color, sf);
747 if(!sf) return InvalidParameter;
749 *sf = GdipAlloc(sizeof(GpSolidFill));
750 if (!*sf) return OutOfMemory;
752 (*sf)->brush.lb.lbStyle = BS_SOLID;
753 (*sf)->brush.lb.lbColor = col;
754 (*sf)->brush.lb.lbHatch = 0;
756 (*sf)->brush.gdibrush = CreateSolidBrush(col);
757 (*sf)->brush.bt = BrushTypeSolidColor;
758 (*sf)->color = color;
759 (*sf)->bmp = ARGB2BMP(color);
761 TRACE("<-- %p\n", *sf);
763 return Ok;
766 /******************************************************************************
767 * GdipCreateTexture [GDIPLUS.@]
769 * PARAMS
770 * image [I] image to use
771 * wrapmode [I] optional
772 * texture [O] pointer to the resulting texturebrush
774 * RETURNS
775 * SUCCESS: Ok
776 * FAILURE: element of GpStatus
778 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
779 GpTexture **texture)
781 UINT width, height;
782 GpImageAttributes *attributes;
783 GpStatus stat;
785 TRACE("%p, %d %p\n", image, wrapmode, texture);
787 if (!(image && texture))
788 return InvalidParameter;
790 stat = GdipGetImageWidth(image, &width);
791 if (stat != Ok) return stat;
792 stat = GdipGetImageHeight(image, &height);
793 if (stat != Ok) return stat;
795 stat = GdipCreateImageAttributes(&attributes);
797 if (stat == Ok)
799 attributes->wrap = wrapmode;
801 stat = GdipCreateTextureIA(image, attributes, 0, 0, width, height,
802 texture);
804 GdipDisposeImageAttributes(attributes);
807 return stat;
810 /******************************************************************************
811 * GdipCreateTexture2 [GDIPLUS.@]
813 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
814 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
816 GpImageAttributes *attributes;
817 GpStatus stat;
819 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
820 x, y, width, height, texture);
822 stat = GdipCreateImageAttributes(&attributes);
824 if (stat == Ok)
826 attributes->wrap = wrapmode;
828 stat = GdipCreateTextureIA(image, attributes, x, y, width, height,
829 texture);
831 GdipDisposeImageAttributes(attributes);
834 return stat;
837 /******************************************************************************
838 * GdipCreateTextureIA [GDIPLUS.@]
840 * FIXME: imageattr ignored
842 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
843 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
844 REAL height, GpTexture **texture)
846 HBITMAP hbm=NULL;
847 GpStatus status;
848 GpImage *new_image=NULL;
850 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
851 texture);
853 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
854 return InvalidParameter;
856 *texture = NULL;
858 if(image->type != ImageTypeBitmap){
859 FIXME("not implemented for image type %d\n", image->type);
860 return NotImplemented;
863 status = GdipCloneBitmapArea(x, y, width, height, PixelFormatDontCare, (GpBitmap*)image, (GpBitmap**)&new_image);
864 if (status != Ok)
865 return status;
867 status = GdipCreateHBITMAPFromBitmap((GpBitmap*)new_image, &hbm, 0);
868 if(!hbm)
870 status = GenericError;
871 goto exit;
874 *texture = GdipAlloc(sizeof(GpTexture));
875 if (!*texture){
876 status = OutOfMemory;
877 goto exit;
880 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
881 goto exit;
884 if (imageattr)
886 status = GdipCloneImageAttributes(imageattr, &(*texture)->imageattributes);
888 else
890 status = GdipCreateImageAttributes(&(*texture)->imageattributes);
891 if (status == Ok)
892 (*texture)->imageattributes->wrap = WrapModeTile;
894 if (status != Ok)
895 goto exit;
897 (*texture)->brush.lb.lbStyle = BS_PATTERN;
898 (*texture)->brush.lb.lbColor = 0;
899 (*texture)->brush.lb.lbHatch = (ULONG_PTR)hbm;
901 (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
902 (*texture)->brush.bt = BrushTypeTextureFill;
903 (*texture)->image = new_image;
905 exit:
906 if (status == Ok)
908 TRACE("<-- %p\n", *texture);
910 else
912 if (*texture)
914 GdipDeleteMatrix((*texture)->transform);
915 GdipDisposeImageAttributes((*texture)->imageattributes);
916 GdipFree(*texture);
917 *texture = NULL;
919 GdipDisposeImage(new_image);
920 TRACE("<-- error %u\n", status);
923 DeleteObject(hbm);
925 return status;
928 /******************************************************************************
929 * GdipCreateTextureIAI [GDIPLUS.@]
931 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
932 INT x, INT y, INT width, INT height, GpTexture **texture)
934 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
935 texture);
937 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
940 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
941 INT x, INT y, INT width, INT height, GpTexture **texture)
943 GpImageAttributes imageattr;
945 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
946 texture);
948 imageattr.wrap = wrapmode;
950 return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
953 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
955 TRACE("(%p, %p)\n", brush, type);
957 if(!brush || !type) return InvalidParameter;
959 *type = brush->bt;
961 return Ok;
964 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
966 TRACE("(%p, %p)\n", brush, backcol);
968 if(!brush || !backcol) return InvalidParameter;
970 *backcol = brush->backcol;
972 return Ok;
975 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
977 TRACE("(%p, %p)\n", brush, forecol);
979 if(!brush || !forecol) return InvalidParameter;
981 *forecol = brush->forecol;
983 return Ok;
986 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
988 TRACE("(%p, %p)\n", brush, hatchstyle);
990 if(!brush || !hatchstyle) return InvalidParameter;
992 *hatchstyle = brush->hatchstyle;
994 return Ok;
997 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
999 TRACE("(%p)\n", brush);
1001 if(!brush) return InvalidParameter;
1003 switch(brush->bt)
1005 case BrushTypePathGradient:
1006 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
1007 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
1008 GdipFree(((GpPathGradient*) brush)->blendfac);
1009 GdipFree(((GpPathGradient*) brush)->blendpos);
1010 break;
1011 case BrushTypeSolidColor:
1012 if (((GpSolidFill*)brush)->bmp)
1013 DeleteObject(((GpSolidFill*)brush)->bmp);
1014 break;
1015 case BrushTypeLinearGradient:
1016 GdipFree(((GpLineGradient*)brush)->blendfac);
1017 GdipFree(((GpLineGradient*)brush)->blendpos);
1018 GdipFree(((GpLineGradient*)brush)->pblendcolor);
1019 GdipFree(((GpLineGradient*)brush)->pblendpos);
1020 break;
1021 case BrushTypeTextureFill:
1022 GdipDeleteMatrix(((GpTexture*)brush)->transform);
1023 GdipDisposeImage(((GpTexture*)brush)->image);
1024 GdipDisposeImageAttributes(((GpTexture*)brush)->imageattributes);
1025 GdipFree(((GpTexture*)brush)->bitmap_bits);
1026 break;
1027 default:
1028 break;
1031 DeleteObject(brush->gdibrush);
1032 GdipFree(brush);
1034 return Ok;
1037 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
1038 BOOL *usinggamma)
1040 TRACE("(%p, %p)\n", line, usinggamma);
1042 if(!line || !usinggamma)
1043 return InvalidParameter;
1045 *usinggamma = line->gamma;
1047 return Ok;
1050 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
1052 TRACE("(%p, %p)\n", brush, wrapmode);
1054 if(!brush || !wrapmode)
1055 return InvalidParameter;
1057 *wrapmode = brush->wrap;
1059 return Ok;
1062 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
1063 REAL *positions, INT count)
1065 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
1067 if(!brush || !blend || !positions || count <= 0)
1068 return InvalidParameter;
1070 if(count < brush->blendcount)
1071 return InsufficientBuffer;
1073 memcpy(blend, brush->blendfac, count*sizeof(REAL));
1074 if(brush->blendcount > 1){
1075 memcpy(positions, brush->blendpos, count*sizeof(REAL));
1078 return Ok;
1081 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
1083 TRACE("(%p, %p)\n", brush, count);
1085 if(!brush || !count)
1086 return InvalidParameter;
1088 *count = brush->blendcount;
1090 return Ok;
1093 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
1094 GpPointF *point)
1096 TRACE("(%p, %p)\n", grad, point);
1098 if(!grad || !point)
1099 return InvalidParameter;
1101 point->X = grad->center.X;
1102 point->Y = grad->center.Y;
1104 return Ok;
1107 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
1108 GpPoint *point)
1110 GpStatus ret;
1111 GpPointF ptf;
1113 TRACE("(%p, %p)\n", grad, point);
1115 if(!point)
1116 return InvalidParameter;
1118 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
1120 if(ret == Ok){
1121 point->X = roundr(ptf.X);
1122 point->Y = roundr(ptf.Y);
1125 return ret;
1128 GpStatus WINGDIPAPI GdipGetPathGradientCenterColor(GpPathGradient *grad,
1129 ARGB *colors)
1131 static int calls;
1133 TRACE("(%p,%p)\n", grad, colors);
1135 if(!(calls++))
1136 FIXME("not implemented\n");
1138 return NotImplemented;
1141 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
1142 REAL *x, REAL *y)
1144 TRACE("(%p, %p, %p)\n", grad, x, y);
1146 if(!grad || !x || !y)
1147 return InvalidParameter;
1149 *x = grad->focus.X;
1150 *y = grad->focus.Y;
1152 return Ok;
1155 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
1156 BOOL *gamma)
1158 TRACE("(%p, %p)\n", grad, gamma);
1160 if(!grad || !gamma)
1161 return InvalidParameter;
1163 *gamma = grad->gamma;
1165 return Ok;
1168 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
1169 INT *count)
1171 TRACE("(%p, %p)\n", grad, count);
1173 if(!grad || !count)
1174 return InvalidParameter;
1176 *count = grad->pathdata.Count;
1178 return Ok;
1181 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1183 GpRectF r;
1184 GpPath* path;
1185 GpStatus stat;
1187 TRACE("(%p, %p)\n", brush, rect);
1189 if(!brush || !rect)
1190 return InvalidParameter;
1192 stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
1193 brush->pathdata.Count, FillModeAlternate, &path);
1194 if(stat != Ok) return stat;
1196 stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
1197 if(stat != Ok){
1198 GdipDeletePath(path);
1199 return stat;
1202 memcpy(rect, &r, sizeof(GpRectF));
1204 GdipDeletePath(path);
1206 return Ok;
1209 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1211 GpRectF rectf;
1212 GpStatus stat;
1214 TRACE("(%p, %p)\n", brush, rect);
1216 if(!brush || !rect)
1217 return InvalidParameter;
1219 stat = GdipGetPathGradientRect(brush, &rectf);
1220 if(stat != Ok) return stat;
1222 rect->X = roundr(rectf.X);
1223 rect->Y = roundr(rectf.Y);
1224 rect->Width = roundr(rectf.Width);
1225 rect->Height = roundr(rectf.Height);
1227 return Ok;
1230 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1231 *grad, ARGB *argb, INT *count)
1233 static int calls;
1235 TRACE("(%p,%p,%p)\n", grad, argb, count);
1237 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
1238 return InvalidParameter;
1240 if(!(calls++))
1241 FIXME("not implemented\n");
1243 return NotImplemented;
1246 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorCount(GpPathGradient *brush, INT *count)
1248 TRACE("(%p, %p)\n", brush, count);
1250 if (!brush || !count)
1251 return InvalidParameter;
1253 return NotImplemented;
1256 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1257 GpWrapMode *wrapmode)
1259 TRACE("(%p, %p)\n", brush, wrapmode);
1261 if(!brush || !wrapmode)
1262 return InvalidParameter;
1264 *wrapmode = brush->wrap;
1266 return Ok;
1269 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1271 TRACE("(%p, %p)\n", sf, argb);
1273 if(!sf || !argb)
1274 return InvalidParameter;
1276 *argb = sf->color;
1278 return Ok;
1281 /******************************************************************************
1282 * GdipGetTextureImage [GDIPLUS.@]
1284 GpStatus WINGDIPAPI GdipGetTextureImage(GpTexture *brush, GpImage **image)
1286 TRACE("(%p, %p)\n", brush, image);
1288 if(!brush || !image)
1289 return InvalidParameter;
1291 return GdipCloneImage(brush->image, image);
1294 /******************************************************************************
1295 * GdipGetTextureTransform [GDIPLUS.@]
1297 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1299 TRACE("(%p, %p)\n", brush, matrix);
1301 if(!brush || !matrix)
1302 return InvalidParameter;
1304 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1306 return Ok;
1309 /******************************************************************************
1310 * GdipGetTextureWrapMode [GDIPLUS.@]
1312 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1314 TRACE("(%p, %p)\n", brush, wrapmode);
1316 if(!brush || !wrapmode)
1317 return InvalidParameter;
1319 *wrapmode = brush->imageattributes->wrap;
1321 return Ok;
1324 /******************************************************************************
1325 * GdipMultiplyTextureTransform [GDIPLUS.@]
1327 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1328 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1330 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1332 if(!brush || !matrix)
1333 return InvalidParameter;
1335 return GdipMultiplyMatrix(brush->transform, matrix, order);
1338 /******************************************************************************
1339 * GdipResetTextureTransform [GDIPLUS.@]
1341 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1343 TRACE("(%p)\n", brush);
1345 if(!brush)
1346 return InvalidParameter;
1348 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1351 /******************************************************************************
1352 * GdipScaleTextureTransform [GDIPLUS.@]
1354 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1355 REAL sx, REAL sy, GpMatrixOrder order)
1357 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1359 if(!brush)
1360 return InvalidParameter;
1362 return GdipScaleMatrix(brush->transform, sx, sy, order);
1365 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1366 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1368 REAL *new_blendfac, *new_blendpos;
1370 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1372 if(!brush || !factors || !positions || count <= 0 ||
1373 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1374 return InvalidParameter;
1376 new_blendfac = GdipAlloc(count * sizeof(REAL));
1377 new_blendpos = GdipAlloc(count * sizeof(REAL));
1379 if (!new_blendfac || !new_blendpos)
1381 GdipFree(new_blendfac);
1382 GdipFree(new_blendpos);
1383 return OutOfMemory;
1386 memcpy(new_blendfac, factors, count * sizeof(REAL));
1387 memcpy(new_blendpos, positions, count * sizeof(REAL));
1389 GdipFree(brush->blendfac);
1390 GdipFree(brush->blendpos);
1392 brush->blendcount = count;
1393 brush->blendfac = new_blendfac;
1394 brush->blendpos = new_blendpos;
1396 return Ok;
1399 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1400 REAL *positions, INT count)
1402 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1404 if (!brush || !factors || !positions || count <= 0)
1405 return InvalidParameter;
1407 if (count < brush->blendcount)
1408 return InsufficientBuffer;
1410 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1411 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1413 return Ok;
1416 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1418 TRACE("(%p, %p)\n", brush, count);
1420 if (!brush || !count)
1421 return InvalidParameter;
1423 *count = brush->blendcount;
1425 return Ok;
1428 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1429 BOOL usegamma)
1431 TRACE("(%p, %d)\n", line, usegamma);
1433 if(!line)
1434 return InvalidParameter;
1436 line->gamma = usegamma;
1438 return Ok;
1441 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1442 REAL scale)
1444 REAL factors[33];
1445 REAL positions[33];
1446 int num_points = 0;
1447 int i;
1448 const int precision = 16;
1449 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1450 REAL min_erf;
1451 REAL scale_erf;
1453 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1455 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1456 return InvalidParameter;
1458 /* we want 2 standard deviations */
1459 erf_range = 2.0 / sqrt(2);
1461 /* calculate the constants we need to normalize the error function to be
1462 between 0.0 and scale over the range we need */
1463 min_erf = erf(-erf_range);
1464 scale_erf = scale / (-2.0 * min_erf);
1466 if (focus != 0.0)
1468 positions[0] = 0.0;
1469 factors[0] = 0.0;
1470 for (i=1; i<precision; i++)
1472 positions[i] = focus * i / precision;
1473 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1475 num_points += precision;
1478 positions[num_points] = focus;
1479 factors[num_points] = scale;
1480 num_points += 1;
1482 if (focus != 1.0)
1484 for (i=1; i<precision; i++)
1486 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1487 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1489 num_points += precision;
1490 positions[num_points-1] = 1.0;
1491 factors[num_points-1] = 0.0;
1494 return GdipSetLineBlend(line, factors, positions, num_points);
1497 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1498 GpWrapMode wrap)
1500 TRACE("(%p, %d)\n", line, wrap);
1502 if(!line || wrap == WrapModeClamp)
1503 return InvalidParameter;
1505 line->wrap = wrap;
1507 return Ok;
1510 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1511 GDIPCONST REAL *pos, INT count)
1513 static int calls;
1515 TRACE("(%p,%p,%p,%i)\n", brush, blend, pos, count);
1517 if(!(calls++))
1518 FIXME("not implemented\n");
1520 return NotImplemented;
1523 GpStatus WINGDIPAPI GdipSetPathGradientLinearBlend(GpPathGradient *brush,
1524 REAL focus, REAL scale)
1526 static int calls;
1528 TRACE("(%p,%0.2f,%0.2f)\n", brush, focus, scale);
1530 if(!(calls++))
1531 FIXME("not implemented\n");
1533 return NotImplemented;
1536 GpStatus WINGDIPAPI GdipSetPathGradientPresetBlend(GpPathGradient *brush,
1537 GDIPCONST ARGB *blend, GDIPCONST REAL *pos, INT count)
1539 FIXME("(%p,%p,%p,%i): stub\n", brush, blend, pos, count);
1540 return NotImplemented;
1543 GpStatus WINGDIPAPI GdipGetPathGradientPresetBlend(GpPathGradient *brush,
1544 ARGB *blend, REAL *pos, INT count)
1546 FIXME("(%p,%p,%p,%i): stub\n", brush, blend, pos, count);
1547 return NotImplemented;
1550 GpStatus WINGDIPAPI GdipGetPathGradientPresetBlendCount(GpPathGradient *brush,
1551 INT *count)
1553 FIXME("(%p,%p): stub\n", brush, count);
1554 return NotImplemented;
1557 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1558 ARGB argb)
1560 TRACE("(%p, %x)\n", grad, argb);
1562 if(!grad)
1563 return InvalidParameter;
1565 grad->centercolor = argb;
1566 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1568 DeleteObject(grad->brush.gdibrush);
1569 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1571 return Ok;
1574 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1575 GpPointF *point)
1577 TRACE("(%p, %s)\n", grad, debugstr_pointf(point));
1579 if(!grad || !point)
1580 return InvalidParameter;
1582 grad->center.X = point->X;
1583 grad->center.Y = point->Y;
1585 return Ok;
1588 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1589 GpPoint *point)
1591 GpPointF ptf;
1593 TRACE("(%p, %p)\n", grad, point);
1595 if(!point)
1596 return InvalidParameter;
1598 ptf.X = (REAL)point->X;
1599 ptf.Y = (REAL)point->Y;
1601 return GdipSetPathGradientCenterPoint(grad,&ptf);
1604 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1605 REAL x, REAL y)
1607 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1609 if(!grad)
1610 return InvalidParameter;
1612 grad->focus.X = x;
1613 grad->focus.Y = y;
1615 return Ok;
1618 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1619 BOOL gamma)
1621 TRACE("(%p, %d)\n", grad, gamma);
1623 if(!grad)
1624 return InvalidParameter;
1626 grad->gamma = gamma;
1628 return Ok;
1631 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1632 REAL focus, REAL scale)
1634 static int calls;
1636 TRACE("(%p,%0.2f,%0.2f)\n", grad, focus, scale);
1638 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1639 return InvalidParameter;
1641 if(!(calls++))
1642 FIXME("not implemented\n");
1644 return NotImplemented;
1647 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1648 *grad, GDIPCONST ARGB *argb, INT *count)
1650 static int calls;
1652 TRACE("(%p,%p,%p)\n", grad, argb, count);
1654 if(!grad || !argb || !count || (*count <= 0) ||
1655 (*count > grad->pathdata.Count))
1656 return InvalidParameter;
1658 if(!(calls++))
1659 FIXME("not implemented\n");
1661 return NotImplemented;
1664 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1665 GpWrapMode wrap)
1667 TRACE("(%p, %d)\n", grad, wrap);
1669 if(!grad)
1670 return InvalidParameter;
1672 grad->wrap = wrap;
1674 return Ok;
1677 GpStatus WINGDIPAPI GdipSetPathGradientTransform(GpPathGradient *grad,
1678 GpMatrix *matrix)
1680 static int calls;
1682 TRACE("(%p,%p)\n", grad, matrix);
1684 if(!(calls++))
1685 FIXME("not implemented\n");
1687 return NotImplemented;
1690 GpStatus WINGDIPAPI GdipGetPathGradientTransform(GpPathGradient *grad,
1691 GpMatrix *matrix)
1693 static int calls;
1695 TRACE("(%p,%p)\n", grad, matrix);
1697 if(!(calls++))
1698 FIXME("not implemented\n");
1700 return NotImplemented;
1703 GpStatus WINGDIPAPI GdipMultiplyPathGradientTransform(GpPathGradient *grad,
1704 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1706 static int calls;
1708 TRACE("(%p,%p,%i)\n", grad, matrix, order);
1710 if(!(calls++))
1711 FIXME("not implemented\n");
1713 return NotImplemented;
1716 GpStatus WINGDIPAPI GdipRotatePathGradientTransform(GpPathGradient *grad,
1717 REAL angle, GpMatrixOrder order)
1719 static int calls;
1721 TRACE("(%p,%0.2f,%i)\n", grad, angle, order);
1723 if(!(calls++))
1724 FIXME("not implemented\n");
1726 return NotImplemented;
1729 GpStatus WINGDIPAPI GdipScalePathGradientTransform(GpPathGradient *grad,
1730 REAL sx, REAL sy, GpMatrixOrder order)
1732 static int calls;
1734 TRACE("(%p,%0.2f,%0.2f,%i)\n", grad, sx, sy, order);
1736 if(!(calls++))
1737 FIXME("not implemented\n");
1739 return NotImplemented;
1742 GpStatus WINGDIPAPI GdipTranslatePathGradientTransform(GpPathGradient *grad,
1743 REAL dx, REAL dy, GpMatrixOrder order)
1745 static int calls;
1747 TRACE("(%p,%0.2f,%0.2f,%i)\n", grad, dx, dy, order);
1749 if(!(calls++))
1750 FIXME("not implemented\n");
1752 return NotImplemented;
1755 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1757 TRACE("(%p, %x)\n", sf, argb);
1759 if(!sf)
1760 return InvalidParameter;
1762 sf->color = argb;
1763 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1765 DeleteObject(sf->brush.gdibrush);
1766 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1768 return Ok;
1771 /******************************************************************************
1772 * GdipSetTextureTransform [GDIPLUS.@]
1774 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1775 GDIPCONST GpMatrix *matrix)
1777 TRACE("(%p, %p)\n", texture, matrix);
1779 if(!texture || !matrix)
1780 return InvalidParameter;
1782 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1784 return Ok;
1787 /******************************************************************************
1788 * GdipSetTextureWrapMode [GDIPLUS.@]
1790 * WrapMode not used, only stored
1792 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1794 TRACE("(%p, %d)\n", brush, wrapmode);
1796 if(!brush)
1797 return InvalidParameter;
1799 brush->imageattributes->wrap = wrapmode;
1801 return Ok;
1804 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1805 ARGB color2)
1807 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1809 if(!brush)
1810 return InvalidParameter;
1812 brush->startcolor = color1;
1813 brush->endcolor = color2;
1815 return Ok;
1818 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1820 TRACE("(%p, %p)\n", brush, colors);
1822 if(!brush || !colors)
1823 return InvalidParameter;
1825 colors[0] = brush->startcolor;
1826 colors[1] = brush->endcolor;
1828 return Ok;
1831 /******************************************************************************
1832 * GdipRotateTextureTransform [GDIPLUS.@]
1834 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1835 GpMatrixOrder order)
1837 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1839 if(!brush)
1840 return InvalidParameter;
1842 return GdipRotateMatrix(brush->transform, angle, order);
1845 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1846 REAL scale)
1848 REAL factors[3];
1849 REAL positions[3];
1850 int num_points = 0;
1852 TRACE("(%p,%.2f,%.2f)\n", brush, focus, scale);
1854 if (!brush) return InvalidParameter;
1856 if (focus != 0.0)
1858 factors[num_points] = 0.0;
1859 positions[num_points] = 0.0;
1860 num_points++;
1863 factors[num_points] = scale;
1864 positions[num_points] = focus;
1865 num_points++;
1867 if (focus != 1.0)
1869 factors[num_points] = 0.0;
1870 positions[num_points] = 1.0;
1871 num_points++;
1874 return GdipSetLineBlend(brush, factors, positions, num_points);
1877 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1878 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1880 ARGB *new_color;
1881 REAL *new_pos;
1882 TRACE("(%p,%p,%p,%i)\n", brush, blend, positions, count);
1884 if (!brush || !blend || !positions || count < 2 ||
1885 positions[0] != 0.0f || positions[count-1] != 1.0f)
1887 return InvalidParameter;
1890 new_color = GdipAlloc(count * sizeof(ARGB));
1891 new_pos = GdipAlloc(count * sizeof(REAL));
1892 if (!new_color || !new_pos)
1894 GdipFree(new_color);
1895 GdipFree(new_pos);
1896 return OutOfMemory;
1899 memcpy(new_color, blend, sizeof(ARGB) * count);
1900 memcpy(new_pos, positions, sizeof(REAL) * count);
1902 GdipFree(brush->pblendcolor);
1903 GdipFree(brush->pblendpos);
1905 brush->pblendcolor = new_color;
1906 brush->pblendpos = new_pos;
1907 brush->pblendcount = count;
1909 return Ok;
1912 GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient *brush,
1913 ARGB *blend, REAL* positions, INT count)
1915 if (!brush || !blend || !positions || count < 2)
1916 return InvalidParameter;
1918 if (brush->pblendcount == 0)
1919 return GenericError;
1921 if (count < brush->pblendcount)
1922 return InsufficientBuffer;
1924 memcpy(blend, brush->pblendcolor, sizeof(ARGB) * brush->pblendcount);
1925 memcpy(positions, brush->pblendpos, sizeof(REAL) * brush->pblendcount);
1927 return Ok;
1930 GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient *brush,
1931 INT *count)
1933 if (!brush || !count)
1934 return InvalidParameter;
1936 *count = brush->pblendcount;
1938 return Ok;
1941 GpStatus WINGDIPAPI GdipResetLineTransform(GpLineGradient *brush)
1943 static int calls;
1945 TRACE("(%p)\n", brush);
1947 if(!(calls++))
1948 FIXME("not implemented\n");
1950 return NotImplemented;
1953 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1954 GDIPCONST GpMatrix *matrix)
1956 static int calls;
1958 TRACE("(%p,%p)\n", brush, matrix);
1960 if(!(calls++))
1961 FIXME("not implemented\n");
1963 return NotImplemented;
1966 GpStatus WINGDIPAPI GdipGetLineTransform(GpLineGradient *brush, GpMatrix *matrix)
1968 static int calls;
1970 TRACE("(%p,%p)\n", brush, matrix);
1972 if(!(calls++))
1973 FIXME("not implemented\n");
1975 return NotImplemented;
1978 GpStatus WINGDIPAPI GdipScaleLineTransform(GpLineGradient *brush, REAL sx, REAL sy,
1979 GpMatrixOrder order)
1981 static int calls;
1983 TRACE("(%p,%0.2f,%0.2f,%u)\n", brush, sx, sy, order);
1985 if(!(calls++))
1986 FIXME("not implemented\n");
1988 return NotImplemented;
1991 GpStatus WINGDIPAPI GdipMultiplyLineTransform(GpLineGradient *brush,
1992 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1994 static int calls;
1996 TRACE("(%p,%p,%u)\n", brush, matrix, order);
1998 if(!(calls++))
1999 FIXME("not implemented\n");
2001 return NotImplemented;
2004 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
2005 REAL dx, REAL dy, GpMatrixOrder order)
2007 FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
2009 return NotImplemented;
2012 /******************************************************************************
2013 * GdipTranslateTextureTransform [GDIPLUS.@]
2015 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
2016 GpMatrixOrder order)
2018 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
2020 if(!brush)
2021 return InvalidParameter;
2023 return GdipTranslateMatrix(brush->transform, dx, dy, order);
2026 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
2028 TRACE("(%p, %p)\n", brush, rect);
2030 if(!brush || !rect)
2031 return InvalidParameter;
2033 *rect = brush->rect;
2035 return Ok;
2038 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
2040 GpRectF rectF;
2041 GpStatus ret;
2043 TRACE("(%p, %p)\n", brush, rect);
2045 if(!rect)
2046 return InvalidParameter;
2048 ret = GdipGetLineRect(brush, &rectF);
2050 if(ret == Ok){
2051 rect->X = roundr(rectF.X);
2052 rect->Y = roundr(rectF.Y);
2053 rect->Width = roundr(rectF.Width);
2054 rect->Height = roundr(rectF.Height);
2057 return ret;
2060 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
2061 REAL angle, GpMatrixOrder order)
2063 static int calls;
2065 TRACE("(%p,%0.2f,%u)\n", brush, angle, order);
2067 if(!brush)
2068 return InvalidParameter;
2070 if(!(calls++))
2071 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
2073 return NotImplemented;