Ocean
Frame.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_BASE_FRAME_H
9 #define META_OCEAN_BASE_FRAME_H
10 
11 #include "ocean/base/Base.h"
12 #include "ocean/base/DataType.h"
13 #include "ocean/base/ObjectRef.h"
15 #include "ocean/base/Timestamp.h"
16 
17 #include <type_traits>
18 
19 namespace Ocean
20 {
21 
22 /**
23  * Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
24  * The frame dimension of a frame specifies the number of pixels in horizontal (width) and vertical (height) direction.<br>
25  * The pixel format specifies which kind of image information is stored.<br>
26  * The pixel origin defines whether the image data starts at the top left corner or at the bottom left corner.<br>
27  * @ingroup base
28  */
29 class OCEAN_BASE_EXPORT FrameType
30 {
31  public:
32 
33  /**
34  * Definition of individual channel data type.
35  */
36  enum DataType : uint8_t
37  {
38  /// Undefined data type.
39  DT_UNDEFINED = 0u,
40  /// Unsigned 8 bit integer data type (uint8_t).
42  /// Signed 8 bit integer data type (int8_t).
44  /// Unsigned 16 bit integer data type (uint16_t).
46  /// Signed 16 bit integer data type (int16_t).
48  /// Unsigned 32 bit integer data type (uint32_t).
50  /// Signed 232 bit integer data type (int32_t).
52  /// Unsigned 64 bit integer data type (uint64_t).
54  /// Signed 64 bit integer data type (int64_t).
56  /// Signed 16 bit float data type.
58  /// Signed 32 bit float data type (float).
60  /// Signed 64 bit float data type (double).
62  /// The helper data type which can be used to identify the last defined data type, DT_END is exclusive.
63  DT_END
64  };
65 
66  /**
67  * Definition of a vector holding data types.
68  */
69  using DataTypes = std::vector<DataType>;
70 
71  protected:
72 
73  /// The number of bits the channel value is shifted within the PixelFormat value.
74  static constexpr uint32_t pixelFormatBitOffsetChannels = 16u;
75 
76  /// The number of bits the data type value is shifted within the PixelFormat value.
77  static constexpr uint32_t pixelFormatBitOffsetDatatype = pixelFormatBitOffsetChannels + 8u;
78 
79  /// The number of bits the planes value is shifted within the PixelFormat value.
80  static constexpr uint32_t pixelFormatBitOffsetPlanes = pixelFormatBitOffsetDatatype + 8u;
81 
82  /// The number of bits the width-multiple value is shifted within the PixelFormat value.
83  static constexpr uint32_t pixelFormatBitOffsetWidthMultiple = pixelFormatBitOffsetPlanes + 8u;
84 
85  /// The number of bits the height-multiple value is shifted within the PixelFormat value.
86  static constexpr uint32_t pixelFormatBitOffsetHeightMultiple = pixelFormatBitOffsetWidthMultiple + 8u;
87 
88  /**
89  * This class implements a helper class allowing to create generic pixel formats.
90  * @tparam tDataType The data type of the generic pixel format
91  * @tparam tChannels The number of channels of the pixel format
92  * @tparam tPlanes The number of planes of the pixel format, a plane is a joined memory block
93  * @tparam tWidthMultiple The number of pixels the width of a frame must be a multiple of
94  * @tparam tHeightMultiple The number of pixels the height of a frame must be a multiple of
95  */
96  template <DataType tDataType, uint32_t tChannels, uint32_t tPlanes, uint32_t tWidthMultiple, uint32_t tHeightMultiple>
98  {
99  public:
100 
101  /// The value of the generic pixel format.
102  static constexpr uint64_t value = (uint64_t(tHeightMultiple) << pixelFormatBitOffsetHeightMultiple) | (uint64_t(tWidthMultiple) << pixelFormatBitOffsetWidthMultiple) | (uint64_t(tPlanes) << pixelFormatBitOffsetPlanes) |(uint64_t(tDataType) << pixelFormatBitOffsetDatatype) | (uint64_t(tChannels) << pixelFormatBitOffsetChannels);
103  };
104 
105  /**
106  * Definition of a protected helper enum that simplifies to read the definition of a predefined pixel format.
107  */
108  enum ChannelsValue : uint32_t
109  {
110  /// An invalid channel number, used for non-generic pixel formats.
111  CV_CHANNELS_UNDEFINED = 0u,
112  /// One channel.
113  CV_CHANNELS_1 = 1u,
114  /// Two channels.
115  CV_CHANNELS_2 = 2u,
116  /// Three channels.
117  CV_CHANNELS_3 = 3u,
118  /// Four channels.
119  CV_CHANNELS_4 = 4u
120  };
121 
122  /**
123  * Definition of a protected helper enum that simplifies to read the definition of a predefined pixel format.
124  */
125  enum PlanesValue : uint32_t
126  {
127  /// One plane.
128  PV_PLANES_1 = 1u,
129  /// Two planes.
130  PV_PLANES_2 = 2u,
131  /// Three planes.
132  PV_PLANES_3 = 3u,
133  /// Four planes.
134  PV_PLANES_4 = 4u
135  };
136 
137  /**
138  * Definition of a protected helper enum that simplifies to read the definition of a predefined pixel format.
139  */
140  enum MultipleValue : uint32_t
141  {
142  /// The size can have any value (as the value must be a multiple of 1).
143  MV_MULTIPLE_1 = 1u,
144  /// The size must have a multiple of 2.
145  MV_MULTIPLE_2 = 2u,
146  /// The size must have a multiple of 3.
147  MV_MULTIPLE_3 = 3u,
148  /// The size must have a multiple of 4.
149  MV_MULTIPLE_4 = 4u
150  };
151 
152  public:
153 
154  /**
155  * Definition of all pixel formats available in the Ocean framework.
156  * Several common pixel formats are predefined specifying a unique representation of the image information of a frame.<br>
157  * Further, generic pixel formats can be defined. Generic formats can have up to 31 zipped data channels and can be composed of any kind of data type.<br>
158  * The value of a pixel format can be separated into individual parts.<br>
159  * The lower two bytes can be used for predefined pixel formats.<br>
160  * The third byte define the number of data channels of all generic zipped pixel formats.<br>
161  * The fourth byte define the data type.<br>
162  * The fifth byte holds the number of planes.<br>
163  * The sixth byte holds the number of pixels the width of a frame must be a multiple of.<br>
164  * The seventh byte holds the number of pixels the height of a frame must be a multiple of:<br>
165  * <pre>
166  * Byte: | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
167  * | unused | height-multiple | width-multiple | planes | data type | channel number | predefined pixel format |
168  * </pre>
169  * A generic zipped pixel format may have the same data layout compared to a predefined pixel format while the actual value of the pixel format may be different.
170  *
171  * The naming convention of predefined pixel formats is:<br>
172  * Left to right is equivalent from first to last bytes in memory.<br>
173  * For example RGB24 stored the red color value in the first byte and the blue color value in the last byte.<br>
174  * BGRA32 stores the blue color value in the first byte, green in the second bytes, red in the third byte and the alpha value in the last byte.
175  *
176  * The following code can be used to define a generic pixel format, in case the predefined pixel formats in 'PixelFormat' do not have the desired format:
177  * @code
178  * // define a used-defined pixel format with three double values per channel
179  * const FrameType::PixelFormat newPixelFormat = FrameType::genericPixelFormat<double, 3u>();
180  * @endcode
181  */
182  enum PixelFormat : uint64_t
183  {
184  /**
185  * Undefined pixel format.
186  */
187  FORMAT_UNDEFINED = 0ull,
188 
189  /**
190  * Pixel format with byte order ABGR and 32 bits per pixel.
191  * Here is the memory layout:
192  * <pre>
193  * Pixel: 0 1
194  * Byte: 0 1 2 3 4
195  * Bit: 0123456789ABCDEF0123456789ABCDEF 01234567
196  * Channel: 0 1 2 3 0
197  * Color: AAAAAAAABBBBBBBBGGGGGGGGRRRRRRRR AAAAAAAA ........
198  * </pre>
199  */
201 
202  /**
203  * Pixel format with byte order ARGB and 32 bits per pixel.
204  * Here is the memory layout:
205  * <pre>
206  * Pixel: 0 1
207  * Byte: 0 1 2 3 4
208  * Bit: 0123456789ABCDEF0123456789ABCDEF 01234567
209  * Channel: 0 1 2 3 0
210  * Color: AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB AAAAAAAA ........
211  * </pre>
212  */
214 
215  /**
216  * Pixel format with byte order BGR and 24 bits per pixel.
217  * Here is the memory layout:
218  * <pre>
219  * Pixel: 0 1 2
220  * Byte: 0 1 2 3 4 5 6
221  * Bit: 0123456789ABCDEF01234567 89ABCDEF0123456789ABCDEF 01234567
222  * Channel: 0 1 2 0 1 2 0
223  * Color: BBBBBBBBGGGGGGGGRRRRRRRR BBBBBBBBGGGGGGGGRRRRRRRR BBBBBBBB ........
224  * </pre>
225  */
227 
228  /**
229  * Pixel format with byte order BGR and 24 bits per pixel and 8 unused bits.
230  * Here is the memory layout:
231  * <pre>
232  * Pixel: 0 1
233  * Byte: 0 1 2 3 4
234  * Bit: 0123456789ABCDEF0123456789ABCDEF 01234567
235  * Channel: 0 1 2 0
236  * Color: BBBBBBBBGGGGGGGGRRRRRRRR BBBBBBBB ........
237  * </pre>
238  */
240 
241  /**
242  * Pixel format with entirely 16 bits per pixel, 12 bits for BGR and 4 unused bits.
243  */
244  FORMAT_BGR4444 = 5ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
245 
246  /**
247  * Pixel format with entirely 16 bits per pixel, 15 bits for BGR and 1 unused bit.
248  */
249  FORMAT_BGR5551 = 6ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
250 
251  /**
252  * Pixel format with 16 bits per pixel, 5 bits for blue, 6 bits for green and 5 bits for red.
253  * Here is the memory layout:
254  * <pre>
255  * Pixel: 0 1 2
256  * Byte: 0 1 2 3 4
257  * Bit: 0123456789ABCDEF 0123456789ABCDEF 01234
258  * Channel: 0 1 2 0 1 2 0
259  * Color: BBBBBGGGGGGRRRRR BBBBBGGGGGGRRRRR BBBBB ........
260  * </pre>
261  * This pixel format is equivalent to the following pixel formats on Android (note the inverse order or RGB):<br>
262  * Native code: ANDROID_BITMAP_FORMAT_RGB_565, Java: Bitmap.Config.RGB_565.
263  */
264  FORMAT_BGR565 = 7ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
265 
266  /**
267  * Pixel format with byte order BGRA and 32 bits per pixel.
268  * Here is the memory layout:
269  * <pre>
270  * Pixel: 0 1
271  * Byte: 0 1 2 3 4
272  * Bit: 0123456789ABCDEF0123456789ABCDEF 01234567
273  * Channel: 0 1 2 3 0
274  * Color: BBBBBBBBGGGGGGGGRRRRRRRRAAAAAAAA BBBBBBBB ........
275  * </pre>
276  */
278 
279  /**
280  * Pixel format with entirely 16 bits per pixel, 4 bits for each channel.
281  */
282  FORMAT_BGRA4444 = 9ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
283 
284  /**
285  * The packed pixel format representing a Bayer mosaic pattern for images with blue, green, and red channels with order BGGR for a 2x2 pixel block.
286  * The format has the byte order B G for the upper two pixels, and G R for the lower two pixels in a 2x2 pixel block.<br>
287  * Images with this pixel format have a resolution which is a multiple of 4x2 pixels.<br>
288  * The Pixel format stores 10 bits per pixel (and channel), packed so that four consecutive pixels fit into five bytes.<br>
289  * The higher 8 bits of each pixel are stored in the first four bytes, the lower 2 bits of all four pixels are stored in the fifth byte.<br>
290  * Here is the memory layout:
291  * <pre>
292  * Pixel: 0 1 2 3 0 1 2 3 4 5 6 7 4 5 6 7
293  * Byte: 0 1 2 3 4 5 6 7 8 9
294  * Bit: 01234567 89ABCDEF 01234567 89ABCDEF 01234567 01234567 89ABCDEF 01234567 89ABCDEF 01234567
295  * Channel: row 0: 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
296  * Channel: row 1: 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2
297  * Color: row 1: BBBBBBBB GGGGGGGG BBBBBBBB GGGGGGGG BBGGBBGG BBBBBBBB GGGGGGGG BBBBBBBB GGGGGGGG BBGGBBGG ........
298  * Color: row 0: GGGGGGGG RRRRRRRR GGGGGGGG RRRRRRRR GGRRGGRR GGGGGGGG RRRRRRRR GGGGGGGG RRRRRRRR GGRRGGRR ........
299  * Color: row 2: BBBBBBBB GGGGGGGG ........
300  * </pre>
301  */
302  FORMAT_BGGR10_PACKED = 10ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_4, MV_MULTIPLE_2>::value,
303 
304  /**
305  * Pixel format with byte order RGB and 24 bits per pixel.
306  * Here is the memory layout:
307  * <pre>
308  * Pixel: 0 1 2
309  * Byte: 0 1 2 3 4 5 6
310  * Bit: 0123456789ABCDEF01234567 89ABCDEF0123456789ABCDEF 01234567
311  * Channel: 0 1 2 0 1 2 0
312  * Color: RRRRRRRRGGGGGGGGBBBBBBBB RRRRRRRRGGGGGGGGBBBBBBBB RRRRRRRR ........
313  * </pre>
314  */
316 
317  /**
318  * Pixel format with byte order RGB and 24 bits per pixel and 8 unused bits.
319  * Here is the memory layout:
320  * <pre>
321  * Pixel: 0 1
322  * Byte: 0 1 2 3 4
323  * Bit: 0123456789ABCDEF0123456789ABCDEF 01234567
324  * Channel: 0 1 2 0
325  * Color: RRRRRRRRGGGGGGGGBBBBBBBB RRRRRRRR ........
326  * </pre>
327  */
329 
330  /**
331  * Pixel format with entirely 16 bits per pixel, 12 bits for RGB and 4 unused bits.
332  * Here is the memory layout:
333  * <pre>
334  * Pixel: 0 1 2
335  * Byte: 0 1 2 3 4
336  * Bit: 0123456789ABCDEF 0123456789ABCDEF 01234
337  * Channel: 0 1 2 0 1 2 0
338  * Color: RRRRGGGGBBBB RRRRGGGGBBBB RRRRR ........
339  * </pre>
340  */
341  FORMAT_RGB4444 = 13ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
342 
343  /**
344  * Pixel format with entirely 16 bits per pixel, 15 bits for RGB and 1 unused bit.
345  * Here is the memory layout:
346  * <pre>
347  * Pixel: 0 1 2
348  * Byte: 0 1 2 3 4
349  * Bit: 0123456789ABCDEF 0123456789ABCDEF 01234
350  * Channel: 0 1 2 0 1 2 0
351  * Color: RRRRRGGGGGBBBBB RRRRRGGGGGBBBBB RRRRR ........
352  * </pre>
353  */
354  FORMAT_RGB5551 = 14ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
355 
356  /**
357  * Pixel format with entirely 16 bits per pixel, 5 bits for red, 6 bits for green and 5 bits for blue.
358  * Here is the memory layout:
359  * <pre>
360  * Pixel: 0 1 2
361  * Byte: 0 1 2 3 4
362  * Bit: 0123456789ABCDEF 0123456789ABCDEF 01234
363  * Channel: 0 1 2 0 1 2 0
364  * Color: RRRRRGGGGGGBBBBB RRRRRGGGGGGBBBBB RRRRR ........
365  * </pre>
366  */
367  FORMAT_RGB565 = 15ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
368 
369  /**
370  * Pixel format with byte order RGBA and 32 bits per pixel.
371  * Here is the memory layout:
372  * <pre>
373  * Pixel: 0 1
374  * Byte: 0 1 2 3 4
375  * Bit: 0123456789ABCDEF0123456789ABCDEF 01234567
376  * Channel: 0 1 2 3 0
377  * Color: RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA RRRRRRRR ........
378  * </pre>
379  * This pixel format is equivalent to the following pixel formats on Android (note the inverse order of ARGB):<br>
380  * Native code: ANDROID_BITMAP_FORMAT_RGBA_8888, Java: Bitmap.Config.ARGB_8888.
381  */
383 
384  /**
385  * Pixel format with entirely 16 bits per pixel, 4 bits for each channel.
386  * Here is the memory layout:
387  * <pre>
388  * Pixel: 0 1 2
389  * Byte: 0 1 2 3 4
390  * Bit: 0123456789ABCDEF 0123456789ABCDEF 01234
391  * Channel: 0 1 2 0 1 2 0
392  * Color: RRRRGGGGBBBBAAAA RRRRGGGGBBBBAAAA RRRRR ........
393  * </pre>
394  */
395  FORMAT_RGBA4444 = 17ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
396 
397  /**
398  * Pixel format with byte order RGBT and 24 bits for the RGB channels and 8 bits for an arbitrary texture channel.
399  * Here is the memory layout:
400  * <pre>
401  * Pixel: 0 1
402  * Byte: 0 1 2 3 4
403  * Bit: 0123456789ABCDEF0123456789ABCDEF 01234567
404  * Channel: 0 1 2 3 0
405  * Color: RRRRRRRRGGGGGGGGBBBBBBBBTTTTTTTT RRRRRRRR ........
406  * </pre>
407  */
409 
410  /**
411  * The packed pixel format representing a Bayer mosaic pattern for images with red, green, and blue channels with order RGGB for a 2x2 pixel block.
412  * The format has the byte order R G for the upper two pixels, and G B for the lower two pixels in a 2x2 pixel block.<br>
413  * Images with this pixel format have a resolution which is a multiple of 4x2 pixels.<br>
414  * The Pixel format stores 10 bits per pixel (and channel), packed so that four consecutive pixels fit into five bytes.<br>
415  * The higher 8 bits of each pixel are stored in the first four bytes, the lower 2 bits of all four pixels are stored in the fifth byte.<br>
416  * Here is the memory layout:
417  * <pre>
418  * Pixel: 0 1 2 3 0 1 2 3 4 5 6 7 4 5 6 7
419  * Byte: 0 1 2 3 4 5 6 7 8 9
420  * Bit: 01234567 89ABCDEF 01234567 89ABCDEF 01234567 01234567 89ABCDEF 01234567 89ABCDEF 01234567
421  * Channel: row 0: 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
422  * Channel: row 1: 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2
423  * Color: row 0: RRRRRRRR GGGGGGGG RRRRRRRR GGGGGGGG RRGGRRGG RRRRRRRR GGGGGGGG RRRRRRRR GGGGGGGG RRGGRRGG ........
424  * Color: row 1: GGGGGGGG BBBBBBBB GGGGGGGG BBBBBBBB GGBBGGBB GGGGGGGG BBBBBBBB GGGGGGGG BBBBBBBB GGBBGGBB ........
425  * Color: row 2: RRRRRRRR GGGGGGGG ........
426  * </pre>
427  */
428  FORMAT_RGGB10_PACKED = 19ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_4, MV_MULTIPLE_2>::value,
429 
430  /**
431  * Pixel format with 8 bits Y frame as individual block, followed by 8 bits 2x2 sub-sampled U frame and 8 bits 2x2 sub-sampled V frame, both as individual blocks, resulting in 12 bits per pixel.
432  * Sometimes also denoted as 'I420'.
433  *
434  * The memory layout of a Y_U_V12 image looks like this:
435  * <pre>
436  * y-plane: u-plane: v-plane:
437  * --------- ----- -----
438  * | Y Y Y Y | | U U | | V V |
439  * | Y Y Y Y | | U U | | V V |
440  * | Y Y Y Y | ----- -----
441  * | Y Y Y Y |
442  * ---------
443  * </pre>
444  * Width and height must be even (multiple of two).
445  */
446  FORMAT_Y_U_V12 = 20ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_3, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
447 
448  /**
449  * Pixel format with byte order YUV and 24 bits per pixel.
450  * Here is the memory layout:
451  * <pre>
452  * Pixel: 0 1 2
453  * Byte: 0 1 2 3 4 5 6
454  * Bit: 0123456789ABCDEF01234567 89ABCDEF0123456789ABCDEF 01234567
455  * Channel: 0 1 2 0 1 2 0
456  * Color: YYYYYYYYUUUUUUUUVVVVVVVV YYYYYYYYUUUUUUUUVVVVVVVV YYYYYYYY ........
457  * </pre>
458  */
460 
461  /**
462  * Pixel format with byte order YUVA and 32 bits per pixel.
463  * Here is the memory layout:
464  * <pre>
465  * Pixel: 0 1
466  * Byte: 0 1 2 3 4
467  * Bit: 0123456789ABCDEF0123456789ABCDEF 01234567
468  * Channel: 0 1 2 3 0
469  * Color: YYYYYYYYUUUUUUUUVVVVVVVVAAAAAAAA YYYYYYYY ........
470  * </pre>
471  */
473 
474  /**
475  * Pixel format with byte order YUVA and 24 bits for the YUV channels and 8 bit for an arbitrary texture channel.
476  */
478 
479  /**
480  * Pixel format with 8 bits Y frame as individual block, followed by 8 bits 2x2 sub-sampled V frame and 8 bits 2x2 sub-sampled U frame, both as individual blocks, resulting in 12 bits per pixel.
481  * Sometimes also denoted as 'YV12'.
482  *
483  * The memory layout of a Y_V_U12 image looks like this:
484  * <pre>
485  * y-plane: v-plane: u-plane:
486  * --------- ----- -----
487  * | Y Y Y Y | | V V | | U U |
488  * | Y Y Y Y | | V V | | U U |
489  * | Y Y Y Y | ----- -----
490  * | Y Y Y Y |
491  * ---------
492  * </pre>
493  * Width and height must be even (multiple of two).
494  */
495  FORMAT_Y_V_U12 = 24ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_3, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
496 
497  /**
498  * Pixel format with byte order YVU and 24-bits per pixel.
499  * Here is the memory layout:
500  * <pre>
501  * Pixel: 0 1 2
502  * Byte: 0 1 2 3 4 5 6
503  * Bit: 0123456789ABCDEF01234567 89ABCDEF0123456789ABCDEF 01234567
504  * Channel: 0 1 2 0 1 2 0
505  * Color: YYYYYYYYVVVVVVVVUUUUUUUU YYYYYYYYVVVVVVVVUUUUUUUU YYYYYYYY ........
506  * </pre>
507  */
509 
510  /**
511  * This pixel format is deprecated and is currently an alias for FORMAT_Y_UV12_LIMITED_RANGE.
512  * Pixel format with 8 bits Y frame as entire block, followed by 8 bits 2x2 sub-sampled U and V zipped (interleaved) pixels, resulting in 12 bits per pixel.
513  * Sometimes also denoted as 'NV12'.
514  *
515  * The memory layout of a Y_UV12 image looks like this:
516  * <pre>
517  * y-plane: u/v-plane:
518  * --------- ---------
519  * | Y Y Y Y | | U V U V |
520  * | Y Y Y Y | | U V U V |
521  * | Y Y Y Y | ---------
522  * | Y Y Y Y |
523  * ---------
524  * </pre>
525  * Width and height must be even (multiple of two).
526  */
527  FORMAT_Y_UV12 = 26ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_2, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
528 
529  /**
530  * Pixel format with 8 bits Y frame as entire block, followed by 8 bits 2x2 sub-sampled V and U zipped (interleaved) pixels, resulting in 12 bits per pixel.
531  * Sometimes also denoted as 'NV21'.
532  *
533  * The memory layout of a Y_VU12 image looks like this:
534  * <pre>
535  * y-plane: v/u-plane:
536  * --------- ---------
537  * | Y Y Y Y | | V U V U |
538  * | Y Y Y Y | | V U V U |
539  * | Y Y Y Y | ---------
540  * | Y Y Y Y |
541  * ---------
542  * </pre>
543  * Width and height must be even (multiple of two).
544  */
545  FORMAT_Y_VU12 = 27ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_2, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
546 
547  /**
548  * Pixel format with 8 bit Y pixel values zipped (interleaved) with 8 bits 2x1 (horizontal) sub-sampled U and V pixel values respectively, resulting in 16 bits per pixel.
549  * Sometimes also denoted as 'YUY2'.
550  *
551  * The memory layout of a YUYV16 image looks like this:
552  * <pre>
553  * y/u/v-plane:
554  * -----------------
555  * | Y U Y V Y U Y V |
556  * | Y U Y V Y U Y V |
557  * | Y U Y V Y U Y V |
558  * | Y U Y V Y U Y V |
559  * -----------------
560  * </pre>
561  * The width must be even (multiple of two).
562  */
563  FORMAT_YUYV16 = 28ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_2, MV_MULTIPLE_1>::value,
564 
565  /**
566  * Pixel format with 8 bit Y pixel values zipped (interleaved) with 8 bits 2x1 (horizontal) sub-sampled U and V pixel values respectively, resulting in 16 bits per pixel.
567  * Sometimes also denoted as 'UYVY'.
568  *
569  * The memory layout of a UYVY16 image looks like this:
570  * <pre>
571  * y/u/v-plane:
572  * -----------------
573  * | U Y V Y U Y V Y |
574  * | U Y V Y U Y V Y |
575  * | U Y V Y U Y V Y |
576  * | U Y V Y U Y V Y |
577  * -----------------
578  * </pre>
579  * The width must be even (multiple of two).
580  */
581  FORMAT_UYVY16 = 29ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_2, MV_MULTIPLE_1>::value,
582 
583  /**
584  * Pixel format for grayscale images with byte order Y and 8 bits per pixel.
585  * Here is the memory layout:
586  * <pre>
587  * Pixel: 0 1
588  * Byte: 0 1
589  * Bit: 01234567 89ABCDEF
590  * Channel: 0 0
591  * Color: YYYYYYYY YYYYYYYY ........
592  * </pre>
593  */
595 
596  /**
597  * Pixel format with byte order Y and 10 bits per pixel, the upper 6 bits are unused.
598  * Here is the memory layout:
599  * <pre>
600  * Pixel: 0 1
601  * Byte: 0 1 2 3
602  * Bit: 01234567 89ABCDEF 01234567 89ABCDEF
603  * Channel: 0 0
604  * Color: YYYYYYYY YY YYYYYYYY YY ........
605  * </pre>
606  */
608 
609  /**
610  * Pixel format with byte order Y and 10 bits per pixel, packed so that four consecutive pixels fit into five bytes.
611  * The higher 8 bits of each pixel are stored in the first four bytes, the lower 2 bits of all four pixels are stored in the fifth byte.
612  * Here is the memory layout:
613  * <pre>
614  * Pixel: 0 1 2 3 0 1 2 3 4 5 6 7 4 5 6 7
615  * Byte: 0 1 2 3 4 5 6 7 8 9
616  * Bit: 01234567 89ABCDEF 01234567 89ABCDEF 01234567 01234567 89ABCDEF 01234567 89ABCDEF 01234567
617  * Channel: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
618  * Color: YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY ........
619  * </pre>
620  */
621  FORMAT_Y10_PACKED = 32ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_1, MV_MULTIPLE_4, MV_MULTIPLE_1>::value,
622 
623  /**
624  * Pixel format with 16 bits Y frame.
625  * Here is the memory layout:
626  * <pre>
627  * Pixel: 0 1 2
628  * Byte: 0 1 2 3 4
629  * Bit: 0123456789ABCDEF 0123456789ABCDEF 01
630  * Channel: 0 0
631  * Color: YYYYYYYYYYYYYYYY YYYYYYYYYYYYYYYY YY ........
632  * </pre>
633  */
635 
636  /**
637  * Pixel format with 32 bits Y frame.
638  */
640 
641  /**
642  * Pixel format with 64 bits Y frame.
643  */
645 
646  /**
647  * Pixel format with byte order YA and 16 bits per pixel.
648  */
650 
651  /**
652  * Pixel format with byte order RGB and 48 bits per pixel, with 16 bit per component.
653  * Here is the memory layout:
654  * <pre>
655  * Pixel: 0 1
656  * Byte: 0 1 2 3 4 5 6 7
657  * Bit: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF 0123456789ABCDEF
658  * Channel: 0 1 2 0
659  * Color: RRRRRRRRRRRRRRRRGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBB RRRRRRRRRRRRRRRR ........
660  * </pre>
661  */
663 
664  /**
665  * Pixel format with byte order RGBA and 64 bits per pixel, with 16 bit per component.
666  * Here is the memory layout:
667  * <pre>
668  * Pixel: 0 1
669  * Byte: 0 1 2 3 4 5 6 7 8 9
670  * Bit: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF 0123456789ABCDEF
671  * Channel: 0 1 2 3 0
672  * Color: RRRRRRRRRRRRRRRRGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAA RRRRRRRRRRRRRRRR ........
673  * </pre>
674  */
676 
677  /**
678  * This pixel format is deprecated and is currently an alias for FORMAT_Y_U_V24_LIMITED_RANGE.
679  * Pixel format with 8 bits Y frame as individual block, followed by 8 bits U frame as individual block, followed by a V frame as individual block, resulting in 24 bits per pixel.
680  * Sometimes also denoted as 'I444'.
681  *
682  * The memory layout of a Y_U_V24 image looks like this:
683  * <pre>
684  * y-plane: u-plane: v-plane:
685  * --------- --------- ---------
686  * | Y Y Y Y | | U U U U | | V V V V |
687  * | Y Y Y Y | | U U U U | | V V V V |
688  * | Y Y Y Y | | U U U U | | V V V V |
689  * | Y Y Y Y | | U U U U | | V V V V |
690  * --------- --------- ---------
691  * </pre>
692  */
693  FORMAT_Y_U_V24 = 39ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_3, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
694 
695  /**
696  * Pixel format with 8 bits Y frame as individual block, followed by 8 bits U frame as individual block, followed by a V frame as individual block, resulting in 24 bits per pixel.
697  * Sometimes also denoted as 'I444'.
698  *
699  * The pixel format is using a limited value range for the individual channels:
700  * <pre>
701  * Y channel: [16, 235]
702  * U channel: [16, 240]
703  * V channel: [16, 240]
704  * </pre>
705  *
706  * The memory layout of a Y_U_V24 image looks like this:
707  * <pre>
708  * y-plane: u-plane: v-plane:
709  * --------- --------- ---------
710  * | Y Y Y Y | | U U U U | | V V V V |
711  * | Y Y Y Y | | U U U U | | V V V V |
712  * | Y Y Y Y | | U U U U | | V V V V |
713  * | Y Y Y Y | | U U U U | | V V V V |
714  * --------- --------- ---------
715  * </pre>
716  * @see FORMAT_Y_U_V24_FULL_RANGE.
717  */
718  FORMAT_Y_U_V24_LIMITED_RANGE = FORMAT_Y_U_V24,
719 
720  /**
721  * Pixel format with 8 bits Y frame as individual block, followed by 8 bits U frame as individual block, followed by a V frame as individual block, resulting in 24 bits per pixel.
722  * Sometimes also denoted as 'I444'.
723  *
724  * The pixel format is using a full value range for all three channels:
725  * <pre>
726  * Y channel: [0, 255]
727  * U channel: [0, 255]
728  * V channel: [0, 255]
729  * </pre>
730  *
731  * The memory layout of a Y_U_V24 image looks like this:
732  * <pre>
733  * y-plane: u-plane: v-plane:
734  * --------- --------- ---------
735  * | Y Y Y Y | | U U U U | | V V V V |
736  * | Y Y Y Y | | U U U U | | V V V V |
737  * | Y Y Y Y | | U U U U | | V V V V |
738  * | Y Y Y Y | | U U U U | | V V V V |
739  * --------- --------- ---------
740  * </pre>
741  * @see FORMAT_Y_U_V24_LIMITED_RANGE.
742  */
743  FORMAT_Y_U_V24_FULL_RANGE = 40ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_3, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
744 
745  /**
746  * Pixel format for grayscale images with byte order Y and 8 bits per pixel (with limited range).
747  *
748  * The pixel format is using a limited value range:
749  * <pre>
750  * Y channel: [16, 235]
751  * </pre>
752  *
753  * Here is the memory layout:
754  * <pre>
755  * Pixel: 0 1
756  * Byte: 0 1
757  * Bit: 01234567 89ABCDEF
758  * Channel: 0 0
759  * Color: YYYYYYYY YYYYYYYY ........
760  * </pre>
761  * @see FORMAT_Y8_FULL_RANGE.
762  */
764 
765  /**
766  * Pixel format for grayscale images with byte order Y and 8 bits per pixel (with full range).
767  *
768  * The pixel format is using a full value range:
769  * <pre>
770  * Y channel: [0, 255]
771  * </pre>
772  *
773  * Here is the memory layout:
774  * <pre>
775  * Pixel: 0 1
776  * Byte: 0 1
777  * Bit: 01234567 89ABCDEF
778  * Channel: 0 0
779  * Color: YYYYYYYY YYYYYYYY ........
780  * </pre>
781  * @see FORMAT_Y8_LIMITED_RANGE.
782  */
783  FORMAT_Y8_FULL_RANGE = FORMAT_Y8,
784 
785  /**
786  * Pixel format with 8 bits Y frame as entire block, followed by 8 bits 2x2 sub-sampled U and V zipped (interleaved) pixels, resulting in 12 bits per pixel.
787  * Sometimes also denoted as 'NV12'.
788  *
789  * The pixel format is using a limited value range for all three channels:
790  * <pre>
791  * Y channel: [16, 235]
792  * U channel: [16, 240]
793  * V channel: [16, 240]
794  * </pre>
795  *
796  * The memory layout of a Y_UV12 image looks like this:
797  * <pre>
798  * y-plane: u/v-plane:
799  * --------- ---------
800  * | Y Y Y Y | | U V U V |
801  * | Y Y Y Y | | U V U V |
802  * | Y Y Y Y | ---------
803  * | Y Y Y Y |
804  * ---------
805  * </pre>
806  * @see FORMAT_Y_UV12_FULL_RANGE.
807  */
808  FORMAT_Y_UV12_LIMITED_RANGE = FORMAT_Y_UV12,
809 
810  /**
811  * Pixel format with 8 bits Y frame as entire block, followed by 8 bits 2x2 sub-sampled U and V zipped (interleaved) pixels, resulting in 12 bits per pixel.
812  * Sometimes also denoted as 'NV12'.
813  *
814  * The pixel format is using a full value range for all three channels:
815  * <pre>
816  * Y channel: [0, 255]
817  * U channel: [0, 255]
818  * V channel: [0, 255]
819  * </pre>
820  *
821  * The memory layout of a Y_UV12 image looks like this:
822  * <pre>
823  * y-plane: u/v-plane:
824  * --------- ---------
825  * | Y Y Y Y | | U V U V |
826  * | Y Y Y Y | | U V U V |
827  * | Y Y Y Y | ---------
828  * | Y Y Y Y |
829  * ---------
830  * </pre>
831  * @see FORMAT_Y_UV12_LIMITED_RANGE.
832  * Width and height must be even (multiple of two).
833  */
834  FORMAT_Y_UV12_FULL_RANGE = 42ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_2, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
835 
836  /**
837  * Pixel format with 8 bits Y frame as entire block, followed by 8 bits 2x2 sub-sampled V and U zipped (interleaved) pixels, resulting in 12 bits per pixel.
838  * Sometimes also denoted as 'NV21'.
839  *
840  * The pixel format is using a limited value range for all three channels:
841  * <pre>
842  * Y channel: [16, 235]
843  * V channel: [16, 240]
844  * U channel: [16, 240]
845  * </pre>
846  *
847  * The memory layout of a Y_VU12 image looks like this:
848  * <pre>
849  * y-plane: u/v-plane:
850  * --------- ---------
851  * | Y Y Y Y | | V U V U |
852  * | Y Y Y Y | | V U V U |
853  * | Y Y Y Y | ---------
854  * | Y Y Y Y |
855  * ---------
856  * </pre>
857  * @see FORMAT_Y_VU12_FULL_RANGE.
858  */
859  FORMAT_Y_VU12_LIMITED_RANGE = FORMAT_Y_VU12,
860 
861  /**
862  * Pixel format with 8 bits Y frame as entire block, followed by 8 bits 2x2 sub-sampled V and U zipped (interleaved) pixels, resulting in 12 bits per pixel.
863  * Sometimes also denoted as 'NV21'.
864  *
865  * The pixel format is using a full value range for all three channels:
866  * <pre>
867  * Y channel: [0, 255]
868  * V channel: [0, 255]
869  * U channel: [0, 255]
870  * </pre>
871  *
872  * The memory layout of a Y_VU12 image looks like this:
873  * <pre>
874  * y-plane: u/v-plane:
875  * --------- ---------
876  * | Y Y Y Y | | V U V U |
877  * | Y Y Y Y | | V U V U |
878  * | Y Y Y Y | ---------
879  * | Y Y Y Y |
880  * ---------
881  * </pre>
882  * @see FORMAT_Y_VU12_LIMITED_RANGE.
883  * Width and height must be even (multiple of two).
884  */
885  FORMAT_Y_VU12_FULL_RANGE = 43ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_2, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
886 
887  /**
888  * Pixel format with 8 bits Y frame as individual block, followed by 8 bits 2x2 sub-sampled U frame and 8 bits 2x2 sub-sampled V frame, both as individual blocks, resulting in 12 bits per pixel.
889  * Sometimes also denoted as 'I420'.
890  *
891  * The pixel format is using a limited value range for all three channels:
892  * <pre>
893  * Y channel: [16, 235]
894  * V channel: [16, 240]
895  * U channel: [16, 240]
896  * </pre>
897  *
898  * The memory layout of a Y_U_V12 image looks like this:
899  * <pre>
900  * y-plane: u-plane: v-plane:
901  * --------- ----- -----
902  * | Y Y Y Y | | U U | | V V |
903  * | Y Y Y Y | | U U | | V V |
904  * | Y Y Y Y | ----- -----
905  * | Y Y Y Y |
906  * ---------
907  * </pre>
908  * @see FORMAT_Y_U_V12_FULL_RANGE.
909  */
910  FORMAT_Y_U_V12_LIMITED_RANGE = FORMAT_Y_U_V12,
911 
912  /**
913  * Pixel format with 8 bits Y frame as individual block, followed by 8 bits 2x2 sub-sampled U frame and 8 bits 2x2 sub-sampled V frame, both as individual blocks, resulting in 12 bits per pixel.
914  * Sometimes also denoted as 'I420'.
915  *
916  * The pixel format is using a full value range for all three channels:
917  * <pre>
918  * Y channel: [0, 255]
919  * V channel: [0, 255]
920  * U channel: [0, 255]
921  * </pre>
922  *
923  * The memory layout of a Y_U_V12 image looks like this:
924  * <pre>
925  * y-plane: u-plane: v-plane:
926  * --------- ----- -----
927  * | Y Y Y Y | | U U | | V V |
928  * | Y Y Y Y | | U U | | V V |
929  * | Y Y Y Y | ----- -----
930  * | Y Y Y Y |
931  * ---------
932  * </pre>
933  * @see FORMAT_Y_U_V12_LIMITED_RANGE.
934  * Width and height must be even (multiple of two).
935  */
936  FORMAT_Y_U_V12_FULL_RANGE = 44ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_3, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
937 
938  /**
939  * Pixel format with 8 bits Y frame as individual block, followed by 8 bits 2x2 sub-sampled V frame and 8 bits 2x2 sub-sampled U frame, both as individual blocks, resulting in 12 bits per pixel.
940  * Sometimes also denoted as 'YV12'.
941  *
942  * The pixel format is using a limited value range for all three channels:
943  * <pre>
944  * Y channel: [16, 235]
945  * V channel: [16, 240]
946  * U channel: [16, 240]
947  * </pre>
948  *
949  * The memory layout of a Y_V_U12 image looks like this:
950  * <pre>
951  * y-plane: v-plane: u-plane:
952  * --------- ----- -----
953  * | Y Y Y Y | | V V | | U U |
954  * | Y Y Y Y | | V V | | U U |
955  * | Y Y Y Y | ----- -----
956  * | Y Y Y Y |
957  * ---------
958  * </pre>
959  * @see FORMAT_Y_V_U12_FULL_RANGE.
960  */
961  FORMAT_Y_V_U12_LIMITED_RANGE = FORMAT_Y_V_U12,
962 
963  /**
964  * Pixel format with 8 bits Y frame as individual block, followed by 8 bits 2x2 sub-sampled V frame and 8 bits 2x2 sub-sampled U frame, both as individual blocks, resulting in 12 bits per pixel.
965  * Sometimes also denoted as 'YV12'.
966  *
967  * The pixel format is using a full value range for all three channels:
968  * <pre>
969  * Y channel: [0, 255]
970  * V channel: [0, 255]
971  * U channel: [0, 255]
972  * </pre>
973  *
974  * The memory layout of a Y_V_U12 image looks like this:
975  * <pre>
976  * y-plane: v-plane: u-plane:
977  * --------- ----- -----
978  * | Y Y Y Y | | V V | | U U |
979  * | Y Y Y Y | | V V | | U U |
980  * | Y Y Y Y | ----- -----
981  * | Y Y Y Y |
982  * ---------
983  * </pre>
984  * @see FORMAT_Y_V_U12_LIMITED_RANGE.
985  * Width and height must be even (multiple of two).
986  */
987  FORMAT_Y_V_U12_FULL_RANGE = 45ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_3, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
988 
989  /**
990  * Pixel format for a frame with one channel and 32 bit floating point precision per element.
991  */
993 
994  /**
995  * Pixel format for a frame with one channel and 64 bit floating point precision per element.
996  */
998 
999  /**
1000  * Pixel format with 8 bits R frame as individual block, followed by 8 bits G frame as individual block, followed by a B frame as individual block, resulting in 24 bits per pixel.
1001  *
1002  * The memory layout of a R_G_B24 image looks like this:
1003  * <pre>
1004  * r-plane: g-plane: b-plane:
1005  * --------- --------- ---------
1006  * | R R R R | | G G G G | | B B B B |
1007  * | R R R R | | G G G G | | B B B B |
1008  * | R R R R | | G G G G | | B B B B |
1009  * | R R R R | | G G G G | | B B B B |
1010  * --------- --------- ---------
1011  * </pre>
1012  */
1013  FORMAT_R_G_B24 = 48ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_3, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
1014 
1015  /**
1016  * Pixel format with 8 bits B frame as individual block, followed by 8 bits G frame as individual block, followed by a R frame as individual block, resulting in 24 bits per pixel.
1017  *
1018  * The memory layout of a B_G_R24 image looks like this:
1019  * <pre>
1020  * b-plane: g-plane: r-plane:
1021  * --------- --------- ---------
1022  * | B B B B | | G G G G | | R R R R |
1023  * | B B B B | | G G G G | | R R R R |
1024  * | B B B B | | G G G G | | R R R R |
1025  * | B B B B | | G G G G | | R R R R |
1026  * --------- --------- ---------
1027  * </pre>
1028  */
1029  FORMAT_B_G_R24 = 49ull | GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED /* as non-generic */, PV_PLANES_3, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
1030 
1031  /**
1032  * The helper pixel format which can be used to identify the last defined pixel format, FORMAT_END is exclusive.
1033  */
1034  FORMAT_END = 50ull
1035  };
1036 
1037  /**
1038  * Definition of a vector holding pixel formats.
1039  */
1040  using PixelFormats = std::vector<PixelFormat>;
1041 
1042  /**
1043  * Defines different types of frame origin positions.
1044  */
1045  enum PixelOrigin : uint32_t
1046  {
1047  /// Invalid origin type.
1048  ORIGIN_INVALID = 0u,
1049  /// The first pixel lies in the upper left corner, the last pixel in the lower right corner.
1051  /// The first pixel lies in the lower left corner, the last pixel in the upper right corner.
1052  ORIGIN_LOWER_LEFT
1053  };
1054 
1055  private:
1056 
1057  /**
1058  * Helper struct allowing to get access to the properties of a pixel format with a debugger.
1059  */
1061  {
1062  /// The value of the pixel format if predefined (if the pixel format is e.g., FORMAT_RGB24, FORMAT_Y8, FORMAT_Y_UV12, ...), 0 if the pixel format is pure generic.
1064 
1065  /// The number of channels, the pixel format has.
1066  uint8_t channels_;
1067 
1068  /// The data type of each elements of the pixel format.
1070 
1071  /// The number of individual planes of the pixel format.
1072  uint8_t planes_;
1073 
1074  /// The number of pixels the width of a frame must be a multiple of
1076 
1077  /// The number of pixels the height of a frame must be a multiple of
1079 
1080  /// Currently unused.
1081  uint8_t unused_;
1082  };
1083 
1084  static_assert(sizeof(PixelFormatProperties) == sizeof(std::underlying_type<PixelFormat>::type), "Invalid helper struct!");
1085 
1086  /**
1087  * This union mainly contains the pixel format as value.
1088  * In addition, this union allows to access a struct (genericPixelFormatStruct_) to investigate the individual components of a pixel format during a debugging session.<br>
1089  * However, overall this union is nothing else but a wrapper around 'PixelFormat'.
1090  */
1092  {
1093  public:
1094 
1095  /**
1096  * Creates a new union object based on a given pixel format.
1097  * @param pixelFormat The pixel format to be stored in the new union
1098  */
1099  explicit inline PixelFormatUnion(const PixelFormat& pixelFormat);
1100 
1101  public:
1102 
1103  /**
1104  * The actual pixel format defining the layout of the color space, the number of channels and the data type.
1105  * In case, the pixel format is pure generic, use 'genericPixelFormatStruct_' during a debugging session to lookup the data type and channel number.
1106  */
1108 
1109  private:
1110 
1111  /// The properties of the pixel format.
1113  };
1114 
1115  public:
1116 
1117  /**
1118  * Creates a new frame type with invalid parameters.
1119  */
1120  FrameType() = default;
1121 
1122  /**
1123  * Creates a new frame type.
1124  * @param width The width of the frame in pixel, must match with the pixel format condition, widthMultiple()
1125  * @param height The height of the frame in pixel, must match with the pixel format condition, heightMultiple()
1126  * @param pixelFormat Pixel format of the frame
1127  * @param pixelOrigin Pixel origin of the frame
1128  */
1129  inline FrameType(const unsigned int width, const unsigned int height, const PixelFormat pixelFormat, const PixelOrigin pixelOrigin);
1130 
1131  /**
1132  * Creates a new frame type.
1133  * @param type Frame type to copy most properties from
1134  * @param width The width of the frame in pixel to be used instead of the width defined in the given frame type, must match with the pixel format condition, widthMultiple()
1135  * @param height The height of the frame in pixel to be used instead of the height defined in the given frame type, must match with the pixel format condition, heightMultiple()
1136  */
1137  inline FrameType(const FrameType& type, const unsigned int width, const unsigned int height);
1138 
1139  /**
1140  * Creates a new frame type.
1141  * @param type Frame type to copy most properties from
1142  * @param pixelFormat Pixel format to be used instead of the pixel format defined in the given frame type
1143  */
1144  inline FrameType(const FrameType& type, const PixelFormat pixelFormat);
1145 
1146  /**
1147  * Creates a new frame type.
1148  * @param type Frame type to copy most properties from
1149  * @param pixelOrigin Pixel origin to be used instead of the pixel origin defined in the given frame type
1150  */
1151  inline FrameType(const FrameType& type, const PixelOrigin pixelOrigin);
1152 
1153  /**
1154  * Creates a new frame type.
1155  * @param type Frame type to copy most properties from
1156  * @param pixelFormat Pixel format of the frame
1157  * @param pixelOrigin Pixel origin to be used instead of the pixel origin defined in the given frame type
1158  */
1159  inline FrameType(const FrameType& type, const PixelFormat pixelFormat, const PixelOrigin pixelOrigin);
1160 
1161  /**
1162  * Returns the width of the frame format in pixel.
1163  * @return Width in pixel
1164  */
1165  inline unsigned int width() const;
1166 
1167  /**
1168  * Returns the height of the frame in pixel.
1169  * @return Height in pixel
1170  */
1171  inline unsigned int height() const;
1172 
1173  /**
1174  * Returns the pixel format of the frame.
1175  * @return Pixel format
1176  */
1177  inline PixelFormat pixelFormat() const;
1178 
1179  /**
1180  * Explicitly changes the pixel format of this frame.
1181  * Beware: Commonly there is no need to change the pixel format explicitly.
1182  * @param pixelFormat The new pixel format to be set, can be invalid
1183  */
1184  inline void setPixelFormat(const PixelFormat pixelFormat);
1185 
1186  /**
1187  * Returns the data type of the pixel format of this frame.
1188  * @return The frame's data type
1189  */
1190  inline DataType dataType() const;
1191 
1192  /**
1193  * Returns the number of bytes which are necessary to store the data type of this frame.
1194  * @return The number of bytes of the frame's data type, with range [1, infinity)
1195  */
1196  inline unsigned int bytesPerDataType() const;
1197 
1198  /**
1199  * Returns the number of individual channels the frame has.
1200  * An invalid frame or a frame with undefined pixel format has 0 channels.
1201  * @return Number of channels, with range [0, infinity)
1202  */
1203  inline unsigned int channels() const;
1204 
1205  /**
1206  * Returns the number of planes of the pixel format of this frame.
1207  * @return The number of planes, with range [0, infinity)
1208  */
1209  inline uint32_t numberPlanes() const;
1210 
1211  /**
1212  * Returns the pixel origin of the frame.
1213  * @return Pixel origin
1214  */
1215  inline PixelOrigin pixelOrigin() const;
1216 
1217  /**
1218  * Returns the number of pixels for the frame.
1219  * @return Number of frame pixels
1220  */
1221  inline unsigned int pixels() const;
1222 
1223  /**
1224  * Returns the number of bytes necessary for the frame type, without padding at the end of frame rows.
1225  * In case the pixel format holds more than one plane, the resulting number of bytes is the sum of all planes.
1226  * Beware: An actual frame may have a larger size if the frame comes with padding at end of rows.
1227  * @return The size of the memory necessary for this frame type in bytes, with range [0, infinity)
1228  * @see Frame::size().
1229  */
1230  unsigned int frameTypeSize() const;
1231 
1232  /**
1233  * Returns whether the pixel format of this frame type is compatible with a given pixel format.
1234  * Two pixel formats are compatible if:
1235  * - Both pixel formats are identical, or
1236  * - Both pixel formats are pure generic pixel formats with identical data type and channel number, or
1237  * - One pixel format is not pure generic (e.g., FORMAT_RGB24), while the other pixel format is pure generic but has the same data type and channel number
1238  * @param pixelFormat The pixel format to be checked, must be valid
1239  * @return True, if the given pixel format is compatible
1240  * @see isFrameTypeCompatible().
1241  */
1242  inline bool isPixelFormatCompatible(const PixelFormat pixelFormat) const;
1243 
1244  /**
1245  * Returns whether this frame type is compatible with a given frame type.
1246  * Two frame types are compatible if:
1247  * - Both types are identical, or
1248  * - Both types have the same dimension and compatible pixel formats
1249  * @param frameType The first frame type to be checked, must be valid
1250  * @param allowDifferentPixelOrigins True, to allow different pixel origins; False, so that both frame types must have the same pixel origin
1251  * @return True, if the given frame type is compatible
1252  * @see isPixelFormatCompatible().
1253  */
1254  inline bool isFrameTypeCompatible(const FrameType& frameType, const bool allowDifferentPixelOrigins) const;
1255 
1256  /**
1257  * Returns whether two frame types are equal.
1258  * @param right The right frame type
1259  * @return True, if so
1260  */
1261  bool operator==(const FrameType& right) const;
1262 
1263  /**
1264  * Returns whether two frame types are not equal.
1265  * @param right The right frame type
1266  * @return True, if so
1267  */
1268  inline bool operator!=(const FrameType& right) const;
1269 
1270  /**
1271  * Returns whether the left frame type is 'smaller' than the right one.
1272  * The operator does not compare the area of both frames but considers 'width', 'height', pixel format, and pixel origin to create a unique order between frame types.
1273  * @param right The right frame type
1274  * @return True, if so
1275  */
1276  bool operator<(const FrameType& right) const;
1277 
1278  /**
1279  * Returns whether this frame type is valid.
1280  * @return True, if so
1281  */
1282  inline bool isValid() const;
1283 
1284  /**
1285  * Returns the number of individual channels of a given pixel format.
1286  * @param pixelFormat Pixel format to be check
1287  * @return Number of channels
1288  */
1289  static unsigned int channels(const PixelFormat pixelFormat);
1290 
1291  /**
1292  * Returns the number of planes of a pixel format.
1293  * @param pixelFormat The pixel format for which the number of planes will be returned
1294  * @return The number of planes, with range [0, infinity)
1295  */
1296  static inline uint32_t numberPlanes(const PixelFormat pixelFormat);
1297 
1298  /**
1299  * Returns the (pixel format) data type of a given C++ data type.
1300  * @return The data type of the given template parameter, DT_UNDEFINED if the C++ data type is not supported
1301  * @tparam T The C++ data type for which the (pixel format) data type is returned
1302  */
1303  template <typename T>
1304  static constexpr DataType dataType();
1305 
1306  /**
1307  * Returns the data type of a pixel format.
1308  * @param pixelFormat Pixel format to be check
1309  * @return The data type of the given pixel format, DT_UNDEFINED if the pixel format is not supported
1310  */
1311  static inline DataType dataType(const PixelFormat pixelFormat);
1312 
1313  /**
1314  * Returns the number of bytes which are necessary to store a specified data type.
1315  * @param dataType The data type for which the number of bytes is requested
1316  * @return The number of bytes per data type, with range [1, infinity)
1317  */
1318  static unsigned int bytesPerDataType(const DataType dataType);
1319 
1320  /**
1321  * Returns a specific generic pixel format with a specified data type, channel number, and plane number.
1322  * @param dataType The data type of the generic format
1323  * @param channels The number of channels of the generic format, with range [1, 31]
1324  * @param planes The number of planes of the generic pixel format, with range [1, 255]
1325  * @param widthMultiple The number of pixels the width of a frame must be a multiple of, with range [1, 255]
1326  * @param heightMultiple The number of pixels the height of a frame must be a multiple of, with range [1, 255]
1327  * @return Pixel format the resulting pixel format
1328  */
1329  static constexpr inline PixelFormat genericPixelFormat(const DataType dataType, const uint32_t channels, const uint32_t planes = 1u, const uint32_t widthMultiple = 1u, const uint32_t heightMultiple = 1u);
1330 
1331  /**
1332  * Returns a specific generic pixel format with specified bit per pixel per channel, channel number, and plane number.
1333  * The overall number of bits per pixel will be bitsPerPixelChannel * channels
1334  * @param bitsPerPixelChannel The number of bits each pixel and channel of the pixel format will have, with values (4, 8, 16, 32, 64)
1335  * @param channels The number of channels of the generic format, with range [1, 31]
1336  * @param planes The number of planes of the generic pixel format, with range [1, 255]
1337  * @param widthMultiple The number of pixels the width of a frame must be a multiple of, with range [1, 255]
1338  * @param heightMultiple The number of pixels the height of a frame must be a multiple of, with range [1, 255]
1339  * @return Pixel format the resulting pixel format
1340  */
1341  static PixelFormat genericPixelFormat(const unsigned int bitsPerPixelChannel, const uint32_t channels, const uint32_t planes = 1u, const uint32_t widthMultiple = 1u, const uint32_t heightMultiple = 1u);
1342 
1343  /**
1344  * Returns a specific generic pixel format with a specified data type and channel number.
1345  * @return Pixel format the resulting pixel format
1346  * @tparam tDataType The data type of the generic format
1347  * @tparam tChannels The number of channels of the generic format, with range [1, 31]
1348  * @tparam tPlanes The number of planes of the generic pixel format, with range [1, 255]
1349  * @tparam tWidthMultiple The number of pixels the width of a frame must be a multiple of, with range [1, 255]
1350  * @tparam tHeightMultiple The number of pixels the height of a frame must be a multiple of, with range [1, 255]
1351  *
1352  * @code
1353  * // a pixel format with 3 channels storing 'unsigned char' values for each channel
1354  * const FrameType::PixelFormat pixelFormat3Channels = FrameType::genericPixelFormat<FrameType::DT_UNSIGNED_INTEGER_8, 3u>();
1355  *
1356  * // a pixel format with 1 channel composed of 'float' values
1357  * const FrameType::PixelFormat pixelFormat1Channel = FrameType::genericPixelFormat<FrameType::DT_SIGNED_FLOAT_32, 1u>();
1358  * @endcode
1359  * @see genericPixelFormat<TDataType, tChannels>();
1360  */
1361  template <DataType tDataType, uint32_t tChannels, uint32_t tPlanes = 1u, uint32_t tWidthMultiple = 1u, uint32_t tHeightMultiple = 1u>
1362  constexpr static PixelFormat genericPixelFormat();
1363 
1364  /**
1365  * Returns a specific generic pixel format with a specified data type and channel number.
1366  * @return Pixel format the resulting pixel format
1367  * @param channels The number of channels of the generic format, with range [1, 31]
1368  * @param planes The number of planes of the generic pixel format, with range [1, 255]
1369  * @param widthMultiple The number of pixels the width of a frame must be a multiple of, with range [1, 255]
1370  * @param heightMultiple The number of pixels the height of a frame must be a multiple of, with range [1, 255]
1371  * @tparam tDataType The data type of the generic format
1372  *
1373  * @code
1374  * // a pixel format with 3 channels storing 'unsigned char' values for each channel
1375  * const FrameType::PixelFormat pixelFormat3Channels = FrameType::genericPixelFormat<FrameType::DT_UNSIGNED_INTEGER_8>(3u);
1376  *
1377  * // a pixel format with 1 channel composed of 'float' values
1378  * const FrameType::PixelFormat pixelFormat1Channel = FrameType::genericPixelFormat<FrameType::DT_SIGNED_FLOAT_32>(1u);
1379  * @endcode
1380  */
1381  template <DataType tDataType>
1382  constexpr static PixelFormat genericPixelFormat(const uint32_t channels, const uint32_t planes = 1u, const uint32_t widthMultiple = 1u, const uint32_t heightMultiple = 1u);
1383 
1384  /**
1385  * Returns a specific generic pixel format with a specified data type and channel number.
1386  * @return Pixel format the resulting pixel format
1387  * @tparam TDataType The C++ data type for which the (pixel format) data type is returned
1388  * @tparam tChannels The number of channels of the generic format, with range [1, 31]
1389  * @tparam tPlanes The number of planes of the generic pixel format, with range [1, 255]
1390  * @tparam tWidthMultiple The number of pixels the width of a frame must be a multiple of, with range [1, 255]
1391  * @tparam tHeightMultiple The number of pixels the height of a frame must be a multiple of, with range [1, 255]
1392  *
1393  * The following code snippet shows how to use this function:
1394  * @code
1395  * // a pixel format with 3 channels storing 'unsigned char' values for each channel
1396  * const FrameType::PixelFormat pixelFormat3Channels = FrameType::genericPixelFormat<unsigned char, 3u>();
1397  *
1398  * // a pixel format with 1 channel composed of 'float' values
1399  * const FrameType::PixelFormat pixelFormat1Channel = FrameType::genericPixelFormat<float, 1u>();
1400  * @endcode
1401  * @see genericPixelFormat<tDataType, tChannels>();
1402  */
1403  template <typename TDataType, uint32_t tChannels, uint32_t tPlanes = 1u, uint32_t tWidthMultiple = 1u, uint32_t tHeightMultiple = 1u>
1404  constexpr static PixelFormat genericPixelFormat();
1405 
1406  /**
1407  * Returns a specific generic pixel format with a specified data type and channel number.
1408  * @return Pixel format the resulting pixel format
1409  * @param channels The number of channels of the generic format, with range [1, 31]
1410  * @param planes The number of planes of the generic pixel format, with range [1, 255]
1411  * @param widthMultiple The number of pixels the width of a frame must be a multiple of, with range [1, 255]
1412  * @param heightMultiple The number of pixels the height of a frame must be a multiple of, with range [1, 255]
1413  * @tparam TDataType The C++ data type for which the (pixel format) data type is returned
1414  *
1415  * The following code snippet shows how to use this function:
1416  * @code
1417  * // a pixel format with 3 channels storing 'unsigned char' values for each channel
1418  * const FrameType::PixelFormat pixelFormat3Channels = FrameType::genericPixelFormat<unsigned char>(3u);
1419  *
1420  * // a pixel format with 1 channel composed of 'float' values
1421  * const FrameType::PixelFormat pixelFormat1Channel = FrameType::genericPixelFormat<float>(1u);
1422  * @endcode
1423  */
1424  template <typename TDataType>
1425  constexpr static PixelFormat genericPixelFormat(uint32_t channels, const uint32_t planes = 1u, const uint32_t widthMultiple = 1u, const uint32_t heightMultiple = 1u);
1426 
1427  /**
1428  * Converts a any pixel format into a generic one
1429  * This function has no effect for input pixel formats which are already generic
1430  * @param pixelFormat A pixel format
1431  * @return The generic pixel format; for generic pixel formats output will be identical to input
1432  */
1433  static inline PixelFormat makeGenericPixelFormat(const PixelFormat pixelFormat);
1434 
1435  /**
1436  * Checks whether a given pixel format is a specific layout regarding data channels and data type.
1437  * @param pixelFormat The pixel format to be checked
1438  * @param dataType The expected data type of the given pixel format
1439  * @param channels The expected number of channels of the given pixel format, with range [0, 31]
1440  * @param planes The number of planes of the generic pixel format, with range [0, 255]
1441  * @param widthMultiple The number of pixels the width of a frame must be a multiple of, with range [1, 255]
1442  * @param heightMultiple The number of pixels the height of a frame must be a multiple of, with range [1, 255]
1443  * @return True, if succeeded
1444  */
1445  static inline bool formatIsGeneric(const PixelFormat pixelFormat, const DataType dataType, const uint32_t channels, const uint32_t planes = 1u, const uint32_t widthMultiple = 1u, const uint32_t heightMultiple = 1u);
1446 
1447  /**
1448  * Checks whether a given pixel format is a generic pixel format.
1449  * @param pixelFormat The pixel format to be checked
1450  * @return True, if succeeded
1451  */
1452  static inline bool formatIsGeneric(const PixelFormat pixelFormat);
1453 
1454  /**
1455  * Checks whether a given pixel format is a pure generic pixel format.
1456  * @param pixelFormat The pixel format to be checked
1457  * @return True, if succeeded
1458  */
1459  static inline bool formatIsPureGeneric(const PixelFormat pixelFormat);
1460 
1461  /**
1462  * Returns the number of individual channels of a given generic pixel format.
1463  * @param pixelFormat Generic pixel format to be checked
1464  * @return The number of channels, 0 if the pixel format is not generic (e.g., FORMAT_Y_UV12)
1465  */
1466  static unsigned int formatGenericNumberChannels(const PixelFormat pixelFormat);
1467 
1468  /**
1469  * Returns the number of bits of one pixel for a given generic pixel format.
1470  * @param pixelFormat Pixel format to check
1471  * @return Number of bits per pixel
1472  */
1473  static inline unsigned int formatGenericBitsPerPixel(const PixelFormat pixelFormat);
1474 
1475  /**
1476  * Returns the number of bits of one pixel for the red channel.
1477  * @param pixelFormat Pixel format to check
1478  * @return Number of bits per pixel
1479  */
1480  static unsigned int formatBitsPerPixelRedChannel(const PixelFormat pixelFormat);
1481 
1482  /**
1483  * Returns the number of bits of one pixel for the green channel.
1484  * @param pixelFormat Pixel format to check
1485  * @return Number of bits per pixel
1486  */
1487  static unsigned int formatBitsPerPixelGreenChannel(const PixelFormat pixelFormat);
1488 
1489  /**
1490  * Returns the number of bits of one pixel for the blue channel.
1491  * @param pixelFormat Pixel format to check
1492  * @return Number of bits per pixel
1493  */
1494  static unsigned int formatBitsPerPixelBlueChannel(const PixelFormat pixelFormat);
1495 
1496  /**
1497  * Returns the number of bits of one pixel for the alpha channel.
1498  * @param pixelFormat Pixel format to check
1499  * @return Number of bits per pixel
1500  */
1501  static unsigned int formatBitsPerPixelAlphaChannel(const PixelFormat pixelFormat);
1502 
1503  /**
1504  * Returns whether a given pixel format holds an alpha channel.
1505  * @param pixelFormat Pixel format to check
1506  * @param isLastChannel Optional returning whether the alpha channel is the last channel (true) or whether it is the first channel (false)
1507  * @return True, if so
1508  */
1509  static bool formatHasAlphaChannel(const PixelFormat pixelFormat, bool* isLastChannel = nullptr);
1510 
1511  /**
1512  * Returns whether a given pixel format is a packed pixel format.
1513  * Packed pixel formats like FORMAT_BGGR10_PACKED or FORMAT_Y10_PACKED contain bytes providing color information for several individual pixels.
1514  * @return True, if so
1515  */
1516  static bool formatIsPacked(const PixelFormat pixelFormat);
1517 
1518  /**
1519  * Returns the most suitable 1-plane pixel format for a given pixel format which may be composed of several planes.
1520  * If the given pixel format is a generic 1-plane pixel format already, the same pixel format will be returned.
1521  * Here is a table with some examples:
1522  * <pre>
1523  * Output pixel format: Input pixel format:
1524  * <generic pixel format> <generic pixel format> (e.g., FORMAT_RGB24)
1525  * FORMAT_BGR24 FORMAT_BGR4444, FORMAT_BGR5551, FORMAT_BGR565
1526  * FORMAT_BGRA32 FORMAT_BGRA4444
1527  * FORMAT_RGB24 FORMAT_RGB4444, FORMAT_RGB5551, FORMAT_RGB565
1528  * FORMAT_RGBA32 FORMAT_RGBA4444
1529  * FORMAT_YUV24, FORMAT_Y_UV12, FORMAT_UYVY16, FORMAT_Y_U_V12, FORMAT_YUYV16, FORMAT_Y_U_V24
1530  * FORMAT_YVU24 FORMAT_Y_VU12, FORMAT_Y_V_U12
1531  * </pre>
1532  * @param pixelFormat Pixel format for which the 1-plane pixel format will be returned
1533  * @return The resulting 1-plane pixel format, FORMAT_UNDEFINED if no matching pixel format could be found
1534  */
1536 
1537  /**
1538  * Adds an alpha channel to a given pixel format.
1539  * @param pixelFormat Pixel format without alpha channel
1540  * @param lastChannel True, to add the alpha channel at the end of the data channels, otherwise the alpha channel will be added in front of the data channels
1541  * @return Pixel format with alpha channel, if existing
1542  */
1543  static PixelFormat formatAddAlphaChannel(const PixelFormat pixelFormat, const bool lastChannel = true);
1544 
1545  /**
1546  * Removes an alpha channel from a given pixel format.
1547  * @param pixelFormat Pixel format with alpha channel
1548  * @return Pixel format without alpha channel, if existing
1549  */
1551 
1552  /**
1553  * Returns the number of pixels the width of a frame must be a multiple of.
1554  * @param pixelFormat Pixel format to return the number of pixels for
1555  * @return Number of pixels
1556  */
1557  static inline unsigned int widthMultiple(const PixelFormat pixelFormat);
1558 
1559  /**
1560  * Returns the number of pixels the height of a frame must be a multiple of.
1561  * @param pixelFormat Pixel format to return the number of pixels for
1562  * @return Number of pixels
1563  */
1564  static inline unsigned int heightMultiple(const PixelFormat pixelFormat);
1565 
1566  /**
1567  * Returns the channels of a plane for a pixel format.
1568  * @param imagePixelFormat The pixel format of the entire frame, must be valid
1569  * @param planeIndex The index of the plane for which the channels will be returned, with range [0, numberPlanes(imagePixelFormat))
1570  * @return The plane's channels, with range [0, infinity)
1571  */
1572  static unsigned int planeChannels(const PixelFormat& imagePixelFormat, const unsigned int planeIndex);
1573 
1574  /**
1575  * Returns the number of bytes of one pixel of a plane for a pixel format.
1576  * Beware: This function will return 0 if the pixel format is a special packed format (e.g., FORMAT_Y10_PACKED) which does not allow to calculate the number of bytes per pixel.
1577  * @param imagePixelFormat The pixel format of the entire frame, must be valid
1578  * @param planeIndex The index of the plane for which the bytes per pixel will be returned, with range [0, numberPlanes(imagePixelFormat))
1579  * @return The plane's number of bytes per pixel, will be 0 for special packed pixel formats like FORMAT_Y10_PACKED
1580  */
1581  static inline unsigned int planeBytesPerPixel(const PixelFormat& imagePixelFormat, const unsigned int planeIndex);
1582 
1583  /**
1584  * Returns the plane layout of a given pixel format.
1585  * @param imagePixelFormat The pixel format of the image for which the plane layout will be returned, must be valid
1586  * @param imageWidth The width of the image, in (image) pixel, with range [1, infinity)
1587  * @param imageHeight The height of the image, in (image) pixel, with range [1, infinity)
1588  * @param planeIndex The index of the plane for which the layout will be returned, with range [0, numberPlanes(imagePixelFormat) - 1]
1589  * @param planeWidth The resulting width of the specified plane, in (plane) pixel, with range [1, infinity)
1590  * @param planeHeight The resulting height of the specified plane, in (plane) pixel, with range [1, infinity)
1591  * @param planeChannels The resulting number of channels the plane has, with range [1, infinity)
1592  * @param planeWidthElementsMultiple Optional the resulting number of (plane) elements the width of the plane must be a multiple of, in elements, with range [1, infinity)
1593  * @param planeHeightElementsMultiple Optional the resulting number of (plane) elements the height of the plane must be a multiple of, in elements, with range [1, infinity)
1594  * @return True, if succeeded
1595  */
1596  static bool planeLayout(const PixelFormat imagePixelFormat, const unsigned int imageWidth, const unsigned int imageHeight, const unsigned int planeIndex, unsigned int& planeWidth, unsigned int& planeHeight, unsigned int& planeChannels, unsigned int* planeWidthElementsMultiple = nullptr, unsigned int* planeHeightElementsMultiple = nullptr);
1597 
1598  /**
1599  * Returns the plane layout of a given frame type.
1600  * @param frameType The frame type for which the plane layout will be returned, must be valid
1601  * @param planeIndex The index of the plane for which the layout will be returned, with range [0, numberPlanes(imagePixelFormat) - 1]
1602  * @param planeWidth The resulting width of the specified plane, in (plane) pixel, with range [1, infinity)
1603  * @param planeHeight The resulting height of the specified plane, in (plane) pixel, with range [1, infinity)
1604  * @param planeChannels The resulting number of channels the plane has, with range [1, infinity)
1605  * @param planeWidthElementsMultiple Optional the resulting number of (plane) elements the width of the plane must be a multiple of, in elements, with range [1, infinity)
1606  * @param planeHeightElementsMultiple Optional the resulting number of (plane) elements the height of the plane must be a multiple of, in elements, with range [1, infinity)
1607  * @return True, if succeeded
1608  */
1609  static inline bool planeLayout(const FrameType& frameType, const unsigned int planeIndex, unsigned int& planeWidth, unsigned int& planeHeight, unsigned int& planeChannels, unsigned int* planeWidthElementsMultiple = nullptr, unsigned int* planeHeightElementsMultiple = nullptr);
1610 
1611  /**
1612  * Translates a string containing a data type into the data type.<br>
1613  * For example 'UNSIGNED_INTEGER_8' will be translated into DT_UNSIGNED_INTEGER_8.
1614  * @param dataType Data type as string
1615  * @return Data type as value
1616  */
1617  static DataType translateDataType(const std::string& dataType);
1618 
1619  /**
1620  * Translates a string containing a pixel format into the pixel format.<br>
1621  * For example 'BGR24' will be translated into FORMAT_BGR24.
1622  * @param pixelFormat Pixel format as string
1623  * @return Pixel format as value
1624  */
1625  static PixelFormat translatePixelFormat(const std::string& pixelFormat);
1626 
1627  /**
1628  * Translates a string containing the pixel origin into the pixel origin value.<br>
1629  * For example 'UPPER_LEFT' will be translated into ORIGIN_UPPER_LEFT.
1630  * @param pixelOrigin Pixel origin as string
1631  * @return Pixel origin as value
1632  */
1633  static PixelOrigin translatePixelOrigin(const std::string& pixelOrigin);
1634 
1635  /**
1636  * Translates a data type value into a string containing the data type.<br>
1637  * For example the DT_UNSIGNED_INTEGER_8 will be translated into 'UNSIGNED_INTEGER_8'.
1638  * @param dataType the data type as value
1639  * @return The data type as string, 'UNDEFINED' if the data type is invalid or cannot be translated
1640  */
1641  static std::string translateDataType(const DataType dataType);
1642 
1643  /**
1644  * Translates a pixel format value into a string containing the pixel format.<br>
1645  * For example the FORMAT_BGR24 will be translated into 'BGR24'.
1646  * @param pixelFormat Pixel format as value
1647  * @return Pixel format as string, 'UNDEFINED' if the pixel format is invalid or cannot be translated
1648  */
1649  static std::string translatePixelFormat(const PixelFormat pixelFormat);
1650 
1651  /**
1652  * Translates a pixel origin value into a string containing the pixel origin.<br>
1653  * For example the ORIGIN_UPPER_LEFT will be translated into 'UPPER_LEFT'.
1654  * @param pixelOrigin Pixel origin as value
1655  * @return Pixel origin as string, 'INVALID' if the pixel origin is invalid or cannot be translated
1656  */
1657  static std::string translatePixelOrigin(const PixelOrigin pixelOrigin);
1658 
1659  /**
1660  * Returns a best fitting pixel format having the given number of bits per pixels.
1661  * @param bitsPerPixel Number of bits per pixel the resulting pixel format will have, with range [1, infinity)
1662  * @return Resulting pixel format, FORMAT_UNDEFINED if no pixel format can be found
1663  */
1664  static PixelFormat findPixelFormat(const unsigned int bitsPerPixel);
1665 
1666  /**
1667  * Returns a best fitting pixel format having the given number of bits per pixels.
1668  * The following mappings are defined:
1669  * <pre>
1670  * DataType: Channels: PixelFormat:
1671  * DT_UNSIGNED_INTEGER_8 1 FORMAT_Y8
1672  * DT_UNSIGNED_INTEGER_8 2 FORMAT_YA16
1673  * DT_UNSIGNED_INTEGER_8 3 FORMAT_RGB24
1674  * DT_UNSIGNED_INTEGER_8 4 FORMAT_RGBA32
1675  * </pre>
1676  * @param dataType The data type of each pixel element for which a pixel type is determined, must be valid
1677  * @param channels The number of channels for which a pixel format will be determined, with range [1, infinity)
1678  * @return Resulting pixel format, FORMAT_UNDEFINED if no pixel format can be found
1679  */
1680  static PixelFormat findPixelFormat(const DataType dataType, const unsigned int channels);
1681 
1682  /**
1683  * Returns whether two given pixel formats are compatible.
1684  * Two pixel formats are compatible if:
1685  * - Both pixel formats are identical, or
1686  * - Both pixel formats are pure generic pixel formats with identical data type and channel number, or
1687  * - One pixel format is not pure generic (e.g., FORMAT_RGB24), while the other pixel format is pure generic but has the same data type and channel number
1688  * @param pixelFormatA The first pixel format to be checked, must be valid
1689  * @param pixelFormatB The second pixel format to be checked, must be valid
1690  * @return True, if both pixel formats are compatible
1691  * @see areFrameTypesCompatible().
1692  */
1693  static bool arePixelFormatsCompatible(const PixelFormat pixelFormatA, const PixelFormat pixelFormatB);
1694 
1695  /**
1696  * Returns whether two given frame types are compatible.
1697  * Two frame types are compatible if:
1698  * - Both types are identical, or
1699  * - Both types have the same dimension and compatible pixel formats
1700  * @param frameTypeA The first frame type to be checked, must be valid
1701  * @param frameTypeB The second frame type to be checked, must be valid
1702  * @param allowDifferentPixelOrigins True, to allow different pixel origins; False, so that both frame types must have the same pixel origin
1703  * @return True, if both frame types are compatible
1704  * @see arePixelFormatsCompatible().
1705  */
1706  static bool areFrameTypesCompatible(const FrameType& frameTypeA, const FrameType& frameTypeB, const bool allowDifferentPixelOrigins);
1707 
1708  /**
1709  * Returns whether a given pointer has the same byte alignment as the size of the data type the pointer is pointing to.
1710  * Actually, this function returns whether the following condition is true:
1711  * <pre>
1712  * size_t(data) % sizeof(T) == 0
1713  * </pre>
1714  * @param data The pointer to the memory to be checked, must be valid
1715  * @return True, if so
1716  */
1717  template <typename T>
1718  static inline bool dataIsAligned(const void* data);
1719 
1720  /**
1721  * Returns all defined data types.
1722  * @return Ocean's defined data types
1723  */
1725 
1726  /**
1727  * Returns all defined pixel formats.
1728  * @return Ocean's defined pixel formats
1729  */
1731 
1732  private:
1733 
1734  /// Frame width in pixel, with range [0, infinity)
1735  unsigned int width_ = 0u;
1736 
1737  /// Frame height in pixel, with range [0, infinity)
1738  unsigned int height_ = 0u;
1739 
1740  /// The pixel format of the frame encapsulated in a union (mainly holding PixelFormat).
1741  PixelFormatUnion pixelFormat_ = PixelFormatUnion(FORMAT_UNDEFINED);
1742 
1743  /// The origin of the pixel data, either the upper left corner or the bottom left corner (if valid).
1744  PixelOrigin pixelOrigin_ = ORIGIN_INVALID;
1745 };
1746 
1747 // Forward declaration.
1748 class Frame;
1749 
1750 /**
1751  * Definition of a vector holding padding frames.
1752  * @see Frame.
1753  * @ingroup base
1754  */
1755 using Frames = std::vector<Frame>;
1756 
1757 /**
1758  * Definition of an object reference for frame objects.
1759  * @ingroup base
1760  */
1762 
1763 /**
1764  * Definition of a vector holding frame references.
1765  * @ingroup base
1766  */
1767 using FrameRefs = std::vector<FrameRef>;
1768 
1769 /**
1770  * This class implements Ocean's image class.
1771  * An image is composed of several planes, each plane can store image content with interleaved color channels.
1772  * <pre>
1773  * Plane 0:
1774  * ---------------------------------- ----------------------------
1775  * | | |
1776  * | | |
1777  * | |<--- paddingElements(0) --->| plane height (0)
1778  * | | |
1779  * | | |
1780  * ---------------------------------- ----------------------------
1781  *
1782  * Plane 1:
1783  * -------------- ------------------------
1784  * | | |
1785  * | |<- paddingElements(1) ->| plane height (1)
1786  * | | |
1787  * -------------- ------------------------
1788  * </pre>
1789  * @ingroup base
1790  */
1791 class OCEAN_BASE_EXPORT Frame : public FrameType
1792 {
1793  public:
1794 
1795  /**
1796  * Definition of individual copy modes.
1797  */
1798  enum CopyMode : uint32_t
1799  {
1800  /// The source memory is used only, no copy is created, the padding layout is preserved.
1801  CM_USE_KEEP_LAYOUT = 1u << 0u,
1802  /// Makes a copy of the source memory, but the new plane will not contain padding elements.
1803  CM_COPY_REMOVE_PADDING_LAYOUT = 1u << 1u,
1804  /// Makes a copy of the source memory, the padding layout is preserved, but the padding data is not copied.
1805  CM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA = 1u << 2u,
1806  /// Makes a copy of the source memory, the padding layout is preserved, the padding data is copied as well.
1807  CM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA = 1u << 3u,
1808  };
1809 
1810  /**
1811  * Definition of advanced copy modes containing all copy modes from `CopyMode` but also some additional.
1812  */
1813  enum AdvancedCopyMode : std::underlying_type<CopyMode>::type
1814  {
1815  /// Same as CM_USE_KEEP_LAYOUT.
1816  ACM_USE_KEEP_LAYOUT = CM_USE_KEEP_LAYOUT,
1817  /// Same as CM_COPY_REMOVE_PADDING_LAYOUT.
1818  ACM_COPY_REMOVE_PADDING_LAYOUT = CM_COPY_REMOVE_PADDING_LAYOUT,
1819  /// Same as CM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA.
1820  ACM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA = CM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA,
1821  /// Same as CM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA.
1822  ACM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA = CM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA,
1823 
1824  /// The source memory is used if the source is not owner of the memory; The source memory is copied if the source is owner of the memory, padding layout will be removed.
1825  ACM_USE_OR_COPY = ACM_USE_KEEP_LAYOUT | ACM_COPY_REMOVE_PADDING_LAYOUT,
1826  /// The source memory is used if the source is not owner of the memory; The source memory is copied if the source is owner of the memory, padding layout is preserved, but padding data is not copied.
1827  ACM_USE_OR_COPY_KEEP_LAYOUT = ACM_USE_KEEP_LAYOUT | ACM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA,
1828  };
1829 
1830  /**
1831  * Definition of an image plane, a block of memory storing pixel data with interleaved channels (or just one channel).
1832  * The plane does not store the specific pixel format or the width of the plane, as this information is part of the frame which owns the plane.
1833  * A plane has the following memory layout:
1834  * <pre>
1835  * |<-------- plane width ----------->|<-- paddingElements -->|
1836  *
1837  * ---------------------------------- ----------------------- ---
1838  * |A0 A1 An-1 B0 B1 Bn-1 ... | | ^
1839  * |... | | |
1840  * | | | plane height
1841  * | | | |
1842  * | | | V
1843  * ---------------------------------- ----------------------- ---
1844  *
1845  * |<------------------- stride bytes ----------------------->|
1846  *
1847  * With A0 first channel (or element) of first pixel, A1 second channel of first pixel, ...
1848  * And B0 first channel of second pixel, ...
1849  * </pre>
1850  * Note that: strideBytes == (planeWidth * channels + paddingElements) * bytesPerElement.<br>
1851  * A plane can have a different number of channels than a frame's pixel format which is owning the plane.<br>
1852  * The plane's channels are defined in relation to the data type of each pixel:<br>
1853  * A frame with pixel format FORMAT_RGB24 has three channels, one plane, and the plane has three channels (as the data type of each pixel element is uint8_t).<br>
1854  * However, a frame with pixel format FORMAT_RGB565 has three channels, one plane, but the plane has one channel only (as the data type of each pixel is uint16_t).
1855  */
1856  class OCEAN_BASE_EXPORT Plane
1857  {
1858  friend class Frame;
1859 
1860  public:
1861 
1862  /**
1863  * Creates a new invalid plane.
1864  */
1865  Plane() = default;
1866 
1867  /**
1868  * Move constructor.
1869  * @param plane The plane to be moved
1870  */
1871  inline Plane(Plane&& plane) noexcept;
1872 
1873  /**
1874  * Copy constructor.
1875  * @param plane The plane to be copied, can be invalid
1876  * @param advancedCopyMode The copy mode specifying whether the source memory is used or copied
1877  */
1878  Plane(const Plane& plane, const AdvancedCopyMode advancedCopyMode = ACM_USE_OR_COPY_KEEP_LAYOUT) noexcept;
1879 
1880  /**
1881  * Creates a new plane object with own allocated memory.
1882  * @param width The width of the plane in pixel, with range [1, infinity)
1883  * @param height The height of the plane in pixel, with range [1, infinity)
1884  * @param channels The number of channels the plane has, with respect to the specified data type `T`, with range [1, infinity)
1885  * @param elementTypeSize The size of each element of the new plane, in bytes, with range [1, infinity)
1886  * @param paddingElements The optional number of padding elements at the end of each row, in elements, with range [0, infinity)
1887  */
1888  Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const unsigned int paddingElements) noexcept;
1889 
1890  /**
1891  * Creates a new plane object which is not creating a copy of the given memory. Instead, the memory pointer is just used.
1892  * @param width The width of the plane in pixels, one pixel has size `sizeof(T) * channels`, with range [1, infinity)
1893  * @param height The height of the plane in pixel, with range [1, infinity)
1894  * @param channels The number of channels the plane has, with respect to the specified data type `T`, with range [1, infinity)
1895  * @param dataToUse Memory pointer of the read-only memory which will not be copied, must be valid
1896  * @param paddingElements The optional number of padding elements at the end of each row, in elements, with range [0, infinity)
1897  * @tparam T The data type of each element
1898  */
1899  template <typename T>
1900  inline Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const T* dataToUse, const unsigned int paddingElements) noexcept;
1901 
1902  /**
1903  * Creates a new plane object which is not creating a copy of the given memory. Instead, the memory pointer is just used.
1904  * @param width The width of the plane in pixels, one pixel has size `sizeof(T) * channels`, with range [1, infinity)
1905  * @param height The height of the plane in pixel, with range [1, infinity)
1906  * @param channels The number of channels the plane has, with respect to the specified data type `T`, with range [1, infinity)
1907  * @param dataToUse Memory pointer of the writable memory which will not be copied, must be valid
1908  * @param paddingElements The optional number of padding elements at the end of each row, in elements, with range [0, infinity)
1909  * @tparam T The data type of each element
1910  */
1911  template <typename T>
1912  inline Plane(const unsigned int width, const unsigned int height, const unsigned int channels, T* dataToUse, const unsigned int paddingElements) noexcept;
1913 
1914  /**
1915  * Creates a new plane object by making a copy of the given memory.
1916  * @param sourceDataToCopy The source data to be copied, must be valid
1917  * @param width The width of the plane in pixels, one pixel has size `sizeof(T) * channels`, with range [1, infinity)
1918  * @param height The height of the plane in pixels, with range [1, infinity)
1919  * @param channels The number of channels the plane has, with respect to the specified data type `T`, with range [1, infinity)
1920  * @param targetPaddingElements The optional number of padding elements at the end of each row this new plane will have, in elements, with range [0, infinity)
1921  * @param sourcePaddingElements The number of padding elements at the end of each row the given source memory has, in elements, with range [0, infinity)
1922  * @param makeCopyOfPaddingData True, to copy the entire padding data of the source plane (both planes must have the same padding layout: `targetPaddingElements == sourcePaddingElements`); False, to skip the padding data when copying the plane
1923  * @tparam T The data type of each element
1924  */
1925  template <typename T>
1926  inline Plane(const T* sourceDataToCopy, const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int targetPaddingElements, const unsigned int sourcePaddingElements, const bool makeCopyOfPaddingData = false) noexcept;
1927 
1928  /**
1929  * Creates a new plane object by making a copy of the given memory.
1930  * @param sourceDataToCopy The source data to be copied, must be valid
1931  * @param width The width of the plane in pixels, one pixel has size `sizeof(T) * channels`, with range [1, infinity)
1932  * @param height The height of the plane in pixels, with range [1, infinity)
1933  * @param channels The number of channels the plane has, with respect to the specified data type `T`, with range [1, infinity)
1934  * @param sourcePaddingElements The number of padding elements at the end of each row the given source memory has, in elements, with range [0, infinity)
1935  * @param copyMode The copy mode to be applied
1936  * @tparam T The data type of each element
1937  */
1938  template <typename T>
1939  inline Plane(const T* sourceDataToCopy, const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int sourcePaddingElements, const CopyMode copyMode) noexcept;
1940 
1941  /**
1942  * Destructs a Plane object.
1943  */
1944  inline ~Plane();
1945 
1946  /**
1947  * Returns the width of the plane in pixel.
1948  * @return The plane's width, in pixel, with range [0, infinity)
1949  */
1950  inline unsigned int width() const;
1951 
1952  /**
1953  * Returns the height of the plane in pixel.
1954  * @return The plane's height, in pixel, with range [0, infinity)
1955  */
1956  inline unsigned int height() const;
1957 
1958  /**
1959  * Returns the channels of the plane.
1960  * @return The plane's channels, with range [0, infinity)
1961  */
1962  inline unsigned int channels() const;
1963 
1964  /**
1965  * Returns the read-only memory pointer to this plane with a specific data type compatible with elementTypeSize().
1966  * @return The plane's read-only memory pointer, nullptr if this plane is invalid
1967  * @tparam T the data type of the resulting memory pointer, with `sizeof(T) == elementTypeSize()`
1968  */
1969  template <typename T>
1970  inline const T* constdata() const;
1971 
1972  /**
1973  * Returns the writable memory pointer to this plane with a specific data type compatible with elementTypeSize().
1974  * @return The plane's writable memory pointer, nullptr if this plane is not writable or invalid
1975  * @tparam T the data type of the resulting memory pointer, with `sizeof(T) == elementTypeSize()`
1976  */
1977  template <typename T>
1978  inline T* data();
1979 
1980  /**
1981  * Returns the number of padding elements at the end of each plane row, in elements.
1982  * @return The number of padding elements, with range [0, infinity)
1983  * @see paddingBytes().
1984  */
1985  inline unsigned int paddingElements() const;
1986 
1987  /**
1988  * Returns the number of padding bytes at the end of each plane row, in bytes.
1989  * This function actually returns `paddingElements() * elementTypeSize()`.
1990  * @return The number of padding bytes, with range [0, infinity)
1991  * @see paddingElements().
1992  */
1993  inline unsigned int paddingBytes() const;
1994 
1995  /**
1996  * Returns the size of each element of this plane.
1997  * @return The element size, in bytes
1998  */
1999  inline unsigned int elementTypeSize() const;
2000 
2001  /**
2002  * Returns the width of the plane in elements, the width does not contain optional padding elements.
2003  * This is the number of elements in which image data is stored (the number of elements between start of a row and start of the padding elements):
2004  * <pre>
2005  * widthElements == width * channels == strideElements() - paddingElements()
2006  * </pre>
2007  * @return The number of elements, with range [0, infinity)
2008  */
2009  inline unsigned int widthElements() const;
2010 
2011  /**
2012  * Returns the width of the plane in bytes, the width does not contain optional padding elements.
2013  * This is the number of bytes in which image data is stored (the number of bytes between start of a row and start of the padding elements):
2014  * <pre>
2015  * widthBytes == width * channels * elementTypeSize() == strideBytes - elementTypeSize() * paddingElements()
2016  * </pre>
2017  * @return The number of bytes, with range [0, infinity)
2018  */
2019  inline unsigned int widthBytes() const;
2020 
2021  /**
2022  * Returns the number of elements between the start positions of two consecutive rows, in elements.
2023  * This function actually returns `width * channels + paddingElements`.
2024  * @return The number of elements, with range [width * elementsPerPixel, infinity)
2025  */
2026  inline unsigned int strideElements() const;
2027 
2028  /**
2029  * Returns the number of bytes between the start positions of two consecutive rows, in bytes.
2030  * @return The number of bytes, with range [width * bytesPerPlanePixel, infinity)
2031  */
2032  inline unsigned int strideBytes() const;
2033 
2034  /**
2035  * Returns the number of bytes which is used for each pixel.
2036  * @return The number of bytes, with range [1, infinity), 0 if unknown
2037  */
2038  inline unsigned int bytesPerPixel() const;
2039 
2040  /**
2041  * Releases this plane and all resources of this plane.
2042  */
2043  void release();
2044 
2045  /**
2046  * Returns whether this plane is compatible with a given element data type.
2047  * @tparam T The data type to be checked
2048  * @return True, if so
2049  */
2050  template <typename T>
2051  inline bool isCompatibleWithDataType() const;
2052 
2053  /**
2054  * Returns the number of bytes necessary for the entire plane data including optional padding elements at the end of each row.
2055  * This function actually returns `strideBytes() * height()`.
2056  * @return Plane size in bytes, with range [0, infinity)
2057  */
2058  inline unsigned int size() const;
2059 
2060  /**
2061  * Returns whether this plane is based on continuous memory and thus does not have any padding at the end of rows.
2062  * @return True, if so
2063  */
2064  inline bool isContinuous() const;
2065 
2066  /**
2067  * Returns whether this plane is the owner of the memory.
2068  * @return True, if the plane is the owner; False, if someone else is the owner
2069  */
2070  inline bool isOwner() const;
2071 
2072  /**
2073  * Returns whether this plane holds read-only memory.
2074  * @return True, if the memory of the plane is not writable
2075  */
2076  inline bool isReadOnly() const;
2077 
2078  /**
2079  * Returns whether this plane holds valid data.
2080  * @return True, if so; False, if the plane is empty
2081  */
2082  inline bool isValid() const;
2083 
2084  /**
2085  * Copies data from another plane into this plane.
2086  * If this plane does not have a compatible memory, or if this plane's memory is not writable, reallocation will be done if `reallocateIfNecessary == true`.
2087  * @param sourcePlane The source plane from which the memory will be copied, an invalid plane to release this plane
2088  * @param advancedCopyMode The copy mode specifying whether the source memory is used or copied
2089  * @param reallocateIfNecessary True, to reallocate new memory if this plane is not compatible with the source plane; False, to prevent a reallocation and to skip to copy the source plane
2090  * @return True, if succeeded
2091  */
2092  bool copy(const Plane& sourcePlane, const AdvancedCopyMode advancedCopyMode = ACM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA, const bool reallocateIfNecessary = true);
2093 
2094  /**
2095  * Move operator.
2096  * @param plane The plane to be moved
2097  * @return The reference to this object
2098  */
2099  Plane& operator=(Plane&& plane) noexcept;
2100 
2101  /**
2102  * Copy operator.
2103  * This plane will have the same stride/padding layout. However, the padding memory will not be copied.
2104  * If the source plane is owner of the memory, this plane will be owner of an own copy of the memory.
2105  * If the source plane is not the owner of the memory, this plane will also not be the owner but will use the memory of the source plane as well.
2106  * @param plane The plane to be copied
2107  * @return Reference to this object
2108  */
2109  Plane& operator=(const Plane& plane) noexcept;
2110 
2111  /**
2112  * Allocates memory with specific byte alignment.
2113  * @param size The size of the resulting buffer in bytes, with range [0, infinity)
2114  * @param alignment The requested byte alignment, with range [1, infinity)
2115  * @param alignedData the resulting pointer to the aligned memory
2116  * @return The allocated memory with arbitrary alignment
2117  */
2118  static void* alignedMemory(const size_t size, const size_t alignment, void*& alignedData);
2119 
2120  protected:
2121 
2122  /**
2123  * Creates a new plane object which is not creating a copy of the given memory. Instead, the memory pointer is just used.
2124  * @param width The width of the plane, in pixel, with range [0, infinity)
2125  * @param height The height of the plane, in pixel, with range [0, infinity)
2126  * @param channels The channels of the plane, with range [0, infinity)
2127  * @param elementTypeSize The size of each element in bytes, which is `sizeof(T)`, with range [1, infinity)
2128  * @param constData The value for `constData` to be set
2129  * @param data The value for `data` to be set
2130  * @param paddingElements The optional number of padding elements at the end of each row, in elements, with range [0, infinity)
2131  */
2132  inline Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const void* constData, void* data, const unsigned int paddingElements) noexcept;
2133 
2134  /**
2135  * Creates a new plane object which is not creating a copy of the given memory. Instead, the memory pointer is just used.
2136  * @param width The width of the plane, in pixel, with range [0, infinity)
2137  * @param height The height of the plane, in pixel, with range [0, infinity)
2138  * @param channels The channels of the plane, with range [0, infinity)
2139  * @param elementTypeSize The size of each element in bytes, which is `sizeof(T)`, with range [1, infinity)
2140  * @param dataToUse Memory pointer of the read-only memory which will not be copied, must be valid
2141  * @param paddingElements The number of padding elements at the end of each row, in elements, with range [0, infinity)
2142  */
2143  Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const void* dataToUse, const unsigned int paddingElements) noexcept;
2144 
2145  /**
2146  * Creates a new plane object which is not creating a copy of the given memory. Instead, the memory pointer is just used.
2147  * @param width The width of the plane, in pixel, with range [0, infinity)
2148  * @param height The height of the plane, in pixel, with range [0, infinity)
2149  * @param channels The channels of the plane, with range [0, infinity)
2150  * @param elementTypeSize The size of each element in bytes, which is `sizeof(T)`, with range [1, infinity)
2151  * @param dataToUse Memory pointer of the read-only memory which will not be copied, must be valid
2152  * @param paddingElements The number of padding elements at the end of each row, in elements, with range [0, infinity)
2153  */
2154  Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, void* dataToUse, const unsigned int paddingElements) noexcept;
2155 
2156  /**
2157  * Creates a new plane object by making a copy of the given memory.
2158  * @param width The width of the plane in pixels, one pixel has size `sizeof(T) * channels`, with range [1, infinity)
2159  * @param height The height of the plane in pixels, with range [1, infinity)
2160  * @param channels The number of channels the plane has, with respect to the specified data type, with range [1, infinity)
2161  * @param elementTypeSize The size of each element in bytes, which is `sizeof(T)`, with range [1, infinity)
2162  * @param sourceDataToCopy The source data to be copied, must be valid
2163  * @param targetPaddingElements The number of padding elements at the end of each row this new plane will have, in elements, with range [0, infinity)
2164  * @param sourcePaddingElements The number of padding elements at the end of each row the given source memory has, in elements, with range [0, infinity)
2165  * @param makeCopyOfPaddingData True, to copy the entire padding data of the source plane (both planes must have the same padding layout: `targetPaddingElements == sourcePaddingElements`); False, to skip the padding data when copying the plane
2166  */
2167  Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const void* sourceDataToCopy, const unsigned int targetPaddingElements, const unsigned int sourcePaddingElements, const bool makeCopyOfPaddingData = false) noexcept;
2168 
2169  /**
2170  * Creates a new plane object by making a copy of the given memory.
2171  * @param width The width of the plane in pixels, one pixel has size `sizeof(T) * channels`, with range [1, infinity)
2172  * @param height The height of the plane in pixels, with range [1, infinity)
2173  * @param channels The number of channels the plane has, with respect to the specified data type, with range [1, infinity)
2174  * @param elementTypeSize The size of each element in bytes, which is `sizeof(T)`, with range [1, infinity)
2175  * @param sourceDataToCopy The source data to be copied, must be valid
2176  * @param sourcePaddingElements The number of padding elements at the end of each row the given source memory has, in elements, with range [0, infinity)
2177  * @param copyMode The copy mode to be applied
2178  */
2179  Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const void* sourceDataToCopy, const unsigned int sourcePaddingElements, const CopyMode copyMode) noexcept;
2180 
2181  /**
2182  * Copies memory into this plane which has compatible memory already.
2183  * @param sourceData The source data from a compatible plane, must be valid
2184  * @param sourceStrideBytes The number of bytes between the start positions of two consecutive rows in the source plane, in bytes, with range [strideBytes(), infinity)
2185  * @param sourcePaddingElements The number of padding elements at the end of each row, in elements, with range [0, infinity)
2186  * @param makeCopyOfPaddingData True, to copy the entire padding data of the source plane (this plane mast have the same padding layout); False, to skip the padding data when copying the plane
2187  */
2188  void copy(const void* sourceData, const unsigned int sourceStrideBytes, const unsigned int sourcePaddingElements, const bool makeCopyOfPaddingData = false);
2189 
2190  /**
2191  * Calculates the number of bytes between the start positions of two consecutive rows, in bytes.
2192  * @return The number of bytes, with range [width * bytesPerPlanePixel, infinity).
2193  */
2194  inline unsigned int calculateStrideBytes() const;
2195 
2196  /**
2197  * Calculates the number of bytes per pixel.
2198  * @return The number of bytes, with range [1, infinity), 0 if unknown
2199  */
2200  unsigned int calculateBytesPerPixel() const;
2201 
2202  protected:
2203 
2204  /// The pointer to the memory which this plane has allocated, this pointer is pointing to the memory which needs to be freed when disposing the plane object, nullptr if the plane is not owner of the memory.
2205  void* allocatedData_ = nullptr;
2206 
2207  /// The pointer to the read-only memory of the plane (not the pointer to the allocated memory), nullptr, if the plane is not read-only, or invalid.
2208  const void* constData_ = nullptr;
2209 
2210  /// The pointer to the writable memory of the plane (not the pointer to the allocated memory), nullptr if the plane is not writable.
2211  void* data_ = nullptr;
2212 
2213  /// The width of the plane in pixel, with range [0, infinity).
2214  unsigned int width_ = 0u;
2215 
2216  /// The height of the plane in pixel, with range [0, infinity).
2217  unsigned int height_ = 0u;
2218 
2219  /// The number of channels the plane has, with range [0, infinity).
2220  unsigned int channels_ = 0u;
2221 
2222  /// The size of each element of this plane, in bytes, with range [0, infinity).
2223  unsigned int elementTypeSize_ = 0u;
2224 
2225  /// The number of padding elements at the end of each plane row, in elements, with range [0, infinity).
2226  unsigned int paddingElements_ = 0u;
2227 
2228  /// The number of bytes between the start positions of two consecutive rows, in bytes, identical to '(width_ * channels_ + paddingElements_) * elementTypeSize_`
2229  unsigned int strideBytes_ = 0u;
2230 
2231  /// The number of bytes per pixel, with range [1, infinity), 0 if unknown.
2232  unsigned int bytesPerPixel_ = 0u;
2233  };
2234 
2235  /**
2236  * Definition of a vector storing planes.
2237  */
2239 
2240  /**
2241  * This class implements a helper class which can be used to initialize a multi-plane frame in the constructor.
2242  * The class is mainly a temporary storage for memory pointers, copy modes, and number of padding elements.
2243  * @tparam T The data type of the frame's element type, can be `void` if unknown
2244  */
2245  template <typename T>
2247  {
2248  friend class Frame;
2249 
2250  public:
2251 
2252  /**
2253  * Creates a new initializer object for a read-only memory pointer.
2254  * @param constdata The read-only memory pointer to the plane data, must be valid
2255  * @param copyMode The copy mode to be applied when initializing the plane
2256  * @param dataPaddingElements The number of padding elements at the end of each row of the given memory pointer, in elements, with range [0, infinity)
2257  */
2258  inline PlaneInitializer(const T* constdata, const CopyMode copyMode, const unsigned int dataPaddingElements = 0u);
2259 
2260  /**
2261  * Creates a new initializer object for a writable memory pointer.
2262  * @param data The writable memory pointer to the plane data, must be valid
2263  * @param copyMode The copy mode to be applied when initializing the plane
2264  * @param dataPaddingElements The number of padding elements at the end of each row of the given memory pointer, in elements, with range [0, infinity)
2265  */
2266  inline PlaneInitializer(T* data, const CopyMode copyMode, const unsigned int dataPaddingElements = 0u);
2267 
2268  /**
2269  * Creates a new initializer object for a new plane for which the number of padding elements is known.
2270  * @param planePaddingElements The number of padding elements at the end of each row of the resulting plane, in elements, with range [0, infinity)
2271  */
2272  explicit inline PlaneInitializer(const unsigned int planePaddingElements = 0u);
2273 
2274  protected:
2275 
2276  /**
2277  * Creates plane initializer objects with padding elements only.
2278  * @param paddingElementsPerPlane The padding elements one value for each plane
2279  * @return The resulting plane initializer objects
2280  */
2281  static std::vector<PlaneInitializer<T>> createPlaneInitializersWithPaddingElements(const Indices32& paddingElementsPerPlane);
2282 
2283  protected:
2284 
2285  /// The pointer to the read-only source memory, can be nullptr.
2286  const T* constdata_ = nullptr;
2287 
2288  /// The pointer to the writable source memory, can be nullptr.
2289  T* data_ = nullptr;
2290 
2291  /// The copy mode to be applied, unused if `constdata_ == nullptr` and `data_ == nullptr`.
2292  CopyMode copyMode_ = CopyMode(0u);
2293 
2294  /// If a valid memory pointer is provided, the number of padding elements at the end of each source memory row; Otherwise, the number of padding elements at the end row of the new plane, with range [0, infinity)
2295  unsigned int paddingElements_ = 0u;
2296  };
2297 
2298  /**
2299  * Definition of a vector holding plane initializer objects.
2300  * @tparam T The data type of the frame's element type.
2301  */
2302  template <typename T>
2303  using PlaneInitializers = std::vector<PlaneInitializer<T>>;
2304 
2305  /**
2306  * Definition of a data type storing all channel values of one pixel in an array.
2307  * @tparam T The data type of each pixel channel
2308  * @tparam tChannels The number of channels the pixel has, with range [1, infinity)
2309  */
2310  template <typename T, unsigned int tChannels>
2312 
2313  public:
2314 
2315  /**
2316  * Creates an empty frame.
2317  */
2318  inline Frame();
2319 
2320  /**
2321  * Creates a second version of a given frame.
2322  * If the given source frame is not owner of the frame data, this new frame will also not be owner of the frame data.<br>
2323  * But, if the given source frame is the owner of the frame data, this new frame will also be the owner of new copy of the frame data.<br>
2324  * Thus, the following two lines of code produce the same result:
2325  * @code
2326  * Frame newFrameA(frame);
2327  * Frame newFrameB(frame, ACM_USE_OR_COPY);
2328  * ocean_assert(newFrameB.isOwner() == false || newFrameB.isContinuous());
2329  * @endcode
2330  * This function behaves similar like the normal assign operator.
2331  * Whenever a copy is created, the memory layout of the resulting frame will be continuous.
2332  * @param frame The frame to copy
2333  */
2334  Frame(const Frame& frame);
2335 
2336  /**
2337  * Move constructor.
2338  * @param frame The frame to be moved
2339  */
2340  inline Frame(Frame&& frame) noexcept;
2341 
2342  /**
2343  * Creates a second version of a given frame.
2344  * Beware: The pixel memory will either be copied or used only, this depends on 'advancedCopyMode'.<br>
2345  * @param frame The frame to copy, can be invalid
2346  * @param advancedCopyMode The copy mode to be applied
2347  */
2348  Frame(const Frame& frame, const AdvancedCopyMode advancedCopyMode) noexcept;
2349 
2350  /**
2351  * Creates a frame with specified width, height, pixel format and frame origin and an optional padding.
2352  * The necessary buffer is allocated but not initialized.
2353  * @param frameType Type of the frame, must be valid
2354  * @param paddingElementsPerPlane The padding elements at the end of each individual plane row, in elements of the pixel format, one for each plane, an empty vector to define a frame without padding
2355  * @param timestamp The timestamp of the frame
2356  */
2357  explicit inline Frame(const FrameType& frameType, const Indices32& paddingElementsPerPlane = Indices32(), const Timestamp& timestamp = Timestamp(false));
2358 
2359  /**
2360  * Deprecated: Use Frame(const FrameType& frameType, const Indices32& paddingElements, const Timestamp& timestamp) instead.
2361  *
2362  * Creates a new one-plane frame by given width, height, pixel format and frame origin and an optional padding.
2363  * The necessary buffer is allocated but not initialized.
2364  * @param frameType Type of the frame, must be valid
2365  * @param paddingElements Optional number of elements at the end of each row, one pixel has (1 * channels) elements, must be 0 for non-generic pixel formats (e.g., Y_UV12), with range [0, infinity)
2366  * @param timestamp The timestamp of the frame
2367  */
2368  explicit inline Frame(const FrameType& frameType, const unsigned int paddingElements, const Timestamp& timestamp = Timestamp(false));
2369 
2370  /**
2371  * Creates a new one-plane frame with known frame type with read-only source memory.
2372  * Beware: If this frame uses the pixel data only, the provided buffer must be valid as long as this new frame exists!
2373  * @param frameType Type of the frame, must be valid
2374  * @param data Frame data to copy or to use, depending on the data copy flag
2375  * @param copyMode The copy mode to be applied
2376  * @param paddingElements Optional number of elements at the end of each row, one pixel has (1 * channels) elements, must be 0 for non-generic pixel formats (e.g., Y_UV12), with range [0, infinity)
2377  * @param timestamp The timestamp of the frame
2378  * @tparam T The data type of each pixel element, e.g., 'uint8_t', 'uint16_t', or 'float', can be `void` to force the usage of the pixel element type as defined in `frameType.pixelFormat()`
2379  */
2380  template <typename T>
2381  inline Frame(const FrameType& frameType, const T* data, const CopyMode copyMode, const unsigned int paddingElements = 0u, const Timestamp& timestamp = Timestamp(false));
2382 
2383  /**
2384  * Creates a new one-plane frame with known frame type with writable source memory.
2385  * Beware: If this frame uses the pixel data only, the provided buffer must be valid as long as this new frame exists!
2386  * @param frameType Type of the frame
2387  * @param data Frame data to copy or to use, depending on the data copy flag
2388  * @param copyMode The copy mode to be applied
2389  * @param paddingElements Optional number of elements at the end of each row, one pixel has (1 * channels) elements, must be 0 for non-generic pixel formats (e.g., Y_UV12), with range [0, infinity)
2390  * @param timestamp The timestamp of the frame
2391  * @tparam T The data type of each pixel element, e.g., 'uint8_t', 'uint16_t', or 'float', can be `void` to force the usage of the pixel element type as defined in `frameType.pixelFormat()`
2392  */
2393  template <typename T>
2394  inline Frame(const FrameType& frameType, T* data, const CopyMode copyMode, const unsigned int paddingElements = 0u, const Timestamp& timestamp = Timestamp(false));
2395 
2396  /**
2397  * Creates a new multi-plane frame with known frame type and given source memory for each individual plane.
2398  * @param frameType The data type of the new frame, must be valid
2399  * @param planeInitializers The initializers for the individual planes, one for each plane of the pixel format
2400  * @param timestamp The timestamp of the frame
2401  * @tparam T The data type of each pixel element, e.g., 'uint8_t', 'uint16_t', or 'float', can be `void` to force the usage of the pixel element type as defined in `frameType.pixelFormat()`
2402  */
2403  template <typename T>
2404  inline Frame(const FrameType& frameType, const PlaneInitializers<T>& planeInitializers, const Timestamp& timestamp = Timestamp(false));
2405 
2406  /**
2407  * Destructs a frame.
2408  */
2410 
2411  /**
2412  * Returns the frame type of this frame.
2413  * This return value is actually the cast of the base class of this frame.
2414  * @return Frame type
2415  */
2416  inline const FrameType& frameType() const;
2417 
2418  /**
2419  * Returns the individual planes of this frame.
2420  * @return The frame's plane
2421  */
2422  inline const Planes& planes() const;
2423 
2424  /**
2425  * Deprecated.
2426  *
2427  * Copies frame data from a source frame.
2428  * When both frame types are not identical, the frame type of this frame is changed to the source frame type.<br>
2429  * This frame will own the new frame data, thus a new frame buffer is allocated if necessary.<br>
2430  * In case a new frame buffer needed to be allocated, the memory layout of the new frame buffer will be continuous.
2431  * @param source The source frame to copy, must be valid and must not be this frame
2432  * @param copyTimestamp True, to copy the frame's timestamp; False, to copy the image data only
2433  * @return True, if the copy operation was successful; otherwise, the frame is not modified and false is returned.
2434  */
2435  bool copy(const Frame& source, const bool copyTimestamp = true);
2436 
2437  /**
2438  * Copies the entire image content of a source frame into this frame.
2439  * Both frames must have a compatible pixel format and must have the same pixel origin.<br>
2440  * Only the intersecting image content will be copied, padding data is not copied:
2441  * <pre>
2442  * Source frame
2443  * -------------------------------
2444  * This |(targetLeft, targetTop) |
2445  * target frame | |
2446  * -----------------|--------- |
2447  * |(0, 0) |XXXXXXXXX| |
2448  * | |XXXXXXXXX| |
2449  * | -------------------------------
2450  * | |
2451  * ---------------------------
2452  * </pre>
2453  * The intersecting image content is marked with an 'X'.
2454  * @param targetLeft The horizontal position within this image to which the top-left corner of the source image will be copied, with range (-infinity, infinity)
2455  * @param targetTop The vertical position within this image to which the top-left corner of the source image will be copied, with range (-infinity, infinity)
2456  * @param source The source frame to be copied, must be valid
2457  * @param copyTimestamp True, to copy the frame's timestamp; False, to copy the image data only
2458  * @return False, if both frames are not compatible; True, if the input was valid, even if both images do not intersect
2459  */
2460  bool copy(const int targetLeft, const int targetTop, const Frame& source, const bool copyTimestamp = true);
2461 
2462  /**
2463  * Sets a new frame type for this frame.
2464  * The frame data will be reallocated (re-initialized) if the specified frame types, or one of the property flags (forceOwner, forceWritable) do not fit with the current frame.
2465  * @param frameType New frame type to set, can be invalid
2466  * @param forceOwner If specified and the frame is not yet owner, then the frame will allocate its own frame buffer
2467  * @param forceWritable If specified and the frame is read-only, then the frame will allocate its own frame buffer
2468  * @param planePaddingElements The padding elements at the end of each individual plane row, in elements, one for each plane, an empty vector to use the existing padding layout or no padding if reallocation
2469  * @param timestamp The timestamp to be set
2470  * @param reallocated Optional resulting state whether the frame has been reallocated; nullptr otherwise
2471  * @return True, if succeeded
2472  */
2473  bool set(const FrameType& frameType, const bool forceOwner, const bool forceWritable = false, const Indices32& planePaddingElements = Indices32(), const Timestamp& timestamp = Timestamp(false), bool* reallocated = nullptr);
2474 
2475  /**
2476  * Updates the memory pointer for a specific plane of the frame to a new read-only memory location.
2477  * This function should only be used if the specified plane does not own its memory to ensure that the frame's ownership behavior remains consistent.
2478  * @param data The new read-only memory pointer to be set, must be valid
2479  * @param planeIndex The index of the frame's plane for which the memory will be updated, with range [0, numberPlanes())
2480  * @return True, if succeeded; False, if e.g., the plane to update owned the memory
2481  * @see isPlaneOwner().
2482  */
2483  template <typename T>
2484  bool updateMemory(const T* data, const unsigned int planeIndex = 0u);
2485 
2486  /**
2487  * Updates the memory pointer for a specific plane of the frame to a new read-only or writable memory location.
2488  * This function should only be used if the specified plane currently does not own its memory to ensure that the frame's ownership behavior remains consistent.
2489  * For read-only memory, provide a const memory pointer; For writable memory, provide a non-const pointer.
2490  * @param data The new writable memory pointer to be set, must be valid
2491  * @param planeIndex The index of the frame's plane for which the memory will be updated, with range [0, numberPlanes())
2492  * @return True, if succeeded; False, if e.g., the plane to update owned the memory
2493  * @see isPlaneOwner().
2494  */
2495  template <typename T>
2496  bool updateMemory(T* data, const unsigned int planeIndex = 0u);
2497 
2498  /**
2499  * Updates the memory pointers for all or some of the planes of the frame to new writable memory locations.
2500  * This function should be used only when the planes do not own their memory, to maintain consistent ownership behavior across the frame.
2501  * @param planeDatas The new writable memory pointers to be set, the number of pointers provided should be at least one and at most equal to numberPlanes().
2502  * @return True, if succeeded; False, if e.g., the plane to update owned the memory
2503  * @see isPlaneOwner().
2504  */
2505  template <typename T>
2506  bool updateMemory(const std::initializer_list<T*>& planeDatas);
2507 
2508  /**
2509  * Makes the memory of this frame continuous.
2510  * If the memory is already continuous, nothing happens.<br>
2511  * If the memory is not continuous, a new continuous memory block will be allocated and the memory is copied into the new memory block (for each plane individually), the frame will be owner of the memory.
2512  */
2514 
2515  /**
2516  * Makes this frame the owner of the memory.
2517  * In case this frame does not own the memory, new memory will be allocated.
2518  */
2519  void makeOwner();
2520 
2521  /**
2522  * Returns a sub-frame of this frame.
2523  * The copy mode defines whether the resulting sub-frame owns the memory or uses the memory.
2524  * @param subFrameLeft Left start location of the resulting sub-frame, in pixels, defined within this frame, with range [0, width - 1], must be 0 if the pixel format is packed
2525  * @param subFrameTop Top start location of the resulting sub-frame, in pixels, defined within this frame, with range [0, height - 1]
2526  * @param subFrameWidth Width of the resulting sub-frame in pixels, with range [1, width() - subFrameLeft]
2527  * @param subFrameHeight Height of the resulting sub-frame in pixels, with range [1, height() - subFrameTop]
2528  * @param copyMode The copy mode to be applied, must not be CM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA
2529  * @return The requested sub-frame not owning the image data, an invalid frame if the defined sub-region does not fit into this frame
2530  * @see FrameType::formatIsPacked().
2531  */
2532  Frame subFrame(const unsigned int subFrameLeft, const unsigned int subFrameTop, const unsigned int subFrameWidth, const unsigned int subFrameHeight, const CopyMode copyMode = CM_USE_KEEP_LAYOUT) const;
2533 
2534  /**
2535  * Sets the memory of the frame to a specified byte value (the memory of one plane).
2536  * Each byte of the frame's memory will be set to the same value.
2537  *
2538  * The following code snippet shows how this function may be used:
2539  * @code
2540  * Frame rgbFrame(FrameType(1920u, 1080u, FrameType::FORMAT_RGB24, FrameType::ORIGIN_UPPER_LEFT));
2541  * rgbFrame.setValue(0x00u);
2542  * @endcode
2543  * @param value The 8 bit value to be set to each byte of the frame, with range [0, 255]
2544  * @param planeIndex The index of the plane for which the memory will be set, with range [0, numberPlanes())
2545  * @param skipPaddingData True, to do not set the memory value of the padding data; False, to write the memory value of the padding data as well
2546  * @return True, if the image data was writable; False, if the image holds read-only memory
2547  * @see isReadOnly().
2548  */
2549  bool setValue(const uint8_t value, const unsigned int planeIndex = 0u, const bool skipPaddingData = true);
2550 
2551  /**
2552  * Sets the memory of the frame to a specified pixel value (the memory of one plane).
2553  * Each pixel will be set to the same values (each channel will be set to an own value).
2554  *
2555  * The following code snippet shows how this function may be used:
2556  * @code
2557  * Frame rgbFrame(FrameType(1920u, 1080u, FrameType::FORMAT_RGB24, FrameType::ORIGIN_UPPER_LEFT));
2558  * const Frame::PixelType<uint8_t, 3u> yellow({0xFFu, 0xFFu, 0x00u});
2559  * rgbFrame.setValue<uint8_t, 3u>(yellow);
2560  *
2561  * Frame tensorFrame(FrameType(1920u, 1080u, FrameType::genericPixelFormat<float, 3u>(), FrameType::ORIGIN_UPPER_LEFT));
2562  * const Frame::PixelType<float, 3u> value({0.0f, 1.0f, 2.0f});
2563  * tensorFrame.setValue<float, 3u>(value);
2564  * @endcode
2565  * @param planePixelValue The pixel value to be set to each pixel
2566  * @param planeIndex The index of the plane for which the memory will be set, with range [0, numberPlanes())
2567  * @tparam T The data type of the given pixel value, must be identical to the data type of the frame
2568  * @tparam tPlaneChannels The number of channels the plane has (not the number of channels the frame has), with range [1, channels()]
2569  * @return True, if the image data was writable; False, if the image holds read-only memory
2570  */
2571  template <typename T, const unsigned int tPlaneChannels>
2572  bool setValue(const PixelType<T, tPlaneChannels>& planePixelValue, const unsigned int planeIndex = 0u);
2573 
2574  /**
2575  * Sets the memory of the frame to a specified pixel value (the memory of one plane).
2576  * Each pixel will be set to the same values (each channel will be set to an own value).
2577  *
2578  * The following code snippet shows how this function may be used:
2579  * @code
2580  * Frame rgbFrame(FrameType(1920u, 1080u, FrameType::FORMAT_RGB24, FrameType::ORIGIN_UPPER_LEFT));
2581  * rgbFrame.setValue<uint8_t>(CV::Canvas::yellow(), 3u);
2582  * @endcode
2583  * @param planePixelValue The pixel value to be set to each pixel, one value for each plane channel, must be valid
2584  * @param planePixelValueSize The number of provided pixel values, with range [1, 4], must be `planes().channels()`
2585  * @param planeIndex The index of the plane for which the memory will be set, with range [0, numberPlanes())
2586  * @tparam T The data type of the given pixel value, must be identical to the data type of the frame
2587  * @return True, if the image data was writable; False, if the image holds read-only memory
2588  */
2589  template <typename T>
2590  bool setValue(const T* planePixelValue, const size_t planePixelValueSize, const unsigned int planeIndex = 0u);
2591 
2592  /**
2593  * Sets the memory of the frame to a specified pixel value (the memory of one plane).
2594  * Each pixel will be set to the same values (each channel will be set to an own value).
2595  *
2596  * The following code snippet shows how this function may be used:
2597  * @code
2598  * Frame rgbFrame(FrameType(1920u, 1080u, FrameType::FORMAT_RGB24, FrameType::ORIGIN_UPPER_LEFT));
2599  * rgbFrame.setValue<uint8_t>({0xFFu, 0xFFu, 0x00u});
2600  *
2601  * Frame tensorFrame(FrameType(1920u, 1080u, FrameType::genericPixelFormat<float, 3u>(), FrameType::ORIGIN_UPPER_LEFT));
2602  * tensorFrame.setValue<float>({0.0f, 1.0f, 2.0f});
2603  * @endcode
2604  * @param planePixelValues The pixel values to be set to each pixel, one value for each plane channel
2605  * @param planeIndex The index of the plane for which the memory will be set, with range [0, numberPlanes())
2606  * @tparam T The data type of the given pixel value, must be identical to the data type of the frame
2607  * @return True, if the image data was writable; False, if the image holds read-only memory
2608  */
2609  template <typename T>
2610  bool setValue(const std::initializer_list<typename Identity<T>::Type>& planePixelValues, const unsigned int planeIndex = 0u);
2611 
2612  /**
2613  * Returns whether the frame (one plane) contains a specified pixel value.
2614  * @param planePixelValue The pixel value to be checked
2615  * @param planeIndex The index of the plane for which the memory will be set, with range [0, numberPlanes())
2616  * @tparam T The data type of the given pixel value, must be identical to the data type of the frame
2617  * @tparam tPlaneChannels The number of channels the plane has (not the number of channels the frame has), with range [1, channels()]
2618  * @return True, if at least one pixel has the specified value
2619  */
2620  template <typename T, const unsigned int tPlaneChannels>
2621  bool containsValue(const PixelType<T, tPlaneChannels>& planePixelValue, const unsigned int planeIndex = 0u) const;
2622 
2623  /**
2624  * Returns the number of bytes necessary for a specific plane including optional padding at the end of plane rows.
2625  * @param planeIndex The index of the plane for which the check is done, with range [0, planes().size())
2626  * @return Frame buffer size in bytes, with range [0, infinity)
2627  */
2628  inline unsigned int size(const unsigned int planeIndex = 0u) const;
2629 
2630  /**
2631  * Returns the optional number of padding elements at the end of each row for a specific plane.
2632  * @param planeIndex The index of the plane for which the number of padding elements will be returned, with range [0, planes().size())
2633  * @return The frame's number of padding elements, in elements, with range [0, infinity)
2634  */
2635  inline unsigned int paddingElements(const unsigned int planeIndex = 0u) const;
2636 
2637  /**
2638  * Returns the optional number of padding bytes at the end of each row for a specific plane.
2639  * @param planeIndex The index of the plane for which the number of padding bytes will be returned, with range [0, planes().size())
2640  * @return The frame's number of padding bytes, in bytes, with range [0, infinity)
2641  */
2642  inline unsigned int paddingBytes(const unsigned int planeIndex = 0u) const;
2643 
2644  /**
2645  * Returns the number of elements within one row, including optional padding at the end of a row for a specific plane.
2646  * The number of elements per row is be determined by the plane's values: pixels * elementsPerPixel + paddingElements().
2647  * @param planeIndex The index of the plane for which the number of stride elements will be returned, with range [0, planes().size())
2648  * @return The frame's stride defined in elements, with range [width * elementsPerPixel, infinity)
2649  */
2650  inline unsigned int strideElements(const unsigned int planeIndex = 0u) const;
2651 
2652  /**
2653  * Returns the number of bytes within one row, including optional padding at the end of a row for a specific plane.
2654  * @param planeIndex The index of the plane for which the number of stride bytes will be returned, with range [0, planes().size())
2655  * @return The frame's stride defined in bytes, with range [pixels * elementsPerPixel * bitsPerDatatype() / 8, infinity)
2656  */
2657  inline unsigned int strideBytes(const unsigned int planeIndex = 0u) const;
2658 
2659  /**
2660  * Returns the width of a plane of this frame.
2661  * @param planeIndex The index of the plane for which the width will be returned, with range [0, planes().size())
2662  * @return The plane's width, in pixel, with range [0, infinity)
2663  */
2664  inline unsigned int planeWidth(const unsigned int planeIndex) const;
2665 
2666  /**
2667  * Returns the height of a plane of this frame.
2668  * @param planeIndex The index of the plane for which the height will be returned, with range [0, planes().size())
2669  * @return The plane's height, in pixel, with range [0, infinity)
2670  */
2671  inline unsigned int planeHeight(const unsigned int planeIndex) const;
2672 
2673  /**
2674  * Returns the channels of a plane of this frame.
2675  * @param planeIndex The index of the plane for which the channels will be returned, with range [0, planes().size())
2676  * @return The plane's channels, with range [0, infinity)
2677  */
2678  inline unsigned int planeChannels(const unsigned int planeIndex) const;
2679 
2680  /**
2681  * Returns the width of a plane of this frame, not in pixel, but in elements, not including padding at the end of each plane row.
2682  * @param planeIndex The index of the plane for which the width will be returned, with range [0, planes().size())
2683  * @return The plane's width, in elements, with is `planeWidth(planeIndex) * planeChannels(planeIndex)`, with range [0, infinity)
2684  */
2685  inline unsigned int planeWidthElements(const unsigned int planeIndex) const;
2686 
2687  /**
2688  * Returns the width of a plane of this frame, not in pixel, but in bytes, not including padding at the end of each plane row.
2689  * @param planeIndex The index of the plane for which the width will be returned, with range [0, planes().size())
2690  * @return The plane's width, in bytes, with range [0, infinity)
2691  */
2692  inline unsigned int planeWidthBytes(const unsigned int planeIndex) const;
2693 
2694  /**
2695  * Returns the number of bytes of one pixel of a plane for a pixel format.
2696  * Beware: This function will return 0 if the pixel format is a special packed format (e.g., FORMAT_Y10_PACKED) which does not allow to calculate the number of bytes per pixel.
2697  * @param planeIndex The index of the plane for which the bytes per pixel will be returned, with range [0, numberPlanes(imagePixelFormat))
2698  * @return The plane's number of bytes per pixel, will be 0 for special packed pixel formats like FORMAT_Y10_PACKED
2699  */
2700  inline unsigned int planeBytesPerPixel(const unsigned int planeIndex) const;
2701 
2702  /**
2703  * Returns whether a specific plane of this frame is based on continuous memory and thus does not have any padding at the end of rows.
2704  * @param planeIndex The index of the plane for which the check is done, with range [0, planes().size())
2705  * @return True, if so
2706  */
2707  inline bool isPlaneContinuous(const unsigned int planeIndex = 0u) const;
2708 
2709  /**
2710  * Returns whether a specific plane of this frame is the owner of the memory.
2711  * @param planeIndex The index of the plane for which the check is done, with range [0, planes().size())
2712  * @return True, if so
2713  */
2714  inline bool isPlaneOwner(const unsigned int planeIndex = 0u) const;
2715 
2716  /**
2717  * Returns the timestamp of this frame.
2718  * @return Timestamp
2719  */
2720  inline const Timestamp& timestamp() const;
2721 
2722  /**
2723  * Returns the relative timestamp of this frame.
2724  * @return Timestamp
2725  */
2726  inline const Timestamp& relativeTimestamp() const;
2727 
2728  /**
2729  * Sets the timestamp of this frame.
2730  * @param timestamp Timestamp to be set
2731  * @see setRelativeTimestamp().
2732  */
2733  inline void setTimestamp(const Timestamp& timestamp);
2734 
2735  /**
2736  * Sets the relative timestamp of this frame.
2737  * In contrast to the standard timestamp of this frame, the relative timestamp provides the frame time in relation to a reference time.<br>
2738  * @param relative The relative timestamp to be set
2739  * @see setTimestamp().
2740  */
2741  inline void setRelativeTimestamp(const Timestamp& relative);
2742 
2743  /**
2744  * Releases this frame and the frame data if this frame is the owner.
2745  */
2746  void release();
2747 
2748  /**
2749  * Returns a pointer to the pixel data of a specific plane.
2750  * Ensure that the frame holds writable pixel data before calling this function.
2751  * @param planeIndex The index of the plane for which the data will be returned, with range [0, planes().size())
2752  * @return The plane's writable pixel data
2753  * @tparam T The explicit data type of the value of each pixel channel
2754  * @see isValid(), isReadOnly().
2755  */
2756  template <typename T>
2757  inline T* data(const unsigned int planeIndex = 0u);
2758 
2759  /**
2760  * Returns a pointer to the read-only pixel data of a specific plane.
2761  * @param planeIndex The index of the plane for which the data will be returned, with range [0, planes().size())
2762  * @return The plane's read-only pixel data
2763  * @tparam T The explicit data type of the value of each pixel channel
2764  * @see isValid().
2765  */
2766  template <typename T>
2767  inline const T* constdata(const unsigned int planeIndex = 0u) const;
2768 
2769  /**
2770  * Returns the pointer to the pixel data of a specific row.
2771  * Ensure that the frame is valid and that the frame holds a valid frame buffer before this function is called.
2772  *
2773  * The index of the row is defined with respect to the origin of the frame's data.<br>
2774  * Therefore, row<T>(0) will return the top row of an image if pixelOrigin() == ORIGIN_UPPER_LEFT,<br>
2775  * and will return the bottom row of an image if pixelOrigin() == ORIGIN_LOWER_LEFT.<br>
2776  * In any case, row<T>(0) is equivalent to data<T>().
2777  *
2778  * @param y The index of the row (the vertical location) to which the resulting pointer will point, with range [0, planeHeight(planeIndex) - 1]
2779  * @param planeIndex The index of the plane for which the pixel will be returned, with range [0, planes().size())
2780  * @return The pointer to the memory at which the row starts
2781  * @tparam T The explicit data type of the value of each pixel channel
2782  * @see data(), pixel(), constrow(), constdata(), constpixel().
2783  */
2784  template <typename T>
2785  inline T* row(const unsigned int y, const unsigned int planeIndex = 0u);
2786 
2787  /**
2788  * Returns the pointer to the constant data of a specific row.
2789  * Ensure that the frame is valid and that the frame holds a valid frame buffer before this function is called.
2790  *
2791  * The index of the row is defined with respect to the origin of the frame's data.<br>
2792  * Therefore, constrow<T>(0) will return the top row of an image if pixelOrigin() == ORIGIN_UPPER_LEFT,<br>
2793  * and will return the bottom row of an image if pixelOrigin() == ORIGIN_LOWER_LEFT.<br>
2794  * In any case, constrow<T>(0) is equivalent to constdata<T>().
2795  *
2796  * @param y The index of the row (the vertical location) to which the resulting pointer will point, with range [0, planeHeight(planeIndex) - 1]
2797  * @param planeIndex The index of the plane for which the pixel will be returned, with range [0, planes().size())
2798  * @return The pointer to the memory at which the row starts
2799  * @tparam T The explicit data type of the value of each pixel channel
2800  * @see data(), pixel(), constrow(), constdata(), constpixel().
2801  */
2802  template <typename T>
2803  inline const T* constrow(const unsigned int y, const unsigned int planeIndex = 0u) const;
2804 
2805  /**
2806  * Returns the pointer to the data of a specific pixel.
2807  * Ensure that the frame is valid and that the frame holds a valid frame buffer before this function is called.
2808  *
2809  * In general, the usage of this function is recommended for prototyping only.<br>
2810  * As the location of each pixel has to be calculated every time, this function is quite slow.<br>
2811  * Production code should use the constdata(), data(), constrow(), and row() functions instead.
2812  *
2813  * The vertical location (the y coordinate) of the pixel is defined with respect to the origin of the frame's data.<br>
2814  * Therefore, pixel(0, 0) will return the top left pixel of an image if pixelOrigin() == ORIGIN_UPPER_LEFT,<br>
2815  * and will return the bottom left pixel of an image if pixelOrigin() == ORIGIN_LOWER_LEFT.<br>
2816  * In any case, pixel(0, 0) is equivalent to data().
2817  *
2818  * This function most not be called for packed pixel formats.
2819  *
2820  * @param x The horizontal position of the requested pixel, with range [0, planeWidth(planeIndex) - 1]
2821  * @param y The vertical position of the requested pixel, with range [0, planeHeight(planeIndex) - 1]
2822  * @param planeIndex The index of the plane for which the pixel will be returned, with range [0, planes().size())
2823  * @return The pointer to the memory at which the pixel starts
2824  * @tparam T The explicit data type of the value of each pixel channel
2825  * @see data(), row(), constpixel(), constdata(), constrow(). formatIsPacked().
2826  *
2827  *
2828  * The following code snippet shows how this function may be used:
2829  * @code
2830  * // we create a RGB image with 24 bit per pixel (8 bit per channel)
2831  * Frame rgbImage(FrameType(1280u, 720u, FrameType::FORMAT_RGB24, FrameType::ORIGIN_UPPER_LEFT));
2832  *
2833  * const uint8_t redChannelValue = 0xFF; // 255
2834  * const uint8_t greenChannelValue = 0x80; // 128
2835  * const uint8_t blueChannelValue = 0x00; // 0
2836  *
2837  * // we iterate overall every pixel
2838  * for (unsigned int y = 0u; y < rgbImage.height(); ++y)
2839  * {
2840  * for (unsigned int x = 0u; x < rgbImage.width(); ++x)
2841  * {
2842  * // we store the pointer to the pixel
2843  * uint8_t* rgbPixel = rgbImage.pixel<uint8_t>(x, y);
2844  *
2845  * // we set the color value of each red channel and green channel
2846  * rgbPixel[0] = redChannelValue;
2847  * rgbPixel[1] = greenChannelValue;
2848  *
2849  * // we also can set the value of each channel directly
2850  * rgbImage.pixel<uint8_t>(x, y)[2] = blueChannelValue;
2851  * }
2852  * }
2853  *
2854  * // now we have set the color of every pixel of the image
2855  * @endcode
2856  */
2857  template <typename T>
2858  inline T* pixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex = 0u);
2859 
2860  /**
2861  * Returns the pointer to the constant data of a specific pixel.
2862  * Ensure that the frame is valid and that the frame holds a valid frame buffer before this function is called.
2863  *
2864  * In general, the usage of this function is recommended for prototyping only.<br>
2865  * As the location of each pixel has to be calculated every time, this function is quite slow.<br>
2866  * Production code should use the constdata(), data(), constrow(), and row() functions instead.
2867  *
2868  * The vertical location (the y coordinate) of the pixel is defined with respect to the origin of the frame's data.<br>
2869  * Therefore, pixel<T>(0, 0) will return the top left pixel of an image if pixelOrigin() == ORIGIN_UPPER_LEFT,<br>
2870  * and will return the bottom left pixel of an image if pixelOrigin() == ORIGIN_LOWER_LEFT.<br>
2871  * In any case, pixel<T>(0, 0) is equivalent to data<T>().
2872  *
2873  * This function most not be called for packed pixel formats.
2874  *
2875  * @param x The horizontal position of the requested pixel, with range [0, planeWidth(planeIndex) - 1]
2876  * @param y The vertical position of the requested pixel, with range [0, planeHeight(planeIndex) - 1]
2877  * @param planeIndex The index of the plane for which the pixel will be returned, with range [0, planes().size())
2878  * @return The pointer to the memory at which the pixel starts
2879  * @tparam T The explicit data type of the value of each pixel channel
2880  * @see data(), row(), pixel(), constdata(), constrow(), formatIsPacked().
2881  */
2882  template <typename T>
2883  inline const T* constpixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex = 0u) const;
2884 
2885  /**
2886  * Returns whether all planes of this frame have continuous memory and thus do not contain any padding at the end of their rows.
2887  * @return True, if so
2888  */
2889  inline bool isContinuous() const;
2890 
2891  /**
2892  * Returns whether the frame is the owner of the internal frame data.
2893  * Otherwise the frame data is stored by e.g., a 3rd party and this frame holds a reference only.<br>
2894  * The frame is not owner of the memory if at least one plane is not owner of the memory.
2895  * @return True, if so
2896  * @see Plane::isOwner().
2897  */
2898  inline bool isOwner() const;
2899 
2900  /**
2901  * Returns true, if the frame allows only read access (using constdata()). Otherwise, data() may be used to modify the frame data.
2902  * Beware: Call this method only if the frame is valid.
2903  * The frame is read-only if at least one plane is read-only.
2904  * @return True, if the frame object allows read access only
2905  * @see data(), constdata(), Plane::isReadOnly().
2906  */
2907  inline bool isReadOnly() const;
2908 
2909  /**
2910  * Returns whether the frame's pixel format contains an alpha channel.
2911  * @return True, if so
2912  */
2913  inline bool hasAlphaChannel() const;
2914 
2915  /**
2916  * Returns whether the frame holds at least one pixel with an non opaque alpha value.
2917  * The pixel format must be composed of one plane only.
2918  * @return True, if so
2919  * @tparam T The type of the frame's data type, either `uint8_t`, or `uint16_t`
2920  */
2921  template <typename T>
2922  bool hasTransparentPixel(const T opaque) const;
2923 
2924  /**
2925  * Returns whether this frame is valid.
2926  * This function is mainly callying `FrameType::isValid()`, while in debug builds, addtional checks are performed.
2927  * @return True, if so
2928  */
2929  inline bool isValid() const;
2930 
2931  /**
2932  * Returns whether two frame objects have any amount of intersecting memory.
2933  * This frame and the given frame must both be valid.<br>
2934  * Use this function to ensure that e.g., a source buffer and target buffer is completely independent.<br>
2935  * This functions also considers memory intersections in the padding area as regular intersection.
2936  * @param frame The second frame of which its memory will be compared to the memory of this frame, must be valid
2937  * @return True, if so
2938  */
2939  bool haveIntersectingMemory(const Frame& frame) const;
2940 
2941  /**
2942  * Returns whether this frame object is valid and holds a frame.
2943  * @return True, if so
2944  */
2945  explicit inline operator bool() const;
2946 
2947  /**
2948  * Assign operator.
2949  * Releases the current frame (and frees the memory if the frame is the owner) and creates a second version of a given frame.
2950  * If the given source frame is not owner of the frame data, this frame will also not be owner of the frame data.<br>
2951  * But, if the given source frame is the owner of the frame data, this frame will also be the owner of new copy of the frame data.<br>
2952  * If the memory is actually copied, the memory layout of this new frame will be continuous.
2953  * This function behaves similar like the normal copy constructor.
2954  * @param right The right frame to assign
2955  * @return Reference to this frame
2956  */
2957  Frame& operator=(const Frame& right) noexcept;
2958 
2959  /**
2960  * Move operator.
2961  * @param right The right frame to moved
2962  * @return Reference to this frame
2963  */
2964  Frame& operator=(Frame&& right) noexcept;
2965 
2966  /**
2967  * Determines the number of padding elements at the end of a row of a plane for which the pixel format, the image width and the plane's stride (in bytes) are known.
2968  * @param pixelFormat The pixel format of the image, must be valid
2969  * @param imageWidth The width of the image in pixels, with range [0, infinity)
2970  * @param planeStrideBytes The number of bytes between to start points of successive rows (the stride of the row in bytes) for the specified image plane, with range [planeWidthBytes(planeIndex), infinity)
2971  * @param planePaddingElements The resulting number of padding elements at the end of each row (at the actual end of the row's pixel data) for the specified image plane, in elements (not bytes), with range [0, infinity)
2972  * @param planeIndex The index of the image plane for which the number of padding elements will be calculated, with range [0, numberPlanes() - 1]
2973  * @return True, if succeeded; False, if the given plane configuration is invalid
2974  */
2975  static bool strideBytes2paddingElements(const PixelFormat& pixelFormat, const unsigned int imageWidth, const unsigned int planeStrideBytes, unsigned int& planePaddingElements, const unsigned int planeIndex = 0u);
2976 
2977  protected:
2978 
2979  /**
2980  * Creates a new multi-plane frame with known frame type and given source memory for each individual plane.
2981  * @param frameType The data type of the new frame, must be valid
2982  * @param planeInitializers The initializers for the individual planes, one for each plane of the pixel format, must be valid
2983  * @param sizePlaneInitializers The number of specified initializers for the individual planes, must be frameType.numberPlanes()
2984  * @param timestamp The timestamp of the frame
2985  */
2986  Frame(const FrameType& frameType, const PlaneInitializer<void>* planeInitializers, size_t sizePlaneInitializers, const Timestamp& timestamp = Timestamp(false));
2987 
2988  /**
2989  * Deleted constructor to prevent misuse.
2990  * @param frame The frame to copy
2991  * @param copyData Determines whether this new frame will make an own copy of the given frame data or whether the pixel data is used only
2992  */
2993  Frame(const Frame& frame, const bool copyData) = delete;
2994 
2995  /**
2996  * Deleted constructor to prevent misuse.
2997  * @param frameType The frame type which would be used to create the object
2998  * @param copyMode The copy mode which would be used to create the object
2999  */
3000  Frame(const FrameType& frameType, const CopyMode copyMode) = delete;
3001 
3002  /**
3003  * Deleted constructor to prevent misuse.
3004  * @param frameType The frame type which would be used to create the object
3005  * @param avancedCopyMode The advanced copy mode which would be used to create the object
3006  */
3007  Frame(const FrameType& frameType, const AdvancedCopyMode avancedCopyMode) = delete;
3008 
3009  /**
3010  * Deleted constructor to prevent misuse, use `AdvancedCopyMode` instead.
3011  * @param frame The frame to be copied
3012  * @param copyMode The copy mode which would be used to create the object
3013  */
3014  Frame(const Frame& frame, const CopyMode copyMode) = delete;
3015 
3016  /**
3017  * Deleted constructor to prevent misuse.
3018  * @param frameType The frame type which would be used
3019  * @param timestamp The timestamp which would be used to create the object
3020  */
3021  Frame(const FrameType& frameType, const Timestamp& timestamp) = delete;
3022 
3023  /**
3024  * Deleted constructor to prevent misuse.
3025  * @param frame The frame to be copied
3026  * @param timestamp The timestamp which would be used to create the object
3027  */
3028  Frame(const Frame& frame, const Timestamp& timestamp) = delete;
3029 
3030  /**
3031  * Deleted constructor to prevent misuse, use `Frame(const FrameType& frameType, const T* data, const CopyMode copyMode, const unsigned int paddingElements = 0u, const Timestamp& timestamp = Timestamp(false));` instead.
3032  * @param frameType Type of the frame, must be valid
3033  * @param data Frame data to copy or to use, depending on the data copy flag
3034  * @param copyData Determines whether the frame will make an own copy of the given frame data or whether the pixel data are used only
3035  * @param paddingElements Optional number of elements at the end of each row, one pixel has (1 * channels) elements, must be 0 for non-generic pixel formats (e.g., Y_UV12), with range [0, infinity)
3036  * @param timestamp The timestamp of the frame
3037  * @tparam T The data type of each pixel element, e.g., 'uint8_t', 'uint16_t', or 'float', can be `void` to force the usage of the pixel element type as defined in `frameType.pixelFormat()`
3038  */
3039  template <typename T>
3040  Frame(const FrameType& frameType, const T* data, const bool copyData, const unsigned int paddingElements = 0u, const Timestamp& timestamp = Timestamp(false)) = delete;
3041 
3042  /**
3043  * Deleted constructor to prevent misuse, use `Frame(const FrameType& frameType, T* data, const CopyMode copyMode, const unsigned int paddingElements = 0u, const Timestamp& timestamp = Timestamp(false));` instead.
3044  * @param frameType Type of the frame
3045  * @param data Frame data to copy or to use, depending on the data copy flag
3046  * @param copyData Determines whether the frame will make an own copy of the given frame data or whether the pixel data are used only
3047  * @param paddingElements Optional number of elements at the end of each row, one pixel has (1 * channels) elements, must be 0 for non-generic pixel formats (e.g., Y_UV12), with range [0, infinity)
3048  * @param timestamp The timestamp of the frame
3049  * @tparam T The data type of each pixel element, e.g., 'uint8_t', 'uint16_t', or 'float', can be `void` to force the usage of the pixel element type as defined in `frameType.pixelFormat()`
3050  */
3051  template <typename T>
3052  Frame(const FrameType& frameType, T* data, const bool copyData, const unsigned int paddingElements = 0u, const Timestamp& timestamp = Timestamp(false)) = delete;
3053 
3054  protected:
3055 
3056  /// The individual memory planes of this frame.
3058 
3059  /// Timestamp of the frame.
3061 
3062  /// Relative timestamp of this frame.
3064 };
3065 
3067  pixelFormat_(pixelFormat)
3068 {
3069  // nothing to do here
3070 }
3071 
3072 inline FrameType::FrameType(const unsigned int width, const unsigned int height, const PixelFormat pixelFormat, const PixelOrigin pixelOrigin) :
3073  width_(width),
3074  height_(height),
3077 {
3078  if (isValid())
3079  {
3081  {
3082  ocean_assert(false && "The configuration of this frame type is invalid - this should never happen!");
3083 
3084  width_ = 0u;
3085  height_ = 0u;
3088 
3089  ocean_assert(!isValid());
3090  }
3091  }
3092 }
3093 
3094 inline FrameType::FrameType(const FrameType& type, const unsigned int width, const unsigned int height) :
3095  width_(width),
3096  height_(height),
3097  pixelFormat_(type.pixelFormat_),
3098  pixelOrigin_(type.pixelOrigin_)
3099 {
3100  if (isValid())
3101  {
3103  {
3104  ocean_assert(false && "The configuration of this frame type is invalid - this should never happen!");
3105 
3106  width_ = 0u;
3107  height_ = 0u;
3110 
3111  ocean_assert(!isValid());
3112  }
3113  }
3114 }
3115 
3116 inline FrameType::FrameType(const FrameType& type, const PixelFormat pixelFormat) :
3117  width_(type.width_),
3118  height_(type.height_),
3119  pixelFormat_(pixelFormat),
3120  pixelOrigin_(type.pixelOrigin_)
3121 {
3122  // nothing to do here
3123 }
3124 
3125 inline FrameType::FrameType(const FrameType& type, const PixelOrigin pixelOrigin) :
3126  width_(type.width_),
3127  height_(type.height_),
3128  pixelFormat_(type.pixelFormat_),
3129  pixelOrigin_(pixelOrigin)
3130 {
3131  // nothing to do here
3132 }
3133 
3134 inline FrameType::FrameType(const FrameType& type, const PixelFormat pixelFormat, const PixelOrigin pixelOrigin) :
3135  width_(type.width_),
3136  height_(type.height_),
3137  pixelFormat_(pixelFormat),
3138  pixelOrigin_(pixelOrigin)
3139 {
3140  // nothing to do here
3141 }
3142 
3143 inline unsigned int FrameType::width() const
3144 {
3145  return width_;
3146 }
3147 
3148 inline unsigned int FrameType::height() const
3149 {
3150  return height_;
3151 }
3152 
3154 {
3155  return pixelFormat_.pixelFormat_;
3156 }
3157 
3158 inline void FrameType::setPixelFormat(const PixelFormat pixelFormat)
3159 {
3161 }
3162 
3164 {
3166 }
3167 
3168 inline unsigned int FrameType::bytesPerDataType() const
3169 {
3170  return bytesPerDataType(dataType());
3171 }
3172 
3173 inline unsigned int FrameType::channels() const
3174 {
3176  {
3177  return 0u;
3178  }
3179 
3181 }
3182 
3183 inline uint32_t FrameType::numberPlanes() const
3184 {
3186 }
3187 
3189 {
3190  return pixelOrigin_;
3191 }
3192 
3193 inline unsigned int FrameType::pixels() const
3194 {
3195  return width_ * height_;
3196 }
3197 
3198 inline bool FrameType::isPixelFormatCompatible(const PixelFormat pixelFormat) const
3199 {
3200  return arePixelFormatsCompatible(this->pixelFormat(), pixelFormat);
3201 }
3202 
3203 inline bool FrameType::isFrameTypeCompatible(const FrameType& frameType, const bool allowDifferentPixelOrigins) const
3204 {
3205  return areFrameTypesCompatible(*this, frameType, allowDifferentPixelOrigins);
3206 }
3207 
3208 inline bool FrameType::operator!=(const FrameType& right) const
3209 {
3210  return !(*this == right);
3211 }
3212 
3213 inline bool FrameType::isValid() const
3214 {
3216 }
3217 
3218 inline uint32_t FrameType::numberPlanes(const PixelFormat pixelFormat)
3219 {
3220  return uint32_t((pixelFormat >> pixelFormatBitOffsetPlanes) & 0xFFull);
3221 }
3222 
3223 inline uint32_t FrameType::formatGenericNumberChannels(const PixelFormat pixelFormat)
3224 {
3225  return uint32_t((pixelFormat >> pixelFormatBitOffsetChannels) & 0xFFull);
3226 }
3227 
3228 template <>
3229 constexpr FrameType::DataType FrameType::dataType<char>()
3230 {
3231  static_assert(sizeof(char) == 1, "Invalid data type!");
3232 
3233  return (std::is_signed<char>::value) ? DT_SIGNED_INTEGER_8 : DT_UNSIGNED_INTEGER_8;
3234 }
3235 
3236 template <>
3237 constexpr FrameType::DataType FrameType::dataType<signed char>()
3238 {
3239  static_assert(sizeof(signed char) == 1, "Invalid data type!");
3240  return DT_SIGNED_INTEGER_8;
3241 }
3242 
3243 template <>
3244 constexpr FrameType::DataType FrameType::dataType<unsigned char>()
3245 {
3246  static_assert(sizeof(unsigned char) == 1, "Invalid data type!");
3247  return DT_UNSIGNED_INTEGER_8;
3248 }
3249 
3250 template <>
3251 constexpr FrameType::DataType FrameType::dataType<unsigned short>()
3252 {
3253  static_assert(sizeof(unsigned short) == 2, "Invalid data type!");
3254  return DT_UNSIGNED_INTEGER_16;
3255 }
3256 
3257 template <>
3258 constexpr FrameType::DataType FrameType::dataType<short>()
3259 {
3260  static_assert(sizeof(short) == 2, "Invalid data type!");
3261  return DT_SIGNED_INTEGER_16;
3262 }
3263 
3264 template <>
3265 constexpr FrameType::DataType FrameType::dataType<unsigned int>()
3266 {
3267  static_assert(sizeof(unsigned int) == 4, "Invalid data type!");
3268  return DT_UNSIGNED_INTEGER_32;
3269 }
3270 
3271 template <>
3272 constexpr FrameType::DataType FrameType::dataType<int>()
3273 {
3274  static_assert(sizeof(int) == 4, "Invalid data type!");
3275  return DT_SIGNED_INTEGER_32;
3276 }
3277 
3278 template <>
3279 constexpr FrameType::DataType FrameType::dataType<unsigned long>()
3280 {
3281  static_assert(sizeof(unsigned long) == 4 || sizeof(unsigned long) == 8, "Invalid data type!");
3282 
3283  return (sizeof(unsigned long) == 4) ? DT_UNSIGNED_INTEGER_32 : DT_UNSIGNED_INTEGER_64;
3284 }
3285 
3286 template <>
3287 constexpr FrameType::DataType FrameType::dataType<long>()
3288 {
3289  static_assert(sizeof(unsigned long) == 4 || sizeof(unsigned long) == 8, "Invalid data type!");
3290 
3291  return (sizeof(long) == 4) ? DT_SIGNED_INTEGER_32 : DT_SIGNED_INTEGER_64;
3292 }
3293 
3294 template <>
3295 constexpr FrameType::DataType FrameType::dataType<unsigned long long>()
3296 {
3297  static_assert(sizeof(unsigned long long) == 8, "Invalid data type!");
3298  return DT_UNSIGNED_INTEGER_64;
3299 }
3300 
3301 template <>
3302 constexpr FrameType::DataType FrameType::dataType<long long>()
3303 {
3304  static_assert(sizeof(long long) == 8, "Invalid data type!");
3305  return DT_SIGNED_INTEGER_64;
3306 }
3307 
3308 template <>
3309 constexpr FrameType::DataType FrameType::dataType<float>()
3310 {
3311  static_assert(sizeof(float) == 4, "Invalid data type!");
3312  return DT_SIGNED_FLOAT_32;
3313 }
3314 
3315 template <>
3316 constexpr FrameType::DataType FrameType::dataType<double>()
3317 {
3318  static_assert(sizeof(double) == 8, "Invalid data type!");
3319  return DT_SIGNED_FLOAT_64;
3320 }
3321 
3322 template <typename T>
3324 {
3325  return DT_UNDEFINED;
3326 }
3327 
3329 {
3330  ocean_assert(((pixelFormat >> pixelFormatBitOffsetDatatype) & 0xFFull) <= DT_SIGNED_FLOAT_64);
3331 
3332  return DataType((pixelFormat >> pixelFormatBitOffsetDatatype) & 0xFFull);
3333 }
3334 
3335 inline uint32_t FrameType::formatGenericBitsPerPixel(const PixelFormat pixelFormat)
3336 {
3338 }
3339 
3340 constexpr inline FrameType::PixelFormat FrameType::genericPixelFormat(const DataType dataType, const uint32_t channels, const uint32_t planes, const uint32_t widthMultiple, const uint32_t heightMultiple)
3341 {
3342  ocean_assert(uint8_t(dataType) > uint8_t(DT_UNDEFINED) && uint8_t(dataType) < DT_END);
3343  ocean_assert(channels >= 1u && channels <= 31u);
3344  ocean_assert(planes >= 1u && planes <= 255u);
3345  ocean_assert(widthMultiple >= 1u && widthMultiple <= 255u);
3346  ocean_assert(heightMultiple >= 1u && heightMultiple <= 255u);
3347 
3349 }
3350 
3351 template <FrameType::DataType tDataType, uint32_t tChannels, uint32_t tPlanes, uint32_t tWidthMultiple, uint32_t tHeightMultiple>
3353 {
3354  static_assert(uint8_t(tDataType) > uint8_t(DT_UNDEFINED) && uint8_t(tDataType) < DT_END, "Invalid data type!");
3355  static_assert(tChannels >= 1u && tChannels < 31u, "Invalid channel number!");
3356  static_assert(tPlanes >= 1u && tPlanes <= 255u, "Invalid plane number!");
3357  static_assert(tWidthMultiple >= 1u && tWidthMultiple <= 255u, "Invalid width-multiple!");
3358  static_assert(tHeightMultiple >= 1u && tHeightMultiple <= 255u, "Invalid height-multiple!");
3359 
3360  return genericPixelFormat(tDataType, tChannels, tPlanes, tWidthMultiple, tHeightMultiple);
3361 }
3362 
3363 template <FrameType::DataType tDataType>
3364 constexpr FrameType::PixelFormat FrameType::genericPixelFormat(const uint32_t channels, const uint32_t planes, const uint32_t widthMultiple, const uint32_t heightMultiple)
3365 {
3366  static_assert(uint8_t(tDataType) > uint8_t(DT_UNDEFINED) && uint8_t(tDataType) < DT_END, "Invalid data type!");
3367 
3368  return genericPixelFormat(tDataType, channels, planes, widthMultiple, heightMultiple);
3369 }
3370 
3371 template <typename TDataType, uint32_t tChannels, uint32_t tPlanes, uint32_t tWidthMultiple, uint32_t tHeightMultiple>
3373 {
3374  static_assert(tChannels >= 1u && tChannels < 31u, "Invalid channel number!");
3375  static_assert(tPlanes >= 1u && tPlanes <= 255u, "Invalid plane number!");
3376  static_assert(tWidthMultiple >= 1u && tWidthMultiple <= 255u, "Invalid width-multiple!");
3377  static_assert(tHeightMultiple >= 1u && tHeightMultiple <= 255u, "Invalid height-multiple!");
3378 
3379  constexpr DataType pixelFormatDataType = dataType<TDataType>();
3380  static_assert(uint8_t(pixelFormatDataType) > uint8_t(DT_UNDEFINED) && uint8_t(pixelFormatDataType) < DT_END, "Invalid data type!");
3381 
3382  return genericPixelFormat(pixelFormatDataType, tChannels, tPlanes, tWidthMultiple, tHeightMultiple);
3383 }
3384 
3385 template <typename TDataType>
3386 constexpr FrameType::PixelFormat FrameType::genericPixelFormat(const uint32_t channels, const uint32_t planes, const uint32_t widthMultiple, const uint32_t heightMultiple)
3387 {
3388  constexpr DataType pixelFormatDataType = dataType<TDataType>();
3389  static_assert(uint8_t(pixelFormatDataType) > uint8_t(DT_UNDEFINED) && uint8_t(pixelFormatDataType) < DT_END, "Invalid data type!");
3390 
3391  ocean_assert(channels >= 1u && channels <= 31u);
3392  ocean_assert(planes >= 1u && planes <= 255u);
3393  ocean_assert(widthMultiple >= 1u && widthMultiple <= 255u);
3394  ocean_assert(heightMultiple >= 1u && heightMultiple <= 255u);
3395 
3396  return genericPixelFormat(pixelFormatDataType, channels, planes, widthMultiple, heightMultiple);
3397 }
3398 
3400 {
3401  static_assert(std::is_same<std::underlying_type<PixelFormat>::type, uint64_t>::value, "Invalid pixel format data type!");
3402 
3403  return PixelFormat(pixelFormat & 0xFFFFFFFFFFFF0000ull); // Cf. documentation of enum PixelFormat
3404 }
3405 
3406 inline bool FrameType::formatIsGeneric(const PixelFormat pixelFormat, const DataType pixelFormatDataType, const uint32_t channels, const uint32_t planes, const uint32_t widthMultiple, const uint32_t heightMultiple)
3407 {
3409 }
3410 
3411 inline bool FrameType::formatIsGeneric(const PixelFormat pixelFormat)
3412 {
3414 }
3415 
3416 inline bool FrameType::formatIsPureGeneric(const PixelFormat pixelFormat)
3417 {
3418  static_assert(std::is_same<std::underlying_type<PixelFormat>::type, uint64_t>::value, "Invalid pixel format data type!");
3419 
3420  return (pixelFormat & 0x000000000000FFFFull) == 0u && formatIsGeneric(pixelFormat);
3421 }
3422 
3423 inline uint32_t FrameType::widthMultiple(const PixelFormat pixelFormat)
3424 {
3425  return uint32_t((pixelFormat >> pixelFormatBitOffsetWidthMultiple) & 0xFFull);
3426 }
3427 
3428 inline uint32_t FrameType::heightMultiple(const PixelFormat pixelFormat)
3429 {
3430  return uint32_t((pixelFormat >> pixelFormatBitOffsetHeightMultiple) & 0xFFull);
3431 }
3432 
3433 inline unsigned int FrameType::planeBytesPerPixel(const PixelFormat& imagePixelFormat, const unsigned int planeIndex)
3434 {
3435  unsigned int planeWidthDummy;
3436  unsigned int planeHeightDummy;
3437 
3438  unsigned int planeChannels;
3439 
3440  unsigned int planeWidthElementsMultiple;
3441  unsigned int planeHeightElementsMultiple;
3442 
3443  if (planeLayout(imagePixelFormat, widthMultiple(imagePixelFormat), heightMultiple(imagePixelFormat), planeIndex, planeWidthDummy, planeHeightDummy, planeChannels, &planeWidthElementsMultiple, &planeHeightElementsMultiple))
3444  {
3445  ocean_assert(planeChannels >= 1u && planeWidthElementsMultiple >= 1u && planeHeightElementsMultiple >= 1u);
3446 
3447  if (planeWidthElementsMultiple != 1u || planeHeightElementsMultiple != 1u)
3448  {
3449  // we have a packed pixel format for which we cannot calculate the number of bytes per pixel
3450  return 0u;
3451  }
3452 
3453  return planeChannels * bytesPerDataType(dataType(imagePixelFormat));
3454  }
3455  else
3456  {
3457  ocean_assert(false && "Invalid input!");
3458  return 0u;
3459  }
3460 }
3461 
3462 inline bool FrameType::planeLayout(const FrameType& frameType, const unsigned int planeIndex, unsigned int& planeWidth, unsigned int& planeHeight, unsigned int& planeChannels, unsigned int* planeWidthElementsMultiple, unsigned int* planeHeightElementsMultiple)
3463 {
3464  ocean_assert(frameType.isValid());
3465 
3466  return planeLayout(frameType.pixelFormat(), frameType.width(), frameType.height(), planeIndex, planeWidth, planeHeight, planeChannels, planeWidthElementsMultiple, planeHeightElementsMultiple);
3467 }
3468 
3469 template <typename T>
3470 inline bool FrameType::dataIsAligned(const void* data)
3471 {
3472  ocean_assert(data != nullptr);
3473  return size_t(data) % sizeof(T) == size_t(0);
3474 }
3475 
3476 inline Frame::Plane::Plane(Plane&& plane) noexcept
3477 {
3478  *this = std::move(plane);
3479 }
3480 
3481 template <typename T>
3482 inline Frame::Plane::Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const T* dataToUse, const unsigned int paddingElements) noexcept :
3483  Plane(width, height, channels, sizeof(T), (const void*)dataToUse, paddingElements)
3484 {
3485  // nothing to do here
3486 }
3487 
3488 template <typename T>
3489 inline Frame::Plane::Plane(const unsigned int width, const unsigned int height, const unsigned int channels, T* dataToUse, const unsigned int paddingElements) noexcept :
3490  Plane(width, height, channels, sizeof(T), (void*)dataToUse, paddingElements)
3491 {
3492  // nothing to do here
3493 }
3494 
3495 template <typename T>
3496 inline Frame::Plane::Plane(const T* sourceDataToCopy, const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int targetPaddingElements, const unsigned int sourcePaddingElements, const bool makeCopyOfPaddingData) noexcept :
3497  Plane(width, height, channels, sizeof(T), (const void*)sourceDataToCopy, targetPaddingElements, sourcePaddingElements, makeCopyOfPaddingData)
3498 {
3499  // nothing to do here
3500 }
3501 
3502 template <typename T>
3503 inline Frame::Plane::Plane(const T* sourceDataToCopy, const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int sourcePaddingElements, const CopyMode copyMode) noexcept :
3504  Plane(width, height, channels, sizeof(T), (const void*)sourceDataToCopy, sourcePaddingElements, copyMode)
3505 {
3506  // nothing to do here
3507 }
3508 
3509 inline Frame::Plane::Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const void* constData, void* data, const unsigned int paddingElements) noexcept :
3510  allocatedData_(nullptr),
3511  constData_(constData),
3512  data_(data),
3513  width_(width),
3514  height_(height),
3515  channels_(channels),
3516  elementTypeSize_(elementTypeSize),
3517  paddingElements_(paddingElements)
3518 {
3519  strideBytes_ = calculateStrideBytes();
3520  bytesPerPixel_ = calculateBytesPerPixel();
3521 }
3522 
3524 {
3525  release();
3526 }
3527 
3528 inline unsigned int Frame::Plane::width() const
3529 {
3530  return width_;
3531 }
3532 
3533 inline unsigned int Frame::Plane::height() const
3534 {
3535  return height_;
3536 }
3537 
3538 inline unsigned int Frame::Plane::channels() const
3539 {
3540  return channels_;
3541 }
3542 
3543 template <typename T>
3544 inline const T* Frame::Plane::constdata() const
3545 {
3546  return reinterpret_cast<const T*>(constData_);
3547 }
3548 
3549 template <typename T>
3551 {
3552  return reinterpret_cast<T*>(data_);
3553 }
3554 
3555 inline unsigned int Frame::Plane::paddingElements() const
3556 {
3557  return paddingElements_;
3558 }
3559 
3560 inline unsigned int Frame::Plane::paddingBytes() const
3561 {
3562  return paddingElements_ * elementTypeSize_;
3563 }
3564 
3565 inline unsigned int Frame::Plane::elementTypeSize() const
3566 {
3567  return elementTypeSize_;
3568 }
3569 
3570 inline unsigned int Frame::Plane::widthElements() const
3571 {
3572  return width_ * channels_;
3573 }
3574 
3575 inline unsigned int Frame::Plane::widthBytes() const
3576 {
3577  return widthElements() * elementTypeSize_;
3578 }
3579 
3580 inline unsigned int Frame::Plane::strideElements() const
3581 {
3582  return width_ * channels_ + paddingElements_;
3583 }
3584 
3585 inline unsigned int Frame::Plane::strideBytes() const
3586 {
3587  ocean_assert(width_ == 0u || strideBytes_ != 0u);
3588  ocean_assert(strideBytes_ == calculateStrideBytes()); // ensuring that stride bytes is actually correct
3589 
3590  return strideBytes_;
3591 }
3592 
3593 inline unsigned int Frame::Plane::bytesPerPixel() const
3594 {
3595  ocean_assert(bytesPerPixel_ == calculateBytesPerPixel());
3596 
3597  return bytesPerPixel_;
3598 }
3599 
3600 template <typename T>
3602 {
3603  return elementTypeSize_ == sizeof(T);
3604 }
3605 
3606 inline unsigned int Frame::Plane::size() const
3607 {
3608  return strideBytes() * height_;
3609 }
3610 
3611 inline bool Frame::Plane::isContinuous() const
3612 {
3613  return paddingElements_ == 0u;
3614 }
3615 
3616 inline bool Frame::Plane::isOwner() const
3617 {
3618  return allocatedData_ != nullptr;
3619 }
3620 
3621 inline bool Frame::Plane::isReadOnly() const
3622 {
3623  return data_ == nullptr;
3624 }
3625 
3626 inline bool Frame::Plane::isValid() const
3627 {
3628  return width_ != 0u && height_ != 0u && channels_ != 0u;
3629 }
3630 
3631 inline unsigned int Frame::Plane::calculateStrideBytes() const
3632 {
3633  return strideElements() * elementTypeSize_;
3634 }
3635 
3636 template <typename T>
3637 inline Frame::PlaneInitializer<T>::PlaneInitializer(const T* constdata, const CopyMode copyMode, const unsigned int dataPaddingElements) :
3638  constdata_(constdata),
3639  data_(nullptr),
3640  copyMode_(copyMode),
3641  paddingElements_(dataPaddingElements)
3642 {
3643  // nothing to do here
3644 }
3645 
3646 template <typename T>
3647 inline Frame::PlaneInitializer<T>::PlaneInitializer(T* data, const CopyMode copyMode, const unsigned int dataPaddingElements) :
3648  constdata_(nullptr),
3649  data_(data),
3650  copyMode_(copyMode),
3651  paddingElements_(dataPaddingElements)
3652 {
3653  // nothing to do here
3654 }
3655 
3656 template <typename T>
3657 inline Frame::PlaneInitializer<T>::PlaneInitializer(const unsigned int planePaddingElements) :
3658  constdata_(nullptr),
3659  data_(nullptr),
3660  copyMode_(CM_USE_KEEP_LAYOUT),
3661  paddingElements_(planePaddingElements)
3662 {
3663  // nothing to do here
3664 }
3665 
3666 template <typename T>
3667 std::vector<Frame::PlaneInitializer<T>> Frame::PlaneInitializer<T>::createPlaneInitializersWithPaddingElements(const Indices32& paddingElementsPerPlane)
3668 {
3669  PlaneInitializers<T> planeInitializers;
3670  planeInitializers.reserve(paddingElementsPerPlane.size());
3671 
3672  for (const Index32& paddingElements : paddingElementsPerPlane)
3673  {
3674  planeInitializers.emplace_back(paddingElements);
3675  }
3676 
3677  return planeInitializers;
3678 }
3679 
3680 inline Frame::Frame() :
3681  FrameType(),
3682  planes_(1, Plane())
3683 {
3684  // nothing to do here
3685 }
3686 
3687 inline Frame::Frame(Frame&& frame) noexcept :
3688  FrameType()
3689 {
3690  *this = std::move(frame);
3691 
3692  ocean_assert(planes_.size() >= 1);
3693  ocean_assert(frame.planes_.size() == 1);
3694 }
3695 
3696 inline Frame::Frame(const FrameType& frameType, const Indices32& planePaddingElements, const Timestamp& timestamp) :
3697  Frame(frameType, PlaneInitializer<void>::createPlaneInitializersWithPaddingElements(planePaddingElements), timestamp)
3698 {
3699  ocean_assert(frameType.numberPlanes() == planePaddingElements.size() || planePaddingElements.empty());
3700  ocean_assert(planes_.size() == frameType.numberPlanes());
3701 }
3702 
3703 inline Frame::Frame(const FrameType& frameType, const unsigned int paddingElements, const Timestamp& timestamp) :
3704  Frame(frameType, PlaneInitializers<void>(1, PlaneInitializer<void>(paddingElements)), timestamp)
3705 {
3706  ocean_assert(frameType.numberPlanes() == 1u);
3707  ocean_assert(planes_.size() == 1);
3708 }
3709 
3710 template <>
3711 inline Frame::Frame(const FrameType& frameType, const void* data, const CopyMode copyMode, const unsigned int paddingElements, const Timestamp& timestamp) :
3712  Frame(frameType, PlaneInitializers<void>(1, PlaneInitializer<void>(data, copyMode, paddingElements)), timestamp)
3713 {
3714  // this constructor is for 1-plane frames only
3715 
3716  ocean_assert(frameType.numberPlanes() == 1u);
3717  ocean_assert(planes_.size() == 1);
3718 }
3719 
3720 template <typename T>
3721 inline Frame::Frame(const FrameType& frameType, const T* data, const CopyMode copyMode, const unsigned int paddingElements, const Timestamp& timestamp) :
3722  Frame(frameType, (const void*)(data), copyMode, paddingElements, timestamp)
3723 {
3724 #ifdef OCEAN_DEBUG
3725  const FrameType::DataType debugTemplateDataType = FrameType::dataType<T>();
3726  const FrameType::DataType debugFrameTypeDataType = frameType.dataType();
3727 
3728  // we ensure that the template data type matches with the data type of the pixel format (as padding is defined in elements)
3729  ocean_assert(debugTemplateDataType == FrameType::DT_UNDEFINED || debugTemplateDataType == debugFrameTypeDataType);
3730 #endif
3731 
3732  ocean_assert(planes_.size() == 1);
3733 }
3734 
3735 template <>
3736 inline Frame::Frame(const FrameType& frameType, void* data, const CopyMode copyMode, const unsigned int paddingElements, const Timestamp& timestamp) :
3737  Frame(frameType, PlaneInitializers<void>(1, PlaneInitializer<void>(data, copyMode, paddingElements)), timestamp)
3738 {
3739  // this constructor is for 1-plane frames only
3740 
3741  ocean_assert(frameType.numberPlanes() == 1u);
3742  ocean_assert(planes_.size() == 1);
3743 }
3744 
3745 template <typename T>
3746 inline Frame::Frame(const FrameType& frameType, T* data, const CopyMode copyMode, const unsigned int paddingElements, const Timestamp& timestamp) :
3747  Frame(frameType, (void*)(data), copyMode, paddingElements, timestamp)
3748 {
3749 #ifdef OCEAN_DEBUG
3750  const FrameType::DataType debugTemplateDataType = FrameType::dataType<T>();
3751  const FrameType::DataType debugFrameTypeDataType = frameType.dataType();
3752 
3753  // we ensure that the template data type matches with the data type of the pixel format (as padding is defined in elements)
3754  ocean_assert(debugTemplateDataType == FrameType::DT_UNDEFINED || debugTemplateDataType == debugFrameTypeDataType);
3755 #endif
3756 
3757  ocean_assert(planes_.size() == 1);
3758 }
3759 
3760 template <typename T>
3761 inline Frame::Frame(const FrameType& frameType, const PlaneInitializers<T>& planeInitializers, const Timestamp& timestamp) :
3762  Frame(frameType, (const PlaneInitializer<void>*)planeInitializers.data(), planeInitializers.size(), timestamp)
3763 {
3764 #ifdef OCEAN_DEBUG
3765  const FrameType::DataType debugTemplateDataType = FrameType::dataType<T>();
3766  const FrameType::DataType debugFrameTypeDataType = frameType.dataType();
3767 
3768  // we ensure that the template data type matches with the data type of the pixel format (as padding is defined in elements)
3769  ocean_assert(debugTemplateDataType == FrameType::DT_UNDEFINED || debugTemplateDataType == debugFrameTypeDataType);
3770 #endif
3771 
3772  ocean_assert(planes_.size() == frameType.numberPlanes());
3773 }
3774 
3775 inline const FrameType& Frame::frameType() const
3776 {
3777  return (const FrameType&)(*this);
3778 }
3779 
3780 inline const Frame::Planes& Frame::planes() const
3781 {
3782  return planes_;
3783 }
3784 
3785 template <typename T>
3786 bool Frame::updateMemory(const T* data, const unsigned int planeIndex)
3787 {
3788  ocean_assert(data != nullptr);
3789  if (data != nullptr)
3790  {
3791  ocean_assert(planeIndex < planes_.size());
3792  if (planeIndex < planes_.size())
3793  {
3794  Plane& plane = planes_[planeIndex];
3795 
3796  if constexpr (!std::is_void_v<T>)
3797  {
3798  ocean_assert(sizeof(T) == plane.elementTypeSize());
3799  }
3800 
3801  ocean_assert(plane.allocatedData_ == nullptr);
3802  if (plane.allocatedData_ == nullptr)
3803  {
3804  plane.constData_ = data;
3805  plane.data_ = nullptr;
3806 
3807  return true;
3808  }
3809  }
3810  }
3811 
3812  return false;
3813 }
3814 
3815 template <typename T>
3816 bool Frame::updateMemory(T* data, const unsigned int planeIndex)
3817 {
3818  ocean_assert(data != nullptr);
3819  if (data != nullptr)
3820  {
3821  ocean_assert(planeIndex < planes_.size());
3822  if (planeIndex < planes_.size())
3823  {
3824  Plane& plane = planes_[planeIndex];
3825 
3826  if constexpr (!std::is_void_v<T>)
3827  {
3828  ocean_assert(sizeof(T) == plane.elementTypeSize());
3829  }
3830 
3831  ocean_assert(plane.allocatedData_ == nullptr);
3832  if (plane.allocatedData_ == nullptr)
3833  {
3834  plane.data_ = data;
3835  plane.constData_ = (const T*)(data);
3836 
3837  return true;
3838  }
3839  }
3840  }
3841 
3842  return false;
3843 }
3844 
3845 template <typename T>
3846 bool Frame::updateMemory(const std::initializer_list<T*>& planeDatas)
3847 {
3848  ocean_assert(planeDatas.size() != 0);
3849  ocean_assert(planeDatas.size() <= planes_.size());
3850 
3851  if (planeDatas.size() == 0 || planeDatas.size() > planes_.size())
3852  {
3853  return false;
3854  }
3855 
3856  for (unsigned int planeIndex = 0u; planeIndex < planeDatas.size(); ++planeIndex)
3857  {
3858  if (!updateMemory(planeDatas.begin()[planeIndex], planeIndex))
3859  {
3860  return false;
3861  }
3862  }
3863 
3864  return true;
3865 }
3866 
3867 template <typename T, const unsigned int tPlaneChannels>
3868 bool Frame::setValue(const PixelType<T, tPlaneChannels>& planePixelValue, const unsigned int planeIndex)
3869 {
3870  static_assert(!std::is_void_v<T>, "Value access/assignment cannot be performed with void types.");
3871 
3872  ocean_assert(planes_.size() >= 1);
3873  ocean_assert(planeIndex < planes_.size());
3874 
3875  Plane& plane = planes_[planeIndex];
3876 
3877  ocean_assert(plane.isValid());
3878 
3879  if (sizeof(T) != plane.elementTypeSize())
3880  {
3881  ocean_assert(false && "The specified data type must fit to the frame's data type!");
3882  return false;
3883  }
3884 
3885  if (plane.channels() != tPlaneChannels)
3886  {
3887  ocean_assert(false && "The specified number of channels does not fit with the plane's actual channels!");
3888  return false;
3889  }
3890 
3891  if (plane.isReadOnly())
3892  {
3893  return false;
3894  }
3895 
3896  if (plane.paddingElements_ == 0u)
3897  {
3899 
3900  for (unsigned int n = 0u; n < plane.width() * plane.height(); ++n)
3901  {
3902  data[n] = planePixelValue;
3903  }
3904  }
3905  else
3906  {
3907  const unsigned int planeStrideBytes = plane.strideBytes();
3908 
3909  for (unsigned int y = 0u; y < plane.height(); ++y)
3910  {
3911  PixelType<T, tPlaneChannels>* const data = (PixelType<T, tPlaneChannels>*)(plane.data<uint8_t>() + y * planeStrideBytes);
3912 
3913  for (unsigned int x = 0u; x < plane.width(); ++x)
3914  {
3915  data[x] = planePixelValue;
3916  }
3917  }
3918  }
3919 
3920  return true;
3921 }
3922 
3923 template <typename T, const unsigned int tPlaneChannels>
3924 bool Frame::containsValue(const PixelType<T, tPlaneChannels>& planePixelValue, const unsigned int planeIndex) const
3925 {
3926  static_assert(!std::is_void_v<T>, "Value access/comparison cannot be performed with void types.");
3927 
3928  ocean_assert(planes_.size() >= 1);
3929  ocean_assert(planeIndex < planes_.size());
3930 
3931  const Plane& plane = planes_[planeIndex];
3932 
3933  ocean_assert(plane.isValid());
3934 
3935  if (sizeof(T) != plane.elementTypeSize())
3936  {
3937  ocean_assert(false && "The specified data type must fit to the frame's data type!");
3938  return false;
3939  }
3940 
3941  if (plane.channels() != tPlaneChannels)
3942  {
3943  ocean_assert(false && "The specified number of channels does not fit with the plane's actual channels!");
3944  return false;
3945  }
3946 
3947  const unsigned int planeStrideBytes = plane.strideBytes();
3948 
3949  for (unsigned int y = 0u; y < plane.height(); ++y)
3950  {
3951  PixelType<T, tPlaneChannels>* const data = (PixelType<T, tPlaneChannels>*)(plane.constdata<uint8_t>() + y * planeStrideBytes);
3952 
3953  for (unsigned int x = 0u; x < plane.width(); ++x)
3954  {
3955  if (data[x] == planePixelValue)
3956  {
3957  return true;
3958  }
3959  }
3960  }
3961 
3962  return false;
3963 }
3964 
3965 template <typename T>
3966 bool Frame::setValue(const T* planePixelValue, const size_t planePixelValueSize, const unsigned int planeIndex)
3967 {
3968  static_assert(!std::is_void_v<T>, "Value access/assignment cannot be performed with void types.");
3969 
3970  ocean_assert(planePixelValue != nullptr);
3971 
3972  ocean_assert(planes_[planeIndex].elementTypeSize() == sizeof(T));
3973  ocean_assert(planes_[planeIndex].channels() == planePixelValueSize);
3974 
3975  switch (planePixelValueSize)
3976  {
3977  case 1:
3978  {
3979  const PixelType<T, 1u> value =
3980  {{
3981  planePixelValue[0]
3982  }};
3983 
3984  return setValue<T, 1u>(value, planeIndex);
3985  }
3986 
3987  case 2:
3988  {
3989  const PixelType<T, 2u> value =
3990  {{
3991  planePixelValue[0],
3992  planePixelValue[1]
3993  }};
3994 
3995  return setValue<T, 2u>(value, planeIndex);
3996  }
3997 
3998  case 3:
3999  {
4000  const PixelType<T, 3u> value =
4001  {{
4002  planePixelValue[0],
4003  planePixelValue[1],
4004  planePixelValue[2]
4005  }};
4006 
4007  return setValue<T, 3u>(value, planeIndex);
4008  }
4009 
4010  case 4:
4011  {
4012  const PixelType<T, 4u> value =
4013  {{
4014  planePixelValue[0],
4015  planePixelValue[1],
4016  planePixelValue[2],
4017  planePixelValue[3]
4018  }};
4019 
4020  return setValue<T, 4u>(value, planeIndex);
4021  }
4022  }
4023 
4024  ocean_assert(false && "The number of channels is not supported");
4025  return false;
4026 }
4027 
4028 template <typename T>
4029 bool Frame::setValue(const std::initializer_list<typename Identity<T>::Type>& planePixelValues, const unsigned int planeIndex)
4030 {
4031  return setValue<T>(planePixelValues.begin(), planePixelValues.size(), planeIndex);
4032 }
4033 
4034 inline unsigned int Frame::size(const unsigned int planeIndex) const
4035 {
4036  ocean_assert(planes_.size() >= 1);
4037  ocean_assert(planeIndex < planes_.size());
4038 
4039  return planes_[planeIndex].size();
4040 }
4041 
4042 inline unsigned int Frame::paddingElements(const unsigned int planeIndex) const
4043 {
4044  ocean_assert(planes_.size() >= 1);
4045  ocean_assert(planeIndex < planes_.size());
4046 
4047  return planes_[planeIndex].paddingElements();
4048 }
4049 
4050 inline unsigned int Frame::paddingBytes(const unsigned int planeIndex) const
4051 {
4052  ocean_assert(planes_.size() >= 1);
4053  ocean_assert(planeIndex < planes_.size());
4054 
4055  return planes_[planeIndex].paddingBytes();
4056 }
4057 
4058 inline unsigned int Frame::strideElements(const unsigned int planeIndex) const
4059 {
4060  ocean_assert(planes_.size() >= 1);
4061  ocean_assert(planeIndex < planes_.size());
4062 
4063  return planes_[planeIndex].strideElements();
4064 }
4065 
4066 inline unsigned int Frame::strideBytes(const unsigned int planeIndex) const
4067 {
4068  ocean_assert(planes_.size() >= 1);
4069  ocean_assert(planeIndex < planes_.size());
4070 
4071  return planes_[planeIndex].strideBytes();
4072 }
4073 
4074 inline unsigned int Frame::planeWidth(const unsigned int planeIndex) const
4075 {
4076  ocean_assert(planes_.size() >= 1);
4077  ocean_assert(planeIndex < planes_.size());
4078 
4079  return planes_[planeIndex].width();
4080 }
4081 
4082 inline unsigned int Frame::planeHeight(const unsigned int planeIndex) const
4083 {
4084  ocean_assert(planes_.size() >= 1);
4085  ocean_assert(planeIndex < planes_.size());
4086 
4087  return planes_[planeIndex].height();
4088 }
4089 
4090 inline unsigned int Frame::planeChannels(const unsigned int planeIndex) const
4091 {
4092  ocean_assert(planes_.size() >= 1);
4093  ocean_assert(planeIndex < planes_.size());
4094 
4095  return planes_[planeIndex].channels();
4096 }
4097 
4098 inline unsigned int Frame::planeWidthElements(const unsigned int planeIndex) const
4099 {
4100  ocean_assert(planes_.size() >= 1);
4101  ocean_assert(planeIndex < planes_.size());
4102 
4103  return planes_[planeIndex].widthElements();
4104 }
4105 
4106 inline unsigned int Frame::planeWidthBytes(const unsigned int planeIndex) const
4107 {
4108  ocean_assert(planes_.size() >= 1);
4109  ocean_assert(planeIndex < planes_.size());
4110 
4111  return planes_[planeIndex].widthBytes();
4112 }
4113 
4114 inline unsigned int Frame::planeBytesPerPixel(const unsigned int planeIndex) const
4115 {
4116  ocean_assert(planes_.size() >= 1);
4117  ocean_assert(planeIndex < planes_.size());
4118 
4119  return FrameType::planeBytesPerPixel(pixelFormat(), planeIndex);
4120 }
4121 
4122 inline bool Frame::isPlaneContinuous(const unsigned int planeIndex) const
4123 {
4124  ocean_assert(planes_.size() >= 1);
4125  ocean_assert(planeIndex < planes_.size());
4126 
4127  return planes_[planeIndex].isContinuous();
4128 }
4129 
4130 inline bool Frame::isPlaneOwner(const unsigned int planeIndex) const
4131 {
4132  ocean_assert(planes_.size() >= 1);
4133  ocean_assert(planeIndex < planes_.size());
4134 
4135  return planes_[planeIndex].isOwner();
4136 }
4137 
4138 inline const Timestamp& Frame::timestamp() const
4139 {
4140  return timestamp_;
4141 }
4142 
4144 {
4145  return relativeTimestamp_;
4146 }
4147 
4148 inline void Frame::setTimestamp(const Timestamp& timestamp)
4149 {
4151 }
4152 
4153 inline void Frame::setRelativeTimestamp(const Timestamp& relativeTimestamp)
4154 {
4156 }
4157 
4158 template <typename T>
4159 inline T* Frame::data(const unsigned int planeIndex)
4160 {
4161  ocean_assert(planes_.size() >= 1);
4162  ocean_assert(planeIndex < planes_.size());
4163 
4164  return planes_[planeIndex].data<T>();
4165 }
4166 
4167 template <typename T>
4168 inline const T* Frame::constdata(const unsigned int planeIndex) const
4169 {
4170  ocean_assert(planes_.size() >= 1);
4171  ocean_assert(planeIndex < planes_.size());
4172 
4173  return planes_[planeIndex].constdata<T>();
4174 }
4175 
4176 template <typename T>
4177 inline T* Frame::row(const unsigned int y, const unsigned int planeIndex)
4178 {
4179  ocean_assert(isValid());
4180  ocean_assert(y < height());
4181 
4182  ocean_assert(planes_.size() >= 1);
4183  ocean_assert(planeIndex < planes_.size());
4184  Plane& plane = planes_[planeIndex];
4185 
4186  ocean_assert(plane.isValid());
4187 
4188  ocean_assert(y < plane.height());
4189  return reinterpret_cast<T*>(plane.data<uint8_t>() + y * plane.strideBytes());
4190 }
4191 
4192 template <typename T>
4193 inline const T* Frame::constrow(const unsigned int y, const unsigned int planeIndex) const
4194 {
4195  ocean_assert(isValid());
4196  ocean_assert(y < height());
4197 
4198  ocean_assert(planes_.size() >= 1);
4199  ocean_assert(planeIndex < planes_.size());
4200  const Plane& plane = planes_[planeIndex];
4201 
4202  ocean_assert(plane.isValid());
4203 
4204  ocean_assert(y < plane.height());
4205  return reinterpret_cast<const T*>(plane.constdata<uint8_t>() + y * plane.strideBytes());
4206 }
4207 
4208 template <typename T>
4209 inline T* Frame::pixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex)
4210 {
4211  ocean_assert(isValid());
4212  ocean_assert(x < planeWidth(planeIndex));
4213  ocean_assert(y < planeHeight(planeIndex));
4214 
4215  ocean_assert(planes_.size() >= 1);
4216  ocean_assert(planeIndex < planes_.size());
4217  Plane& plane = planes_[planeIndex];
4218 
4219  ocean_assert(plane.isValid());
4220 
4221  if constexpr (!std::is_void_v<T>)
4222  {
4223  ocean_assert(sizeof(T) == plane.elementTypeSize());
4224  }
4225 
4226  /*
4227  * how to determine pixel offsets within row:
4228  *
4229  * the pixel format RGB24 has data type`uint8_t` and 3 channels
4230  * so the n-th pixel is reach by row<uint8_t>() + n * sizeof(uint8_t) * channels()
4231  *
4232  * RGB5551 has data type `uint16_t` and 3 channels
4233  * so the n-th pixel is reach by row<uint8_t>() + n * sizeof(uint16_t) * channels() / 3 == row<uint8_t>() + n * sizeof(uint16_t)
4234  * or row<uint16_t>() + n * channels() / 3 == row<uint16_t>() + n
4235  *
4236  * Therefore, the pixel offset cannot be determined via x * channels(),
4237  * Instead, we determine the offset via bytes per pixel == planeWidthBytes() / planeWidth()
4238  */
4239 
4240  ocean_assert(x == 0u || !formatIsPacked(pixelFormat()));
4241 
4242  ocean_assert(plane.bytesPerPixel() != 0u);
4243  const unsigned int xBytes = x * plane.bytesPerPixel();
4244 
4245  ocean_assert(y < plane.height());
4246  return reinterpret_cast<T*>(plane.data<uint8_t>() + y * plane.strideBytes() + xBytes);
4247 }
4248 
4249 template <typename T>
4250 inline const T* Frame::constpixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex) const
4251 {
4252  ocean_assert(isValid());
4253  ocean_assert(x < planeWidth(planeIndex));
4254  ocean_assert(y < planeHeight(planeIndex));
4255 
4256  ocean_assert(planes_.size() >= 1);
4257  ocean_assert(planeIndex < planes_.size());
4258  const Plane& plane = planes_[planeIndex];
4259 
4260  ocean_assert(plane.isValid());
4261 
4262  if constexpr (!std::is_void_v<T>)
4263  {
4264  ocean_assert(sizeof(T) == plane.elementTypeSize());
4265  }
4266 
4267  ocean_assert(x == 0u || !formatIsPacked(pixelFormat()));
4268 
4269  ocean_assert(plane.bytesPerPixel() != 0u);
4270  const unsigned int xBytes = x * plane.bytesPerPixel();
4271 
4272  ocean_assert(y < plane.height());
4273  return reinterpret_cast<const T*>(plane.constdata<uint8_t>() + y * plane.strideBytes() + xBytes);
4274 }
4275 
4276 inline bool Frame::isContinuous() const
4277 {
4278  ocean_assert(planes_.size() >= 1);
4279 
4280  for (const Plane& plane : planes_)
4281  {
4282  if (!plane.isContinuous())
4283  {
4284  return false;
4285  }
4286  }
4287 
4288  return true;
4289 }
4290 
4291 inline bool Frame::isOwner() const
4292 {
4293  ocean_assert(planes_.size() >= 1);
4294 
4295  for (const Plane& plane : planes_)
4296  {
4297  if (!plane.isOwner())
4298  {
4299  return false;
4300  }
4301  }
4302 
4303  return true;
4304 }
4305 
4306 inline bool Frame::isReadOnly() const
4307 {
4308  ocean_assert(planes_.size() >= 1);
4309 
4310  for (const Plane& plane : planes_)
4311  {
4312  if (plane.isReadOnly())
4313  {
4314  return true;
4315  }
4316  }
4317 
4318  return false;
4319 }
4320 
4321 inline bool Frame::hasAlphaChannel() const
4322 {
4323  ocean_assert(isValid());
4324 
4326 }
4327 
4328 template <>
4329 inline bool Frame::hasTransparentPixel(const uint8_t opaque) const
4330 {
4331  if (!hasAlphaChannel())
4332  {
4333  return false;
4334  }
4335 
4336  ocean_assert(numberPlanes() == 1u);
4337 
4338  if (dataType() != dataType<uint8_t>())
4339  {
4340  ocean_assert(false && "Data type does not fit with the frame's data type!");
4341  return false;
4342  }
4343 
4344  if (pixelFormat() == FORMAT_YA16)
4345  {
4346  for (unsigned int y = 0u; y < height(); ++y)
4347  {
4348  const uint8_t* row = constrow<uint8_t>(y) + 1;
4349 
4350  for (unsigned int x = 0u; x < width(); ++x)
4351  {
4352  if (*row != opaque)
4353  {
4354  return true;
4355  }
4356 
4357  row += 2;
4358  }
4359  }
4360  }
4361  else
4362  {
4364 
4365  const unsigned int offset = (pixelFormat() == FORMAT_ABGR32 || pixelFormat() == FORMAT_ARGB32) ? 0u : 3u;
4366 
4367  for (unsigned int y = 0u; y < height(); ++y)
4368  {
4369  const uint8_t* row = constrow<uint8_t>(y) + offset;
4370 
4371  for (unsigned int x = 0u; x < width(); ++x)
4372  {
4373  if (*row != opaque)
4374  {
4375  return true;
4376  }
4377 
4378  row += 4;
4379  }
4380  }
4381  }
4382 
4383  return false;
4384 }
4385 
4386 template <>
4387 inline bool Frame::hasTransparentPixel(const uint16_t opaque) const
4388 {
4389  if (!hasAlphaChannel())
4390  {
4391  return false;
4392  }
4393 
4394  ocean_assert(numberPlanes() == 1u);
4395 
4396  if (dataType() != dataType<uint16_t>())
4397  {
4398  ocean_assert(false && "Data type does not fit with the frame's data type!");
4399  return false;
4400  }
4401 
4402  if (pixelFormat() == FORMAT_RGBA64)
4403  {
4404  for (unsigned int y = 0u; y < height(); ++y)
4405  {
4406  const uint16_t* row = constrow<uint16_t>(y) + 3;
4407 
4408  for (unsigned int x = 0u; x < width(); ++x)
4409  {
4410  if (*row != opaque)
4411  {
4412  return true;
4413  }
4414 
4415  row += 4;
4416  }
4417  }
4418  }
4419  else
4420  {
4421  ocean_assert(pixelFormat() == FORMAT_RGBA4444 || pixelFormat() == FORMAT_BGRA4444);
4422 
4423  for (unsigned int y = 0u; y < height(); ++y)
4424  {
4425  const uint16_t* row = constrow<uint16_t>(y);
4426 
4427  for (unsigned int x = 0u; x < width(); ++x)
4428  {
4429  if ((*row & opaque) != opaque)
4430  {
4431  return true;
4432  }
4433 
4434  ++row;
4435  }
4436  }
4437  }
4438 
4439  return false;
4440 }
4441 
4442 template <typename T>
4443 bool Frame::hasTransparentPixel(const T /*opaque*/) const
4444 {
4445  return false;
4446 }
4447 
4448 inline bool Frame::isValid() const
4449 {
4450  ocean_assert(planes_.size() >= 1);
4451 
4452  const bool frameTypeIsValid = FrameType::isValid();
4453 
4454 #ifdef OCEAN_DEBUG
4455  {
4456  // we ensure that the state of `planes_` is consistent with the state of `FrameType::isValid()`
4457 
4458  size_t debugValidPlanes = 0;
4459 
4460  for (const Plane& plane : planes_)
4461  {
4462  if (plane.isValid())
4463  {
4464  ++debugValidPlanes;
4465  }
4466  }
4467 
4468  const bool debugIsValid = !planes_.isEmpty() && debugValidPlanes == planes_.size();
4469 
4470  ocean_assert(debugIsValid == frameTypeIsValid);
4471  }
4472 #endif // OCEAN_DEBUG
4473 
4474  return frameTypeIsValid;
4475 }
4476 
4477 inline Frame::operator bool() const
4478 {
4479  return isValid();
4480 }
4481 
4482 }
4483 
4484 #endif // META_OCEAN_BASE_FRAME_H
Template class allowing to define an array of data types.
Definition: DataType.h:27
Definition of an image plane, a block of memory storing pixel data with interleaved channels (or just...
Definition: Frame.h:1857
unsigned int width() const
Returns the width of the plane in pixel.
Definition: Frame.h:3528
bool isCompatibleWithDataType() const
Returns whether this plane is compatible with a given element data type.
Definition: Frame.h:3601
unsigned int paddingElements() const
Returns the number of padding elements at the end of each plane row, in elements.
Definition: Frame.h:3555
void * allocatedData_
The pointer to the memory which this plane has allocated, this pointer is pointing to the memory whic...
Definition: Frame.h:2205
unsigned int paddingBytes() const
Returns the number of padding bytes at the end of each plane row, in bytes.
Definition: Frame.h:3560
unsigned int elementTypeSize() const
Returns the size of each element of this plane.
Definition: Frame.h:3565
bool isOwner() const
Returns whether this plane is the owner of the memory.
Definition: Frame.h:3616
unsigned int calculateStrideBytes() const
Calculates the number of bytes between the start positions of two consecutive rows,...
Definition: Frame.h:3631
void * data_
The pointer to the writable memory of the plane (not the pointer to the allocated memory),...
Definition: Frame.h:2211
unsigned int strideBytes() const
Returns the number of bytes between the start positions of two consecutive rows, in bytes.
Definition: Frame.h:3585
bool isContinuous() const
Returns whether this plane is based on continuous memory and thus does not have any padding at the en...
Definition: Frame.h:3611
Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const unsigned int paddingElements) noexcept
Creates a new plane object with own allocated memory.
const T * constdata() const
Returns the read-only memory pointer to this plane with a specific data type compatible with elementT...
Definition: Frame.h:3544
bool isValid() const
Returns whether this plane holds valid data.
Definition: Frame.h:3626
T * data()
Returns the writable memory pointer to this plane with a specific data type compatible with elementTy...
Definition: Frame.h:3550
bool isReadOnly() const
Returns whether this plane holds read-only memory.
Definition: Frame.h:3621
unsigned int size() const
Returns the number of bytes necessary for the entire plane data including optional padding elements a...
Definition: Frame.h:3606
unsigned int widthBytes() const
Returns the width of the plane in bytes, the width does not contain optional padding elements.
Definition: Frame.h:3575
~Plane()
Destructs a Plane object.
Definition: Frame.h:3523
Plane()=default
Creates a new invalid plane.
unsigned int channels() const
Returns the channels of the plane.
Definition: Frame.h:3538
const void * constData_
The pointer to the read-only memory of the plane (not the pointer to the allocated memory),...
Definition: Frame.h:2208
unsigned int bytesPerPixel() const
Returns the number of bytes which is used for each pixel.
Definition: Frame.h:3593
void release()
Releases this plane and all resources of this plane.
unsigned int strideElements() const
Returns the number of elements between the start positions of two consecutive rows,...
Definition: Frame.h:3580
Plane(const Plane &plane, const AdvancedCopyMode advancedCopyMode=ACM_USE_OR_COPY_KEEP_LAYOUT) noexcept
Copy constructor.
unsigned int height() const
Returns the height of the plane in pixel.
Definition: Frame.h:3533
unsigned int paddingElements_
The number of padding elements at the end of each plane row, in elements, with range [0,...
Definition: Frame.h:2226
unsigned int widthElements() const
Returns the width of the plane in elements, the width does not contain optional padding elements.
Definition: Frame.h:3570
This class implements a helper class which can be used to initialize a multi-plane frame in the const...
Definition: Frame.h:2247
PlaneInitializer(const T *constdata, const CopyMode copyMode, const unsigned int dataPaddingElements=0u)
Creates a new initializer object for a read-only memory pointer.
Definition: Frame.h:3637
static std::vector< PlaneInitializer< T > > createPlaneInitializersWithPaddingElements(const Indices32 &paddingElementsPerPlane)
Creates plane initializer objects with padding elements only.
Definition: Frame.h:3667
This class implements Ocean's image class.
Definition: Frame.h:1792
bool copy(const int targetLeft, const int targetTop, const Frame &source, const bool copyTimestamp=true)
Copies the entire image content of a source frame into this frame.
static bool strideBytes2paddingElements(const PixelFormat &pixelFormat, const unsigned int imageWidth, const unsigned int planeStrideBytes, unsigned int &planePaddingElements, const unsigned int planeIndex=0u)
Determines the number of padding elements at the end of a row of a plane for which the pixel format,...
Frame & operator=(Frame &&right) noexcept
Move operator.
Frame(const FrameType &frameType, const CopyMode copyMode)=delete
Deleted constructor to prevent misuse.
typename Ocean::DataType< T, tChannels >::Type PixelType
Definition of a data type storing all channel values of one pixel in an array.
Definition: Frame.h:2311
Timestamp relativeTimestamp_
Relative timestamp of this frame.
Definition: Frame.h:3063
bool isContinuous() const
Returns whether all planes of this frame have continuous memory and thus do not contain any padding a...
Definition: Frame.h:4276
bool hasAlphaChannel() const
Returns whether the frame's pixel format contains an alpha channel.
Definition: Frame.h:4321
Frame(const FrameType &frameType, const PlaneInitializer< void > *planeInitializers, size_t sizePlaneInitializers, const Timestamp &timestamp=Timestamp(false))
Creates a new multi-plane frame with known frame type and given source memory for each individual pla...
unsigned int strideBytes(const unsigned int planeIndex=0u) const
Returns the number of bytes within one row, including optional padding at the end of a row for a spec...
Definition: Frame.h:4066
bool haveIntersectingMemory(const Frame &frame) const
Returns whether two frame objects have any amount of intersecting memory.
Timestamp timestamp_
Timestamp of the frame.
Definition: Frame.h:3060
unsigned int strideElements(const unsigned int planeIndex=0u) const
Returns the number of elements within one row, including optional padding at the end of a row for a s...
Definition: Frame.h:4058
T * row(const unsigned int y, const unsigned int planeIndex=0u)
Returns the pointer to the pixel data of a specific row.
Definition: Frame.h:4177
bool updateMemory(const T *data, const unsigned int planeIndex=0u)
Updates the memory pointer for a specific plane of the frame to a new read-only memory location.
Definition: Frame.h:3786
Frame subFrame(const unsigned int subFrameLeft, const unsigned int subFrameTop, const unsigned int subFrameWidth, const unsigned int subFrameHeight, const CopyMode copyMode=CM_USE_KEEP_LAYOUT) const
Returns a sub-frame of this frame.
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
void setRelativeTimestamp(const Timestamp &relative)
Sets the relative timestamp of this frame.
Definition: Frame.h:4153
const FrameType & frameType() const
Returns the frame type of this frame.
Definition: Frame.h:3775
Frame(const Frame &frame)
Creates a second version of a given frame.
T * data(const unsigned int planeIndex=0u)
Returns a pointer to the pixel data of a specific plane.
Definition: Frame.h:4159
bool isValid() const
Returns whether this frame is valid.
Definition: Frame.h:4448
Frame(const FrameType &frameType, const T *data, const bool copyData, const unsigned int paddingElements=0u, const Timestamp &timestamp=Timestamp(false))=delete
Deleted constructor to prevent misuse, use Frame(const FrameType& frameType, const T* data,...
T * pixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex=0u)
Returns the pointer to the data of a specific pixel.
Definition: Frame.h:4209
void setTimestamp(const Timestamp &timestamp)
Sets the timestamp of this frame.
Definition: Frame.h:4148
bool isReadOnly() const
Returns true, if the frame allows only read access (using constdata()).
Definition: Frame.h:4306
Frame & operator=(const Frame &right) noexcept
Assign operator.
Frame(const Frame &frame, const Timestamp &timestamp)=delete
Deleted constructor to prevent misuse.
bool copy(const Frame &source, const bool copyTimestamp=true)
Deprecated.
Frame(const Frame &frame, const bool copyData)=delete
Deleted constructor to prevent misuse.
Frame(const FrameType &frameType, const AdvancedCopyMode avancedCopyMode)=delete
Deleted constructor to prevent misuse.
bool set(const FrameType &frameType, const bool forceOwner, const bool forceWritable=false, const Indices32 &planePaddingElements=Indices32(), const Timestamp &timestamp=Timestamp(false), bool *reallocated=nullptr)
Sets a new frame type for this frame.
const Timestamp & timestamp() const
Returns the timestamp of this frame.
Definition: Frame.h:4138
unsigned int planeBytesPerPixel(const unsigned int planeIndex) const
Returns the number of bytes of one pixel of a plane for a pixel format.
Definition: Frame.h:4114
unsigned int planeWidthElements(const unsigned int planeIndex) const
Returns the width of a plane of this frame, not in pixel, but in elements, not including padding at t...
Definition: Frame.h:4098
std::vector< PlaneInitializer< T > > PlaneInitializers
Definition of a vector holding plane initializer objects.
Definition: Frame.h:2303
const Timestamp & relativeTimestamp() const
Returns the relative timestamp of this frame.
Definition: Frame.h:4143
const Planes & planes() const
Returns the individual planes of this frame.
Definition: Frame.h:3780
bool isOwner() const
Returns whether the frame is the owner of the internal frame data.
Definition: Frame.h:4291
CopyMode
Definition of individual copy modes.
Definition: Frame.h:1799
@ CM_USE_KEEP_LAYOUT
The source memory is used only, no copy is created, the padding layout is preserved.
Definition: Frame.h:1801
unsigned int planeChannels(const unsigned int planeIndex) const
Returns the channels of a plane of this frame.
Definition: Frame.h:4090
unsigned int planeWidth(const unsigned int planeIndex) const
Returns the width of a plane of this frame.
Definition: Frame.h:4074
void release()
Releases this frame and the frame data if this frame is the owner.
Frame(const Frame &frame, const AdvancedCopyMode advancedCopyMode) noexcept
Creates a second version of a given frame.
Frame()
Creates an empty frame.
Definition: Frame.h:3680
const T * constpixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex=0u) const
Returns the pointer to the constant data of a specific pixel.
Definition: Frame.h:4250
Frame(const FrameType &frameType, T *data, const bool copyData, const unsigned int paddingElements=0u, const Timestamp &timestamp=Timestamp(false))=delete
Deleted constructor to prevent misuse, use Frame(const FrameType& frameType, T* data,...
~Frame()
Destructs a frame.
void makeOwner()
Makes this frame the owner of the memory.
Frame(const FrameType &frameType, const Timestamp &timestamp)=delete
Deleted constructor to prevent misuse.
AdvancedCopyMode
Definition of advanced copy modes containing all copy modes from CopyMode but also some additional.
Definition: Frame.h:1814
Frame(const Frame &frame, const CopyMode copyMode)=delete
Deleted constructor to prevent misuse, use AdvancedCopyMode instead.
bool isPlaneContinuous(const unsigned int planeIndex=0u) const
Returns whether a specific plane of this frame is based on continuous memory and thus does not have a...
Definition: Frame.h:4122
bool containsValue(const PixelType< T, tPlaneChannels > &planePixelValue, const unsigned int planeIndex=0u) const
Returns whether the frame (one plane) contains a specified pixel value.
Definition: Frame.h:3924
bool setValue(const uint8_t value, const unsigned int planeIndex=0u, const bool skipPaddingData=true)
Sets the memory of the frame to a specified byte value (the memory of one plane).
bool isPlaneOwner(const unsigned int planeIndex=0u) const
Returns whether a specific plane of this frame is the owner of the memory.
Definition: Frame.h:4130
unsigned int paddingBytes(const unsigned int planeIndex=0u) const
Returns the optional number of padding bytes at the end of each row for a specific plane.
Definition: Frame.h:4050
const T * constrow(const unsigned int y, const unsigned int planeIndex=0u) const
Returns the pointer to the constant data of a specific row.
Definition: Frame.h:4193
void makeContinuous()
Makes the memory of this frame continuous.
unsigned int planeWidthBytes(const unsigned int planeIndex) const
Returns the width of a plane of this frame, not in pixel, but in bytes, not including padding at the ...
Definition: Frame.h:4106
bool hasTransparentPixel(const T opaque) const
Returns whether the frame holds at least one pixel with an non opaque alpha value.
Definition: Frame.h:4443
unsigned int planeHeight(const unsigned int planeIndex) const
Returns the height of a plane of this frame.
Definition: Frame.h:4082
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:4034
Planes planes_
The individual memory planes of this frame.
Definition: Frame.h:3057
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
This class implements a helper class allowing to create generic pixel formats.
Definition: Frame.h:98
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition: Frame.h:30
static unsigned int widthMultiple(const PixelFormat pixelFormat)
Returns the number of pixels the width of a frame must be a multiple of.
Definition: Frame.h:3423
static const FrameType::DataTypes & definedDataTypes()
Returns all defined data types.
static PixelFormat translatePixelFormat(const std::string &pixelFormat)
Translates a string containing a pixel format into the pixel format.
static PixelFormat genericPixelFormat(const unsigned int bitsPerPixelChannel, const uint32_t channels, const uint32_t planes=1u, const uint32_t widthMultiple=1u, const uint32_t heightMultiple=1u)
Returns a specific generic pixel format with specified bit per pixel per channel, channel number,...
static unsigned int bytesPerDataType(const DataType dataType)
Returns the number of bytes which are necessary to store a specified data type.
bool operator==(const FrameType &right) const
Returns whether two frame types are equal.
unsigned int pixels() const
Returns the number of pixels for the frame.
Definition: Frame.h:3193
FrameType()=default
Creates a new frame type with invalid parameters.
static unsigned int formatBitsPerPixelGreenChannel(const PixelFormat pixelFormat)
Returns the number of bits of one pixel for the green channel.
static constexpr uint32_t pixelFormatBitOffsetChannels
The number of bits the channel value is shifted within the PixelFormat value.
Definition: Frame.h:74
static const FrameType::PixelFormats & definedPixelFormats()
Returns all defined pixel formats.
static PixelFormat findPixelFormat(const DataType dataType, const unsigned int channels)
Returns a best fitting pixel format having the given number of bits per pixels.
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition: Frame.h:183
@ FORMAT_YA16
Pixel format with byte order YA and 16 bits per pixel.
Definition: Frame.h:649
@ FORMAT_BGRA4444
Pixel format with entirely 16 bits per pixel, 4 bits for each channel.
Definition: Frame.h:282
@ FORMAT_UNDEFINED
Undefined pixel format.
Definition: Frame.h:187
@ FORMAT_RGBA64
Pixel format with byte order RGBA and 64 bits per pixel, with 16 bit per component.
Definition: Frame.h:675
@ FORMAT_RGBA4444
Pixel format with entirely 16 bits per pixel, 4 bits for each channel.
Definition: Frame.h:395
@ FORMAT_ARGB32
Pixel format with byte order ARGB and 32 bits per pixel.
Definition: Frame.h:213
@ FORMAT_ABGR32
Pixel format with byte order ABGR and 32 bits per pixel.
Definition: Frame.h:200
@ FORMAT_RGBA32
Pixel format with byte order RGBA and 32 bits per pixel.
Definition: Frame.h:382
@ FORMAT_YUVA32
Pixel format with byte order YUVA and 32 bits per pixel.
Definition: Frame.h:472
@ FORMAT_BGRA32
Pixel format with byte order BGRA and 32 bits per pixel.
Definition: Frame.h:277
unsigned int width() const
Returns the width of the frame format in pixel.
Definition: Frame.h:3143
static PixelFormat genericSinglePlanePixelFormat(const PixelFormat pixelFormat)
Returns the most suitable 1-plane pixel format for a given pixel format which may be composed of seve...
PlanesValue
Definition of a protected helper enum that simplifies to read the definition of a predefined pixel fo...
Definition: Frame.h:126
PixelOrigin pixelOrigin() const
Returns the pixel origin of the frame.
Definition: Frame.h:3188
std::vector< PixelFormat > PixelFormats
Definition of a vector holding pixel formats.
Definition: Frame.h:1040
constexpr static PixelFormat genericPixelFormat(const uint32_t channels, const uint32_t planes=1u, const uint32_t widthMultiple=1u, const uint32_t heightMultiple=1u)
Returns a specific generic pixel format with a specified data type and channel number.
static DataType translateDataType(const std::string &dataType)
Translates a string containing a data type into the data type.
unsigned int frameTypeSize() const
Returns the number of bytes necessary for the frame type, without padding at the end of frame rows.
static unsigned int formatGenericBitsPerPixel(const PixelFormat pixelFormat)
Returns the number of bits of one pixel for a given generic pixel format.
Definition: Frame.h:3335
unsigned int height_
Frame height in pixel, with range [0, infinity)
Definition: Frame.h:1738
static bool dataIsAligned(const void *data)
Returns whether a given pointer has the same byte alignment as the size of the data type the pointer ...
Definition: Frame.h:3470
static PixelOrigin translatePixelOrigin(const std::string &pixelOrigin)
Translates a string containing the pixel origin into the pixel origin value.
bool operator!=(const FrameType &right) const
Returns whether two frame types are not equal.
Definition: Frame.h:3208
static bool planeLayout(const PixelFormat imagePixelFormat, const unsigned int imageWidth, const unsigned int imageHeight, const unsigned int planeIndex, unsigned int &planeWidth, unsigned int &planeHeight, unsigned int &planeChannels, unsigned int *planeWidthElementsMultiple=nullptr, unsigned int *planeHeightElementsMultiple=nullptr)
Returns the plane layout of a given pixel format.
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition: Frame.h:3183
PixelOrigin pixelOrigin_
The origin of the pixel data, either the upper left corner or the bottom left corner (if valid).
Definition: Frame.h:1744
static std::string translatePixelFormat(const PixelFormat pixelFormat)
Translates a pixel format value into a string containing the pixel format.
static PixelFormat formatRemoveAlphaChannel(const PixelFormat pixelFormat)
Removes an alpha channel from a given pixel format.
static bool arePixelFormatsCompatible(const PixelFormat pixelFormatA, const PixelFormat pixelFormatB)
Returns whether two given pixel formats are compatible.
static unsigned int formatBitsPerPixelAlphaChannel(const PixelFormat pixelFormat)
Returns the number of bits of one pixel for the alpha channel.
MultipleValue
Definition of a protected helper enum that simplifies to read the definition of a predefined pixel fo...
Definition: Frame.h:141
constexpr static PixelFormat genericPixelFormat()
Returns a specific generic pixel format with a specified data type and channel number.
static bool areFrameTypesCompatible(const FrameType &frameTypeA, const FrameType &frameTypeB, const bool allowDifferentPixelOrigins)
Returns whether two given frame types are compatible.
static bool formatHasAlphaChannel(const PixelFormat pixelFormat, bool *isLastChannel=nullptr)
Returns whether a given pixel format holds an alpha channel.
static unsigned int heightMultiple(const PixelFormat pixelFormat)
Returns the number of pixels the height of a frame must be a multiple of.
Definition: Frame.h:3428
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition: Frame.h:3153
unsigned int bytesPerDataType() const
Returns the number of bytes which are necessary to store the data type of this frame.
Definition: Frame.h:3168
constexpr static PixelFormat genericPixelFormat(uint32_t channels, const uint32_t planes=1u, const uint32_t widthMultiple=1u, const uint32_t heightMultiple=1u)
Returns a specific generic pixel format with a specified data type and channel number.
PixelOrigin
Defines different types of frame origin positions.
Definition: Frame.h:1046
@ ORIGIN_INVALID
Invalid origin type.
Definition: Frame.h:1048
@ ORIGIN_UPPER_LEFT
The first pixel lies in the upper left corner, the last pixel in the lower right corner.
Definition: Frame.h:1050
ChannelsValue
Definition of a protected helper enum that simplifies to read the definition of a predefined pixel fo...
Definition: Frame.h:109
DataType
Definition of individual channel data type.
Definition: Frame.h:37
@ DT_UNSIGNED_INTEGER_64
Unsigned 64 bit integer data type (uint64_t).
Definition: Frame.h:53
@ DT_UNSIGNED_INTEGER_16
Unsigned 16 bit integer data type (uint16_t).
Definition: Frame.h:45
@ DT_SIGNED_INTEGER_16
Signed 16 bit integer data type (int16_t).
Definition: Frame.h:47
@ DT_SIGNED_INTEGER_32
Signed 232 bit integer data type (int32_t).
Definition: Frame.h:51
@ DT_END
The helper data type which can be used to identify the last defined data type, DT_END is exclusive.
Definition: Frame.h:63
@ DT_SIGNED_INTEGER_64
Signed 64 bit integer data type (int64_t).
Definition: Frame.h:55
@ DT_UNDEFINED
Undefined data type.
Definition: Frame.h:39
@ DT_SIGNED_FLOAT_64
Signed 64 bit float data type (double).
Definition: Frame.h:61
@ DT_UNSIGNED_INTEGER_8
Unsigned 8 bit integer data type (uint8_t).
Definition: Frame.h:41
@ DT_UNSIGNED_INTEGER_32
Unsigned 32 bit integer data type (uint32_t).
Definition: Frame.h:49
@ DT_SIGNED_FLOAT_16
Signed 16 bit float data type.
Definition: Frame.h:57
@ DT_SIGNED_FLOAT_32
Signed 32 bit float data type (float).
Definition: Frame.h:59
@ DT_SIGNED_INTEGER_8
Signed 8 bit integer data type (int8_t).
Definition: Frame.h:43
static unsigned int planeBytesPerPixel(const PixelFormat &imagePixelFormat, const unsigned int planeIndex)
Returns the number of bytes of one pixel of a plane for a pixel format.
Definition: Frame.h:3433
unsigned int height() const
Returns the height of the frame in pixel.
Definition: Frame.h:3148
static unsigned int formatBitsPerPixelRedChannel(const PixelFormat pixelFormat)
Returns the number of bits of one pixel for the red channel.
static constexpr uint32_t pixelFormatBitOffsetDatatype
The number of bits the data type value is shifted within the PixelFormat value.
Definition: Frame.h:77
static bool formatIsPacked(const PixelFormat pixelFormat)
Returns whether a given pixel format is a packed pixel format.
unsigned int width_
Frame width in pixel, with range [0, infinity)
Definition: Frame.h:1735
static constexpr uint32_t pixelFormatBitOffsetWidthMultiple
The number of bits the width-multiple value is shifted within the PixelFormat value.
Definition: Frame.h:83
bool operator<(const FrameType &right) const
Returns whether the left frame type is 'smaller' than the right one.
static bool formatIsPureGeneric(const PixelFormat pixelFormat)
Checks whether a given pixel format is a pure generic pixel format.
Definition: Frame.h:3416
bool isValid() const
Returns whether this frame type is valid.
Definition: Frame.h:3213
bool isPixelFormatCompatible(const PixelFormat pixelFormat) const
Returns whether the pixel format of this frame type is compatible with a given pixel format.
Definition: Frame.h:3198
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition: Frame.h:3173
static unsigned int channels(const PixelFormat pixelFormat)
Returns the number of individual channels of a given pixel format.
PixelFormatUnion pixelFormat_
The pixel format of the frame encapsulated in a union (mainly holding PixelFormat).
Definition: Frame.h:1741
static std::string translateDataType(const DataType dataType)
Translates a data type value into a string containing the data type.
std::vector< DataType > DataTypes
Definition of a vector holding data types.
Definition: Frame.h:69
static unsigned int formatBitsPerPixelBlueChannel(const PixelFormat pixelFormat)
Returns the number of bits of one pixel for the blue channel.
static PixelFormat findPixelFormat(const unsigned int bitsPerPixel)
Returns a best fitting pixel format having the given number of bits per pixels.
DataType dataType() const
Returns the data type of the pixel format of this frame.
Definition: Frame.h:3163
static PixelFormat makeGenericPixelFormat(const PixelFormat pixelFormat)
Converts a any pixel format into a generic one This function has no effect for input pixel formats wh...
Definition: Frame.h:3399
static unsigned int planeChannels(const PixelFormat &imagePixelFormat, const unsigned int planeIndex)
Returns the channels of a plane for a pixel format.
bool isFrameTypeCompatible(const FrameType &frameType, const bool allowDifferentPixelOrigins) const
Returns whether this frame type is compatible with a given frame type.
Definition: Frame.h:3203
static constexpr uint32_t pixelFormatBitOffsetHeightMultiple
The number of bits the height-multiple value is shifted within the PixelFormat value.
Definition: Frame.h:86
static unsigned int formatGenericNumberChannels(const PixelFormat pixelFormat)
Returns the number of individual channels of a given generic pixel format.
Definition: Frame.h:3223
static std::string translatePixelOrigin(const PixelOrigin pixelOrigin)
Translates a pixel origin value into a string containing the pixel origin.
static bool formatIsGeneric(const PixelFormat pixelFormat, const DataType dataType, const uint32_t channels, const uint32_t planes=1u, const uint32_t widthMultiple=1u, const uint32_t heightMultiple=1u)
Checks whether a given pixel format is a specific layout regarding data channels and data type.
Definition: Frame.h:3406
static constexpr uint32_t pixelFormatBitOffsetPlanes
The number of bits the planes value is shifted within the PixelFormat value.
Definition: Frame.h:80
void setPixelFormat(const PixelFormat pixelFormat)
Explicitly changes the pixel format of this frame.
Definition: Frame.h:3158
static PixelFormat formatAddAlphaChannel(const PixelFormat pixelFormat, const bool lastChannel=true)
Adds an alpha channel to a given pixel format.
T Type
The data type of 'T'.
Definition: DataType.h:90
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
bool isEmpty() const
Returns whether this vector is empty.
Definition: StackHeapVector.h:570
size_t size() const
Returns the number of elements of this vector.
Definition: StackHeapVector.h:556
This class implements a timestamp.
Definition: Timestamp.h:36
std::vector< Frame > Frames
Definition of a vector holding padding frames.
Definition: Frame.h:1755
std::vector< FrameRef > FrameRefs
Definition of a vector holding frame references.
Definition: Frame.h:1767
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
uint32_t Index32
Definition of a 32 bit index value.
Definition: Base.h:84
void release(T *object)
This functions allows to release a DirectShow object if it does exist.
Definition: DSObject.h:266
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15
Default definition of a type with tBytes bytes.
Definition: DataType.h:32
Helper struct allowing to get access to the properties of a pixel format with a debugger.
Definition: Frame.h:1061
DataType dataType_
The data type of each elements of the pixel format.
Definition: Frame.h:1069
uint16_t predefinedPixelFormat_
The value of the pixel format if predefined (if the pixel format is e.g., FORMAT_RGB24,...
Definition: Frame.h:1063
uint8_t planes_
The number of individual planes of the pixel format.
Definition: Frame.h:1072
uint8_t heightMultiple_
The number of pixels the height of a frame must be a multiple of.
Definition: Frame.h:1078
uint8_t widthMultiple_
The number of pixels the width of a frame must be a multiple of.
Definition: Frame.h:1075
uint8_t unused_
Currently unused.
Definition: Frame.h:1081
uint8_t channels_
The number of channels, the pixel format has.
Definition: Frame.h:1066
This union mainly contains the pixel format as value.
Definition: Frame.h:1092
PixelFormat pixelFormat_
The actual pixel format defining the layout of the color space, the number of channels and the data t...
Definition: Frame.h:1107
PixelFormatProperties properties_
The properties of the pixel format.
Definition: Frame.h:1112
PixelFormatUnion(const PixelFormat &pixelFormat)
Creates a new union object based on a given pixel format.
Definition: Frame.h:3066