2 * Copyright (C) 2007 Google (Evan Stade)
3 * Copyright (C) 2003-2004,2007 Novell, Inc. http://www.novell.com (Ravindra (rkumar@novell.com))
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "gdiplus_private.h"
25 Code from http://www.johndcook.com/blog/2009/01/19/stand-alone-error-function-erf/
29 const float a1
= 0.254829592f
;
30 const float a2
= -0.284496736f
;
31 const float a3
= 1.421413741f
;
32 const float a4
= -1.453152027f
;
33 const float a5
= 1.061405429f
;
34 const float p
= 0.3275911f
;
37 /* Save the sign of x */
45 y
= 1.0 - (((((a5
*t
+ a4
)*t
) + a3
)*t
+ a2
)*t
+ a1
)*t
*exp(-x
*x
);
51 /******************************************************************************
52 * GdipCloneBrush [GDIPLUS.@]
54 GpStatus WINGDIPAPI
GdipCloneBrush(GpBrush
*brush
, GpBrush
**clone
)
56 TRACE("(%p, %p)\n", brush
, clone
);
59 return InvalidParameter
;
62 case BrushTypeSolidColor
:
64 *clone
= heap_alloc_zero(sizeof(GpSolidFill
));
65 if (!*clone
) return OutOfMemory
;
66 memcpy(*clone
, brush
, sizeof(GpSolidFill
));
69 case BrushTypeHatchFill
:
71 GpHatch
*hatch
= (GpHatch
*)brush
;
73 return GdipCreateHatchBrush(hatch
->hatchstyle
, hatch
->forecol
, hatch
->backcol
, (GpHatch
**)clone
);
75 case BrushTypePathGradient
:{
76 GpPathGradient
*src
, *dest
;
80 *clone
= heap_alloc_zero(sizeof(GpPathGradient
));
81 if (!*clone
) return OutOfMemory
;
83 src
= (GpPathGradient
*) brush
,
84 dest
= (GpPathGradient
*) *clone
;
86 memcpy(dest
, src
, sizeof(GpPathGradient
));
88 stat
= GdipClonePath(src
->path
, &dest
->path
);
95 dest
->transform
= src
->transform
;
98 count
= src
->blendcount
;
99 dest
->blendcount
= count
;
100 dest
->blendfac
= heap_alloc_zero(count
* sizeof(REAL
));
101 dest
->blendpos
= heap_alloc_zero(count
* sizeof(REAL
));
102 dest
->surroundcolors
= heap_alloc_zero(dest
->surroundcolorcount
* sizeof(ARGB
));
103 pcount
= dest
->pblendcount
;
106 dest
->pblendcolor
= heap_alloc_zero(pcount
* sizeof(ARGB
));
107 dest
->pblendpos
= heap_alloc_zero(pcount
* sizeof(REAL
));
110 if(!dest
->blendfac
|| !dest
->blendpos
|| !dest
->surroundcolors
||
111 (pcount
&& (!dest
->pblendcolor
|| !dest
->pblendpos
))){
112 GdipDeletePath(dest
->path
);
113 heap_free(dest
->blendfac
);
114 heap_free(dest
->blendpos
);
115 heap_free(dest
->surroundcolors
);
116 heap_free(dest
->pblendcolor
);
117 heap_free(dest
->pblendpos
);
122 memcpy(dest
->blendfac
, src
->blendfac
, count
* sizeof(REAL
));
123 memcpy(dest
->blendpos
, src
->blendpos
, count
* sizeof(REAL
));
124 memcpy(dest
->surroundcolors
, src
->surroundcolors
, dest
->surroundcolorcount
* sizeof(ARGB
));
128 memcpy(dest
->pblendcolor
, src
->pblendcolor
, pcount
* sizeof(ARGB
));
129 memcpy(dest
->pblendpos
, src
->pblendpos
, pcount
* sizeof(REAL
));
134 case BrushTypeLinearGradient
:{
135 GpLineGradient
*dest
, *src
;
138 dest
= heap_alloc_zero(sizeof(GpLineGradient
));
139 if(!dest
) return OutOfMemory
;
141 src
= (GpLineGradient
*)brush
;
143 memcpy(dest
, src
, sizeof(GpLineGradient
));
145 count
= dest
->blendcount
;
146 dest
->blendfac
= heap_alloc_zero(count
* sizeof(REAL
));
147 dest
->blendpos
= heap_alloc_zero(count
* sizeof(REAL
));
148 pcount
= dest
->pblendcount
;
151 dest
->pblendcolor
= heap_alloc_zero(pcount
* sizeof(ARGB
));
152 dest
->pblendpos
= heap_alloc_zero(pcount
* sizeof(REAL
));
155 if (!dest
->blendfac
|| !dest
->blendpos
||
156 (pcount
&& (!dest
->pblendcolor
|| !dest
->pblendpos
)))
158 heap_free(dest
->blendfac
);
159 heap_free(dest
->blendpos
);
160 heap_free(dest
->pblendcolor
);
161 heap_free(dest
->pblendpos
);
166 dest
->transform
= src
->transform
;
168 memcpy(dest
->blendfac
, src
->blendfac
, count
* sizeof(REAL
));
169 memcpy(dest
->blendpos
, src
->blendpos
, count
* sizeof(REAL
));
173 memcpy(dest
->pblendcolor
, src
->pblendcolor
, pcount
* sizeof(ARGB
));
174 memcpy(dest
->pblendpos
, src
->pblendpos
, pcount
* sizeof(REAL
));
177 *clone
= &dest
->brush
;
180 case BrushTypeTextureFill
:
183 GpTexture
*texture
= (GpTexture
*)brush
;
184 GpTexture
*new_texture
;
187 stat
= GdipGetImageWidth(texture
->image
, &width
);
188 if (stat
!= Ok
) return stat
;
189 stat
= GdipGetImageHeight(texture
->image
, &height
);
190 if (stat
!= Ok
) return stat
;
192 stat
= GdipCreateTextureIA(texture
->image
, texture
->imageattributes
, 0, 0, width
, height
, &new_texture
);
196 new_texture
->transform
= texture
->transform
;
197 *clone
= &new_texture
->brush
;
205 ERR("not implemented for brush type %d\n", brush
->bt
);
206 return NotImplemented
;
209 TRACE("<-- %p\n", *clone
);
213 static const char HatchBrushes
[][8] = {
214 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HatchStyleHorizontal */
215 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleVertical */
216 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HatchStyleForwardDiagonal */
217 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HatchStyleBackwardDiagonal */
218 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HatchStyleCross */
219 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 }, /* HatchStyleDiagonalCross */
220 { 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x80 }, /* HatchStyle05Percent */
221 { 0x00, 0x02, 0x00, 0x88, 0x00, 0x20, 0x00, 0x88 }, /* HatchStyle10Percent */
222 { 0x00, 0x22, 0x00, 0xcc, 0x00, 0x22, 0x00, 0xcc }, /* HatchStyle20Percent */
223 { 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc }, /* HatchStyle25Percent */
224 { 0x00, 0xcc, 0x04, 0xcc, 0x00, 0xcc, 0x40, 0xcc }, /* HatchStyle30Percent */
225 { 0x44, 0xcc, 0x22, 0xcc, 0x44, 0xcc, 0x22, 0xcc }, /* HatchStyle40Percent */
226 { 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc, 0x55, 0xcc }, /* HatchStyle50Percent */
227 { 0x55, 0xcd, 0x55, 0xee, 0x55, 0xdc, 0x55, 0xee }, /* HatchStyle60Percent */
228 { 0x55, 0xdd, 0x55, 0xff, 0x55, 0xdd, 0x55, 0xff }, /* HatchStyle70Percent */
229 { 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff }, /* HatchStyle75Percent */
230 { 0x55, 0xff, 0x59, 0xff, 0x55, 0xff, 0x99, 0xff }, /* HatchStyle80Percent */
231 { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xfd, 0xff }, /* HatchStyle90Percent */
232 { 0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88 }, /* HatchStyleLightDownwardDiagonal */
233 { 0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11 }, /* HatchStyleLightUpwardDiagonal */
234 { 0x99, 0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc }, /* HatchStyleDarkDownwardDiagonal */
235 { 0xcc, 0x66, 0x33, 0x99, 0xcc, 0x66, 0x33, 0x99 }, /* HatchStyleDarkUpwardDiagonal */
236 { 0xc1, 0x83, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0 }, /* HatchStyleWideDownwardDiagonal */
237 { 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x83, 0xc1 }, /* HatchStyleWideUpwardDiagonal */
238 { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 }, /* HatchStyleLightVertical */
239 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff }, /* HatchStyleLightHorizontal */
240 { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }, /* HatchStyleNarrowVertical */
241 { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, /* HatchStyleNarrowHorizontal */
242 { 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }, /* HatchStyleDarkVertical */
243 { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff }, /* HatchStyleDarkHorizontal */
246 GpStatus
get_hatch_data(HatchStyle hatchstyle
, const char **result
)
248 if (hatchstyle
< sizeof(HatchBrushes
) / sizeof(HatchBrushes
[0]))
250 *result
= HatchBrushes
[hatchstyle
];
254 return NotImplemented
;
257 /******************************************************************************
258 * GdipCreateHatchBrush [GDIPLUS.@]
260 GpStatus WINGDIPAPI
GdipCreateHatchBrush(HatchStyle hatchstyle
, ARGB forecol
, ARGB backcol
, GpHatch
**brush
)
262 TRACE("(%d, %d, %d, %p)\n", hatchstyle
, forecol
, backcol
, brush
);
264 if(!brush
) return InvalidParameter
;
266 *brush
= heap_alloc_zero(sizeof(GpHatch
));
267 if (!*brush
) return OutOfMemory
;
269 (*brush
)->brush
.bt
= BrushTypeHatchFill
;
270 (*brush
)->forecol
= forecol
;
271 (*brush
)->backcol
= backcol
;
272 (*brush
)->hatchstyle
= hatchstyle
;
273 TRACE("<-- %p\n", *brush
);
278 static void linegradient_init_transform(GpLineGradient
*line
)
280 float trans_x
= line
->rect
.X
+ (line
->rect
.Width
/ 2.f
);
281 float trans_y
= line
->rect
.Y
+ (line
->rect
.Height
/ 2.f
);
282 float dx
= line
->endpoint
.X
- line
->startpoint
.X
;
283 float dy
= line
->endpoint
.Y
- line
->startpoint
.Y
;
284 float t_cos
, t_sin
, w_ratio
, h_ratio
;
288 h
= sqrtf(dx
* dx
+ dy
* dy
);
293 w_ratio
= (fabs(t_cos
) * line
->rect
.Width
+ fabs(t_sin
) * line
->rect
.Height
) / line
->rect
.Width
;
294 h_ratio
= (fabs(t_sin
) * line
->rect
.Width
+ fabs(t_cos
) * line
->rect
.Height
) / line
->rect
.Height
;
296 GdipSetMatrixElements(&line
->transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
298 GdipSetMatrixElements(&rot
, t_cos
, t_sin
, -1.f
* t_sin
, t_cos
, 0, 0);
300 /* center about the origin */
301 GdipTranslateMatrix(&line
->transform
, -trans_x
, -trans_y
, MatrixOrderAppend
);
303 /* scale to normalize gradient along gradient line (?) */
304 GdipScaleMatrix(&line
->transform
, w_ratio
, h_ratio
, MatrixOrderAppend
);
306 /* rotate so the gradient is horizontal */
307 GdipMultiplyMatrix(&line
->transform
, &rot
, MatrixOrderAppend
);
309 /* restore original offset in new coords */
310 GdipTranslateMatrix(&line
->transform
, trans_x
, trans_y
, MatrixOrderAppend
);
313 /******************************************************************************
314 * GdipCreateLineBrush [GDIPLUS.@]
316 GpStatus WINGDIPAPI
GdipCreateLineBrush(GDIPCONST GpPointF
* startpoint
,
317 GDIPCONST GpPointF
* endpoint
, ARGB startcolor
, ARGB endcolor
,
318 GpWrapMode wrap
, GpLineGradient
**line
)
320 TRACE("(%s, %s, %x, %x, %d, %p)\n", debugstr_pointf(startpoint
),
321 debugstr_pointf(endpoint
), startcolor
, endcolor
, wrap
, line
);
323 if(!line
|| !startpoint
|| !endpoint
|| wrap
== WrapModeClamp
)
324 return InvalidParameter
;
326 if (startpoint
->X
== endpoint
->X
&& startpoint
->Y
== endpoint
->Y
)
329 *line
= heap_alloc_zero(sizeof(GpLineGradient
));
330 if(!*line
) return OutOfMemory
;
332 (*line
)->brush
.bt
= BrushTypeLinearGradient
;
334 (*line
)->startpoint
.X
= startpoint
->X
;
335 (*line
)->startpoint
.Y
= startpoint
->Y
;
336 (*line
)->endpoint
.X
= endpoint
->X
;
337 (*line
)->endpoint
.Y
= endpoint
->Y
;
338 (*line
)->startcolor
= startcolor
;
339 (*line
)->endcolor
= endcolor
;
340 (*line
)->wrap
= wrap
;
341 (*line
)->gamma
= FALSE
;
343 (*line
)->rect
.X
= (startpoint
->X
< endpoint
->X
? startpoint
->X
: endpoint
->X
);
344 (*line
)->rect
.Y
= (startpoint
->Y
< endpoint
->Y
? startpoint
->Y
: endpoint
->Y
);
345 (*line
)->rect
.Width
= fabs(startpoint
->X
- endpoint
->X
);
346 (*line
)->rect
.Height
= fabs(startpoint
->Y
- endpoint
->Y
);
348 if ((*line
)->rect
.Width
== 0)
350 (*line
)->rect
.X
-= (*line
)->rect
.Height
/ 2.0f
;
351 (*line
)->rect
.Width
= (*line
)->rect
.Height
;
353 else if ((*line
)->rect
.Height
== 0)
355 (*line
)->rect
.Y
-= (*line
)->rect
.Width
/ 2.0f
;
356 (*line
)->rect
.Height
= (*line
)->rect
.Width
;
359 (*line
)->blendcount
= 1;
360 (*line
)->blendfac
= heap_alloc_zero(sizeof(REAL
));
361 (*line
)->blendpos
= heap_alloc_zero(sizeof(REAL
));
363 if (!(*line
)->blendfac
|| !(*line
)->blendpos
)
365 heap_free((*line
)->blendfac
);
366 heap_free((*line
)->blendpos
);
372 (*line
)->blendfac
[0] = 1.0f
;
373 (*line
)->blendpos
[0] = 1.0f
;
375 (*line
)->pblendcolor
= NULL
;
376 (*line
)->pblendpos
= NULL
;
377 (*line
)->pblendcount
= 0;
379 linegradient_init_transform(*line
);
381 TRACE("<-- %p\n", *line
);
386 GpStatus WINGDIPAPI
GdipCreateLineBrushI(GDIPCONST GpPoint
* startpoint
,
387 GDIPCONST GpPoint
* endpoint
, ARGB startcolor
, ARGB endcolor
,
388 GpWrapMode wrap
, GpLineGradient
**line
)
393 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint
, endpoint
,
394 startcolor
, endcolor
, wrap
, line
);
396 if(!startpoint
|| !endpoint
)
397 return InvalidParameter
;
399 stF
.X
= (REAL
)startpoint
->X
;
400 stF
.Y
= (REAL
)startpoint
->Y
;
401 endF
.X
= (REAL
)endpoint
->X
;
402 endF
.Y
= (REAL
)endpoint
->Y
;
404 return GdipCreateLineBrush(&stF
, &endF
, startcolor
, endcolor
, wrap
, line
);
407 GpStatus WINGDIPAPI
GdipCreateLineBrushFromRect(GDIPCONST GpRectF
* rect
,
408 ARGB startcolor
, ARGB endcolor
, LinearGradientMode mode
, GpWrapMode wrap
,
409 GpLineGradient
**line
)
415 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect
, startcolor
, endcolor
, mode
,
419 return InvalidParameter
;
421 far_x
= rect
->X
+ rect
->Width
;
422 far_y
= rect
->Y
+ rect
->Height
;
426 case LinearGradientModeHorizontal
:
427 start
.X
= min(rect
->X
, far_x
);
429 end
.X
= max(rect
->X
, far_x
);
432 case LinearGradientModeVertical
:
434 start
.Y
= min(rect
->Y
, far_y
);
436 end
.Y
= max(rect
->Y
, far_y
);
438 case LinearGradientModeForwardDiagonal
:
439 start
.X
= min(rect
->X
, far_x
);
440 start
.Y
= min(rect
->Y
, far_y
);
441 end
.X
= max(rect
->X
, far_x
);
442 end
.Y
= max(rect
->Y
, far_y
);
444 case LinearGradientModeBackwardDiagonal
:
445 start
.X
= max(rect
->X
, far_x
);
446 start
.Y
= min(rect
->Y
, far_y
);
447 end
.X
= min(rect
->X
, far_x
);
448 end
.Y
= max(rect
->Y
, far_y
);
451 return InvalidParameter
;
454 stat
= GdipCreateLineBrush(&start
, &end
, startcolor
, endcolor
, wrap
, line
);
457 (*line
)->rect
= *rect
;
462 GpStatus WINGDIPAPI
GdipCreateLineBrushFromRectI(GDIPCONST GpRect
* rect
,
463 ARGB startcolor
, ARGB endcolor
, LinearGradientMode mode
, GpWrapMode wrap
,
464 GpLineGradient
**line
)
468 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect
, startcolor
, endcolor
, mode
,
471 rectF
.X
= (REAL
) rect
->X
;
472 rectF
.Y
= (REAL
) rect
->Y
;
473 rectF
.Width
= (REAL
) rect
->Width
;
474 rectF
.Height
= (REAL
) rect
->Height
;
476 return GdipCreateLineBrushFromRect(&rectF
, startcolor
, endcolor
, mode
, wrap
, line
);
479 /******************************************************************************
480 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
482 GpStatus WINGDIPAPI
GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF
* rect
,
483 ARGB startcolor
, ARGB endcolor
, REAL angle
, BOOL isAngleScalable
, GpWrapMode wrap
,
484 GpLineGradient
**line
)
487 LinearGradientMode mode
;
489 REAL sin_angle
, cos_angle
, sin_cos_angle
;
491 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect
, startcolor
, endcolor
, angle
, isAngleScalable
,
494 if (!rect
|| !rect
->Width
|| !rect
->Height
)
495 return InvalidParameter
;
497 angle
= fmodf(angle
, 360);
510 if (angle
!= 90 && angle
!= -90)
511 angle
= atan((rect
->Width
/ rect
->Height
) * tan(deg2rad(angle
)));
513 angle
= deg2rad(angle
);
518 angle
= deg2rad(angle
);
521 sin_angle
= sinf(angle
);
522 cos_angle
= cosf(angle
);
523 sin_cos_angle
= sin_angle
* cos_angle
;
525 if (sin_cos_angle
>= 0)
526 mode
= LinearGradientModeForwardDiagonal
;
528 mode
= LinearGradientModeBackwardDiagonal
;
530 stat
= GdipCreateLineBrushFromRect(rect
, startcolor
, endcolor
, mode
, wrap
, line
);
534 if (sin_cos_angle
>= 0)
536 exofs
= rect
->Height
* sin_cos_angle
+ rect
->Width
* cos_angle
* cos_angle
;
537 eyofs
= rect
->Height
* sin_angle
* sin_angle
+ rect
->Width
* sin_cos_angle
;
541 exofs
= rect
->Width
* sin_angle
* sin_angle
+ rect
->Height
* sin_cos_angle
;
542 eyofs
= -rect
->Width
* sin_cos_angle
+ rect
->Height
* sin_angle
* sin_angle
;
547 (*line
)->endpoint
.X
= rect
->X
+ exofs
;
548 (*line
)->endpoint
.Y
= rect
->Y
+ eyofs
;
552 (*line
)->endpoint
.X
= (*line
)->startpoint
.X
;
553 (*line
)->endpoint
.Y
= (*line
)->startpoint
.Y
;
554 (*line
)->startpoint
.X
= rect
->X
+ exofs
;
555 (*line
)->startpoint
.Y
= rect
->Y
+ eyofs
;
558 linegradient_init_transform(*line
);
564 GpStatus WINGDIPAPI
GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect
* rect
,
565 ARGB startcolor
, ARGB endcolor
, REAL angle
, BOOL isAngleScalable
, GpWrapMode wrap
,
566 GpLineGradient
**line
)
568 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect
, startcolor
, endcolor
, angle
, isAngleScalable
,
571 return GdipCreateLineBrushFromRectI(rect
, startcolor
, endcolor
, LinearGradientModeForwardDiagonal
,
575 static GpStatus
create_path_gradient(GpPath
*path
, ARGB centercolor
, GpPathGradient
**grad
)
580 return InvalidParameter
;
582 if (path
->pathdata
.Count
< 2)
585 GdipGetPathWorldBounds(path
, &bounds
, NULL
, NULL
);
587 *grad
= heap_alloc_zero(sizeof(GpPathGradient
));
593 GdipSetMatrixElements(&(*grad
)->transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
595 (*grad
)->blendfac
= heap_alloc_zero(sizeof(REAL
));
596 (*grad
)->blendpos
= heap_alloc_zero(sizeof(REAL
));
597 (*grad
)->surroundcolors
= heap_alloc_zero(sizeof(ARGB
));
598 if(!(*grad
)->blendfac
|| !(*grad
)->blendpos
|| !(*grad
)->surroundcolors
){
599 heap_free((*grad
)->blendfac
);
600 heap_free((*grad
)->blendpos
);
601 heap_free((*grad
)->surroundcolors
);
606 (*grad
)->blendfac
[0] = 1.0;
607 (*grad
)->blendpos
[0] = 1.0;
608 (*grad
)->blendcount
= 1;
610 (*grad
)->path
= path
;
612 (*grad
)->brush
.bt
= BrushTypePathGradient
;
613 (*grad
)->centercolor
= centercolor
;
614 (*grad
)->wrap
= WrapModeClamp
;
615 (*grad
)->gamma
= FALSE
;
616 /* FIXME: this should be set to the "centroid" of the path by default */
617 (*grad
)->center
.X
= bounds
.X
+ bounds
.Width
/ 2;
618 (*grad
)->center
.Y
= bounds
.Y
+ bounds
.Height
/ 2;
619 (*grad
)->focus
.X
= 0.0;
620 (*grad
)->focus
.Y
= 0.0;
621 (*grad
)->surroundcolors
[0] = 0xffffffff;
622 (*grad
)->surroundcolorcount
= 1;
624 TRACE("<-- %p\n", *grad
);
629 GpStatus WINGDIPAPI
GdipCreatePathGradient(GDIPCONST GpPointF
* points
,
630 INT count
, GpWrapMode wrap
, GpPathGradient
**grad
)
635 TRACE("(%p, %d, %d, %p)\n", points
, count
, wrap
, grad
);
638 return InvalidParameter
;
640 if(!points
|| count
<= 0)
643 stat
= GdipCreatePath(FillModeAlternate
, &path
);
647 stat
= GdipAddPathLine2(path
, points
, count
);
650 stat
= create_path_gradient(path
, 0xff000000, grad
);
653 GdipDeletePath(path
);
657 (*grad
)->wrap
= wrap
;
662 GpStatus WINGDIPAPI
GdipCreatePathGradientI(GDIPCONST GpPoint
* points
,
663 INT count
, GpWrapMode wrap
, GpPathGradient
**grad
)
668 TRACE("(%p, %d, %d, %p)\n", points
, count
, wrap
, grad
);
671 return InvalidParameter
;
673 if(!points
|| count
<= 0)
676 stat
= GdipCreatePath(FillModeAlternate
, &path
);
680 stat
= GdipAddPathLine2I(path
, points
, count
);
683 stat
= create_path_gradient(path
, 0xff000000, grad
);
686 GdipDeletePath(path
);
690 (*grad
)->wrap
= wrap
;
695 /******************************************************************************
696 * GdipCreatePathGradientFromPath [GDIPLUS.@]
698 GpStatus WINGDIPAPI
GdipCreatePathGradientFromPath(GDIPCONST GpPath
* path
,
699 GpPathGradient
**grad
)
704 TRACE("(%p, %p)\n", path
, grad
);
707 return InvalidParameter
;
712 stat
= GdipClonePath((GpPath
*)path
, &new_path
);
716 stat
= create_path_gradient(new_path
, 0xffffffff, grad
);
719 GdipDeletePath(new_path
);
725 /******************************************************************************
726 * GdipCreateSolidFill [GDIPLUS.@]
728 GpStatus WINGDIPAPI
GdipCreateSolidFill(ARGB color
, GpSolidFill
**sf
)
730 TRACE("(%x, %p)\n", color
, sf
);
732 if(!sf
) return InvalidParameter
;
734 *sf
= heap_alloc_zero(sizeof(GpSolidFill
));
735 if (!*sf
) return OutOfMemory
;
737 (*sf
)->brush
.bt
= BrushTypeSolidColor
;
738 (*sf
)->color
= color
;
740 TRACE("<-- %p\n", *sf
);
745 /******************************************************************************
746 * GdipCreateTexture [GDIPLUS.@]
749 * image [I] image to use
750 * wrapmode [I] optional
751 * texture [O] pointer to the resulting texturebrush
755 * FAILURE: element of GpStatus
757 GpStatus WINGDIPAPI
GdipCreateTexture(GpImage
*image
, GpWrapMode wrapmode
,
761 GpImageAttributes
*attributes
;
764 TRACE("%p, %d %p\n", image
, wrapmode
, texture
);
766 if (!(image
&& texture
))
767 return InvalidParameter
;
769 stat
= GdipGetImageWidth(image
, &width
);
770 if (stat
!= Ok
) return stat
;
771 stat
= GdipGetImageHeight(image
, &height
);
772 if (stat
!= Ok
) return stat
;
774 stat
= GdipCreateImageAttributes(&attributes
);
778 attributes
->wrap
= wrapmode
;
780 stat
= GdipCreateTextureIA(image
, attributes
, 0, 0, width
, height
,
783 GdipDisposeImageAttributes(attributes
);
789 /******************************************************************************
790 * GdipCreateTexture2 [GDIPLUS.@]
792 GpStatus WINGDIPAPI
GdipCreateTexture2(GpImage
*image
, GpWrapMode wrapmode
,
793 REAL x
, REAL y
, REAL width
, REAL height
, GpTexture
**texture
)
795 GpImageAttributes
*attributes
;
798 TRACE("%p %d %f %f %f %f %p\n", image
, wrapmode
,
799 x
, y
, width
, height
, texture
);
801 stat
= GdipCreateImageAttributes(&attributes
);
805 attributes
->wrap
= wrapmode
;
807 stat
= GdipCreateTextureIA(image
, attributes
, x
, y
, width
, height
,
810 GdipDisposeImageAttributes(attributes
);
816 /******************************************************************************
817 * GdipCreateTextureIA [GDIPLUS.@]
819 GpStatus WINGDIPAPI
GdipCreateTextureIA(GpImage
*image
,
820 GDIPCONST GpImageAttributes
*imageattr
, REAL x
, REAL y
, REAL width
,
821 REAL height
, GpTexture
**texture
)
824 GpImage
*new_image
=NULL
;
826 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image
, imageattr
, x
, y
, width
, height
,
829 if(!image
|| !texture
|| x
< 0.0 || y
< 0.0 || width
< 0.0 || height
< 0.0)
830 return InvalidParameter
;
834 if(image
->type
!= ImageTypeBitmap
){
835 FIXME("not implemented for image type %d\n", image
->type
);
836 return NotImplemented
;
839 status
= GdipCloneBitmapArea(x
, y
, width
, height
, PixelFormatDontCare
, (GpBitmap
*)image
, (GpBitmap
**)&new_image
);
843 *texture
= heap_alloc_zero(sizeof(GpTexture
));
845 status
= OutOfMemory
;
849 GdipSetMatrixElements(&(*texture
)->transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
853 status
= GdipCloneImageAttributes(imageattr
, &(*texture
)->imageattributes
);
857 status
= GdipCreateImageAttributes(&(*texture
)->imageattributes
);
859 (*texture
)->imageattributes
->wrap
= WrapModeTile
;
863 (*texture
)->brush
.bt
= BrushTypeTextureFill
;
864 (*texture
)->image
= new_image
;
870 TRACE("<-- %p\n", *texture
);
876 GdipDisposeImageAttributes((*texture
)->imageattributes
);
880 GdipDisposeImage(new_image
);
881 TRACE("<-- error %u\n", status
);
887 /******************************************************************************
888 * GdipCreateTextureIAI [GDIPLUS.@]
890 GpStatus WINGDIPAPI
GdipCreateTextureIAI(GpImage
*image
, GDIPCONST GpImageAttributes
*imageattr
,
891 INT x
, INT y
, INT width
, INT height
, GpTexture
**texture
)
893 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image
, imageattr
, x
, y
, width
, height
,
896 return GdipCreateTextureIA(image
,imageattr
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,texture
);
899 GpStatus WINGDIPAPI
GdipCreateTexture2I(GpImage
*image
, GpWrapMode wrapmode
,
900 INT x
, INT y
, INT width
, INT height
, GpTexture
**texture
)
902 GpImageAttributes
*imageattr
;
905 TRACE("%p %d %d %d %d %d %p\n", image
, wrapmode
, x
, y
, width
, height
,
908 stat
= GdipCreateImageAttributes(&imageattr
);
912 imageattr
->wrap
= wrapmode
;
914 stat
= GdipCreateTextureIA(image
, imageattr
, x
, y
, width
, height
, texture
);
915 GdipDisposeImageAttributes(imageattr
);
921 GpStatus WINGDIPAPI
GdipGetBrushType(GpBrush
*brush
, GpBrushType
*type
)
923 TRACE("(%p, %p)\n", brush
, type
);
925 if(!brush
|| !type
) return InvalidParameter
;
932 GpStatus WINGDIPAPI
GdipGetHatchBackgroundColor(GpHatch
*brush
, ARGB
*backcol
)
934 TRACE("(%p, %p)\n", brush
, backcol
);
936 if(!brush
|| !backcol
) return InvalidParameter
;
938 *backcol
= brush
->backcol
;
943 GpStatus WINGDIPAPI
GdipGetHatchForegroundColor(GpHatch
*brush
, ARGB
*forecol
)
945 TRACE("(%p, %p)\n", brush
, forecol
);
947 if(!brush
|| !forecol
) return InvalidParameter
;
949 *forecol
= brush
->forecol
;
954 GpStatus WINGDIPAPI
GdipGetHatchStyle(GpHatch
*brush
, HatchStyle
*hatchstyle
)
956 TRACE("(%p, %p)\n", brush
, hatchstyle
);
958 if(!brush
|| !hatchstyle
) return InvalidParameter
;
960 *hatchstyle
= brush
->hatchstyle
;
965 GpStatus WINGDIPAPI
GdipDeleteBrush(GpBrush
*brush
)
967 TRACE("(%p)\n", brush
);
969 if(!brush
) return InvalidParameter
;
973 case BrushTypePathGradient
:
974 GdipDeletePath(((GpPathGradient
*) brush
)->path
);
975 heap_free(((GpPathGradient
*) brush
)->blendfac
);
976 heap_free(((GpPathGradient
*) brush
)->blendpos
);
977 heap_free(((GpPathGradient
*) brush
)->surroundcolors
);
978 heap_free(((GpPathGradient
*) brush
)->pblendcolor
);
979 heap_free(((GpPathGradient
*) brush
)->pblendpos
);
981 case BrushTypeLinearGradient
:
982 heap_free(((GpLineGradient
*)brush
)->blendfac
);
983 heap_free(((GpLineGradient
*)brush
)->blendpos
);
984 heap_free(((GpLineGradient
*)brush
)->pblendcolor
);
985 heap_free(((GpLineGradient
*)brush
)->pblendpos
);
987 case BrushTypeTextureFill
:
988 GdipDisposeImage(((GpTexture
*)brush
)->image
);
989 GdipDisposeImageAttributes(((GpTexture
*)brush
)->imageattributes
);
990 heap_free(((GpTexture
*)brush
)->bitmap_bits
);
1001 GpStatus WINGDIPAPI
GdipGetLineGammaCorrection(GpLineGradient
*line
,
1004 TRACE("(%p, %p)\n", line
, usinggamma
);
1006 if(!line
|| !usinggamma
)
1007 return InvalidParameter
;
1009 *usinggamma
= line
->gamma
;
1014 GpStatus WINGDIPAPI
GdipGetLineWrapMode(GpLineGradient
*brush
, GpWrapMode
*wrapmode
)
1016 TRACE("(%p, %p)\n", brush
, wrapmode
);
1018 if(!brush
|| !wrapmode
|| brush
->brush
.bt
!= BrushTypeLinearGradient
)
1019 return InvalidParameter
;
1021 *wrapmode
= brush
->wrap
;
1026 GpStatus WINGDIPAPI
GdipGetPathGradientBlend(GpPathGradient
*brush
, REAL
*blend
,
1027 REAL
*positions
, INT count
)
1029 TRACE("(%p, %p, %p, %d)\n", brush
, blend
, positions
, count
);
1031 if(!brush
|| !blend
|| !positions
|| count
<= 0 || brush
->brush
.bt
!= BrushTypePathGradient
)
1032 return InvalidParameter
;
1034 if(count
< brush
->blendcount
)
1035 return InsufficientBuffer
;
1037 memcpy(blend
, brush
->blendfac
, count
*sizeof(REAL
));
1038 if(brush
->blendcount
> 1){
1039 memcpy(positions
, brush
->blendpos
, count
*sizeof(REAL
));
1045 GpStatus WINGDIPAPI
GdipGetPathGradientBlendCount(GpPathGradient
*brush
, INT
*count
)
1047 TRACE("(%p, %p)\n", brush
, count
);
1049 if(!brush
|| !count
|| brush
->brush
.bt
!= BrushTypePathGradient
)
1050 return InvalidParameter
;
1052 *count
= brush
->blendcount
;
1057 GpStatus WINGDIPAPI
GdipGetPathGradientCenterPoint(GpPathGradient
*grad
,
1060 TRACE("(%p, %p)\n", grad
, point
);
1062 if(!grad
|| !point
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1063 return InvalidParameter
;
1065 point
->X
= grad
->center
.X
;
1066 point
->Y
= grad
->center
.Y
;
1071 GpStatus WINGDIPAPI
GdipGetPathGradientCenterPointI(GpPathGradient
*grad
,
1077 TRACE("(%p, %p)\n", grad
, point
);
1080 return InvalidParameter
;
1082 ret
= GdipGetPathGradientCenterPoint(grad
,&ptf
);
1085 point
->X
= gdip_round(ptf
.X
);
1086 point
->Y
= gdip_round(ptf
.Y
);
1092 GpStatus WINGDIPAPI
GdipGetPathGradientCenterColor(GpPathGradient
*grad
,
1095 TRACE("(%p,%p)\n", grad
, colors
);
1097 if (!grad
|| !colors
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1098 return InvalidParameter
;
1100 *colors
= grad
->centercolor
;
1105 GpStatus WINGDIPAPI
GdipGetPathGradientFocusScales(GpPathGradient
*grad
,
1108 TRACE("(%p, %p, %p)\n", grad
, x
, y
);
1110 if(!grad
|| !x
|| !y
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1111 return InvalidParameter
;
1119 GpStatus WINGDIPAPI
GdipGetPathGradientGammaCorrection(GpPathGradient
*grad
,
1122 TRACE("(%p, %p)\n", grad
, gamma
);
1124 if(!grad
|| !gamma
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1125 return InvalidParameter
;
1127 *gamma
= grad
->gamma
;
1132 GpStatus WINGDIPAPI
GdipGetPathGradientPath(GpPathGradient
*grad
, GpPath
*path
)
1136 TRACE("(%p, %p)\n", grad
, path
);
1139 FIXME("not implemented\n");
1141 return NotImplemented
;
1144 GpStatus WINGDIPAPI
GdipGetPathGradientPointCount(GpPathGradient
*grad
,
1147 TRACE("(%p, %p)\n", grad
, count
);
1149 if(!grad
|| !count
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1150 return InvalidParameter
;
1152 *count
= grad
->path
->pathdata
.Count
;
1157 GpStatus WINGDIPAPI
GdipGetPathGradientRect(GpPathGradient
*brush
, GpRectF
*rect
)
1161 TRACE("(%p, %p)\n", brush
, rect
);
1163 if(!brush
|| !rect
|| brush
->brush
.bt
!= BrushTypePathGradient
)
1164 return InvalidParameter
;
1166 stat
= GdipGetPathWorldBounds(brush
->path
, rect
, NULL
, NULL
);
1171 GpStatus WINGDIPAPI
GdipGetPathGradientRectI(GpPathGradient
*brush
, GpRect
*rect
)
1176 TRACE("(%p, %p)\n", brush
, rect
);
1179 return InvalidParameter
;
1181 stat
= GdipGetPathGradientRect(brush
, &rectf
);
1182 if(stat
!= Ok
) return stat
;
1184 rect
->X
= gdip_round(rectf
.X
);
1185 rect
->Y
= gdip_round(rectf
.Y
);
1186 rect
->Width
= gdip_round(rectf
.Width
);
1187 rect
->Height
= gdip_round(rectf
.Height
);
1192 GpStatus WINGDIPAPI
GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1193 *grad
, ARGB
*argb
, INT
*count
)
1197 TRACE("(%p,%p,%p)\n", grad
, argb
, count
);
1199 if(!grad
|| !argb
|| !count
|| (*count
< grad
->path
->pathdata
.Count
) || grad
->brush
.bt
!= BrushTypePathGradient
)
1200 return InvalidParameter
;
1202 for (i
=0; i
<grad
->path
->pathdata
.Count
; i
++)
1204 if (i
< grad
->surroundcolorcount
)
1205 argb
[i
] = grad
->surroundcolors
[i
];
1207 argb
[i
] = grad
->surroundcolors
[grad
->surroundcolorcount
-1];
1210 *count
= grad
->surroundcolorcount
;
1215 GpStatus WINGDIPAPI
GdipGetPathGradientSurroundColorCount(GpPathGradient
*brush
, INT
*count
)
1217 TRACE("(%p, %p)\n", brush
, count
);
1219 if (!brush
|| !count
|| brush
->brush
.bt
!= BrushTypePathGradient
)
1220 return InvalidParameter
;
1222 /* Yes, this actually returns the number of points in the path (which is the
1223 * required size of a buffer to get the surround colors), rather than the
1224 * number of surround colors. The real count is returned when getting the
1226 *count
= brush
->path
->pathdata
.Count
;
1231 GpStatus WINGDIPAPI
GdipGetPathGradientWrapMode(GpPathGradient
*brush
,
1232 GpWrapMode
*wrapmode
)
1234 TRACE("(%p, %p)\n", brush
, wrapmode
);
1236 if(!brush
|| !wrapmode
|| brush
->brush
.bt
!= BrushTypePathGradient
)
1237 return InvalidParameter
;
1239 *wrapmode
= brush
->wrap
;
1244 GpStatus WINGDIPAPI
GdipGetSolidFillColor(GpSolidFill
*sf
, ARGB
*argb
)
1246 TRACE("(%p, %p)\n", sf
, argb
);
1249 return InvalidParameter
;
1256 /******************************************************************************
1257 * GdipGetTextureImage [GDIPLUS.@]
1259 GpStatus WINGDIPAPI
GdipGetTextureImage(GpTexture
*brush
, GpImage
**image
)
1261 TRACE("(%p, %p)\n", brush
, image
);
1263 if(!brush
|| !image
)
1264 return InvalidParameter
;
1266 return GdipCloneImage(brush
->image
, image
);
1269 /******************************************************************************
1270 * GdipGetTextureTransform [GDIPLUS.@]
1272 GpStatus WINGDIPAPI
GdipGetTextureTransform(GpTexture
*brush
, GpMatrix
*matrix
)
1274 TRACE("(%p, %p)\n", brush
, matrix
);
1276 if(!brush
|| !matrix
)
1277 return InvalidParameter
;
1279 *matrix
= brush
->transform
;
1284 /******************************************************************************
1285 * GdipGetTextureWrapMode [GDIPLUS.@]
1287 GpStatus WINGDIPAPI
GdipGetTextureWrapMode(GpTexture
*brush
, GpWrapMode
*wrapmode
)
1289 TRACE("(%p, %p)\n", brush
, wrapmode
);
1291 if(!brush
|| !wrapmode
)
1292 return InvalidParameter
;
1294 *wrapmode
= brush
->imageattributes
->wrap
;
1299 /******************************************************************************
1300 * GdipMultiplyTextureTransform [GDIPLUS.@]
1302 GpStatus WINGDIPAPI
GdipMultiplyTextureTransform(GpTexture
* brush
,
1303 GDIPCONST GpMatrix
*matrix
, GpMatrixOrder order
)
1305 TRACE("(%p, %p, %d)\n", brush
, matrix
, order
);
1307 if(!brush
|| !matrix
)
1308 return InvalidParameter
;
1310 return GdipMultiplyMatrix(&brush
->transform
, matrix
, order
);
1313 /******************************************************************************
1314 * GdipResetTextureTransform [GDIPLUS.@]
1316 GpStatus WINGDIPAPI
GdipResetTextureTransform(GpTexture
* brush
)
1318 TRACE("(%p)\n", brush
);
1321 return InvalidParameter
;
1323 return GdipSetMatrixElements(&brush
->transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1326 /******************************************************************************
1327 * GdipScaleTextureTransform [GDIPLUS.@]
1329 GpStatus WINGDIPAPI
GdipScaleTextureTransform(GpTexture
* brush
,
1330 REAL sx
, REAL sy
, GpMatrixOrder order
)
1332 TRACE("(%p, %.2f, %.2f, %d)\n", brush
, sx
, sy
, order
);
1335 return InvalidParameter
;
1337 return GdipScaleMatrix(&brush
->transform
, sx
, sy
, order
);
1340 GpStatus WINGDIPAPI
GdipSetLineBlend(GpLineGradient
*brush
,
1341 GDIPCONST REAL
*factors
, GDIPCONST REAL
* positions
, INT count
)
1343 REAL
*new_blendfac
, *new_blendpos
;
1345 TRACE("(%p, %p, %p, %i)\n", brush
, factors
, positions
, count
);
1347 if(!brush
|| !factors
|| !positions
|| count
<= 0 || brush
->brush
.bt
!= BrushTypeLinearGradient
||
1348 (count
>= 2 && (positions
[0] != 0.0f
|| positions
[count
-1] != 1.0f
)))
1349 return InvalidParameter
;
1351 new_blendfac
= heap_alloc_zero(count
* sizeof(REAL
));
1352 new_blendpos
= heap_alloc_zero(count
* sizeof(REAL
));
1354 if (!new_blendfac
|| !new_blendpos
)
1356 heap_free(new_blendfac
);
1357 heap_free(new_blendpos
);
1361 memcpy(new_blendfac
, factors
, count
* sizeof(REAL
));
1362 memcpy(new_blendpos
, positions
, count
* sizeof(REAL
));
1364 heap_free(brush
->blendfac
);
1365 heap_free(brush
->blendpos
);
1367 brush
->blendcount
= count
;
1368 brush
->blendfac
= new_blendfac
;
1369 brush
->blendpos
= new_blendpos
;
1374 GpStatus WINGDIPAPI
GdipGetLineBlend(GpLineGradient
*brush
, REAL
*factors
,
1375 REAL
*positions
, INT count
)
1377 TRACE("(%p, %p, %p, %i)\n", brush
, factors
, positions
, count
);
1379 if (!brush
|| !factors
|| !positions
|| count
<= 0 || brush
->brush
.bt
!= BrushTypeLinearGradient
)
1380 return InvalidParameter
;
1382 if (count
< brush
->blendcount
)
1383 return InsufficientBuffer
;
1385 memcpy(factors
, brush
->blendfac
, brush
->blendcount
* sizeof(REAL
));
1386 memcpy(positions
, brush
->blendpos
, brush
->blendcount
* sizeof(REAL
));
1391 GpStatus WINGDIPAPI
GdipGetLineBlendCount(GpLineGradient
*brush
, INT
*count
)
1393 TRACE("(%p, %p)\n", brush
, count
);
1395 if (!brush
|| !count
|| brush
->brush
.bt
!= BrushTypeLinearGradient
)
1396 return InvalidParameter
;
1398 *count
= brush
->blendcount
;
1403 GpStatus WINGDIPAPI
GdipSetLineGammaCorrection(GpLineGradient
*line
,
1406 TRACE("(%p, %d)\n", line
, usegamma
);
1408 if(!line
|| line
->brush
.bt
!= BrushTypeLinearGradient
)
1409 return InvalidParameter
;
1411 line
->gamma
= usegamma
;
1416 GpStatus WINGDIPAPI
GdipSetLineSigmaBlend(GpLineGradient
*line
, REAL focus
,
1423 const int precision
= 16;
1424 REAL erf_range
; /* we use values erf(-erf_range) through erf(+erf_range) */
1428 TRACE("(%p, %0.2f, %0.2f)\n", line
, focus
, scale
);
1430 if(!line
|| focus
< 0.0 || focus
> 1.0 || scale
< 0.0 || scale
> 1.0 || line
->brush
.bt
!= BrushTypeLinearGradient
)
1431 return InvalidParameter
;
1433 /* we want 2 standard deviations */
1434 erf_range
= 2.0 / sqrt(2);
1436 /* calculate the constants we need to normalize the error function to be
1437 between 0.0 and scale over the range we need */
1438 min_erf
= erf(-erf_range
);
1439 scale_erf
= scale
/ (-2.0 * min_erf
);
1445 for (i
=1; i
<precision
; i
++)
1447 positions
[i
] = focus
* i
/ precision
;
1448 factors
[i
] = scale_erf
* (erf(2 * erf_range
* i
/ precision
- erf_range
) - min_erf
);
1450 num_points
+= precision
;
1453 positions
[num_points
] = focus
;
1454 factors
[num_points
] = scale
;
1459 for (i
=1; i
<precision
; i
++)
1461 positions
[i
+num_points
-1] = (focus
+ ((1.0-focus
) * i
/ precision
));
1462 factors
[i
+num_points
-1] = scale_erf
* (erf(erf_range
- 2 * erf_range
* i
/ precision
) - min_erf
);
1464 num_points
+= precision
;
1465 positions
[num_points
-1] = 1.0;
1466 factors
[num_points
-1] = 0.0;
1469 return GdipSetLineBlend(line
, factors
, positions
, num_points
);
1472 GpStatus WINGDIPAPI
GdipSetLineWrapMode(GpLineGradient
*line
,
1475 TRACE("(%p, %d)\n", line
, wrap
);
1477 if(!line
|| wrap
== WrapModeClamp
|| line
->brush
.bt
!= BrushTypeLinearGradient
)
1478 return InvalidParameter
;
1485 GpStatus WINGDIPAPI
GdipSetPathGradientBlend(GpPathGradient
*brush
, GDIPCONST REAL
*blend
,
1486 GDIPCONST REAL
*pos
, INT count
)
1488 REAL
*new_blendfac
, *new_blendpos
;
1490 TRACE("(%p,%p,%p,%i)\n", brush
, blend
, pos
, count
);
1492 if(!brush
|| !blend
|| !pos
|| count
<= 0 || brush
->brush
.bt
!= BrushTypePathGradient
||
1493 (count
>= 2 && (pos
[0] != 0.0f
|| pos
[count
-1] != 1.0f
)))
1494 return InvalidParameter
;
1496 new_blendfac
= heap_alloc_zero(count
* sizeof(REAL
));
1497 new_blendpos
= heap_alloc_zero(count
* sizeof(REAL
));
1499 if (!new_blendfac
|| !new_blendpos
)
1501 heap_free(new_blendfac
);
1502 heap_free(new_blendpos
);
1506 memcpy(new_blendfac
, blend
, count
* sizeof(REAL
));
1507 memcpy(new_blendpos
, pos
, count
* sizeof(REAL
));
1509 heap_free(brush
->blendfac
);
1510 heap_free(brush
->blendpos
);
1512 brush
->blendcount
= count
;
1513 brush
->blendfac
= new_blendfac
;
1514 brush
->blendpos
= new_blendpos
;
1519 GpStatus WINGDIPAPI
GdipSetPathGradientLinearBlend(GpPathGradient
*brush
,
1520 REAL focus
, REAL scale
)
1526 TRACE("(%p,%0.2f,%0.2f)\n", brush
, focus
, scale
);
1528 if (!brush
|| brush
->brush
.bt
!= BrushTypePathGradient
)
1529 return InvalidParameter
;
1533 factors
[num_points
] = 0.0;
1534 positions
[num_points
] = 0.0;
1538 factors
[num_points
] = scale
;
1539 positions
[num_points
] = focus
;
1544 factors
[num_points
] = 0.0;
1545 positions
[num_points
] = 1.0;
1549 return GdipSetPathGradientBlend(brush
, factors
, positions
, num_points
);
1552 GpStatus WINGDIPAPI
GdipSetPathGradientPresetBlend(GpPathGradient
*brush
,
1553 GDIPCONST ARGB
*blend
, GDIPCONST REAL
*pos
, INT count
)
1557 TRACE("(%p,%p,%p,%i)\n", brush
, blend
, pos
, count
);
1559 if (!brush
|| !blend
|| !pos
|| count
< 2 || brush
->brush
.bt
!= BrushTypePathGradient
||
1560 pos
[0] != 0.0f
|| pos
[count
-1] != 1.0f
)
1562 return InvalidParameter
;
1565 new_color
= heap_alloc_zero(count
* sizeof(ARGB
));
1566 new_pos
= heap_alloc_zero(count
* sizeof(REAL
));
1567 if (!new_color
|| !new_pos
)
1569 heap_free(new_color
);
1574 memcpy(new_color
, blend
, sizeof(ARGB
) * count
);
1575 memcpy(new_pos
, pos
, sizeof(REAL
) * count
);
1577 heap_free(brush
->pblendcolor
);
1578 heap_free(brush
->pblendpos
);
1580 brush
->pblendcolor
= new_color
;
1581 brush
->pblendpos
= new_pos
;
1582 brush
->pblendcount
= count
;
1587 GpStatus WINGDIPAPI
GdipGetPathGradientPresetBlend(GpPathGradient
*brush
,
1588 ARGB
*blend
, REAL
*pos
, INT count
)
1590 TRACE("(%p,%p,%p,%i)\n", brush
, blend
, pos
, count
);
1595 if (!brush
|| !blend
|| !pos
|| count
< 2 || brush
->brush
.bt
!= BrushTypePathGradient
)
1596 return InvalidParameter
;
1598 if (brush
->pblendcount
== 0)
1599 return GenericError
;
1601 if (count
!= brush
->pblendcount
)
1603 /* Native lines up the ends of each array, and copies the destination size. */
1604 FIXME("Braindead behavior on wrong-sized buffer not implemented.\n");
1605 return InvalidParameter
;
1608 memcpy(blend
, brush
->pblendcolor
, sizeof(ARGB
) * brush
->pblendcount
);
1609 memcpy(pos
, brush
->pblendpos
, sizeof(REAL
) * brush
->pblendcount
);
1614 GpStatus WINGDIPAPI
GdipGetPathGradientPresetBlendCount(GpPathGradient
*brush
,
1617 TRACE("(%p,%p)\n", brush
, count
);
1619 if (!brush
|| !count
|| brush
->brush
.bt
!= BrushTypePathGradient
)
1620 return InvalidParameter
;
1622 *count
= brush
->pblendcount
;
1627 GpStatus WINGDIPAPI
GdipSetPathGradientCenterColor(GpPathGradient
*grad
,
1630 TRACE("(%p, %x)\n", grad
, argb
);
1632 if(!grad
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1633 return InvalidParameter
;
1635 grad
->centercolor
= argb
;
1639 GpStatus WINGDIPAPI
GdipSetPathGradientCenterPoint(GpPathGradient
*grad
,
1642 TRACE("(%p, %s)\n", grad
, debugstr_pointf(point
));
1644 if(!grad
|| !point
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1645 return InvalidParameter
;
1647 grad
->center
.X
= point
->X
;
1648 grad
->center
.Y
= point
->Y
;
1653 GpStatus WINGDIPAPI
GdipSetPathGradientCenterPointI(GpPathGradient
*grad
,
1658 TRACE("(%p, %p)\n", grad
, point
);
1661 return InvalidParameter
;
1663 ptf
.X
= (REAL
)point
->X
;
1664 ptf
.Y
= (REAL
)point
->Y
;
1666 return GdipSetPathGradientCenterPoint(grad
,&ptf
);
1669 GpStatus WINGDIPAPI
GdipSetPathGradientFocusScales(GpPathGradient
*grad
,
1672 TRACE("(%p, %.2f, %.2f)\n", grad
, x
, y
);
1674 if(!grad
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1675 return InvalidParameter
;
1683 GpStatus WINGDIPAPI
GdipSetPathGradientGammaCorrection(GpPathGradient
*grad
,
1686 TRACE("(%p, %d)\n", grad
, gamma
);
1688 if(!grad
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1689 return InvalidParameter
;
1691 grad
->gamma
= gamma
;
1696 GpStatus WINGDIPAPI
GdipSetPathGradientSigmaBlend(GpPathGradient
*grad
,
1697 REAL focus
, REAL scale
)
1703 const int precision
= 16;
1704 REAL erf_range
; /* we use values erf(-erf_range) through erf(+erf_range) */
1708 TRACE("(%p,%0.2f,%0.2f)\n", grad
, focus
, scale
);
1710 if(!grad
|| focus
< 0.0 || focus
> 1.0 || scale
< 0.0 || scale
> 1.0 || grad
->brush
.bt
!= BrushTypePathGradient
)
1711 return InvalidParameter
;
1713 /* we want 2 standard deviations */
1714 erf_range
= 2.0 / sqrt(2);
1716 /* calculate the constants we need to normalize the error function to be
1717 between 0.0 and scale over the range we need */
1718 min_erf
= erf(-erf_range
);
1719 scale_erf
= scale
/ (-2.0 * min_erf
);
1725 for (i
=1; i
<precision
; i
++)
1727 positions
[i
] = focus
* i
/ precision
;
1728 factors
[i
] = scale_erf
* (erf(2 * erf_range
* i
/ precision
- erf_range
) - min_erf
);
1730 num_points
+= precision
;
1733 positions
[num_points
] = focus
;
1734 factors
[num_points
] = scale
;
1739 for (i
=1; i
<precision
; i
++)
1741 positions
[i
+num_points
-1] = (focus
+ ((1.0-focus
) * i
/ precision
));
1742 factors
[i
+num_points
-1] = scale_erf
* (erf(erf_range
- 2 * erf_range
* i
/ precision
) - min_erf
);
1744 num_points
+= precision
;
1745 positions
[num_points
-1] = 1.0;
1746 factors
[num_points
-1] = 0.0;
1749 return GdipSetPathGradientBlend(grad
, factors
, positions
, num_points
);
1752 GpStatus WINGDIPAPI
GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1753 *grad
, GDIPCONST ARGB
*argb
, INT
*count
)
1755 ARGB
*new_surroundcolors
;
1758 TRACE("(%p,%p,%p)\n", grad
, argb
, count
);
1760 if(!grad
|| !argb
|| !count
|| (*count
<= 0) || grad
->brush
.bt
!= BrushTypePathGradient
||
1761 (*count
> grad
->path
->pathdata
.Count
))
1762 return InvalidParameter
;
1764 num_colors
= *count
;
1766 /* If all colors are the same, only store 1 color. */
1769 for (i
=1; i
< num_colors
; i
++)
1770 if (argb
[i
] != argb
[i
-1])
1773 if (i
== num_colors
)
1777 new_surroundcolors
= heap_alloc_zero(num_colors
* sizeof(ARGB
));
1778 if (!new_surroundcolors
)
1781 memcpy(new_surroundcolors
, argb
, num_colors
* sizeof(ARGB
));
1783 heap_free(grad
->surroundcolors
);
1785 grad
->surroundcolors
= new_surroundcolors
;
1786 grad
->surroundcolorcount
= num_colors
;
1791 GpStatus WINGDIPAPI
GdipSetPathGradientWrapMode(GpPathGradient
*grad
,
1794 TRACE("(%p, %d)\n", grad
, wrap
);
1796 if(!grad
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1797 return InvalidParameter
;
1804 GpStatus WINGDIPAPI
GdipSetPathGradientTransform(GpPathGradient
*grad
,
1807 TRACE("(%p,%p)\n", grad
, matrix
);
1809 if (!grad
|| !matrix
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1810 return InvalidParameter
;
1812 grad
->transform
= *matrix
;
1817 GpStatus WINGDIPAPI
GdipGetPathGradientTransform(GpPathGradient
*grad
,
1820 TRACE("(%p,%p)\n", grad
, matrix
);
1822 if (!grad
|| !matrix
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1823 return InvalidParameter
;
1825 *matrix
= grad
->transform
;
1830 GpStatus WINGDIPAPI
GdipMultiplyPathGradientTransform(GpPathGradient
*grad
,
1831 GDIPCONST GpMatrix
*matrix
, GpMatrixOrder order
)
1833 TRACE("(%p,%p,%i)\n", grad
, matrix
, order
);
1835 if (!grad
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1836 return InvalidParameter
;
1838 return GdipMultiplyMatrix(&grad
->transform
, matrix
, order
);
1841 GpStatus WINGDIPAPI
GdipResetPathGradientTransform(GpPathGradient
*grad
)
1843 TRACE("(%p)\n", grad
);
1845 if (!grad
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1846 return InvalidParameter
;
1848 return GdipSetMatrixElements(&grad
->transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1851 GpStatus WINGDIPAPI
GdipRotatePathGradientTransform(GpPathGradient
*grad
,
1852 REAL angle
, GpMatrixOrder order
)
1854 TRACE("(%p,%0.2f,%i)\n", grad
, angle
, order
);
1856 if (!grad
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1857 return InvalidParameter
;
1859 return GdipRotateMatrix(&grad
->transform
, angle
, order
);
1862 GpStatus WINGDIPAPI
GdipScalePathGradientTransform(GpPathGradient
*grad
,
1863 REAL sx
, REAL sy
, GpMatrixOrder order
)
1865 TRACE("(%p,%0.2f,%0.2f,%i)\n", grad
, sx
, sy
, order
);
1867 if (!grad
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1868 return InvalidParameter
;
1870 return GdipScaleMatrix(&grad
->transform
, sx
, sy
, order
);
1873 GpStatus WINGDIPAPI
GdipTranslatePathGradientTransform(GpPathGradient
*grad
,
1874 REAL dx
, REAL dy
, GpMatrixOrder order
)
1876 TRACE("(%p,%0.2f,%0.2f,%i)\n", grad
, dx
, dy
, order
);
1878 if (!grad
|| grad
->brush
.bt
!= BrushTypePathGradient
)
1879 return InvalidParameter
;
1881 return GdipTranslateMatrix(&grad
->transform
, dx
, dy
, order
);
1884 GpStatus WINGDIPAPI
GdipSetSolidFillColor(GpSolidFill
*sf
, ARGB argb
)
1886 TRACE("(%p, %x)\n", sf
, argb
);
1889 return InvalidParameter
;
1895 /******************************************************************************
1896 * GdipSetTextureTransform [GDIPLUS.@]
1898 GpStatus WINGDIPAPI
GdipSetTextureTransform(GpTexture
*texture
,
1899 GDIPCONST GpMatrix
*matrix
)
1901 TRACE("(%p, %p)\n", texture
, matrix
);
1903 if(!texture
|| !matrix
)
1904 return InvalidParameter
;
1906 texture
->transform
= *matrix
;
1911 /******************************************************************************
1912 * GdipSetTextureWrapMode [GDIPLUS.@]
1914 * WrapMode not used, only stored
1916 GpStatus WINGDIPAPI
GdipSetTextureWrapMode(GpTexture
*brush
, GpWrapMode wrapmode
)
1918 TRACE("(%p, %d)\n", brush
, wrapmode
);
1921 return InvalidParameter
;
1923 brush
->imageattributes
->wrap
= wrapmode
;
1928 GpStatus WINGDIPAPI
GdipSetLineColors(GpLineGradient
*brush
, ARGB color1
,
1931 TRACE("(%p, %x, %x)\n", brush
, color1
, color2
);
1933 if(!brush
|| brush
->brush
.bt
!= BrushTypeLinearGradient
)
1934 return InvalidParameter
;
1936 brush
->startcolor
= color1
;
1937 brush
->endcolor
= color2
;
1942 GpStatus WINGDIPAPI
GdipGetLineColors(GpLineGradient
*brush
, ARGB
*colors
)
1944 TRACE("(%p, %p)\n", brush
, colors
);
1946 if(!brush
|| !colors
|| brush
->brush
.bt
!= BrushTypeLinearGradient
)
1947 return InvalidParameter
;
1949 colors
[0] = brush
->startcolor
;
1950 colors
[1] = brush
->endcolor
;
1955 /******************************************************************************
1956 * GdipRotateTextureTransform [GDIPLUS.@]
1958 GpStatus WINGDIPAPI
GdipRotateTextureTransform(GpTexture
* brush
, REAL angle
,
1959 GpMatrixOrder order
)
1961 TRACE("(%p, %.2f, %d)\n", brush
, angle
, order
);
1964 return InvalidParameter
;
1966 return GdipRotateMatrix(&brush
->transform
, angle
, order
);
1969 GpStatus WINGDIPAPI
GdipSetLineLinearBlend(GpLineGradient
*brush
, REAL focus
,
1976 TRACE("(%p,%.2f,%.2f)\n", brush
, focus
, scale
);
1978 if (!brush
) return InvalidParameter
;
1982 factors
[num_points
] = 0.0;
1983 positions
[num_points
] = 0.0;
1987 factors
[num_points
] = scale
;
1988 positions
[num_points
] = focus
;
1993 factors
[num_points
] = 0.0;
1994 positions
[num_points
] = 1.0;
1998 return GdipSetLineBlend(brush
, factors
, positions
, num_points
);
2001 GpStatus WINGDIPAPI
GdipSetLinePresetBlend(GpLineGradient
*brush
,
2002 GDIPCONST ARGB
*blend
, GDIPCONST REAL
* positions
, INT count
)
2006 TRACE("(%p,%p,%p,%i)\n", brush
, blend
, positions
, count
);
2008 if (!brush
|| !blend
|| !positions
|| count
< 2 || brush
->brush
.bt
!= BrushTypeLinearGradient
||
2009 positions
[0] != 0.0f
|| positions
[count
-1] != 1.0f
)
2011 return InvalidParameter
;
2014 new_color
= heap_alloc_zero(count
* sizeof(ARGB
));
2015 new_pos
= heap_alloc_zero(count
* sizeof(REAL
));
2016 if (!new_color
|| !new_pos
)
2018 heap_free(new_color
);
2023 memcpy(new_color
, blend
, sizeof(ARGB
) * count
);
2024 memcpy(new_pos
, positions
, sizeof(REAL
) * count
);
2026 heap_free(brush
->pblendcolor
);
2027 heap_free(brush
->pblendpos
);
2029 brush
->pblendcolor
= new_color
;
2030 brush
->pblendpos
= new_pos
;
2031 brush
->pblendcount
= count
;
2036 GpStatus WINGDIPAPI
GdipGetLinePresetBlend(GpLineGradient
*brush
,
2037 ARGB
*blend
, REAL
* positions
, INT count
)
2039 if (!brush
|| !blend
|| !positions
|| count
< 2 || brush
->brush
.bt
!= BrushTypeLinearGradient
)
2040 return InvalidParameter
;
2042 if (brush
->pblendcount
== 0)
2043 return GenericError
;
2045 if (count
< brush
->pblendcount
)
2046 return InsufficientBuffer
;
2048 memcpy(blend
, brush
->pblendcolor
, sizeof(ARGB
) * brush
->pblendcount
);
2049 memcpy(positions
, brush
->pblendpos
, sizeof(REAL
) * brush
->pblendcount
);
2054 GpStatus WINGDIPAPI
GdipGetLinePresetBlendCount(GpLineGradient
*brush
,
2057 if (!brush
|| !count
|| brush
->brush
.bt
!= BrushTypeLinearGradient
)
2058 return InvalidParameter
;
2060 *count
= brush
->pblendcount
;
2065 GpStatus WINGDIPAPI
GdipResetLineTransform(GpLineGradient
*brush
)
2067 TRACE("(%p)\n", brush
);
2070 return InvalidParameter
;
2072 return GdipSetMatrixElements(&brush
->transform
, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
2075 GpStatus WINGDIPAPI
GdipSetLineTransform(GpLineGradient
*brush
,
2076 GDIPCONST GpMatrix
*matrix
)
2078 TRACE("(%p,%p)\n", brush
, matrix
);
2080 if(!brush
|| !matrix
)
2081 return InvalidParameter
;
2083 brush
->transform
= *matrix
;
2088 GpStatus WINGDIPAPI
GdipGetLineTransform(GpLineGradient
*brush
, GpMatrix
*matrix
)
2090 TRACE("(%p,%p)\n", brush
, matrix
);
2092 if(!brush
|| !matrix
)
2093 return InvalidParameter
;
2095 *matrix
= brush
->transform
;
2100 GpStatus WINGDIPAPI
GdipScaleLineTransform(GpLineGradient
*brush
, REAL sx
, REAL sy
,
2101 GpMatrixOrder order
)
2103 TRACE("(%p,%0.2f,%0.2f,%u)\n", brush
, sx
, sy
, order
);
2106 return InvalidParameter
;
2108 return GdipScaleMatrix(&brush
->transform
, sx
, sy
, order
);
2111 GpStatus WINGDIPAPI
GdipMultiplyLineTransform(GpLineGradient
*brush
,
2112 GDIPCONST GpMatrix
*matrix
, GpMatrixOrder order
)
2114 TRACE("(%p,%p,%u)\n", brush
, matrix
, order
);
2117 return InvalidParameter
;
2122 return GdipMultiplyMatrix(&brush
->transform
, matrix
, order
);
2125 GpStatus WINGDIPAPI
GdipTranslateLineTransform(GpLineGradient
*brush
,
2126 REAL dx
, REAL dy
, GpMatrixOrder order
)
2128 TRACE("(%p,%f,%f,%d)\n", brush
, dx
, dy
, order
);
2131 return InvalidParameter
;
2133 return GdipTranslateMatrix(&brush
->transform
, dx
, dy
, order
);
2136 /******************************************************************************
2137 * GdipTranslateTextureTransform [GDIPLUS.@]
2139 GpStatus WINGDIPAPI
GdipTranslateTextureTransform(GpTexture
* brush
, REAL dx
, REAL dy
,
2140 GpMatrixOrder order
)
2142 TRACE("(%p, %.2f, %.2f, %d)\n", brush
, dx
, dy
, order
);
2145 return InvalidParameter
;
2147 return GdipTranslateMatrix(&brush
->transform
, dx
, dy
, order
);
2150 GpStatus WINGDIPAPI
GdipGetLineRect(GpLineGradient
*brush
, GpRectF
*rect
)
2152 TRACE("(%p, %p)\n", brush
, rect
);
2154 if(!brush
|| !rect
|| brush
->brush
.bt
!= BrushTypeLinearGradient
)
2155 return InvalidParameter
;
2157 *rect
= brush
->rect
;
2162 GpStatus WINGDIPAPI
GdipGetLineRectI(GpLineGradient
*brush
, GpRect
*rect
)
2167 TRACE("(%p, %p)\n", brush
, rect
);
2170 return InvalidParameter
;
2172 ret
= GdipGetLineRect(brush
, &rectF
);
2175 rect
->X
= gdip_round(rectF
.X
);
2176 rect
->Y
= gdip_round(rectF
.Y
);
2177 rect
->Width
= gdip_round(rectF
.Width
);
2178 rect
->Height
= gdip_round(rectF
.Height
);
2184 GpStatus WINGDIPAPI
GdipRotateLineTransform(GpLineGradient
* brush
,
2185 REAL angle
, GpMatrixOrder order
)
2189 TRACE("(%p,%0.2f,%u)\n", brush
, angle
, order
);
2191 if(!brush
|| brush
->brush
.bt
!= BrushTypeLinearGradient
)
2192 return InvalidParameter
;
2195 FIXME("(%p, %.2f, %d) stub\n", brush
, angle
, order
);
2197 return NotImplemented
;