Ocean
Loading...
Searching...
No Matches
media/openimagelibraries/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_OPEN_IMAGE_LIBRARIES_IMAGE_H
9#define META_OCEAN_MEDIA_OPEN_IMAGE_LIBRARIES_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 OpenImageLibraries
24{
25
26/**
27 * This class implements read and write functions for all file formats supported by the OpenImageLibraries media library.
28 * This class is not derived from Media::Image as this class is a simple wrapper for ImageBmp, ImageJpg, ImagePng, and ImageTif only.<br>
29 * Instead, OILImage is derived from Media::Image.
30 *
31 * OpenImageLibraries supports for the following image types: bmp, 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 * jpg FORMAT_Y8 ORIGIN_UPPER_LEFT yes
38 * jpg FORMAT_Y16 ORIGIN_UPPER_LEFT yes
39 * jpg FORMAT_RGB24 ORIGIN_UPPER_LEFT yes
40 * jpg FORMAT_YUV24 ORIGIN_UPPER_LEFT yes
41 *
42 * png FORMAT_Y8 ORIGIN_UPPER_LEFT no
43 * png FORMAT_Y16 ORIGIN_UPPER_LEFT no
44 * png FORMAT_YA16 ORIGIN_UPPER_LEFT no
45 * png FORMAT_RGB24 ORIGIN_UPPER_LEFT no
46 * png FORMAT_RGBA32 ORIGIN_UPPER_LEFT no
47 * png FORMAT_RGBA64 ORIGIN_UPPER_LEFT no
48 *
49 * webp FORMAT_RGB24 ORIGIN_UPPER_LEFT yes
50 * webp FORMAT_BGR24 ORIGIN_UPPER_LEFT yes
51 *
52 * tif FORMAT_RGB24 ORIGIN_UPPER_LEFT no
53 * tif FORMAT_RGBA32 ORIGIN_UPPER_LEFT no
54 * </pre>
55 * @see OILImage.
56 * @ingroup mediaoil
57 */
58class OCEAN_MEDIA_OIL_EXPORT Image
59{
60 public:
61
62 /**
63 * Re-definition of Media::Image::Properties.
64 */
66
67 public:
68
69 /**
70 * Decodes (reads/loads) an image from a given binary buffer.
71 * @param buffer The buffer from which the image will be loaded, must be valid
72 * @param size The size of the given buffer in bytes, with range [1, infinity)
73 * @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)
74 * @param imageBufferTypeOut Optional type of the given image that is stored in the buffer, as determined by the decoder (if possible)
75 * @return The frame containing the image information, an invalid frame if the image could not be loaded
76 * @see writeImage().
77 */
78 static Frame decodeImage(const void* buffer, const size_t size, const std::string& imageBufferTypeIn = std::string(), std::string* imageBufferTypeOut = nullptr);
79
80 /**
81 * Encodes (writes) a given frame as image (with specified image type) to a resulting buffer.
82 * @param frame The frame to be written, must be valid
83 * @param imageType The file extension of the image to be created (e.g. jpg, png, gif, or tif), must be defined
84 * @param buffer The resulting buffer storing the binary information of the image
85 * @param allowConversion True, to allow an internal conversion of the frame if does not support the given frame type; False, to prevent a conversion and to stop creating the buffer
86 * @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
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 written as image e.g., if the frame contained an alpha channel
89 * @see readImage().
90 */
91 static bool encodeImage(const Frame& frame, const std::string& imageType, std::vector<uint8_t>& buffer, const bool allowConversion = true, bool* hasBeenConverted = nullptr, const Properties& properties = Properties());
92
93 /**
94 * Reads/loads an image from a specified file.
95 * @param filename The name of the file from which the image will be loaded, must be valid
96 * @return The frame containing the image information, an invalid frame if the image could not be loaded
97 * @see writeImage().
98 */
99 static Frame readImage(const std::string& filename);
100
101 /**
102 * Writes a given frame to a specified file.
103 * @param frame The frame to be written, must be valid
104 * @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, gif, or tif), must be valid
105 * @param allowConversion True, to allow an internal conversion of the frame if the image format does not support the given frame type; False, to prevent a conversion and to stop writing the file
106 * @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
107 * @param properties The properties to be used when writing the image, must be valid
108 * @return True, if succeeded
109 * @see readImage().
110 */
111 static bool writeImage(const Frame& frame, const std::string& filename, const bool allowConversion = true, bool* hasBeenConverted = nullptr, const Properties& properties = Properties());
112};
113
114}
115
116}
117
118}
119
120#endif // META_OCEAN_MEDIA_OPEN_IMAGE_LIBRARIES_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 and write functions for all file formats supported by the OpenImageLibrari...
Definition media/openimagelibraries/Image.h:59
static bool writeImage(const Frame &frame, const std::string &filename, const bool allowConversion=true, bool *hasBeenConverted=nullptr, const Properties &properties=Properties())
Writes a given frame to a specified file.
static Frame readImage(const std::string &filename)
Reads/loads an image from a specified file.
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 encodeImage(const Frame &frame, const std::string &imageType, std::vector< uint8_t > &buffer, const bool allowConversion=true, bool *hasBeenConverted=nullptr, 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