2003-03-20 03:06:52 +00:00
|
|
|
/*
|
2003-05-18 17:16:18 +00:00
|
|
|
* ReactOS W32 Subsystem
|
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2003-05-18 17:16:18 +00:00
|
|
|
*/
|
2005-01-06 13:58:04 +00:00
|
|
|
/* $Id$
|
2003-05-18 17:16:18 +00:00
|
|
|
*
|
2003-03-20 03:06:52 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* PURPOSE: Various Polygon Filling routines for Polygon()
|
|
|
|
* FILE: subsys/win32k/objects/polyfill.c
|
|
|
|
* PROGRAMER: Mark Tempel
|
|
|
|
* REVISION HISTORY:
|
|
|
|
* 21/2/2003: Created
|
|
|
|
*/
|
2005-06-29 07:09:25 +00:00
|
|
|
|
2004-05-10 17:07:20 +00:00
|
|
|
#include <w32k.h>
|
2003-03-20 03:06:52 +00:00
|
|
|
|
2005-06-29 07:09:25 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2006-01-08 23:26:03 +00:00
|
|
|
INT __cdecl abs(INT nm);
|
2003-08-16 05:12:37 +00:00
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
#define FILL_EDGE_ALLOC_TAG 0x45465044
|
2003-03-20 03:06:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** This struct is used for book keeping during polygon filling routines.
|
|
|
|
*/
|
2003-08-16 04:47:41 +00:00
|
|
|
typedef struct _tagFILL_EDGE
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-15 18:51:32 +00:00
|
|
|
/*Basic line information*/
|
|
|
|
int FromX;
|
|
|
|
int FromY;
|
|
|
|
int ToX;
|
|
|
|
int ToY;
|
|
|
|
int dx;
|
|
|
|
int dy;
|
2003-08-16 04:47:41 +00:00
|
|
|
int absdx, absdy;
|
|
|
|
int x, y;
|
|
|
|
int xmajor;
|
2003-08-15 18:51:32 +00:00
|
|
|
|
|
|
|
/*Active Edge List information*/
|
2003-08-16 04:47:41 +00:00
|
|
|
int XIntercept[2];
|
2003-08-15 18:51:32 +00:00
|
|
|
int Error;
|
|
|
|
int ErrorMax;
|
2003-08-16 04:47:41 +00:00
|
|
|
int XDirection, YDirection;
|
2003-08-15 18:51:32 +00:00
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
/* The next edge in the active Edge List*/
|
|
|
|
struct _tagFILL_EDGE * pNext;
|
|
|
|
} FILL_EDGE;
|
2003-03-20 03:06:52 +00:00
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
typedef struct _FILL_EDGE_LIST
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
int Count;
|
|
|
|
FILL_EDGE** Edges;
|
|
|
|
} FILL_EDGE_LIST;
|
2003-03-20 03:06:52 +00:00
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
#if 0
|
2003-08-15 18:51:32 +00:00
|
|
|
static
|
|
|
|
void
|
2003-08-16 04:47:41 +00:00
|
|
|
DEBUG_PRINT_ACTIVE_EDGELIST ( FILL_EDGE* list )
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
FILL_EDGE* pThis = list;
|
|
|
|
if (0 == list)
|
|
|
|
{
|
|
|
|
DPRINT1("List is NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(0 != pThis)
|
|
|
|
{
|
|
|
|
//DPRINT1("EDGE: (%d, %d) to (%d, %d)\n", pThis->FromX, pThis->FromY, pThis->ToX, pThis->ToY);
|
|
|
|
DPRINT1("EDGE: [%d,%d]\n", pThis->XIntercept[0], pThis->XIntercept[1] );
|
|
|
|
pThis = pThis->pNext;
|
|
|
|
}
|
2003-03-20 03:06:52 +00:00
|
|
|
}
|
2003-08-16 04:47:41 +00:00
|
|
|
#else
|
|
|
|
#define DEBUG_PRINT_ACTIVE_EDGELIST(x)
|
|
|
|
#endif
|
2003-03-20 03:06:52 +00:00
|
|
|
|
|
|
|
/*
|
2003-08-16 04:47:41 +00:00
|
|
|
** Hide memory clean up.
|
2003-03-20 03:06:52 +00:00
|
|
|
*/
|
2003-08-15 18:51:32 +00:00
|
|
|
static
|
|
|
|
void
|
|
|
|
FASTCALL
|
2003-08-16 04:47:41 +00:00
|
|
|
POLYGONFILL_DestroyEdgeList(FILL_EDGE_LIST* list)
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
int i;
|
|
|
|
if ( list )
|
2003-08-15 18:51:32 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
if ( list->Edges )
|
|
|
|
{
|
|
|
|
for ( i = 0; i < list->Count; i++ )
|
|
|
|
{
|
|
|
|
if ( list->Edges[i] )
|
|
|
|
EngFreeMem ( list->Edges[i] );
|
|
|
|
}
|
|
|
|
EngFreeMem ( list->Edges );
|
|
|
|
}
|
|
|
|
EngFreeMem ( list );
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
2003-03-20 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** This makes and initiaizes an Edge struct for a line between two points.
|
|
|
|
*/
|
2003-08-15 18:51:32 +00:00
|
|
|
static
|
2003-08-16 04:47:41 +00:00
|
|
|
FILL_EDGE*
|
2003-08-15 18:51:32 +00:00
|
|
|
FASTCALL
|
|
|
|
POLYGONFILL_MakeEdge(POINT From, POINT To)
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
FILL_EDGE* rc = (FILL_EDGE*)EngAllocMem(FL_ZERO_MEMORY, sizeof(FILL_EDGE), FILL_EDGE_ALLOC_TAG);
|
2003-08-15 18:51:32 +00:00
|
|
|
|
|
|
|
if (0 == rc)
|
|
|
|
return NULL;
|
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
//DPRINT1("Making Edge: (%d, %d) to (%d, %d)\n", From.x, From.y, To.x, To.y);
|
2003-08-15 18:51:32 +00:00
|
|
|
//Now Fill the struct.
|
|
|
|
if ( To.y < From.y )
|
|
|
|
{
|
|
|
|
rc->FromX = To.x;
|
|
|
|
rc->FromY = To.y;
|
|
|
|
rc->ToX = From.x;
|
|
|
|
rc->ToY = From.y;
|
|
|
|
rc->YDirection = -1;
|
2003-08-16 21:17:20 +00:00
|
|
|
|
2003-08-17 17:32:58 +00:00
|
|
|
// lines that go up get walked backwards, so need to be offset
|
|
|
|
// by -1 in order to make the walk identically on a pixel-level
|
|
|
|
rc->Error = -1;
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rc->FromX = From.x;
|
|
|
|
rc->FromY = From.y;
|
|
|
|
rc->ToX = To.x;
|
|
|
|
rc->ToY = To.y;
|
|
|
|
rc->YDirection = 1;
|
2003-08-16 21:17:20 +00:00
|
|
|
|
2003-08-17 17:32:58 +00:00
|
|
|
rc->Error = 0;
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
rc->x = rc->FromX;
|
|
|
|
rc->y = rc->FromY;
|
2003-08-15 18:51:32 +00:00
|
|
|
rc->dx = rc->ToX - rc->FromX;
|
|
|
|
rc->dy = rc->ToY - rc->FromY;
|
2003-08-16 04:47:41 +00:00
|
|
|
rc->absdx = abs(rc->dx);
|
|
|
|
rc->absdy = abs(rc->dy);
|
|
|
|
|
|
|
|
rc->xmajor = rc->absdx > rc->absdy;
|
2003-08-15 18:51:32 +00:00
|
|
|
|
2004-04-09 20:03:21 +00:00
|
|
|
rc->ErrorMax = max(rc->absdx,rc->absdy);
|
2003-08-15 18:51:32 +00:00
|
|
|
|
2003-08-16 21:17:20 +00:00
|
|
|
rc->Error += rc->ErrorMax / 2;
|
2003-08-15 18:51:32 +00:00
|
|
|
|
|
|
|
rc->XDirection = (rc->dx < 0)?(-1):(1);
|
|
|
|
|
|
|
|
rc->pNext = 0;
|
|
|
|
|
2003-08-17 17:32:58 +00:00
|
|
|
//DPRINT("MakeEdge (%i,%i)->(%i,%i) d=(%i,%i) dir=(%i,%i) err=%i max=%i\n",
|
|
|
|
// From.x, From.y, To.x, To.y, rc->dx, rc->dy, rc->XDirection, rc->YDirection, rc->Error, rc->ErrorMax );
|
2003-08-15 18:51:32 +00:00
|
|
|
|
|
|
|
return rc;
|
2003-03-20 03:06:52 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
** My Edge comparison routine.
|
|
|
|
** This is for scan converting polygon fill.
|
2003-08-15 18:51:32 +00:00
|
|
|
** First sort by MinY, then Minx, then slope.
|
2003-03-20 03:06:52 +00:00
|
|
|
**
|
|
|
|
** This comparison will help us determine which
|
|
|
|
** lines will become active first when scanning from
|
|
|
|
** top (min y) to bottom (max y).
|
|
|
|
**
|
2005-05-08 02:11:54 +00:00
|
|
|
** Return Value Meaning
|
|
|
|
** Negative integer element1 < element2
|
|
|
|
** Zero element1 = element2
|
|
|
|
** Positive integer element1 > element2
|
2003-03-20 03:06:52 +00:00
|
|
|
*/
|
2003-08-15 18:51:32 +00:00
|
|
|
static
|
|
|
|
INT
|
|
|
|
FASTCALL
|
2003-08-16 04:47:41 +00:00
|
|
|
FILL_EDGE_Compare(FILL_EDGE* Edge1, FILL_EDGE* Edge2)
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
int e1 = Edge1->XIntercept[0] + Edge1->XIntercept[1];
|
|
|
|
int e2 = Edge2->XIntercept[0] + Edge2->XIntercept[1];
|
|
|
|
|
|
|
|
return e1 - e2;
|
2003-03-20 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Insert an edge into a list keeping the list in order.
|
|
|
|
*/
|
2003-08-15 18:51:32 +00:00
|
|
|
static
|
|
|
|
void
|
|
|
|
FASTCALL
|
2003-08-16 04:47:41 +00:00
|
|
|
POLYGONFILL_ActiveListInsert(FILL_EDGE** activehead, FILL_EDGE* NewEdge )
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
FILL_EDGE *pPrev, *pThis;
|
|
|
|
//DPRINT1("In POLYGONFILL_ActiveListInsert()\n");
|
|
|
|
ASSERT ( activehead && NewEdge );
|
|
|
|
if ( !*activehead )
|
2003-08-15 18:51:32 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
NewEdge->pNext = NULL;
|
|
|
|
*activehead = NewEdge;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
** First lets check to see if we have a new smallest value.
|
|
|
|
*/
|
|
|
|
if (FILL_EDGE_Compare(NewEdge, *activehead) <= 0)
|
|
|
|
{
|
|
|
|
NewEdge->pNext = *activehead;
|
|
|
|
*activehead = NewEdge;
|
|
|
|
return;
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
2003-08-16 04:47:41 +00:00
|
|
|
/*
|
|
|
|
** Ok, now scan to the next spot to put this item.
|
|
|
|
*/
|
|
|
|
pThis = *activehead;
|
|
|
|
pPrev = NULL;
|
|
|
|
while ( pThis && FILL_EDGE_Compare(pThis, NewEdge) < 0 )
|
|
|
|
{
|
|
|
|
pPrev = pThis;
|
|
|
|
pThis = pThis->pNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(pPrev);
|
|
|
|
NewEdge->pNext = pPrev->pNext;
|
|
|
|
pPrev->pNext = NewEdge;
|
|
|
|
//DEBUG_PRINT_ACTIVE_EDGELIST(*activehead);
|
2003-03-20 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Create a list of edges for a list of points.
|
|
|
|
*/
|
2003-08-15 18:51:32 +00:00
|
|
|
static
|
2003-08-16 04:47:41 +00:00
|
|
|
FILL_EDGE_LIST*
|
2003-08-15 18:51:32 +00:00
|
|
|
FASTCALL
|
|
|
|
POLYGONFILL_MakeEdgeList(PPOINT Points, int Count)
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-15 18:51:32 +00:00
|
|
|
int CurPt = 0;
|
2003-08-16 04:47:41 +00:00
|
|
|
FILL_EDGE_LIST* list = 0;
|
|
|
|
FILL_EDGE* e = 0;
|
2003-08-15 18:51:32 +00:00
|
|
|
|
|
|
|
if ( 0 == Points || 2 > Count )
|
2003-08-16 04:47:41 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
list = (FILL_EDGE_LIST*)EngAllocMem(FL_ZERO_MEMORY, sizeof(FILL_EDGE_LIST), FILL_EDGE_ALLOC_TAG);
|
|
|
|
if ( 0 == list )
|
|
|
|
goto fail;
|
|
|
|
list->Count = 0;
|
|
|
|
list->Edges = (FILL_EDGE**)EngAllocMem(FL_ZERO_MEMORY, Count*sizeof(FILL_EDGE*), FILL_EDGE_ALLOC_TAG);
|
|
|
|
if ( !list->Edges )
|
|
|
|
goto fail;
|
2005-12-29 11:16:28 +00:00
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
memset ( list->Edges, 0, Count * sizeof(FILL_EDGE*) );
|
|
|
|
|
|
|
|
for ( CurPt = 1; CurPt < Count; ++CurPt )
|
2003-08-15 18:51:32 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
e = POLYGONFILL_MakeEdge ( Points[CurPt-1], Points[CurPt] );
|
2007-10-19 23:21:45 +00:00
|
|
|
if ( !e )
|
2003-08-16 04:47:41 +00:00
|
|
|
goto fail;
|
2005-12-29 11:16:28 +00:00
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
// if a straight horizontal line - who cares?
|
|
|
|
if ( !e->absdy )
|
|
|
|
EngFreeMem ( e );
|
2003-08-15 18:51:32 +00:00
|
|
|
else
|
2003-08-16 04:47:41 +00:00
|
|
|
list->Edges[list->Count++] = e;
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
2003-08-16 04:47:41 +00:00
|
|
|
e = POLYGONFILL_MakeEdge ( Points[CurPt-1], Points[0] );
|
|
|
|
if ( !e )
|
|
|
|
goto fail;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
if ( !e->absdy )
|
|
|
|
EngFreeMem ( e );
|
|
|
|
else
|
|
|
|
list->Edges[list->Count++] = e;
|
|
|
|
return list;
|
|
|
|
|
|
|
|
fail:
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
DPRINT1("Out Of MEMORY!!\n");
|
|
|
|
POLYGONFILL_DestroyEdgeList ( list );
|
|
|
|
return 0;
|
2003-03-20 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2005-05-08 02:11:54 +00:00
|
|
|
** This slow routine uses the data stored in the edge list to
|
2003-03-20 03:06:52 +00:00
|
|
|
** calculate the x intercepts for each line in the edge list
|
|
|
|
** for scanline Scanline.
|
|
|
|
**TODO: Get rid of this floating point arithmetic
|
|
|
|
*/
|
2003-08-15 18:51:32 +00:00
|
|
|
static
|
|
|
|
void
|
|
|
|
FASTCALL
|
2003-08-16 04:47:41 +00:00
|
|
|
POLYGONFILL_UpdateScanline(FILL_EDGE* pEdge, int Scanline)
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-15 18:51:32 +00:00
|
|
|
if ( 0 == pEdge->dy )
|
|
|
|
return;
|
2003-03-20 03:06:52 +00:00
|
|
|
|
2003-08-19 21:29:20 +00:00
|
|
|
ASSERT ( pEdge->FromY <= Scanline && pEdge->ToY > Scanline );
|
2003-08-16 04:47:41 +00:00
|
|
|
|
|
|
|
if ( pEdge->xmajor )
|
2003-08-15 18:51:32 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
int steps;
|
|
|
|
|
|
|
|
ASSERT ( pEdge->y == Scanline );
|
|
|
|
|
|
|
|
// now shoot to end of scanline collision
|
|
|
|
steps = (pEdge->ErrorMax-pEdge->Error-1)/pEdge->absdy;
|
|
|
|
if ( steps )
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
// record first collision with scanline
|
|
|
|
int x1 = pEdge->x;
|
|
|
|
pEdge->x += steps * pEdge->XDirection;
|
|
|
|
pEdge->Error += steps * pEdge->absdy;
|
|
|
|
ASSERT ( pEdge->Error < pEdge->ErrorMax );
|
2004-04-09 20:03:21 +00:00
|
|
|
pEdge->XIntercept[0] = min(x1,pEdge->x);
|
|
|
|
pEdge->XIntercept[1] = max(x1,pEdge->x);
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
2003-08-16 04:47:41 +00:00
|
|
|
else
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
pEdge->XIntercept[0] = pEdge->x;
|
|
|
|
pEdge->XIntercept[1] = pEdge->x;
|
2003-03-20 03:06:52 +00:00
|
|
|
}
|
2003-08-17 17:32:58 +00:00
|
|
|
|
|
|
|
// we should require exactly 1 step to step onto next scanline...
|
|
|
|
ASSERT ( (pEdge->ErrorMax-pEdge->Error-1) / pEdge->absdy == 0 );
|
|
|
|
pEdge->x += pEdge->XDirection;
|
|
|
|
pEdge->Error += pEdge->absdy;
|
|
|
|
ASSERT ( pEdge->Error >= pEdge->ErrorMax );
|
|
|
|
|
|
|
|
// now step onto next scanline...
|
|
|
|
pEdge->Error -= pEdge->absdx;
|
|
|
|
pEdge->y++;
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
2003-08-16 04:47:41 +00:00
|
|
|
else // then this is a y-major line
|
2003-08-15 18:51:32 +00:00
|
|
|
{
|
2003-08-17 17:32:58 +00:00
|
|
|
pEdge->XIntercept[0] = pEdge->x;
|
|
|
|
pEdge->XIntercept[1] = pEdge->x;
|
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
pEdge->Error += pEdge->absdx;
|
|
|
|
pEdge->y++;
|
2003-08-15 18:51:32 +00:00
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
if ( pEdge->Error >= pEdge->ErrorMax )
|
2003-08-15 18:51:32 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
pEdge->Error -= pEdge->ErrorMax;
|
|
|
|
pEdge->x += pEdge->XDirection;
|
|
|
|
ASSERT ( pEdge->Error < pEdge->ErrorMax );
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-16 04:47:41 +00:00
|
|
|
|
2003-08-17 17:32:58 +00:00
|
|
|
//DPRINT("Line (%d, %d) to (%d, %d) intersects scanline %d at (%d,%d)\n",
|
|
|
|
// pEdge->FromX, pEdge->FromY, pEdge->ToX, pEdge->ToY, Scanline, pEdge->XIntercept[0], pEdge->XIntercept[1] );
|
2003-03-20 03:06:52 +00:00
|
|
|
}
|
2003-08-16 04:47:41 +00:00
|
|
|
|
2003-03-20 03:06:52 +00:00
|
|
|
/*
|
|
|
|
** This method updates the Active edge collection for the scanline Scanline.
|
|
|
|
*/
|
2003-08-15 18:51:32 +00:00
|
|
|
static
|
|
|
|
void
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2003-08-16 04:47:41 +00:00
|
|
|
POLYGONFILL_BuildActiveList ( int Scanline, FILL_EDGE_LIST* list, FILL_EDGE** ActiveHead )
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
int i;
|
2003-08-15 18:51:32 +00:00
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
ASSERT ( list && ActiveHead );
|
|
|
|
*ActiveHead = 0;
|
|
|
|
for ( i = 0; i < list->Count; i++ )
|
2003-08-15 18:51:32 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
FILL_EDGE* pEdge = list->Edges[i];
|
|
|
|
ASSERT(pEdge);
|
2003-08-19 21:29:20 +00:00
|
|
|
if ( pEdge->FromY <= Scanline && pEdge->ToY > Scanline )
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
POLYGONFILL_UpdateScanline ( pEdge, Scanline );
|
|
|
|
POLYGONFILL_ActiveListInsert ( ActiveHead, pEdge );
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-20 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** This method fills the portion of the polygon that intersects with the scanline
|
|
|
|
** Scanline.
|
|
|
|
*/
|
2003-08-15 18:51:32 +00:00
|
|
|
static
|
|
|
|
void
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2003-08-16 04:47:41 +00:00
|
|
|
POLYGONFILL_FillScanLineAlternate(
|
|
|
|
PDC dc,
|
|
|
|
int ScanLine,
|
|
|
|
FILL_EDGE* ActiveHead,
|
2009-01-08 16:33:40 +00:00
|
|
|
SURFACE *psurf,
|
2004-04-09 20:03:21 +00:00
|
|
|
BRUSHOBJ *BrushObj,
|
2003-08-16 04:47:41 +00:00
|
|
|
MIX RopMode )
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
FILL_EDGE *pLeft, *pRight;
|
|
|
|
|
|
|
|
if ( !ActiveHead )
|
|
|
|
return;
|
|
|
|
|
|
|
|
pLeft = ActiveHead;
|
|
|
|
pRight = pLeft->pNext;
|
|
|
|
ASSERT(pRight);
|
2003-08-15 18:51:32 +00:00
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
while ( NULL != pRight )
|
2003-08-15 18:51:32 +00:00
|
|
|
{
|
2003-08-17 17:32:58 +00:00
|
|
|
int x1 = pLeft->XIntercept[0];
|
|
|
|
int x2 = pRight->XIntercept[1];
|
2003-08-16 04:47:41 +00:00
|
|
|
if ( x2 > x1 )
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
RECTL BoundRect;
|
|
|
|
BoundRect.top = ScanLine;
|
|
|
|
BoundRect.bottom = ScanLine + 1;
|
|
|
|
BoundRect.left = x1;
|
|
|
|
BoundRect.right = x2;
|
|
|
|
|
2003-08-17 17:32:58 +00:00
|
|
|
//DPRINT("Fill Line (%d, %d) to (%d, %d)\n",x1, ScanLine, x2, ScanLine);
|
2009-01-08 16:33:40 +00:00
|
|
|
IntEngLineTo(&psurf->SurfObj,
|
2009-03-20 01:35:49 +00:00
|
|
|
dc->rosdc.CombinedClip,
|
2005-06-20 08:31:48 +00:00
|
|
|
BrushObj,
|
|
|
|
x1,
|
|
|
|
ScanLine,
|
|
|
|
x2,
|
|
|
|
ScanLine,
|
|
|
|
&BoundRect, // Bounding rectangle
|
|
|
|
RopMode); // MIX
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
2003-08-16 04:47:41 +00:00
|
|
|
pLeft = pRight->pNext;
|
|
|
|
pRight = pLeft ? pLeft->pNext : NULL;
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2003-08-16 04:47:41 +00:00
|
|
|
POLYGONFILL_FillScanLineWinding(
|
|
|
|
PDC dc,
|
|
|
|
int ScanLine,
|
|
|
|
FILL_EDGE* ActiveHead,
|
2009-01-08 16:33:40 +00:00
|
|
|
SURFACE *psurf,
|
2004-04-09 20:03:21 +00:00
|
|
|
BRUSHOBJ *BrushObj,
|
2003-08-16 04:47:41 +00:00
|
|
|
MIX RopMode )
|
2003-08-15 18:51:32 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
FILL_EDGE *pLeft, *pRight;
|
2003-08-17 17:32:58 +00:00
|
|
|
int x1, x2, winding = 0;
|
|
|
|
RECTL BoundRect;
|
2003-08-15 18:51:32 +00:00
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
if ( !ActiveHead )
|
|
|
|
return;
|
|
|
|
|
2003-08-17 17:32:58 +00:00
|
|
|
BoundRect.top = ScanLine;
|
|
|
|
BoundRect.bottom = ScanLine + 1;
|
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
pLeft = ActiveHead;
|
|
|
|
winding = pLeft->YDirection;
|
|
|
|
pRight = pLeft->pNext;
|
|
|
|
ASSERT(pRight);
|
2003-08-15 18:51:32 +00:00
|
|
|
|
2003-08-17 17:32:58 +00:00
|
|
|
// setup first line...
|
|
|
|
x1 = pLeft->XIntercept[0];
|
|
|
|
x2 = pRight->XIntercept[1];
|
|
|
|
|
|
|
|
pLeft = pRight;
|
|
|
|
pRight = pLeft->pNext;
|
|
|
|
winding += pLeft->YDirection;
|
|
|
|
|
2003-08-16 04:47:41 +00:00
|
|
|
while ( NULL != pRight )
|
2003-08-15 18:51:32 +00:00
|
|
|
{
|
2003-08-17 17:32:58 +00:00
|
|
|
int newx1 = pLeft->XIntercept[0];
|
|
|
|
int newx2 = pRight->XIntercept[1];
|
|
|
|
if ( winding )
|
2003-08-15 18:51:32 +00:00
|
|
|
{
|
2003-08-17 17:32:58 +00:00
|
|
|
// check and see if this new line touches the previous...
|
|
|
|
if ( (newx1 >= x1 && newx1 <= x2)
|
|
|
|
|| (newx2 >= x1 && newx2 <= x2)
|
|
|
|
|| (x1 >= newx1 && x1 <= newx2)
|
|
|
|
|| (x2 >= newx2 && x2 <= newx2)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// yup, just tack it on to our existing line
|
2004-04-09 20:03:21 +00:00
|
|
|
x1 = min(x1,newx1);
|
|
|
|
x2 = max(x2,newx2);
|
2003-08-17 17:32:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// nope - render the old line..
|
|
|
|
BoundRect.left = x1;
|
|
|
|
BoundRect.right = x2;
|
|
|
|
|
|
|
|
//DPRINT("Fill Line (%d, %d) to (%d, %d)\n",x1, ScanLine, x2, ScanLine);
|
2009-01-08 16:33:40 +00:00
|
|
|
IntEngLineTo(&psurf->SurfObj,
|
2009-03-20 01:35:49 +00:00
|
|
|
dc->rosdc.CombinedClip,
|
2005-06-20 08:31:48 +00:00
|
|
|
BrushObj,
|
|
|
|
x1,
|
|
|
|
ScanLine,
|
|
|
|
x2,
|
|
|
|
ScanLine,
|
|
|
|
&BoundRect, // Bounding rectangle
|
|
|
|
RopMode); // MIX
|
2003-08-17 17:32:58 +00:00
|
|
|
|
|
|
|
x1 = newx1;
|
|
|
|
x2 = newx2;
|
|
|
|
}
|
2003-03-20 03:06:52 +00:00
|
|
|
}
|
2003-08-16 04:47:41 +00:00
|
|
|
pLeft = pRight;
|
|
|
|
pRight = pLeft->pNext;
|
|
|
|
winding += pLeft->YDirection;
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
2003-08-17 17:32:58 +00:00
|
|
|
// there will always be a line left-over, render it now...
|
|
|
|
BoundRect.left = x1;
|
|
|
|
BoundRect.right = x2;
|
|
|
|
|
|
|
|
//DPRINT("Fill Line (%d, %d) to (%d, %d)\n",x1, ScanLine, x2, ScanLine);
|
2009-01-08 16:33:40 +00:00
|
|
|
IntEngLineTo(&psurf->SurfObj,
|
2009-03-20 01:35:49 +00:00
|
|
|
dc->rosdc.CombinedClip,
|
2005-06-20 08:31:48 +00:00
|
|
|
BrushObj,
|
|
|
|
x1,
|
|
|
|
ScanLine,
|
|
|
|
x2,
|
|
|
|
ScanLine,
|
|
|
|
&BoundRect, // Bounding rectangle
|
|
|
|
RopMode); // MIX
|
2003-03-20 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
2005-05-08 02:11:54 +00:00
|
|
|
//When the fill mode is ALTERNATE, GDI fills the area between odd-numbered and
|
|
|
|
//even-numbered polygon sides on each scan line. That is, GDI fills the area between the
|
|
|
|
//first and second side, between the third and fourth side, and so on.
|
2003-03-20 03:06:52 +00:00
|
|
|
|
2005-05-08 02:11:54 +00:00
|
|
|
//WINDING Selects winding mode (fills any region with a nonzero winding value).
|
2003-08-16 04:47:41 +00:00
|
|
|
//When the fill mode is WINDING, GDI fills any region that has a nonzero winding value.
|
|
|
|
//This value is defined as the number of times a pen used to draw the polygon would go around the region.
|
2005-05-08 02:11:54 +00:00
|
|
|
//The direction of each edge of the polygon is important.
|
2003-08-16 04:47:41 +00:00
|
|
|
|
2003-08-15 18:51:32 +00:00
|
|
|
BOOL
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2003-08-16 04:47:41 +00:00
|
|
|
FillPolygon(
|
|
|
|
PDC dc,
|
2009-01-08 16:33:40 +00:00
|
|
|
SURFACE *psurf,
|
2004-04-09 20:03:21 +00:00
|
|
|
BRUSHOBJ *BrushObj,
|
2003-08-16 04:47:41 +00:00
|
|
|
MIX RopMode,
|
|
|
|
CONST PPOINT Points,
|
|
|
|
int Count,
|
|
|
|
RECTL BoundRect )
|
2003-03-20 03:06:52 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
FILL_EDGE_LIST *list = 0;
|
|
|
|
FILL_EDGE *ActiveHead = 0;
|
2003-08-15 18:51:32 +00:00
|
|
|
int ScanLine;
|
2009-03-20 04:51:26 +00:00
|
|
|
PDC_ATTR pdcattr = dc->pdcattr;
|
2003-08-16 04:47:41 +00:00
|
|
|
void
|
2008-11-29 22:48:58 +00:00
|
|
|
(APIENTRY *FillScanLine)(
|
2003-08-16 04:47:41 +00:00
|
|
|
PDC dc,
|
|
|
|
int ScanLine,
|
|
|
|
FILL_EDGE* ActiveHead,
|
2009-01-08 16:33:40 +00:00
|
|
|
SURFACE *psurf,
|
2004-04-09 20:03:21 +00:00
|
|
|
BRUSHOBJ *BrushObj,
|
2003-08-16 04:47:41 +00:00
|
|
|
MIX RopMode );
|
|
|
|
|
2003-08-17 17:32:58 +00:00
|
|
|
//DPRINT("FillPolygon\n");
|
2003-06-25 16:55:33 +00:00
|
|
|
|
2003-08-15 18:51:32 +00:00
|
|
|
/* Create Edge List. */
|
|
|
|
list = POLYGONFILL_MakeEdgeList(Points, Count);
|
|
|
|
/* DEBUG_PRINT_EDGELIST(list); */
|
|
|
|
if (NULL == list)
|
|
|
|
return FALSE;
|
|
|
|
|
2009-03-20 04:51:26 +00:00
|
|
|
if ( WINDING == pdcattr->jFillMode )
|
2003-08-16 04:47:41 +00:00
|
|
|
FillScanLine = POLYGONFILL_FillScanLineWinding;
|
|
|
|
else /* default */
|
|
|
|
FillScanLine = POLYGONFILL_FillScanLineAlternate;
|
|
|
|
|
2005-05-08 02:11:54 +00:00
|
|
|
/* For each Scanline from BoundRect.bottom to BoundRect.top,
|
2003-08-15 18:51:32 +00:00
|
|
|
* determine line segments to draw
|
|
|
|
*/
|
2003-08-17 17:32:58 +00:00
|
|
|
for ( ScanLine = BoundRect.top; ScanLine < BoundRect.bottom; ++ScanLine )
|
2003-08-15 18:51:32 +00:00
|
|
|
{
|
2003-08-16 04:47:41 +00:00
|
|
|
POLYGONFILL_BuildActiveList(ScanLine, list, &ActiveHead);
|
|
|
|
//DEBUG_PRINT_ACTIVE_EDGELIST(ActiveHead);
|
2009-01-08 16:33:40 +00:00
|
|
|
FillScanLine ( dc, ScanLine, ActiveHead, psurf, BrushObj, RopMode );
|
2003-08-15 18:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free Edge List. If any are left. */
|
|
|
|
POLYGONFILL_DestroyEdgeList(list);
|
|
|
|
|
|
|
|
return TRUE;
|
2003-05-18 17:16:18 +00:00
|
|
|
}
|
2009-03-16 03:21:00 +00:00
|
|
|
|
|
|
|
BOOL FASTCALL
|
|
|
|
IntFillPolygon(
|
|
|
|
PDC dc,
|
|
|
|
SURFACE *psurf,
|
|
|
|
BRUSHOBJ *BrushObj,
|
|
|
|
CONST PPOINT Points,
|
|
|
|
int Count,
|
|
|
|
RECTL DestRect,
|
|
|
|
POINTL *BrushOrigin)
|
|
|
|
{
|
|
|
|
FILL_EDGE_LIST *list = 0;
|
|
|
|
FILL_EDGE *ActiveHead = 0;
|
|
|
|
FILL_EDGE *pLeft, *pRight;
|
|
|
|
int ScanLine;
|
|
|
|
|
|
|
|
//DPRINT("IntFillPolygon\n");
|
|
|
|
|
|
|
|
/* Create Edge List. */
|
|
|
|
list = POLYGONFILL_MakeEdgeList(Points, Count);
|
|
|
|
/* DEBUG_PRINT_EDGELIST(list); */
|
|
|
|
if (NULL == list)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* For each Scanline from DestRect.top to DestRect.bottom, determine line segments to draw */
|
|
|
|
for ( ScanLine = DestRect.top; ScanLine < DestRect.bottom; ++ScanLine )
|
|
|
|
{
|
|
|
|
POLYGONFILL_BuildActiveList(ScanLine, list, &ActiveHead);
|
|
|
|
//DEBUG_PRINT_ACTIVE_EDGELIST(ActiveHead);
|
|
|
|
|
|
|
|
if ( !ActiveHead )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pLeft = ActiveHead;
|
|
|
|
pRight = pLeft->pNext;
|
|
|
|
ASSERT(pRight);
|
|
|
|
|
|
|
|
while ( NULL != pRight )
|
|
|
|
{
|
|
|
|
int x1 = pLeft->XIntercept[0];
|
|
|
|
int x2 = pRight->XIntercept[1];
|
|
|
|
if ( x2 > x1 )
|
|
|
|
{
|
|
|
|
RECTL LineRect;
|
|
|
|
LineRect.top = ScanLine;
|
|
|
|
LineRect.bottom = ScanLine + 1;
|
|
|
|
LineRect.left = x1;
|
|
|
|
LineRect.right = x2;
|
|
|
|
|
|
|
|
IntEngBitBlt(&psurf->SurfObj,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2009-03-20 01:35:49 +00:00
|
|
|
dc->rosdc.CombinedClip,
|
2009-03-16 03:21:00 +00:00
|
|
|
NULL,
|
|
|
|
&LineRect,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
BrushObj,
|
|
|
|
BrushOrigin,
|
|
|
|
ROP3_TO_ROP4(PATCOPY));
|
|
|
|
}
|
|
|
|
pLeft = pRight->pNext;
|
|
|
|
pRight = pLeft ? pLeft->pNext : NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free Edge List. If any are left. */
|
|
|
|
POLYGONFILL_DestroyEdgeList(list);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-05-18 17:16:18 +00:00
|
|
|
/* EOF */
|