mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
Fix some overflows in drawing.
This commit is contained in:
parent
6234f01a6d
commit
82010bf5c1
@ -1159,7 +1159,7 @@ FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int lin
|
||||
edge[0].x = edge[1].x = -XY_ONE;
|
||||
edge[0].dx = edge[1].dx = 0;
|
||||
|
||||
ptr += img.step*y;
|
||||
ptr += (int64_t)img.step*y;
|
||||
|
||||
do
|
||||
{
|
||||
@ -1188,7 +1188,7 @@ FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int lin
|
||||
}
|
||||
|
||||
edge[i].ye = ty;
|
||||
edge[i].dx = ((xe - xs)*2 + (ty - y)) / (2 * (ty - y));
|
||||
edge[i].dx = ((xe - xs)*2 + ((int64_t)ty - y)) / (2 * ((int64_t)ty - y));
|
||||
edge[i].x = xs;
|
||||
edge[i].idx = idx;
|
||||
break;
|
||||
@ -1461,7 +1461,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
|
||||
size_t step = img.step;
|
||||
int pix_size = (int)img.elemSize();
|
||||
uchar* ptr = img.ptr();
|
||||
int err = 0, dx = radius, dy = 0, plus = 1, minus = (radius << 1) - 1;
|
||||
int64_t err = 0, dx = radius, dy = 0, plus = 1, minus = (radius << 1) - 1;
|
||||
int inside = center.x >= radius && center.x < size.width - radius &&
|
||||
center.y >= radius && center.y < size.height - radius;
|
||||
|
||||
@ -1471,8 +1471,8 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
|
||||
while( dx >= dy )
|
||||
{
|
||||
int mask;
|
||||
int y11 = center.y - dy, y12 = center.y + dy, y21 = center.y - dx, y22 = center.y + dx;
|
||||
int x11 = center.x - dx, x12 = center.x + dx, x21 = center.x - dy, x22 = center.x + dy;
|
||||
int64_t y11 = center.y - dy, y12 = center.y + dy, y21 = center.y - dx, y22 = center.y + dx;
|
||||
int64_t x11 = center.x - dx, x12 = center.x + dx, x21 = center.x - dy, x22 = center.x + dy;
|
||||
|
||||
if( inside )
|
||||
{
|
||||
@ -1512,7 +1512,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
|
||||
{
|
||||
if( fill )
|
||||
{
|
||||
x11 = std::max( x11, 0 );
|
||||
x11 = std::max( x11, (int64_t)0 );
|
||||
x12 = MIN( x12, size.width - 1 );
|
||||
}
|
||||
|
||||
@ -1550,7 +1550,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
|
||||
{
|
||||
if( fill )
|
||||
{
|
||||
x21 = std::max( x21, 0 );
|
||||
x21 = std::max( x21, (int64_t)0 );
|
||||
x22 = MIN( x22, size.width - 1 );
|
||||
}
|
||||
|
||||
@ -1848,6 +1848,11 @@ void rectangle( Mat& img, Rect rec,
|
||||
CV_INSTRUMENT_REGION();
|
||||
|
||||
CV_Assert( 0 <= shift && shift <= XY_SHIFT );
|
||||
|
||||
// Crop the rectangle to right around the mat.
|
||||
rec &= Rect(-(1 << shift), -(1 << shift), ((img.cols + 2) << shift),
|
||||
((img.rows + 2) << shift));
|
||||
|
||||
if( !rec.empty() )
|
||||
rectangle( img, rec.tl(), rec.br() - Point(1<<shift,1<<shift),
|
||||
color, thickness, lineType, shift );
|
||||
|
Loading…
Reference in New Issue
Block a user