Merge pull request #7309 from K-Shinotsuka:issue22

This commit is contained in:
Alexander Alekhin 2016-09-21 14:46:53 +00:00
commit cde9d640fe

View File

@ -4494,7 +4494,6 @@ struct HSV2RGB_b
v_scale = vdupq_n_f32(255.f); v_scale = vdupq_n_f32(255.f);
v_alpha = vdup_n_u8(ColorChannel<uchar>::max()); v_alpha = vdup_n_u8(ColorChannel<uchar>::max());
#elif CV_SSE2 #elif CV_SSE2
v_scale_inv = _mm_set1_ps(1.f/255.f);
v_scale = _mm_set1_ps(255.0f); v_scale = _mm_set1_ps(255.0f);
v_zero = _mm_setzero_si128(); v_zero = _mm_setzero_si128();
haveSIMD = checkHardwareSupport(CV_CPU_SSE2); haveSIMD = checkHardwareSupport(CV_CPU_SSE2);
@ -4502,8 +4501,8 @@ struct HSV2RGB_b
} }
#if CV_SSE2 #if CV_SSE2
// 16s x 8
void process(__m128i v_r, __m128i v_g, __m128i v_b, void process(__m128i v_r, __m128i v_g, __m128i v_b,
__m128 v_coeffs,
float * buf) const float * buf) const
{ {
__m128 v_r0 = _mm_cvtepi32_ps(_mm_unpacklo_epi16(v_r, v_zero)); __m128 v_r0 = _mm_cvtepi32_ps(_mm_unpacklo_epi16(v_r, v_zero));
@ -4514,13 +4513,18 @@ struct HSV2RGB_b
__m128 v_g1 = _mm_cvtepi32_ps(_mm_unpackhi_epi16(v_g, v_zero)); __m128 v_g1 = _mm_cvtepi32_ps(_mm_unpackhi_epi16(v_g, v_zero));
__m128 v_b1 = _mm_cvtepi32_ps(_mm_unpackhi_epi16(v_b, v_zero)); __m128 v_b1 = _mm_cvtepi32_ps(_mm_unpackhi_epi16(v_b, v_zero));
v_g0 = _mm_mul_ps(v_g0, v_scale_inv); v_r0 = _mm_mul_ps(v_r0, v_coeffs);
v_b0 = _mm_mul_ps(v_b0, v_scale_inv); v_g1 = _mm_mul_ps(v_g1, v_coeffs);
v_g1 = _mm_mul_ps(v_g1, v_scale_inv); v_coeffs = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(v_coeffs), 0x49));
v_b1 = _mm_mul_ps(v_b1, v_scale_inv);
_mm_interleave_ps(v_r0, v_r1, v_g0, v_g1, v_b0, v_b1); v_r1 = _mm_mul_ps(v_r1, v_coeffs);
v_b0 = _mm_mul_ps(v_b0, v_coeffs);
v_coeffs = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(v_coeffs), 0x49));
v_g0 = _mm_mul_ps(v_g0, v_coeffs);
v_b1 = _mm_mul_ps(v_b1, v_coeffs);
_mm_store_ps(buf, v_r0); _mm_store_ps(buf, v_r0);
_mm_store_ps(buf + 4, v_r1); _mm_store_ps(buf + 4, v_r1);
@ -4536,6 +4540,9 @@ struct HSV2RGB_b
int i, j, dcn = dstcn; int i, j, dcn = dstcn;
uchar alpha = ColorChannel<uchar>::max(); uchar alpha = ColorChannel<uchar>::max();
float CV_DECL_ALIGNED(16) buf[3*BLOCK_SIZE]; float CV_DECL_ALIGNED(16) buf[3*BLOCK_SIZE];
#if CV_SSE2
__m128 v_coeffs = _mm_set_ps(1.f, 1.f/255.f, 1.f/255.f, 1.f);
#endif
for( i = 0; i < n; i += BLOCK_SIZE, src += BLOCK_SIZE*3 ) for( i = 0; i < n; i += BLOCK_SIZE, src += BLOCK_SIZE*3 )
{ {
@ -4564,36 +4571,16 @@ struct HSV2RGB_b
#elif CV_SSE2 #elif CV_SSE2
if (haveSIMD) if (haveSIMD)
{ {
for ( ; j <= (dn - 32) * 3; j += 96) for ( ; j <= (dn - 8) * 3; j += 24)
{ {
__m128i v_r0 = _mm_loadu_si128((__m128i const *)(src + j)); __m128i v_src0 = _mm_loadu_si128((__m128i const *)(src + j));
__m128i v_r1 = _mm_loadu_si128((__m128i const *)(src + j + 16)); __m128i v_src1 = _mm_loadl_epi64((__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_deinterleave_epi8(v_r0, v_r1, v_g0, v_g1, v_b0, v_b1); process(_mm_unpacklo_epi8(v_src0, v_zero),
_mm_unpackhi_epi8(v_src0, v_zero),
process(_mm_unpacklo_epi8(v_r0, v_zero), _mm_unpacklo_epi8(v_src1, v_zero),
_mm_unpacklo_epi8(v_g0, v_zero), v_coeffs,
_mm_unpacklo_epi8(v_b0, v_zero),
buf + j); 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 #endif
@ -4677,7 +4664,7 @@ struct HSV2RGB_b
float32x4_t v_scale, v_scale_inv; float32x4_t v_scale, v_scale_inv;
uint8x8_t v_alpha; uint8x8_t v_alpha;
#elif CV_SSE2 #elif CV_SSE2
__m128 v_scale_inv, v_scale; __m128 v_scale;
__m128i v_zero; __m128i v_zero;
bool haveSIMD; bool haveSIMD;
#endif #endif