File size: 4,889 Bytes
be94e5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation


#ifndef GFLUIDUTILS_HPP
#define GFLUIDUTILS_HPP

#include <limits>
#include <type_traits>
#include <opencv2/gapi/util/compiler_hints.hpp> //suppress_unused_warning
#include <opencv2/gapi/own/saturate.hpp>

namespace cv {
namespace gapi {
namespace fluid {

using cv::gapi::own::saturate;
using cv::gapi::own::ceild;
using cv::gapi::own::floord;
using cv::gapi::own::roundd;
using cv::gapi::own::rintd;

//--------------------------------
//
// Macros for mapping of data types
//
//--------------------------------

#define UNARY_(DST, SRC, OP, ...)                         \
    if (cv::DataType<DST>::depth == dst.meta().depth &&   \
        cv::DataType<SRC>::depth == src.meta().depth)     \
    {                                                     \
        GAPI_DbgAssert(dst.length() == src.length());       \
        GAPI_DbgAssert(dst.meta().chan == src.meta().chan); \
                                                          \
        OP<DST, SRC>(__VA_ARGS__);                        \
        return;                                           \
    }

// especial unary operation: dst is always 8UC1 image
#define INRANGE_(DST, SRC, OP, ...)                       \
    if (cv::DataType<DST>::depth == dst.meta().depth &&   \
        cv::DataType<SRC>::depth == src.meta().depth)     \
    {                                                     \
        GAPI_DbgAssert(dst.length() == src.length());       \
        GAPI_DbgAssert(dst.meta().chan == 1);               \
                                                          \
        OP<DST, SRC>(__VA_ARGS__);                        \
        return;                                           \
    }

#define BINARY_(DST, SRC1, SRC2, OP, ...)                  \
    if (cv::DataType<DST>::depth == dst.meta().depth &&    \
        cv::DataType<SRC1>::depth == src1.meta().depth &&  \
        cv::DataType<SRC2>::depth == src2.meta().depth)    \
    {                                                      \
        GAPI_DbgAssert(dst.length() == src1.length());       \
        GAPI_DbgAssert(dst.length() == src2.length());       \
                                                           \
        GAPI_DbgAssert(dst.meta().chan == src1.meta().chan); \
        GAPI_DbgAssert(dst.meta().chan == src2.meta().chan); \
                                                           \
        OP<DST, SRC1, SRC2>(__VA_ARGS__);                  \
        return;                                            \
    }

// especial ternary operation: src3 has only one channel
#define SELECT_(DST, SRC1, SRC2, SRC3, OP, ...)            \
    if (cv::DataType<DST>::depth == dst.meta().depth &&    \
        cv::DataType<SRC1>::depth == src1.meta().depth &&  \
        cv::DataType<SRC2>::depth == src2.meta().depth &&  \
        cv::DataType<SRC3>::depth == src3.meta().depth)    \
    {                                                      \
        GAPI_DbgAssert(dst.length() == src1.length());       \
        GAPI_DbgAssert(dst.length() == src2.length());       \
        GAPI_DbgAssert(dst.length() == src3.length());       \
                                                           \
        GAPI_DbgAssert(dst.meta().chan == src1.meta().chan); \
        GAPI_DbgAssert(dst.meta().chan == src2.meta().chan); \
        GAPI_DbgAssert(              1 == src3.meta().chan); \
                                                           \
        OP<DST, SRC1, SRC2, SRC3>(__VA_ARGS__);            \
        return;                                            \
    }

#define MERGE3_(T, OP, ...)                                \
    if (cv::DataType<T>::depth == dst.meta().depth &&      \
        cv::DataType<T>::depth == src1.meta().depth)       \
    {                                                      \
        GAPI_DbgAssert(dst.length() == src1.length());     \
        GAPI_DbgAssert(dst.length() == src2.length());     \
        GAPI_DbgAssert(dst.length() == src3.length());     \
                                                           \
        GAPI_DbgAssert(1 == src1.meta().chan);             \
        GAPI_DbgAssert(1 == src2.meta().chan);             \
        GAPI_DbgAssert(1 == src3.meta().chan);             \
        GAPI_DbgAssert(3 == dst.meta().chan);              \
                                                           \
        OP<T>(__VA_ARGS__);                                \
        return;                                            \
    }

} // namespace fluid
} // namespace gapi
} // namespace cv

#endif // GFLUIDUTILS_HPP