Ocean
Loading...
Searching...
No Matches
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"
16
17#include <type_traits>
18
19namespace 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 */
29class 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
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
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>
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 whether a given pixel format is using a limited value range (e.g., like Y_UV12_LIMITED_RANGE) or a full value range (e.g., like Y_UV12_FULL_RANGE).
1520 * @param pixelFormat The pixel format to be checked
1521 * @return True, if the pixel format is using a limited value range; False, if the pixel format is using a full value range
1522 */
1523 static bool formatIsLimitedRange(const PixelFormat pixelFormat);
1524
1525 /**
1526 * Returns the most suitable 1-plane pixel format for a given pixel format which may be composed of several planes.
1527 * If the given pixel format is a generic 1-plane pixel format already, the same pixel format will be returned.
1528 * Here is a table with some examples:
1529 * <pre>
1530 * Output pixel format: Input pixel format:
1531 * <generic pixel format> <generic pixel format> (e.g., FORMAT_RGB24)
1532 * FORMAT_BGR24 FORMAT_BGR4444, FORMAT_BGR5551, FORMAT_BGR565
1533 * FORMAT_BGRA32 FORMAT_BGRA4444
1534 * FORMAT_RGB24 FORMAT_RGB4444, FORMAT_RGB5551, FORMAT_RGB565
1535 * FORMAT_RGBA32 FORMAT_RGBA4444
1536 * FORMAT_YUV24, FORMAT_Y_UV12, FORMAT_UYVY16, FORMAT_Y_U_V12, FORMAT_YUYV16, FORMAT_Y_U_V24
1537 * FORMAT_YVU24 FORMAT_Y_VU12, FORMAT_Y_V_U12
1538 * </pre>
1539 * @param pixelFormat Pixel format for which the 1-plane pixel format will be returned
1540 * @return The resulting 1-plane pixel format, FORMAT_UNDEFINED if no matching pixel format could be found
1541 */
1543
1544 /**
1545 * Adds an alpha channel to a given pixel format.
1546 * @param pixelFormat Pixel format without alpha channel
1547 * @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
1548 * @return Pixel format with alpha channel, if existing
1549 */
1550 static PixelFormat formatAddAlphaChannel(const PixelFormat pixelFormat, const bool lastChannel = true);
1551
1552 /**
1553 * Removes an alpha channel from a given pixel format.
1554 * @param pixelFormat Pixel format with alpha channel
1555 * @return Pixel format without alpha channel, if existing
1556 */
1558
1559 /**
1560 * Returns the best matching grayscale pixel format for a given pixel format.
1561 * The resulting pixel format will either be FORMAT_Y8_LIMITED_RANGE or FORMAT_Y8_FULL_RANGE, depending on the whether the input pixel format is a limited range or a full range pixel format.<br>
1562 * The function can be used to quickly determine the grayscale pixel format for an input image to avoid making a copy of the image during conversion:
1563 * <pre>
1564 * Frame inputFrame = ... // e.g., FORMAT_RGB24, or FORMAT_Y_UV12_LIMITED_RANGE, or FORMAT_Y_UV12_FULL_RANGE
1565 * Frame yFrame; // a frame with either FORMAT_Y8_LIMITED_RANGE or FORMAT_Y8_FULL_RANGE
1566 * CV::FrameConverter::Comfort::convert(inputFrame, FrameType::formatGrayscalePixelFormat(inputFrame.pixelFormat()), yFrame, CV::FrameConverter::CP_AVOID_COPY_IF_POSSIBLE);
1567 * </pre>
1568 * @param pixelFormat The pixel format for which the best matching grayscale pixel format will be returned, must be valid
1569 * @return The best matching grayscale pixel format, either FORMAT_Y8_LIMITED_RANGE or FORMAT_Y8_FULL_RANGE
1570 */
1572
1573 /**
1574 * Returns the number of pixels the width of a frame must be a multiple of.
1575 * @param pixelFormat Pixel format to return the number of pixels for
1576 * @return Number of pixels
1577 */
1578 static inline unsigned int widthMultiple(const PixelFormat pixelFormat);
1579
1580 /**
1581 * Returns the number of pixels the height of a frame must be a multiple of.
1582 * @param pixelFormat Pixel format to return the number of pixels for
1583 * @return Number of pixels
1584 */
1585 static inline unsigned int heightMultiple(const PixelFormat pixelFormat);
1586
1587 /**
1588 * Returns the channels of a plane for a pixel format.
1589 * @param imagePixelFormat The pixel format of the entire frame, must be valid
1590 * @param planeIndex The index of the plane for which the channels will be returned, with range [0, numberPlanes(imagePixelFormat))
1591 * @return The plane's channels, with range [0, infinity)
1592 */
1593 static unsigned int planeChannels(const PixelFormat& imagePixelFormat, const unsigned int planeIndex);
1594
1595 /**
1596 * Returns the number of bytes of one pixel of a plane for a pixel format.
1597 * 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.
1598 * @param imagePixelFormat The pixel format of the entire frame, must be valid
1599 * @param planeIndex The index of the plane for which the bytes per pixel will be returned, with range [0, numberPlanes(imagePixelFormat))
1600 * @return The plane's number of bytes per pixel, will be 0 for special packed pixel formats like FORMAT_Y10_PACKED
1601 */
1602 static inline unsigned int planeBytesPerPixel(const PixelFormat& imagePixelFormat, const unsigned int planeIndex);
1603
1604 /**
1605 * Returns the plane layout of a given pixel format.
1606 * @param imagePixelFormat The pixel format of the image for which the plane layout will be returned, must be valid
1607 * @param imageWidth The width of the image, in (image) pixel, with range [1, infinity)
1608 * @param imageHeight The height of the image, in (image) pixel, with range [1, infinity)
1609 * @param planeIndex The index of the plane for which the layout will be returned, with range [0, numberPlanes(imagePixelFormat) - 1]
1610 * @param planeWidth The resulting width of the specified plane, in (plane) pixel, with range [1, infinity)
1611 * @param planeHeight The resulting height of the specified plane, in (plane) pixel, with range [1, infinity)
1612 * @param planeChannels The resulting number of channels the plane has, with range [1, infinity)
1613 * @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)
1614 * @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)
1615 * @return True, if succeeded
1616 */
1617 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);
1618
1619 /**
1620 * Returns the plane layout of a given frame type.
1621 * @param frameType The frame type for which the plane layout will be returned, must be valid
1622 * @param planeIndex The index of the plane for which the layout will be returned, with range [0, numberPlanes(imagePixelFormat) - 1]
1623 * @param planeWidth The resulting width of the specified plane, in (plane) pixel, with range [1, infinity)
1624 * @param planeHeight The resulting height of the specified plane, in (plane) pixel, with range [1, infinity)
1625 * @param planeChannels The resulting number of channels the plane has, with range [1, infinity)
1626 * @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)
1627 * @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)
1628 * @return True, if succeeded
1629 */
1630 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);
1631
1632 /**
1633 * Translates a string containing a data type into the data type.<br>
1634 * For example 'UNSIGNED_INTEGER_8' will be translated into DT_UNSIGNED_INTEGER_8.
1635 * @param dataType Data type as string
1636 * @return Data type as value
1637 */
1638 static DataType translateDataType(const std::string& dataType);
1639
1640 /**
1641 * Translates a string containing a pixel format into the pixel format.<br>
1642 * For example 'BGR24' will be translated into FORMAT_BGR24.
1643 * @param pixelFormat Pixel format as string
1644 * @return Pixel format as value
1645 */
1646 static PixelFormat translatePixelFormat(const std::string& pixelFormat);
1647
1648 /**
1649 * Translates a string containing the pixel origin into the pixel origin value.<br>
1650 * For example 'UPPER_LEFT' will be translated into ORIGIN_UPPER_LEFT.
1651 * @param pixelOrigin Pixel origin as string
1652 * @return Pixel origin as value
1653 */
1654 static PixelOrigin translatePixelOrigin(const std::string& pixelOrigin);
1655
1656 /**
1657 * Translates a data type value into a string containing the data type.<br>
1658 * For example the DT_UNSIGNED_INTEGER_8 will be translated into 'UNSIGNED_INTEGER_8'.
1659 * @param dataType the data type as value
1660 * @return The data type as string, 'UNDEFINED' if the data type is invalid or cannot be translated
1661 */
1662 static std::string translateDataType(const DataType dataType);
1663
1664 /**
1665 * Translates a pixel format value into a string containing the pixel format.<br>
1666 * For example the FORMAT_BGR24 will be translated into 'BGR24'.
1667 * @param pixelFormat Pixel format as value
1668 * @return Pixel format as string, 'UNDEFINED' if the pixel format is invalid or cannot be translated
1669 */
1670 static std::string translatePixelFormat(const PixelFormat pixelFormat);
1671
1672 /**
1673 * Translates a pixel origin value into a string containing the pixel origin.<br>
1674 * For example the ORIGIN_UPPER_LEFT will be translated into 'UPPER_LEFT'.
1675 * @param pixelOrigin Pixel origin as value
1676 * @return Pixel origin as string, 'INVALID' if the pixel origin is invalid or cannot be translated
1677 */
1678 static std::string translatePixelOrigin(const PixelOrigin pixelOrigin);
1679
1680 /**
1681 * Returns a best fitting pixel format having the given number of bits per pixels.
1682 * @param bitsPerPixel Number of bits per pixel the resulting pixel format will have, with range [1, infinity)
1683 * @return Resulting pixel format, FORMAT_UNDEFINED if no pixel format can be found
1684 */
1685 static PixelFormat findPixelFormat(const unsigned int bitsPerPixel);
1686
1687 /**
1688 * Returns a best fitting pixel format having the given number of bits per pixels.
1689 * The following mappings are defined:
1690 * <pre>
1691 * DataType: Channels: PixelFormat:
1692 * DT_UNSIGNED_INTEGER_8 1 FORMAT_Y8
1693 * DT_UNSIGNED_INTEGER_8 2 FORMAT_YA16
1694 * DT_UNSIGNED_INTEGER_8 3 FORMAT_RGB24
1695 * DT_UNSIGNED_INTEGER_8 4 FORMAT_RGBA32
1696 *
1697 * DT_UNSIGNED_INTEGER_16 3 FORMAT_RGB48
1698 * DT_UNSIGNED_INTEGER_16 4 FORMAT_RGBA64
1699 * </pre>
1700 * @param dataType The data type of each pixel element for which a pixel type is determined, must be valid
1701 * @param channels The number of channels for which a pixel format will be determined, with range [1, infinity)
1702 * @return Resulting pixel format, FORMAT_UNDEFINED if no pixel format can be found
1703 */
1704 static PixelFormat findPixelFormat(const DataType dataType, const unsigned int channels);
1705
1706 /**
1707 * Returns whether two given pixel formats are compatible.
1708 * Two pixel formats are compatible if:
1709 * - Both pixel formats are identical, or
1710 * - Both pixel formats are pure generic pixel formats with identical data type and channel number, or
1711 * - 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
1712 * @param pixelFormatA The first pixel format to be checked, must be valid
1713 * @param pixelFormatB The second pixel format to be checked, must be valid
1714 * @return True, if both pixel formats are compatible
1715 * @see areFrameTypesCompatible().
1716 */
1717 static bool arePixelFormatsCompatible(const PixelFormat pixelFormatA, const PixelFormat pixelFormatB);
1718
1719 /**
1720 * Returns whether two given frame types are compatible.
1721 * Two frame types are compatible if:
1722 * - Both types are identical, or
1723 * - Both types have the same dimension and compatible pixel formats
1724 * @param frameTypeA The first frame type to be checked, must be valid
1725 * @param frameTypeB The second frame type to be checked, must be valid
1726 * @param allowDifferentPixelOrigins True, to allow different pixel origins; False, so that both frame types must have the same pixel origin
1727 * @return True, if both frame types are compatible
1728 * @see arePixelFormatsCompatible().
1729 */
1730 static bool areFrameTypesCompatible(const FrameType& frameTypeA, const FrameType& frameTypeB, const bool allowDifferentPixelOrigins);
1731
1732 /**
1733 * Returns whether a given pointer has the same byte alignment as the size of the data type the pointer is pointing to.
1734 * Actually, this function returns whether the following condition is true:
1735 * <pre>
1736 * size_t(data) % sizeof(T) == 0
1737 * </pre>
1738 * @param data The pointer to the memory to be checked, must be valid
1739 * @return True, if so
1740 */
1741 template <typename T>
1742 static inline bool dataIsAligned(const void* data);
1743
1744 /**
1745 * Returns all defined data types.
1746 * @return Ocean's defined data types
1747 */
1749
1750 /**
1751 * Returns all defined pixel formats.
1752 * @return Ocean's defined pixel formats
1753 */
1755
1756 /**
1757 * Returns whether two values can be added with each other without producing an overflow.
1758 * @param valueA The first value to add
1759 * @param valueB The second value to add
1760 * @return True, if the sum is within a valid value range
1761 */
1762 static constexpr bool isSumInsideValueRange(const unsigned int valueA, const unsigned int valueB);
1763
1764 /**
1765 * Returns whether two values can be multiplied with each other without producing an overflow.
1766 * @param valueA The first value to multiply
1767 * @param valueB The second value to multiply
1768 * @return True, if the product is within a valid value range
1769 */
1770 static constexpr bool isProductInsideValueRange(const unsigned int valueA, const unsigned int valueB);
1771
1772 private:
1773
1774 /// Frame width in pixel, with range [0, infinity)
1775 unsigned int width_ = 0u;
1776
1777 /// Frame height in pixel, with range [0, infinity)
1778 unsigned int height_ = 0u;
1779
1780 /// The pixel format of the frame encapsulated in a union (mainly holding PixelFormat).
1781 PixelFormatUnion pixelFormat_ = PixelFormatUnion(FORMAT_UNDEFINED);
1782
1783 /// The origin of the pixel data, either the upper left corner or the bottom left corner (if valid).
1784 PixelOrigin pixelOrigin_ = ORIGIN_INVALID;
1785};
1786
1787// Forward declaration.
1788class Frame;
1789
1790/**
1791 * Definition of a vector holding padding frames.
1792 * @see Frame.
1793 * @ingroup base
1794 */
1795using Frames = std::vector<Frame>;
1796
1797/**
1798 * Definition of an object reference for frame objects.
1799 * @ingroup base
1800 */
1802
1803/**
1804 * Definition of a vector holding frame references.
1805 * @ingroup base
1806 */
1807using FrameRefs = std::vector<FrameRef>;
1808
1809/**
1810 * This class implements Ocean's image class.
1811 * An image is composed of several planes, each plane can store image content with interleaved color channels.
1812 * <pre>
1813 * Plane 0:
1814 * ---------------------------------- ----------------------------
1815 * | | |
1816 * | | |
1817 * | |<--- paddingElements(0) --->| plane height (0)
1818 * | | |
1819 * | | |
1820 * ---------------------------------- ----------------------------
1821 *
1822 * Plane 1:
1823 * -------------- ------------------------
1824 * | | |
1825 * | |<- paddingElements(1) ->| plane height (1)
1826 * | | |
1827 * -------------- ------------------------
1828 * </pre>
1829 * @ingroup base
1830 */
1831class OCEAN_BASE_EXPORT Frame : public FrameType
1832{
1833 public:
1834
1835 /**
1836 * Definition of individual copy modes.
1837 */
1838 enum CopyMode : uint32_t
1839 {
1840 /// The source memory is used only, no copy is created, the padding layout is preserved.
1841 CM_USE_KEEP_LAYOUT = 1u << 0u,
1842 /// Makes a copy of the source memory, but the new plane will not contain padding elements.
1843 CM_COPY_REMOVE_PADDING_LAYOUT = 1u << 1u,
1844 /// Makes a copy of the source memory, the padding layout is preserved, but the padding data is not copied.
1845 CM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA = 1u << 2u,
1846 /// Makes a copy of the source memory, the padding layout is preserved, the padding data is copied as well.
1847 CM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA = 1u << 3u,
1848 };
1849
1850 /**
1851 * Definition of advanced copy modes containing all copy modes from `CopyMode` but also some additional.
1852 */
1853 enum AdvancedCopyMode : std::underlying_type<CopyMode>::type
1854 {
1855 /// Same as CM_USE_KEEP_LAYOUT.
1856 ACM_USE_KEEP_LAYOUT = CM_USE_KEEP_LAYOUT,
1857 /// Same as CM_COPY_REMOVE_PADDING_LAYOUT.
1858 ACM_COPY_REMOVE_PADDING_LAYOUT = CM_COPY_REMOVE_PADDING_LAYOUT,
1859 /// Same as CM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA.
1860 ACM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA = CM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA,
1861 /// Same as CM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA.
1862 ACM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA = CM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA,
1863
1864 /// 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.
1865 ACM_USE_OR_COPY = ACM_USE_KEEP_LAYOUT | ACM_COPY_REMOVE_PADDING_LAYOUT,
1866 /// 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.
1867 ACM_USE_OR_COPY_KEEP_LAYOUT = ACM_USE_KEEP_LAYOUT | ACM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA,
1868 };
1869
1870 /**
1871 * Definition of an image plane, a block of memory storing pixel data with interleaved channels (or just one channel).
1872 * 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.
1873 * A plane has the following memory layout:
1874 * <pre>
1875 * |<-------- plane width ----------->|<-- paddingElements -->|
1876 *
1877 * ---------------------------------- ----------------------- ---
1878 * |A0 A1 An-1 B0 B1 Bn-1 ... | | ^
1879 * |... | | |
1880 * | | | plane height
1881 * | | | |
1882 * | | | V
1883 * ---------------------------------- ----------------------- ---
1884 *
1885 * |<------------------- stride bytes ----------------------->|
1886 *
1887 * With A0 first channel (or element) of first pixel, A1 second channel of first pixel, ...
1888 * And B0 first channel of second pixel, ...
1889 * </pre>
1890 * Note that: strideBytes == (planeWidth * channels + paddingElements) * bytesPerElement.<br>
1891 * A plane can have a different number of channels than a frame's pixel format which is owning the plane.<br>
1892 * The plane's channels are defined in relation to the data type of each pixel:<br>
1893 * 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>
1894 * 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).
1895 */
1896 class OCEAN_BASE_EXPORT Plane
1897 {
1898 friend class Frame;
1899
1900 public:
1901
1902 /**
1903 * Creates a new invalid plane.
1904 */
1905 Plane() = default;
1906
1907 /**
1908 * Move constructor.
1909 * @param plane The plane to be moved
1910 */
1911 inline Plane(Plane&& plane) noexcept;
1912
1913 /**
1914 * Copy constructor.
1915 * @param plane The plane to be copied, can be invalid
1916 * @param advancedCopyMode The copy mode specifying whether the source memory is used or copied
1917 */
1918 Plane(const Plane& plane, const AdvancedCopyMode advancedCopyMode = ACM_USE_OR_COPY_KEEP_LAYOUT) noexcept;
1919
1920 /**
1921 * Creates a new plane object with own allocated memory.
1922 * @param width The width of the plane in pixel, with range [1, infinity)
1923 * @param height The height of the plane in pixel, with range [1, infinity)
1924 * @param channels The number of channels the plane has, with respect to the specified data type `T`, with range [1, infinity)
1925 * @param elementTypeSize The size of each element of the new plane, in bytes, with range [1, infinity)
1926 * @param paddingElements The optional number of padding elements at the end of each row, in elements, with range [0, infinity)
1927 */
1928 Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, const unsigned int paddingElements) noexcept;
1929
1930 /**
1931 * Creates a new plane object which is not creating a copy of the given memory. Instead, the memory pointer is just used.
1932 * @param width The width of the plane in pixels, one pixel has size `sizeof(T) * channels`, with range [1, infinity)
1933 * @param height The height of the plane in pixel, with range [1, infinity)
1934 * @param channels The number of channels the plane has, with respect to the specified data type `T`, with range [1, infinity)
1935 * @param dataToUse Memory pointer of the read-only memory which will not be copied, must be valid
1936 * @param paddingElements The optional number of padding elements at the end of each row, in elements, with range [0, infinity)
1937 * @tparam T The data type of each element
1938 */
1939 template <typename T>
1940 inline Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const T* dataToUse, const unsigned int paddingElements) noexcept;
1941
1942 /**
1943 * Creates a new plane object which is not creating a copy of the given memory. Instead, the memory pointer is just used.
1944 * @param width The width of the plane in pixels, one pixel has size `sizeof(T) * channels`, with range [1, infinity)
1945 * @param height The height of the plane in pixel, with range [1, infinity)
1946 * @param channels The number of channels the plane has, with respect to the specified data type `T`, with range [1, infinity)
1947 * @param dataToUse Memory pointer of the writable memory which will not be copied, must be valid
1948 * @param paddingElements The optional number of padding elements at the end of each row, in elements, with range [0, infinity)
1949 * @tparam T The data type of each element
1950 */
1951 template <typename T>
1952 inline Plane(const unsigned int width, const unsigned int height, const unsigned int channels, T* dataToUse, const unsigned int paddingElements) noexcept;
1953
1954 /**
1955 * Creates a new plane object by making a copy of the given memory.
1956 * @param sourceDataToCopy The source data to be copied, must be valid
1957 * @param width The width of the plane in pixels, one pixel has size `sizeof(T) * channels`, with range [1, infinity)
1958 * @param height The height of the plane in pixels, with range [1, infinity)
1959 * @param channels The number of channels the plane has, with respect to the specified data type `T`, with range [1, infinity)
1960 * @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)
1961 * @param sourcePaddingElements The number of padding elements at the end of each row the given source memory has, in elements, with range [0, infinity)
1962 * @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
1963 * @tparam T The data type of each element
1964 */
1965 template <typename T>
1966 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;
1967
1968 /**
1969 * Creates a new plane object by making a copy of the given memory.
1970 * @param sourceDataToCopy The source data to be copied, must be valid
1971 * @param width The width of the plane in pixels, one pixel has size `sizeof(T) * channels`, with range [1, infinity)
1972 * @param height The height of the plane in pixels, with range [1, infinity)
1973 * @param channels The number of channels the plane has, with respect to the specified data type `T`, with range [1, infinity)
1974 * @param sourcePaddingElements The number of padding elements at the end of each row the given source memory has, in elements, with range [0, infinity)
1975 * @param copyMode The copy mode to be applied
1976 * @tparam T The data type of each element
1977 */
1978 template <typename T>
1979 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;
1980
1981 /**
1982 * Destructs a Plane object.
1983 */
1984 inline ~Plane();
1985
1986 /**
1987 * Returns the width of the plane in pixel.
1988 * @return The plane's width, in pixel, with range [0, infinity)
1989 */
1990 inline unsigned int width() const;
1991
1992 /**
1993 * Returns the height of the plane in pixel.
1994 * @return The plane's height, in pixel, with range [0, infinity)
1995 */
1996 inline unsigned int height() const;
1997
1998 /**
1999 * Returns the channels of the plane.
2000 * @return The plane's channels, with range [0, infinity)
2001 */
2002 inline unsigned int channels() const;
2003
2004 /**
2005 * Returns the read-only memory pointer to this plane with a specific data type compatible with elementTypeSize().
2006 * @return The plane's read-only memory pointer, nullptr if this plane is invalid
2007 * @tparam T the data type of the resulting memory pointer, with `sizeof(T) == elementTypeSize()`
2008 */
2009 template <typename T>
2010 inline const T* constdata() const;
2011
2012 /**
2013 * Returns the writable memory pointer to this plane with a specific data type compatible with elementTypeSize().
2014 * @return The plane's writable memory pointer, nullptr if this plane is not writable or invalid
2015 * @tparam T the data type of the resulting memory pointer, with `sizeof(T) == elementTypeSize()`
2016 */
2017 template <typename T>
2018 inline T* data();
2019
2020 /**
2021 * Returns the number of padding elements at the end of each plane row, in elements.
2022 * @return The number of padding elements, with range [0, infinity)
2023 * @see paddingBytes().
2024 */
2025 inline unsigned int paddingElements() const;
2026
2027 /**
2028 * Returns the number of padding bytes at the end of each plane row, in bytes.
2029 * This function actually returns `paddingElements() * elementTypeSize()`.
2030 * @return The number of padding bytes, with range [0, infinity)
2031 * @see paddingElements().
2032 */
2033 inline unsigned int paddingBytes() const;
2034
2035 /**
2036 * Returns the size of each element of this plane.
2037 * @return The element size, in bytes
2038 */
2039 inline unsigned int elementTypeSize() const;
2040
2041 /**
2042 * Returns the width of the plane in elements, the width does not contain optional padding elements.
2043 * 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):
2044 * <pre>
2045 * widthElements == width * channels == strideElements() - paddingElements()
2046 * </pre>
2047 * @return The number of elements, with range [0, infinity)
2048 */
2049 inline unsigned int widthElements() const;
2050
2051 /**
2052 * Returns the width of the plane in bytes, the width does not contain optional padding elements.
2053 * 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):
2054 * <pre>
2055 * widthBytes == width * channels * elementTypeSize() == strideBytes - elementTypeSize() * paddingElements()
2056 * </pre>
2057 * @return The number of bytes, with range [0, infinity)
2058 */
2059 inline unsigned int widthBytes() const;
2060
2061 /**
2062 * Returns the number of elements between the start positions of two consecutive rows, in elements.
2063 * This function actually returns `width * channels + paddingElements`.
2064 * @return The number of elements, with range [width * elementsPerPixel, infinity)
2065 */
2066 inline unsigned int strideElements() const;
2067
2068 /**
2069 * Returns the number of bytes between the start positions of two consecutive rows, in bytes.
2070 * @return The number of bytes, with range [width * bytesPerPlanePixel, infinity)
2071 */
2072 inline unsigned int strideBytes() const;
2073
2074 /**
2075 * Returns the number of bytes which is used for each pixel.
2076 * @return The number of bytes, with range [1, infinity), 0 if unknown
2077 */
2078 inline unsigned int bytesPerPixel() const;
2079
2080 /**
2081 * Releases this plane and all resources of this plane.
2082 */
2083 void release();
2084
2085 /**
2086 * Returns whether this plane is compatible with a given element data type.
2087 * @tparam T The data type to be checked
2088 * @return True, if so
2089 */
2090 template <typename T>
2091 inline bool isCompatibleWithDataType() const;
2092
2093 /**
2094 * Returns the number of bytes necessary for the entire plane data including optional padding elements at the end of each row.
2095 * This function actually returns `strideBytes() * height()`.
2096 * @return Plane size in bytes, with range [0, infinity)
2097 */
2098 inline unsigned int size() const;
2099
2100 /**
2101 * Returns whether this plane is based on continuous memory and thus does not have any padding at the end of rows.
2102 * @return True, if so
2103 */
2104 inline bool isContinuous() const;
2105
2106 /**
2107 * Returns whether this plane is the owner of the memory.
2108 * @return True, if the plane is the owner; False, if someone else is the owner
2109 */
2110 inline bool isOwner() const;
2111
2112 /**
2113 * Returns whether this plane holds read-only memory.
2114 * @return True, if the memory of the plane is not writable
2115 */
2116 inline bool isReadOnly() const;
2117
2118 /**
2119 * Returns whether this plane holds valid data.
2120 * @return True, if so; False, if the plane is empty
2121 */
2122 inline bool isValid() const;
2123
2124 /**
2125 * Copies data from another plane into this plane.
2126 * 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`.
2127 * @param sourcePlane The source plane from which the memory will be copied, an invalid plane to release this plane
2128 * @param advancedCopyMode The copy mode specifying whether the source memory is used or copied
2129 * @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
2130 * @return True, if succeeded
2131 */
2132 bool copy(const Plane& sourcePlane, const AdvancedCopyMode advancedCopyMode = ACM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA, const bool reallocateIfNecessary = true);
2133
2134 /**
2135 * Move operator.
2136 * @param plane The plane to be moved
2137 * @return The reference to this object
2138 */
2139 Plane& operator=(Plane&& plane) noexcept;
2140
2141 /**
2142 * Copy operator.
2143 * This plane will have the same stride/padding layout. However, the padding memory will not be copied.
2144 * If the source plane is owner of the memory, this plane will be owner of an own copy of the memory.
2145 * 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.
2146 * @param plane The plane to be copied
2147 * @return Reference to this object
2148 */
2149 Plane& operator=(const Plane& plane) noexcept;
2150
2151 /**
2152 * Allocates memory with specific byte alignment.
2153 * @param size The size of the resulting buffer in bytes, with range [0, infinity)
2154 * @param alignment The requested byte alignment, with range [1, infinity)
2155 * @param alignedData the resulting pointer to the aligned memory
2156 * @return The allocated memory with arbitrary alignment
2157 */
2158 static void* alignedMemory(const size_t size, const size_t alignment, void*& alignedData);
2159
2160 /**
2161 * Returns whether the memory layout of a plane is valid (and fits into the memory).
2162 * @param planeWidth The width of the plane, in pixel, with range [0, infinity)
2163 * @param planeHeight The height of the plane, in pixel, with range [0, infinity)
2164 * @param planeChannels The channels of the plane, with range [0, infinity)
2165 * @param bytesPerElement The number of bytes each element has, with range [1, infinity)
2166 * @param paddingElements The optional number of padding elements at the end of each plane row, in elements, with range [0, infinity)
2167 * @return True, if so; False, if the memory usage is out of bounds
2168 */
2169 static constexpr bool validateMemoryLayout(const unsigned int planeWidth, const unsigned int planeHeight, const unsigned int planeChannels, const unsigned int bytesPerElement, const unsigned int paddingElements);
2170
2171 protected:
2172
2173 /**
2174 * Creates a new plane object which is not creating a copy of the given memory. Instead, the memory pointer is just used.
2175 * @param width The width of the plane, in pixel, with range [0, infinity)
2176 * @param height The height of the plane, in pixel, with range [0, infinity)
2177 * @param channels The channels of the plane, with range [0, infinity)
2178 * @param elementTypeSize The size of each element in bytes, which is `sizeof(T)`, with range [1, infinity)
2179 * @param constData The value for `constData` to be set
2180 * @param data The value for `data` to be set
2181 * @param paddingElements The optional number of padding elements at the end of each row, in elements, with range [0, infinity)
2182 */
2183 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;
2184
2185 /**
2186 * Creates a new plane object which is not creating a copy of the given memory. Instead, the memory pointer is just used.
2187 * @param width The width of the plane, in pixel, with range [0, infinity)
2188 * @param height The height of the plane, in pixel, with range [0, infinity)
2189 * @param channels The channels of the plane, with range [0, infinity)
2190 * @param elementTypeSize The size of each element in bytes, which is `sizeof(T)`, with range [1, infinity)
2191 * @param dataToUse Memory pointer of the read-only memory which will not be copied, must be valid
2192 * @param paddingElements The number of padding elements at the end of each row, in elements, with range [0, infinity)
2193 */
2194 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;
2195
2196 /**
2197 * Creates a new plane object which is not creating a copy of the given memory. Instead, the memory pointer is just used.
2198 * @param width The width of the plane, in pixel, with range [0, infinity)
2199 * @param height The height of the plane, in pixel, with range [0, infinity)
2200 * @param channels The channels of the plane, with range [0, infinity)
2201 * @param elementTypeSize The size of each element in bytes, which is `sizeof(T)`, with range [1, infinity)
2202 * @param dataToUse Memory pointer of the read-only memory which will not be copied, must be valid
2203 * @param paddingElements The number of padding elements at the end of each row, in elements, with range [0, infinity)
2204 */
2205 Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int elementTypeSize, void* dataToUse, const unsigned int paddingElements) noexcept;
2206
2207 /**
2208 * Creates a new plane object by making a copy of the given memory.
2209 * @param width The width of the plane in pixels, one pixel has size `sizeof(T) * channels`, with range [1, infinity)
2210 * @param height The height of the plane in pixels, with range [1, infinity)
2211 * @param channels The number of channels the plane has, with respect to the specified data type, with range [1, infinity)
2212 * @param elementTypeSize The size of each element in bytes, which is `sizeof(T)`, with range [1, infinity)
2213 * @param sourceDataToCopy The source data to be copied, must be valid
2214 * @param targetPaddingElements The number of padding elements at the end of each row this new plane will have, in elements, with range [0, infinity)
2215 * @param sourcePaddingElements The number of padding elements at the end of each row the given source memory has, in elements, with range [0, infinity)
2216 * @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
2217 */
2218 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;
2219
2220 /**
2221 * Creates a new plane object by making a copy of the given memory.
2222 * @param width The width of the plane in pixels, one pixel has size `sizeof(T) * channels`, with range [1, infinity)
2223 * @param height The height of the plane in pixels, with range [1, infinity)
2224 * @param channels The number of channels the plane has, with respect to the specified data type, with range [1, infinity)
2225 * @param elementTypeSize The size of each element in bytes, which is `sizeof(T)`, with range [1, infinity)
2226 * @param sourceDataToCopy The source data to be copied, must be valid
2227 * @param sourcePaddingElements The number of padding elements at the end of each row the given source memory has, in elements, with range [0, infinity)
2228 * @param copyMode The copy mode to be applied
2229 */
2230 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;
2231
2232 /**
2233 * Copies memory into this plane which has compatible memory already.
2234 * @param sourceData The source data from a compatible plane, must be valid
2235 * @param sourceStrideBytes The number of bytes between the start positions of two consecutive rows in the source plane, in bytes, with range [strideBytes(), infinity)
2236 * @param sourcePaddingElements The number of padding elements at the end of each row, in elements, with range [0, infinity)
2237 * @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
2238 */
2239 void copy(const void* sourceData, const unsigned int sourceStrideBytes, const unsigned int sourcePaddingElements, const bool makeCopyOfPaddingData = false);
2240
2241 /**
2242 * Calculates the number of bytes between the start positions of two consecutive rows, in bytes.
2243 * @return The number of bytes, with range [width * bytesPerPlanePixel, infinity).
2244 */
2245 inline unsigned int calculateStrideBytes() const;
2246
2247 /**
2248 * Calculates the number of bytes per pixel.
2249 * @return The number of bytes, with range [1, infinity), 0 if unknown
2250 */
2251 unsigned int calculateBytesPerPixel() const;
2252
2253 protected:
2254
2255 /// 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.
2256 void* allocatedData_ = nullptr;
2257
2258 /// 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.
2259 const void* constData_ = nullptr;
2260
2261 /// The pointer to the writable memory of the plane (not the pointer to the allocated memory), nullptr if the plane is not writable.
2262 void* data_ = nullptr;
2263
2264 /// The width of the plane in pixel, with range [0, infinity).
2265 unsigned int width_ = 0u;
2266
2267 /// The height of the plane in pixel, with range [0, infinity).
2268 unsigned int height_ = 0u;
2269
2270 /// The number of channels the plane has, with range [0, infinity).
2271 unsigned int channels_ = 0u;
2272
2273 /// The size of each element of this plane, in bytes, with range [0, infinity).
2274 unsigned int elementTypeSize_ = 0u;
2275
2276 /// The number of padding elements at the end of each plane row, in elements, with range [0, infinity).
2277 unsigned int paddingElements_ = 0u;
2278
2279 /// The number of bytes between the start positions of two consecutive rows, in bytes, identical to '(width_ * channels_ + paddingElements_) * elementTypeSize_`
2280 unsigned int strideBytes_ = 0u;
2281
2282 /// The number of bytes per pixel, with range [1, infinity), 0 if unknown.
2283 unsigned int bytesPerPixel_ = 0u;
2284 };
2285
2286 /**
2287 * Definition of a vector storing planes.
2288 */
2290
2291 /**
2292 * This class implements a helper class which can be used to initialize a multi-plane frame in the constructor.
2293 * The class is mainly a temporary storage for memory pointers, copy modes, and number of padding elements.
2294 * @tparam T The data type of the frame's element type, can be `void` if unknown
2295 */
2296 template <typename T>
2298 {
2299 friend class Frame;
2300
2301 public:
2302
2303 /**
2304 * Creates a new initializer object for a read-only memory pointer.
2305 * @param constdata The read-only memory pointer to the plane data, must be valid
2306 * @param copyMode The copy mode to be applied when initializing the plane
2307 * @param dataPaddingElements The number of padding elements at the end of each row of the given memory pointer, in elements, with range [0, infinity)
2308 */
2309 inline PlaneInitializer(const T* constdata, const CopyMode copyMode, const unsigned int dataPaddingElements = 0u);
2310
2311 /**
2312 * Creates a new initializer object for a writable memory pointer.
2313 * @param data The writable memory pointer to the plane data, must be valid
2314 * @param copyMode The copy mode to be applied when initializing the plane
2315 * @param dataPaddingElements The number of padding elements at the end of each row of the given memory pointer, in elements, with range [0, infinity)
2316 */
2317 inline PlaneInitializer(T* data, const CopyMode copyMode, const unsigned int dataPaddingElements = 0u);
2318
2319 /**
2320 * Creates a new initializer object for a new plane for which the number of padding elements is known.
2321 * @param planePaddingElements The number of padding elements at the end of each row of the resulting plane, in elements, with range [0, infinity)
2322 */
2323 explicit inline PlaneInitializer(const unsigned int planePaddingElements = 0u);
2324
2325 protected:
2326
2327 /**
2328 * Creates plane initializer objects with padding elements only.
2329 * @param paddingElementsPerPlane The padding elements one value for each plane
2330 * @return The resulting plane initializer objects
2331 */
2332 static std::vector<PlaneInitializer<T>> createPlaneInitializersWithPaddingElements(const Indices32& paddingElementsPerPlane);
2333
2334 protected:
2335
2336 /// The pointer to the read-only source memory, can be nullptr.
2337 const T* constdata_ = nullptr;
2338
2339 /// The pointer to the writable source memory, can be nullptr.
2340 T* data_ = nullptr;
2341
2342 /// The copy mode to be applied, unused if `constdata_ == nullptr` and `data_ == nullptr`.
2343 CopyMode copyMode_ = CopyMode(0u);
2344
2345 /// 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)
2346 unsigned int paddingElements_ = 0u;
2347 };
2348
2349 /**
2350 * Definition of a vector holding plane initializer objects.
2351 * @tparam T The data type of the frame's element type.
2352 */
2353 template <typename T>
2354 using PlaneInitializers = std::vector<PlaneInitializer<T>>;
2355
2356 /**
2357 * Definition of a data type storing all channel values of one pixel in an array.
2358 * @tparam T The data type of each pixel channel
2359 * @tparam tChannels The number of channels the pixel has, with range [1, infinity)
2360 */
2361 template <typename T, unsigned int tChannels>
2363
2364 public:
2365
2366 /**
2367 * Creates an empty frame.
2368 */
2369 inline Frame();
2370
2371 /**
2372 * Creates a second version of a given frame.
2373 * 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>
2374 * 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>
2375 * Thus, the following two lines of code produce the same result:
2376 * @code
2377 * Frame newFrameA(frame);
2378 * Frame newFrameB(frame, ACM_USE_OR_COPY);
2379 * ocean_assert(newFrameB.isOwner() == false || newFrameB.isContinuous());
2380 * @endcode
2381 * This function behaves similar like the normal assign operator.
2382 * Whenever a copy is created, the memory layout of the resulting frame will be continuous.
2383 * @param frame The frame to copy
2384 */
2385 Frame(const Frame& frame);
2386
2387 /**
2388 * Move constructor.
2389 * @param frame The frame to be moved
2390 */
2391 inline Frame(Frame&& frame) noexcept;
2392
2393 /**
2394 * Creates a second version of a given frame.
2395 * Beware: The pixel memory will either be copied or used only, this depends on 'advancedCopyMode'.<br>
2396 * @param frame The frame to copy, can be invalid
2397 * @param advancedCopyMode The copy mode to be applied
2398 */
2399 Frame(const Frame& frame, const AdvancedCopyMode advancedCopyMode) noexcept;
2400
2401 /**
2402 * Creates a frame with specified width, height, pixel format and frame origin and an optional padding.
2403 * The necessary buffer is allocated but not initialized.
2404 * @param frameType Type of the frame, must be valid
2405 * @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
2406 * @param timestamp The timestamp of the frame
2407 */
2408 explicit inline Frame(const FrameType& frameType, const Indices32& paddingElementsPerPlane = Indices32(), const Timestamp& timestamp = Timestamp(false));
2409
2410 /**
2411 * Deprecated: Use Frame(const FrameType& frameType, const Indices32& paddingElements, const Timestamp& timestamp) instead.
2412 *
2413 * Creates a new one-plane frame by given width, height, pixel format and frame origin and an optional padding.
2414 * The necessary buffer is allocated but not initialized.
2415 * @param frameType Type of the frame, must be valid
2416 * @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)
2417 * @param timestamp The timestamp of the frame
2418 */
2419 explicit inline Frame(const FrameType& frameType, const unsigned int paddingElements, const Timestamp& timestamp = Timestamp(false));
2420
2421 /**
2422 * Creates a new one-plane frame with known frame type with read-only source memory.
2423 * Beware: If this frame uses the pixel data only, the provided buffer must be valid as long as this new frame exists!
2424 * @param frameType Type of the frame, must be valid
2425 * @param data Frame data to copy or to use, depending on the data copy flag
2426 * @param copyMode The copy mode to be applied
2427 * @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)
2428 * @param timestamp The timestamp of the frame
2429 * @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()`
2430 */
2431 template <typename T>
2432 inline Frame(const FrameType& frameType, const T* data, const CopyMode copyMode, const unsigned int paddingElements = 0u, const Timestamp& timestamp = Timestamp(false));
2433
2434 /**
2435 * Creates a new one-plane frame with known frame type with writable source memory.
2436 * Beware: If this frame uses the pixel data only, the provided buffer must be valid as long as this new frame exists!
2437 * @param frameType Type of the frame
2438 * @param data Frame data to copy or to use, depending on the data copy flag
2439 * @param copyMode The copy mode to be applied
2440 * @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)
2441 * @param timestamp The timestamp of the frame
2442 * @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()`
2443 */
2444 template <typename T>
2445 inline Frame(const FrameType& frameType, T* data, const CopyMode copyMode, const unsigned int paddingElements = 0u, const Timestamp& timestamp = Timestamp(false));
2446
2447 /**
2448 * Creates a new multi-plane frame with known frame type and given source memory for each individual plane.
2449 * @param frameType The data type of the new frame, must be valid
2450 * @param planeInitializers The initializers for the individual planes, one for each plane of the pixel format
2451 * @param timestamp The timestamp of the frame
2452 * @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()`
2453 */
2454 template <typename T>
2455 inline Frame(const FrameType& frameType, const PlaneInitializers<T>& planeInitializers, const Timestamp& timestamp = Timestamp(false));
2456
2457 /**
2458 * Destructs a frame.
2459 */
2461
2462 /**
2463 * Returns the frame type of this frame.
2464 * This return value is actually the cast of the base class of this frame.
2465 * @return Frame type
2466 */
2467 inline const FrameType& frameType() const;
2468
2469 /**
2470 * Returns the individual planes of this frame.
2471 * @return The frame's plane
2472 */
2473 inline const Planes& planes() const;
2474
2475 /**
2476 * Deprecated.
2477 *
2478 * Copies frame data from a source frame.
2479 * When both frame types are not identical, the frame type of this frame is changed to the source frame type.<br>
2480 * This frame will own the new frame data, thus a new frame buffer is allocated if necessary.<br>
2481 * In case a new frame buffer needed to be allocated, the memory layout of the new frame buffer will be continuous.
2482 * @param source The source frame to copy, must be valid and must not be this frame
2483 * @param copyTimestamp True, to copy the frame's timestamp; False, to copy the image data only
2484 * @return True, if the copy operation was successful; otherwise, the frame is not modified and false is returned.
2485 */
2486 bool copy(const Frame& source, const bool copyTimestamp = true);
2487
2488 /**
2489 * Copies the entire image content of a source frame into this frame.
2490 * Both frames must have a compatible pixel format and must have the same pixel origin.<br>
2491 * Only the intersecting image content will be copied, padding data is not copied:
2492 * <pre>
2493 * Source frame
2494 * -------------------------------
2495 * This |(targetLeft, targetTop) |
2496 * target frame | |
2497 * -----------------|--------- |
2498 * |(0, 0) |XXXXXXXXX| |
2499 * | |XXXXXXXXX| |
2500 * | -------------------------------
2501 * | |
2502 * ---------------------------
2503 * </pre>
2504 * The intersecting image content is marked with an 'X'.
2505 * @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)
2506 * @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)
2507 * @param source The source frame to be copied, must be valid
2508 * @param copyTimestamp True, to copy the frame's timestamp; False, to copy the image data only
2509 * @return False, if both frames are not compatible; True, if the input was valid, even if both images do not intersect
2510 */
2511 bool copy(const int targetLeft, const int targetTop, const Frame& source, const bool copyTimestamp = true);
2512
2513 /**
2514 * Sets a new frame type for this frame.
2515 * 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.
2516 * @param frameType New frame type to set, can be invalid
2517 * @param forceOwner If specified and the frame is not yet owner, then the frame will allocate its own frame buffer
2518 * @param forceWritable If specified and the frame is read-only, then the frame will allocate its own frame buffer
2519 * @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
2520 * @param timestamp The timestamp to be set
2521 * @param reallocated Optional resulting state whether the frame has been reallocated; nullptr otherwise
2522 * @return True, if succeeded
2523 */
2524 bool set(const FrameType& frameType, const bool forceOwner, const bool forceWritable = false, const Indices32& planePaddingElements = Indices32(), const Timestamp& timestamp = Timestamp(false), bool* reallocated = nullptr);
2525
2526 /**
2527 * Updates the memory pointer for a specific plane of the frame to a new read-only memory location.
2528 * 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.
2529 * @param data The new read-only memory pointer to be set, must be valid
2530 * @param planeIndex The index of the frame's plane for which the memory will be updated, with range [0, numberPlanes())
2531 * @return True, if succeeded; False, if e.g., the plane to update owned the memory
2532 * @see isPlaneOwner().
2533 */
2534 template <typename T>
2535 bool updateMemory(const T* data, const unsigned int planeIndex = 0u);
2536
2537 /**
2538 * Updates the memory pointer for a specific plane of the frame to a new read-only or writable memory location.
2539 * 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.
2540 * For read-only memory, provide a const memory pointer; For writable memory, provide a non-const pointer.
2541 * @param data The new writable memory pointer to be set, must be valid
2542 * @param planeIndex The index of the frame's plane for which the memory will be updated, with range [0, numberPlanes())
2543 * @return True, if succeeded; False, if e.g., the plane to update owned the memory
2544 * @see isPlaneOwner().
2545 */
2546 template <typename T>
2547 bool updateMemory(T* data, const unsigned int planeIndex = 0u);
2548
2549 /**
2550 * Updates the memory pointers for all or some of the planes of the frame to new writable memory locations.
2551 * This function should be used only when the planes do not own their memory, to maintain consistent ownership behavior across the frame.
2552 * @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().
2553 * @return True, if succeeded; False, if e.g., the plane to update owned the memory
2554 * @see isPlaneOwner().
2555 */
2556 template <typename T>
2557 bool updateMemory(const std::initializer_list<T*>& planeDatas);
2558
2559 /**
2560 * Makes the memory of this frame continuous.
2561 * If the memory is already continuous, nothing happens.<br>
2562 * 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.
2563 */
2565
2566 /**
2567 * Makes this frame the owner of the memory.
2568 * In case this frame does not own the memory, new memory will be allocated.
2569 */
2571
2572 /**
2573 * Returns a sub-frame of this frame.
2574 * The copy mode defines whether the resulting sub-frame owns the memory or uses the memory.
2575 * @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
2576 * @param subFrameTop Top start location of the resulting sub-frame, in pixels, defined within this frame, with range [0, height - 1]
2577 * @param subFrameWidth Width of the resulting sub-frame in pixels, with range [1, width() - subFrameLeft]
2578 * @param subFrameHeight Height of the resulting sub-frame in pixels, with range [1, height() - subFrameTop]
2579 * @param copyMode The copy mode to be applied, must not be CM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA
2580 * @return The requested sub-frame not owning the image data, an invalid frame if the defined sub-region does not fit into this frame
2581 * @see FrameType::formatIsPacked().
2582 */
2583 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;
2584
2585 /**
2586 * Sets the memory of the frame to a specified byte value (the memory of one plane).
2587 * Each byte of the frame's memory will be set to the same value.
2588 *
2589 * The following code snippet shows how this function may be used:
2590 * @code
2591 * Frame rgbFrame(FrameType(1920u, 1080u, FrameType::FORMAT_RGB24, FrameType::ORIGIN_UPPER_LEFT));
2592 * rgbFrame.setValue(0x00u);
2593 * @endcode
2594 * @param value The 8 bit value to be set to each byte of the frame, with range [0, 255]
2595 * @param planeIndex The index of the plane for which the memory will be set, with range [0, numberPlanes())
2596 * @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
2597 * @return True, if the image data was writable; False, if the image holds read-only memory
2598 * @see isReadOnly().
2599 */
2600 bool setValue(const uint8_t value, const unsigned int planeIndex = 0u, const bool skipPaddingData = true);
2601
2602 /**
2603 * Sets the memory of the frame to a specified pixel value (the memory of one plane).
2604 * Each pixel will be set to the same values (each channel will be set to an own value).
2605 *
2606 * The following code snippet shows how this function may be used:
2607 * @code
2608 * Frame rgbFrame(FrameType(1920u, 1080u, FrameType::FORMAT_RGB24, FrameType::ORIGIN_UPPER_LEFT));
2609 * const Frame::PixelType<uint8_t, 3u> yellow({0xFFu, 0xFFu, 0x00u});
2610 * rgbFrame.setValue<uint8_t, 3u>(yellow);
2611 *
2612 * Frame tensorFrame(FrameType(1920u, 1080u, FrameType::genericPixelFormat<float, 3u>(), FrameType::ORIGIN_UPPER_LEFT));
2613 * const Frame::PixelType<float, 3u> value({0.0f, 1.0f, 2.0f});
2614 * tensorFrame.setValue<float, 3u>(value);
2615 * @endcode
2616 * @param planePixelValue The pixel value to be set to each pixel
2617 * @param planeIndex The index of the plane for which the memory will be set, with range [0, numberPlanes())
2618 * @tparam T The data type of the given pixel value, must be identical to the data type of the frame
2619 * @tparam tPlaneChannels The number of channels the plane has (not the number of channels the frame has), with range [1, channels()]
2620 * @return True, if the image data was writable; False, if the image holds read-only memory
2621 */
2622 template <typename T, const unsigned int tPlaneChannels>
2623 bool setValue(const PixelType<T, tPlaneChannels>& planePixelValue, const unsigned int planeIndex = 0u);
2624
2625 /**
2626 * Sets the memory of the frame to a specified pixel value (the memory of one plane).
2627 * Each pixel will be set to the same values (each channel will be set to an own value).
2628 *
2629 * The following code snippet shows how this function may be used:
2630 * @code
2631 * Frame rgbFrame(FrameType(1920u, 1080u, FrameType::FORMAT_RGB24, FrameType::ORIGIN_UPPER_LEFT));
2632 * rgbFrame.setValue<uint8_t>(CV::Canvas::yellow(), 3u);
2633 * @endcode
2634 * @param planePixelValue The pixel value to be set to each pixel, one value for each plane channel, must be valid
2635 * @param planePixelValueSize The number of provided pixel values, with range [1, 4], must be `planes().channels()`
2636 * @param planeIndex The index of the plane for which the memory will be set, with range [0, numberPlanes())
2637 * @tparam T The data type of the given pixel value, must be identical to the data type of the frame
2638 * @return True, if the image data was writable; False, if the image holds read-only memory
2639 */
2640 template <typename T>
2641 bool setValue(const T* planePixelValue, const size_t planePixelValueSize, const unsigned int planeIndex = 0u);
2642
2643 /**
2644 * Sets the memory of the frame to a specified pixel value (the memory of one plane).
2645 * Each pixel will be set to the same values (each channel will be set to an own value).
2646 *
2647 * The following code snippet shows how this function may be used:
2648 * @code
2649 * Frame rgbFrame(FrameType(1920u, 1080u, FrameType::FORMAT_RGB24, FrameType::ORIGIN_UPPER_LEFT));
2650 * rgbFrame.setValue<uint8_t>({0xFFu, 0xFFu, 0x00u});
2651 *
2652 * Frame tensorFrame(FrameType(1920u, 1080u, FrameType::genericPixelFormat<float, 3u>(), FrameType::ORIGIN_UPPER_LEFT));
2653 * tensorFrame.setValue<float>({0.0f, 1.0f, 2.0f});
2654 * @endcode
2655 * @param planePixelValues The pixel values to be set to each pixel, one value for each plane channel
2656 * @param planeIndex The index of the plane for which the memory will be set, with range [0, numberPlanes())
2657 * @tparam T The data type of the given pixel value, must be identical to the data type of the frame
2658 * @return True, if the image data was writable; False, if the image holds read-only memory
2659 */
2660 template <typename T>
2661 bool setValue(const std::initializer_list<typename Identity<T>::Type>& planePixelValues, const unsigned int planeIndex = 0u);
2662
2663 /**
2664 * Returns whether the frame (one plane) contains a specified pixel value.
2665 * @param planePixelValue The pixel value to be checked
2666 * @param planeIndex The index of the plane for which the memory will be set, with range [0, numberPlanes())
2667 * @tparam T The data type of the given pixel value, must be identical to the data type of the frame
2668 * @tparam tPlaneChannels The number of channels the plane has (not the number of channels the frame has), with range [1, channels()]
2669 * @return True, if at least one pixel has the specified value
2670 */
2671 template <typename T, const unsigned int tPlaneChannels>
2672 bool containsValue(const PixelType<T, tPlaneChannels>& planePixelValue, const unsigned int planeIndex = 0u) const;
2673
2674 /**
2675 * Returns the number of bytes necessary for a specific plane including optional padding at the end of plane rows.
2676 * @param planeIndex The index of the plane for which the check is done, with range [0, planes().size())
2677 * @return Frame buffer size in bytes, with range [0, infinity)
2678 */
2679 inline unsigned int size(const unsigned int planeIndex = 0u) const;
2680
2681 /**
2682 * Returns the optional number of padding elements at the end of each row for a specific plane.
2683 * @param planeIndex The index of the plane for which the number of padding elements will be returned, with range [0, planes().size())
2684 * @return The frame's number of padding elements, in elements, with range [0, infinity)
2685 */
2686 inline unsigned int paddingElements(const unsigned int planeIndex = 0u) const;
2687
2688 /**
2689 * Returns the optional number of padding bytes at the end of each row for a specific plane.
2690 * @param planeIndex The index of the plane for which the number of padding bytes will be returned, with range [0, planes().size())
2691 * @return The frame's number of padding bytes, in bytes, with range [0, infinity)
2692 */
2693 inline unsigned int paddingBytes(const unsigned int planeIndex = 0u) const;
2694
2695 /**
2696 * Returns the number of elements within one row, including optional padding at the end of a row for a specific plane.
2697 * The number of elements per row is be determined by the plane's values: pixels * elementsPerPixel + paddingElements().
2698 * @param planeIndex The index of the plane for which the number of stride elements will be returned, with range [0, planes().size())
2699 * @return The frame's stride defined in elements, with range [width * elementsPerPixel, infinity)
2700 */
2701 inline unsigned int strideElements(const unsigned int planeIndex = 0u) const;
2702
2703 /**
2704 * Returns the number of bytes within one row, including optional padding at the end of a row for a specific plane.
2705 * @param planeIndex The index of the plane for which the number of stride bytes will be returned, with range [0, planes().size())
2706 * @return The frame's stride defined in bytes, with range [pixels * elementsPerPixel * bitsPerDatatype() / 8, infinity)
2707 */
2708 inline unsigned int strideBytes(const unsigned int planeIndex = 0u) const;
2709
2710 /**
2711 * Returns the width of a plane of this frame.
2712 * @param planeIndex The index of the plane for which the width will be returned, with range [0, planes().size())
2713 * @return The plane's width, in pixel, with range [0, infinity)
2714 */
2715 inline unsigned int planeWidth(const unsigned int planeIndex) const;
2716
2717 /**
2718 * Returns the height of a plane of this frame.
2719 * @param planeIndex The index of the plane for which the height will be returned, with range [0, planes().size())
2720 * @return The plane's height, in pixel, with range [0, infinity)
2721 */
2722 inline unsigned int planeHeight(const unsigned int planeIndex) const;
2723
2724 /**
2725 * Returns the channels of a plane of this frame.
2726 * @param planeIndex The index of the plane for which the channels will be returned, with range [0, planes().size())
2727 * @return The plane's channels, with range [0, infinity)
2728 */
2729 inline unsigned int planeChannels(const unsigned int planeIndex) const;
2730
2731 /**
2732 * 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.
2733 * @param planeIndex The index of the plane for which the width will be returned, with range [0, planes().size())
2734 * @return The plane's width, in elements, with is `planeWidth(planeIndex) * planeChannels(planeIndex)`, with range [0, infinity)
2735 */
2736 inline unsigned int planeWidthElements(const unsigned int planeIndex) const;
2737
2738 /**
2739 * 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.
2740 * @param planeIndex The index of the plane for which the width will be returned, with range [0, planes().size())
2741 * @return The plane's width, in bytes, with range [0, infinity)
2742 */
2743 inline unsigned int planeWidthBytes(const unsigned int planeIndex) const;
2744
2745 /**
2746 * Returns the number of bytes of one pixel of a plane for a pixel format.
2747 * 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.
2748 * @param planeIndex The index of the plane for which the bytes per pixel will be returned, with range [0, numberPlanes(imagePixelFormat))
2749 * @return The plane's number of bytes per pixel, will be 0 for special packed pixel formats like FORMAT_Y10_PACKED
2750 */
2751 inline unsigned int planeBytesPerPixel(const unsigned int planeIndex) const;
2752
2753 /**
2754 * 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.
2755 * @param planeIndex The index of the plane for which the check is done, with range [0, planes().size())
2756 * @return True, if so
2757 */
2758 inline bool isPlaneContinuous(const unsigned int planeIndex = 0u) const;
2759
2760 /**
2761 * Returns whether a specific plane of this frame is the owner of the memory.
2762 * @param planeIndex The index of the plane for which the check is done, with range [0, planes().size())
2763 * @return True, if so
2764 */
2765 inline bool isPlaneOwner(const unsigned int planeIndex = 0u) const;
2766
2767 /**
2768 * Returns the timestamp of this frame.
2769 * @return Timestamp
2770 */
2771 inline const Timestamp& timestamp() const;
2772
2773 /**
2774 * Returns the relative timestamp of this frame.
2775 * @return Timestamp
2776 */
2777 inline const Timestamp& relativeTimestamp() const;
2778
2779 /**
2780 * Sets the timestamp of this frame.
2781 * @param timestamp Timestamp to be set
2782 * @see setRelativeTimestamp().
2783 */
2784 inline void setTimestamp(const Timestamp& timestamp);
2785
2786 /**
2787 * Sets the relative timestamp of this frame.
2788 * In contrast to the standard timestamp of this frame, the relative timestamp provides the frame time in relation to a reference time.<br>
2789 * @param relative The relative timestamp to be set
2790 * @see setTimestamp().
2791 */
2792 inline void setRelativeTimestamp(const Timestamp& relative);
2793
2794 /**
2795 * Releases this frame and the frame data if this frame is the owner.
2796 */
2797 void release();
2798
2799 /**
2800 * Returns a pointer to the pixel data of a specific plane.
2801 * Ensure that the frame holds writable pixel data before calling this function.
2802 * @param planeIndex The index of the plane for which the data will be returned, with range [0, planes().size())
2803 * @return The plane's writable pixel data
2804 * @tparam T The explicit data type of the value of each pixel channel
2805 * @see isValid(), isReadOnly().
2806 */
2807 template <typename T>
2808 inline T* data(const unsigned int planeIndex = 0u);
2809
2810 /**
2811 * Returns a pointer to the read-only pixel data of a specific plane.
2812 * @param planeIndex The index of the plane for which the data will be returned, with range [0, planes().size())
2813 * @return The plane's read-only pixel data
2814 * @tparam T The explicit data type of the value of each pixel channel
2815 * @see isValid().
2816 */
2817 template <typename T>
2818 inline const T* constdata(const unsigned int planeIndex = 0u) const;
2819
2820 /**
2821 * Returns the pointer to the pixel data of a specific row.
2822 * Ensure that the frame is valid and that the frame holds a valid frame buffer before this function is called.
2823 *
2824 * The index of the row is defined with respect to the origin of the frame's data.<br>
2825 * Therefore, row<T>(0) will return the top row of an image if pixelOrigin() == ORIGIN_UPPER_LEFT,<br>
2826 * and will return the bottom row of an image if pixelOrigin() == ORIGIN_LOWER_LEFT.<br>
2827 * In any case, row<T>(0) is equivalent to data<T>().
2828 *
2829 * @param y The index of the row (the vertical location) to which the resulting pointer will point, with range [0, planeHeight(planeIndex) - 1]
2830 * @param planeIndex The index of the plane for which the pixel will be returned, with range [0, planes().size())
2831 * @return The pointer to the memory at which the row starts
2832 * @tparam T The explicit data type of the value of each pixel channel
2833 * @see data(), pixel(), constrow(), constdata(), constpixel().
2834 */
2835 template <typename T>
2836 inline T* row(const unsigned int y, const unsigned int planeIndex = 0u);
2837
2838 /**
2839 * Returns the pointer to the constant data of a specific row.
2840 * Ensure that the frame is valid and that the frame holds a valid frame buffer before this function is called.
2841 *
2842 * The index of the row is defined with respect to the origin of the frame's data.<br>
2843 * Therefore, constrow<T>(0) will return the top row of an image if pixelOrigin() == ORIGIN_UPPER_LEFT,<br>
2844 * and will return the bottom row of an image if pixelOrigin() == ORIGIN_LOWER_LEFT.<br>
2845 * In any case, constrow<T>(0) is equivalent to constdata<T>().
2846 *
2847 * @param y The index of the row (the vertical location) to which the resulting pointer will point, with range [0, planeHeight(planeIndex) - 1]
2848 * @param planeIndex The index of the plane for which the pixel will be returned, with range [0, planes().size())
2849 * @return The pointer to the memory at which the row starts
2850 * @tparam T The explicit data type of the value of each pixel channel
2851 * @see data(), pixel(), constrow(), constdata(), constpixel().
2852 */
2853 template <typename T>
2854 inline const T* constrow(const unsigned int y, const unsigned int planeIndex = 0u) const;
2855
2856 /**
2857 * Returns the pointer to the data of a specific pixel.
2858 * Ensure that the frame is valid and that the frame holds a valid frame buffer before this function is called.
2859 *
2860 * In general, the usage of this function is recommended for prototyping only.<br>
2861 * As the location of each pixel has to be calculated every time, this function is quite slow.<br>
2862 * Production code should use the constdata(), data(), constrow(), and row() functions instead.
2863 *
2864 * The vertical location (the y coordinate) of the pixel is defined with respect to the origin of the frame's data.<br>
2865 * Therefore, pixel(0, 0) will return the top left pixel of an image if pixelOrigin() == ORIGIN_UPPER_LEFT,<br>
2866 * and will return the bottom left pixel of an image if pixelOrigin() == ORIGIN_LOWER_LEFT.<br>
2867 * In any case, pixel(0, 0) is equivalent to data().
2868 *
2869 * This function most not be called for packed pixel formats.
2870 *
2871 * @param x The horizontal position of the requested pixel, with range [0, planeWidth(planeIndex) - 1]
2872 * @param y The vertical position of the requested pixel, with range [0, planeHeight(planeIndex) - 1]
2873 * @param planeIndex The index of the plane for which the pixel will be returned, with range [0, planes().size())
2874 * @return The pointer to the memory at which the pixel starts
2875 * @tparam T The explicit data type of the value of each pixel channel
2876 * @see data(), row(), constpixel(), constdata(), constrow(). formatIsPacked().
2877 *
2878 *
2879 * The following code snippet shows how this function may be used:
2880 * @code
2881 * // we create a RGB image with 24 bit per pixel (8 bit per channel)
2882 * Frame rgbImage(FrameType(1280u, 720u, FrameType::FORMAT_RGB24, FrameType::ORIGIN_UPPER_LEFT));
2883 *
2884 * const uint8_t redChannelValue = 0xFF; // 255
2885 * const uint8_t greenChannelValue = 0x80; // 128
2886 * const uint8_t blueChannelValue = 0x00; // 0
2887 *
2888 * // we iterate overall every pixel
2889 * for (unsigned int y = 0u; y < rgbImage.height(); ++y)
2890 * {
2891 * for (unsigned int x = 0u; x < rgbImage.width(); ++x)
2892 * {
2893 * // we store the pointer to the pixel
2894 * uint8_t* rgbPixel = rgbImage.pixel<uint8_t>(x, y);
2895 *
2896 * // we set the color value of each red channel and green channel
2897 * rgbPixel[0] = redChannelValue;
2898 * rgbPixel[1] = greenChannelValue;
2899 *
2900 * // we also can set the value of each channel directly
2901 * rgbImage.pixel<uint8_t>(x, y)[2] = blueChannelValue;
2902 * }
2903 * }
2904 *
2905 * // now we have set the color of every pixel of the image
2906 * @endcode
2907 */
2908 template <typename T>
2909 inline T* pixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex = 0u);
2910
2911 /**
2912 * Returns the pointer to the constant data of a specific pixel.
2913 * Ensure that the frame is valid and that the frame holds a valid frame buffer before this function is called.
2914 *
2915 * In general, the usage of this function is recommended for prototyping only.<br>
2916 * As the location of each pixel has to be calculated every time, this function is quite slow.<br>
2917 * Production code should use the constdata(), data(), constrow(), and row() functions instead.
2918 *
2919 * The vertical location (the y coordinate) of the pixel is defined with respect to the origin of the frame's data.<br>
2920 * Therefore, pixel<T>(0, 0) will return the top left pixel of an image if pixelOrigin() == ORIGIN_UPPER_LEFT,<br>
2921 * and will return the bottom left pixel of an image if pixelOrigin() == ORIGIN_LOWER_LEFT.<br>
2922 * In any case, pixel<T>(0, 0) is equivalent to data<T>().
2923 *
2924 * This function most not be called for packed pixel formats.
2925 *
2926 * @param x The horizontal position of the requested pixel, with range [0, planeWidth(planeIndex) - 1]
2927 * @param y The vertical position of the requested pixel, with range [0, planeHeight(planeIndex) - 1]
2928 * @param planeIndex The index of the plane for which the pixel will be returned, with range [0, planes().size())
2929 * @return The pointer to the memory at which the pixel starts
2930 * @tparam T The explicit data type of the value of each pixel channel
2931 * @see data(), row(), pixel(), constdata(), constrow(), formatIsPacked().
2932 */
2933 template <typename T>
2934 inline const T* constpixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex = 0u) const;
2935
2936 /**
2937 * Returns whether all planes of this frame have continuous memory and thus do not contain any padding at the end of their rows.
2938 * @return True, if so
2939 */
2940 inline bool isContinuous() const;
2941
2942 /**
2943 * Returns whether the frame is the owner of the internal frame data.
2944 * Otherwise the frame data is stored by e.g., a 3rd party and this frame holds a reference only.<br>
2945 * The frame is not owner of the memory if at least one plane is not owner of the memory.
2946 * @return True, if so
2947 * @see Plane::isOwner().
2948 */
2949 inline bool isOwner() const;
2950
2951 /**
2952 * Returns true, if the frame allows only read access (using constdata()). Otherwise, data() may be used to modify the frame data.
2953 * Beware: Call this method only if the frame is valid.
2954 * The frame is read-only if at least one plane is read-only.
2955 * @return True, if the frame object allows read access only
2956 * @see data(), constdata(), Plane::isReadOnly().
2957 */
2958 inline bool isReadOnly() const;
2959
2960 /**
2961 * Returns whether the frame's pixel format contains an alpha channel.
2962 * @return True, if so
2963 */
2964 inline bool hasAlphaChannel() const;
2965
2966 /**
2967 * Returns whether the frame holds at least one pixel with an non opaque alpha value.
2968 * The pixel format must be composed of one plane only.
2969 * @return True, if so
2970 * @tparam T The type of the frame's data type, either `uint8_t`, or `uint16_t`
2971 */
2972 template <typename T>
2973 bool hasTransparentPixel(const T opaque) const;
2974
2975 /**
2976 * Returns whether this frame is valid.
2977 * This function is mainly calling `FrameType::isValid()`, while in debug builds, additional checks are performed.
2978 * @return True, if so
2979 */
2980 inline bool isValid() const;
2981
2982 /**
2983 * Returns whether two frame objects have any amount of intersecting memory.
2984 * This frame and the given frame must both be valid.<br>
2985 * Use this function to ensure that e.g., a source buffer and target buffer is completely independent.<br>
2986 * This functions also considers memory intersections in the padding area as regular intersection.
2987 * @param frame The second frame of which its memory will be compared to the memory of this frame, must be valid
2988 * @return True, if so
2989 */
2990 bool haveIntersectingMemory(const Frame& frame) const;
2991
2992 /**
2993 * Returns whether this frame object is valid and holds a frame.
2994 * @return True, if so
2995 */
2996 explicit inline operator bool() const;
2997
2998 /**
2999 * Assign operator.
3000 * Releases the current frame (and frees the memory if the frame is the owner) and creates a second version of a given frame.
3001 * If the given source frame is not owner of the frame data, this frame will also not be owner of the frame data.<br>
3002 * 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>
3003 * If the memory is actually copied, the memory layout of this new frame will be continuous.
3004 * This function behaves similar like the normal copy constructor.
3005 * @param right The right frame to assign
3006 * @return Reference to this frame
3007 */
3008 Frame& operator=(const Frame& right) noexcept;
3009
3010 /**
3011 * Move operator.
3012 * @param right The right frame to moved
3013 * @return Reference to this frame
3014 */
3015 Frame& operator=(Frame&& right) noexcept;
3016
3017 /**
3018 * 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.
3019 * @param pixelFormat The pixel format of the image, must be valid
3020 * @param imageWidth The width of the image in pixels, with range [0, infinity)
3021 * @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)
3022 * @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)
3023 * @param planeIndex The index of the image plane for which the number of padding elements will be calculated, with range [0, numberPlanes() - 1]
3024 * @return True, if succeeded; False, if the given plane configuration is invalid
3025 */
3026 static bool strideBytes2paddingElements(const PixelFormat& pixelFormat, const unsigned int imageWidth, const unsigned int planeStrideBytes, unsigned int& planePaddingElements, const unsigned int planeIndex = 0u);
3027
3028 protected:
3029
3030 /**
3031 * Creates a new multi-plane frame with known frame type and given source memory for each individual plane.
3032 * @param frameType The data type of the new frame, must be valid
3033 * @param planeInitializers The initializers for the individual planes, one for each plane of the pixel format, must be valid
3034 * @param sizePlaneInitializers The number of specified initializers for the individual planes, must be frameType.numberPlanes()
3035 * @param timestamp The timestamp of the frame
3036 */
3037 Frame(const FrameType& frameType, const PlaneInitializer<void>* planeInitializers, size_t sizePlaneInitializers, const Timestamp& timestamp = Timestamp(false));
3038
3039 /**
3040 * Deleted constructor to prevent misuse.
3041 * @param frame The frame to copy
3042 * @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
3043 */
3044 Frame(const Frame& frame, const bool copyData) = delete;
3045
3046 /**
3047 * Deleted constructor to prevent misuse.
3048 * @param frameType The frame type which would be used to create the object
3049 * @param copyMode The copy mode which would be used to create the object
3050 */
3051 Frame(const FrameType& frameType, const CopyMode copyMode) = delete;
3052
3053 /**
3054 * Deleted constructor to prevent misuse.
3055 * @param frameType The frame type which would be used to create the object
3056 * @param advancedCopyMode The advanced copy mode which would be used to create the object
3057 */
3058 Frame(const FrameType& frameType, const AdvancedCopyMode advancedCopyMode) = delete;
3059
3060 /**
3061 * Deleted constructor to prevent misuse, use `AdvancedCopyMode` instead.
3062 * @param frame The frame to be copied
3063 * @param copyMode The copy mode which would be used to create the object
3064 */
3065 Frame(const Frame& frame, const CopyMode copyMode) = delete;
3066
3067 /**
3068 * Deleted constructor to prevent misuse.
3069 * @param frameType The frame type which would be used
3070 * @param timestamp The timestamp which would be used to create the object
3071 */
3072 Frame(const FrameType& frameType, const Timestamp& timestamp) = delete;
3073
3074 /**
3075 * Deleted constructor to prevent misuse.
3076 * @param frame The frame to be copied
3077 * @param timestamp The timestamp which would be used to create the object
3078 */
3079 Frame(const Frame& frame, const Timestamp& timestamp) = delete;
3080
3081 /**
3082 * 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.
3083 * @param frameType Type of the frame, must be valid
3084 * @param data Frame data to copy or to use, depending on the data copy flag
3085 * @param copyData Determines whether the frame will make an own copy of the given frame data or whether the pixel data are used only
3086 * @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)
3087 * @param timestamp The timestamp of the frame
3088 * @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()`
3089 */
3090 template <typename T>
3091 Frame(const FrameType& frameType, const T* data, const bool copyData, const unsigned int paddingElements = 0u, const Timestamp& timestamp = Timestamp(false)) = delete;
3092
3093 /**
3094 * 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.
3095 * @param frameType Type of the frame
3096 * @param data Frame data to copy or to use, depending on the data copy flag
3097 * @param copyData Determines whether the frame will make an own copy of the given frame data or whether the pixel data are used only
3098 * @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)
3099 * @param timestamp The timestamp of the frame
3100 * @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()`
3101 */
3102 template <typename T>
3103 Frame(const FrameType& frameType, T* data, const bool copyData, const unsigned int paddingElements = 0u, const Timestamp& timestamp = Timestamp(false)) = delete;
3104
3105 protected:
3106
3107 /// The individual memory planes of this frame.
3109
3110 /// Timestamp of the frame.
3112
3113 /// Relative timestamp of this frame.
3115};
3116
3117inline FrameType::PixelFormatUnion::PixelFormatUnion(const PixelFormat& pixelFormat) :
3118 pixelFormat_(pixelFormat)
3119{
3120 // nothing to do here
3121}
3122
3123inline FrameType::FrameType(const unsigned int width, const unsigned int height, const PixelFormat pixelFormat, const PixelOrigin pixelOrigin) :
3124 width_(width),
3125 height_(height),
3128{
3129 if (isValid())
3130 {
3132 {
3133 ocean_assert(false && "The configuration of this frame type is invalid - this should never happen!");
3134
3135 width_ = 0u;
3136 height_ = 0u;
3139
3140 ocean_assert(!isValid());
3141 }
3142 }
3143}
3144
3145inline FrameType::FrameType(const FrameType& type, const unsigned int width, const unsigned int height) :
3146 width_(width),
3147 height_(height),
3148 pixelFormat_(type.pixelFormat_),
3149 pixelOrigin_(type.pixelOrigin_)
3150{
3151 if (isValid())
3152 {
3154 {
3155 ocean_assert(false && "The configuration of this frame type is invalid - this should never happen!");
3156
3157 width_ = 0u;
3158 height_ = 0u;
3161
3162 ocean_assert(!isValid());
3163 }
3164 }
3165}
3166
3167inline FrameType::FrameType(const FrameType& type, const PixelFormat pixelFormat) :
3168 width_(type.width_),
3169 height_(type.height_),
3170 pixelFormat_(pixelFormat),
3171 pixelOrigin_(type.pixelOrigin_)
3172{
3173 // nothing to do here
3174}
3175
3176inline FrameType::FrameType(const FrameType& type, const PixelOrigin pixelOrigin) :
3177 width_(type.width_),
3178 height_(type.height_),
3179 pixelFormat_(type.pixelFormat_),
3180 pixelOrigin_(pixelOrigin)
3181{
3182 // nothing to do here
3183}
3184
3185inline FrameType::FrameType(const FrameType& type, const PixelFormat pixelFormat, const PixelOrigin pixelOrigin) :
3186 width_(type.width_),
3187 height_(type.height_),
3188 pixelFormat_(pixelFormat),
3189 pixelOrigin_(pixelOrigin)
3190{
3191 // nothing to do here
3192}
3193
3194inline unsigned int FrameType::width() const
3195{
3196 return width_;
3197}
3198
3199inline unsigned int FrameType::height() const
3200{
3201 return height_;
3202}
3203
3208
3209inline void FrameType::setPixelFormat(const PixelFormat pixelFormat)
3210{
3212}
3213
3218
3219inline unsigned int FrameType::bytesPerDataType() const
3220{
3221 return bytesPerDataType(dataType());
3222}
3223
3224inline unsigned int FrameType::channels() const
3225{
3227 {
3228 return 0u;
3229 }
3230
3232}
3233
3234inline uint32_t FrameType::numberPlanes() const
3235{
3237}
3238
3240{
3241 return pixelOrigin_;
3242}
3243
3244inline unsigned int FrameType::pixels() const
3245{
3247
3248 return width_ * height_;
3249}
3250
3251inline bool FrameType::isPixelFormatCompatible(const PixelFormat pixelFormat) const
3252{
3253 return arePixelFormatsCompatible(this->pixelFormat(), pixelFormat);
3254}
3255
3256inline bool FrameType::isFrameTypeCompatible(const FrameType& frameType, const bool allowDifferentPixelOrigins) const
3257{
3258 return areFrameTypesCompatible(*this, frameType, allowDifferentPixelOrigins);
3259}
3260
3261inline bool FrameType::operator!=(const FrameType& right) const
3262{
3263 return !(*this == right);
3264}
3265
3266inline bool FrameType::isValid() const
3267{
3269}
3270
3271inline uint32_t FrameType::numberPlanes(const PixelFormat pixelFormat)
3272{
3273 return uint32_t((pixelFormat >> pixelFormatBitOffsetPlanes) & 0xFFull);
3274}
3275
3276inline uint32_t FrameType::formatGenericNumberChannels(const PixelFormat pixelFormat)
3277{
3278 return uint32_t((pixelFormat >> pixelFormatBitOffsetChannels) & 0xFFull);
3279}
3280
3281template <>
3282constexpr FrameType::DataType FrameType::dataType<char>()
3283{
3284 static_assert(sizeof(char) == 1, "Invalid data type!");
3285
3286 return (std::is_signed<char>::value) ? DT_SIGNED_INTEGER_8 : DT_UNSIGNED_INTEGER_8;
3287}
3288
3289template <>
3290constexpr FrameType::DataType FrameType::dataType<signed char>()
3291{
3292 static_assert(sizeof(signed char) == 1, "Invalid data type!");
3293 return DT_SIGNED_INTEGER_8;
3294}
3295
3296template <>
3297constexpr FrameType::DataType FrameType::dataType<unsigned char>()
3298{
3299 static_assert(sizeof(unsigned char) == 1, "Invalid data type!");
3300 return DT_UNSIGNED_INTEGER_8;
3301}
3302
3303template <>
3304constexpr FrameType::DataType FrameType::dataType<unsigned short>()
3305{
3306 static_assert(sizeof(unsigned short) == 2, "Invalid data type!");
3308}
3309
3310template <>
3311constexpr FrameType::DataType FrameType::dataType<short>()
3312{
3313 static_assert(sizeof(short) == 2, "Invalid data type!");
3314 return DT_SIGNED_INTEGER_16;
3315}
3316
3317template <>
3318constexpr FrameType::DataType FrameType::dataType<unsigned int>()
3319{
3320 static_assert(sizeof(unsigned int) == 4, "Invalid data type!");
3322}
3323
3324template <>
3325constexpr FrameType::DataType FrameType::dataType<int>()
3326{
3327 static_assert(sizeof(int) == 4, "Invalid data type!");
3328 return DT_SIGNED_INTEGER_32;
3329}
3330
3331template <>
3332constexpr FrameType::DataType FrameType::dataType<unsigned long>()
3333{
3334 static_assert(sizeof(unsigned long) == 4 || sizeof(unsigned long) == 8, "Invalid data type!");
3335
3336 return (sizeof(unsigned long) == 4) ? DT_UNSIGNED_INTEGER_32 : DT_UNSIGNED_INTEGER_64;
3337}
3338
3339template <>
3340constexpr FrameType::DataType FrameType::dataType<long>()
3341{
3342 static_assert(sizeof(unsigned long) == 4 || sizeof(unsigned long) == 8, "Invalid data type!");
3343
3344 return (sizeof(long) == 4) ? DT_SIGNED_INTEGER_32 : DT_SIGNED_INTEGER_64;
3345}
3346
3347template <>
3348constexpr FrameType::DataType FrameType::dataType<unsigned long long>()
3349{
3350 static_assert(sizeof(unsigned long long) == 8, "Invalid data type!");
3352}
3353
3354template <>
3355constexpr FrameType::DataType FrameType::dataType<long long>()
3356{
3357 static_assert(sizeof(long long) == 8, "Invalid data type!");
3358 return DT_SIGNED_INTEGER_64;
3359}
3360
3361template <>
3362constexpr FrameType::DataType FrameType::dataType<float>()
3363{
3364 static_assert(sizeof(float) == 4, "Invalid data type!");
3365 return DT_SIGNED_FLOAT_32;
3366}
3367
3368template <>
3369constexpr FrameType::DataType FrameType::dataType<double>()
3370{
3371 static_assert(sizeof(double) == 8, "Invalid data type!");
3372 return DT_SIGNED_FLOAT_64;
3373}
3374
3375template <typename T>
3377{
3378 return DT_UNDEFINED;
3379}
3380
3382{
3383 ocean_assert(((pixelFormat >> pixelFormatBitOffsetDatatype) & 0xFFull) <= DT_SIGNED_FLOAT_64);
3384
3385 return DataType((pixelFormat >> pixelFormatBitOffsetDatatype) & 0xFFull);
3386}
3387
3392
3393constexpr inline FrameType::PixelFormat FrameType::genericPixelFormat(const DataType dataType, const uint32_t channels, const uint32_t planes, const uint32_t widthMultiple, const uint32_t heightMultiple)
3394{
3395 ocean_assert(uint8_t(dataType) > uint8_t(DT_UNDEFINED) && uint8_t(dataType) < DT_END);
3396 ocean_assert(channels >= 1u && channels <= 31u);
3397 ocean_assert(planes >= 1u && planes <= 255u);
3398 ocean_assert(widthMultiple >= 1u && widthMultiple <= 255u);
3399 ocean_assert(heightMultiple >= 1u && heightMultiple <= 255u);
3400
3402}
3403
3404template <FrameType::DataType tDataType, uint32_t tChannels, uint32_t tPlanes, uint32_t tWidthMultiple, uint32_t tHeightMultiple>
3406{
3407 static_assert(uint8_t(tDataType) > uint8_t(DT_UNDEFINED) && uint8_t(tDataType) < DT_END, "Invalid data type!");
3408 static_assert(tChannels >= 1u && tChannels < 31u, "Invalid channel number!");
3409 static_assert(tPlanes >= 1u && tPlanes <= 255u, "Invalid plane number!");
3410 static_assert(tWidthMultiple >= 1u && tWidthMultiple <= 255u, "Invalid width-multiple!");
3411 static_assert(tHeightMultiple >= 1u && tHeightMultiple <= 255u, "Invalid height-multiple!");
3412
3413 return genericPixelFormat(tDataType, tChannels, tPlanes, tWidthMultiple, tHeightMultiple);
3414}
3415
3416template <FrameType::DataType tDataType>
3417constexpr FrameType::PixelFormat FrameType::genericPixelFormat(const uint32_t channels, const uint32_t planes, const uint32_t widthMultiple, const uint32_t heightMultiple)
3418{
3419 static_assert(uint8_t(tDataType) > uint8_t(DT_UNDEFINED) && uint8_t(tDataType) < DT_END, "Invalid data type!");
3420
3421 return genericPixelFormat(tDataType, channels, planes, widthMultiple, heightMultiple);
3422}
3423
3424template <typename TDataType, uint32_t tChannels, uint32_t tPlanes, uint32_t tWidthMultiple, uint32_t tHeightMultiple>
3426{
3427 static_assert(tChannels >= 1u && tChannels < 31u, "Invalid channel number!");
3428 static_assert(tPlanes >= 1u && tPlanes <= 255u, "Invalid plane number!");
3429 static_assert(tWidthMultiple >= 1u && tWidthMultiple <= 255u, "Invalid width-multiple!");
3430 static_assert(tHeightMultiple >= 1u && tHeightMultiple <= 255u, "Invalid height-multiple!");
3431
3432 constexpr DataType pixelFormatDataType = dataType<TDataType>();
3433 static_assert(uint8_t(pixelFormatDataType) > uint8_t(DT_UNDEFINED) && uint8_t(pixelFormatDataType) < DT_END, "Invalid data type!");
3434
3435 return genericPixelFormat(pixelFormatDataType, tChannels, tPlanes, tWidthMultiple, tHeightMultiple);
3436}
3437
3438template <typename TDataType>
3439constexpr FrameType::PixelFormat FrameType::genericPixelFormat(const uint32_t channels, const uint32_t planes, const uint32_t widthMultiple, const uint32_t heightMultiple)
3440{
3441 constexpr DataType pixelFormatDataType = dataType<TDataType>();
3442 static_assert(uint8_t(pixelFormatDataType) > uint8_t(DT_UNDEFINED) && uint8_t(pixelFormatDataType) < DT_END, "Invalid data type!");
3443
3444 ocean_assert(channels >= 1u && channels <= 31u);
3445 ocean_assert(planes >= 1u && planes <= 255u);
3446 ocean_assert(widthMultiple >= 1u && widthMultiple <= 255u);
3447 ocean_assert(heightMultiple >= 1u && heightMultiple <= 255u);
3448
3449 return genericPixelFormat(pixelFormatDataType, channels, planes, widthMultiple, heightMultiple);
3450}
3451
3453{
3454 static_assert(std::is_same<std::underlying_type<PixelFormat>::type, uint64_t>::value, "Invalid pixel format data type!");
3455
3456 return PixelFormat(pixelFormat & 0xFFFFFFFFFFFF0000ull); // Cf. documentation of enum PixelFormat
3457}
3458
3459inline 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)
3460{
3462}
3463
3468
3469inline bool FrameType::formatIsPureGeneric(const PixelFormat pixelFormat)
3470{
3471 static_assert(std::is_same<std::underlying_type<PixelFormat>::type, uint64_t>::value, "Invalid pixel format data type!");
3472
3473 return (pixelFormat & 0x000000000000FFFFull) == 0u && formatIsGeneric(pixelFormat);
3474}
3475
3476inline uint32_t FrameType::widthMultiple(const PixelFormat pixelFormat)
3477{
3478 return uint32_t((pixelFormat >> pixelFormatBitOffsetWidthMultiple) & 0xFFull);
3479}
3480
3481inline uint32_t FrameType::heightMultiple(const PixelFormat pixelFormat)
3482{
3483 return uint32_t((pixelFormat >> pixelFormatBitOffsetHeightMultiple) & 0xFFull);
3484}
3485
3486inline unsigned int FrameType::planeBytesPerPixel(const PixelFormat& imagePixelFormat, const unsigned int planeIndex)
3487{
3488 unsigned int planeWidthDummy;
3489 unsigned int planeHeightDummy;
3490
3491 unsigned int planeChannels;
3492
3493 unsigned int planeWidthElementsMultiple;
3494 unsigned int planeHeightElementsMultiple;
3495
3496 if (planeLayout(imagePixelFormat, widthMultiple(imagePixelFormat), heightMultiple(imagePixelFormat), planeIndex, planeWidthDummy, planeHeightDummy, planeChannels, &planeWidthElementsMultiple, &planeHeightElementsMultiple))
3497 {
3498 ocean_assert(planeChannels >= 1u && planeWidthElementsMultiple >= 1u && planeHeightElementsMultiple >= 1u);
3499
3500 if (planeWidthElementsMultiple != 1u || planeHeightElementsMultiple != 1u)
3501 {
3502 // we have a packed pixel format for which we cannot calculate the number of bytes per pixel
3503 return 0u;
3504 }
3505
3506 return planeChannels * bytesPerDataType(dataType(imagePixelFormat));
3507 }
3508 else
3509 {
3510 ocean_assert(false && "Invalid input!");
3511 return 0u;
3512 }
3513}
3514
3515inline 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)
3516{
3517 ocean_assert(frameType.isValid());
3518
3519 return planeLayout(frameType.pixelFormat(), frameType.width(), frameType.height(), planeIndex, planeWidth, planeHeight, planeChannels, planeWidthElementsMultiple, planeHeightElementsMultiple);
3520}
3521
3522template <typename T>
3523inline bool FrameType::dataIsAligned(const void* data)
3524{
3525 ocean_assert(data != nullptr);
3526 return size_t(data) % sizeof(T) == size_t(0);
3527}
3528
3529constexpr bool FrameType::isSumInsideValueRange(const unsigned int valueA, const unsigned int valueB)
3530{
3531 return valueA <= (unsigned int)(-1) - valueB;
3532}
3533
3534constexpr bool FrameType::isProductInsideValueRange(const unsigned int valueA, const unsigned int valueB)
3535{
3536 return valueB == 0u || valueA <= (unsigned int)(-1) / valueB;
3537}
3538
3539inline Frame::Plane::Plane(Plane&& plane) noexcept
3540{
3541 *this = std::move(plane);
3542}
3543
3544template <typename T>
3545inline Frame::Plane::Plane(const unsigned int width, const unsigned int height, const unsigned int channels, const T* dataToUse, const unsigned int paddingElements) noexcept :
3546 Plane(width, height, channels, sizeof(T), (const void*)(dataToUse), paddingElements)
3547{
3548 // nothing to do here
3549}
3550
3551template <typename T>
3552inline Frame::Plane::Plane(const unsigned int width, const unsigned int height, const unsigned int channels, T* dataToUse, const unsigned int paddingElements) noexcept :
3553 Plane(width, height, channels, sizeof(T), (void*)(dataToUse), paddingElements)
3554{
3555 // nothing to do here
3556}
3557
3558template <typename T>
3559inline 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 :
3560 Plane(width, height, channels, sizeof(T), (const void*)(sourceDataToCopy), targetPaddingElements, sourcePaddingElements, makeCopyOfPaddingData)
3561{
3562 // nothing to do here
3563}
3564
3565template <typename T>
3566inline 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 :
3567 Plane(width, height, channels, sizeof(T), (const void*)(sourceDataToCopy), sourcePaddingElements, copyMode)
3568{
3569 // nothing to do here
3570}
3571
3572inline 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 :
3573 allocatedData_(nullptr),
3574 constData_(constData),
3575 data_(data),
3576 width_(width),
3577 height_(height),
3578 channels_(channels),
3579 elementTypeSize_(elementTypeSize),
3580 paddingElements_(paddingElements)
3581{
3582 strideBytes_ = calculateStrideBytes();
3583 bytesPerPixel_ = calculateBytesPerPixel();
3584}
3585
3587{
3588 release();
3589}
3590
3591inline unsigned int Frame::Plane::width() const
3592{
3593 return width_;
3594}
3595
3596inline unsigned int Frame::Plane::height() const
3597{
3598 return height_;
3599}
3600
3601inline unsigned int Frame::Plane::channels() const
3602{
3603 return channels_;
3604}
3605
3606template <typename T>
3607inline const T* Frame::Plane::constdata() const
3608{
3609 return reinterpret_cast<const T*>(constData_);
3610}
3611
3612template <typename T>
3614{
3615 return reinterpret_cast<T*>(data_);
3616}
3617
3618inline unsigned int Frame::Plane::paddingElements() const
3619{
3620 return paddingElements_;
3621}
3622
3623inline unsigned int Frame::Plane::paddingBytes() const
3624{
3625 return paddingElements_ * elementTypeSize_;
3626}
3627
3628inline unsigned int Frame::Plane::elementTypeSize() const
3629{
3630 return elementTypeSize_;
3631}
3632
3633inline unsigned int Frame::Plane::widthElements() const
3634{
3635 ocean_assert(isProductInsideValueRange(width_, channels_));
3636
3637 return width_ * channels_;
3638}
3639
3640inline unsigned int Frame::Plane::widthBytes() const
3641{
3642 ocean_assert(isProductInsideValueRange(widthElements(), elementTypeSize_));
3643
3644 return widthElements() * elementTypeSize_;
3645}
3646
3647inline unsigned int Frame::Plane::strideElements() const
3648{
3649 ocean_assert(isSumInsideValueRange(widthElements(), paddingElements_));
3650
3651 return widthElements() + paddingElements_;
3652}
3653
3654inline unsigned int Frame::Plane::strideBytes() const
3655{
3656 ocean_assert(width_ == 0u || strideBytes_ != 0u);
3657 ocean_assert(strideBytes_ == calculateStrideBytes()); // ensuring that stride bytes is actually correct
3658
3659 return strideBytes_;
3660}
3661
3662inline unsigned int Frame::Plane::bytesPerPixel() const
3663{
3664 ocean_assert(bytesPerPixel_ == calculateBytesPerPixel());
3665
3666 return bytesPerPixel_;
3667}
3668
3669template <typename T>
3671{
3672 return elementTypeSize_ == sizeof(T);
3673}
3674
3675inline unsigned int Frame::Plane::size() const
3676{
3678
3679 return strideBytes() * height_;
3680}
3681
3683{
3684 return paddingElements_ == 0u;
3685}
3686
3687inline bool Frame::Plane::isOwner() const
3688{
3689 return allocatedData_ != nullptr;
3690}
3691
3692inline bool Frame::Plane::isReadOnly() const
3693{
3694 return data_ == nullptr;
3695}
3696
3697inline bool Frame::Plane::isValid() const
3698{
3699 return width_ != 0u && height_ != 0u && channels_ != 0u;
3700}
3701
3702constexpr bool Frame::Plane::validateMemoryLayout(const unsigned int planeWidth, const unsigned int planeHeight, const unsigned int planeChannels, const unsigned int bytesPerElement, const unsigned int paddingElements)
3703{
3705 {
3706 return false;
3707 }
3708
3709 const unsigned int planeWidthElements = planeWidth * planeChannels;
3710
3712 {
3713 return false;
3714 }
3715
3716 const unsigned int planeStrideElements = planeWidthElements + paddingElements;
3717
3718 if (!isProductInsideValueRange(planeStrideElements, bytesPerElement))
3719 {
3720 return false;
3721 }
3722
3723 const unsigned int planeStrideBytes = planeStrideElements * bytesPerElement;
3724
3725 if (!isProductInsideValueRange(planeStrideBytes, planeHeight))
3726 {
3727 return false;
3728 }
3729
3730 return true;
3731}
3732
3733inline unsigned int Frame::Plane::calculateStrideBytes() const
3734{
3735 ocean_assert(isProductInsideValueRange(strideElements(), elementTypeSize_));
3736
3737 return strideElements() * elementTypeSize_;
3738}
3739
3740template <typename T>
3741inline Frame::PlaneInitializer<T>::PlaneInitializer(const T* constdata, const CopyMode copyMode, const unsigned int dataPaddingElements) :
3742 constdata_(constdata),
3743 data_(nullptr),
3744 copyMode_(copyMode),
3745 paddingElements_(dataPaddingElements)
3746{
3747 // nothing to do here
3748}
3749
3750template <typename T>
3751inline Frame::PlaneInitializer<T>::PlaneInitializer(T* data, const CopyMode copyMode, const unsigned int dataPaddingElements) :
3752 constdata_(nullptr),
3753 data_(data),
3754 copyMode_(copyMode),
3755 paddingElements_(dataPaddingElements)
3756{
3757 // nothing to do here
3758}
3759
3760template <typename T>
3761inline Frame::PlaneInitializer<T>::PlaneInitializer(const unsigned int planePaddingElements) :
3762 constdata_(nullptr),
3763 data_(nullptr),
3764 copyMode_(CM_USE_KEEP_LAYOUT),
3765 paddingElements_(planePaddingElements)
3766{
3767 // nothing to do here
3768}
3769
3770template <typename T>
3771std::vector<Frame::PlaneInitializer<T>> Frame::PlaneInitializer<T>::createPlaneInitializersWithPaddingElements(const Indices32& paddingElementsPerPlane)
3772{
3773 PlaneInitializers<T> planeInitializers;
3774 planeInitializers.reserve(paddingElementsPerPlane.size());
3775
3776 for (const Index32& paddingElements : paddingElementsPerPlane)
3777 {
3778 planeInitializers.emplace_back(paddingElements);
3779 }
3780
3781 return planeInitializers;
3782}
3783
3785 FrameType(),
3786 planes_(1, Plane())
3787{
3788 // nothing to do here
3789}
3790
3791inline Frame::Frame(Frame&& frame) noexcept :
3792 FrameType()
3793{
3794 *this = std::move(frame);
3795
3796 ocean_assert(planes_.size() >= 1);
3797 ocean_assert(frame.planes_.size() == 1);
3798}
3799
3800inline Frame::Frame(const FrameType& frameType, const Indices32& planePaddingElements, const Timestamp& timestamp) :
3801 Frame(frameType, PlaneInitializer<void>::createPlaneInitializersWithPaddingElements(planePaddingElements), timestamp)
3802{
3803 ocean_assert(frameType.numberPlanes() == planePaddingElements.size() || planePaddingElements.empty());
3804 ocean_assert(planes_.size() == frameType.numberPlanes());
3805}
3806
3807inline Frame::Frame(const FrameType& frameType, const unsigned int paddingElements, const Timestamp& timestamp) :
3808 Frame(frameType, PlaneInitializers<void>(1, PlaneInitializer<void>(paddingElements)), timestamp)
3809{
3810 ocean_assert(frameType.numberPlanes() == 1u);
3811 ocean_assert(planes_.size() == 1);
3812}
3813
3814template <>
3815inline Frame::Frame(const FrameType& frameType, const void* data, const CopyMode copyMode, const unsigned int paddingElements, const Timestamp& timestamp) :
3816 Frame(frameType, PlaneInitializers<void>(1, PlaneInitializer<void>(data, copyMode, paddingElements)), timestamp)
3817{
3818 // this constructor is for 1-plane frames only
3819
3820 ocean_assert(frameType.numberPlanes() == 1u);
3821 ocean_assert(planes_.size() == 1);
3822}
3823
3824template <typename T>
3825inline Frame::Frame(const FrameType& frameType, const T* data, const CopyMode copyMode, const unsigned int paddingElements, const Timestamp& timestamp) :
3826 Frame(frameType, (const void*)(data), copyMode, paddingElements, timestamp)
3827{
3828#ifdef OCEAN_DEBUG
3829 const FrameType::DataType debugTemplateDataType = FrameType::dataType<T>();
3830 const FrameType::DataType debugFrameTypeDataType = frameType.dataType();
3831
3832 // we ensure that the template data type matches with the data type of the pixel format (as padding is defined in elements)
3833 ocean_assert(debugTemplateDataType == FrameType::DT_UNDEFINED || debugTemplateDataType == debugFrameTypeDataType);
3834#endif
3835
3836 ocean_assert(planes_.size() == 1);
3837}
3838
3839template <>
3840inline Frame::Frame(const FrameType& frameType, void* data, const CopyMode copyMode, const unsigned int paddingElements, const Timestamp& timestamp) :
3841 Frame(frameType, PlaneInitializers<void>(1, PlaneInitializer<void>(data, copyMode, paddingElements)), timestamp)
3842{
3843 // this constructor is for 1-plane frames only
3844
3845 ocean_assert(frameType.numberPlanes() == 1u);
3846 ocean_assert(planes_.size() == 1);
3847}
3848
3849template <typename T>
3850inline Frame::Frame(const FrameType& frameType, T* data, const CopyMode copyMode, const unsigned int paddingElements, const Timestamp& timestamp) :
3851 Frame(frameType, (void*)(data), copyMode, paddingElements, timestamp)
3852{
3853#ifdef OCEAN_DEBUG
3854 const FrameType::DataType debugTemplateDataType = FrameType::dataType<T>();
3855 const FrameType::DataType debugFrameTypeDataType = frameType.dataType();
3856
3857 // we ensure that the template data type matches with the data type of the pixel format (as padding is defined in elements)
3858 ocean_assert(debugTemplateDataType == FrameType::DT_UNDEFINED || debugTemplateDataType == debugFrameTypeDataType);
3859#endif
3860
3861 ocean_assert(planes_.size() == 1);
3862}
3863
3864template <typename T>
3865inline Frame::Frame(const FrameType& frameType, const PlaneInitializers<T>& planeInitializers, const Timestamp& timestamp) :
3866 Frame(frameType, (const PlaneInitializer<void>*)planeInitializers.data(), planeInitializers.size(), timestamp)
3867{
3868#ifdef OCEAN_DEBUG
3869 const FrameType::DataType debugTemplateDataType = FrameType::dataType<T>();
3870 const FrameType::DataType debugFrameTypeDataType = frameType.dataType();
3871
3872 // we ensure that the template data type matches with the data type of the pixel format (as padding is defined in elements)
3873 ocean_assert(debugTemplateDataType == FrameType::DT_UNDEFINED || debugTemplateDataType == debugFrameTypeDataType);
3874#endif
3875
3876 ocean_assert(planes_.size() == frameType.numberPlanes());
3877}
3878
3879inline const FrameType& Frame::frameType() const
3880{
3881 return (const FrameType&)(*this);
3882}
3883
3884inline const Frame::Planes& Frame::planes() const
3885{
3886 return planes_;
3887}
3888
3889template <typename T>
3890bool Frame::updateMemory(const T* data, const unsigned int planeIndex)
3891{
3892 ocean_assert(data != nullptr);
3893 if (data != nullptr)
3894 {
3895 ocean_assert(planeIndex < planes_.size());
3896 if (planeIndex < planes_.size())
3897 {
3898 Plane& plane = planes_[planeIndex];
3899
3900 if constexpr (!std::is_void_v<T>)
3901 {
3902 ocean_assert(sizeof(T) == plane.elementTypeSize());
3903 }
3904
3905 ocean_assert(plane.allocatedData_ == nullptr);
3906 if (plane.allocatedData_ == nullptr)
3907 {
3908 plane.constData_ = data;
3909 plane.data_ = nullptr;
3910
3911 return true;
3912 }
3913 }
3914 }
3915
3916 return false;
3917}
3918
3919template <typename T>
3920bool Frame::updateMemory(T* data, const unsigned int planeIndex)
3921{
3922 ocean_assert(data != nullptr);
3923 if (data != nullptr)
3924 {
3925 ocean_assert(planeIndex < planes_.size());
3926 if (planeIndex < planes_.size())
3927 {
3928 Plane& plane = planes_[planeIndex];
3929
3930 if constexpr (!std::is_void_v<T>)
3931 {
3932 ocean_assert(sizeof(T) == plane.elementTypeSize());
3933 }
3934
3935 ocean_assert(plane.allocatedData_ == nullptr);
3936 if (plane.allocatedData_ == nullptr)
3937 {
3938 plane.data_ = data;
3939 plane.constData_ = (const T*)(data);
3940
3941 return true;
3942 }
3943 }
3944 }
3945
3946 return false;
3947}
3948
3949template <typename T>
3950bool Frame::updateMemory(const std::initializer_list<T*>& planeDatas)
3951{
3952 ocean_assert(planeDatas.size() != 0);
3953 ocean_assert(planeDatas.size() <= planes_.size());
3954
3955 if (planeDatas.size() == 0 || planeDatas.size() > planes_.size())
3956 {
3957 return false;
3958 }
3959
3960 for (unsigned int planeIndex = 0u; planeIndex < planeDatas.size(); ++planeIndex)
3961 {
3962 if (!updateMemory(planeDatas.begin()[planeIndex], planeIndex))
3963 {
3964 return false;
3965 }
3966 }
3967
3968 return true;
3969}
3970
3971template <typename T, const unsigned int tPlaneChannels>
3972bool Frame::setValue(const PixelType<T, tPlaneChannels>& planePixelValue, const unsigned int planeIndex)
3973{
3974 static_assert(!std::is_void_v<T>, "Value access/assignment cannot be performed with void types.");
3975
3976 ocean_assert(planes_.size() >= 1);
3977 ocean_assert(planeIndex < planes_.size());
3978
3979 Plane& plane = planes_[planeIndex];
3980
3981 ocean_assert(plane.isValid());
3982
3983 if (sizeof(T) != plane.elementTypeSize())
3984 {
3985 ocean_assert(false && "The specified data type must fit to the frame's data type!");
3986 return false;
3987 }
3988
3989 if (plane.channels() != tPlaneChannels)
3990 {
3991 ocean_assert(false && "The specified number of channels does not fit with the plane's actual channels!");
3992 return false;
3993 }
3994
3995 if (plane.isReadOnly())
3996 {
3997 return false;
3998 }
3999
4000 if (plane.paddingElements_ == 0u)
4001 {
4003
4004 for (unsigned int n = 0u; n < plane.width() * plane.height(); ++n)
4005 {
4006 data[n] = planePixelValue;
4007 }
4008 }
4009 else
4010 {
4011 const unsigned int planeStrideBytes = plane.strideBytes();
4012
4013 for (unsigned int y = 0u; y < plane.height(); ++y)
4014 {
4015 PixelType<T, tPlaneChannels>* const data = (PixelType<T, tPlaneChannels>*)(plane.data<uint8_t>() + y * planeStrideBytes);
4016
4017 for (unsigned int x = 0u; x < plane.width(); ++x)
4018 {
4019 data[x] = planePixelValue;
4020 }
4021 }
4022 }
4023
4024 return true;
4025}
4026
4027template <typename T, const unsigned int tPlaneChannels>
4028bool Frame::containsValue(const PixelType<T, tPlaneChannels>& planePixelValue, const unsigned int planeIndex) const
4029{
4030 static_assert(!std::is_void_v<T>, "Value access/comparison cannot be performed with void types.");
4031
4032 ocean_assert(planes_.size() >= 1);
4033 ocean_assert(planeIndex < planes_.size());
4034
4035 const Plane& plane = planes_[planeIndex];
4036
4037 ocean_assert(plane.isValid());
4038
4039 if (sizeof(T) != plane.elementTypeSize())
4040 {
4041 ocean_assert(false && "The specified data type must fit to the frame's data type!");
4042 return false;
4043 }
4044
4045 if (plane.channels() != tPlaneChannels)
4046 {
4047 ocean_assert(false && "The specified number of channels does not fit with the plane's actual channels!");
4048 return false;
4049 }
4050
4051 const unsigned int planeStrideBytes = plane.strideBytes();
4052
4053 for (unsigned int y = 0u; y < plane.height(); ++y)
4054 {
4055 PixelType<T, tPlaneChannels>* const data = (PixelType<T, tPlaneChannels>*)(plane.constdata<uint8_t>() + y * planeStrideBytes);
4056
4057 for (unsigned int x = 0u; x < plane.width(); ++x)
4058 {
4059 if (data[x] == planePixelValue)
4060 {
4061 return true;
4062 }
4063 }
4064 }
4065
4066 return false;
4067}
4068
4069template <typename T>
4070bool Frame::setValue(const T* planePixelValue, const size_t planePixelValueSize, const unsigned int planeIndex)
4071{
4072 static_assert(!std::is_void_v<T>, "Value access/assignment cannot be performed with void types.");
4073
4074 ocean_assert(planePixelValue != nullptr);
4075
4076 ocean_assert(planes_[planeIndex].elementTypeSize() == sizeof(T));
4077 ocean_assert(planes_[planeIndex].channels() == planePixelValueSize);
4078
4079 switch (planePixelValueSize)
4080 {
4081 case 1:
4082 {
4083 const PixelType<T, 1u> value =
4084 {{
4085 planePixelValue[0]
4086 }};
4087
4088 return setValue<T, 1u>(value, planeIndex);
4089 }
4090
4091 case 2:
4092 {
4093 const PixelType<T, 2u> value =
4094 {{
4095 planePixelValue[0],
4096 planePixelValue[1]
4097 }};
4098
4099 return setValue<T, 2u>(value, planeIndex);
4100 }
4101
4102 case 3:
4103 {
4104 const PixelType<T, 3u> value =
4105 {{
4106 planePixelValue[0],
4107 planePixelValue[1],
4108 planePixelValue[2]
4109 }};
4110
4111 return setValue<T, 3u>(value, planeIndex);
4112 }
4113
4114 case 4:
4115 {
4116 const PixelType<T, 4u> value =
4117 {{
4118 planePixelValue[0],
4119 planePixelValue[1],
4120 planePixelValue[2],
4121 planePixelValue[3]
4122 }};
4123
4124 return setValue<T, 4u>(value, planeIndex);
4125 }
4126
4127 default:
4128 break;
4129 }
4130
4131 ocean_assert(false && "The number of channels is not supported");
4132 return false;
4133}
4134
4135template <typename T>
4136bool Frame::setValue(const std::initializer_list<typename Identity<T>::Type>& planePixelValues, const unsigned int planeIndex)
4137{
4138 return setValue<T>(planePixelValues.begin(), planePixelValues.size(), planeIndex);
4139}
4140
4141inline unsigned int Frame::size(const unsigned int planeIndex) const
4142{
4143 ocean_assert(planes_.size() >= 1);
4144 ocean_assert(planeIndex < planes_.size());
4145
4146 return planes_[planeIndex].size();
4147}
4148
4149inline unsigned int Frame::paddingElements(const unsigned int planeIndex) const
4150{
4151 ocean_assert(planes_.size() >= 1);
4152 ocean_assert(planeIndex < planes_.size());
4153
4154 return planes_[planeIndex].paddingElements();
4155}
4156
4157inline unsigned int Frame::paddingBytes(const unsigned int planeIndex) const
4158{
4159 ocean_assert(planes_.size() >= 1);
4160 ocean_assert(planeIndex < planes_.size());
4161
4162 return planes_[planeIndex].paddingBytes();
4163}
4164
4165inline unsigned int Frame::strideElements(const unsigned int planeIndex) const
4166{
4167 ocean_assert(planes_.size() >= 1);
4168 ocean_assert(planeIndex < planes_.size());
4169
4170 return planes_[planeIndex].strideElements();
4171}
4172
4173inline unsigned int Frame::strideBytes(const unsigned int planeIndex) const
4174{
4175 ocean_assert(planes_.size() >= 1);
4176 ocean_assert(planeIndex < planes_.size());
4177
4178 return planes_[planeIndex].strideBytes();
4179}
4180
4181inline unsigned int Frame::planeWidth(const unsigned int planeIndex) const
4182{
4183 ocean_assert(planes_.size() >= 1);
4184 ocean_assert(planeIndex < planes_.size());
4185
4186 return planes_[planeIndex].width();
4187}
4188
4189inline unsigned int Frame::planeHeight(const unsigned int planeIndex) const
4190{
4191 ocean_assert(planes_.size() >= 1);
4192 ocean_assert(planeIndex < planes_.size());
4193
4194 return planes_[planeIndex].height();
4195}
4196
4197inline unsigned int Frame::planeChannels(const unsigned int planeIndex) const
4198{
4199 ocean_assert(planes_.size() >= 1);
4200 ocean_assert(planeIndex < planes_.size());
4201
4202 return planes_[planeIndex].channels();
4203}
4204
4205inline unsigned int Frame::planeWidthElements(const unsigned int planeIndex) const
4206{
4207 ocean_assert(planes_.size() >= 1);
4208 ocean_assert(planeIndex < planes_.size());
4209
4210 return planes_[planeIndex].widthElements();
4211}
4212
4213inline unsigned int Frame::planeWidthBytes(const unsigned int planeIndex) const
4214{
4215 ocean_assert(planes_.size() >= 1);
4216 ocean_assert(planeIndex < planes_.size());
4217
4218 return planes_[planeIndex].widthBytes();
4219}
4220
4221inline unsigned int Frame::planeBytesPerPixel(const unsigned int planeIndex) const
4222{
4223 ocean_assert(planes_.size() >= 1);
4224 ocean_assert(planeIndex < planes_.size());
4225
4226 return FrameType::planeBytesPerPixel(pixelFormat(), planeIndex);
4227}
4228
4229inline bool Frame::isPlaneContinuous(const unsigned int planeIndex) const
4230{
4231 ocean_assert(planes_.size() >= 1);
4232 ocean_assert(planeIndex < planes_.size());
4233
4234 return planes_[planeIndex].isContinuous();
4235}
4236
4237inline bool Frame::isPlaneOwner(const unsigned int planeIndex) const
4238{
4239 ocean_assert(planes_.size() >= 1);
4240 ocean_assert(planeIndex < planes_.size());
4241
4242 return planes_[planeIndex].isOwner();
4243}
4244
4245inline const Timestamp& Frame::timestamp() const
4246{
4247 return timestamp_;
4248}
4249
4251{
4252 return relativeTimestamp_;
4253}
4254
4255inline void Frame::setTimestamp(const Timestamp& timestamp)
4256{
4258}
4259
4260inline void Frame::setRelativeTimestamp(const Timestamp& relativeTimestamp)
4261{
4263}
4264
4265template <typename T>
4266inline T* Frame::data(const unsigned int planeIndex)
4267{
4268 ocean_assert(planes_.size() >= 1);
4269 ocean_assert(planeIndex < planes_.size());
4270
4271 return planes_[planeIndex].data<T>();
4272}
4273
4274template <typename T>
4275inline const T* Frame::constdata(const unsigned int planeIndex) const
4276{
4277 ocean_assert(planes_.size() >= 1);
4278 ocean_assert(planeIndex < planes_.size());
4279
4280 return planes_[planeIndex].constdata<T>();
4281}
4282
4283template <typename T>
4284inline T* Frame::row(const unsigned int y, const unsigned int planeIndex)
4285{
4286 ocean_assert(isValid());
4287 ocean_assert(y < height());
4288
4289 ocean_assert(planes_.size() >= 1);
4290 ocean_assert(planeIndex < planes_.size());
4291 Plane& plane = planes_[planeIndex];
4292
4293 ocean_assert(plane.isValid());
4294
4295 ocean_assert(y < plane.height());
4296 return reinterpret_cast<T*>(plane.data<uint8_t>() + y * plane.strideBytes());
4297}
4298
4299template <typename T>
4300inline const T* Frame::constrow(const unsigned int y, const unsigned int planeIndex) const
4301{
4302 ocean_assert(isValid());
4303 ocean_assert(y < height());
4304
4305 ocean_assert(planes_.size() >= 1);
4306 ocean_assert(planeIndex < planes_.size());
4307 const Plane& plane = planes_[planeIndex];
4308
4309 ocean_assert(plane.isValid());
4310
4311 ocean_assert(y < plane.height());
4312 return reinterpret_cast<const T*>(plane.constdata<uint8_t>() + y * plane.strideBytes());
4313}
4314
4315template <typename T>
4316inline T* Frame::pixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex)
4317{
4318 ocean_assert(isValid());
4319 ocean_assert(x < planeWidth(planeIndex));
4320 ocean_assert(y < planeHeight(planeIndex));
4321
4322 ocean_assert(planes_.size() >= 1);
4323 ocean_assert(planeIndex < planes_.size());
4324 Plane& plane = planes_[planeIndex];
4325
4326 ocean_assert(plane.isValid());
4327
4328 if constexpr (!std::is_void_v<T>)
4329 {
4330 ocean_assert(sizeof(T) == plane.elementTypeSize());
4331 }
4332
4333 /*
4334 * how to determine pixel offsets within row:
4335 *
4336 * the pixel format RGB24 has data type`uint8_t` and 3 channels
4337 * so the n-th pixel is reach by row<uint8_t>() + n * sizeof(uint8_t) * channels()
4338 *
4339 * RGB5551 has data type `uint16_t` and 3 channels
4340 * so the n-th pixel is reach by row<uint8_t>() + n * sizeof(uint16_t) * channels() / 3 == row<uint8_t>() + n * sizeof(uint16_t)
4341 * or row<uint16_t>() + n * channels() / 3 == row<uint16_t>() + n
4342 *
4343 * Therefore, the pixel offset cannot be determined via x * channels(),
4344 * Instead, we determine the offset via bytes per pixel == planeWidthBytes() / planeWidth()
4345 */
4346
4347 ocean_assert(x == 0u || !formatIsPacked(pixelFormat()));
4348
4349 ocean_assert(plane.bytesPerPixel() != 0u);
4350 const unsigned int xBytes = x * plane.bytesPerPixel();
4351
4352 ocean_assert(y < plane.height());
4353 return reinterpret_cast<T*>(plane.data<uint8_t>() + y * plane.strideBytes() + xBytes);
4354}
4355
4356template <typename T>
4357inline const T* Frame::constpixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex) const
4358{
4359 ocean_assert(isValid());
4360 ocean_assert(x < planeWidth(planeIndex));
4361 ocean_assert(y < planeHeight(planeIndex));
4362
4363 ocean_assert(planes_.size() >= 1);
4364 ocean_assert(planeIndex < planes_.size());
4365 const Plane& plane = planes_[planeIndex];
4366
4367 ocean_assert(plane.isValid());
4368
4369 if constexpr (!std::is_void_v<T>)
4370 {
4371 ocean_assert(sizeof(T) == plane.elementTypeSize());
4372 }
4373
4374 ocean_assert(x == 0u || !formatIsPacked(pixelFormat()));
4375
4376 ocean_assert(plane.bytesPerPixel() != 0u);
4377 const unsigned int xBytes = x * plane.bytesPerPixel();
4378
4379 ocean_assert(y < plane.height());
4380 return reinterpret_cast<const T*>(plane.constdata<uint8_t>() + y * plane.strideBytes() + xBytes);
4381}
4382
4383inline bool Frame::isContinuous() const
4384{
4385 ocean_assert(planes_.size() >= 1);
4386
4387 for (const Plane& plane : planes_)
4388 {
4389 if (!plane.isContinuous())
4390 {
4391 return false;
4392 }
4393 }
4394
4395 return true;
4396}
4397
4398inline bool Frame::isOwner() const
4399{
4400 ocean_assert(planes_.size() >= 1);
4401
4402 for (const Plane& plane : planes_)
4403 {
4404 if (!plane.isOwner())
4405 {
4406 return false;
4407 }
4408 }
4409
4410 return true;
4411}
4412
4413inline bool Frame::isReadOnly() const
4414{
4415 ocean_assert(planes_.size() >= 1);
4416
4417 for (const Plane& plane : planes_)
4418 {
4419 if (plane.isReadOnly())
4420 {
4421 return true;
4422 }
4423 }
4424
4425 return false;
4426}
4427
4428inline bool Frame::hasAlphaChannel() const
4429{
4430 ocean_assert(isValid());
4431
4433}
4434
4435template <>
4436inline bool Frame::hasTransparentPixel(const uint8_t opaque) const
4437{
4438 if (!hasAlphaChannel())
4439 {
4440 return false;
4441 }
4442
4443 ocean_assert(numberPlanes() == 1u);
4444
4445 if (dataType() != dataType<uint8_t>())
4446 {
4447 ocean_assert(false && "Data type does not fit with the frame's data type!");
4448 return false;
4449 }
4450
4451 if (pixelFormat() == FORMAT_YA16)
4452 {
4453 for (unsigned int y = 0u; y < height(); ++y)
4454 {
4455 const uint8_t* row = constrow<uint8_t>(y) + 1;
4456
4457 for (unsigned int x = 0u; x < width(); ++x)
4458 {
4459 if (*row != opaque)
4460 {
4461 return true;
4462 }
4463
4464 row += 2;
4465 }
4466 }
4467 }
4468 else
4469 {
4471
4472 const unsigned int offset = (pixelFormat() == FORMAT_ABGR32 || pixelFormat() == FORMAT_ARGB32) ? 0u : 3u;
4473
4474 for (unsigned int y = 0u; y < height(); ++y)
4475 {
4476 const uint8_t* row = constrow<uint8_t>(y) + offset;
4477
4478 for (unsigned int x = 0u; x < width(); ++x)
4479 {
4480 if (*row != opaque)
4481 {
4482 return true;
4483 }
4484
4485 row += 4;
4486 }
4487 }
4488 }
4489
4490 return false;
4491}
4492
4493template <>
4494inline bool Frame::hasTransparentPixel(const uint16_t opaque) const
4495{
4496 if (!hasAlphaChannel())
4497 {
4498 return false;
4499 }
4500
4501 ocean_assert(numberPlanes() == 1u);
4502
4503 if (dataType() != dataType<uint16_t>())
4504 {
4505 ocean_assert(false && "Data type does not fit with the frame's data type!");
4506 return false;
4507 }
4508
4509 if (pixelFormat() == FORMAT_RGBA64)
4510 {
4511 for (unsigned int y = 0u; y < height(); ++y)
4512 {
4513 const uint16_t* row = constrow<uint16_t>(y) + 3;
4514
4515 for (unsigned int x = 0u; x < width(); ++x)
4516 {
4517 if (*row != opaque)
4518 {
4519 return true;
4520 }
4521
4522 row += 4;
4523 }
4524 }
4525 }
4526 else
4527 {
4528 ocean_assert(pixelFormat() == FORMAT_RGBA4444 || pixelFormat() == FORMAT_BGRA4444);
4529
4530 for (unsigned int y = 0u; y < height(); ++y)
4531 {
4532 const uint16_t* row = constrow<uint16_t>(y);
4533
4534 for (unsigned int x = 0u; x < width(); ++x)
4535 {
4536 if ((*row & opaque) != opaque)
4537 {
4538 return true;
4539 }
4540
4541 ++row;
4542 }
4543 }
4544 }
4545
4546 return false;
4547}
4548
4549template <typename T>
4550bool Frame::hasTransparentPixel(const T /*opaque*/) const
4551{
4552 return false;
4553}
4554
4555inline bool Frame::isValid() const
4556{
4557 ocean_assert(planes_.size() >= 1);
4558
4559 const bool frameTypeIsValid = FrameType::isValid();
4560
4561#ifdef OCEAN_DEBUG
4562 {
4563 // we ensure that the state of `planes_` is consistent with the state of `FrameType::isValid()`
4564
4565 size_t debugValidPlanes = 0;
4566
4567 for (const Plane& plane : planes_)
4568 {
4569 if (plane.isValid())
4570 {
4571 ++debugValidPlanes;
4572 }
4573 }
4574
4575 const bool debugIsValid = !planes_.isEmpty() && debugValidPlanes == planes_.size();
4576
4577 ocean_assert(debugIsValid == frameTypeIsValid);
4578 }
4579#endif // OCEAN_DEBUG
4580
4581 return frameTypeIsValid;
4582}
4583
4584inline Frame::operator bool() const
4585{
4586 return isValid();
4587}
4588
4589}
4590
4591#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:1897
unsigned int width() const
Returns the width of the plane in pixel.
Definition Frame.h:3591
bool isCompatibleWithDataType() const
Returns whether this plane is compatible with a given element data type.
Definition Frame.h:3670
unsigned int paddingElements() const
Returns the number of padding elements at the end of each plane row, in elements.
Definition Frame.h:3618
void * allocatedData_
The pointer to the memory which this plane has allocated, this pointer is pointing to the memory whic...
Definition Frame.h:2256
unsigned int paddingBytes() const
Returns the number of padding bytes at the end of each plane row, in bytes.
Definition Frame.h:3623
unsigned int elementTypeSize() const
Returns the size of each element of this plane.
Definition Frame.h:3628
bool isOwner() const
Returns whether this plane is the owner of the memory.
Definition Frame.h:3687
unsigned int calculateStrideBytes() const
Calculates the number of bytes between the start positions of two consecutive rows,...
Definition Frame.h:3733
void * data_
The pointer to the writable memory of the plane (not the pointer to the allocated memory),...
Definition Frame.h:2262
unsigned int strideBytes() const
Returns the number of bytes between the start positions of two consecutive rows, in bytes.
Definition Frame.h:3654
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:3682
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:3607
bool isValid() const
Returns whether this plane holds valid data.
Definition Frame.h:3697
T * data()
Returns the writable memory pointer to this plane with a specific data type compatible with elementTy...
Definition Frame.h:3613
bool isReadOnly() const
Returns whether this plane holds read-only memory.
Definition Frame.h:3692
unsigned int size() const
Returns the number of bytes necessary for the entire plane data including optional padding elements a...
Definition Frame.h:3675
static constexpr bool validateMemoryLayout(const unsigned int planeWidth, const unsigned int planeHeight, const unsigned int planeChannels, const unsigned int bytesPerElement, const unsigned int paddingElements)
Returns whether the memory layout of a plane is valid (and fits into the memory).
Definition Frame.h:3702
unsigned int widthBytes() const
Returns the width of the plane in bytes, the width does not contain optional padding elements.
Definition Frame.h:3640
~Plane()
Destructs a Plane object.
Definition Frame.h:3586
Plane()=default
Creates a new invalid plane.
unsigned int channels() const
Returns the channels of the plane.
Definition Frame.h:3601
const void * constData_
The pointer to the read-only memory of the plane (not the pointer to the allocated memory),...
Definition Frame.h:2259
unsigned int bytesPerPixel() const
Returns the number of bytes which is used for each pixel.
Definition Frame.h:3662
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:3647
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:3596
unsigned int paddingElements_
The number of padding elements at the end of each plane row, in elements, with range [0,...
Definition Frame.h:2277
unsigned int widthElements() const
Returns the width of the plane in elements, the width does not contain optional padding elements.
Definition Frame.h:3633
This class implements a helper class which can be used to initialize a multi-plane frame in the const...
Definition Frame.h:2298
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:3741
static std::vector< PlaneInitializer< T > > createPlaneInitializersWithPaddingElements(const Indices32 &paddingElementsPerPlane)
Creates plane initializer objects with padding elements only.
Definition Frame.h:3771
This class implements Ocean's image class.
Definition Frame.h:1832
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(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:2362
Timestamp relativeTimestamp_
Relative timestamp of this frame.
Definition Frame.h:3114
bool isContinuous() const
Returns whether all planes of this frame have continuous memory and thus do not contain any padding a...
Definition Frame.h:4383
bool hasAlphaChannel() const
Returns whether the frame's pixel format contains an alpha channel.
Definition Frame.h:4428
Frame(const FrameType &frameType, const AdvancedCopyMode advancedCopyMode)=delete
Deleted constructor to prevent misuse.
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:4173
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:3111
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:4165
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:4284
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:3890
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:4275
void setRelativeTimestamp(const Timestamp &relative)
Sets the relative timestamp of this frame.
Definition Frame.h:4260
const FrameType & frameType() const
Returns the frame type of this frame.
Definition Frame.h:3879
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:4266
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4555
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:4316
void setTimestamp(const Timestamp &timestamp)
Sets the timestamp of this frame.
Definition Frame.h:4255
bool isReadOnly() const
Returns true, if the frame allows only read access (using constdata()).
Definition Frame.h:4413
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.
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.
Frame & operator=(Frame &&right) noexcept
Move operator.
const Timestamp & timestamp() const
Returns the timestamp of this frame.
Definition Frame.h:4245
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:4221
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:4205
std::vector< PlaneInitializer< T > > PlaneInitializers
Definition of a vector holding plane initializer objects.
Definition Frame.h:2354
const Timestamp & relativeTimestamp() const
Returns the relative timestamp of this frame.
Definition Frame.h:4250
const Planes & planes() const
Returns the individual planes of this frame.
Definition Frame.h:3884
bool isOwner() const
Returns whether the frame is the owner of the internal frame data.
Definition Frame.h:4398
CopyMode
Definition of individual copy modes.
Definition Frame.h:1839
@ CM_USE_KEEP_LAYOUT
The source memory is used only, no copy is created, the padding layout is preserved.
Definition Frame.h:1841
unsigned int planeChannels(const unsigned int planeIndex) const
Returns the channels of a plane of this frame.
Definition Frame.h:4197
unsigned int planeWidth(const unsigned int planeIndex) const
Returns the width of a plane of this frame.
Definition Frame.h:4181
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:3784
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:4357
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:1854
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:4229
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:4028
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:4237
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:4157
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:4300
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:4213
bool hasTransparentPixel(const T opaque) const
Returns whether the frame holds at least one pixel with an non opaque alpha value.
Definition Frame.h:4550
Frame & operator=(const Frame &right) noexcept
Assign operator.
unsigned int planeHeight(const unsigned int planeIndex) const
Returns the height of a plane of this frame.
Definition Frame.h:4189
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:4141
Planes planes_
The individual memory planes of this frame.
Definition Frame.h:3108
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:4149
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:3476
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:3244
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 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:3194
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:3239
std::vector< PixelFormat > PixelFormats
Definition of a vector holding pixel formats.
Definition Frame.h:1040
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:3388
static constexpr bool isProductInsideValueRange(const unsigned int valueA, const unsigned int valueB)
Returns whether two values can be multiplied with each other without producing an overflow.
Definition Frame.h:3534
unsigned int height_
Frame height in pixel, with range [0, infinity)
Definition Frame.h:1778
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:3523
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:3261
static constexpr bool isSumInsideValueRange(const unsigned int valueA, const unsigned int valueB)
Returns whether two values can be added with each other without producing an overflow.
Definition Frame.h:3529
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.
static PixelFormat formatGrayscalePixelFormat(const PixelFormat pixelFormat)
Returns the best matching grayscale pixel format for a given pixel format.
static constexpr PixelFormat genericPixelFormat()
Returns a specific generic pixel format with a specified data type and channel number.
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition Frame.h:3234
PixelOrigin pixelOrigin_
The origin of the pixel data, either the upper left corner or the bottom left corner (if valid).
Definition Frame.h:1784
static std::string translatePixelFormat(const PixelFormat pixelFormat)
Translates a pixel format value into a string containing the pixel format.
static bool formatIsLimitedRange(const PixelFormat pixelFormat)
Returns whether a given pixel format is using a limited value range (e.g., like Y_UV12_LIMITED_RANGE)...
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
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:3481
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition Frame.h:3204
unsigned int bytesPerDataType() const
Returns the number of bytes which are necessary to store the data type of this frame.
Definition Frame.h:3219
static constexpr 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
static const FrameType::DataTypes & definedDataTypes()
Returns all defined data types.
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:3486
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3199
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:1775
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:3469
bool isValid() const
Returns whether this frame type is valid.
Definition Frame.h:3266
static const FrameType::PixelFormats & definedPixelFormats()
Returns all defined pixel formats.
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:3251
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition Frame.h:3224
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:1781
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:3214
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:3452
static unsigned int planeChannels(const PixelFormat &imagePixelFormat, const unsigned int planeIndex)
Returns the channels of a plane for a pixel format.
static constexpr PixelFormat genericPixelFormat()
Returns a specific generic pixel format with a specified data type and channel number.
Definition Frame.h:3405
bool isFrameTypeCompatible(const FrameType &frameType, const bool allowDifferentPixelOrigins) const
Returns whether this frame type is compatible with a given frame type.
Definition Frame.h:3256
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:3276
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:3459
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:3209
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:621
size_t size() const
Returns the number of elements of this vector.
Definition StackHeapVector.h:607
This class implements a timestamp.
Definition Timestamp.h:51
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
std::vector< Frame > Frames
Definition of a vector holding padding frames.
Definition Frame.h:1795
std::vector< FrameRef > FrameRefs
Definition of a vector holding frame references.
Definition Frame.h:1807
uint32_t Index32
Definition of a 32 bit index value.
Definition Base.h:84
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