Debian Codegraph @

cvd/colourspacebuffer.h

raw symbols SCIP
1 // PAS 17/6/04 (revised 16/2/05)
2
3 #ifndef CVD_INCLUDE_COLOURSPACEBUFFER_H
4 #define CVD_INCLUDE_COLOURSPACEBUFFER_H
5
6 #include <cvd/colourspace_convert.h>
7 #include <cvd/colourspace_frame.h>
8 #include <cvd/convert_image.h>
9 #include <cvd/localvideobuffer.h>
10
11 namespace CVD
12 {
13 /// A decorator class which wraps a VideoBuffer to perfrom colourspace
14 /// conversion on the incoming data. In general, the kernel video buffers
15 /// such as dvbuffer and v4l1buffer give access to what the device can provide
16 /// natively. However, the native formats may not be what is required. This
17 /// buffer transparently converts incoming frames to the required type.
18 ///
19 /// Not every possible conversion is available natively through the library,
20 /// some conversions have to be performed in several steps. For instance, to
21 /// convert yuv411 to <code>Rgb<float></code>, the conversion must go via
22 /// <code>Rgb<byte></code> since
23 /// the conversions from yuv411 are limited.
24 ///
25 /// Provides frames of type <code>CVD::ColourspaceFrame.</code>
26 ///
27 /// This class throws only generic VideoBuffer exceptions, but the underlying
28 /// videobuffer may throw.
29 /// @param From The pixel type of the original VideoBuffer
30 /// @param T The pixel type to convert in to.
31 /// @ingroup gVideoBuffer
32 template <class T, class From>
33 class ColourspaceBuffer : public CVD::LocalVideoBuffer<T>
34 {
35 public:
36 /// Construct a ColourspaceBuffer by wrapping it around another VideoBuffer
37 /// @param buf The buffer that will provide the raw frames
38 ColourspaceBuffer(CVD::VideoBuffer<From>& buf)
39 : LocalVideoBuffer<T>(buf.type())
40 , m_vidbuf(buf)
41 , m_size(buf.size())
42 {
43 }
44
45 virtual RawVideoBuffer* source_buffer()
46 {
47 return &m_vidbuf;
48 }
49
50 /// The size of the VideoFrames returns by this buffer.
51 ImageRef size()
52 {
53 return m_size;
54 }
55
56 virtual bool frame_pending()
57 {
58 return m_vidbuf.frame_pending();
59 }
60
61 virtual void seek_to(double t)
62 {
63 m_vidbuf.seek_to(t);
64 }
65
66 virtual double frame_rate()
67 {
68 return m_vidbuf.frame_rate();
69 }
70
71 virtual CVD::ColourspaceFrame<T>* get_frame()
72 {
73 VideoFrame<From>* fr = m_vidbuf.get_frame();
74 Image<T> cv = convert_image<T>(*fr);
75 ColourspaceFrame<T>* ret = new ColourspaceFrame<T>(fr->timestamp(), std::move(cv));
76 m_vidbuf.put_frame(fr);
77 return ret;
78 }
79
80 virtual void put_frame(CVD::VideoFrame<T>* f)
81 {
82 //Check that the type is correct...
83 ColourspaceFrame<T>* csf = dynamic_cast<ColourspaceFrame<T>*>(f);
84
85 if(csf == NULL)
86 throw CVD::Exceptions::VideoBuffer::BadPutFrame();
87 else
88 delete csf;
89 }
90
91 private:
92 CVD::VideoBuffer<From>& m_vidbuf;
93 ImageRef m_size;
94 };
95
96 /// This is just like ColourspaceBuffer, except it deleted the videobuffer on destruction
97 template <class T, class From>
98 class ColourspaceBuffer_managed : public ColourspaceBuffer<T, From>
99 {
100 public:
101 /// Construct a ColourspaceBuffer by wrapping it around another VideoBuffer
102 /// @param buf The buffer that will provide the raw frames
103 ColourspaceBuffer_managed(CVD::VideoBuffer<From>* buf)
104 : ColourspaceBuffer<T, From>(*buf)
105 , vb(buf)
106 {
107 }
108
109 ~ColourspaceBuffer_managed()
110 {
111 delete vb;
112 }
113
114 private:
115 VideoBuffer<From>* vb;
116 };
117
118 }
119 #endif