Commit 98181e9d authored by Alexander Alekhin's avatar Alexander Alekhin

imgproc/drawing: minor refactoring in FillConvexPoly

parent 7e0f1ec0
...@@ -1099,7 +1099,7 @@ FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int lin ...@@ -1099,7 +1099,7 @@ FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int lin
edge[2]; edge[2];
int delta = 1 << shift >> 1; int delta = 1 << shift >> 1;
int i, y, imin = 0, left = 0, right = 1; int i, y, imin = 0;
int edges = npts; int edges = npts;
int64 xmin, xmax, ymin, ymax; int64 xmin, xmax, ymin, ymax;
uchar* ptr = img.ptr(); uchar* ptr = img.ptr();
...@@ -1181,44 +1181,46 @@ FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int lin ...@@ -1181,44 +1181,46 @@ FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int lin
{ {
if( y >= edge[i].ye ) if( y >= edge[i].ye )
{ {
int idx = edge[i].idx, di = edge[i].di; int idx0 = edge[i].idx, di = edge[i].di;
int64 xs = 0, xe; int idx = idx0 + di;
if (idx >= npts) idx -= npts;
int ty = 0; int ty = 0;
for(;;) for (; edges-- > 0; )
{ {
ty = (int)((v[idx].y + delta) >> shift); ty = (int)((v[idx].y + delta) >> shift);
if( ty > y || edges == 0 ) if (ty > y)
break; {
xs = v[idx].x; int64 xs = v[idx0].x;
idx += di; int64 xe = v[idx].x;
idx -= ((idx < npts) - 1) & npts; /* idx -= idx >= npts ? npts : 0 */ if (shift != XY_SHIFT)
edges--; {
}
xs <<= XY_SHIFT - shift; xs <<= XY_SHIFT - shift;
xe = v[idx].x << (XY_SHIFT - shift); xe <<= XY_SHIFT - shift;
}
/* no more edges */
if( y >= ty)
return;
edge[i].ye = ty; edge[i].ye = ty;
edge[i].dx = ((xe - xs)*2 + (ty - y)) / (2 * (ty - y)); edge[i].dx = ((xe - xs)*2 + (ty - y)) / (2 * (ty - y));
edge[i].x = xs; edge[i].x = xs;
edge[i].idx = idx; edge[i].idx = idx;
break;
}
idx0 = idx;
idx += di;
if (idx >= npts) idx -= npts;
}
} }
} }
} }
if( edge[left].x > edge[right].x ) if (y >= 0)
{
int left = 0, right = 1;
if (edge[0].x > edge[1].x)
{ {
left ^= 1; left = 1, right = 0;
right ^= 1;
} }
if( y >= 0 )
{
int xx1 = (int)((edge[left].x + delta1) >> XY_SHIFT); int xx1 = (int)((edge[left].x + delta1) >> XY_SHIFT);
int xx2 = (int)((edge[right].x + delta2) >> XY_SHIFT); int xx2 = (int)((edge[right].x + delta2) >> XY_SHIFT);
...@@ -1231,9 +1233,13 @@ FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int lin ...@@ -1231,9 +1233,13 @@ FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int lin
ICV_HLINE( ptr, xx1, xx2, color, pix_size ); ICV_HLINE( ptr, xx1, xx2, color, pix_size );
} }
} }
else
{
// TODO optimize scan for negative y
}
edge[left].x += edge[left].dx; edge[0].x += edge[0].dx;
edge[right].x += edge[right].dx; edge[1].x += edge[1].dx;
ptr += img.step; ptr += img.step;
} }
while( ++y <= (int)ymax ); while( ++y <= (int)ymax );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment