static const type max_allowable = INT_MAX;
};
+// inclusive maxVal !!!
template<int depth>
-bool chackIntegerRang(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value)
+bool checkIntegerRange(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value)
{
typedef mat_type_assotiations<depth> type_ass;
{
return true;
}
- else if (minVal >= type_ass::max_allowable || maxVal <= type_ass::min_allowable || maxVal <= minVal)
+ else if (minVal > type_ass::max_allowable || maxVal < type_ass::min_allowable || maxVal < minVal)
{
bad_pt = cv::Point(0,0);
return false;
for (int j = 0; j < as_one_channel.rows; ++j)
for (int i = 0; i < as_one_channel.cols; ++i)
{
- if (as_one_channel.at<typename type_ass::type>(j ,i) < minVal || as_one_channel.at<typename type_ass::type>(j ,i) >= maxVal)
+ if (as_one_channel.at<typename type_ass::type>(j ,i) < minVal || as_one_channel.at<typename type_ass::type>(j ,i) > maxVal)
{
bad_pt.y = j ;
bad_pt.x = i % src.channels();
return true;
}
-typedef bool (*check_pange_function)(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value);
+typedef bool (*check_range_function)(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value);
-check_pange_function check_range_functions[] =
+check_range_function check_range_functions[] =
{
- &chackIntegerRang<CV_8U>,
- &chackIntegerRang<CV_8S>,
- &chackIntegerRang<CV_16U>,
- &chackIntegerRang<CV_16S>,
- &chackIntegerRang<CV_32S>
+ &checkIntegerRange<CV_8U>,
+ &checkIntegerRange<CV_8S>,
+ &checkIntegerRange<CV_16U>,
+ &checkIntegerRange<CV_16S>,
+ &checkIntegerRange<CV_32S>
};
bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double maxVal)
if (depth < CV_32F)
{
- int minVali = cvFloor(minVal);
- int maxVali = cvCeil(maxVal);
+ // see "Bug #1784"
+ int minVali = minVal<(-INT_MAX - 1) ? (-INT_MAX - 1) : cvFloor(minVal);
+ int maxVali = maxVal>INT_MAX ? INT_MAX : cvCeil(maxVal) - 1; // checkIntegerRang() use inclusive maxVal
(check_range_functions[depth])(src, badPt, minVali, maxVali, badValue);
}
}
}
+class Core_CheckRange_Empty : public cvtest::BaseTest
+{
+public:
+ Core_CheckRange_Empty(){}
+ ~Core_CheckRange_Empty(){}
+protected:
+ virtual void run( int start_from );
+};
+
+void Core_CheckRange_Empty::run( int )
+{
+ cv::Mat m;
+ ASSERT_TRUE( cv::checkRange(m) );
+}
+
+TEST(Core_CheckRange_Empty, accuracy) { Core_CheckRange_Empty test; test.safe_run(); }
+
+class Core_CheckRange_INT_MAX : public cvtest::BaseTest
+{
+public:
+ Core_CheckRange_INT_MAX(){}
+ ~Core_CheckRange_INT_MAX(){}
+protected:
+ virtual void run( int start_from );
+};
+
+void Core_CheckRange_INT_MAX::run( int )
+{
+ cv::Mat m(3, 3, CV_32SC1, cv::Scalar(INT_MAX));
+ ASSERT_FALSE( cv::checkRange(m, true, 0, 0, INT_MAX) );
+ ASSERT_TRUE( cv::checkRange(m) );
+}
+
+TEST(Core_CheckRange_INT_MAX, accuracy) { Core_CheckRange_INT_MAX test; test.safe_run(); }
+
template <typename T> class Core_CheckRange : public testing::Test {};
TYPED_TEST_CASE_P(Core_CheckRange);