Ocean
Loading...
Searching...
No Matches
WICObject.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_WIC_OBJECT_H
9#define META_OCEAN_MEDIA_WIC_WIC_OBJECT_H
10
11#include "ocean/media/wic/WIC.h"
12
13#include "ocean/base/Frame.h"
15
16#include <Wincodec.h>
17
18namespace Ocean
19{
20
21namespace Media
22{
23
24namespace WIC
25{
26
27/**
28 * This functions allows to release a WIC object if it does exist.
29 * @param object The WIC object to be released
30 * @ingroup mediawic
31 */
32template <class T> void release(T* object);
33
34/**
35 * Template specialization for ScopedObjectCompileTimeVoid using the release() function to release WIC objects.
36 * @tparam T The data type of the wrapped object
37 * @ingroup mediawic
38 */
39template <typename T>
41
42/**
43 * Definition of a scoped object holding an IPropertyBag2 object.
44 * The wrapped IPropertyBag2 object will be released automatically once the scoped object does not exist anymore.
45 * @ingroup mediawic
46 */
48
49/**
50 * Definition of a scoped object holding an IStream object.
51 * The wrapped IStream object will be released automatically once the scoped object does not exist anymore.
52 * @ingroup mediawic
53 */
55
56/**
57 * Definition of a scoped object holding an IWICBitmapDecoder object.
58 * The wrapped IWICBitmapDecoder object will be released automatically once the scoped object does not exist anymore.
59 * @ingroup mediawic
60 */
62
63/**
64 * Definition of a scoped object holding an IWICBitmapEncoder object.
65 * The wrapped IWICBitmapEncoder object will be released automatically once the scoped object does not exist anymore.
66 * @ingroup mediawic
67 */
69
70/**
71 * Definition of a scoped object holding an IWICBitmapEncoderInfo object.
72 * The wrapped IWICBitmapEncoderInfo object will be released automatically once the scoped object does not exist anymore.
73 * @ingroup mediawic
74 */
76
77/**
78 * Definition of a scoped object holding an IWICBitmapFrameDecode object.
79 * The wrapped IWICBitmapFrameDecode object will be released automatically once the scoped object does not exist anymore.
80 * @ingroup mediawic
81 */
83
84/**
85 * Definition of a scoped object holding an IWICBitmapFrameEncode object.
86 * The wrapped IWICBitmapFrameEncode object will be released automatically once the scoped object does not exist anymore.
87 * @ingroup mediawic
88 */
90
91/**
92 * Definition of a scoped object holding an IWICFormatConverter object.
93 * The wrapped IWICFormatConverter object will be released automatically once the scoped object does not exist anymore.
94 * @ingroup mediawic
95 */
97
98/**
99 * Definition of a scoped object holding an IWICImagingFactory object.
100 * The wrapped IWICImagingFactory object will be released automatically once the scoped object does not exist anymore.
101 * @ingroup mediawic
102 */
104
105/**
106 * Definition of a scoped object holding an IWICPalette object.
107 * The wrapped IWICPalette object will be released automatically once the scoped object does not exist anymore.
108 * @ingroup mediawic
109 */
111
112/**
113 * Definition of a scoped object holding an IWICStream object.
114 * The wrapped IWICStream object will be released automatically once the scoped object does not exist anymore.
115 * @ingroup mediawic
116 */
118
119/**
120 * This class is the base class for all object inside this library.
121 * @ingroup mediawic
122 */
123class OCEAN_MEDIA_WIC_EXPORT WICObject
124{
125 public:
126
127 /**
128 * Translates a pixel format from Windows Imaging Component to a framework pixel format.
129 * @param format The Windows Imaging Component pixel format to be translated
130 * @param pixelOrigin Optional resulting Ocean specific pixel origin of the given format
131 * @return Ocean pixel format, FORMAT_UNDEFINED if no corresponding pixel format exists
132 */
133 static FrameType::PixelFormat translatePixelFormat(const WICPixelFormatGUID& format, FrameType::PixelOrigin* pixelOrigin = nullptr);
134
135 /**
136 * Determines the best matching Windows Imaging Component pixel format for a given Ocean pixel format.
137 * @param format The pixel format for which the best matching pixel format will be determined
138 * @param adjustedFormat The resulting adjusted pixel format as compromise in the case a direct matching pixel format does not exist, otherwise identical with format
139 * @param supportedPixelFormats Optional set of supported pixel formats, if known
140 * @return The WIC pixel format, GUID_NULL if no corresponding pixel format exists
141 */
142 static WICPixelFormatGUID matchingPixelFormat(const FrameType::PixelFormat format, FrameType::PixelFormat& adjustedFormat, const std::vector<GUID>& supportedPixelFormats = std::vector<GUID>());
143
144 /**
145 * Returns whether a Windows Imaging Component pixel format has an alpha channel.
146 * @param imagingFactory The imaging factory owner of the decoder, must be valid
147 * @param bitmapDecoder The bitmap decoder object from which the frame will be loaded, must be valid
148 * @param frameDecode The actual frame to check, must be valid
149 * @return True, if so
150 */
151 static bool hasAlphaChannel(IWICImagingFactory* imagingFactory, IWICBitmapDecoder* bitmapDecoder, IWICBitmapFrameDecode* frameDecode);
152
153 /**
154 * Finds the corresponding container format for a specified file extension.
155 * @param fileExtension The file extension for which the container format is requested, e.g., "jpg", "bmp", or "gif"
156 * @return The container format for the specified file extension, GUID_NULL if no matching container could be found
157 */
158 static GUID findContainerFormat(const std::string& fileExtension);
159
160 /**
161 * Translates a container format to the corresponding file extension.
162 * @param containerFormat The container format to be translated
163 * @return The resulting file extension, e.g., "jpg", "bmp", or "gif", empty if unknown
164 */
165 static std::string translateContainerFormat(const GUID& containerFormat);
166
167 /**
168 * Loads a frame from a bitmap decoder object.
169 * @param imagingFactory The imaging factory owner of the decoder, must be valid
170 * @param bitmapDecoder The bitmap decoder object from which the frame will be loaded, must be valid
171 * @return The resulting frame, an invalid frame if the frame could not be loaded
172 */
173 static Frame loadFrameFromBitmapDecoder(IWICImagingFactory* imagingFactory, IWICBitmapDecoder* bitmapDecoder);
174
175 /**
176 * Writes a frame to a bitmap encoder object.
177 * @param imagingFactory The imaging factory owner of the decoder, must be valid
178 * @param bitmapEncoder The bitmap encoder object to which the frame will be written, must be valid
179 * @param frame The frame to which will be written to the decoder, must be valid
180 * @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
181 * @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
182 * @return True, if succeeded
183 */
184 static bool writeFrameToBitmapDecoder(IWICImagingFactory* imagingFactory, IWICBitmapEncoder* bitmapEncoder, const Frame& frame, const bool allowConversion = true, bool* hasBeenConverted = nullptr);
185};
186
187template <class T>
188void release(T* object)
189{
190 if (object != nullptr)
191 {
192 object->Release();
193 }
194}
195
196}
197
198}
199
200}
201
202#endif // META_OCEAN_MEDIA_WIC_WIC_OBJECT_H
This class implements Ocean's image class.
Definition Frame.h:1969
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition Frame.h:183
PixelOrigin
Defines different types of frame origin positions.
Definition Frame.h:1136
This class is the base class for all object inside this library.
Definition WICObject.h:124
static bool writeFrameToBitmapDecoder(IWICImagingFactory *imagingFactory, IWICBitmapEncoder *bitmapEncoder, const Frame &frame, const bool allowConversion=true, bool *hasBeenConverted=nullptr)
Writes a frame to a bitmap encoder object.
static bool hasAlphaChannel(IWICImagingFactory *imagingFactory, IWICBitmapDecoder *bitmapDecoder, IWICBitmapFrameDecode *frameDecode)
Returns whether a Windows Imaging Component pixel format has an alpha channel.
static FrameType::PixelFormat translatePixelFormat(const WICPixelFormatGUID &format, FrameType::PixelOrigin *pixelOrigin=nullptr)
Translates a pixel format from Windows Imaging Component to a framework pixel format.
static Frame loadFrameFromBitmapDecoder(IWICImagingFactory *imagingFactory, IWICBitmapDecoder *bitmapDecoder)
Loads a frame from a bitmap decoder object.
static GUID findContainerFormat(const std::string &fileExtension)
Finds the corresponding container format for a specified file extension.
static std::string translateContainerFormat(const GUID &containerFormat)
Translates a container format to the corresponding file extension.
static WICPixelFormatGUID matchingPixelFormat(const FrameType::PixelFormat format, FrameType::PixelFormat &adjustedFormat, const std::vector< GUID > &supportedPixelFormats=std::vector< GUID >())
Determines the best matching Windows Imaging Component pixel format for a given Ocean pixel format.
This class wraps an unmanaged object (or reference) which needs to be released after usage.
Definition ScopedObject.h:166
void release(T *object)
This functions allows to release a WIC object if it does exist.
Definition WICObject.h:188
The namespace covering the entire Ocean framework.
Definition Accessor.h:15