1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge pull request #24058 from hanliutong:rewrite-imgporc

Rewrite Universal Intrinsic code by using new API: ImgProc module. #24058

The goal of this series of PRs is to modify the SIMD code blocks guarded by CV_SIMD macro in the `opencv/modules/imgproc` folder: rewrite them by using the new Universal Intrinsic API. 

For easier review, this PR includes a part of the rewritten code, and another part will be brought in the next PR (coming soon). I tested this patch on RVV (QEMU) and AVX devices, `opencv_test_imgproc` is passed.

The patch is partially auto-generated by using the [rewriter](https://github.com/hanliutong/rewriter), related PR https://github.com/opencv/opencv/pull/23885 and https://github.com/opencv/opencv/pull/23980.



### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [ ] I agree to contribute to the project under Apache 2 License.
- [ ] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
HAN Liutong
2023-09-15 01:37:46 +08:00
committed by GitHub
parent 515f119a59
commit 5e9191558d
11 changed files with 1180 additions and 1140 deletions
+10 -10
View File
@@ -1080,7 +1080,7 @@ cvFindNextContour( CvContourScanner scanner )
}
else
{
#if CV_SIMD
#if (CV_SIMD || CV_SIMD_SCALABLE)
if ((p = img[x]) != prev)
{
goto _next_contour;
@@ -1088,9 +1088,9 @@ cvFindNextContour( CvContourScanner scanner )
else
{
v_uint8 v_prev = vx_setall_u8((uchar)prev);
for (; x <= width - v_uint8::nlanes; x += v_uint8::nlanes)
for (; x <= width - VTraits<v_uint8>::vlanes(); x += VTraits<v_uint8>::vlanes())
{
v_uint8 vmask = (vx_load((uchar*)(img + x)) != v_prev);
v_uint8 vmask = (v_ne(vx_load((uchar *)(img + x)), v_prev));
if (v_check_any(vmask))
{
p = img[(x += v_scan_forward(vmask))];
@@ -1105,7 +1105,7 @@ cvFindNextContour( CvContourScanner scanner )
if( x >= width )
break;
#if CV_SIMD
#if (CV_SIMD || CV_SIMD_SCALABLE)
_next_contour:
#endif
{
@@ -1353,11 +1353,11 @@ CvLinkedRunPoint;
inline int findStartContourPoint(uchar *src_data, CvSize img_size, int j)
{
#if CV_SIMD
#if (CV_SIMD || CV_SIMD_SCALABLE)
v_uint8 v_zero = vx_setzero_u8();
for (; j <= img_size.width - v_uint8::nlanes; j += v_uint8::nlanes)
for (; j <= img_size.width - VTraits<v_uint8>::vlanes(); j += VTraits<v_uint8>::vlanes())
{
v_uint8 vmask = (vx_load((uchar*)(src_data + j)) != v_zero);
v_uint8 vmask = (v_ne(vx_load((uchar *)(src_data + j)), v_zero));
if (v_check_any(vmask))
{
j += v_scan_forward(vmask);
@@ -1372,7 +1372,7 @@ inline int findStartContourPoint(uchar *src_data, CvSize img_size, int j)
inline int findEndContourPoint(uchar *src_data, CvSize img_size, int j)
{
#if CV_SIMD
#if (CV_SIMD || CV_SIMD_SCALABLE)
if (j < img_size.width && !src_data[j])
{
return j;
@@ -1380,9 +1380,9 @@ inline int findEndContourPoint(uchar *src_data, CvSize img_size, int j)
else
{
v_uint8 v_zero = vx_setzero_u8();
for (; j <= img_size.width - v_uint8::nlanes; j += v_uint8::nlanes)
for (; j <= img_size.width - VTraits<v_uint8>::vlanes(); j += VTraits<v_uint8>::vlanes())
{
v_uint8 vmask = (vx_load((uchar*)(src_data + j)) == v_zero);
v_uint8 vmask = (v_eq(vx_load((uchar *)(src_data + j)), v_zero));
if (v_check_any(vmask))
{
j += v_scan_forward(vmask);