texture compression
[mesa.git] / src / mesa / main / texformat_tmp.h
1 /**
2 * \file texformat_tmp.h
3 * Texel fetch functions template.
4 *
5 * This template file is used by texformat.c to generate texel fetch functions
6 * for 1-D, 2-D and 3-D texture images.
7 *
8 * It should be expanded by definining \p DIM as the number texture dimensions
9 * (1, 2 or 3). According to the value of \p DIM a serie of macros is defined
10 * for the texel lookup in the gl_texture_image::Data.
11 *
12 * \sa texformat.c and FetchTexel.
13 *
14 * \author Gareth Hughes
15 * \author Brian Paul
16 */
17
18 /*
19 * Mesa 3-D graphics library
20 * Version: 5.1
21 *
22 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
23 *
24 * Permission is hereby granted, free of charge, to any person obtaining a
25 * copy of this software and associated documentation files (the "Software"),
26 * to deal in the Software without restriction, including without limitation
27 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
28 * and/or sell copies of the Software, and to permit persons to whom the
29 * Software is furnished to do so, subject to the following conditions:
30 *
31 * The above copyright notice and this permission notice shall be included
32 * in all copies or substantial portions of the Software.
33 *
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
35 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
37 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
38 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 */
41
42
43 #if DIM == 1
44
45 #define CHAN_SRC( t, i, j, k, sz ) \
46 ((GLchan *)(t)->Data + (i) * (sz))
47 #define UBYTE_SRC( t, i, j, k, sz ) \
48 ((GLubyte *)(t)->Data + (i) * (sz))
49 #define USHORT_SRC( t, i, j, k ) \
50 ((GLushort *)(t)->Data + (i))
51 #define FLOAT_SRC( t, i, j, k ) \
52 ((GLfloat *)(t)->Data + (i))
53
54 #define FETCH(x) fetch_1d_texel_##x
55
56 #elif DIM == 2
57
58 #define CHAN_SRC( t, i, j, k, sz ) \
59 ((GLchan *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
60 #define UBYTE_SRC( t, i, j, k, sz ) \
61 ((GLubyte *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
62 #define USHORT_SRC( t, i, j, k ) \
63 ((GLushort *)(t)->Data + ((t)->RowStride * (j) + (i)))
64 #define FLOAT_SRC( t, i, j, k ) \
65 ((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)))
66
67 #define FETCH(x) fetch_2d_texel_##x
68
69 #elif DIM == 3
70
71 #define CHAN_SRC( t, i, j, k, sz ) \
72 (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \
73 (t)->RowStride + (i)) * (sz)
74 #define UBYTE_SRC( t, i, j, k, sz ) \
75 ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \
76 (t)->RowStride + (i)) * (sz))
77 #define USHORT_SRC( t, i, j, k ) \
78 ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \
79 (t)->RowStride + (i)))
80 #define FLOAT_SRC( t, i, j, k ) \
81 ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \
82 (t)->RowStride + (i)))
83
84 #define FETCH(x) fetch_3d_texel_##x
85
86 #else
87 #error illegal number of texture dimensions
88 #endif
89
90
91 static void FETCH(rgba)( const struct gl_texture_image *texImage,
92 GLint i, GLint j, GLint k, GLvoid *texel )
93 {
94 const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 );
95 GLchan *rgba = (GLchan *) texel;
96 COPY_CHAN4( rgba, src );
97 }
98
99 static void FETCH(rgb)( const struct gl_texture_image *texImage,
100 GLint i, GLint j, GLint k, GLvoid *texel )
101 {
102 const GLchan *src = CHAN_SRC( texImage, i, j, k, 3 );
103 GLchan *rgba = (GLchan *) texel;
104 rgba[RCOMP] = src[0];
105 rgba[GCOMP] = src[1];
106 rgba[BCOMP] = src[2];
107 rgba[ACOMP] = CHAN_MAX;
108 }
109
110 static void FETCH(alpha)( const struct gl_texture_image *texImage,
111 GLint i, GLint j, GLint k, GLvoid *texel )
112 {
113 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
114 GLchan *rgba = (GLchan *) texel;
115 rgba[RCOMP] = 0;
116 rgba[GCOMP] = 0;
117 rgba[BCOMP] = 0;
118 rgba[ACOMP] = src[0];
119 }
120
121 static void FETCH(luminance)( const struct gl_texture_image *texImage,
122 GLint i, GLint j, GLint k, GLvoid *texel )
123 {
124 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
125 GLchan *rgba = (GLchan *) texel;
126 rgba[RCOMP] = src[0];
127 rgba[GCOMP] = src[0];
128 rgba[BCOMP] = src[0];
129 rgba[ACOMP] = CHAN_MAX;
130 }
131
132 static void FETCH(luminance_alpha)( const struct gl_texture_image *texImage,
133 GLint i, GLint j, GLint k, GLvoid *texel )
134 {
135 const GLchan *src = CHAN_SRC( texImage, i, j, k, 2 );
136 GLchan *rgba = (GLchan *) texel;
137 rgba[RCOMP] = src[0];
138 rgba[GCOMP] = src[0];
139 rgba[BCOMP] = src[0];
140 rgba[ACOMP] = src[1];
141 }
142
143 static void FETCH(intensity)( const struct gl_texture_image *texImage,
144 GLint i, GLint j, GLint k, GLvoid *texel )
145 {
146 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
147 GLchan *rgba = (GLchan *) texel;
148 rgba[RCOMP] = src[0];
149 rgba[GCOMP] = src[0];
150 rgba[BCOMP] = src[0];
151 rgba[ACOMP] = src[0];
152 }
153
154 static void FETCH(color_index)( const struct gl_texture_image *texImage,
155 GLint i, GLint j, GLint k, GLvoid *texel )
156 {
157 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
158 GLchan *index = (GLchan *) texel;
159 *index = *src;
160 }
161
162 static void FETCH(depth_component)( const struct gl_texture_image *texImage,
163 GLint i, GLint j, GLint k, GLvoid *texel )
164 {
165 const GLfloat *src = FLOAT_SRC( texImage, i, j, k );
166 GLfloat *depth = (GLfloat *) texel;
167 *depth = *src;
168 }
169
170 static void FETCH(rgba8888)( const struct gl_texture_image *texImage,
171 GLint i, GLint j, GLint k, GLvoid *texel )
172 {
173 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
174 GLchan *rgba = (GLchan *) texel;
175 rgba[RCOMP] = UBYTE_TO_CHAN( src[3] );
176 rgba[GCOMP] = UBYTE_TO_CHAN( src[2] );
177 rgba[BCOMP] = UBYTE_TO_CHAN( src[1] );
178 rgba[ACOMP] = UBYTE_TO_CHAN( src[0] );
179 }
180
181 static void FETCH(argb8888)( const struct gl_texture_image *texImage,
182 GLint i, GLint j, GLint k, GLvoid *texel )
183 {
184 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
185 GLchan *rgba = (GLchan *) texel;
186 rgba[RCOMP] = UBYTE_TO_CHAN( src[2] );
187 rgba[GCOMP] = UBYTE_TO_CHAN( src[1] );
188 rgba[BCOMP] = UBYTE_TO_CHAN( src[0] );
189 rgba[ACOMP] = UBYTE_TO_CHAN( src[3] );
190 }
191
192 static void FETCH(rgb888)( const struct gl_texture_image *texImage,
193 GLint i, GLint j, GLint k, GLvoid *texel )
194 {
195 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
196 GLchan *rgba = (GLchan *) texel;
197 rgba[RCOMP] = UBYTE_TO_CHAN( src[2] );
198 rgba[GCOMP] = UBYTE_TO_CHAN( src[1] );
199 rgba[BCOMP] = UBYTE_TO_CHAN( src[0] );
200 rgba[ACOMP] = CHAN_MAX;
201 }
202
203 static void FETCH(rgb565)( const struct gl_texture_image *texImage,
204 GLint i, GLint j, GLint k, GLvoid *texel )
205 {
206 const GLushort *src = USHORT_SRC( texImage, i, j, k );
207 const GLushort s = *src;
208 GLchan *rgba = (GLchan *) texel;
209 rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) * 255 / 0xf8 );
210 rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) * 255 / 0xfc );
211 rgba[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) * 255 / 0xf8 );
212 rgba[ACOMP] = CHAN_MAX;
213 }
214
215 static void FETCH(argb4444)( const struct gl_texture_image *texImage,
216 GLint i, GLint j, GLint k, GLvoid *texel )
217 {
218 const GLushort *src = USHORT_SRC( texImage, i, j, k );
219 const GLushort s = *src;
220 GLchan *rgba = (GLchan *) texel;
221 rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf );
222 rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf );
223 rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf );
224 rgba[ACOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) * 255 / 0xf );
225 }
226
227 static void FETCH(argb1555)( const struct gl_texture_image *texImage,
228 GLint i, GLint j, GLint k, GLvoid *texel )
229 {
230 const GLushort *src = USHORT_SRC( texImage, i, j, k );
231 const GLushort s = *src;
232 GLchan *rgba = (GLchan *) texel;
233 rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0x1f) * 255 / 0x1f );
234 rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0x1f) * 255 / 0x1f );
235 rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0x1f) * 255 / 0x1f );
236 rgba[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
237 }
238
239 static void FETCH(al88)( const struct gl_texture_image *texImage,
240 GLint i, GLint j, GLint k, GLvoid *texel )
241 {
242 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 2 );
243 GLchan *rgba = (GLchan *) texel;
244 rgba[RCOMP] = UBYTE_TO_CHAN( src[0] );
245 rgba[GCOMP] = UBYTE_TO_CHAN( src[0] );
246 rgba[BCOMP] = UBYTE_TO_CHAN( src[0] );
247 rgba[ACOMP] = UBYTE_TO_CHAN( src[1] );
248 }
249
250 static void FETCH(rgb332)( const struct gl_texture_image *texImage,
251 GLint i, GLint j, GLint k, GLvoid *texel )
252 {
253 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
254 const GLubyte s = *src;
255 GLchan *rgba = (GLchan *) texel;
256 rgba[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xe0) * 255 / 0xe0 );
257 rgba[GCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xe0) * 255 / 0xe0 );
258 rgba[BCOMP] = UBYTE_TO_CHAN( ((s << 5) & 0xc0) * 255 / 0xc0 );
259 rgba[ACOMP] = CHAN_MAX;
260 }
261
262 static void FETCH(a8)( const struct gl_texture_image *texImage,
263 GLint i, GLint j, GLint k, GLvoid *texel )
264 {
265 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
266 GLchan *rgba = (GLchan *) texel;
267 rgba[RCOMP] = 0;
268 rgba[GCOMP] = 0;
269 rgba[BCOMP] = 0;
270 rgba[ACOMP] = UBYTE_TO_CHAN( src[0] );
271 }
272
273 static void FETCH(l8)( const struct gl_texture_image *texImage,
274 GLint i, GLint j, GLint k, GLvoid *texel )
275 {
276 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
277 GLchan *rgba = (GLchan *) texel;
278 rgba[RCOMP] = UBYTE_TO_CHAN( src[0] );
279 rgba[GCOMP] = UBYTE_TO_CHAN( src[0] );
280 rgba[BCOMP] = UBYTE_TO_CHAN( src[0] );
281 rgba[ACOMP] = CHAN_MAX;
282 }
283
284 static void FETCH(i8)( const struct gl_texture_image *texImage,
285 GLint i, GLint j, GLint k, GLvoid *texel )
286 {
287 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
288 GLchan *rgba = (GLchan *) texel;
289 rgba[RCOMP] = UBYTE_TO_CHAN( src[0] );
290 rgba[GCOMP] = UBYTE_TO_CHAN( src[0] );
291 rgba[BCOMP] = UBYTE_TO_CHAN( src[0] );
292 rgba[ACOMP] = UBYTE_TO_CHAN( src[0] );
293 }
294
295 static void FETCH(ci8)( const struct gl_texture_image *texImage,
296 GLint i, GLint j, GLint k, GLvoid *texel )
297 {
298 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
299 GLchan *index = (GLchan *) texel;
300 *index = UBYTE_TO_CHAN( *src );
301 }
302
303 /* XXX this may break if GLchan != GLubyte */
304 static void FETCH(ycbcr)( const struct gl_texture_image *texImage,
305 GLint i, GLint j, GLint k, GLvoid *texel )
306 {
307 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
308 const GLushort *src1 = src0 + 1; /* odd */
309 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
310 const GLubyte cb = *src0 & 0xff; /* chroma U */
311 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
312 const GLubyte cr = *src1 & 0xff; /* chroma V */
313 GLchan *rgba = (GLchan *) texel;
314 GLint r, g, b;
315 if (i & 1) {
316 /* odd pixel: use y1,cr,cb */
317 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
318 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
319 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
320 }
321 else {
322 /* even pixel: use y0,cr,cb */
323 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
324 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
325 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
326 }
327 rgba[RCOMP] = CLAMP(r, 0, CHAN_MAX);
328 rgba[GCOMP] = CLAMP(g, 0, CHAN_MAX);
329 rgba[BCOMP] = CLAMP(b, 0, CHAN_MAX);
330 rgba[ACOMP] = CHAN_MAX;
331 }
332
333 /* XXX this may break if GLchan != GLubyte */
334 static void FETCH(ycbcr_rev)( const struct gl_texture_image *texImage,
335 GLint i, GLint j, GLint k, GLvoid *texel )
336 {
337 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
338 const GLushort *src1 = src0 + 1; /* odd */
339 const GLubyte y0 = *src0 & 0xff; /* luminance */
340 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma U */
341 const GLubyte y1 = *src1 & 0xff; /* luminance */
342 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma V */
343 GLchan *rgba = (GLchan *) texel;
344 GLint r, g, b;
345 if (i & 1) {
346 /* odd pixel: use y1,cr,cb */
347 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
348 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
349 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
350 }
351 else {
352 /* even pixel: use y0,cr,cb */
353 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
354 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
355 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
356 }
357 rgba[RCOMP] = CLAMP(r, 0, CHAN_MAX);
358 rgba[GCOMP] = CLAMP(g, 0, CHAN_MAX);
359 rgba[BCOMP] = CLAMP(b, 0, CHAN_MAX);
360 rgba[ACOMP] = CHAN_MAX;
361 }
362
363
364 #if DIM == 2
365 static void FETCH(rgb_fxt1)( const struct gl_texture_image *texImage,
366 GLint i, GLint j, GLint k, GLvoid *texel )
367 {
368 /* Extract the (i,j) pixel from texImage->Data and return it
369 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
370 */
371 }
372 #endif
373
374 #if DIM == 2
375 static void FETCH(rgba_fxt1)( const struct gl_texture_image *texImage,
376 GLint i, GLint j, GLint k, GLvoid *texel )
377 {
378 /* Extract the (i,j) pixel from texImage->Data and return it
379 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
380 */
381 }
382 #endif
383
384
385 #if DIM == 2
386 static void FETCH(rgb_dxt1)( const struct gl_texture_image *texImage,
387 GLint i, GLint j, GLint k, GLvoid *texel )
388 {
389 /* Extract the (i,j) pixel from texImage->Data and return it
390 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
391 */
392 }
393 #endif
394
395 #if DIM == 2
396 static void FETCH(rgba_dxt1)( const struct gl_texture_image *texImage,
397 GLint i, GLint j, GLint k, GLvoid *texel )
398 {
399 /* Extract the (i,j) pixel from texImage->Data and return it
400 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
401 */
402 }
403 #endif
404
405 #if DIM == 2
406 static void FETCH(rgba_dxt3)( const struct gl_texture_image *texImage,
407 GLint i, GLint j, GLint k, GLvoid *texel )
408 {
409 /* Extract the (i,j) pixel from texImage->Data and return it
410 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
411 */
412 }
413 #endif
414
415 #if DIM == 2
416 static void FETCH(rgba_dxt5)( const struct gl_texture_image *texImage,
417 GLint i, GLint j, GLint k, GLvoid *texel )
418 {
419 /* Extract the (i,j) pixel from texImage->Data and return it
420 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
421 */
422 }
423 #endif
424
425
426
427 /* big-endian */
428
429 #if 0
430 static void FETCH(abgr8888)( const struct gl_texture_image *texImage,
431 GLint i, GLint j, GLint k, GLvoid *texel )
432 {
433 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
434 GLchan *rgba = (GLchan *) texel;
435 rgba[RCOMP] = UBYTE_TO_CHAN( src[3] );
436 rgba[GCOMP] = UBYTE_TO_CHAN( src[2] );
437 rgba[BCOMP] = UBYTE_TO_CHAN( src[1] );
438 rgba[ACOMP] = UBYTE_TO_CHAN( src[0] );
439 }
440
441 static void FETCH(bgra8888)( const struct gl_texture_image *texImage,
442 GLint i, GLint j, GLint k, GLvoid *texel )
443 {
444 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
445 GLchan *rgba = (GLchan *) texel;
446 rgba[RCOMP] = UBYTE_TO_CHAN( src[2] );
447 rgba[GCOMP] = UBYTE_TO_CHAN( src[1] );
448 rgba[BCOMP] = UBYTE_TO_CHAN( src[0] );
449 rgba[ACOMP] = UBYTE_TO_CHAN( src[3] );
450 }
451
452 static void FETCH(bgr888)( const struct gl_texture_image *texImage,
453 GLint i, GLint j, GLint k, GLvoid *texel )
454 {
455 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
456 GLchan *rgba = (GLchan *) texel;
457 rgba[RCOMP] = UBYTE_TO_CHAN( src[2] );
458 rgba[GCOMP] = UBYTE_TO_CHAN( src[1] );
459 rgba[BCOMP] = UBYTE_TO_CHAN( src[0] );
460 rgba[ACOMP] = CHAN_MAX;
461 }
462
463 static void FETCH(bgr565)( const struct gl_texture_image *texImage,
464 GLint i, GLint j, GLint k, GLvoid *texel )
465 {
466 const GLushort *src = USHORT_SRC( texImage, i, j, k );
467 const GLushort s = *src;
468 GLchan *rgba = (GLchan *) texel;
469 rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) * 255 / 0xf8 );
470 rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) * 255 / 0xfc );
471 rgba[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) * 255 / 0xf8 );
472 rgba[ACOMP] = CHAN_MAX;
473 }
474
475 static void FETCH(bgra4444)( const struct gl_texture_image *texImage,
476 GLint i, GLint j, GLint k, GLvoid *texel )
477 {
478 const GLushort *src = USHORT_SRC( texImage, i, j, k );
479 const GLushort s = *src;
480 GLchan *rgba = (GLchan *) texel;
481 rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf );
482 rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf );
483 rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf );
484 rgba[ACOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) * 255 / 0xf );
485 }
486
487 static void FETCH(bgra5551)( const struct gl_texture_image *texImage,
488 GLint i, GLint j, GLint k, GLvoid *texel )
489 {
490 const GLushort *src = USHORT_SRC( texImage, i, j, k );
491 const GLushort s = *src;
492 GLchan *rgba = (GLchan *) texel;
493 rgba[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0x1f) * 255 / 0x1f );
494 rgba[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0x1f) * 255 / 0x1f );
495 rgba[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0x1f) * 255 / 0x1f );
496 rgba[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
497 }
498
499 static void FETCH(la88)( const struct gl_texture_image *texImage,
500 GLint i, GLint j, GLint k, GLvoid *texel )
501 {
502 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 2 );
503 GLchan *rgba = (GLchan *) texel;
504 rgba[RCOMP] = UBYTE_TO_CHAN( src[0] );
505 rgba[GCOMP] = UBYTE_TO_CHAN( src[0] );
506 rgba[BCOMP] = UBYTE_TO_CHAN( src[0] );
507 rgba[ACOMP] = UBYTE_TO_CHAN( src[1] );
508 }
509
510 static void FETCH(bgr233)( const struct gl_texture_image *texImage,
511 GLint i, GLint j, GLint k, GLvoid *texel )
512 {
513 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
514 const GLubyte s = *src;
515 GLchan *rgba = (GLchan *) texel;
516 rgba[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xe0) * 255 / 0xe0 );
517 rgba[GCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xe0) * 255 / 0xe0 );
518 rgba[BCOMP] = UBYTE_TO_CHAN( ((s << 5) & 0xc0) * 255 / 0xc0 );
519 rgba[ACOMP] = CHAN_MAX;
520 }
521 #endif
522
523
524 #undef CHAN_SRC
525 #undef UBYTE_SRC
526 #undef USHORT_SRC
527 #undef FLOAT_SRC
528 #undef FETCH
529 #undef DIM