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