Ocean
TestWIC.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_WIC_H
9 #define META_OCEAN_TEST_TESTMEDIA_TEST_WIC_H
10 
12 
13 #ifdef OCEAN_PLATFORM_BUILD_WINDOWS
14 
15 #include "ocean/base/Frame.h"
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 WIC media library.
28  * @ingroup testmedia
29  */
30 class OCEAN_TEST_MEDIA_EXPORT TestWIC
31 {
32  public:
33 
34  /**
35  * Invokes all tests that are defined.
36  * @param testDuration The number of seconds for each test
37  * @return True, if succeeded
38  */
39  static bool test(const double testDuration);
40 
41  /**
42  * Tests the read and write functions for any image.
43  * @param testDuration The number of seconds for each test
44  * @return True, if succeeded
45  */
46  static bool testAnyImageEncodeDecode(const double testDuration);
47 
48  /**
49  * Tests the read and write functions for BMP images.
50  * @param width The width of the frame to be tested, with range [1, infinity)
51  * @param height The height of the frame to be tested, with range [1, infinity)
52  * @param pixelFormat The pixel format of the frame to be tested, must be valid
53  * @param pixelOrigin The pixel origin of the frame to be tested, must be valid
54  * @param testDuration The number of seconds for each test
55  * @return True, if succeeded
56  */
57  static bool testBmpImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration);
58 
59 #ifdef OCEAN_MEDIA_OIL_SUPPORT_JPG
60 
61  /**
62  * Tests the read and write functions for JPEG images.
63  * @param width The width of the frame to be tested, with range [1, infinity)
64  * @param height The height of the frame to be tested, with range [1, infinity)
65  * @param pixelFormat The pixel format of the frame to be tested, must be valid
66  * @param pixelOrigin The pixel origin of the frame to be tested, must be valid
67  * @param testDuration The number of seconds for each test
68  * @return True, if succeeded
69  */
70  static bool testJpgImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration);
71 
72 #endif // OCEAN_MEDIA_OIL_SUPPORT_JPG
73 
74 #ifdef OCEAN_MEDIA_OIL_SUPPORT_PNG
75 
76  /**
77  * Tests the read and write functions for PNG images.
78  * @param width The width of the frame to be tested, with range [1, infinity)
79  * @param height The height of the frame to be tested, with range [1, infinity)
80  * @param pixelFormat The pixel format of the frame to be tested, must be valid
81  * @param pixelOrigin The pixel origin of the frame to be tested, must be valid
82  * @param testDuration The number of seconds for each test
83  * @return True, if succeeded
84  */
85  static bool testPngImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration);
86 
87 #endif // OCEAN_MEDIA_OIL_SUPPORT_PNG
88 
89 #ifdef OCEAN_MEDIA_OIL_SUPPORT_TIF
90 
91  /**
92  * Tests the read and write functions for TIFF images.
93  * @param width The width of the frame to be tested, with range [1, infinity)
94  * @param height The height of the frame to be tested, with range [1, infinity)
95  * @param pixelFormat The pixel format of the frame to be tested, must be valid
96  * @param pixelOrigin The pixel origin of the frame to be tested, must be valid
97  * @param testDuration The number of seconds for each test
98  * @return True, if succeeded
99  */
100  static bool testTifImageEncodeDecode(const unsigned int width, const unsigned int height, const FrameType::PixelFormat pixelFormat, const FrameType::PixelOrigin pixelOrigin, const double testDuration);
101 
102 #endif // OCEAN_MEDIA_OIL_SUPPORT_TIF
103 
104  /**
105  * Tests the ImageBufferRecorder and ImageBuffer functionality of the media library.
106  * @param frameType The frame type to be used for testing, must be valid
107  * @param imageType The file extension of the image to be created (e.g. jpg, png, bmp, or tif), must be defined
108  * @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
109  * @return True, if succeeded
110  */
111  static bool testBufferImageRecorder(const FrameType& frameType, const std::string& imageType, const double maximalAverageDifference);
112 
113  protected:
114 
115  /**
116  * Determines the minimal, the average and the maximal distance between corresponding pixel values (channel-wise) for two frames.
117  * @param firstFrame The first frame for which the similarity will be determined, must be valid
118  * @param secondFrame The second frame for which the similarity will be determined, with identical frame type as 'firstFrame' must be valid
119  * @param minDifference Resulting minimal value difference, with range [0, infinity)
120  * @param aveDifference Resulting average value difference, with range [minDifference, maxDifference]
121  * @param maxDifference Resulting maximal value difference, with range [aveDifference, infinity)
122  * @return True, if succeeded
123  */
124  static bool determineSimilarity(const Frame& firstFrame, const Frame& secondFrame, double& minDifference, double& aveDifference, double& maxDifference);
125 
126  /**
127  * Determines the minimal, the average and the maximal distance between corresponding pixel values (channel-wise) for two frames.
128  * @param firstFrame The image data of the first frame for which the similarity will be determined, must be valid
129  * @param secondFrame The image data of the second frame for which the similarity will be determined, must be valid
130  * @param width The width of the frames in pixel, with range [1, infinity)
131  * @param height The height of the frames in pixel, with range [1, infinity)
132  * @param channels The number of frame channels, with range [1, infinity)
133  * @param firstFramePaddingElements The number of padding elements at the end of each first image row, in elements, with range [0, infinity)
134  * @param secondFramePaddingElements The number of padding elements at the end of each second image row, in elements, with range [0, infinity)
135  * @param minDifference Resulting minimal value difference, with range [0, infinity)
136  * @param aveDifference Resulting average value difference, with range [minDifference, maxDifference]
137  * @param maxDifference Resulting maximal value difference, with range [aveDifference, infinity)
138  */
139  template <typename T>
140  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);
141 };
142 
143 }
144 
145 }
146 
147 }
148 
149 #endif // META_OCEAN_TEST_TESTMEDIA_TEST_WIC_H
150 
151 #endif // OCEAN_PLATFORM_BUILD_WINDOWS
This class implements Ocean's image class.
Definition: Frame.h:1792
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 WIC media library.
Definition: TestWIC.h:31
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 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 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 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.
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 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 testBufferImageRecorder(const FrameType &frameType, const std::string &imageType, const double maximalAverageDifference)
Tests the ImageBufferRecorder and ImageBuffer functionality of the media library.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15