ILubyte *iScanFill() { Edge **edges = NULL, *active = NULL/*, *temp*/; ILuint i, scan; iRegionMask = NULL; if ((RegionPointsi == NULL && RegionPointsf == NULL) || PointNum == 0) return NULL; if (RegionPointsf) { RegionPointsi = (ILpointi*)ialloc(sizeof(ILpointi) * PointNum); if (RegionPointsi == NULL) goto error; } for (i = 0; i < PointNum; i++) { if (RegionPointsf) { RegionPointsi[i].x = (ILuint)(iluCurImage->Width * RegionPointsf[i].x); RegionPointsi[i].y = (ILuint)(iluCurImage->Height * RegionPointsf[i].y); } if (RegionPointsi[i].x >= (ILint)iluCurImage->Width || RegionPointsi[i].y >= (ILint)iluCurImage->Height) goto error; } edges = (Edge**)ialloc(sizeof(Edge*) * iluCurImage->Height); iRegionMask = (ILubyte*)ialloc(iluCurImage->Width * iluCurImage->Height * iluCurImage->Depth); if (edges == NULL || iRegionMask == NULL) goto error; imemclear(iRegionMask, iluCurImage->Width * iluCurImage->Height * iluCurImage->Depth); for (i = 0; i < iluCurImage->Height; i++) { edges[i] = (Edge*)ialloc(sizeof(Edge)); edges[i]->next = NULL; } BuildEdgeList(PointNum, RegionPointsi, edges); active = (Edge*)ialloc(sizeof(Edge)); active->next = NULL; for (scan = 0; scan < iluCurImage->Height; scan++) { BuildActiveList(scan, active, edges); if (active->next) { FillScan(scan, active); UpdateActiveList(scan, active); ResortActiveList(active); } } // Free edge records that have been allocated. /*for (i = 0; i < iluCurImage->Height; i++) { while (edges[i]) { temp = edges[i]->next; ifree(edges[i]); edges[i] = temp; } }*/ ifree(edges); if (RegionPointsf) { ifree(RegionPointsi); RegionPointsi = NULL; } return iRegionMask; error: if (RegionPointsf) { ifree(RegionPointsi); RegionPointsi = NULL; } // Free edge records that have been allocated. ifree(edges); ifree(iRegionMask); return NULL; }
/// /// ScanFill() VOID ScanFill( FRAME *frame ) { int cnt = frame->selection.nVertices; Point *pts = frame->selection.vertices; EdgePtr *edges, active; int scan, i; edges = pmalloc( sizeof(EdgePtr) * (frame->pix->height+1) ); D(bug("ScanFill: allocating edges\n")); for( i = 0; i <= frame->pix->height; i++ ) { edges[i] = smalloc( sizeof(EdgeRec) ); edges[i]->next = NULL; } active = smalloc( sizeof(EdgeRec) ); active->next = NULL; BuildEdgeList( cnt, pts, edges ); for( scan = 0; scan < frame->pix->height; scan++ ) { D(bug(" Line=%d\n",scan)); D(bug("List: edges[%d]\n",scan)); D(PrintList( "", edges[scan] )); BuildActiveList( scan, edges, active ); // D(bug("List: edges[%d]\n",scan)); // D(PrintList( "", edges[scan] )); D(PrintList( "active", active )); if( active->next ) { ROWPTR cp; cp = GetPixelRow( frame->selection.mask, scan, globxd ); bzero( cp, frame->pix->bytes_per_row ); FillScan( cp, scan, active ); PutPixelRow( frame->selection.mask, scan, cp, globxd ); UpdateActiveList( scan, active ); ResortActiveList( active ); } } D(bug(" ScanFill done\n")); #if 1 for( i = 0; i <= frame->pix->height; i++ ) { if( edges[i] ) { sfree( edges[i] ); } } #endif #if 1 if( active ) { EdgePtr e,ep; D(PrintList( "active", active )); ep = active->next; while( ep ) { e = ep->next; sfree( ep ); ep = e; } sfree( active ); } #endif pfree(edges); }