Ocean
FramePyramid.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_CV_FRAME_PYRAMID_H
9 #define META_OCEAN_CV_FRAME_PYRAMID_H
10 
11 #include "ocean/cv/CV.h"
12 
13 #include "ocean/base/Callback.h"
14 #include "ocean/base/Frame.h"
15 #include "ocean/base/Memory.h"
16 #include "ocean/base/Worker.h"
17 
18 #include "ocean/cv/FrameShrinker.h"
20 
21 #include <functional>
22 
23 namespace Ocean
24 {
25 
26 namespace CV
27 {
28 
29 /**
30  * This class implements a frame pyramid.<br>
31  * A frame pyramid holds the same frame with several scale spaces.<br>
32  * Each further layer holds the frame with half size (half width and half height).<br>
33  * The finest layer has index 0 and the coarsest layer has the highest index.
34  * @ingroup cv
35  */
36 class OCEAN_CV_EXPORT FramePyramid
37 {
38  public:
39 
40  /**
41  * Definition of individual down sampling modes.
42  */
43  enum DownsamplingMode : uint32_t
44  {
45  /**
46  * Down sampling is realized by a 2x2 averaging filter.
47  * This down sampling mode is the fastest mode available, as 2x2 pixel blocks are simply averaged.<br>
48  * The corresponding filter mask has the following layout:
49  * <pre>
50  * | 1 1 |
51  * | 1 1 | * 1/4
52  * </pre>
53  * The upper left filter element is applied to every even pixel location in the source frame.<br>
54  * In case, the width or height of a given frame is odd, the last column/row will apply a 121 filter.
55  */
57 
58  /**
59  * Down sampling is realized by a 5x5 Gaussian filter.
60  * This down sampling mode is more expensive but reduces aliasing effects on down sampled images.<br>
61  * The corresponding filter mask has the following layout:
62  * <pre>
63  * | 1 4 6 4 1 |
64  * | 4 16 24 16 4 |
65  * | 6 24 36 24 6 | * 1/256
66  * | 4 16 24 16 4 |
67  * | 1 4 6 4 1 |
68  * </pre>
69  * The center of the filter is applied to every even pixel location in the source frame.<br>
70  * At the border of frames, the filter responses are determined based on mirrored pixel values.
71  */
72  DM_FILTER_14641
73  };
74 
75  /**
76  * Definition of a function allowing to downsample a frame.
77  * @param sourceLayer The source layer to downsample
78  * @param targetLayer The target layer reviving the downsampled image content
79  * @param worker Optional worker to distribute the computation
80  * @return True, if succeeded
81  */
82  using DownsamplingFunction = std::function<bool(const Frame& sourceLayer, Frame& targetLayer, Worker* worker)>;
83 
84  /**
85  * Definition of a value that can be used to create as many pyramid layers as possible (so that the coarsest pyramid layer has resolution 1x1).
86  */
87  static constexpr unsigned int AS_MANY_LAYERS_AS_POSSIBLE = (unsigned int)(-1);
88 
89  protected:
90 
91  /// The number of bytes for memory alignment.
92  static constexpr size_t memoryAlignmentBytes_ = 8;
93 
94  public:
95 
96  /**
97  * Creates an empty frame pyramid object.
98  */
99  inline FramePyramid();
100 
101  /**
102  * Copy constructor.
103  * @param framePyramid Frame pyramid to be copied
104  * @param copyData True, to copy the image content of the frame pyramid; False, to only reuse the image content of the frame pyramid
105  */
106  FramePyramid(const FramePyramid& framePyramid, const bool copyData);
107 
108  /**
109  * Move constructor.
110  * @param framePyramid Frame pyramid to be moved
111  */
112  FramePyramid(FramePyramid&& framePyramid) noexcept;
113 
114  /**
115  * Creates a frame pyramid object for a given frame type and layer number.
116  * The resulting pyramid may have fewer layers than desired.<br>
117  * The image content of the replaced frame pyramid will be uninitialized.
118  * @param layers The preferred number of layers to be created, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to create as may layers as possible
119  * @param frameType Type of the frame to create a frame pyramid for, must be valid
120  */
121  explicit FramePyramid(const unsigned int layers, const FrameType& frameType);
122 
123  /**
124  * Creates a new pyramid frame for frames with 1 plane and data type DT_UNSIGNED_INTEGER_8 applying a 1-1 downsampling.
125  * This constructor is intentionally restrictive to reduce binary impact when used, use other constructors or functions in case more flexibility is needed an binary size does not matter.<br>
126  * The constructor mainly calls replace8BitPerChannel11().
127  * @param frame The frame for which the pyramid will be created, must be valid
128  * @param width The width of the given frame in pixel, with range [1, infinity)
129  * @param height The height of the given frame in pixel, with range [1, infinity)
130  * @param channels The number of channels the given frame has, with range [1, infinity)
131  * @param pixelOrigin The pixel origin of the given frame
132  * @param layers Number of pyramid layers to be created, with range [1, infinity)
133  * @param framePaddingElements The number of padding elements at the end of each frame row, in elements, with range [0, infinity)
134  * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
135  * @param worker Optional worker object to distribute the computation
136  * @param pixelFormat The explicit pixel format which will be used for each pyramid layer, must be compatible with DT_UNSIGNED_INTEGER_8 and 'channels'; FORMAT_UNDEFINED to use a generic pixel format
137  * @param timestamp Timestamp to be assigned to the frame pyramid (e.g., the timestamp of the frame used to created the timestamp)
138  * @see replace8BitPerChannel11().
139  */
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));
141 
142  /**
143  * Creates a new pyramid frame for frames with 1 plane and data type DT_UNSIGNED_INTEGER_8 applying a 1-1 downsampling.
144  * This constructor is intentionally restrictive to reduce binary impact when used, use other constructors or functions in case more flexibility is needed an binary size does not matter.<br>
145  * In case the provided frame not a valid 1-plane DT_UNSIGNED_INTEGER_8 frame, the pyramid will be invalid.<br>
146  * The constructor mainly calls replace8BitPerChannel11().
147  * @param frame The frame for which the pyramid will be created, with 1 plane and data type DT_UNSIGNED_INTEGER_8, must be valid
148  * @param layers Number of pyramid layers to be created, with range [1, infinity)
149  * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
150  * @param worker Optional worker object to distribute the computation
151  * @see replace8BitPerChannel11().
152  */
153  inline FramePyramid(const Frame& frame, const unsigned int layers, const bool copyFirstLayer, Worker* worker = nullptr);
154 
155  /**
156  * Creates a frame pyramid based on a frame with 1 plane and data type DT_UNSIGNED_INTEGER_8 applying a custom downsampling.
157  * The resulting pyramid will contain a copy of the given frame (as finest pyramid layer) or will just use the memory, depending on 'copyFirstLayer'.<br>
158  * The constructor mainly calls replace8BitPerChannel().
159  * @param frame The frame for which the pyramid will be created, must be valid
160  * @param width The width of the frame in pixel, with range [1, infinity)
161  * @param height The height of the frame in pixel, with range [1, infinity)
162  * @param channels The number of channels the given frame has, with range [1, infinity)
163  * @param pixelOrigin The pixel origin of the given frame
164  * @param downsamplingMode The downsampling mode to use when creating the individual pyramid layers, must be valid
165  * @param layers Number of pyramid layers to be created, with range [1, infinity)
166  * @param framePaddingElements The number of padding elements at the end of each frame row, in elements, with range [0, infinity)
167  * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
168  * @param worker Optional worker object to distribute the computation
169  * @param pixelFormat The explicit pixel format which will be used for each pyramid layer, must be compatible with DT_UNSIGNED_INTEGER_8 and 'channels'; FORMAT_UNDEFINED to use a generic pixel format
170  * @param timestamp Timestamp to be assigned to the frame pyramid (e.g., the timestamp of the frame used to created the timestamp)
171  * @see replace8BitPerChannel().
172  */
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));
174 
175  /**
176  * Creates a frame pyramid based on a frame applying a custom downsampling.
177  * The resulting pyramid will contain a copy of the given frame (as finest pyramid layer) or will just use the memory, depending on 'copyFirstLayer'.
178  * @param frame The frame for which the pyramid will be created, must be valid
179  * @param downsamplingMode The downsampling mode to use when creating the individual pyramid layers, must be valid
180  * @param layers The number of pyramid layers to be created, with range [1, infinity)
181  * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case,
182  * @param worker Optional worker object to distribute the computation
183  */
184  inline FramePyramid(const Frame& frame, const DownsamplingMode downsamplingMode, const unsigned int layers, const bool copyFirstLayer, Worker* worker);
185 
186  /**
187  * Creates a frame pyramid based on a frame applying a custom downsampling.
188  * The resulting pyramid will contain a copy of the given frame (as finest pyramid layer) or will just use the memory, depending on 'copyFirstLayer'.
189  * @param frame The frame for which the pyramid will be created, must be valid
190  * @param downsamplingFunction The custom function used to downsample the individual pyramid layers, must be valid
191  * @param layers The number of pyramid layers to be created, with range [1, infinity)
192  * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case,
193  * @param worker Optional worker object to distribute the computation
194  */
195  inline FramePyramid(const Frame& frame, const DownsamplingFunction& downsamplingFunction, const unsigned int layers, const bool copyFirstLayer, Worker* worker);
196 
197  /**
198  * Creates a frame pyramid based on a frame applying a custom downsampling.
199  * The resulting pyramid will re-used the given frame (as finest pyramid layer); thus, ensure that the frame's memory is valid as long as this pyramid exists.
200  * @param downsamplingMode The downsampling mode to use when creating the individual pyramid layers, must be valid
201  * @param frame The frame for which the pyramid will be created, must be valid
202  * @param layers The number of pyramid layers to be created, with range [1, infinity)
203  * @param worker Optional worker object to distribute the computation
204  */
205  inline FramePyramid(const DownsamplingMode downsamplingMode, Frame&& frame, const unsigned int layers, Worker* worker);
206 
207  /**
208  * Creates a frame pyramid based on a frame applying a custom downsampling.
209  * The resulting pyramid will re-used the given frame (as finest pyramid layer); thus, ensure that the frame's memory is valid as long as this pyramid exists.
210  * @param downsamplingFunction The custom function used to downsample the individual pyramid layers, must be valid
211  * @param frame The frame for which the pyramid will be created, must be valid
212  * @param layers The number of pyramid layers to be created, with range [1, infinity)
213  * @param worker Optional worker object to distribute the computation
214  */
215  inline FramePyramid(const DownsamplingFunction& downsamplingFunction, Frame&& frame, const unsigned int layers, Worker* worker);
216 
217  /**
218  * Creates a new frame pyramid based on an existing frame pyramid.
219  * @param framePyramid The existing frame pyramid from which the new pyramid will be created, must be valid
220  * @param firstLayerIndex The index of the first layer to use from the source pyramid, with range [0, framePyramid.layers() - 1]
221  * @param layers The number of layers to use from the source pyramid, with range [1, infinity), AS_MANY_LAYERS_AS_POSSIBLE to use as many layers as exist
222  * @param copyData True, to make a copy of the image content of the existing pyramid; False, to only use the memory
223  */
224  FramePyramid(const FramePyramid& framePyramid, const unsigned int firstLayerIndex, const unsigned int layers, bool copyData);
225 
226  /**
227  * Returns the frame of a specified layer.
228  * @param layer Index of the layer frame to be returned, with range [0, layers())
229  * @return Pyramid layer frame
230  */
231  inline const Frame& layer(const unsigned int layer) const;
232 
233  /**
234  * Returns the frame of a specified layer.
235  * @param layer Index of the layer frame to be returned, with range [0, layers())
236  * @return Pyramid layer frame
237  */
238  inline Frame& layer(const unsigned int layer);
239 
240  /**
241  * Returns the finest layer frame of this pyramid.
242  * Beware: The frame will not be the owner of the frame data, if you need a copy of this frame enforce to copy the frame buffer!
243  * @return Finest pyramid layer frame
244  */
245  inline const Frame& finestLayer() const;
246 
247  /**
248  * Returns the coarsest layer frame of this pyramid.
249  * Beware: The frame will not be the owner of the frame data, if you need a copy of this frame enforce to copy the frame buffer!
250  * @return Finest pyramid layer frame
251  */
252  inline Frame& finestLayer();
253 
254  /**
255  * Returns the coarsest layer frame of this pyramid regarding to the number of valid layers.
256  * If no valid layer is stored in this pyramid, the finest layer is used instead.<br>
257  * Beware: The frame will not be the owner of the frame data, if you need a copy of this frame enforce to copy the frame buffer!<br>
258  * @return Finest pyramid layer frame
259  */
260  inline const Frame& coarsestLayer() const;
261 
262  /**
263  * Returns the finest layer frame of this pyramid regarding to the number of valid layers.
264  * If no valid layer is stored in this pyramid, the finest layer is used instead.<br>
265  * Beware: The frame will not be the owner of the frame data, if you need a copy of this frame enforce to copy the frame buffer!<br>
266  * @return Finest pyramid layer frame
267  */
268  inline Frame& coarsestLayer();
269 
270  /**
271  * Returns the number of layers this pyramid holds.
272  * @return Pyramid layers, with range [0, infinity)
273  */
274  inline unsigned int layers() const;
275 
276  /**
277  * Returns the width of a given layer.
278  * @param layer The layer to return the width for, with range [0, layers())
279  * @return Width in pixel
280  */
281  inline unsigned int width(const unsigned int layer) const;
282 
283  /**
284  * Returns the height of a given layer.
285  * @param layer The layer to return the height for, with range [0, layers())
286  * @return Height in pixel
287  */
288  inline unsigned int height(const unsigned int layer) const;
289 
290  /**
291  * Returns the width of the finest (first) layer.
292  * @return Width in pixel
293  */
294  inline unsigned int finestWidth() const;
295 
296  /**
297  * Returns the height of the finest (first) layer.
298  * @return Height in pixel
299  */
300  inline unsigned int finestHeight() const;
301 
302  /**
303  * Returns the width of the coarsest (last) layer regarding to the number of valid layers.
304  * If no valid layer is stored in this pyramid, the finest layer is used instead.
305  * @return Width in pixel
306  */
307  inline unsigned int coarsestWidth() const;
308 
309  /**
310  * Returns the height of the coarsest (last) layer regarding to the number of valid layers.
311  * If no valid layer is stored in this pyramid, the finest layer is used instead.
312  * @return Height in pixel
313  */
314  inline unsigned int coarsestHeight() const;
315 
316  /**
317  * Returns the size factor for the coarsest layer in relation to the finest layer regarding to the number of valid layers.
318  * If no valid layer is stored in this pyramid, the finest layer is used instead.
319  * @return Coarsest layer size factor
320  */
321  inline unsigned int coarsestSizeFactor() const;
322 
323  /**
324  * Returns the frame type of the finest layer.
325  * Beware: Ensure that the pyramid holds at least one pyramid layer before calling this function.
326  * @return Frame type
327  */
328  inline const FrameType& frameType() const;
329 
330  /**
331  * Replaces this frame pyramid based on a new frame.
332  * The function will re-used the existing pyramid's memory if possible.<br>
333  * The resulting pyramid will contain a copy of the given frame (as finest pyramid layer) or will just use the memory, depending on 'copyFirstLayer'.
334  * @param frame The frame for which the pyramid will be created, must be valid
335  * @param downsamplingMode The downsampling mode to use when creating the individual pyramid layers, must be valid
336  * @param layers The number of pyramid layers to be created, with range [1, infinity)
337  * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
338  * @param worker Optional worker object to distribute the computation
339  * @return True, if the frame pyramid was replaced
340  * @see replace8BitPerChannel11().
341  */
342  bool replace(const Frame& frame, const DownsamplingMode downsamplingMode, const unsigned int layers, const bool copyFirstLayer, Worker* worker);
343 
344  /**
345  * Replaces this frame pyramid based on a new frame.
346  * The function will re-used the existing pyramid's memory if possible.<br>
347  * The resulting pyramid will contain a copy of the given frame (as finest pyramid layer) or will just use the memory, depending on 'copyFirstLayer'.
348  * @param frame The frame for which the pyramid will be created, must be valid
349  * @param downsamplingFunction The custom function used to downsample the individual pyramid layers, must be valid
350  * @param layers The number of pyramid layers to be created, with range [1, infinity)
351  * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
352  * @param worker Optional worker object to distribute the computation
353  * @return True, if the frame pyramid was replaced
354  * @see replace8BitPerChannel11().
355  */
356  bool replace(const Frame& frame, const DownsamplingFunction& downsamplingFunction, const unsigned int layers, const bool copyFirstLayer, Worker* worker);
357 
358  /**
359  * Replaces this frame pyramid based on a new frame.
360  * The function will re-used the existing pyramid's memory if possible.<br>
361  * The resulting pyramid will re-used the given frame (as finest pyramid layer); thus, ensure that the frame's memory is valid as long as this pyramid exists.
362  * @param downsamplingMode The downsampling mode to use when creating the individual pyramid layers, must be valid
363  * @param frame The frame for which the pyramid will be created, must be valid
364  * @param layers The number of pyramid layers to be created, with range [1, infinity)
365  * @param worker Optional worker object to distribute the computation
366  * @return True, if the frame pyramid was replaced
367  * @see replace8BitPerChannel11().
368  */
369  bool replace(const DownsamplingMode downsamplingMode, Frame&& frame, const unsigned int layers, Worker* worker);
370 
371  /**
372  * Replaces this frame pyramid based on a new frame.
373  * The function will re-used the existing pyramid's memory if possible.<br>
374  * The resulting pyramid will re-used the given frame (as finest pyramid layer); thus, ensure that the frame's memory is valid as long as this pyramid exists.
375  * @param downsamplingFunction The custom function used to downsample the individual pyramid layers, must be valid
376  * @param frame The frame for which the pyramid will be created, must be valid
377  * @param layers The number of pyramid layers to be created, with range [1, infinity)
378  * @param worker Optional worker object to distribute the computation
379  * @return True, if the frame pyramid was replaced
380  * @see replace8BitPerChannel11().
381  */
382  bool replace(const DownsamplingFunction& downsamplingFunction, Frame&& frame, const unsigned int layers, Worker* worker);
383 
384  /**
385  * Replaces this frame pyramid based on a new frame.
386  * The function will re-used the existing pyramid's memory if possible.<br>
387  * The resulting pyramid will contain a copy of the given frame (as finest pyramid layer).
388  * @param frame The frame for which the pyramid will be created, must be valid
389  * @param width The width of the frame in pixel, with range [1, infinity)
390  * @param height The height of the frame in pixel, with range [1, infinity)
391  * @param channels The number of channels the given frame has, with range [1, infinity)
392  * @param pixelOrigin The pixel origin of the given frame
393  * @param downsamplingMode The downsampling mode to use when creating the individual pyramid layers, must be valid
394  * @param layers Number of pyramid layers to be created, with range [1, infinity)
395  * @param framePaddingElements The number of padding elements at the end of each frame row, in elements, with range [0, infinity)
396  * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
397  * @param worker Optional worker object to distribute the computation
398  * @param pixelFormat The explicit pixel format which will be used for each pyramid layer, must be compatible with DT_UNSIGNED_INTEGER_8 and 'channels'; FORMAT_UNDEFINED to use a generic pixel format
399  * @param timestamp Timestamp to be assigned to the frame pyramid (e.g., the timestamp of the frame used to created the timestamp)
400  * @return True, if the frame pyramid was replaced
401  * @see replace().
402  */
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));
404 
405  /**
406  * Replaces this frame pyramid by a new frame with 1 plane and data type DT_UNSIGNED_INTEGER_8 applying a 1-1 downsampling.
407  * This function is intentionally restrictive to reduce binary impact when used, use other function or the constructor in case more flexibility is needed an binary size does not matter.<br>
408  * The function will re-used the existing pyramid's memory of possible.
409  * @param frame The frame for which the pyramid will be created, must be valid
410  * @param width The width of the given frame in pixel, with range [1, infinity)
411  * @param height The height of the given frame in pixel, with range [1, infinity)
412  * @param channels The number of channels the given frame has, with range [1, infinity)
413  * @param pixelOrigin The pixel origin of the given frame
414  * @param layers The number of pyramid layers to be created, with range [1, infinity)
415  * @param framePaddingElements The number of padding elements at the end of each frame row, in elements, with range [0, infinity)
416  * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
417  * @param worker Optional worker object to distribute the computation
418  * @param pixelFormat The explicit pixel format which will be used for each pyramid layer, must be compatible with DT_UNSIGNED_INTEGER_8 and 'channels'; FORMAT_UNDEFINED to use a generic pixel format
419  * @param timestamp Timestamp to be assigned to the frame pyramid (e.g., the timestamp of the frame used to created the timestamp)
420  * @return True, if the frame pyramid was replaced
421  * @see isOwner(), replace().
422  */
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));
424 
425  /**
426  * Replaces this frame pyramid by a new frame with 1 plane and data type DT_UNSIGNED_INTEGER_8 applying a 1-1 downsampling.
427  * This function is intentionally restrictive to reduce binary impact when used, use other function or the constructor in case more flexibility is needed an binary size does not matter.<br>
428  * The function will re-used the existing pyramid's memory of possible.<br>
429  * This function does not provide the optimal image quality for images with alpha channel, use replace() instead.
430  * @param frame The frame for which the pyramid will be created, with 1 plane and data type DT_UNSIGNED_INTEGER_8, should not contain an alpha channel, must be valid
431  * @param layers The number of pyramid layers to be created, with range [1, infinity)
432  * @param copyFirstLayer True, to copy the memory of the first layer into the pyramid; False, to re-use the memory of the first layer only (in this case, ensure that the memory of the first layer exists as long as this pyramid exist)
433  * @param worker Optional worker object to distribute the computation
434  * @return True, if the frame pyramid was replaced
435  * @see isOwner(), replace().
436  */
437  inline bool replace8BitPerChannel11(const Frame& frame, const unsigned int layers, const bool copyFirstLayer, Worker* worker);
438 
439  /**
440  * Replaces this frame pyramid with a new pyramid defined by the frame type of the finest layer.
441  * The image content of the replaced frame pyramid will be uninitialized.
442  * @param frameType The type of the finest pyramid layer, must be valid
443  * @param layers The number of layers to be created during the resizing, the resulting layers will be as many as possible but not exceed this value, with range [1, infinity)
444  * @param forceOwner True, to force the pyramid to be the owner of the memory afterwards; False, to allow that the pyramid is not owning the memory (because the memory is managed outside of this pyramid)
445  * @return True, if succeeded
446  */
447  inline bool replace(const FrameType& frameType, const bool forceOwner, const unsigned int layers);
448 
449  /**
450  * Reduces the number of pyramid layers.
451  * @param layers The number of pyramid layers, with range [0, layers()]
452  */
453  void reduceLayers(const size_t layers);
454 
455  /**
456  * Releases the internal frame layers.
457  */
458  inline void clear();
459 
460  /**
461  * Returns whether the frame pyramid is the owner of the entire image data or owner of a specific pyramid layer.
462  * @param layerIndex The index of the layer to be checked, 'AS_MANY_LAYERS_AS_POSSIBLE" to check all layers
463  * @return True, if so
464  */
465  bool isOwner(const unsigned int layerIndex = AS_MANY_LAYERS_AS_POSSIBLE) const;
466 
467  /**
468  * Returns whether this pyramid holds at least one frame layer.
469  * @return True, if so
470  */
471  inline bool isValid() const;
472 
473  /**
474  * Returns the pyramid's memory block.
475  * This functions is intended for testing purposes only, don't use this function.
476  * @return The pyramid's memory block, if any
477  */
478  inline const Memory& memory() const;
479 
480  /**
481  * Move operator
482  * @param right The right frame to assign
483  * @return Reference to this frame
484  */
485  FramePyramid& operator=(FramePyramid&& right) noexcept;
486 
487  /**
488  * Returns the frame of a specified layer.
489  * Beware: The frame will not be the owner of the frame data, if you need a copy of this frame enforce to copy the frame buffer!
490  * @param layer Index of the layer frame to be returned, with range [0, layers())
491  * @return Pyramid layer frame
492  */
493  inline const Frame& operator[](const unsigned int layer) const;
494 
495  /**
496  * Returns the frame of a specified layer.
497  * Beware: The frame will not be the owner of the frame data, if you need a copy of this frame enforce to copy the frame buffer!
498  * @param layer Index of the layer frame to be returned, with range [0, layers())
499  * @return Pyramid layer frame
500  */
501  inline Frame& operator[](const unsigned int layer);
502 
503  /**
504  * Returns whether this pyramid holds at least one frame layer.
505  * @return True, if so
506  */
507  explicit inline operator bool() const;
508 
509  /**
510  * Returns the size factor of a specified layer in relation to the finest layer.
511  * The finest (first) layer has factor 1, the second layer has factor 2, the third layer has factor 4, ...<br>
512  * @param layer The layer to return the size factor for, with range [1, 31]
513  * @return The resulting size factor, with range [1, infinity)
514  */
515  static constexpr unsigned int sizeFactor(const unsigned int layer);
516 
517  /**
518  * Determines the number of layers until an invalid frame size would be reached in the next layer.
519  * @param width The width of the finest layer in pixel, with range [1, infinity)
520  * @param height The height of the finest layer in pixel, with range [1, infinity)
521  * @param invalidCoarsestWidthOrHeight The width or the height of a coarse layer not valid any more, with range (0, infinity)
522  * @param coarsestLayerWidth Optional resulting width of the coarsest valid pyramid layer, with range [invalidCoarsestWidth + 1u, width], nullptr if not of interest
523  * @param coarsestLayerHeight Optional resulting height of the coarsest valid pyramid layer, with range [invalidCoarsestHeight + 1u, height], nullptr if not of interest
524  * @return Resulting layers so that the invalid frame size will not be reached, with range [1, infinity), 0 if 'width' or 'height' are smaller or equal than 'invalidCoarsestWidthOrHeight'
525  */
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);
527 
528  /**
529  * Determines the number of layers until an invalid frame size would be reached in the next layer.
530  * @param width The width of the finest layer in pixel, with range [1, infinity)
531  * @param height The height of the finest layer in pixel, with range [1, infinity)
532  * @param invalidCoarsestWidth The width of a coarse layer not valid any more, with range (0, infinity)
533  * @param invalidCoarsestHeight The height of a coarse layer not valid any more, with range (0, infinity)
534  * @param coarsestLayerWidth Optional resulting width of the coarsest valid pyramid layer, with range [invalidCoarsestWidth + 1u, width], nullptr if not of interest
535  * @param coarsestLayerHeight Optional resulting height of the coarsest valid pyramid layer, with range [invalidCoarsestHeight + 1u, height], nullptr if not of interest
536  * @return Resulting layers so that the invalid frame size will not be reached, with range [1, infinity), 0 if 'width/height' is smaller or equal than 'invalidCoarsestWidth/invalidCoarsestHeight'
537  */
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);
539 
540  /**
541  * Determines the number of layers until an invalid frame size would be reached in the next layer or an overall size radius is reached.
542  * @param width The width of the finest layer in pixel
543  * @param height The height of the finest layer in pixel
544  * @param invalidCoarsestWidth Width of a coarse layer not valid any more, with range (0, infinity)
545  * @param invalidCoarsestHeight Height of a coarse layer not valid any more, with range (0, infinity)
546  * @param layerFactor Size factor on each layer (a factor of 2 means that the layer dimension is halved on each layer), with range [2, infinity)
547  * @param maximalRadius Maximal radius that can be reached on the finest layer by starting with coarsestLayerRadius on the coarsest layer in pixel (the maximal expected baseline between two pixels in the finest pyramid layer), with range [1, infinity)
548  * @param coarsestLayerRadius The search radius on the coarsest layer, with range [2, infinity)
549  * @param coarsestLayerWidth Optional resulting width of the coarsest valid pyramid layer, with range [invalidCoarsestWidth + 1u, width], nullptr if not of interest
550  * @param coarsestLayerHeight Optional resulting height of the coarsest valid pyramid layer, with range [invalidCoarsestHeight + 1u, height], nullptr if not of interest
551  * @return Resulting layers so that the invalid frame size will not be reached, with range [1, infinity), 0 if 'width/height' is smaller or equal than 'invalidCoarsestWidth/invalidCoarsestHeight'
552  */
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);
554 
555  protected:
556 
557  /**
558  * Disabled constructor.
559  */
560  explicit FramePyramid(Frame&&) = delete;
561 
562  /**
563  * Disabled constructor.
564  */
565  FramePyramid(const Frame&, const bool) = delete;
566 
567  /**
568  * Disabled constructor to prevent confusion between all constructors.
569  */
570  FramePyramid(const Frame& frame, const DownsamplingMode downsamplingMode, const unsigned int layers, Worker* worker) = delete;
571 
572  /**
573  * Disabled constructor to prevent confusion between all constructors.
574  */
575  FramePyramid(const Frame& frame, const DownsamplingFunction& downsamplingFunction, const unsigned int layers, Worker* worker) = delete;
576 
577  /**
578  * Replaces this frame pyramid with a new pyramid defined by the frame type of the finest layer.
579  * The image content of the replaced frame pyramid will be uninitialized.
580  * @param frameType The type of the finest pyramid layer, must be valid
581  * @param reserveFirstLayerMemory True, to reserve memory for the first pyramid layer (and to initialize the first layer frame); False, to reserve memory for the remaining pyramid layers only (and to skip initializing the first layer frame)
582  * @param layers The number of layers to be created during the resizing, the resulting layers will be as many as possible but not exceed this value, with range [1, infinity)
583  * @param forceOwner True, to force the pyramid to be the owner of the memory afterwards; False, to allow that the pyramid is not owning the memory (because the memory is managed outside of this pyramid)
584  * @return True, if succeeded
585  */
586  bool replace(const FrameType& frameType, const bool reserveFirstLayerMemory, const bool forceOwner, const unsigned int layers);
587 
588  /**
589  * Calculates the size of the entire pyramid in bytes covering all images in all pyramid layers.
590  * @param width The width of the finest layer in pixel, with range [0, 65535]
591  * @param height The height of the finest layer in pixel, with range [0, 65535]
592  * @param pixelFormat The pixel format of each layer, must be a generic 1-plane pixel format, must be valid
593  * @param layers Number of layers, with range [0, infinity)
594  * @param includeFirstLayer True, to determine the memory for all layers; False, to skip the first layer and only determine the memory for all remaining (coarser) layers
595  * @param totalLayers Optional resulting number of pyramid layers that will exist (always counts the very first layer independently of 'includeFirstLayer'), with range [0, layers]
596  * @return Resulting number of bytes, with range [0, infinity)
597  */
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);
599 
600  /**
601  * Deleted function to prevent confusion between Frame and FrameType.
602  * @param frame The potential frame to be used
603  * @param layers The number of layers
604  * @param forceOwner The ownership information
605  * @return True, if succeeded
606  */
607  bool replace(const Frame& frame, const bool forceOwner, const unsigned int layers = AS_MANY_LAYERS_AS_POSSIBLE) = delete;
608 
609  /**
610  * Disabled assign operator
611  * Use a constructor or the move operator instead.
612  * @return Reference to this object
613  */
615 
616  /**
617  * Downsamples a frame with 1-1 filter.
618  * @param finerLayer The finer pyramid layer, must be valid
619  * @param coarserLayer The coarser pyramid layer, must be valid
620  * @param worker The optional worker to distribute the computation
621  * @return True, if succeeded
622  */
623  static bool downsampleByTwo11(const Frame& finerLayer, Frame& coarserLayer, Worker* worker);
624 
625  /**
626  * Downsamples a frame with 1-1 filter which contains an alpha channel.
627  * @param finerLayer The finer pyramid layer, must be valid
628  * @param coarserLayer The coarser pyramid layer, must be valid
629  * @param worker The optional worker to distribute the computation
630  * @return True, if succeeded
631  */
632  static bool downsampleAlphaByTwo11(const Frame& finerLayer, Frame& coarserLayer, Worker* worker);
633 
634  /**
635  * Downsamples a frame with 1-4-6-4-1 filter.
636  * @param finerLayer The finer pyramid layer, must be valid
637  * @param coarserLayer The coarser pyramid layer, must be valid
638  * @param worker The optional worker to distribute the computation
639  * @return True, if succeeded
640  */
641  static bool downsampleByTwo14641(const Frame& finerLayer, Frame& coarserLayer, Worker* worker);
642 
643  /**
644  * Returns the downsampling function for a specified downsampling mode.
645  * @param downsamplingMode The downsampling mode for which the function will be returned
646  * @param pixelFormat The pixel format for which the downsampling function will be returned, must be valid
647  * @return The downsampling function, nullptr if unknown
648  */
650 
651  /**
652  * Deleted function to prevent confusion between several different replace functions.
653  */
654  bool replace(const Frame&, const DownsamplingMode, const unsigned int layers, Worker* worker) = delete;
655 
656  /**
657  * Deleted function to prevent confusion between several different replace functions.
658  */
659  bool replace(const Frame&, const DownsamplingFunction&, const unsigned int layers, Worker* worker) = delete;
660 
661  protected:
662 
663  /// The individual layers of this pyramid, zero if not valid.
665 
666  /// Optional memory which may be used by at least one pyramid layer.
668 };
669 
671 {
672  // nothing to do here
673 }
674 
675 inline 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)
676 {
677  ocean_assert(frame != nullptr && width >= 1u && height >= 1u && layers >= 1u);
678  ocean_assert(channels >= 1u);
679 
680  const bool result = replace8BitPerChannel11(frame, width, height, channels, pixelOrigin, layers, framePaddingElements, copyFirstLayer, worker, pixelFormat, timestamp);
681  ocean_assert_and_suppress_unused(result, result);
682 }
683 
684 inline FramePyramid::FramePyramid(const Frame& frame, const unsigned int layers, const bool copyFirstLayer, Worker* worker)
685 {
686  const bool result = replace8BitPerChannel11(frame, layers, copyFirstLayer, worker);
687  ocean_assert_and_suppress_unused(result, result);
688 }
689 
690 inline 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)
691 {
692  ocean_assert(frame != nullptr && width >= 1u && height >= 1u && layers >= 1u);
693  ocean_assert(channels >= 1u);
694 
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);
697 }
698 
699 inline FramePyramid::FramePyramid(const Frame& frame, const DownsamplingMode downsamplingMode, const unsigned int layers, const bool copyFirstLayer, Worker* worker)
700 {
701  const bool result = replace(frame, downsamplingMode, layers, copyFirstLayer, worker);
702  ocean_assert_and_suppress_unused(result, result);
703 }
704 
705 inline FramePyramid::FramePyramid(const Frame& frame, const DownsamplingFunction& downsamplingFunction, const unsigned int layers, const bool copyFirstLayer, Worker* worker)
706 {
707  const bool result = replace(frame, downsamplingFunction, layers, copyFirstLayer, worker);
708  ocean_assert_and_suppress_unused(result, result);
709 }
710 
711 inline FramePyramid::FramePyramid(const DownsamplingMode downsamplingMode, Frame&& frame, const unsigned int layers, Worker* worker)
712 {
713  const bool result = replace(downsamplingMode, std::move(frame), layers, worker);
714  ocean_assert_and_suppress_unused(result, result);
715 }
716 
717 inline FramePyramid::FramePyramid(const DownsamplingFunction& downsamplingFunction, Frame&& frame, const unsigned int layers, Worker* worker)
718 {
719  const bool result = replace(downsamplingFunction, std::move(frame), layers, worker);
720  ocean_assert_and_suppress_unused(result, result);
721 }
722 
723 inline const Frame& FramePyramid::layer(const unsigned int layer) const
724 {
725  ocean_assert(layer < layers_.size());
726  return layers_[layer];
727 }
728 
729 inline Frame& FramePyramid::layer(const unsigned int layer)
730 {
731  ocean_assert(layer < layers_.size());
732  return layers_[layer];
733 }
734 
735 inline const Frame& FramePyramid::finestLayer() const
736 {
737  ocean_assert(isValid());
738  return layers_.front();
739 }
740 
742 {
743  ocean_assert(isValid());
744  return layers_.front();
745 }
746 
747 inline const Frame& FramePyramid::coarsestLayer() const
748 {
749  ocean_assert(isValid());
750 
751  return layers_.back();
752 }
753 
755 {
756  ocean_assert(isValid());
757 
758  return layers_.back();
759 }
760 
761 inline unsigned int FramePyramid::layers() const
762 {
763  return (unsigned int)layers_.size();
764 }
765 
766 inline unsigned int FramePyramid::width(const unsigned int layer) const
767 {
768  ocean_assert(layer < layers_.size());
769  return layers_[layer].width();
770 }
771 
772 inline unsigned int FramePyramid::height(const unsigned int layer) const
773 {
774  ocean_assert(layer < layers_.size());
775  return layers_[layer].height();
776 }
777 
778 inline unsigned int FramePyramid::finestWidth() const
779 {
780  ocean_assert(isValid());
781  return layers_.front().width();
782 }
783 
784 inline unsigned int FramePyramid::finestHeight() const
785 {
786  ocean_assert(isValid());
787  return layers_.front().height();
788 }
789 
790 inline unsigned int FramePyramid::coarsestWidth() const
791 {
792  ocean_assert(isValid());
793 
794  return layers_.back().width();
795 }
796 
797 inline unsigned int FramePyramid::coarsestHeight() const
798 {
799  ocean_assert(isValid());
800 
801  return layers_.back().height();
802 }
803 
805 {
806  ocean_assert(isValid());
807 
808  return 1u << (unsigned int)((layers_.size() - 1));
809 }
810 
811 inline const FrameType& FramePyramid::frameType() const
812 {
813  ocean_assert(isValid());
814  return layers_.front().frameType();
815 }
816 
817 inline bool FramePyramid::replace8BitPerChannel11(const Frame& frame, const unsigned int layers, const bool copyFirstLayer, Worker* worker)
818 {
819  ocean_assert(frame.isValid() && frame.numberPlanes() == 1u && frame.dataType() == FrameType::DT_UNSIGNED_INTEGER_8);
820 
821  if (frame.numberPlanes() == 1u && frame.dataType() == FrameType::DT_UNSIGNED_INTEGER_8)
822  {
823  return replace8BitPerChannel11(frame.constdata<uint8_t>(), frame.width(), frame.height(), frame.channels(), frame.pixelOrigin(), layers, frame.paddingElements(), copyFirstLayer, worker, frame.pixelFormat(), frame.timestamp());
824  }
825 
826  return false;
827 }
828 
829 inline bool FramePyramid::replace(const FrameType& frameType, const bool forceOwner, const unsigned int layers)
830 {
831  return replace(frameType, true /*reserveFirstLayerMemory*/, forceOwner, layers);
832 }
833 
834 constexpr unsigned int FramePyramid::sizeFactor(const unsigned int layer)
835 {
836  ocean_assert(layer <= 31u);
837  if (layer > 31u)
838  {
839  return 0u;
840  }
841 
842  return 1u << layer;
843 }
844 
845 inline void FramePyramid::clear()
846 {
847  layers_.clear();
848  memory_.free();
849 }
850 
851 inline const Frame& FramePyramid::operator[](const unsigned int layer) const
852 {
853  ocean_assert(layer < layers_.size());
854  return layers_[layer];
855 }
856 
857 inline Frame& FramePyramid::operator[](const unsigned int layer)
858 {
859  ocean_assert(layer < layers_.size());
860  return layers_[layer];
861 }
862 
863 inline bool FramePyramid::isValid() const
864 {
865  return !layers_.empty();
866 }
867 
868 inline const Memory& FramePyramid::memory() const
869 {
870  return memory_;
871 }
872 
873 inline FramePyramid::operator bool() const
874 {
875  return isValid();
876 }
877 
878 }
879 
880 }
881 
882 #endif // META_OCEAN_CV_FRAME_PYRAMID_H
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.
FramePyramid & operator=(FramePyramid &&right) noexcept
Move operator.
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 ...
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
FramePyramid & operator=(const FramePyramid &)=delete
Disabled assign operator Use a constructor or the move operator instead.
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.
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:1792
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:4168
bool isValid() const
Returns whether this frame is valid.
Definition: Frame.h:4448
const Timestamp & timestamp() const
Returns the timestamp of this frame.
Definition: Frame.h:4138
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:4042
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
@ FORMAT_UNDEFINED
Undefined pixel format.
Definition: Frame.h:187
unsigned int width() const
Returns the width of the frame format in pixel.
Definition: Frame.h:3143
PixelOrigin pixelOrigin() const
Returns the pixel origin of the frame.
Definition: Frame.h:3188
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition: Frame.h:3183
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition: Frame.h:3153
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:3148
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition: Frame.h:3173
DataType dataType() const
Returns the data type of the pixel format of this frame.
Definition: Frame.h:3163
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:1755
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15