2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "gdiplus_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
37 /******************************************************************************
38 * GdipCloneBrush [GDIPLUS.@]
40 GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone)
42 TRACE("(%p, %p)\n", brush, clone);
45 return InvalidParameter;
48 case BrushTypeSolidColor:
49 *clone = GdipAlloc(sizeof(GpSolidFill));
50 if (!*clone) return OutOfMemory;
52 memcpy(*clone, brush, sizeof(GpSolidFill));
54 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
56 case BrushTypeHatchFill:
57 *clone = GdipAlloc(sizeof(GpHatch));
58 if (!*clone) return OutOfMemory;
60 memcpy(*clone, brush, sizeof(GpHatch));
62 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
64 case BrushTypePathGradient:{
65 GpPathGradient *src, *dest;
68 *clone = GdipAlloc(sizeof(GpPathGradient));
69 if (!*clone) return OutOfMemory;
71 src = (GpPathGradient*) brush,
72 dest = (GpPathGradient*) *clone;
73 count = src->pathdata.Count;
75 memcpy(dest, src, sizeof(GpPathGradient));
77 dest->pathdata.Count = count;
78 dest->pathdata.Points = GdipAlloc(count * sizeof(PointF));
79 dest->pathdata.Types = GdipAlloc(count);
81 if(!dest->pathdata.Points || !dest->pathdata.Types){
82 GdipFree(dest->pathdata.Points);
83 GdipFree(dest->pathdata.Types);
88 memcpy(dest->pathdata.Points, src->pathdata.Points, count * sizeof(PointF));
89 memcpy(dest->pathdata.Types, src->pathdata.Types, count);
92 count = src->blendcount;
93 dest->blendcount = count;
94 dest->blendfac = GdipAlloc(count * sizeof(REAL));
95 dest->blendpos = GdipAlloc(count * sizeof(REAL));
97 if(!dest->blendfac || !dest->blendpos){
98 GdipFree(dest->pathdata.Points);
99 GdipFree(dest->pathdata.Types);
100 GdipFree(dest->blendfac);
101 GdipFree(dest->blendpos);
106 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
107 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
111 case BrushTypeLinearGradient:{
112 GpLineGradient *dest, *src;
115 dest = GdipAlloc(sizeof(GpLineGradient));
116 if(!dest) return OutOfMemory;
118 src = (GpLineGradient*)brush;
120 memcpy(dest, src, sizeof(GpLineGradient));
122 dest->brush.gdibrush = CreateSolidBrush(dest->brush.lb.lbColor);
124 count = dest->blendcount;
125 dest->blendfac = GdipAlloc(count * sizeof(REAL));
126 dest->blendpos = GdipAlloc(count * sizeof(REAL));
128 if (!dest->blendfac || !dest->blendpos)
130 GdipFree(dest->blendfac);
131 GdipFree(dest->blendpos);
132 DeleteObject(dest->brush.gdibrush);
137 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
138 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
140 *clone = &dest->brush;
143 case BrushTypeTextureFill:
144 *clone = GdipAlloc(sizeof(GpTexture));
145 if(!*clone) return OutOfMemory;
147 memcpy(*clone, brush, sizeof(GpTexture));
149 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
152 ERR("not implemented for brush type %d\n", brush->bt);
153 return NotImplemented;
159 static LONG HatchStyleToHatch(HatchStyle hatchstyle)
163 case HatchStyleHorizontal: return HS_HORIZONTAL;
164 case HatchStyleVertical: return HS_VERTICAL;
165 case HatchStyleForwardDiagonal: return HS_FDIAGONAL;
166 case HatchStyleBackwardDiagonal: return HS_BDIAGONAL;
167 case HatchStyleCross: return HS_CROSS;
168 case HatchStyleDiagonalCross: return HS_DIAGCROSS;
173 /******************************************************************************
174 * GdipCreateHatchBrush [GDIPLUS.@]
176 GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle hatchstyle, ARGB forecol, ARGB backcol, GpHatch **brush)
178 COLORREF fgcol = ARGB2COLORREF(forecol);
180 TRACE("(%d, %d, %d, %p)\n", hatchstyle, forecol, backcol, brush);
182 if(!brush) return InvalidParameter;
184 *brush = GdipAlloc(sizeof(GpHatch));
185 if (!*brush) return OutOfMemory;
189 case HatchStyleHorizontal:
190 case HatchStyleVertical:
191 case HatchStyleForwardDiagonal:
192 case HatchStyleBackwardDiagonal:
193 case HatchStyleCross:
194 case HatchStyleDiagonalCross:
195 /* Brushes that map to BS_HATCHED */
196 (*brush)->brush.lb.lbStyle = BS_HATCHED;
197 (*brush)->brush.lb.lbColor = fgcol;
198 (*brush)->brush.lb.lbHatch = HatchStyleToHatch(hatchstyle);
202 FIXME("Unimplemented hatch style %d\n", hatchstyle);
204 (*brush)->brush.lb.lbStyle = BS_SOLID;
205 (*brush)->brush.lb.lbColor = fgcol;
206 (*brush)->brush.lb.lbHatch = 0;
211 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
212 (*brush)->brush.bt = BrushTypeHatchFill;
213 (*brush)->forecol = forecol;
214 (*brush)->backcol = backcol;
215 (*brush)->hatchstyle = hatchstyle;
220 /******************************************************************************
221 * GdipCreateLineBrush [GDIPLUS.@]
223 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
224 GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
225 GpWrapMode wrap, GpLineGradient **line)
227 COLORREF col = ARGB2COLORREF(startcolor);
229 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
230 startcolor, endcolor, wrap, line);
232 if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
233 return InvalidParameter;
235 *line = GdipAlloc(sizeof(GpLineGradient));
236 if(!*line) return OutOfMemory;
238 (*line)->brush.lb.lbStyle = BS_SOLID;
239 (*line)->brush.lb.lbColor = col;
240 (*line)->brush.lb.lbHatch = 0;
241 (*line)->brush.gdibrush = CreateSolidBrush(col);
242 (*line)->brush.bt = BrushTypeLinearGradient;
244 (*line)->startpoint.X = startpoint->X;
245 (*line)->startpoint.Y = startpoint->Y;
246 (*line)->endpoint.X = endpoint->X;
247 (*line)->endpoint.Y = endpoint->Y;
248 (*line)->startcolor = startcolor;
249 (*line)->endcolor = endcolor;
250 (*line)->wrap = wrap;
251 (*line)->gamma = FALSE;
253 (*line)->rect.X = (startpoint->X < endpoint->X ? startpoint->X: endpoint->X);
254 (*line)->rect.Y = (startpoint->Y < endpoint->Y ? startpoint->Y: endpoint->Y);
255 (*line)->rect.Width = fabs(startpoint->X - endpoint->X);
256 (*line)->rect.Height = fabs(startpoint->Y - endpoint->Y);
258 (*line)->blendcount = 1;
259 (*line)->blendfac = GdipAlloc(sizeof(REAL));
260 (*line)->blendpos = GdipAlloc(sizeof(REAL));
262 if (!(*line)->blendfac || !(*line)->blendpos)
264 GdipFree((*line)->blendfac);
265 GdipFree((*line)->blendpos);
266 DeleteObject((*line)->brush.gdibrush);
272 (*line)->blendfac[0] = 1.0f;
273 (*line)->blendpos[0] = 1.0f;
278 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
279 GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
280 GpWrapMode wrap, GpLineGradient **line)
285 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
286 startcolor, endcolor, wrap, line);
288 if(!startpoint || !endpoint)
289 return InvalidParameter;
291 stF.X = (REAL)startpoint->X;
292 stF.Y = (REAL)startpoint->Y;
293 endF.X = (REAL)endpoint->X;
294 endF.X = (REAL)endpoint->Y;
296 return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
299 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
300 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
301 GpLineGradient **line)
306 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
310 return InvalidParameter;
314 end.X = rect->X + rect->Width;
315 end.Y = rect->Y + rect->Height;
317 stat = GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
320 (*line)->rect = *rect;
325 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
326 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
327 GpLineGradient **line)
331 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
334 rectF.X = (REAL) rect->X;
335 rectF.Y = (REAL) rect->Y;
336 rectF.Width = (REAL) rect->Width;
337 rectF.Height = (REAL) rect->Height;
339 return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
342 /******************************************************************************
343 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
345 * FIXME: angle value completely ignored. Don't know how to use it since native
346 * always set Brush rectangle to rect (independetly of this angle).
347 * Maybe it's used only on drawing.
349 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
350 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
351 GpLineGradient **line)
353 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
356 return GdipCreateLineBrushFromRect(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
360 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
361 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
362 GpLineGradient **line)
364 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
367 return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
371 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
372 INT count, GpWrapMode wrap, GpPathGradient **grad)
374 COLORREF col = ARGB2COLORREF(0xffffffff);
376 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
379 return InvalidParameter;
384 *grad = GdipAlloc(sizeof(GpPathGradient));
385 if (!*grad) return OutOfMemory;
387 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
388 if(!(*grad)->blendfac){
392 (*grad)->blendfac[0] = 1.0;
393 (*grad)->blendpos = NULL;
394 (*grad)->blendcount = 1;
396 (*grad)->pathdata.Count = count;
397 (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
398 (*grad)->pathdata.Types = GdipAlloc(count);
400 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
401 GdipFree((*grad)->pathdata.Points);
402 GdipFree((*grad)->pathdata.Types);
407 memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
408 memset((*grad)->pathdata.Types, PathPointTypeLine, count);
410 (*grad)->brush.lb.lbStyle = BS_SOLID;
411 (*grad)->brush.lb.lbColor = col;
412 (*grad)->brush.lb.lbHatch = 0;
414 (*grad)->brush.gdibrush = CreateSolidBrush(col);
415 (*grad)->brush.bt = BrushTypePathGradient;
416 (*grad)->centercolor = 0xffffffff;
417 (*grad)->wrap = wrap;
418 (*grad)->gamma = FALSE;
419 (*grad)->center.X = 0.0;
420 (*grad)->center.Y = 0.0;
421 (*grad)->focus.X = 0.0;
422 (*grad)->focus.Y = 0.0;
427 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
428 INT count, GpWrapMode wrap, GpPathGradient **grad)
434 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
437 return InvalidParameter;
442 pointsF = GdipAlloc(sizeof(GpPointF) * count);
446 for(i = 0; i < count; i++){
447 pointsF[i].X = (REAL)points[i].X;
448 pointsF[i].Y = (REAL)points[i].Y;
451 ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
457 /******************************************************************************
458 * GdipCreatePathGradientFromPath [GDIPLUS.@]
460 * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
462 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
463 GpPathGradient **grad)
465 COLORREF col = ARGB2COLORREF(0xffffffff);
467 TRACE("(%p, %p)\n", path, grad);
470 return InvalidParameter;
472 *grad = GdipAlloc(sizeof(GpPathGradient));
473 if (!*grad) return OutOfMemory;
475 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
476 if(!(*grad)->blendfac){
480 (*grad)->blendfac[0] = 1.0;
481 (*grad)->blendpos = NULL;
482 (*grad)->blendcount = 1;
484 (*grad)->pathdata.Count = path->pathdata.Count;
485 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
486 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
488 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
489 GdipFree((*grad)->pathdata.Points);
490 GdipFree((*grad)->pathdata.Types);
495 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
496 path->pathdata.Count * sizeof(PointF));
497 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
499 (*grad)->brush.lb.lbStyle = BS_SOLID;
500 (*grad)->brush.lb.lbColor = col;
501 (*grad)->brush.lb.lbHatch = 0;
503 (*grad)->brush.gdibrush = CreateSolidBrush(col);
504 (*grad)->brush.bt = BrushTypePathGradient;
505 (*grad)->centercolor = 0xffffffff;
506 (*grad)->wrap = WrapModeClamp;
507 (*grad)->gamma = FALSE;
508 /* FIXME: this should be set to the "centroid" of the path by default */
509 (*grad)->center.X = 0.0;
510 (*grad)->center.Y = 0.0;
511 (*grad)->focus.X = 0.0;
512 (*grad)->focus.Y = 0.0;
517 /******************************************************************************
518 * GdipCreateSolidFill [GDIPLUS.@]
520 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
522 COLORREF col = ARGB2COLORREF(color);
524 TRACE("(%x, %p)\n", color, sf);
526 if(!sf) return InvalidParameter;
528 *sf = GdipAlloc(sizeof(GpSolidFill));
529 if (!*sf) return OutOfMemory;
531 (*sf)->brush.lb.lbStyle = BS_SOLID;
532 (*sf)->brush.lb.lbColor = col;
533 (*sf)->brush.lb.lbHatch = 0;
535 (*sf)->brush.gdibrush = CreateSolidBrush(col);
536 (*sf)->brush.bt = BrushTypeSolidColor;
537 (*sf)->color = color;
542 /******************************************************************************
543 * GdipCreateTexture [GDIPLUS.@]
546 * image [I] image to use
547 * wrapmode [I] optional
548 * texture [O] pointer to the resulting texturebrush
552 * FAILURE: element of GpStatus
554 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
558 GpImageAttributes attributes;
561 TRACE("%p, %d %p\n", image, wrapmode, texture);
563 if (!(image && texture))
564 return InvalidParameter;
566 stat = GdipGetImageWidth(image, &width);
567 if (stat != Ok) return stat;
568 stat = GdipGetImageHeight(image, &height);
569 if (stat != Ok) return stat;
570 attributes.wrap = wrapmode;
572 return GdipCreateTextureIA(image, &attributes, 0, 0, width, height,
576 /******************************************************************************
577 * GdipCreateTexture2 [GDIPLUS.@]
579 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
580 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
582 GpImageAttributes attributes;
584 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
585 x, y, width, height, texture);
587 attributes.wrap = wrapmode;
588 return GdipCreateTextureIA(image, &attributes, x, y, width, height,
592 /******************************************************************************
593 * GdipCreateTextureIA [GDIPLUS.@]
595 * FIXME: imageattr ignored
597 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
598 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
599 REAL height, GpTexture **texture)
602 HBITMAP hbm, old = NULL;
604 BITMAPINFOHEADER *bmih;
605 INT n_x, n_y, n_width, n_height, abs_height, stride, image_stride, i, bytespp;
607 BYTE *dibits, *buff, *textbits;
610 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
613 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
614 return InvalidParameter;
616 if(image->type != ImageTypeBitmap){
617 FIXME("not implemented for image type %d\n", image->type);
618 return NotImplemented;
623 n_width = roundr(width);
624 n_height = roundr(height);
626 if(n_x + n_width > ((GpBitmap*)image)->width ||
627 n_y + n_height > ((GpBitmap*)image)->height)
628 return InvalidParameter;
630 IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbm);
631 if(!hbm) return GenericError;
632 IPicture_get_CurDC(image->picture, &hdc);
633 bm_is_selected = (hdc != 0);
635 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
638 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
639 pbmi->bmiHeader.biBitCount = 0;
642 hdc = CreateCompatibleDC(0);
643 old = SelectObject(hdc, hbm);
647 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
649 bytespp = pbmi->bmiHeader.biBitCount / 8;
650 abs_height = abs(pbmi->bmiHeader.biHeight);
652 if(n_x > pbmi->bmiHeader.biWidth || n_x + n_width > pbmi->bmiHeader.biWidth ||
653 n_y > abs_height || n_y + n_height > abs_height){
655 return InvalidParameter;
658 dibits = GdipAlloc(pbmi->bmiHeader.biSizeImage);
660 if(dibits) /* this is not a good place to error out */
661 GetDIBits(hdc, hbm, 0, abs_height, dibits, pbmi, DIB_RGB_COLORS);
664 SelectObject(hdc, old);
673 image_stride = (pbmi->bmiHeader.biWidth * bytespp + 3) & ~3;
674 stride = (n_width * bytespp + 3) & ~3;
675 buff = GdipAlloc(sizeof(BITMAPINFOHEADER) + stride * n_height);
682 bmih = (BITMAPINFOHEADER*)buff;
683 textbits = (BYTE*) (bmih + 1);
684 bmih->biSize = sizeof(BITMAPINFOHEADER);
685 bmih->biWidth = n_width;
686 bmih->biHeight = n_height;
687 bmih->biCompression = BI_RGB;
688 bmih->biSizeImage = stride * n_height;
689 bmih->biBitCount = pbmi->bmiHeader.biBitCount;
693 /* image is flipped */
694 if(pbmi->bmiHeader.biHeight > 0){
695 dibits += pbmi->bmiHeader.biSizeImage;
697 textbits += stride * (n_height - 1);
703 for(i = 0; i < n_height; i++)
704 memcpy(&textbits[i * stride],
705 &dibits[n_x * bytespp + (n_y + i) * image_stride],
708 *texture = GdipAlloc(sizeof(GpTexture));
715 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
722 (*texture)->brush.lb.lbStyle = BS_DIBPATTERNPT;
723 (*texture)->brush.lb.lbColor = DIB_RGB_COLORS;
724 (*texture)->brush.lb.lbHatch = (ULONG_PTR)buff;
726 (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
727 (*texture)->brush.bt = BrushTypeTextureFill;
728 (*texture)->wrap = imageattr->wrap;
736 /******************************************************************************
737 * GdipCreateTextureIAI [GDIPLUS.@]
739 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
740 INT x, INT y, INT width, INT height, GpTexture **texture)
742 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
745 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
748 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
749 INT x, INT y, INT width, INT height, GpTexture **texture)
751 GpImageAttributes imageattr;
753 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
756 imageattr.wrap = wrapmode;
758 return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
761 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
763 TRACE("(%p, %p)\n", brush, type);
765 if(!brush || !type) return InvalidParameter;
772 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
774 TRACE("(%p, %p)\n", brush, backcol);
776 if(!brush || !backcol) return InvalidParameter;
778 *backcol = brush->backcol;
783 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
785 TRACE("(%p, %p)\n", brush, forecol);
787 if(!brush || !forecol) return InvalidParameter;
789 *forecol = brush->forecol;
794 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
796 TRACE("(%p, %p)\n", brush, hatchstyle);
798 if(!brush || !hatchstyle) return InvalidParameter;
800 *hatchstyle = brush->hatchstyle;
805 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
807 TRACE("(%p)\n", brush);
809 if(!brush) return InvalidParameter;
813 case BrushTypePathGradient:
814 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
815 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
816 GdipFree(((GpPathGradient*) brush)->blendfac);
817 GdipFree(((GpPathGradient*) brush)->blendpos);
819 case BrushTypeSolidColor:
821 case BrushTypeLinearGradient:
822 GdipFree(((GpLineGradient*)brush)->blendfac);
823 GdipFree(((GpLineGradient*)brush)->blendpos);
825 case BrushTypeTextureFill:
826 GdipDeleteMatrix(((GpTexture*)brush)->transform);
832 DeleteObject(brush->gdibrush);
838 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
841 TRACE("(%p, %p)\n", line, usinggamma);
843 if(!line || !usinggamma)
844 return InvalidParameter;
846 *usinggamma = line->gamma;
851 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
853 TRACE("(%p, %p)\n", brush, wrapmode);
855 if(!brush || !wrapmode)
856 return InvalidParameter;
858 *wrapmode = brush->wrap;
863 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
864 REAL *positions, INT count)
866 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
868 if(!brush || !blend || !positions || count <= 0)
869 return InvalidParameter;
871 if(count < brush->blendcount)
872 return InsufficientBuffer;
874 memcpy(blend, brush->blendfac, count*sizeof(REAL));
875 if(brush->blendcount > 1){
876 memcpy(positions, brush->blendpos, count*sizeof(REAL));
882 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
884 TRACE("(%p, %p)\n", brush, count);
887 return InvalidParameter;
889 *count = brush->blendcount;
894 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
897 TRACE("(%p, %p)\n", grad, point);
900 return InvalidParameter;
902 point->X = grad->center.X;
903 point->Y = grad->center.Y;
908 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
914 TRACE("(%p, %p)\n", grad, point);
917 return InvalidParameter;
919 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
922 point->X = roundr(ptf.X);
923 point->Y = roundr(ptf.Y);
929 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
932 TRACE("(%p, %p, %p)\n", grad, x, y);
934 if(!grad || !x || !y)
935 return InvalidParameter;
943 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
946 TRACE("(%p, %p)\n", grad, gamma);
949 return InvalidParameter;
951 *gamma = grad->gamma;
956 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
959 TRACE("(%p, %p)\n", grad, count);
962 return InvalidParameter;
964 *count = grad->pathdata.Count;
969 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
975 TRACE("(%p, %p)\n", brush, rect);
978 return InvalidParameter;
980 stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
981 brush->pathdata.Count, FillModeAlternate, &path);
982 if(stat != Ok) return stat;
984 stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
986 GdipDeletePath(path);
990 memcpy(rect, &r, sizeof(GpRectF));
992 GdipDeletePath(path);
997 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1002 TRACE("(%p, %p)\n", brush, rect);
1005 return InvalidParameter;
1007 stat = GdipGetPathGradientRect(brush, &rectf);
1008 if(stat != Ok) return stat;
1010 rect->X = roundr(rectf.X);
1011 rect->Y = roundr(rectf.Y);
1012 rect->Width = roundr(rectf.Width);
1013 rect->Height = roundr(rectf.Height);
1018 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1019 *grad, ARGB *argb, INT *count)
1023 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
1024 return InvalidParameter;
1027 FIXME("not implemented\n");
1029 return NotImplemented;
1032 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1033 GpWrapMode *wrapmode)
1035 TRACE("(%p, %p)\n", brush, wrapmode);
1037 if(!brush || !wrapmode)
1038 return InvalidParameter;
1040 *wrapmode = brush->wrap;
1045 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1047 TRACE("(%p, %p)\n", sf, argb);
1050 return InvalidParameter;
1057 /******************************************************************************
1058 * GdipGetTextureTransform [GDIPLUS.@]
1060 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1062 TRACE("(%p, %p)\n", brush, matrix);
1064 if(!brush || !matrix)
1065 return InvalidParameter;
1067 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1072 /******************************************************************************
1073 * GdipGetTextureWrapMode [GDIPLUS.@]
1075 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1077 TRACE("(%p, %p)\n", brush, wrapmode);
1079 if(!brush || !wrapmode)
1080 return InvalidParameter;
1082 *wrapmode = brush->wrap;
1087 /******************************************************************************
1088 * GdipMultiplyTextureTransform [GDIPLUS.@]
1090 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1091 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1093 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1095 if(!brush || !matrix)
1096 return InvalidParameter;
1098 return GdipMultiplyMatrix(brush->transform, matrix, order);
1101 /******************************************************************************
1102 * GdipResetTextureTransform [GDIPLUS.@]
1104 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1106 TRACE("(%p)\n", brush);
1109 return InvalidParameter;
1111 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1114 /******************************************************************************
1115 * GdipScaleTextureTransform [GDIPLUS.@]
1117 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1118 REAL sx, REAL sy, GpMatrixOrder order)
1120 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1123 return InvalidParameter;
1125 return GdipScaleMatrix(brush->transform, sx, sy, order);
1128 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1129 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1131 REAL *new_blendfac, *new_blendpos;
1133 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1135 if(!brush || !factors || !positions || count <= 0 ||
1136 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1137 return InvalidParameter;
1139 new_blendfac = GdipAlloc(count * sizeof(REAL));
1140 new_blendpos = GdipAlloc(count * sizeof(REAL));
1142 if (!new_blendfac || !new_blendpos)
1144 GdipFree(new_blendfac);
1145 GdipFree(new_blendpos);
1149 memcpy(new_blendfac, factors, count * sizeof(REAL));
1150 memcpy(new_blendpos, positions, count * sizeof(REAL));
1152 GdipFree(brush->blendfac);
1153 GdipFree(brush->blendpos);
1155 brush->blendcount = count;
1156 brush->blendfac = new_blendfac;
1157 brush->blendpos = new_blendpos;
1162 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1163 REAL *positions, INT count)
1165 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1167 if (!brush || !factors || !positions || count <= 0)
1168 return InvalidParameter;
1170 if (count < brush->blendcount)
1171 return InsufficientBuffer;
1173 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1174 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1179 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1181 TRACE("(%p, %p)\n", brush, count);
1183 if (!brush || !count)
1184 return InvalidParameter;
1186 *count = brush->blendcount;
1191 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1194 TRACE("(%p, %d)\n", line, usegamma);
1197 return InvalidParameter;
1199 line->gamma = usegamma;
1204 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1211 const int precision = 16;
1212 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1216 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1218 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1219 return InvalidParameter;
1221 /* we want 2 standard deviations */
1222 erf_range = 2.0 / sqrt(2);
1224 /* calculate the constants we need to normalize the error function to be
1225 between 0.0 and scale over the range we need */
1226 min_erf = erf(-erf_range);
1227 scale_erf = scale / (-2.0 * min_erf);
1233 for (i=1; i<precision; i++)
1235 positions[i] = focus * i / precision;
1236 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1238 num_points += precision;
1241 positions[num_points] = focus;
1242 factors[num_points] = scale;
1247 for (i=1; i<precision; i++)
1249 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1250 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1252 num_points += precision;
1253 positions[num_points-1] = 1.0;
1254 factors[num_points-1] = 0.0;
1257 return GdipSetLineBlend(line, factors, positions, num_points);
1260 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1263 TRACE("(%p, %d)\n", line, wrap);
1265 if(!line || wrap == WrapModeClamp)
1266 return InvalidParameter;
1273 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1274 GDIPCONST REAL *pos, INT count)
1279 FIXME("not implemented\n");
1281 return NotImplemented;
1284 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1287 TRACE("(%p, %x)\n", grad, argb);
1290 return InvalidParameter;
1292 grad->centercolor = argb;
1293 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1295 DeleteObject(grad->brush.gdibrush);
1296 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1301 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1304 TRACE("(%p, %p)\n", grad, point);
1307 return InvalidParameter;
1309 grad->center.X = point->X;
1310 grad->center.Y = point->Y;
1315 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1320 TRACE("(%p, %p)\n", grad, point);
1323 return InvalidParameter;
1325 ptf.X = (REAL)point->X;
1326 ptf.Y = (REAL)point->Y;
1328 return GdipSetPathGradientCenterPoint(grad,&ptf);
1331 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1334 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1337 return InvalidParameter;
1345 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1348 TRACE("(%p, %d)\n", grad, gamma);
1351 return InvalidParameter;
1353 grad->gamma = gamma;
1358 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1359 REAL focus, REAL scale)
1363 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1364 return InvalidParameter;
1367 FIXME("not implemented\n");
1369 return NotImplemented;
1372 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1373 *grad, ARGB *argb, INT *count)
1377 if(!grad || !argb || !count || (*count <= 0) ||
1378 (*count > grad->pathdata.Count))
1379 return InvalidParameter;
1382 FIXME("not implemented\n");
1384 return NotImplemented;
1387 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1390 TRACE("(%p, %d)\n", grad, wrap);
1393 return InvalidParameter;
1400 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1402 TRACE("(%p, %x)\n", sf, argb);
1405 return InvalidParameter;
1408 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1410 DeleteObject(sf->brush.gdibrush);
1411 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1416 /******************************************************************************
1417 * GdipSetTextureTransform [GDIPLUS.@]
1419 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1420 GDIPCONST GpMatrix *matrix)
1422 TRACE("(%p, %p)\n", texture, matrix);
1424 if(!texture || !matrix)
1425 return InvalidParameter;
1427 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1432 /******************************************************************************
1433 * GdipSetTextureWrapMode [GDIPLUS.@]
1435 * WrapMode not used, only stored
1437 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1439 TRACE("(%p, %d)\n", brush, wrapmode);
1442 return InvalidParameter;
1444 brush->wrap = wrapmode;
1449 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1452 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1455 return InvalidParameter;
1457 brush->startcolor = color1;
1458 brush->endcolor = color2;
1463 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1465 TRACE("(%p, %p)\n", brush, colors);
1467 if(!brush || !colors)
1468 return InvalidParameter;
1470 colors[0] = brush->startcolor;
1471 colors[1] = brush->endcolor;
1476 /******************************************************************************
1477 * GdipRotateTextureTransform [GDIPLUS.@]
1479 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1480 GpMatrixOrder order)
1482 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1485 return InvalidParameter;
1487 return GdipRotateMatrix(brush->transform, angle, order);
1490 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1496 FIXME("not implemented\n");
1498 return NotImplemented;
1501 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1502 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1507 FIXME("not implemented\n");
1509 return NotImplemented;
1512 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1513 GDIPCONST GpMatrix *matrix)
1518 FIXME("not implemented\n");
1520 return NotImplemented;
1523 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1524 REAL dx, REAL dy, GpMatrixOrder order)
1526 FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1528 return NotImplemented;
1531 /******************************************************************************
1532 * GdipTranslateTextureTransform [GDIPLUS.@]
1534 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1535 GpMatrixOrder order)
1537 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1540 return InvalidParameter;
1542 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1545 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1547 TRACE("(%p, %p)\n", brush, rect);
1550 return InvalidParameter;
1552 *rect = brush->rect;
1557 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1562 TRACE("(%p, %p)\n", brush, rect);
1565 return InvalidParameter;
1567 ret = GdipGetLineRect(brush, &rectF);
1570 rect->X = roundr(rectF.X);
1571 rect->Y = roundr(rectF.Y);
1572 rect->Width = roundr(rectF.Width);
1573 rect->Height = roundr(rectF.Height);
1579 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1580 REAL angle, GpMatrixOrder order)
1585 return InvalidParameter;
1588 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1590 return NotImplemented;