1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #24233 from jvuillaumier:rotate_flip_hal_hooks

Add HAL implementation hooks to cv::flip() and cv::rotate() functions from core module #24233

Hello,

This change proposes the addition of HAL hooks for cv::flip() and cv::rotate() functions from OpenCV core module.
Flip and rotation are functions commonly available from 2D hardware accelerators. This is convenient provision to enable custom optimized implementation of image flip/rotation on systems embedding such accelerator.

Thank you

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] 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:
jvuillaumier
2023-10-06 11:31:53 +02:00
committed by GitHub
parent 07bf9cb013
commit 24fd39538e
2 changed files with 93 additions and 3 deletions
+52 -3
View File
@@ -4,6 +4,7 @@
#include "precomp.hpp"
#include "opencl_kernels_core.hpp"
#include "hal_replacement.hpp"
#include "opencv2/core/detail/dispatch_helper.impl.hpp"
#include <algorithm> // std::swap_ranges
@@ -802,6 +803,9 @@ void flip( InputArray _src, OutputArray _dst, int flip_mode )
_dst.create( size, type );
Mat dst = _dst.getMat();
CALL_HAL(flip, cv_hal_flip, type, src.ptr(), src.step, src.cols, src.rows,
dst.ptr(), dst.step, flip_mode);
CV_IPP_RUN_FAST(ipp_flip(src, dst, flip_mode));
size_t esz = CV_ELEM_SIZE(type);
@@ -1075,10 +1079,8 @@ void broadcast(InputArray _src, InputArray _shape, OutputArray _dst) {
}
}
void rotate(InputArray _src, OutputArray _dst, int rotateMode)
static void rotateImpl(InputArray _src, OutputArray _dst, int rotateMode)
{
CV_Assert(_src.dims() <= 2);
switch (rotateMode)
{
case ROTATE_90_CLOCKWISE:
@@ -1097,4 +1099,51 @@ void rotate(InputArray _src, OutputArray _dst, int rotateMode)
}
}
void rotate(InputArray _src, OutputArray _dst, int rotateMode)
{
CV_Assert(_src.dims() <= 2);
int angle;
if (_dst.isUMat())
{
rotateImpl(_src, _dst, rotateMode);
return;
}
Mat src = _src.getMat();
int type = src.type();
if( src.empty() )
{
_dst.release();
return;
}
switch (rotateMode)
{
case ROTATE_90_CLOCKWISE:
_dst.create(src.cols, src.rows, type);
angle = 90;
break;
case ROTATE_180:
_dst.create(src.rows, src.cols, type);
angle = 180;
break;
case ROTATE_90_COUNTERCLOCKWISE:
_dst.create(src.cols, src.rows, type);
angle = 270;
break;
default:
_dst.create(src.rows, src.cols, type);
angle = 0;
break;
}
Mat dst = _dst.getMat();
CALL_HAL(rotate90, cv_hal_rotate90, type, src.ptr(), src.step, src.cols, src.rows,
dst.ptr(), dst.step, angle);
// use src (Mat) since _src (InputArray) is updated by _dst.create() when in-place
rotateImpl(src, _dst, rotateMode);
}
} // namespace