File: SimdGaussianBlur.h

package info (click to toggle)
visp 3.7.0-7
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 166,380 kB
  • sloc: cpp: 392,705; ansic: 224,448; xml: 23,444; python: 13,701; java: 4,792; sh: 206; objc: 145; makefile: 118
file content (148 lines) | stat: -rw-r--r-- 4,964 bytes parent folder | download | duplicates (6)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Simd Library (http://ermig1979.github.io/Simd).
*
* Copyright (c) 2011-2021 Yermalayeu Ihar.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __SimdGaussianBlur_h__
#define __SimdGaussianBlur_h__

#include "Simd/SimdArray.h"
#include "Simd/SimdMath.h"
#include "Simd/SimdCopyPixel.h"

namespace Simd
{
    struct BlurParam
    {
        size_t width;
        size_t height;
        size_t channels;
        float sigma;
        float epsilon;
        size_t align;

        BlurParam(size_t w, size_t h, size_t c, const float* s, const float * e, size_t a);
        bool Valid() const;
    };

    class GaussianBlur : Deletable
    {
    public:
        GaussianBlur(const BlurParam& param);

        virtual void Run(const uint8_t* src, size_t srcStride, uint8_t* dst, size_t dstStride) = 0;

    protected:
        BlurParam _param;
    };

    namespace Base
    {
        template<int channels> SIMD_INLINE void PadCols(const uint8_t* src, size_t half, size_t size, uint8_t* dst)
        {
            for (size_t x = 0; x < half; x += 1, dst += channels)
                Base::CopyPixel<channels>(src, dst);
            memcpy(dst, src, size), dst += size, src += size - channels;
            for (size_t x = 0; x < half; x += 1, dst += channels)
                Base::CopyPixel<channels>(src, dst);
        }

        //---------------------------------------------------------------------

        struct AlgDefault
        {
            size_t half, kernel, edge, start, size, stride, nose, body;
            Array32f weight;
        };

        typedef void (*BlurDefaultPtr)(const BlurParam& p, const AlgDefault& a, const uint8_t* src, 
            size_t srcStride, uint8_t* cols, float* rows, uint8_t* dst, size_t dstStride);

        class GaussianBlurDefault : public Simd::GaussianBlur
        {
        public:
            GaussianBlurDefault(const BlurParam& param);

            virtual void Run(const uint8_t* src, size_t srcStride, uint8_t* dst, size_t dstStride);

        protected:
            AlgDefault _alg;
            Array8u _cols;
            Array32f _rows;
            BlurDefaultPtr _blur;
        };

        void * GaussianBlurInit(size_t width, size_t height, size_t channels, const float* sigma, const float* epsilon);
    }

#ifdef SIMD_SSE41_ENABLE    
    namespace Sse41
    {
        class GaussianBlurDefault : public Base::GaussianBlurDefault
        {
        public:
            GaussianBlurDefault(const BlurParam& param);
        };

        void* GaussianBlurInit(size_t width, size_t height, size_t channels, const float* sigma, const float* epsilon);
    }
#endif //SIMD_SSE41_ENABLE

#ifdef SIMD_AVX2_ENABLE    
    namespace Avx2
    {
        class GaussianBlurDefault : public Sse41::GaussianBlurDefault
        {
        public:
            GaussianBlurDefault(const BlurParam& param);
        };

        void* GaussianBlurInit(size_t width, size_t height, size_t channels, const float* sigma, const float* epsilon);
    }
#endif //SIMD_AVX2_ENABLE

#ifdef SIMD_AVX512BW_ENABLE    
    namespace Avx512bw
    {
        class GaussianBlurDefault : public Avx2::GaussianBlurDefault
        {
        public:
            GaussianBlurDefault(const BlurParam& param);
        };

        void* GaussianBlurInit(size_t width, size_t height, size_t channels, const float* sigma, const float* epsilon);
    }
#endif //SIMD_AVX512BW_ENABLE

#ifdef SIMD_NEON_ENABLE    
    namespace Neon
    {
        class GaussianBlurDefault : public Base::GaussianBlurDefault
        {
        public:
            GaussianBlurDefault(const BlurParam& param);
        };

        void* GaussianBlurInit(size_t width, size_t height, size_t channels, const float* sigma, const float* epsilon);
    }
#endif //SIMD_NEON_ENABLE
}
#endif//__SimdGaussianBlur_h__