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