- Fix compilation with GCC 4.0-20041219.
[reactos.git] / reactos / lib / mesa32 / src / main / texformat_tmp.h
1 /* $XFree86$ */
2 /*
3 * Mesa 3-D graphics library
4 * Version: 6.2
5 *
6 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /**
28 * \file texformat_tmp.h
29 * Texel fetch functions template.
30 *
31 * This template file is used by texformat.c to generate texel fetch functions
32 * for 1-D, 2-D and 3-D texture images.
33 *
34 * It should be expanded by defining \p DIM as the number texture dimensions
35 * (1, 2 or 3). According to the value of \p DIM a series of macros is defined
36 * for the texel lookup in the gl_texture_image::Data.
37 *
38 * \sa texformat.c and FetchTexel.
39 *
40 * \author Gareth Hughes
41 * \author Brian Paul
42 */
43
44
45 #if DIM == 1
46
47 #define CHAN_SRC( t, i, j, k, sz ) \
48 ((GLchan *)(t)->Data + (i) * (sz))
49 #define UBYTE_SRC( t, i, j, k, sz ) \
50 ((GLubyte *)(t)->Data + (i) * (sz))
51 #define USHORT_SRC( t, i, j, k ) \
52 ((GLushort *)(t)->Data + (i))
53 #define UINT_SRC( t, i, j, k ) \
54 ((GLuint *)(t)->Data + (i))
55 #define FLOAT_SRC( t, i, j, k, sz ) \
56 ((GLfloat *)(t)->Data + (i) * (sz))
57 #define HALF_SRC( t, i, j, k, sz ) \
58 ((GLhalfARB *)(t)->Data + (i) * (sz))
59
60 #define FETCH(x) fetch_texel_1d_##x
61
62 #elif DIM == 2
63
64 #define CHAN_SRC( t, i, j, k, sz ) \
65 ((GLchan *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
66 #define UBYTE_SRC( t, i, j, k, sz ) \
67 ((GLubyte *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
68 #define USHORT_SRC( t, i, j, k ) \
69 ((GLushort *)(t)->Data + ((t)->RowStride * (j) + (i)))
70 #define UINT_SRC( t, i, j, k ) \
71 ((GLuint *)(t)->Data + ((t)->RowStride * (j) + (i)))
72 #define FLOAT_SRC( t, i, j, k, sz ) \
73 ((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
74 #define HALF_SRC( t, i, j, k, sz ) \
75 ((GLhalfARB *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
76
77 #define FETCH(x) fetch_texel_2d_##x
78
79 #elif DIM == 3
80
81 #define CHAN_SRC( t, i, j, k, sz ) \
82 (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \
83 (t)->RowStride + (i)) * (sz)
84 #define UBYTE_SRC( t, i, j, k, sz ) \
85 ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \
86 (t)->RowStride + (i)) * (sz))
87 #define USHORT_SRC( t, i, j, k ) \
88 ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \
89 (t)->RowStride + (i)))
90 #define UINT_SRC( t, i, j, k ) \
91 ((GLuint *)(t)->Data + (((t)->Height * (k) + (j)) * \
92 (t)->RowStride + (i)))
93 #define FLOAT_SRC( t, i, j, k, sz ) \
94 ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \
95 (t)->RowStride + (i)) * (sz))
96 #define HALF_SRC( t, i, j, k, sz ) \
97 ((GLhalfARB *)(t)->Data + (((t)->Height * (k) + (j)) * \
98 (t)->RowStride + (i)) * (sz))
99
100 #define FETCH(x) fetch_texel_3d_##x
101
102 #else
103 #error illegal number of texture dimensions
104 #endif
105
106
107 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
108 static void FETCH(rgba)( const struct gl_texture_image *texImage,
109 GLint i, GLint j, GLint k, GLchan *texel )
110 {
111 const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 );
112 COPY_CHAN4( texel, src );
113 }
114
115 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
116 static void FETCH(f_rgba)( const struct gl_texture_image *texImage,
117 GLint i, GLint j, GLint k, GLfloat *texel )
118 {
119 const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 );
120 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
121 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
122 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
123 texel[ACOMP] = CHAN_TO_FLOAT(src[3]);
124 }
125
126
127 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
128 static void FETCH(rgb)( const struct gl_texture_image *texImage,
129 GLint i, GLint j, GLint k, GLchan *texel )
130 {
131 const GLchan *src = CHAN_SRC( texImage, i, j, k, 3 );
132 texel[RCOMP] = src[0];
133 texel[GCOMP] = src[1];
134 texel[BCOMP] = src[2];
135 texel[ACOMP] = CHAN_MAX;
136 }
137
138 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
139 static void FETCH(f_rgb)( const struct gl_texture_image *texImage,
140 GLint i, GLint j, GLint k, GLfloat *texel )
141 {
142 const GLchan *src = CHAN_SRC( texImage, i, j, k, 3 );
143 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
144 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
145 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
146 texel[ACOMP] = CHAN_MAXF;
147 }
148
149 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
150 static void FETCH(alpha)( const struct gl_texture_image *texImage,
151 GLint i, GLint j, GLint k, GLchan *texel )
152 {
153 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
154 texel[RCOMP] =
155 texel[GCOMP] =
156 texel[BCOMP] = 0;
157 texel[ACOMP] = src[0];
158 }
159
160 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLfloats */
161 static void FETCH(f_alpha)( const struct gl_texture_image *texImage,
162 GLint i, GLint j, GLint k, GLfloat *texel )
163 {
164 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
165 texel[RCOMP] =
166 texel[GCOMP] =
167 texel[BCOMP] = 0.0;
168 texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
169 }
170
171 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
172 static void FETCH(luminance)( const struct gl_texture_image *texImage,
173 GLint i, GLint j, GLint k, GLchan *texel )
174 {
175 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
176 texel[RCOMP] =
177 texel[GCOMP] =
178 texel[BCOMP] = src[0];
179 texel[ACOMP] = CHAN_MAX;
180 }
181
182 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
183 static void FETCH(f_luminance)( const struct gl_texture_image *texImage,
184 GLint i, GLint j, GLint k, GLfloat *texel )
185 {
186 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
187 texel[RCOMP] =
188 texel[GCOMP] =
189 texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
190 texel[ACOMP] = CHAN_MAXF;
191 }
192
193 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
194 static void FETCH(luminance_alpha)( const struct gl_texture_image *texImage,
195 GLint i, GLint j, GLint k, GLchan *texel )
196 {
197 const GLchan *src = CHAN_SRC( texImage, i, j, k, 2 );
198 texel[RCOMP] = src[0];
199 texel[GCOMP] = src[0];
200 texel[BCOMP] = src[0];
201 texel[ACOMP] = src[1];
202 }
203
204 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLfloats */
205 static void FETCH(f_luminance_alpha)( const struct gl_texture_image *texImage,
206 GLint i, GLint j, GLint k, GLfloat *texel )
207 {
208 const GLchan *src = CHAN_SRC( texImage, i, j, k, 2 );
209 texel[RCOMP] =
210 texel[GCOMP] =
211 texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
212 texel[ACOMP] = CHAN_TO_FLOAT(src[1]);
213 }
214
215
216 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
217 static void FETCH(intensity)( const struct gl_texture_image *texImage,
218 GLint i, GLint j, GLint k, GLchan *texel )
219 {
220 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
221 texel[RCOMP] = src[0];
222 texel[GCOMP] = src[0];
223 texel[BCOMP] = src[0];
224 texel[ACOMP] = src[0];
225 }
226
227 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLfloats */
228 static void FETCH(f_intensity)( const struct gl_texture_image *texImage,
229 GLint i, GLint j, GLint k, GLfloat *texel )
230 {
231 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
232 texel[RCOMP] =
233 texel[GCOMP] =
234 texel[BCOMP] =
235 texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
236 }
237
238
239 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
240 * returning 1 GLfloat.
241 * Note: no GLchan version of this function.
242 */
243 static void FETCH(f_depth_component_f32)( const struct gl_texture_image *texImage,
244 GLint i, GLint j, GLint k, GLfloat *texel )
245 {
246 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
247 texel[0] = src[0];
248 }
249
250
251 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
252 * returning 1 GLfloat.
253 * Note: no GLchan version of this function.
254 */
255 static void FETCH(f_depth_component16)( const struct gl_texture_image *texImage,
256 GLint i, GLint j, GLint k, GLfloat *texel )
257 {
258 const GLushort *src = USHORT_SRC( texImage, i, j, k );
259 texel[0] = src[0] * (1.0F / 65535.0F);
260 }
261
262
263 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture,
264 * returning 4 GLchans.
265 */
266 static void FETCH(rgba_f32)( const struct gl_texture_image *texImage,
267 GLint i, GLint j, GLint k, GLchan *texel )
268 {
269 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 4 );
270 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
271 UNCLAMPED_FLOAT_TO_CHAN(texel[GCOMP], src[1]);
272 UNCLAMPED_FLOAT_TO_CHAN(texel[BCOMP], src[2]);
273 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], src[3]);
274 }
275
276 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture,
277 * returning 4 GLfloats.
278 */
279 static void FETCH(f_rgba_f32)( const struct gl_texture_image *texImage,
280 GLint i, GLint j, GLint k, GLfloat *texel )
281 {
282 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 4 );
283 texel[RCOMP] = src[0];
284 texel[GCOMP] = src[1];
285 texel[BCOMP] = src[2];
286 texel[ACOMP] = src[3];
287 }
288
289 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
290 * returning 4 GLchans.
291 */
292 static void FETCH(rgba_f16)( const struct gl_texture_image *texImage,
293 GLint i, GLint j, GLint k, GLchan *texel )
294 {
295 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 4 );
296 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
297 UNCLAMPED_FLOAT_TO_CHAN(texel[GCOMP], _mesa_half_to_float(src[1]));
298 UNCLAMPED_FLOAT_TO_CHAN(texel[BCOMP], _mesa_half_to_float(src[2]));
299 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], _mesa_half_to_float(src[3]));
300 }
301
302 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
303 * returning 4 GLfloats.
304 */
305 static void FETCH(f_rgba_f16)( const struct gl_texture_image *texImage,
306 GLint i, GLint j, GLint k, GLfloat *texel )
307 {
308 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 4 );
309 texel[RCOMP] = _mesa_half_to_float(src[0]);
310 texel[GCOMP] = _mesa_half_to_float(src[1]);
311 texel[BCOMP] = _mesa_half_to_float(src[2]);
312 texel[ACOMP] = _mesa_half_to_float(src[3]);
313 }
314
315 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
316 * returning 4 GLchans.
317 */
318 static void FETCH(rgb_f32)( const struct gl_texture_image *texImage,
319 GLint i, GLint j, GLint k, GLchan *texel )
320 {
321 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 3 );
322 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
323 UNCLAMPED_FLOAT_TO_CHAN(texel[GCOMP], src[1]);
324 UNCLAMPED_FLOAT_TO_CHAN(texel[BCOMP], src[2]);
325 texel[ACOMP] = CHAN_MAX;
326 }
327
328 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
329 * returning 4 GLfloats.
330 */
331 static void FETCH(f_rgb_f32)( const struct gl_texture_image *texImage,
332 GLint i, GLint j, GLint k, GLfloat *texel )
333 {
334 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 3 );
335 texel[RCOMP] = src[0];
336 texel[GCOMP] = src[1];
337 texel[BCOMP] = src[2];
338 texel[ACOMP] = CHAN_MAXF;
339 }
340
341 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
342 * returning 4 GLchans.
343 */
344 static void FETCH(rgb_f16)( const struct gl_texture_image *texImage,
345 GLint i, GLint j, GLint k, GLchan *texel )
346 {
347 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 3 );
348 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
349 UNCLAMPED_FLOAT_TO_CHAN(texel[GCOMP], _mesa_half_to_float(src[1]));
350 UNCLAMPED_FLOAT_TO_CHAN(texel[BCOMP], _mesa_half_to_float(src[2]));
351 texel[ACOMP] = CHAN_MAX;
352 }
353
354 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
355 * returning 4 GLfloats.
356 */
357 static void FETCH(f_rgb_f16)( const struct gl_texture_image *texImage,
358 GLint i, GLint j, GLint k, GLfloat *texel )
359 {
360 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 3 );
361 texel[RCOMP] = _mesa_half_to_float(src[0]);
362 texel[GCOMP] = _mesa_half_to_float(src[1]);
363 texel[BCOMP] = _mesa_half_to_float(src[2]);
364 texel[ACOMP] = CHAN_MAXF;
365 }
366
367 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
368 * returning 4 GLchans.
369 */
370 static void FETCH(alpha_f32)( const struct gl_texture_image *texImage,
371 GLint i, GLint j, GLint k, GLchan *texel )
372 {
373 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
374 texel[RCOMP] =
375 texel[GCOMP] =
376 texel[BCOMP] = 0;
377 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], src[0]);
378 }
379
380 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
381 * returning 4 GLfloats.
382 */
383 static void FETCH(f_alpha_f32)( const struct gl_texture_image *texImage,
384 GLint i, GLint j, GLint k, GLfloat *texel )
385 {
386 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
387 texel[RCOMP] =
388 texel[GCOMP] =
389 texel[BCOMP] = 0.0F;
390 texel[ACOMP] = src[0];
391 }
392
393 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
394 * returning 4 GLchans.
395 */
396 static void FETCH(alpha_f16)( const struct gl_texture_image *texImage,
397 GLint i, GLint j, GLint k, GLchan *texel )
398 {
399 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 1 );
400 texel[RCOMP] =
401 texel[GCOMP] =
402 texel[BCOMP] = 0;
403 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], _mesa_half_to_float(src[0]));
404 }
405
406 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
407 * returning 4 GLfloats.
408 */
409 static void FETCH(f_alpha_f16)( const struct gl_texture_image *texImage,
410 GLint i, GLint j, GLint k, GLfloat *texel )
411 {
412 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 1 );
413 texel[RCOMP] =
414 texel[GCOMP] =
415 texel[BCOMP] = 0.0F;
416 texel[ACOMP] = _mesa_half_to_float(src[0]);
417 }
418
419 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
420 * returning 4 GLchans.
421 */
422 static void FETCH(luminance_f32)( const struct gl_texture_image *texImage,
423 GLint i, GLint j, GLint k, GLchan *texel )
424 {
425 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
426 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
427 texel[GCOMP] =
428 texel[BCOMP] = texel[RCOMP];
429 texel[ACOMP] = CHAN_MAX;
430 }
431
432 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
433 * returning 4 GLfloats.
434 */
435 static void FETCH(f_luminance_f32)( const struct gl_texture_image *texImage,
436 GLint i, GLint j, GLint k, GLfloat *texel )
437 {
438 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
439 texel[RCOMP] =
440 texel[GCOMP] =
441 texel[BCOMP] = src[0];
442 texel[ACOMP] = CHAN_MAXF;
443 }
444
445 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
446 * returning 4 GLchans.
447 */
448 static void FETCH(luminance_f16)( const struct gl_texture_image *texImage,
449 GLint i, GLint j, GLint k, GLchan *texel )
450 {
451 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 1 );
452 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
453 texel[GCOMP] =
454 texel[BCOMP] = texel[RCOMP];
455 texel[ACOMP] = CHAN_MAX;
456 }
457
458 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
459 * returning 4 GLfloats.
460 */
461 static void FETCH(f_luminance_f16)( const struct gl_texture_image *texImage,
462 GLint i, GLint j, GLint k, GLfloat *texel )
463 {
464 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 1 );
465 texel[RCOMP] =
466 texel[GCOMP] =
467 texel[BCOMP] = _mesa_half_to_float(src[0]);
468 texel[ACOMP] = CHAN_MAXF;
469 }
470
471 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
472 * returning 4 GLchans.
473 */
474 static void FETCH(luminance_alpha_f32)( const struct gl_texture_image *texImage,
475 GLint i, GLint j, GLint k, GLchan *texel )
476 {
477 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 2 );
478 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
479 texel[GCOMP] =
480 texel[BCOMP] = texel[RCOMP];
481 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], src[1]);
482 }
483
484 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
485 * returning 4 GLfloats.
486 */
487 static void FETCH(f_luminance_alpha_f32)( const struct gl_texture_image *texImage,
488 GLint i, GLint j, GLint k, GLfloat *texel )
489 {
490 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 2 );
491 texel[RCOMP] =
492 texel[GCOMP] =
493 texel[BCOMP] = src[0];
494 texel[ACOMP] = src[1];
495 }
496
497 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
498 * returning 4 GLfloats.
499 */
500 static void FETCH(luminance_alpha_f16)( const struct gl_texture_image *texImage,
501 GLint i, GLint j, GLint k, GLchan *texel )
502 {
503 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 2 );
504 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
505 texel[GCOMP] =
506 texel[BCOMP] = texel[RCOMP];
507 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], _mesa_half_to_float(src[1]));
508 }
509
510 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
511 * returning 4 GLfloats.
512 */
513 static void FETCH(f_luminance_alpha_f16)( const struct gl_texture_image *texImage,
514 GLint i, GLint j, GLint k, GLfloat *texel )
515 {
516 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 2 );
517 texel[RCOMP] =
518 texel[GCOMP] =
519 texel[BCOMP] = _mesa_half_to_float(src[0]);
520 texel[ACOMP] = _mesa_half_to_float(src[1]);
521 }
522
523 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
524 * returning 4 GLchans.
525 */
526 static void FETCH(intensity_f32)( const struct gl_texture_image *texImage,
527 GLint i, GLint j, GLint k, GLchan *texel )
528 {
529 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
530 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
531 texel[GCOMP] =
532 texel[BCOMP] =
533 texel[ACOMP] = texel[RCOMP];
534 }
535
536 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
537 * returning 4 GLfloats.
538 */
539 static void FETCH(f_intensity_f32)( const struct gl_texture_image *texImage,
540 GLint i, GLint j, GLint k, GLfloat *texel )
541 {
542 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
543 texel[RCOMP] =
544 texel[GCOMP] =
545 texel[BCOMP] =
546 texel[ACOMP] = src[0];
547 }
548
549 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
550 * returning 4 GLchans.
551 */
552 static void FETCH(intensity_f16)( const struct gl_texture_image *texImage,
553 GLint i, GLint j, GLint k, GLchan *texel )
554 {
555 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 1 );
556 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
557 texel[GCOMP] =
558 texel[BCOMP] =
559 texel[ACOMP] = texel[RCOMP];
560 }
561
562 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
563 * returning 4 GLfloats.
564 */
565 static void FETCH(f_intensity_f16)( const struct gl_texture_image *texImage,
566 GLint i, GLint j, GLint k, GLfloat *texel )
567 {
568 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 1 );
569 texel[RCOMP] =
570 texel[GCOMP] =
571 texel[BCOMP] =
572 texel[ACOMP] = _mesa_half_to_float(src[0]);
573 }
574
575
576
577 /*
578 * Begin Hardware formats
579 */
580
581 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
582 static void FETCH(rgba8888)( const struct gl_texture_image *texImage,
583 GLint i, GLint j, GLint k, GLchan *texel )
584 {
585 const GLuint s = *UINT_SRC( texImage, i, j, k );
586 texel[RCOMP] = UBYTE_TO_CHAN( (s >> 24) );
587 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
588 texel[BCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
589 texel[ACOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
590 }
591
592 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
593 static void FETCH(f_rgba8888)( const struct gl_texture_image *texImage,
594 GLint i, GLint j, GLint k, GLfloat *texel )
595 {
596 const GLuint s = *UINT_SRC( texImage, i, j, k );
597 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
598 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
599 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
600 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
601 }
602
603
604 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
605 static void FETCH(rgba8888_rev)( const struct gl_texture_image *texImage,
606 GLint i, GLint j, GLint k, GLchan *texel )
607 {
608 const GLuint s = *UINT_SRC( texImage, i, j, k );
609 texel[RCOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
610 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
611 texel[BCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
612 texel[ACOMP] = UBYTE_TO_CHAN( (s >> 24) );
613 }
614
615 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLfloats */
616 static void FETCH(f_rgba8888_rev)( const struct gl_texture_image *texImage,
617 GLint i, GLint j, GLint k, GLfloat *texel )
618 {
619 const GLuint s = *UINT_SRC( texImage, i, j, k );
620 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
621 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
622 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
623 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
624 }
625
626
627 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
628 static void FETCH(argb8888)( const struct gl_texture_image *texImage,
629 GLint i, GLint j, GLint k, GLchan *texel )
630 {
631 const GLuint s = *UINT_SRC( texImage, i, j, k );
632 texel[RCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
633 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
634 texel[BCOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
635 texel[ACOMP] = UBYTE_TO_CHAN( (s >> 24) );
636 }
637
638 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLfloats */
639 static void FETCH(f_argb8888)( const struct gl_texture_image *texImage,
640 GLint i, GLint j, GLint k, GLfloat *texel )
641 {
642 const GLuint s = *UINT_SRC( texImage, i, j, k );
643 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
644 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
645 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
646 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
647 }
648
649
650 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLchans */
651 static void FETCH(argb8888_rev)( const struct gl_texture_image *texImage,
652 GLint i, GLint j, GLint k, GLchan *texel )
653 {
654 const GLuint s = *UINT_SRC( texImage, i, j, k );
655 texel[RCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
656 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
657 texel[BCOMP] = UBYTE_TO_CHAN( (s >> 24) );
658 texel[ACOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
659 }
660
661
662 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
663 static void FETCH(f_argb8888_rev)( const struct gl_texture_image *texImage,
664 GLint i, GLint j, GLint k, GLfloat *texel )
665 {
666 const GLuint s = *UINT_SRC( texImage, i, j, k );
667 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
668 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
669 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
670 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
671 }
672
673
674 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
675 static void FETCH(rgb888)( const struct gl_texture_image *texImage,
676 GLint i, GLint j, GLint k, GLchan *texel )
677 {
678 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
679 texel[RCOMP] = UBYTE_TO_CHAN( src[2] );
680 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
681 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
682 texel[ACOMP] = CHAN_MAX;
683 }
684
685 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLfloats */
686 static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
687 GLint i, GLint j, GLint k, GLfloat *texel )
688 {
689 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
690 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
691 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
692 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
693 texel[ACOMP] = CHAN_MAXF;
694 }
695
696
697 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
698 static void FETCH(bgr888)( const struct gl_texture_image *texImage,
699 GLint i, GLint j, GLint k, GLchan *texel )
700 {
701 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
702 texel[RCOMP] = UBYTE_TO_CHAN( src[0] );
703 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
704 texel[BCOMP] = UBYTE_TO_CHAN( src[2] );
705 texel[ACOMP] = CHAN_MAX;
706 }
707
708 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLfloats */
709 static void FETCH(f_bgr888)( const struct gl_texture_image *texImage,
710 GLint i, GLint j, GLint k, GLfloat *texel )
711 {
712 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
713 texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
714 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
715 texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
716 texel[ACOMP] = CHAN_MAXF;
717 }
718
719
720 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
721 static void FETCH(rgb565)( const struct gl_texture_image *texImage,
722 GLint i, GLint j, GLint k, GLchan *texel )
723 {
724 const GLushort *src = USHORT_SRC( texImage, i, j, k );
725 const GLushort s = *src;
726 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) * 255 / 0xf8 );
727 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) * 255 / 0xfc );
728 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) * 255 / 0xf8 );
729 texel[ACOMP] = CHAN_MAX;
730 }
731
732 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
733 static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
734 GLint i, GLint j, GLint k, GLfloat *texel )
735 {
736 const GLushort *src = USHORT_SRC( texImage, i, j, k );
737 const GLushort s = *src;
738 texel[RCOMP] = ((s >> 8) & 0xf8) * (1.0F / 248.0F);
739 texel[GCOMP] = ((s >> 3) & 0xfc) * (1.0F / 252.0F);
740 texel[BCOMP] = ((s << 3) & 0xf8) * (1.0F / 248.0F);
741 texel[ACOMP] = CHAN_MAXF;
742 }
743
744
745 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
746 static void FETCH(rgb565_rev)( const struct gl_texture_image *texImage,
747 GLint i, GLint j, GLint k, GLchan *texel )
748 {
749 const GLushort *src = USHORT_SRC( texImage, i, j, k );
750 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
751 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) * 255 / 0xf8 );
752 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) * 255 / 0xfc );
753 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) * 255 / 0xf8 );
754 texel[ACOMP] = CHAN_MAX;
755 }
756
757 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLfloats */
758 static void FETCH(f_rgb565_rev)( const struct gl_texture_image *texImage,
759 GLint i, GLint j, GLint k, GLfloat *texel )
760 {
761 const GLushort *src = USHORT_SRC( texImage, i, j, k );
762 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
763 texel[RCOMP] = ((s >> 8) & 0xf8) * (1.0F / 248.0F);
764 texel[GCOMP] = ((s >> 3) & 0xfc) * (1.0F / 252.0F);
765 texel[BCOMP] = ((s << 3) & 0xf8) * (1.0F / 248.0F);
766 texel[ACOMP] = CHAN_MAXF;
767 }
768
769
770 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
771 static void FETCH(argb4444)( const struct gl_texture_image *texImage,
772 GLint i, GLint j, GLint k, GLchan *texel )
773 {
774 const GLushort *src = USHORT_SRC( texImage, i, j, k );
775 const GLushort s = *src;
776 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf );
777 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf );
778 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf );
779 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) * 255 / 0xf );
780 }
781
782 /* Fetch texel from 1D, 2D or 3D argb4444 texture, return 4 GLfloats */
783 static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
784 GLint i, GLint j, GLint k, GLfloat *texel )
785 {
786 const GLushort *src = USHORT_SRC( texImage, i, j, k );
787 const GLushort s = *src;
788 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
789 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
790 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
791 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
792 }
793
794
795 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
796 static void FETCH(argb4444_rev)( const struct gl_texture_image *texImage,
797 GLint i, GLint j, GLint k, GLchan *texel )
798 {
799 const GLushort s = *USHORT_SRC( texImage, i, j, k );
800 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf );
801 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) * 255 / 0xf );
802 texel[BCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf );
803 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf );
804 }
805
806 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLfloats */
807 static void FETCH(f_argb4444_rev)( const struct gl_texture_image *texImage,
808 GLint i, GLint j, GLint k, GLfloat *texel )
809 {
810 const GLushort s = *USHORT_SRC( texImage, i, j, k );
811 texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
812 texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
813 texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
814 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
815 }
816
817
818 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
819 static void FETCH(argb1555)( const struct gl_texture_image *texImage,
820 GLint i, GLint j, GLint k, GLchan *texel )
821 {
822 const GLushort *src = USHORT_SRC( texImage, i, j, k );
823 const GLushort s = *src;
824 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0x1f) * 255 / 0x1f );
825 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0x1f) * 255 / 0x1f );
826 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0x1f) * 255 / 0x1f );
827 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
828 }
829
830 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLfloats */
831 static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
832 GLint i, GLint j, GLint k, GLfloat *texel )
833 {
834 const GLushort *src = USHORT_SRC( texImage, i, j, k );
835 const GLushort s = *src;
836 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
837 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
838 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
839 texel[ACOMP] = ((s >> 15) & 0x01);
840 }
841
842
843 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
844 static void FETCH(argb1555_rev)( const struct gl_texture_image *texImage,
845 GLint i, GLint j, GLint k, GLchan *texel )
846 {
847 const GLushort *src = USHORT_SRC( texImage, i, j, k );
848 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
849 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0x1f) * 255 / 0x1f );
850 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0x1f) * 255 / 0x1f );
851 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0x1f) * 255 / 0x1f );
852 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
853 }
854
855 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLfloats */
856 static void FETCH(f_argb1555_rev)( const struct gl_texture_image *texImage,
857 GLint i, GLint j, GLint k, GLfloat *texel )
858 {
859 const GLushort *src = USHORT_SRC( texImage, i, j, k );
860 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
861 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
862 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
863 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
864 texel[ACOMP] = ((s >> 15) & 0x01);
865 }
866
867
868 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
869 static void FETCH(al88)( const struct gl_texture_image *texImage,
870 GLint i, GLint j, GLint k, GLchan *texel )
871 {
872 const GLushort s = *USHORT_SRC( texImage, i, j, k );
873 texel[RCOMP] =
874 texel[GCOMP] =
875 texel[BCOMP] = UBYTE_TO_CHAN( s & 0xff );
876 texel[ACOMP] = UBYTE_TO_CHAN( s >> 8 );
877 }
878
879 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLfloats */
880 static void FETCH(f_al88)( const struct gl_texture_image *texImage,
881 GLint i, GLint j, GLint k, GLfloat *texel )
882 {
883 const GLushort s = *USHORT_SRC( texImage, i, j, k );
884 texel[RCOMP] =
885 texel[GCOMP] =
886 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
887 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
888 }
889
890
891 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
892 static void FETCH(al88_rev)( const struct gl_texture_image *texImage,
893 GLint i, GLint j, GLint k, GLchan *texel )
894 {
895 const GLushort s = *USHORT_SRC( texImage, i, j, k );
896 texel[RCOMP] =
897 texel[GCOMP] =
898 texel[BCOMP] = UBYTE_TO_CHAN( s >> 8 );
899 texel[ACOMP] = UBYTE_TO_CHAN( s & 0xff );
900 }
901
902 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLfloats */
903 static void FETCH(f_al88_rev)( const struct gl_texture_image *texImage,
904 GLint i, GLint j, GLint k, GLfloat *texel )
905 {
906 const GLushort s = *USHORT_SRC( texImage, i, j, k );
907 texel[RCOMP] =
908 texel[GCOMP] =
909 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
910 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
911 }
912
913
914 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
915 static void FETCH(rgb332)( const struct gl_texture_image *texImage,
916 GLint i, GLint j, GLint k, GLchan *texel )
917 {
918 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
919 const GLubyte s = *src;
920 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xe0) * 255 / 0xe0 );
921 texel[GCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xe0) * 255 / 0xe0 );
922 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 6) & 0xc0) * 255 / 0xc0 );
923 texel[ACOMP] = CHAN_MAX;
924 }
925
926 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLfloats */
927 static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
928 GLint i, GLint j, GLint k, GLfloat *texel )
929 {
930 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
931 const GLubyte s = *src;
932 texel[RCOMP] = ((s ) & 0xe0) * (1.0F / 224.0F);
933 texel[GCOMP] = ((s << 3) & 0xe0) * (1.0F / 224.0F);
934 texel[BCOMP] = ((s << 6) & 0xc0) * (1.0F / 192.0F);
935 texel[ACOMP] = CHAN_MAXF;
936 }
937
938
939 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
940 static void FETCH(a8)( const struct gl_texture_image *texImage,
941 GLint i, GLint j, GLint k, GLchan *texel )
942 {
943 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
944 texel[RCOMP] =
945 texel[GCOMP] =
946 texel[BCOMP] = 0;
947 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
948 }
949
950 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLfloats */
951 static void FETCH(f_a8)( const struct gl_texture_image *texImage,
952 GLint i, GLint j, GLint k, GLfloat *texel )
953 {
954 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
955 texel[RCOMP] =
956 texel[GCOMP] =
957 texel[BCOMP] = 0.0;
958 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
959 }
960
961
962 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
963 static void FETCH(l8)( const struct gl_texture_image *texImage,
964 GLint i, GLint j, GLint k, GLchan *texel )
965 {
966 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
967 texel[RCOMP] =
968 texel[GCOMP] =
969 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
970 texel[ACOMP] = CHAN_MAX;
971 }
972
973 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLfloats */
974 static void FETCH(f_l8)( const struct gl_texture_image *texImage,
975 GLint i, GLint j, GLint k, GLfloat *texel )
976 {
977 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
978 texel[RCOMP] =
979 texel[GCOMP] =
980 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
981 texel[ACOMP] = CHAN_MAXF;
982 }
983
984
985 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
986 static void FETCH(i8)( const struct gl_texture_image *texImage,
987 GLint i, GLint j, GLint k, GLchan *texel )
988 {
989 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
990 texel[RCOMP] =
991 texel[GCOMP] =
992 texel[BCOMP] =
993 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
994 }
995
996 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLfloats */
997 static void FETCH(f_i8)( const struct gl_texture_image *texImage,
998 GLint i, GLint j, GLint k, GLfloat *texel )
999 {
1000 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
1001 texel[RCOMP] =
1002 texel[GCOMP] =
1003 texel[BCOMP] =
1004 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1005 }
1006
1007
1008 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1009 * color table, and return 4 GLchans.
1010 */
1011 static void FETCH(ci8)( const struct gl_texture_image *texImage,
1012 GLint i, GLint j, GLint k, GLchan *texel )
1013 {
1014 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
1015 const struct gl_color_table *palette;
1016 const GLchan *table;
1017 GLuint index;
1018 GET_CURRENT_CONTEXT(ctx);
1019
1020 if (ctx->Texture.SharedPalette) {
1021 palette = &ctx->Texture.Palette;
1022 }
1023 else {
1024 palette = &texImage->TexObject->Palette;
1025 }
1026 if (palette->Size == 0)
1027 return; /* undefined results */
1028 ASSERT(palette->Type != GL_FLOAT);
1029 table = (const GLchan *) palette->Table;
1030
1031 /* Mask the index against size of palette to avoid going out of bounds */
1032 index = (*src) & (palette->Size - 1);
1033
1034 switch (palette->Format) {
1035 case GL_ALPHA:
1036 texel[RCOMP] =
1037 texel[GCOMP] =
1038 texel[BCOMP] = 0;
1039 texel[ACOMP] = table[index];
1040 return;
1041 case GL_LUMINANCE:
1042 texel[RCOMP] =
1043 texel[GCOMP] =
1044 texel[BCOMP] = table[index];
1045 texel[ACOMP] = CHAN_MAX;
1046 break;
1047 case GL_INTENSITY:
1048 texel[RCOMP] =
1049 texel[GCOMP] =
1050 texel[BCOMP] =
1051 texel[ACOMP] = table[index];
1052 return;
1053 case GL_LUMINANCE_ALPHA:
1054 texel[RCOMP] =
1055 texel[GCOMP] =
1056 texel[BCOMP] = table[index * 2 + 0];
1057 texel[ACOMP] = table[index * 2 + 1];
1058 return;
1059 case GL_RGB:
1060 texel[RCOMP] = table[index * 3 + 0];
1061 texel[GCOMP] = table[index * 3 + 1];
1062 texel[BCOMP] = table[index * 3 + 2];
1063 texel[ACOMP] = CHAN_MAX;
1064 return;
1065 case GL_RGBA:
1066 texel[RCOMP] = table[index * 4 + 0];
1067 texel[GCOMP] = table[index * 4 + 1];
1068 texel[BCOMP] = table[index * 4 + 2];
1069 texel[ACOMP] = table[index * 4 + 3];
1070 return;
1071 default:
1072 _mesa_problem(ctx, "Bad palette format in palette_sample");
1073 }
1074 }
1075
1076
1077 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1078 * color table, and return 4 GLfloats.
1079 */
1080 static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
1081 GLint i, GLint j, GLint k, GLfloat *texel )
1082 {
1083 GLchan rgba[4];
1084 /* Sample as GLchan */
1085 FETCH(ci8)(texImage, i, j, k, rgba);
1086 /* and return as floats */
1087 texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
1088 texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
1089 texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
1090 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
1091 }
1092
1093
1094 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
1095 /* We convert YCbCr to RGB here */
1096 /* XXX this may break if GLchan != GLubyte */
1097 static void FETCH(ycbcr)( const struct gl_texture_image *texImage,
1098 GLint i, GLint j, GLint k, GLchan *texel )
1099 {
1100 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
1101 const GLushort *src1 = src0 + 1; /* odd */
1102 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1103 const GLubyte cb = *src0 & 0xff; /* chroma U */
1104 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1105 const GLubyte cr = *src1 & 0xff; /* chroma V */
1106 GLint r, g, b;
1107 if (i & 1) {
1108 /* odd pixel: use y1,cr,cb */
1109 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
1110 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1111 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
1112 }
1113 else {
1114 /* even pixel: use y0,cr,cb */
1115 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
1116 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1117 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
1118 }
1119 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
1120 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
1121 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
1122 texel[ACOMP] = CHAN_MAX;
1123 }
1124
1125 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats */
1126 /* We convert YCbCr to RGB here */
1127 static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
1128 GLint i, GLint j, GLint k, GLfloat *texel )
1129 {
1130 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
1131 const GLushort *src1 = src0 + 1; /* odd */
1132 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1133 const GLubyte cb = *src0 & 0xff; /* chroma U */
1134 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1135 const GLubyte cr = *src1 & 0xff; /* chroma V */
1136 GLfloat r, g, b;
1137 if (i & 1) {
1138 /* odd pixel: use y1,cr,cb */
1139 r = (1.164 * (y1-16) + 1.596 * (cr-128));
1140 g = (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1141 b = (1.164 * (y1-16) + 2.018 * (cb-128));
1142 }
1143 else {
1144 /* even pixel: use y0,cr,cb */
1145 r = (1.164 * (y0-16) + 1.596 * (cr-128));
1146 g = (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1147 b = (1.164 * (y0-16) + 2.018 * (cb-128));
1148 }
1149 /* XXX remove / 255 here by tweaking arithmetic above */
1150 r /= 255.0;
1151 g /= 255.0;
1152 b /= 255.0;
1153 /* XXX should we really clamp??? */
1154 texel[RCOMP] = CLAMP(r, 0.0, 1.0);
1155 texel[GCOMP] = CLAMP(g, 0.0, 1.0);
1156 texel[BCOMP] = CLAMP(b, 0.0, 1.0);
1157 texel[ACOMP] = CHAN_MAXF;
1158 }
1159
1160
1161 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
1162 /* We convert YCbCr to RGB here */
1163 /* XXX this may break if GLchan != GLubyte */
1164 static void FETCH(ycbcr_rev)( const struct gl_texture_image *texImage,
1165 GLint i, GLint j, GLint k, GLchan *texel )
1166 {
1167 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
1168 const GLushort *src1 = src0 + 1; /* odd */
1169 const GLubyte y0 = *src0 & 0xff; /* luminance */
1170 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1171 const GLubyte y1 = *src1 & 0xff; /* luminance */
1172 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1173 GLint r, g, b;
1174 if (i & 1) {
1175 /* odd pixel: use y1,cr,cb */
1176 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
1177 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1178 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
1179 }
1180 else {
1181 /* even pixel: use y0,cr,cb */
1182 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
1183 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1184 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
1185 }
1186 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
1187 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
1188 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
1189 texel[ACOMP] = CHAN_MAX;
1190 }
1191
1192 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
1193 /* We convert YCbCr to RGB here */
1194 static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
1195 GLint i, GLint j, GLint k, GLfloat *texel )
1196 {
1197 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
1198 const GLushort *src1 = src0 + 1; /* odd */
1199 const GLubyte y0 = *src0 & 0xff; /* luminance */
1200 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1201 const GLubyte y1 = *src1 & 0xff; /* luminance */
1202 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1203 GLfloat r, g, b;
1204 if (i & 1) {
1205 /* odd pixel: use y1,cr,cb */
1206 r = (1.164 * (y1-16) + 1.596 * (cr-128));
1207 g = (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1208 b = (1.164 * (y1-16) + 2.018 * (cb-128));
1209 }
1210 else {
1211 /* even pixel: use y0,cr,cb */
1212 r = (1.164 * (y0-16) + 1.596 * (cr-128));
1213 g = (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1214 b = (1.164 * (y0-16) + 2.018 * (cb-128));
1215 }
1216 /* XXX remove / 255 here by tweaking arithmetic above */
1217 r /= 255.0;
1218 g /= 255.0;
1219 b /= 255.0;
1220 /* XXX should we really clamp??? */
1221 texel[RCOMP] = CLAMP(r, 0.0, 1.0);
1222 texel[GCOMP] = CLAMP(g, 0.0, 1.0);
1223 texel[BCOMP] = CLAMP(b, 0.0, 1.0);
1224 texel[ACOMP] = CHAN_MAXF;
1225 }
1226
1227
1228
1229 #undef CHAN_SRC
1230 #undef UBYTE_SRC
1231 #undef USHORT_SRC
1232 #undef UINT_SRC
1233 #undef FLOAT_SRC
1234 #undef HALF_SRC
1235 #undef FETCH
1236 #undef DIM