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