Blame gegl/buffer/gegl-region-generic.h

Packit Service 2781ba
/* $TOG: region.h /main/9 1998/02/06 17:50:30 kaleb $ */
Packit Service 2781ba
/************************************************************************
Packit Service 2781ba
Packit Service 2781ba
Copyright 1987, 1998  The Open Group
Packit Service 2781ba
Packit Service 2781ba
All Rights Reserved.
Packit Service 2781ba
Packit Service 2781ba
The above copyright notice and this permission notice shall be included in
Packit Service 2781ba
all copies or substantial portions of the Software.
Packit Service 2781ba
Packit Service 2781ba
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service 2781ba
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service 2781ba
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
Packit Service 2781ba
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
Packit Service 2781ba
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit Service 2781ba
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit Service 2781ba
Packit Service 2781ba
Except as contained in this notice, the name of The Open Group shall not be
Packit Service 2781ba
used in advertising or otherwise to promote the sale, use or other dealings
Packit Service 2781ba
in this Software without prior written authorization from The Open Group.
Packit Service 2781ba
Packit Service 2781ba
Packit Service 2781ba
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
Packit Service 2781ba
Packit Service 2781ba
                        All Rights Reserved
Packit Service 2781ba
Packit Service 2781ba
Permission to use, copy, modify, and distribute this software and its
Packit Service 2781ba
documentation for any purpose and without fee is hereby granted,
Packit Service 2781ba
provided that the above copyright notice appear in all copies and that
Packit Service 2781ba
both that copyright notice and this permission notice appear in
Packit Service 2781ba
supporting documentation, and that the name of Digital not be
Packit Service 2781ba
used in advertising or publicity pertaining to distribution of the
Packit Service 2781ba
software without specific, written prior permission.
Packit Service 2781ba
Packit Service 2781ba
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
Packit Service 2781ba
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
Packit Service 2781ba
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
Packit Service 2781ba
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
Packit Service 2781ba
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
Packit Service 2781ba
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
Packit Service 2781ba
SOFTWARE.
Packit Service 2781ba
Packit Service 2781ba
************************************************************************/
Packit Service 2781ba
Packit Service 2781ba
#ifndef __GEGL_REGION_GENERIC_H__
Packit Service 2781ba
#define __GEGL_REGION_GENERIC_H__
Packit Service 2781ba
Packit Service 2781ba
typedef GeglSegment GeglRegionBox;
Packit Service 2781ba
Packit Service 2781ba
/*
Packit Service 2781ba
 *   clip region
Packit Service 2781ba
 */
Packit Service 2781ba
Packit Service 2781ba
struct _GeglRegion
Packit Service 2781ba
{
Packit Service 2781ba
  long size;
Packit Service 2781ba
  long numRects;
Packit Service 2781ba
  GeglRegionBox *rects;
Packit Service 2781ba
  GeglRegionBox extents;
Packit Service 2781ba
};
Packit Service 2781ba
Packit Service 2781ba
/*  1 if two BOXs overlap.
Packit Service 2781ba
 *  0 if two BOXs do not overlap.
Packit Service 2781ba
 *  Remember, x2 and y2 are not in the region
Packit Service 2781ba
 */
Packit Service 2781ba
#define EXTENTCHECK(r1, r2) \
Packit Service 2781ba
	((r1)->x2 > (r2)->x1 && \
Packit Service 2781ba
	 (r1)->x1 < (r2)->x2 && \
Packit Service 2781ba
	 (r1)->y2 > (r2)->y1 && \
Packit Service 2781ba
	 (r1)->y1 < (r2)->y2)
Packit Service 2781ba
Packit Service 2781ba
/*
Packit Service 2781ba
 *  update region extents
Packit Service 2781ba
 */
Packit Service 2781ba
#define EXTENTS(r,idRect){\
Packit Service 2781ba
            if((r)->x1 < (idRect)->extents.x1)\
Packit Service 2781ba
              (idRect)->extents.x1 = (r)->x1;\
Packit Service 2781ba
            if((r)->y1 < (idRect)->extents.y1)\
Packit Service 2781ba
              (idRect)->extents.y1 = (r)->y1;\
Packit Service 2781ba
            if((r)->x2 > (idRect)->extents.x2)\
Packit Service 2781ba
              (idRect)->extents.x2 = (r)->x2;\
Packit Service 2781ba
            if((r)->y2 > (idRect)->extents.y2)\
Packit Service 2781ba
              (idRect)->extents.y2 = (r)->y2;\
Packit Service 2781ba
        }
Packit Service 2781ba
Packit Service 2781ba
#define GROWREGION(reg, nRects){  					         \
Packit Service 2781ba
	  if ((reg)->rects == &(reg)->extents) {                                 \
Packit Service 2781ba
            (reg)->rects = g_new (GeglRegionBox, (nRects));		         \
Packit Service 2781ba
            (reg)->rects[0] = reg->extents;                                      \
Packit Service 2781ba
          }                                                                      \
Packit Service 2781ba
          else                                                                   \
Packit Service 2781ba
            (reg)->rects = g_renew (GeglRegionBox, (reg)->rects, (nRects));       \
Packit Service 2781ba
	  (reg)->size = (nRects);                                                \
Packit Service 2781ba
       }
Packit Service 2781ba
Packit Service 2781ba
/*
Packit Service 2781ba
 *   Check to see if there is enough memory in the present region.
Packit Service 2781ba
 */
Packit Service 2781ba
#define MEMCHECK(reg, rect, firstrect){					  	 \
Packit Service 2781ba
        if ((reg)->numRects >= ((reg)->size - 1)) {			 	 \
Packit Service 2781ba
          GROWREGION(reg,2*(reg)->size);                                         \
Packit Service 2781ba
          (rect) = &(firstrect)[(reg)->numRects];				 \
Packit Service 2781ba
         }									 \
Packit Service 2781ba
       }
Packit Service 2781ba
Packit Service 2781ba
/*  this routine checks to see if the previous rectangle is the same
Packit Service 2781ba
 *  or subsumes the new rectangle to add.
Packit Service 2781ba
 */
Packit Service 2781ba
Packit Service 2781ba
#define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
Packit Service 2781ba
               (!(((Reg)->numRects > 0)&&\
Packit Service 2781ba
                  ((R-1)->y1 == (Ry1)) &&\
Packit Service 2781ba
                  ((R-1)->y2 == (Ry2)) &&\
Packit Service 2781ba
                  ((R-1)->x1 <= (Rx1)) &&\
Packit Service 2781ba
                  ((R-1)->x2 >= (Rx2))))
Packit Service 2781ba
Packit Service 2781ba
/*  add a rectangle to the given Region */
Packit Service 2781ba
#define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
Packit Service 2781ba
    if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
Packit Service 2781ba
        CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
Packit Service 2781ba
              (r)->x1 = (rx1);\
Packit Service 2781ba
              (r)->y1 = (ry1);\
Packit Service 2781ba
              (r)->x2 = (rx2);\
Packit Service 2781ba
              (r)->y2 = (ry2);\
Packit Service 2781ba
              EXTENTS((r), (reg));\
Packit Service 2781ba
              (reg)->numRects++;\
Packit Service 2781ba
              (r)++;\
Packit Service 2781ba
            }\
Packit Service 2781ba
        }
Packit Service 2781ba
Packit Service 2781ba
Packit Service 2781ba
Packit Service 2781ba
/*  add a rectangle to the given Region */
Packit Service 2781ba
#define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
Packit Service 2781ba
            if ((rx1 < rx2) && (ry1 < ry2) &&\
Packit Service 2781ba
                CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
Packit Service 2781ba
              (r)->x1 = (rx1);\
Packit Service 2781ba
              (r)->y1 = (ry1);\
Packit Service 2781ba
              (r)->x2 = (rx2);\
Packit Service 2781ba
              (r)->y2 = (ry2);\
Packit Service 2781ba
              (reg)->numRects++;\
Packit Service 2781ba
              (r)++;\
Packit Service 2781ba
            }\
Packit Service 2781ba
        }
Packit Service 2781ba
Packit Service 2781ba
#define EMPTY_REGION(pReg) pReg->numRects = 0
Packit Service 2781ba
Packit Service 2781ba
#define REGION_NOT_EMPTY(pReg) pReg->numRects
Packit Service 2781ba
Packit Service 2781ba
#define INBOX(r, x, y) \
Packit Service 2781ba
      ( ( ((r).x2 >  x)) && \
Packit Service 2781ba
        ( ((r).x1 <= x)) && \
Packit Service 2781ba
        ( ((r).y2 >  y)) && \
Packit Service 2781ba
        ( ((r).y1 <= y)) )
Packit Service 2781ba
Packit Service 2781ba
/*
Packit Service 2781ba
 * number of points to buffer before sending them off
Packit Service 2781ba
 * to scanlines() :  Must be an even number
Packit Service 2781ba
 */
Packit Service 2781ba
#define NUMPTSTOBUFFER 200
Packit Service 2781ba
Packit Service 2781ba
/*
Packit Service 2781ba
 * used to allocate buffers for points and link
Packit Service 2781ba
 * the buffers together
Packit Service 2781ba
 */
Packit Service 2781ba
typedef struct _POINTBLOCK {
Packit Service 2781ba
  GeglPoint pts[NUMPTSTOBUFFER];
Packit Service 2781ba
  struct _POINTBLOCK *next;
Packit Service 2781ba
} POINTBLOCK;
Packit Service 2781ba
Packit Service 2781ba
#endif /* __GEGL_REGION_GENERIC_H__ */