10 #include <smmintrin.h> 15 static constexpr
auto DOWNSAMPLE_FACTOR = 4;
17 assert(source.cols % 8 == 0);
18 assert(source.rows % 4 == 0);
19 assert(source.type() == CV_16U);
21 assert(pDest->cols == source.cols / DOWNSAMPLE_FACTOR);
22 assert(pDest->rows == source.rows / DOWNSAMPLE_FACTOR);
23 assert(pDest->type() == CV_16U);
25 const size_t sizeYresized = source.rows / DOWNSAMPLE_FACTOR;
28 __m128i ones = _mm_set1_epi16(1);
34 #pragma omp parallel for 35 for (
int y = 0;
y < sizeYresized;
y++)
38 const int newY =
y * 4;
40 __m128i A = _mm_loadu_si128((
const __m128i*)&source.at<
uint16_t>(newY,
x));
41 __m128i B = _mm_loadu_si128((
const __m128i*)&source.at<
uint16_t>(newY + 1,
x));
42 __m128i C = _mm_loadu_si128((
const __m128i*)&source.at<
uint16_t>(newY + 2,
x));
43 __m128i
D = _mm_loadu_si128((
const __m128i*)&source.at<
uint16_t>(newY + 3,
x));
46 A = _mm_sub_epi16(A, ones);
47 B = _mm_sub_epi16(B, ones);
48 C = _mm_sub_epi16(C, ones);
49 D = _mm_sub_epi16(D, ones);
52 __m128i rowMin = _mm_min_epu16(D, C);
53 rowMin = _mm_min_epu16(rowMin, B);
54 rowMin = _mm_min_epu16(rowMin, A);
56 __m128i shuf32 = _mm_shuffle_epi32(rowMin, _MM_SHUFFLE(2, 3, 0, 1));
58 __m128i min32 = _mm_min_epu16(rowMin, shuf32);
60 __m128i shuf16 = _mm_shufflelo_epi16(min32, _MM_SHUFFLE(3, 2, 0, 1));
61 shuf16 = _mm_shufflehi_epi16(shuf16, _MM_SHUFFLE(3, 2, 0, 1));
63 __m128i min2 = _mm_min_epu16(min32, shuf16);
66 min2 = _mm_add_epi16(min2, ones);
68 uint16_t minA = _mm_extract_epi16(min2, 0);
69 uint16_t minB = _mm_extract_epi16(min2, 4);
71 pDest->at<
uint16_t>(
y,
x / DOWNSAMPLE_FACTOR) = minA;
72 pDest->at<
uint16_t>(
y,
x / DOWNSAMPLE_FACTOR + 1) = minB;
79 #pragma omp parallel for 80 for (
int y = 0;
y < sizeYresized;
y++)
81 for (
int x = 0;
x < source.cols;
x += DOWNSAMPLE_FACTOR)
86 for (
int i = 0;
i < DOWNSAMPLE_FACTOR;
i++)
87 for (
int j = 0;
j < DOWNSAMPLE_FACTOR;
j++)
95 if (min_value == MAX_DEPTH) min_value = 0;
97 pDest->at<
uint16_t>(
y,
x / DOWNSAMPLE_FACTOR) = min_value;
void downsample_min_4x4(const cv::Mat &source, cv::Mat *pDest)
GLsizei GLsizei GLchar * source