core: support CV_Check*() macros with 'bool' parameters
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Tue, 15 Nov 2022 09:55:22 +0000 (09:55 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Tue, 15 Nov 2022 11:47:16 +0000 (11:47 +0000)
modules/core/include/opencv2/core/check.hpp
modules/core/src/check.cpp
modules/imgcodecs/src/grfmt_webp.cpp

index d975223cc5143a1919515b1e45917af2f65158f3..76445a9934bb81ba728f0a0a0c952ba2f6f6e968 100644 (file)
@@ -65,6 +65,7 @@ struct CheckContext {
     static const cv::detail::CheckContext CV__CHECK_LOCATION_VARNAME(id) = \
             { CV__CHECK_FUNCTION, CV__CHECK_FILENAME, __LINE__, testOp, "" message, "" p1_str, "" p2_str }
 
+CV_EXPORTS void CV_NORETURN check_failed_auto(const bool v1, const bool v2, const CheckContext& ctx);
 CV_EXPORTS void CV_NORETURN check_failed_auto(const int v1, const int v2, const CheckContext& ctx);
 CV_EXPORTS void CV_NORETURN check_failed_auto(const size_t v1, const size_t v2, const CheckContext& ctx);
 CV_EXPORTS void CV_NORETURN check_failed_auto(const float v1, const float v2, const CheckContext& ctx);
@@ -74,6 +75,9 @@ CV_EXPORTS void CV_NORETURN check_failed_MatDepth(const int v1, const int v2, co
 CV_EXPORTS void CV_NORETURN check_failed_MatType(const int v1, const int v2, const CheckContext& ctx);
 CV_EXPORTS void CV_NORETURN check_failed_MatChannels(const int v1, const int v2, const CheckContext& ctx);
 
+CV_EXPORTS void CV_NORETURN check_failed_true(const bool v, const CheckContext& ctx);
+CV_EXPORTS void CV_NORETURN check_failed_false(const bool v, const CheckContext& ctx);
+
 CV_EXPORTS void CV_NORETURN check_failed_auto(const int v, const CheckContext& ctx);
 CV_EXPORTS void CV_NORETURN check_failed_auto(const size_t v, const CheckContext& ctx);
 CV_EXPORTS void CV_NORETURN check_failed_auto(const float v, const CheckContext& ctx);
@@ -134,6 +138,12 @@ CV_EXPORTS void CV_NORETURN check_failed_MatChannels(const int v, const CheckCon
 /// Example: v == A || v == B
 #define CV_Check(v, test_expr, msg)  CV__CHECK_CUSTOM_TEST(_, auto, v, (test_expr), #v, #test_expr, msg)
 
+/// Example: v == true
+#define CV_CheckTrue(v, msg)  CV__CHECK_CUSTOM_TEST(_, true, v, v, #v, "", msg)
+
+/// Example: v == false
+#define CV_CheckFalse(v, msg)  CV__CHECK_CUSTOM_TEST(_, false, v, (!(v)), #v, "", msg)
+
 /// Some complex conditions: CV_Check(src2, src2.empty() || (src2.type() == src1.type() && src2.size() == src1.size()), "src2 should have same size/type as src1")
 // TODO define pretty-printers
 
index 4988b87c340e9b7db4de63505417c2aa45bec70e..1c0471a34ccb25ccb86380165fdd96b3c3435bf0 100644 (file)
@@ -97,6 +97,10 @@ void check_failed_MatChannels(const int v1, const int v2, const CheckContext& ct
 {
     check_failed_auto_<int>(v1, v2, ctx);
 }
+void check_failed_auto(const bool v1, const bool v2, const CheckContext& ctx)
+{
+    check_failed_auto_<bool>(v1, v2, ctx);
+}
 void check_failed_auto(const int v1, const int v2, const CheckContext& ctx)
 {
     check_failed_auto_<int>(v1, v2, ctx);
@@ -151,6 +155,22 @@ void check_failed_MatChannels(const int v, const CheckContext& ctx)
 {
     check_failed_auto_<int>(v, ctx);
 }
+void check_failed_true(const bool v, const CheckContext& ctx)
+{
+    CV_UNUSED(v);
+    std::stringstream ss;
+    ss  << ctx.message << ":" << std::endl
+        << "    '" << ctx.p1_str << "' must be 'true'";
+    cv::errorNoReturn(cv::Error::StsError, ss.str(), ctx.func, ctx.file, ctx.line);
+}
+void check_failed_false(const bool v, const CheckContext& ctx)
+{
+    CV_UNUSED(v);
+    std::stringstream ss;
+    ss  << ctx.message << ":" << std::endl
+        << "    '" << ctx.p1_str << "' must be 'false'";
+    cv::errorNoReturn(cv::Error::StsError, ss.str(), ctx.func, ctx.file, ctx.line);
+}
 void check_failed_auto(const int v, const CheckContext& ctx)
 {
     check_failed_auto_<int>(v, ctx);
index 99eb09e105e6649a484d4e51ef4352ced0d97745..1f530e7b9b57baa4ded3d9272028e1ee1be880d9 100644 (file)
@@ -126,7 +126,7 @@ bool WebPDecoder::readHeader()
     WebPBitstreamFeatures features;
     if (VP8_STATUS_OK == WebPGetFeatures(header, sizeof(header), &features))
     {
-        CV_CheckEQ(features.has_animation, false, "WebP backend does not support animated webp images");
+        CV_CheckEQ(features.has_animation, 0, "WebP backend does not support animated webp images");
 
         m_width  = features.width;
         m_height = features.height;