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
27 namespace tcu
28 {
29
30 const RGBA RGBA::red (0xFF, 0x0, 0x0, 0xFF);
31 const RGBA RGBA::green (0x0, 0xFF, 0x0, 0xFF);
32 const RGBA RGBA::blue (0x0, 0x0, 0xFF, 0xFF);
33 const RGBA RGBA::gray (0x80, 0x80, 0x80, 0xFF);
34 const RGBA RGBA::white (0xFF, 0xFF, 0xFF, 0xFF);
35 const RGBA RGBA::black (0x0, 0x0, 0x0, 0xFF);
36
RGBA(const Vec4 & v)37 RGBA::RGBA (const Vec4& v)
38 {
39 int r = deClamp32(int(v.x() * 255.0f + 0.5f), 0, 255);
40 int g = deClamp32(int(v.y() * 255.0f + 0.5f), 0, 255);
41 int b = deClamp32(int(v.z() * 255.0f + 0.5f), 0, 255);
42 int a = deClamp32(int(v.w() * 255.0f + 0.5f), 0, 255);
43 m_value = (a << ALPHA_SHIFT) | (r << RED_SHIFT) | (g << GREEN_SHIFT) | (b << BLUE_SHIFT);
44 }
45
toVec(void) const46 Vec4 RGBA::toVec (void) const
47 {
48 return Vec4(float(getRed()) / 255.0f,
49 float(getGreen()) / 255.0f,
50 float(getBlue()) / 255.0f,
51 float(getAlpha()) / 255.0f);
52 }
53
toIVec(void) const54 IVec4 RGBA::toIVec (void) const
55 {
56 return IVec4(getRed(), getGreen(), getBlue(), getAlpha());
57 }
58
computeAbsDiffMasked(RGBA a,RGBA b,deUint32 cmpMask)59 RGBA computeAbsDiffMasked (RGBA a, RGBA b, deUint32 cmpMask)
60 {
61 deUint32 aPacked = a.getPacked();
62 deUint32 bPacked = b.getPacked();
63 deUint8 rDiff = 0;
64 deUint8 gDiff = 0;
65 deUint8 bDiff = 0;
66 deUint8 aDiff = 0;
67
68 if (cmpMask & RGBA::RED_MASK)
69 {
70 int ra = (aPacked >> RGBA::RED_SHIFT) & 0xFF;
71 int rb = (bPacked >> RGBA::RED_SHIFT) & 0xFF;
72
73 rDiff = (deUint8)deAbs32(ra - rb);
74 }
75
76 if (cmpMask & RGBA::GREEN_MASK)
77 {
78 int ga = (aPacked >> RGBA::GREEN_SHIFT) & 0xFF;
79 int gb = (bPacked >> RGBA::GREEN_SHIFT) & 0xFF;
80
81 gDiff = (deUint8)deAbs32(ga - gb);
82 }
83
84 if (cmpMask & RGBA::BLUE_MASK)
85 {
86 int ba = (aPacked >> RGBA::BLUE_SHIFT) & 0xFF;
87 int bb = (bPacked >> RGBA::BLUE_SHIFT) & 0xFF;
88
89 bDiff = (deUint8)deAbs32(ba - bb);
90 }
91
92 if (cmpMask & RGBA::ALPHA_MASK)
93 {
94 int aa = (aPacked >> RGBA::ALPHA_SHIFT) & 0xFF;
95 int ab = (bPacked >> RGBA::ALPHA_SHIFT) & 0xFF;
96
97 aDiff = (deUint8)deAbs32(aa - ab);
98 }
99
100 return RGBA(rDiff,gDiff,bDiff,aDiff);
101 }
102
compareThresholdMasked(RGBA a,RGBA b,RGBA threshold,deUint32 cmpMask)103 bool compareThresholdMasked (RGBA a, RGBA b, RGBA threshold, deUint32 cmpMask)
104 {
105 return computeAbsDiffMasked(a, b, cmpMask).isBelowThreshold(threshold);
106 }
107
108 } // tcu
109