Merge pull request #8697 from sovrasov:cvt_col_bgra_bgra_fix

pull/8745/head
Vadim Pisarevsky 8 years ago
commit 03aa69da99
  1. 12
      modules/imgproc/src/color.cpp
  2. 25
      modules/imgproc/test/test_color.cpp

@ -688,7 +688,7 @@ template<typename _Tp> struct RGB2RGB
for( int i = 0; i < n; i += 4 ) for( int i = 0; i < n; i += 4 )
{ {
_Tp t0 = src[i], t1 = src[i+1], t2 = src[i+2], t3 = src[i+3]; _Tp t0 = src[i], t1 = src[i+1], t2 = src[i+2], t3 = src[i+3];
dst[i] = t2; dst[i+1] = t1; dst[i+2] = t0; dst[i+3] = t3; dst[i+bidx] = t0; dst[i+1] = t1; dst[i+(bidx^2)] = t2; dst[i+3] = t3;
} }
} }
} }
@ -802,25 +802,25 @@ template<> struct RGB2RGB<uchar>
for ( ; i <= n - 64; i += 64 ) for ( ; i <= n - 64; i += 64 )
{ {
uint8x16x4_t v_src = vld4q_u8(src + i), v_dst; uint8x16x4_t v_src = vld4q_u8(src + i), v_dst;
v_dst.val[0] = v_src.val[2]; v_dst.val[0] = v_src.val[bidx];
v_dst.val[1] = v_src.val[1]; v_dst.val[1] = v_src.val[1];
v_dst.val[2] = v_src.val[0]; v_dst.val[2] = v_src.val[bidx^2];
v_dst.val[3] = v_src.val[3]; v_dst.val[3] = v_src.val[3];
vst4q_u8(dst + i, v_dst); vst4q_u8(dst + i, v_dst);
} }
for ( ; i <= n - 32; i += 32 ) for ( ; i <= n - 32; i += 32 )
{ {
uint8x8x4_t v_src = vld4_u8(src + i), v_dst; uint8x8x4_t v_src = vld4_u8(src + i), v_dst;
v_dst.val[0] = v_src.val[2]; v_dst.val[0] = v_src.val[bidx];
v_dst.val[1] = v_src.val[1]; v_dst.val[1] = v_src.val[1];
v_dst.val[2] = v_src.val[0]; v_dst.val[2] = v_src.val[bidx^2];
v_dst.val[3] = v_src.val[3]; v_dst.val[3] = v_src.val[3];
vst4_u8(dst + i, v_dst); vst4_u8(dst + i, v_dst);
} }
for ( ; i < n; i += 4) for ( ; i < n; i += 4)
{ {
uchar t0 = src[i], t1 = src[i+1], t2 = src[i+2], t3 = src[i+3]; uchar t0 = src[i], t1 = src[i+1], t2 = src[i+2], t3 = src[i+3];
dst[i] = t2; dst[i+1] = t1; dst[i+2] = t0; dst[i+3] = t3; dst[i+bidx] = t0; dst[i+1] = t1; dst[i+(bidx^2)] = t2; dst[i+3] = t3;
} }
} }
} }

@ -2190,3 +2190,28 @@ TEST(ImgProc_Bayer2RGBA, accuracy)
} }
} }
} }
TEST(ImgProc_BGR2RGBA, regression_8696)
{
Mat src(Size(80, 10), CV_8UC4);
src.setTo(Scalar(255, 0, 200, 100));
Mat dst;
cvtColor(src, dst, COLOR_BGR2BGRA);
EXPECT_DOUBLE_EQ(norm(dst - src, NORM_INF), 0.);
}
TEST(ImgProc_BGR2RGBA, 3ch24ch)
{
Mat src(Size(80, 10), CV_8UC3);
src.setTo(Scalar(200, 0, 200));
Mat dst;
cvtColor(src, dst, COLOR_BGR2BGRA);
Mat expected(Size(80, 10), CV_8UC4);
expected.setTo(Scalar(80, 0, 200, 255));
EXPECT_DOUBLE_EQ(norm(expected - dst, NORM_INF), 0.);
}

Loading…
Cancel
Save