glBindProgramARB dispatches to glBindProgramNV (remove _mesa_BindProgramARB).
[mesa.git] / src / mesa / main / colormac.h
1 /* $Id: colormac.h,v 1.12 2003/03/01 01:50:20 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 5.1
6 *
7 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28
29 /*
30 * Color-related macros
31 */
32
33 #ifndef COLORMAC_H
34 #define COLORMAC_H
35
36
37 #include "imports.h"
38 #include "config.h"
39 #include "macros.h"
40
41
42 #if CHAN_BITS == 8
43
44 #define BYTE_TO_CHAN(b) ((b) < 0 ? 0 : (GLchan) (b))
45 #define UBYTE_TO_CHAN(b) (b)
46 #define SHORT_TO_CHAN(s) ((s) < 0 ? 0 : (GLchan) ((s) >> 7))
47 #define USHORT_TO_CHAN(s) ((GLchan) ((s) >> 8))
48 #define INT_TO_CHAN(i) ((i) < 0 ? 0 : (GLchan) ((i) >> 23))
49 #define UINT_TO_CHAN(i) ((GLchan) ((i) >> 24))
50
51 #define CHAN_TO_UBYTE(c) (c)
52 #define CHAN_TO_FLOAT(c) UBYTE_TO_FLOAT(c)
53
54 #define CLAMPED_FLOAT_TO_CHAN(c, f) CLAMPED_FLOAT_TO_UBYTE(c, f)
55 #define UNCLAMPED_FLOAT_TO_CHAN(c, f) UNCLAMPED_FLOAT_TO_UBYTE(c, f)
56
57 #define COPY_CHAN4(DST, SRC) COPY_4UBV(DST, SRC)
58
59 #define CHAN_PRODUCT(a, b) ((GLubyte) (((GLint)(a) * ((GLint)(b) + 1)) >> 8))
60
61
62 #elif CHAN_BITS == 16
63
64 #define BYTE_TO_CHAN(b) ((b) < 0 ? 0 : (((GLchan) (b)) * 516))
65 #define UBYTE_TO_CHAN(b) ((((GLchan) (b)) << 8) | ((GLchan) (b)))
66 #define SHORT_TO_CHAN(s) ((s) < 0 ? 0 : (GLchan) (s))
67 #define USHORT_TO_CHAN(s) (s)
68 #define INT_TO_CHAN(i) ((i) < 0 ? 0 : (GLchan) ((i) >> 15))
69 #define UINT_TO_CHAN(i) ((GLchan) ((i) >> 16))
70
71 #define CHAN_TO_UBYTE(c) ((c) >> 8)
72 #define CHAN_TO_FLOAT(c) ((GLfloat) ((c) * (1.0 / CHAN_MAXF)))
73
74 #define CLAMPED_FLOAT_TO_CHAN(c, f) CLAMPED_FLOAT_TO_USHORT(c, f)
75 #define UNCLAMPED_FLOAT_TO_CHAN(c, f) UNCLAMPED_FLOAT_TO_USHORT(c, f)
76
77 #define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC)
78
79 #define CHAN_PRODUCT(a, b) ((GLchan) ((((GLuint) (a)) * ((GLuint) (b))) / 65535))
80
81
82 #elif CHAN_BITS == 32
83
84 /* XXX floating-point color channels not fully thought-out */
85 #define BYTE_TO_CHAN(b) ((GLfloat) ((b) * (1.0F / 127.0F)))
86 #define UBYTE_TO_CHAN(b) ((GLfloat) ((b) * (1.0F / 255.0F)))
87 #define SHORT_TO_CHAN(s) ((GLfloat) ((s) * (1.0F / 32767.0F)))
88 #define USHORT_TO_CHAN(s) ((GLfloat) ((s) * (1.0F / 65535.0F)))
89 #define INT_TO_CHAN(i) ((GLfloat) ((i) * (1.0F / 2147483647.0F)))
90 #define UINT_TO_CHAN(i) ((GLfloat) ((i) * (1.0F / 4294967295.0F)))
91
92 #define CHAN_TO_UBYTE(c) FLOAT_TO_UBYTE(c)
93 #define CHAN_TO_FLOAT(c) (c)
94
95 #define CLAMPED_FLOAT_TO_CHAN(c, f) c = (f)
96 #define UNCLAMPED_FLOAT_TO_CHAN(c, f) c = (f)
97
98 #define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC)
99
100 #define CHAN_PRODUCT(a, b) ((a) * (b))
101
102 #else
103
104 #error unexpected CHAN_BITS size
105
106 #endif
107
108
109
110 /*
111 * Convert 3 channels at once.
112 */
113 #define UNCLAMPED_FLOAT_TO_RGB_CHAN(dst, f) \
114 do { \
115 UNCLAMPED_FLOAT_TO_CHAN(dst[0], f[0]); \
116 UNCLAMPED_FLOAT_TO_CHAN(dst[1], f[1]); \
117 UNCLAMPED_FLOAT_TO_CHAN(dst[2], f[2]); \
118 } while (0)
119
120
121 /*
122 * Convert 4 channels at once.
123 */
124 #define UNCLAMPED_FLOAT_TO_RGBA_CHAN(dst, f) \
125 do { \
126 UNCLAMPED_FLOAT_TO_CHAN(dst[0], f[0]); \
127 UNCLAMPED_FLOAT_TO_CHAN(dst[1], f[1]); \
128 UNCLAMPED_FLOAT_TO_CHAN(dst[2], f[2]); \
129 UNCLAMPED_FLOAT_TO_CHAN(dst[3], f[3]); \
130 } while (0)
131
132
133
134 /* Generic color packing macros
135 * XXX We may move these into texutil.h at some point.
136 */
137
138 #define PACK_COLOR_8888( a, b, c, d ) \
139 (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
140
141 #define PACK_COLOR_888( a, b, c ) \
142 (((a) << 16) | ((b) << 8) | (c))
143
144 #define PACK_COLOR_565( a, b, c ) \
145 ((((a) & 0xf8) << 8) | (((b) & 0xfc) << 3) | (((c) & 0xf8) >> 3))
146
147 #define PACK_COLOR_1555( a, b, c, d ) \
148 ((((b) & 0xf8) << 7) | (((c) & 0xf8) << 2) | (((d) & 0xf8) >> 3) | \
149 ((a) ? 0x8000 : 0))
150
151 #define PACK_COLOR_4444( a, b, c, d ) \
152 ((((a) & 0xf0) << 8) | (((b) & 0xf0) << 4) | ((c) & 0xf0) | ((d) >> 4))
153
154 #define PACK_COLOR_88( a, b ) \
155 (((a) << 8) | (b))
156
157 #define PACK_COLOR_332( a, b, c ) \
158 (((a) & 0xe0) | (((b) & 0xe0) >> 3) | (((c) & 0xc0) >> 6))
159
160
161 #ifdef MESA_BIG_ENDIAN
162
163 #define PACK_COLOR_8888_LE( a, b, c, d ) PACK_COLOR_8888( d, c, b, a )
164
165 #define PACK_COLOR_565_LE( a, b, c ) \
166 (((a) & 0xf8) | (((b) & 0xe0) >> 5) | (((b) & 0x1c) << 11) | \
167 (((c) & 0xf8) << 5))
168
169 #define PACK_COLOR_1555_LE( a, b, c, d ) \
170 ((((b) & 0xf8) >> 1) | (((c) & 0xc0) >> 6) | (((c) & 0x38) << 10) | \
171 (((d) & 0xf8) << 5) | ((a) ? 0x80 : 0))
172
173 #define PACK_COLOR_4444_LE( a, b, c, d ) PACK_COLOR_4444( c, d, a, b )
174
175 #define PACK_COLOR_88_LE( a, b ) PACK_COLOR_88( b, a )
176
177 #else /* little endian */
178
179 #define PACK_COLOR_8888_LE( a, b, c, d ) PACK_COLOR_8888( a, b, c, d )
180
181 #define PACK_COLOR_565_LE( a, b, c ) PACK_COLOR_565( a, b, c )
182
183 #define PACK_COLOR_1555_LE( a, b, c, d ) PACK_COLOR_1555( a, b, c, d )
184
185 #define PACK_COLOR_4444_LE( a, b, c, d ) PACK_COLOR_4444( a, b, c, d )
186
187 #define PACK_COLOR_88_LE( a, b ) PACK_COLOR_88( a, b )
188
189 #endif /* endianness */
190
191
192 #endif /* COLORMAC_H */