8#ifndef META_OCEAN_CV_FRAME_PYRAMID_H
9#define META_OCEAN_CV_FRAME_PYRAMID_H
96 static constexpr unsigned int AS_MANY_LAYERS_AS_POSSIBLE = (
unsigned int)(-1);
101 static constexpr size_t memoryAlignmentBytes_ = 8;
149 inline FramePyramid(
const uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const FrameType::PixelOrigin pixelOrigin,
const unsigned int layers,
const unsigned int framePaddingElements,
const bool copyFirstLayer,
Worker* worker =
nullptr,
const FrameType::PixelFormat pixelFormat = FrameType::FORMAT_UNDEFINED,
const Timestamp timestamp =
Timestamp(
false));
162 inline FramePyramid(
const Frame& frame,
const unsigned int layers,
const bool copyFirstLayer,
Worker* worker =
nullptr);
182 inline FramePyramid(
const uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const FrameType::PixelOrigin pixelOrigin,
const DownsamplingMode downsamplingMode,
const unsigned int layers,
const unsigned int framePaddingElements,
const bool copyFirstLayer,
Worker* worker,
const FrameType::PixelFormat pixelFormat = FrameType::FORMAT_UNDEFINED,
const Timestamp timestamp =
Timestamp(
false));
240 inline const Frame& layer(
const unsigned int layer)
const;
247 inline Frame& layer(
const unsigned int layer);
254 inline const Frame& finestLayer()
const;
261 inline Frame& finestLayer();
269 inline const Frame& coarsestLayer()
const;
277 inline Frame& coarsestLayer();
283 inline unsigned int layers()
const;
290 inline unsigned int width(
const unsigned int layer)
const;
297 inline unsigned int height(
const unsigned int layer)
const;
303 inline unsigned int finestWidth()
const;
309 inline unsigned int finestHeight()
const;
316 inline unsigned int coarsestWidth()
const;
323 inline unsigned int coarsestHeight()
const;
330 inline unsigned int coarsestSizeFactor()
const;
337 inline const FrameType& frameType()
const;
412 bool replace8BitPerChannel(
const uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const FrameType::PixelOrigin pixelOrigin,
const DownsamplingMode downsamplingMode,
const unsigned int layers,
const unsigned int framePaddingElements,
const bool copyFirstLayer,
Worker* worker,
const FrameType::PixelFormat pixelFormat = FrameType::FORMAT_UNDEFINED,
const Timestamp timestamp =
Timestamp(
false));
432 bool replace8BitPerChannel11(
const uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const FrameType::PixelOrigin pixelOrigin,
const unsigned int layers,
const unsigned int framePaddingElements,
const bool copyFirstLayer,
Worker* worker,
const FrameType::PixelFormat pixelFormat = FrameType::FORMAT_UNDEFINED,
const Timestamp timestamp =
Timestamp(
false));
446 inline bool replace8BitPerChannel11(
const Frame& frame,
const unsigned int layers,
const bool copyFirstLayer,
Worker* worker);
456 inline bool replace(
const FrameType& frameType,
const bool forceOwner,
const unsigned int layers);
474 bool isOwner(
const unsigned int layerIndex = AS_MANY_LAYERS_AS_POSSIBLE)
const;
480 inline bool isValid()
const;
487 inline const Memory& memory()
const;
502 inline const Frame& operator[](
const unsigned int layer)
const;
510 inline Frame& operator[](
const unsigned int layer);
516 explicit inline operator bool()
const;
524 static constexpr unsigned int sizeFactor(
const unsigned int layer);
535 static unsigned int idealLayers(
const unsigned int width,
const unsigned int height,
const unsigned int invalidCoarsestWidthOrHeight,
unsigned int* coarsestLayerWidth =
nullptr,
unsigned int* coarsestLayerHeight =
nullptr);
547 static unsigned int idealLayers(
const unsigned int width,
const unsigned int height,
const unsigned int invalidCoarsestWidth,
const unsigned int invalidCoarsestHeight,
unsigned int* coarsestLayerWidth =
nullptr,
unsigned int* coarsestLayerHeight =
nullptr);
562 static unsigned int idealLayers(
const unsigned int width,
const unsigned int height,
const unsigned int invalidCoarsestWidth,
const unsigned int invalidCoarsestHeight,
const unsigned int layerFactor,
const unsigned int maximalRadius = (
unsigned int)(-1),
const unsigned int coarsestLayerRadius = 2u,
unsigned int* coarsestLayerWidth =
nullptr,
unsigned int* coarsestLayerHeight =
nullptr);
595 bool replace(
const FrameType& frameType,
const bool reserveFirstLayerMemory,
const bool forceOwner,
const unsigned int layers);
607 static size_t calculateMemorySize(
const unsigned int width,
const unsigned int height,
const FrameType::PixelFormat pixelFormat,
const unsigned int layers,
const bool includeFirstLayer,
unsigned int* totalLayers =
nullptr);
616 bool replace(
const Frame& frame,
const bool forceOwner,
const unsigned int layers = AS_MANY_LAYERS_AS_POSSIBLE) =
delete;
684inline FramePyramid::FramePyramid(
const uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const FrameType::PixelOrigin pixelOrigin,
const unsigned int layers,
const unsigned int framePaddingElements,
const bool copyFirstLayer,
Worker* worker,
const FrameType::PixelFormat pixelFormat,
const Timestamp timestamp)
687 ocean_assert(channels >= 1u);
689 const bool result =
replace8BitPerChannel11(frame,
width,
height, channels, pixelOrigin,
layers, framePaddingElements, copyFirstLayer, worker, pixelFormat, timestamp);
690 ocean_assert_and_suppress_unused(result, result);
696 ocean_assert_and_suppress_unused(result, result);
699inline FramePyramid::FramePyramid(
const uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const FrameType::PixelOrigin pixelOrigin,
const DownsamplingMode downsamplingMode,
const unsigned int layers,
const unsigned int framePaddingElements,
const bool copyFirstLayer,
Worker* worker,
const FrameType::PixelFormat pixelFormat,
const Timestamp timestamp)
702 ocean_assert(channels >= 1u);
704 const bool result =
replace8BitPerChannel(frame,
width,
height, channels, pixelOrigin, downsamplingMode,
layers, framePaddingElements, copyFirstLayer, worker, pixelFormat, timestamp);
705 ocean_assert_and_suppress_unused(result, result);
710 const bool result =
replace(frame, downsamplingMode,
layers, copyFirstLayer, worker);
711 ocean_assert_and_suppress_unused(result, result);
717 ocean_assert_and_suppress_unused(result, result);
722 const bool result =
replace(downsamplingMode, std::move(frame),
layers, worker);
723 ocean_assert_and_suppress_unused(result, result);
729 ocean_assert_and_suppress_unused(result, result);
772 return (
unsigned int)
layers_.size();
790 return layers_.front().width();
796 return layers_.front().height();
810 return layers_.back().height();
817 return 1u << (
unsigned int)((
layers_.size() - 1));
823 return layers_.front().frameType();
832 return replace8BitPerChannel11(frame.
constdata<uint8_t>(), frame.
width(), frame.
height(), frame.
channels(), frame.
pixelOrigin(),
layers, frame.
paddingElements(), copyFirstLayer, worker, frame.
pixelFormat(), frame.
timestamp());
845 ocean_assert(
layer <= 31u);
882inline FramePyramid::operator bool()
const
This class implements a frame pyramid.
Definition FramePyramid.h:46
static CV::FramePyramid::DownsamplingFunction downsamplingFunction(const CV::FramePyramid::DownsamplingMode downsamplingMode, const FrameType::PixelFormat pixelFormat)
Returns the downsampling function for a specified downsampling mode.
const Frame & finestLayer() const
Returns the finest layer frame of this pyramid.
Definition FramePyramid.h:744
FramePyramid(const FramePyramid &framePyramid, const unsigned int firstLayerIndex, const unsigned int layers, bool copyData)
Creates a new frame pyramid based on an existing frame pyramid.
FramePyramid(const unsigned int layers, const FrameType &frameType)
Creates a frame pyramid object for a given frame type and layer number.
bool replace(const Frame &frame, const DownsamplingMode downsamplingMode, const unsigned int layers, const bool copyFirstLayer, Worker *worker)
Replaces this frame pyramid based on a new frame.
static unsigned int idealLayers(const unsigned int width, const unsigned int height, const unsigned int invalidCoarsestWidthOrHeight, unsigned int *coarsestLayerWidth=nullptr, unsigned int *coarsestLayerHeight=nullptr)
Determines the number of layers until an invalid frame size would be reached in the next layer.
unsigned int coarsestWidth() const
Returns the width of the coarsest (last) layer regarding to the number of valid layers.
Definition FramePyramid.h:799
FramePyramid(Frame &&)=delete
Disabled constructor.
bool replace8BitPerChannel(const uint8_t *frame, const unsigned int width, const unsigned int height, const unsigned int channels, const FrameType::PixelOrigin pixelOrigin, const DownsamplingMode downsamplingMode, const unsigned int layers, const unsigned int framePaddingElements, const bool copyFirstLayer, Worker *worker, const FrameType::PixelFormat pixelFormat=FrameType::FORMAT_UNDEFINED, const Timestamp timestamp=Timestamp(false))
Replaces this frame pyramid based on a new frame.
unsigned int finestWidth() const
Returns the width of the finest (first) layer.
Definition FramePyramid.h:787
bool replace(const Frame &frame, const DownsamplingFunction &downsamplingFunction, const unsigned int layers, const bool copyFirstLayer, Worker *worker)
Replaces this frame pyramid based on a new frame.
void reduceLayers(const size_t layers)
Reduces the number of pyramid layers.
bool replace(const DownsamplingMode downsamplingMode, Frame &&frame, const unsigned int layers, Worker *worker)
Replaces this frame pyramid based on a new frame.
bool replace(const Frame &, const DownsamplingMode, const unsigned int layers, Worker *worker)=delete
Deleted function to prevent confusion between several different replace functions.
const Memory & memory() const
Returns the pyramid's memory block.
Definition FramePyramid.h:877
bool replace(const FrameType &frameType, const bool reserveFirstLayerMemory, const bool forceOwner, const unsigned int layers)
Replaces this frame pyramid with a new pyramid defined by the frame type of the finest layer.
bool isValid() const
Returns whether this pyramid holds at least one frame layer.
Definition FramePyramid.h:872
std::function< bool(const Frame &sourceLayer, Frame &targetLayer, Worker *worker)> DownsamplingFunction
Definition of a function allowing to downsample a frame.
Definition FramePyramid.h:91
static unsigned int idealLayers(const unsigned int width, const unsigned int height, const unsigned int invalidCoarsestWidth, const unsigned int invalidCoarsestHeight, const unsigned int layerFactor, const unsigned int maximalRadius=(unsigned int)(-1), const unsigned int coarsestLayerRadius=2u, unsigned int *coarsestLayerWidth=nullptr, unsigned int *coarsestLayerHeight=nullptr)
Determines the number of layers until an invalid frame size would be reached in the next layer or an ...
FramePyramid & operator=(const FramePyramid &)=delete
Disabled assign operator Use a constructor or the move operator instead.
Frames layers_
The individual layers of this pyramid, zero if not valid.
Definition FramePyramid.h:673
unsigned int coarsestHeight() const
Returns the height of the coarsest (last) layer regarding to the number of valid layers.
Definition FramePyramid.h:806
unsigned int width(const unsigned int layer) const
Returns the width of a given layer.
Definition FramePyramid.h:775
static unsigned int idealLayers(const unsigned int width, const unsigned int height, const unsigned int invalidCoarsestWidth, const unsigned int invalidCoarsestHeight, unsigned int *coarsestLayerWidth=nullptr, unsigned int *coarsestLayerHeight=nullptr)
Determines the number of layers until an invalid frame size would be reached in the next layer.
FramePyramid & operator=(FramePyramid &&right) noexcept
Move operator.
DownsamplingMode
Definition of individual down sampling modes.
Definition FramePyramid.h:53
@ DM_FILTER_11
Down sampling is realized by a 2x2 averaging filter.
Definition FramePyramid.h:65
FramePyramid(const Frame &frame, const DownsamplingFunction &downsamplingFunction, const unsigned int layers, Worker *worker)=delete
Disabled constructor to prevent confusion between all constructors.
FramePyramid(const FramePyramid &framePyramid, const bool copyData)
Copy constructor.
const Frame & operator[](const unsigned int layer) const
Returns the frame of a specified layer.
Definition FramePyramid.h:860
void clear()
Releases the internal frame layers.
Definition FramePyramid.h:854
unsigned int coarsestSizeFactor() const
Returns the size factor for the coarsest layer in relation to the finest layer regarding to the numbe...
Definition FramePyramid.h:813
FramePyramid()
Creates an empty frame pyramid object.
Definition FramePyramid.h:679
const Frame & coarsestLayer() const
Returns the coarsest layer frame of this pyramid regarding to the number of valid layers.
Definition FramePyramid.h:756
static size_t calculateMemorySize(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const unsigned int layers, const bool includeFirstLayer, unsigned int *totalLayers=nullptr)
Calculates the size of the entire pyramid in bytes covering all images in all pyramid layers.
unsigned int layers() const
Returns the number of layers this pyramid holds.
Definition FramePyramid.h:770
static bool downsampleByTwo11(const Frame &finerLayer, Frame &coarserLayer, Worker *worker)
Downsamples a frame with 1-1 filter.
FramePyramid(const Frame &, const bool)=delete
Disabled constructor.
bool replace(const Frame &frame, const bool forceOwner, const unsigned int layers=AS_MANY_LAYERS_AS_POSSIBLE)=delete
Deleted function to prevent confusion between Frame and FrameType.
static bool downsampleAlphaByTwo11(const Frame &finerLayer, Frame &coarserLayer, Worker *worker)
Downsamples a frame with 1-1 filter which contains an alpha channel.
bool replace(const Frame &, const DownsamplingFunction &, const unsigned int layers, Worker *worker)=delete
Deleted function to prevent confusion between several different replace functions.
Memory memory_
Optional memory which may be used by at least one pyramid layer.
Definition FramePyramid.h:676
FramePyramid(const Frame &frame, const DownsamplingMode downsamplingMode, const unsigned int layers, Worker *worker)=delete
Disabled constructor to prevent confusion between all constructors.
bool replace8BitPerChannel11(const uint8_t *frame, const unsigned int width, const unsigned int height, const unsigned int channels, const FrameType::PixelOrigin pixelOrigin, const unsigned int layers, const unsigned int framePaddingElements, const bool copyFirstLayer, Worker *worker, const FrameType::PixelFormat pixelFormat=FrameType::FORMAT_UNDEFINED, const Timestamp timestamp=Timestamp(false))
Replaces this frame pyramid by a new frame with 1 plane and data type DT_UNSIGNED_INTEGER_8 applying ...
const FrameType & frameType() const
Returns the frame type of the finest layer.
Definition FramePyramid.h:820
unsigned int finestHeight() const
Returns the height of the finest (first) layer.
Definition FramePyramid.h:793
unsigned int height(const unsigned int layer) const
Returns the height of a given layer.
Definition FramePyramid.h:781
bool isOwner(const unsigned int layerIndex=AS_MANY_LAYERS_AS_POSSIBLE) const
Returns whether the frame pyramid is the owner of the entire image data or owner of a specific pyrami...
static constexpr unsigned int sizeFactor(const unsigned int layer)
Returns the size factor of a specified layer in relation to the finest layer.
Definition FramePyramid.h:843
FramePyramid(FramePyramid &&framePyramid) noexcept
Move constructor.
static bool downsampleByTwo14641(const Frame &finerLayer, Frame &coarserLayer, Worker *worker)
Downsamples a frame with 1-4-6-4-1 filter.
const Frame & layer(const unsigned int layer) const
Returns the frame of a specified layer.
Definition FramePyramid.h:732
bool replace(const DownsamplingFunction &downsamplingFunction, Frame &&frame, const unsigned int layers, Worker *worker)
Replaces this frame pyramid based on a new frame.
This class implements Ocean's image class.
Definition Frame.h:1808
const T * constdata(const unsigned int planeIndex=0u) const
Returns a pointer to the read-only pixel data of a specific plane.
Definition Frame.h:4251
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4531
const Timestamp & timestamp() const
Returns the timestamp of this frame.
Definition Frame.h:4221
unsigned int size(const unsigned int planeIndex=0u) const
Returns the number of bytes necessary for a specific plane including optional padding at the end of p...
Definition Frame.h:4117
unsigned int paddingElements(const unsigned int planeIndex=0u) const
Returns the optional number of padding elements at the end of each row for a specific plane.
Definition Frame.h:4125
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition Frame.h:30
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition Frame.h:183
unsigned int width() const
Returns the width of the frame format in pixel.
Definition Frame.h:3170
PixelOrigin pixelOrigin() const
Returns the pixel origin of the frame.
Definition Frame.h:3215
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition Frame.h:3210
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition Frame.h:3180
PixelOrigin
Defines different types of frame origin positions.
Definition Frame.h:1046
@ DT_UNSIGNED_INTEGER_8
Unsigned 8 bit integer data type (uint8_t).
Definition Frame.h:41
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3175
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition Frame.h:3200
DataType dataType() const
Returns the data type of the pixel format of this frame.
Definition Frame.h:3190
This class implements an object able to allocate memory.
Definition base/Memory.h:22
void free()
Explicitly frees (releases) the memory before this object is released.
Definition base/Memory.h:370
This class implements a timestamp.
Definition Timestamp.h:47
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
std::vector< Frame > Frames
Definition of a vector holding padding frames.
Definition Frame.h:1771
std::vector< FramePyramid > FramePyramids
Definition of a vector holding frame pyramid objects.
Definition FramePyramid.h:36
The namespace covering the entire Ocean framework.
Definition Accessor.h:15