Ocean
Loading...
Searching...
No Matches
TestImageIO.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_TEST_TESTMEDIA_TEST_IMAGE_IO_H
9#define META_OCEAN_TEST_TESTMEDIA_TEST_IMAGE_IO_H
10
12
14
15#include "ocean/base/Frame.h"
16
17#ifdef OCEAN_PLATFORM_BUILD_APPLE
18
19namespace Ocean
20{
21
22namespace Test
23{
24
25namespace TestMedia
26{
27
28/**
29 * This class implements a test for the IMageIO media library.
30 * @ingroup testmedia
31 */
32class OCEAN_TEST_MEDIA_EXPORT TestImageIO
33{
34 protected:
35
36 /**
37 * Definition of a pair combining a pixel format with a color profile name.
38 */
39 using ColorProfilePair = std::pair<FrameType::PixelFormat, std::string>;
40
41 public:
42
43 /**
44 * Invokes all tests that are defined.
45 * @param testDuration The number of seconds for each test, with range (0, infinity)
46 * @param selector The test selector
47 * @return True, if succeeded
48 */
49 static bool test(const double testDuration, const TestSelector& selector);
50
51 /**
52 * Tests the read and write functions for BMP images.
53 * @param testDuration The number of seconds for each test, with range (0, infinity)
54 * @return True, if succeeded
55 */
56 static bool testBmpImageEncodeDecode(const double testDuration);
57
58 /**
59 * Tests the read and write functions for JPEG images.
60 * @param testDuration The number of seconds for each test, with range (0, infinity)
61 * @return True, if succeeded
62 */
63 static bool testJpgImageEncodeDecode(const double testDuration);
64
65 /**
66 * Tests the read and write functions for HEIC images.
67 * @param testDuration The number of seconds for each test, with range (0, infinity)
68 * @return True, if succeeded
69 */
70 static bool testHeicImageEncodeDecode(const double testDuration);
71
72 /**
73 * Tests the read and write functions for PNG images.
74 * @param testDuration The number of seconds for each test, with range (0, infinity)
75 * @return True, if succeeded
76 */
77 static bool testPngImageEncodeDecode(const double testDuration);
78
79 /**
80 * Tests the read and write functions for PNG images.
81 * @param testDuration The number of seconds for each test, with range (0, infinity)
82 * @return True, if succeeded
83 */
84 static bool testTifImageEncodeDecode(const double testDuration);
85
86 /**
87 * Tests the read and write functions for any image.
88 * @param testDuration The number of seconds for each test, with range (0, infinity)
89 * @return True, if succeeded
90 */
91 static bool testAnyImageEncodeDecode(const double testDuration);
92
93 /**
94 * Tests the encoding and decoding between individual media libraries.
95 * @param testDuration The number of seconds for each test, with range (0, infinity)
96 * @return True, if succeeded
97 */
98 static bool testInterchangeability(const double testDuration);
99
100 /**
101 * Tests the forward and backward conversion between a Frame and a CGImage.
102 * @param testDuration The number of seconds for each test, with range (0, infinity)
103 * @return True, if succeeded
104 */
105 static bool testConversionCGImage(const double testDuration);
106
107 /**
108 * Tests the read and write functions for BMP images.
109 * @param width The width of the frame to be tested, with range [1, infinity)
110 * @param height The height of the frame to be tested, with range [1, infinity)
111 * @param pixelFormat The pixel format of the frame to be tested, must be valid
112 * @param pixelOrigin The pixel origin of the frame to be tested, must be valid
113 * @param testDuration The number of seconds for each test, with range (0, infinity)
114 * @return True, if succeeded
115 */
116 static bool testBmpImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration);
117
118 /**
119 * Tests the read and write functions for JPEG images.
120 * @param width The width of the frame to be tested, with range [1, infinity)
121 * @param height The height of the frame to be tested, with range [1, infinity)
122 * @param pixelFormat The pixel format of the frame to be tested, must be valid
123 * @param pixelOrigin The pixel origin of the frame to be tested, must be valid
124 * @param testDuration The number of seconds for each test, with range (0, infinity)
125 * @return True, if succeeded
126 */
127 static bool testJpgImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration);
128
129 /**
130 * Tests the read and write functions for HEIC images.
131 * @param width The width of the frame to be tested, with range [1, infinity)
132 * @param height The height of the frame to be tested, with range [1, infinity)
133 * @param pixelFormat The pixel format of the frame to be tested, must be valid
134 * @param pixelOrigin The pixel origin of the frame to be tested, must be valid
135 * @param testDuration The number of seconds for each test, with range (0, infinity)
136 * @return True, if succeeded
137 */
138 static bool testHeicImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration);
139
140 /**
141 * Tests the read and write functions for PNG images.
142 * @param width The width of the frame to be tested, with range [1, infinity)
143 * @param height The height of the frame to be tested, with range [1, infinity)
144 * @param pixelFormat The pixel format of the frame to be tested, must be valid
145 * @param pixelOrigin The pixel origin of the frame to be tested, must be valid
146 * @param testDuration The number of seconds for each test, with range (0, infinity)
147 * @return True, if succeeded
148 */
149 static bool testPngImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration);
150
151 /**
152 * Tests the read and write functions for TIFF images.
153 * @param width The width of the frame to be tested, with range [1, infinity)
154 * @param height The height of the frame to be tested, with range [1, infinity)
155 * @param pixelFormat The pixel format of the frame to be tested, must be valid
156 * @param pixelOrigin The pixel origin of the frame to be tested, must be valid
157 * @param testDuration The number of seconds for each test
158 * @return True, if succeeded
159 */
160 static bool testTifImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration);
161
162 /**
163 * Tests the ImageBufferRecorder and ImageBuffer functionality of the media library.
164 * @param frameType The frame type to be used for testing, must be valid
165 * @param imageType The file extension of the image to be created (e.g. jpg, png, bmp, or tif), must be defined
166 * @param maximalAverageDifference The maximal average difference between two frames so that they still count as similar, with range [0, infinity), 0 for lossless compress, >0 for lossy compression
167 * @return True, if succeeded
168 */
169 static bool testBufferImageRecorder(const FrameType& frameType, const std::string& imageType, const double maximalAverageDifference);
170
171 /**
172 * Tests the quality property for a specified image type.
173 * @param imageType The image type for which the test will be executed
174 * @param testDuration The number of seconds for each test, with range (0, infinity)
175 * @return True, if succeeded
176 */
177 static bool testQualityProperty(const std::string& imageType, const double testDuration);
178
179 /**
180 * Tests setting color profile names for a specified image type.
181 * @param imageType The image type for which the test will be executed
182 * @param testDuration The number of seconds for each test, with range (0, infinity)
183 * @return True, if succeeded
184 */
185 static bool testColorProfileNameProperty(const std::string& imageType, const double testDuration);
186
187 protected:
188
189 /**
190 * Returns color profile pairs for testing, using the correct profile name for the current OS version.
191 * @param imageType The image type (e.g., "jpg", "heic")
192 * @return The color profile pairs
193 */
194 static std::vector<ColorProfilePair> getColorProfilePairsForImageType(const std::string& imageType);
195
196 /**
197 * Determines the minimal, the average and the maximal distance between corresponding pixel values (channel-wise) for two frames.
198 * @param firstFrame The first frame for which the similarity will be determined, must be valid
199 * @param secondFrame The second frame for which the similarity will be determined, with identical frame type as 'firstFrame' must be valid
200 * @param minDifference Resulting minimal value difference, with range [0, infinity)
201 * @param aveDifference Resulting average value difference, with range [minDifference, maxDifference]
202 * @param maxDifference Resulting maximal value difference, with range [aveDifference, infinity)
203 * @return True, if succeeded
204 */
205 static bool determineSimilarity(const Frame& firstFrame, const Frame& secondFrame, double& minDifference, double& aveDifference, double& maxDifference);
206
207 /**
208 * Determines the minimal, the average and the maximal distance between corresponding pixel values (channel-wise) for two frames.
209 * @param firstFrame The image data of the first frame for which the similarity will be determined, must be valid
210 * @param secondFrame The image data of the second frame for which the similarity will be determined, must be valid
211 * @param width The width of the frames in pixel, with range [1, infinity)
212 * @param height The height of the frames in pixel, with range [1, infinity)
213 * @param channels The number of frame channels, with range [1, infinity)
214 * @param firstFramePaddingElements The number of padding elements at the end of each first image row, in elements, with range [0, infinity)
215 * @param secondFramePaddingElements The number of padding elements at the end of each second image row, in elements, with range [0, infinity)
216 * @param minDifference Resulting minimal value difference, with range [0, infinity)
217 * @param aveDifference Resulting average value difference, with range [minDifference, maxDifference]
218 * @param maxDifference Resulting maximal value difference, with range [aveDifference, infinity)
219 */
220 template <typename T>
221 static void determineSimilarity(const T* firstFrame, const T* secondFrame, const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int firstFramePaddingElements, const unsigned int secondFramePaddingElements, double& minDifference, double& aveDifference, double& maxDifference);
222};
223
224}
225
226}
227
228}
229
230#endif // OCEAN_PLATFORM_BUILD_APPLE
231
232#endif // META_OCEAN_TEST_TESTMEDIA_TEST_IMAGE_IO_H
This class implements Ocean's image class.
Definition Frame.h:1879
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition Frame.h:30
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 implements a test for the IMageIO media library.
Definition TestImageIO.h:33
static bool testHeicImageEncodeDecode(const double testDuration)
Tests the read and write functions for HEIC images.
static bool test(const double testDuration, const TestSelector &selector)
Invokes all tests that are defined.
static bool testPngImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration)
Tests the read and write functions for PNG images.
static std::vector< ColorProfilePair > getColorProfilePairsForImageType(const std::string &imageType)
Returns color profile pairs for testing, using the correct profile name for the current OS version.
static bool testBmpImageEncodeDecode(const double testDuration)
Tests the read and write functions for BMP images.
static bool determineSimilarity(const Frame &firstFrame, const Frame &secondFrame, double &minDifference, double &aveDifference, double &maxDifference)
Determines the minimal, the average and the maximal distance between corresponding pixel values (chan...
static bool testConversionCGImage(const double testDuration)
Tests the forward and backward conversion between a Frame and a CGImage.
static bool testBmpImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration)
Tests the read and write functions for BMP images.
static bool testTifImageEncodeDecode(const double testDuration)
Tests the read and write functions for PNG images.
static bool testHeicImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration)
Tests the read and write functions for HEIC images.
static bool testQualityProperty(const std::string &imageType, const double testDuration)
Tests the quality property for a specified image type.
static bool testBufferImageRecorder(const FrameType &frameType, const std::string &imageType, const double maximalAverageDifference)
Tests the ImageBufferRecorder and ImageBuffer functionality of the media library.
std::pair< FrameType::PixelFormat, std::string > ColorProfilePair
Definition of a pair combining a pixel format with a color profile name.
Definition TestImageIO.h:39
static bool testTifImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration)
Tests the read and write functions for TIFF images.
static bool testAnyImageEncodeDecode(const double testDuration)
Tests the read and write functions for any image.
static bool testPngImageEncodeDecode(const double testDuration)
Tests the read and write functions for PNG images.
static bool testJpgImageEncodeDecode(const double testDuration)
Tests the read and write functions for JPEG images.
static bool testInterchangeability(const double testDuration)
Tests the encoding and decoding between individual media libraries.
static bool testColorProfileNameProperty(const std::string &imageType, const double testDuration)
Tests setting color profile names for a specified image type.
static void determineSimilarity(const T *firstFrame, const T *secondFrame, const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int firstFramePaddingElements, const unsigned int secondFramePaddingElements, double &minDifference, double &aveDifference, double &maxDifference)
Determines the minimal, the average and the maximal distance between corresponding pixel values (chan...
static bool testJpgImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration)
Tests the read and write functions for JPEG images.
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
The namespace covering the entire Ocean framework.
Definition Accessor.h:15