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