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 case LinearGradientModeHorizontal:
317 end.X = rect->X + rect->Width;
320 case LinearGradientModeVertical:
324 end.Y = rect->Y + rect->Height;
326 case LinearGradientModeForwardDiagonal:
329 end.X = rect->X + rect->Width;
330 end.Y = rect->Y + rect->Height;
332 case LinearGradientModeBackwardDiagonal:
333 start.X = rect->X + rect->Width;
336 end.Y = rect->Y + rect->Height;
339 return InvalidParameter;
342 stat = GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
345 (*line)->rect = *rect;
350 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
351 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
352 GpLineGradient **line)
356 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
359 rectF.X = (REAL) rect->X;
360 rectF.Y = (REAL) rect->Y;
361 rectF.Width = (REAL) rect->Width;
362 rectF.Height = (REAL) rect->Height;
364 return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
367 /******************************************************************************
368 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
370 * FIXME: angle value completely ignored. Don't know how to use it since native
371 * always set Brush rectangle to rect (independetly of this angle).
372 * Maybe it's used only on drawing.
374 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
375 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
376 GpLineGradient **line)
378 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
381 return GdipCreateLineBrushFromRect(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
385 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
386 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
387 GpLineGradient **line)
389 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
392 return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
396 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
397 INT count, GpWrapMode wrap, GpPathGradient **grad)
399 COLORREF col = ARGB2COLORREF(0xffffffff);
401 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
404 return InvalidParameter;
409 *grad = GdipAlloc(sizeof(GpPathGradient));
410 if (!*grad) return OutOfMemory;
412 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
413 if(!(*grad)->blendfac){
417 (*grad)->blendfac[0] = 1.0;
418 (*grad)->blendpos = NULL;
419 (*grad)->blendcount = 1;
421 (*grad)->pathdata.Count = count;
422 (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
423 (*grad)->pathdata.Types = GdipAlloc(count);
425 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
426 GdipFree((*grad)->pathdata.Points);
427 GdipFree((*grad)->pathdata.Types);
432 memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
433 memset((*grad)->pathdata.Types, PathPointTypeLine, count);
435 (*grad)->brush.lb.lbStyle = BS_SOLID;
436 (*grad)->brush.lb.lbColor = col;
437 (*grad)->brush.lb.lbHatch = 0;
439 (*grad)->brush.gdibrush = CreateSolidBrush(col);
440 (*grad)->brush.bt = BrushTypePathGradient;
441 (*grad)->centercolor = 0xffffffff;
442 (*grad)->wrap = wrap;
443 (*grad)->gamma = FALSE;
444 (*grad)->center.X = 0.0;
445 (*grad)->center.Y = 0.0;
446 (*grad)->focus.X = 0.0;
447 (*grad)->focus.Y = 0.0;
452 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
453 INT count, GpWrapMode wrap, GpPathGradient **grad)
459 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
462 return InvalidParameter;
467 pointsF = GdipAlloc(sizeof(GpPointF) * count);
471 for(i = 0; i < count; i++){
472 pointsF[i].X = (REAL)points[i].X;
473 pointsF[i].Y = (REAL)points[i].Y;
476 ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
482 /******************************************************************************
483 * GdipCreatePathGradientFromPath [GDIPLUS.@]
485 * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
487 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
488 GpPathGradient **grad)
490 COLORREF col = ARGB2COLORREF(0xffffffff);
492 TRACE("(%p, %p)\n", path, grad);
495 return InvalidParameter;
497 *grad = GdipAlloc(sizeof(GpPathGradient));
498 if (!*grad) return OutOfMemory;
500 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
501 if(!(*grad)->blendfac){
505 (*grad)->blendfac[0] = 1.0;
506 (*grad)->blendpos = NULL;
507 (*grad)->blendcount = 1;
509 (*grad)->pathdata.Count = path->pathdata.Count;
510 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
511 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
513 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
514 GdipFree((*grad)->pathdata.Points);
515 GdipFree((*grad)->pathdata.Types);
520 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
521 path->pathdata.Count * sizeof(PointF));
522 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
524 (*grad)->brush.lb.lbStyle = BS_SOLID;
525 (*grad)->brush.lb.lbColor = col;
526 (*grad)->brush.lb.lbHatch = 0;
528 (*grad)->brush.gdibrush = CreateSolidBrush(col);
529 (*grad)->brush.bt = BrushTypePathGradient;
530 (*grad)->centercolor = 0xffffffff;
531 (*grad)->wrap = WrapModeClamp;
532 (*grad)->gamma = FALSE;
533 /* FIXME: this should be set to the "centroid" of the path by default */
534 (*grad)->center.X = 0.0;
535 (*grad)->center.Y = 0.0;
536 (*grad)->focus.X = 0.0;
537 (*grad)->focus.Y = 0.0;
542 /******************************************************************************
543 * GdipCreateSolidFill [GDIPLUS.@]
545 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
547 COLORREF col = ARGB2COLORREF(color);
549 TRACE("(%x, %p)\n", color, sf);
551 if(!sf) return InvalidParameter;
553 *sf = GdipAlloc(sizeof(GpSolidFill));
554 if (!*sf) return OutOfMemory;
556 (*sf)->brush.lb.lbStyle = BS_SOLID;
557 (*sf)->brush.lb.lbColor = col;
558 (*sf)->brush.lb.lbHatch = 0;
560 (*sf)->brush.gdibrush = CreateSolidBrush(col);
561 (*sf)->brush.bt = BrushTypeSolidColor;
562 (*sf)->color = color;
567 /******************************************************************************
568 * GdipCreateTexture [GDIPLUS.@]
571 * image [I] image to use
572 * wrapmode [I] optional
573 * texture [O] pointer to the resulting texturebrush
577 * FAILURE: element of GpStatus
579 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
583 GpImageAttributes attributes;
586 TRACE("%p, %d %p\n", image, wrapmode, texture);
588 if (!(image && texture))
589 return InvalidParameter;
591 stat = GdipGetImageWidth(image, &width);
592 if (stat != Ok) return stat;
593 stat = GdipGetImageHeight(image, &height);
594 if (stat != Ok) return stat;
595 attributes.wrap = wrapmode;
597 return GdipCreateTextureIA(image, &attributes, 0, 0, width, height,
601 /******************************************************************************
602 * GdipCreateTexture2 [GDIPLUS.@]
604 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
605 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
607 GpImageAttributes attributes;
609 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
610 x, y, width, height, texture);
612 attributes.wrap = wrapmode;
613 return GdipCreateTextureIA(image, &attributes, x, y, width, height,
617 /******************************************************************************
618 * GdipCreateTextureIA [GDIPLUS.@]
620 * FIXME: imageattr ignored
622 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
623 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
624 REAL height, GpTexture **texture)
627 HBITMAP hbm, old = NULL;
629 BITMAPINFOHEADER *bmih;
630 INT n_x, n_y, n_width, n_height, abs_height, stride, image_stride, i, bytespp;
632 BYTE *dibits, *buff, *textbits;
635 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
638 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
639 return InvalidParameter;
641 if(image->type != ImageTypeBitmap){
642 FIXME("not implemented for image type %d\n", image->type);
643 return NotImplemented;
648 n_width = roundr(width);
649 n_height = roundr(height);
651 if(n_x + n_width > ((GpBitmap*)image)->width ||
652 n_y + n_height > ((GpBitmap*)image)->height)
653 return InvalidParameter;
655 IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbm);
656 if(!hbm) return GenericError;
657 IPicture_get_CurDC(image->picture, &hdc);
658 bm_is_selected = (hdc != 0);
660 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
663 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
664 pbmi->bmiHeader.biBitCount = 0;
667 hdc = CreateCompatibleDC(0);
668 old = SelectObject(hdc, hbm);
672 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
674 bytespp = pbmi->bmiHeader.biBitCount / 8;
675 abs_height = abs(pbmi->bmiHeader.biHeight);
677 if(n_x > pbmi->bmiHeader.biWidth || n_x + n_width > pbmi->bmiHeader.biWidth ||
678 n_y > abs_height || n_y + n_height > abs_height){
680 return InvalidParameter;
683 dibits = GdipAlloc(pbmi->bmiHeader.biSizeImage);
685 if(dibits) /* this is not a good place to error out */
686 GetDIBits(hdc, hbm, 0, abs_height, dibits, pbmi, DIB_RGB_COLORS);
689 SelectObject(hdc, old);
698 image_stride = (pbmi->bmiHeader.biWidth * bytespp + 3) & ~3;
699 stride = (n_width * bytespp + 3) & ~3;
700 buff = GdipAlloc(sizeof(BITMAPINFOHEADER) + stride * n_height);
707 bmih = (BITMAPINFOHEADER*)buff;
708 textbits = (BYTE*) (bmih + 1);
709 bmih->biSize = sizeof(BITMAPINFOHEADER);
710 bmih->biWidth = n_width;
711 bmih->biHeight = n_height;
712 bmih->biCompression = BI_RGB;
713 bmih->biSizeImage = stride * n_height;
714 bmih->biBitCount = pbmi->bmiHeader.biBitCount;
718 /* image is flipped */
719 if(pbmi->bmiHeader.biHeight > 0){
720 dibits += pbmi->bmiHeader.biSizeImage;
722 textbits += stride * (n_height - 1);
728 for(i = 0; i < n_height; i++)
729 memcpy(&textbits[i * stride],
730 &dibits[n_x * bytespp + (n_y + i) * image_stride],
733 *texture = GdipAlloc(sizeof(GpTexture));
740 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
747 (*texture)->brush.lb.lbStyle = BS_DIBPATTERNPT;
748 (*texture)->brush.lb.lbColor = DIB_RGB_COLORS;
749 (*texture)->brush.lb.lbHatch = (ULONG_PTR)buff;
751 (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
752 (*texture)->brush.bt = BrushTypeTextureFill;
753 (*texture)->wrap = imageattr->wrap;
761 /******************************************************************************
762 * GdipCreateTextureIAI [GDIPLUS.@]
764 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
765 INT x, INT y, INT width, INT height, GpTexture **texture)
767 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
770 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
773 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
774 INT x, INT y, INT width, INT height, GpTexture **texture)
776 GpImageAttributes imageattr;
778 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
781 imageattr.wrap = wrapmode;
783 return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
786 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
788 TRACE("(%p, %p)\n", brush, type);
790 if(!brush || !type) return InvalidParameter;
797 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
799 TRACE("(%p, %p)\n", brush, backcol);
801 if(!brush || !backcol) return InvalidParameter;
803 *backcol = brush->backcol;
808 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
810 TRACE("(%p, %p)\n", brush, forecol);
812 if(!brush || !forecol) return InvalidParameter;
814 *forecol = brush->forecol;
819 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
821 TRACE("(%p, %p)\n", brush, hatchstyle);
823 if(!brush || !hatchstyle) return InvalidParameter;
825 *hatchstyle = brush->hatchstyle;
830 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
832 TRACE("(%p)\n", brush);
834 if(!brush) return InvalidParameter;
838 case BrushTypePathGradient:
839 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
840 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
841 GdipFree(((GpPathGradient*) brush)->blendfac);
842 GdipFree(((GpPathGradient*) brush)->blendpos);
844 case BrushTypeSolidColor:
846 case BrushTypeLinearGradient:
847 GdipFree(((GpLineGradient*)brush)->blendfac);
848 GdipFree(((GpLineGradient*)brush)->blendpos);
850 case BrushTypeTextureFill:
851 GdipDeleteMatrix(((GpTexture*)brush)->transform);
857 DeleteObject(brush->gdibrush);
863 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
866 TRACE("(%p, %p)\n", line, usinggamma);
868 if(!line || !usinggamma)
869 return InvalidParameter;
871 *usinggamma = line->gamma;
876 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
878 TRACE("(%p, %p)\n", brush, wrapmode);
880 if(!brush || !wrapmode)
881 return InvalidParameter;
883 *wrapmode = brush->wrap;
888 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
889 REAL *positions, INT count)
891 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
893 if(!brush || !blend || !positions || count <= 0)
894 return InvalidParameter;
896 if(count < brush->blendcount)
897 return InsufficientBuffer;
899 memcpy(blend, brush->blendfac, count*sizeof(REAL));
900 if(brush->blendcount > 1){
901 memcpy(positions, brush->blendpos, count*sizeof(REAL));
907 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
909 TRACE("(%p, %p)\n", brush, count);
912 return InvalidParameter;
914 *count = brush->blendcount;
919 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
922 TRACE("(%p, %p)\n", grad, point);
925 return InvalidParameter;
927 point->X = grad->center.X;
928 point->Y = grad->center.Y;
933 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
939 TRACE("(%p, %p)\n", grad, point);
942 return InvalidParameter;
944 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
947 point->X = roundr(ptf.X);
948 point->Y = roundr(ptf.Y);
954 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
957 TRACE("(%p, %p, %p)\n", grad, x, y);
959 if(!grad || !x || !y)
960 return InvalidParameter;
968 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
971 TRACE("(%p, %p)\n", grad, gamma);
974 return InvalidParameter;
976 *gamma = grad->gamma;
981 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
984 TRACE("(%p, %p)\n", grad, count);
987 return InvalidParameter;
989 *count = grad->pathdata.Count;
994 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
1000 TRACE("(%p, %p)\n", brush, rect);
1003 return InvalidParameter;
1005 stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
1006 brush->pathdata.Count, FillModeAlternate, &path);
1007 if(stat != Ok) return stat;
1009 stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
1011 GdipDeletePath(path);
1015 memcpy(rect, &r, sizeof(GpRectF));
1017 GdipDeletePath(path);
1022 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
1027 TRACE("(%p, %p)\n", brush, rect);
1030 return InvalidParameter;
1032 stat = GdipGetPathGradientRect(brush, &rectf);
1033 if(stat != Ok) return stat;
1035 rect->X = roundr(rectf.X);
1036 rect->Y = roundr(rectf.Y);
1037 rect->Width = roundr(rectf.Width);
1038 rect->Height = roundr(rectf.Height);
1043 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
1044 *grad, ARGB *argb, INT *count)
1048 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
1049 return InvalidParameter;
1052 FIXME("not implemented\n");
1054 return NotImplemented;
1057 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
1058 GpWrapMode *wrapmode)
1060 TRACE("(%p, %p)\n", brush, wrapmode);
1062 if(!brush || !wrapmode)
1063 return InvalidParameter;
1065 *wrapmode = brush->wrap;
1070 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
1072 TRACE("(%p, %p)\n", sf, argb);
1075 return InvalidParameter;
1082 /******************************************************************************
1083 * GdipGetTextureTransform [GDIPLUS.@]
1085 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1087 TRACE("(%p, %p)\n", brush, matrix);
1089 if(!brush || !matrix)
1090 return InvalidParameter;
1092 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1097 /******************************************************************************
1098 * GdipGetTextureWrapMode [GDIPLUS.@]
1100 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1102 TRACE("(%p, %p)\n", brush, wrapmode);
1104 if(!brush || !wrapmode)
1105 return InvalidParameter;
1107 *wrapmode = brush->wrap;
1112 /******************************************************************************
1113 * GdipMultiplyTextureTransform [GDIPLUS.@]
1115 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1116 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1118 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1120 if(!brush || !matrix)
1121 return InvalidParameter;
1123 return GdipMultiplyMatrix(brush->transform, matrix, order);
1126 /******************************************************************************
1127 * GdipResetTextureTransform [GDIPLUS.@]
1129 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1131 TRACE("(%p)\n", brush);
1134 return InvalidParameter;
1136 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1139 /******************************************************************************
1140 * GdipScaleTextureTransform [GDIPLUS.@]
1142 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1143 REAL sx, REAL sy, GpMatrixOrder order)
1145 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1148 return InvalidParameter;
1150 return GdipScaleMatrix(brush->transform, sx, sy, order);
1153 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1154 GDIPCONST REAL *factors, GDIPCONST REAL* positions, INT count)
1156 REAL *new_blendfac, *new_blendpos;
1158 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1160 if(!brush || !factors || !positions || count <= 0 ||
1161 (count >= 2 && (positions[0] != 0.0f || positions[count-1] != 1.0f)))
1162 return InvalidParameter;
1164 new_blendfac = GdipAlloc(count * sizeof(REAL));
1165 new_blendpos = GdipAlloc(count * sizeof(REAL));
1167 if (!new_blendfac || !new_blendpos)
1169 GdipFree(new_blendfac);
1170 GdipFree(new_blendpos);
1174 memcpy(new_blendfac, factors, count * sizeof(REAL));
1175 memcpy(new_blendpos, positions, count * sizeof(REAL));
1177 GdipFree(brush->blendfac);
1178 GdipFree(brush->blendpos);
1180 brush->blendcount = count;
1181 brush->blendfac = new_blendfac;
1182 brush->blendpos = new_blendpos;
1187 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient *brush, REAL *factors,
1188 REAL *positions, INT count)
1190 TRACE("(%p, %p, %p, %i)\n", brush, factors, positions, count);
1192 if (!brush || !factors || !positions || count <= 0)
1193 return InvalidParameter;
1195 if (count < brush->blendcount)
1196 return InsufficientBuffer;
1198 memcpy(factors, brush->blendfac, brush->blendcount * sizeof(REAL));
1199 memcpy(positions, brush->blendpos, brush->blendcount * sizeof(REAL));
1204 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient *brush, INT *count)
1206 TRACE("(%p, %p)\n", brush, count);
1208 if (!brush || !count)
1209 return InvalidParameter;
1211 *count = brush->blendcount;
1216 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1219 TRACE("(%p, %d)\n", line, usegamma);
1222 return InvalidParameter;
1224 line->gamma = usegamma;
1229 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1236 const int precision = 16;
1237 REAL erf_range; /* we use values erf(-erf_range) through erf(+erf_range) */
1241 TRACE("(%p, %0.2f, %0.2f)\n", line, focus, scale);
1243 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1244 return InvalidParameter;
1246 /* we want 2 standard deviations */
1247 erf_range = 2.0 / sqrt(2);
1249 /* calculate the constants we need to normalize the error function to be
1250 between 0.0 and scale over the range we need */
1251 min_erf = erf(-erf_range);
1252 scale_erf = scale / (-2.0 * min_erf);
1258 for (i=1; i<precision; i++)
1260 positions[i] = focus * i / precision;
1261 factors[i] = scale_erf * (erf(2 * erf_range * i / precision - erf_range) - min_erf);
1263 num_points += precision;
1266 positions[num_points] = focus;
1267 factors[num_points] = scale;
1272 for (i=1; i<precision; i++)
1274 positions[i+num_points-1] = (focus + ((1.0-focus) * i / precision));
1275 factors[i+num_points-1] = scale_erf * (erf(erf_range - 2 * erf_range * i / precision) - min_erf);
1277 num_points += precision;
1278 positions[num_points-1] = 1.0;
1279 factors[num_points-1] = 0.0;
1282 return GdipSetLineBlend(line, factors, positions, num_points);
1285 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1288 TRACE("(%p, %d)\n", line, wrap);
1290 if(!line || wrap == WrapModeClamp)
1291 return InvalidParameter;
1298 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1299 GDIPCONST REAL *pos, INT count)
1304 FIXME("not implemented\n");
1306 return NotImplemented;
1309 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1312 TRACE("(%p, %x)\n", grad, argb);
1315 return InvalidParameter;
1317 grad->centercolor = argb;
1318 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1320 DeleteObject(grad->brush.gdibrush);
1321 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1326 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1329 TRACE("(%p, %p)\n", grad, point);
1332 return InvalidParameter;
1334 grad->center.X = point->X;
1335 grad->center.Y = point->Y;
1340 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1345 TRACE("(%p, %p)\n", grad, point);
1348 return InvalidParameter;
1350 ptf.X = (REAL)point->X;
1351 ptf.Y = (REAL)point->Y;
1353 return GdipSetPathGradientCenterPoint(grad,&ptf);
1356 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1359 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1362 return InvalidParameter;
1370 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1373 TRACE("(%p, %d)\n", grad, gamma);
1376 return InvalidParameter;
1378 grad->gamma = gamma;
1383 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1384 REAL focus, REAL scale)
1388 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1389 return InvalidParameter;
1392 FIXME("not implemented\n");
1394 return NotImplemented;
1397 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1398 *grad, ARGB *argb, INT *count)
1402 if(!grad || !argb || !count || (*count <= 0) ||
1403 (*count > grad->pathdata.Count))
1404 return InvalidParameter;
1407 FIXME("not implemented\n");
1409 return NotImplemented;
1412 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1415 TRACE("(%p, %d)\n", grad, wrap);
1418 return InvalidParameter;
1425 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1427 TRACE("(%p, %x)\n", sf, argb);
1430 return InvalidParameter;
1433 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1435 DeleteObject(sf->brush.gdibrush);
1436 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1441 /******************************************************************************
1442 * GdipSetTextureTransform [GDIPLUS.@]
1444 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1445 GDIPCONST GpMatrix *matrix)
1447 TRACE("(%p, %p)\n", texture, matrix);
1449 if(!texture || !matrix)
1450 return InvalidParameter;
1452 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1457 /******************************************************************************
1458 * GdipSetTextureWrapMode [GDIPLUS.@]
1460 * WrapMode not used, only stored
1462 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1464 TRACE("(%p, %d)\n", brush, wrapmode);
1467 return InvalidParameter;
1469 brush->wrap = wrapmode;
1474 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1477 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1480 return InvalidParameter;
1482 brush->startcolor = color1;
1483 brush->endcolor = color2;
1488 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1490 TRACE("(%p, %p)\n", brush, colors);
1492 if(!brush || !colors)
1493 return InvalidParameter;
1495 colors[0] = brush->startcolor;
1496 colors[1] = brush->endcolor;
1501 /******************************************************************************
1502 * GdipRotateTextureTransform [GDIPLUS.@]
1504 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1505 GpMatrixOrder order)
1507 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1510 return InvalidParameter;
1512 return GdipRotateMatrix(brush->transform, angle, order);
1515 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1521 FIXME("not implemented\n");
1523 return NotImplemented;
1526 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1527 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1532 FIXME("not implemented\n");
1534 return NotImplemented;
1537 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1538 GDIPCONST GpMatrix *matrix)
1543 FIXME("not implemented\n");
1545 return NotImplemented;
1548 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1549 REAL dx, REAL dy, GpMatrixOrder order)
1551 FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1553 return NotImplemented;
1556 /******************************************************************************
1557 * GdipTranslateTextureTransform [GDIPLUS.@]
1559 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1560 GpMatrixOrder order)
1562 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1565 return InvalidParameter;
1567 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1570 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1572 TRACE("(%p, %p)\n", brush, rect);
1575 return InvalidParameter;
1577 *rect = brush->rect;
1582 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1587 TRACE("(%p, %p)\n", brush, rect);
1590 return InvalidParameter;
1592 ret = GdipGetLineRect(brush, &rectF);
1595 rect->X = roundr(rectF.X);
1596 rect->Y = roundr(rectF.Y);
1597 rect->Width = roundr(rectF.Width);
1598 rect->Height = roundr(rectF.Height);
1604 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1605 REAL angle, GpMatrixOrder order)
1610 return InvalidParameter;
1613 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1615 return NotImplemented;