Skip to content

Commit

Permalink
use better region compressor for polygon2region
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Aug 4, 2024
1 parent 024d3a0 commit 548b9d2
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions img/region.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,35 +1007,6 @@ superimpose_outline( PRegionRec region, Point *pts, int count)
return region;
}

/* compress region vertically */
static PRegionRec
compress_region( PRegionRec region)
{
int i, n;
Box *prev, *curr;
for (
i = 1, n = region-> n_boxes, prev = region->boxes, curr = prev + 1;
i < n;
i++, curr++
) {
if (
curr->x == prev->x &&
curr->y == prev->y + prev->height &&
curr->width == prev->width
) {
prev->height += curr->height;
region-> n_boxes--;
} else {
if ( curr - prev > 1 ) {
memmove( prev + 1, curr, sizeof(Box) * (n - i));
curr = prev + 1;
}
prev = curr;
}
}
return region;
}

static PRegionRec
points2region( PolyPointBlock *block, int outline)
{
Expand Down Expand Up @@ -1131,7 +1102,8 @@ img_region_polygon( Point *pts, int count, int rule)
PRegionRec new = superimpose_outline(region, pts, count);
if (new) region = new;
}
return compress_region(region);
img_region_compress(region);
return region;
}

#ifdef __cplusplus
Expand Down

0 comments on commit 548b9d2

Please sign in to comment.