ole32/tests: Tests that show the consumer data object isn't a singleton.
[wine/hacks.git] / dlls / gdiplus / brush.c
blobf0c9b20681199cda996b49fc5406faee6f9f6dad
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winuser.h"
24 #include "wingdi.h"
26 #define COBJMACROS
27 #include "objbase.h"
28 #include "olectl.h"
29 #include "ole2.h"
31 #include "gdiplus.h"
32 #include "gdiplus_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
37 /******************************************************************************
38 * GdipCloneBrush [GDIPLUS.@]
40 GpStatus WINGDIPAPI GdipCloneBrush(GpBrush *brush, GpBrush **clone)
42 TRACE("(%p, %p)\n", brush, clone);
44 if(!brush || !clone)
45 return InvalidParameter;
47 switch(brush->bt){
48 case BrushTypeSolidColor:
49 *clone = GdipAlloc(sizeof(GpSolidFill));
50 if (!*clone) return OutOfMemory;
52 memcpy(*clone, brush, sizeof(GpSolidFill));
54 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
55 break;
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);
63 break;
64 case BrushTypePathGradient:{
65 GpPathGradient *src, *dest;
66 INT count;
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);
84 GdipFree(dest);
85 return OutOfMemory;
88 memcpy(dest->pathdata.Points, src->pathdata.Points, count * sizeof(PointF));
89 memcpy(dest->pathdata.Types, src->pathdata.Types, count);
91 /* blending */
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);
102 GdipFree(dest);
103 return OutOfMemory;
106 memcpy(dest->blendfac, src->blendfac, count * sizeof(REAL));
107 memcpy(dest->blendpos, src->blendpos, count * sizeof(REAL));
109 break;
111 case BrushTypeLinearGradient:
112 *clone = GdipAlloc(sizeof(GpLineGradient));
113 if(!*clone) return OutOfMemory;
115 memcpy(*clone, brush, sizeof(GpLineGradient));
117 (*clone)->gdibrush = CreateSolidBrush((*clone)->lb.lbColor);
118 break;
119 case BrushTypeTextureFill:
120 *clone = GdipAlloc(sizeof(GpTexture));
121 if(!*clone) return OutOfMemory;
123 memcpy(*clone, brush, sizeof(GpTexture));
125 (*clone)->gdibrush = CreateBrushIndirect(&(*clone)->lb);
126 break;
127 default:
128 ERR("not implemented for brush type %d\n", brush->bt);
129 return NotImplemented;
132 return Ok;
135 static LONG HatchStyleToHatch(HatchStyle hatchstyle)
137 switch (hatchstyle)
139 case HatchStyleHorizontal: return HS_HORIZONTAL;
140 case HatchStyleVertical: return HS_VERTICAL;
141 case HatchStyleForwardDiagonal: return HS_FDIAGONAL;
142 case HatchStyleBackwardDiagonal: return HS_BDIAGONAL;
143 case HatchStyleCross: return HS_CROSS;
144 case HatchStyleDiagonalCross: return HS_DIAGCROSS;
145 default: return 0;
149 /******************************************************************************
150 * GdipCreateHatchBrush [GDIPLUS.@]
152 GpStatus WINGDIPAPI GdipCreateHatchBrush(HatchStyle hatchstyle, ARGB forecol, ARGB backcol, GpHatch **brush)
154 COLORREF fgcol = ARGB2COLORREF(forecol);
156 TRACE("(%d, %d, %d, %p)\n", hatchstyle, forecol, backcol, brush);
158 if(!brush) return InvalidParameter;
160 *brush = GdipAlloc(sizeof(GpHatch));
161 if (!*brush) return OutOfMemory;
163 switch (hatchstyle)
165 case HatchStyleHorizontal:
166 case HatchStyleVertical:
167 case HatchStyleForwardDiagonal:
168 case HatchStyleBackwardDiagonal:
169 case HatchStyleCross:
170 case HatchStyleDiagonalCross:
171 /* Brushes that map to BS_HATCHED */
172 (*brush)->brush.lb.lbStyle = BS_HATCHED;
173 (*brush)->brush.lb.lbColor = fgcol;
174 (*brush)->brush.lb.lbHatch = HatchStyleToHatch(hatchstyle);
175 break;
177 default:
178 FIXME("Unimplemented hatch style %d\n", hatchstyle);
180 (*brush)->brush.lb.lbStyle = BS_SOLID;
181 (*brush)->brush.lb.lbColor = fgcol;
182 (*brush)->brush.lb.lbHatch = 0;
183 break;
187 (*brush)->brush.gdibrush = CreateBrushIndirect(&(*brush)->brush.lb);
188 (*brush)->brush.bt = BrushTypeHatchFill;
189 (*brush)->forecol = forecol;
190 (*brush)->backcol = backcol;
191 (*brush)->hatchstyle = hatchstyle;
193 return Ok;
196 /******************************************************************************
197 * GdipCreateLineBrush [GDIPLUS.@]
199 GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* startpoint,
200 GDIPCONST GpPointF* endpoint, ARGB startcolor, ARGB endcolor,
201 GpWrapMode wrap, GpLineGradient **line)
203 COLORREF col = ARGB2COLORREF(startcolor);
205 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
206 startcolor, endcolor, wrap, line);
208 if(!line || !startpoint || !endpoint || wrap == WrapModeClamp)
209 return InvalidParameter;
211 *line = GdipAlloc(sizeof(GpLineGradient));
212 if(!*line) return OutOfMemory;
214 (*line)->brush.lb.lbStyle = BS_SOLID;
215 (*line)->brush.lb.lbColor = col;
216 (*line)->brush.lb.lbHatch = 0;
217 (*line)->brush.gdibrush = CreateSolidBrush(col);
218 (*line)->brush.bt = BrushTypeLinearGradient;
220 (*line)->startpoint.X = startpoint->X;
221 (*line)->startpoint.Y = startpoint->Y;
222 (*line)->endpoint.X = endpoint->X;
223 (*line)->endpoint.Y = endpoint->Y;
224 (*line)->startcolor = startcolor;
225 (*line)->endcolor = endcolor;
226 (*line)->wrap = wrap;
227 (*line)->gamma = FALSE;
229 return Ok;
232 GpStatus WINGDIPAPI GdipCreateLineBrushI(GDIPCONST GpPoint* startpoint,
233 GDIPCONST GpPoint* endpoint, ARGB startcolor, ARGB endcolor,
234 GpWrapMode wrap, GpLineGradient **line)
236 GpPointF stF;
237 GpPointF endF;
239 TRACE("(%p, %p, %x, %x, %d, %p)\n", startpoint, endpoint,
240 startcolor, endcolor, wrap, line);
242 if(!startpoint || !endpoint)
243 return InvalidParameter;
245 stF.X = (REAL)startpoint->X;
246 stF.Y = (REAL)startpoint->Y;
247 endF.X = (REAL)endpoint->X;
248 endF.X = (REAL)endpoint->Y;
250 return GdipCreateLineBrush(&stF, &endF, startcolor, endcolor, wrap, line);
253 GpStatus WINGDIPAPI GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect,
254 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
255 GpLineGradient **line)
257 GpPointF start, end;
259 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
260 wrap, line);
262 if(!line || !rect)
263 return InvalidParameter;
265 start.X = rect->X;
266 start.Y = rect->Y;
267 end.X = rect->X + rect->Width;
268 end.Y = rect->Y + rect->Height;
270 return GdipCreateLineBrush(&start, &end, startcolor, endcolor, wrap, line);
273 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectI(GDIPCONST GpRect* rect,
274 ARGB startcolor, ARGB endcolor, LinearGradientMode mode, GpWrapMode wrap,
275 GpLineGradient **line)
277 GpRectF rectF;
279 TRACE("(%p, %x, %x, %d, %d, %p)\n", rect, startcolor, endcolor, mode,
280 wrap, line);
282 rectF.X = (REAL) rect->X;
283 rectF.Y = (REAL) rect->Y;
284 rectF.Width = (REAL) rect->Width;
285 rectF.Height = (REAL) rect->Height;
287 return GdipCreateLineBrushFromRect(&rectF, startcolor, endcolor, mode, wrap, line);
290 /******************************************************************************
291 * GdipCreateLineBrushFromRectWithAngle [GDIPLUS.@]
293 * FIXME: angle value completely ignored. Don't know how to use it since native
294 * always set Brush rectangle to rect (independetly of this angle).
295 * Maybe it's used only on drawing.
297 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngle(GDIPCONST GpRectF* rect,
298 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
299 GpLineGradient **line)
301 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
302 wrap, line);
304 return GdipCreateLineBrushFromRect(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
305 wrap, line);
308 GpStatus WINGDIPAPI GdipCreateLineBrushFromRectWithAngleI(GDIPCONST GpRect* rect,
309 ARGB startcolor, ARGB endcolor, REAL angle, BOOL isAngleScalable, GpWrapMode wrap,
310 GpLineGradient **line)
312 TRACE("(%p, %x, %x, %.2f, %d, %d, %p)\n", rect, startcolor, endcolor, angle, isAngleScalable,
313 wrap, line);
315 return GdipCreateLineBrushFromRectI(rect, startcolor, endcolor, LinearGradientModeForwardDiagonal,
316 wrap, line);
319 GpStatus WINGDIPAPI GdipCreatePathGradient(GDIPCONST GpPointF* points,
320 INT count, GpWrapMode wrap, GpPathGradient **grad)
322 COLORREF col = ARGB2COLORREF(0xffffffff);
324 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
326 if(!points || !grad)
327 return InvalidParameter;
329 if(count <= 0)
330 return OutOfMemory;
332 *grad = GdipAlloc(sizeof(GpPathGradient));
333 if (!*grad) return OutOfMemory;
335 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
336 if(!(*grad)->blendfac){
337 GdipFree(*grad);
338 return OutOfMemory;
340 (*grad)->blendfac[0] = 1.0;
341 (*grad)->blendpos = NULL;
342 (*grad)->blendcount = 1;
344 (*grad)->pathdata.Count = count;
345 (*grad)->pathdata.Points = GdipAlloc(count * sizeof(PointF));
346 (*grad)->pathdata.Types = GdipAlloc(count);
348 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
349 GdipFree((*grad)->pathdata.Points);
350 GdipFree((*grad)->pathdata.Types);
351 GdipFree(*grad);
352 return OutOfMemory;
355 memcpy((*grad)->pathdata.Points, points, count * sizeof(PointF));
356 memset((*grad)->pathdata.Types, PathPointTypeLine, count);
358 (*grad)->brush.lb.lbStyle = BS_SOLID;
359 (*grad)->brush.lb.lbColor = col;
360 (*grad)->brush.lb.lbHatch = 0;
362 (*grad)->brush.gdibrush = CreateSolidBrush(col);
363 (*grad)->brush.bt = BrushTypePathGradient;
364 (*grad)->centercolor = 0xffffffff;
365 (*grad)->wrap = wrap;
366 (*grad)->gamma = FALSE;
367 (*grad)->center.X = 0.0;
368 (*grad)->center.Y = 0.0;
369 (*grad)->focus.X = 0.0;
370 (*grad)->focus.Y = 0.0;
372 return Ok;
375 GpStatus WINGDIPAPI GdipCreatePathGradientI(GDIPCONST GpPoint* points,
376 INT count, GpWrapMode wrap, GpPathGradient **grad)
378 GpPointF *pointsF;
379 GpStatus ret;
380 INT i;
382 TRACE("(%p, %d, %d, %p)\n", points, count, wrap, grad);
384 if(!points || !grad)
385 return InvalidParameter;
387 if(count <= 0)
388 return OutOfMemory;
390 pointsF = GdipAlloc(sizeof(GpPointF) * count);
391 if(!pointsF)
392 return OutOfMemory;
394 for(i = 0; i < count; i++){
395 pointsF[i].X = (REAL)points[i].X;
396 pointsF[i].Y = (REAL)points[i].Y;
399 ret = GdipCreatePathGradient(pointsF, count, wrap, grad);
400 GdipFree(pointsF);
402 return ret;
405 /******************************************************************************
406 * GdipCreatePathGradientFromPath [GDIPLUS.@]
408 * FIXME: path gradient brushes not truly supported (drawn as solid brushes)
410 GpStatus WINGDIPAPI GdipCreatePathGradientFromPath(GDIPCONST GpPath* path,
411 GpPathGradient **grad)
413 COLORREF col = ARGB2COLORREF(0xffffffff);
415 TRACE("(%p, %p)\n", path, grad);
417 if(!path || !grad)
418 return InvalidParameter;
420 *grad = GdipAlloc(sizeof(GpPathGradient));
421 if (!*grad) return OutOfMemory;
423 (*grad)->blendfac = GdipAlloc(sizeof(REAL));
424 if(!(*grad)->blendfac){
425 GdipFree(*grad);
426 return OutOfMemory;
428 (*grad)->blendfac[0] = 1.0;
429 (*grad)->blendpos = NULL;
430 (*grad)->blendcount = 1;
432 (*grad)->pathdata.Count = path->pathdata.Count;
433 (*grad)->pathdata.Points = GdipAlloc(path->pathdata.Count * sizeof(PointF));
434 (*grad)->pathdata.Types = GdipAlloc(path->pathdata.Count);
436 if(!(*grad)->pathdata.Points || !(*grad)->pathdata.Types){
437 GdipFree((*grad)->pathdata.Points);
438 GdipFree((*grad)->pathdata.Types);
439 GdipFree(*grad);
440 return OutOfMemory;
443 memcpy((*grad)->pathdata.Points, path->pathdata.Points,
444 path->pathdata.Count * sizeof(PointF));
445 memcpy((*grad)->pathdata.Types, path->pathdata.Types, path->pathdata.Count);
447 (*grad)->brush.lb.lbStyle = BS_SOLID;
448 (*grad)->brush.lb.lbColor = col;
449 (*grad)->brush.lb.lbHatch = 0;
451 (*grad)->brush.gdibrush = CreateSolidBrush(col);
452 (*grad)->brush.bt = BrushTypePathGradient;
453 (*grad)->centercolor = 0xffffffff;
454 (*grad)->wrap = WrapModeClamp;
455 (*grad)->gamma = FALSE;
456 /* FIXME: this should be set to the "centroid" of the path by default */
457 (*grad)->center.X = 0.0;
458 (*grad)->center.Y = 0.0;
459 (*grad)->focus.X = 0.0;
460 (*grad)->focus.Y = 0.0;
462 return Ok;
465 /******************************************************************************
466 * GdipCreateSolidFill [GDIPLUS.@]
468 GpStatus WINGDIPAPI GdipCreateSolidFill(ARGB color, GpSolidFill **sf)
470 COLORREF col = ARGB2COLORREF(color);
472 TRACE("(%x, %p)\n", color, sf);
474 if(!sf) return InvalidParameter;
476 *sf = GdipAlloc(sizeof(GpSolidFill));
477 if (!*sf) return OutOfMemory;
479 (*sf)->brush.lb.lbStyle = BS_SOLID;
480 (*sf)->brush.lb.lbColor = col;
481 (*sf)->brush.lb.lbHatch = 0;
483 (*sf)->brush.gdibrush = CreateSolidBrush(col);
484 (*sf)->brush.bt = BrushTypeSolidColor;
485 (*sf)->color = color;
487 return Ok;
490 /******************************************************************************
491 * GdipCreateTexture [GDIPLUS.@]
493 * PARAMS
494 * image [I] image to use
495 * wrapmode [I] optional
496 * texture [O] pointer to the resulting texturebrush
498 * RETURNS
499 * SUCCESS: Ok
500 * FAILURE: element of GpStatus
502 GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode,
503 GpTexture **texture)
505 UINT width, height;
506 GpImageAttributes attributes;
507 GpStatus stat;
509 TRACE("%p, %d %p\n", image, wrapmode, texture);
511 if (!(image && texture))
512 return InvalidParameter;
514 stat = GdipGetImageWidth(image, &width);
515 if (stat != Ok) return stat;
516 stat = GdipGetImageHeight(image, &height);
517 if (stat != Ok) return stat;
518 attributes.wrap = wrapmode;
520 return GdipCreateTextureIA(image, &attributes, 0, 0, width, height,
521 texture);
524 /******************************************************************************
525 * GdipCreateTexture2 [GDIPLUS.@]
527 GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode,
528 REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
530 GpImageAttributes attributes;
532 TRACE("%p %d %f %f %f %f %p\n", image, wrapmode,
533 x, y, width, height, texture);
535 attributes.wrap = wrapmode;
536 return GdipCreateTextureIA(image, &attributes, x, y, width, height,
537 texture);
540 /******************************************************************************
541 * GdipCreateTextureIA [GDIPLUS.@]
543 * FIXME: imageattr ignored
545 GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image,
546 GDIPCONST GpImageAttributes *imageattr, REAL x, REAL y, REAL width,
547 REAL height, GpTexture **texture)
549 HDC hdc;
550 HBITMAP hbm, old = NULL;
551 BITMAPINFO *pbmi;
552 BITMAPINFOHEADER *bmih;
553 INT n_x, n_y, n_width, n_height, abs_height, stride, image_stride, i, bytespp;
554 BOOL bm_is_selected;
555 BYTE *dibits, *buff, *textbits;
556 GpStatus status;
558 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %p)\n", image, imageattr, x, y, width, height,
559 texture);
561 if(!image || !texture || x < 0.0 || y < 0.0 || width < 0.0 || height < 0.0)
562 return InvalidParameter;
564 if(image->type != ImageTypeBitmap){
565 FIXME("not implemented for image type %d\n", image->type);
566 return NotImplemented;
569 n_x = roundr(x);
570 n_y = roundr(y);
571 n_width = roundr(width);
572 n_height = roundr(height);
574 if(n_x + n_width > ((GpBitmap*)image)->width ||
575 n_y + n_height > ((GpBitmap*)image)->height)
576 return InvalidParameter;
578 IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbm);
579 if(!hbm) return GenericError;
580 IPicture_get_CurDC(image->picture, &hdc);
581 bm_is_selected = (hdc != 0);
583 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
584 if (!pbmi)
585 return OutOfMemory;
586 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
587 pbmi->bmiHeader.biBitCount = 0;
589 if(!bm_is_selected){
590 hdc = CreateCompatibleDC(0);
591 old = SelectObject(hdc, hbm);
594 /* fill out bmi */
595 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
597 bytespp = pbmi->bmiHeader.biBitCount / 8;
598 abs_height = abs(pbmi->bmiHeader.biHeight);
600 if(n_x > pbmi->bmiHeader.biWidth || n_x + n_width > pbmi->bmiHeader.biWidth ||
601 n_y > abs_height || n_y + n_height > abs_height){
602 GdipFree(pbmi);
603 return InvalidParameter;
606 dibits = GdipAlloc(pbmi->bmiHeader.biSizeImage);
608 if(dibits) /* this is not a good place to error out */
609 GetDIBits(hdc, hbm, 0, abs_height, dibits, pbmi, DIB_RGB_COLORS);
611 if(!bm_is_selected){
612 SelectObject(hdc, old);
613 DeleteDC(hdc);
616 if(!dibits){
617 GdipFree(pbmi);
618 return OutOfMemory;
621 image_stride = (pbmi->bmiHeader.biWidth * bytespp + 3) & ~3;
622 stride = (n_width * bytespp + 3) & ~3;
623 buff = GdipAlloc(sizeof(BITMAPINFOHEADER) + stride * n_height);
624 if(!buff){
625 GdipFree(pbmi);
626 GdipFree(dibits);
627 return OutOfMemory;
630 bmih = (BITMAPINFOHEADER*)buff;
631 textbits = (BYTE*) (bmih + 1);
632 bmih->biSize = sizeof(BITMAPINFOHEADER);
633 bmih->biWidth = n_width;
634 bmih->biHeight = n_height;
635 bmih->biCompression = BI_RGB;
636 bmih->biSizeImage = stride * n_height;
637 bmih->biBitCount = pbmi->bmiHeader.biBitCount;
638 bmih->biClrUsed = 0;
639 bmih->biPlanes = 1;
641 /* image is flipped */
642 if(pbmi->bmiHeader.biHeight > 0){
643 dibits += pbmi->bmiHeader.biSizeImage;
644 image_stride *= -1;
645 textbits += stride * (n_height - 1);
646 stride *= -1;
649 GdipFree(pbmi);
651 for(i = 0; i < n_height; i++)
652 memcpy(&textbits[i * stride],
653 &dibits[n_x * bytespp + (n_y + i) * image_stride],
654 abs(stride));
656 *texture = GdipAlloc(sizeof(GpTexture));
657 if (!*texture){
658 GdipFree(dibits);
659 GdipFree(buff);
660 return OutOfMemory;
663 if((status = GdipCreateMatrix(&(*texture)->transform)) != Ok){
664 GdipFree(*texture);
665 GdipFree(dibits);
666 GdipFree(buff);
667 return status;
670 (*texture)->brush.lb.lbStyle = BS_DIBPATTERNPT;
671 (*texture)->brush.lb.lbColor = DIB_RGB_COLORS;
672 (*texture)->brush.lb.lbHatch = (ULONG_PTR)buff;
674 (*texture)->brush.gdibrush = CreateBrushIndirect(&(*texture)->brush.lb);
675 (*texture)->brush.bt = BrushTypeTextureFill;
676 (*texture)->wrap = imageattr->wrap;
678 GdipFree(dibits);
679 GdipFree(buff);
681 return Ok;
684 /******************************************************************************
685 * GdipCreateTextureIAI [GDIPLUS.@]
687 GpStatus WINGDIPAPI GdipCreateTextureIAI(GpImage *image, GDIPCONST GpImageAttributes *imageattr,
688 INT x, INT y, INT width, INT height, GpTexture **texture)
690 TRACE("(%p, %p, %d, %d, %d, %d, %p)\n", image, imageattr, x, y, width, height,
691 texture);
693 return GdipCreateTextureIA(image,imageattr,(REAL)x,(REAL)y,(REAL)width,(REAL)height,texture);
696 GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode,
697 INT x, INT y, INT width, INT height, GpTexture **texture)
699 GpImageAttributes imageattr;
701 TRACE("%p %d %d %d %d %d %p\n", image, wrapmode, x, y, width, height,
702 texture);
704 imageattr.wrap = wrapmode;
706 return GdipCreateTextureIA(image, &imageattr, x, y, width, height, texture);
709 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush *brush, GpBrushType *type)
711 TRACE("(%p, %p)\n", brush, type);
713 if(!brush || !type) return InvalidParameter;
715 *type = brush->bt;
717 return Ok;
720 GpStatus WINGDIPAPI GdipGetHatchBackgroundColor(GpHatch *brush, ARGB *backcol)
722 TRACE("(%p, %p)\n", brush, backcol);
724 if(!brush || !backcol) return InvalidParameter;
726 *backcol = brush->backcol;
728 return Ok;
731 GpStatus WINGDIPAPI GdipGetHatchForegroundColor(GpHatch *brush, ARGB *forecol)
733 TRACE("(%p, %p)\n", brush, forecol);
735 if(!brush || !forecol) return InvalidParameter;
737 *forecol = brush->forecol;
739 return Ok;
742 GpStatus WINGDIPAPI GdipGetHatchStyle(GpHatch *brush, HatchStyle *hatchstyle)
744 TRACE("(%p, %p)\n", brush, hatchstyle);
746 if(!brush || !hatchstyle) return InvalidParameter;
748 *hatchstyle = brush->hatchstyle;
750 return Ok;
753 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush *brush)
755 TRACE("(%p)\n", brush);
757 if(!brush) return InvalidParameter;
759 switch(brush->bt)
761 case BrushTypePathGradient:
762 GdipFree(((GpPathGradient*) brush)->pathdata.Points);
763 GdipFree(((GpPathGradient*) brush)->pathdata.Types);
764 GdipFree(((GpPathGradient*) brush)->blendfac);
765 GdipFree(((GpPathGradient*) brush)->blendpos);
766 break;
767 case BrushTypeSolidColor:
768 case BrushTypeLinearGradient:
769 break;
770 case BrushTypeTextureFill:
771 GdipDeleteMatrix(((GpTexture*)brush)->transform);
772 break;
773 default:
774 break;
777 DeleteObject(brush->gdibrush);
778 GdipFree(brush);
780 return Ok;
783 GpStatus WINGDIPAPI GdipGetLineGammaCorrection(GpLineGradient *line,
784 BOOL *usinggamma)
786 TRACE("(%p, %p)\n", line, usinggamma);
788 if(!line || !usinggamma)
789 return InvalidParameter;
791 *usinggamma = line->gamma;
793 return Ok;
796 GpStatus WINGDIPAPI GdipGetLineWrapMode(GpLineGradient *brush, GpWrapMode *wrapmode)
798 TRACE("(%p, %p)\n", brush, wrapmode);
800 if(!brush || !wrapmode)
801 return InvalidParameter;
803 *wrapmode = brush->wrap;
805 return Ok;
808 GpStatus WINGDIPAPI GdipGetPathGradientBlend(GpPathGradient *brush, REAL *blend,
809 REAL *positions, INT count)
811 TRACE("(%p, %p, %p, %d)\n", brush, blend, positions, count);
813 if(!brush || !blend || !positions || count <= 0)
814 return InvalidParameter;
816 if(count < brush->blendcount)
817 return InsufficientBuffer;
819 memcpy(blend, brush->blendfac, count*sizeof(REAL));
820 if(brush->blendcount > 1){
821 memcpy(positions, brush->blendpos, count*sizeof(REAL));
824 return Ok;
827 GpStatus WINGDIPAPI GdipGetPathGradientBlendCount(GpPathGradient *brush, INT *count)
829 TRACE("(%p, %p)\n", brush, count);
831 if(!brush || !count)
832 return InvalidParameter;
834 *count = brush->blendcount;
836 return Ok;
839 GpStatus WINGDIPAPI GdipGetPathGradientCenterPoint(GpPathGradient *grad,
840 GpPointF *point)
842 TRACE("(%p, %p)\n", grad, point);
844 if(!grad || !point)
845 return InvalidParameter;
847 point->X = grad->center.X;
848 point->Y = grad->center.Y;
850 return Ok;
853 GpStatus WINGDIPAPI GdipGetPathGradientCenterPointI(GpPathGradient *grad,
854 GpPoint *point)
856 GpStatus ret;
857 GpPointF ptf;
859 TRACE("(%p, %p)\n", grad, point);
861 if(!point)
862 return InvalidParameter;
864 ret = GdipGetPathGradientCenterPoint(grad,&ptf);
866 if(ret == Ok){
867 point->X = roundr(ptf.X);
868 point->Y = roundr(ptf.Y);
871 return ret;
874 GpStatus WINGDIPAPI GdipGetPathGradientFocusScales(GpPathGradient *grad,
875 REAL *x, REAL *y)
877 TRACE("(%p, %p, %p)\n", grad, x, y);
879 if(!grad || !x || !y)
880 return InvalidParameter;
882 *x = grad->focus.X;
883 *y = grad->focus.Y;
885 return Ok;
888 GpStatus WINGDIPAPI GdipGetPathGradientGammaCorrection(GpPathGradient *grad,
889 BOOL *gamma)
891 TRACE("(%p, %p)\n", grad, gamma);
893 if(!grad || !gamma)
894 return InvalidParameter;
896 *gamma = grad->gamma;
898 return Ok;
901 GpStatus WINGDIPAPI GdipGetPathGradientPointCount(GpPathGradient *grad,
902 INT *count)
904 TRACE("(%p, %p)\n", grad, count);
906 if(!grad || !count)
907 return InvalidParameter;
909 *count = grad->pathdata.Count;
911 return Ok;
914 GpStatus WINGDIPAPI GdipGetPathGradientRect(GpPathGradient *brush, GpRectF *rect)
916 GpRectF r;
917 GpPath* path;
918 GpStatus stat;
920 TRACE("(%p, %p)\n", brush, rect);
922 if(!brush || !rect)
923 return InvalidParameter;
925 stat = GdipCreatePath2(brush->pathdata.Points, brush->pathdata.Types,
926 brush->pathdata.Count, FillModeAlternate, &path);
927 if(stat != Ok) return stat;
929 stat = GdipGetPathWorldBounds(path, &r, NULL, NULL);
930 if(stat != Ok){
931 GdipDeletePath(path);
932 return stat;
935 memcpy(rect, &r, sizeof(GpRectF));
937 GdipDeletePath(path);
939 return Ok;
942 GpStatus WINGDIPAPI GdipGetPathGradientRectI(GpPathGradient *brush, GpRect *rect)
944 GpRectF rectf;
945 GpStatus stat;
947 TRACE("(%p, %p)\n", brush, rect);
949 if(!brush || !rect)
950 return InvalidParameter;
952 stat = GdipGetPathGradientRect(brush, &rectf);
953 if(stat != Ok) return stat;
955 rect->X = roundr(rectf.X);
956 rect->Y = roundr(rectf.Y);
957 rect->Width = roundr(rectf.Width);
958 rect->Height = roundr(rectf.Height);
960 return Ok;
963 GpStatus WINGDIPAPI GdipGetPathGradientSurroundColorsWithCount(GpPathGradient
964 *grad, ARGB *argb, INT *count)
966 static int calls;
968 if(!grad || !argb || !count || (*count < grad->pathdata.Count))
969 return InvalidParameter;
971 if(!(calls++))
972 FIXME("not implemented\n");
974 return NotImplemented;
977 GpStatus WINGDIPAPI GdipGetPathGradientWrapMode(GpPathGradient *brush,
978 GpWrapMode *wrapmode)
980 TRACE("(%p, %p)\n", brush, wrapmode);
982 if(!brush || !wrapmode)
983 return InvalidParameter;
985 *wrapmode = brush->wrap;
987 return Ok;
990 GpStatus WINGDIPAPI GdipGetSolidFillColor(GpSolidFill *sf, ARGB *argb)
992 TRACE("(%p, %p)\n", sf, argb);
994 if(!sf || !argb)
995 return InvalidParameter;
997 *argb = sf->color;
999 return Ok;
1002 /******************************************************************************
1003 * GdipGetTextureTransform [GDIPLUS.@]
1005 GpStatus WINGDIPAPI GdipGetTextureTransform(GpTexture *brush, GpMatrix *matrix)
1007 TRACE("(%p, %p)\n", brush, matrix);
1009 if(!brush || !matrix)
1010 return InvalidParameter;
1012 memcpy(matrix, brush->transform, sizeof(GpMatrix));
1014 return Ok;
1017 /******************************************************************************
1018 * GdipGetTextureWrapMode [GDIPLUS.@]
1020 GpStatus WINGDIPAPI GdipGetTextureWrapMode(GpTexture *brush, GpWrapMode *wrapmode)
1022 TRACE("(%p, %p)\n", brush, wrapmode);
1024 if(!brush || !wrapmode)
1025 return InvalidParameter;
1027 *wrapmode = brush->wrap;
1029 return Ok;
1032 /******************************************************************************
1033 * GdipMultiplyTextureTransform [GDIPLUS.@]
1035 GpStatus WINGDIPAPI GdipMultiplyTextureTransform(GpTexture* brush,
1036 GDIPCONST GpMatrix *matrix, GpMatrixOrder order)
1038 TRACE("(%p, %p, %d)\n", brush, matrix, order);
1040 if(!brush || !matrix)
1041 return InvalidParameter;
1043 return GdipMultiplyMatrix(brush->transform, matrix, order);
1046 /******************************************************************************
1047 * GdipResetTextureTransform [GDIPLUS.@]
1049 GpStatus WINGDIPAPI GdipResetTextureTransform(GpTexture* brush)
1051 TRACE("(%p)\n", brush);
1053 if(!brush)
1054 return InvalidParameter;
1056 return GdipSetMatrixElements(brush->transform, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
1059 /******************************************************************************
1060 * GdipScaleTextureTransform [GDIPLUS.@]
1062 GpStatus WINGDIPAPI GdipScaleTextureTransform(GpTexture* brush,
1063 REAL sx, REAL sy, GpMatrixOrder order)
1065 TRACE("(%p, %.2f, %.2f, %d)\n", brush, sx, sy, order);
1067 if(!brush)
1068 return InvalidParameter;
1070 return GdipScaleMatrix(brush->transform, sx, sy, order);
1073 GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush,
1074 GDIPCONST REAL *blend, GDIPCONST REAL* positions, INT count)
1076 static int calls;
1078 if(!brush || !blend || !positions || count <= 0)
1079 return InvalidParameter;
1081 if(!(calls++))
1082 FIXME("not implemented\n");
1084 return Ok;
1087 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *line,
1088 BOOL usegamma)
1090 TRACE("(%p, %d)\n", line, usegamma);
1092 if(!line)
1093 return InvalidParameter;
1095 line->gamma = usegamma;
1097 return Ok;
1100 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient *line, REAL focus,
1101 REAL scale)
1103 static int calls;
1105 if(!line || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1106 return InvalidParameter;
1108 if(!(calls++))
1109 FIXME("not implemented\n");
1111 return NotImplemented;
1114 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient *line,
1115 GpWrapMode wrap)
1117 TRACE("(%p, %d)\n", line, wrap);
1119 if(!line || wrap == WrapModeClamp)
1120 return InvalidParameter;
1122 line->wrap = wrap;
1124 return Ok;
1127 GpStatus WINGDIPAPI GdipSetPathGradientBlend(GpPathGradient *brush, GDIPCONST REAL *blend,
1128 GDIPCONST REAL *pos, INT count)
1130 static int calls;
1132 if(!(calls++))
1133 FIXME("not implemented\n");
1135 return NotImplemented;
1138 GpStatus WINGDIPAPI GdipSetPathGradientCenterColor(GpPathGradient *grad,
1139 ARGB argb)
1141 TRACE("(%p, %x)\n", grad, argb);
1143 if(!grad)
1144 return InvalidParameter;
1146 grad->centercolor = argb;
1147 grad->brush.lb.lbColor = ARGB2COLORREF(argb);
1149 DeleteObject(grad->brush.gdibrush);
1150 grad->brush.gdibrush = CreateSolidBrush(grad->brush.lb.lbColor);
1152 return Ok;
1155 GpStatus WINGDIPAPI GdipSetPathGradientCenterPoint(GpPathGradient *grad,
1156 GpPointF *point)
1158 TRACE("(%p, %p)\n", grad, point);
1160 if(!grad || !point)
1161 return InvalidParameter;
1163 grad->center.X = point->X;
1164 grad->center.Y = point->Y;
1166 return Ok;
1169 GpStatus WINGDIPAPI GdipSetPathGradientCenterPointI(GpPathGradient *grad,
1170 GpPoint *point)
1172 GpPointF ptf;
1174 TRACE("(%p, %p)\n", grad, point);
1176 if(!point)
1177 return InvalidParameter;
1179 ptf.X = (REAL)point->X;
1180 ptf.Y = (REAL)point->Y;
1182 return GdipSetPathGradientCenterPoint(grad,&ptf);
1185 GpStatus WINGDIPAPI GdipSetPathGradientFocusScales(GpPathGradient *grad,
1186 REAL x, REAL y)
1188 TRACE("(%p, %.2f, %.2f)\n", grad, x, y);
1190 if(!grad)
1191 return InvalidParameter;
1193 grad->focus.X = x;
1194 grad->focus.Y = y;
1196 return Ok;
1199 GpStatus WINGDIPAPI GdipSetPathGradientGammaCorrection(GpPathGradient *grad,
1200 BOOL gamma)
1202 TRACE("(%p, %d)\n", grad, gamma);
1204 if(!grad)
1205 return InvalidParameter;
1207 grad->gamma = gamma;
1209 return Ok;
1212 GpStatus WINGDIPAPI GdipSetPathGradientSigmaBlend(GpPathGradient *grad,
1213 REAL focus, REAL scale)
1215 static int calls;
1217 if(!grad || focus < 0.0 || focus > 1.0 || scale < 0.0 || scale > 1.0)
1218 return InvalidParameter;
1220 if(!(calls++))
1221 FIXME("not implemented\n");
1223 return NotImplemented;
1226 GpStatus WINGDIPAPI GdipSetPathGradientSurroundColorsWithCount(GpPathGradient
1227 *grad, ARGB *argb, INT *count)
1229 static int calls;
1231 if(!grad || !argb || !count || (*count <= 0) ||
1232 (*count > grad->pathdata.Count))
1233 return InvalidParameter;
1235 if(!(calls++))
1236 FIXME("not implemented\n");
1238 return NotImplemented;
1241 GpStatus WINGDIPAPI GdipSetPathGradientWrapMode(GpPathGradient *grad,
1242 GpWrapMode wrap)
1244 TRACE("(%p, %d)\n", grad, wrap);
1246 if(!grad)
1247 return InvalidParameter;
1249 grad->wrap = wrap;
1251 return Ok;
1254 GpStatus WINGDIPAPI GdipSetSolidFillColor(GpSolidFill *sf, ARGB argb)
1256 TRACE("(%p, %x)\n", sf, argb);
1258 if(!sf)
1259 return InvalidParameter;
1261 sf->color = argb;
1262 sf->brush.lb.lbColor = ARGB2COLORREF(argb);
1264 DeleteObject(sf->brush.gdibrush);
1265 sf->brush.gdibrush = CreateSolidBrush(sf->brush.lb.lbColor);
1267 return Ok;
1270 /******************************************************************************
1271 * GdipSetTextureTransform [GDIPLUS.@]
1273 GpStatus WINGDIPAPI GdipSetTextureTransform(GpTexture *texture,
1274 GDIPCONST GpMatrix *matrix)
1276 TRACE("(%p, %p)\n", texture, matrix);
1278 if(!texture || !matrix)
1279 return InvalidParameter;
1281 memcpy(texture->transform, matrix, sizeof(GpMatrix));
1283 return Ok;
1286 /******************************************************************************
1287 * GdipSetTextureWrapMode [GDIPLUS.@]
1289 * WrapMode not used, only stored
1291 GpStatus WINGDIPAPI GdipSetTextureWrapMode(GpTexture *brush, GpWrapMode wrapmode)
1293 TRACE("(%p, %d)\n", brush, wrapmode);
1295 if(!brush)
1296 return InvalidParameter;
1298 brush->wrap = wrapmode;
1300 return Ok;
1303 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient *brush, ARGB color1,
1304 ARGB color2)
1306 TRACE("(%p, %x, %x)\n", brush, color1, color2);
1308 if(!brush)
1309 return InvalidParameter;
1311 brush->startcolor = color1;
1312 brush->endcolor = color2;
1314 return Ok;
1317 GpStatus WINGDIPAPI GdipGetLineColors(GpLineGradient *brush, ARGB *colors)
1319 TRACE("(%p, %p)\n", brush, colors);
1321 if(!brush || !colors)
1322 return InvalidParameter;
1324 colors[0] = brush->startcolor;
1325 colors[1] = brush->endcolor;
1327 return Ok;
1330 /******************************************************************************
1331 * GdipRotateTextureTransform [GDIPLUS.@]
1333 GpStatus WINGDIPAPI GdipRotateTextureTransform(GpTexture* brush, REAL angle,
1334 GpMatrixOrder order)
1336 TRACE("(%p, %.2f, %d)\n", brush, angle, order);
1338 if(!brush)
1339 return InvalidParameter;
1341 return GdipRotateMatrix(brush->transform, angle, order);
1344 GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient *brush, REAL focus,
1345 REAL scale)
1347 static int calls;
1349 if(!(calls++))
1350 FIXME("not implemented\n");
1352 return NotImplemented;
1355 GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient *brush,
1356 GDIPCONST ARGB *blend, GDIPCONST REAL* positions, INT count)
1358 static int calls;
1360 if(!(calls++))
1361 FIXME("not implemented\n");
1363 return NotImplemented;
1366 GpStatus WINGDIPAPI GdipSetLineTransform(GpLineGradient *brush,
1367 GDIPCONST GpMatrix *matrix)
1369 static int calls;
1371 if(!(calls++))
1372 FIXME("not implemented\n");
1374 return NotImplemented;
1377 GpStatus WINGDIPAPI GdipTranslateLineTransform(GpLineGradient* brush,
1378 REAL dx, REAL dy, GpMatrixOrder order)
1380 FIXME("stub: %p %f %f %d\n", brush, dx, dy, order);
1382 return NotImplemented;
1385 /******************************************************************************
1386 * GdipTranslateTextureTransform [GDIPLUS.@]
1388 GpStatus WINGDIPAPI GdipTranslateTextureTransform(GpTexture* brush, REAL dx, REAL dy,
1389 GpMatrixOrder order)
1391 TRACE("(%p, %.2f, %.2f, %d)\n", brush, dx, dy, order);
1393 if(!brush)
1394 return InvalidParameter;
1396 return GdipTranslateMatrix(brush->transform, dx, dy, order);
1399 GpStatus WINGDIPAPI GdipGetLineRect(GpLineGradient *brush, GpRectF *rect)
1401 TRACE("(%p, %p)\n", brush, rect);
1403 if(!brush || !rect)
1404 return InvalidParameter;
1406 rect->X = (brush->startpoint.X < brush->endpoint.X ? brush->startpoint.X: brush->endpoint.X);
1407 rect->Y = (brush->startpoint.Y < brush->endpoint.Y ? brush->startpoint.Y: brush->endpoint.Y);
1409 rect->Width = fabs(brush->startpoint.X - brush->endpoint.X);
1410 rect->Height = fabs(brush->startpoint.Y - brush->endpoint.Y);
1412 return Ok;
1415 GpStatus WINGDIPAPI GdipGetLineRectI(GpLineGradient *brush, GpRect *rect)
1417 GpRectF rectF;
1418 GpStatus ret;
1420 TRACE("(%p, %p)\n", brush, rect);
1422 if(!rect)
1423 return InvalidParameter;
1425 ret = GdipGetLineRect(brush, &rectF);
1427 if(ret == Ok){
1428 rect->X = roundr(rectF.X);
1429 rect->Y = roundr(rectF.Y);
1430 rect->Width = roundr(rectF.Width);
1431 rect->Height = roundr(rectF.Height);
1434 return ret;
1437 GpStatus WINGDIPAPI GdipRotateLineTransform(GpLineGradient* brush,
1438 REAL angle, GpMatrixOrder order)
1440 static int calls;
1442 if(!brush)
1443 return InvalidParameter;
1445 if(!(calls++))
1446 FIXME("(%p, %.2f, %d) stub\n", brush, angle, order);
1448 return NotImplemented;