simplify, clean-up texel addressing macros
[mesa.git] / src / mesa / main / texformat_tmp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 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 TEXEL_ADDR( type, image, i, j, k, size ) \
47 ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
48
49 #define FETCH(x) fetch_texel_1d_##x
50
51 #elif DIM == 2
52
53 #define TEXEL_ADDR( type, image, i, j, k, size ) \
54 ((void) (k), \
55 ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
56
57 #define FETCH(x) fetch_texel_2d_##x
58
59 #elif DIM == 3
60
61 #define TEXEL_ADDR( type, image, i, j, k, size ) \
62 ((type *)(image)->Data + (((image)->Height * (k) + (j)) * \
63 (image)->RowStride + (i)) * (size))
64
65 #define FETCH(x) fetch_texel_3d_##x
66
67 #else
68 #error illegal number of texture dimensions
69 #endif
70
71
72 /* MESA_FORMAT_RGBA **********************************************************/
73
74 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
75 static void FETCH(rgba)( const struct gl_texture_image *texImage,
76 GLint i, GLint j, GLint k, GLchan *texel )
77 {
78 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 4);
79 COPY_CHAN4( texel, src );
80 }
81
82 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
83 static void FETCH(f_rgba)( const struct gl_texture_image *texImage,
84 GLint i, GLint j, GLint k, GLfloat *texel )
85 {
86 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 4);
87 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
88 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
89 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
90 texel[ACOMP] = CHAN_TO_FLOAT(src[3]);
91 }
92
93 #if DIM == 3
94 /* Store a GLchan RGBA texel */
95 static void store_texel_rgba(struct gl_texture_image *texImage,
96 GLint i, GLint j, GLint k, const void *texel)
97 {
98 const GLchan *rgba = (const GLchan *) texel;
99 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 4);
100 dst[0] = rgba[RCOMP];
101 dst[1] = rgba[GCOMP];
102 dst[2] = rgba[BCOMP];
103 dst[3] = rgba[ACOMP];
104 }
105 #endif
106
107 /* MESA_FORMAT_RGB ***********************************************************/
108
109 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
110 static void FETCH(rgb)( const struct gl_texture_image *texImage,
111 GLint i, GLint j, GLint k, GLchan *texel )
112 {
113 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 3);
114 texel[RCOMP] = src[0];
115 texel[GCOMP] = src[1];
116 texel[BCOMP] = src[2];
117 texel[ACOMP] = CHAN_MAX;
118 }
119
120 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
121 static void FETCH(f_rgb)( const struct gl_texture_image *texImage,
122 GLint i, GLint j, GLint k, GLfloat *texel )
123 {
124 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 3);
125 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
126 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
127 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
128 texel[ACOMP] = 1.0F;
129 }
130
131 #if DIM == 3
132 static void store_texel_rgb(struct gl_texture_image *texImage,
133 GLint i, GLint j, GLint k, const void *texel)
134 {
135 const GLchan *rgba = (const GLchan *) texel;
136 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 3);
137 dst[0] = rgba[RCOMP];
138 dst[1] = rgba[GCOMP];
139 dst[2] = rgba[BCOMP];
140 }
141 #endif
142
143 /* MESA_FORMAT_ALPHA *********************************************************/
144
145 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
146 static void FETCH(alpha)( const struct gl_texture_image *texImage,
147 GLint i, GLint j, GLint k, GLchan *texel )
148 {
149 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
150 texel[RCOMP] =
151 texel[GCOMP] =
152 texel[BCOMP] = 0;
153 texel[ACOMP] = src[0];
154 }
155
156 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLfloats */
157 static void FETCH(f_alpha)( const struct gl_texture_image *texImage,
158 GLint i, GLint j, GLint k, GLfloat *texel )
159 {
160 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
161 texel[RCOMP] =
162 texel[GCOMP] =
163 texel[BCOMP] = 0.0;
164 texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
165 }
166
167 #if DIM == 3
168 static void store_texel_alpha(struct gl_texture_image *texImage,
169 GLint i, GLint j, GLint k, const void *texel)
170 {
171 const GLchan *rgba = (const GLchan *) texel;
172 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
173 dst[0] = rgba[ACOMP];
174 }
175 #endif
176
177 /* MESA_FORMAT_LUMINANCE *****************************************************/
178
179 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
180 static void FETCH(luminance)( const struct gl_texture_image *texImage,
181 GLint i, GLint j, GLint k, GLchan *texel )
182 {
183 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
184 texel[RCOMP] =
185 texel[GCOMP] =
186 texel[BCOMP] = src[0];
187 texel[ACOMP] = CHAN_MAX;
188 }
189
190 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLfloats */
191 static void FETCH(f_luminance)( const struct gl_texture_image *texImage,
192 GLint i, GLint j, GLint k, GLfloat *texel )
193 {
194 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
195 texel[RCOMP] =
196 texel[GCOMP] =
197 texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
198 texel[ACOMP] = 1.0F;
199 }
200
201 #if DIM == 3
202 static void store_texel_luminance(struct gl_texture_image *texImage,
203 GLint i, GLint j, GLint k, const void *texel)
204 {
205 const GLchan *rgba = (const GLchan *) texel;
206 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
207 dst[0] = rgba[RCOMP];
208 }
209 #endif
210
211 /* MESA_FORMAT_LUMINANCE_ALPHA ***********************************************/
212
213 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
214 static void FETCH(luminance_alpha)( const struct gl_texture_image *texImage,
215 GLint i, GLint j, GLint k, GLchan *texel )
216 {
217 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 2);
218 texel[RCOMP] = src[0];
219 texel[GCOMP] = src[0];
220 texel[BCOMP] = src[0];
221 texel[ACOMP] = src[1];
222 }
223
224 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLfloats */
225 static void FETCH(f_luminance_alpha)( const struct gl_texture_image *texImage,
226 GLint i, GLint j, GLint k, GLfloat *texel )
227 {
228 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 2);
229 texel[RCOMP] =
230 texel[GCOMP] =
231 texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
232 texel[ACOMP] = CHAN_TO_FLOAT(src[1]);
233 }
234
235 #if DIM == 3
236 static void store_texel_luminance_alpha(struct gl_texture_image *texImage,
237 GLint i, GLint j, GLint k, const void *texel)
238 {
239 const GLchan *rgba = (const GLchan *) texel;
240 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 2);
241 dst[0] = rgba[RCOMP];
242 dst[1] = rgba[ACOMP];
243 }
244 #endif
245
246 /* MESA_FORMAT_INTENSITY *****************************************************/
247
248 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
249 static void FETCH(intensity)( const struct gl_texture_image *texImage,
250 GLint i, GLint j, GLint k, GLchan *texel )
251 {
252 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
253 texel[RCOMP] = src[0];
254 texel[GCOMP] = src[0];
255 texel[BCOMP] = src[0];
256 texel[ACOMP] = src[0];
257 }
258
259 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLfloats */
260 static void FETCH(f_intensity)( const struct gl_texture_image *texImage,
261 GLint i, GLint j, GLint k, GLfloat *texel )
262 {
263 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
264 texel[RCOMP] =
265 texel[GCOMP] =
266 texel[BCOMP] =
267 texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
268 }
269
270 #if DIM == 3
271 static void store_texel_intensity(struct gl_texture_image *texImage,
272 GLint i, GLint j, GLint k, const void *texel)
273 {
274 const GLchan *rgba = (const GLchan *) texel;
275 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
276 dst[0] = rgba[RCOMP];
277 }
278 #endif
279
280
281 /* MESA_FORMAT_DEPTH_COMPONENT_F32 *******************************************/
282
283 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
284 * returning 1 GLfloat.
285 * Note: no GLchan version of this function.
286 */
287 static void FETCH(f_depth_component_f32)( const struct gl_texture_image *texImage,
288 GLint i, GLint j, GLint k, GLfloat *texel )
289 {
290 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
291 texel[0] = src[0];
292 }
293
294 #if DIM == 3
295 static void store_texel_depth_component_f32(struct gl_texture_image *texImage,
296 GLint i, GLint j, GLint k, const void *texel)
297 {
298 const GLfloat *depth = (const GLfloat *) texel;
299 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
300 dst[0] = *depth;
301 }
302 #endif
303
304
305 /* MESA_FORMAT_DEPTH_COMPONENT16 *********************************************/
306
307 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
308 * returning 1 GLfloat.
309 * Note: no GLchan version of this function.
310 */
311 static void FETCH(f_depth_component16)(const struct gl_texture_image *texImage,
312 GLint i, GLint j, GLint k, GLfloat *texel )
313 {
314 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
315 texel[0] = src[0] * (1.0F / 65535.0F);
316 }
317
318 #if DIM == 3
319 static void store_texel_depth_component16(struct gl_texture_image *texImage,
320 GLint i, GLint j, GLint k, const void *texel)
321 {
322 const GLushort *depth = (const GLushort *) texel;
323 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
324 dst[0] = *depth;
325 }
326 #endif
327
328
329 /* MESA_FORMAT_RGBA_F32 ******************************************************/
330
331 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLchans.
332 */
333 static void FETCH(rgba_f32)( const struct gl_texture_image *texImage,
334 GLint i, GLint j, GLint k, GLchan *texel )
335 {
336 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
337 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
338 UNCLAMPED_FLOAT_TO_CHAN(texel[GCOMP], src[1]);
339 UNCLAMPED_FLOAT_TO_CHAN(texel[BCOMP], src[2]);
340 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], src[3]);
341 }
342
343 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
344 */
345 static void FETCH(f_rgba_f32)( const struct gl_texture_image *texImage,
346 GLint i, GLint j, GLint k, GLfloat *texel )
347 {
348 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
349 texel[RCOMP] = src[0];
350 texel[GCOMP] = src[1];
351 texel[BCOMP] = src[2];
352 texel[ACOMP] = src[3];
353 }
354
355 #if DIM == 3
356 static void store_texel_rgba_f32(struct gl_texture_image *texImage,
357 GLint i, GLint j, GLint k, const void *texel)
358 {
359 const GLfloat *depth = (const GLfloat *) texel;
360 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
361 dst[0] = depth[RCOMP];
362 dst[1] = depth[GCOMP];
363 dst[2] = depth[BCOMP];
364 dst[3] = depth[ACOMP];
365 }
366 #endif
367
368
369 /* MESA_FORMAT_RGBA_F16 ******************************************************/
370
371 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
372 * returning 4 GLchans.
373 */
374 static void FETCH(rgba_f16)( const struct gl_texture_image *texImage,
375 GLint i, GLint j, GLint k, GLchan *texel )
376 {
377 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
378 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
379 UNCLAMPED_FLOAT_TO_CHAN(texel[GCOMP], _mesa_half_to_float(src[1]));
380 UNCLAMPED_FLOAT_TO_CHAN(texel[BCOMP], _mesa_half_to_float(src[2]));
381 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], _mesa_half_to_float(src[3]));
382 }
383
384 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
385 * returning 4 GLfloats.
386 */
387 static void FETCH(f_rgba_f16)( const struct gl_texture_image *texImage,
388 GLint i, GLint j, GLint k, GLfloat *texel )
389 {
390 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
391 texel[RCOMP] = _mesa_half_to_float(src[0]);
392 texel[GCOMP] = _mesa_half_to_float(src[1]);
393 texel[BCOMP] = _mesa_half_to_float(src[2]);
394 texel[ACOMP] = _mesa_half_to_float(src[3]);
395 }
396
397 #if DIM == 3
398 static void store_texel_rgba_f16(struct gl_texture_image *texImage,
399 GLint i, GLint j, GLint k, const void *texel)
400 {
401 const GLfloat *depth = (const GLfloat *) texel;
402 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
403 dst[0] = _mesa_float_to_half(*depth);
404 }
405 #endif
406
407 /* MESA_FORMAT_RGB_F32 *******************************************************/
408
409 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
410 * returning 4 GLchans.
411 */
412 static void FETCH(rgb_f32)( const struct gl_texture_image *texImage,
413 GLint i, GLint j, GLint k, GLchan *texel )
414 {
415 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
416 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
417 UNCLAMPED_FLOAT_TO_CHAN(texel[GCOMP], src[1]);
418 UNCLAMPED_FLOAT_TO_CHAN(texel[BCOMP], src[2]);
419 texel[ACOMP] = CHAN_MAX;
420 }
421
422 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
423 * returning 4 GLfloats.
424 */
425 static void FETCH(f_rgb_f32)( const struct gl_texture_image *texImage,
426 GLint i, GLint j, GLint k, GLfloat *texel )
427 {
428 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
429 texel[RCOMP] = src[0];
430 texel[GCOMP] = src[1];
431 texel[BCOMP] = src[2];
432 texel[ACOMP] = 1.0F;
433 }
434
435 #if DIM == 3
436 static void store_texel_rgb_f32(struct gl_texture_image *texImage,
437 GLint i, GLint j, GLint k, const void *texel)
438 {
439 const GLfloat *depth = (const GLfloat *) texel;
440 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
441 dst[0] = *depth;
442 }
443 #endif
444
445
446 /* MESA_FORAMT_RGB_F16 *******************************************************/
447
448 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
449 * returning 4 GLchans.
450 */
451 static void FETCH(rgb_f16)( const struct gl_texture_image *texImage,
452 GLint i, GLint j, GLint k, GLchan *texel )
453 {
454 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
455 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
456 UNCLAMPED_FLOAT_TO_CHAN(texel[GCOMP], _mesa_half_to_float(src[1]));
457 UNCLAMPED_FLOAT_TO_CHAN(texel[BCOMP], _mesa_half_to_float(src[2]));
458 texel[ACOMP] = CHAN_MAX;
459 }
460
461 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
462 * returning 4 GLfloats.
463 */
464 static void FETCH(f_rgb_f16)( const struct gl_texture_image *texImage,
465 GLint i, GLint j, GLint k, GLfloat *texel )
466 {
467 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
468 texel[RCOMP] = _mesa_half_to_float(src[0]);
469 texel[GCOMP] = _mesa_half_to_float(src[1]);
470 texel[BCOMP] = _mesa_half_to_float(src[2]);
471 texel[ACOMP] = 1.0F;
472 }
473
474 #if DIM == 3
475 static void store_texel_rgb_f16(struct gl_texture_image *texImage,
476 GLint i, GLint j, GLint k, const void *texel)
477 {
478 const GLfloat *depth = (const GLfloat *) texel;
479 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
480 dst[0] = _mesa_float_to_half(*depth);
481 }
482 #endif
483
484
485 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
486
487 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
488 * returning 4 GLchans.
489 */
490 static void FETCH(alpha_f32)( const struct gl_texture_image *texImage,
491 GLint i, GLint j, GLint k, GLchan *texel )
492 {
493 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
494 texel[RCOMP] =
495 texel[GCOMP] =
496 texel[BCOMP] = 0;
497 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], src[0]);
498 }
499
500 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
501 * returning 4 GLfloats.
502 */
503 static void FETCH(f_alpha_f32)( const struct gl_texture_image *texImage,
504 GLint i, GLint j, GLint k, GLfloat *texel )
505 {
506 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
507 texel[RCOMP] =
508 texel[GCOMP] =
509 texel[BCOMP] = 0.0F;
510 texel[ACOMP] = src[0];
511 }
512
513 #if DIM == 3
514 static void store_texel_alpha_f32(struct gl_texture_image *texImage,
515 GLint i, GLint j, GLint k, const void *texel)
516 {
517 const GLfloat *rgba = (const GLfloat *) texel;
518 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
519 dst[0] = rgba[ACOMP];
520 }
521 #endif
522
523
524 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
525
526 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
527 * returning 4 GLchans.
528 */
529 static void FETCH(alpha_f16)( const struct gl_texture_image *texImage,
530 GLint i, GLint j, GLint k, GLchan *texel )
531 {
532 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
533 texel[RCOMP] =
534 texel[GCOMP] =
535 texel[BCOMP] = 0;
536 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], _mesa_half_to_float(src[0]));
537 }
538
539 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
540 * returning 4 GLfloats.
541 */
542 static void FETCH(f_alpha_f16)( const struct gl_texture_image *texImage,
543 GLint i, GLint j, GLint k, GLfloat *texel )
544 {
545 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
546 texel[RCOMP] =
547 texel[GCOMP] =
548 texel[BCOMP] = 0.0F;
549 texel[ACOMP] = _mesa_half_to_float(src[0]);
550 }
551
552 #if DIM == 3
553 static void store_texel_alpha_f16(struct gl_texture_image *texImage,
554 GLint i, GLint j, GLint k, const void *texel)
555 {
556 const GLfloat *rgba = (const GLfloat *) texel;
557 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
558 dst[0] = _mesa_float_to_half(rgba[ACOMP]);
559 }
560 #endif
561
562
563 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
564
565 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
566 * returning 4 GLchans.
567 */
568 static void FETCH(luminance_f32)( const struct gl_texture_image *texImage,
569 GLint i, GLint j, GLint k, GLchan *texel )
570 {
571 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
572 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
573 texel[GCOMP] =
574 texel[BCOMP] = texel[RCOMP];
575 texel[ACOMP] = CHAN_MAX;
576 }
577
578 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
579 * returning 4 GLfloats.
580 */
581 static void FETCH(f_luminance_f32)( const struct gl_texture_image *texImage,
582 GLint i, GLint j, GLint k, GLfloat *texel )
583 {
584 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
585 texel[RCOMP] =
586 texel[GCOMP] =
587 texel[BCOMP] = src[0];
588 texel[ACOMP] = 1.0F;
589 }
590
591 #if DIM == 3
592 static void store_texel_luminance_f32(struct gl_texture_image *texImage,
593 GLint i, GLint j, GLint k, const void *texel)
594 {
595 const GLfloat *rgba = (const GLfloat *) texel;
596 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
597 dst[0] = rgba[RCOMP];
598 }
599 #endif
600
601
602 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
603
604 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
605 * returning 4 GLchans.
606 */
607 static void FETCH(luminance_f16)( const struct gl_texture_image *texImage,
608 GLint i, GLint j, GLint k, GLchan *texel )
609 {
610 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
611 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
612 texel[GCOMP] =
613 texel[BCOMP] = texel[RCOMP];
614 texel[ACOMP] = CHAN_MAX;
615 }
616
617 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
618 * returning 4 GLfloats.
619 */
620 static void FETCH(f_luminance_f16)( const struct gl_texture_image *texImage,
621 GLint i, GLint j, GLint k, GLfloat *texel )
622 {
623 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
624 texel[RCOMP] =
625 texel[GCOMP] =
626 texel[BCOMP] = _mesa_half_to_float(src[0]);
627 texel[ACOMP] = 1.0F;
628 }
629
630 #if DIM == 3
631 static void store_texel_luminance_f16(struct gl_texture_image *texImage,
632 GLint i, GLint j, GLint k, const void *texel)
633 {
634 const GLfloat *rgba = (const GLfloat *) texel;
635 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
636 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
637 }
638 #endif
639
640
641 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
642
643 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
644 * returning 4 GLchans.
645 */
646 static void FETCH(luminance_alpha_f32)( const struct gl_texture_image *texImage,
647 GLint i, GLint j, GLint k, GLchan *texel )
648 {
649 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
650 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
651 texel[GCOMP] =
652 texel[BCOMP] = texel[RCOMP];
653 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], src[1]);
654 }
655
656 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
657 * returning 4 GLfloats.
658 */
659 static void FETCH(f_luminance_alpha_f32)( const struct gl_texture_image *texImage,
660 GLint i, GLint j, GLint k, GLfloat *texel )
661 {
662 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
663 texel[RCOMP] =
664 texel[GCOMP] =
665 texel[BCOMP] = src[0];
666 texel[ACOMP] = src[1];
667 }
668
669 #if DIM == 3
670 static void store_texel_luminance_alpha_f32(struct gl_texture_image *texImage,
671 GLint i, GLint j, GLint k, const void *texel)
672 {
673 const GLfloat *rgba = (const GLfloat *) texel;
674 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
675 dst[0] = rgba[RCOMP];
676 dst[1] = rgba[ACOMP];
677 }
678 #endif
679
680
681 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
682
683 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
684 * returning 4 GLfloats.
685 */
686 static void FETCH(luminance_alpha_f16)( const struct gl_texture_image *texImage,
687 GLint i, GLint j, GLint k, GLchan *texel )
688 {
689 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
690 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
691 texel[GCOMP] =
692 texel[BCOMP] = texel[RCOMP];
693 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], _mesa_half_to_float(src[1]));
694 }
695
696 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
697 * returning 4 GLfloats.
698 */
699 static void FETCH(f_luminance_alpha_f16)( const struct gl_texture_image *texImage,
700 GLint i, GLint j, GLint k, GLfloat *texel )
701 {
702 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
703 texel[RCOMP] =
704 texel[GCOMP] =
705 texel[BCOMP] = _mesa_half_to_float(src[0]);
706 texel[ACOMP] = _mesa_half_to_float(src[1]);
707 }
708
709 #if DIM == 3
710 static void store_texel_luminance_alpha_f16(struct gl_texture_image *texImage,
711 GLint i, GLint j, GLint k, const void *texel)
712 {
713 const GLfloat *rgba = (const GLfloat *) texel;
714 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
715 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
716 dst[1] = _mesa_float_to_half(rgba[ACOMP]);
717 }
718 #endif
719
720
721 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
722
723 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
724 * returning 4 GLchans.
725 */
726 static void FETCH(intensity_f32)( const struct gl_texture_image *texImage,
727 GLint i, GLint j, GLint k, GLchan *texel )
728 {
729 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
730 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
731 texel[GCOMP] =
732 texel[BCOMP] =
733 texel[ACOMP] = texel[RCOMP];
734 }
735
736 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
737 * returning 4 GLfloats.
738 */
739 static void FETCH(f_intensity_f32)( const struct gl_texture_image *texImage,
740 GLint i, GLint j, GLint k, GLfloat *texel )
741 {
742 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
743 texel[RCOMP] =
744 texel[GCOMP] =
745 texel[BCOMP] =
746 texel[ACOMP] = src[0];
747 }
748
749 #if DIM == 3
750 static void store_texel_intensity_f32(struct gl_texture_image *texImage,
751 GLint i, GLint j, GLint k, const void *texel)
752 {
753 const GLfloat *rgba = (const GLfloat *) texel;
754 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
755 dst[0] = rgba[RCOMP];
756 }
757 #endif
758
759
760 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
761
762 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
763 * returning 4 GLchans.
764 */
765 static void FETCH(intensity_f16)( const struct gl_texture_image *texImage,
766 GLint i, GLint j, GLint k, GLchan *texel )
767 {
768 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
769 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
770 texel[GCOMP] =
771 texel[BCOMP] =
772 texel[ACOMP] = texel[RCOMP];
773 }
774
775 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
776 * returning 4 GLfloats.
777 */
778 static void FETCH(f_intensity_f16)( const struct gl_texture_image *texImage,
779 GLint i, GLint j, GLint k, GLfloat *texel )
780 {
781 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
782 texel[RCOMP] =
783 texel[GCOMP] =
784 texel[BCOMP] =
785 texel[ACOMP] = _mesa_half_to_float(src[0]);
786 }
787
788 #if DIM == 3
789 static void store_texel_intensity_f16(struct gl_texture_image *texImage,
790 GLint i, GLint j, GLint k, const void *texel)
791 {
792 const GLfloat *rgba = (const GLfloat *) texel;
793 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
794 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
795 }
796 #endif
797
798
799
800
801 /*
802 * Begin Hardware formats
803 */
804
805 /* MESA_FORMAT_RGBA8888 ******************************************************/
806
807 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
808 static void FETCH(rgba8888)( const struct gl_texture_image *texImage,
809 GLint i, GLint j, GLint k, GLchan *texel )
810 {
811 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
812 texel[RCOMP] = UBYTE_TO_CHAN( (s >> 24) );
813 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
814 texel[BCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
815 texel[ACOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
816 }
817
818 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
819 static void FETCH(f_rgba8888)( const struct gl_texture_image *texImage,
820 GLint i, GLint j, GLint k, GLfloat *texel )
821 {
822 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
823 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
824 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
825 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
826 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
827 }
828
829 #if DIM == 3
830 static void store_texel_rgba8888(struct gl_texture_image *texImage,
831 GLint i, GLint j, GLint k, const void *texel)
832 {
833 const GLubyte *rgba = (const GLubyte *) texel;
834 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
835 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
836 }
837 #endif
838
839
840 /* MESA_FORMAT_RGBA888_REV ***************************************************/
841
842 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
843 static void FETCH(rgba8888_rev)( const struct gl_texture_image *texImage,
844 GLint i, GLint j, GLint k, GLchan *texel )
845 {
846 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
847 texel[RCOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
848 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
849 texel[BCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
850 texel[ACOMP] = UBYTE_TO_CHAN( (s >> 24) );
851 }
852
853 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLfloats */
854 static void FETCH(f_rgba8888_rev)( const struct gl_texture_image *texImage,
855 GLint i, GLint j, GLint k, GLfloat *texel )
856 {
857 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
858 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
859 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
860 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
861 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
862 }
863
864 #if DIM == 3
865 static void store_texel_rgba8888_rev(struct gl_texture_image *texImage,
866 GLint i, GLint j, GLint k, const void *texel)
867 {
868 const GLubyte *rgba = (const GLubyte *) texel;
869 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
870 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
871 }
872 #endif
873
874
875 /* MESA_FORMAT_ARGB8888 ******************************************************/
876
877 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
878 static void FETCH(argb8888)( const struct gl_texture_image *texImage,
879 GLint i, GLint j, GLint k, GLchan *texel )
880 {
881 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
882 texel[RCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
883 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
884 texel[BCOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
885 texel[ACOMP] = UBYTE_TO_CHAN( (s >> 24) );
886 }
887
888 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLfloats */
889 static void FETCH(f_argb8888)( const struct gl_texture_image *texImage,
890 GLint i, GLint j, GLint k, GLfloat *texel )
891 {
892 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
893 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
894 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
895 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
896 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
897 }
898
899 #if DIM == 3
900 static void store_texel_argb8888(struct gl_texture_image *texImage,
901 GLint i, GLint j, GLint k, const void *texel)
902 {
903 const GLubyte *rgba = (const GLubyte *) texel;
904 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
905 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
906 }
907 #endif
908
909
910 /* MESA_FORMAT_ARGB8888_REV **************************************************/
911
912 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLchans */
913 static void FETCH(argb8888_rev)( const struct gl_texture_image *texImage,
914 GLint i, GLint j, GLint k, GLchan *texel )
915 {
916 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
917 texel[RCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
918 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
919 texel[BCOMP] = UBYTE_TO_CHAN( (s >> 24) );
920 texel[ACOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
921 }
922
923 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
924 static void FETCH(f_argb8888_rev)( const struct gl_texture_image *texImage,
925 GLint i, GLint j, GLint k, GLfloat *texel )
926 {
927 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
928 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
929 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
930 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
931 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
932 }
933
934 #if DIM == 3
935 static void store_texel_argb8888_rev(struct gl_texture_image *texImage,
936 GLint i, GLint j, GLint k, const void *texel)
937 {
938 const GLubyte *rgba = (const GLubyte *) texel;
939 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
940 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
941 }
942 #endif
943
944
945 /* MESA_FORMAT_RGB888 ********************************************************/
946
947 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
948 static void FETCH(rgb888)( const struct gl_texture_image *texImage,
949 GLint i, GLint j, GLint k, GLchan *texel )
950 {
951 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
952 texel[RCOMP] = UBYTE_TO_CHAN( src[2] );
953 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
954 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
955 texel[ACOMP] = CHAN_MAX;
956 }
957
958 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLfloats */
959 static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
960 GLint i, GLint j, GLint k, GLfloat *texel )
961 {
962 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
963 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
964 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
965 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
966 texel[ACOMP] = 1.0F;
967 }
968
969 #if DIM == 3
970 static void store_texel_rgb888(struct gl_texture_image *texImage,
971 GLint i, GLint j, GLint k, const void *texel)
972 {
973 const GLubyte *rgba = (const GLubyte *) texel;
974 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
975 dst[0] = rgba[RCOMP];
976 dst[1] = rgba[GCOMP];
977 dst[2] = rgba[BCOMP];
978 }
979 #endif
980
981
982 /* MESA_FORMAT_BGR888 ********************************************************/
983
984 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
985 static void FETCH(bgr888)( const struct gl_texture_image *texImage,
986 GLint i, GLint j, GLint k, GLchan *texel )
987 {
988 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
989 texel[RCOMP] = UBYTE_TO_CHAN( src[0] );
990 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
991 texel[BCOMP] = UBYTE_TO_CHAN( src[2] );
992 texel[ACOMP] = CHAN_MAX;
993 }
994
995 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLfloats */
996 static void FETCH(f_bgr888)( const struct gl_texture_image *texImage,
997 GLint i, GLint j, GLint k, GLfloat *texel )
998 {
999 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1000 texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
1001 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
1002 texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
1003 texel[ACOMP] = 1.0F;
1004 }
1005
1006 #if DIM == 3
1007 static void store_texel_bgr888(struct gl_texture_image *texImage,
1008 GLint i, GLint j, GLint k, const void *texel)
1009 {
1010 const GLubyte *rgba = (const GLubyte *) texel;
1011 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1012 dst[0] = rgba[BCOMP];
1013 dst[1] = rgba[GCOMP];
1014 dst[2] = rgba[RCOMP];
1015 }
1016 #endif
1017
1018
1019 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
1020 instead of slow (g << 2) * 255 / 252 (always rounds down) */
1021
1022 /* MESA_FORMAT_RGB565 ********************************************************/
1023
1024 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
1025 static void FETCH(rgb565)( const struct gl_texture_image *texImage,
1026 GLint i, GLint j, GLint k, GLchan *texel )
1027 {
1028 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1029 const GLushort s = *src;
1030 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
1031 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
1032 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
1033 texel[ACOMP] = CHAN_MAX;
1034 }
1035
1036 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
1037 static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
1038 GLint i, GLint j, GLint k, GLfloat *texel )
1039 {
1040 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1041 const GLushort s = *src;
1042 texel[RCOMP] = ((s >> 8) & 0xf8) * (1.0F / 248.0F);
1043 texel[GCOMP] = ((s >> 3) & 0xfc) * (1.0F / 252.0F);
1044 texel[BCOMP] = ((s << 3) & 0xf8) * (1.0F / 248.0F);
1045 texel[ACOMP] = 1.0F;
1046 }
1047
1048 #if DIM == 3
1049 static void store_texel_rgb565(struct gl_texture_image *texImage,
1050 GLint i, GLint j, GLint k, const void *texel)
1051 {
1052 const GLubyte *rgba = (const GLubyte *) texel;
1053 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1054 *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1055 }
1056 #endif
1057
1058
1059 /* MESA_FORMAT_RGB565_REV ****************************************************/
1060
1061 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
1062 static void FETCH(rgb565_rev)( const struct gl_texture_image *texImage,
1063 GLint i, GLint j, GLint k, GLchan *texel )
1064 {
1065 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1066 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
1067 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
1068 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
1069 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
1070 texel[ACOMP] = CHAN_MAX;
1071 }
1072
1073 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLfloats */
1074 static void FETCH(f_rgb565_rev)( const struct gl_texture_image *texImage,
1075 GLint i, GLint j, GLint k, GLfloat *texel )
1076 {
1077 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1078 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
1079 texel[RCOMP] = ((s >> 8) & 0xf8) * (1.0F / 248.0F);
1080 texel[GCOMP] = ((s >> 3) & 0xfc) * (1.0F / 252.0F);
1081 texel[BCOMP] = ((s << 3) & 0xf8) * (1.0F / 248.0F);
1082 texel[ACOMP] = 1.0F;
1083 }
1084
1085 #if DIM == 3
1086 static void store_texel_rgb565_rev(struct gl_texture_image *texImage,
1087 GLint i, GLint j, GLint k, const void *texel)
1088 {
1089 const GLubyte *rgba = (const GLubyte *) texel;
1090 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1091 *dst = PACK_COLOR_565(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
1092 }
1093 #endif
1094
1095
1096 /* MESA_FORMAT_ARGB4444 ******************************************************/
1097
1098 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
1099 static void FETCH(argb4444)( const struct gl_texture_image *texImage,
1100 GLint i, GLint j, GLint k, GLchan *texel )
1101 {
1102 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1103 const GLushort s = *src;
1104 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) | ((s >> 4) & 0xf0) );
1105 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) | ((s ) & 0xf0) );
1106 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) | ((s << 4) & 0xf0) );
1107 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) | ((s >> 8) & 0xf0) );
1108 }
1109
1110 /* Fetch texel from 1D, 2D or 3D argb4444 texture, return 4 GLfloats */
1111 static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
1112 GLint i, GLint j, GLint k, GLfloat *texel )
1113 {
1114 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1115 const GLushort s = *src;
1116 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
1117 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
1118 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
1119 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
1120 }
1121
1122 #if DIM == 3
1123 static void store_texel_argb4444(struct gl_texture_image *texImage,
1124 GLint i, GLint j, GLint k, const void *texel)
1125 {
1126 const GLubyte *rgba = (const GLubyte *) texel;
1127 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1128 *dst = PACK_COLOR_4444(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1129 }
1130 #endif
1131
1132
1133 /* MESA_FORMAT_ARGB4444_REV **************************************************/
1134
1135 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
1136 static void FETCH(argb4444_rev)( const struct gl_texture_image *texImage,
1137 GLint i, GLint j, GLint k, GLchan *texel )
1138 {
1139 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1140 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) | ((s << 4) & 0xf0) );
1141 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) | ((s >> 8) & 0xf0) );
1142 texel[BCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) | ((s >> 4) & 0xf0) );
1143 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) | ((s ) & 0xf0) );
1144 }
1145
1146 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLfloats */
1147 static void FETCH(f_argb4444_rev)( const struct gl_texture_image *texImage,
1148 GLint i, GLint j, GLint k, GLfloat *texel )
1149 {
1150 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1151 texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
1152 texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
1153 texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
1154 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
1155 }
1156
1157 #if DIM == 3
1158 static void store_texel_argb4444_rev(struct gl_texture_image *texImage,
1159 GLint i, GLint j, GLint k, const void *texel)
1160 {
1161 const GLubyte *rgba = (const GLubyte *) texel;
1162 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1163 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
1164 }
1165 #endif
1166
1167
1168 /* MESA_FORMAT_ARGB1555 ******************************************************/
1169
1170 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
1171 static void FETCH(argb1555)( const struct gl_texture_image *texImage,
1172 GLint i, GLint j, GLint k, GLchan *texel )
1173 {
1174 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1175 const GLushort s = *src;
1176 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
1177 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
1178 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
1179 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
1180 }
1181
1182 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLfloats */
1183 static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
1184 GLint i, GLint j, GLint k, GLfloat *texel )
1185 {
1186 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1187 const GLushort s = *src;
1188 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
1189 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
1190 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
1191 texel[ACOMP] = ((s >> 15) & 0x01);
1192 }
1193
1194 #if DIM == 3
1195 static void store_texel_argb1555(struct gl_texture_image *texImage,
1196 GLint i, GLint j, GLint k, const void *texel)
1197 {
1198 const GLubyte *rgba = (const GLubyte *) texel;
1199 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1200 *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1201 }
1202 #endif
1203
1204
1205 /* MESA_FORMAT_ARGB1555_REV **************************************************/
1206
1207 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
1208 static void FETCH(argb1555_rev)( const struct gl_texture_image *texImage,
1209 GLint i, GLint j, GLint k, GLchan *texel )
1210 {
1211 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1212 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
1213 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
1214 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
1215 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
1216 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
1217 }
1218
1219 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLfloats */
1220 static void FETCH(f_argb1555_rev)( const struct gl_texture_image *texImage,
1221 GLint i, GLint j, GLint k, GLfloat *texel )
1222 {
1223 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1224 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
1225 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
1226 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
1227 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
1228 texel[ACOMP] = ((s >> 15) & 0x01);
1229 }
1230
1231 #if DIM == 3
1232 static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
1233 GLint i, GLint j, GLint k, const void *texel)
1234 {
1235 const GLubyte *rgba = (const GLubyte *) texel;
1236 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1237 *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1238 }
1239 #endif
1240
1241
1242 /* MESA_FORMAT_AL88 **********************************************************/
1243
1244 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
1245 static void FETCH(al88)( const struct gl_texture_image *texImage,
1246 GLint i, GLint j, GLint k, GLchan *texel )
1247 {
1248 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1249 texel[RCOMP] =
1250 texel[GCOMP] =
1251 texel[BCOMP] = UBYTE_TO_CHAN( s & 0xff );
1252 texel[ACOMP] = UBYTE_TO_CHAN( s >> 8 );
1253 }
1254
1255 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLfloats */
1256 static void FETCH(f_al88)( const struct gl_texture_image *texImage,
1257 GLint i, GLint j, GLint k, GLfloat *texel )
1258 {
1259 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1260 texel[RCOMP] =
1261 texel[GCOMP] =
1262 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
1263 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
1264 }
1265
1266 #if DIM == 3
1267 static void store_texel_al88(struct gl_texture_image *texImage,
1268 GLint i, GLint j, GLint k, const void *texel)
1269 {
1270 const GLubyte *rgba = (const GLubyte *) texel;
1271 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1272 *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
1273 }
1274 #endif
1275
1276
1277 /* MESA_FORMAT_AL88_REV ******************************************************/
1278
1279 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
1280 static void FETCH(al88_rev)( const struct gl_texture_image *texImage,
1281 GLint i, GLint j, GLint k, GLchan *texel )
1282 {
1283 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1284 texel[RCOMP] =
1285 texel[GCOMP] =
1286 texel[BCOMP] = UBYTE_TO_CHAN( s >> 8 );
1287 texel[ACOMP] = UBYTE_TO_CHAN( s & 0xff );
1288 }
1289
1290 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLfloats */
1291 static void FETCH(f_al88_rev)( const struct gl_texture_image *texImage,
1292 GLint i, GLint j, GLint k, GLfloat *texel )
1293 {
1294 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1295 texel[RCOMP] =
1296 texel[GCOMP] =
1297 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
1298 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
1299 }
1300
1301 #if DIM == 3
1302 static void store_texel_al88_rev(struct gl_texture_image *texImage,
1303 GLint i, GLint j, GLint k, const void *texel)
1304 {
1305 const GLubyte *rgba = (const GLubyte *) texel;
1306 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1307 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
1308 }
1309 #endif
1310
1311
1312 /* MESA_FORMAT_RGB332 ********************************************************/
1313
1314 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1315 static void FETCH(rgb332)( const struct gl_texture_image *texImage,
1316 GLint i, GLint j, GLint k, GLchan *texel )
1317 {
1318 static const GLubyte lut2to8[4] = {0, 85, 170, 255};
1319 static const GLubyte lut3to8[8] = {0, 36, 73, 109, 146, 182, 219, 255};
1320 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1321 const GLubyte s = *src;
1322 texel[RCOMP] = UBYTE_TO_CHAN( lut3to8[(s >> 5) & 0x7] );
1323 texel[GCOMP] = UBYTE_TO_CHAN( lut3to8[(s >> 2) & 0x7] );
1324 texel[BCOMP] = UBYTE_TO_CHAN( lut2to8[(s ) & 0x3] );
1325 texel[ACOMP] = CHAN_MAX;
1326 }
1327
1328 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLfloats */
1329 static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
1330 GLint i, GLint j, GLint k, GLfloat *texel )
1331 {
1332 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1333 const GLubyte s = *src;
1334 texel[RCOMP] = ((s ) & 0xe0) * (1.0F / 224.0F);
1335 texel[GCOMP] = ((s << 3) & 0xe0) * (1.0F / 224.0F);
1336 texel[BCOMP] = ((s << 6) & 0xc0) * (1.0F / 192.0F);
1337 texel[ACOMP] = 1.0F;
1338 }
1339
1340 #if DIM == 3
1341 static void store_texel_rgb332(struct gl_texture_image *texImage,
1342 GLint i, GLint j, GLint k, const void *texel)
1343 {
1344 const GLubyte *rgba = (const GLubyte *) texel;
1345 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1346 *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1347 }
1348 #endif
1349
1350
1351 /* MESA_FORMAT_A8 ************************************************************/
1352
1353 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1354 static void FETCH(a8)( const struct gl_texture_image *texImage,
1355 GLint i, GLint j, GLint k, GLchan *texel )
1356 {
1357 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1358 texel[RCOMP] =
1359 texel[GCOMP] =
1360 texel[BCOMP] = 0;
1361 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
1362 }
1363
1364 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLfloats */
1365 static void FETCH(f_a8)( const struct gl_texture_image *texImage,
1366 GLint i, GLint j, GLint k, GLfloat *texel )
1367 {
1368 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1369 texel[RCOMP] =
1370 texel[GCOMP] =
1371 texel[BCOMP] = 0.0;
1372 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1373 }
1374
1375 #if DIM == 3
1376 static void store_texel_a8(struct gl_texture_image *texImage,
1377 GLint i, GLint j, GLint k, const void *texel)
1378 {
1379 const GLubyte *rgba = (const GLubyte *) texel;
1380 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1381 *dst = rgba[ACOMP];
1382 }
1383 #endif
1384
1385
1386 /* MESA_FORMAT_L8 ************************************************************/
1387
1388 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1389 static void FETCH(l8)( const struct gl_texture_image *texImage,
1390 GLint i, GLint j, GLint k, GLchan *texel )
1391 {
1392 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1393 texel[RCOMP] =
1394 texel[GCOMP] =
1395 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
1396 texel[ACOMP] = CHAN_MAX;
1397 }
1398
1399 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLfloats */
1400 static void FETCH(f_l8)( const struct gl_texture_image *texImage,
1401 GLint i, GLint j, GLint k, GLfloat *texel )
1402 {
1403 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1404 texel[RCOMP] =
1405 texel[GCOMP] =
1406 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
1407 texel[ACOMP] = 1.0F;
1408 }
1409
1410 #if DIM == 3
1411 static void store_texel_l8(struct gl_texture_image *texImage,
1412 GLint i, GLint j, GLint k, const void *texel)
1413 {
1414 const GLubyte *rgba = (const GLubyte *) texel;
1415 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1416 *dst = rgba[RCOMP];
1417 }
1418 #endif
1419
1420
1421 /* MESA_FORMAT_I8 ************************************************************/
1422
1423 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1424 static void FETCH(i8)( const struct gl_texture_image *texImage,
1425 GLint i, GLint j, GLint k, GLchan *texel )
1426 {
1427 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1428 texel[RCOMP] =
1429 texel[GCOMP] =
1430 texel[BCOMP] =
1431 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
1432 }
1433
1434 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLfloats */
1435 static void FETCH(f_i8)( const struct gl_texture_image *texImage,
1436 GLint i, GLint j, GLint k, GLfloat *texel )
1437 {
1438 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1439 texel[RCOMP] =
1440 texel[GCOMP] =
1441 texel[BCOMP] =
1442 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1443 }
1444
1445 #if DIM == 3
1446 static void store_texel_i8(struct gl_texture_image *texImage,
1447 GLint i, GLint j, GLint k, const void *texel)
1448 {
1449 const GLubyte *rgba = (const GLubyte *) texel;
1450 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1451 *dst = rgba[RCOMP];
1452 }
1453 #endif
1454
1455
1456 /* MESA_FORMAT_CI8 ***********************************************************/
1457
1458 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1459 * color table, and return 4 GLchans.
1460 */
1461 static void FETCH(ci8)( const struct gl_texture_image *texImage,
1462 GLint i, GLint j, GLint k, GLchan *texel )
1463 {
1464 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1465 const struct gl_color_table *palette;
1466 const GLchan *table;
1467 GLuint index;
1468 GET_CURRENT_CONTEXT(ctx);
1469
1470 if (ctx->Texture.SharedPalette) {
1471 palette = &ctx->Texture.Palette;
1472 }
1473 else {
1474 palette = &texImage->TexObject->Palette;
1475 }
1476 if (palette->Size == 0)
1477 return; /* undefined results */
1478 ASSERT(palette->Type != GL_FLOAT);
1479 table = (const GLchan *) palette->Table;
1480
1481 /* Mask the index against size of palette to avoid going out of bounds */
1482 index = (*src) & (palette->Size - 1);
1483
1484 switch (palette->Format) {
1485 case GL_ALPHA:
1486 texel[RCOMP] =
1487 texel[GCOMP] =
1488 texel[BCOMP] = 0;
1489 texel[ACOMP] = table[index];
1490 return;
1491 case GL_LUMINANCE:
1492 texel[RCOMP] =
1493 texel[GCOMP] =
1494 texel[BCOMP] = table[index];
1495 texel[ACOMP] = CHAN_MAX;
1496 break;
1497 case GL_INTENSITY:
1498 texel[RCOMP] =
1499 texel[GCOMP] =
1500 texel[BCOMP] =
1501 texel[ACOMP] = table[index];
1502 return;
1503 case GL_LUMINANCE_ALPHA:
1504 texel[RCOMP] =
1505 texel[GCOMP] =
1506 texel[BCOMP] = table[index * 2 + 0];
1507 texel[ACOMP] = table[index * 2 + 1];
1508 return;
1509 case GL_RGB:
1510 texel[RCOMP] = table[index * 3 + 0];
1511 texel[GCOMP] = table[index * 3 + 1];
1512 texel[BCOMP] = table[index * 3 + 2];
1513 texel[ACOMP] = CHAN_MAX;
1514 return;
1515 case GL_RGBA:
1516 texel[RCOMP] = table[index * 4 + 0];
1517 texel[GCOMP] = table[index * 4 + 1];
1518 texel[BCOMP] = table[index * 4 + 2];
1519 texel[ACOMP] = table[index * 4 + 3];
1520 return;
1521 default:
1522 _mesa_problem(ctx, "Bad palette format in palette_sample");
1523 }
1524 }
1525
1526
1527 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1528 * color table, and return 4 GLfloats.
1529 */
1530 static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
1531 GLint i, GLint j, GLint k, GLfloat *texel )
1532 {
1533 GLchan rgba[4];
1534 /* Sample as GLchan */
1535 FETCH(ci8)(texImage, i, j, k, rgba);
1536 /* and return as floats */
1537 texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
1538 texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
1539 texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
1540 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
1541 }
1542
1543 #if DIM == 3
1544 static void store_texel_ci8(struct gl_texture_image *texImage,
1545 GLint i, GLint j, GLint k, const void *texel)
1546 {
1547 const GLubyte *index = (const GLubyte *) texel;
1548 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1549 *dst = *index;
1550 }
1551 #endif
1552
1553
1554 /* MESA_FORMAT_YCBCR *********************************************************/
1555
1556 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
1557 /* We convert YCbCr to RGB here */
1558 /* XXX this may break if GLchan != GLubyte */
1559 static void FETCH(ycbcr)( const struct gl_texture_image *texImage,
1560 GLint i, GLint j, GLint k, GLchan *texel )
1561 {
1562 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1563 const GLushort *src1 = src0 + 1; /* odd */
1564 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1565 const GLubyte cb = *src0 & 0xff; /* chroma U */
1566 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1567 const GLubyte cr = *src1 & 0xff; /* chroma V */
1568 GLint r, g, b;
1569 if (i & 1) {
1570 /* odd pixel: use y1,cr,cb */
1571 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
1572 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1573 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
1574 }
1575 else {
1576 /* even pixel: use y0,cr,cb */
1577 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
1578 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1579 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
1580 }
1581 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
1582 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
1583 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
1584 texel[ACOMP] = CHAN_MAX;
1585 }
1586
1587 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats */
1588 /* We convert YCbCr to RGB here */
1589 static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
1590 GLint i, GLint j, GLint k, GLfloat *texel )
1591 {
1592 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1593 const GLushort *src1 = src0 + 1; /* odd */
1594 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1595 const GLubyte cb = *src0 & 0xff; /* chroma U */
1596 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1597 const GLubyte cr = *src1 & 0xff; /* chroma V */
1598 GLfloat r, g, b;
1599 if (i & 1) {
1600 /* odd pixel: use y1,cr,cb */
1601 r = (1.164 * (y1-16) + 1.596 * (cr-128));
1602 g = (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1603 b = (1.164 * (y1-16) + 2.018 * (cb-128));
1604 }
1605 else {
1606 /* even pixel: use y0,cr,cb */
1607 r = (1.164 * (y0-16) + 1.596 * (cr-128));
1608 g = (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1609 b = (1.164 * (y0-16) + 2.018 * (cb-128));
1610 }
1611 /* XXX remove / 255 here by tweaking arithmetic above */
1612 r /= 255.0;
1613 g /= 255.0;
1614 b /= 255.0;
1615 /* XXX should we really clamp??? */
1616 texel[RCOMP] = CLAMP(r, 0.0, 1.0);
1617 texel[GCOMP] = CLAMP(g, 0.0, 1.0);
1618 texel[BCOMP] = CLAMP(b, 0.0, 1.0);
1619 texel[ACOMP] = 1.0F;
1620 }
1621
1622 #if DIM == 3
1623 static void store_texel_ycbcr(struct gl_texture_image *texImage,
1624 GLint i, GLint j, GLint k, const void *texel)
1625 {
1626 /* XXX to do */
1627 }
1628 #endif
1629
1630
1631 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1632
1633 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
1634 /* We convert YCbCr to RGB here */
1635 /* XXX this may break if GLchan != GLubyte */
1636 static void FETCH(ycbcr_rev)( const struct gl_texture_image *texImage,
1637 GLint i, GLint j, GLint k, GLchan *texel )
1638 {
1639 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1640 const GLushort *src1 = src0 + 1; /* odd */
1641 const GLubyte y0 = *src0 & 0xff; /* luminance */
1642 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1643 const GLubyte y1 = *src1 & 0xff; /* luminance */
1644 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1645 GLint r, g, b;
1646 if (i & 1) {
1647 /* odd pixel: use y1,cr,cb */
1648 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
1649 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1650 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
1651 }
1652 else {
1653 /* even pixel: use y0,cr,cb */
1654 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
1655 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1656 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
1657 }
1658 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
1659 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
1660 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
1661 texel[ACOMP] = CHAN_MAX;
1662 }
1663
1664 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
1665 /* We convert YCbCr to RGB here */
1666 static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
1667 GLint i, GLint j, GLint k, GLfloat *texel )
1668 {
1669 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1670 const GLushort *src1 = src0 + 1; /* odd */
1671 const GLubyte y0 = *src0 & 0xff; /* luminance */
1672 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1673 const GLubyte y1 = *src1 & 0xff; /* luminance */
1674 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1675 GLfloat r, g, b;
1676 if (i & 1) {
1677 /* odd pixel: use y1,cr,cb */
1678 r = (1.164 * (y1-16) + 1.596 * (cr-128));
1679 g = (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1680 b = (1.164 * (y1-16) + 2.018 * (cb-128));
1681 }
1682 else {
1683 /* even pixel: use y0,cr,cb */
1684 r = (1.164 * (y0-16) + 1.596 * (cr-128));
1685 g = (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1686 b = (1.164 * (y0-16) + 2.018 * (cb-128));
1687 }
1688 /* XXX remove / 255 here by tweaking arithmetic above */
1689 r /= 255.0;
1690 g /= 255.0;
1691 b /= 255.0;
1692 /* XXX should we really clamp??? */
1693 texel[RCOMP] = CLAMP(r, 0.0, 1.0);
1694 texel[GCOMP] = CLAMP(g, 0.0, 1.0);
1695 texel[BCOMP] = CLAMP(b, 0.0, 1.0);
1696 texel[ACOMP] = 1.0F;
1697 }
1698
1699 #if DIM == 3
1700 static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
1701 GLint i, GLint j, GLint k, const void *texel)
1702 {
1703 /* XXX to do */
1704 }
1705 #endif
1706
1707
1708
1709 #undef TEXEL_ADDR
1710 #undef DIM
1711 #undef FETCH