2 * GDI region definitions
3 * Mainly taken from the X11 distribution.
4 * Modifications: Copyright 1998 Huw Davies
7 /************************************************************************
9 Copyright (c) 1987 X Consortium
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
18 The above copyright notice and this permission notice shall be included in
19 all copies or substantial portions of the Software.
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
25 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 Except as contained in this notice, the name of the X Consortium shall not be
29 used in advertising or otherwise to promote the sale, use or other dealings
30 in this Software without prior written authorization from the X Consortium.
33 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
37 Permission to use, copy, modify, and distribute this software and its
38 documentation for any purpose and without fee is hereby granted,
39 provided that the above copyright notice appear in all copies and that
40 both that copyright notice and this permission notice appear in
41 supporting documentation, and that the name of Digital not be
42 used in advertising or publicity pertaining to distribution of the
43 software without specific, written prior permission.
45 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
46 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
47 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
48 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
49 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
50 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
53 ************************************************************************/
54 #ifndef __WINE_REGION_H
55 #define __WINE_REGION_H
64 INT type
; /* NULL, SIMPLE or COMPLEX */
69 /* GDI logical region object */
76 /* 1 if two RECTs overlap.
77 * 0 if two RECTs do not overlap.
79 #define EXTENTCHECK(r1, r2) \
80 ((r1)->right > (r2)->left && \
81 (r1)->left < (r2)->right && \
82 (r1)->bottom > (r2)->top && \
83 (r1)->top < (r2)->bottom)
86 * Check to see if there is enough memory in the present region.
88 #define MEMCHECK(reg, rect, firstrect){\
89 if ((reg)->numRects >= ((reg)->size - 1)){\
90 (firstrect) = HeapReAlloc( SystemHeap, 0, \
91 (firstrect), (2 * (sizeof(RECT)) * ((reg)->size)));\
92 if ((firstrect) == 0)\
95 (rect) = &(firstrect)[(reg)->numRects];\
99 #define EMPTY_REGION(pReg) { \
100 (pReg)->numRects = 0; \
101 (pReg)->extents.left = (pReg)->extents.top = 0; \
102 (pReg)->extents.right = (pReg)->extents.bottom = 0; \
103 (pReg)->type = NULLREGION; \
106 #define REGION_NOT_EMPTY(pReg) pReg->numRects
108 #define INRECT(r, x, y) \
109 ( ( ((r).right > x)) && \
110 ( ((r).left <= x)) && \
111 ( ((r).bottom > y)) && \
116 * number of points to buffer before sending them off
117 * to scanlines() : Must be an even number
119 #define NUMPTSTOBUFFER 200
122 * used to allocate buffers for points and link
123 * the buffers together
126 typedef struct _POINTBLOCK
{
127 POINT pts
[NUMPTSTOBUFFER
];
128 struct _POINTBLOCK
*next
;
134 * This file contains a few macros to help track
135 * the edge of a filled object. The object is assumed
136 * to be filled in scanline order, and thus the
137 * algorithm used is an extension of Bresenham's line
138 * drawing algorithm which assumes that y is always the
140 * Since these pieces of code are the same for any filled shape,
141 * it is more convenient to gather the library in one
142 * place, but since these pieces of code are also in
143 * the inner loops of output primitives, procedure call
144 * overhead is out of the question.
145 * See the author for a derivation if needed.
150 * In scan converting polygons, we want to choose those pixels
151 * which are inside the polygon. Thus, we add .5 to the starting
152 * x coordinate for both left and right edges. Now we choose the
153 * first pixel which is inside the pgon for the left edge and the
154 * first pixel which is outside the pgon for the right edge.
155 * Draw the left pixel, but not the right.
157 * How to add .5 to the starting x coordinate:
158 * If the edge is moving to the right, then subtract dy from the
159 * error term from the general form of the algorithm.
160 * If the edge is moving to the left, then add dy to the error term.
162 * The reason for the difference between edges moving to the left
163 * and edges moving to the right is simple: If an edge is moving
164 * to the right, then we want the algorithm to flip immediately.
165 * If it is moving to the left, then we don't want it to flip until
166 * we traverse an entire pixel.
168 #define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \
169 int dx; /* local storage */ \
172 * if the edge is horizontal, then it is ignored \
173 * and assumed not to be processed. Otherwise, do this stuff. \
177 dx = (x2) - xStart; \
181 incr1 = -2 * dx + 2 * (dy) * m1; \
182 incr2 = -2 * dx + 2 * (dy) * m; \
183 d = 2 * m * (dy) - 2 * dx - 2 * (dy); \
187 incr1 = 2 * dx - 2 * (dy) * m1; \
188 incr2 = 2 * dx - 2 * (dy) * m; \
189 d = -2 * m * (dy) + 2 * dx; \
194 #define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \
217 * This structure contains all of the information needed
218 * to run the bresenham algorithm.
219 * The variables may be hardcoded into the declarations
220 * instead of using this structure to make use of
221 * register declarations.
224 INT minor_axis
; /* minor axis */
225 INT d
; /* decision variable */
226 INT m
, m1
; /* slope and slope+1 */
227 INT incr1
, incr2
; /* error increments */
231 #define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \
232 BRESINITPGON(dmaj, min1, min2, bres.minor_axis, bres.d, \
233 bres.m, bres.m1, bres.incr1, bres.incr2)
235 #define BRESINCRPGONSTRUCT(bres) \
236 BRESINCRPGON(bres.d, bres.minor_axis, bres.m, bres.m1, bres.incr1, bres.incr2)
241 * These are the data structures needed to scan
242 * convert regions. Two different scan conversion
243 * methods are available -- the even-odd method, and
244 * the winding number method.
245 * The even-odd rule states that a point is inside
246 * the polygon if a ray drawn from that point in any
247 * direction will pass through an odd number of
249 * By the winding number rule, a point is decided
250 * to be inside the polygon if a ray drawn from that
251 * point in any direction passes through a different
252 * number of clockwise and counter-clockwise path
255 * These data structures are adapted somewhat from
256 * the algorithm in (Foley/Van Dam) for scan converting
258 * The basic algorithm is to start at the top (smallest y)
259 * of the polygon, stepping down to the bottom of
260 * the polygon by incrementing the y coordinate. We
261 * keep a list of edges which the current scanline crosses,
262 * sorted by x. This list is called the Active Edge Table (AET)
263 * As we change the y-coordinate, we update each entry in
264 * in the active edge table to reflect the edges new xcoord.
265 * This list must be sorted at each scanline in case
266 * two edges intersect.
267 * We also keep a data structure known as the Edge Table (ET),
268 * which keeps track of all the edges which the current
269 * scanline has not yet reached. The ET is basically a
270 * list of ScanLineList structures containing a list of
271 * edges which are entered at a given scanline. There is one
272 * ScanLineList per scanline at which an edge is entered.
273 * When we enter a new edge, we move it from the ET to the AET.
275 * From the AET, we can implement the even-odd rule as in
277 * The winding number rule is a little trickier. We also
278 * keep the EdgeTableEntries in the AET linked by the
279 * nextWETE (winding EdgeTableEntry) link. This allows
280 * the edges to be linked just as before for updating
281 * purposes, but only uses the edges linked by the nextWETE
282 * link as edges representing spans of the polygon to
283 * drawn (as with the even-odd rule).
287 * for the winding number rule
290 #define COUNTERCLOCKWISE -1
292 typedef struct _EdgeTableEntry
{
293 INT ymax
; /* ycoord at which we exit this edge. */
294 BRESINFO bres
; /* Bresenham info to run the edge */
295 struct _EdgeTableEntry
*next
; /* next in the list */
296 struct _EdgeTableEntry
*back
; /* for insertion sort */
297 struct _EdgeTableEntry
*nextWETE
; /* for winding num rule */
298 int ClockWise
; /* flag for winding number rule */
302 typedef struct _ScanLineList
{
303 INT scanline
; /* the scanline represented */
304 EdgeTableEntry
*edgelist
; /* header node */
305 struct _ScanLineList
*next
; /* next in the list */
310 INT ymax
; /* ymax for the polygon */
311 INT ymin
; /* ymin for the polygon */
312 ScanLineList scanlines
; /* header node */
317 * Here is a struct to help with storage allocation
318 * so we can allocate a big chunk at a time, and then take
319 * pieces from this heap when we need to.
321 #define SLLSPERBLOCK 25
323 typedef struct _ScanLineListBlock
{
324 ScanLineList SLLs
[SLLSPERBLOCK
];
325 struct _ScanLineListBlock
*next
;
331 * a few macros for the inner loops of the fill code where
332 * performance considerations don't allow a procedure call.
334 * Evaluate the given edge at the given scanline.
335 * If the edge has expired, then we leave it and fix up
336 * the active edge table; otherwise, we increment the
337 * x value to be ready for the next scanline.
338 * The winding number rule is in effect, so we must notify
339 * the caller when the edge has been removed so he
340 * can reorder the Winding Active Edge Table.
342 #define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
343 if (pAET->ymax == y) { /* leaving this edge */ \
344 pPrevAET->next = pAET->next; \
345 pAET = pPrevAET->next; \
348 pAET->back = pPrevAET; \
351 BRESINCRPGONSTRUCT(pAET->bres); \
359 * Evaluate the given edge at the given scanline.
360 * If the edge has expired, then we leave it and fix up
361 * the active edge table; otherwise, we increment the
362 * x value to be ready for the next scanline.
363 * The even-odd rule is in effect.
365 #define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
366 if (pAET->ymax == y) { /* leaving this edge */ \
367 pPrevAET->next = pAET->next; \
368 pAET = pPrevAET->next; \
370 pAET->back = pPrevAET; \
373 BRESINCRPGONSTRUCT(pAET->bres); \
379 extern BOOL
REGION_DeleteObject( HRGN hrgn
, RGNOBJ
* obj
);
380 extern BOOL
REGION_UnionRectWithRgn( HRGN hrgn
, const RECT
*lpRect
);
381 extern BOOL
REGION_FrameRgn( HRGN dest
, HRGN src
, INT x
, INT y
);
382 extern BOOL
REGION_LPTODP( HDC hdc
, HRGN hDest
, HRGN hSrc
);
384 #endif /* __WINE_REGION_H */