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