edge[2];
int delta = 1 << shift >> 1;
- int i, y, imin = 0, left = 0, right = 1;
+ int i, y, imin = 0;
int edges = npts;
int64 xmin, xmax, ymin, ymax;
uchar* ptr = img.ptr();
{
if( y >= edge[i].ye )
{
- int idx = edge[i].idx, di = edge[i].di;
- int64 xs = 0, xe;
+ int idx0 = edge[i].idx, di = edge[i].di;
+ int idx = idx0 + di;
+ if (idx >= npts) idx -= npts;
int ty = 0;
- for(;;)
+ for (; edges-- > 0; )
{
ty = (int)((v[idx].y + delta) >> shift);
- if( ty > y || edges == 0 )
+ if (ty > y)
+ {
+ int64 xs = v[idx0].x;
+ int64 xe = v[idx].x;
+ if (shift != XY_SHIFT)
+ {
+ xs <<= XY_SHIFT - shift;
+ xe <<= XY_SHIFT - shift;
+ }
+
+ edge[i].ye = ty;
+ edge[i].dx = ((xe - xs)*2 + (ty - y)) / (2 * (ty - y));
+ edge[i].x = xs;
+ edge[i].idx = idx;
break;
- xs = v[idx].x;
+ }
+ idx0 = idx;
idx += di;
- idx -= ((idx < npts) - 1) & npts; /* idx -= idx >= npts ? npts : 0 */
- edges--;
+ if (idx >= npts) idx -= npts;
}
-
- xs <<= XY_SHIFT - shift;
- xe = v[idx].x << (XY_SHIFT - shift);
-
- /* no more edges */
- if( y >= ty)
- return;
-
- edge[i].ye = ty;
- edge[i].dx = ((xe - xs)*2 + (ty - y)) / (2 * (ty - y));
- edge[i].x = xs;
- edge[i].idx = idx;
}
}
}
- if( edge[left].x > edge[right].x )
+ if (y >= 0)
{
- left ^= 1;
- right ^= 1;
- }
+ int left = 0, right = 1;
+ if (edge[0].x > edge[1].x)
+ {
+ left = 1, right = 0;
+ }
- if( y >= 0 )
- {
int xx1 = (int)((edge[left].x + delta1) >> XY_SHIFT);
int xx2 = (int)((edge[right].x + delta2) >> XY_SHIFT);
ICV_HLINE( ptr, xx1, xx2, color, pix_size );
}
}
+ else
+ {
+ // TODO optimize scan for negative y
+ }
- edge[left].x += edge[left].dx;
- edge[right].x += edge[right].dx;
+ edge[0].x += edge[0].dx;
+ edge[1].x += edge[1].dx;
ptr += img.step;
}
while( ++y <= (int)ymax );