1 /*******************************************************************************
2 * Copyright 2016-2019 Intel Corporation.
3 *
4 * This software and the related documents are Intel copyrighted  materials,  and
5 * your use of  them is  governed by the  express license  under which  they were
6 * provided to you (License).  Unless the License provides otherwise, you may not
7 * use, modify, copy, publish, distribute,  disclose or transmit this software or
8 * the related documents without Intel's prior written permission.
9 *
10 * This software and the related documents  are provided as  is,  with no express
11 * or implied  warranties,  other  than those  that are  expressly stated  in the
12 * License.
13 *******************************************************************************/
14 
15 #if !defined( __IPP_IWPP_IMAGE_FILTER__ )
16 #define __IPP_IWPP_IMAGE_FILTER__
17 
18 #include "iw/iw_image_filter.h"
19 #include "iw++/iw_image.hpp"
20 
21 namespace ipp
22 {
23 
24 /* /////////////////////////////////////////////////////////////////////////////
25 //                   iwiFilter
26 ///////////////////////////////////////////////////////////////////////////// */
27 
28 // Auxiliary parameters class
29 // C API descriptions has more details
30 class IwiFilterParams: public ::IwiFilterParams
31 {
32 public:
IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterParams,iwiFilter_SetDefaultParams)33     IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterParams, iwiFilter_SetDefaultParams)
34     IwiFilterParams(double _divisor = 0, int _offset = 0, IppHintAlgorithm _algoMode = ippAlgHintNone, IppRoundMode _roundMode = ippRndNear)
35     {
36         this->divisor    = _divisor;
37         this->offset     = _offset;
38         this->roundMode  = _roundMode;
39         this->algoMode   = _algoMode;
40     }
41 };
42 
43 // Performs filtration of an image with an arbitrary kernel
44 // Throws:
45 //      ippStsBorderErr                     border value is illegal
46 //      ippStsDataTypeErr                   data type is illegal
47 //      ippStsNumChannelsErr                channels value is illegal
48 //      ippStsNotEvenStepErr                step value is not divisible by size of elements
49 //      ippStsNotSupportedModeErr           selected function mode is not supported
50 //      ippStsNoMemErr                      failed to allocate memory
51 //      ippStsInplaceModeNotSupportedErr    doesn't support output into the source buffer
52 //      ippStsNullPtrErr                    unexpected NULL pointer
53 // Returns:
54 //      ippStsNoErr                         no errors
iwiFilter(const IwiImage & srcImage,IwiImage & dstImage,const IwiImage & kernel,const IwiFilterParams & auxParams=IwiFilterParams (),const IwiBorderType & border=ippBorderRepl,const IwiTile & tile=IwiTile ())55 IW_DECL_CPP(IppStatus) iwiFilter(
56     const IwiImage         &srcImage,                           // [in]     Reference to the source image
57     IwiImage               &dstImage,                           // [in,out] Reference to the destination image
58     const IwiImage         &kernel,                             // [in]     Reference to the filter kernel image. Kernel must be continuous, [16s,32f], [C1]
59     const IwiFilterParams  &auxParams   = IwiFilterParams(),    // [in]     Reference to the auxiliary parameters structure
60     const IwiBorderType    &border      = ippBorderRepl,        // [in]     Extrapolation algorithm and value for out of image pixels: ippBorderConst, ippBorderRepl, ippBorderMirror, ippBorderInMem
61     const IwiTile          &tile        = IwiTile()             // [in]     Reference to the IwiTile structure for tiling. By default no tiling is used
62 )
63 {
64     IppStatus ippStatus = ::iwiFilter(&srcImage, &dstImage, &kernel, &auxParams, border.m_type, border.m_value, &tile);
65     OWN_ERROR_CHECK(ippStatus)
66     return ippStatus;
67 }
68 
69 /* /////////////////////////////////////////////////////////////////////////////
70 //                   iwiFilterBox
71 ///////////////////////////////////////////////////////////////////////////// */
72 
73 // Auxiliary parameters class
74 // C API descriptions has more details
75 class IwiFilterBoxParams: public ::IwiFilterBoxParams
76 {
77 public:
IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterBoxParams,iwiFilterBox_SetDefaultParams)78     IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterBoxParams, iwiFilterBox_SetDefaultParams)
79     IwiFilterBoxParams(IwiChDescriptor _chDesc = iwiChDesc_None)
80     {
81         this->chDesc = _chDesc;
82     }
83 };
84 
85 // Applies box filter to the image
86 // Throws:
87 //      ippStsBorderErr                     border value is illegal
88 //      ippStsDataTypeErr                   data type is illegal
89 //      ippStsNumChannelsErr                channels value is illegal
90 //      ippStsNotEvenStepErr                step value is not divisible by size of elements
91 //      ippStsNotSupportedModeErr           selected function mode is not supported
92 //      ippStsNoMemErr                      failed to allocate memory
93 //      ippStsInplaceModeNotSupportedErr    doesn't support output into the source buffer
94 //      ippStsNullPtrErr                    unexpected NULL pointer
95 // Returns:
96 //      ippStsNoErr                         no errors
iwiFilterBox(const IwiImage & srcImage,IwiImage & dstImage,IwiSize kernel,const IwiFilterBoxParams & auxParams=IwiFilterBoxParams (),const IwiBorderType & border=ippBorderRepl,const IwiTile & tile=IwiTile ())97 IW_DECL_CPP(IppStatus) iwiFilterBox(
98     const IwiImage             &srcImage,                           // [in]     Reference to the source image
99     IwiImage                   &dstImage,                           // [in,out] Reference to the destination image
100     IwiSize                     kernel,                             // [in]     Size of the filter kernel
101     const IwiFilterBoxParams   &auxParams   = IwiFilterBoxParams(), // [in]     Reference to the auxiliary parameters structure
102     const IwiBorderType        &border      = ippBorderRepl,        // [in]     Extrapolation algorithm and value for out of image pixels: ippBorderConst, ippBorderRepl, ippBorderMirror, ippBorderInMem
103     const IwiTile              &tile        = IwiTile()             // [in]     Reference to the IwiTile structure for tiling. By default no tiling is used
104 )
105 {
106     IppStatus ippStatus = ::iwiFilterBox(&srcImage, &dstImage, kernel, &auxParams, border.m_type, border.m_value, &tile);
107     OWN_ERROR_CHECK(ippStatus)
108     return ippStatus;
109 }
110 
111 /* /////////////////////////////////////////////////////////////////////////////
112 //                   iwiFilterSobel
113 ///////////////////////////////////////////////////////////////////////////// */
114 
115 // Auxiliary parameters class
116 // C API descriptions has more details
117 class IwiFilterSobelParams: public ::IwiFilterSobelParams
118 {
119 public:
IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterSobelParams,iwiFilterSobel_SetDefaultParams)120     IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterSobelParams, iwiFilterSobel_SetDefaultParams)
121     IwiFilterSobelParams() {}
122 };
123 
124 // Applies Sobel filter of specific type to the source image
125 // C API descriptions has more details.
126 // Throws:
127 //      ippStsMaskSizeErr                   mask value is illegal
128 //      ippStsDataTypeErr                   data type is illegal
129 //      ippStsNumChannelsErr                channels value is illegal
130 //      ippStsNotEvenStepErr                step value is not divisible by size of elements
131 //      ippStsBorderErr                     border value is illegal
132 //      ippStsNotSupportedModeErr           selected function mode is not supported
133 //      ippStsNoMemErr                      failed to allocate memory
134 //      ippStsSizeErr                       size fields values are illegal
135 //      ippStsInplaceModeNotSupportedErr    doesn't support output into the source buffer
136 //      ippStsNullPtrErr                    unexpected NULL pointer
137 // Returns:
138 //      ippStsNoErr                         no errors
iwiFilterSobel(const IwiImage & srcImage,IwiImage & dstImage,IwiDerivativeType opType,IppiMaskSize kernelSize=ippMskSize3x3,const IwiFilterSobelParams & auxParams=IwiFilterSobelParams (),const IwiBorderType & border=ippBorderRepl,const IwiTile & tile=IwiTile ())139 IW_DECL_CPP(IppStatus) iwiFilterSobel(
140     const IwiImage             &srcImage,                               // [in]     Reference to the source image
141     IwiImage                   &dstImage,                               // [in,out] Reference to the destination image
142     IwiDerivativeType           opType,                                 // [in]     Type of derivative from IwiDerivativeType
143     IppiMaskSize                kernelSize  = ippMskSize3x3,            // [in]     Size of filter kernel: ippMskSize3x3, ippMskSize5x5
144     const IwiFilterSobelParams &auxParams   = IwiFilterSobelParams(),   // [in]     Reference to the auxiliary parameters structure
145     const IwiBorderType        &border      = ippBorderRepl,            // [in]     Extrapolation algorithm and value for out of image pixels: ippBorderConst, ippBorderRepl, ippBorderMirror, ippBorderInMem
146     const IwiTile              &tile        = IwiTile()                 // [in]     Reference to the IwiTile structure for tiling. By default no tiling is used
147 )
148 {
149     IppStatus ippStatus = ::iwiFilterSobel(&srcImage, &dstImage, opType, kernelSize, &auxParams, border.m_type, border.m_value, &tile);
150     OWN_ERROR_CHECK(ippStatus)
151     return ippStatus;
152 }
153 
154 /* /////////////////////////////////////////////////////////////////////////////
155 //                   iwiFilterScharr
156 ///////////////////////////////////////////////////////////////////////////// */
157 
158 // Auxiliary parameters class
159 // C API descriptions has more details
160 class IwiFilterScharrParams: public ::IwiFilterScharrParams
161 {
162 public:
IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterScharrParams,iwiFilterScharr_SetDefaultParams)163     IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterScharrParams, iwiFilterScharr_SetDefaultParams)
164     IwiFilterScharrParams() {}
165 };
166 
167 // Applies Scharr filter of specific type to the source image
168 // C API descriptions has more details
169 // Throws:
170 //      ippStsMaskSizeErr                   mask value is illegal
171 //      ippStsDataTypeErr                   data type is illegal
172 //      ippStsNumChannelsErr                channels value is illegal
173 //      ippStsNotEvenStepErr                step value is not divisible by size of elements
174 //      ippStsBorderErr                     border value is illegal
175 //      ippStsNotSupportedModeErr           selected function mode is not supported
176 //      ippStsNoMemErr                      failed to allocate memory
177 //      ippStsSizeErr                       size fields values are illegal
178 //      ippStsInplaceModeNotSupportedErr    doesn't support output into the source buffer
179 //      ippStsNullPtrErr                    unexpected NULL pointer
180 // Returns:
181 //      ippStsNoErr                         no errors
iwiFilterScharr(const IwiImage & srcImage,IwiImage & dstImage,IwiDerivativeType opType,IppiMaskSize kernelSize=ippMskSize3x3,const IwiFilterScharrParams & auxParams=IwiFilterScharrParams (),const IwiBorderType & border=ippBorderRepl,const IwiTile & tile=IwiTile ())182 IW_DECL_CPP(IppStatus) iwiFilterScharr(
183     const IwiImage              &srcImage,                              // [in]     Reference to the source image
184     IwiImage                    &dstImage,                              // [in,out] Reference to the destination image
185     IwiDerivativeType            opType,                                // [in]     Type of derivative from IwiDerivativeType
186     IppiMaskSize                 kernelSize = ippMskSize3x3,            // [in]     Size of filter kernel: ippMskSize3x3, ippMskSize5x5
187     const IwiFilterScharrParams &auxParams  = IwiFilterScharrParams(),  // [in]     Reference to the auxiliary parameters structure
188     const IwiBorderType         &border     = ippBorderRepl,            // [in]     Extrapolation algorithm and value for out of image pixels: ippBorderConst, ippBorderRepl, ippBorderMirror, ippBorderInMem
189     const IwiTile               &tile       = IwiTile()                 // [in]     Reference to the IwiTile structure for tiling. By default no tiling is used
190 )
191 {
192     IppStatus ippStatus = ::iwiFilterScharr(&srcImage, &dstImage, opType, kernelSize, &auxParams, border.m_type, border.m_value, &tile);
193     OWN_ERROR_CHECK(ippStatus)
194     return ippStatus;
195 }
196 
197 /**/////////////////////////////////////////////////////////////////////////////
198 //                   iwiFilterLaplacian
199 ///////////////////////////////////////////////////////////////////////////// */
200 
201 // Auxiliary parameters class
202 // C API descriptions has more details
203 class IwiFilterLaplacianParams: public ::IwiFilterLaplacianParams
204 {
205 public:
IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterLaplacianParams,iwiFilterLaplacian_SetDefaultParams)206     IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterLaplacianParams, iwiFilterLaplacian_SetDefaultParams)
207     IwiFilterLaplacianParams() {}
208 };
209 
210 // Applies Laplacian filter to the source image
211 // C API descriptions has more details.
212 // Throws:
213 //      ippStsMaskSizeErr                   mask value is illegal
214 //      ippStsDataTypeErr                   data type is illegal
215 //      ippStsNumChannelsErr                channels value is illegal
216 //      ippStsNotEvenStepErr                step value is not divisible by size of elements
217 //      ippStsBorderErr                     border value is illegal
218 //      ippStsNotSupportedModeErr           selected function mode is not supported
219 //      ippStsNoMemErr                      failed to allocate memory
220 //      ippStsSizeErr                       size fields values are illegal
221 //      ippStsInplaceModeNotSupportedErr    doesn't support output into the source buffer
222 //      ippStsNullPtrErr                    unexpected NULL pointer
223 // Returns:
224 //      ippStsNoErr                         no errors
iwiFilterLaplacian(const IwiImage & srcImage,IwiImage & dstImage,IppiMaskSize kernelSize=ippMskSize3x3,const IwiFilterLaplacianParams & auxParams=IwiFilterLaplacianParams (),const IwiBorderType & border=ippBorderRepl,const IwiTile & tile=IwiTile ())225 IW_DECL_CPP(IppStatus) iwiFilterLaplacian(
226     const IwiImage                 &srcImage,                                   // [in]     Reference to the source image
227     IwiImage                       &dstImage,                                   // [in,out] Reference to the destination image
228     IppiMaskSize                    kernelSize  = ippMskSize3x3,                // [in]     Size of filter kernel: ippMskSize3x3, ippMskSize5x5
229     const IwiFilterLaplacianParams &auxParams   = IwiFilterLaplacianParams(),   // [in]     Reference to the auxiliary parameters structure
230     const IwiBorderType            &border      = ippBorderRepl,                // [in]     Extrapolation algorithm and value for out of image pixels: ippBorderConst, ippBorderRepl, ippBorderMirror, ippBorderInMem
231     const IwiTile                  &tile        = IwiTile()                     // [in]     Reference to the IwiTile structure for tiling. By default no tiling is used
232 )
233 {
234     IppStatus ippStatus = ::iwiFilterLaplacian(&srcImage, &dstImage, kernelSize, &auxParams, border.m_type, border.m_value, &tile);
235     OWN_ERROR_CHECK(ippStatus)
236     return ippStatus;
237 }
238 
239 
240 /**/////////////////////////////////////////////////////////////////////////////
241 //                   iwiFilterGaussian
242 ///////////////////////////////////////////////////////////////////////////// */
243 
244 // Auxiliary parameters class
245 // C API descriptions has more details
246 class IwiFilterGaussianParams: public ::IwiFilterGaussianParams
247 {
248 public:
IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterGaussianParams,iwiFilterGaussian_SetDefaultParams)249     IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterGaussianParams, iwiFilterGaussian_SetDefaultParams)
250     IwiFilterGaussianParams(IwiChDescriptor _chDesc = iwiChDesc_None)
251     {
252         this->chDesc = _chDesc;
253     }
254 };
255 
256 // Applies Gaussian filter to the source image
257 // C API descriptions has more details.
258 // Throws:
259 //      ippStsMaskSizeErr                   mask value is illegal
260 //      ippStsDataTypeErr                   data type is illegal
261 //      ippStsNumChannelsErr                channels value is illegal
262 //      ippStsNotEvenStepErr                step value is not divisible by size of elements
263 //      ippStsBorderErr                     border value is illegal
264 //      ippStsNotSupportedModeErr           selected function mode is not supported
265 //      ippStsNoMemErr                      failed to allocate memory
266 //      ippStsSizeErr                       size fields values are illegal
267 //      ippStsInplaceModeNotSupportedErr    doesn't support output into the source buffer
268 //      ippStsNullPtrErr                    unexpected NULL pointer
269 // Returns:
270 //      ippStsNoErr                         no errors
iwiFilterGaussian(const IwiImage & srcImage,IwiImage & dstImage,int kernelSize,double sigma,const IwiFilterGaussianParams & auxParams=IwiFilterGaussianParams (),const IwiBorderType & border=ippBorderRepl,const IwiTile & tile=IwiTile ())271 IW_DECL_CPP(IppStatus) iwiFilterGaussian(
272     const IwiImage                 &srcImage,                                   // [in]     Reference to the source image
273     IwiImage                       &dstImage,                                   // [in,out] Reference to the destination image
274     int                             kernelSize,                                 // [in]     Size of the Gaussian kernel (odd, greater or equal to 3)
275     double                          sigma,                                      // [in]     Standard deviation of the Gaussian kernel
276     const IwiFilterGaussianParams  &auxParams   = IwiFilterGaussianParams(),    // [in]     Reference to the auxiliary parameters structure
277     const IwiBorderType            &border      = ippBorderRepl,                // [in]     Extrapolation algorithm and value for out of image pixels: ippBorderConst, ippBorderRepl, ippBorderMirror, ippBorderInMem
278     const IwiTile                  &tile        = IwiTile()                     // [in]     Reference to the IwiTile structure for tiling. By default no tiling is used
279 )
280 {
281     IppStatus ippStatus = ::iwiFilterGaussian(&srcImage, &dstImage, kernelSize, sigma, &auxParams, border.m_type, border.m_value, &tile);
282     OWN_ERROR_CHECK(ippStatus)
283     return ippStatus;
284 }
285 
286 // FilterGaussian operation class
287 // C API descriptions has more details.
288 class IwiFilterGaussian
289 {
290 public:
291     // Default constructor
IwiFilterGaussian()292     IwiFilterGaussian()
293     {
294         m_bInitialized = false;
295     }
296 
297     // Constructor with initialization
298     // Throws:
299     //      ippStsMaskSizeErr                   mask value is illegal
300     //      ippStsDataTypeErr                   data type is illegal
301     //      ippStsNumChannelsErr                channels value is illegal
302     //      ippStsNotEvenStepErr                step value is not divisible by size of elements
303     //      ippStsBorderErr                     border value is illegal
304     //      ippStsNotSupportedModeErr           selected function mode is not supported
305     //      ippStsNoMemErr                      failed to allocate memory
306     //      ippStsSizeErr                       size fields values are illegal
307     //      ippStsNullPtrErr                    unexpected NULL pointer
IwiFilterGaussian(IwiSize size,IppDataType dataType,int channels,int kernelSize,double sigma,const IwiFilterGaussianParams & auxParams=IwiFilterGaussianParams (),const IwiBorderType & border=ippBorderRepl)308     IwiFilterGaussian(
309         IwiSize                         size,                                       // [in]     Size of the image in pixels
310         IppDataType                     dataType,                                   // [in]     Image pixel type
311         int                             channels,                                   // [in]     Number of image channels
312         int                             kernelSize,                                 // [in]     Size of the Gaussian kernel (odd, greater or equal to 3)
313         double                          sigma,                                      // [in]     Standard deviation of the Gaussian kernel
314         const IwiFilterGaussianParams  &auxParams   = IwiFilterGaussianParams(),    // [in] Reference to the auxiliary parameters structure
315         const IwiBorderType            &border      = ippBorderRepl                 // [in] Extrapolation algorithm and value for out of image pixels: ippBorderConst, ippBorderRepl, ippBorderInMem
316     )
317     {
318         m_bInitialized = false;
319 
320         IppStatus ippStatus = InitAlloc(size, dataType, channels, kernelSize, sigma, auxParams, border);
321         OWN_ERROR_CHECK_THROW_ONLY(ippStatus);
322     }
323 
324     // Default destructor
~IwiFilterGaussian()325     ~IwiFilterGaussian()
326     {
327         if(m_bInitialized)
328         {
329             ::iwiFilterGaussian_Free(m_pSpec);
330             m_bInitialized = false;
331         }
332     }
333 
334     // Allocates and initializes internal data structure
335     // Throws:
336     //      ippStsMaskSizeErr                   mask value is illegal
337     //      ippStsDataTypeErr                   data type is illegal
338     //      ippStsNumChannelsErr                channels value is illegal
339     //      ippStsNotEvenStepErr                step value is not divisible by size of elements
340     //      ippStsBorderErr                     border value is illegal
341     //      ippStsNotSupportedModeErr           selected function mode is not supported
342     //      ippStsNoMemErr                      failed to allocate memory
343     //      ippStsSizeErr                       size fields values are illegal
344     //      ippStsNullPtrErr                    unexpected NULL pointer
345     // Returns:
346     //      ippStsNoErr                         no errors
InitAlloc(IwiSize size,IppDataType dataType,int channels,int kernelSize,double sigma,const IwiFilterGaussianParams & auxParams=IwiFilterGaussianParams (),const IwiBorderType & border=ippBorderRepl)347     IppStatus InitAlloc(
348         IwiSize                         size,                                       // [in]     Size of the image in pixels
349         IppDataType                     dataType,                                   // [in]     Image pixel type
350         int                             channels,                                   // [in]     Number of image channels
351         int                             kernelSize,                                 // [in]     Size of the Gaussian kernel (odd, greater or equal to 3)
352         double                          sigma,                                      // [in]     Standard deviation of the Gaussian kernel
353         const IwiFilterGaussianParams  &auxParams   = IwiFilterGaussianParams(),    // [in] Reference to the auxiliary parameters structure
354         const IwiBorderType            &border      = ippBorderRepl                 // [in] Extrapolation algorithm and value for out of image pixels: ippBorderConst, ippBorderRepl, ippBorderInMem
355     )
356     {
357         if(m_bInitialized)
358         {
359             ::iwiFilterGaussian_Free(m_pSpec);
360             m_bInitialized = false;
361         }
362 
363         IppStatus ippStatus = ::iwiFilterGaussian_InitAlloc(&m_pSpec, size, dataType, channels, kernelSize, sigma, &auxParams, border);
364         OWN_ERROR_CHECK(ippStatus);
365 
366         m_bInitialized = true;
367         return ippStatus;
368     }
369 
370     // Applies Gaussian filter to the source image
371     // Throws:
372     //      ippStsMaskSizeErr                   mask value is illegal
373     //      ippStsDataTypeErr                   data type is illegal
374     //      ippStsNumChannelsErr                channels value is illegal
375     //      ippStsNotEvenStepErr                step value is not divisible by size of elements
376     //      ippStsBorderErr                     border value is illegal
377     //      ippStsContextMatchErr               internal structure is not initialized or of invalid type
378     //      ippStsNoMemErr                      failed to allocate memory
379     //      ippStsSizeErr                       size fields values are illegal
380     //      ippStsInplaceModeNotSupportedErr    doesn't support output into the source buffer
381     //      ippStsNullPtrErr                    unexpected NULL pointer
382     // Returns:
383     //      ippStsNoErr                         no errors
operator ()(const IwiImage & srcImage,IwiImage & dstImage,const IwiBorderType & border=ippBorderRepl,const IwiTile & tile=IwiTile ()) const384     IppStatus operator()(
385         const IwiImage         &srcImage,                       // [in]     Reference to the source image
386         IwiImage               &dstImage,                       // [in,out] Reference to the destination image
387         const IwiBorderType    &border      = ippBorderRepl,    // [in]     Extrapolation algorithm and value for out of image pixels: ippBorderConst, ippBorderRepl, ippBorderInMem
388         const IwiTile          &tile        = IwiTile()         // [in]     Reference to the IwiTile structure for tiling. By default no tiling is used
389     ) const
390     {
391         if(m_bInitialized)
392         {
393             IppStatus ippStatus = ::iwiFilterGaussian_Process(m_pSpec, &srcImage, &dstImage, border.m_type, border.m_value, &tile);
394             OWN_ERROR_CHECK(ippStatus);
395             return ippStatus;
396         }
397         else
398             OWN_ERROR_THROW(ippStsBadArgErr);
399     }
400 
401 private:
402     IwiFilterGaussianSpec  *m_pSpec;        // Pointer to internal spec structure
403     bool                    m_bInitialized; // Initialization flag
404 };
405 
406 /* /////////////////////////////////////////////////////////////////////////////
407 //                   iwiFilterCanny
408 ///////////////////////////////////////////////////////////////////////////// */
409 
410 // Auxiliary parameters class
411 // C API descriptions has more details
412 class IwiFilterCannyParams: public ::IwiFilterCannyParams
413 {
414 public:
IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterCannyParams,iwiFilterCanny_SetDefaultParams)415     IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterCannyParams, iwiFilterCanny_SetDefaultParams)
416     IwiFilterCannyParams(IppiDifferentialKernel _kernel = ippFilterSobel, IppiMaskSize _kernelSize = ippMskSize3x3, IppNormType _norm = ippNormL2)
417     {
418         this->kernel     = _kernel;
419         this->kernelSize = _kernelSize;
420         this->norm       = _norm;
421     }
422 };
423 
424 // Applies Canny edge detector to the source image
425 // C API descriptions has more details.
426 // Throws:
427 //      ippStsMaskSizeErr                   mask value is illegal
428 //      ippStsDataTypeErr                   data type is illegal
429 //      ippStsNumChannelsErr                channels value is illegal
430 //      ippStsNotEvenStepErr                step value is not divisible by size of elements
431 //      ippStsBorderErr                     border value is illegal
432 //      ippStsNoMemErr                      failed to allocate memory
433 //      ippStsSizeErr                       size fields values are illegal
434 //      ippStsInplaceModeNotSupportedErr    doesn't support output into the source buffer
435 //      ippStsNullPtrErr                    unexpected NULL pointer
436 // Returns:
437 //      ippStsNoErr                         no errors
iwiFilterCanny(const IwiImage & srcImage,IwiImage & dstImage,Ipp32f treshLow=50,Ipp32f treshHigh=150,const IwiFilterCannyParams & auxParams=IwiFilterCannyParams (),const IwiBorderType & border=ippBorderRepl)438 IW_DECL_CPP(IppStatus) iwiFilterCanny(
439     const IwiImage             &srcImage,                               // [in]     Reference to the source image
440     IwiImage                   &dstImage,                               // [in,out] Reference to the destination image
441     Ipp32f                      treshLow    = 50,                       // [in]     Lower threshold for edges detection
442     Ipp32f                      treshHigh   = 150,                      // [in]     Upper threshold for edges detection
443     const IwiFilterCannyParams &auxParams   = IwiFilterCannyParams(),   // [in]     Reference to the auxiliary parameters structure
444     const IwiBorderType        &border      = ippBorderRepl             // [in]     Extrapolation algorithm and value for out of image pixels: ippBorderConst, ippBorderRepl, ippBorderMirror, ippBorderInMem
445 )
446 {
447     IppStatus ippStatus = ::iwiFilterCanny(&srcImage, &dstImage, treshLow, treshHigh, &auxParams, border.m_type, border.m_value);
448     OWN_ERROR_CHECK(ippStatus)
449     return ippStatus;
450 }
451 
452 /* /////////////////////////////////////////////////////////////////////////////
453 //                   iwiFilterCannyDeriv
454 ///////////////////////////////////////////////////////////////////////////// */
455 
456 // Auxiliary parameters class
457 // C API descriptions has more details
458 class IwiFilterCannyDerivParams: public ::IwiFilterCannyDerivParams
459 {
460 public:
IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterCannyDerivParams,iwiFilterCannyDeriv_SetDefaultParams)461     IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterCannyDerivParams, iwiFilterCannyDeriv_SetDefaultParams)
462     IwiFilterCannyDerivParams(IppNormType _norm = ippNormL2)
463     {
464         this->norm = _norm;
465     }
466 };
467 
468 // Applies Canny edge detector to the image derivatives
469 // C API descriptions has more details.
470 // Throws:
471 //      ippStsDataTypeErr                   data type is illegal
472 //      ippStsNumChannelsErr                channels value is illegal
473 //      ippStsNotEvenStepErr                step value is not divisible by size of elements
474 //      ippStsNoMemErr                      failed to allocate memory
475 //      ippStsSizeErr                       size fields values are illegal
476 //      ippStsNullPtrErr                    unexpected NULL pointer
477 // Returns:
478 //      ippStsNoErr                         no errors
iwiFilterCannyDeriv(const IwiImage & srcImageDx,const IwiImage & srcImageDy,IwiImage & dstImage,Ipp32f treshLow=50,Ipp32f treshHigh=150,const IwiFilterCannyDerivParams & auxParams=IwiFilterCannyDerivParams ())479 IW_DECL_CPP(IppStatus) iwiFilterCannyDeriv(
480     const IwiImage                  &srcImageDx,                                // [in]     Reference to X derivative of the source image
481     const IwiImage                  &srcImageDy,                                // [in]     Reference to Y derivative of the source image
482     IwiImage                        &dstImage,                                  // [in,out] Reference to the destination image
483     Ipp32f                           treshLow   = 50,                           // [in]     Lower threshold for edges detection
484     Ipp32f                           treshHigh  = 150,                          // [in]     Upper threshold for edges detection
485     const IwiFilterCannyDerivParams &auxParams  = IwiFilterCannyDerivParams()   // [in]     Reference to the auxiliary parameters structure
486 )
487 {
488     IppStatus ippStatus = ::iwiFilterCannyDeriv(&srcImageDx, &srcImageDy, &dstImage, treshLow, treshHigh, &auxParams);
489     OWN_ERROR_CHECK(ippStatus)
490     return ippStatus;
491 }
492 
493 /**/////////////////////////////////////////////////////////////////////////////
494 //                   iwiFilterMorphology
495 ///////////////////////////////////////////////////////////////////////////// */
496 
497 using ::IwiMorphologyType;
498 using ::iwiMorphErode;
499 using ::iwiMorphDilate;
500 using ::iwiMorphOpen;
501 using ::iwiMorphClose;
502 using ::iwiMorphTophat;
503 using ::iwiMorphBlackhat;
504 using ::iwiMorphGradient;
505 
506 // Auxiliary parameters class
507 // C API descriptions has more details
508 class IwiFilterMorphologyParams: public ::IwiFilterMorphologyParams
509 {
510 public:
IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterMorphologyParams,iwiFilterMorphology_SetDefaultParams)511     IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterMorphologyParams, iwiFilterMorphology_SetDefaultParams)
512     IwiFilterMorphologyParams(int _iterations = 1)
513     {
514         this->iterations = _iterations;
515     }
516 };
517 
518 // Performs morphology filter operation on given image ROI
519 // C API descriptions has more details.
520 // Throws:
521 //      ippStsBorderErr                     border value is illegal
522 //      ippStsDataTypeErr                   data type is illegal
523 //      ippStsNumChannelsErr                channels value is illegal
524 //      ippStsNotEvenStepErr                step value is not divisible by size of elements
525 //      ippStsNotSupportedModeErr           selected function mode is not supported
526 //      ippStsNoMemErr                      failed to allocate memory
527 //      ippStsInplaceModeNotSupportedErr    doesn't support output into the source buffer
528 //      ippStsNullPtrErr                    unexpected NULL pointer
529 // Returns:
530 //      ippStsNoErr                         no errors
iwiFilterMorphology(const IwiImage & srcImage,IwiImage & dstImage,IwiMorphologyType morphType,const IwiImage & maskImage,const IwiFilterMorphologyParams & auxParams=IwiFilterMorphologyParams (),const IwiBorderType & border=ippBorderDefault,const IwiTile & tile=IwiTile ())531 IW_DECL_CPP(IppStatus) iwiFilterMorphology(
532     const IwiImage                  &srcImage,                                  // [in]     Reference to the source image
533     IwiImage                        &dstImage,                                  // [in,out] Reference to the destination image
534     IwiMorphologyType                morphType,                                 // [in]     Morphology filter type
535     const IwiImage                  &maskImage,                                 // [in]     Reference to the morphology mask image
536     const IwiFilterMorphologyParams &auxParams  = IwiFilterMorphologyParams(),  // [in]     Reference to the auxiliary parameters structure
537     const IwiBorderType             &border     = ippBorderDefault,             // [in]     Extrapolation algorithm and value for out of image pixels: ippBorderDefault, ippBorderConst, ippBorderRepl, ippBorderMirror, ippBorderInMem
538     const IwiTile                   &tile       = IwiTile()                     // [in]     Reference to the IwiTile structure for tiling. By default no tiling is used
539 )
540 {
541     IppStatus ippStatus = ::iwiFilterMorphology(&srcImage, &dstImage, morphType, &maskImage, &auxParams, border.m_type, border.m_value, &tile);
542     OWN_ERROR_CHECK(ippStatus)
543     return ippStatus;
544 }
545 
546 // Calculates border size for morphology operation
547 // Throws:
548 //      ippStsNotSupportedModeErr           selected function mode is not supported
549 //      ippStsNullPtrErr                    unexpected NULL pointer
550 // Returns:
551 //      Size of border
iwiFilterMorphology_GetBorderSize(IwiMorphologyType morphType,IwiSize maskSize)552 IW_DECL_CPP(IwiBorderSize) iwiFilterMorphology_GetBorderSize(
553     IwiMorphologyType   morphType,      // [in]  Morphology filter type
554     IwiSize             maskSize        // [in]  Size of morphology mask
555 )
556 {
557     IwiBorderSize borderSize;
558     IppStatus ippStatus = ::iwiFilterMorphology_GetBorderSize(morphType, maskSize, &borderSize);
559     OWN_ERROR_CHECK_THROW_ONLY(ippStatus)
560     return borderSize;
561 }
562 
563 /**/////////////////////////////////////////////////////////////////////////////
564 //                   iwiFilterBilateral
565 ///////////////////////////////////////////////////////////////////////////// */
566 
567 // Auxiliary parameters class
568 // C API descriptions has more details
569 class IwiFilterBilateralParams: public ::IwiFilterBilateralParams
570 {
571 public:
IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterBilateralParams,iwiFilterBilateral_SetDefaultParams)572     IW_BASE_PARAMS_CONSTRUCTORS(IwiFilterBilateralParams, iwiFilterBilateral_SetDefaultParams)
573     IwiFilterBilateralParams(IppiFilterBilateralType _filter = ippiFilterBilateralGauss,
574         IppiDistanceMethodType _distMethod = ippDistNormL1)
575     {
576         this->distMethod = _distMethod;
577         this->filter     = _filter;
578     }
579 };
580 
581 // Performs bilateral filtering of an image
582 // C API descriptions has more details.
583 // Throws:
584 //      ippStsSizeErr                       size fields values are illegal
585 //      ippStsBadArgErr                     valSquareSigma or posSquareSigma is less or equal 0
586 //      ippStsMaskSizeErr                   radius is less or equal 0
587 //      ippStsBorderErr                     border value is illegal
588 //      ippStsDataTypeErr                   data type is illegal
589 //      ippStsNumChannelsErr                channels value is illegal
590 //      ippStsNotEvenStepErr                step value is not divisible by size of elements
591 //      ippStsNotSupportedModeErr           filter or distMethod is not supported
592 //      ippStsNoMemErr                      failed to allocate memory
593 //      ippStsInplaceModeNotSupportedErr    doesn't support output into the source buffer
594 //      ippStsNullPtrErr                    unexpected NULL pointer
595 // Returns:
596 //      ippStsNoErr                         no errors
iwiFilterBilateral(const IwiImage & srcImage,IwiImage & dstImage,int radius,Ipp32f valSquareSigma,Ipp32f posSquareSigma,const IwiFilterBilateralParams & auxParams=IwiFilterBilateralParams (),const IwiBorderType & border=ippBorderRepl,const IwiTile & tile=IwiTile ())597 IW_DECL_CPP(IppStatus) iwiFilterBilateral(
598     const IwiImage                 &srcImage,                                   // [in]     Reference to the source image
599     IwiImage                       &dstImage,                                   // [in,out] Reference to the destination image
600     int                             radius,                                     // [in]     Radius of circular neighborhood what defines pixels for calculation
601     Ipp32f                          valSquareSigma,                             // [in]     Square of Sigma for factor function for pixel intensity
602     Ipp32f                          posSquareSigma,                             // [in]     Square of Sigma for factor function for pixel position
603     const IwiFilterBilateralParams &auxParams   = IwiFilterBilateralParams(),   // [in]     Reference to the auxiliary parameters structure
604     const IwiBorderType            &border      = ippBorderRepl,                // [in]     Extrapolation algorithm and value for out of image pixels: ippBorderConst, ippBorderRepl, ippBorderMirror, ippBorderInMem
605     const IwiTile                  &tile        = IwiTile()                     // [in]     Reference to the IwiTile structure for tiling. By default no tiling is used
606 )
607 {
608     IppStatus ippStatus = ::iwiFilterBilateral(&srcImage, &dstImage, radius, valSquareSigma, posSquareSigma, &auxParams, border.m_type, border.m_value, &tile);
609     OWN_ERROR_CHECK(ippStatus)
610     return ippStatus;
611 }
612 
613 }
614 
615 #endif
616