fix for-loop in _mesa_GetDouble to avoid out of bounds memory read
[mesa.git] / src / mesa / main / texformat_tmp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
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 /* MESA_FORMAT_RGB565 ********************************************************/
1066
1067 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
1068 static void FETCH(rgb565)( const struct gl_texture_image *texImage,
1069 GLint i, GLint j, GLint k, GLchan *texel )
1070 {
1071 const GLushort *src = USHORT_ADDR( texImage, i, j, k );
1072 const GLushort s = *src;
1073 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) * 255 / 0xf8 );
1074 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) * 255 / 0xfc );
1075 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) * 255 / 0xf8 );
1076 texel[ACOMP] = CHAN_MAX;
1077 }
1078
1079 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
1080 static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
1081 GLint i, GLint j, GLint k, GLfloat *texel )
1082 {
1083 const GLushort *src = USHORT_ADDR( texImage, i, j, k );
1084 const GLushort s = *src;
1085 texel[RCOMP] = ((s >> 8) & 0xf8) * (1.0F / 248.0F);
1086 texel[GCOMP] = ((s >> 3) & 0xfc) * (1.0F / 252.0F);
1087 texel[BCOMP] = ((s << 3) & 0xf8) * (1.0F / 248.0F);
1088 texel[ACOMP] = 1.0F;
1089 }
1090
1091 #if DIM == 3
1092 static void store_texel_rgb565(struct gl_texture_image *texImage,
1093 GLint i, GLint j, GLint k, const void *texel)
1094 {
1095 const GLubyte *rgba = (const GLubyte *) texel;
1096 GLushort *dst = USHORT_ADDR(texImage, i, j, k);
1097 *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1098 }
1099 #endif
1100
1101
1102 /* MESA_FORMAT_RGB565_REV ****************************************************/
1103
1104 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
1105 static void FETCH(rgb565_rev)( const struct gl_texture_image *texImage,
1106 GLint i, GLint j, GLint k, GLchan *texel )
1107 {
1108 const GLushort *src = USHORT_ADDR( texImage, i, j, k );
1109 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
1110 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) * 255 / 0xf8 );
1111 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) * 255 / 0xfc );
1112 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) * 255 / 0xf8 );
1113 texel[ACOMP] = CHAN_MAX;
1114 }
1115
1116 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLfloats */
1117 static void FETCH(f_rgb565_rev)( const struct gl_texture_image *texImage,
1118 GLint i, GLint j, GLint k, GLfloat *texel )
1119 {
1120 const GLushort *src = USHORT_ADDR( texImage, i, j, k );
1121 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
1122 texel[RCOMP] = ((s >> 8) & 0xf8) * (1.0F / 248.0F);
1123 texel[GCOMP] = ((s >> 3) & 0xfc) * (1.0F / 252.0F);
1124 texel[BCOMP] = ((s << 3) & 0xf8) * (1.0F / 248.0F);
1125 texel[ACOMP] = 1.0F;
1126 }
1127
1128 #if DIM == 3
1129 static void store_texel_rgb565_rev(struct gl_texture_image *texImage,
1130 GLint i, GLint j, GLint k, const void *texel)
1131 {
1132 const GLubyte *rgba = (const GLubyte *) texel;
1133 GLushort *dst = USHORT_ADDR(texImage, i, j, k);
1134 *dst = PACK_COLOR_565(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
1135 }
1136 #endif
1137
1138
1139 /* MESA_FORMAT_ARGB4444 ******************************************************/
1140
1141 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
1142 static void FETCH(argb4444)( const struct gl_texture_image *texImage,
1143 GLint i, GLint j, GLint k, GLchan *texel )
1144 {
1145 const GLushort *src = USHORT_ADDR( texImage, i, j, k );
1146 const GLushort s = *src;
1147 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf );
1148 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf );
1149 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf );
1150 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) * 255 / 0xf );
1151 }
1152
1153 /* Fetch texel from 1D, 2D or 3D argb4444 texture, return 4 GLfloats */
1154 static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
1155 GLint i, GLint j, GLint k, GLfloat *texel )
1156 {
1157 const GLushort *src = USHORT_ADDR( texImage, i, j, k );
1158 const GLushort s = *src;
1159 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
1160 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
1161 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
1162 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
1163 }
1164
1165 #if DIM == 3
1166 static void store_texel_argb4444(struct gl_texture_image *texImage,
1167 GLint i, GLint j, GLint k, const void *texel)
1168 {
1169 const GLubyte *rgba = (const GLubyte *) texel;
1170 GLushort *dst = USHORT_ADDR(texImage, i, j, k);
1171 *dst = PACK_COLOR_4444(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1172 }
1173 #endif
1174
1175
1176 /* MESA_FORMAT_ARGB4444_REV **************************************************/
1177
1178 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
1179 static void FETCH(argb4444_rev)( const struct gl_texture_image *texImage,
1180 GLint i, GLint j, GLint k, GLchan *texel )
1181 {
1182 const GLushort s = *USHORT_ADDR( texImage, i, j, k );
1183 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf );
1184 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) * 255 / 0xf );
1185 texel[BCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf );
1186 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf );
1187 }
1188
1189 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLfloats */
1190 static void FETCH(f_argb4444_rev)( const struct gl_texture_image *texImage,
1191 GLint i, GLint j, GLint k, GLfloat *texel )
1192 {
1193 const GLushort s = *USHORT_ADDR( texImage, i, j, k );
1194 texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
1195 texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
1196 texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
1197 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
1198 }
1199
1200 #if DIM == 3
1201 static void store_texel_argb4444_rev(struct gl_texture_image *texImage,
1202 GLint i, GLint j, GLint k, const void *texel)
1203 {
1204 const GLubyte *rgba = (const GLubyte *) texel;
1205 GLushort *dst = USHORT_ADDR(texImage, i, j, k);
1206 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
1207 }
1208 #endif
1209
1210
1211 /* MESA_FORMAT_ARGB1555 ******************************************************/
1212
1213 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
1214 static void FETCH(argb1555)( const struct gl_texture_image *texImage,
1215 GLint i, GLint j, GLint k, GLchan *texel )
1216 {
1217 const GLushort *src = USHORT_ADDR( texImage, i, j, k );
1218 const GLushort s = *src;
1219 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0x1f) * 255 / 0x1f );
1220 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0x1f) * 255 / 0x1f );
1221 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0x1f) * 255 / 0x1f );
1222 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
1223 }
1224
1225 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLfloats */
1226 static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
1227 GLint i, GLint j, GLint k, GLfloat *texel )
1228 {
1229 const GLushort *src = USHORT_ADDR( texImage, i, j, k );
1230 const GLushort s = *src;
1231 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
1232 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
1233 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
1234 texel[ACOMP] = ((s >> 15) & 0x01);
1235 }
1236
1237 #if DIM == 3
1238 static void store_texel_argb1555(struct gl_texture_image *texImage,
1239 GLint i, GLint j, GLint k, const void *texel)
1240 {
1241 const GLubyte *rgba = (const GLubyte *) texel;
1242 GLushort *dst = USHORT_ADDR(texImage, i, j, k);
1243 *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1244 }
1245 #endif
1246
1247
1248 /* MESA_FORMAT_ARGB1555_REV **************************************************/
1249
1250 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
1251 static void FETCH(argb1555_rev)( const struct gl_texture_image *texImage,
1252 GLint i, GLint j, GLint k, GLchan *texel )
1253 {
1254 const GLushort *src = USHORT_ADDR( texImage, i, j, k );
1255 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
1256 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0x1f) * 255 / 0x1f );
1257 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0x1f) * 255 / 0x1f );
1258 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0x1f) * 255 / 0x1f );
1259 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
1260 }
1261
1262 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLfloats */
1263 static void FETCH(f_argb1555_rev)( const struct gl_texture_image *texImage,
1264 GLint i, GLint j, GLint k, GLfloat *texel )
1265 {
1266 const GLushort *src = USHORT_ADDR( texImage, i, j, k );
1267 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
1268 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
1269 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
1270 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
1271 texel[ACOMP] = ((s >> 15) & 0x01);
1272 }
1273
1274 #if DIM == 3
1275 static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
1276 GLint i, GLint j, GLint k, const void *texel)
1277 {
1278 const GLubyte *rgba = (const GLubyte *) texel;
1279 GLushort *dst = USHORT_ADDR(texImage, i, j, k);
1280 *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1281 }
1282 #endif
1283
1284
1285 /* MESA_FORMAT_AL88 **********************************************************/
1286
1287 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
1288 static void FETCH(al88)( const struct gl_texture_image *texImage,
1289 GLint i, GLint j, GLint k, GLchan *texel )
1290 {
1291 const GLushort s = *USHORT_ADDR( texImage, i, j, k );
1292 texel[RCOMP] =
1293 texel[GCOMP] =
1294 texel[BCOMP] = UBYTE_TO_CHAN( s & 0xff );
1295 texel[ACOMP] = UBYTE_TO_CHAN( s >> 8 );
1296 }
1297
1298 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLfloats */
1299 static void FETCH(f_al88)( const struct gl_texture_image *texImage,
1300 GLint i, GLint j, GLint k, GLfloat *texel )
1301 {
1302 const GLushort s = *USHORT_ADDR( texImage, i, j, k );
1303 texel[RCOMP] =
1304 texel[GCOMP] =
1305 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
1306 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
1307 }
1308
1309 #if DIM == 3
1310 static void store_texel_al88(struct gl_texture_image *texImage,
1311 GLint i, GLint j, GLint k, const void *texel)
1312 {
1313 const GLubyte *rgba = (const GLubyte *) texel;
1314 GLushort *dst = USHORT_ADDR(texImage, i, j, k);
1315 *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
1316 }
1317 #endif
1318
1319
1320 /* MESA_FORMAT_AL88_REV ******************************************************/
1321
1322 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
1323 static void FETCH(al88_rev)( const struct gl_texture_image *texImage,
1324 GLint i, GLint j, GLint k, GLchan *texel )
1325 {
1326 const GLushort s = *USHORT_ADDR( texImage, i, j, k );
1327 texel[RCOMP] =
1328 texel[GCOMP] =
1329 texel[BCOMP] = UBYTE_TO_CHAN( s >> 8 );
1330 texel[ACOMP] = UBYTE_TO_CHAN( s & 0xff );
1331 }
1332
1333 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLfloats */
1334 static void FETCH(f_al88_rev)( const struct gl_texture_image *texImage,
1335 GLint i, GLint j, GLint k, GLfloat *texel )
1336 {
1337 const GLushort s = *USHORT_ADDR( texImage, i, j, k );
1338 texel[RCOMP] =
1339 texel[GCOMP] =
1340 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
1341 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
1342 }
1343
1344 #if DIM == 3
1345 static void store_texel_al88_rev(struct gl_texture_image *texImage,
1346 GLint i, GLint j, GLint k, const void *texel)
1347 {
1348 const GLubyte *rgba = (const GLubyte *) texel;
1349 GLushort *dst = USHORT_ADDR(texImage, i, j, k);
1350 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
1351 }
1352 #endif
1353
1354
1355 /* MESA_FORMAT_RGB332 ********************************************************/
1356
1357 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1358 static void FETCH(rgb332)( const struct gl_texture_image *texImage,
1359 GLint i, GLint j, GLint k, GLchan *texel )
1360 {
1361 const GLubyte *src = UBYTE_ADDR( texImage, i, j, k, 1 );
1362 const GLubyte s = *src;
1363 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xe0) * 255 / 0xe0 );
1364 texel[GCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xe0) * 255 / 0xe0 );
1365 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 6) & 0xc0) * 255 / 0xc0 );
1366 texel[ACOMP] = CHAN_MAX;
1367 }
1368
1369 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLfloats */
1370 static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
1371 GLint i, GLint j, GLint k, GLfloat *texel )
1372 {
1373 const GLubyte *src = UBYTE_ADDR( texImage, i, j, k, 1 );
1374 const GLubyte s = *src;
1375 texel[RCOMP] = ((s ) & 0xe0) * (1.0F / 224.0F);
1376 texel[GCOMP] = ((s << 3) & 0xe0) * (1.0F / 224.0F);
1377 texel[BCOMP] = ((s << 6) & 0xc0) * (1.0F / 192.0F);
1378 texel[ACOMP] = 1.0F;
1379 }
1380
1381 #if DIM == 3
1382 static void store_texel_rgb332(struct gl_texture_image *texImage,
1383 GLint i, GLint j, GLint k, const void *texel)
1384 {
1385 const GLubyte *rgba = (const GLubyte *) texel;
1386 GLubyte *dst = UBYTE_ADDR(texImage, i, j, k, 1);
1387 *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1388 }
1389 #endif
1390
1391
1392 /* MESA_FORMAT_A8 ************************************************************/
1393
1394 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1395 static void FETCH(a8)( const struct gl_texture_image *texImage,
1396 GLint i, GLint j, GLint k, GLchan *texel )
1397 {
1398 const GLubyte *src = UBYTE_ADDR( texImage, i, j, k, 1 );
1399 texel[RCOMP] =
1400 texel[GCOMP] =
1401 texel[BCOMP] = 0;
1402 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
1403 }
1404
1405 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLfloats */
1406 static void FETCH(f_a8)( const struct gl_texture_image *texImage,
1407 GLint i, GLint j, GLint k, GLfloat *texel )
1408 {
1409 const GLubyte *src = UBYTE_ADDR( texImage, i, j, k, 1 );
1410 texel[RCOMP] =
1411 texel[GCOMP] =
1412 texel[BCOMP] = 0.0;
1413 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1414 }
1415
1416 #if DIM == 3
1417 static void store_texel_a8(struct gl_texture_image *texImage,
1418 GLint i, GLint j, GLint k, const void *texel)
1419 {
1420 const GLubyte *rgba = (const GLubyte *) texel;
1421 GLubyte *dst = UBYTE_ADDR(texImage, i, j, k, 1);
1422 *dst = rgba[ACOMP];
1423 }
1424 #endif
1425
1426
1427 /* MESA_FORMAT_L8 ************************************************************/
1428
1429 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1430 static void FETCH(l8)( const struct gl_texture_image *texImage,
1431 GLint i, GLint j, GLint k, GLchan *texel )
1432 {
1433 const GLubyte *src = UBYTE_ADDR( texImage, i, j, k, 1 );
1434 texel[RCOMP] =
1435 texel[GCOMP] =
1436 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
1437 texel[ACOMP] = CHAN_MAX;
1438 }
1439
1440 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLfloats */
1441 static void FETCH(f_l8)( const struct gl_texture_image *texImage,
1442 GLint i, GLint j, GLint k, GLfloat *texel )
1443 {
1444 const GLubyte *src = UBYTE_ADDR( texImage, i, j, k, 1 );
1445 texel[RCOMP] =
1446 texel[GCOMP] =
1447 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
1448 texel[ACOMP] = 1.0F;
1449 }
1450
1451 #if DIM == 3
1452 static void store_texel_l8(struct gl_texture_image *texImage,
1453 GLint i, GLint j, GLint k, const void *texel)
1454 {
1455 const GLubyte *rgba = (const GLubyte *) texel;
1456 GLubyte *dst = UBYTE_ADDR(texImage, i, j, k, 1);
1457 *dst = rgba[RCOMP];
1458 }
1459 #endif
1460
1461
1462 /* MESA_FORMAT_I8 ************************************************************/
1463
1464 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1465 static void FETCH(i8)( const struct gl_texture_image *texImage,
1466 GLint i, GLint j, GLint k, GLchan *texel )
1467 {
1468 const GLubyte *src = UBYTE_ADDR( texImage, i, j, k, 1 );
1469 texel[RCOMP] =
1470 texel[GCOMP] =
1471 texel[BCOMP] =
1472 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
1473 }
1474
1475 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLfloats */
1476 static void FETCH(f_i8)( const struct gl_texture_image *texImage,
1477 GLint i, GLint j, GLint k, GLfloat *texel )
1478 {
1479 const GLubyte *src = UBYTE_ADDR( texImage, i, j, k, 1 );
1480 texel[RCOMP] =
1481 texel[GCOMP] =
1482 texel[BCOMP] =
1483 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1484 }
1485
1486 #if DIM == 3
1487 static void store_texel_i8(struct gl_texture_image *texImage,
1488 GLint i, GLint j, GLint k, const void *texel)
1489 {
1490 const GLubyte *rgba = (const GLubyte *) texel;
1491 GLubyte *dst = UBYTE_ADDR(texImage, i, j, k, 1);
1492 *dst = rgba[RCOMP];
1493 }
1494 #endif
1495
1496
1497 /* MESA_FORMAT_CI8 ***********************************************************/
1498
1499 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1500 * color table, and return 4 GLchans.
1501 */
1502 static void FETCH(ci8)( const struct gl_texture_image *texImage,
1503 GLint i, GLint j, GLint k, GLchan *texel )
1504 {
1505 const GLubyte *src = UBYTE_ADDR( texImage, i, j, k, 1 );
1506 const struct gl_color_table *palette;
1507 const GLchan *table;
1508 GLuint index;
1509 GET_CURRENT_CONTEXT(ctx);
1510
1511 if (ctx->Texture.SharedPalette) {
1512 palette = &ctx->Texture.Palette;
1513 }
1514 else {
1515 palette = &texImage->TexObject->Palette;
1516 }
1517 if (palette->Size == 0)
1518 return; /* undefined results */
1519 ASSERT(palette->Type != GL_FLOAT);
1520 table = (const GLchan *) palette->Table;
1521
1522 /* Mask the index against size of palette to avoid going out of bounds */
1523 index = (*src) & (palette->Size - 1);
1524
1525 switch (palette->Format) {
1526 case GL_ALPHA:
1527 texel[RCOMP] =
1528 texel[GCOMP] =
1529 texel[BCOMP] = 0;
1530 texel[ACOMP] = table[index];
1531 return;
1532 case GL_LUMINANCE:
1533 texel[RCOMP] =
1534 texel[GCOMP] =
1535 texel[BCOMP] = table[index];
1536 texel[ACOMP] = CHAN_MAX;
1537 break;
1538 case GL_INTENSITY:
1539 texel[RCOMP] =
1540 texel[GCOMP] =
1541 texel[BCOMP] =
1542 texel[ACOMP] = table[index];
1543 return;
1544 case GL_LUMINANCE_ALPHA:
1545 texel[RCOMP] =
1546 texel[GCOMP] =
1547 texel[BCOMP] = table[index * 2 + 0];
1548 texel[ACOMP] = table[index * 2 + 1];
1549 return;
1550 case GL_RGB:
1551 texel[RCOMP] = table[index * 3 + 0];
1552 texel[GCOMP] = table[index * 3 + 1];
1553 texel[BCOMP] = table[index * 3 + 2];
1554 texel[ACOMP] = CHAN_MAX;
1555 return;
1556 case GL_RGBA:
1557 texel[RCOMP] = table[index * 4 + 0];
1558 texel[GCOMP] = table[index * 4 + 1];
1559 texel[BCOMP] = table[index * 4 + 2];
1560 texel[ACOMP] = table[index * 4 + 3];
1561 return;
1562 default:
1563 _mesa_problem(ctx, "Bad palette format in palette_sample");
1564 }
1565 }
1566
1567
1568 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1569 * color table, and return 4 GLfloats.
1570 */
1571 static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
1572 GLint i, GLint j, GLint k, GLfloat *texel )
1573 {
1574 GLchan rgba[4];
1575 /* Sample as GLchan */
1576 FETCH(ci8)(texImage, i, j, k, rgba);
1577 /* and return as floats */
1578 texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
1579 texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
1580 texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
1581 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
1582 }
1583
1584 #if DIM == 3
1585 static void store_texel_ci8(struct gl_texture_image *texImage,
1586 GLint i, GLint j, GLint k, const void *texel)
1587 {
1588 const GLubyte *index = (const GLubyte *) texel;
1589 GLubyte *dst = UBYTE_ADDR(texImage, i, j, k, 1);
1590 *dst = *index;
1591 }
1592 #endif
1593
1594
1595 /* MESA_FORMAT_YCBCR *********************************************************/
1596
1597 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
1598 /* We convert YCbCr to RGB here */
1599 /* XXX this may break if GLchan != GLubyte */
1600 static void FETCH(ycbcr)( const struct gl_texture_image *texImage,
1601 GLint i, GLint j, GLint k, GLchan *texel )
1602 {
1603 const GLushort *src0 = USHORT_ADDR( texImage, (i & ~1), j, k ); /* even */
1604 const GLushort *src1 = src0 + 1; /* odd */
1605 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1606 const GLubyte cb = *src0 & 0xff; /* chroma U */
1607 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1608 const GLubyte cr = *src1 & 0xff; /* chroma V */
1609 GLint r, g, b;
1610 if (i & 1) {
1611 /* odd pixel: use y1,cr,cb */
1612 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
1613 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1614 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
1615 }
1616 else {
1617 /* even pixel: use y0,cr,cb */
1618 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
1619 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1620 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
1621 }
1622 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
1623 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
1624 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
1625 texel[ACOMP] = CHAN_MAX;
1626 }
1627
1628 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats */
1629 /* We convert YCbCr to RGB here */
1630 static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
1631 GLint i, GLint j, GLint k, GLfloat *texel )
1632 {
1633 const GLushort *src0 = USHORT_ADDR( texImage, (i & ~1), j, k ); /* even */
1634 const GLushort *src1 = src0 + 1; /* odd */
1635 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1636 const GLubyte cb = *src0 & 0xff; /* chroma U */
1637 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1638 const GLubyte cr = *src1 & 0xff; /* chroma V */
1639 GLfloat r, g, b;
1640 if (i & 1) {
1641 /* odd pixel: use y1,cr,cb */
1642 r = (1.164 * (y1-16) + 1.596 * (cr-128));
1643 g = (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1644 b = (1.164 * (y1-16) + 2.018 * (cb-128));
1645 }
1646 else {
1647 /* even pixel: use y0,cr,cb */
1648 r = (1.164 * (y0-16) + 1.596 * (cr-128));
1649 g = (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1650 b = (1.164 * (y0-16) + 2.018 * (cb-128));
1651 }
1652 /* XXX remove / 255 here by tweaking arithmetic above */
1653 r /= 255.0;
1654 g /= 255.0;
1655 b /= 255.0;
1656 /* XXX should we really clamp??? */
1657 texel[RCOMP] = CLAMP(r, 0.0, 1.0);
1658 texel[GCOMP] = CLAMP(g, 0.0, 1.0);
1659 texel[BCOMP] = CLAMP(b, 0.0, 1.0);
1660 texel[ACOMP] = 1.0F;
1661 }
1662
1663 #if DIM == 3
1664 static void store_texel_ycbcr(struct gl_texture_image *texImage,
1665 GLint i, GLint j, GLint k, const void *texel)
1666 {
1667 /* XXX to do */
1668 }
1669 #endif
1670
1671
1672 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1673
1674 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
1675 /* We convert YCbCr to RGB here */
1676 /* XXX this may break if GLchan != GLubyte */
1677 static void FETCH(ycbcr_rev)( const struct gl_texture_image *texImage,
1678 GLint i, GLint j, GLint k, GLchan *texel )
1679 {
1680 const GLushort *src0 = USHORT_ADDR( texImage, (i & ~1), j, k ); /* even */
1681 const GLushort *src1 = src0 + 1; /* odd */
1682 const GLubyte y0 = *src0 & 0xff; /* luminance */
1683 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1684 const GLubyte y1 = *src1 & 0xff; /* luminance */
1685 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1686 GLint r, g, b;
1687 if (i & 1) {
1688 /* odd pixel: use y1,cr,cb */
1689 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
1690 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1691 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
1692 }
1693 else {
1694 /* even pixel: use y0,cr,cb */
1695 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
1696 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1697 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
1698 }
1699 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
1700 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
1701 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
1702 texel[ACOMP] = CHAN_MAX;
1703 }
1704
1705 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
1706 /* We convert YCbCr to RGB here */
1707 static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
1708 GLint i, GLint j, GLint k, GLfloat *texel )
1709 {
1710 const GLushort *src0 = USHORT_ADDR( texImage, (i & ~1), j, k ); /* even */
1711 const GLushort *src1 = src0 + 1; /* odd */
1712 const GLubyte y0 = *src0 & 0xff; /* luminance */
1713 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1714 const GLubyte y1 = *src1 & 0xff; /* luminance */
1715 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1716 GLfloat r, g, b;
1717 if (i & 1) {
1718 /* odd pixel: use y1,cr,cb */
1719 r = (1.164 * (y1-16) + 1.596 * (cr-128));
1720 g = (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1721 b = (1.164 * (y1-16) + 2.018 * (cb-128));
1722 }
1723 else {
1724 /* even pixel: use y0,cr,cb */
1725 r = (1.164 * (y0-16) + 1.596 * (cr-128));
1726 g = (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1727 b = (1.164 * (y0-16) + 2.018 * (cb-128));
1728 }
1729 /* XXX remove / 255 here by tweaking arithmetic above */
1730 r /= 255.0;
1731 g /= 255.0;
1732 b /= 255.0;
1733 /* XXX should we really clamp??? */
1734 texel[RCOMP] = CLAMP(r, 0.0, 1.0);
1735 texel[GCOMP] = CLAMP(g, 0.0, 1.0);
1736 texel[BCOMP] = CLAMP(b, 0.0, 1.0);
1737 texel[ACOMP] = 1.0F;
1738 }
1739
1740 #if DIM == 3
1741 static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
1742 GLint i, GLint j, GLint k, const void *texel)
1743 {
1744 /* XXX to do */
1745 }
1746 #endif
1747
1748
1749
1750 #undef CHAN_ADDR
1751 #undef UBYTE_ADDR
1752 #undef USHORT_ADDR
1753 #undef UINT_ADDR
1754 #undef FLOAT_ADDR
1755 #undef HALF_ADDR
1756 #undef FETCH
1757 #undef DIM