1 #ifndef _TCUPIXELFORMAT_HPP
2 #define _TCUPIXELFORMAT_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Pixel format descriptor.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "tcuRGBA.hpp"
32 /*--------------------------------------------------------------------*//*!
33 * \brief Fixed-point render target pixel format
34 *//*--------------------------------------------------------------------*/
42 PixelFormat (int red, int green, int blue, int alpha)
58 /*--------------------------------------------------------------------*//*!
59 * \brief Get default threshold for per-pixel comparison for this format
61 * Per-channel threshold is 2^(8-bits). If alpha channel bits are zero,
62 * threshold for that channel is 0.
63 *//*--------------------------------------------------------------------*/
64 inline RGBA getColorThreshold (void) const
70 (alphaBits > 0) ? (1 << (8 - alphaBits)) : 0);
73 static inline int convertChannel (int val, int bits)
76 return (val & 0x80) ? 0xff : 0;
79 DE_ASSERT(deInRange32(bits, 4, 8));
80 int c = val >> (8-bits);
81 return (c << (8-bits)) | (c >> (2*bits-8));
85 /*--------------------------------------------------------------------*//*!
86 * \brief Emulate reduced bit depth
88 * The color value bit depth is reduced and converted back. The lowest
89 * bits are filled by replicating the upper bits.
90 *//*--------------------------------------------------------------------*/
91 inline RGBA convertColor (const RGBA& col) const
93 return RGBA(convertChannel(col.getRed(), redBits),
94 convertChannel(col.getGreen(), greenBits),
95 convertChannel(col.getBlue(), blueBits),
96 alphaBits ? convertChannel(col.getAlpha(), alphaBits) : 0xff);
99 inline bool operator== (const PixelFormat& other) const
101 return redBits == other.redBits &&
102 greenBits == other.greenBits &&
103 blueBits == other.blueBits &&
104 alphaBits == other.alphaBits;
107 inline bool operator!= (const PixelFormat& other) const
109 return !(*this == other);
111 } DE_WARN_UNUSED_TYPE;
115 #endif // _TCUPIXELFORMAT_HPP