1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

core: fix adjustROI behavior on indexes overflow

This commit is contained in:
Vladislav Sovrasov
2017-02-22 14:00:22 +03:00
parent 526220a171
commit 14451f3f06
4 changed files with 42 additions and 4 deletions
+7 -2
View File
@@ -599,8 +599,13 @@ UMat& UMat::adjustROI( int dtop, int dbottom, int dleft, int dright )
Size wholeSize; Point ofs;
size_t esz = elemSize();
locateROI( wholeSize, ofs );
int row1 = std::max(ofs.y - dtop, 0), row2 = std::min(ofs.y + rows + dbottom, wholeSize.height);
int col1 = std::max(ofs.x - dleft, 0), col2 = std::min(ofs.x + cols + dright, wholeSize.width);
int row1 = std::min(std::max(ofs.y - dtop, 0), wholeSize.height), row2 = std::max(0, std::min(ofs.y + rows + dbottom, wholeSize.height));
int col1 = std::min(std::max(ofs.x - dleft, 0), wholeSize.width), col2 = std::max(0, std::min(ofs.x + cols + dright, wholeSize.width));
if(row1 > row2)
std::swap(row1, row2);
if(col1 > col2)
std::swap(col1, col2);
offset += (row1 - ofs.y)*step + (col1 - ofs.x)*esz;
rows = row2 - row1; cols = col2 - col1;
size.p[0] = rows; size.p[1] = cols;