diff --git a/3rdparty/openvx/include/openvx_hal.hpp b/3rdparty/openvx/include/openvx_hal.hpp index e21b2ea4b0..d4745168ac 100644 --- a/3rdparty/openvx/include/openvx_hal.hpp +++ b/3rdparty/openvx/include/openvx_hal.hpp @@ -171,10 +171,6 @@ struct vxImage addr.dim_y = h; addr.stride_x = sizeof(T); addr.stride_y = (vx_int32)step; - addr.scale_x = VX_SCALE_UNITY; - addr.scale_y = VX_SCALE_UNITY; - addr.step_x = 1; - addr.step_y = 1; void *ptrs[] = { (void*)data }; img = vxCreateImageFromHandle(ctx.ctx, VX_Traits::ImgType, &addr, ptrs, VX_MEMORY_TYPE_HOST); vxErr::check(img); @@ -200,12 +196,9 @@ struct vxImage addr[0].dim_y = h; addr[0].stride_x = imgType == VX_DF_IMAGE_U8 ? 1 : imgType == VX_DF_IMAGE_RGB ? 3 : - (imgType == VX_DF_IMAGE_U16 || imgType == VX_DF_IMAGE_S16) ? 2 : 4; + (imgType == VX_DF_IMAGE_U16 || imgType == VX_DF_IMAGE_S16 || + imgType == VX_DF_IMAGE_UYVY || imgType == VX_DF_IMAGE_YUYV) ? 2 : 4; addr[0].stride_y = (vx_int32)step; - addr[0].scale_x = VX_SCALE_UNITY; - addr[0].scale_y = VX_SCALE_UNITY; - addr[0].step_x = (imgType == VX_DF_IMAGE_UYVY || imgType == VX_DF_IMAGE_YUYV) ? 2 : 1; - addr[0].step_y = 1; ptrs[0] = (void*)data; break; case VX_DF_IMAGE_NV12: @@ -214,19 +207,11 @@ struct vxImage addr[0].dim_y = h; addr[0].stride_x = 1; addr[0].stride_y = (vx_int32)step; - addr[0].scale_x = VX_SCALE_UNITY; - addr[0].scale_y = VX_SCALE_UNITY; - addr[0].step_x = 1; - addr[0].step_y = 1; ptrs[0] = (void*)data; - addr[1].dim_x = (w + 1) / 2; - addr[1].dim_y = (h + 1) / 2; + addr[1].dim_x = w / 2; + addr[1].dim_y = h / 2; addr[1].stride_x = 2; addr[1].stride_y = (vx_int32)step; - addr[1].scale_x = VX_SCALE_UNITY; - addr[1].scale_y = VX_SCALE_UNITY; - addr[1].step_x = 2; - addr[1].step_y = 2; ptrs[1] = (void*)(data + h * step); break; case VX_DF_IMAGE_IYUV: @@ -235,29 +220,19 @@ struct vxImage addr[0].dim_y = h; addr[0].stride_x = 1; addr[0].stride_y = (vx_int32)step; - addr[0].scale_x = VX_SCALE_UNITY; - addr[0].scale_y = VX_SCALE_UNITY; - addr[0].step_x = 1; - addr[0].step_y = 1; ptrs[0] = (void*)data; - addr[1].dim_x = imgType == VX_DF_IMAGE_YUV4 ? w : (w + 1) / 2; - addr[1].dim_y = imgType == VX_DF_IMAGE_YUV4 ? h : (h + 1) / 2; + addr[1].dim_x = imgType == VX_DF_IMAGE_YUV4 ? w : w / 2; + addr[1].dim_y = imgType == VX_DF_IMAGE_YUV4 ? h : h / 2; + if (addr[1].dim_x != (step - addr[1].dim_x)) + vxErr(VX_ERROR_INVALID_PARAMETERS, "UV planes use variable stride").check(); addr[1].stride_x = 1; - addr[1].stride_y = (vx_int32)step; - addr[1].scale_x = VX_SCALE_UNITY; - addr[1].scale_y = VX_SCALE_UNITY; - addr[1].step_x = imgType == VX_DF_IMAGE_YUV4 ? 1 : 2; - addr[1].step_y = imgType == VX_DF_IMAGE_YUV4 ? 1 : 2; + addr[1].stride_y = (vx_int32)addr[1].dim_x; ptrs[1] = (void*)(data + h * step); addr[2].dim_x = addr[1].dim_x; addr[2].dim_y = addr[1].dim_y; addr[2].stride_x = 1; - addr[2].stride_y = (vx_int32)step; - addr[2].scale_x = VX_SCALE_UNITY; - addr[2].scale_y = VX_SCALE_UNITY; - addr[2].step_x = addr[1].step_x; - addr[2].step_y = addr[1].step_y; - ptrs[2] = (void*)(data + (h + addr[1].dim_y) * step); + addr[2].stride_y = addr[1].stride_y; + ptrs[2] = (void*)(data + h * step + addr[1].dim_y * addr[1].stride_y); break; default: vxErr(VX_ERROR_INVALID_PARAMETERS, "Bad image format").check(); @@ -897,6 +872,9 @@ inline int ovx_hal_cvtBGRtoBGR(const uchar * a, size_t astep, uchar * b, size_t if (depth != CV_8U || swapBlue || acn == bcn || (acn != 3 && acn != 4) || (bcn != 3 && bcn != 4)) return CV_HAL_ERROR_NOT_IMPLEMENTED; + if (w & 1 || h & 1) // It's strange but sample implementation unable to convert odd sized images + return CV_HAL_ERROR_NOT_IMPLEMENTED; + try { vxContext * ctx = vxContext::getContext(); @@ -917,10 +895,17 @@ inline int ovx_hal_cvtTwoPlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, if (!swapBlue || (bcn != 3 && bcn != 4)) return CV_HAL_ERROR_NOT_IMPLEMENTED; + if (w & 1 || h & 1) // It's not described in spec but sample implementation unable to convert odd sized images + return CV_HAL_ERROR_NOT_IMPLEMENTED; + try { vxContext * ctx = vxContext::getContext(); vxImage ia(*ctx, uIdx ? VX_DF_IMAGE_NV21 : VX_DF_IMAGE_NV12, a, astep, w, h); + vx_channel_range_e cRange; + vxErr::check(vxQueryImage(ia.img, VX_IMAGE_RANGE, &cRange, sizeof(cRange))); + if (cRange == VX_CHANNEL_RANGE_FULL) + return CV_HAL_ERROR_NOT_IMPLEMENTED; // OpenCV store NV12/NV21 as RANGE_RESTRICTED while OpenVX expect RANGE_FULL vxImage ib(*ctx, bcn == 3 ? VX_DF_IMAGE_RGB : VX_DF_IMAGE_RGBX, b, bstep, w, h); vxErr::check(vxuColorConvert(ctx->ctx, ia.img, ib.img)); } @@ -934,13 +919,20 @@ 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 (!swapBlue || (bcn != 3 && bcn != 4) || uIdx) + if (!swapBlue || (bcn != 3 && bcn != 4) || uIdx || w / 2 != astep - w / 2) + return CV_HAL_ERROR_NOT_IMPLEMENTED; + + if (w & 1 || h & 1) // It's not described in spec but sample implementation unable to convert odd sized images return CV_HAL_ERROR_NOT_IMPLEMENTED; try { vxContext * ctx = vxContext::getContext(); vxImage ia(*ctx, VX_DF_IMAGE_IYUV, a, astep, w, h); + vx_channel_range_e cRange; + vxErr::check(vxQueryImage(ia.img, VX_IMAGE_RANGE, &cRange, sizeof(cRange))); + if (cRange == VX_CHANNEL_RANGE_FULL) + return CV_HAL_ERROR_NOT_IMPLEMENTED; // OpenCV store NV12/NV21 as RANGE_RESTRICTED while OpenVX expect RANGE_FULL vxImage ib(*ctx, bcn == 3 ? VX_DF_IMAGE_RGB : VX_DF_IMAGE_RGBX, b, bstep, w, h); vxErr::check(vxuColorConvert(ctx->ctx, ia.img, ib.img)); } @@ -954,7 +946,10 @@ 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 (!swapBlue || (acn != 3 && acn != 4) || uIdx) + if (!swapBlue || (acn != 3 && acn != 4) || uIdx || w / 2 != bstep - w / 2) + return CV_HAL_ERROR_NOT_IMPLEMENTED; + + if (w & 1 || h & 1) // It's not described in spec but sample implementation unable to convert odd sized images return CV_HAL_ERROR_NOT_IMPLEMENTED; try @@ -977,10 +972,17 @@ inline int ovx_hal_cvtOnePlaneYUVtoBGR(const uchar * a, size_t astep, uchar * b, if (!swapBlue || (bcn != 3 && bcn != 4) || uIdx) return CV_HAL_ERROR_NOT_IMPLEMENTED; + if (w & 1) // It's not described in spec but sample implementation unable to convert odd sized images + return CV_HAL_ERROR_NOT_IMPLEMENTED; + try { vxContext * ctx = vxContext::getContext(); vxImage ia(*ctx, ycn ? VX_DF_IMAGE_UYVY : VX_DF_IMAGE_YUYV, a, astep, w, h); + vx_channel_range_e cRange; + vxErr::check(vxQueryImage(ia.img, VX_IMAGE_RANGE, &cRange, sizeof(cRange))); + if (cRange == VX_CHANNEL_RANGE_FULL) + return CV_HAL_ERROR_NOT_IMPLEMENTED; // OpenCV store NV12/NV21 as RANGE_RESTRICTED while OpenVX expect RANGE_FULL vxImage ib(*ctx, bcn == 3 ? VX_DF_IMAGE_RGB : VX_DF_IMAGE_RGBX, b, bstep, w, h); vxErr::check(vxuColorConvert(ctx->ctx, ia.img, ib.img)); }