From a84e11451b6e638a63f7c39ffb0a3330be882491 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 21 Jan 2019 16:04:23 +0300 Subject: [PATCH 1/2] imgproc(test): RGB2YUV regression test --- modules/imgproc/test/test_color.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/imgproc/test/test_color.cpp b/modules/imgproc/test/test_color.cpp index c36bc1fd6e..6ad51ad512 100644 --- a/modules/imgproc/test/test_color.cpp +++ b/modules/imgproc/test/test_color.cpp @@ -3062,4 +3062,14 @@ TEST(ImgProc_BGR2RGBA, 3ch24ch) EXPECT_DOUBLE_EQ(cvtest::norm(expected - dst, NORM_INF), 0.); } +TEST(ImgProc_RGB2YUV, regression_13668) +{ + Mat src(Size(32, 4), CV_8UC3, Scalar(9, 250, 82)); // Ensure that SIMD code path works + Mat dst; + cvtColor(src, dst, COLOR_RGB2YUV); + Vec3b res = dst.at(0, 0); + Vec3b ref(159, 90, 0); + EXPECT_EQ(res, ref); +} + }} // namespace From 74ba4b7ae2baf8a01112fbbac011409d7797b67d Mon Sep 17 00:00:00 2001 From: Rostislav Vasilikhin Date: Mon, 21 Jan 2019 18:01:44 +0300 Subject: [PATCH 2/2] fixed (un)signed packing s16 -> u8 --- modules/imgproc/src/color_yuv.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/imgproc/src/color_yuv.cpp b/modules/imgproc/src/color_yuv.cpp index acc290ad9b..f80c9c36fc 100644 --- a/modules/imgproc/src/color_yuv.cpp +++ b/modules/imgproc/src/color_yuv.cpp @@ -446,8 +446,8 @@ struct RGB2YCrCb_i swap(sr0, sb0); swap(sr1, sb1); } - v_uint32 cr00, cr01, cr10, cr11; - v_uint32 cb00, cb01, cb10, cb11; + v_int32 cr00, cr01, cr10, cr11; + v_int32 cb00, cb01, cb10, cb11; // delta + descaleShift == descaleShift*(half*2+1) { @@ -460,15 +460,15 @@ struct RGB2YCrCb_i v_zip(sb0, vdescale, bd00, bd01); v_zip(sb1, vdescale, bd10, bd11); - cr00 = v_reinterpret_as_u32(v_dotprod(rd00, c3h)); - cr01 = v_reinterpret_as_u32(v_dotprod(rd01, c3h)); - cr10 = v_reinterpret_as_u32(v_dotprod(rd10, c3h)); - cr11 = v_reinterpret_as_u32(v_dotprod(rd11, c3h)); + cr00 = v_dotprod(rd00, c3h); + cr01 = v_dotprod(rd01, c3h); + cr10 = v_dotprod(rd10, c3h); + cr11 = v_dotprod(rd11, c3h); - cb00 = v_reinterpret_as_u32(v_dotprod(bd00, c4h)); - cb01 = v_reinterpret_as_u32(v_dotprod(bd01, c4h)); - cb10 = v_reinterpret_as_u32(v_dotprod(bd10, c4h)); - cb11 = v_reinterpret_as_u32(v_dotprod(bd11, c4h)); + cb00 = v_dotprod(bd00, c4h); + cb01 = v_dotprod(bd01, c4h); + cb10 = v_dotprod(bd10, c4h); + cb11 = v_dotprod(bd11, c4h); } v_uint8 cr, cb; @@ -483,12 +483,12 @@ struct RGB2YCrCb_i cb10 = cb10 >> shift; cb11 = cb11 >> shift; - v_uint16 cr0, cr1, cb0, cb1; + v_int16 cr0, cr1, cb0, cb1; cr0 = v_pack(cr00, cr01); cr1 = v_pack(cr10, cr11); cb0 = v_pack(cb00, cb01); cb1 = v_pack(cb10, cb11); - cr = v_pack(cr0, cr1); - cb = v_pack(cb0, cb1); + cr = v_pack_u(cr0, cr1); + cb = v_pack_u(cb0, cb1); if(yuvOrder) {