cvtColor Luv 2 RGB u8

This commit is contained in:
Ilya Lavrenov 2015-01-12 10:59:30 +03:00
parent e20613a776
commit a340ea872e
2 changed files with 262 additions and 15 deletions

View File

@ -56,10 +56,50 @@ enum
};
CV_ENUM(CvtMode,
COLOR_BGR2BGR555, COLOR_BGR2BGR565, COLOR_BGR2BGRA, COLOR_BGR2GRAY,
COLOR_BGR2HLS, COLOR_BGR2HLS_FULL, COLOR_BGR2HSV, COLOR_BGR2HSV_FULL,
COLOR_BGR2Lab, COLOR_BGR2Luv, COLOR_BGR2RGB, COLOR_BGR2RGBA, COLOR_BGR2XYZ,
COLOR_BGR2YCrCb, COLOR_BGR2YUV, COLOR_BGR5552BGR, COLOR_BGR5552BGRA,
COLOR_BGR5552GRAY, COLOR_BGR5552RGB, COLOR_BGR5552RGBA, COLOR_BGR5652BGR,
COLOR_BGR5652BGRA, COLOR_BGR5652GRAY, COLOR_BGR5652RGB, COLOR_BGR5652RGBA,
COLOR_BGRA2BGR, COLOR_BGRA2BGR555, COLOR_BGRA2BGR565, COLOR_BGRA2GRAY, COLOR_BGRA2RGBA,
CX_BGRA2HLS, CX_BGRA2HLS_FULL, CX_BGRA2HSV, CX_BGRA2HSV_FULL,
CX_BGRA2Lab, CX_BGRA2Luv, CX_BGRA2XYZ,
CX_BGRA2YCrCb, CX_BGRA2YUV,
COLOR_GRAY2BGR, COLOR_GRAY2BGR555, COLOR_GRAY2BGR565, COLOR_GRAY2BGRA,
COLOR_HLS2BGR, COLOR_HLS2BGR_FULL, COLOR_HLS2RGB, COLOR_HLS2RGB_FULL,
CX_HLS2BGRA, CX_HLS2BGRA_FULL, CX_HLS2RGBA, CX_HLS2RGBA_FULL,
COLOR_HSV2BGR, COLOR_HSV2BGR_FULL, COLOR_HSV2RGB, COLOR_HSV2RGB_FULL,
CX_HSV2BGRA, CX_HSV2BGRA_FULL, CX_HSV2RGBA, CX_HSV2RGBA_FULL,
COLOR_Lab2BGR, COLOR_Lab2LBGR, COLOR_Lab2LRGB, COLOR_Lab2RGB,
CX_Lab2BGRA, CX_Lab2LBGRA, CX_Lab2LRGBA, CX_Lab2RGBA,
COLOR_LBGR2Lab, COLOR_LBGR2Luv, COLOR_LRGB2Lab, COLOR_LRGB2Luv,
CX_LBGRA2Lab, CX_LBGRA2Luv, CX_LRGBA2Lab, CX_LRGBA2Luv,
COLOR_Luv2BGR, COLOR_Luv2LBGR, COLOR_Luv2LRGB, COLOR_Luv2RGB,
CX_Luv2BGRA, CX_Luv2LBGRA, CX_Luv2LRGBA, CX_Luv2RGBA,
COLOR_RGB2BGR555, COLOR_RGB2BGR565, COLOR_RGB2GRAY,
COLOR_RGB2HLS, COLOR_RGB2HLS_FULL, COLOR_RGB2HSV, COLOR_RGB2HSV_FULL,
COLOR_RGB2Lab, COLOR_RGB2Luv, COLOR_RGB2XYZ, COLOR_RGB2YCrCb, COLOR_RGB2YUV,
CX_RGBA2YCrCb, CX_RGBA2YUV)
COLOR_RGBA2BGR, COLOR_RGBA2BGR555, COLOR_RGBA2BGR565, COLOR_RGBA2GRAY,
CX_RGBA2HLS, CX_RGBA2HLS_FULL, CX_RGBA2HSV, CX_RGBA2HSV_FULL,
CX_RGBA2Lab, CX_RGBA2Luv, CX_RGBA2XYZ,
CX_RGBA2YCrCb, CX_RGBA2YUV,
COLOR_XYZ2BGR, COLOR_XYZ2RGB, CX_XYZ2BGRA, CX_XYZ2RGBA,
COLOR_YCrCb2BGR, COLOR_YCrCb2RGB, CX_YCrCb2BGRA, CX_YCrCb2RGBA,
COLOR_YUV2BGR, COLOR_YUV2RGB, CX_YUV2BGRA, CX_YUV2RGBA
)
CV_ENUM(CvtModeBayer,
@ -197,25 +237,135 @@ ChPair getConversionInfo(int cvtMode)
return ChPair(0,0);
}
typedef perf::TestBaseWithParam<Size> Size_CvtMode;
typedef std::tr1::tuple<Size, CvtMode> Size_CvtMode_t;
typedef perf::TestBaseWithParam<Size_CvtMode_t> Size_CvtMode;
PERF_TEST_P(Size_CvtMode, cvtColor8u,
testing::Values(::perf::szODD, ::perf::szVGA, ::perf::sz1080p)
testing::Combine(
testing::Values(::perf::szODD, ::perf::szVGA, ::perf::sz1080p),
CvtMode::all()
)
)
{
Size sz = GetParam();
int mode = COLOR_RGB2Luv;
Size sz = get<0>(GetParam());
int _mode = get<1>(GetParam()), mode = _mode;
ChPair ch = getConversionInfo(mode);
mode %= COLOR_COLORCVT_MAX;
Mat src(sz, CV_8UC(3));
Mat dst(sz, CV_8UC(3));
Mat src(sz, CV_8UC(ch.scn));
Mat dst(sz, CV_8UC(ch.dcn));
declare.time(100);
declare.in(src, WARMUP_RNG).out(dst);
int runs = sz.width <= 320 ? 100 : 5;
TEST_CYCLE_MULTIRUN(runs) cvtColor(src, dst, mode, 3);
TEST_CYCLE_MULTIRUN(runs) cvtColor(src, dst, mode, ch.dcn);
SANITY_CHECK_NOTHING();
#if defined(__APPLE__) && defined(HAVE_IPP)
SANITY_CHECK(dst, _mode == CX_BGRA2HLS_FULL ? 2 : 1);
#else
SANITY_CHECK(dst, 1);
#endif
}
typedef std::tr1::tuple<Size, CvtModeBayer> Size_CvtMode_Bayer_t;
typedef perf::TestBaseWithParam<Size_CvtMode_Bayer_t> Size_CvtMode_Bayer;
PERF_TEST_P(Size_CvtMode_Bayer, cvtColorBayer8u,
testing::Combine(
testing::Values(::perf::szODD, ::perf::szVGA),
CvtModeBayer::all()
)
)
{
Size sz = get<0>(GetParam());
int mode = get<1>(GetParam());
ChPair ch = getConversionInfo(mode);
mode %= COLOR_COLORCVT_MAX;
Mat src(sz, CV_8UC(ch.scn));
Mat dst(sz, CV_8UC(ch.dcn));
declare.time(100);
declare.in(src, WARMUP_RNG).out(dst);
TEST_CYCLE() cvtColor(src, dst, mode, ch.dcn);
SANITY_CHECK(dst, 1);
}
typedef std::tr1::tuple<Size, CvtMode2> Size_CvtMode2_t;
typedef perf::TestBaseWithParam<Size_CvtMode2_t> Size_CvtMode2;
PERF_TEST_P(Size_CvtMode2, cvtColorYUV420,
testing::Combine(
testing::Values(szVGA, sz1080p, Size(130, 60)),
CvtMode2::all()
)
)
{
Size sz = get<0>(GetParam());
int mode = get<1>(GetParam());
ChPair ch = getConversionInfo(mode);
Mat src(sz.height + sz.height / 2, sz.width, CV_8UC(ch.scn));
Mat dst(sz, CV_8UC(ch.dcn));
declare.in(src, WARMUP_RNG).out(dst);
int runs = (sz.width <= 640) ? 8 : 1;
TEST_CYCLE_MULTIRUN(runs) cvtColor(src, dst, mode, ch.dcn);
SANITY_CHECK(dst, 1);
}
typedef std::tr1::tuple<Size, CvtMode3> Size_CvtMode3_t;
typedef perf::TestBaseWithParam<Size_CvtMode3_t> Size_CvtMode3;
PERF_TEST_P(Size_CvtMode3, cvtColorRGB2YUV420p,
testing::Combine(
testing::Values(szVGA, sz720p, sz1080p, Size(130, 60)),
CvtMode3::all()
)
)
{
Size sz = get<0>(GetParam());
int mode = get<1>(GetParam());
ChPair ch = getConversionInfo(mode);
Mat src(sz, CV_8UC(ch.scn));
Mat dst(sz.height + sz.height / 2, sz.width, CV_8UC(ch.dcn));
declare.time(100);
declare.in(src, WARMUP_RNG).out(dst);
int runs = (sz.width <= 640) ? 10 : 1;
TEST_CYCLE_MULTIRUN(runs) cvtColor(src, dst, mode, ch.dcn);
SANITY_CHECK(dst, 1);
}
CV_ENUM(EdgeAwareBayerMode, COLOR_BayerBG2BGR_EA, COLOR_BayerGB2BGR_EA, COLOR_BayerRG2BGR_EA, COLOR_BayerGR2BGR_EA)
typedef std::tr1::tuple<Size, EdgeAwareBayerMode> EdgeAwareParams;
typedef perf::TestBaseWithParam<EdgeAwareParams> EdgeAwareDemosaicingTest;
PERF_TEST_P(EdgeAwareDemosaicingTest, demosaicingEA,
testing::Combine(
testing::Values(szVGA, sz720p, sz1080p, Size(130, 60)),
EdgeAwareBayerMode::all()
)
)
{
Size sz = get<0>(GetParam());
int mode = get<1>(GetParam());
Mat src(sz, CV_8UC1);
Mat dst(sz, CV_8UC3);
declare.in(src, WARMUP_RNG).out(dst);
TEST_CYCLE() cvtColor(src, dst, mode, 3);
SANITY_CHECK(dst, 1);
}

View File

@ -4376,7 +4376,7 @@ struct HSV2RGB_b
{
int i, j, dcn = dstcn;
uchar alpha = ColorChannel<uchar>::max();
CV_DECL_ALIGNED(16) float buf[3*BLOCK_SIZE];
float CV_DECL_ALIGNED(16) buf[3*BLOCK_SIZE];
for( i = 0; i < n; i += BLOCK_SIZE, src += BLOCK_SIZE*3 )
{
@ -4622,7 +4622,7 @@ struct RGB2HLS_b
void operator()(const uchar* src, uchar* dst, int n) const
{
int i, j, scn = srccn;
CV_DECL_ALIGNED(16) float buf[3*BLOCK_SIZE];
float CV_DECL_ALIGNED(16) buf[3*BLOCK_SIZE];
for( i = 0; i < n; i += BLOCK_SIZE, dst += BLOCK_SIZE*3 )
{
@ -4876,7 +4876,7 @@ struct HLS2RGB_b
{
int i, j, dcn = dstcn;
uchar alpha = ColorChannel<uchar>::max();
CV_DECL_ALIGNED(16) float buf[3*BLOCK_SIZE];
float CV_DECL_ALIGNED(16) buf[3*BLOCK_SIZE];
for( i = 0; i < n; i += BLOCK_SIZE, src += BLOCK_SIZE*3 )
{
@ -5375,7 +5375,7 @@ struct Lab2RGB_b
{
int i, j, dcn = dstcn;
uchar alpha = ColorChannel<uchar>::max();
CV_DECL_ALIGNED(16) float buf[3*BLOCK_SIZE];
float CV_DECL_ALIGNED(16) buf[3*BLOCK_SIZE];
for( i = 0; i < n; i += BLOCK_SIZE, src += BLOCK_SIZE*3 )
{
@ -5731,7 +5731,7 @@ struct RGB2Luv_b
void operator()(const uchar* src, uchar* dst, int n) const
{
int i, j, scn = srccn;
float buf[3*BLOCK_SIZE];
float CV_DECL_ALIGNED(16) buf[3*BLOCK_SIZE];
for( i = 0; i < n; i += BLOCK_SIZE, dst += BLOCK_SIZE*3 )
{
@ -5888,14 +5888,54 @@ struct Luv2RGB_b
v_140 = vdupq_n_f32(140.f);
v_scale = vdupq_n_f32(255.f);
v_alpha = vdup_n_u8(ColorChannel<uchar>::max());
#elif CV_SSE2
v_scale_inv = _mm_set1_ps(100.f/255.f);
v_coeff1 = _mm_set1_ps(1.388235294117647f);
v_coeff2 = _mm_set1_ps(1.027450980392157f);
v_134 = _mm_set1_ps(134.f);
v_140 = _mm_set1_ps(140.f);
v_scale = _mm_set1_ps(255.f);
v_zero = _mm_setzero_si128();
#endif
}
#if CV_SSE2
// 16s x 8
void process(__m128i v_l, __m128i v_u, __m128i v_v,
float * buf) const
{
__m128 v_l0 = _mm_cvtepi32_ps(_mm_unpacklo_epi16(v_l, v_zero));
__m128 v_u0 = _mm_cvtepi32_ps(_mm_unpacklo_epi16(v_u, v_zero));
__m128 v_v0 = _mm_cvtepi32_ps(_mm_unpacklo_epi16(v_v, v_zero));
__m128 v_l1 = _mm_cvtepi32_ps(_mm_unpackhi_epi16(v_l, v_zero));
__m128 v_u1 = _mm_cvtepi32_ps(_mm_unpackhi_epi16(v_u, v_zero));
__m128 v_v1 = _mm_cvtepi32_ps(_mm_unpackhi_epi16(v_v, v_zero));
v_l0 = _mm_mul_ps(v_l0, v_scale_inv);
v_l1 = _mm_mul_ps(v_l1, v_scale_inv);
v_u0 = _mm_sub_ps(_mm_mul_ps(v_u0, v_coeff1), v_134);
v_u1 = _mm_sub_ps(_mm_mul_ps(v_u1, v_coeff1), v_134);
v_v0 = _mm_sub_ps(_mm_mul_ps(v_v0, v_coeff2), v_140);
v_v1 = _mm_sub_ps(_mm_mul_ps(v_v1, v_coeff2), v_140);
_MM_INTERLIV_PS(v_l0, v_l1, v_u0, v_u1, v_v0, v_v1)
_mm_store_ps(buf, v_l0);
_mm_store_ps(buf + 4, v_l1);
_mm_store_ps(buf + 8, v_u0);
_mm_store_ps(buf + 12, v_u1);
_mm_store_ps(buf + 16, v_v0);
_mm_store_ps(buf + 20, v_v1);
}
#endif
void operator()(const uchar* src, uchar* dst, int n) const
{
int i, j, dcn = dstcn;
uchar alpha = ColorChannel<uchar>::max();
float buf[3*BLOCK_SIZE];
float CV_DECL_ALIGNED(16) buf[3*BLOCK_SIZE];
for( i = 0; i < n; i += BLOCK_SIZE, src += BLOCK_SIZE*3 )
{
@ -5921,6 +5961,38 @@ struct Luv2RGB_b
v_dst.val[2] = vsubq_f32(vmulq_f32(vcvtq_f32_u32(vmovl_u16(vget_high_u16(v_t2))), v_coeff2), v_140);
vst3q_f32(buf + j + 12, v_dst);
}
#elif CV_SSE2
for ( ; j <= (dn - 32) * 3; j += 96)
{
__m128i v_r0 = _mm_loadu_si128((__m128i const *)(src + j));
__m128i v_r1 = _mm_loadu_si128((__m128i const *)(src + j + 16));
__m128i v_g0 = _mm_loadu_si128((__m128i const *)(src + j + 32));
__m128i v_g1 = _mm_loadu_si128((__m128i const *)(src + j + 48));
__m128i v_b0 = _mm_loadu_si128((__m128i const *)(src + j + 64));
__m128i v_b1 = _mm_loadu_si128((__m128i const *)(src + j + 80));
_MM_DEINTERLIV_EPI8(v_r0, v_r1, v_g0, v_g1, v_b0, v_b1)
process(_mm_unpacklo_epi8(v_r0, v_zero),
_mm_unpacklo_epi8(v_g0, v_zero),
_mm_unpacklo_epi8(v_b0, v_zero),
buf + j);
process(_mm_unpackhi_epi8(v_r0, v_zero),
_mm_unpackhi_epi8(v_g0, v_zero),
_mm_unpackhi_epi8(v_b0, v_zero),
buf + j + 24);
process(_mm_unpacklo_epi8(v_r1, v_zero),
_mm_unpacklo_epi8(v_g1, v_zero),
_mm_unpacklo_epi8(v_b1, v_zero),
buf + j + 48);
process(_mm_unpackhi_epi8(v_r1, v_zero),
_mm_unpackhi_epi8(v_g1, v_zero),
_mm_unpackhi_epi8(v_b1, v_zero),
buf + j + 72);
}
#endif
for( ; j < dn*3; j += 3 )
{
@ -5960,6 +6032,28 @@ struct Luv2RGB_b
vst3_u8(dst, v_dst);
}
}
#elif CV_SSE2
if (dcn == 3)
{
for ( ; j <= (dn * 3 - 16); j += 16, dst += 16)
{
__m128 v_src0 = _mm_mul_ps(_mm_load_ps(buf + j), v_scale);
__m128 v_src1 = _mm_mul_ps(_mm_load_ps(buf + j + 4), v_scale);
__m128 v_src2 = _mm_mul_ps(_mm_load_ps(buf + j + 8), v_scale);
__m128 v_src3 = _mm_mul_ps(_mm_load_ps(buf + j + 12), v_scale);
__m128i v_dst0 = _mm_packs_epi32(_mm_cvtps_epi32(v_src0),
_mm_cvtps_epi32(v_src1));
__m128i v_dst1 = _mm_packs_epi32(_mm_cvtps_epi32(v_src2),
_mm_cvtps_epi32(v_src3));
_mm_storeu_si128((__m128i *)dst, _mm_packus_epi16(v_dst0, v_dst1));
}
int jr = j % 3;
if (jr)
dst -= jr, j -= jr;
}
#endif
for( ; j < dn*3; j += 3, dst += dcn )
@ -5979,6 +6073,9 @@ struct Luv2RGB_b
#if CV_NEON
float32x4_t v_scale, v_scale_inv, v_coeff1, v_coeff2, v_134, v_140;
uint8x8_t v_alpha;
#elif CV_SSE2
__m128 v_scale, v_scale_inv, v_coeff1, v_coeff2, v_134, v_140;
__m128i v_zero;
#endif
};