Ocean
media/wic/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_WIC_IMAGE_H
9 #define META_OCEAN_MEDIA_WIC_IMAGE_H
10 
11 #include "ocean/media/wic/WIC.h"
12 
13 #include "ocean/base/Frame.h"
14 
15 namespace Ocean
16 {
17 
18 namespace Media
19 {
20 
21 namespace WIC
22 {
23 
24 /**
25  * This class implements read and write functions for all file formats supported by the WIC media library.
26  * This class is not derived from Media::Image as this class provides a simple to read and write images without using the Plugin mechanism..<br>
27  * @ingroup mediawic
28  */
29 class OCEAN_MEDIA_WIC_EXPORT Image
30 {
31  public:
32 
33  /**
34  * Decodes (reads/loads) an image from a given binary buffer.
35  * @param buffer The buffer from which the image will be loaded, must be valid
36  * @param size The size of the given buffer in bytes, with range [1, infinity)
37  * @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)
38  * @param imageBufferTypeOut Optional type of the given image that is stored in the buffer, as determined by the decoder (if possible)
39  * @return The frame containing the image information, an invalid frame if the image could not be loaded
40  * @see writeImage().
41  */
42  static Frame decodeImage(const void* buffer, const size_t size, const std::string& imageBufferTypeIn = std::string(), std::string* imageBufferTypeOut = nullptr);
43 
44  /**
45  * Encodes (writes) a given frame as image (with specified image type) to a resulting buffer.
46  * @param frame The frame to be written, must be valid
47  * @param imageType The file extension of the image to be created (e.g. jpg, png, bmp, or tif), must be defined
48  * @param buffer The resulting buffer storing the binary information of the image
49  * @param allowConversion True, to allow an internal conversion of the frame if the encoder does not support the given frame type; False, to prevent a conversion and to stop creating the buffer
50  * @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
51  * @return True, if succeeded; False, if the frame could not be encoded
52  * @see readImage().
53  */
54  static bool encodeImage(const Frame& frame, const std::string& imageType, std::vector<uint8_t>& buffer, const bool allowConversion = true, bool* hasBeenConverted = nullptr);
55 
56  /**
57  * Reads/loads an image from a specified file.
58  * @param filename The name of the file from which the image will be loaded, must be valid
59  * @return The frame containing the image information, an invalid frame if the image could not be loaded
60  * @see writeImage().
61  */
62  static Frame readImage(const std::string& filename);
63 
64  /**
65  * Writes a given frame to a specified file.
66  * @param frame The frame to be written, must be valid
67  * @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
68  * @param allowConversion True, to allow an internal conversion of the frame if the encoder does not support the given frame type; False, to prevent a conversion and to stop writing the file
69  * @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
70  * @return True, if succeeded
71  * @see readImage().
72  */
73  static bool writeImage(const Frame& frame, const std::string& filename, const bool allowConversion = true, bool* hasBeenConverted = nullptr);
74 };
75 
76 }
77 
78 }
79 
80 }
81 
82 #endif // META_OCEAN_MEDIA_WIC_IMAGE_H
This class implements Ocean's image class.
Definition: Frame.h:1792
This class implements read and write functions for all file formats supported by the WIC media librar...
Definition: media/wic/Image.h:30
static bool encodeImage(const Frame &frame, const std::string &imageType, std::vector< uint8_t > &buffer, const bool allowConversion=true, bool *hasBeenConverted=nullptr)
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)
Decodes (reads/loads) an image from a given binary buffer.
static bool writeImage(const Frame &frame, const std::string &filename, const bool allowConversion=true, bool *hasBeenConverted=nullptr)
Writes a given frame to a specified file.
static Frame readImage(const std::string &filename)
Reads/loads an image from a specified file.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15