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