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