|
|
|
@ -160,21 +160,21 @@ bool clipLine( Rect img_rect, Point& pt1, Point& pt2 ) |
|
|
|
|
Initializes line iterator. |
|
|
|
|
Returns number of points on the line or negative number if error. |
|
|
|
|
*/ |
|
|
|
|
void LineIterator::init(const Size& size, int type, uchar* data, size_t dataStep, Point pt1, Point pt2, |
|
|
|
|
int connectivity, bool left_to_right) |
|
|
|
|
LineIterator::LineIterator(const Mat& img, Point pt1, Point pt2, |
|
|
|
|
int connectivity, bool left_to_right) |
|
|
|
|
{ |
|
|
|
|
count = -1; |
|
|
|
|
|
|
|
|
|
CV_Assert( connectivity == 8 || connectivity == 4 ); |
|
|
|
|
|
|
|
|
|
if( (unsigned)pt1.x >= (unsigned)(size.width) || |
|
|
|
|
(unsigned)pt2.x >= (unsigned)(size.width) || |
|
|
|
|
(unsigned)pt1.y >= (unsigned)(size.height) || |
|
|
|
|
(unsigned)pt2.y >= (unsigned)(size.height) ) |
|
|
|
|
if( (unsigned)pt1.x >= (unsigned)(img.cols) || |
|
|
|
|
(unsigned)pt2.x >= (unsigned)(img.cols) || |
|
|
|
|
(unsigned)pt1.y >= (unsigned)(img.rows) || |
|
|
|
|
(unsigned)pt2.y >= (unsigned)(img.rows) ) |
|
|
|
|
{ |
|
|
|
|
if( !clipLine( size, pt1, pt2 ) ) |
|
|
|
|
if( !clipLine( img.size(), pt1, pt2 ) ) |
|
|
|
|
{ |
|
|
|
|
ptr = data; |
|
|
|
|
ptr = img.data; |
|
|
|
|
err = plusDelta = minusDelta = plusStep = minusStep = count = 0; |
|
|
|
|
ptr0 = 0; |
|
|
|
|
step = 0; |
|
|
|
@ -183,8 +183,8 @@ void LineIterator::init(const Size& size, int type, uchar* data, size_t dataStep |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
size_t bt_pix0 = CV_ELEM_SIZE(type), bt_pix = bt_pix0; |
|
|
|
|
size_t istep = dataStep; |
|
|
|
|
size_t bt_pix0 = img.elemSize(), bt_pix = bt_pix0; |
|
|
|
|
size_t istep = img.step; |
|
|
|
|
|
|
|
|
|
int dx = pt2.x - pt1.x; |
|
|
|
|
int dy = pt2.y - pt1.y; |
|
|
|
@ -203,7 +203,7 @@ void LineIterator::init(const Size& size, int type, uchar* data, size_t dataStep |
|
|
|
|
bt_pix = (bt_pix ^ s) - s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ptr = (uchar*)(data + pt1.y * istep + pt1.x * bt_pix0);//when no Mat is attached, ptr is just a dummy address and should not be dereferenced
|
|
|
|
|
ptr = (uchar*)(img.data + pt1.y * istep + pt1.x * bt_pix0); |
|
|
|
|
|
|
|
|
|
s = dy < 0 ? -1 : 0; |
|
|
|
|
dy = (dy ^ s) - s; |
|
|
|
@ -243,8 +243,8 @@ void LineIterator::init(const Size& size, int type, uchar* data, size_t dataStep |
|
|
|
|
count = dx + dy + 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this->ptr0 = data; |
|
|
|
|
this->step = static_cast<int>(dataStep); |
|
|
|
|
this->ptr0 = img.ptr(); |
|
|
|
|
this->step = (int)img.step; |
|
|
|
|
this->elemSize = (int)bt_pix0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|