Ocean
|
Definition of an image plane, a block of memory storing pixel data with interleaved channels (or just one channel). More...
Public Member Functions | |
Plane ()=default | |
Creates a new invalid plane. More... | |
Plane (Plane &&plane) noexcept | |
Move constructor. More... | |
Plane (const Plane &plane, const AdvancedCopyMode advancedCopyMode=ACM_USE_OR_COPY_KEEP_LAYOUT) noexcept | |
Copy constructor. More... | |
Plane (const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const unsigned int paddingElements) noexcept | |
Creates a new plane object with own allocated memory. More... | |
template<typename T > | |
Plane (const unsigned int width, const unsigned int height, const unsigned int channels, const T *dataToUse, const unsigned int paddingElements) noexcept | |
Creates a new plane object which is not creating a copy of the given memory. More... | |
template<typename T > | |
Plane (const unsigned int width, const unsigned int height, const unsigned int channels, T *dataToUse, const unsigned int paddingElements) noexcept | |
Creates a new plane object which is not creating a copy of the given memory. More... | |
template<typename T > | |
Plane (const T *sourceDataToCopy, const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int targetPaddingElements, const unsigned int sourcePaddingElements, const bool makeCopyOfPaddingData=false) noexcept | |
Creates a new plane object by making a copy of the given memory. More... | |
template<typename T > | |
Plane (const T *sourceDataToCopy, const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int sourcePaddingElements, const CopyMode copyMode) noexcept | |
Creates a new plane object by making a copy of the given memory. More... | |
~Plane () | |
Destructs a Plane object. More... | |
unsigned int | width () const |
Returns the width of the plane in pixel. More... | |
unsigned int | height () const |
Returns the height of the plane in pixel. More... | |
unsigned int | channels () const |
Returns the channels of the plane. More... | |
template<typename T > | |
const T * | constdata () const |
Returns the read-only memory pointer to this plane with a specific data type compatible with elementTypeSize(). More... | |
template<typename T > | |
T * | data () |
Returns the writable memory pointer to this plane with a specific data type compatible with elementTypeSize(). More... | |
unsigned int | paddingElements () const |
Returns the number of padding elements at the end of each plane row, in elements. More... | |
unsigned int | paddingBytes () const |
Returns the number of padding bytes at the end of each plane row, in bytes. More... | |
unsigned int | elementTypeSize () const |
Returns the size of each element of this plane. More... | |
unsigned int | widthElements () const |
Returns the width of the plane in elements, the width does not contain optional padding elements. More... | |
unsigned int | widthBytes () const |
Returns the width of the plane in bytes, the width does not contain optional padding elements. More... | |
unsigned int | strideElements () const |
Returns the number of elements between the start positions of two consecutive rows, in elements. More... | |
unsigned int | strideBytes () const |
Returns the number of bytes between the start positions of two consecutive rows, in bytes. More... | |
unsigned int | bytesPerPixel () const |
Returns the number of bytes which is used for each pixel. More... | |
void | release () |
Releases this plane and all resources of this plane. More... | |
template<typename T > | |
bool | isCompatibleWithDataType () const |
Returns whether this plane is compatible with a given element data type. More... | |
unsigned int | size () const |
Returns the number of bytes necessary for the entire plane data including optional padding elements at the end of each row. More... | |
bool | isContinuous () const |
Returns whether this plane is based on continuous memory and thus does not have any padding at the end of rows. More... | |
bool | isOwner () const |
Returns whether this plane is the owner of the memory. More... | |
bool | isReadOnly () const |
Returns whether this plane holds read-only memory. More... | |
bool | isValid () const |
Returns whether this plane holds valid data. More... | |
bool | copy (const Plane &sourcePlane, const AdvancedCopyMode advancedCopyMode=ACM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA, const bool reallocateIfNecessary=true) |
Copies data from another plane into this plane. More... | |
Plane & | operator= (Plane &&plane) noexcept |
Move operator. More... | |
Plane & | operator= (const Plane &plane) noexcept |
Copy operator. More... | |
Static Public Member Functions | |
static void * | alignedMemory (const size_t size, const size_t alignment, void *&alignedData) |
Allocates memory with specific byte alignment. More... | |
Protected Member Functions | |
Plane (const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const void *constData, void *data, const unsigned int paddingElements) noexcept | |
Creates a new plane object which is not creating a copy of the given memory. More... | |
Plane (const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const void *dataToUse, const unsigned int paddingElements) noexcept | |
Creates a new plane object which is not creating a copy of the given memory. More... | |
Plane (const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, void *dataToUse, const unsigned int paddingElements) noexcept | |
Creates a new plane object which is not creating a copy of the given memory. More... | |
Plane (const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const void *sourceDataToCopy, const unsigned int targetPaddingElements, const unsigned int sourcePaddingElements, const bool makeCopyOfPaddingData=false) noexcept | |
Creates a new plane object by making a copy of the given memory. More... | |
Plane (const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const void *sourceDataToCopy, const unsigned int sourcePaddingElements, const CopyMode copyMode) noexcept | |
Creates a new plane object by making a copy of the given memory. More... | |
void | copy (const void *sourceData, const unsigned int sourceStrideBytes, const unsigned int sourcePaddingElements, const bool makeCopyOfPaddingData=false) |
Copies memory into this plane which has compatible memory already. More... | |
unsigned int | calculateStrideBytes () const |
Calculates the number of bytes between the start positions of two consecutive rows, in bytes. More... | |
unsigned int | calculateBytesPerPixel () const |
Calculates the number of bytes per pixel. More... | |
Protected Attributes | |
void * | allocatedData_ = nullptr |
The pointer to the memory which this plane has allocated, this pointer is pointing to the memory which needs to be freed when disposing the plane object, nullptr if the plane is not owner of the memory. More... | |
const void * | constData_ = nullptr |
The pointer to the read-only memory of the plane (not the pointer to the allocated memory), nullptr, if the plane is not read-only, or invalid. More... | |
void * | data_ = nullptr |
The pointer to the writable memory of the plane (not the pointer to the allocated memory), nullptr if the plane is not writable. More... | |
unsigned int | width_ = 0u |
The width of the plane in pixel, with range [0, infinity). More... | |
unsigned int | height_ = 0u |
The height of the plane in pixel, with range [0, infinity). More... | |
unsigned int | channels_ = 0u |
The number of channels the plane has, with range [0, infinity). More... | |
unsigned int | elementTypeSize_ = 0u |
The size of each element of this plane, in bytes, with range [0, infinity). More... | |
unsigned int | paddingElements_ = 0u |
The number of padding elements at the end of each plane row, in elements, with range [0, infinity). More... | |
unsigned int | strideBytes_ = 0u |
The number of bytes between the start positions of two consecutive rows, in bytes, identical to '(width_ * channels_ + paddingElements_) * elementTypeSize_`. More... | |
unsigned int | bytesPerPixel_ = 0u |
The number of bytes per pixel, with range [1, infinity), 0 if unknown. More... | |
Friends | |
class | Frame |
Definition of an image plane, a block of memory storing pixel data with interleaved channels (or just one channel).
The plane does not store the specific pixel format or the width of the plane, as this information is part of the frame which owns the plane. A plane has the following memory layout:
|<-------- plane width ----------->|<-- paddingElements -->| ---------------------------------- ----------------------- --- |A0 A1 An-1 B0 B1 Bn-1 ... | | ^ |... | | | | | | plane height | | | | | | | V ---------------------------------- ----------------------- --- |<------------------- stride bytes ----------------------->| With A0 first channel (or element) of first pixel, A1 second channel of first pixel, ... And B0 first channel of second pixel, ...
Note that: strideBytes == (planeWidth * channels + paddingElements) * bytesPerElement.
A plane can have a different number of channels than a frame's pixel format which is owning the plane.
The plane's channels are defined in relation to the data type of each pixel:
A frame with pixel format FORMAT_RGB24 has three channels, one plane, and the plane has three channels (as the data type of each pixel element is uint8_t).
However, a frame with pixel format FORMAT_RGB565 has three channels, one plane, but the plane has one channel only (as the data type of each pixel is uint16_t).
|
default |
Creates a new invalid plane.
|
inlinenoexcept |
Move constructor.
plane | The plane to be moved |
|
noexcept |
Copy constructor.
plane | The plane to be copied, can be invalid |
advancedCopyMode | The copy mode specifying whether the source memory is used or copied |
|
noexcept |
Creates a new plane object with own allocated memory.
width | The width of the plane in pixel, with range [1, infinity) |
height | The height of the plane in pixel, with range [1, infinity) |
channels | The number of channels the plane has, with respect to the specified data type T , with range [1, infinity) |
elementTypeSize | The size of each element of the new plane, in bytes, with range [1, infinity) |
paddingElements | The optional number of padding elements at the end of each row, in elements, with range [0, infinity) |
|
inlinenoexcept |
Creates a new plane object which is not creating a copy of the given memory.
Instead, the memory pointer is just used.
width | The width of the plane in pixels, one pixel has size sizeof(T) * channels , with range [1, infinity) |
height | The height of the plane in pixel, with range [1, infinity) |
channels | The number of channels the plane has, with respect to the specified data type T , with range [1, infinity) |
dataToUse | Memory pointer of the read-only memory which will not be copied, must be valid |
paddingElements | The optional number of padding elements at the end of each row, in elements, with range [0, infinity) |
T | The data type of each element |
|
inlinenoexcept |
Creates a new plane object which is not creating a copy of the given memory.
Instead, the memory pointer is just used.
width | The width of the plane in pixels, one pixel has size sizeof(T) * channels , with range [1, infinity) |
height | The height of the plane in pixel, with range [1, infinity) |
channels | The number of channels the plane has, with respect to the specified data type T , with range [1, infinity) |
dataToUse | Memory pointer of the writable memory which will not be copied, must be valid |
paddingElements | The optional number of padding elements at the end of each row, in elements, with range [0, infinity) |
T | The data type of each element |
|
inlinenoexcept |
Creates a new plane object by making a copy of the given memory.
sourceDataToCopy | The source data to be copied, must be valid |
width | The width of the plane in pixels, one pixel has size sizeof(T) * channels , with range [1, infinity) |
height | The height of the plane in pixels, with range [1, infinity) |
channels | The number of channels the plane has, with respect to the specified data type T , with range [1, infinity) |
targetPaddingElements | The optional number of padding elements at the end of each row this new plane will have, in elements, with range [0, infinity) |
sourcePaddingElements | The number of padding elements at the end of each row the given source memory has, in elements, with range [0, infinity) |
makeCopyOfPaddingData | True, to copy the entire padding data of the source plane (both planes must have the same padding layout: targetPaddingElements == sourcePaddingElements ); False, to skip the padding data when copying the plane |
T | The data type of each element |
|
inlinenoexcept |
Creates a new plane object by making a copy of the given memory.
sourceDataToCopy | The source data to be copied, must be valid |
width | The width of the plane in pixels, one pixel has size sizeof(T) * channels , with range [1, infinity) |
height | The height of the plane in pixels, with range [1, infinity) |
channels | The number of channels the plane has, with respect to the specified data type T , with range [1, infinity) |
sourcePaddingElements | The number of padding elements at the end of each row the given source memory has, in elements, with range [0, infinity) |
copyMode | The copy mode to be applied |
T | The data type of each element |
|
inline |
Destructs a Plane object.
|
inlineprotectednoexcept |
Creates a new plane object which is not creating a copy of the given memory.
Instead, the memory pointer is just used.
width | The width of the plane, in pixel, with range [0, infinity) |
height | The height of the plane, in pixel, with range [0, infinity) |
channels | The channels of the plane, with range [0, infinity) |
elementTypeSize | The size of each element in bytes, which is sizeof(T) , with range [1, infinity) |
constData | The value for constData to be set |
data | The value for data to be set |
paddingElements | The optional number of padding elements at the end of each row, in elements, with range [0, infinity) |
|
protectednoexcept |
Creates a new plane object which is not creating a copy of the given memory.
Instead, the memory pointer is just used.
width | The width of the plane, in pixel, with range [0, infinity) |
height | The height of the plane, in pixel, with range [0, infinity) |
channels | The channels of the plane, with range [0, infinity) |
elementTypeSize | The size of each element in bytes, which is sizeof(T) , with range [1, infinity) |
dataToUse | Memory pointer of the read-only memory which will not be copied, must be valid |
paddingElements | The number of padding elements at the end of each row, in elements, with range [0, infinity) |
|
protectednoexcept |
Creates a new plane object which is not creating a copy of the given memory.
Instead, the memory pointer is just used.
width | The width of the plane, in pixel, with range [0, infinity) |
height | The height of the plane, in pixel, with range [0, infinity) |
channels | The channels of the plane, with range [0, infinity) |
elementTypeSize | The size of each element in bytes, which is sizeof(T) , with range [1, infinity) |
dataToUse | Memory pointer of the read-only memory which will not be copied, must be valid |
paddingElements | The number of padding elements at the end of each row, in elements, with range [0, infinity) |
|
protectednoexcept |
Creates a new plane object by making a copy of the given memory.
width | The width of the plane in pixels, one pixel has size sizeof(T) * channels , with range [1, infinity) |
height | The height of the plane in pixels, with range [1, infinity) |
channels | The number of channels the plane has, with respect to the specified data type, with range [1, infinity) |
elementTypeSize | The size of each element in bytes, which is sizeof(T) , with range [1, infinity) |
sourceDataToCopy | The source data to be copied, must be valid |
targetPaddingElements | The number of padding elements at the end of each row this new plane will have, in elements, with range [0, infinity) |
sourcePaddingElements | The number of padding elements at the end of each row the given source memory has, in elements, with range [0, infinity) |
makeCopyOfPaddingData | True, to copy the entire padding data of the source plane (both planes must have the same padding layout: targetPaddingElements == sourcePaddingElements ); False, to skip the padding data when copying the plane |
|
protectednoexcept |
Creates a new plane object by making a copy of the given memory.
width | The width of the plane in pixels, one pixel has size sizeof(T) * channels , with range [1, infinity) |
height | The height of the plane in pixels, with range [1, infinity) |
channels | The number of channels the plane has, with respect to the specified data type, with range [1, infinity) |
elementTypeSize | The size of each element in bytes, which is sizeof(T) , with range [1, infinity) |
sourceDataToCopy | The source data to be copied, must be valid |
sourcePaddingElements | The number of padding elements at the end of each row the given source memory has, in elements, with range [0, infinity) |
copyMode | The copy mode to be applied |
|
static |
Allocates memory with specific byte alignment.
size | The size of the resulting buffer in bytes, with range [0, infinity) |
alignment | The requested byte alignment, with range [1, infinity) |
alignedData | the resulting pointer to the aligned memory |
|
inline |
Returns the number of bytes which is used for each pixel.
|
protected |
Calculates the number of bytes per pixel.
|
inlineprotected |
Calculates the number of bytes between the start positions of two consecutive rows, in bytes.
|
inline |
Returns the channels of the plane.
|
inline |
Returns the read-only memory pointer to this plane with a specific data type compatible with elementTypeSize().
T | the data type of the resulting memory pointer, with sizeof(T) == elementTypeSize() |
bool Ocean::Frame::Plane::copy | ( | const Plane & | sourcePlane, |
const AdvancedCopyMode | advancedCopyMode = ACM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA , |
||
const bool | reallocateIfNecessary = true |
||
) |
Copies data from another plane into this plane.
If this plane does not have a compatible memory, or if this plane's memory is not writable, reallocation will be done if reallocateIfNecessary == true
.
sourcePlane | The source plane from which the memory will be copied, an invalid plane to release this plane |
advancedCopyMode | The copy mode specifying whether the source memory is used or copied |
reallocateIfNecessary | True, to reallocate new memory if this plane is not compatible with the source plane; False, to prevent a reallocation and to skip to copy the source plane |
|
protected |
Copies memory into this plane which has compatible memory already.
sourceData | The source data from a compatible plane, must be valid |
sourceStrideBytes | The number of bytes between the start positions of two consecutive rows in the source plane, in bytes, with range [strideBytes(), infinity) |
sourcePaddingElements | The number of padding elements at the end of each row, in elements, with range [0, infinity) |
makeCopyOfPaddingData | True, to copy the entire padding data of the source plane (this plane mast have the same padding layout); False, to skip the padding data when copying the plane |
|
inline |
Returns the writable memory pointer to this plane with a specific data type compatible with elementTypeSize().
T | the data type of the resulting memory pointer, with sizeof(T) == elementTypeSize() |
|
inline |
Returns the size of each element of this plane.
|
inline |
Returns the height of the plane in pixel.
|
inline |
Returns whether this plane is compatible with a given element data type.
T | The data type to be checked |
|
inline |
Returns whether this plane is based on continuous memory and thus does not have any padding at the end of rows.
|
inline |
Returns whether this plane is the owner of the memory.
|
inline |
Returns whether this plane holds read-only memory.
|
inline |
Returns whether this plane holds valid data.
Copy operator.
This plane will have the same stride/padding layout. However, the padding memory will not be copied. If the source plane is owner of the memory, this plane will be owner of an own copy of the memory. If the source plane is not the owner of the memory, this plane will also not be the owner but will use the memory of the source plane as well.
plane | The plane to be copied |
Move operator.
plane | The plane to be moved |
|
inline |
Returns the number of padding bytes at the end of each plane row, in bytes.
This function actually returns paddingElements() * elementTypeSize()
.
|
inline |
Returns the number of padding elements at the end of each plane row, in elements.
void Ocean::Frame::Plane::release | ( | ) |
Releases this plane and all resources of this plane.
|
inline |
Returns the number of bytes necessary for the entire plane data including optional padding elements at the end of each row.
This function actually returns strideBytes() * height()
.
|
inline |
Returns the number of bytes between the start positions of two consecutive rows, in bytes.
|
inline |
Returns the number of elements between the start positions of two consecutive rows, in elements.
This function actually returns width * channels + paddingElements
.
|
inline |
Returns the width of the plane in pixel.
|
inline |
Returns the width of the plane in bytes, the width does not contain optional padding elements.
This is the number of bytes in which image data is stored (the number of bytes between start of a row and start of the padding elements):
widthBytes == width * channels * elementTypeSize() == strideBytes - elementTypeSize() * paddingElements()
|
inline |
Returns the width of the plane in elements, the width does not contain optional padding elements.
This is the number of elements in which image data is stored (the number of elements between start of a row and start of the padding elements):
widthElements == width * channels == strideElements() - paddingElements()
|
friend |
|
protected |
The pointer to the memory which this plane has allocated, this pointer is pointing to the memory which needs to be freed when disposing the plane object, nullptr if the plane is not owner of the memory.
|
protected |
The number of bytes per pixel, with range [1, infinity), 0 if unknown.
|
protected |
The number of channels the plane has, with range [0, infinity).
|
protected |
The pointer to the read-only memory of the plane (not the pointer to the allocated memory), nullptr, if the plane is not read-only, or invalid.
|
protected |
The pointer to the writable memory of the plane (not the pointer to the allocated memory), nullptr if the plane is not writable.
|
protected |
The size of each element of this plane, in bytes, with range [0, infinity).
|
protected |
The height of the plane in pixel, with range [0, infinity).
|
protected |
The number of padding elements at the end of each plane row, in elements, with range [0, infinity).
|
protected |
The number of bytes between the start positions of two consecutive rows, in bytes, identical to '(width_ * channels_ + paddingElements_) * elementTypeSize_`.
|
protected |
The width of the plane in pixel, with range [0, infinity).