| 1 |
|
| 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 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
template <class T, class From> |
| 33 |
class ColourspaceBuffer : public CVD::LocalVideoBuffer<T> |
| 34 |
{ |
| 35 |
public: |
| 36 |
|
| 37 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 97 |
template <class T, class From> |
| 98 |
class ColourspaceBuffer_managed : public ColourspaceBuffer<T, From> |
| 99 |
{ |
| 100 |
public: |
| 101 |
|
| 102 |
|
| 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 |