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 static inline int channelThreshold(int bits)
62 // Threshold is 2^(8 - bits)
63 return 1 << (8 - bits);
67 // Threshold is bound by the 8-bit buffer value
72 /*--------------------------------------------------------------------*//*!
73 * \brief Get default threshold for per-pixel comparison for this format
75 * Per-channel threshold is 2^(8-bits). If alpha channel bits are zero,
76 * threshold for that channel is 0.
77 *//*--------------------------------------------------------------------*/
78 inline RGBA getColorThreshold (void) const
81 channelThreshold(redBits),
82 channelThreshold(greenBits),
83 channelThreshold(blueBits),
84 alphaBits ? channelThreshold(alphaBits) : 0);
87 static inline int convertChannel (int val, int bits)
95 return (val & 0x80) ? 0xff : 0;
99 // Emulate precision reduction by replicating the upper bits as the fractional component
100 int intComp = val >> (8 - bits);
101 int fractComp = (intComp << (24 - bits)) | (intComp << (24 - 2 * bits)) | (intComp << (24 - 3 * bits));
102 return (intComp << (8 - bits)) | (fractComp >> (bits + 16));
106 // Bits greater than or equal to 8 will have full precision, so no reduction
111 /*--------------------------------------------------------------------*//*!
112 * \brief Emulate reduced bit depth
114 * The color value bit depth is reduced and converted back. The lowest
115 * bits are filled by replicating the upper bits.
116 *//*--------------------------------------------------------------------*/
117 inline RGBA convertColor (const RGBA& col) const
119 return RGBA(convertChannel(col.getRed(), redBits),
120 convertChannel(col.getGreen(), greenBits),
121 convertChannel(col.getBlue(), blueBits),
122 alphaBits ? convertChannel(col.getAlpha(), alphaBits) : 0xff);
125 inline bool operator== (const PixelFormat& other) const
127 return redBits == other.redBits &&
128 greenBits == other.greenBits &&
129 blueBits == other.blueBits &&
130 alphaBits == other.alphaBits;
133 inline bool operator!= (const PixelFormat& other) const
135 return !(*this == other);
137 } DE_WARN_UNUSED_TYPE;
141 #endif // _TCUPIXELFORMAT_HPP