Ocean
Loading...
Searching...
No Matches
ImageBmp.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_MEDIA_SPECIAL_IMAGE_BMP_H
9#define META_OCEAN_MEDIA_SPECIAL_IMAGE_BMP_H
10
12
13#include "ocean/base/Frame.h"
14
15namespace Ocean
16{
17
18namespace Media
19{
20
21namespace Special
22{
23
24/**
25 * This class implements read and write functions for BMP images.
26 * @ingroup mediaspecial
27 */
28class OCEAN_MEDIA_SPECIAL_EXPORT ImageBmp
29{
30 protected:
31
32 /**
33 * Definition of the Windows Bitmap file header.
34 */
35 struct FileHeader;
36
37 /**
38 * Definition of a Windows Bitmap data header.
39 */
40 struct DataHeader;
41
42 public:
43
44 /**
45 * Decodes a BMP image from a given binary buffer.
46 * @param buffer The buffer from which the image will be loaded, must be valid
47 * @param size The size of the given buffer in bytes, with range [1, infinity)
48 * @return The frame containing the image information, an invalid frame if the image could not be loaded
49 */
50 static Frame decodeImage(const void* buffer, const size_t size);
51
52 /**
53 * Encodes a given frame as BMP image to a resulting buffer.
54 * @param frame The frame to be written, must be valid
55 * @param buffer The resulting buffer storing the binary information of the BMP image
56 * @param allowConversion True, to allow an internal conversion of the frame if BMP does not support the given frame type; False, to prevent a conversion and to stop creating the buffer
57 * @param hasBeenConverted Optional resulting statement whether the frame had to be converted to a different pixel format before it could be written; True, if so; False, if not
58 * @return True, if succeeded; False, if the frame could not be written as BMP image e.g., if the frame contained an alpha channel
59 */
60 static bool encodeImage(const Frame& frame, std::vector<uint8_t>& buffer, const bool allowConversion = true, bool* hasBeenConverted = nullptr);
61
62 /**
63 * Returns whether a given pixel format is supported natively.
64 * @param pixelFormat The pixel format to be checked
65 * @return True, if so; False, if a conversion will be necessary
66 */
67 static inline bool isPixelFormatSupported(const FrameType::PixelFormat pixelFormat);
68
69 /**
70 * Returns whether a given pixel origin is supported natively.
71 * @param pixelOrigin The pixel origin to be checked
72 * @return True, if so; False, if a conversion will be necessary
73 */
74 static inline bool isPixelOriginSupported(const FrameType::PixelOrigin pixelOrigin);
75
76 /**
77 * Returns whether a given pixel format together with a given pixel origin is supported natively.
78 * @param pixelFormat The pixel format to be checked
79 * @param pixelOrigin The pixel origin to be checked
80 * @return True, if so; False, if a conversion will be necessary
81 */
82 static inline bool isFrameTypeSupported(const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin);
83};
84
86{
87 return pixelFormat == FrameType::FORMAT_BGR24;
88}
89
91{
92 return pixelOrigin == FrameType::ORIGIN_UPPER_LEFT || pixelOrigin == FrameType::ORIGIN_LOWER_LEFT;
93}
94
95inline bool ImageBmp::isFrameTypeSupported(const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin)
96{
97 return isPixelFormatSupported(pixelFormat) && isPixelOriginSupported(pixelOrigin);
98}
99
100}
101
102}
103
104}
105
106#endif // META_OCEAN_MEDIA_SPECIAL_IMAGE_BMP_H
This class implements Ocean's image class.
Definition Frame.h:1808
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition Frame.h:183
@ FORMAT_BGR24
Pixel format with byte order BGR and 24 bits per pixel.
Definition Frame.h:226
PixelOrigin
Defines different types of frame origin positions.
Definition Frame.h:1046
@ ORIGIN_UPPER_LEFT
The first pixel lies in the upper left corner, the last pixel in the lower right corner.
Definition Frame.h:1050
@ ORIGIN_LOWER_LEFT
The first pixel lies in the lower left corner, the last pixel in the upper right corner.
Definition Frame.h:1052
This class implements read and write functions for BMP images.
Definition ImageBmp.h:29
static bool encodeImage(const Frame &frame, std::vector< uint8_t > &buffer, const bool allowConversion=true, bool *hasBeenConverted=nullptr)
Encodes a given frame as BMP image to a resulting buffer.
static bool isFrameTypeSupported(const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin)
Returns whether a given pixel format together with a given pixel origin is supported natively.
Definition ImageBmp.h:95
static bool isPixelOriginSupported(const FrameType::PixelOrigin pixelOrigin)
Returns whether a given pixel origin is supported natively.
Definition ImageBmp.h:90
static Frame decodeImage(const void *buffer, const size_t size)
Decodes a BMP image from a given binary buffer.
static bool isPixelFormatSupported(const FrameType::PixelFormat pixelFormat)
Returns whether a given pixel format is supported natively.
Definition ImageBmp.h:85
The namespace covering the entire Ocean framework.
Definition Accessor.h:15