13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ----------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Bilinear image comparison.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuBilinearImageCompare.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTexture.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRGBA.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NUM_SUBPIXEL_BITS	= 8	//!< Number of subpixel bits used when doing bilinear interpolation.
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4074731a6adf5816339b00b854a513b1b950ad4357Pyry Haulos// \note Algorithm assumes that colors are packed to 32-bit values as dictated by
4174731a6adf5816339b00b854a513b1b950ad4357Pyry Haulos//		 tcu::RGBA::*_SHIFT values.
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<int Channel>
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline deUint8 getChannel (deUint32 color)
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (deUint8)((color >> (Channel*8)) & 0xff);
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4974731a6adf5816339b00b854a513b1b950ad4357Pyry Haulos#if (DE_ENDIANNESS == DE_LITTLE_ENDIAN)
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline deUint32 readRGBA8Raw (const ConstPixelBufferAccess& src, deUint32 x, deUint32 y)
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return *(const deUint32*)((const deUint8*)src.getDataPtr() + y*src.getRowPitch() + x*4);
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5474731a6adf5816339b00b854a513b1b950ad4357Pyry Haulos#else
5574731a6adf5816339b00b854a513b1b950ad4357Pyry Haulosinline deUint32 readRGBA8Raw (const ConstPixelBufferAccess& src, deUint32 x, deUint32 y)
5674731a6adf5816339b00b854a513b1b950ad4357Pyry Haulos{
5774731a6adf5816339b00b854a513b1b950ad4357Pyry Haulos	return deReverseBytes32(*(const deUint32*)((const deUint8*)src.getDataPtr() + y*src.getRowPitch() + x*4));
5874731a6adf5816339b00b854a513b1b950ad4357Pyry Haulos}
5974731a6adf5816339b00b854a513b1b950ad4357Pyry Haulos#endif
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline RGBA readRGBA8 (const ConstPixelBufferAccess& src, deUint32 x, deUint32 y)
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 raw = readRGBA8Raw(src, x, y);
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32 res = 0;
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res |= getChannel<0>(raw) << RGBA::RED_SHIFT;
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res |= getChannel<1>(raw) << RGBA::GREEN_SHIFT;
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res |= getChannel<2>(raw) << RGBA::BLUE_SHIFT;
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res |= getChannel<3>(raw) << RGBA::ALPHA_SHIFT;
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return RGBA(res);
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline deUint8 interpolateChannel (deUint32 fx1, deUint32 fy1, deUint8 p00, deUint8 p01, deUint8 p10, deUint8 p11)
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32 fx0		= (1u<<NUM_SUBPIXEL_BITS) - fx1;
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32 fy0		= (1u<<NUM_SUBPIXEL_BITS) - fy1;
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32 half		= 1u<<(NUM_SUBPIXEL_BITS*2 - 1);
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32 sum		= fx0*fy0*p00 + fx1*fy0*p10 + fx0*fy1*p01 + fx1*fy1*p11;
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint32 rounded	= (sum + half) >> (NUM_SUBPIXEL_BITS*2);
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(de::inRange<deUint32>(rounded, 0, 0xff));
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return (deUint8)rounded;
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
863c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRGBA bilinearSampleRGBA8 (const ConstPixelBufferAccess& access, deUint32 u, deUint32 v)
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	x0		= u>>NUM_SUBPIXEL_BITS;
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	y0		= v>>NUM_SUBPIXEL_BITS;
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	x1		= x0+1; //de::min(x0+1, (deUint32)(access.getWidth()-1));
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	y1		= y0+1; //de::min(y0+1, (deUint32)(access.getHeight()-1));
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(x1 < (deUint32)access.getWidth());
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(y1 < (deUint32)access.getHeight());
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	fx1		= u-(x0<<NUM_SUBPIXEL_BITS);
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	fy1		= v-(y0<<NUM_SUBPIXEL_BITS);
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	p00		= readRGBA8Raw(access, x0, y0);
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	p10		= readRGBA8Raw(access, x1, y0);
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	p01		= readRGBA8Raw(access, x0, y1);
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	p11		= readRGBA8Raw(access, x1, y1);
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32	res		= 0;
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res |= interpolateChannel(fx1, fy1, getChannel<0>(p00), getChannel<0>(p01), getChannel<0>(p10), getChannel<0>(p11)) << RGBA::RED_SHIFT;
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res |= interpolateChannel(fx1, fy1, getChannel<1>(p00), getChannel<1>(p01), getChannel<1>(p10), getChannel<1>(p11)) << RGBA::GREEN_SHIFT;
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res |= interpolateChannel(fx1, fy1, getChannel<2>(p00), getChannel<2>(p01), getChannel<2>(p10), getChannel<2>(p11)) << RGBA::BLUE_SHIFT;
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res |= interpolateChannel(fx1, fy1, getChannel<3>(p00), getChannel<3>(p01), getChannel<3>(p10), getChannel<3>(p11)) << RGBA::ALPHA_SHIFT;
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return RGBA(res);
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool comparePixelRGBA8 (const ConstPixelBufferAccess& reference, const ConstPixelBufferAccess& result, const RGBA threshold, int x, int y)
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const RGBA resPix = readRGBA8(result, (deUint32)x, (deUint32)y);
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Step 1: Compare result pixel to 3x3 neighborhood pixels in reference.
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint32	x0		= (deUint32)de::max(x-1, 0);
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint32	x1		= (deUint32)x;
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint32	x2		= (deUint32)de::min(x+1, reference.getWidth()-1);
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint32	y0		= (deUint32)de::max(y-1, 0);
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint32	y1		= (deUint32)y;
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const deUint32	y2		= (deUint32)de::min(y+1, reference.getHeight()-1);
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (compareThreshold(resPix, readRGBA8(reference, x1, y1), threshold) ||
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			compareThreshold(resPix, readRGBA8(reference, x0, y1), threshold) ||
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			compareThreshold(resPix, readRGBA8(reference, x2, y1), threshold) ||
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			compareThreshold(resPix, readRGBA8(reference, x0, y0), threshold) ||
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			compareThreshold(resPix, readRGBA8(reference, x1, y0), threshold) ||
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			compareThreshold(resPix, readRGBA8(reference, x2, y0), threshold) ||
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			compareThreshold(resPix, readRGBA8(reference, x0, y2), threshold) ||
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			compareThreshold(resPix, readRGBA8(reference, x1, y2), threshold) ||
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			compareThreshold(resPix, readRGBA8(reference, x2, y2), threshold))
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return true;
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Step 2: Compare using bilinear sampling.
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// \todo [pyry] Optimize sample positions!
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		static const deUint32 s_offsets[][2] =
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 226, 186 },
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 335, 235 },
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 279, 334 },
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 178, 272 },
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 112, 202 },
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 306, 117 },
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 396, 299 },
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 206, 382 },
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 146,  96 },
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 423, 155 },
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 361, 412 },
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{  84, 339 },
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{  48, 130 },
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 367,  43 },
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 455, 367 },
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 105, 439 },
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{  83,  46 },
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 217,  24 },
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 461,  71 },
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 450, 459 },
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 239, 469 },
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{  67, 267 },
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 459, 255 },
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{  13, 416 },
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{  10, 192 },
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 141, 502 },
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 503, 304 },
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{ 380, 506 }
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		};
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int sampleNdx = 0; sampleNdx < DE_LENGTH_OF_ARRAY(s_offsets); sampleNdx++)
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int u = ((x-1)<<NUM_SUBPIXEL_BITS) + (int)s_offsets[sampleNdx][0];
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const int v = ((y-1)<<NUM_SUBPIXEL_BITS) + (int)s_offsets[sampleNdx][1];
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!de::inBounds(u, 0, (reference.getWidth()-1)<<NUM_SUBPIXEL_BITS) ||
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				!de::inBounds(v, 0, (reference.getHeight()-1)<<NUM_SUBPIXEL_BITS))
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				continue;
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (compareThreshold(resPix, bilinearSampleRGBA8(reference, (deUint32)u, (deUint32)v), threshold))
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				return true;
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return false;
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool bilinearCompareRGBA8 (const ConstPixelBufferAccess& reference, const ConstPixelBufferAccess& result, const PixelBufferAccess& errorMask, const RGBA threshold)
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(reference.getFormat() == TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8) &&
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			  result.getFormat()	== TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8));
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Clear error mask first to green (faster this way).
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	clear(errorMask, Vec4(0.0f, 1.0f, 0.0f, 1.0f));
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool allOk = true;
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int y = 0; y < reference.getHeight(); y++)
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int x = 0; x < reference.getWidth(); x++)
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (!comparePixelRGBA8(reference, result, threshold, x, y) &&
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				!comparePixelRGBA8(result, reference, threshold, x, y))
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				allOk = false;
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				errorMask.setPixel(Vec4(1.0f, 0.0f, 0.0f, 1.0f), x, y);
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return allOk;
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool bilinearCompare (const ConstPixelBufferAccess& reference, const ConstPixelBufferAccess& result, const PixelBufferAccess& errorMask, const RGBA threshold)
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(reference.getWidth()	== result.getWidth()	&&
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			  reference.getHeight()	== result.getHeight()	&&
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			  reference.getDepth()	== result.getDepth()	&&
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			  reference.getFormat()	== result.getFormat());
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(reference.getWidth()	== errorMask.getWidth()		&&
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			  reference.getHeight()	== errorMask.getHeight()	&&
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			  reference.getDepth()	== errorMask.getDepth());
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (reference.getFormat() == TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8))
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return bilinearCompareRGBA8(reference, result, errorMask, threshold);
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw InternalError("Unsupported format for bilinear comparison");
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu
236