b17a803add4cb2dac5609dcd50a2a9ae69e39ee6
[profile/ivi/opencv.git] / modules / core / include / opencv2 / core / ippasync.hpp
1 #ifndef __OPENCV_CORE_IPPASYNC_HPP__
2 #define __OPENCV_CORE_IPPASYNC_HPP__
3
4 #include "opencv2/core.hpp"
5 #include <ipp_async_op.h>
6 #include <ipp_async_accel.h>
7
8 namespace cv
9 {
10     void DefaultDeleter<hppiMatrix>::operator () (hppiMatrix* p) const
11     {
12         hppiFreeMatrix(p);
13     }
14
15 namespace hpp
16 {
17     //convert OpenCV data type to hppDataType
18     inline int toHppType(const int cvType)
19     {
20         int depth = CV_MAT_DEPTH(cvType);
21         int hppType = depth == CV_8U ? HPP_DATA_TYPE_8U :
22                      depth == CV_16U ? HPP_DATA_TYPE_16U :
23                      depth == CV_16S ? HPP_DATA_TYPE_16S :
24                      depth == CV_32S ? HPP_DATA_TYPE_32S :
25                      depth == CV_32F ? HPP_DATA_TYPE_32F :
26                      depth == CV_64F ? HPP_DATA_TYPE_64F : -1;
27         CV_Assert( hppType >= 0 );
28         return hppType; 
29     }
30
31     //convert hppDataType to OpenCV data type
32     inline int toCvType(const int hppType)
33     {
34         int cvType = hppType == HPP_DATA_TYPE_8U ? CV_8U :
35                     hppType == HPP_DATA_TYPE_16U ? CV_16U :
36                     hppType == HPP_DATA_TYPE_16S ? CV_16S :
37                     hppType == HPP_DATA_TYPE_32S ? CV_32S :
38                     hppType == HPP_DATA_TYPE_32F ? CV_32F :
39                     hppType == HPP_DATA_TYPE_64F ? CV_64F : -1;
40         CV_Assert( cvType >= 0 );
41         return cvType;
42     }
43
44     inline void copyHppToMat(hppiMatrix* src, Mat& dst, hppAccel accel, int cn)
45     {
46         hppDataType type;
47         hpp32u width, height;
48         hppStatus sts;
49
50         CV_Assert(src!=NULL);
51
52         sts = hppiInquireMatrix(src, &type, &width, &height);
53
54         CV_Assert( sts == HPP_STATUS_NO_ERROR);
55
56         int matType = CV_MAKETYPE(toCvType(type), cn);
57
58         CV_Assert(width%cn == 0);
59
60         width /= cn;
61
62         dst.create((int)height, (int)width, (int)matType);
63
64         size_t newSize = (size_t)(height*(hpp32u)(dst.step));
65
66         sts = hppiGetMatrixData(accel,src,(hpp32u)(dst.step),dst.data,&newSize);
67
68         CV_Assert( sts == HPP_STATUS_NO_ERROR);
69     }
70
71     //create cv::Mat from hppiMatrix
72     inline Mat getMat(hppiMatrix* src, hppAccel accel, int cn)
73     {
74         Mat dst;
75         copyHppToMat(src, dst, accel, cn);
76         return dst;
77     }
78
79      //create hppiMatrix from cv::Mat
80     inline Ptr<hppiMatrix> getHpp(const Mat& src)
81     {
82         int htype = toHppType(src.type());
83         int cn = src.channels();
84
85         CV_Assert(src.data);
86         hppiMatrix *dst = hppiCreateMatrix(htype, src.cols*cn, src.rows, src.data, (hpp32s)(src.step));
87
88         return Ptr<hppiMatrix>(dst);
89     }
90 }}
91
92 #endif