Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Private Attributes | Friends
omni::Buffer< T > Struct Template Reference

A buffer holds an w x h pixel array. More...

#include <Buffer.h>

Collaboration diagram for omni::Buffer< T >:
Collaboration graph
[legend]

Public Types

typedef T pixel_type
 Our pixel type. More...
 
typedef std::vector< pixel_typedata_type
 Our data type (a dynamic array) More...
 

Public Member Functions

 Buffer ()
 Standard constructor. More...
 
 Buffer (int _width, int _height)
 Constructor with automatic resize. More...
 
void put (int _x, int _y, const pixel_type &_pixel)
 Write pixel value to position (x,y) More...
 
void put (size_t _offset, const pixel_type &_pixel)
 Write pixel value to offset (= x * width + y) More...
 
pixel_typeoperator() (int _x, int _y)
 Return pixel on position (x,y) More...
 
pixel_type const & operator() (int _x, int _y) const
 Return pixel on position (x,y) (const version) More...
 
pixel_typeoperator() (size_t _offset)
 Return pixel on offset (= x * width + y) More...
 
pixel_type const & operator() (size_t _offset) const
 Return pixel on offset (= x * width + y) (const version) More...
 
pixel_typeoperator[] (size_t _offset)
 Subscript operator for accessing elements by index. More...
 
pixel_type const & operator[] (size_t _offset) const
 Subscript operator for accessing elements by index (const version) More...
 
pixel_typepixel (int _x, int _y)
 Return pixel on position (x,y) More...
 
Buffer cropRect (QRect const &_rect) const
 
pixel_type const & pixel (int _x, int _y) const
 Return pixel on position (x,y) (const version) More...
 
pixel_typepixel (size_t _offset)
 Return pixel on offset (= x * width + y) More...
 
pixel_type const & pixel (size_t _offset) const
 Return pixel on offset (= x * width + y) (const version) More...
 
int width () const
 Return width of the buffer. More...
 
int height () const
 Return height of the buffer. More...
 
data_type const & data () const
 Return const reference to data. More...
 
void clear ()
 Clear buffer with black color. More...
 
void clear (const pixel_type &_pixel)
 Clear buffer with specific pixel. More...
 
bool empty () const
 Returns true if width and height are zero. More...
 
size_t size () const
 Returns size of buffer (= width * height) More...
 
void resize (int _width, int _height)
 Resize buffer to given width and height. More...
 
QImage toQImage () const
 Convert buffer to QImage. More...
 
void * ptr ()
 Return void pointer to data. More...
 
void const * ptr () const
 Return void pointer to data (const version) More...
 
void toStream (QDataStream &_os) const
 Write blend mask to stream. More...
 
void fromStream (QDataStream &_is)
 Read blend mask from stream. More...
 

Private Attributes

int width_
 
int height_
 
data_type data_
 

Friends

bool operator== (Buffer const &_lhs, Buffer const &_rhs)
 Test for equality, buffer is ignored. More...
 

Detailed Description

template<typename T>
struct omni::Buffer< T >

A buffer holds an w x h pixel array.

Member Typedef Documentation

template<typename T>
typedef std::vector<pixel_type> omni::Buffer< T >::data_type

Our data type (a dynamic array)

template<typename T>
typedef T omni::Buffer< T >::pixel_type

Our pixel type.

Constructor & Destructor Documentation

template<typename T>
omni::Buffer< T >::Buffer ( )
inline

Standard constructor.

42 : width_(0), height_(0) {}
int height_
Definition: Buffer.h:231
int width_
Definition: Buffer.h:231
template<typename T>
omni::Buffer< T >::Buffer ( int  _width,
int  _height 
)
inline

Constructor with automatic resize.

45  {
46  resize(_width, _height);
47  }
void resize(int _width, int _height)
Resize buffer to given width and height.
Definition: Buffer.h:172

Member Function Documentation

template<typename T>
void omni::Buffer< T >::clear ( )
inline

Clear buffer with black color.

150  {
151  data_ = data_type(data_.size(), 0);
152  }
data_type data_
Definition: Buffer.h:232
std::vector< pixel_type > data_type
Our data type (a dynamic array)
Definition: Buffer.h:39
template<typename T>
void omni::Buffer< T >::clear ( const pixel_type _pixel)
inline

Clear buffer with specific pixel.

156  {
157  data_ = data_type(data_.size(), _pixel);
158  }
data_type data_
Definition: Buffer.h:232
std::vector< pixel_type > data_type
Our data type (a dynamic array)
Definition: Buffer.h:39
template<typename T>
Buffer omni::Buffer< T >::cropRect ( QRect const &  _rect) const
inline
102  {
103  Buffer _buffer(_rect.width(), _rect.height());
104 
105  for (int y = 0; y < _rect.height(); ++y)
106  for (int x = 0; x < _rect.width(); ++x)
107  {
108  _buffer(x, y) = pixel(x + _rect.x(), y + _rect.y());
109  }
110 
111  return _buffer;
112  }
Buffer()
Standard constructor.
Definition: Buffer.h:42
pixel_type & pixel(int _x, int _y)
Return pixel on position (x,y)
Definition: Buffer.h:96
template<typename T>
data_type const& omni::Buffer< T >::data ( ) const
inline

Return const reference to data.

144  {
145  return data_;
146  }
data_type data_
Definition: Buffer.h:232
template<typename T>
bool omni::Buffer< T >::empty ( ) const
inline

Returns true if width and height are zero.

162  {
163  return data_.empty();
164  }
data_type data_
Definition: Buffer.h:232
template<typename T>
void omni::Buffer< T >::fromStream ( QDataStream &  _is)
inline

Read blend mask from stream.

216  {
217  deserialize(_is, width_);
218  deserialize(_is, height_);
219  deserialize(_is, data_);
220  }
STREAM & deserialize(STREAM &_stream, T &_t, ARGS &&..._args)
Deserialize object of type T from stream with optional additional arguments.
Definition: traits.h:125
data_type data_
Definition: Buffer.h:232
int height_
Definition: Buffer.h:231
int width_
Definition: Buffer.h:231
template<typename T>
int omni::Buffer< T >::height ( ) const
inline

Return height of the buffer.

138  {
139  return height_;
140  }
int height_
Definition: Buffer.h:231
template<typename T>
pixel_type& omni::Buffer< T >::operator() ( int  _x,
int  _y 
)
inline

Return pixel on position (x,y)

63  {
64  return pixel(_x, _y);
65  }
pixel_type & pixel(int _x, int _y)
Return pixel on position (x,y)
Definition: Buffer.h:96
template<typename T>
pixel_type const& omni::Buffer< T >::operator() ( int  _x,
int  _y 
) const
inline

Return pixel on position (x,y) (const version)

69  {
70  return pixel(_x, _y);
71  }
pixel_type & pixel(int _x, int _y)
Return pixel on position (x,y)
Definition: Buffer.h:96
template<typename T>
pixel_type& omni::Buffer< T >::operator() ( size_t  _offset)
inline

Return pixel on offset (= x * width + y)

75  {
76  return pixel(_offset);
77  }
pixel_type & pixel(int _x, int _y)
Return pixel on position (x,y)
Definition: Buffer.h:96
template<typename T>
pixel_type const& omni::Buffer< T >::operator() ( size_t  _offset) const
inline

Return pixel on offset (= x * width + y) (const version)

81  {
82  return pixel(_offset);
83  }
pixel_type & pixel(int _x, int _y)
Return pixel on position (x,y)
Definition: Buffer.h:96
template<typename T>
pixel_type& omni::Buffer< T >::operator[] ( size_t  _offset)
inline

Subscript operator for accessing elements by index.

86  {
87  return pixel(_offset);
88  }
pixel_type & pixel(int _x, int _y)
Return pixel on position (x,y)
Definition: Buffer.h:96
template<typename T>
pixel_type const& omni::Buffer< T >::operator[] ( size_t  _offset) const
inline

Subscript operator for accessing elements by index (const version)

91  {
92  return pixel(_offset);
93  }
pixel_type & pixel(int _x, int _y)
Return pixel on position (x,y)
Definition: Buffer.h:96
template<typename T>
pixel_type& omni::Buffer< T >::pixel ( int  _x,
int  _y 
)
inline

Return pixel on position (x,y)

97  {
98  return pixel(_y * width() + _x);
99  }
pixel_type & pixel(int _x, int _y)
Return pixel on position (x,y)
Definition: Buffer.h:96
int width() const
Return width of the buffer.
Definition: Buffer.h:131
template<typename T>
pixel_type const& omni::Buffer< T >::pixel ( int  _x,
int  _y 
) const
inline

Return pixel on position (x,y) (const version)

116  {
117  return pixel(_y * width() + _x);
118  }
pixel_type & pixel(int _x, int _y)
Return pixel on position (x,y)
Definition: Buffer.h:96
int width() const
Return width of the buffer.
Definition: Buffer.h:131
template<typename T>
pixel_type& omni::Buffer< T >::pixel ( size_t  _offset)
inline

Return pixel on offset (= x * width + y)

121  {
122  return data_[_offset];
123  }
data_type data_
Definition: Buffer.h:232
template<typename T>
pixel_type const& omni::Buffer< T >::pixel ( size_t  _offset) const
inline

Return pixel on offset (= x * width + y) (const version)

126  {
127  return data_[_offset];
128  }
data_type data_
Definition: Buffer.h:232
template<typename T>
void* omni::Buffer< T >::ptr ( )
inline

Return void pointer to data.

198  {
199  return static_cast<void *>(data_.data());
200  }
data_type data_
Definition: Buffer.h:232
template<typename T>
void const* omni::Buffer< T >::ptr ( ) const
inline

Return void pointer to data (const version)

204  {
205  return static_cast<void const*>(data_.data());
206  }
data_type data_
Definition: Buffer.h:232
template<typename T>
void omni::Buffer< T >::put ( int  _x,
int  _y,
const pixel_type _pixel 
)
inline

Write pixel value to position (x,y)

51  {
52  put(_y * width() + _x, _pixel);
53  }
void put(int _x, int _y, const pixel_type &_pixel)
Write pixel value to position (x,y)
Definition: Buffer.h:50
int width() const
Return width of the buffer.
Definition: Buffer.h:131
template<typename T>
void omni::Buffer< T >::put ( size_t  _offset,
const pixel_type _pixel 
)
inline

Write pixel value to offset (= x * width + y)

57  {
58  data_[_offset] = _pixel;
59  }
data_type data_
Definition: Buffer.h:232
template<typename T>
void omni::Buffer< T >::resize ( int  _width,
int  _height 
)
inline

Resize buffer to given width and height.

173  {
174  if (_width * _height <= 0) return;
175 
176  width_ = _width;
177  height_ = _height;
178  data_.resize(width_ * height_);
179  }
data_type data_
Definition: Buffer.h:232
int height_
Definition: Buffer.h:231
int width_
Definition: Buffer.h:231
template<typename T>
size_t omni::Buffer< T >::size ( ) const
inline

Returns size of buffer (= width * height)

167  {
168  return data_.size();
169  }
data_type data_
Definition: Buffer.h:232
template<typename T>
QImage omni::Buffer< T >::toQImage ( ) const
inline

Convert buffer to QImage.

183  {
184  QImage _output(width(), height(), QImage::Format_RGB32);
185 
186  for (int y = 0; y < height(); ++y)
187  for (int x = 0; x < width(); ++x)
188  {
189  auto _p = pixel(x, y);
190  _output.setPixel(x, y, convertPixel<QColor>(_p).rgb());
191  }
192 
193  return _output;
194  }
int height() const
Return height of the buffer.
Definition: Buffer.h:137
pixel_type & pixel(int _x, int _y)
Return pixel on position (x,y)
Definition: Buffer.h:96
int width() const
Return width of the buffer.
Definition: Buffer.h:131
template<typename T>
void omni::Buffer< T >::toStream ( QDataStream &  _os) const
inline

Write blend mask to stream.

209  {
210  serialize(_os, width_);
211  serialize(_os, height_);
212  serialize(_os, data_);
213  }
STREAM & serialize(STREAM &_stream, T const &_t)
Serialize object to stream.
Definition: traits.h:140
data_type data_
Definition: Buffer.h:232
int height_
Definition: Buffer.h:231
int width_
Definition: Buffer.h:231
template<typename T>
int omni::Buffer< T >::width ( ) const
inline

Return width of the buffer.

132  {
133  return width_;
134  }
int width_
Definition: Buffer.h:231

Friends And Related Function Documentation

template<typename T>
bool operator== ( Buffer< T > const &  _lhs,
Buffer< T > const &  _rhs 
)
friend

Test for equality, buffer is ignored.

223  {
224  return
228  }
#define OMNI_TEST_MEMBER_EQUAL(member)
Definition: util.h:125
data_type data_
Definition: Buffer.h:232
int height_
Definition: Buffer.h:231
int width_
Definition: Buffer.h:231

Field Documentation

template<typename T>
data_type omni::Buffer< T >::data_
private
template<typename T>
int omni::Buffer< T >::height_
private
template<typename T>
int omni::Buffer< T >::width_
private

The documentation for this struct was generated from the following file: