Replaced magic constant in large image handling check
authorVitaly Tuzov <terfendail@mediana.jetos.com>
Wed, 16 Nov 2016 10:36:37 +0000 (13:36 +0300)
committerVitaly Tuzov <terfendail@mediana.jetos.com>
Wed, 16 Nov 2016 14:55:04 +0000 (17:55 +0300)
3rdparty/openvx/include/openvx_hal.hpp

index f0aa3d5..b027ff0 100644 (file)
 #include <climits>
 #include <cmath>
 
+#ifndef VX_VENDOR_ID
+#define VX_VENDOR_ID VX_ID_DEFAULT
+#endif
+
 #if VX_VERSION == VX_VERSION_1_0
 
 #define VX_MEMORY_TYPE_HOST VX_IMPORT_TYPE_HOST
@@ -66,6 +70,17 @@ struct Tick
 };
 #endif
 
+inline bool dimTooBig(int size)
+{
+    if (VX_VENDOR_ID == VX_ID_KHRONOS || VX_VENDOR_ID == VX_ID_DEFAULT)
+    {
+        //OpenVX use uint32_t for image addressing
+        return ((unsigned)size > (UINT_MAX / VX_SCALE_UNITY));
+    }
+    else
+        return false;
+}
+
 //==================================================================================================
 // One more OpenVX C++ binding :-)
 // ...
@@ -349,7 +364,7 @@ inline void setConstantBorder(vx_border_t &border, vx_uint8 val)
 template <typename T>                                                                                               \
 inline int ovx_hal_##hal_func(const T *a, size_t astep, const T *b, size_t bstep, T *c, size_t cstep, int w, int h) \
 {                                                                                                                   \
-    if(w >= 4194304 || h >= 4194304)                                                                                \
+    if(dimTooBig(w) || dimTooBig(h))                                                                                \
         return CV_HAL_ERROR_NOT_IMPLEMENTED;                                                                        \
     try                                                                                                             \
     {                                                                                                               \
@@ -379,7 +394,7 @@ OVX_BINARY_OP(xor, {vxErr::check(vxuXor(ctx->ctx, ia.img, ib.img, ic.img));})
 template <typename T>
 inline int ovx_hal_mul(const T *a, size_t astep, const T *b, size_t bstep, T *c, size_t cstep, int w, int h, double scale)
 {
-    if (w >= 4194304 || h >= 4194304)
+    if(dimTooBig(w) || dimTooBig(h))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
 #ifdef _MSC_VER
     const float MAGIC_SCALE = 0x0.01010102;
@@ -418,7 +433,7 @@ inline int ovx_hal_mul(const T *a, size_t astep, const T *b, size_t bstep, T *c,
 
 inline int ovx_hal_not(const uchar *a, size_t astep, uchar *c, size_t cstep, int w, int h)
 {
-    if (w >= 4194304 || h >= 4194304)
+    if(dimTooBig(w) || dimTooBig(h))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
     try
     {
@@ -437,7 +452,7 @@ inline int ovx_hal_not(const uchar *a, size_t astep, uchar *c, size_t cstep, int
 
 inline int ovx_hal_merge8u(const uchar **src_data, uchar *dst_data, int len, int cn)
 {
-    if (len >= 4194304)
+    if(dimTooBig(len))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
     if (cn != 3 && cn != 4)
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -462,7 +477,7 @@ inline int ovx_hal_merge8u(const uchar **src_data, uchar *dst_data, int len, int
 
 inline int ovx_hal_resize(int atype, const uchar *a, size_t astep, int aw, int ah, uchar *b, size_t bstep, int bw, int bh, double inv_scale_x, double inv_scale_y, int interpolation)
 {
-    if (aw >= 4194304 || ah >= 4194304 || bw >= 4194304 || bh >= 4194304)
+    if(dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
     try
     {
@@ -503,7 +518,7 @@ inline int ovx_hal_resize(int atype, const uchar *a, size_t astep, int aw, int a
 
 inline int ovx_hal_warpAffine(int atype, const uchar *a, size_t astep, int aw, int ah, uchar *b, size_t bstep, int bw, int bh, const double M[6], int interpolation, int borderType, const double borderValue[4])
 {
-    if (aw >= 4194304 || ah >= 4194304 || bw >= 4194304 || bh >= 4194304)
+    if(dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
     try
     {
@@ -562,7 +577,7 @@ inline int ovx_hal_warpAffine(int atype, const uchar *a, size_t astep, int aw, i
 
 inline int ovx_hal_warpPerspectve(int atype, const uchar *a, size_t astep, int aw, int ah, uchar *b, size_t bstep, int bw, int bh, const double M[9], int interpolation, int borderType, const double borderValue[4])
 {
-    if (aw >= 4194304 || ah >= 4194304 || bw >= 4194304 || bh >= 4194304)
+    if(dimTooBig(aw) || dimTooBig(ah) || dimTooBig(bw) || dimTooBig(bh))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
     try
     {
@@ -707,7 +722,7 @@ inline int ovx_hal_filterFree(cvhalFilter2D *filter_context)
 
 inline int ovx_hal_filter(cvhalFilter2D *filter_context, uchar *a, size_t astep, uchar *b, size_t bstep, int w, int h, int , int , int , int )
 {
-    if (w >= 4194304 || h >= 4194304)
+    if(dimTooBig(w) || dimTooBig(h))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
     try
     {
@@ -929,7 +944,7 @@ inline int ovx_hal_morphFree(cvhalFilter2D *filter_context)
 
 inline int ovx_hal_morph(cvhalFilter2D *filter_context, uchar *a, size_t astep, uchar *b, size_t bstep, int w, int h, int , int , int , int , int , int , int , int )
 {
-    if (w >= 4194304 || h >= 4194304)
+    if(dimTooBig(w) || dimTooBig(h))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
     try
     {
@@ -961,7 +976,7 @@ inline int ovx_hal_morph(cvhalFilter2D *filter_context, uchar *a, size_t astep,
 
 inline int ovx_hal_cvtBGRtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int depth, int acn, int bcn, bool swapBlue)
 {
-    if (w >= 4194304 || h >= 4194304)
+    if(dimTooBig(w) || dimTooBig(h))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
     if (depth != CV_8U || swapBlue || acn == bcn || (acn != 3 && acn != 4) || (bcn != 3 && bcn != 4))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -986,7 +1001,7 @@ inline int ovx_hal_cvtBGRtoBGR(const uchar * a, size_t astep, uchar * b, size_t
 
 inline int ovx_hal_cvtTwoPlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int bcn, bool swapBlue, int uIdx)
 {
-    if (w >= 4194304 || h >= 4194304)
+    if(dimTooBig(w) || dimTooBig(h))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
     if (!swapBlue || (bcn != 3 && bcn != 4))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -1015,7 +1030,7 @@ inline int ovx_hal_cvtTwoPlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b,
 
 inline int ovx_hal_cvtThreePlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int bcn, bool swapBlue, int uIdx)
 {
-    if (w >= 4194304 || h >= 4194304)
+    if(dimTooBig(w) || dimTooBig(h))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
     if (!swapBlue || (bcn != 3 && bcn != 4) || uIdx || (size_t)w / 2 != astep - (size_t)w / 2)
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -1044,7 +1059,7 @@ inline int ovx_hal_cvtThreePlaneYUVtoBGR(const uchar * a, size_t astep, uchar *
 
 inline int ovx_hal_cvtBGRtoThreePlaneYUV(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int acn, bool swapBlue, int uIdx)
 {
-    if (w >= 4194304 || h >= 4194304)
+    if(dimTooBig(w) || dimTooBig(h))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
     if (!swapBlue || (acn != 3 && acn != 4) || uIdx || (size_t)w / 2 != bstep - (size_t)w / 2)
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
@@ -1069,7 +1084,7 @@ inline int ovx_hal_cvtBGRtoThreePlaneYUV(const uchar * a, size_t astep, uchar *
 
 inline int ovx_hal_cvtOnePlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, size_t bstep, int w, int h, int bcn, bool swapBlue, int uIdx, int ycn)
 {
-    if (w >= 4194304 || h >= 4194304)
+    if(dimTooBig(w) || dimTooBig(h))
         return CV_HAL_ERROR_NOT_IMPLEMENTED;
     if (!swapBlue || (bcn != 3 && bcn != 4) || uIdx)
         return CV_HAL_ERROR_NOT_IMPLEMENTED;