SDC C-Project CF Review 프로그램
LYW
2022-08-05 5f12658f37fed156e67b3318542c98f359341ffd
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
 
#ifndef BASEFWT2D_H
#define BASEFWT2D_H
 
/*
     BaseFWT2D (abstract)
 
    //derived (redefine transrows, transcols, synthrows, synthcols)
       -FWT2D
       -mHaar
       -mBior53
       -mBior97
*/
 
class vec1D;
 
class BaseFWT2D
{        
public:
    BaseFWT2D(const wchar_t* fname);
    BaseFWT2D(const wchar_t* fname, const float* tH, unsigned int thL, int thZ,
                const float* tG, unsigned int tgL, int tgZ,
                const float* H, unsigned int hL, int hZ,
                const float* G, unsigned int gL, int gZ);
    virtual ~BaseFWT2D();
 
// Operators
 
// Operations
    void init(unsigned int width, unsigned int height);                                 //allocate buffers for transforms  status=1
    void init(char* data, char* tdata, unsigned int width, unsigned int height);        //use supplied buffers  status=2
    void close(void);                                                                   //deallocate buffers        
 
    //FWT transforms
    int trans(unsigned int scales, unsigned int th = 0);                               //forward transform data in spec buffer
    int trans(const char* data, unsigned int scales, unsigned int th = 0);             //forward transform DC corrected data
    int trans(const unsigned char* data, unsigned int scales, unsigned int th = 0);    //forward transform DC uncorrected data
    int synth();                                                                       //synthesis fwt spectrum in spec buffer
    int synth(char* data);                                                             //synthesis to DC corrected data buffer
    int synth(unsigned char* data);                                                    //synthesis to DC uncorrected data buffer
 
    //denoising
    void remove_LLband();
 
// Access
 
// Inquiry
    const wchar_t* status(int& status) const;                                           //get status after constructor
    void tracefilters(const wchar_t* fname) const;                                      //trace filters
 
    inline unsigned int width() const;                                                  //data width
    inline unsigned int height() const;                                                 //data height
    inline char* getspec() const;                                                       //get spectrum buffer
    inline char** getspec2d() const;                                                    //get 2D spectrum buffer
    inline char* gettspec() const;                                                      //get temp fwt buffer
 
    inline unsigned int getJ() const;
    inline void setJ(unsigned int j);                
 
 
protected:
    inline const vec1D& gettH() const;
    inline const vec1D& gettG() const;
    inline const vec1D& getH2m() const;
    inline const vec1D& getG2m() const;
    inline const vec1D& getH2m1() const;
    inline const vec1D& getG2m1() const;
 
    inline unsigned int getTH() const;
 
    inline char mmxround(float f) const;
    inline char mmxroundTH(float f) const;
 
    //virtual functions should be defined in derived ones
    virtual void transrows(char** dest, char** sour, unsigned int w, unsigned int h) const = 0;      //transform rows
    virtual void transcols(char** dest, char** sour, unsigned int w, unsigned int h) const = 0;      //transform cols
    virtual void synthrows(char** dest, char** sour, unsigned int w, unsigned int h) const = 0;      //transform rows
    virtual void synthcols(char** dest, char** sour, unsigned int w, unsigned int h) const = 0;      //transform cols
 
 
private:
 
    int m_status;   //constructor status 0 - not initilized, 
                    //1 - class allocated its own buffers, separate for spec and tspec
                    //2 - class was supplied with buffers for spec and tspec
 
    wchar_t filter[_MAX_PATH];                      //filter name
 
    vec1D* tH;                                      //transform filters
    vec1D* tG;
    vec1D* H;                                       //synthesis filters (never used directly)
    vec1D* G;
    vec1D* H2m;                                     //even 2m coeffs from H,G filters
    vec1D* G2m;
    vec1D* H2m1;                                    //odd 2m+1 coeffs from H,G filters
    vec1D* G2m1;
 
    unsigned int J;                                 //number of scales
    unsigned int TH;                                //threshold for denoising
 
    unsigned int m_width;                           //array width
    unsigned int m_height;                          //array height
    char* spec;                                     //2*width*height fwt spectrum
    char* tspec;                                    //spec + width*height temp fwt buffer
    char** spec2d;                                  //spec 2D version with addreses from spec
    char** tspec2d;                                 //tspec 2D version with addreses from spec
 
 
    vec1D* loadfilter(FILE* flt) const;             //load filter from file  0-error
    void makeHGsynth(void);                         //create 2m,2m1 filters from H,G   -2,-1,0,1,2,3
 
    void mmxmemcpy(char* dest, const char* sour, unsigned int size);                 //copy mem routine
    void sub128(char* dest, const unsigned char* sour, unsigned int size);           //dest = sour - 128
    void add128(unsigned char *dest, const char* sour, unsigned int size);           //dest = sour + 128
 
    //not intended functions
    BaseFWT2D(BaseFWT2D& basefwt);
    const BaseFWT2D& operator=(const BaseFWT2D& basefwt);
 
};
 
 
 
/*
 filter.flt
 
  size zerooffset
   -3   coeff1
   -2   coeff2
   -1   coeff3
    0   coeff4
    1   coeff5
    2   coeff6
 
    tH
    tG
    H
    G
 
 
  usage:
   FWT2D fwt(L"bior97.flt");
    fwt.init(width,height);    //init buffers
     fwt.trans(data,3,30);     //fwt transform from data buffer J=3,TH=30, data is intact after fwt
     fwt.synth(data);          //fwt synthesis to data buffer
     ...
     ...  //keep going multiple times transforming and synthesing
     ...
    fwt.close();
*/
 
 
inline unsigned int BaseFWT2D::getJ() const
{
    return J;
}
 
inline void BaseFWT2D::setJ(unsigned int j)
{
    J = j;
}
 
inline unsigned int BaseFWT2D::width() const
{
    return m_width;
}
 
inline unsigned int BaseFWT2D::height() const
{
    return m_height;
}
 
inline char* BaseFWT2D::getspec() const
{
    return spec;
}
 
inline char** BaseFWT2D::getspec2d() const
{
    return spec2d;
}
 
inline char* BaseFWT2D::gettspec() const
{
    return tspec;
}
 
inline const vec1D& BaseFWT2D::gettH() const
{
    return *tH;
}
 
inline const vec1D& BaseFWT2D::gettG() const
{
    return *tG;
}
 
inline const vec1D& BaseFWT2D::getH2m() const
{
    return *H2m;
}
 
inline const vec1D& BaseFWT2D::getG2m() const
{
    return *G2m;
}
 
inline const vec1D& BaseFWT2D::getH2m1() const
{
    return *H2m1;
}
 
inline const vec1D& BaseFWT2D::getG2m1() const
{
    return *G2m1;
}
 
inline unsigned int BaseFWT2D::getTH() const
{
    return TH;
}
 
inline char BaseFWT2D::mmxroundTH(float f) const
{
    char c[8] = {0, 0, 0, 0, 0, 0, 0, 0};
    __m64 *mc = (__m64 *) c;
 
    __m128 mf = _mm_load_ss(&f);
    *mc = _mm_cvtps_pi8(mf);
 
    _mm_empty();
 
    int th = TH;
    if (th != 0) 
    {       
        //denoise
        if (c[0] > 0) 
        {
            if (c[0] <= th)
                c[0] = 0;
        } else 
        {
            if (c[0] >= -th)
                c[0] = 0;
        }
    }
 
    //if(c[0]%2)                  //quantize
    // c[0] -= c[0]%2;
 
    return c[0];
}
 
inline char BaseFWT2D::mmxround(float f) const
{
    char c[8] = {0, 0, 0, 0, 0, 0, 0, 0};
    __m64 *mc = (__m64 *)c;
 
    __m128 mf = _mm_load_ss(&f);
    *mc = _mm_cvtps_pi8(mf);
 
    _mm_empty();
 
    return c[0];
}
 
#endif