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

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2024-09-10 10:15:22 +03:00
26 changed files with 237 additions and 204 deletions
@@ -66,6 +66,9 @@
#define __CV_CUDA_HOST_DEVICE__
#endif
#include "opencv2/core/cvdef.h"
#include "opencv2/core.hpp"
namespace cv
{
namespace cuda
@@ -124,6 +127,11 @@ namespace cv
int cols;
int rows;
CV_NODISCARD_STD __CV_CUDA_HOST_DEVICE__ Size size() const { return {cols, rows}; }
CV_NODISCARD_STD __CV_CUDA_HOST_DEVICE__ T& operator ()(const Point &pos) { return (*this)(pos.y, pos.x); }
CV_NODISCARD_STD __CV_CUDA_HOST_DEVICE__ const T& operator ()(const Point &pos) const { return (*this)(pos.y, pos.x); }
using PtrStep<T>::operator();
};
typedef PtrStepSz<unsigned char> PtrStepSzb;
+5 -1
View File
@@ -758,7 +758,11 @@ __CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumType, EnumType)
# define __has_cpp_attribute(__x) 0
# endif
# if __has_cpp_attribute(nodiscard)
# define CV_NODISCARD_STD [[nodiscard]]
# if defined(__NVCC__) && __CUDACC_VER_MAJOR__ < 12
# define CV_NODISCARD_STD
# else
# define CV_NODISCARD_STD [[nodiscard]]
# endif
# elif __cplusplus >= 201703L
// available when compiler is C++17 compliant
# define CV_NODISCARD_STD [[nodiscard]]
@@ -650,16 +650,18 @@ inline v_float32x8 v256_shuffle(const v_float32x8 &a)
template<int m>
inline v_float64x4 v256_shuffle(const v_float64x4 &a)
{
int imm8 = m & 0b0001; //0 or 1
if (m & 0x0b0010) imm8 |= 0b0100;
//else imm8 |= 0b0000;
if (m & 0x0b0100) imm8 |= 0b110000; //2 or 3
else imm8 |= 0b100000;
if (m & 0x0b1000) imm8 |= 0b11000000;
else imm8 |= 0b10000000;
const int m1 = m & 0b1;
const int m2 = m & 0b10;
const int m3 = m & 0b100;
const int m4 = m & 0b1000;
const int m5 = m2 << 1;
const int m6 = m3 << 2;
const int m7 = m4 << 3;
const int m8 = m1 & m5 & m6 & m7;
return v_float64x4(__lasx_xvpermi_d(*((__m256i*)&a.val), imm8));
return v_float64x4(__lasx_xvshuf4i_d(*((__m256i*)&a.val), *((__m256i*)&a.val), m8));
}
template<typename _Tpvec>
inline void v256_zip(const _Tpvec& a, const _Tpvec& b, _Tpvec& ab0, _Tpvec& ab1)
{
@@ -1100,7 +1102,7 @@ inline v_uint8x32 v_rotate_right(const v_uint8x32& a, const v_uint8x32& b)
template<int imm>
inline v_uint8x32 v_rotate_left(const v_uint8x32& a)
{
enum {IMM_L = (imm - 16) & 0xFF};
enum {IMM_L = ((imm - 16) & 0xFF) > 31 ? 31 : ((imm - 16) & 0xFF)};
enum {IMM_R = (16 - imm) & 0xFF};
if (imm == 0) return a;
@@ -1117,7 +1119,7 @@ inline v_uint8x32 v_rotate_left(const v_uint8x32& a)
template<int imm>
inline v_uint8x32 v_rotate_right(const v_uint8x32& a)
{
enum {IMM_L = (imm - 16) & 0xFF};
enum {IMM_L = ((imm - 16) & 0xFF) > 31 ? 31 : ((imm - 16) & 0xFF)};
if (imm == 0) return a;
if (imm > 32) return v_uint8x32();
+5 -2
View File
@@ -358,7 +358,8 @@ typedef TestBaseWithParam<FlipParams> FlipFixture;
OCL_PERF_TEST_P(FlipFixture, Flip,
::testing::Combine(OCL_TEST_SIZES,
OCL_TEST_TYPES, FlipType::all()))
::testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_32FC1, CV_32FC4),
FlipType::all()))
{
const FlipParams params = GetParam();
const Size srcSize = get<0>(params);
@@ -388,7 +389,9 @@ typedef tuple<Size, MatType, RotateType> RotateParams;
typedef TestBaseWithParam<RotateParams> RotateFixture;
OCL_PERF_TEST_P(RotateFixture, rotate,
::testing::Combine(OCL_TEST_SIZES, OCL_TEST_TYPES, RotateType::all()))
::testing::Combine(OCL_TEST_SIZES,
::testing::Values(CV_8UC1, CV_8UC2, CV_8UC4, CV_32FC1, CV_32FC4),
RotateType::all()))
{
const RotateParams params = GetParam();
const Size srcSize = get<0>(params);
+41
View File
@@ -1049,6 +1049,13 @@ void cv::add( InputArray src1, InputArray src2, OutputArray dst,
{
CV_INSTRUMENT_REGION();
CV_Assert(src1.empty() == src2.empty());
if (src1.empty() && src2.empty())
{
dst.release();
return;
}
arithm_op(src1, src2, dst, mask, dtype, getAddTab(), false, 0, OCL_OP_ADD );
}
@@ -1057,6 +1064,13 @@ void cv::subtract( InputArray _src1, InputArray _src2, OutputArray _dst,
{
CV_INSTRUMENT_REGION();
CV_Assert(_src1.empty() == _src2.empty());
if (_src1.empty() && _src2.empty())
{
_dst.release();
return;
}
ExtendedTypeFunc subExtFunc = getSubExtFunc(_src1.depth(), _src2.depth(), dtype < 0 ? _dst.depth() : dtype);
arithm_op(_src1, _src2, _dst, mask, dtype, getSubTab(), false, 0, OCL_OP_SUB,
/* extendedFunc */ subExtFunc);
@@ -1066,6 +1080,13 @@ void cv::absdiff( InputArray src1, InputArray src2, OutputArray dst )
{
CV_INSTRUMENT_REGION();
CV_Assert(src1.empty() == src2.empty());
if (src1.empty() && src2.empty())
{
dst.release();
return;
}
arithm_op(src1, src2, dst, noArray(), -1, getAbsDiffTab(), false, 0, OCL_OP_ABSDIFF);
}
@@ -1186,6 +1207,13 @@ void divide(InputArray src1, InputArray src2,
{
CV_INSTRUMENT_REGION();
CV_Assert(src1.empty() == src2.empty());
if (src1.empty() && src2.empty())
{
dst.release();
return;
}
arithm_op(src1, src2, dst, noArray(), dtype, getDivTab(), true, &scale, OCL_OP_DIV_SCALE);
}
@@ -1194,6 +1222,12 @@ void divide(double scale, InputArray src2,
{
CV_INSTRUMENT_REGION();
if (src2.empty())
{
dst.release();
return;
}
arithm_op(src2, src2, dst, noArray(), dtype, getRecipTab(), true, &scale, OCL_OP_RECIP_SCALE);
}
@@ -1236,6 +1270,13 @@ void cv::addWeighted( InputArray src1, double alpha, InputArray src2,
{
CV_INSTRUMENT_REGION();
CV_Assert(src1.empty() == src2.empty());
if (src1.empty() && src2.empty())
{
dst.release();
return;
}
double scalars[] = {alpha, beta, gamma};
arithm_op(src1, src2, dst, noArray(), dtype, getAddWeightedTab(), true, scalars, OCL_OP_ADDW);
}
+4 -2
View File
@@ -21,6 +21,8 @@ static MinMaxIdxFunc getMinMaxIdxFunc(int depth)
CV_CPU_DISPATCH_MODES_ALL);
}
// The function expects 1-based indexing for ofs
// Zero is treated as invalid offset (not found)
static void ofs2idx(const Mat& a, size_t ofs, int* idx)
{
int i, d = a.dims;
@@ -324,9 +326,9 @@ void cv::minMaxIdx(InputArray _src, double* minVal,
{
// minIdx[0] and minIdx[0] are always 0 for "flatten" version
if (minIdx)
ofs2idx(src, minIdx[1], minIdx);
ofs2idx(src, minIdx[1]+1, minIdx);
if (maxIdx)
ofs2idx(src, maxIdx[1], maxIdx);
ofs2idx(src, maxIdx[1]+1, maxIdx);
return;
}
else if (res != CV_HAL_ERROR_NOT_IMPLEMENTED)
@@ -460,7 +460,7 @@ PERF_TEST_P_(DivPerfTest, TestPerformance)
//This condition need to workaround the #21044 issue in the OpenCV.
//It reinitializes divider matrix without zero values for CV_16S DST type.
if (dtype == CV_16S && dtype != type)
if (dtype != type)
cv::randu(in_mat2, cv::Scalar::all(1), cv::Scalar::all(255));
// OpenCV code ///////////////////////////////////////////////////////////
@@ -552,8 +552,7 @@ PERF_TEST_P_(DivRCPerfTest, TestPerformance)
initMatsRandU(type, sz, dtype, false);
//This condition need to workaround the #21044 issue in the OpenCV.
//It reinitializes divider matrix without zero values for CV_16S DST type.
if (dtype == CV_16S || (type == CV_16S && dtype == -1))
cv::randu(in_mat1, cv::Scalar::all(1), cv::Scalar::all(255));
cv::randu(in_mat1, cv::Scalar::all(1), cv::Scalar::all(255));
// OpenCV code ///////////////////////////////////////////////////////////
cv::divide(sc, in_mat1, out_mat_ocv, scale, dtype);
+2
View File
@@ -143,6 +143,7 @@ AvifDecoder::AvifDecoder() {
m_buf_supported = true;
channels_ = 0;
decoder_ = avifDecoderCreate();
decoder_->strictFlags = AVIF_STRICT_DISABLED;
}
AvifDecoder::~AvifDecoder() {
@@ -166,6 +167,7 @@ bool AvifDecoder::checkSignature(const String &signature) const {
std::unique_ptr<avifDecoder, decltype(&avifDecoderDestroy)> decoder(
avifDecoderCreate(), avifDecoderDestroy);
if (!decoder) return false;
decoder->strictFlags = AVIF_STRICT_DISABLED;
OPENCV_AVIF_CHECK_STATUS(
avifDecoderSetIOMemory(
decoder.get(), reinterpret_cast<const uint8_t *>(signature.c_str()),
+1 -2
View File
@@ -1096,7 +1096,6 @@ INSTANTIATE_TEST_CASE_P(AllModes, Imgcodecs_Tiff_Modes, testing::ValuesIn(all_mo
TEST(Imgcodecs_Tiff_Modes, write_multipage)
{
const string root = cvtest::TS::ptr()->get_data_path();
const string filename = root + "readwrite/multipage.tif";
const string page_files[] = {
"readwrite/multipage_p1.tif",
"readwrite/multipage_p2.tif",
@@ -1109,7 +1108,7 @@ TEST(Imgcodecs_Tiff_Modes, write_multipage)
vector<Mat> pages;
for (size_t i = 0; i < page_count; i++)
{
const Mat page = imread(root + page_files[i]);
const Mat page = imread(root + page_files[i], IMREAD_REDUCED_GRAYSCALE_8 + (int)i);
pages.push_back(page);
}
+17 -11
View File
@@ -12,7 +12,7 @@ CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR)
CV_ENUM(InterTypeExtended, INTER_NEAREST, INTER_LINEAR, WARP_RELATIVE_MAP)
CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH)
typedef TestBaseWithParam< tuple<Size, InterType, BorderMode> > TestWarpAffine;
typedef TestBaseWithParam< tuple<MatType, Size, InterType, BorderMode> > TestWarpAffine;
typedef TestBaseWithParam< tuple<Size, InterType, BorderMode, int> > TestWarpPerspective;
typedef TestBaseWithParam< tuple<Size, InterType, BorderMode, MatType> > TestWarpPerspectiveNear_t;
typedef TestBaseWithParam< tuple<MatType, Size, InterTypeExtended, BorderMode, RemapMode> > TestRemap;
@@ -21,6 +21,7 @@ void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode, boo
PERF_TEST_P( TestWarpAffine, WarpAffine,
Combine(
Values(CV_8UC1, CV_8UC4),
Values( szVGA, sz720p, sz1080p ),
InterType::all(),
BorderMode::all()
@@ -28,13 +29,14 @@ PERF_TEST_P( TestWarpAffine, WarpAffine,
)
{
Size sz, szSrc(512, 512);
int borderMode, interType;
sz = get<0>(GetParam());
interType = get<1>(GetParam());
borderMode = get<2>(GetParam());
int borderMode, interType, dataType;
dataType = get<0>(GetParam());
sz = get<1>(GetParam());
interType = get<2>(GetParam());
borderMode = get<3>(GetParam());
Scalar borderColor = Scalar::all(150);
Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4);
Mat src(szSrc, dataType), dst(sz, dataType);
cvtest::fillGradient(src);
if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
Mat warpMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
@@ -47,6 +49,7 @@ PERF_TEST_P( TestWarpAffine, WarpAffine,
PERF_TEST_P(TestWarpAffine, DISABLED_WarpAffine_ovx,
Combine(
Values(CV_8UC1, CV_8UC4),
Values(szVGA, sz720p, sz1080p),
InterType::all(),
BorderMode::all()
@@ -54,13 +57,16 @@ PERF_TEST_P(TestWarpAffine, DISABLED_WarpAffine_ovx,
)
{
Size sz, szSrc(512, 512);
int borderMode, interType;
sz = get<0>(GetParam());
interType = get<1>(GetParam());
borderMode = get<2>(GetParam());
int borderMode, interType, dataType;
dataType = get<0>(GetParam());
sz = get<1>(GetParam());
interType = get<2>(GetParam());
borderMode = get<3>(GetParam());
Scalar borderColor = Scalar::all(150);
Mat src(szSrc, CV_8UC1), dst(sz, CV_8UC1);
Mat src(szSrc, dataType), dst(sz, dataType);
cvtest::fillGradient(src);
if (borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
Mat warpMat = getRotationMatrix2D(Point2f(src.cols / 2.f, src.rows / 2.f), 30., 2.2);
-5
View File
@@ -1088,11 +1088,6 @@ struct mRGBA2RGBA<uchar>
uchar v3_half = v3 / 2;
dst[0] = (v3==0)? 0 : (v0 * max_val + v3_half) / v3;
dst[1] = (v3==0)? 0 : (v1 * max_val + v3_half) / v3;
dst[2] = (v3==0)? 0 : (v2 * max_val + v3_half) / v3;
dst[3] = v3;
dst[0] = (v3==0)? 0 : saturate_cast<uchar>((v0 * max_val + v3_half) / v3);
dst[1] = (v3==0)? 0 : saturate_cast<uchar>((v1 * max_val + v3_half) / v3);
dst[2] = (v3==0)? 0 : saturate_cast<uchar>((v2 * max_val + v3_half) / v3);
+33 -52
View File
@@ -1983,65 +1983,46 @@ void cv::convertMaps( InputArray _map1, InputArray _map2,
}
else if( m1type == CV_32FC2 && dstm1type == CV_16SC2 )
{
if( nninterpolate )
#if CV_TRY_SSE4_1
if( useSSE4_1 )
opt_SSE4_1::convertMaps_32f2c16s_SSE41(src1f, dst1, dst2, size.width);
else
#endif
{
#if CV_SIMD128
int span = VTraits<v_float32x4>::vlanes();
{
for( ; x <= (size.width << 1) - span * 2; x += span * 2 )
v_store(dst1 + x, v_pack(v_round(v_load(src1f + x)),
v_round(v_load(src1f + x + span))));
v_float32x4 v_scale = v_setall_f32((float)INTER_TAB_SIZE);
v_int32x4 v_mask = v_setall_s32(INTER_TAB_SIZE - 1);
v_int32x4 v_scale3 = v_setall_s32(INTER_TAB_SIZE);
int span = VTraits<v_uint16x8>::vlanes();
for (; x <= size.width - span; x += span )
{
v_float32x4 v_src0[2], v_src1[2];
v_load_deinterleave(src1f + (x << 1), v_src0[0], v_src0[1]);
v_load_deinterleave(src1f + (x << 1) + span, v_src1[0], v_src1[1]);
v_int32x4 v_ix0 = v_round(v_mul(v_src0[0], v_scale));
v_int32x4 v_ix1 = v_round(v_mul(v_src1[0], v_scale));
v_int32x4 v_iy0 = v_round(v_mul(v_src0[1], v_scale));
v_int32x4 v_iy1 = v_round(v_mul(v_src1[1], v_scale));
v_int16x8 v_dst[2];
v_dst[0] = v_pack(v_shr<INTER_BITS>(v_ix0), v_shr<INTER_BITS>(v_ix1));
v_dst[1] = v_pack(v_shr<INTER_BITS>(v_iy0), v_shr<INTER_BITS>(v_iy1));
v_store_interleave(dst1 + (x << 1), v_dst[0], v_dst[1]);
v_store(dst2 + x, v_pack_u(
v_muladd(v_scale3, (v_and(v_iy0, v_mask)), (v_and(v_ix0, v_mask))),
v_muladd(v_scale3, (v_and(v_iy1, v_mask)), (v_and(v_ix1, v_mask)))));
}
}
#endif
for( ; x < size.width; x++ )
{
dst1[x*2] = saturate_cast<short>(src1f[x*2]);
dst1[x*2+1] = saturate_cast<short>(src1f[x*2+1]);
}
}
else
{
#if CV_TRY_SSE4_1
if( useSSE4_1 )
opt_SSE4_1::convertMaps_32f2c16s_SSE41(src1f, dst1, dst2, size.width);
else
#endif
{
#if CV_SIMD128
{
v_float32x4 v_scale = v_setall_f32((float)INTER_TAB_SIZE);
v_int32x4 v_mask = v_setall_s32(INTER_TAB_SIZE - 1);
v_int32x4 v_scale3 = v_setall_s32(INTER_TAB_SIZE);
int span = VTraits<v_uint16x8>::vlanes();
for (; x <= size.width - span; x += span )
{
v_float32x4 v_src0[2], v_src1[2];
v_load_deinterleave(src1f + (x << 1), v_src0[0], v_src0[1]);
v_load_deinterleave(src1f + (x << 1) + span, v_src1[0], v_src1[1]);
v_int32x4 v_ix0 = v_round(v_mul(v_src0[0], v_scale));
v_int32x4 v_ix1 = v_round(v_mul(v_src1[0], v_scale));
v_int32x4 v_iy0 = v_round(v_mul(v_src0[1], v_scale));
v_int32x4 v_iy1 = v_round(v_mul(v_src1[1], v_scale));
v_int16x8 v_dst[2];
v_dst[0] = v_pack(v_shr<INTER_BITS>(v_ix0), v_shr<INTER_BITS>(v_ix1));
v_dst[1] = v_pack(v_shr<INTER_BITS>(v_iy0), v_shr<INTER_BITS>(v_iy1));
v_store_interleave(dst1 + (x << 1), v_dst[0], v_dst[1]);
v_store(dst2 + x, v_pack_u(
v_muladd(v_scale3, (v_and(v_iy0, v_mask)), (v_and(v_ix0, v_mask))),
v_muladd(v_scale3, (v_and(v_iy1, v_mask)), (v_and(v_ix1, v_mask)))));
}
}
#endif
for( ; x < size.width; x++ )
{
int ix = saturate_cast<int>(src1f[x*2]*INTER_TAB_SIZE);
int iy = saturate_cast<int>(src1f[x*2+1]*INTER_TAB_SIZE);
dst1[x*2] = saturate_cast<short>(ix >> INTER_BITS);
dst1[x*2+1] = saturate_cast<short>(iy >> INTER_BITS);
dst2[x] = (ushort)((iy & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + (ix & (INTER_TAB_SIZE-1)));
}
int ix = saturate_cast<int>(src1f[x*2]*INTER_TAB_SIZE);
int iy = saturate_cast<int>(src1f[x*2+1]*INTER_TAB_SIZE);
dst1[x*2] = saturate_cast<short>(ix >> INTER_BITS);
dst1[x*2+1] = saturate_cast<short>(iy >> INTER_BITS);
dst2[x] = (ushort)((iy & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + (ix & (INTER_TAB_SIZE-1)));
}
}
}
+56
View File
@@ -94,6 +94,10 @@ static void hlineResize(ET* src, int cn, int *ofst, FT* m, FT* dst, int dst_min,
}
}
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
ET* src_last = src + cn*ofst[dst_width - 1];
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
{
@@ -125,6 +129,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 2, true, 1>
ET* px = src + ofst[i];
*(dst++) = m[0] * px[0] + m[1] * px[1];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
src0 = (src + ofst[dst_width - 1])[0];
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
{
@@ -149,6 +157,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 2, true, 2>
*(dst++) = m[0] * px[0] + m[1] * px[2];
*(dst++) = m[0] * px[1] + m[1] * px[3];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
src0 = (src + 2*ofst[dst_width - 1])[0];
src1 = (src + 2*ofst[dst_width - 1])[1];
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
@@ -177,6 +189,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 2, true, 3>
*(dst++) = m[0] * px[1] + m[1] * px[4];
*(dst++) = m[0] * px[2] + m[1] * px[5];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
src0 = (src + 3*ofst[dst_width - 1])[0];
src1 = (src + 3*ofst[dst_width - 1])[1];
src2 = (src + 3*ofst[dst_width - 1])[2];
@@ -209,6 +225,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 2, true, 4>
*(dst++) = m[0] * px[2] + m[1] * px[6];
*(dst++) = m[0] * px[3] + m[1] * px[7];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
src0 = (src + 4*ofst[dst_width - 1])[0];
src1 = (src + 4*ofst[dst_width - 1])[1];
src2 = (src + 4*ofst[dst_width - 1])[2];
@@ -237,6 +257,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 4, true, 1>
ET* px = src + ofst[i];
*(dst++) = m[0] * src[0] + m[1] * src[1] + m[2] * src[2] + m[3] * src[3];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
src0 = (src + ofst[dst_width - 1])[0];
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
{
@@ -261,6 +285,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 4, true, 2>
*(dst++) = m[0] * src[0] + m[1] * src[2] + m[2] * src[4] + m[3] * src[6];
*(dst++) = m[0] * src[1] + m[1] * src[3] + m[2] * src[5] + m[3] * src[7];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
src0 = (src + 2*ofst[dst_width - 1])[0];
src1 = (src + 2*ofst[dst_width - 1])[1];
for (; i < dst_width; i++) // Points that fall right from src image so became equal to rightmost src point
@@ -289,6 +317,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 4, true, 3>
*(dst++) = m[0] * src[1] + m[1] * src[4] + m[2] * src[7] + m[3] * src[10];
*(dst++) = m[0] * src[2] + m[1] * src[5] + m[2] * src[8] + m[3] * src[11];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
src0 = (src + 3*ofst[dst_width - 1])[0];
src1 = (src + 3*ofst[dst_width - 1])[1];
src2 = (src + 3*ofst[dst_width - 1])[2];
@@ -321,6 +353,10 @@ template <typename ET, typename FT> struct hline<ET, FT, 4, true, 4>
*(dst++) = m[0] * src[2] + m[1] * src[6] + m[2] * src[10] + m[3] * src[14];
*(dst++) = m[0] * src[3] + m[1] * src[7] + m[2] * src[11] + m[3] * src[15];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
src0 = (src + 4*ofst[dst_width - 1])[0];
src1 = (src + 4*ofst[dst_width - 1])[1];
src2 = (src + 4*ofst[dst_width - 1])[2];
@@ -382,6 +418,10 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 1>(uint8_t* src, int, int *o
uint8_t* px = src + ofst[i];
*(dst++) = m[0] * px[0] + m[1] * px[1];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
src_0 = (src + ofst[dst_width - 1])[0];
#if (CV_SIMD || CV_SIMD_SCALABLE)
v_src_0 = vx_setall_u16(*((uint16_t*)&src_0));
@@ -438,6 +478,10 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 2>(uint8_t* src, int, int *o
*(dst++) = m[0] * px[0] + m[1] * px[2];
*(dst++) = m[0] * px[1] + m[1] * px[3];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
((ufixedpoint16*)(srccn.w))[0] = (src + 2 * ofst[dst_width - 1])[0]; ((ufixedpoint16*)(srccn.w))[1] = (src + 2 * ofst[dst_width - 1])[1];
#if (CV_SIMD || CV_SIMD_SCALABLE)
v_srccn = v_reinterpret_as_u16(vx_setall_u32(srccn.d));
@@ -510,6 +554,10 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 3>(uint8_t* src, int, int *o
*(dst++) = m[0] * px[1] + m[1] * px[4];
*(dst++) = m[0] * px[2] + m[1] * px[5];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
((ufixedpoint16*)(srccn.w))[0] = (src + 3*ofst[dst_width - 1])[0];
((ufixedpoint16*)(srccn.w))[1] = (src + 3*ofst[dst_width - 1])[1];
((ufixedpoint16*)(srccn.w))[2] = (src + 3*ofst[dst_width - 1])[2];
@@ -583,6 +631,10 @@ void hlineResizeCn<uint8_t, ufixedpoint16, 2, true, 4>(uint8_t* src, int, int *o
*(dst++) = m[0] * px[2] + m[1] * px[6];
*(dst++) = m[0] * px[3] + m[1] * px[7];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
((ufixedpoint16*)(srccn.w))[0] = (src + 4 * ofst[dst_width - 1])[0]; ((ufixedpoint16*)(srccn.w))[1] = (src + 4 * ofst[dst_width - 1])[1];
((ufixedpoint16*)(srccn.w))[2] = (src + 4 * ofst[dst_width - 1])[2]; ((ufixedpoint16*)(srccn.w))[3] = (src + 4 * ofst[dst_width - 1])[3];
#if (CV_SIMD || CV_SIMD_SCALABLE)
@@ -634,6 +686,10 @@ void hlineResizeCn<uint16_t, ufixedpoint32, 2, true, 1>(uint16_t* src, int, int
uint16_t* px = src + ofst[i];
*(dst++) = m[0] * px[0] + m[1] * px[1];
}
// Avoid reading a potentially unset ofst, leading to a random memory read.
if (i >= dst_width) {
return;
}
src_0 = (src + ofst[dst_width - 1])[0];
#if (CV_SIMD || CV_SIMD_SCALABLE)
v_src_0 = vx_setall_u32(*((uint32_t*)&src_0));
+6 -1
View File
@@ -455,7 +455,7 @@ void CV_ColorGrayTest::get_test_array_types_and_sizes( int test_case_idx, vector
double CV_ColorGrayTest::get_success_error_level( int /*test_case_idx*/, int i, int j )
{
int depth = test_mat[i][j].depth();
return depth == CV_8U ? 2 : depth == CV_16U ? 16 : 1e-5;
return depth == CV_8U ? 1 : depth == CV_16U ? 2 : 1e-5;
}
@@ -2844,6 +2844,11 @@ void runCvtColorBitExactCheck(ColorConversionCodes code, int inputType, uint32_t
}
}
TEST(Imgproc_cvtColor_BE, COLOR_RGB2GRAY) { runCvtColorBitExactCheck(COLOR_RGB2GRAY, CV_8UC3, 0x416bd44a); }
TEST(Imgproc_cvtColor_BE, COLOR_RGBA2GRAY) { runCvtColorBitExactCheck(COLOR_RGBA2GRAY, CV_8UC3, 0x416bd44a); }
TEST(Imgproc_cvtColor_BE, COLOR_BGR2GRAY) { runCvtColorBitExactCheck(COLOR_BGR2GRAY, CV_8UC3, 0x3008c6b8); }
TEST(Imgproc_cvtColor_BE, COLOR_BGRA2GRAY) { runCvtColorBitExactCheck(COLOR_BGRA2GRAY, CV_8UC3, 0x3008c6b8); }
TEST(Imgproc_cvtColor_BE, COLOR_BGR2YUV) { runCvtColorBitExactCheck(COLOR_BGR2YUV, CV_8UC3, 0xc2cbcfda); }
TEST(Imgproc_cvtColor_BE, COLOR_RGB2YUV) { runCvtColorBitExactCheck(COLOR_RGB2YUV, CV_8UC3, 0x4e98e757); }
TEST(Imgproc_cvtColor_BE, COLOR_YUV2BGR) { runCvtColorBitExactCheck(COLOR_YUV2BGR, CV_8UC3, 0xb2c62a3f); }
+2 -2
View File
@@ -1449,11 +1449,11 @@ void CvCaptureCAM_V4L::convertToRgb(const Buffer &currentBuffer)
return;
case V4L2_PIX_FMT_NV12:
cv::cvtColor(cv::Mat(imageSize.height * 3 / 2, imageSize.width, CV_8U, start), frame,
COLOR_YUV2RGB_NV12);
COLOR_YUV2BGR_NV12);
return;
case V4L2_PIX_FMT_NV21:
cv::cvtColor(cv::Mat(imageSize.height * 3 / 2, imageSize.width, CV_8U, start), frame,
COLOR_YUV2RGB_NV21);
COLOR_YUV2BGR_NV21);
return;
#ifdef HAVE_JPEG
case V4L2_PIX_FMT_MJPEG: