1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
5 // Copyright (C) 2018-2019 Intel Corporation
8 #ifndef OPENCV_GAPI_FLUID_BUFFER_HPP
9 #define OPENCV_GAPI_FLUID_BUFFER_HPP
12 #include <numeric> // accumulate
13 #include <ostream> // ostream
14 #include <cstdint> // uint8_t
16 #include <opencv2/gapi/opencv_includes.hpp>
17 #include <opencv2/gapi/own/mat.hpp>
18 #include <opencv2/gapi/gmat.hpp>
20 #include "opencv2/gapi/util/optional.hpp"
21 #include "opencv2/gapi/own/scalar.hpp"
22 #include "opencv2/gapi/own/mat.hpp"
30 #if !defined(GAPI_STANDALONE)
31 // This constructor is required to support existing kernels which are part of G-API
32 Border(int _type, cv::Scalar _val) : type(_type), value(to_own(_val)) {};
33 #endif // !defined(GAPI_STANDALONE)
34 Border(int _type, cv::gapi::own::Scalar _val) : type(_type), value(_val) {};
36 cv::gapi::own::Scalar value;
39 using BorderOpt = util::optional<Border>;
41 bool operator == (const Border& b1, const Border& b2);
43 class GAPI_EXPORTS Buffer;
45 class GAPI_EXPORTS View
50 std::vector<const uint8_t*> m_linePtrs;
52 int m_border_size = 0;
54 inline const uint8_t* linePtr(int index) const
56 return m_linePtrs[index + m_border_size];
62 const inline uint8_t* InLineB(int index) const // -(w-1)/2...0...+(w-1)/2 for Filters
64 return m_cache->linePtr(index);
67 template<typename T> const inline T* InLine(int i) const
69 const uint8_t* ptr = this->InLineB(i);
70 return reinterpret_cast<const T*>(ptr);
73 inline operator bool() const { return m_priv != nullptr; }
75 inline int length() const { return m_cache->m_desc.size.width; }
78 inline const GMatDesc& meta() const { return m_cache->m_desc; }
80 class GAPI_EXPORTS Priv; // internal use only
81 Priv& priv(); // internal use only
82 const Priv& priv() const; // internal use only
87 std::shared_ptr<Priv> m_priv;
91 class GAPI_EXPORTS Buffer
96 std::vector<uint8_t*> m_linePtrs;
100 // Default constructor (executable creation stage,
101 // all following initialization performed in Priv::init())
103 // Scratch constructor (user kernels)
104 Buffer(const cv::GMatDesc &desc);
106 // Constructor for intermediate buffers (for tests)
107 Buffer(const cv::GMatDesc &desc,
108 int max_line_consumption, int border_size,
112 // Constructor for in/out buffers (for tests)
113 Buffer(const cv::gapi::own::Mat &data, bool is_input);
115 inline uint8_t* OutLineB(int index = 0)
117 return m_cache->m_linePtrs[index];
120 template<typename T> inline T* OutLine(int index = 0)
122 uint8_t* ptr = this->OutLineB(index);
123 return reinterpret_cast<T*>(ptr);
128 int linesReady() const;
129 void debug(std::ostream &os) const;
130 inline int length() const { return m_cache->m_desc.size.width; }
131 int lpi() const; // LPI for WRITER
133 inline const GMatDesc& meta() const { return m_cache->m_desc; }
135 View mkView(int borderSize, bool ownStorage);
137 class GAPI_EXPORTS Priv; // internal use only
138 Priv& priv(); // internal use only
139 const Priv& priv() const; // internal use only
142 std::shared_ptr<Priv> m_priv;
143 const Cache* m_cache;
146 } // namespace cv::gapi::fluid
147 } // namespace cv::gapi
150 #endif // OPENCV_GAPI_FLUID_BUFFER_HPP