• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _TCUPIXELFORMAT_HPP
2 #define _TCUPIXELFORMAT_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Tester Core
5  * ----------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  *//*!
22  * \file
23  * \brief Pixel format descriptor.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tcuRGBA.hpp"
28 
29 namespace tcu
30 {
31 
32 /*--------------------------------------------------------------------*//*!
33  * \brief Fixed-point render target pixel format
34  *//*--------------------------------------------------------------------*/
35 struct PixelFormat
36 {
37 	int redBits;
38 	int greenBits;
39 	int blueBits;
40 	int alphaBits;
41 
PixelFormattcu::PixelFormat42 	PixelFormat (int red, int green, int blue, int alpha)
43 		: redBits(red)
44 		, greenBits(green)
45 		, blueBits(blue)
46 		, alphaBits(alpha)
47 	{
48 	}
49 
PixelFormattcu::PixelFormat50 	PixelFormat (void)
51 		: redBits(0)
52 		, greenBits(0)
53 		, blueBits(0)
54 		, alphaBits(0)
55 	{
56 	}
57 
58 	/*--------------------------------------------------------------------*//*!
59 	 * \brief Get default threshold for per-pixel comparison for this format
60 	 *
61 	 * Per-channel threshold is 2^(8-bits). If alpha channel bits are zero,
62 	 * threshold for that channel is 0.
63 	 *//*--------------------------------------------------------------------*/
getColorThresholdtcu::PixelFormat64 	inline RGBA getColorThreshold (void) const
65 	{
66 		return RGBA(
67 			1 << (8 - redBits),
68 			1 << (8 - greenBits),
69 			1 << (8 - blueBits),
70 			(alphaBits > 0) ? (1 << (8 - alphaBits)) : 0);
71 	}
72 
convertChanneltcu::PixelFormat73 	static inline int convertChannel (int val, int bits)
74 	{
75 		if (bits == 1)
76 			return (val & 0x80) ? 0xff : 0;
77 		else
78 		{
79 			DE_ASSERT(deInRange32(bits, 4, 8));
80 			int c = val >> (8-bits);
81 			return (c << (8-bits)) | (c >> (2*bits-8));
82 		}
83 	}
84 
85 	/*--------------------------------------------------------------------*//*!
86 	 * \brief Emulate reduced bit depth
87 	 *
88 	 * The color value bit depth is reduced and converted back. The lowest
89 	 * bits are filled by replicating the upper bits.
90 	 *//*--------------------------------------------------------------------*/
convertColortcu::PixelFormat91 	inline RGBA convertColor (const RGBA& col) const
92 	{
93 		return RGBA(convertChannel(col.getRed(),	redBits),
94 					convertChannel(col.getGreen(),	greenBits),
95 					convertChannel(col.getBlue(),	blueBits),
96 					alphaBits ? convertChannel(col.getAlpha(), alphaBits) : 0xff);
97 	}
98 
operator ==tcu::PixelFormat99 	inline bool operator== (const PixelFormat& other) const
100 	{
101 		return redBits		== other.redBits	&&
102 			   greenBits	== other.greenBits	&&
103 			   blueBits		== other.blueBits	&&
104 			   alphaBits	== other.alphaBits;
105 	}
106 
operator !=tcu::PixelFormat107 	inline bool operator!= (const PixelFormat& other) const
108 	{
109 		return !(*this == other);
110 	}
111 } DE_WARN_UNUSED_TYPE;
112 
113 } // namespace tcu
114 
115 #endif // _TCUPIXELFORMAT_HPP
116