Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1901 | serge | 1 | /* |
2 | * Mesa 3-D graphics library |
||
3 | * Version: 7.3 |
||
4 | * |
||
5 | * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. |
||
6 | * |
||
7 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
8 | * copy of this software and associated documentation files (the "Software"), |
||
9 | * to deal in the Software without restriction, including without limitation |
||
10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
11 | * and/or sell copies of the Software, and to permit persons to whom the |
||
12 | * Software is furnished to do so, subject to the following conditions: |
||
13 | * |
||
14 | * The above copyright notice and this permission notice shall be included |
||
15 | * in all copies or substantial portions of the Software. |
||
16 | * |
||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
20 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||
21 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||
22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
23 | */ |
||
24 | |||
25 | |||
26 | /** |
||
27 | * \file colormac.h |
||
28 | * Color-related macros |
||
29 | */ |
||
30 | |||
31 | |||
32 | #ifndef COLORMAC_H |
||
33 | #define COLORMAC_H |
||
34 | |||
35 | |||
36 | #include "config.h" |
||
37 | #include "macros.h" |
||
38 | #include "mtypes.h" |
||
39 | |||
40 | |||
41 | /** \def BYTE_TO_CHAN |
||
42 | * Convert from GLbyte to GLchan */ |
||
43 | |||
44 | /** \def UBYTE_TO_CHAN |
||
45 | * Convert from GLubyte to GLchan */ |
||
46 | |||
47 | /** \def SHORT_TO_CHAN |
||
48 | * Convert from GLshort to GLchan */ |
||
49 | |||
50 | /** \def USHORT_TO_CHAN |
||
51 | * Convert from GLushort to GLchan */ |
||
52 | |||
53 | /** \def INT_TO_CHAN |
||
54 | * Convert from GLint to GLchan */ |
||
55 | |||
56 | /** \def UINT_TO_CHAN |
||
57 | * Convert from GLuint to GLchan */ |
||
58 | |||
59 | /** \def CHAN_TO_UBYTE |
||
60 | * Convert from GLchan to GLubyte */ |
||
61 | |||
62 | /** \def CHAN_TO_FLOAT |
||
63 | * Convert from GLchan to GLfloat */ |
||
64 | |||
65 | /** \def CLAMPED_FLOAT_TO_CHAN |
||
66 | * Convert from GLclampf to GLchan */ |
||
67 | |||
68 | /** \def UNCLAMPED_FLOAT_TO_CHAN |
||
69 | * Convert from GLfloat to GLchan */ |
||
70 | |||
71 | /** \def COPY_CHAN4 |
||
72 | * Copy a GLchan[4] array */ |
||
73 | |||
74 | #if CHAN_BITS == 8 |
||
75 | |||
76 | #define BYTE_TO_CHAN(b) ((b) < 0 ? 0 : (GLchan) (b)) |
||
77 | #define UBYTE_TO_CHAN(b) (b) |
||
78 | #define SHORT_TO_CHAN(s) ((s) < 0 ? 0 : (GLchan) ((s) >> 7)) |
||
79 | #define USHORT_TO_CHAN(s) ((GLchan) ((s) >> 8)) |
||
80 | #define INT_TO_CHAN(i) ((i) < 0 ? 0 : (GLchan) ((i) >> 23)) |
||
81 | #define UINT_TO_CHAN(i) ((GLchan) ((i) >> 24)) |
||
82 | |||
83 | #define CHAN_TO_UBYTE(c) (c) |
||
84 | #define CHAN_TO_FLOAT(c) UBYTE_TO_FLOAT(c) |
||
85 | |||
86 | #define CLAMPED_FLOAT_TO_CHAN(c, f) CLAMPED_FLOAT_TO_UBYTE(c, f) |
||
87 | #define UNCLAMPED_FLOAT_TO_CHAN(c, f) UNCLAMPED_FLOAT_TO_UBYTE(c, f) |
||
88 | |||
89 | #define COPY_CHAN4(DST, SRC) COPY_4UBV(DST, SRC) |
||
90 | |||
91 | #elif CHAN_BITS == 16 |
||
92 | |||
93 | #define BYTE_TO_CHAN(b) ((b) < 0 ? 0 : (((GLchan) (b)) * 516)) |
||
94 | #define UBYTE_TO_CHAN(b) ((((GLchan) (b)) << 8) | ((GLchan) (b))) |
||
95 | #define SHORT_TO_CHAN(s) ((s) < 0 ? 0 : (GLchan) (s)) |
||
96 | #define USHORT_TO_CHAN(s) (s) |
||
97 | #define INT_TO_CHAN(i) ((i) < 0 ? 0 : (GLchan) ((i) >> 15)) |
||
98 | #define UINT_TO_CHAN(i) ((GLchan) ((i) >> 16)) |
||
99 | |||
100 | #define CHAN_TO_UBYTE(c) ((c) >> 8) |
||
101 | #define CHAN_TO_FLOAT(c) ((GLfloat) ((c) * (1.0 / CHAN_MAXF))) |
||
102 | |||
103 | #define CLAMPED_FLOAT_TO_CHAN(c, f) CLAMPED_FLOAT_TO_USHORT(c, f) |
||
104 | #define UNCLAMPED_FLOAT_TO_CHAN(c, f) UNCLAMPED_FLOAT_TO_USHORT(c, f) |
||
105 | |||
106 | #define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC) |
||
107 | |||
108 | #elif CHAN_BITS == 32 |
||
109 | |||
110 | /* XXX floating-point color channels not fully thought-out */ |
||
111 | #define BYTE_TO_CHAN(b) ((GLfloat) ((b) * (1.0F / 127.0F))) |
||
112 | #define UBYTE_TO_CHAN(b) ((GLfloat) ((b) * (1.0F / 255.0F))) |
||
113 | #define SHORT_TO_CHAN(s) ((GLfloat) ((s) * (1.0F / 32767.0F))) |
||
114 | #define USHORT_TO_CHAN(s) ((GLfloat) ((s) * (1.0F / 65535.0F))) |
||
115 | #define INT_TO_CHAN(i) ((GLfloat) ((i) * (1.0F / 2147483647.0F))) |
||
116 | #define UINT_TO_CHAN(i) ((GLfloat) ((i) * (1.0F / 4294967295.0F))) |
||
117 | |||
118 | #define CHAN_TO_UBYTE(c) FLOAT_TO_UBYTE(c) |
||
119 | #define CHAN_TO_FLOAT(c) (c) |
||
120 | |||
121 | #define CLAMPED_FLOAT_TO_CHAN(c, f) c = (f) |
||
122 | #define UNCLAMPED_FLOAT_TO_CHAN(c, f) c = (f) |
||
123 | |||
124 | #define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC) |
||
125 | |||
126 | #else |
||
127 | |||
128 | #error unexpected CHAN_BITS size |
||
129 | |||
130 | #endif |
||
131 | |||
132 | |||
133 | /** |
||
134 | * Convert 3 channels at once. |
||
135 | * |
||
136 | * \param dst pointer to destination GLchan[3] array. |
||
137 | * \param f pointer to source GLfloat[3] array. |
||
138 | * |
||
139 | * \sa #UNCLAMPED_FLOAT_TO_CHAN. |
||
140 | */ |
||
141 | #define UNCLAMPED_FLOAT_TO_RGB_CHAN(dst, f) \ |
||
142 | do { \ |
||
143 | UNCLAMPED_FLOAT_TO_CHAN((dst)[0], (f)[0]); \ |
||
144 | UNCLAMPED_FLOAT_TO_CHAN((dst)[1], (f)[1]); \ |
||
145 | UNCLAMPED_FLOAT_TO_CHAN((dst)[2], (f)[2]); \ |
||
146 | } while (0) |
||
147 | |||
148 | |||
149 | /** |
||
150 | * Convert 4 channels at once. |
||
151 | * |
||
152 | * \param dst pointer to destination GLchan[4] array. |
||
153 | * \param f pointer to source GLfloat[4] array. |
||
154 | * |
||
155 | * \sa #UNCLAMPED_FLOAT_TO_CHAN. |
||
156 | */ |
||
157 | #define UNCLAMPED_FLOAT_TO_RGBA_CHAN(dst, f) \ |
||
158 | do { \ |
||
159 | UNCLAMPED_FLOAT_TO_CHAN((dst)[0], (f)[0]); \ |
||
160 | UNCLAMPED_FLOAT_TO_CHAN((dst)[1], (f)[1]); \ |
||
161 | UNCLAMPED_FLOAT_TO_CHAN((dst)[2], (f)[2]); \ |
||
162 | UNCLAMPED_FLOAT_TO_CHAN((dst)[3], (f)[3]); \ |
||
163 | } while (0) |
||
164 | |||
165 | |||
166 | |||
167 | /** |
||
168 | * \name Generic color packing macros. All inputs should be GLubytes. |
||
169 | * |
||
170 | * \todo We may move these into texstore.h at some point. |
||
171 | */ |
||
172 | /*@{*/ |
||
173 | |||
174 | #define PACK_COLOR_8888( X, Y, Z, W ) \ |
||
175 | (((X) << 24) | ((Y) << 16) | ((Z) << 8) | (W)) |
||
176 | |||
177 | #define PACK_COLOR_8888_REV( X, Y, Z, W ) \ |
||
178 | (((W) << 24) | ((Z) << 16) | ((Y) << 8) | (X)) |
||
179 | |||
180 | #define PACK_COLOR_888( X, Y, Z ) \ |
||
181 | (((X) << 16) | ((Y) << 8) | (Z)) |
||
182 | |||
183 | #define PACK_COLOR_565( X, Y, Z ) \ |
||
184 | ((((X) & 0xf8) << 8) | (((Y) & 0xfc) << 3) | (((Z) & 0xf8) >> 3)) |
||
185 | |||
186 | #define PACK_COLOR_565_REV( X, Y, Z ) \ |
||
187 | (((X) & 0xf8) | ((Y) & 0xe0) >> 5 | (((Y) & 0x1c) << 11) | (((Z) & 0xf8) << 5)) |
||
188 | |||
189 | #define PACK_COLOR_5551( R, G, B, A ) \ |
||
190 | ((((R) & 0xf8) << 8) | (((G) & 0xf8) << 3) | (((B) & 0xf8) >> 2) | \ |
||
191 | ((A) ? 1 : 0)) |
||
192 | |||
193 | #define PACK_COLOR_1555( A, B, G, R ) \ |
||
194 | ((((B) & 0xf8) << 7) | (((G) & 0xf8) << 2) | (((R) & 0xf8) >> 3) | \ |
||
195 | ((A) ? 0x8000 : 0)) |
||
196 | |||
197 | #define PACK_COLOR_1555_REV( A, B, G, R ) \ |
||
198 | ((((B) & 0xf8) >> 1) | (((G) & 0xc0) >> 6) | (((G) & 0x38) << 10) | (((R) & 0xf8) << 5) | \ |
||
199 | ((A) ? 0x80 : 0)) |
||
200 | |||
201 | #define PACK_COLOR_4444( R, G, B, A ) \ |
||
202 | ((((R) & 0xf0) << 8) | (((G) & 0xf0) << 4) | ((B) & 0xf0) | ((A) >> 4)) |
||
203 | |||
204 | #define PACK_COLOR_4444_REV( R, G, B, A ) \ |
||
205 | ((((B) & 0xf0) << 8) | (((A) & 0xf0) << 4) | ((R) & 0xf0) | ((G) >> 4)) |
||
206 | |||
207 | #define PACK_COLOR_88( L, A ) \ |
||
208 | (((L) << 8) | (A)) |
||
209 | |||
210 | #define PACK_COLOR_88_REV( L, A ) \ |
||
211 | (((A) << 8) | (L)) |
||
212 | |||
213 | #define PACK_COLOR_1616( L, A ) \ |
||
214 | (((L) << 16) | (A)) |
||
215 | |||
216 | #define PACK_COLOR_1616_REV( L, A ) \ |
||
217 | (((A) << 16) | (L)) |
||
218 | |||
219 | #define PACK_COLOR_332( R, G, B ) \ |
||
220 | (((R) & 0xe0) | (((G) & 0xe0) >> 3) | (((B) & 0xc0) >> 6)) |
||
221 | |||
222 | #define PACK_COLOR_233( B, G, R ) \ |
||
223 | (((B) & 0xc0) | (((G) & 0xe0) >> 2) | (((R) & 0xe0) >> 5)) |
||
224 | |||
225 | /*@}*/ |
||
226 | |||
227 | |||
228 | #endif /* COLORMAC_H */><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>>>><>>>>> |