Debian Codegraph @

cvd_src/SSE2/half_sample.cc

raw symbols SCIP
1 #include "cvd/vision.h"
2 #include <emmintrin.h>
3
4 namespace CVD
5 {
6 namespace Internal
7 {
8
9 void halfSampleSSE2(const byte* in, byte* out, int w, int h)
10 {
11 const unsigned long long mask[2] = { 0x00FF00FF00FF00FFull, 0x00FF00FF00FF00FFull };
12 //byte test[16];
13 const byte* nextRow = in + w;
14 __m128i m = _mm_loadu_si128((const __m128i*)mask);
15 int sw = w >> 4;
16 int sh = h >> 1;
17
18 for(int i = 0; i < sh; i++)
19 {
20 for(int j = 0; j < sw; j++)
21 {
22 __m128i here = _mm_load_si128((const __m128i*)in);
23 __m128i next = _mm_load_si128((const __m128i*)nextRow);
24 here = _mm_avg_epu8(here, next);
25 next = _mm_and_si128(_mm_srli_si128(here, 1), m);
26 here = _mm_and_si128(here, m);
27 here = _mm_avg_epu16(here, next);
28 _mm_storel_epi64((__m128i*)out, _mm_packus_epi16(here, here));
29 in += 16;
30 nextRow += 16;
31 out += 8;
32 }
33
34 in += w;
35 nextRow += w;
36 }
37 }
38 }
39
40 void halfSample(const BasicImage<byte>& in, BasicImage<byte>& out)
41 {
42 if((in.size() / 2) != out.size())
43 throw Exceptions::Vision::IncompatibleImageSizes("halfSample");
44
45 if(is_aligned<16>(in.data()) && is_aligned<16>(out.data()) && ((in.size().x % 16) == 0))
46 Internal::halfSampleSSE2(in.data(), out.data(), in.size().x, in.size().y);
47 else
48 halfSample<byte>(in, out);
49 }
50 }