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"
14
15#include <Wincodec.h>
16
17namespace Ocean
18{
19
20namespace Media
21{
22
23namespace WIC
24{
25
26/**
27 * This class is the base class for all object inside this library.
28 * @ingroup mediawic
29 */
30class OCEAN_MEDIA_WIC_EXPORT WICObject
31{
32 public:
33
34 /**
35 * Translates a pixel format from Windows Imaging Component to a framework pixel format.
36 * @param format The Windows Imaging Component pixel format to be translated
37 * @param pixelOrigin Optional resulting Ocean specific pixel origin of the given format
38 * @return Ocean pixel format, FORMAT_UNDEFINED if no corresponding pixel format exists
39 */
40 static FrameType::PixelFormat translatePixelFormat(const WICPixelFormatGUID& format, FrameType::PixelOrigin* pixelOrigin = nullptr);
41
42 /**
43 * Determines the best matching Windows Imaging Component pixel format for a given Ocean pixel format.
44 * @param format The pixel format for which the best matching pixel format will be determined
45 * @param adjustedFormat The resulting adjusted pixel format as compromise in the case a direct matching pixel format does not exist, otherwise identical with format
46 * @param supportedPixelFormats Optional set of supported pixel formats, if known
47 * @return The WIC pixel format, GUID_NULL if no corresponding pixel format exists
48 */
49 static WICPixelFormatGUID matchingPixelFormat(const FrameType::PixelFormat format, FrameType::PixelFormat& adjustedFormat, const std::vector<GUID>& supportedPixelFormats = std::vector<GUID>());
50
51 /**
52 * Returns whether a Windows Imaging Component pixel format has an alpha channel.
53 * @param imagingFactory The imaging factory owner of the decoder, must be valid
54 * @param bitmapDecoder The bitmap decoder object from which the frame will be loaded, must be valid
55 * @param frameDecode The actual frame to check, must be valid
56 * @return True, if so
57 */
58 static bool hasAlphaChannel(IWICImagingFactory* imagingFactory, IWICBitmapDecoder* bitmapDecoder, IWICBitmapFrameDecode* frameDecode);
59
60 /**
61 * Finds the corresponding container format for a specified file extension.
62 * @param fileExtension The file extension for which the container format is requested, e.g., "jpg", "bmp", or "gif"
63 * @return The container format for the specified file extension, GUID_NULL if no matching container could be found
64 */
65 static GUID findContainerFormat(const std::string& fileExtension);
66
67 /**
68 * Translates a container format to the corresponding file extension.
69 * @param containerFormat The container format to be translated
70 * @return The resulting file extension, e.g., "jpg", "bmp", or "gif", empty if unknown
71 */
72 static std::string translateContainerFormat(const GUID& containerFormat);
73
74 /**
75 * Loads a frame from a bitmap decoder object.
76 * @param imagingFactory The imaging factory owner of the decoder, must be valid
77 * @param bitmapDecoder The bitmap decoder object from which the frame will be loaded, must be valid
78 * @return The resulting frame, an invalid frame if the frame could not be loaded
79 */
80 static Frame loadFrameFromBitmapDecoder(IWICImagingFactory* imagingFactory, IWICBitmapDecoder* bitmapDecoder);
81
82 /**
83 * Writes a frame to a bitmap encoder object.
84 * @param imagingFactory The imaging factory owner of the decoder, must be valid
85 * @param bitmapEncoder The bitmap encoder object to which the frame will be written, must be valid
86 * @param frame The frame to which will be written to the decoder, must be valid
87 * @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
88 * @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
89 * @return True, if succeeded
90 */
91 static bool writeFrameToBitmapDecoder(IWICImagingFactory* imagingFactory, IWICBitmapEncoder* bitmapEncoder, const Frame& frame, const bool allowConversion = true, bool* hasBeenConverted = nullptr);
92};
93
94}
95
96}
97
98}
99
100#endif // META_OCEAN_MEDIA_WIC_WIC_OBJECT_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
PixelOrigin
Defines different types of frame origin positions.
Definition Frame.h:1046
This class is the base class for all object inside this library.
Definition WICObject.h:31
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.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15