Ocean
Loading...
Searching...
No Matches
ImageTif.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_OL_IMAGE_TIFF_H
9#define META_OCEAN_MEDIA_OPEN_IMAGE_LIBRARIES_OL_IMAGE_TIFF_H
10
12
13#include "ocean/base/Frame.h"
14#include "ocean/base/Triple.h"
15
16#ifdef OCEAN_MEDIA_OIL_SUPPORT_TIF
17
18namespace Ocean
19{
20
21namespace Media
22{
23
24namespace OpenImageLibraries
25{
26
27/**
28 * This class implements read and write functions for TIFF images.
29 * @ingroup mediaoil
30 */
31class OCEAN_MEDIA_OIL_EXPORT ImageTif
32{
33 public:
34
35 /**
36 * Definition of a triple containing the input buffer, the size of the input buffer, and the current location within the buffer.
37 */
39
40 /**
41 * Definition of a triple containing an output buffer (with addtional reserved bytes), the size of the output buffer, and the current location within the output buffer.
42 */
44
45 public:
46
47 /**
48 * Decodes a TIFF image from a given binary buffer.
49 * @param buffer The buffer from which the image will be loaded, must be valid
50 * @param size The size of the given buffer in bytes, with range [1, infinity)
51 * @return The frame containing the image information, an invalid frame if the image could not be loaded
52 */
53 static Frame decodeImage(const void* buffer, const size_t size);
54
55 /**
56 * Encodes a given frame as BMP image to a resulting buffer.
57 * @param frame The frame to be written, must be valid
58 * @param buffer The resulting buffer storing the binary information of the TIFF image
59 * @param allowConversion True, to allow an internal conversion of the frame if TIFF does not support the given frame type; False, to prevent a conversion and to stop creating the buffer
60 * @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
61 * @return True, if succeeded; False, if the frame could not be written as TIFF image e.g., if the frame contained an alpha channel
62 */
63 static bool encodeImage(const Frame& frame, std::vector<uint8_t>& buffer, const bool allowConversion = true, bool* hasBeenConverted = nullptr);
64
65 /**
66 * Returns whether a given pixel format is supported natively.
67 * @param pixelFormat The pixel format to be checked
68 * @return True, if so; False, if a conversion will be necessary
69 */
70 static inline bool isPixelFormatSupported(const FrameType::PixelFormat pixelFormat);
71
72 /**
73 * Returns whether a given pixel origin is supported natively.
74 * @param pixelOrigin The pixel origin to be checked
75 * @return True, if so; False, if a conversion will be necessary
76 */
77 static inline bool isPixelOriginSupported(const FrameType::PixelOrigin pixelOrigin);
78
79 /**
80 * Returns whether a given pixel format together with a given pixel origin is supported natively.
81 * @param pixelFormat The pixel format to be checked
82 * @param pixelOrigin The pixel origin to be checked
83 * @return True, if so; False, if a conversion will be necessary
84 */
85 static inline bool isFrameTypeSupported(const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin);
86};
87
89{
90 return pixelFormat == FrameType::FORMAT_RGB24 || pixelFormat == FrameType::FORMAT_RGBA32;
91}
92
94{
95 return pixelOrigin == FrameType::ORIGIN_UPPER_LEFT || pixelOrigin == FrameType::ORIGIN_LOWER_LEFT;
96}
97
98inline bool ImageTif::isFrameTypeSupported(const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin)
99{
100 return isPixelFormatSupported(pixelFormat) && isPixelOriginSupported(pixelOrigin);
101}
102
103}
104
105}
106
107}
108
109#endif // OCEAN_MEDIA_OIL_SUPPORT_TIF
110
111#endif // META_OCEAN_MEDIA_OPEN_IMAGE_LIBRARIES_OL_IMAGE_TIFF_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
@ FORMAT_RGBA32
Pixel format with byte order RGBA and 32 bits per pixel.
Definition Frame.h:382
@ FORMAT_RGB24
Pixel format with byte order RGB and 24 bits per pixel.
Definition Frame.h:315
PixelOrigin
Defines different types of frame origin positions.
Definition Frame.h:1046
@ ORIGIN_UPPER_LEFT
The first pixel lies in the upper left corner, the last pixel in the lower right corner.
Definition Frame.h:1050
@ ORIGIN_LOWER_LEFT
The first pixel lies in the lower left corner, the last pixel in the upper right corner.
Definition Frame.h:1052
This class implements read and write functions for TIFF images.
Definition ImageTif.h:32
static bool isPixelFormatSupported(const FrameType::PixelFormat pixelFormat)
Returns whether a given pixel format is supported natively.
Definition ImageTif.h:88
Triple< const uint8_t *, size_t, size_t > InputDataTriple
Definition of a triple containing the input buffer, the size of the input buffer, and the current loc...
Definition ImageTif.h:38
Triple< std::vector< uint8_t >, size_t, size_t > OutputDataTriple
Definition of a triple containing an output buffer (with addtional reserved bytes),...
Definition ImageTif.h:43
static bool encodeImage(const Frame &frame, std::vector< uint8_t > &buffer, const bool allowConversion=true, bool *hasBeenConverted=nullptr)
Encodes a given frame as BMP image to a resulting buffer.
static bool isPixelOriginSupported(const FrameType::PixelOrigin pixelOrigin)
Returns whether a given pixel origin is supported natively.
Definition ImageTif.h:93
static bool isFrameTypeSupported(const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin)
Returns whether a given pixel format together with a given pixel origin is supported natively.
Definition ImageTif.h:98
static Frame decodeImage(const void *buffer, const size_t size)
Decodes a TIFF image from a given binary buffer.
This class implements a triple object able to hold three individual elements.
Definition Triple.h:28
The namespace covering the entire Ocean framework.
Definition Accessor.h:15