include/icftypes.idl: Add more typedefs.
[wine.git] / dlls / gdiplus / region.c
blob7d909d2ac4b0193758469e7588765fb6ab67f1a0
1 /*
2 * Copyright (C) 2008 Google (Lei Zhang)
3 * Copyright (C) 2013 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "wingdi.h"
26 #include "objbase.h"
28 #include "gdiplus.h"
29 #include "gdiplus_private.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
34 /**********************************************************
36 * Data returned by GdipGetRegionData looks something like this:
38 * struct region_data_header
39 * {
40 * DWORD size; size in bytes of the data - 8.
41 * DWORD magic1; probably a checksum.
42 * DWORD magic2; always seems to be 0xdbc01001 - version?
43 * DWORD num_ops; number of combining ops * 2
44 * };
46 * Then follows a sequence of combining ops and region elements.
48 * A region element is either a RECTF or some path data.
50 * Combining ops are just stored as their CombineMode value.
52 * Each RECTF is preceded by the DWORD 0x10000000. An empty rect is
53 * stored as 0x10000002 (with no following RECTF) and an infinite rect
54 * is stored as 0x10000003 (again with no following RECTF).
56 * Path data is preceded by the DWORD 0x10000001. Then follows a
57 * DWORD size and then size bytes of data.
59 * The combining ops are stored in the reverse order to the region
60 * elements and in the reverse order to which the region was
61 * constructed.
63 * When two or more complex regions (ie those with more than one
64 * element) are combined, the combining op for the two regions comes
65 * first, then the combining ops for the region elements in region 1,
66 * followed by the region elements for region 1, then follows the
67 * combining ops for region 2 and finally region 2's region elements.
68 * Presumably you're supposed to use the 0x1000000x header to find the
69 * end of the op list (the count of the elements in each region is not
70 * stored).
72 * When a simple region (1 element) is combined, it's treated as if a
73 * single rect/path is being combined.
77 #define FLAGS_NOFLAGS 0x0
78 #define FLAGS_INTPATH 0x4000
80 struct memory_buffer
82 const BYTE *buffer;
83 INT size, pos;
86 struct region_header
88 DWORD size;
89 DWORD checksum;
90 DWORD magic;
91 DWORD num_children;
94 struct path_header
96 DWORD size;
97 DWORD magic;
98 DWORD count;
99 DWORD flags;
102 /* Header size as far as header->size is concerned. This doesn't include
103 * header->size or header->checksum
105 static const INT sizeheader_size = sizeof(DWORD) * 2;
107 typedef struct packed_point
109 short X;
110 short Y;
111 } packed_point;
113 /* Test to see if the path could be stored as an array of shorts */
114 static BOOL is_integer_path(const GpPath *path)
116 int i;
118 if (!path->pathdata.Count) return FALSE;
120 for (i = 0; i < path->pathdata.Count; i++)
122 short x, y;
123 x = gdip_round(path->pathdata.Points[i].X);
124 y = gdip_round(path->pathdata.Points[i].Y);
125 if (path->pathdata.Points[i].X != (REAL)x || path->pathdata.Points[i].Y != (REAL)y)
126 return FALSE;
128 return TRUE;
131 /* Everything is measured in DWORDS; round up if there's a remainder */
132 static inline INT get_pathtypes_size(const GpPath* path)
134 INT needed = path->pathdata.Count / sizeof(DWORD);
136 if (path->pathdata.Count % sizeof(DWORD) > 0)
137 needed++;
139 return needed * sizeof(DWORD);
142 static inline INT get_element_size(const region_element* element)
144 INT needed = sizeof(DWORD); /* DWORD for the type */
145 switch(element->type)
147 case RegionDataRect:
148 return needed + sizeof(GpRect);
149 case RegionDataPath:
151 const GpPath *path = element->elementdata.path;
152 DWORD flags = is_integer_path(path) ? FLAGS_INTPATH : FLAGS_NOFLAGS;
153 /* 3 for headers, once again size doesn't count itself */
154 needed += sizeof(DWORD) * 3;
155 if (flags & FLAGS_INTPATH)
156 needed += 2 * sizeof(SHORT) * path->pathdata.Count;
157 else
158 needed += 2 * sizeof(FLOAT) * path->pathdata.Count;
160 needed += get_pathtypes_size(path);
161 needed += sizeof(DWORD); /* Extra DWORD for pathheader.size */
162 return needed;
164 case RegionDataEmptyRect:
165 case RegionDataInfiniteRect:
166 return needed;
167 default:
168 needed += get_element_size(element->elementdata.combine.left);
169 needed += get_element_size(element->elementdata.combine.right);
170 return needed;
173 return 0;
176 /* Does not check parameters, caller must do that */
177 static inline GpStatus init_region(GpRegion* region, const RegionType type)
179 region->node.type = type;
180 region->num_children = 0;
182 return Ok;
185 static inline GpStatus clone_element(const region_element* element,
186 region_element** element2)
188 GpStatus stat;
190 /* root node is allocated with GpRegion */
191 if(!*element2){
192 *element2 = heap_alloc_zero(sizeof(region_element));
193 if (!*element2)
194 return OutOfMemory;
197 (*element2)->type = element->type;
199 switch (element->type)
201 case RegionDataRect:
202 (*element2)->elementdata.rect = element->elementdata.rect;
203 return Ok;
204 case RegionDataEmptyRect:
205 case RegionDataInfiniteRect:
206 return Ok;
207 case RegionDataPath:
208 stat = GdipClonePath(element->elementdata.path, &(*element2)->elementdata.path);
209 if (stat == Ok) return Ok;
210 break;
211 default:
212 (*element2)->elementdata.combine.left = NULL;
213 (*element2)->elementdata.combine.right = NULL;
215 stat = clone_element(element->elementdata.combine.left,
216 &(*element2)->elementdata.combine.left);
217 if (stat == Ok)
219 stat = clone_element(element->elementdata.combine.right,
220 &(*element2)->elementdata.combine.right);
221 if (stat == Ok) return Ok;
223 break;
226 delete_element(*element2);
227 *element2 = NULL;
228 return stat;
231 /* Common code for CombineRegion*
232 * All the caller has to do is get its format into an element
234 static inline void fuse_region(GpRegion* region, region_element* left,
235 region_element* right, const CombineMode mode)
237 region->node.type = mode;
238 region->node.elementdata.combine.left = left;
239 region->node.elementdata.combine.right = right;
240 region->num_children += 2;
243 /*****************************************************************************
244 * GdipCloneRegion [GDIPLUS.@]
246 * Creates a deep copy of the region
248 * PARAMS
249 * region [I] source region
250 * clone [O] resulting clone
252 * RETURNS
253 * SUCCESS: Ok
254 * FAILURE: InvalidParameter or OutOfMemory
256 GpStatus WINGDIPAPI GdipCloneRegion(GpRegion *region, GpRegion **clone)
258 region_element *element;
260 TRACE("%p %p\n", region, clone);
262 if (!(region && clone))
263 return InvalidParameter;
265 *clone = heap_alloc_zero(sizeof(GpRegion));
266 if (!*clone)
267 return OutOfMemory;
268 element = &(*clone)->node;
270 (*clone)->num_children = region->num_children;
271 return clone_element(&region->node, &element);
274 /*****************************************************************************
275 * GdipCombineRegionPath [GDIPLUS.@]
277 GpStatus WINGDIPAPI GdipCombineRegionPath(GpRegion *region, GpPath *path, CombineMode mode)
279 GpRegion *path_region;
280 region_element *left, *right = NULL;
281 GpStatus stat;
283 TRACE("%p %p %d\n", region, path, mode);
285 if (!(region && path))
286 return InvalidParameter;
288 stat = GdipCreateRegionPath(path, &path_region);
289 if (stat != Ok)
290 return stat;
292 /* simply replace region data */
293 if(mode == CombineModeReplace){
294 delete_element(&region->node);
295 memcpy(region, path_region, sizeof(GpRegion));
296 heap_free(path_region);
297 return Ok;
300 left = heap_alloc_zero(sizeof(region_element));
301 if (left)
303 *left = region->node;
304 stat = clone_element(&path_region->node, &right);
305 if (stat == Ok)
307 fuse_region(region, left, right, mode);
308 GdipDeleteRegion(path_region);
309 return Ok;
312 else
313 stat = OutOfMemory;
315 heap_free(left);
316 GdipDeleteRegion(path_region);
317 return stat;
320 /*****************************************************************************
321 * GdipCombineRegionRect [GDIPLUS.@]
323 GpStatus WINGDIPAPI GdipCombineRegionRect(GpRegion *region,
324 GDIPCONST GpRectF *rect, CombineMode mode)
326 GpRegion *rect_region;
327 region_element *left, *right = NULL;
328 GpStatus stat;
330 TRACE("%p %s %d\n", region, debugstr_rectf(rect), mode);
332 if (!(region && rect))
333 return InvalidParameter;
335 stat = GdipCreateRegionRect(rect, &rect_region);
336 if (stat != Ok)
337 return stat;
339 /* simply replace region data */
340 if(mode == CombineModeReplace){
341 delete_element(&region->node);
342 memcpy(region, rect_region, sizeof(GpRegion));
343 heap_free(rect_region);
344 return Ok;
347 left = heap_alloc_zero(sizeof(region_element));
348 if (left)
350 memcpy(left, &region->node, sizeof(region_element));
351 stat = clone_element(&rect_region->node, &right);
352 if (stat == Ok)
354 fuse_region(region, left, right, mode);
355 GdipDeleteRegion(rect_region);
356 return Ok;
359 else
360 stat = OutOfMemory;
362 heap_free(left);
363 GdipDeleteRegion(rect_region);
364 return stat;
367 /*****************************************************************************
368 * GdipCombineRegionRectI [GDIPLUS.@]
370 GpStatus WINGDIPAPI GdipCombineRegionRectI(GpRegion *region,
371 GDIPCONST GpRect *rect, CombineMode mode)
373 GpRectF rectf;
375 TRACE("%p %p %d\n", region, rect, mode);
377 if (!rect)
378 return InvalidParameter;
380 rectf.X = (REAL)rect->X;
381 rectf.Y = (REAL)rect->Y;
382 rectf.Height = (REAL)rect->Height;
383 rectf.Width = (REAL)rect->Width;
385 return GdipCombineRegionRect(region, &rectf, mode);
388 /*****************************************************************************
389 * GdipCombineRegionRegion [GDIPLUS.@]
391 GpStatus WINGDIPAPI GdipCombineRegionRegion(GpRegion *region1,
392 GpRegion *region2, CombineMode mode)
394 region_element *left, *right = NULL;
395 GpStatus stat;
396 GpRegion *reg2copy;
398 TRACE("%p %p %d\n", region1, region2, mode);
400 if(!(region1 && region2))
401 return InvalidParameter;
403 /* simply replace region data */
404 if(mode == CombineModeReplace){
405 stat = GdipCloneRegion(region2, &reg2copy);
406 if(stat != Ok) return stat;
408 delete_element(&region1->node);
409 memcpy(region1, reg2copy, sizeof(GpRegion));
410 heap_free(reg2copy);
411 return Ok;
414 left = heap_alloc_zero(sizeof(region_element));
415 if (!left)
416 return OutOfMemory;
418 *left = region1->node;
419 stat = clone_element(&region2->node, &right);
420 if (stat != Ok)
422 heap_free(left);
423 return OutOfMemory;
426 fuse_region(region1, left, right, mode);
427 region1->num_children += region2->num_children;
429 return Ok;
432 /*****************************************************************************
433 * GdipCreateRegion [GDIPLUS.@]
435 GpStatus WINGDIPAPI GdipCreateRegion(GpRegion **region)
437 TRACE("%p\n", region);
439 if(!region)
440 return InvalidParameter;
442 *region = heap_alloc_zero(sizeof(GpRegion));
443 if(!*region)
444 return OutOfMemory;
446 TRACE("=> %p\n", *region);
448 return init_region(*region, RegionDataInfiniteRect);
451 /*****************************************************************************
452 * GdipCreateRegionPath [GDIPLUS.@]
454 * Creates a GpRegion from a GpPath
456 * PARAMS
457 * path [I] path to base the region on
458 * region [O] pointer to the newly allocated region
460 * RETURNS
461 * SUCCESS: Ok
462 * FAILURE: InvalidParameter
464 * NOTES
465 * If a path has no floating point points, its points will be stored as shorts
466 * (INTPATH)
468 * If a path is empty, it is considered to be an INTPATH
470 GpStatus WINGDIPAPI GdipCreateRegionPath(GpPath *path, GpRegion **region)
472 region_element* element;
473 GpStatus stat;
475 TRACE("%p, %p\n", path, region);
477 if (!(path && region))
478 return InvalidParameter;
480 *region = heap_alloc_zero(sizeof(GpRegion));
481 if(!*region)
482 return OutOfMemory;
483 stat = init_region(*region, RegionDataPath);
484 if (stat != Ok)
486 GdipDeleteRegion(*region);
487 return stat;
489 element = &(*region)->node;
491 stat = GdipClonePath(path, &element->elementdata.path);
492 if (stat != Ok)
494 GdipDeleteRegion(*region);
495 return stat;
498 return Ok;
501 /*****************************************************************************
502 * GdipCreateRegionRect [GDIPLUS.@]
504 GpStatus WINGDIPAPI GdipCreateRegionRect(GDIPCONST GpRectF *rect,
505 GpRegion **region)
507 GpStatus stat;
509 TRACE("%p, %p\n", rect, region);
511 if (!(rect && region))
512 return InvalidParameter;
514 *region = heap_alloc_zero(sizeof(GpRegion));
515 stat = init_region(*region, RegionDataRect);
516 if(stat != Ok)
518 GdipDeleteRegion(*region);
519 return stat;
522 (*region)->node.elementdata.rect.X = rect->X;
523 (*region)->node.elementdata.rect.Y = rect->Y;
524 (*region)->node.elementdata.rect.Width = rect->Width;
525 (*region)->node.elementdata.rect.Height = rect->Height;
527 return Ok;
530 /*****************************************************************************
531 * GdipCreateRegionRectI [GDIPLUS.@]
533 GpStatus WINGDIPAPI GdipCreateRegionRectI(GDIPCONST GpRect *rect,
534 GpRegion **region)
536 GpRectF rectf;
538 TRACE("%p, %p\n", rect, region);
540 rectf.X = (REAL)rect->X;
541 rectf.Y = (REAL)rect->Y;
542 rectf.Width = (REAL)rect->Width;
543 rectf.Height = (REAL)rect->Height;
545 return GdipCreateRegionRect(&rectf, region);
548 /******************************************************************************
549 * GdipCreateRegionHrgn [GDIPLUS.@]
551 GpStatus WINGDIPAPI GdipCreateRegionHrgn(HRGN hrgn, GpRegion **region)
553 DWORD size;
554 LPRGNDATA buf;
555 LPRECT rect;
556 GpStatus stat;
557 GpPath* path;
558 GpRegion* local;
559 DWORD i;
561 TRACE("(%p, %p)\n", hrgn, region);
563 if(!region || !(size = GetRegionData(hrgn, 0, NULL)))
564 return InvalidParameter;
566 buf = heap_alloc_zero(size);
567 if(!buf)
568 return OutOfMemory;
570 if(!GetRegionData(hrgn, size, buf)){
571 heap_free(buf);
572 return GenericError;
575 if(buf->rdh.nCount == 0){
576 if((stat = GdipCreateRegion(&local)) != Ok){
577 heap_free(buf);
578 return stat;
580 if((stat = GdipSetEmpty(local)) != Ok){
581 heap_free(buf);
582 GdipDeleteRegion(local);
583 return stat;
585 *region = local;
586 heap_free(buf);
587 return Ok;
590 if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok){
591 heap_free(buf);
592 return stat;
595 rect = (LPRECT)buf->Buffer;
596 for(i = 0; i < buf->rdh.nCount; i++){
597 if((stat = GdipAddPathRectangle(path, (REAL)rect->left, (REAL)rect->top,
598 (REAL)(rect->right - rect->left), (REAL)(rect->bottom - rect->top))) != Ok){
599 heap_free(buf);
600 GdipDeletePath(path);
601 return stat;
603 rect++;
606 stat = GdipCreateRegionPath(path, region);
608 heap_free(buf);
609 GdipDeletePath(path);
610 return stat;
613 /*****************************************************************************
614 * GdipDeleteRegion [GDIPLUS.@]
616 GpStatus WINGDIPAPI GdipDeleteRegion(GpRegion *region)
618 TRACE("%p\n", region);
620 if (!region)
621 return InvalidParameter;
623 delete_element(&region->node);
624 heap_free(region);
626 return Ok;
629 /*****************************************************************************
630 * GdipGetRegionBounds [GDIPLUS.@]
632 GpStatus WINGDIPAPI GdipGetRegionBounds(GpRegion *region, GpGraphics *graphics, GpRectF *rect)
634 HRGN hrgn;
635 RECT r;
636 GpStatus status;
638 TRACE("(%p, %p, %p)\n", region, graphics, rect);
640 if(!region || !graphics || !rect)
641 return InvalidParameter;
643 /* Contrary to MSDN, native ignores the graphics transform. */
644 status = GdipGetRegionHRgn(region, NULL, &hrgn);
645 if(status != Ok)
646 return status;
648 /* infinite */
649 if(!hrgn){
650 rect->X = rect->Y = -(REAL)(1 << 22);
651 rect->Width = rect->Height = (REAL)(1 << 23);
652 TRACE("%p => infinite\n", region);
653 return Ok;
656 if(GetRgnBox(hrgn, &r)){
657 rect->X = r.left;
658 rect->Y = r.top;
659 rect->Width = r.right - r.left;
660 rect->Height = r.bottom - r.top;
661 TRACE("%p => %s\n", region, debugstr_rectf(rect));
663 else
664 status = GenericError;
666 DeleteObject(hrgn);
668 return status;
671 /*****************************************************************************
672 * GdipGetRegionBoundsI [GDIPLUS.@]
674 GpStatus WINGDIPAPI GdipGetRegionBoundsI(GpRegion *region, GpGraphics *graphics, GpRect *rect)
676 GpRectF rectf;
677 GpStatus status;
679 TRACE("(%p, %p, %p)\n", region, graphics, rect);
681 if(!rect)
682 return InvalidParameter;
684 status = GdipGetRegionBounds(region, graphics, &rectf);
685 if(status == Ok){
686 rect->X = gdip_round(rectf.X);
687 rect->Y = gdip_round(rectf.Y);
688 rect->Width = gdip_round(rectf.Width);
689 rect->Height = gdip_round(rectf.Height);
692 return status;
695 static inline void write_dword(DWORD* location, INT* offset, const DWORD write)
697 location[*offset] = write;
698 (*offset)++;
701 static inline void write_float(DWORD* location, INT* offset, const FLOAT write)
703 ((FLOAT*)location)[*offset] = write;
704 (*offset)++;
707 static inline void write_packed_point(DWORD* location, INT* offset,
708 const GpPointF* write)
710 packed_point *point = (packed_point *)(location + *offset);
711 point->X = gdip_round(write->X);
712 point->Y = gdip_round(write->Y);
713 (*offset)++;
716 static inline void write_path_types(DWORD* location, INT* offset,
717 const GpPath* path)
719 INT rounded_size = get_pathtypes_size(path);
721 memcpy(location + *offset, path->pathdata.Types, path->pathdata.Count);
723 /* The unwritten parts of the DWORD (if any) must be cleared */
724 if (rounded_size - path->pathdata.Count)
725 ZeroMemory(((BYTE*)location) + (*offset * sizeof(DWORD)) +
726 path->pathdata.Count, rounded_size - path->pathdata.Count);
727 *offset += rounded_size / sizeof(DWORD);
730 static void write_element(const region_element* element, DWORD *buffer,
731 INT* filled)
733 write_dword(buffer, filled, element->type);
734 switch (element->type)
736 case CombineModeReplace:
737 case CombineModeIntersect:
738 case CombineModeUnion:
739 case CombineModeXor:
740 case CombineModeExclude:
741 case CombineModeComplement:
742 write_element(element->elementdata.combine.left, buffer, filled);
743 write_element(element->elementdata.combine.right, buffer, filled);
744 break;
745 case RegionDataRect:
746 write_float(buffer, filled, element->elementdata.rect.X);
747 write_float(buffer, filled, element->elementdata.rect.Y);
748 write_float(buffer, filled, element->elementdata.rect.Width);
749 write_float(buffer, filled, element->elementdata.rect.Height);
750 break;
751 case RegionDataPath:
753 INT i;
754 const GpPath* path = element->elementdata.path;
755 struct path_header *pathheader;
757 pathheader = (struct path_header *)(buffer + *filled);
759 pathheader->flags = is_integer_path(path) ? FLAGS_INTPATH : FLAGS_NOFLAGS;
760 /* 3 for headers, once again size doesn't count itself */
761 pathheader->size = sizeof(DWORD) * 3;
762 if (pathheader->flags & FLAGS_INTPATH)
763 pathheader->size += 2 * sizeof(SHORT) * path->pathdata.Count;
764 else
765 pathheader->size += 2 * sizeof(FLOAT) * path->pathdata.Count;
766 pathheader->size += get_pathtypes_size(path);
767 pathheader->magic = VERSION_MAGIC;
768 pathheader->count = path->pathdata.Count;
770 *filled += 4;
772 switch (pathheader->flags & FLAGS_INTPATH)
774 case FLAGS_NOFLAGS:
775 for (i = 0; i < path->pathdata.Count; i++)
777 write_float(buffer, filled, path->pathdata.Points[i].X);
778 write_float(buffer, filled, path->pathdata.Points[i].Y);
780 break;
781 case FLAGS_INTPATH:
782 for (i = 0; i < path->pathdata.Count; i++)
784 write_packed_point(buffer, filled,
785 &path->pathdata.Points[i]);
787 break;
789 write_path_types(buffer, filled, path);
790 break;
792 case RegionDataEmptyRect:
793 case RegionDataInfiniteRect:
794 break;
798 /*****************************************************************************
799 * GdipGetRegionData [GDIPLUS.@]
801 * Returns the header, followed by combining ops and region elements.
803 * PARAMS
804 * region [I] region to retrieve from
805 * buffer [O] buffer to hold the resulting data
806 * size [I] size of the buffer
807 * needed [O] (optional) how much data was written
809 * RETURNS
810 * SUCCESS: Ok
811 * FAILURE: InvalidParameter
813 * NOTES
814 * The header contains the size, a checksum, a version string, and the number
815 * of children. The size does not count itself or the checksum.
816 * Version is always something like 0xdbc01001 or 0xdbc01002
818 * An element is a RECT, or PATH; Combining ops are stored as their
819 * CombineMode value. Special regions (infinite, empty) emit just their
820 * op-code; GpRectFs emit their code followed by their points; GpPaths emit
821 * their code followed by a second header for the path followed by the actual
822 * path data. Followed by the flags for each point. The pathheader contains
823 * the size of the data to follow, a version number again, followed by a count
824 * of how many points, and any special flags which may apply. 0x4000 means its
825 * a path of shorts instead of FLOAT.
827 * Combining Ops are stored in reverse order from when they were constructed;
828 * the output is a tree where the left side combining area is always taken
829 * first.
831 GpStatus WINGDIPAPI GdipGetRegionData(GpRegion *region, BYTE *buffer, UINT size,
832 UINT *needed)
834 struct region_header *region_header;
835 INT filled = 0;
836 UINT required;
837 GpStatus status;
839 TRACE("%p, %p, %d, %p\n", region, buffer, size, needed);
841 if (!region || !buffer || !size)
842 return InvalidParameter;
844 status = GdipGetRegionDataSize(region, &required);
845 if (status != Ok) return status;
846 if (size < required)
848 if (needed) *needed = size;
849 return InsufficientBuffer;
852 region_header = (struct region_header *)buffer;
853 region_header->size = sizeheader_size + get_element_size(&region->node);
854 region_header->checksum = 0;
855 region_header->magic = VERSION_MAGIC;
856 region_header->num_children = region->num_children;
857 filled += 4;
858 /* With few exceptions, everything written is DWORD aligned,
859 * so use that as our base */
860 write_element(&region->node, (DWORD*)buffer, &filled);
862 if (needed)
863 *needed = filled * sizeof(DWORD);
865 return Ok;
868 static inline void init_memory_buffer(struct memory_buffer *mbuf, const BYTE *buffer, INT size)
870 mbuf->buffer = buffer;
871 mbuf->size = size;
872 mbuf->pos = 0;
875 static inline const void *buffer_read(struct memory_buffer *mbuf, INT size)
877 if (mbuf->size - mbuf->pos >= size)
879 const void *data = mbuf->buffer + mbuf->pos;
880 mbuf->pos += size;
881 return data;
883 return NULL;
886 static GpStatus read_element(struct memory_buffer *mbuf, GpRegion *region, region_element *node, INT *count)
888 GpStatus status;
889 const DWORD *type;
891 type = buffer_read(mbuf, sizeof(*type));
892 if (!type) return Ok;
894 TRACE("type %#x\n", *type);
896 node->type = *type;
898 switch (node->type)
900 case CombineModeReplace:
901 case CombineModeIntersect:
902 case CombineModeUnion:
903 case CombineModeXor:
904 case CombineModeExclude:
905 case CombineModeComplement:
907 region_element *left, *right;
909 left = heap_alloc_zero(sizeof(region_element));
910 if (!left) return OutOfMemory;
911 right = heap_alloc_zero(sizeof(region_element));
912 if (!right)
914 heap_free(left);
915 return OutOfMemory;
918 status = read_element(mbuf, region, left, count);
919 if (status == Ok)
921 status = read_element(mbuf, region, right, count);
922 if (status == Ok)
924 node->elementdata.combine.left = left;
925 node->elementdata.combine.right = right;
926 region->num_children += 2;
927 return Ok;
931 heap_free(left);
932 heap_free(right);
933 return status;
936 case RegionDataRect:
938 const GpRectF *rc;
940 rc = buffer_read(mbuf, sizeof(*rc));
941 if (!rc)
943 ERR("failed to read rect data\n");
944 return InvalidParameter;
947 node->elementdata.rect = *rc;
948 *count += 1;
949 return Ok;
952 case RegionDataPath:
954 GpPath *path;
955 const struct path_header *path_header;
956 const BYTE *types;
958 path_header = buffer_read(mbuf, sizeof(*path_header));
959 if (!path_header)
961 ERR("failed to read path header\n");
962 return InvalidParameter;
964 if (path_header->magic != VERSION_MAGIC)
966 ERR("invalid path header magic %#x\n", path_header->magic);
967 return InvalidParameter;
970 /* Windows always fails to create an empty path in a region */
971 if (!path_header->count)
973 TRACE("refusing to create an empty path in a region\n");
974 return GenericError;
977 status = GdipCreatePath(FillModeAlternate, &path);
978 if (status) return status;
980 node->elementdata.path = path;
982 if (!lengthen_path(path, path_header->count))
983 return OutOfMemory;
985 path->pathdata.Count = path_header->count;
987 if (path_header->flags & ~FLAGS_INTPATH)
988 FIXME("unhandled path flags %#x\n", path_header->flags);
990 if (path_header->flags & FLAGS_INTPATH)
992 const packed_point *pt;
993 DWORD i;
995 pt = buffer_read(mbuf, sizeof(*pt) * path_header->count);
996 if (!pt)
998 ERR("failed to read packed %u path points\n", path_header->count);
999 return InvalidParameter;
1002 for (i = 0; i < path_header->count; i++)
1004 path->pathdata.Points[i].X = (REAL)pt[i].X;
1005 path->pathdata.Points[i].Y = (REAL)pt[i].Y;
1008 else
1010 const GpPointF *ptf;
1012 ptf = buffer_read(mbuf, sizeof(*ptf) * path_header->count);
1013 if (!ptf)
1015 ERR("failed to read %u path points\n", path_header->count);
1016 return InvalidParameter;
1018 memcpy(path->pathdata.Points, ptf, sizeof(*ptf) * path_header->count);
1021 types = buffer_read(mbuf, path_header->count);
1022 if (!types)
1024 ERR("failed to read %u path types\n", path_header->count);
1025 return InvalidParameter;
1027 memcpy(path->pathdata.Types, types, path_header->count);
1028 if (path_header->count & 3)
1030 if (!buffer_read(mbuf, 4 - (path_header->count & 3)))
1032 ERR("failed to read rounding %u bytes\n", 4 - (path_header->count & 3));
1033 return InvalidParameter;
1037 *count += 1;
1038 return Ok;
1041 case RegionDataEmptyRect:
1042 case RegionDataInfiniteRect:
1043 *count += 1;
1044 return Ok;
1046 default:
1047 FIXME("element type %#x is not supported\n", *type);
1048 break;
1051 return InvalidParameter;
1054 /*****************************************************************************
1055 * GdipCreateRegionRgnData [GDIPLUS.@]
1057 GpStatus WINGDIPAPI GdipCreateRegionRgnData(GDIPCONST BYTE *data, INT size, GpRegion **region)
1059 const struct region_header *region_header;
1060 struct memory_buffer mbuf;
1061 GpStatus status;
1062 INT count;
1064 TRACE("(%p, %d, %p)\n", data, size, region);
1066 if (!data || !size)
1067 return InvalidParameter;
1069 init_memory_buffer(&mbuf, data, size);
1071 region_header = buffer_read(&mbuf, sizeof(*region_header));
1072 if (!region_header || (region_header->magic != VERSION_MAGIC &&
1073 region_header->magic != VERSION_MAGIC2))
1074 return InvalidParameter;
1076 status = GdipCreateRegion(region);
1077 if (status != Ok)
1078 return status;
1080 count = 0;
1081 status = read_element(&mbuf, *region, &(*region)->node, &count);
1082 if (status == Ok && !count)
1083 status = InvalidParameter;
1085 if (status != Ok)
1087 GdipDeleteRegion(*region);
1088 *region = NULL;
1091 return status;
1094 /*****************************************************************************
1095 * GdipGetRegionDataSize [GDIPLUS.@]
1097 GpStatus WINGDIPAPI GdipGetRegionDataSize(GpRegion *region, UINT *needed)
1099 TRACE("%p, %p\n", region, needed);
1101 if (!(region && needed))
1102 return InvalidParameter;
1104 /* header.size doesn't count header.size and header.checksum */
1105 *needed = sizeof(DWORD) * 2 + sizeheader_size + get_element_size(&region->node);
1107 return Ok;
1110 static GpStatus get_path_hrgn(GpPath *path, GpGraphics *graphics, HRGN *hrgn)
1112 HDC new_hdc=NULL;
1113 GpGraphics *new_graphics=NULL;
1114 GpStatus stat;
1115 INT save_state;
1117 if (!path->pathdata.Count) /* PathToRegion doesn't support empty paths */
1119 *hrgn = CreateRectRgn( 0, 0, 0, 0 );
1120 return *hrgn ? Ok : OutOfMemory;
1123 if (!graphics)
1125 new_hdc = CreateCompatibleDC(0);
1126 if (!new_hdc)
1127 return OutOfMemory;
1129 stat = GdipCreateFromHDC(new_hdc, &new_graphics);
1130 graphics = new_graphics;
1131 if (stat != Ok)
1133 DeleteDC(new_hdc);
1134 return stat;
1137 else if (!graphics->hdc)
1139 graphics->hdc = new_hdc = CreateCompatibleDC(0);
1140 if (!new_hdc)
1141 return OutOfMemory;
1144 save_state = SaveDC(graphics->hdc);
1145 EndPath(graphics->hdc);
1147 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
1148 : WINDING));
1150 stat = trace_path(graphics, path);
1151 if (stat == Ok)
1153 *hrgn = PathToRegion(graphics->hdc);
1154 stat = *hrgn ? Ok : OutOfMemory;
1157 RestoreDC(graphics->hdc, save_state);
1158 if (new_hdc)
1160 DeleteDC(new_hdc);
1161 if (new_graphics)
1162 GdipDeleteGraphics(new_graphics);
1163 else
1164 graphics->hdc = NULL;
1167 return stat;
1170 static GpStatus get_region_hrgn(struct region_element *element, GpGraphics *graphics, HRGN *hrgn)
1172 switch (element->type)
1174 case RegionDataInfiniteRect:
1175 *hrgn = NULL;
1176 return Ok;
1177 case RegionDataEmptyRect:
1178 *hrgn = CreateRectRgn(0, 0, 0, 0);
1179 return *hrgn ? Ok : OutOfMemory;
1180 case RegionDataPath:
1181 return get_path_hrgn(element->elementdata.path, graphics, hrgn);
1182 case RegionDataRect:
1184 GpPath* path;
1185 GpStatus stat;
1186 GpRectF* rc = &element->elementdata.rect;
1188 stat = GdipCreatePath(FillModeAlternate, &path);
1189 if (stat != Ok)
1190 return stat;
1191 stat = GdipAddPathRectangle(path, rc->X, rc->Y, rc->Width, rc->Height);
1193 if (stat == Ok)
1194 stat = get_path_hrgn(path, graphics, hrgn);
1196 GdipDeletePath(path);
1198 return stat;
1200 case CombineModeIntersect:
1201 case CombineModeUnion:
1202 case CombineModeXor:
1203 case CombineModeExclude:
1204 case CombineModeComplement:
1206 HRGN left, right;
1207 GpStatus stat;
1208 int ret;
1210 stat = get_region_hrgn(element->elementdata.combine.left, graphics, &left);
1211 if (stat != Ok)
1213 *hrgn = NULL;
1214 return stat;
1217 if (left == NULL)
1219 /* existing region is infinite */
1220 switch (element->type)
1222 case CombineModeIntersect:
1223 return get_region_hrgn(element->elementdata.combine.right, graphics, hrgn);
1224 case CombineModeXor: case CombineModeExclude:
1225 left = CreateRectRgn(-(1 << 22), -(1 << 22), 1 << 22, 1 << 22);
1226 break;
1227 case CombineModeUnion: case CombineModeComplement:
1228 *hrgn = NULL;
1229 return Ok;
1233 stat = get_region_hrgn(element->elementdata.combine.right, graphics, &right);
1234 if (stat != Ok)
1236 DeleteObject(left);
1237 *hrgn = NULL;
1238 return stat;
1241 if (right == NULL)
1243 /* new region is infinite */
1244 switch (element->type)
1246 case CombineModeIntersect:
1247 *hrgn = left;
1248 return Ok;
1249 case CombineModeXor: case CombineModeComplement:
1250 right = CreateRectRgn(-(1 << 22), -(1 << 22), 1 << 22, 1 << 22);
1251 break;
1252 case CombineModeUnion: case CombineModeExclude:
1253 DeleteObject(left);
1254 *hrgn = NULL;
1255 return Ok;
1259 switch (element->type)
1261 case CombineModeIntersect:
1262 ret = CombineRgn(left, left, right, RGN_AND);
1263 break;
1264 case CombineModeUnion:
1265 ret = CombineRgn(left, left, right, RGN_OR);
1266 break;
1267 case CombineModeXor:
1268 ret = CombineRgn(left, left, right, RGN_XOR);
1269 break;
1270 case CombineModeExclude:
1271 ret = CombineRgn(left, left, right, RGN_DIFF);
1272 break;
1273 case CombineModeComplement:
1274 ret = CombineRgn(left, right, left, RGN_DIFF);
1275 break;
1276 default:
1277 ret = ERROR;
1280 DeleteObject(right);
1282 if (ret == ERROR)
1284 DeleteObject(left);
1285 *hrgn = NULL;
1286 return GenericError;
1289 *hrgn = left;
1290 return Ok;
1292 default:
1293 FIXME("GdipGetRegionHRgn unimplemented for region type=%x\n", element->type);
1294 *hrgn = NULL;
1295 return NotImplemented;
1299 /*****************************************************************************
1300 * GdipGetRegionHRgn [GDIPLUS.@]
1302 GpStatus WINGDIPAPI GdipGetRegionHRgn(GpRegion *region, GpGraphics *graphics, HRGN *hrgn)
1304 TRACE("(%p, %p, %p)\n", region, graphics, hrgn);
1306 if (!region || !hrgn)
1307 return InvalidParameter;
1309 return get_region_hrgn(&region->node, graphics, hrgn);
1312 GpStatus WINGDIPAPI GdipIsEmptyRegion(GpRegion *region, GpGraphics *graphics, BOOL *res)
1314 GpStatus status;
1315 GpRectF rect;
1317 TRACE("(%p, %p, %p)\n", region, graphics, res);
1319 if(!region || !graphics || !res)
1320 return InvalidParameter;
1322 status = GdipGetRegionBounds(region, graphics, &rect);
1323 if (status != Ok) return status;
1325 *res = rect.Width == 0.0 && rect.Height == 0.0;
1326 TRACE("=> %d\n", *res);
1328 return Ok;
1331 /*****************************************************************************
1332 * GdipIsEqualRegion [GDIPLUS.@]
1334 GpStatus WINGDIPAPI GdipIsEqualRegion(GpRegion *region, GpRegion *region2, GpGraphics *graphics,
1335 BOOL *res)
1337 HRGN hrgn1, hrgn2;
1338 GpStatus stat;
1340 TRACE("(%p, %p, %p, %p)\n", region, region2, graphics, res);
1342 if(!region || !region2 || !graphics || !res)
1343 return InvalidParameter;
1345 stat = GdipGetRegionHRgn(region, graphics, &hrgn1);
1346 if(stat != Ok)
1347 return stat;
1348 stat = GdipGetRegionHRgn(region2, graphics, &hrgn2);
1349 if(stat != Ok){
1350 DeleteObject(hrgn1);
1351 return stat;
1354 *res = EqualRgn(hrgn1, hrgn2);
1356 /* one of GpRegions is infinite */
1357 if(*res == ERROR)
1358 *res = (!hrgn1 && !hrgn2);
1360 DeleteObject(hrgn1);
1361 DeleteObject(hrgn2);
1363 return Ok;
1366 /*****************************************************************************
1367 * GdipIsInfiniteRegion [GDIPLUS.@]
1369 GpStatus WINGDIPAPI GdipIsInfiniteRegion(GpRegion *region, GpGraphics *graphics, BOOL *res)
1371 /* I think graphics is ignored here */
1372 TRACE("(%p, %p, %p)\n", region, graphics, res);
1374 if(!region || !graphics || !res)
1375 return InvalidParameter;
1377 *res = (region->node.type == RegionDataInfiniteRect);
1379 return Ok;
1382 /*****************************************************************************
1383 * GdipIsVisibleRegionRect [GDIPLUS.@]
1385 GpStatus WINGDIPAPI GdipIsVisibleRegionRect(GpRegion* region, REAL x, REAL y, REAL w, REAL h, GpGraphics *graphics, BOOL *res)
1387 HRGN hrgn;
1388 GpStatus stat;
1389 RECT rect;
1391 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %p, %p)\n", region, x, y, w, h, graphics, res);
1393 if(!region || !res)
1394 return InvalidParameter;
1396 if((stat = GdipGetRegionHRgn(region, NULL, &hrgn)) != Ok)
1397 return stat;
1399 /* infinite */
1400 if(!hrgn){
1401 *res = TRUE;
1402 return Ok;
1405 SetRect(&rect, ceilr(x), ceilr(y), ceilr(x + w), ceilr(y + h));
1406 *res = RectInRegion(hrgn, &rect);
1408 DeleteObject(hrgn);
1410 return Ok;
1413 /*****************************************************************************
1414 * GdipIsVisibleRegionRectI [GDIPLUS.@]
1416 GpStatus WINGDIPAPI GdipIsVisibleRegionRectI(GpRegion* region, INT x, INT y, INT w, INT h, GpGraphics *graphics, BOOL *res)
1418 TRACE("(%p, %d, %d, %d, %d, %p, %p)\n", region, x, y, w, h, graphics, res);
1419 if(!region || !res)
1420 return InvalidParameter;
1422 return GdipIsVisibleRegionRect(region, (REAL)x, (REAL)y, (REAL)w, (REAL)h, graphics, res);
1425 /*****************************************************************************
1426 * GdipIsVisibleRegionPoint [GDIPLUS.@]
1428 GpStatus WINGDIPAPI GdipIsVisibleRegionPoint(GpRegion* region, REAL x, REAL y, GpGraphics *graphics, BOOL *res)
1430 HRGN hrgn;
1431 GpStatus stat;
1433 TRACE("(%p, %.2f, %.2f, %p, %p)\n", region, x, y, graphics, res);
1435 if(!region || !res)
1436 return InvalidParameter;
1438 if((stat = GdipGetRegionHRgn(region, NULL, &hrgn)) != Ok)
1439 return stat;
1441 /* infinite */
1442 if(!hrgn){
1443 *res = TRUE;
1444 return Ok;
1447 *res = PtInRegion(hrgn, gdip_round(x), gdip_round(y));
1449 DeleteObject(hrgn);
1451 return Ok;
1454 /*****************************************************************************
1455 * GdipIsVisibleRegionPointI [GDIPLUS.@]
1457 GpStatus WINGDIPAPI GdipIsVisibleRegionPointI(GpRegion* region, INT x, INT y, GpGraphics *graphics, BOOL *res)
1459 TRACE("(%p, %d, %d, %p, %p)\n", region, x, y, graphics, res);
1461 return GdipIsVisibleRegionPoint(region, (REAL)x, (REAL)y, graphics, res);
1464 /*****************************************************************************
1465 * GdipSetEmpty [GDIPLUS.@]
1467 GpStatus WINGDIPAPI GdipSetEmpty(GpRegion *region)
1469 GpStatus stat;
1471 TRACE("%p\n", region);
1473 if (!region)
1474 return InvalidParameter;
1476 delete_element(&region->node);
1477 stat = init_region(region, RegionDataEmptyRect);
1479 return stat;
1482 GpStatus WINGDIPAPI GdipSetInfinite(GpRegion *region)
1484 GpStatus stat;
1486 TRACE("%p\n", region);
1488 if (!region)
1489 return InvalidParameter;
1491 delete_element(&region->node);
1492 stat = init_region(region, RegionDataInfiniteRect);
1494 return stat;
1497 /* Transforms GpRegion elements with given matrix */
1498 static GpStatus transform_region_element(region_element* element, GpMatrix *matrix)
1500 GpStatus stat;
1502 switch(element->type)
1504 case RegionDataEmptyRect:
1505 case RegionDataInfiniteRect:
1506 return Ok;
1507 case RegionDataRect:
1509 /* We can't transform a rectangle, so convert it to a path. */
1510 GpRegion *new_region;
1511 GpPath *path;
1513 stat = GdipCreatePath(FillModeAlternate, &path);
1514 if (stat == Ok)
1516 stat = GdipAddPathRectangle(path,
1517 element->elementdata.rect.X, element->elementdata.rect.Y,
1518 element->elementdata.rect.Width, element->elementdata.rect.Height);
1520 if (stat == Ok)
1521 stat = GdipCreateRegionPath(path, &new_region);
1523 GdipDeletePath(path);
1526 if (stat == Ok)
1528 /* Steal the element from the created region. */
1529 memcpy(element, &new_region->node, sizeof(region_element));
1530 heap_free(new_region);
1532 else
1533 return stat;
1535 /* Fall-through to do the actual conversion. */
1536 case RegionDataPath:
1537 if (!element->elementdata.path->pathdata.Count)
1538 return Ok;
1540 stat = GdipTransformMatrixPoints(matrix,
1541 element->elementdata.path->pathdata.Points,
1542 element->elementdata.path->pathdata.Count);
1543 return stat;
1544 default:
1545 stat = transform_region_element(element->elementdata.combine.left, matrix);
1546 if (stat == Ok)
1547 stat = transform_region_element(element->elementdata.combine.right, matrix);
1548 return stat;
1552 GpStatus WINGDIPAPI GdipTransformRegion(GpRegion *region, GpMatrix *matrix)
1554 TRACE("(%p, %p)\n", region, matrix);
1556 if (!region || !matrix)
1557 return InvalidParameter;
1559 return transform_region_element(&region->node, matrix);
1562 /* Translates GpRegion elements with specified offsets */
1563 static void translate_region_element(region_element* element, REAL dx, REAL dy)
1565 INT i;
1567 switch(element->type)
1569 case RegionDataEmptyRect:
1570 case RegionDataInfiniteRect:
1571 return;
1572 case RegionDataRect:
1573 element->elementdata.rect.X += dx;
1574 element->elementdata.rect.Y += dy;
1575 return;
1576 case RegionDataPath:
1577 for(i = 0; i < element->elementdata.path->pathdata.Count; i++){
1578 element->elementdata.path->pathdata.Points[i].X += dx;
1579 element->elementdata.path->pathdata.Points[i].Y += dy;
1581 return;
1582 default:
1583 translate_region_element(element->elementdata.combine.left, dx, dy);
1584 translate_region_element(element->elementdata.combine.right, dx, dy);
1585 return;
1589 /*****************************************************************************
1590 * GdipTranslateRegion [GDIPLUS.@]
1592 GpStatus WINGDIPAPI GdipTranslateRegion(GpRegion *region, REAL dx, REAL dy)
1594 TRACE("(%p, %f, %f)\n", region, dx, dy);
1596 if(!region)
1597 return InvalidParameter;
1599 translate_region_element(&region->node, dx, dy);
1601 return Ok;
1604 /*****************************************************************************
1605 * GdipTranslateRegionI [GDIPLUS.@]
1607 GpStatus WINGDIPAPI GdipTranslateRegionI(GpRegion *region, INT dx, INT dy)
1609 TRACE("(%p, %d, %d)\n", region, dx, dy);
1611 return GdipTranslateRegion(region, (REAL)dx, (REAL)dy);
1614 static GpStatus get_region_scans_data(GpRegion *region, GpMatrix *matrix, LPRGNDATA *data)
1616 GpRegion *region_copy;
1617 GpStatus stat;
1618 HRGN hrgn;
1619 DWORD data_size;
1621 stat = GdipCloneRegion(region, &region_copy);
1623 if (stat == Ok)
1625 stat = GdipTransformRegion(region_copy, matrix);
1627 if (stat == Ok)
1628 stat = GdipGetRegionHRgn(region_copy, NULL, &hrgn);
1630 if (stat == Ok)
1632 if (hrgn)
1634 data_size = GetRegionData(hrgn, 0, NULL);
1636 *data = heap_alloc_zero(data_size);
1638 if (*data)
1639 GetRegionData(hrgn, data_size, *data);
1640 else
1641 stat = OutOfMemory;
1643 DeleteObject(hrgn);
1645 else
1647 data_size = sizeof(RGNDATAHEADER) + sizeof(RECT);
1649 *data = heap_alloc_zero(data_size);
1651 if (*data)
1653 (*data)->rdh.dwSize = sizeof(RGNDATAHEADER);
1654 (*data)->rdh.iType = RDH_RECTANGLES;
1655 (*data)->rdh.nCount = 1;
1656 (*data)->rdh.nRgnSize = sizeof(RECT);
1657 (*data)->rdh.rcBound.left = (*data)->rdh.rcBound.top = -0x400000;
1658 (*data)->rdh.rcBound.right = (*data)->rdh.rcBound.bottom = 0x400000;
1660 memcpy((*data)->Buffer, &(*data)->rdh.rcBound, sizeof(RECT));
1662 else
1663 stat = OutOfMemory;
1667 GdipDeleteRegion(region_copy);
1670 return stat;
1673 GpStatus WINGDIPAPI GdipGetRegionScansCount(GpRegion *region, UINT *count, GpMatrix *matrix)
1675 GpStatus stat;
1676 LPRGNDATA data;
1678 TRACE("(%p, %p, %p)\n", region, count, matrix);
1680 if (!region || !count || !matrix)
1681 return InvalidParameter;
1683 stat = get_region_scans_data(region, matrix, &data);
1685 if (stat == Ok)
1687 *count = data->rdh.nCount;
1688 heap_free(data);
1691 return stat;
1694 GpStatus WINGDIPAPI GdipGetRegionScansI(GpRegion *region, GpRect *scans, INT *count, GpMatrix *matrix)
1696 GpStatus stat;
1697 DWORD i;
1698 LPRGNDATA data;
1699 RECT *rects;
1701 if (!region || !count || !matrix)
1702 return InvalidParameter;
1704 stat = get_region_scans_data(region, matrix, &data);
1706 if (stat == Ok)
1708 *count = data->rdh.nCount;
1709 rects = (RECT*)data->Buffer;
1711 if (scans)
1713 for (i=0; i<data->rdh.nCount; i++)
1715 scans[i].X = rects[i].left;
1716 scans[i].Y = rects[i].top;
1717 scans[i].Width = rects[i].right - rects[i].left;
1718 scans[i].Height = rects[i].bottom - rects[i].top;
1722 heap_free(data);
1725 return Ok;
1728 GpStatus WINGDIPAPI GdipGetRegionScans(GpRegion *region, GpRectF *scans, INT *count, GpMatrix *matrix)
1730 GpStatus stat;
1731 DWORD i;
1732 LPRGNDATA data;
1733 RECT *rects;
1735 if (!region || !count || !matrix)
1736 return InvalidParameter;
1738 stat = get_region_scans_data(region, matrix, &data);
1740 if (stat == Ok)
1742 *count = data->rdh.nCount;
1743 rects = (RECT*)data->Buffer;
1745 if (scans)
1747 for (i=0; i<data->rdh.nCount; i++)
1749 scans[i].X = rects[i].left;
1750 scans[i].Y = rects[i].top;
1751 scans[i].Width = rects[i].right - rects[i].left;
1752 scans[i].Height = rects[i].bottom - rects[i].top;
1756 heap_free(data);
1759 return Ok;