Ocean
Loading...
Searching...
No Matches
media/imageio/Image.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_IMAGEIO_IMAGE_H
9#define META_OCEAN_MEDIA_IMAGEIO_IMAGE_H
10
12
13#include "ocean/base/Frame.h"
14
15#include "ocean/media/Image.h"
16
17namespace Ocean
18{
19
20namespace Media
21{
22
23namespace ImageIO
24{
25
26/**
27 * This class implements read, write, decocde, and encode functions for all file formats supported by the ImageIO media library.
28 * This class is not derived from Media::Image as this class provides simple static functions to handle images.<br>
29 * Instead, IIOImage is derived from Media::Image.
30 *
31 * ImageIO supports for the following image types: bmp, gif, jpg, png, tiff.
32 * The following pixel formats are supported by the individual image types:
33 * <pre>
34 * ImageType: Pixel format: Pixel origin: Supports compression quality:
35 * bmp FORMAT_RGB24 ORIGIN_UPPER_LEFT no
36 *
37 * gif FORMAT_RGB24 ORIGIN_UPPER_LEFT no
38 *
39 * jpg FORMAT_Y8 ORIGIN_UPPER_LEFT yes
40 * jpg FORMAT_RGB24 ORIGIN_UPPER_LEFT yes
41 *
42 * heic FORMAT_RGB24 ORIGIN_UPPER_LEFT yes
43 * heic FORMAT_RGBA32 ORIGIN_UPPER_LEFT yes
44 *
45 * png FORMAT_Y8 ORIGIN_UPPER_LEFT no
46 * png FORMAT_YA16 ORIGIN_UPPER_LEFT no
47 * png FORMAT_RGB24 ORIGIN_UPPER_LEFT no
48 * png FORMAT_RGBA32 ORIGIN_UPPER_LEFT no
49 *
50 * tif FORMAT_RGB24 ORIGIN_UPPER_LEFT no
51 * tif FORMAT_RGBA32 ORIGIN_UPPER_LEFT no
52 * </pre>
53 * @see IIOImage.
54 * @ingroup mediaiio
55 */
56class OCEAN_MEDIA_IIO_EXPORT Image
57{
58 public:
59
60 /**
61 * Re-definition of Media::Image::Properties.
62 */
64
65 public:
66
67 /**
68 * Decodes (reads/loads) an image from a given binary buffer.
69 * @param buffer The buffer from which the image will be loaded, must be valid
70 * @param size The size of the given buffer in bytes, with range [1, infinity)
71 * @param imageBufferTypeIn Type of the given image that is stored in the buffer, should be specified if known (e.g. the file extension of a corresponding image file)
72 * @param imageBufferTypeOut Optional type of the given image that is stored in the buffer, as determined by the decoder (if possible)
73 * @param properties Optional resulting properties which are encoded in the image; nullptr if not of interest
74 * @return The frame containing the image information, an invalid frame if the image could not be loaded
75 * @see writeImage().
76 */
77 static Frame decodeImage(const void* buffer, const size_t size, const std::string& imageBufferTypeIn = std::string(), std::string* imageBufferTypeOut = nullptr, Media::Image::Properties* properties = nullptr);
78
79 /**
80 * Encodes (writes) a given frame as image (with specified image type) to a resulting buffer.
81 * In case, the pixel format of the given frame is not supported by the destination, the function will fail.<br>
82 * As this function does not provide an automatic color space conversion, the binary impact when using this function will be quite small.<br>
83 * Note: Depending on the encoder, a provided quality value may not have any impact, e.g., png images do not support a loosely compression.
84 * @param frame The frame to be written, must be valid
85 * @param imageType The file extension of the image to be created (e.g. jpg, png, bmp, or tif), must be defined
86 * @param buffer The resulting buffer storing the binary information of the given image
87 * @param properties The properties to be used when writing the image, must be valid
88 * @return True, if succeeded; False, if the frame could not be encoded e.g., if the pixel format is not supported or if the `imageType` is unknown
89 * @see readImage().
90 */
91 static bool encodeImage(const Frame& frame, const std::string& imageType, std::vector<uint8_t>& buffer, const Properties& properties = Properties());
92
93 /**
94 * Encodes (writes) a given frame as image (with specified image type) to a resulting buffer.
95 * In case, the pixel format of the given frame is not supported by the destination, the function may convert the frame internally (depending on 'allowConversion').
96 * As this function supports the conversion of color spaces, the binary impact when using this function may be quite high.<br>
97 * Note: Depending on the encoder, a provided quality value may not have any impact, e.g., png images do not support a loosely compression.
98 * @param frame The frame to be written, must be valid
99 * @param imageType The file extension of the image to be created (e.g. jpg, png, bmp, or tif), must be defined
100 * @param buffer The resulting buffer storing the binary information of the resulting image
101 * @param allowConversion True, to allow an internal conversion of the frame if the image type does not support the given frame type; False, to prevent a conversion and to stop creating the buffer
102 * @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
103 * @param properties The properties to be used when writing the image, must be valid
104 * @return True, if succeeded; False, if the frame could not be encoded e.g., if the pixel format could not be converted to a valid pixel format or if the `imageType` is unknown
105 * @see readImage().
106 */
107 static bool encodeImage(const Frame& frame, const std::string& imageType, std::vector<uint8_t>& buffer, const bool allowConversion, bool* hasBeenConverted = nullptr, const Properties& properties = Properties());
108
109 /**
110 * Reads/loads an image from a specified file.
111 * @param filename The name of the file from which the image will be loaded, must be valid
112 * @param properties Optional resulting properties which are encoded in the image; nullptr if not of interest
113 * @return The frame containing the image information, an invalid frame if the image could not be loaded
114 * @see writeImage().
115 */
116 static Frame readImage(const std::string& filename, Media::Image::Properties* properties = nullptr);
117
118 /**
119 * Writes a given frame to a specified file.
120 * In case, the pixel format of the given frame is not supported by the destination, the function will fail.<br>
121 * As this function does not provide an automatic color space conversion, the binary impact when using this function will be quite small.<br>
122 * Note: Depending on the encoder, a provided quality value may not have any impact, e.g., png images do not support a loosely compression.
123 * @param frame The frame to be written, must be valid
124 * @param filename The name of the file to which the frame will be written, must contain a valid image extension like e.g. jpg, png, bmp, or tif), must be valid
125 * @param properties The properties to be used when writing the image, must be valid
126 * @return True, if succeeded
127 * @see readImage().
128 */
129 static bool writeImage(const Frame& frame, const std::string& filename, const Properties& properties = Properties());
130
131 /**
132 * Writes a given frame to a specified file.
133 * In case, the pixel format of the given frame is not supported by the destination, the function may convert the frame internally (depending on 'allowConversion').
134 * As this function supports the conversion of color spaces, the binary impact when using this function may be quite high.<br>
135 * Note: Depending on the encoder, a provided quality value may not have any impact, e.g., png images do not support a loosely compression.
136 * @param frame The frame to be written, must be valid
137 * @param filename The name of the file to which the frame will be written, must contain a valid image extension like e.g. jpg, png, bmp, or tif), must be valid
138 * @param allowConversion True, to allow an internal conversion of the frame if the image type does not support the given frame type; False, to prevent a conversion and to stop writing the image
139 * @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
140 * @param properties The properties to be used when writing the image, must be valid
141 * @return True, if succeeded
142 * @see readImage().
143 */
144 static bool writeImage(const Frame& frame, const std::string& filename, const bool allowConversion, bool* hasBeenConverted = nullptr, const Properties& properties = Properties());
145
146 protected:
147
148 /**
149 * Disabled function to prevent wrong usage.
150 * @return Would return True on success
151 */
152 static bool encodeImage(const Frame&, const std::string&, std::vector<uint8_t>&, const float) = delete;
153
154 /**
155 * Disabled function to prevent wrong usage.
156 * @return Would return True on success
157 */
158 static bool writeImage(const Frame&, const std::string&, const float) = delete;
159};
160
161}
162
163}
164
165}
166
167#endif // META_OCEAN_MEDIA_IMAGEIO_IMAGE_H
This class implements Ocean's image class.
Definition Frame.h:1808
Definition of a class holding properties.
Definition media/Image.h:45
This class implements read, write, decocde, and encode functions for all file formats supported by th...
Definition media/imageio/Image.h:57
static bool encodeImage(const Frame &, const std::string &, std::vector< uint8_t > &, const float)=delete
Disabled function to prevent wrong usage.
static bool writeImage(const Frame &frame, const std::string &filename, const bool allowConversion, bool *hasBeenConverted=nullptr, const Properties &properties=Properties())
Writes a given frame to a specified file.
static bool writeImage(const Frame &, const std::string &, const float)=delete
Disabled function to prevent wrong usage.
static Frame readImage(const std::string &filename, Media::Image::Properties *properties=nullptr)
Reads/loads an image from a specified file.
static bool encodeImage(const Frame &frame, const std::string &imageType, std::vector< uint8_t > &buffer, const bool allowConversion, bool *hasBeenConverted=nullptr, const Properties &properties=Properties())
Encodes (writes) a given frame as image (with specified image type) to a resulting buffer.
static Frame decodeImage(const void *buffer, const size_t size, const std::string &imageBufferTypeIn=std::string(), std::string *imageBufferTypeOut=nullptr, Media::Image::Properties *properties=nullptr)
Decodes (reads/loads) an image from a given binary buffer.
static bool writeImage(const Frame &frame, const std::string &filename, const Properties &properties=Properties())
Writes a given frame to a specified file.
static bool encodeImage(const Frame &frame, const std::string &imageType, std::vector< uint8_t > &buffer, const Properties &properties=Properties())
Encodes (writes) a given frame as image (with specified image type) to a resulting buffer.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15