1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Tester Core
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 RGBA8888 color type.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "tcuRGBA.hpp"
25 #include "tcuVector.hpp"
26 #include "tcuTextureUtil.hpp"
27 
28 namespace tcu
29 {
30 
RGBA(const Vec4 & v)31 RGBA::RGBA (const Vec4& v)
32 {
33 	const deUint32 r = (deUint32)floatToU8(v.x());
34 	const deUint32 g = (deUint32)floatToU8(v.y());
35 	const deUint32 b = (deUint32)floatToU8(v.z());
36 	const deUint32 a = (deUint32)floatToU8(v.w());
37 	m_value = (a << ALPHA_SHIFT) | (r << RED_SHIFT) | (g << GREEN_SHIFT) | (b << BLUE_SHIFT);
38 }
39 
toVec(void) const40 Vec4 RGBA::toVec (void) const
41 {
42 	return Vec4(float(getRed())		/ 255.0f,
43 				float(getGreen())	/ 255.0f,
44 				float(getBlue())	/ 255.0f,
45 				float(getAlpha())	/ 255.0f);
46 }
47 
toIVec(void) const48 IVec4 RGBA::toIVec (void) const
49 {
50 	return IVec4(getRed(), getGreen(), getBlue(), getAlpha());
51 }
52 
computeAbsDiffMasked(RGBA a,RGBA b,deUint32 cmpMask)53 RGBA computeAbsDiffMasked (RGBA a, RGBA b, deUint32 cmpMask)
54 {
55 	deUint32	aPacked = a.getPacked();
56 	deUint32	bPacked = b.getPacked();
57 	deUint8		rDiff	= 0;
58 	deUint8		gDiff	= 0;
59 	deUint8		bDiff	= 0;
60 	deUint8		aDiff	= 0;
61 
62 	if (cmpMask & RGBA::RED_MASK)
63 	{
64 		int ra = (aPacked >> RGBA::RED_SHIFT) & 0xFF;
65 		int rb = (bPacked >> RGBA::RED_SHIFT) & 0xFF;
66 
67 		rDiff = (deUint8)deAbs32(ra - rb);
68 	}
69 
70 	if (cmpMask & RGBA::GREEN_MASK)
71 	{
72 		int ga = (aPacked >> RGBA::GREEN_SHIFT) & 0xFF;
73 		int gb = (bPacked >> RGBA::GREEN_SHIFT) & 0xFF;
74 
75 		gDiff = (deUint8)deAbs32(ga - gb);
76 	}
77 
78 	if (cmpMask & RGBA::BLUE_MASK)
79 	{
80 		int ba = (aPacked >> RGBA::BLUE_SHIFT) & 0xFF;
81 		int bb = (bPacked >> RGBA::BLUE_SHIFT) & 0xFF;
82 
83 		bDiff = (deUint8)deAbs32(ba - bb);
84 	}
85 
86 	if (cmpMask & RGBA::ALPHA_MASK)
87 	{
88 		int aa = (aPacked >> RGBA::ALPHA_SHIFT) & 0xFF;
89 		int ab = (bPacked >> RGBA::ALPHA_SHIFT) & 0xFF;
90 
91 		aDiff = (deUint8)deAbs32(aa - ab);
92 	}
93 
94 	return RGBA(rDiff,gDiff,bDiff,aDiff);
95 }
96 
compareThresholdMasked(RGBA a,RGBA b,RGBA threshold,deUint32 cmpMask)97 bool compareThresholdMasked	(RGBA a, RGBA b, RGBA threshold, deUint32 cmpMask)
98 {
99 	return computeAbsDiffMasked(a, b, cmpMask).isBelowThreshold(threshold);
100 }
101 
102 } // tcu
103