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