Ocean
Loading...
Searching...
No Matches
TestFrameChannels.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_TESTCV_TEST_FRAME_CHANNELS_H
9#define META_OCEAN_TEST_TESTCV_TEST_FRAME_CHANNELS_H
10
12
13#include "ocean/base/DataType.h"
15#include "ocean/base/RandomI.h"
17#include "ocean/base/Worker.h"
18
21
22namespace Ocean
23{
24
25namespace Test
26{
27
28namespace TestCV
29{
30
31/**
32 * This class implements a frame channels test.
33 * @ingroup testcv
34 */
35class OCEAN_TEST_CV_EXPORT TestFrameChannels
36{
37 public:
38
39 /**
40 * Tests all frame channels functions.
41 * @param width The width of the test frame in pixel, with range [1, infinity)
42 * @param height The height of the test frame in pixel, with range [1, infinity)
43 * @param testDuration The number of seconds for each test, with range (0, infinity)
44 * @param worker The worker object to distribute the computation
45 * @return True, if so
46 */
47 static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
48
49 /**
50 * Tests frame separation to one channel function.
51 * @param width The width of the test frame in pixel, with range [1, infinity)
52 * @param height The height of the test frame in pixel, with range [1, infinity)
53 * @param testDuration The number of seconds for each test, with range (0, infinity)
54 * @return True, if succeeded
55 */
56 static bool testSeparateTo1Channel(const unsigned int width, const unsigned int height, const double testDuration);
57
58 /**
59 * Tests frame zip channels function.
60 * @param width The width of the test frame in pixel, with range [1, infinity)
61 * @param height The height of the test frame in pixel, with range [1, infinity)
62 * @param testDuration The number of seconds for each test, with range (0, infinity)
63 * @return True, if succeeded
64 */
65 static bool testZipChannels(const unsigned int width, const unsigned int height, const double testDuration);
66
67 /**
68 * Tests the add channel function that adds a channel as new first channel.
69 * @param width The width of the test frame in pixel, with range [1, infinity)
70 * @param height The height of the test frame in pixel, with range [1, infinity)
71 * @param testDuration The number of seconds for each test, with range (0, infinity)
72 * @param worker The worker object to distribute the computation
73 * @return True, if so
74 */
75 static bool testAddFirstChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
76
77 /**
78 * Tests the add channel value function that adds a channel as new first channel.
79 * @param width The width of the test frame in pixel, with range [1, infinity)
80 * @param height The height of the test frame in pixel, with range [1, infinity)
81 * @param testDuration The number of seconds for each test, with range (0, infinity)
82 * @param worker The worker object to distribute the computation
83 * @return True, if so
84 */
85 static bool testAddFirstChannelValue(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
86
87 /**
88 * Tests the add channel function that adds a channel as new last channel.
89 * @param width The width of the test frame in pixel, with range [1, infinity)
90 * @param height The height of the test frame in pixel, with range [1, infinity)
91 * @param testDuration The number of seconds for each test, with range (0, infinity)
92 * @param worker The worker object to distribute the computation
93 * @return True, if so
94 */
95 static bool testAddLastChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
96
97 /**
98 * Tests the add channel value function that adds a channel as new last channel.
99 * @param width The width of the test frame in pixel, with range [1, infinity)
100 * @param height The height of the test frame in pixel, with range [1, infinity)
101 * @param testDuration The number of seconds for each test, with range (0, infinity)
102 * @param worker The worker object to distribute the computation
103 * @return True, if so
104 */
105 static bool testAddLastChannelValue(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
106
107 /**
108 * Tests the remove channel function that removes the first channel.
109 * @param width The width of the test frame in pixel, with range [1, infinity)
110 * @param height The height of the test frame in pixel, with range [1, infinity)
111 * @param testDuration The number of seconds for each test, with range (0, infinity)
112 * @param worker The worker object to distribute the computation
113 * @return True, if so
114 */
115 static bool testRemoveFirstChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
116
117 /**
118 * Tests the remove channel function that removes the last channel.
119 * @param width The width of the test frame in pixel, with range [1, infinity)
120 * @param height The height of the test frame in pixel, with range [1, infinity)
121 * @param testDuration The number of seconds for each test, with range (0, infinity)
122 * @param worker The worker object to distribute the computation
123 * @return True, if so
124 */
125 static bool testRemoveLastChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
126
127 /**
128 * Tests the copy channel function.
129 * @param width The width of the test frame in pixel, with range [1, infinity)
130 * @param height The height of the test frame in pixel, with range [1, infinity)
131 * @param testDuration The number of seconds for each test, with range (0, infinity)
132 * @param worker The worker object to distribute the computation
133 * @return True, if so
134 */
135 static bool testCopyChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
136
137 /**
138 * Tests the set channel function.
139 * @param width The width of the test frame in pixel, with range [1, infinity)
140 * @param height The height of the test frame in pixel, with range [1, infinity)
141 * @param testDuration The number of seconds for each test, with range (0, infinity)
142 * @param worker The worker object to distribute the computation
143 * @return True, if so
144 */
145 static bool testSetChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
146
147 /**
148 * Tests the advanced pixel modifier function
149 * @param width The width of the test frame in pixel, with range [1, infinity)
150 * @param height The height of the test frame in pixel, with range [1, infinity)
151 * @param testDuration The number of seconds for each test, with range (0, infinity)
152 * @param worker The worker object to distribute the computation
153 * @return True, if the test was successful
154 */
155 static bool testApplyAdvancedPixelModifier(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
156
157 /**
158 * Tests the advanced pixel modifier function for specifc element type and number of channels
159 * @param width The width of the test frame in pixel, with range [1, infinity)
160 * @param height The height of the test frame in pixel, with range [1, infinity)
161 * @param testDuration The number of seconds for each test, with range (0, infinity)
162 * @param worker The worker object to distribute the computation
163 * @return True, if the test was successful
164 * @tparam TElement The type that the test data will use, must be an integral type
165 * @tparam tChannels The number of channels that the test data will use, range: [1, 4]
166 * @tparam tFunction The pixel function that will be used for testing, must be valid
167 */
168 template <typename TElement, unsigned int tChannels, void (*tPixelFunction)(const TElement*, TElement*)>
169 static bool testApplyAdvancedPixelModifier(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
170
171 /**
172 * Test the pixel operator for two inputs and one output.
173 * @param testDuration The number of seconds for each test, with range (0, infinity)
174 * @param worker The worker object to distribute the computation
175 * @return True, if the test was successful, otherwise false
176 * @tparam TPrecision The type that the test data will use, must be an integral type
177 * @tparam tChannels The number of channels that the test data will use, range: [1, 4]
178 */
179 template <typename TPrecision, unsigned int tChannels>
180 static bool testApplyBivariateOperator(const double testDuration, Worker& worker);
181
182 /**
183 * Test the image transformation function for generic pixel formats.
184 * @param testDuration The number of seconds for each test, range: (0, infinity)
185 * @param worker A worker instance to test the parallelized version of the test function
186 * @return True if the test was successful, otherwise false
187 */
188 static bool testTransformGeneric(const double testDuration, Worker& worker);
189
190 /**
191 * Tests the image transformation function for a specific generic pixel format.
192 * @param width The width of the images to be tested, range: [1, infinity)
193 * @param height The height of the images to be tested, range: [1, infinity)
194 * @param testDuration The number of seconds for each test, range: (0, infinity)
195 * @param worker A worker instance to test the parallelized version of the test function
196 * @return True if the test was successful, otherwise false
197 * @tparam TElementType Type used for data of the images (will be used internally to generate random test data)
198 * @tparam tChannels The number of channels of the test images (will be used internally to generate random test data), range: [1, infinity)
199 */
200 template <typename TElementType, unsigned int tChannels>
201 static bool testTransformGeneric(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
202
203 /**
204 * Tests the conversion function from premultiplied alpha to straight alpha images.
205 * @param testDuration The number of seconds for each test, range: (0, infinity)
206 * @param worker A worker instance to test the parallelized version of the test function
207 * @return True if the test was successful, otherwise false
208 */
209 static bool testPremultipliedAlphaToStraightAlpha(const double testDuration, Worker& worker);
210
211 /**
212 * Tests the conversion function from straight alpha to premultiplied alpha images.
213 * @param testDuration The number of seconds for each test, range: (0, infinity)
214 * @param worker A worker instance to test the parallelized version of the test function
215 * @return True if the test was successful, otherwise false
216 */
217 static bool testStraightAlphaToPremultipliedAlpha(const double testDuration, Worker& worker);
218
219 /**
220 * Tests the image conversion function reversing the order of pixel channels.
221 * @param testDuration The number of seconds for each test, range: (0, infinity)
222 * @param worker A worker instance to test the parallelized version of the test function
223 * @return True if the test was successful, otherwise false
224 */
225 static bool testReverseChannelOrder(const double testDuration, Worker& worker);
226
227 /**
228 * Tests the image conversion function reversing the order of pixel channels for a specific data type and channel number.
229 * @param width The width of the images to be tested, with range [1, infinity)
230 * @param height The height of the images to be tested, with range [1, infinity)
231 * @param testDuration The number of seconds for each test, with range (0, infinity)
232 * @param worker A worker instance to test the parallelized version of the test function
233 * @return True if the test was successful, otherwise false
234 * @tparam T The data type of each pixel channel, e.g., 'unsigned char' or 'float'
235 * @tparam tChannels The number of channels of the test images, with range [1, infinity)
236 */
237 template <typename T, unsigned int tChannels>
238 static bool testReverseChannelOrder(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
239
240 /**
241 * Test the row-based pixel conversion from 3 channels to 1 channel.
242 * @param testDuration The number of seconds for each test, with range (0, infinity)
243 * @return True, if the test was successful, otherwise false
244 */
245 static bool testRowPixelConversion3ChannelsTo1Channel(const double testDuration);
246
247 /**
248 * Test the row-based pixel conversion from 3 channels to 3 channels with 6 bit precision.
249 * @param testDuration The number of seconds for each test, with range (0, infinity)
250 * @return True, if the test was successful, otherwise false
251 */
252 static bool testRowPixelConversion3ChannelsTo3Channels6BitPrecision(const double testDuration);
253
254 /**
255 * Test the row-based pixel conversion from 3 channels to 3 channels with 7 bit precision.
256 * @param testDuration The number of seconds for each test, with range (0, infinity)
257 * @return True, if the test was successful, otherwise false
258 */
259 static bool testRowPixelConversion3ChannelsTo3Channels7BitPrecision(const double testDuration);
260
261 /**
262 * Test the row-based pixel conversion from 3 channels to 3 channels with 10 bit precision.
263 * @param testDuration The number of seconds for each test, with range (0, infinity)
264 * @return True, if the test was successful, otherwise false
265 */
266 static bool testRowPixelConversion3ChannelsTo3Channels10BitPrecision(const double testDuration);
267
268 /**
269 * Test the row-based pixel conversion from 4 channels to 1 channel.
270 * @param testDuration The number of seconds for each test, with range (0, infinity)
271 * @return True, if the test was successful, otherwise false
272 */
273 static bool testRowPixelConversion4ChannelsTo1Channel(const double testDuration);
274
275 /**
276 * Test the row-based pixel conversion from 4 channels to 2 channel.
277 * @param testDuration The number of seconds for each test, with range (0, infinity)
278 * @return True, if the test was successful, otherwise false
279 */
280 static bool testRowPixelConversion4ChannelsTo2Channels(const double testDuration);
281
282 /**
283 * Test the row-based pixel conversion from 4 channels to 3 channel.
284 * @param testDuration The number of seconds for each test, with range (0, infinity)
285 * @return True, if the test was successful, otherwise false
286 */
287 static bool testRowPixelConversion4ChannelsTo3Channels(const double testDuration);
288
289 /**
290 * Test the row-based pixel reverse order function.
291 * @param testDuration The number of seconds for each test, with range (0, infinity)
292 * @return True, if the test was successful, otherwise false
293 */
294 static bool testReverseRowPixelOrder(const double testDuration);
295
296 /**
297 * Test the row-based pixel reverse order function.
298 * @param testDuration The number of seconds for each test, with range (0, infinity)
299 * @return True, if the test was successful, otherwise false
300 */
301 static bool testReverseRowChannelOrder(const double testDuration);
302
303 /**
304 * Test the row-based shuffling of pixel channels.
305 * @param testDuration The number of seconds for each test, with range (0, infinity)
306 * @return True, if the test was successful, otherwise false
307 */
308 static bool testShuffleRowChannels(const double testDuration);
309
310 /**
311 * Test the row-based shuffling of pixel channels and setting the last channel with constant value.
312 * @param testDuration The number of seconds for each test, with range (0, infinity)
313 * @return True, if the test was successful, otherwise false
314 */
315 static bool testShuffleRowChannelsAndSetLastChannelValue(const double testDuration);
316
317 /**
318 * Test the row-based narrowing of pixel with 16 bit channels.
319 * @param testDuration The number of seconds for each test, with range (0, infinity)
320 * @return True, if the test was successful, otherwise false
321 */
322 static bool testNarrowRow16BitPerChannels(const double testDuration);
323
324 /**
325 * Test function to be used with the test for the advanced pixel modifier
326 * @param source The pointer to the source pixel, must be valid
327 * @param target The pointer to the target pixel, must be valid
328 * @tparam TSource The type of the source
329 * @tparam TTarget The type of the target
330 */
331 template <typename TSource, typename TTarget, unsigned int tChannels>
332 static void testFunctionApplyAdvancedModifier(const TSource* source, TTarget* target);
333
334 protected:
335
336 /**
337 * Tests frame separation to one channel function.
338 * @param width The width of the test frame in pixel, with range [1, infinity)
339 * @param height The height of the test frame in pixel, with range [1, infinity)
340 * @param channels The number of channels the test frame has, with range [2, infinity)
341 * @param testDuration The number of seconds for each test, with range (0, infinity)
342 * @return True, if succeeded
343 * @tparam TSource The data type of the source elements
344 * @tparam TTarget The data type of the target elements
345 */
346 template <typename TSource, typename TTarget>
347 static bool testSeparateTo1Channel(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration);
348
349 /**
350 * Tests zip channels function.
351 * @param width The width of the test frame in pixel, with range [1, infinity)
352 * @param height The height of the test frame in pixel, with range [1, infinity)
353 * @param channels The number of channels the test frame has, with range [2, infinity)
354 * @param testDuration The number of seconds for each test, with range (0, infinity)
355 * @return True, if succeeded
356 * @tparam TSource The data type of the source elements
357 * @tparam TTarget The data type of the target elements
358 */
359 template <typename TSource, typename TTarget>
360 static bool testZipChannels(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration);
361
362 /**
363 * Tests the add channel function that adds a channel as new first channel.
364 * @param width The width of the test frame in pixel, with range [1, infinity)
365 * @param height The height of the test frame in pixel, with range [1, infinity)
366 * @param testDuration The number of seconds for each test, with range (0, infinity)
367 * @param worker The worker object to distribute the computation
368 * @return True, if so
369 * @tparam T The data type of each pixel element, e.g., 'unsigned char' or 'float'
370 * @tparam tSourceChannels The number of channels of the source frame, with range [1, infinity)
371 */
372 template <typename T, unsigned int tSourceChannels>
373 static bool testAddFirstChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
374
375 /**
376 * Tests the add channel value function that adds a channel as new first channel.
377 * @param width The width of the test frame in pixel, with range [1, infinity)
378 * @param height The height of the test frame in pixel, with range [1, infinity)
379 * @param testDuration The number of seconds for each test, with range (0, infinity)
380 * @param worker The worker object to distribute the computation
381 * @return True, if so
382 * @tparam T The data type of each pixel element, e.g., 'unsigned char' or 'float'
383 * @tparam tSourceChannels The number of channels of the source frame, with range [1, infinity)
384 */
385 template <typename T, unsigned int tSourceChannels>
386 static bool testAddFirstChannelValue(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
387
388 /**
389 * Tests the add channel function that adds a channel as new last channel.
390 * @param width The width of the test frame in pixel, with range [1, infinity)
391 * @param height The height of the test frame in pixel, with range [1, infinity)
392 * @param testDuration The number of seconds for each test, with range (0, infinity)
393 * @param worker The worker object to distribute the computation
394 * @return True, if so
395 * @tparam T The data type of each pixel element, e.g., 'unsigned char' or 'float'
396 * @tparam tSourceChannels The number of channels of the source frame, with range [1, infinity)
397 */
398 template <typename T, unsigned int tSourceChannels>
399 static bool testAddLastChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
400
401 /**
402 * Tests the add channel value function that adds a channel as new last channel.
403 * @param width The width of the test frame in pixel, with range [1, infinity)
404 * @param height The height of the test frame in pixel, with range [1, infinity)
405 * @param testDuration The number of seconds for each test, with range (0, infinity)
406 * @param worker The worker object to distribute the computation
407 * @return True, if so
408 * @tparam T The data type of each pixel element, e.g., 'unsigned char' or 'float'
409 * @tparam tSourceChannels The number of channels of the source frame, with range [1, infinity)
410 */
411 template <typename T, unsigned int tSourceChannels>
412 static bool testAddLastChannelValue(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
413
414 /**
415 * Tests the remove channel function that removes the first channel.
416 * @param width The width of the test frame in pixel, with range [1, infinity)
417 * @param height The height of the test frame in pixel, with range [1, infinity)
418 * @param testDuration The number of seconds for each test, with range (0, infinity)
419 * @param worker The worker object to distribute the computation
420 * @return True, if so
421 * @tparam T The data type of each pixel element, e.g., 'unsigned char' or 'float'
422 * @tparam tSourceChannels The number of channels of the source frame, with range [2, infinity)
423 */
424 template <typename T, unsigned int tSourceChannels>
425 static bool testRemoveFirstChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
426
427 /**
428 * Tests the remove channel function that removes the last channel.
429 * @param width The width of the test frame in pixel, with range [1, infinity)
430 * @param height The height of the test frame in pixel, with range [1, infinity)
431 * @param testDuration The number of seconds for each test, with range (0, infinity)
432 * @param worker The worker object to distribute the computation
433 * @return True, if so
434 * @tparam T The data type of each pixel element, e.g., 'unsigned char' or 'float'
435 * @tparam tSourceChannels The number of channels of the source frame, with range [2, infinity)
436 */
437 template <typename T, unsigned int tSourceChannels>
438 static bool testRemoveLastChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
439
440 /**
441 * Tests the copy channel function.
442 * @param width The width of the test frame in pixel, with range [1, infinity)
443 * @param height The height of the test frame in pixel, with range [1, infinity)
444 * @param testDuration The number of seconds for each test, with range (0, infinity)
445 * @param worker The worker object to distribute the computation
446 * @return True, if so
447 * @tparam T The data type of each pixel element, e.g., 'unsigned char' or 'float'
448 * @tparam tSourceChannels The number of channels of the source frame, with range [1, infinity)
449 * @tparam tTargetChannels The number of channels of the source frame, with range [1, infinity)
450 * @tparam tSourceChannelIndex The number of channels of the source frame, with range [1, tSourceChannels - 1]
451 * @tparam tTargetChannelIndex The number of channels of the source frame, with range [1, tTargetchannels - 1]
452 */
453 template <typename T, unsigned int tSourceChannels, unsigned int tTargetChannels, unsigned int tSourceChannelIndex, unsigned int tTargetChannelIndex>
454 static bool testCopyChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
455
456 /**
457 * Tests the set channel function.
458 * @param width The width of the test frame in pixel, with range [1, infinity)
459 * @param height The height of the test frame in pixel, with range [1, infinity)
460 * @param testDuration The number of seconds for each test, with range (0, infinity)
461 * @param worker The worker object to distribute the computation
462 * @return True, if so
463 * @tparam T The data type of each pixel element, e.g., 'unsigned char' or 'float'
464 * @tparam tChannel The number of channels of the source frame, with range [1, tChannels - 1]
465 * @tparam tChannels The number of channels of the frame, with range [1, infinity)
466 */
467 template <typename T, unsigned int tChannel, unsigned int tChannels>
468 static bool testSetChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
469
470 /**
471 * Validates the add channel function that add a new channel as first channel.
472 * @param source The source frame to which the new channel will be added, must be valid
473 * @param sourceNewChannel The new channel to be added, must be valid
474 * @param target The target frame with added channel, must be valid
475 * @param sourceChannels The number of channels the source frame has, with range [1, infinity)
476 * @param width The width of both frames frame in pixel, with range [1, infinity)
477 * @param height The height of both frames frame in pixel, with range [1, infinity)
478 * @param flag The conversion type to be applied
479 * @param sourcePaddingElements Optional number of padding elements at the end of each source row, in elements, with range [0, infinity)
480 * @param sourceNewChannelPaddingElements Optional number of padding elements at the end of each new-channel-source row, in elements, with range [0, infinity)
481 * @param targetPaddingElements Optional number of padding elements at the end of each target row, in elements, with range [0, infinity)
482 * @tparam T The data type of each pixel element, e.g., 'unsigned char' or 'float'
483 */
484 template <typename T>
485 static bool validateAddFirstChannel(const T* source, const T* sourceNewChannel, const T* target, const unsigned int sourceChannels, const unsigned int width, const unsigned int height, const CV::FrameConverter::ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int sourceNewChannelPaddingElements, const unsigned int targetPaddingElements);
486
487 /**
488 * Validates the add channel value function that adds a new channel as first channel.
489 * @param source The source frame to which the new channel will be added, must be valid
490 * @param newChannelValue The value of the new channel
491 * @param target The target frame with added channel, must be valid
492 * @param sourceChannels The number of channels the source frame has, with range [1, infinity)
493 * @param width The width of both frames frame in pixel, with range [1, infinity)
494 * @param height The height of both frames frame in pixel, with range [1, infinity)
495 * @param flag The conversion type to be applied
496 * @param sourcePaddingElements Optional number of padding elements at the end of each source row, in elements, with range [0, infinity)
497 * @param targetPaddingElements Optional number of padding elements at the end of each target row, in elements, with range [0, infinity)
498 * @tparam T The data type of each pixel element, e.g., 'unsigned char' or 'float'
499 */
500 template <typename T>
501 static bool validateAddFirstChannelValue(const T* source, const T& newChannelValue, const T* target, const unsigned int sourceChannels, const unsigned int width, const unsigned int height, const CV::FrameConverter::ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements);
502
503 /**
504 * Validates the add channel function that add a new channel as last channel.
505 * @param source The source frame to which the new channel will be added, must be valid
506 * @param sourceNewChannel The new channel to be added, must be valid
507 * @param target The target frame with added channel, must be valid
508 * @param sourceChannels The number of channels the source frame has, with range [1, infinity)
509 * @param width The width of both frames frame in pixel, with range [1, infinity)
510 * @param height The height of both frames frame in pixel, with range [1, infinity)
511 * @param flag The conversion type to be applied
512 * @param sourcePaddingElements Optional number of padding elements at the end of each source row, in elements, with range [0, infinity)
513 * @param sourceNewChannelPaddingElements Optional number of padding elements at the end of each new-channel-source row, in elements, with range [0, infinity)
514 * @param targetPaddingElements Optional number of padding elements at the end of each target row, in elements, with range [0, infinity)
515 * @tparam T The data type of each pixel element, e.g., 'unsigned char' or 'float'
516 */
517 template <typename T>
518 static bool validateAddLastChannel(const T* source, const T* sourceNewChannel, const T* target, const unsigned int sourceChannels, const unsigned int width, const unsigned int height, const CV::FrameConverter::ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int sourceNewChannelPaddingElements, const unsigned int targetPaddingElements);
519
520 /**
521 * Validates the add channel value function that adds a new channel as last channel.
522 * @param source The source frame to which the new channel will be added, must be valid
523 * @param newChannelValue The value of the new channel
524 * @param target The target frame with added channel, must be valid
525 * @param sourceChannels The number of channels the source frame has, with range [1, infinity)
526 * @param width The width of both frames frame in pixel, with range [1, infinity)
527 * @param height The height of both frames frame in pixel, with range [1, infinity)
528 * @param flag The conversion type to be applied
529 * @param sourcePaddingElements Optional number of padding elements at the end of each source row, in elements, with range [0, infinity)
530 * @param targetPaddingElements Optional number of padding elements at the end of each target row, in elements, with range [0, infinity)
531 * @tparam T The data type of each pixel element, e.g., 'unsigned char' or 'float'
532 */
533 template <typename T>
534 static bool validateAddLastChannelValue(const T* source, const T& newChannelValue, const T* target, const unsigned int sourceChannels, const unsigned int width, const unsigned int height, const CV::FrameConverter::ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements);
535
536 /**
537 * Validates the advanced pixel modification function
538 * @param source The source frame that will be used for the validation, must be valid
539 * @param validationTarget The target frame that will be validated, must be valid
540 * @param conversionFlag The conversion flag that will be used for the validation
541 * @tparam TElement The type that the test data will use, must be an integral type
542 * @tparam tChannels The number of channels that the test data will use, range: [1, 4]
543 * @tparam tFunction The pixel function that will be used for testing, must be valid
544 */
545 template <typename TElement, unsigned int tChannels, void (*tPixelFunction)(const TElement*, TElement*)>
546 static bool validateApplyAdvancedPixelModifier(const Frame& source, const Frame& validationTarget, const CV::FrameConverter::ConversionFlag conversionFlag);
547
548 /**
549 * Validates the bivariate operator using subtraction
550 * @param source0 The first source frame, must be valid
551 * @param source1 The second source frame, must be valid
552 * @param target The target frame that will be validated, must be valid
553 * @param flag The conversion flag
554 * @tparam TSource0 Type of the first source
555 * @tparam TSource1 Type of the second source
556 * @tparam TTarget Type of the target
557 * @return True on successful validation, otherwise false
558 */
559 template <typename TSource0, typename TSource1, typename TTarget>
560 static bool validateApplyBivariateOperatorSubtract(const Frame& source0, const Frame& source1, const Frame& target, const CV::FrameChannels::ConversionFlag flag);
561
562 /**
563 * Validation function for image transformations like flipping and mirroring for a specific generic pixel format.
564 * @param source Pointer to the source data, must be valid
565 * @param target Pointer to the data to be tested, must be valid
566 * @param width The width of the images to be tested, range: [1, infinity)
567 * @param height The height of the images to be tested, range: [1, infinity)
568 * @param sourcePaddingElements The number of padding elements in the source image, range: [0, infinity)
569 * @param targetPaddingElements The number of padding elements in the test image, range: [0, infinity)
570 * @param flag Conversion flag, cf. @c CV::FrameConverter::ConversionFlag
571 * @return True if the test was successful, otherwise false
572 * @tparam TElementType Type used for data of the images (will be used internally to generate random test data)
573 * @tparam tChannels The number of channels of the test images (will be used internally to generate random test data), range: [1, infinity)
574 */
575 template <typename TElementType, unsigned int tChannels>
576 static bool validateTransformGeneric(const TElementType* source, const TElementType* target, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const CV::FrameConverter::ConversionFlag flag);
577
578 /**
579 * Validates the reversion of channels of frame pixels.
580 * @param source The source frame for which the channels will be reversed, must be valid
581 * @param target The target frame with reversed channels, must be valid
582 * @param width The width of the images to be tested, with range [1, infinity)
583 * @param height The height of the images to be tested, with range [1, infinity)
584 * @param channels The number of channels of the test images, with range [1, infinity)
585 * @param sourcePaddingElements The number of padding elements in the source image, witgh range [0, infinity)
586 * @param targetPaddingElements The number of padding elements in the test image, with range [0, infinity)
587 * @param flag The conversion flag which has been applied
588 * @return True if the test was successful, otherwise false
589 * @tparam T The data type of each pixel channel, e.g., 'unsigned char' or 'float'
590 */
591 template <typename T>
592 static bool validateReverseChannelOrder(const T* source, const T* target, const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const CV::FrameConverter::ConversionFlag flag);
593
594 /**
595 * Validates the remove channel function that removes the first channel.
596 * @param source The source frame from which the channel will be removed, must be valid
597 * @param target The target frame with removed channel, must be valid
598 * @param sourceChannels The number of channels of the source frame, with range [2, infinity)
599 * @param width The width of the original frame in pixel, with range [1, infinity)
600 * @param height The height of the original frame in pixel, with range [1, infinity)
601 * @param flag Conversion flag
602 * @param sourcePaddingElements The number of padding elements at the end of each row of the source image, in elements, with range [0, infinity)
603 * @param targetPaddingElements The number of padding elements at the end of each row of the target image, in elements, with range [0, infinity)
604 * @tparam T The data type of each pixel channel, e.g., 'unsigned char' or 'float'
605 */
606 template <typename T>
607 static bool validateRemoveFirstChannel(const T* source, const T* target, const unsigned int sourceChannels, const unsigned int width, const unsigned int height, const CV::FrameConverter::ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements);
608
609 /**
610 * Validates the remove channel function that removes the last channel.
611 * @param source The source frame from which the channel will be removed, must be valid
612 * @param target The target frame with removed channel, must be valid
613 * @param sourceChannels The number of channels of the source frame, with range [2, infinity)
614 * @param width The width of the original frame in pixel, with range [1, infinity)
615 * @param height The height of the original frame in pixel, with range [1, infinity)
616 * @param flag Conversion flag
617 * @param sourcePaddingElements The number of padding elements at the end of each row of the source image, in elements, with range [0, infinity)
618 * @param targetPaddingElements The number of padding elements at the end of each row of the target image, in elements, with range [0, infinity)
619 */
620 template <typename T>
621 static bool validateRemoveLastChannel(const T* source, const T* target, const unsigned int sourceChannels, const unsigned int width, const unsigned int height, const CV::FrameConverter::ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements);
622
623 /**
624 * Validates the copy channel function.
625 * @param source The source frame from which one channel will be copied, must be valid
626 * @param originalTarget The target frame before the channel has been copied, must be valid
627 * @param target The target frame to which the channel has been copied, must be valid
628 * @param sourceChannels The number of channels of the source frame, with range [1, infinity)
629 * @param targetChannels The number of channels of the target frame, with range [1, infinity)
630 * @param sourceChannelIndex The index of the source channel to be copied, with range [0, sourceChannels - 1]
631 * @param targetChannelIndex The index of the target channel which has received the copied channel, with range [0, targetChannels - 1]
632 * @param width The width of the original frame in pixel, with range [1, infinity)
633 * @param height The height of the original frame in pixel, with range [1, infinity)
634 * @param sourcePaddingElements The number of padding elements at the end of each row of the source image, in elements, with range [0, infinity)
635 * @param targetPaddingElements The number of padding elements at the end of each row of the target image, in elements, with range [0, infinity)
636 */
637 template <typename T>
638 static bool validateCopyChannel(const T* source, const T* originalTarget, const T* target, const unsigned int sourceChannels, const unsigned int targetChannels, const unsigned int sourceChannelIndex, const unsigned int targetChannelIndex, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements);
639
640 /**
641 * Validates the set channel function.
642 * @param originalFrame The frame before the channel has been set, must be valid
643 * @param frame The frame with modified channel, must be valid
644 * @param width The width of the original frame in pixel, with range [1, infinity)
645 * @param height The height of the original frame in pixel, with range [1, infinity)
646 * @param value The channel value that has been set
647 * @param channelIndex The index of the channel which has been set, with range [0, channels - 1]
648 * @param channels The number of channels of the frame, with range [1, infinity)
649 * @param framePaddingElements The number of padding elements at the end of each row of the image, in elements, with range [0, infinity)
650 */
651 template <typename T>
652 static bool validateSetChannel(const T* originalFrame, const T* frame, const unsigned int width, const unsigned int height, const T value, const unsigned int channelIndex, const unsigned int channels, const unsigned int framePaddingElements);
653
654 /**
655 * Validates the row-based pixel reverse order function for a specific data type and channel number.
656 * @param randomGenerator The random generator object to be used
657 * @return True, if succeeded
658 * @tparam T The data type of the each pixel element
659 * @tparam tChannels The number of channels per pixel, with range [1, infinity)
660 */
661 template <typename T, unsigned int tChannels>
662 static bool validateReverseRowPixelOrder(RandomGenerator& randomGenerator);
663
664 /**
665 * Validates the row-based channel reverse order function for a specific data type and channel number.
666 * @param randomGenerator The random generator object to be used
667 * @return True, if succeeded
668 * @tparam T The data type of the each pixel element
669 * @tparam tChannels The number of channels per pixel, with range [1, infinity)
670 */
671 template <typename T, unsigned int tChannels>
672 static bool validateReverseRowChannelOrder(RandomGenerator& randomGenerator);
673
674 /**
675 * Validates the row-based shuffle function for channels.
676 * @param randomGenerator The random generator object to be used
677 * @return True, if succeeded
678 * @tparam T Data type of each channel pixel value, e.g, 'unsigned char' or 'float'
679 * @tparam tSourceChannels The number of source data channels, with range [1, 8u]
680 * @tparam tTargetChannels The number of target data channels, with range [1, 8u]
681 * @tparam tShufflePattern Groups of four bits define the source channel, e.g., 0x76543210 defines the identity transformation, 0x01234567 defines the reverse transformation
682 */
683 template <typename T, unsigned int tSourceChannels, unsigned int tTargetChannels, unsigned int tShufflePattern>
684 static bool validateShuffleRowChannels(RandomGenerator& randomGenerator);
685
686 /**
687 * Validates the row-based shuffle and setting last channel with constant value function for channels.
688 * @param randomGenerator The random generator object to be used
689 * @return True, if succeeded
690 * @tparam T Data type of each channel pixel value, e.g, 'unsigned char' or 'float'
691 * @tparam tSourceChannels The number of source data channels, with range [1, 8u]
692 * @tparam tTargetChannels The number of target data channels, with range [2, 8u]
693 * @tparam tShufflePattern Groups of four bits define the source channel, e.g., 0x76543210 defines the identity transformation, 0x01234567 defines the reverse transformation
694 */
695 template <typename T, unsigned int tSourceChannels, unsigned int tTargetChannels, unsigned int tShufflePattern>
697
698 /**
699 * Validates the row-based narrow function for 16 bit channels.
700 * @param randomGenerator The random generator object to be used
701 * @return True, if succeeded
702 * @tparam tChannels The number of channels, with range [1, infinity)
703 */
704 template <unsigned int tChannels>
706
707 /**
708 * Collection of test operations for pixel operators.
709 * @tparam tChannels The number of frame channels, with range [1, infinity)
710 */
711 template <unsigned int tChannels>
713 {
714 /**
715 * Facilitates subtraction between two sources and stores the result to another destination
716 * Essentially, target = source0 - source1
717 * @param source0 The first source pixel, must be valid
718 * @param source1 The second source pixel must be valid
719 * @param target The location where the result will be stored (of the targer pixel), must be valid
720 */
721 template <typename TSource0, typename TSource1, typename TTarget>
722 static void subtract(const TSource0* source0, const TSource1* source1, TTarget* target);
723 };
724};
725
726template <unsigned int tChannels>
727template <typename TSource0, typename TSource1, typename TTarget>
728void TestFrameChannels::TestOperations<tChannels>::subtract(const TSource0* source0, const TSource1* source1, TTarget* target)
729{
730 static_assert(tChannels >= 1u, "Invalid channel number!");
731
732 ocean_assert(source0 != nullptr && source1 != nullptr && target != nullptr);
733
734 for (unsigned int c = 0u; c < tChannels; ++c)
735 {
736 target[c] = (TTarget)(source0[c] - source1[c]);
737 }
738};
739
740}
741
742}
743
744}
745
746#endif // META_OCEAN_TEST_TESTCV_TEST_FRAME_CHANNELS_H
ConversionFlag
Definition of individual conversion flags.
Definition FrameConverter.h:39
This class implements Ocean's image class.
Definition Frame.h:1808
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
This class implements a frame channels test.
Definition TestFrameChannels.h:36
static bool validateRemoveLastChannel(const T *source, const T *target, const unsigned int sourceChannels, const unsigned int width, const unsigned int height, const CV::FrameConverter::ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements)
Validates the remove channel function that removes the last channel.
static bool testAddFirstChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the add channel function that adds a channel as new first channel.
static bool testAddFirstChannelValue(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the add channel value function that adds a channel as new first channel.
static bool testAddLastChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the add channel function that adds a channel as new last channel.
static bool testNarrowRow16BitPerChannels(const double testDuration)
Test the row-based narrowing of pixel with 16 bit channels.
static bool testRemoveFirstChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the remove channel function that removes the first channel.
static bool testStraightAlphaToPremultipliedAlpha(const double testDuration, Worker &worker)
Tests the conversion function from straight alpha to premultiplied alpha images.
static bool validateNarrowRow16BitPerChannels(RandomGenerator &randomGenerator)
Validates the row-based narrow function for 16 bit channels.
static bool testShuffleRowChannels(const double testDuration)
Test the row-based shuffling of pixel channels.
static bool validateReverseChannelOrder(const T *source, const T *target, const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const CV::FrameConverter::ConversionFlag flag)
Validates the reversion of channels of frame pixels.
static bool validateTransformGeneric(const TElementType *source, const TElementType *target, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const CV::FrameConverter::ConversionFlag flag)
Validation function for image transformations like flipping and mirroring for a specific generic pixe...
static bool testApplyBivariateOperator(const double testDuration, Worker &worker)
Test the pixel operator for two inputs and one output.
static bool testRowPixelConversion4ChannelsTo2Channels(const double testDuration)
Test the row-based pixel conversion from 4 channels to 2 channel.
static void testFunctionApplyAdvancedModifier(const TSource *source, TTarget *target)
Test function to be used with the test for the advanced pixel modifier.
static bool testReverseRowChannelOrder(const double testDuration)
Test the row-based pixel reverse order function.
static bool testReverseChannelOrder(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the image conversion function reversing the order of pixel channels for a specific data type an...
static bool testSeparateTo1Channel(const unsigned int width, const unsigned int height, const double testDuration)
Tests frame separation to one channel function.
static bool testTransformGeneric(const double testDuration, Worker &worker)
Test the image transformation function for generic pixel formats.
static bool validateAddLastChannel(const T *source, const T *sourceNewChannel, const T *target, const unsigned int sourceChannels, const unsigned int width, const unsigned int height, const CV::FrameConverter::ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int sourceNewChannelPaddingElements, const unsigned int targetPaddingElements)
Validates the add channel function that add a new channel as last channel.
static bool testRemoveFirstChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the remove channel function that removes the first channel.
static bool testRowPixelConversion4ChannelsTo1Channel(const double testDuration)
Test the row-based pixel conversion from 4 channels to 1 channel.
static bool testRemoveLastChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the remove channel function that removes the last channel.
static bool testApplyAdvancedPixelModifier(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the advanced pixel modifier function for specifc element type and number of channels.
static bool testAddLastChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the add channel function that adds a channel as new last channel.
static bool testSetChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the set channel function.
static bool testTransformGeneric(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the image transformation function for a specific generic pixel format.
static bool testReverseRowPixelOrder(const double testDuration)
Test the row-based pixel reverse order function.
static bool testRowPixelConversion3ChannelsTo1Channel(const double testDuration)
Test the row-based pixel conversion from 3 channels to 1 channel.
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests all frame channels functions.
static bool validateShuffleRowAndSetLastChannelValueChannels(RandomGenerator &randomGenerator)
Validates the row-based shuffle and setting last channel with constant value function for channels.
static bool testCopyChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the copy channel function.
static bool validateShuffleRowChannels(RandomGenerator &randomGenerator)
Validates the row-based shuffle function for channels.
static bool testSeparateTo1Channel(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration)
Tests frame separation to one channel function.
static bool testRowPixelConversion3ChannelsTo3Channels10BitPrecision(const double testDuration)
Test the row-based pixel conversion from 3 channels to 3 channels with 10 bit precision.
static bool testZipChannels(const unsigned int width, const unsigned int height, const double testDuration)
Tests frame zip channels function.
static bool testShuffleRowChannelsAndSetLastChannelValue(const double testDuration)
Test the row-based shuffling of pixel channels and setting the last channel with constant value.
static bool validateApplyBivariateOperatorSubtract(const Frame &source0, const Frame &source1, const Frame &target, const CV::FrameChannels::ConversionFlag flag)
Validates the bivariate operator using subtraction.
static bool testCopyChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the copy channel function.
static bool testAddLastChannelValue(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the add channel value function that adds a channel as new last channel.
static bool testRemoveLastChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the remove channel function that removes the last channel.
static bool testAddFirstChannelValue(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the add channel value function that adds a channel as new first channel.
static bool testApplyAdvancedPixelModifier(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the advanced pixel modifier function.
static bool testRowPixelConversion3ChannelsTo3Channels7BitPrecision(const double testDuration)
Test the row-based pixel conversion from 3 channels to 3 channels with 7 bit precision.
static bool testPremultipliedAlphaToStraightAlpha(const double testDuration, Worker &worker)
Tests the conversion function from premultiplied alpha to straight alpha images.
static bool validateRemoveFirstChannel(const T *source, const T *target, const unsigned int sourceChannels, const unsigned int width, const unsigned int height, const CV::FrameConverter::ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements)
Validates the remove channel function that removes the first channel.
static bool validateAddLastChannelValue(const T *source, const T &newChannelValue, const T *target, const unsigned int sourceChannels, const unsigned int width, const unsigned int height, const CV::FrameConverter::ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements)
Validates the add channel value function that adds a new channel as last channel.
static bool testRowPixelConversion4ChannelsTo3Channels(const double testDuration)
Test the row-based pixel conversion from 4 channels to 3 channel.
static bool testSetChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the set channel function.
static bool testReverseChannelOrder(const double testDuration, Worker &worker)
Tests the image conversion function reversing the order of pixel channels.
static bool testAddLastChannelValue(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the add channel value function that adds a channel as new last channel.
static bool validateCopyChannel(const T *source, const T *originalTarget, const T *target, const unsigned int sourceChannels, const unsigned int targetChannels, const unsigned int sourceChannelIndex, const unsigned int targetChannelIndex, const unsigned int width, const unsigned int height, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements)
Validates the copy channel function.
static bool validateSetChannel(const T *originalFrame, const T *frame, const unsigned int width, const unsigned int height, const T value, const unsigned int channelIndex, const unsigned int channels, const unsigned int framePaddingElements)
Validates the set channel function.
static bool testRowPixelConversion3ChannelsTo3Channels6BitPrecision(const double testDuration)
Test the row-based pixel conversion from 3 channels to 3 channels with 6 bit precision.
static bool validateReverseRowPixelOrder(RandomGenerator &randomGenerator)
Validates the row-based pixel reverse order function for a specific data type and channel number.
static bool validateAddFirstChannelValue(const T *source, const T &newChannelValue, const T *target, const unsigned int sourceChannels, const unsigned int width, const unsigned int height, const CV::FrameConverter::ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements)
Validates the add channel value function that adds a new channel as first channel.
static bool validateAddFirstChannel(const T *source, const T *sourceNewChannel, const T *target, const unsigned int sourceChannels, const unsigned int width, const unsigned int height, const CV::FrameConverter::ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int sourceNewChannelPaddingElements, const unsigned int targetPaddingElements)
Validates the add channel function that add a new channel as first channel.
static bool validateApplyAdvancedPixelModifier(const Frame &source, const Frame &validationTarget, const CV::FrameConverter::ConversionFlag conversionFlag)
Validates the advanced pixel modification function.
static bool validateReverseRowChannelOrder(RandomGenerator &randomGenerator)
Validates the row-based channel reverse order function for a specific data type and channel number.
static bool testZipChannels(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration)
Tests zip channels function.
static bool testAddFirstChannel(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the add channel function that adds a channel as new first channel.
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
Collection of test operations for pixel operators.
Definition TestFrameChannels.h:713
static void subtract(const TSource0 *source0, const TSource1 *source1, TTarget *target)
Facilitates subtraction between two sources and stores the result to another destination Essentially,...
Definition TestFrameChannels.h:728