1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#ifndef SUMTHRESHOLD_H
#define SUMTHRESHOLD_H
#include <cstddef>
#include <cstring>
#include "../../structures/image2d.h"
#include "../../structures/mask2d.h"
class SumThreshold
{
public:
struct VerticalScratch
{
VerticalScratch(size_t width, size_t height);
std::unique_ptr<int[], decltype(&free)> lastFlaggedPos;
std::unique_ptr<num_t[], decltype(&free)> sum;
std::unique_ptr<int[], decltype(&free)> count;
};
template<size_t Length>
static void Horizontal(const Image2D* input, Mask2D* mask, num_t threshold);
template<size_t Length>
static void Vertical(const Image2D* input, Mask2D* mask, num_t threshold);
template<size_t Length>
static void HorizontalLarge(const Image2D* input, Mask2D* mask, Mask2D* scratch, num_t threshold);
#ifdef __SSE__
template<size_t Length>
static void VerticalLargeSSE(const Image2D* input, Mask2D* mask, Mask2D* scratch, num_t threshold);
static void VerticalLargeSSE(const Image2D* input, Mask2D* mask, Mask2D* scratch, size_t length, num_t threshold);
template<size_t Length>
static void HorizontalLargeSSE(const Image2D* input, Mask2D* mask, Mask2D* scratch, num_t threshold);
static void HorizontalLargeSSE(const Image2D* input, Mask2D* mask, Mask2D* scratch, size_t length, num_t threshold);
#endif
#ifdef __AVX2__
template<size_t Length>
static void VerticalLargeAVX(const Image2D* input, Mask2D* mask, Mask2D* scratch, num_t threshold);
static void VerticalLargeAVX(const Image2D* input, Mask2D* mask, Mask2D* scratch, size_t length, num_t threshold);
static void HorizontalAVXDumas(const Image2D* input, Mask2D* mask, size_t length, num_t threshold);
static void VerticalAVXDumas(const Image2D* input, Mask2D* mask, VerticalScratch* scratch, size_t length, num_t threshold);
template<size_t Length>
static void HorizontalAVXDumas(const Image2D* input, Mask2D* mask, num_t threshold);
template<size_t Length>
static void VerticalAVXDumas(const Image2D* input, Mask2D* mask, VerticalScratch* scratch, num_t threshold);
#endif
template<size_t Length>
static void VerticalLarge(const Image2D* input, Mask2D* mask, Mask2D* scratch, num_t threshold);
template<size_t Length>
static void Large(const Image2D* input, Mask2D* mask, num_t hThreshold, num_t vThreshold)
{
HorizontalLarge<Length>(input, mask, hThreshold);
VerticalLarge<Length>(input, mask, vThreshold);
}
static void VerticalLarge(const Image2D* input, Mask2D* mask, Mask2D* scratch, VerticalScratch* vScratch, size_t length, num_t threshold)
{
#if defined(__AVX2__)
VerticalAVXDumas(input, mask, vScratch, length, threshold);
#elif defined(__SSE__)
VerticalLargeSSE(input, mask, scratch, length, threshold);
#else
VerticalLargeReference(input, mask, scratch, length, threshold);
#endif
}
static void VerticalLargeReference(const Image2D* input, Mask2D* mask, Mask2D* scratch, size_t length, num_t threshold);
static void HorizontalLargeReference(const Image2D* input, Mask2D* mask, Mask2D* scratch, size_t length, num_t threshold);
static void HorizontalLarge(const Image2D* input, Mask2D* mask, Mask2D* scratch, size_t length, num_t threshold)
{
#if defined(__AVX2__)
if(length >= 64)
HorizontalAVXDumas(input, mask, length, threshold);
else
HorizontalLargeSSE(input, mask, scratch, length, threshold);
#elif defined(__SSE__)
HorizontalLargeSSE(input, mask, scratch, length, threshold);
#else
HorizontalLargeReference(input, mask, scratch, length, threshold);
#endif
}
};
#endif
|