1 /*-------------------------------------------------------------------------
2 * drawElements Internal Test Module
3 * ---------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 *
19 *//*!
20 * \file
21 * \brief Image comparison tests.
22 *//*--------------------------------------------------------------------*/
23
24 #include "ditImageCompareTests.hpp"
25 #include "tcuResource.hpp"
26 #include "tcuImageCompare.hpp"
27 #include "tcuFuzzyImageCompare.hpp"
28 #include "tcuImageIO.hpp"
29 #include "tcuTexture.hpp"
30 #include "tcuTestLog.hpp"
31 #include "tcuTextureUtil.hpp"
32 #include "tcuRGBA.hpp"
33 #include "deFilePath.hpp"
34 #include "deClock.h"
35
36 namespace dit
37 {
38
39 using tcu::TestLog;
40
41 static const char *BASE_DIR = "internal/data/imagecompare";
42
loadImageRGBA8(tcu::TextureLevel & dst,const tcu::Archive & archive,const char * path)43 static void loadImageRGBA8(tcu::TextureLevel &dst, const tcu::Archive &archive, const char *path)
44 {
45 tcu::TextureLevel tmp;
46 tcu::ImageIO::loadImage(tmp, archive, path);
47
48 dst.setStorage(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), tmp.getWidth(),
49 tmp.getHeight());
50 tcu::copy(dst, tmp);
51 }
52
53 class FuzzyComparisonMetricCase : public tcu::TestCase
54 {
55 public:
FuzzyComparisonMetricCase(tcu::TestContext & testCtx,const char * name,const char * refImg,const char * cmpImg,const float minBound,const float maxBound)56 FuzzyComparisonMetricCase(tcu::TestContext &testCtx, const char *name, const char *refImg, const char *cmpImg,
57 const float minBound, const float maxBound)
58 : tcu::TestCase(testCtx, name, "")
59 , m_refImg(refImg)
60 , m_cmpImg(cmpImg)
61 , m_minBound(minBound)
62 , m_maxBound(maxBound)
63 {
64 }
65
iterate(void)66 IterateResult iterate(void)
67 {
68 tcu::TextureLevel refImg;
69 tcu::TextureLevel cmpImg;
70 tcu::TextureLevel errorMask;
71 tcu::FuzzyCompareParams params;
72 float result = 0.0f;
73 uint64_t compareTime = 0;
74
75 params.maxSampleSkip = 0;
76
77 tcu::ImageIO::loadImage(refImg, m_testCtx.getArchive(), de::FilePath::join(BASE_DIR, m_refImg).getPath());
78 tcu::ImageIO::loadImage(cmpImg, m_testCtx.getArchive(), de::FilePath::join(BASE_DIR, m_cmpImg).getPath());
79
80 errorMask.setStorage(refImg.getFormat(), refImg.getWidth(), refImg.getHeight(), refImg.getDepth());
81
82 {
83 const uint64_t startTime = deGetMicroseconds();
84 result = tcu::fuzzyCompare(params, refImg, cmpImg, errorMask);
85 compareTime = deGetMicroseconds() - startTime;
86 }
87
88 m_testCtx.getLog() << TestLog::Image("RefImage", "Reference Image", refImg)
89 << TestLog::Image("CmpImage", "Compare Image", cmpImg)
90 << TestLog::Image("ErrorMask", "Error Mask", errorMask);
91
92 m_testCtx.getLog() << TestLog::Float("Result", "Result metric", "", QP_KEY_TAG_NONE, result)
93 << TestLog::Float("MinBound", "Minimum bound", "", QP_KEY_TAG_NONE, m_minBound)
94 << TestLog::Float("MaxBound", "Maximum bound", "", QP_KEY_TAG_NONE, m_maxBound)
95 << TestLog::Integer("CompareTime", "Comparison time", "us", QP_KEY_TAG_TIME, compareTime);
96
97 {
98 const bool isOk = de::inRange(result, m_minBound, m_maxBound);
99 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
100 isOk ? "Pass" : "Metric out of bounds");
101 }
102
103 return STOP;
104 }
105
106 private:
107 const std::string m_refImg;
108 const std::string m_cmpImg;
109 const float m_minBound;
110 const float m_maxBound;
111 };
112
113 class BilinearCompareCase : public tcu::TestCase
114 {
115 public:
BilinearCompareCase(tcu::TestContext & testCtx,const char * name,const char * refImg,const char * cmpImg,const tcu::RGBA & threshold,bool expectedResult)116 BilinearCompareCase(tcu::TestContext &testCtx, const char *name, const char *refImg, const char *cmpImg,
117 const tcu::RGBA &threshold, bool expectedResult)
118 : tcu::TestCase(testCtx, name, "")
119 , m_refImg(refImg)
120 , m_cmpImg(cmpImg)
121 , m_threshold(threshold)
122 , m_expectedResult(expectedResult)
123 {
124 }
125
iterate(void)126 IterateResult iterate(void)
127 {
128 tcu::TextureLevel refImg;
129 tcu::TextureLevel cmpImg;
130 bool result;
131 uint64_t compareTime = 0;
132
133 loadImageRGBA8(refImg, m_testCtx.getArchive(), de::FilePath::join(BASE_DIR, m_refImg).getPath());
134 loadImageRGBA8(cmpImg, m_testCtx.getArchive(), de::FilePath::join(BASE_DIR, m_cmpImg).getPath());
135
136 {
137 const uint64_t startTime = deGetMicroseconds();
138 result = tcu::bilinearCompare(m_testCtx.getLog(), "CompareResult", "Image comparison result", refImg,
139 cmpImg, m_threshold, tcu::COMPARE_LOG_EVERYTHING);
140 compareTime = deGetMicroseconds() - startTime;
141 }
142
143 m_testCtx.getLog() << TestLog::Integer("CompareTime", "Comparison time", "us", QP_KEY_TAG_TIME, compareTime);
144
145 {
146 const bool isOk = result == m_expectedResult;
147 m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
148 isOk ? "Pass" : "Wrong comparison result");
149 }
150
151 return STOP;
152 }
153
154 private:
155 const std::string m_refImg;
156 const std::string m_cmpImg;
157 const tcu::RGBA m_threshold;
158 const bool m_expectedResult;
159 };
160
161 class FuzzyComparisonMetricTests : public tcu::TestCaseGroup
162 {
163 public:
FuzzyComparisonMetricTests(tcu::TestContext & testCtx)164 FuzzyComparisonMetricTests(tcu::TestContext &testCtx)
165 : tcu::TestCaseGroup(testCtx, "fuzzy_metric", "Fuzzy comparison metrics")
166 {
167 }
168
init(void)169 void init(void)
170 {
171 addChild(
172 new FuzzyComparisonMetricCase(m_testCtx, "identical", "cube_ref.png", "cube_ref.png", 0.0f, 0.000001f));
173 addChild(new FuzzyComparisonMetricCase(m_testCtx, "cube", "cube_ref.png", "cube_cmp.png", 0.0029f, 0.0031f));
174 addChild(
175 new FuzzyComparisonMetricCase(m_testCtx, "cube_2", "cube_2_ref.png", "cube_2_cmp.png", 0.0134f, 0.0140f));
176 addChild(new FuzzyComparisonMetricCase(m_testCtx, "cube_sphere", "cube_sphere_ref.png", "cube_sphere_cmp.png",
177 0.0730f, 0.0801f));
178 addChild(new FuzzyComparisonMetricCase(m_testCtx, "cube_nmap", "cube_nmap_ref.png", "cube_nmap_cmp.png",
179 0.0022f, 0.0025f));
180 addChild(new FuzzyComparisonMetricCase(m_testCtx, "cube_nmap_2", "cube_nmap_2_ref.png", "cube_nmap_2_cmp.png",
181 0.0172f, 0.0189f));
182 addChild(new FuzzyComparisonMetricCase(m_testCtx, "earth_diffuse", "earth_diffuse_ref.png",
183 "earth_diffuse_cmp.png", 0.0f, 0.00002f));
184 addChild(new FuzzyComparisonMetricCase(m_testCtx, "eath_texture", "earth_texture_ref.png",
185 "earth_texture_cmp.png", 0.0002f, 0.0003f));
186 addChild(new FuzzyComparisonMetricCase(m_testCtx, "earth_spot", "earth_spot_ref.png", "earth_spot_cmp.png",
187 0.0015f, 0.0018f));
188 addChild(new FuzzyComparisonMetricCase(m_testCtx, "earth_light", "earth_light_ref.png", "earth_light_cmp.png",
189 1.7050f, 1.7070f));
190 addChild(new FuzzyComparisonMetricCase(m_testCtx, "lessThan0", "lessThan0-reference.png",
191 "lessThan0-result.png", 0.0003f, 0.0004f));
192 addChild(new FuzzyComparisonMetricCase(m_testCtx, "cube_sphere_2", "cube_sphere_2_ref.png",
193 "cube_sphere_2_cmp.png", 0.0207f, 0.0230f));
194 addChild(new FuzzyComparisonMetricCase(m_testCtx, "earth_to_empty", "earth_spot_ref.png", "empty_256x256.png",
195 54951.0f, 54955.0f));
196 }
197 };
198
199 class BilinearCompareTests : public tcu::TestCaseGroup
200 {
201 public:
BilinearCompareTests(tcu::TestContext & testCtx)202 BilinearCompareTests(tcu::TestContext &testCtx)
203 : tcu::TestCaseGroup(testCtx, "bilinear_compare", "Bilinear Image Comparison Tests")
204 {
205 }
206
init(void)207 void init(void)
208 {
209 addChild(new BilinearCompareCase(m_testCtx, "identical", "cube_ref.png", "cube_ref.png", tcu::RGBA(0, 0, 0, 0),
210 true));
211 addChild(new BilinearCompareCase(m_testCtx, "empty_to_white", "empty_256x256.png", "white_256x256.png",
212 tcu::RGBA(7, 7, 7, 2), false));
213 addChild(new BilinearCompareCase(m_testCtx, "white_to_empty", "white_256x256.png", "empty_256x256.png",
214 tcu::RGBA(7, 7, 7, 2), false));
215 addChild(
216 new BilinearCompareCase(m_testCtx, "cube", "cube_ref.png", "cube_cmp.png", tcu::RGBA(7, 7, 7, 2), false));
217 addChild(new BilinearCompareCase(m_testCtx, "cube_2", "cube_2_ref.png", "cube_2_cmp.png", tcu::RGBA(7, 7, 7, 2),
218 false));
219 addChild(new BilinearCompareCase(m_testCtx, "cube_sphere", "cube_sphere_ref.png", "cube_sphere_cmp.png",
220 tcu::RGBA(7, 7, 7, 2), false));
221 addChild(new BilinearCompareCase(m_testCtx, "cube_nmap", "cube_nmap_ref.png", "cube_nmap_cmp.png",
222 tcu::RGBA(7, 7, 7, 2), false));
223 addChild(new BilinearCompareCase(m_testCtx, "cube_nmap_2", "cube_nmap_2_ref.png", "cube_nmap_2_cmp.png",
224 tcu::RGBA(7, 7, 7, 2), false));
225 addChild(new BilinearCompareCase(m_testCtx, "earth_diffuse", "earth_diffuse_ref.png", "earth_diffuse_cmp.png",
226 tcu::RGBA(20, 20, 20, 2), true));
227 addChild(new BilinearCompareCase(m_testCtx, "eath_texture", "earth_texture_ref.png", "earth_texture_cmp.png",
228 tcu::RGBA(7, 7, 7, 2), false));
229 addChild(new BilinearCompareCase(m_testCtx, "earth_spot", "earth_spot_ref.png", "earth_spot_cmp.png",
230 tcu::RGBA(7, 7, 7, 2), false));
231 addChild(new BilinearCompareCase(m_testCtx, "earth_light", "earth_light_ref.png", "earth_light_cmp.png",
232 tcu::RGBA(7, 7, 7, 2), false));
233 addChild(new BilinearCompareCase(m_testCtx, "lessThan0", "lessThan0-reference.png", "lessThan0-result.png",
234 tcu::RGBA(36, 36, 36, 2), true));
235 addChild(new BilinearCompareCase(m_testCtx, "cube_sphere_2", "cube_sphere_2_ref.png", "cube_sphere_2_cmp.png",
236 tcu::RGBA(7, 7, 7, 2), false));
237 addChild(new BilinearCompareCase(m_testCtx, "earth_to_empty", "earth_spot_ref.png", "empty_256x256.png",
238 tcu::RGBA(7, 7, 7, 2), false));
239 addChild(new BilinearCompareCase(m_testCtx, "texfilter", "texfilter_ref.png", "texfilter_cmp.png",
240 tcu::RGBA(7, 7, 7, 2), true));
241 addChild(new BilinearCompareCase(m_testCtx, "refract_vtx", "refract_vtx_ref.png", "refract_vtx_cmp.png",
242 tcu::RGBA(7, 7, 7, 2), true));
243 addChild(new BilinearCompareCase(m_testCtx, "refract_frag", "refract_frag_ref.png", "refract_frag_cmp.png",
244 tcu::RGBA(7, 7, 7, 2), true));
245 addChild(new BilinearCompareCase(m_testCtx, "lessthan_vtx", "lessthan_vtx_ref.png", "lessthan_vtx_cmp.png",
246 tcu::RGBA(7, 7, 7, 2), true));
247 addChild(new BilinearCompareCase(m_testCtx, "2_units_2d", "2_units_2d_ref.png", "2_units_2d_cmp.png",
248 tcu::RGBA(7, 7, 7, 2), false));
249 addChild(new BilinearCompareCase(m_testCtx, "4_units_cube_vtx", "4_units_cube_ref.png", "4_units_cube_cmp.png",
250 tcu::RGBA(7, 7, 7, 2), false));
251 addChild(new BilinearCompareCase(m_testCtx, "texfilter_vtx_nearest", "texfilter_vtx_nearest_ref.png",
252 "texfilter_vtx_nearest_cmp.png", tcu::RGBA(7, 7, 7, 2), false));
253 addChild(new BilinearCompareCase(m_testCtx, "texfilter_vtx_linear", "texfilter_vtx_linear_ref.png",
254 "texfilter_vtx_linear_cmp.png", tcu::RGBA(7, 7, 7, 2), false));
255 addChild(new BilinearCompareCase(m_testCtx, "readpixels_msaa", "readpixels_ref.png", "readpixels_msaa.png",
256 tcu::RGBA(1, 1, 1, 1), true));
257 }
258 };
259
ImageCompareTests(tcu::TestContext & testCtx)260 ImageCompareTests::ImageCompareTests(tcu::TestContext &testCtx)
261 : tcu::TestCaseGroup(testCtx, "image_compare", "Image comparison tests")
262 {
263 }
264
~ImageCompareTests(void)265 ImageCompareTests::~ImageCompareTests(void)
266 {
267 }
268
init(void)269 void ImageCompareTests::init(void)
270 {
271 addChild(new FuzzyComparisonMetricTests(m_testCtx));
272 addChild(new BilinearCompareTests(m_testCtx));
273 }
274
275 } // namespace dit
276