1 #ifndef DALI_TEST_IMG_UTILS_H
2 #define DALI_TEST_IMG_UTILS_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
28 #include <dali/dali.h>
29 #include <dali/devel-api/adaptor-framework/image-loading.h>
30 #include <dali/public-api/dali-core.h>
32 #include <dali-test-suite-utils.h>
39 * Test whether two buffers are equal with tolerance value.
40 * @param[in] buffer1 The first buffer
41 * @param[in] buffer2 The second pixelbuffer
42 * @param[in] tolerance value, maximum difference to accept the similarity of buffers.
43 * @param[in] location The TEST_LOCATION macro should be used here
46 inline void DALI_TEST_EQUALS(const unsigned char* buffer1, const unsigned char* buffer2, unsigned int tolerance, long size, const char* location)
50 if(memcmp(buffer1, buffer2, size))
52 fprintf(stderr, "%s, checking buffer1 == buffer2\n", location);
62 const unsigned char* buff1 = buffer1;
63 const unsigned char* buff2 = buffer2;
65 //Create a mask to fast compare, it is expected to be similar values.
66 unsigned int maskBits = 0;
67 while(maskBits < tolerance)
72 maskBits &= ~(1 << --i);
76 for(i = 0; i < size; ++i, ++buff1, ++buff2)
78 //Check bit difference, if exist, do more exhaustive comparison with tolerance value
79 if((*buff1 ^ *buff2) & maskBits)
83 unsigned int diff = *buff2 - *buff1;
92 unsigned int diff = *buff1 - *buff2;
103 fprintf(stderr, "%s, byte %d, checking %u == %u\n", location, i, *buff1, *buff2);
104 tet_result(TET_FAIL);
108 tet_result(TET_PASS);
114 * Test whether two pixelbuffers are equal with tolerance value, with check of width and height.
115 * @param[in] pixelBuffer1 The first buffer
116 * @param[in] pixelBuffer2 The second pixelbuffer
117 * @param[in] tolerance value, maximum difference to accept the similarity of pixel buffers.
118 * @param[in] location The TEST_LOCATION macro should be used here
121 inline void DALI_IMAGE_TEST_EQUALS(Dali::Devel::PixelBuffer pixelBuffer1, Dali::Devel::PixelBuffer pixelBuffer2, unsigned int tolerance, const char* location)
123 if((pixelBuffer1.GetPixelFormat() != Pixel::RGB888) || (pixelBuffer2.GetPixelFormat() != Pixel::RGB888))
125 fprintf(stderr, "%s, PixelFormat != Pixel::RGB888, test only support Pixel::RGB888 formats\n", location);
126 tet_result(TET_FAIL);
128 else if((pixelBuffer1.GetWidth() != pixelBuffer1.GetWidth()) || (pixelBuffer1.GetHeight() != pixelBuffer1.GetHeight()))
130 fprintf(stderr, "%s, Different Image sizes\n", location);
131 tet_result(TET_FAIL);
135 DALI_TEST_EQUALS(pixelBuffer1.GetBuffer(), pixelBuffer2.GetBuffer(), tolerance, pixelBuffer1.GetHeight() * pixelBuffer1.GetWidth() * 3, location);
141 #endif // DALI_TEST_SUITE_UTILS_H