8#ifndef META_OCEAN_CV_FRAME_PYRAMID_H
9#define META_OCEAN_CV_FRAME_PYRAMID_H
87 static constexpr unsigned int AS_MANY_LAYERS_AS_POSSIBLE = (
unsigned int)(-1);
92 static constexpr size_t memoryAlignmentBytes_ = 8;
140 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));
153 inline FramePyramid(
const Frame& frame,
const unsigned int layers,
const bool copyFirstLayer,
Worker* worker =
nullptr);
173 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));
231 inline const Frame& layer(
const unsigned int layer)
const;
238 inline Frame& layer(
const unsigned int layer);
245 inline const Frame& finestLayer()
const;
252 inline Frame& finestLayer();
260 inline const Frame& coarsestLayer()
const;
268 inline Frame& coarsestLayer();
274 inline unsigned int layers()
const;
281 inline unsigned int width(
const unsigned int layer)
const;
288 inline unsigned int height(
const unsigned int layer)
const;
294 inline unsigned int finestWidth()
const;
300 inline unsigned int finestHeight()
const;
307 inline unsigned int coarsestWidth()
const;
314 inline unsigned int coarsestHeight()
const;
321 inline unsigned int coarsestSizeFactor()
const;
328 inline const FrameType& frameType()
const;
403 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));
423 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));
437 inline bool replace8BitPerChannel11(
const Frame& frame,
const unsigned int layers,
const bool copyFirstLayer,
Worker* worker);
447 inline bool replace(
const FrameType& frameType,
const bool forceOwner,
const unsigned int layers);
465 bool isOwner(
const unsigned int layerIndex = AS_MANY_LAYERS_AS_POSSIBLE)
const;
471 inline bool isValid()
const;
478 inline const Memory& memory()
const;
493 inline const Frame& operator[](
const unsigned int layer)
const;
501 inline Frame& operator[](
const unsigned int layer);
507 explicit inline operator bool()
const;
515 static constexpr unsigned int sizeFactor(
const unsigned int layer);
526 static unsigned int idealLayers(
const unsigned int width,
const unsigned int height,
const unsigned int invalidCoarsestWidthOrHeight,
unsigned int* coarsestLayerWidth =
nullptr,
unsigned int* coarsestLayerHeight =
nullptr);
538 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);
553 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);
586 bool replace(
const FrameType& frameType,
const bool reserveFirstLayerMemory,
const bool forceOwner,
const unsigned int layers);
598 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);
607 bool replace(
const Frame& frame,
const bool forceOwner,
const unsigned int layers = AS_MANY_LAYERS_AS_POSSIBLE) =
delete;
675inline 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)
678 ocean_assert(channels >= 1u);
680 const bool result =
replace8BitPerChannel11(frame,
width,
height, channels, pixelOrigin,
layers, framePaddingElements, copyFirstLayer, worker, pixelFormat, timestamp);
681 ocean_assert_and_suppress_unused(result, result);
687 ocean_assert_and_suppress_unused(result, result);
690inline 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)
693 ocean_assert(channels >= 1u);
695 const bool result =
replace8BitPerChannel(frame,
width,
height, channels, pixelOrigin, downsamplingMode,
layers, framePaddingElements, copyFirstLayer, worker, pixelFormat, timestamp);
696 ocean_assert_and_suppress_unused(result, result);
701 const bool result =
replace(frame, downsamplingMode,
layers, copyFirstLayer, worker);
702 ocean_assert_and_suppress_unused(result, result);
708 ocean_assert_and_suppress_unused(result, result);
713 const bool result =
replace(downsamplingMode, std::move(frame),
layers, worker);
714 ocean_assert_and_suppress_unused(result, result);
720 ocean_assert_and_suppress_unused(result, result);
763 return (
unsigned int)
layers_.size();
781 return layers_.front().width();
787 return layers_.front().height();
801 return layers_.back().height();
808 return 1u << (
unsigned int)((
layers_.size() - 1));
814 return layers_.front().frameType();
823 return replace8BitPerChannel11(frame.
constdata<uint8_t>(), frame.
width(), frame.
height(), frame.
channels(), frame.
pixelOrigin(),
layers, frame.
paddingElements(), copyFirstLayer, worker, frame.
pixelFormat(), frame.
timestamp());
836 ocean_assert(
layer <= 31u);
873inline FramePyramid::operator bool()
const
This class implements a frame pyramid.
Definition FramePyramid.h:37
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:735
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:790
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:778
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:868
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:863
std::function< bool(const Frame &sourceLayer, Frame &targetLayer, Worker *worker)> DownsamplingFunction
Definition of a function allowing to downsample a frame.
Definition FramePyramid.h:82
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:664
unsigned int coarsestHeight() const
Returns the height of the coarsest (last) layer regarding to the number of valid layers.
Definition FramePyramid.h:797
unsigned int width(const unsigned int layer) const
Returns the width of a given layer.
Definition FramePyramid.h:766
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:44
@ DM_FILTER_11
Down sampling is realized by a 2x2 averaging filter.
Definition FramePyramid.h:56
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:851
void clear()
Releases the internal frame layers.
Definition FramePyramid.h:845
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:804
FramePyramid()
Creates an empty frame pyramid object.
Definition FramePyramid.h:670
const Frame & coarsestLayer() const
Returns the coarsest layer frame of this pyramid regarding to the number of valid layers.
Definition FramePyramid.h:747
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:761
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:667
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:811
unsigned int finestHeight() const
Returns the height of the finest (first) layer.
Definition FramePyramid.h:784
unsigned int height(const unsigned int layer) const
Returns the height of a given layer.
Definition FramePyramid.h:772
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:834
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:723
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:4248
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4528
const Timestamp & timestamp() const
Returns the timestamp of this frame.
Definition Frame.h:4218
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:4114
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:4122
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:36
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
The namespace covering the entire Ocean framework.
Definition Accessor.h:15