1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief RGBA8888 color type.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuRGBA.hpp"
25 #include "tcuVector.hpp"
26 #include "tcuTextureUtil.hpp"
31 RGBA::RGBA (const Vec4& v)
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);
40 Vec4 RGBA::toVec (void) const
42 return Vec4(float(getRed()) / 255.0f,
43 float(getGreen()) / 255.0f,
44 float(getBlue()) / 255.0f,
45 float(getAlpha()) / 255.0f);
48 IVec4 RGBA::toIVec (void) const
50 return IVec4(getRed(), getGreen(), getBlue(), getAlpha());
53 RGBA computeAbsDiffMasked (RGBA a, RGBA b, deUint32 cmpMask)
55 deUint32 aPacked = a.getPacked();
56 deUint32 bPacked = b.getPacked();
62 if (cmpMask & RGBA::RED_MASK)
64 int ra = (aPacked >> RGBA::RED_SHIFT) & 0xFF;
65 int rb = (bPacked >> RGBA::RED_SHIFT) & 0xFF;
67 rDiff = (deUint8)deAbs32(ra - rb);
70 if (cmpMask & RGBA::GREEN_MASK)
72 int ga = (aPacked >> RGBA::GREEN_SHIFT) & 0xFF;
73 int gb = (bPacked >> RGBA::GREEN_SHIFT) & 0xFF;
75 gDiff = (deUint8)deAbs32(ga - gb);
78 if (cmpMask & RGBA::BLUE_MASK)
80 int ba = (aPacked >> RGBA::BLUE_SHIFT) & 0xFF;
81 int bb = (bPacked >> RGBA::BLUE_SHIFT) & 0xFF;
83 bDiff = (deUint8)deAbs32(ba - bb);
86 if (cmpMask & RGBA::ALPHA_MASK)
88 int aa = (aPacked >> RGBA::ALPHA_SHIFT) & 0xFF;
89 int ab = (bPacked >> RGBA::ALPHA_SHIFT) & 0xFF;
91 aDiff = (deUint8)deAbs32(aa - ab);
94 return RGBA(rDiff,gDiff,bDiff,aDiff);
97 bool compareThresholdMasked (RGBA a, RGBA b, RGBA threshold, deUint32 cmpMask)
99 return computeAbsDiffMasked(a, b, cmpMask).isBelowThreshold(threshold);