8 #ifndef META_OCEAN_BASE_FRAME_H
9 #define META_OCEAN_BASE_FRAME_H
17 #include <type_traits>
74 static constexpr uint32_t pixelFormatBitOffsetChannels = 16u;
77 static constexpr uint32_t pixelFormatBitOffsetDatatype = pixelFormatBitOffsetChannels + 8u;
80 static constexpr uint32_t pixelFormatBitOffsetPlanes = pixelFormatBitOffsetDatatype + 8u;
83 static constexpr uint32_t pixelFormatBitOffsetWidthMultiple = pixelFormatBitOffsetPlanes + 8u;
86 static constexpr uint32_t pixelFormatBitOffsetHeightMultiple = pixelFormatBitOffsetWidthMultiple + 8u;
96 template <DataType tDataType, u
int32_t tChannels, u
int32_t tPlanes, u
int32_t tW
idthMultiple, u
int32_t tHeightMultiple>
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);
111 CV_CHANNELS_UNDEFINED = 0u,
187 FORMAT_UNDEFINED = 0ull,
244 FORMAT_BGR4444 = 5ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
249 FORMAT_BGR5551 = 6ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
264 FORMAT_BGR565 = 7ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
282 FORMAT_BGRA4444 = 9ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
302 FORMAT_BGGR10_PACKED = 10ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_4, MV_MULTIPLE_2>::value,
341 FORMAT_RGB4444 = 13ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
354 FORMAT_RGB5551 = 14ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
367 FORMAT_RGB565 = 15ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
395 FORMAT_RGBA4444 = 17ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_16, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
428 FORMAT_RGGB10_PACKED = 19ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_4, MV_MULTIPLE_2>::value,
446 FORMAT_Y_U_V12 = 20ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_3, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
495 FORMAT_Y_V_U12 = 24ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_3, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
527 FORMAT_Y_UV12 = 26ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_2, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
545 FORMAT_Y_VU12 = 27ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_2, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
563 FORMAT_YUYV16 = 28ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_2, MV_MULTIPLE_1>::value,
581 FORMAT_UYVY16 = 29ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_2, MV_MULTIPLE_1>::value,
621 FORMAT_Y10_PACKED = 32ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_1, MV_MULTIPLE_4, MV_MULTIPLE_1>::value,
693 FORMAT_Y_U_V24 = 39ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_3, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
718 FORMAT_Y_U_V24_LIMITED_RANGE = FORMAT_Y_U_V24,
743 FORMAT_Y_U_V24_FULL_RANGE = 40ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_3, MV_MULTIPLE_1, MV_MULTIPLE_1>::value,
783 FORMAT_Y8_FULL_RANGE = FORMAT_Y8,
808 FORMAT_Y_UV12_LIMITED_RANGE = FORMAT_Y_UV12,
834 FORMAT_Y_UV12_FULL_RANGE = 42ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_2, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
859 FORMAT_Y_VU12_LIMITED_RANGE = FORMAT_Y_VU12,
885 FORMAT_Y_VU12_FULL_RANGE = 43ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_2, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
910 FORMAT_Y_U_V12_LIMITED_RANGE = FORMAT_Y_U_V12,
936 FORMAT_Y_U_V12_FULL_RANGE = 44ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_3, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
961 FORMAT_Y_V_U12_LIMITED_RANGE = FORMAT_Y_V_U12,
987 FORMAT_Y_V_U12_FULL_RANGE = 45ull |
GenericPixelFormat<DT_UNSIGNED_INTEGER_8, CV_CHANNELS_UNDEFINED , PV_PLANES_3, MV_MULTIPLE_2, MV_MULTIPLE_2>::value,
1016 ORIGIN_INVALID = 0u,
1052 static_assert(
sizeof(
PixelFormatProperties) ==
sizeof(std::underlying_type<PixelFormat>::type),
"Invalid helper struct!");
1105 inline FrameType(
const FrameType& type,
const unsigned int width,
const unsigned int height);
1133 inline unsigned int width()
const;
1139 inline unsigned int height()
const;
1152 inline void setPixelFormat(
const PixelFormat pixelFormat);
1164 inline unsigned int bytesPerDataType()
const;
1171 inline unsigned int channels()
const;
1177 inline uint32_t numberPlanes()
const;
1189 inline unsigned int pixels()
const;
1210 inline bool isPixelFormatCompatible(
const PixelFormat pixelFormat)
const;
1222 inline bool isFrameTypeCompatible(
const FrameType& frameType,
const bool allowDifferentPixelOrigins)
const;
1236 inline bool operator!=(
const FrameType& right)
const;
1250 inline bool isValid()
const;
1264 static inline uint32_t numberPlanes(
const PixelFormat pixelFormat);
1271 template <
typename T>
1272 static constexpr
DataType dataType();
1297 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);
1309 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);
1329 template <DataType tDataType, u
int32_t tChannels, u
int32_t tPlanes = 1u, u
int32_t tW
idthMultiple = 1u, u
int32_t tHeightMultiple = 1u>
1349 template <DataType tDataType>
1350 constexpr
static PixelFormat genericPixelFormat(
const uint32_t channels,
const uint32_t planes = 1u,
const uint32_t widthMultiple = 1u,
const uint32_t heightMultiple = 1u);
1371 template <
typename TDataType, u
int32_t tChannels, u
int32_t tPlanes = 1u, u
int32_t tW
idthMultiple = 1u, u
int32_t tHeightMultiple = 1u>
1392 template <
typename TDataType>
1393 constexpr
static PixelFormat genericPixelFormat(uint32_t channels,
const uint32_t planes = 1u,
const uint32_t widthMultiple = 1u,
const uint32_t heightMultiple = 1u);
1413 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);
1420 static inline bool formatIsGeneric(
const PixelFormat pixelFormat);
1427 static inline bool formatIsPureGeneric(
const PixelFormat pixelFormat);
1434 static unsigned int formatGenericNumberChannels(
const PixelFormat pixelFormat);
1441 static inline unsigned int formatGenericBitsPerPixel(
const PixelFormat pixelFormat);
1525 static inline unsigned int widthMultiple(
const PixelFormat pixelFormat);
1532 static inline unsigned int heightMultiple(
const PixelFormat pixelFormat);
1549 static inline unsigned int planeBytesPerPixel(
const PixelFormat& imagePixelFormat,
const unsigned int planeIndex);
1564 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);
1577 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);
1685 template <
typename T>
1686 static inline bool dataIsAligned(
const void* data);
1703 unsigned int width_ = 0u;
1706 unsigned int height_ = 0u;
1769 CM_USE_KEEP_LAYOUT = 1u << 0u,
1771 CM_COPY_REMOVE_PADDING_LAYOUT = 1u << 1u,
1773 CM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA = 1u << 2u,
1775 CM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA = 1u << 3u,
1784 ACM_USE_KEEP_LAYOUT = CM_USE_KEEP_LAYOUT,
1786 ACM_COPY_REMOVE_PADDING_LAYOUT = CM_COPY_REMOVE_PADDING_LAYOUT,
1788 ACM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA = CM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA,
1790 ACM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA = CM_COPY_KEEP_LAYOUT_COPY_PADDING_DATA,
1793 ACM_USE_OR_COPY = ACM_USE_KEEP_LAYOUT | ACM_COPY_REMOVE_PADDING_LAYOUT,
1795 ACM_USE_OR_COPY_KEEP_LAYOUT = ACM_USE_KEEP_LAYOUT | ACM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA,
1856 Plane(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const unsigned int elementTypeSize,
const unsigned int paddingElements) noexcept;
1867 template <
typename T>
1868 inline Plane(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const T* dataToUse,
const unsigned int paddingElements) noexcept;
1879 template <
typename T>
1880 inline Plane(
const unsigned int width,
const unsigned int height,
const unsigned int channels, T* dataToUse,
const unsigned int paddingElements) noexcept;
1893 template <
typename T>
1894 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;
1906 template <typename T>
1907 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;
1918 inline
unsigned int width() const;
1924 inline
unsigned int height() const;
1930 inline
unsigned int channels() const;
1937 template <typename T>
1938 inline const T* constdata() const;
1945 template <typename T>
1953 inline
unsigned int paddingElements() const;
1961 inline
unsigned int paddingBytes() const;
1967 inline
unsigned int elementTypeSize() const;
1977 inline
unsigned int widthElements() const;
1987 inline
unsigned int widthBytes() const;
1994 inline
unsigned int strideElements() const;
2000 inline
unsigned int strideBytes() const;
2006 inline
unsigned int bytesPerPixel() const;
2018 template <typename T>
2019 inline
bool isCompatibleWithDataType() const;
2026 inline
unsigned int size() const;
2032 inline
bool isContinuous() const;
2038 inline
bool isOwner() const;
2044 inline
bool isReadOnly() const;
2050 inline
bool isValid() const;
2060 bool copy(const
Plane& sourcePlane, const
AdvancedCopyMode advancedCopyMode = ACM_COPY_KEEP_LAYOUT_DO_NOT_COPY_PADDING_DATA, const
bool reallocateIfNecessary = true);
2086 static
void* alignedMemory(const
size_t size, const
size_t alignment,
void*& alignedData);
2100 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;
2111 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;
2122 Plane(const
unsigned int width, const
unsigned int height, const
unsigned int channels, const
unsigned int elementTypeSize,
void* dataToUse, const
unsigned int paddingElements) noexcept;
2135 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;
2147 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;
2156 void copy(const
void* sourceData, const
unsigned int sourceStrideBytes, const
unsigned int sourcePaddingElements, const
bool makeCopyOfPaddingData = false);
2162 inline
unsigned int calculateStrideBytes() const;
2168 unsigned int calculateBytesPerPixel() const;
2173 void* allocatedData_ =
nullptr;
2176 const
void* constData_ =
nullptr;
2179 void* data_ =
nullptr;
2182 unsigned int width_ = 0u;
2185 unsigned int height_ = 0u;
2188 unsigned int channels_ = 0u;
2191 unsigned int elementTypeSize_ = 0u;
2194 unsigned int paddingElements_ = 0u;
2197 unsigned int strideBytes_ = 0u;
2200 unsigned int bytesPerPixel_ = 0u;
2213 template <typename T>
2240 explicit inline PlaneInitializer(
const unsigned int planePaddingElements = 0u);
2249 static std::vector<PlaneInitializer<T>> createPlaneInitializersWithPaddingElements(
const Indices32& paddingElementsPerPlane);
2254 const T* constdata_ =
nullptr;
2263 unsigned int paddingElements_ = 0u;
2270 template <
typename T>
2278 template <
typename T,
unsigned int tChannels>
2348 template <
typename T>
2361 template <
typename T>
2371 template <
typename T>
2384 inline const FrameType& frameType()
const;
2390 inline const Planes& planes()
const;
2403 bool copy(
const Frame& source,
const bool copyTimestamp =
true);
2428 bool copy(
const int targetLeft,
const int targetTop,
const Frame& source,
const bool copyTimestamp =
true);
2451 template <
typename T>
2452 bool updateMemory(
const T* data,
const unsigned int planeIndex = 0u);
2463 template <
typename T>
2464 bool updateMemory(T* data,
const unsigned int planeIndex = 0u);
2473 template <
typename T>
2474 bool updateMemory(
const std::initializer_list<T*>& planeDatas);
2500 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;
2517 bool setValue(
const uint8_t value,
const unsigned int planeIndex = 0u,
const bool skipPaddingData =
true);
2539 template <
typename T, const
unsigned int tPlaneChannels>
2557 template <
typename T>
2558 bool setValue(
const T* planePixelValue,
const size_t planePixelValueSize,
const unsigned int planeIndex = 0u);
2577 template <
typename T>
2578 bool setValue(
const std::initializer_list<
typename Identity<T>::Type>& planePixelValues,
const unsigned int planeIndex = 0u);
2588 template <
typename T, const
unsigned int tPlaneChannels>
2596 inline unsigned int size(
const unsigned int planeIndex = 0u)
const;
2603 inline unsigned int paddingElements(
const unsigned int planeIndex = 0u)
const;
2610 inline unsigned int paddingBytes(
const unsigned int planeIndex = 0u)
const;
2618 inline unsigned int strideElements(
const unsigned int planeIndex = 0u)
const;
2625 inline unsigned int strideBytes(
const unsigned int planeIndex = 0u)
const;
2632 inline unsigned int planeWidth(
const unsigned int planeIndex)
const;
2639 inline unsigned int planeHeight(
const unsigned int planeIndex)
const;
2646 inline unsigned int planeChannels(
const unsigned int planeIndex)
const;
2653 inline unsigned int planeWidthElements(
const unsigned int planeIndex)
const;
2660 inline unsigned int planeWidthBytes(
const unsigned int planeIndex)
const;
2668 inline unsigned int planeBytesPerPixel(
const unsigned int planeIndex)
const;
2675 inline bool isPlaneContinuous(
const unsigned int planeIndex = 0u)
const;
2682 inline bool isPlaneOwner(
const unsigned int planeIndex = 0u)
const;
2688 inline const Timestamp& timestamp()
const;
2694 inline const Timestamp& relativeTimestamp()
const;
2701 inline void setTimestamp(
const Timestamp& timestamp);
2709 inline void setRelativeTimestamp(
const Timestamp& relative);
2724 template <
typename T>
2725 inline T* data(
const unsigned int planeIndex = 0u);
2734 template <
typename T>
2735 inline const T* constdata(
const unsigned int planeIndex = 0u)
const;
2752 template <
typename T>
2753 inline T* row(
const unsigned int y,
const unsigned int planeIndex = 0u);
2770 template <
typename T>
2771 inline const T* constrow(
const unsigned int y,
const unsigned int planeIndex = 0u)
const;
2825 template <
typename T>
2826 inline T* pixel(
const unsigned int x,
const unsigned int y,
const unsigned int planeIndex = 0u);
2850 template <
typename T>
2851 inline const T* constpixel(
const unsigned int x,
const unsigned int y,
const unsigned int planeIndex = 0u)
const;
2857 inline bool isContinuous()
const;
2866 inline bool isOwner()
const;
2875 inline bool isReadOnly()
const;
2881 inline bool hasAlphaChannel()
const;
2889 template <
typename T>
2890 bool hasTransparentPixel(
const T opaque)
const;
2897 inline bool isValid()
const;
2913 explicit inline operator bool()
const;
2943 static bool strideBytes2paddingElements(
const PixelFormat& pixelFormat,
const unsigned int imageWidth,
const unsigned int planeStrideBytes,
unsigned int& planePaddingElements,
const unsigned int planeIndex = 0u);
3007 template <
typename T>
3019 template <
typename T>
3035 pixelFormat_(pixelFormat)
3050 ocean_assert(
false &&
"The configuration of this frame type is invalid - this should never happen!");
3065 pixelFormat_(type.pixelFormat_),
3066 pixelOrigin_(type.pixelOrigin_)
3072 ocean_assert(
false &&
"The configuration of this frame type is invalid - this should never happen!");
3085 width_(type.width_),
3086 height_(type.height_),
3087 pixelFormat_(pixelFormat),
3088 pixelOrigin_(type.pixelOrigin_)
3094 width_(type.width_),
3095 height_(type.height_),
3096 pixelFormat_(type.pixelFormat_),
3097 pixelOrigin_(pixelOrigin)
3103 width_(type.width_),
3104 height_(type.height_),
3105 pixelFormat_(pixelFormat),
3106 pixelOrigin_(pixelOrigin)
3178 return !(*
this == right);
3199 static_assert(
sizeof(
char) == 1,
"Invalid data type!");
3207 static_assert(
sizeof(
signed char) == 1,
"Invalid data type!");
3214 static_assert(
sizeof(
unsigned char) == 1,
"Invalid data type!");
3221 static_assert(
sizeof(
unsigned short) == 2,
"Invalid data type!");
3228 static_assert(
sizeof(
short) == 2,
"Invalid data type!");
3235 static_assert(
sizeof(
unsigned int) == 4,
"Invalid data type!");
3242 static_assert(
sizeof(
int) == 4,
"Invalid data type!");
3249 static_assert(
sizeof(
unsigned long) == 4 ||
sizeof(
unsigned long) == 8,
"Invalid data type!");
3257 static_assert(
sizeof(
unsigned long) == 4 ||
sizeof(
unsigned long) == 8,
"Invalid data type!");
3265 static_assert(
sizeof(
unsigned long long) == 8,
"Invalid data type!");
3272 static_assert(
sizeof(
long long) == 8,
"Invalid data type!");
3279 static_assert(
sizeof(
float) == 4,
"Invalid data type!");
3286 static_assert(
sizeof(
double) == 8,
"Invalid data type!");
3290 template <
typename T>
3312 ocean_assert(planes >= 1u && planes <= 255u);
3319 template <FrameType::DataType tDataType, u
int32_t tChannels, u
int32_t tPlanes, u
int32_t tW
idthMultiple, u
int32_t tHeightMultiple>
3322 static_assert(uint8_t(tDataType) > uint8_t(
DT_UNDEFINED) && uint8_t(tDataType) <
DT_END,
"Invalid data type!");
3323 static_assert(tChannels >= 1u && tChannels < 31u,
"Invalid channel number!");
3324 static_assert(tPlanes >= 1u && tPlanes <= 255u,
"Invalid plane number!");
3325 static_assert(tWidthMultiple >= 1u && tWidthMultiple <= 255u,
"Invalid width-multiple!");
3326 static_assert(tHeightMultiple >= 1u && tHeightMultiple <= 255u,
"Invalid height-multiple!");
3328 return genericPixelFormat(tDataType, tChannels, tPlanes, tWidthMultiple, tHeightMultiple);
3331 template <FrameType::DataType tDataType>
3334 static_assert(uint8_t(tDataType) > uint8_t(
DT_UNDEFINED) && uint8_t(tDataType) <
DT_END,
"Invalid data type!");
3339 template <
typename TDataType, u
int32_t tChannels, u
int32_t tPlanes, u
int32_t tW
idthMultiple, u
int32_t tHeightMultiple>
3342 static_assert(tChannels >= 1u && tChannels < 31u,
"Invalid channel number!");
3343 static_assert(tPlanes >= 1u && tPlanes <= 255u,
"Invalid plane number!");
3344 static_assert(tWidthMultiple >= 1u && tWidthMultiple <= 255u,
"Invalid width-multiple!");
3345 static_assert(tHeightMultiple >= 1u && tHeightMultiple <= 255u,
"Invalid height-multiple!");
3347 constexpr
DataType pixelFormatDataType = dataType<TDataType>();
3348 static_assert(uint8_t(pixelFormatDataType) > uint8_t(
DT_UNDEFINED) && uint8_t(pixelFormatDataType) <
DT_END,
"Invalid data type!");
3350 return genericPixelFormat(pixelFormatDataType, tChannels, tPlanes, tWidthMultiple, tHeightMultiple);
3353 template <
typename TDataType>
3356 constexpr
DataType pixelFormatDataType = dataType<TDataType>();
3357 static_assert(uint8_t(pixelFormatDataType) > uint8_t(
DT_UNDEFINED) && uint8_t(pixelFormatDataType) <
DT_END,
"Invalid data type!");
3360 ocean_assert(planes >= 1u && planes <= 255u);
3369 static_assert(std::is_same<std::underlying_type<PixelFormat>::type, uint64_t>::value,
"Invalid pixel format data type!");
3386 static_assert(std::is_same<std::underlying_type<PixelFormat>::type, uint64_t>::value,
"Invalid pixel format data type!");
3403 unsigned int planeWidthDummy;
3404 unsigned int planeHeightDummy;
3408 unsigned int planeWidthElementsMultiple;
3409 unsigned int planeHeightElementsMultiple;
3413 ocean_assert(
planeChannels >= 1u && planeWidthElementsMultiple >= 1u && planeHeightElementsMultiple >= 1u);
3415 if (planeWidthElementsMultiple != 1u || planeHeightElementsMultiple != 1u)
3425 ocean_assert(
false &&
"Invalid input!");
3430 inline bool FrameType::planeLayout(
const FrameType& frameType,
const unsigned int planeIndex,
unsigned int& planeWidth,
unsigned int& planeHeight,
unsigned int& planeChannels,
unsigned int* planeWidthElementsMultiple,
unsigned int* planeHeightElementsMultiple)
3432 ocean_assert(frameType.
isValid());
3437 template <
typename T>
3440 ocean_assert(data !=
nullptr);
3441 return size_t(data) %
sizeof(T) ==
size_t(0);
3446 *
this = std::move(plane);
3449 template <
typename T>
3450 inline Frame::Plane::Plane(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const T* dataToUse,
const unsigned int paddingElements) noexcept :
3451 Plane(width, height, channels,
sizeof(T), (
const void*)dataToUse, paddingElements)
3456 template <
typename T>
3457 inline Frame::Plane::Plane(
const unsigned int width,
const unsigned int height,
const unsigned int channels, T* dataToUse,
const unsigned int paddingElements) noexcept :
3458 Plane(width, height, channels,
sizeof(T), (
void*)dataToUse, paddingElements)
3463 template <
typename T>
3464 inline Frame::Plane::Plane(
const T* sourceDataToCopy,
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const unsigned int targetPaddingElements,
const unsigned int sourcePaddingElements,
const bool makeCopyOfPaddingData) noexcept :
3465 Plane(width, height, channels,
sizeof(T), (
const void*)sourceDataToCopy, targetPaddingElements, sourcePaddingElements, makeCopyOfPaddingData)
3470 template <
typename T>
3471 inline Frame::Plane::Plane(
const T* sourceDataToCopy,
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const unsigned int sourcePaddingElements,
const CopyMode copyMode) noexcept :
3472 Plane(width, height, channels,
sizeof(T), (
const void*)sourceDataToCopy, sourcePaddingElements, copyMode)
3477 inline Frame::Plane::Plane(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const unsigned int elementTypeSize,
const void* constData,
void* data,
const unsigned int paddingElements) noexcept :
3478 allocatedData_(
nullptr),
3479 constData_(constData),
3483 channels_(channels),
3484 elementTypeSize_(elementTypeSize),
3485 paddingElements_(paddingElements)
3487 strideBytes_ = calculateStrideBytes();
3488 bytesPerPixel_ = calculateBytesPerPixel();
3511 template <
typename T>
3514 return reinterpret_cast<const T*
>(constData_);
3517 template <
typename T>
3520 return reinterpret_cast<T*
>(data_);
3525 return paddingElements_;
3530 return paddingElements_ * elementTypeSize_;
3535 return elementTypeSize_;
3540 return width_ * channels_;
3545 return widthElements() * elementTypeSize_;
3550 return width_ * channels_ + paddingElements_;
3555 ocean_assert(
width_ == 0u || strideBytes_ != 0u);
3556 ocean_assert(strideBytes_ == calculateStrideBytes());
3558 return strideBytes_;
3563 ocean_assert(bytesPerPixel_ == calculateBytesPerPixel());
3565 return bytesPerPixel_;
3568 template <
typename T>
3571 return elementTypeSize_ ==
sizeof(T);
3581 return paddingElements_ == 0u;
3586 return allocatedData_ !=
nullptr;
3591 return data_ ==
nullptr;
3604 template <
typename T>
3608 copyMode_(copyMode),
3609 paddingElements_(dataPaddingElements)
3614 template <
typename T>
3616 constdata_(nullptr),
3618 copyMode_(copyMode),
3619 paddingElements_(dataPaddingElements)
3624 template <
typename T>
3626 constdata_(nullptr),
3629 paddingElements_(planePaddingElements)
3634 template <
typename T>
3638 planeInitializers.reserve(paddingElementsPerPlane.size());
3645 return planeInitializers;
3658 *
this = std::move(frame);
3660 ocean_assert(planes_.size() >= 1);
3661 ocean_assert(frame.planes_.size() == 1);
3665 Frame(frameType,
PlaneInitializer<void>::createPlaneInitializersWithPaddingElements(planePaddingElements), timestamp)
3667 ocean_assert(
frameType.
numberPlanes() == planePaddingElements.size() || planePaddingElements.empty());
3688 template <
typename T>
3690 Frame(frameType, (const void*)(data), copyMode, paddingElements, timestamp)
3697 ocean_assert(debugTemplateDataType ==
FrameType::DT_UNDEFINED || debugTemplateDataType == debugFrameTypeDataType);
3713 template <
typename T>
3715 Frame(frameType, (void*)(data), copyMode, paddingElements, timestamp)
3722 ocean_assert(debugTemplateDataType ==
FrameType::DT_UNDEFINED || debugTemplateDataType == debugFrameTypeDataType);
3728 template <
typename T>
3730 Frame(frameType, (const
PlaneInitializer<void>*)planeInitializers.data(), planeInitializers.size(), timestamp)
3737 ocean_assert(debugTemplateDataType ==
FrameType::DT_UNDEFINED || debugTemplateDataType == debugFrameTypeDataType);
3753 template <
typename T>
3756 ocean_assert(
data !=
nullptr);
3757 if (
data !=
nullptr)
3764 if constexpr (!std::is_void_v<T>)
3773 plane.
data_ =
nullptr;
3783 template <
typename T>
3786 ocean_assert(
data !=
nullptr);
3787 if (
data !=
nullptr)
3794 if constexpr (!std::is_void_v<T>)
3813 template <
typename T>
3816 ocean_assert(planeDatas.size() != 0);
3817 ocean_assert(planeDatas.size() <=
planes_.
size());
3819 if (planeDatas.size() == 0 || planeDatas.size() >
planes_.
size())
3824 for (
unsigned int planeIndex = 0u; planeIndex < planeDatas.size(); ++planeIndex)
3826 if (!
updateMemory(planeDatas.begin()[planeIndex], planeIndex))
3835 template <
typename T, const
unsigned int tPlaneChannels>
3838 static_assert(!std::is_void_v<T>,
"Value access/assignment cannot be performed with void types.");
3845 ocean_assert(plane.
isValid());
3849 ocean_assert(
false &&
"The specified data type must fit to the frame's data type!");
3853 if (plane.
channels() != tPlaneChannels)
3855 ocean_assert(
false &&
"The specified number of channels does not fit with the plane's actual channels!");
3868 for (
unsigned int n = 0u; n < plane.
width() * plane.
height(); ++n)
3870 data[n] = planePixelValue;
3875 const unsigned int planeStrideBytes = plane.
strideBytes();
3877 for (
unsigned int y = 0u; y < plane.
height(); ++y)
3881 for (
unsigned int x = 0u; x < plane.
width(); ++x)
3883 data[x] = planePixelValue;
3891 template <
typename T, const
unsigned int tPlaneChannels>
3894 static_assert(!std::is_void_v<T>,
"Value access/comparison cannot be performed with void types.");
3901 ocean_assert(plane.
isValid());
3905 ocean_assert(
false &&
"The specified data type must fit to the frame's data type!");
3909 if (plane.
channels() != tPlaneChannels)
3911 ocean_assert(
false &&
"The specified number of channels does not fit with the plane's actual channels!");
3915 const unsigned int planeStrideBytes = plane.
strideBytes();
3917 for (
unsigned int y = 0u; y < plane.
height(); ++y)
3921 for (
unsigned int x = 0u; x < plane.
width(); ++x)
3923 if (
data[x] == planePixelValue)
3933 template <
typename T>
3934 bool Frame::setValue(
const T* planePixelValue,
const size_t planePixelValueSize,
const unsigned int planeIndex)
3936 static_assert(!std::is_void_v<T>,
"Value access/assignment cannot be performed with void types.");
3938 ocean_assert(planePixelValue !=
nullptr);
3940 ocean_assert(
planes_[planeIndex].elementTypeSize() ==
sizeof(T));
3943 switch (planePixelValueSize)
3952 return setValue<T, 1u>(value, planeIndex);
3963 return setValue<T, 2u>(value, planeIndex);
3975 return setValue<T, 3u>(value, planeIndex);
3988 return setValue<T, 4u>(value, planeIndex);
3992 ocean_assert(
false &&
"The number of channels is not supported");
3996 template <
typename T>
3999 return setValue<T>(planePixelValues.begin(), planePixelValues.size(), planeIndex);
4015 return planes_[planeIndex].paddingElements();
4023 return planes_[planeIndex].paddingBytes();
4031 return planes_[planeIndex].strideElements();
4039 return planes_[planeIndex].strideBytes();
4047 return planes_[planeIndex].width();
4055 return planes_[planeIndex].height();
4063 return planes_[planeIndex].channels();
4071 return planes_[planeIndex].widthElements();
4079 return planes_[planeIndex].widthBytes();
4095 return planes_[planeIndex].isContinuous();
4103 return planes_[planeIndex].isOwner();
4126 template <
typename T>
4132 return planes_[planeIndex].data<T>();
4135 template <
typename T>
4141 return planes_[planeIndex].constdata<T>();
4144 template <
typename T>
4145 inline T*
Frame::row(
const unsigned int y,
const unsigned int planeIndex)
4148 ocean_assert(y <
height());
4154 ocean_assert(plane.
isValid());
4156 ocean_assert(y < plane.
height());
4157 return reinterpret_cast<T*
>(plane.
data<uint8_t>() + y * plane.
strideBytes());
4160 template <
typename T>
4161 inline const T*
Frame::constrow(
const unsigned int y,
const unsigned int planeIndex)
const
4164 ocean_assert(y <
height());
4170 ocean_assert(plane.
isValid());
4172 ocean_assert(y < plane.
height());
4176 template <
typename T>
4177 inline T*
Frame::pixel(
const unsigned int x,
const unsigned int y,
const unsigned int planeIndex)
4187 ocean_assert(plane.
isValid());
4189 if constexpr (!std::is_void_v<T>)
4213 ocean_assert(y < plane.
height());
4214 return reinterpret_cast<T*
>(plane.
data<uint8_t>() + y * plane.
strideBytes() + xBytes);
4217 template <
typename T>
4218 inline const T*
Frame::constpixel(
const unsigned int x,
const unsigned int y,
const unsigned int planeIndex)
const
4228 ocean_assert(plane.
isValid());
4230 if constexpr (!std::is_void_v<T>)
4240 ocean_assert(y < plane.
height());
4241 return reinterpret_cast<const T*
>(plane.
constdata<uint8_t>() + y * plane.
strideBytes() + xBytes);
4250 if (!plane.isContinuous())
4265 if (!plane.isOwner())
4280 if (plane.isReadOnly())
4306 if (
dataType() != dataType<uint8_t>())
4308 ocean_assert(
false &&
"Data type does not fit with the frame's data type!");
4314 for (
unsigned int y = 0u; y <
height(); ++y)
4316 const uint8_t*
row = constrow<uint8_t>(y) + 1;
4318 for (
unsigned int x = 0u; x <
width(); ++x)
4335 for (
unsigned int y = 0u; y <
height(); ++y)
4337 const uint8_t*
row = constrow<uint8_t>(y) + offset;
4339 for (
unsigned int x = 0u; x <
width(); ++x)
4364 if (
dataType() != dataType<uint16_t>())
4366 ocean_assert(
false &&
"Data type does not fit with the frame's data type!");
4372 for (
unsigned int y = 0u; y <
height(); ++y)
4374 const uint16_t*
row = constrow<uint16_t>(y) + 3;
4376 for (
unsigned int x = 0u; x <
width(); ++x)
4391 for (
unsigned int y = 0u; y <
height(); ++y)
4393 const uint16_t*
row = constrow<uint16_t>(y);
4395 for (
unsigned int x = 0u; x <
width(); ++x)
4397 if ((*
row & opaque) != opaque)
4410 template <
typename T>
4426 size_t debugValidPlanes = 0;
4430 if (plane.isValid())
4438 ocean_assert(debugIsValid == frameTypeIsValid);
4442 return frameTypeIsValid;
4445 inline Frame::operator bool()
const
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:1825
unsigned int width() const
Returns the width of the plane in pixel.
Definition: Frame.h:3496
bool isCompatibleWithDataType() const
Returns whether this plane is compatible with a given element data type.
Definition: Frame.h:3569
unsigned int paddingElements() const
Returns the number of padding elements at the end of each plane row, in elements.
Definition: Frame.h:3523
void * allocatedData_
The pointer to the memory which this plane has allocated, this pointer is pointing to the memory whic...
Definition: Frame.h:2173
unsigned int paddingBytes() const
Returns the number of padding bytes at the end of each plane row, in bytes.
Definition: Frame.h:3528
unsigned int elementTypeSize() const
Returns the size of each element of this plane.
Definition: Frame.h:3533
bool isOwner() const
Returns whether this plane is the owner of the memory.
Definition: Frame.h:3584
unsigned int calculateStrideBytes() const
Calculates the number of bytes between the start positions of two consecutive rows,...
Definition: Frame.h:3599
void * data_
The pointer to the writable memory of the plane (not the pointer to the allocated memory),...
Definition: Frame.h:2179
unsigned int strideBytes() const
Returns the number of bytes between the start positions of two consecutive rows, in bytes.
Definition: Frame.h:3553
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:3579
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:3512
bool isValid() const
Returns whether this plane holds valid data.
Definition: Frame.h:3594
T * data()
Returns the writable memory pointer to this plane with a specific data type compatible with elementTy...
Definition: Frame.h:3518
bool isReadOnly() const
Returns whether this plane holds read-only memory.
Definition: Frame.h:3589
unsigned int size() const
Returns the number of bytes necessary for the entire plane data including optional padding elements a...
Definition: Frame.h:3574
unsigned int widthBytes() const
Returns the width of the plane in bytes, the width does not contain optional padding elements.
Definition: Frame.h:3543
~Plane()
Destructs a Plane object.
Definition: Frame.h:3491
Plane()=default
Creates a new invalid plane.
unsigned int channels() const
Returns the channels of the plane.
Definition: Frame.h:3506
const void * constData_
The pointer to the read-only memory of the plane (not the pointer to the allocated memory),...
Definition: Frame.h:2176
unsigned int bytesPerPixel() const
Returns the number of bytes which is used for each pixel.
Definition: Frame.h:3561
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:3548
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:3501
unsigned int paddingElements_
The number of padding elements at the end of each plane row, in elements, with range [0,...
Definition: Frame.h:2194
unsigned int widthElements() const
Returns the width of the plane in elements, the width does not contain optional padding elements.
Definition: Frame.h:3538
This class implements a helper class which can be used to initialize a multi-plane frame in the const...
Definition: Frame.h:2215
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:3605
static std::vector< PlaneInitializer< T > > createPlaneInitializersWithPaddingElements(const Indices32 &paddingElementsPerPlane)
Creates plane initializer objects with padding elements only.
Definition: Frame.h:3635
This class implements Ocean's image class.
Definition: Frame.h:1760
bool copy(const int targetLeft, const int targetTop, const Frame &source, const bool copyTimestamp=true)
Copies the entire image content of a source frame into this frame.
static bool strideBytes2paddingElements(const PixelFormat &pixelFormat, const unsigned int imageWidth, const unsigned int planeStrideBytes, unsigned int &planePaddingElements, const unsigned int planeIndex=0u)
Determines the number of padding elements at the end of a row of a plane for which the pixel format,...
Frame & operator=(Frame &&right) noexcept
Move operator.
Frame(const FrameType &frameType, const CopyMode copyMode)=delete
Deleted constructor to prevent misuse.
typename Ocean::DataType< T, tChannels >::Type PixelType
Definition of a data type storing all channel values of one pixel in an array.
Definition: Frame.h:2279
Timestamp relativeTimestamp_
Relative timestamp of this frame.
Definition: Frame.h:3031
bool isContinuous() const
Returns whether all planes of this frame have continuous memory and thus do not contain any padding a...
Definition: Frame.h:4244
bool hasAlphaChannel() const
Returns whether the frame's pixel format contains an alpha channel.
Definition: Frame.h:4289
Frame(const FrameType &frameType, const PlaneInitializer< void > *planeInitializers, size_t sizePlaneInitializers, const Timestamp ×tamp=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:4034
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:3028
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:4026
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:4145
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:3754
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:4136
void setRelativeTimestamp(const Timestamp &relative)
Sets the relative timestamp of this frame.
Definition: Frame.h:4121
const FrameType & frameType() const
Returns the frame type of this frame.
Definition: Frame.h:3743
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:4127
bool isValid() const
Returns whether this frame is valid.
Definition: Frame.h:4416
Frame(const FrameType &frameType, const T *data, const bool copyData, const unsigned int paddingElements=0u, const Timestamp ×tamp=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:4177
void setTimestamp(const Timestamp ×tamp)
Sets the timestamp of this frame.
Definition: Frame.h:4116
bool isReadOnly() const
Returns true, if the frame allows only read access (using constdata()).
Definition: Frame.h:4274
Frame & operator=(const Frame &right) noexcept
Assign operator.
Frame(const Frame &frame, const Timestamp ×tamp)=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 ×tamp=Timestamp(false), bool *reallocated=nullptr)
Sets a new frame type for this frame.
const Timestamp & timestamp() const
Returns the timestamp of this frame.
Definition: Frame.h:4106
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:4082
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:4066
std::vector< PlaneInitializer< T > > PlaneInitializers
Definition of a vector holding plane initializer objects.
Definition: Frame.h:2271
const Timestamp & relativeTimestamp() const
Returns the relative timestamp of this frame.
Definition: Frame.h:4111
const Planes & planes() const
Returns the individual planes of this frame.
Definition: Frame.h:3748
bool isOwner() const
Returns whether the frame is the owner of the internal frame data.
Definition: Frame.h:4259
CopyMode
Definition of individual copy modes.
Definition: Frame.h:1767
@ CM_USE_KEEP_LAYOUT
The source memory is used only, no copy is created, the padding layout is preserved.
Definition: Frame.h:1769
unsigned int planeChannels(const unsigned int planeIndex) const
Returns the channels of a plane of this frame.
Definition: Frame.h:4058
unsigned int planeWidth(const unsigned int planeIndex) const
Returns the width of a plane of this frame.
Definition: Frame.h:4042
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:3648
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:4218
Frame(const FrameType &frameType, T *data, const bool copyData, const unsigned int paddingElements=0u, const Timestamp ×tamp=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 ×tamp)=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:1782
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:4090
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:3892
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:4098
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:4018
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:4161
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:4074
bool hasTransparentPixel(const T opaque) const
Returns whether the frame holds at least one pixel with an non opaque alpha value.
Definition: Frame.h:4411
unsigned int planeHeight(const unsigned int planeIndex) const
Returns the height of a plane of this frame.
Definition: Frame.h:4050
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:4002
Planes planes_
The individual memory planes of this frame.
Definition: Frame.h:3025
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:4010
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:3391
static const FrameType::DataTypes & definedDataTypes()
Returns all defined data types.
static PixelFormat translatePixelFormat(const std::string &pixelFormat)
Translates a string containing a pixel format into the pixel format.
static PixelFormat genericPixelFormat(const unsigned int bitsPerPixelChannel, const uint32_t channels, const uint32_t planes=1u, const uint32_t widthMultiple=1u, const uint32_t heightMultiple=1u)
Returns a specific generic pixel format with specified bit per pixel per channel, channel number,...
static unsigned int bytesPerDataType(const DataType dataType)
Returns the number of bytes which are necessary to store a specified data type.
bool operator==(const FrameType &right) const
Returns whether two frame types are equal.
unsigned int pixels() const
Returns the number of pixels for the frame.
Definition: Frame.h:3161
FrameType()=default
Creates a new frame type with invalid parameters.
static unsigned int formatBitsPerPixelGreenChannel(const PixelFormat pixelFormat)
Returns the number of bits of one pixel for the green channel.
static constexpr uint32_t pixelFormatBitOffsetChannels
The number of bits the channel value is shifted within the PixelFormat value.
Definition: Frame.h:74
static const FrameType::PixelFormats & definedPixelFormats()
Returns all defined pixel formats.
static PixelFormat findPixelFormat(const DataType dataType, const unsigned int channels)
Returns a best fitting pixel format having the given number of bits per pixels.
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition: Frame.h:183
@ FORMAT_YA16
Pixel format with byte order YA and 16 bits per pixel.
Definition: Frame.h:649
@ FORMAT_BGRA4444
Pixel format with entirely 16 bits per pixel, 4 bits for each channel.
Definition: Frame.h:282
@ FORMAT_UNDEFINED
Undefined pixel format.
Definition: Frame.h:187
@ FORMAT_RGBA64
Pixel format with byte order RGBA and 64 bits per pixel, with 16 bit per component.
Definition: Frame.h:675
@ FORMAT_RGBA4444
Pixel format with entirely 16 bits per pixel, 4 bits for each channel.
Definition: Frame.h:395
@ FORMAT_ARGB32
Pixel format with byte order ARGB and 32 bits per pixel.
Definition: Frame.h:213
@ FORMAT_ABGR32
Pixel format with byte order ABGR and 32 bits per pixel.
Definition: Frame.h:200
@ FORMAT_RGBA32
Pixel format with byte order RGBA and 32 bits per pixel.
Definition: Frame.h:382
@ FORMAT_YUVA32
Pixel format with byte order YUVA and 32 bits per pixel.
Definition: Frame.h:472
@ FORMAT_BGRA32
Pixel format with byte order BGRA and 32 bits per pixel.
Definition: Frame.h:277
unsigned int width() const
Returns the width of the frame format in pixel.
Definition: Frame.h:3111
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:3156
std::vector< PixelFormat > PixelFormats
Definition of a vector holding pixel formats.
Definition: Frame.h:1008
constexpr static PixelFormat genericPixelFormat(const uint32_t channels, const uint32_t planes=1u, const uint32_t widthMultiple=1u, const uint32_t heightMultiple=1u)
Returns a specific generic pixel format with a specified data type and channel number.
static DataType translateDataType(const std::string &dataType)
Translates a string containing a data type into the data type.
unsigned int frameTypeSize() const
Returns the number of bytes necessary for the frame type, without padding at the end of frame rows.
static unsigned int formatGenericBitsPerPixel(const PixelFormat pixelFormat)
Returns the number of bits of one pixel for a given generic pixel format.
Definition: Frame.h:3303
unsigned int height_
Frame height in pixel, with range [0, infinity)
Definition: Frame.h:1706
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:3438
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:3176
static bool planeLayout(const PixelFormat imagePixelFormat, const unsigned int imageWidth, const unsigned int imageHeight, const unsigned int planeIndex, unsigned int &planeWidth, unsigned int &planeHeight, unsigned int &planeChannels, unsigned int *planeWidthElementsMultiple=nullptr, unsigned int *planeHeightElementsMultiple=nullptr)
Returns the plane layout of a given pixel format.
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition: Frame.h:3151
PixelOrigin pixelOrigin_
The origin of the pixel data, either the upper left corner or the bottom left corner (if valid).
Definition: Frame.h:1712
static std::string translatePixelFormat(const PixelFormat pixelFormat)
Translates a pixel format value into a string containing the pixel format.
static PixelFormat formatRemoveAlphaChannel(const PixelFormat pixelFormat)
Removes an alpha channel from a given pixel format.
static bool arePixelFormatsCompatible(const PixelFormat pixelFormatA, const PixelFormat pixelFormatB)
Returns whether two given pixel formats are compatible.
static unsigned int formatBitsPerPixelAlphaChannel(const PixelFormat pixelFormat)
Returns the number of bits of one pixel for the alpha channel.
MultipleValue
Definition of a protected helper enum that simplifies to read the definition of a predefined pixel fo...
Definition: Frame.h:141
constexpr static PixelFormat genericPixelFormat()
Returns a specific generic pixel format with a specified data type and channel number.
static bool areFrameTypesCompatible(const FrameType &frameTypeA, const FrameType &frameTypeB, const bool allowDifferentPixelOrigins)
Returns whether two given frame types are compatible.
static bool formatHasAlphaChannel(const PixelFormat pixelFormat, bool *isLastChannel=nullptr)
Returns whether a given pixel format holds an alpha channel.
static unsigned int heightMultiple(const PixelFormat pixelFormat)
Returns the number of pixels the height of a frame must be a multiple of.
Definition: Frame.h:3396
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition: Frame.h:3121
unsigned int bytesPerDataType() const
Returns the number of bytes which are necessary to store the data type of this frame.
Definition: Frame.h:3136
constexpr static PixelFormat genericPixelFormat(uint32_t channels, const uint32_t planes=1u, const uint32_t widthMultiple=1u, const uint32_t heightMultiple=1u)
Returns a specific generic pixel format with a specified data type and channel number.
PixelOrigin
Defines different types of frame origin positions.
Definition: Frame.h:1014
@ ORIGIN_INVALID
Invalid origin type.
Definition: Frame.h:1016
@ ORIGIN_UPPER_LEFT
The first pixel lies in the upper left corner, the last pixel in the lower right corner.
Definition: Frame.h:1018
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:3401
unsigned int height() const
Returns the height of the frame in pixel.
Definition: Frame.h:3116
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:1703
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:3384
bool isValid() const
Returns whether this frame type is valid.
Definition: Frame.h:3181
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:3166
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition: Frame.h:3141
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:1709
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:3131
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:3367
static unsigned int planeChannels(const PixelFormat &imagePixelFormat, const unsigned int planeIndex)
Returns the channels of a plane for a pixel format.
bool isFrameTypeCompatible(const FrameType &frameType, const bool allowDifferentPixelOrigins) const
Returns whether this frame type is compatible with a given frame type.
Definition: Frame.h:3171
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:3191
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:3374
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:3126
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:1723
std::vector< FrameRef > FrameRefs
Definition of a vector holding frame references.
Definition: Frame.h:1735
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