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 uint32_t r = (uint32_t)floatToU8(v.x());
34 const uint32_t g = (uint32_t)floatToU8(v.y());
35 const uint32_t b = (uint32_t)floatToU8(v.z());
36 const uint32_t a = (uint32_t)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, float(getGreen()) / 255.0f, float(getBlue()) / 255.0f,
43 float(getAlpha()) / 255.0f);
44 }
45
toIVec(void) const46 IVec4 RGBA::toIVec(void) const
47 {
48 return IVec4(getRed(), getGreen(), getBlue(), getAlpha());
49 }
50
computeAbsDiffMasked(RGBA a,RGBA b,uint32_t cmpMask)51 RGBA computeAbsDiffMasked(RGBA a, RGBA b, uint32_t cmpMask)
52 {
53 uint32_t aPacked = a.getPacked();
54 uint32_t bPacked = b.getPacked();
55 uint8_t rDiff = 0;
56 uint8_t gDiff = 0;
57 uint8_t bDiff = 0;
58 uint8_t aDiff = 0;
59
60 if (cmpMask & RGBA::RED_MASK)
61 {
62 int ra = (aPacked >> RGBA::RED_SHIFT) & 0xFF;
63 int rb = (bPacked >> RGBA::RED_SHIFT) & 0xFF;
64
65 rDiff = (uint8_t)deAbs32(ra - rb);
66 }
67
68 if (cmpMask & RGBA::GREEN_MASK)
69 {
70 int ga = (aPacked >> RGBA::GREEN_SHIFT) & 0xFF;
71 int gb = (bPacked >> RGBA::GREEN_SHIFT) & 0xFF;
72
73 gDiff = (uint8_t)deAbs32(ga - gb);
74 }
75
76 if (cmpMask & RGBA::BLUE_MASK)
77 {
78 int ba = (aPacked >> RGBA::BLUE_SHIFT) & 0xFF;
79 int bb = (bPacked >> RGBA::BLUE_SHIFT) & 0xFF;
80
81 bDiff = (uint8_t)deAbs32(ba - bb);
82 }
83
84 if (cmpMask & RGBA::ALPHA_MASK)
85 {
86 int aa = (aPacked >> RGBA::ALPHA_SHIFT) & 0xFF;
87 int ab = (bPacked >> RGBA::ALPHA_SHIFT) & 0xFF;
88
89 aDiff = (uint8_t)deAbs32(aa - ab);
90 }
91
92 return RGBA(rDiff, gDiff, bDiff, aDiff);
93 }
94
compareThresholdMasked(RGBA a,RGBA b,RGBA threshold,uint32_t cmpMask)95 bool compareThresholdMasked(RGBA a, RGBA b, RGBA threshold, uint32_t cmpMask)
96 {
97 return computeAbsDiffMasked(a, b, cmpMask).isBelowThreshold(threshold);
98 }
99
100 } // namespace tcu
101