A class to represent a video frame. More...
#include <videoframe.h>
Public Member Functions | |
VideoFrame (enum ColourSpace colour, bool manage_data=false) | |
Constructor that by default will use externally managed frame data. More... | |
VideoFrame (enum ColourSpace colour, size_t cols, size_t rows, size_t stereo_count=1) | |
Allocates memory for specified dimensions, and sets all pixels to black. More... | |
VideoFrame (const VideoFrame &rhs) | |
Create a video frame by copying the data and all properties of rhs . More... | |
virtual | ~VideoFrame () |
Destructor that will free allocated data in case data management is set. More... | |
void | operator= (const VideoFrame &rhs) |
Clone rhs , copying its data. More... | |
void | init_from_specs (unsigned char *data, size_t data_length, size_t cols, size_t rows, size_t stereo_count=1) |
Initialise using passed data AND frame specs. More... | |
const size_t | data_length (size_t stereo_index=0) const |
Get length of data buffer. More... | |
size_t | stereo_count () const |
Get number of stereo frames stored in this object. More... | |
size_t | rows () const |
Get number of rows (y-axis, i.e. height) More... | |
size_t | cols () const |
Get number of columns (x-axis, i.e. width) More... | |
bool | manages_own_data () const |
Get whether data is managed by this object or externally. More... | |
unsigned char *const | data (size_t stereo_index=0) const |
Get a pointer to frame data. More... | |
enum ColourSpace | colour () const |
Get what colour space this frame uses. More... | |
Static Public Member Functions | |
static size_t | required_data_length (enum ColourSpace colour, size_t cols, size_t rows) |
Compute how much memory is needed to accommodate a video frame in colour space with cols and rows dimensions. More... | |
static size_t | required_pixel_length (enum ColourSpace colour) |
Get the pixel depth in number of bits for colour . More... | |
Protected Member Functions | |
VideoFrame () | |
Default constructor that should never be called externally. More... | |
void | clone (const VideoFrame &rhs) |
Clone rhs , after setting _manage_data . More... | |
void | set_dimensions (size_t cols, size_t rows) |
Set dimensions in conjunction with colour space requirements. More... | |
void | allocate_memory (size_t data_length) |
Allocate / extend memory and set data length indicator, ONLY IF managing own data. More... | |
void | free_memory () |
Free any managed memory, and set all spec variables to 0 or nullptr . More... | |
void | set_pixels_black () |
Set all pixels of frame to black. More... | |
void | validate_stereo_index (size_t stereo_index) const |
Protected Attributes | |
enum ColourSpace | _colour |
Colour space, i.e. description of contained data. More... | |
unsigned char * | _data |
Frame data. More... | |
size_t | _data_length |
Frame data length. More... | |
size_t | _stereo_count |
Number of stereo frames stored, i.e. the total number of frames. More... | |
size_t | _rows |
Always use set_dimensions() to set this. More... | |
size_t | _cols |
Always use set_dimensions() to set this. More... | |
bool | _manage_data |
A class to represent a video frame.
For efficiency issues, data can be chosen to not be copied. In that case, the caller is responsible for ensuring the data pointer is valid during the lifetime of the frame object.
Stereo frame data from a particular point in time are included within a single frame object, so as to preserve temporal relations and to facilitate potential stereo encoding.
|
protected |
Default constructor that should never be called externally.
gg::VideoFrame::VideoFrame | ( | enum ColourSpace | colour, |
bool | manage_data = false |
||
) |
Constructor that by default will use externally managed frame data.
The frame can later be initialised by init_from_specs()
colour | |
manage_data |
gg::VideoFrame::VideoFrame | ( | enum ColourSpace | colour, |
size_t | cols, | ||
size_t | rows, | ||
size_t | stereo_count = 1 |
||
) |
Allocates memory for specified dimensions, and sets all pixels to black.
cols
and rows
are checked in conjunction with colour
requirements. I420 requires even dimensions, so in case an odd dimension is provided, it is made even by adding a pixel.
colour | |
cols | |
rows | |
stereo_count | if larger than 1, then this frame will keep the specified number of stereo frames |
gg::VideoFrame::VideoFrame | ( | const VideoFrame & | rhs | ) |
Create a video frame by copying the data and all properties of rhs
.
rhs |
|
virtual |
Destructor that will free allocated data in case data management is set.
|
protected |
Allocate / extend memory and set data length indicator, ONLY IF managing own data.
data_length | passed to avoid allocating in case existing memory satisfies the length requirement |
|
protected |
|
inline |
Get what colour space this
frame uses.
|
inline |
Get number of columns (x-axis, i.e. width)
unsigned char *const gg::VideoFrame::data | ( | size_t | stereo_index = 0 | ) | const |
Get a pointer to frame data.
The pointer itself cannot be re-assigned, i.e. the data storage location cannot be changed. However the contents of the storage, i.e. the raw video data can be modified. Although this might be considered against the encapsulation principle, this interface is provided considering real-time image processing pipelines where creating copies of the video data could degrade performance.
stereo_index | index of requested stereo frame |
std::out_of_range | if provided index value is invalid (i.e. out of range) |
const size_t gg::VideoFrame::data_length | ( | size_t | stereo_index = 0 | ) | const |
Get length of data buffer.
stereo_index | index of stereo frame whose length is requested |
std::out_of_range | if provided index value is invalid (i.e. out of range) |
|
protected |
Free any managed memory, and set all spec variables to 0 or nullptr
.
void gg::VideoFrame::init_from_specs | ( | unsigned char * | data, |
size_t | data_length, | ||
size_t | cols, | ||
size_t | rows, | ||
size_t | stereo_count = 1 |
||
) |
Initialise using passed data AND frame specs.
The caller is responsible for ensuring consistency of specs. As such, the only check performed is whether the columns and rows are in line with the frame's colour space requirements. Other than that, this function proceeds BLINDLY. So use with care.
data | |
data_length | in case of stereo frames, this is the total length of passed data buffer. Only stereo frames with exactly the same dimensions are supports, so this is assumed to be divisible by the number of stereo frames. |
cols | the width of a single video frame |
rows | the height of a single video frame |
stereo_count | the number of stereo frames included in passed data |
|
inline |
Get whether data is managed by this object or externally.
void gg::VideoFrame::operator= | ( | const VideoFrame & | rhs | ) |
Clone rhs
, copying its data.
rhs |
|
static |
Compute how much memory is needed to accommodate a video frame in colour
space with cols
and rows
dimensions.
colour | |
cols | |
rows |
BasicException | if cols or rows are 0 or colour is not supported |
|
static |
Get the pixel depth in number of bits for colour
.
colour |
BasicException | if colour not supported |
|
inline |
Get number of rows (y-axis, i.e. height)
|
protected |
Set dimensions in conjunction with colour space requirements.
cols | |
rows |
|
protected |
Set all pixels of frame to black.
|
inline |
Get number of stereo frames stored in this object.
|
inlineprotected |
stereo_index |
std::out_of_range | if passed stereo index is invalid |
|
protected |
Colour space, i.e. description of contained data.
|
protected |
Always use set_dimensions()
to set this.
|
protected |
Frame data.
|
protected |
Frame data length.
|
protected |
|
protected |
Always use set_dimensions()
to set this.
|
protected |
Number of stereo frames stored, i.e. the total number of frames.