Files
opencv-MIRROR/hal/ipp/src/precomp_ipp.hpp
Prasad Ayush Kumar ae93a81ec0 Merge pull request #29389 from Prasadayus:cvtcolor_refactor
Refactoring and optimizing cvtcolor in Imgproc #29389

**Key Changes:**

1. Unified three divergent SIMD swap implementations into a single shared `v_swap` helper.
2. Consolidated the repeated `CV_8U/CV_16U/CV_32F` depth-dispatch chains into a single `CvtColorLoopDepth` template.
3. Extracted the duplicated coefficient-selection loops in the YCrCb/YUV constructors into `selectYuvCoeffs`.
4. Collapsed the shared YUV420 store logic duplicated across both decode invokers into `storeYUV420block`.
5. Generalized the inline blue-channel coefficient swaps in `color_lab.cpp` into `swapBlueCoeffsCols`/`swapBlueCoeffsRows`.
6. Added a `v_dotprod`-based SIMD path (`v_RGB2Y`/`v_RGB2UV`) for the previously scalar `RGB8toYUV422Invoker`.
7. Migrated all inline `CV_IPP_CHECK` cvtColor paths out of the dispatch files and into the IPP HAL plugin (`hal/ipp/src/color_ipp.cpp`), replacing each call site with `CALL_HAL`.

**Performance Numbers on Intel(R) Core(TM) i9-11900K**: https://docs.google.com/spreadsheets/d/1pz0aHlTeG4Ao8RT7LipgdNSjhCJz92QfZG3GmNa63hU/edit?usp=sharing

### 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
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-07-03 10:53:13 +03:00

124 lines
3.8 KiB
C++

// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#ifndef __PRECOMP_IPP_HPP__
#define __PRECOMP_IPP_HPP__
#include <opencv2/imgproc.hpp>
#ifdef HAVE_IPP_IW
#include "iw++/iw.hpp"
#endif
static inline IppiSize ippiSize(size_t width, size_t height)
{
IppiSize size = { (int)width, (int)height };
return size;
}
static inline IppiSize ippiSize(const cv::Size & _size)
{
IppiSize size = { _size.width, _size.height };
return size;
}
#if IPP_VERSION_X100 >= 201700
static inline IppiSizeL ippiSizeL(size_t width, size_t height)
{
IppiSizeL size = { (IppSizeL)width, (IppSizeL)height };
return size;
}
static inline IppiSizeL ippiSizeL(const cv::Size & _size)
{
IppiSizeL size = { _size.width, _size.height };
return size;
}
#endif
static inline IppDataType ippiGetDataType(int depth)
{
depth = CV_MAT_DEPTH(depth);
return depth == CV_8U ? ipp8u :
depth == CV_8S ? ipp8s :
depth == CV_16U ? ipp16u :
depth == CV_16S ? ipp16s :
depth == CV_32S ? ipp32s :
depth == CV_32F ? ipp32f :
depth == CV_64F ? ipp64f :
(IppDataType)-1;
}
static inline IppiInterpolationType ippiGetInterpolation(int inter)
{
inter &= cv::InterpolationFlags::INTER_MAX;
return inter == cv::InterpolationFlags::INTER_NEAREST ? ippNearest :
inter == cv::InterpolationFlags::INTER_LINEAR ? ippLinear :
inter == cv::InterpolationFlags::INTER_CUBIC ? ippCubic :
inter == cv::InterpolationFlags::INTER_LANCZOS4 ? ippLanczos :
inter == cv::InterpolationFlags::INTER_AREA ? ippSuper :
(IppiInterpolationType)-1;
}
static inline IppiBorderType ippiGetBorderType(int borderTypeNI)
{
return borderTypeNI == cv::BorderTypes::BORDER_CONSTANT ? ippBorderConst :
borderTypeNI == cv::BorderTypes::BORDER_TRANSPARENT ? ippBorderTransp :
borderTypeNI == cv::BorderTypes::BORDER_REPLICATE ? ippBorderRepl :
(IppiBorderType)-1;
}
static inline int ippiSuggestThreadsNum(size_t width, size_t height, size_t elemSize, double multiplier)
{
int threads = cv::getNumThreads();
if(threads > 1 && height >= 64)
{
size_t opMemory = (int)(width*height*elemSize*multiplier);
int l2cache = 0;
#if IPP_VERSION_X100 >= 201700
ippGetL2CacheSize(&l2cache);
#endif
if(!l2cache)
l2cache = 1 << 18;
return IPP_MAX(1, (IPP_MIN((int)(opMemory/l2cache), threads)));
}
return 1;
}
static inline int ippiSuggestRowThreadsNum(size_t width, size_t height, size_t elemSize, size_t payloadSize)
{
int num_threads = cv::getNumThreads();
if(num_threads > 1)
{
long rowThreads = static_cast<long>(height);
// row-based range shall not allow to split rows
num_threads = (rowThreads < num_threads) ? rowThreads : num_threads;
long rows_per_thread = (rowThreads + num_threads - 1) / num_threads;
size_t item_size = width * elemSize; // row size in bytes
if(static_cast<size_t>(item_size * rows_per_thread) < payloadSize)
{
long items_per_thread = IPP_MAX(1L, static_cast<long>(payloadSize / item_size ));
num_threads = static_cast<int>((height + items_per_thread - 1L) / items_per_thread);
}
}
return num_threads;
}
#ifdef HAVE_IPP_IW
static inline int ippiSuggestThreadsNum(const ::ipp::IwiImage &image, double multiplier)
{
return ippiSuggestThreadsNum(image.m_size.width, image.m_size.height, image.m_typeSize*image.m_channels, multiplier);
}
static inline int ippiSuggestRowThreadsNum(const ::ipp::IwiImage &image, size_t payloadSize)
{
return ippiSuggestRowThreadsNum(image.m_size.width, image.m_size.height, image.m_typeSize*image.m_channels, payloadSize);
}
#endif
#endif //__PRECOMP_IPP_HPP__