i965/fs: Drop the emit(fs_inst) overload.
[mesa.git] / src / mesa / main / format_unpack.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (c) 2011 VMware, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include "colormac.h"
27 #include "format_unpack.h"
28 #include "macros.h"
29 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
30 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
31
32
33 /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
34 struct z32f_x24s8
35 {
36 float z;
37 uint32_t x24s8;
38 };
39
40
41 /* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
42
43 #define EXPAND_1_8(X) ( (X) ? 0xff : 0x0 )
44
45 #define EXPAND_2_8(X) ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
46
47 #define EXPAND_3_8(X) ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
48
49 #define EXPAND_4_8(X) ( ((X) << 4) | (X) )
50
51 #define EXPAND_5_8(X) ( ((X) << 3) | ((X) >> 2) )
52
53 #define EXPAND_6_8(X) ( ((X) << 2) | ((X) >> 4) )
54
55
56 /**
57 * Convert an 8-bit sRGB value from non-linear space to a
58 * linear RGB value in [0, 1].
59 * Implemented with a 256-entry lookup table.
60 */
61 GLfloat
62 _mesa_nonlinear_to_linear(GLubyte cs8)
63 {
64 static GLfloat table[256];
65 static GLboolean tableReady = GL_FALSE;
66 if (!tableReady) {
67 /* compute lookup table now */
68 GLuint i;
69 for (i = 0; i < 256; i++) {
70 const GLfloat cs = UBYTE_TO_FLOAT(i);
71 if (cs <= 0.04045) {
72 table[i] = cs / 12.92f;
73 }
74 else {
75 table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
76 }
77 }
78 tableReady = GL_TRUE;
79 }
80 return table[cs8];
81 }
82
83
84 /**********************************************************************/
85 /* Unpack, returning GLfloat colors */
86 /**********************************************************************/
87
88 typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);
89
90
91 static void
92 unpack_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
93 {
94 const GLuint *s = ((const GLuint *) src);
95 GLuint i;
96 for (i = 0; i < n; i++) {
97 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
98 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
99 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
100 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
101 }
102 }
103
104 static void
105 unpack_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
106 {
107 const GLuint *s = ((const GLuint *) src);
108 GLuint i;
109 for (i = 0; i < n; i++) {
110 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
111 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
112 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
113 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
114 }
115 }
116
117 static void
118 unpack_ARGB8888(const void *src, GLfloat dst[][4], GLuint n)
119 {
120 const GLuint *s = ((const GLuint *) src);
121 GLuint i;
122 for (i = 0; i < n; i++) {
123 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
124 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
125 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
126 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
127 }
128 }
129
130 static void
131 unpack_ARGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
132 {
133 const GLuint *s = ((const GLuint *) src);
134 GLuint i;
135 for (i = 0; i < n; i++) {
136 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
137 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
138 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
139 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
140 }
141 }
142
143 static void
144 unpack_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
145 {
146 const GLuint *s = ((const GLuint *) src);
147 GLuint i;
148 for (i = 0; i < n; i++) {
149 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
150 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
151 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
152 dst[i][ACOMP] = 1.0f;
153 }
154 }
155
156 static void
157 unpack_RGBX8888_REV(const void *src, GLfloat dst[][4], GLuint n)
158 {
159 const GLuint *s = ((const GLuint *) src);
160 GLuint i;
161 for (i = 0; i < n; i++) {
162 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
163 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
164 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
165 dst[i][ACOMP] = 1.0f;
166 }
167 }
168
169 static void
170 unpack_XRGB8888(const void *src, GLfloat dst[][4], GLuint n)
171 {
172 const GLuint *s = ((const GLuint *) src);
173 GLuint i;
174 for (i = 0; i < n; i++) {
175 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
176 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
177 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
178 dst[i][ACOMP] = 1.0f;
179 }
180 }
181
182 static void
183 unpack_XRGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
184 {
185 const GLuint *s = ((const GLuint *) src);
186 GLuint i;
187 for (i = 0; i < n; i++) {
188 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
189 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
190 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
191 dst[i][ACOMP] = 1.0f;
192 }
193 }
194
195 static void
196 unpack_RGB888(const void *src, GLfloat dst[][4], GLuint n)
197 {
198 const GLubyte *s = (const GLubyte *) src;
199 GLuint i;
200 for (i = 0; i < n; i++) {
201 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
202 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
203 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
204 dst[i][ACOMP] = 1.0F;
205 }
206 }
207
208 static void
209 unpack_BGR888(const void *src, GLfloat dst[][4], GLuint n)
210 {
211 const GLubyte *s = (const GLubyte *) src;
212 GLuint i;
213 for (i = 0; i < n; i++) {
214 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
215 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
216 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
217 dst[i][ACOMP] = 1.0F;
218 }
219 }
220
221 static void
222 unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n)
223 {
224 const GLushort *s = ((const GLushort *) src);
225 GLuint i;
226 for (i = 0; i < n; i++) {
227 dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
228 dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F);
229 dst[i][BCOMP] = ((s[i] ) & 0x1f) * (1.0F / 31.0F);
230 dst[i][ACOMP] = 1.0F;
231 }
232 }
233
234 static void
235 unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n)
236 {
237 /* Warning: this function does not match the current Mesa definition
238 * of MESA_FORMAT_R5G6B5_UNORM.
239 */
240 const GLushort *s = ((const GLushort *) src);
241 GLuint i;
242 for (i = 0; i < n; i++) {
243 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
244 dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) );
245 dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >> 9) & 0x3) );
246 dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >> 2) & 0x7) );
247 dst[i][ACOMP] = 1.0F;
248 }
249 }
250
251 static void
252 unpack_ARGB4444(const void *src, GLfloat dst[][4], GLuint n)
253 {
254 const GLushort *s = ((const GLushort *) src);
255 GLuint i;
256 for (i = 0; i < n; i++) {
257 dst[i][RCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
258 dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
259 dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
260 dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
261 }
262 }
263
264 static void
265 unpack_ARGB4444_REV(const void *src, GLfloat dst[][4], GLuint n)
266 {
267 const GLushort *s = ((const GLushort *) src);
268 GLuint i;
269 for (i = 0; i < n; i++) {
270 dst[i][RCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
271 dst[i][GCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
272 dst[i][BCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
273 dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
274 }
275 }
276
277 static void
278 unpack_RGBA5551(const void *src, GLfloat dst[][4], GLuint n)
279 {
280 const GLushort *s = ((const GLushort *) src);
281 GLuint i;
282 for (i = 0; i < n; i++) {
283 dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
284 dst[i][GCOMP] = ((s[i] >> 6) & 0x1f) * (1.0F / 31.0F);
285 dst[i][BCOMP] = ((s[i] >> 1) & 0x1f) * (1.0F / 31.0F);
286 dst[i][ACOMP] = ((s[i] ) & 0x01) * 1.0F;
287 }
288 }
289
290 static void
291 unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n)
292 {
293 const GLushort *s = ((const GLushort *) src);
294 GLuint i;
295 for (i = 0; i < n; i++) {
296 dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
297 dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F);
298 dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F);
299 dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F;
300 }
301 }
302
303 static void
304 unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n)
305 {
306 /* Warning: this function does not match the current Mesa definition
307 * of MESA_FORMAT_A1R5G5B5_UNORM.
308 */
309 const GLushort *s = ((const GLushort *) src);
310 GLuint i;
311 for (i = 0; i < n; i++) {
312 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
313 dst[i][RCOMP] = ((tmp >> 10) & 0x1f) * (1.0F / 31.0F);
314 dst[i][GCOMP] = ((tmp >> 5) & 0x1f) * (1.0F / 31.0F);
315 dst[i][BCOMP] = ((tmp >> 0) & 0x1f) * (1.0F / 31.0F);
316 dst[i][ACOMP] = ((tmp >> 15) & 0x01) * 1.0F;
317 }
318 }
319
320 static void
321 unpack_AL44(const void *src, GLfloat dst[][4], GLuint n)
322 {
323 const GLubyte *s = ((const GLubyte *) src);
324 GLuint i;
325 for (i = 0; i < n; i++) {
326 dst[i][RCOMP] =
327 dst[i][GCOMP] =
328 dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
329 dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
330 }
331 }
332
333 static void
334 unpack_AL88(const void *src, GLfloat dst[][4], GLuint n)
335 {
336 const GLushort *s = ((const GLushort *) src);
337 GLuint i;
338 for (i = 0; i < n; i++) {
339 dst[i][RCOMP] =
340 dst[i][GCOMP] =
341 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
342 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
343 }
344 }
345
346 static void
347 unpack_AL88_REV(const void *src, GLfloat dst[][4], GLuint n)
348 {
349 const GLushort *s = ((const GLushort *) src);
350 GLuint i;
351 for (i = 0; i < n; i++) {
352 dst[i][RCOMP] =
353 dst[i][GCOMP] =
354 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
355 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
356 }
357 }
358
359 static void
360 unpack_AL1616(const void *src, GLfloat dst[][4], GLuint n)
361 {
362 const GLuint *s = ((const GLuint *) src);
363 GLuint i;
364 for (i = 0; i < n; i++) {
365 dst[i][RCOMP] =
366 dst[i][GCOMP] =
367 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
368 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
369 }
370 }
371
372 static void
373 unpack_AL1616_REV(const void *src, GLfloat dst[][4], GLuint n)
374 {
375 const GLuint *s = ((const GLuint *) src);
376 GLuint i;
377 for (i = 0; i < n; i++) {
378 dst[i][RCOMP] =
379 dst[i][GCOMP] =
380 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
381 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
382 }
383 }
384
385 static void
386 unpack_RGB332(const void *src, GLfloat dst[][4], GLuint n)
387 {
388 const GLubyte *s = ((const GLubyte *) src);
389 GLuint i;
390 for (i = 0; i < n; i++) {
391 dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F);
392 dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F);
393 dst[i][BCOMP] = ((s[i] ) & 0x3) * (1.0F / 3.0F);
394 dst[i][ACOMP] = 1.0F;
395 }
396 }
397
398
399 static void
400 unpack_A8(const void *src, GLfloat dst[][4], GLuint n)
401 {
402 const GLubyte *s = ((const GLubyte *) src);
403 GLuint i;
404 for (i = 0; i < n; i++) {
405 dst[i][RCOMP] =
406 dst[i][GCOMP] =
407 dst[i][BCOMP] = 0.0F;
408 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
409 }
410 }
411
412 static void
413 unpack_A16(const void *src, GLfloat dst[][4], GLuint n)
414 {
415 const GLushort *s = ((const GLushort *) src);
416 GLuint i;
417 for (i = 0; i < n; i++) {
418 dst[i][RCOMP] =
419 dst[i][GCOMP] =
420 dst[i][BCOMP] = 0.0F;
421 dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
422 }
423 }
424
425 static void
426 unpack_L8(const void *src, GLfloat dst[][4], GLuint n)
427 {
428 const GLubyte *s = ((const GLubyte *) src);
429 GLuint i;
430 for (i = 0; i < n; i++) {
431 dst[i][RCOMP] =
432 dst[i][GCOMP] =
433 dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
434 dst[i][ACOMP] = 1.0F;
435 }
436 }
437
438 static void
439 unpack_L16(const void *src, GLfloat dst[][4], GLuint n)
440 {
441 const GLushort *s = ((const GLushort *) src);
442 GLuint i;
443 for (i = 0; i < n; i++) {
444 dst[i][RCOMP] =
445 dst[i][GCOMP] =
446 dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
447 dst[i][ACOMP] = 1.0F;
448 }
449 }
450
451 static void
452 unpack_I8(const void *src, GLfloat dst[][4], GLuint n)
453 {
454 const GLubyte *s = ((const GLubyte *) src);
455 GLuint i;
456 for (i = 0; i < n; i++) {
457 dst[i][RCOMP] =
458 dst[i][GCOMP] =
459 dst[i][BCOMP] =
460 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
461 }
462 }
463
464 static void
465 unpack_I16(const void *src, GLfloat dst[][4], GLuint n)
466 {
467 const GLushort *s = ((const GLushort *) src);
468 GLuint i;
469 for (i = 0; i < n; i++) {
470 dst[i][RCOMP] =
471 dst[i][GCOMP] =
472 dst[i][BCOMP] =
473 dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
474 }
475 }
476
477 static void
478 unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n)
479 {
480 GLuint i;
481 for (i = 0; i < n; i++) {
482 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
483 const GLushort *src1 = src0 + 1; /* odd */
484 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
485 const GLubyte cb = *src0 & 0xff; /* chroma U */
486 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
487 const GLubyte cr = *src1 & 0xff; /* chroma V */
488 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
489 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
490 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
491 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
492 r *= (1.0F / 255.0F);
493 g *= (1.0F / 255.0F);
494 b *= (1.0F / 255.0F);
495 dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
496 dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
497 dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
498 dst[i][ACOMP] = 1.0F;
499 }
500 }
501
502 static void
503 unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
504 {
505 GLuint i;
506 for (i = 0; i < n; i++) {
507 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
508 const GLushort *src1 = src0 + 1; /* odd */
509 const GLubyte y0 = *src0 & 0xff; /* luminance */
510 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
511 const GLubyte y1 = *src1 & 0xff; /* luminance */
512 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
513 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
514 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
515 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
516 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
517 r *= (1.0F / 255.0F);
518 g *= (1.0F / 255.0F);
519 b *= (1.0F / 255.0F);
520 dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
521 dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
522 dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
523 dst[i][ACOMP] = 1.0F;
524 }
525 }
526
527 static void
528 unpack_R8(const void *src, GLfloat dst[][4], GLuint n)
529 {
530 const GLubyte *s = ((const GLubyte *) src);
531 GLuint i;
532 for (i = 0; i < n; i++) {
533 dst[i][0] = UBYTE_TO_FLOAT(s[i]);
534 dst[i][1] =
535 dst[i][2] = 0.0F;
536 dst[i][3] = 1.0F;
537 }
538 }
539
540 static void
541 unpack_GR88(const void *src, GLfloat dst[][4], GLuint n)
542 {
543 const GLushort *s = ((const GLushort *) src);
544 GLuint i;
545 for (i = 0; i < n; i++) {
546 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
547 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
548 dst[i][BCOMP] = 0.0;
549 dst[i][ACOMP] = 1.0;
550 }
551 }
552
553 static void
554 unpack_RG88(const void *src, GLfloat dst[][4], GLuint n)
555 {
556 const GLushort *s = ((const GLushort *) src);
557 GLuint i;
558 for (i = 0; i < n; i++) {
559 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
560 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
561 dst[i][BCOMP] = 0.0;
562 dst[i][ACOMP] = 1.0;
563 }
564 }
565
566 static void
567 unpack_R16(const void *src, GLfloat dst[][4], GLuint n)
568 {
569 const GLushort *s = ((const GLushort *) src);
570 GLuint i;
571 for (i = 0; i < n; i++) {
572 dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]);
573 dst[i][GCOMP] = 0.0;
574 dst[i][BCOMP] = 0.0;
575 dst[i][ACOMP] = 1.0;
576 }
577 }
578
579 static void
580 unpack_GR1616(const void *src, GLfloat dst[][4], GLuint n)
581 {
582 const GLuint *s = ((const GLuint *) src);
583 GLuint i;
584 for (i = 0; i < n; i++) {
585 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
586 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
587 dst[i][BCOMP] = 0.0;
588 dst[i][ACOMP] = 1.0;
589 }
590 }
591
592 static void
593 unpack_RG1616(const void *src, GLfloat dst[][4], GLuint n)
594 {
595 const GLuint *s = ((const GLuint *) src);
596 GLuint i;
597 for (i = 0; i < n; i++) {
598 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
599 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
600 dst[i][BCOMP] = 0.0;
601 dst[i][ACOMP] = 1.0;
602 }
603 }
604
605 static void
606 unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n)
607 {
608 const GLuint *s = ((const GLuint *) src);
609 GLuint i;
610 for (i = 0; i < n; i++) {
611 dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
612 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
613 dst[i][BCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
614 dst[i][ACOMP] = ((s[i] >> 30) & 0x03) * (1.0F / 3.0F);
615 }
616 }
617
618
619 static void
620 unpack_ARGB2101010_UINT(const void *src, GLfloat dst[][4], GLuint n)
621 {
622 const GLuint *s = (const GLuint *) src;
623 GLuint i;
624 for (i = 0; i < n; i++) {
625 dst[i][RCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff);
626 dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff);
627 dst[i][BCOMP] = (GLfloat)((s[i] >> 0) & 0x3ff);
628 dst[i][ACOMP] = (GLfloat)((s[i] >> 30) & 0x03);
629 }
630 }
631
632
633 static void
634 unpack_ABGR2101010_UINT(const void *src, GLfloat dst[][4], GLuint n)
635 {
636 const GLuint *s = ((const GLuint *) src);
637 GLuint i;
638 for (i = 0; i < n; i++) {
639 dst[i][RCOMP] = (GLfloat)((s[i] >> 0) & 0x3ff);
640 dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff);
641 dst[i][BCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff);
642 dst[i][ACOMP] = (GLfloat)((s[i] >> 30) & 0x03);
643 }
644 }
645
646
647 static void
648 unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
649 {
650 /* only return Z, not stencil data */
651 const GLuint *s = ((const GLuint *) src);
652 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
653 GLuint i;
654 for (i = 0; i < n; i++) {
655 dst[i][0] =
656 dst[i][1] =
657 dst[i][2] = (GLfloat) ((s[i] >> 8) * scale);
658 dst[i][3] = 1.0F;
659 ASSERT(dst[i][0] >= 0.0F);
660 ASSERT(dst[i][0] <= 1.0F);
661 }
662 }
663
664 static void
665 unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
666 {
667 /* only return Z, not stencil data */
668 const GLuint *s = ((const GLuint *) src);
669 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
670 GLuint i;
671 for (i = 0; i < n; i++) {
672 dst[i][0] =
673 dst[i][1] =
674 dst[i][2] = (float) ((s[i] & 0x00ffffff) * scale);
675 dst[i][3] = 1.0F;
676 ASSERT(dst[i][0] >= 0.0F);
677 ASSERT(dst[i][0] <= 1.0F);
678 }
679 }
680
681 static void
682 unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
683 {
684 const GLushort *s = ((const GLushort *) src);
685 GLuint i;
686 for (i = 0; i < n; i++) {
687 dst[i][0] =
688 dst[i][1] =
689 dst[i][2] = s[i] * (1.0F / 65535.0F);
690 dst[i][3] = 1.0F;
691 }
692 }
693
694 static void
695 unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n)
696 {
697 unpack_S8_Z24(src, dst, n);
698 }
699
700 static void
701 unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n)
702 {
703 unpack_Z24_S8(src, dst, n);
704 }
705
706 static void
707 unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
708 {
709 const GLuint *s = ((const GLuint *) src);
710 GLuint i;
711 for (i = 0; i < n; i++) {
712 dst[i][0] =
713 dst[i][1] =
714 dst[i][2] = s[i] * (1.0F / 0xffffffff);
715 dst[i][3] = 1.0F;
716 }
717 }
718
719 static void
720 unpack_Z32_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
721 {
722 const GLfloat *s = ((const GLfloat *) src);
723 GLuint i;
724 for (i = 0; i < n; i++) {
725 dst[i][0] =
726 dst[i][1] =
727 dst[i][2] = s[i * 2];
728 dst[i][3] = 1.0F;
729 }
730 }
731
732 static void
733 unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[][4], GLuint n)
734 {
735 const GLfloat *s = ((const GLfloat *) src);
736 GLuint i;
737 for (i = 0; i < n; i++) {
738 dst[i][0] =
739 dst[i][1] =
740 dst[i][2] = s[i];
741 dst[i][3] = 1.0F;
742 }
743 }
744
745
746 static void
747 unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
748 {
749 /* should never be used */
750 GLuint i;
751 for (i = 0; i < n; i++) {
752 dst[i][0] =
753 dst[i][1] =
754 dst[i][2] = 0.0F;
755 dst[i][3] = 1.0F;
756 }
757 }
758
759
760 static void
761 unpack_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
762 {
763 const GLubyte *s = (const GLubyte *) src;
764 GLuint i;
765 for (i = 0; i < n; i++) {
766 dst[i][RCOMP] = _mesa_nonlinear_to_linear(s[i*3+2]);
767 dst[i][GCOMP] = _mesa_nonlinear_to_linear(s[i*3+1]);
768 dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i*3+0]);
769 dst[i][ACOMP] = 1.0F;
770 }
771 }
772
773 static void
774 unpack_SRGBA8(const void *src, GLfloat dst[][4], GLuint n)
775 {
776 const GLuint *s = ((const GLuint *) src);
777 GLuint i;
778 for (i = 0; i < n; i++) {
779 dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 24) );
780 dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
781 dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff );
782 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
783 }
784 }
785
786 static void
787 unpack_SARGB8(const void *src, GLfloat dst[][4], GLuint n)
788 {
789 const GLuint *s = ((const GLuint *) src);
790 GLuint i;
791 for (i = 0; i < n; i++) {
792 dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
793 dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff );
794 dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff );
795 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
796 }
797 }
798
799 static void
800 unpack_SL8(const void *src, GLfloat dst[][4], GLuint n)
801 {
802 const GLubyte *s = ((const GLubyte *) src);
803 GLuint i;
804 for (i = 0; i < n; i++) {
805 dst[i][RCOMP] =
806 dst[i][GCOMP] =
807 dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i]);
808 dst[i][ACOMP] = 1.0F;
809 }
810 }
811
812 static void
813 unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n)
814 {
815 const GLushort *s = (const GLushort *) src;
816 GLuint i;
817 for (i = 0; i < n; i++) {
818 dst[i][RCOMP] =
819 dst[i][GCOMP] =
820 dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i] & 0xff);
821 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
822 }
823 }
824
825 static void
826 unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
827 {
828 }
829
830 static void
831 unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
832 {
833 }
834
835 static void
836 unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
837 {
838 }
839
840 static void
841 unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
842 {
843 }
844
845 static void
846 unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
847 {
848 }
849
850 static void
851 unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
852 {
853 }
854
855 static void
856 unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
857 {
858 }
859
860 static void
861 unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
862 {
863 }
864
865 static void
866 unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
867 {
868 }
869
870 static void
871 unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
872 {
873 }
874
875
876 static void
877 unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
878 {
879 const GLfloat *s = (const GLfloat *) src;
880 GLuint i;
881 for (i = 0; i < n; i++) {
882 dst[i][RCOMP] = s[i*4+0];
883 dst[i][GCOMP] = s[i*4+1];
884 dst[i][BCOMP] = s[i*4+2];
885 dst[i][ACOMP] = s[i*4+3];
886 }
887 }
888
889 static void
890 unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
891 {
892 const GLhalfARB *s = (const GLhalfARB *) src;
893 GLuint i;
894 for (i = 0; i < n; i++) {
895 dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
896 dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
897 dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
898 dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
899 }
900 }
901
902 static void
903 unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
904 {
905 const GLfloat *s = (const GLfloat *) src;
906 GLuint i;
907 for (i = 0; i < n; i++) {
908 dst[i][RCOMP] = s[i*3+0];
909 dst[i][GCOMP] = s[i*3+1];
910 dst[i][BCOMP] = s[i*3+2];
911 dst[i][ACOMP] = 1.0F;
912 }
913 }
914
915 static void
916 unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
917 {
918 const GLhalfARB *s = (const GLhalfARB *) src;
919 GLuint i;
920 for (i = 0; i < n; i++) {
921 dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]);
922 dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
923 dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
924 dst[i][ACOMP] = 1.0F;
925 }
926 }
927
928 static void
929 unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
930 {
931 const GLfloat *s = (const GLfloat *) src;
932 GLuint i;
933 for (i = 0; i < n; i++) {
934 dst[i][RCOMP] =
935 dst[i][GCOMP] =
936 dst[i][BCOMP] = 0.0F;
937 dst[i][ACOMP] = s[i];
938 }
939 }
940
941 static void
942 unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
943 {
944 const GLhalfARB *s = (const GLhalfARB *) src;
945 GLuint i;
946 for (i = 0; i < n; i++) {
947 dst[i][RCOMP] =
948 dst[i][GCOMP] =
949 dst[i][BCOMP] = 0.0F;
950 dst[i][ACOMP] = _mesa_half_to_float(s[i]);
951 }
952 }
953
954 static void
955 unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
956 {
957 const GLfloat *s = (const GLfloat *) src;
958 GLuint i;
959 for (i = 0; i < n; i++) {
960 dst[i][RCOMP] =
961 dst[i][GCOMP] =
962 dst[i][BCOMP] = s[i];
963 dst[i][ACOMP] = 1.0F;
964 }
965 }
966
967 static void
968 unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
969 {
970 const GLhalfARB *s = (const GLhalfARB *) src;
971 GLuint i;
972 for (i = 0; i < n; i++) {
973 dst[i][RCOMP] =
974 dst[i][GCOMP] =
975 dst[i][BCOMP] = _mesa_half_to_float(s[i]);
976 dst[i][ACOMP] = 1.0F;
977 }
978 }
979
980 static void
981 unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
982 {
983 const GLfloat *s = (const GLfloat *) src;
984 GLuint i;
985 for (i = 0; i < n; i++) {
986 dst[i][RCOMP] =
987 dst[i][GCOMP] =
988 dst[i][BCOMP] = s[i*2+0];
989 dst[i][ACOMP] = s[i*2+1];
990 }
991 }
992
993 static void
994 unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
995 {
996 const GLhalfARB *s = (const GLhalfARB *) src;
997 GLuint i;
998 for (i = 0; i < n; i++) {
999 dst[i][RCOMP] =
1000 dst[i][GCOMP] =
1001 dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
1002 dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
1003 }
1004 }
1005
1006 static void
1007 unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1008 {
1009 const GLfloat *s = (const GLfloat *) src;
1010 GLuint i;
1011 for (i = 0; i < n; i++) {
1012 dst[i][RCOMP] =
1013 dst[i][GCOMP] =
1014 dst[i][BCOMP] =
1015 dst[i][ACOMP] = s[i];
1016 }
1017 }
1018
1019 static void
1020 unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1021 {
1022 const GLhalfARB *s = (const GLhalfARB *) src;
1023 GLuint i;
1024 for (i = 0; i < n; i++) {
1025 dst[i][RCOMP] =
1026 dst[i][GCOMP] =
1027 dst[i][BCOMP] =
1028 dst[i][ACOMP] = _mesa_half_to_float(s[i]);
1029 }
1030 }
1031
1032 static void
1033 unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1034 {
1035 const GLfloat *s = (const GLfloat *) src;
1036 GLuint i;
1037 for (i = 0; i < n; i++) {
1038 dst[i][RCOMP] = s[i];
1039 dst[i][GCOMP] = 0.0F;
1040 dst[i][BCOMP] = 0.0F;
1041 dst[i][ACOMP] = 1.0F;
1042 }
1043 }
1044
1045 static void
1046 unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1047 {
1048 const GLhalfARB *s = (const GLhalfARB *) src;
1049 GLuint i;
1050 for (i = 0; i < n; i++) {
1051 dst[i][RCOMP] = _mesa_half_to_float(s[i]);
1052 dst[i][GCOMP] = 0.0F;
1053 dst[i][BCOMP] = 0.0F;
1054 dst[i][ACOMP] = 1.0F;
1055 }
1056 }
1057
1058 static void
1059 unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1060 {
1061 const GLfloat *s = (const GLfloat *) src;
1062 GLuint i;
1063 for (i = 0; i < n; i++) {
1064 dst[i][RCOMP] = s[i*2+0];
1065 dst[i][GCOMP] = s[i*2+1];
1066 dst[i][BCOMP] = 0.0F;
1067 dst[i][ACOMP] = 1.0F;
1068 }
1069 }
1070
1071 static void
1072 unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1073 {
1074 const GLhalfARB *s = (const GLhalfARB *) src;
1075 GLuint i;
1076 for (i = 0; i < n; i++) {
1077 dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
1078 dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
1079 dst[i][BCOMP] = 0.0F;
1080 dst[i][ACOMP] = 1.0F;
1081 }
1082 }
1083
1084 static void
1085 unpack_ALPHA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1086 {
1087 const GLubyte *s = (const GLubyte *) src;
1088 GLuint i;
1089 for (i = 0; i < n; i++) {
1090 dst[i][RCOMP] =
1091 dst[i][GCOMP] =
1092 dst[i][BCOMP] = 0.0;
1093 dst[i][ACOMP] = (GLfloat) s[i];
1094 }
1095 }
1096
1097 static void
1098 unpack_ALPHA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1099 {
1100 const GLushort *s = (const GLushort *) src;
1101 GLuint i;
1102 for (i = 0; i < n; i++) {
1103 dst[i][RCOMP] =
1104 dst[i][GCOMP] =
1105 dst[i][BCOMP] = 0.0;
1106 dst[i][ACOMP] = (GLfloat) s[i];
1107 }
1108 }
1109
1110 static void
1111 unpack_ALPHA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1112 {
1113 const GLuint *s = (const GLuint *) src;
1114 GLuint i;
1115 for (i = 0; i < n; i++) {
1116 dst[i][RCOMP] =
1117 dst[i][GCOMP] =
1118 dst[i][BCOMP] = 0.0;
1119 dst[i][ACOMP] = (GLfloat) s[i];
1120 }
1121 }
1122
1123 static void
1124 unpack_ALPHA_INT8(const void *src, GLfloat dst[][4], GLuint n)
1125 {
1126 const GLbyte *s = (const GLbyte *) src;
1127 GLuint i;
1128 for (i = 0; i < n; i++) {
1129 dst[i][RCOMP] =
1130 dst[i][GCOMP] =
1131 dst[i][BCOMP] = 0.0;
1132 dst[i][ACOMP] = (GLfloat) s[i];
1133 }
1134 }
1135
1136 static void
1137 unpack_ALPHA_INT16(const void *src, GLfloat dst[][4], GLuint n)
1138 {
1139 const GLshort *s = (const GLshort *) src;
1140 GLuint i;
1141 for (i = 0; i < n; i++) {
1142 dst[i][RCOMP] =
1143 dst[i][GCOMP] =
1144 dst[i][BCOMP] = 0.0;
1145 dst[i][ACOMP] = (GLfloat) s[i];
1146 }
1147 }
1148
1149 static void
1150 unpack_ALPHA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1151 {
1152 const GLint *s = (const GLint *) src;
1153 GLuint i;
1154 for (i = 0; i < n; i++) {
1155 dst[i][RCOMP] =
1156 dst[i][GCOMP] =
1157 dst[i][BCOMP] = 0.0;
1158 dst[i][ACOMP] = (GLfloat) s[i];
1159 }
1160 }
1161
1162 static void
1163 unpack_INTENSITY_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1164 {
1165 const GLubyte *s = (const GLubyte *) src;
1166 GLuint i;
1167 for (i = 0; i < n; i++) {
1168 dst[i][RCOMP] =
1169 dst[i][GCOMP] =
1170 dst[i][BCOMP] =
1171 dst[i][ACOMP] = (GLfloat) s[i];
1172 }
1173 }
1174
1175 static void
1176 unpack_INTENSITY_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1177 {
1178 const GLushort *s = (const GLushort *) src;
1179 GLuint i;
1180 for (i = 0; i < n; i++) {
1181 dst[i][RCOMP] =
1182 dst[i][GCOMP] =
1183 dst[i][BCOMP] =
1184 dst[i][ACOMP] = (GLfloat) s[i];
1185 }
1186 }
1187
1188 static void
1189 unpack_INTENSITY_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1190 {
1191 const GLuint *s = (const GLuint *) src;
1192 GLuint i;
1193 for (i = 0; i < n; i++) {
1194 dst[i][RCOMP] =
1195 dst[i][GCOMP] =
1196 dst[i][BCOMP] =
1197 dst[i][ACOMP] = (GLfloat) s[i];
1198 }
1199 }
1200
1201 static void
1202 unpack_INTENSITY_INT8(const void *src, GLfloat dst[][4], GLuint n)
1203 {
1204 const GLbyte *s = (const GLbyte *) src;
1205 GLuint i;
1206 for (i = 0; i < n; i++) {
1207 dst[i][RCOMP] =
1208 dst[i][GCOMP] =
1209 dst[i][BCOMP] =
1210 dst[i][ACOMP] = (GLfloat) s[i];
1211 }
1212 }
1213
1214 static void
1215 unpack_INTENSITY_INT16(const void *src, GLfloat dst[][4], GLuint n)
1216 {
1217 const GLshort *s = (const GLshort *) src;
1218 GLuint i;
1219 for (i = 0; i < n; i++) {
1220 dst[i][RCOMP] =
1221 dst[i][GCOMP] =
1222 dst[i][BCOMP] =
1223 dst[i][ACOMP] = (GLfloat) s[i];
1224 }
1225 }
1226
1227 static void
1228 unpack_INTENSITY_INT32(const void *src, GLfloat dst[][4], GLuint n)
1229 {
1230 const GLint *s = (const GLint *) src;
1231 GLuint i;
1232 for (i = 0; i < n; i++) {
1233 dst[i][RCOMP] =
1234 dst[i][GCOMP] =
1235 dst[i][BCOMP] =
1236 dst[i][ACOMP] = (GLfloat) s[i];
1237 }
1238 }
1239
1240 static void
1241 unpack_LUMINANCE_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1242 {
1243 const GLubyte *s = (const GLubyte *) src;
1244 GLuint i;
1245 for (i = 0; i < n; i++) {
1246 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1247 dst[i][ACOMP] = 1.0;
1248 }
1249 }
1250
1251 static void
1252 unpack_LUMINANCE_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1253 {
1254 const GLushort *s = (const GLushort *) src;
1255 GLuint i;
1256 for (i = 0; i < n; i++) {
1257 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1258 dst[i][ACOMP] = 1.0;
1259 }
1260 }
1261
1262 static void
1263 unpack_LUMINANCE_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1264 {
1265 const GLuint *s = (const GLuint *) src;
1266 GLuint i;
1267 for (i = 0; i < n; i++) {
1268 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1269 dst[i][ACOMP] = 1.0;
1270 }
1271 }
1272
1273 static void
1274 unpack_LUMINANCE_INT8(const void *src, GLfloat dst[][4], GLuint n)
1275 {
1276 const GLbyte *s = (const GLbyte *) src;
1277 GLuint i;
1278 for (i = 0; i < n; i++) {
1279 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1280 dst[i][ACOMP] = 1.0;
1281 }
1282 }
1283
1284 static void
1285 unpack_LUMINANCE_INT16(const void *src, GLfloat dst[][4], GLuint n)
1286 {
1287 const GLshort *s = (const GLshort *) src;
1288 GLuint i;
1289 for (i = 0; i < n; i++) {
1290 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1291 dst[i][ACOMP] = 1.0;
1292 }
1293 }
1294
1295 static void
1296 unpack_LUMINANCE_INT32(const void *src, GLfloat dst[][4], GLuint n)
1297 {
1298 const GLint *s = (const GLint *) src;
1299 GLuint i;
1300 for (i = 0; i < n; i++) {
1301 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1302 dst[i][ACOMP] = 1.0;
1303 }
1304 }
1305
1306 static void
1307 unpack_LUMINANCE_ALPHA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1308 {
1309 const GLubyte *s = (const GLubyte *) src;
1310 GLuint i;
1311 for (i = 0; i < n; i++) {
1312 dst[i][RCOMP] =
1313 dst[i][GCOMP] =
1314 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1315 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1316 }
1317 }
1318
1319 static void
1320 unpack_LUMINANCE_ALPHA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1321 {
1322 const GLushort *s = (const GLushort *) src;
1323 GLuint i;
1324 for (i = 0; i < n; i++) {
1325 dst[i][RCOMP] =
1326 dst[i][GCOMP] =
1327 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1328 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1329 }
1330 }
1331
1332 static void
1333 unpack_LUMINANCE_ALPHA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1334 {
1335 const GLuint *s = (const GLuint *) src;
1336 GLuint i;
1337 for (i = 0; i < n; i++) {
1338 dst[i][RCOMP] =
1339 dst[i][GCOMP] =
1340 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1341 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1342 }
1343 }
1344
1345 static void
1346 unpack_LUMINANCE_ALPHA_INT8(const void *src, GLfloat dst[][4], GLuint n)
1347 {
1348 const GLbyte *s = (const GLbyte *) src;
1349 GLuint i;
1350 for (i = 0; i < n; i++) {
1351 dst[i][RCOMP] =
1352 dst[i][GCOMP] =
1353 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1354 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1355 }
1356 }
1357
1358 static void
1359 unpack_LUMINANCE_ALPHA_INT16(const void *src, GLfloat dst[][4], GLuint n)
1360 {
1361 const GLshort *s = (const GLshort *) src;
1362 GLuint i;
1363 for (i = 0; i < n; i++) {
1364 dst[i][RCOMP] =
1365 dst[i][GCOMP] =
1366 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1367 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1368 }
1369 }
1370
1371 static void
1372 unpack_LUMINANCE_ALPHA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1373 {
1374 const GLint *s = (const GLint *) src;
1375 GLuint i;
1376 for (i = 0; i < n; i++) {
1377 dst[i][RCOMP] =
1378 dst[i][GCOMP] =
1379 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1380 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1381 }
1382 }
1383
1384 static void
1385 unpack_R_INT8(const void *src, GLfloat dst[][4], GLuint n)
1386 {
1387 const GLbyte *s = (const GLbyte *) src;
1388 GLuint i;
1389 for (i = 0; i < n; i++) {
1390 dst[i][RCOMP] = (GLfloat) s[i];
1391 dst[i][GCOMP] = 0.0;
1392 dst[i][BCOMP] = 0.0;
1393 dst[i][ACOMP] = 1.0;
1394 }
1395 }
1396
1397 static void
1398 unpack_RG_INT8(const void *src, GLfloat dst[][4], GLuint n)
1399 {
1400 const GLbyte *s = (const GLbyte *) src;
1401 GLuint i;
1402 for (i = 0; i < n; i++) {
1403 dst[i][RCOMP] = (GLfloat) s[i*2+0];
1404 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1405 dst[i][BCOMP] = 0.0;
1406 dst[i][ACOMP] = 1.0;
1407 }
1408 }
1409
1410 static void
1411 unpack_RGB_INT8(const void *src, GLfloat dst[][4], GLuint n)
1412 {
1413 const GLbyte *s = (const GLbyte *) src;
1414 GLuint i;
1415 for (i = 0; i < n; i++) {
1416 dst[i][RCOMP] = (GLfloat) s[i*3+0];
1417 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1418 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1419 dst[i][ACOMP] = 1.0;
1420 }
1421 }
1422
1423 static void
1424 unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
1425 {
1426 const GLbyte *s = (const GLbyte *) src;
1427 GLuint i;
1428 for (i = 0; i < n; i++) {
1429 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1430 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1431 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1432 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1433 }
1434 }
1435
1436 static void
1437 unpack_R_INT16(const void *src, GLfloat dst[][4], GLuint n)
1438 {
1439 const GLshort *s = (const GLshort *) src;
1440 GLuint i;
1441 for (i = 0; i < n; i++) {
1442 dst[i][RCOMP] = (GLfloat) s[i];
1443 dst[i][GCOMP] = 0.0;
1444 dst[i][BCOMP] = 0.0;
1445 dst[i][ACOMP] = 1.0;
1446 }
1447 }
1448
1449 static void
1450 unpack_RG_INT16(const void *src, GLfloat dst[][4], GLuint n)
1451 {
1452 const GLshort *s = (const GLshort *) src;
1453 GLuint i;
1454 for (i = 0; i < n; i++) {
1455 dst[i][RCOMP] = (GLfloat) s[i*2+0];
1456 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1457 dst[i][BCOMP] = 0.0;
1458 dst[i][ACOMP] = 1.0;
1459 }
1460 }
1461
1462 static void
1463 unpack_RGB_INT16(const void *src, GLfloat dst[][4], GLuint n)
1464 {
1465 const GLshort *s = (const GLshort *) src;
1466 GLuint i;
1467 for (i = 0; i < n; i++) {
1468 dst[i][RCOMP] = (GLfloat) s[i*3+0];
1469 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1470 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1471 dst[i][ACOMP] = 1.0;
1472 }
1473 }
1474
1475 static void
1476 unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
1477 {
1478 const GLshort *s = (const GLshort *) src;
1479 GLuint i;
1480 for (i = 0; i < n; i++) {
1481 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1482 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1483 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1484 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1485 }
1486 }
1487
1488 static void
1489 unpack_R_INT32(const void *src, GLfloat dst[][4], GLuint n)
1490 {
1491 const GLint *s = (const GLint *) src;
1492 GLuint i;
1493 for (i = 0; i < n; i++) {
1494 dst[i][RCOMP] = (GLfloat) s[i];
1495 dst[i][GCOMP] = 0.0;
1496 dst[i][BCOMP] = 0.0;
1497 dst[i][ACOMP] = 1.0;
1498 }
1499 }
1500
1501 static void
1502 unpack_RG_INT32(const void *src, GLfloat dst[][4], GLuint n)
1503 {
1504 const GLint *s = (const GLint *) src;
1505 GLuint i;
1506 for (i = 0; i < n; i++) {
1507 dst[i][RCOMP] = (GLfloat) s[i*2+0];
1508 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1509 dst[i][BCOMP] = 0.0;
1510 dst[i][ACOMP] = 1.0;
1511 }
1512 }
1513
1514 static void
1515 unpack_RGB_INT32(const void *src, GLfloat dst[][4], GLuint n)
1516 {
1517 const GLint *s = (const GLint *) src;
1518 GLuint i;
1519 for (i = 0; i < n; i++) {
1520 dst[i][RCOMP] = (GLfloat) s[i*3+0];
1521 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1522 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1523 dst[i][ACOMP] = 1.0;
1524 }
1525 }
1526
1527
1528 static void
1529 unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1530 {
1531 const GLint *s = (const GLint *) src;
1532 GLuint i;
1533 for (i = 0; i < n; i++) {
1534 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1535 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1536 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1537 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1538 }
1539 }
1540
1541 static void
1542 unpack_R_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1543 {
1544 const GLubyte *s = (const GLubyte *) src;
1545 GLuint i;
1546 for (i = 0; i < n; i++) {
1547 dst[i][RCOMP] = (GLfloat) s[i];
1548 dst[i][GCOMP] = 0.0;
1549 dst[i][BCOMP] = 0.0;
1550 dst[i][ACOMP] = 1.0;
1551 }
1552 }
1553
1554 static void
1555 unpack_RG_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1556 {
1557 const GLubyte *s = (const GLubyte *) src;
1558 GLuint i;
1559 for (i = 0; i < n; i++) {
1560 dst[i][RCOMP] = (GLfloat) s[i*2+0];
1561 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1562 dst[i][BCOMP] = 0.0;
1563 dst[i][ACOMP] = 1.0;
1564 }
1565 }
1566
1567 static void
1568 unpack_RGB_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1569 {
1570 const GLubyte *s = (const GLubyte *) src;
1571 GLuint i;
1572 for (i = 0; i < n; i++) {
1573 dst[i][RCOMP] = (GLfloat) s[i*3+0];
1574 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1575 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1576 dst[i][ACOMP] = 1.0;
1577 }
1578 }
1579
1580 static void
1581 unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1582 {
1583 const GLubyte *s = (const GLubyte *) src;
1584 GLuint i;
1585 for (i = 0; i < n; i++) {
1586 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1587 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1588 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1589 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1590 }
1591 }
1592
1593 static void
1594 unpack_R_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1595 {
1596 const GLushort *s = (const GLushort *) src;
1597 GLuint i;
1598 for (i = 0; i < n; i++) {
1599 dst[i][RCOMP] = (GLfloat) s[i];
1600 dst[i][GCOMP] = 0.0;
1601 dst[i][BCOMP] = 0.0;
1602 dst[i][ACOMP] = 1.0;
1603 }
1604 }
1605
1606 static void
1607 unpack_RG_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1608 {
1609 const GLushort *s = (const GLushort *) src;
1610 GLuint i;
1611 for (i = 0; i < n; i++) {
1612 dst[i][RCOMP] = (GLfloat) s[i*2+0];
1613 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1614 dst[i][BCOMP] = 0.0;
1615 dst[i][ACOMP] = 1.0;
1616 }
1617 }
1618
1619 static void
1620 unpack_RGB_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1621 {
1622 const GLushort *s = (const GLushort *) src;
1623 GLuint i;
1624 for (i = 0; i < n; i++) {
1625 dst[i][RCOMP] = (GLfloat) s[i*3+0];
1626 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1627 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1628 dst[i][ACOMP] = 1.0;
1629 }
1630 }
1631
1632 static void
1633 unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1634 {
1635 const GLushort *s = (const GLushort *) src;
1636 GLuint i;
1637 for (i = 0; i < n; i++) {
1638 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1639 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1640 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1641 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1642 }
1643 }
1644
1645 static void
1646 unpack_R_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1647 {
1648 const GLuint *s = (const GLuint *) src;
1649 GLuint i;
1650 for (i = 0; i < n; i++) {
1651 dst[i][RCOMP] = (GLfloat) s[i];
1652 dst[i][GCOMP] = 0.0;
1653 dst[i][BCOMP] = 0.0;
1654 dst[i][ACOMP] = 1.0;
1655 }
1656 }
1657
1658 static void
1659 unpack_RG_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1660 {
1661 const GLuint *s = (const GLuint *) src;
1662 GLuint i;
1663 for (i = 0; i < n; i++) {
1664 dst[i][RCOMP] = (GLfloat) s[i*2+0];
1665 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1666 dst[i][BCOMP] = 0.0;
1667 dst[i][ACOMP] = 1.0;
1668 }
1669 }
1670
1671 static void
1672 unpack_RGB_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1673 {
1674 const GLuint *s = (const GLuint *) src;
1675 GLuint i;
1676 for (i = 0; i < n; i++) {
1677 dst[i][RCOMP] = (GLfloat) s[i*3+0];
1678 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1679 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1680 dst[i][ACOMP] = 1.0;
1681 }
1682 }
1683
1684 static void
1685 unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1686 {
1687 const GLuint *s = (const GLuint *) src;
1688 GLuint i;
1689 for (i = 0; i < n; i++) {
1690 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1691 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1692 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1693 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1694 }
1695 }
1696
1697 static void
1698 unpack_DUDV8(const void *src, GLfloat dst[][4], GLuint n)
1699 {
1700 const GLbyte *s = (const GLbyte *) src;
1701 GLuint i;
1702 for (i = 0; i < n; i++) {
1703 dst[i][RCOMP] = BYTE_TO_FLOAT(s[i*2+0]);
1704 dst[i][GCOMP] = BYTE_TO_FLOAT(s[i*2+1]);
1705 dst[i][BCOMP] = 0;
1706 dst[i][ACOMP] = 0;
1707 }
1708 }
1709
1710 static void
1711 unpack_SIGNED_R8(const void *src, GLfloat dst[][4], GLuint n)
1712 {
1713 const GLbyte *s = ((const GLbyte *) src);
1714 GLuint i;
1715 for (i = 0; i < n; i++) {
1716 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1717 dst[i][GCOMP] = 0.0F;
1718 dst[i][BCOMP] = 0.0F;
1719 dst[i][ACOMP] = 1.0F;
1720 }
1721 }
1722
1723 static void
1724 unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
1725 {
1726 const GLushort *s = ((const GLushort *) src);
1727 GLuint i;
1728 for (i = 0; i < n; i++) {
1729 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1730 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1731 dst[i][BCOMP] = 0.0F;
1732 dst[i][ACOMP] = 1.0F;
1733 }
1734 }
1735
1736 static void
1737 unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
1738 {
1739 const GLuint *s = ((const GLuint *) src);
1740 GLuint i;
1741 for (i = 0; i < n; i++) {
1742 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1743 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1744 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1745 dst[i][ACOMP] = 1.0f;
1746 }
1747 }
1748
1749 static void
1750 unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
1751 {
1752 const GLuint *s = ((const GLuint *) src);
1753 GLuint i;
1754 for (i = 0; i < n; i++) {
1755 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1756 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1757 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1758 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1759 }
1760 }
1761
1762 static void
1763 unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
1764 {
1765 const GLuint *s = ((const GLuint *) src);
1766 GLuint i;
1767 for (i = 0; i < n; i++) {
1768 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1769 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1770 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1771 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1772 }
1773 }
1774
1775 static void
1776 unpack_SIGNED_R16(const void *src, GLfloat dst[][4], GLuint n)
1777 {
1778 const GLshort *s = ((const GLshort *) src);
1779 GLuint i;
1780 for (i = 0; i < n; i++) {
1781 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1782 dst[i][GCOMP] = 0.0F;
1783 dst[i][BCOMP] = 0.0F;
1784 dst[i][ACOMP] = 1.0F;
1785 }
1786 }
1787
1788 static void
1789 unpack_SIGNED_GR1616(const void *src, GLfloat dst[][4], GLuint n)
1790 {
1791 const GLuint *s = ((const GLuint *) src);
1792 GLuint i;
1793 for (i = 0; i < n; i++) {
1794 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
1795 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
1796 dst[i][BCOMP] = 0.0F;
1797 dst[i][ACOMP] = 1.0F;
1798 }
1799 }
1800
1801 static void
1802 unpack_SIGNED_RGB_16(const void *src, GLfloat dst[][4], GLuint n)
1803 {
1804 const GLshort *s = (const GLshort *) src;
1805 GLuint i;
1806 for (i = 0; i < n; i++) {
1807 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] );
1808 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
1809 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
1810 dst[i][ACOMP] = 1.0F;
1811 }
1812 }
1813
1814 static void
1815 unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1816 {
1817 const GLshort *s = (const GLshort *) src;
1818 GLuint i;
1819 for (i = 0; i < n; i++) {
1820 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
1821 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
1822 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
1823 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
1824 }
1825 }
1826
1827 static void
1828 unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1829 {
1830 const GLushort *s = (const GLushort *) src;
1831 GLuint i;
1832 for (i = 0; i < n; i++) {
1833 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
1834 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
1835 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
1836 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
1837 }
1838 }
1839
1840 static void
1841 unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1842 {
1843 /* XXX to do */
1844 }
1845
1846 static void
1847 unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1848 {
1849 /* XXX to do */
1850 }
1851
1852 static void
1853 unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1854 {
1855 /* XXX to do */
1856 }
1857
1858 static void
1859 unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1860 {
1861 /* XXX to do */
1862 }
1863
1864 static void
1865 unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1866 {
1867 /* XXX to do */
1868 }
1869
1870 static void
1871 unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1872 {
1873 /* XXX to do */
1874 }
1875
1876 static void
1877 unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1878 {
1879 /* XXX to do */
1880 }
1881
1882 static void
1883 unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1884 {
1885 /* XXX to do */
1886 }
1887
1888 static void
1889 unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1890 {
1891 /* XXX to do */
1892 }
1893
1894 static void
1895 unpack_ETC2_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1896 {
1897 /* XXX to do */
1898 }
1899
1900 static void
1901 unpack_ETC2_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
1902 {
1903 /* XXX to do */
1904 }
1905
1906 static void
1907 unpack_ETC2_RGBA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
1908 {
1909 /* XXX to do */
1910 }
1911
1912 static void
1913 unpack_ETC2_SRGB8_ALPHA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
1914 {
1915 /* XXX to do */
1916 }
1917
1918 static void
1919 unpack_ETC2_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1920 {
1921 /* XXX to do */
1922 }
1923
1924 static void
1925 unpack_ETC2_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1926 {
1927 /* XXX to do */
1928 }
1929
1930 static void
1931 unpack_ETC2_SIGNED_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1932 {
1933 /* XXX to do */
1934 }
1935
1936 static void
1937 unpack_ETC2_SIGNED_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1938 {
1939 /* XXX to do */
1940 }
1941
1942 static void
1943 unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
1944 GLuint n)
1945 {
1946 /* XXX to do */
1947 }
1948
1949 static void
1950 unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
1951 GLuint n)
1952 {
1953 /* XXX to do */
1954 }
1955
1956 static void
1957 unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n)
1958 {
1959 const GLbyte *s = ((const GLbyte *) src);
1960 GLuint i;
1961 for (i = 0; i < n; i++) {
1962 dst[i][RCOMP] = 0.0F;
1963 dst[i][GCOMP] = 0.0F;
1964 dst[i][BCOMP] = 0.0F;
1965 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1966 }
1967 }
1968
1969 static void
1970 unpack_SIGNED_L8(const void *src, GLfloat dst[][4], GLuint n)
1971 {
1972 const GLbyte *s = ((const GLbyte *) src);
1973 GLuint i;
1974 for (i = 0; i < n; i++) {
1975 dst[i][RCOMP] =
1976 dst[i][GCOMP] =
1977 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1978 dst[i][ACOMP] = 1.0F;
1979 }
1980 }
1981
1982 static void
1983 unpack_SIGNED_AL88(const void *src, GLfloat dst[][4], GLuint n)
1984 {
1985 const GLshort *s = ((const GLshort *) src);
1986 GLuint i;
1987 for (i = 0; i < n; i++) {
1988 dst[i][RCOMP] =
1989 dst[i][GCOMP] =
1990 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1991 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1992 }
1993 }
1994
1995 static void
1996 unpack_SIGNED_I8(const void *src, GLfloat dst[][4], GLuint n)
1997 {
1998 const GLbyte *s = ((const GLbyte *) src);
1999 GLuint i;
2000 for (i = 0; i < n; i++) {
2001 dst[i][RCOMP] =
2002 dst[i][GCOMP] =
2003 dst[i][BCOMP] =
2004 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
2005 }
2006 }
2007
2008 static void
2009 unpack_SIGNED_A16(const void *src, GLfloat dst[][4], GLuint n)
2010 {
2011 const GLshort *s = ((const GLshort *) src);
2012 GLuint i;
2013 for (i = 0; i < n; i++) {
2014 dst[i][RCOMP] = 0.0F;
2015 dst[i][GCOMP] = 0.0F;
2016 dst[i][BCOMP] = 0.0F;
2017 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
2018 }
2019 }
2020
2021 static void
2022 unpack_SIGNED_L16(const void *src, GLfloat dst[][4], GLuint n)
2023 {
2024 const GLshort *s = ((const GLshort *) src);
2025 GLuint i;
2026 for (i = 0; i < n; i++) {
2027 dst[i][RCOMP] =
2028 dst[i][GCOMP] =
2029 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
2030 dst[i][ACOMP] = 1.0F;
2031 }
2032 }
2033
2034 static void
2035 unpack_SIGNED_AL1616(const void *src, GLfloat dst[][4], GLuint n)
2036 {
2037 const GLshort *s = (const GLshort *) src;
2038 GLuint i;
2039 for (i = 0; i < n; i++) {
2040 dst[i][RCOMP] =
2041 dst[i][GCOMP] =
2042 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
2043 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
2044 }
2045 }
2046
2047 static void
2048 unpack_SIGNED_I16(const void *src, GLfloat dst[][4], GLuint n)
2049 {
2050 const GLshort *s = ((const GLshort *) src);
2051 GLuint i;
2052 for (i = 0; i < n; i++) {
2053 dst[i][RCOMP] =
2054 dst[i][GCOMP] =
2055 dst[i][BCOMP] =
2056 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
2057 }
2058 }
2059
2060 static void
2061 unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2062 {
2063 const GLuint *s = (const GLuint *) src;
2064 GLuint i;
2065 for (i = 0; i < n; i++) {
2066 rgb9e5_to_float3(s[i], dst[i]);
2067 dst[i][ACOMP] = 1.0F;
2068 }
2069 }
2070
2071 static void
2072 unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2073 {
2074 const GLuint *s = (const GLuint *) src;
2075 GLuint i;
2076 for (i = 0; i < n; i++) {
2077 r11g11b10f_to_float3(s[i], dst[i]);
2078 dst[i][ACOMP] = 1.0F;
2079 }
2080 }
2081
2082 static void
2083 unpack_XRGB4444_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2084 {
2085 const GLushort *s = ((const GLushort *) src);
2086 GLuint i;
2087 for (i = 0; i < n; i++) {
2088 dst[i][RCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
2089 dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
2090 dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
2091 dst[i][ACOMP] = 1.0;
2092 }
2093 }
2094
2095 static void
2096 unpack_XRGB1555_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2097 {
2098 const GLushort *s = ((const GLushort *) src);
2099 GLuint i;
2100 for (i = 0; i < n; i++) {
2101 dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
2102 dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F);
2103 dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F);
2104 dst[i][ACOMP] = 1.0;
2105 }
2106 }
2107
2108 static void
2109 unpack_XBGR8888_SNORM(const void *src, GLfloat dst[][4], GLuint n)
2110 {
2111 const GLuint *s = ((const GLuint *) src);
2112 GLuint i;
2113 for (i = 0; i < n; i++) {
2114 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
2115 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
2116 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
2117 dst[i][ACOMP] = 1.0;
2118 }
2119 }
2120
2121 static void
2122 unpack_XBGR8888_SRGB(const void *src, GLfloat dst[][4], GLuint n)
2123 {
2124 const GLuint *s = ((const GLuint *) src);
2125 GLuint i;
2126 for (i = 0; i < n; i++) {
2127 dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff );
2128 dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff );
2129 dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
2130 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
2131 }
2132 }
2133
2134 static void
2135 unpack_XBGR8888_UINT(const void *src, GLfloat dst[][4], GLuint n)
2136 {
2137 const GLbyte *s = (const GLbyte *) src;
2138 GLuint i;
2139 for (i = 0; i < n; i++) {
2140 dst[i][RCOMP] = s[i*4+0];
2141 dst[i][GCOMP] = s[i*4+1];
2142 dst[i][BCOMP] = s[i*4+2];
2143 dst[i][ACOMP] = 1.0;
2144 }
2145 }
2146
2147 static void
2148 unpack_XBGR8888_SINT(const void *src, GLfloat dst[][4], GLuint n)
2149 {
2150 const GLbyte *s = (const GLbyte *) src;
2151 GLuint i;
2152 for (i = 0; i < n; i++) {
2153 dst[i][RCOMP] = s[i*4+0];
2154 dst[i][GCOMP] = s[i*4+1];
2155 dst[i][BCOMP] = s[i*4+2];
2156 dst[i][ACOMP] = 1.0;
2157 }
2158 }
2159
2160 static void
2161 unpack_XRGB2101010_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2162 {
2163 const GLuint *s = ((const GLuint *) src);
2164 GLuint i;
2165 for (i = 0; i < n; i++) {
2166 dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
2167 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
2168 dst[i][BCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
2169 dst[i][ACOMP] = 1.0;
2170 }
2171 }
2172
2173 static void
2174 unpack_XBGR16161616_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2175 {
2176 const GLushort *s = (const GLushort *) src;
2177 GLuint i;
2178 for (i = 0; i < n; i++) {
2179 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
2180 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
2181 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
2182 dst[i][ACOMP] = 1.0;
2183 }
2184 }
2185
2186 static void
2187 unpack_XBGR16161616_SNORM(const void *src, GLfloat dst[][4], GLuint n)
2188 {
2189 const GLshort *s = (const GLshort *) src;
2190 GLuint i;
2191 for (i = 0; i < n; i++) {
2192 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
2193 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
2194 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
2195 dst[i][ACOMP] = 1.0;
2196 }
2197 }
2198
2199 static void
2200 unpack_XBGR16161616_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2201 {
2202 const GLshort *s = (const GLshort *) src;
2203 GLuint i;
2204 for (i = 0; i < n; i++) {
2205 dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
2206 dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
2207 dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
2208 dst[i][ACOMP] = 1.0;
2209 }
2210 }
2211
2212 static void
2213 unpack_XBGR16161616_UINT(const void *src, GLfloat dst[][4], GLuint n)
2214 {
2215 const GLushort *s = (const GLushort *) src;
2216 GLuint i;
2217 for (i = 0; i < n; i++) {
2218 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2219 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2220 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2221 dst[i][ACOMP] = 1.0;
2222 }
2223 }
2224
2225 static void
2226 unpack_XBGR16161616_SINT(const void *src, GLfloat dst[][4], GLuint n)
2227 {
2228 const GLshort *s = (const GLshort *) src;
2229 GLuint i;
2230 for (i = 0; i < n; i++) {
2231 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2232 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2233 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2234 dst[i][ACOMP] = 1.0;
2235 }
2236 }
2237
2238 static void
2239 unpack_XBGR32323232_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2240 {
2241 const GLfloat *s = (const GLfloat *) src;
2242 GLuint i;
2243 for (i = 0; i < n; i++) {
2244 dst[i][RCOMP] = s[i*4+0];
2245 dst[i][GCOMP] = s[i*4+1];
2246 dst[i][BCOMP] = s[i*4+2];
2247 dst[i][ACOMP] = 1.0;
2248 }
2249 }
2250
2251 static void
2252 unpack_XBGR32323232_UINT(const void *src, GLfloat dst[][4], GLuint n)
2253 {
2254 const GLuint *s = (const GLuint *) src;
2255 GLuint i;
2256 for (i = 0; i < n; i++) {
2257 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2258 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2259 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2260 dst[i][ACOMP] = 1.0;
2261 }
2262 }
2263
2264 static void
2265 unpack_XBGR32323232_SINT(const void *src, GLfloat dst[][4], GLuint n)
2266 {
2267 const GLint *s = (const GLint *) src;
2268 GLuint i;
2269 for (i = 0; i < n; i++) {
2270 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2271 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2272 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2273 dst[i][ACOMP] = 1.0;
2274 }
2275 }
2276
2277 static void
2278 unpack_ABGR2101010(const void *src, GLfloat dst[][4], GLuint n)
2279 {
2280 const GLuint *s = ((const GLuint *) src);
2281 GLuint i;
2282 for (i = 0; i < n; i++) {
2283 dst[i][RCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
2284 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
2285 dst[i][BCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
2286 dst[i][ACOMP] = ((s[i] >> 30) & 0x03) * (1.0F / 3.0F);
2287 }
2288 }
2289
2290 static void
2291 unpack_SIGNED_RG88(const void *src, GLfloat dst[][4], GLuint n)
2292 {
2293 const GLushort *s = ((const GLushort *) src);
2294 GLuint i;
2295 for (i = 0; i < n; i++) {
2296 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
2297 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
2298 dst[i][BCOMP] = 0.0F;
2299 dst[i][ACOMP] = 1.0F;
2300 }
2301 }
2302
2303 static void
2304 unpack_SIGNED_RG1616(const void *src, GLfloat dst[][4], GLuint n)
2305 {
2306 const GLuint *s = ((const GLuint *) src);
2307 GLuint i;
2308 for (i = 0; i < n; i++) {
2309 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
2310 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
2311 dst[i][BCOMP] = 0.0F;
2312 dst[i][ACOMP] = 1.0F;
2313 }
2314 }
2315
2316 /**
2317 * Return the unpacker function for the given format.
2318 */
2319 static unpack_rgba_func
2320 get_unpack_rgba_function(mesa_format format)
2321 {
2322 static unpack_rgba_func table[MESA_FORMAT_COUNT];
2323 static GLboolean initialized = GL_FALSE;
2324
2325 if (!initialized) {
2326 table[MESA_FORMAT_NONE] = NULL;
2327
2328 table[MESA_FORMAT_A8B8G8R8_UNORM] = unpack_RGBA8888;
2329 table[MESA_FORMAT_R8G8B8A8_UNORM] = unpack_RGBA8888_REV;
2330 table[MESA_FORMAT_B8G8R8A8_UNORM] = unpack_ARGB8888;
2331 table[MESA_FORMAT_A8R8G8B8_UNORM] = unpack_ARGB8888_REV;
2332 table[MESA_FORMAT_X8B8G8R8_UNORM] = unpack_RGBX8888;
2333 table[MESA_FORMAT_R8G8B8X8_UNORM] = unpack_RGBX8888_REV;
2334 table[MESA_FORMAT_B8G8R8X8_UNORM] = unpack_XRGB8888;
2335 table[MESA_FORMAT_X8R8G8B8_UNORM] = unpack_XRGB8888_REV;
2336 table[MESA_FORMAT_BGR_UNORM8] = unpack_RGB888;
2337 table[MESA_FORMAT_RGB_UNORM8] = unpack_BGR888;
2338 table[MESA_FORMAT_B5G6R5_UNORM] = unpack_RGB565;
2339 table[MESA_FORMAT_R5G6B5_UNORM] = unpack_RGB565_REV;
2340 table[MESA_FORMAT_B4G4R4A4_UNORM] = unpack_ARGB4444;
2341 table[MESA_FORMAT_A4R4G4B4_UNORM] = unpack_ARGB4444_REV;
2342 table[MESA_FORMAT_A1B5G5R5_UNORM] = unpack_RGBA5551;
2343 table[MESA_FORMAT_B5G5R5A1_UNORM] = unpack_ARGB1555;
2344 table[MESA_FORMAT_A1R5G5B5_UNORM] = unpack_ARGB1555_REV;
2345 table[MESA_FORMAT_L4A4_UNORM] = unpack_AL44;
2346 table[MESA_FORMAT_L8A8_UNORM] = unpack_AL88;
2347 table[MESA_FORMAT_A8L8_UNORM] = unpack_AL88_REV;
2348 table[MESA_FORMAT_L16A16_UNORM] = unpack_AL1616;
2349 table[MESA_FORMAT_A16L16_UNORM] = unpack_AL1616_REV;
2350 table[MESA_FORMAT_B2G3R3_UNORM] = unpack_RGB332;
2351 table[MESA_FORMAT_A_UNORM8] = unpack_A8;
2352 table[MESA_FORMAT_A_UNORM16] = unpack_A16;
2353 table[MESA_FORMAT_L_UNORM8] = unpack_L8;
2354 table[MESA_FORMAT_L_UNORM16] = unpack_L16;
2355 table[MESA_FORMAT_I_UNORM8] = unpack_I8;
2356 table[MESA_FORMAT_I_UNORM16] = unpack_I16;
2357 table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
2358 table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
2359 table[MESA_FORMAT_R_UNORM8] = unpack_R8;
2360 table[MESA_FORMAT_R8G8_UNORM] = unpack_GR88;
2361 table[MESA_FORMAT_G8R8_UNORM] = unpack_RG88;
2362 table[MESA_FORMAT_R_UNORM16] = unpack_R16;
2363 table[MESA_FORMAT_R16G16_UNORM] = unpack_GR1616;
2364 table[MESA_FORMAT_G16R16_UNORM] = unpack_RG1616;
2365 table[MESA_FORMAT_B10G10R10A2_UNORM] = unpack_ARGB2101010;
2366 table[MESA_FORMAT_B10G10R10A2_UINT] = unpack_ARGB2101010_UINT;
2367 table[MESA_FORMAT_R10G10B10A2_UINT] = unpack_ABGR2101010_UINT;
2368 table[MESA_FORMAT_S8_UINT_Z24_UNORM] = unpack_Z24_S8;
2369 table[MESA_FORMAT_Z24_UNORM_S8_UINT] = unpack_S8_Z24;
2370 table[MESA_FORMAT_Z_UNORM16] = unpack_Z16;
2371 table[MESA_FORMAT_Z24_UNORM_X8_UINT] = unpack_X8_Z24;
2372 table[MESA_FORMAT_X8Z24_UNORM] = unpack_Z24_X8;
2373 table[MESA_FORMAT_Z_UNORM32] = unpack_Z32;
2374 table[MESA_FORMAT_S_UINT8] = unpack_S8;
2375 table[MESA_FORMAT_BGR_SRGB8] = unpack_SRGB8;
2376 table[MESA_FORMAT_A8B8G8R8_SRGB] = unpack_SRGBA8;
2377 table[MESA_FORMAT_B8G8R8A8_SRGB] = unpack_SARGB8;
2378 table[MESA_FORMAT_L_SRGB8] = unpack_SL8;
2379 table[MESA_FORMAT_L8A8_SRGB] = unpack_SLA8;
2380 table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
2381 table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
2382 table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
2383 table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
2384
2385 table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
2386 table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
2387 table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
2388 table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
2389 table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
2390 table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
2391
2392 table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
2393 table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
2394 table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
2395 table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
2396 table[MESA_FORMAT_A_FLOAT32] = unpack_ALPHA_FLOAT32;
2397 table[MESA_FORMAT_A_FLOAT16] = unpack_ALPHA_FLOAT16;
2398 table[MESA_FORMAT_L_FLOAT32] = unpack_LUMINANCE_FLOAT32;
2399 table[MESA_FORMAT_L_FLOAT16] = unpack_LUMINANCE_FLOAT16;
2400 table[MESA_FORMAT_LA_FLOAT32] = unpack_LUMINANCE_ALPHA_FLOAT32;
2401 table[MESA_FORMAT_LA_FLOAT16] = unpack_LUMINANCE_ALPHA_FLOAT16;
2402 table[MESA_FORMAT_I_FLOAT32] = unpack_INTENSITY_FLOAT32;
2403 table[MESA_FORMAT_I_FLOAT16] = unpack_INTENSITY_FLOAT16;
2404 table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
2405 table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
2406 table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
2407 table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
2408
2409 table[MESA_FORMAT_A_UINT8] = unpack_ALPHA_UINT8;
2410 table[MESA_FORMAT_A_UINT16] = unpack_ALPHA_UINT16;
2411 table[MESA_FORMAT_A_UINT32] = unpack_ALPHA_UINT32;
2412 table[MESA_FORMAT_A_SINT8] = unpack_ALPHA_INT8;
2413 table[MESA_FORMAT_A_SINT16] = unpack_ALPHA_INT16;
2414 table[MESA_FORMAT_A_SINT32] = unpack_ALPHA_INT32;
2415
2416 table[MESA_FORMAT_I_UINT8] = unpack_INTENSITY_UINT8;
2417 table[MESA_FORMAT_I_UINT16] = unpack_INTENSITY_UINT16;
2418 table[MESA_FORMAT_I_UINT32] = unpack_INTENSITY_UINT32;
2419 table[MESA_FORMAT_I_SINT8] = unpack_INTENSITY_INT8;
2420 table[MESA_FORMAT_I_SINT16] = unpack_INTENSITY_INT16;
2421 table[MESA_FORMAT_I_SINT32] = unpack_INTENSITY_INT32;
2422
2423 table[MESA_FORMAT_L_UINT8] = unpack_LUMINANCE_UINT8;
2424 table[MESA_FORMAT_L_UINT16] = unpack_LUMINANCE_UINT16;
2425 table[MESA_FORMAT_L_UINT32] = unpack_LUMINANCE_UINT32;
2426 table[MESA_FORMAT_L_SINT8] = unpack_LUMINANCE_INT8;
2427 table[MESA_FORMAT_L_SINT16] = unpack_LUMINANCE_INT16;
2428 table[MESA_FORMAT_L_SINT32] = unpack_LUMINANCE_INT32;
2429
2430 table[MESA_FORMAT_LA_UINT8] = unpack_LUMINANCE_ALPHA_UINT8;
2431 table[MESA_FORMAT_LA_UINT16] = unpack_LUMINANCE_ALPHA_UINT16;
2432 table[MESA_FORMAT_LA_UINT32] = unpack_LUMINANCE_ALPHA_UINT32;
2433 table[MESA_FORMAT_LA_SINT8] = unpack_LUMINANCE_ALPHA_INT8;
2434 table[MESA_FORMAT_LA_SINT16] = unpack_LUMINANCE_ALPHA_INT16;
2435 table[MESA_FORMAT_LA_SINT32] = unpack_LUMINANCE_ALPHA_INT32;
2436
2437 table[MESA_FORMAT_R_SINT8] = unpack_R_INT8;
2438 table[MESA_FORMAT_RG_SINT8] = unpack_RG_INT8;
2439 table[MESA_FORMAT_RGB_SINT8] = unpack_RGB_INT8;
2440 table[MESA_FORMAT_RGBA_SINT8] = unpack_RGBA_INT8;
2441 table[MESA_FORMAT_R_SINT16] = unpack_R_INT16;
2442 table[MESA_FORMAT_RG_SINT16] = unpack_RG_INT16;
2443 table[MESA_FORMAT_RGB_SINT16] = unpack_RGB_INT16;
2444 table[MESA_FORMAT_RGBA_SINT16] = unpack_RGBA_INT16;
2445 table[MESA_FORMAT_R_SINT32] = unpack_R_INT32;
2446 table[MESA_FORMAT_RG_SINT32] = unpack_RG_INT32;
2447 table[MESA_FORMAT_RGB_SINT32] = unpack_RGB_INT32;
2448 table[MESA_FORMAT_RGBA_SINT32] = unpack_RGBA_INT32;
2449 table[MESA_FORMAT_R_UINT8] = unpack_R_UINT8;
2450 table[MESA_FORMAT_RG_UINT8] = unpack_RG_UINT8;
2451 table[MESA_FORMAT_RGB_UINT8] = unpack_RGB_UINT8;
2452 table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
2453 table[MESA_FORMAT_R_UINT16] = unpack_R_UINT16;
2454 table[MESA_FORMAT_RG_UINT16] = unpack_RG_UINT16;
2455 table[MESA_FORMAT_RGB_UINT16] = unpack_RGB_UINT16;
2456 table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
2457 table[MESA_FORMAT_R_UINT32] = unpack_R_UINT32;
2458 table[MESA_FORMAT_RG_UINT32] = unpack_RG_UINT32;
2459 table[MESA_FORMAT_RGB_UINT32] = unpack_RGB_UINT32;
2460 table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
2461
2462 table[MESA_FORMAT_DUDV8] = unpack_DUDV8;
2463 table[MESA_FORMAT_R_SNORM8] = unpack_SIGNED_R8;
2464 table[MESA_FORMAT_R8G8_SNORM] = unpack_SIGNED_RG88_REV;
2465 table[MESA_FORMAT_X8B8G8R8_SNORM] = unpack_SIGNED_RGBX8888;
2466 table[MESA_FORMAT_A8B8G8R8_SNORM] = unpack_SIGNED_RGBA8888;
2467 table[MESA_FORMAT_R8G8B8A8_SNORM] = unpack_SIGNED_RGBA8888_REV;
2468 table[MESA_FORMAT_R_SNORM16] = unpack_SIGNED_R16;
2469 table[MESA_FORMAT_R16G16_SNORM] = unpack_SIGNED_GR1616;
2470 table[MESA_FORMAT_RGB_SNORM16] = unpack_SIGNED_RGB_16;
2471 table[MESA_FORMAT_RGBA_SNORM16] = unpack_SIGNED_RGBA_16;
2472 table[MESA_FORMAT_RGBA_UNORM16] = unpack_RGBA_16;
2473
2474 table[MESA_FORMAT_R_RGTC1_UNORM] = unpack_RED_RGTC1;
2475 table[MESA_FORMAT_R_RGTC1_SNORM] = unpack_SIGNED_RED_RGTC1;
2476 table[MESA_FORMAT_RG_RGTC2_UNORM] = unpack_RG_RGTC2;
2477 table[MESA_FORMAT_RG_RGTC2_SNORM] = unpack_SIGNED_RG_RGTC2;
2478
2479 table[MESA_FORMAT_L_LATC1_UNORM] = unpack_L_LATC1;
2480 table[MESA_FORMAT_L_LATC1_SNORM] = unpack_SIGNED_L_LATC1;
2481 table[MESA_FORMAT_LA_LATC2_UNORM] = unpack_LA_LATC2;
2482 table[MESA_FORMAT_LA_LATC2_SNORM] = unpack_SIGNED_LA_LATC2;
2483
2484 table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
2485 table[MESA_FORMAT_ETC2_RGB8] = unpack_ETC2_RGB8;
2486 table[MESA_FORMAT_ETC2_SRGB8] = unpack_ETC2_SRGB8;
2487 table[MESA_FORMAT_ETC2_RGBA8_EAC] = unpack_ETC2_RGBA8_EAC;
2488 table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = unpack_ETC2_SRGB8_ALPHA8_EAC;
2489 table[MESA_FORMAT_ETC2_R11_EAC] = unpack_ETC2_R11_EAC;
2490 table[MESA_FORMAT_ETC2_RG11_EAC] = unpack_ETC2_RG11_EAC;
2491 table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = unpack_ETC2_SIGNED_R11_EAC;
2492 table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = unpack_ETC2_SIGNED_RG11_EAC;
2493 table[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] =
2494 unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
2495 table[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] =
2496 unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
2497 table[MESA_FORMAT_A_SNORM8] = unpack_SIGNED_A8;
2498 table[MESA_FORMAT_L_SNORM8] = unpack_SIGNED_L8;
2499 table[MESA_FORMAT_L8A8_SNORM] = unpack_SIGNED_AL88;
2500 table[MESA_FORMAT_I_SNORM8] = unpack_SIGNED_I8;
2501 table[MESA_FORMAT_A_SNORM16] = unpack_SIGNED_A16;
2502 table[MESA_FORMAT_L_SNORM16] = unpack_SIGNED_L16;
2503 table[MESA_FORMAT_LA_SNORM16] = unpack_SIGNED_AL1616;
2504 table[MESA_FORMAT_I_SNORM16] = unpack_SIGNED_I16;
2505
2506 table[MESA_FORMAT_R9G9B9E5_FLOAT] = unpack_RGB9_E5_FLOAT;
2507 table[MESA_FORMAT_R11G11B10_FLOAT] = unpack_R11_G11_B10_FLOAT;
2508
2509 table[MESA_FORMAT_Z_FLOAT32] = unpack_Z32_FLOAT;
2510 table[MESA_FORMAT_Z32_FLOAT_S8X24_UINT] = unpack_Z32_FLOAT_X24S8;
2511
2512 table[MESA_FORMAT_B4G4R4X4_UNORM] = unpack_XRGB4444_UNORM;
2513 table[MESA_FORMAT_B5G5R5X1_UNORM] = unpack_XRGB1555_UNORM;
2514 table[MESA_FORMAT_R8G8B8X8_SNORM] = unpack_XBGR8888_SNORM;
2515 table[MESA_FORMAT_R8G8B8X8_SRGB] = unpack_XBGR8888_SRGB;
2516 table[MESA_FORMAT_RGBX_UINT8] = unpack_XBGR8888_UINT;
2517 table[MESA_FORMAT_RGBX_SINT8] = unpack_XBGR8888_SINT;
2518 table[MESA_FORMAT_B10G10R10X2_UNORM] = unpack_XRGB2101010_UNORM;
2519 table[MESA_FORMAT_RGBX_UNORM16] = unpack_XBGR16161616_UNORM;
2520 table[MESA_FORMAT_RGBX_SNORM16] = unpack_XBGR16161616_SNORM;
2521 table[MESA_FORMAT_RGBX_FLOAT16] = unpack_XBGR16161616_FLOAT;
2522 table[MESA_FORMAT_RGBX_UINT16] = unpack_XBGR16161616_UINT;
2523 table[MESA_FORMAT_RGBX_SINT16] = unpack_XBGR16161616_SINT;
2524 table[MESA_FORMAT_RGBX_FLOAT32] = unpack_XBGR32323232_FLOAT;
2525 table[MESA_FORMAT_RGBX_UINT32] = unpack_XBGR32323232_UINT;
2526 table[MESA_FORMAT_RGBX_SINT32] = unpack_XBGR32323232_SINT;
2527
2528 table[MESA_FORMAT_R10G10B10A2_UNORM] = unpack_ABGR2101010;
2529
2530 table[MESA_FORMAT_G8R8_SNORM] = unpack_SIGNED_RG88;
2531 table[MESA_FORMAT_G16R16_SNORM] = unpack_SIGNED_RG1616;
2532
2533 initialized = GL_TRUE;
2534 }
2535
2536 if (table[format] == NULL) {
2537 _mesa_problem(NULL, "unsupported unpack for format %s",
2538 _mesa_get_format_name(format));
2539 }
2540
2541 return table[format];
2542 }
2543
2544
2545 /**
2546 * Unpack rgba colors, returning as GLfloat values.
2547 */
2548 void
2549 _mesa_unpack_rgba_row(mesa_format format, GLuint n,
2550 const void *src, GLfloat dst[][4])
2551 {
2552 unpack_rgba_func unpack = get_unpack_rgba_function(format);
2553 unpack(src, dst, n);
2554 }
2555
2556
2557 /**********************************************************************/
2558 /* Unpack, returning GLubyte colors */
2559 /**********************************************************************/
2560
2561
2562 static void
2563 unpack_ubyte_RGBA8888(const void *src, GLubyte dst[][4], GLuint n)
2564 {
2565 const GLuint *s = ((const GLuint *) src);
2566 GLuint i;
2567 for (i = 0; i < n; i++) {
2568 dst[i][RCOMP] = (s[i] >> 24);
2569 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2570 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
2571 dst[i][ACOMP] = (s[i] ) & 0xff;
2572 }
2573 }
2574
2575 static void
2576 unpack_ubyte_RGBA8888_REV(const void *src, GLubyte dst[][4], GLuint n)
2577 {
2578 const GLuint *s = ((const GLuint *) src);
2579 GLuint i;
2580 for (i = 0; i < n; i++) {
2581 dst[i][RCOMP] = (s[i] ) & 0xff;
2582 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2583 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
2584 dst[i][ACOMP] = (s[i] >> 24);
2585 }
2586 }
2587
2588 static void
2589 unpack_ubyte_ARGB8888(const void *src, GLubyte dst[][4], GLuint n)
2590 {
2591 const GLuint *s = ((const GLuint *) src);
2592 GLuint i;
2593 for (i = 0; i < n; i++) {
2594 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
2595 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2596 dst[i][BCOMP] = (s[i] ) & 0xff;
2597 dst[i][ACOMP] = (s[i] >> 24);
2598 }
2599 }
2600
2601 static void
2602 unpack_ubyte_ARGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
2603 {
2604 const GLuint *s = ((const GLuint *) src);
2605 GLuint i;
2606 for (i = 0; i < n; i++) {
2607 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
2608 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2609 dst[i][BCOMP] = (s[i] >> 24);
2610 dst[i][ACOMP] = (s[i] ) & 0xff;
2611 }
2612 }
2613
2614 static void
2615 unpack_ubyte_RGBX8888(const void *src, GLubyte dst[][4], GLuint n)
2616 {
2617 const GLuint *s = ((const GLuint *) src);
2618 GLuint i;
2619 for (i = 0; i < n; i++) {
2620 dst[i][RCOMP] = (s[i] >> 24);
2621 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2622 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
2623 dst[i][ACOMP] = 0xff;
2624 }
2625 }
2626
2627 static void
2628 unpack_ubyte_RGBX8888_REV(const void *src, GLubyte dst[][4], GLuint n)
2629 {
2630 const GLuint *s = ((const GLuint *) src);
2631 GLuint i;
2632 for (i = 0; i < n; i++) {
2633 dst[i][RCOMP] = (s[i] ) & 0xff;
2634 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2635 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
2636 dst[i][ACOMP] = 0xff;
2637 }
2638 }
2639
2640 static void
2641 unpack_ubyte_XRGB8888(const void *src, GLubyte dst[][4], GLuint n)
2642 {
2643 const GLuint *s = ((const GLuint *) src);
2644 GLuint i;
2645 for (i = 0; i < n; i++) {
2646 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
2647 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2648 dst[i][BCOMP] = (s[i] ) & 0xff;
2649 dst[i][ACOMP] = 0xff;
2650 }
2651 }
2652
2653 static void
2654 unpack_ubyte_XRGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
2655 {
2656 const GLuint *s = ((const GLuint *) src);
2657 GLuint i;
2658 for (i = 0; i < n; i++) {
2659 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
2660 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2661 dst[i][BCOMP] = (s[i] >> 24);
2662 dst[i][ACOMP] = 0xff;
2663 }
2664 }
2665
2666 static void
2667 unpack_ubyte_RGB888(const void *src, GLubyte dst[][4], GLuint n)
2668 {
2669 const GLubyte *s = (const GLubyte *) src;
2670 GLuint i;
2671 for (i = 0; i < n; i++) {
2672 dst[i][RCOMP] = s[i*3+2];
2673 dst[i][GCOMP] = s[i*3+1];
2674 dst[i][BCOMP] = s[i*3+0];
2675 dst[i][ACOMP] = 0xff;
2676 }
2677 }
2678
2679 static void
2680 unpack_ubyte_BGR888(const void *src, GLubyte dst[][4], GLuint n)
2681 {
2682 const GLubyte *s = (const GLubyte *) src;
2683 GLuint i;
2684 for (i = 0; i < n; i++) {
2685 dst[i][RCOMP] = s[i*3+0];
2686 dst[i][GCOMP] = s[i*3+1];
2687 dst[i][BCOMP] = s[i*3+2];
2688 dst[i][ACOMP] = 0xff;
2689 }
2690 }
2691
2692 static void
2693 unpack_ubyte_RGB565(const void *src, GLubyte dst[][4], GLuint n)
2694 {
2695 const GLushort *s = ((const GLushort *) src);
2696 GLuint i;
2697 for (i = 0; i < n; i++) {
2698 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
2699 dst[i][GCOMP] = EXPAND_6_8((s[i] >> 5 ) & 0x3f);
2700 dst[i][BCOMP] = EXPAND_5_8( s[i] & 0x1f);
2701 dst[i][ACOMP] = 0xff;
2702 }
2703 }
2704
2705 static void
2706 unpack_ubyte_RGB565_REV(const void *src, GLubyte dst[][4], GLuint n)
2707 {
2708 /* Warning: this function does not match the current Mesa definition
2709 * of MESA_FORMAT_R5G6B5_UNORM.
2710 */
2711 const GLushort *s = ((const GLushort *) src);
2712 GLuint i;
2713 for (i = 0; i < n; i++) {
2714 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
2715 dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);
2716 dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);
2717 dst[i][BCOMP] = EXPAND_5_8( t & 0x1f);
2718 dst[i][ACOMP] = 0xff;
2719 }
2720 }
2721
2722 static void
2723 unpack_ubyte_ARGB4444(const void *src, GLubyte dst[][4], GLuint n)
2724 {
2725 const GLushort *s = ((const GLushort *) src);
2726 GLuint i;
2727 for (i = 0; i < n; i++) {
2728 dst[i][RCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
2729 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
2730 dst[i][BCOMP] = EXPAND_4_8((s[i] ) & 0xf);
2731 dst[i][ACOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
2732 }
2733 }
2734
2735 static void
2736 unpack_ubyte_ARGB4444_REV(const void *src, GLubyte dst[][4], GLuint n)
2737 {
2738 const GLushort *s = ((const GLushort *) src);
2739 GLuint i;
2740 for (i = 0; i < n; i++) {
2741 dst[i][RCOMP] = EXPAND_4_8((s[i] ) & 0xf);
2742 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
2743 dst[i][BCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
2744 dst[i][ACOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
2745 }
2746 }
2747
2748 static void
2749 unpack_ubyte_RGBA5551(const void *src, GLubyte dst[][4], GLuint n)
2750 {
2751 const GLushort *s = ((const GLushort *) src);
2752 GLuint i;
2753 for (i = 0; i < n; i++) {
2754 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
2755 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 6) & 0x1f);
2756 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 1) & 0x1f);
2757 dst[i][ACOMP] = EXPAND_1_8((s[i] ) & 0x01);
2758 }
2759 }
2760
2761 static void
2762 unpack_ubyte_ARGB1555(const void *src, GLubyte dst[][4], GLuint n)
2763 {
2764 const GLushort *s = ((const GLushort *) src);
2765 GLuint i;
2766 for (i = 0; i < n; i++) {
2767 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 10) & 0x1f);
2768 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 5) & 0x1f);
2769 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 0) & 0x1f);
2770 dst[i][ACOMP] = EXPAND_1_8((s[i] >> 15) & 0x01);
2771 }
2772 }
2773
2774 static void
2775 unpack_ubyte_ARGB1555_REV(const void *src, GLubyte dst[][4], GLuint n)
2776 {
2777 /* Warning: this function does not match the current Mesa definition
2778 * of MESA_FORMAT_A1R5G5B5_UNORM.
2779 */
2780 const GLushort *s = ((const GLushort *) src);
2781 GLuint i;
2782 for (i = 0; i < n; i++) {
2783 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
2784 dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
2785 dst[i][GCOMP] = EXPAND_5_8((tmp >> 5) & 0x1f);
2786 dst[i][BCOMP] = EXPAND_5_8((tmp >> 0) & 0x1f);
2787 dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
2788 }
2789 }
2790
2791 static void
2792 unpack_ubyte_AL44(const void *src, GLubyte dst[][4], GLuint n)
2793 {
2794 const GLubyte *s = ((const GLubyte *) src);
2795 GLuint i;
2796 for (i = 0; i < n; i++) {
2797 dst[i][RCOMP] =
2798 dst[i][GCOMP] =
2799 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xf);
2800 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 4);
2801 }
2802 }
2803
2804 static void
2805 unpack_ubyte_AL88(const void *src, GLubyte dst[][4], GLuint n)
2806 {
2807 const GLushort *s = ((const GLushort *) src);
2808 GLuint i;
2809 for (i = 0; i < n; i++) {
2810 dst[i][RCOMP] =
2811 dst[i][GCOMP] =
2812 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xff);
2813 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 8);
2814 }
2815 }
2816
2817 static void
2818 unpack_ubyte_AL88_REV(const void *src, GLubyte dst[][4], GLuint n)
2819 {
2820 const GLushort *s = ((const GLushort *) src);
2821 GLuint i;
2822 for (i = 0; i < n; i++) {
2823 dst[i][RCOMP] =
2824 dst[i][GCOMP] =
2825 dst[i][BCOMP] = EXPAND_4_8(s[i] >> 8);
2826 dst[i][ACOMP] = EXPAND_4_8(s[i] & 0xff);
2827 }
2828 }
2829
2830 static void
2831 unpack_ubyte_RGB332(const void *src, GLubyte dst[][4], GLuint n)
2832 {
2833 const GLubyte *s = ((const GLubyte *) src);
2834 GLuint i;
2835 for (i = 0; i < n; i++) {
2836 dst[i][RCOMP] = EXPAND_3_8((s[i] >> 5) & 0x7);
2837 dst[i][GCOMP] = EXPAND_3_8((s[i] >> 2) & 0x7);
2838 dst[i][BCOMP] = EXPAND_2_8((s[i] ) & 0x3);
2839 dst[i][ACOMP] = 0xff;
2840 }
2841 }
2842
2843 static void
2844 unpack_ubyte_A8(const void *src, GLubyte dst[][4], GLuint n)
2845 {
2846 const GLubyte *s = ((const GLubyte *) src);
2847 GLuint i;
2848 for (i = 0; i < n; i++) {
2849 dst[i][RCOMP] =
2850 dst[i][GCOMP] =
2851 dst[i][BCOMP] = 0;
2852 dst[i][ACOMP] = s[i];
2853 }
2854 }
2855
2856 static void
2857 unpack_ubyte_L8(const void *src, GLubyte dst[][4], GLuint n)
2858 {
2859 const GLubyte *s = ((const GLubyte *) src);
2860 GLuint i;
2861 for (i = 0; i < n; i++) {
2862 dst[i][RCOMP] =
2863 dst[i][GCOMP] =
2864 dst[i][BCOMP] = s[i];
2865 dst[i][ACOMP] = 0xff;
2866 }
2867 }
2868
2869
2870 static void
2871 unpack_ubyte_I8(const void *src, GLubyte dst[][4], GLuint n)
2872 {
2873 const GLubyte *s = ((const GLubyte *) src);
2874 GLuint i;
2875 for (i = 0; i < n; i++) {
2876 dst[i][RCOMP] =
2877 dst[i][GCOMP] =
2878 dst[i][BCOMP] =
2879 dst[i][ACOMP] = s[i];
2880 }
2881 }
2882
2883 static void
2884 unpack_ubyte_R8(const void *src, GLubyte dst[][4], GLuint n)
2885 {
2886 const GLubyte *s = ((const GLubyte *) src);
2887 GLuint i;
2888 for (i = 0; i < n; i++) {
2889 dst[i][0] = s[i];
2890 dst[i][1] =
2891 dst[i][2] = 0;
2892 dst[i][3] = 0xff;
2893 }
2894 }
2895
2896 static void
2897 unpack_ubyte_GR88(const void *src, GLubyte dst[][4], GLuint n)
2898 {
2899 const GLushort *s = ((const GLushort *) src);
2900 GLuint i;
2901 for (i = 0; i < n; i++) {
2902 dst[i][RCOMP] = s[i] & 0xff;
2903 dst[i][GCOMP] = s[i] >> 8;
2904 dst[i][BCOMP] = 0;
2905 dst[i][ACOMP] = 0xff;
2906 }
2907 }
2908
2909 static void
2910 unpack_ubyte_RG88(const void *src, GLubyte dst[][4], GLuint n)
2911 {
2912 const GLushort *s = ((const GLushort *) src);
2913 GLuint i;
2914 for (i = 0; i < n; i++) {
2915 dst[i][RCOMP] = s[i] >> 8;
2916 dst[i][GCOMP] = s[i] & 0xff;
2917 dst[i][BCOMP] = 0;
2918 dst[i][ACOMP] = 0xff;
2919 }
2920 }
2921
2922
2923 /**
2924 * Unpack rgba colors, returning as GLubyte values. This should usually
2925 * only be used for unpacking formats that use 8 bits or less per channel.
2926 */
2927 void
2928 _mesa_unpack_ubyte_rgba_row(mesa_format format, GLuint n,
2929 const void *src, GLubyte dst[][4])
2930 {
2931 switch (format) {
2932 case MESA_FORMAT_A8B8G8R8_UNORM:
2933 unpack_ubyte_RGBA8888(src, dst, n);
2934 break;
2935 case MESA_FORMAT_R8G8B8A8_UNORM:
2936 unpack_ubyte_RGBA8888_REV(src, dst, n);
2937 break;
2938 case MESA_FORMAT_B8G8R8A8_UNORM:
2939 unpack_ubyte_ARGB8888(src, dst, n);
2940 break;
2941 case MESA_FORMAT_A8R8G8B8_UNORM:
2942 unpack_ubyte_ARGB8888_REV(src, dst, n);
2943 break;
2944 case MESA_FORMAT_X8B8G8R8_UNORM:
2945 unpack_ubyte_RGBX8888(src, dst, n);
2946 break;
2947 case MESA_FORMAT_R8G8B8X8_UNORM:
2948 unpack_ubyte_RGBX8888_REV(src, dst, n);
2949 break;
2950 case MESA_FORMAT_B8G8R8X8_UNORM:
2951 unpack_ubyte_XRGB8888(src, dst, n);
2952 break;
2953 case MESA_FORMAT_X8R8G8B8_UNORM:
2954 unpack_ubyte_XRGB8888_REV(src, dst, n);
2955 break;
2956 case MESA_FORMAT_BGR_UNORM8:
2957 unpack_ubyte_RGB888(src, dst, n);
2958 break;
2959 case MESA_FORMAT_RGB_UNORM8:
2960 unpack_ubyte_BGR888(src, dst, n);
2961 break;
2962 case MESA_FORMAT_B5G6R5_UNORM:
2963 unpack_ubyte_RGB565(src, dst, n);
2964 break;
2965 case MESA_FORMAT_R5G6B5_UNORM:
2966 unpack_ubyte_RGB565_REV(src, dst, n);
2967 break;
2968 case MESA_FORMAT_B4G4R4A4_UNORM:
2969 unpack_ubyte_ARGB4444(src, dst, n);
2970 break;
2971 case MESA_FORMAT_A4R4G4B4_UNORM:
2972 unpack_ubyte_ARGB4444_REV(src, dst, n);
2973 break;
2974 case MESA_FORMAT_A1B5G5R5_UNORM:
2975 unpack_ubyte_RGBA5551(src, dst, n);
2976 break;
2977 case MESA_FORMAT_B5G5R5A1_UNORM:
2978 unpack_ubyte_ARGB1555(src, dst, n);
2979 break;
2980 case MESA_FORMAT_A1R5G5B5_UNORM:
2981 unpack_ubyte_ARGB1555_REV(src, dst, n);
2982 break;
2983 case MESA_FORMAT_L4A4_UNORM:
2984 unpack_ubyte_AL44(src, dst, n);
2985 break;
2986 case MESA_FORMAT_L8A8_UNORM:
2987 unpack_ubyte_AL88(src, dst, n);
2988 break;
2989 case MESA_FORMAT_A8L8_UNORM:
2990 unpack_ubyte_AL88_REV(src, dst, n);
2991 break;
2992 case MESA_FORMAT_B2G3R3_UNORM:
2993 unpack_ubyte_RGB332(src, dst, n);
2994 break;
2995 case MESA_FORMAT_A_UNORM8:
2996 unpack_ubyte_A8(src, dst, n);
2997 break;
2998 case MESA_FORMAT_L_UNORM8:
2999 unpack_ubyte_L8(src, dst, n);
3000 break;
3001 case MESA_FORMAT_I_UNORM8:
3002 unpack_ubyte_I8(src, dst, n);
3003 break;
3004 case MESA_FORMAT_R_UNORM8:
3005 unpack_ubyte_R8(src, dst, n);
3006 break;
3007 case MESA_FORMAT_R8G8_UNORM:
3008 unpack_ubyte_GR88(src, dst, n);
3009 break;
3010 case MESA_FORMAT_G8R8_UNORM:
3011 unpack_ubyte_RG88(src, dst, n);
3012 break;
3013 default:
3014 /* get float values, convert to ubyte */
3015 {
3016 GLfloat *tmp = malloc(n * 4 * sizeof(GLfloat));
3017 if (tmp) {
3018 GLuint i;
3019 _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
3020 for (i = 0; i < n; i++) {
3021 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][0], tmp[i*4+0]);
3022 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][1], tmp[i*4+1]);
3023 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][2], tmp[i*4+2]);
3024 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][3], tmp[i*4+3]);
3025 }
3026 free(tmp);
3027 }
3028 }
3029 break;
3030 }
3031 }
3032
3033
3034 /**********************************************************************/
3035 /* Unpack, returning GLuint colors */
3036 /**********************************************************************/
3037
3038 static void
3039 unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3040 {
3041 memcpy(dst, src, n * 4 * sizeof(GLuint));
3042 }
3043
3044 static void
3045 unpack_int_rgba_RGBA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3046 {
3047 unsigned int i;
3048
3049 for (i = 0; i < n; i++) {
3050 dst[i][0] = src[i * 4 + 0];
3051 dst[i][1] = src[i * 4 + 1];
3052 dst[i][2] = src[i * 4 + 2];
3053 dst[i][3] = src[i * 4 + 3];
3054 }
3055 }
3056
3057 static void
3058 unpack_int_rgba_RGBA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3059 {
3060 unsigned int i;
3061
3062 for (i = 0; i < n; i++) {
3063 dst[i][0] = src[i * 4 + 0];
3064 dst[i][1] = src[i * 4 + 1];
3065 dst[i][2] = src[i * 4 + 2];
3066 dst[i][3] = src[i * 4 + 3];
3067 }
3068 }
3069
3070 static void
3071 unpack_int_rgba_RGBA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3072 {
3073 unsigned int i;
3074
3075 for (i = 0; i < n; i++) {
3076 dst[i][0] = src[i * 4 + 0];
3077 dst[i][1] = src[i * 4 + 1];
3078 dst[i][2] = src[i * 4 + 2];
3079 dst[i][3] = src[i * 4 + 3];
3080 }
3081 }
3082
3083 static void
3084 unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3085 {
3086 unsigned int i;
3087
3088 for (i = 0; i < n; i++) {
3089 dst[i][0] = src[i * 4 + 0];
3090 dst[i][1] = src[i * 4 + 1];
3091 dst[i][2] = src[i * 4 + 2];
3092 dst[i][3] = src[i * 4 + 3];
3093 }
3094 }
3095
3096 static void
3097 unpack_int_rgba_ARGB8888(const GLbyte *src, GLuint dst[][4], GLuint n)
3098 {
3099 unsigned int i;
3100
3101 for (i = 0; i < n; i++) {
3102 dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
3103 dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
3104 dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
3105 dst[i][ACOMP] = (GLubyte) src[i * 4 + 3];
3106 }
3107 }
3108
3109 static void
3110 unpack_int_rgba_XRGB8888(const GLbyte *src, GLuint dst[][4], GLuint n)
3111 {
3112 unsigned int i;
3113
3114 for (i = 0; i < n; i++) {
3115 dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
3116 dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
3117 dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
3118 dst[i][ACOMP] = (GLubyte) 0xff;
3119 }
3120 }
3121
3122 static void
3123 unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3124 {
3125 unsigned int i;
3126
3127 for (i = 0; i < n; i++) {
3128 dst[i][0] = src[i * 3 + 0];
3129 dst[i][1] = src[i * 3 + 1];
3130 dst[i][2] = src[i * 3 + 2];
3131 dst[i][3] = 1;
3132 }
3133 }
3134
3135 static void
3136 unpack_int_rgba_RGB_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3137 {
3138 unsigned int i;
3139
3140 for (i = 0; i < n; i++) {
3141 dst[i][0] = src[i * 3 + 0];
3142 dst[i][1] = src[i * 3 + 1];
3143 dst[i][2] = src[i * 3 + 2];
3144 dst[i][3] = 1;
3145 }
3146 }
3147
3148 static void
3149 unpack_int_rgba_RGB_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3150 {
3151 unsigned int i;
3152
3153 for (i = 0; i < n; i++) {
3154 dst[i][0] = src[i * 3 + 0];
3155 dst[i][1] = src[i * 3 + 1];
3156 dst[i][2] = src[i * 3 + 2];
3157 dst[i][3] = 1;
3158 }
3159 }
3160
3161 static void
3162 unpack_int_rgba_RGB_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3163 {
3164 unsigned int i;
3165
3166 for (i = 0; i < n; i++) {
3167 dst[i][0] = src[i * 3 + 0];
3168 dst[i][1] = src[i * 3 + 1];
3169 dst[i][2] = src[i * 3 + 2];
3170 dst[i][3] = 1;
3171 }
3172 }
3173
3174 static void
3175 unpack_int_rgba_RGB_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3176 {
3177 unsigned int i;
3178
3179 for (i = 0; i < n; i++) {
3180 dst[i][0] = src[i * 3 + 0];
3181 dst[i][1] = src[i * 3 + 1];
3182 dst[i][2] = src[i * 3 + 2];
3183 dst[i][3] = 1;
3184 }
3185 }
3186
3187 static void
3188 unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3189 {
3190 unsigned int i;
3191
3192 for (i = 0; i < n; i++) {
3193 dst[i][0] = src[i * 2 + 0];
3194 dst[i][1] = src[i * 2 + 1];
3195 dst[i][2] = 0;
3196 dst[i][3] = 1;
3197 }
3198 }
3199
3200 static void
3201 unpack_int_rgba_RG_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3202 {
3203 unsigned int i;
3204
3205 for (i = 0; i < n; i++) {
3206 dst[i][0] = src[i * 2 + 0];
3207 dst[i][1] = src[i * 2 + 1];
3208 dst[i][2] = 0;
3209 dst[i][3] = 1;
3210 }
3211 }
3212
3213 static void
3214 unpack_int_rgba_RG_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3215 {
3216 unsigned int i;
3217
3218 for (i = 0; i < n; i++) {
3219 dst[i][0] = src[i * 2 + 0];
3220 dst[i][1] = src[i * 2 + 1];
3221 dst[i][2] = 0;
3222 dst[i][3] = 1;
3223 }
3224 }
3225
3226 static void
3227 unpack_int_rgba_RG_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3228 {
3229 unsigned int i;
3230
3231 for (i = 0; i < n; i++) {
3232 dst[i][0] = src[i * 2 + 0];
3233 dst[i][1] = src[i * 2 + 1];
3234 dst[i][2] = 0;
3235 dst[i][3] = 1;
3236 }
3237 }
3238
3239 static void
3240 unpack_int_rgba_RG_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3241 {
3242 unsigned int i;
3243
3244 for (i = 0; i < n; i++) {
3245 dst[i][0] = src[i * 2 + 0];
3246 dst[i][1] = src[i * 2 + 1];
3247 dst[i][2] = 0;
3248 dst[i][3] = 1;
3249 }
3250 }
3251
3252 static void
3253 unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3254 {
3255 unsigned int i;
3256
3257 for (i = 0; i < n; i++) {
3258 dst[i][0] = src[i];
3259 dst[i][1] = 0;
3260 dst[i][2] = 0;
3261 dst[i][3] = 1;
3262 }
3263 }
3264
3265 static void
3266 unpack_int_rgba_R_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3267 {
3268 unsigned int i;
3269
3270 for (i = 0; i < n; i++) {
3271 dst[i][0] = src[i];
3272 dst[i][1] = 0;
3273 dst[i][2] = 0;
3274 dst[i][3] = 1;
3275 }
3276 }
3277
3278 static void
3279 unpack_int_rgba_R_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3280 {
3281 unsigned int i;
3282
3283 for (i = 0; i < n; i++) {
3284 dst[i][0] = src[i];
3285 dst[i][1] = 0;
3286 dst[i][2] = 0;
3287 dst[i][3] = 1;
3288 }
3289 }
3290
3291 static void
3292 unpack_int_rgba_R_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3293 {
3294 unsigned int i;
3295
3296 for (i = 0; i < n; i++) {
3297 dst[i][0] = src[i];
3298 dst[i][1] = 0;
3299 dst[i][2] = 0;
3300 dst[i][3] = 1;
3301 }
3302 }
3303
3304 static void
3305 unpack_int_rgba_R_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3306 {
3307 unsigned int i;
3308
3309 for (i = 0; i < n; i++) {
3310 dst[i][0] = src[i];
3311 dst[i][1] = 0;
3312 dst[i][2] = 0;
3313 dst[i][3] = 1;
3314 }
3315 }
3316
3317 static void
3318 unpack_int_rgba_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3319 {
3320 unsigned int i;
3321
3322 for (i = 0; i < n; i++) {
3323 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3324 dst[i][3] = src[i];
3325 }
3326 }
3327
3328 static void
3329 unpack_int_rgba_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3330 {
3331 unsigned int i;
3332
3333 for (i = 0; i < n; i++) {
3334 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3335 dst[i][3] = src[i];
3336 }
3337 }
3338
3339 static void
3340 unpack_int_rgba_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3341 {
3342 unsigned int i;
3343
3344 for (i = 0; i < n; i++) {
3345 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3346 dst[i][3] = src[i];
3347 }
3348 }
3349
3350 static void
3351 unpack_int_rgba_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3352 {
3353 unsigned int i;
3354
3355 for (i = 0; i < n; i++) {
3356 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3357 dst[i][3] = src[i];
3358 }
3359 }
3360
3361 static void
3362 unpack_int_rgba_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3363 {
3364 unsigned int i;
3365
3366 for (i = 0; i < n; i++) {
3367 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3368 dst[i][3] = src[i];
3369 }
3370 }
3371
3372 static void
3373 unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3374 {
3375 unsigned int i;
3376
3377 for (i = 0; i < n; i++) {
3378 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3379 dst[i][3] = 1;
3380 }
3381 }
3382
3383 static void
3384 unpack_int_rgba_LUMINANCE_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3385 {
3386 unsigned int i;
3387
3388 for (i = 0; i < n; i++) {
3389 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3390 dst[i][3] = 1;
3391 }
3392 }
3393
3394 static void
3395 unpack_int_rgba_LUMINANCE_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3396 {
3397 unsigned int i;
3398
3399 for (i = 0; i < n; i++) {
3400 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3401 dst[i][3] = 1;
3402 }
3403 }
3404
3405 static void
3406 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3407 {
3408 unsigned int i;
3409
3410 for (i = 0; i < n; i++) {
3411 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3412 dst[i][3] = 1;
3413 }
3414 }
3415
3416 static void
3417 unpack_int_rgba_LUMINANCE_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3418 {
3419 unsigned int i;
3420
3421 for (i = 0; i < n; i++) {
3422 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3423 dst[i][3] = 1;
3424 }
3425 }
3426
3427
3428 static void
3429 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3430 {
3431 unsigned int i;
3432
3433 for (i = 0; i < n; i++) {
3434 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3435 dst[i][3] = src[i * 2 + 1];
3436 }
3437 }
3438
3439 static void
3440 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3441 {
3442 unsigned int i;
3443
3444 for (i = 0; i < n; i++) {
3445 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3446 dst[i][3] = src[i * 2 + 1];
3447 }
3448 }
3449
3450 static void
3451 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3452 {
3453 unsigned int i;
3454
3455 for (i = 0; i < n; i++) {
3456 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3457 dst[i][3] = src[i * 2 + 1];
3458 }
3459 }
3460
3461 static void
3462 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3463 {
3464 unsigned int i;
3465
3466 for (i = 0; i < n; i++) {
3467 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3468 dst[i][3] = src[i * 2 + 1];
3469 }
3470 }
3471
3472 static void
3473 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3474 {
3475 unsigned int i;
3476
3477 for (i = 0; i < n; i++) {
3478 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3479 dst[i][3] = src[i * 2 + 1];
3480 }
3481 }
3482
3483 static void
3484 unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3485 {
3486 unsigned int i;
3487
3488 for (i = 0; i < n; i++) {
3489 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3490 }
3491 }
3492
3493 static void
3494 unpack_int_rgba_INTENSITY_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3495 {
3496 unsigned int i;
3497
3498 for (i = 0; i < n; i++) {
3499 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3500 }
3501 }
3502
3503 static void
3504 unpack_int_rgba_INTENSITY_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3505 {
3506 unsigned int i;
3507
3508 for (i = 0; i < n; i++) {
3509 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3510 }
3511 }
3512
3513 static void
3514 unpack_int_rgba_INTENSITY_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3515 {
3516 unsigned int i;
3517
3518 for (i = 0; i < n; i++) {
3519 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3520 }
3521 }
3522
3523 static void
3524 unpack_int_rgba_INTENSITY_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3525 {
3526 unsigned int i;
3527
3528 for (i = 0; i < n; i++) {
3529 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3530 }
3531 }
3532
3533 static void
3534 unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
3535 {
3536 unsigned int i;
3537
3538 for (i = 0; i < n; i++) {
3539 GLuint tmp = src[i];
3540 dst[i][0] = (tmp >> 20) & 0x3ff;
3541 dst[i][1] = (tmp >> 10) & 0x3ff;
3542 dst[i][2] = (tmp >> 0) & 0x3ff;
3543 dst[i][3] = (tmp >> 30) & 0x3;
3544 }
3545 }
3546
3547 static void
3548 unpack_int_rgba_ABGR2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
3549 {
3550 unsigned int i;
3551
3552 for (i = 0; i < n; i++) {
3553 GLuint tmp = src[i];
3554 dst[i][0] = (tmp >> 0) & 0x3ff;
3555 dst[i][1] = (tmp >> 10) & 0x3ff;
3556 dst[i][2] = (tmp >> 20) & 0x3ff;
3557 dst[i][3] = (tmp >> 30) & 0x3;
3558 }
3559 }
3560
3561 static void
3562 unpack_int_rgba_ARGB2101010(const GLuint *src, GLuint dst[][4], GLuint n)
3563 {
3564 unsigned int i;
3565
3566 for (i = 0; i < n; i++) {
3567 GLuint tmp = src[i];
3568 dst[i][0] = (tmp >> 20) & 0x3ff;
3569 dst[i][1] = (tmp >> 10) & 0x3ff;
3570 dst[i][2] = (tmp >> 0) & 0x3ff;
3571 dst[i][3] = (tmp >> 30) & 0x3;
3572 }
3573 }
3574
3575 static void
3576 unpack_int_rgba_XBGR8888_UINT(const GLubyte *src, GLuint dst[][4], GLuint n)
3577 {
3578 unsigned int i;
3579
3580 for (i = 0; i < n; i++) {
3581 dst[i][0] = src[i * 4 + 0];
3582 dst[i][1] = src[i * 4 + 1];
3583 dst[i][2] = src[i * 4 + 2];
3584 dst[i][3] = 1;
3585 }
3586 }
3587
3588 static void
3589 unpack_int_rgba_XBGR8888_SINT(const GLbyte *src, GLuint dst[][4], GLuint n)
3590 {
3591 unsigned int i;
3592
3593 for (i = 0; i < n; i++) {
3594 dst[i][0] = src[i * 4 + 0];
3595 dst[i][1] = src[i * 4 + 1];
3596 dst[i][2] = src[i * 4 + 2];
3597 dst[i][3] = 1;
3598 }
3599 }
3600
3601 static void
3602 unpack_int_rgba_XBGR16161616_UINT(const GLushort *src, GLuint dst[][4], GLuint n)
3603 {
3604 unsigned int i;
3605
3606 for (i = 0; i < n; i++) {
3607 dst[i][0] = src[i * 4 + 0];
3608 dst[i][1] = src[i * 4 + 1];
3609 dst[i][2] = src[i * 4 + 2];
3610 dst[i][3] = 1;
3611 }
3612 }
3613
3614 static void
3615 unpack_int_rgba_XBGR16161616_SINT(const GLshort *src, GLuint dst[][4], GLuint n)
3616 {
3617 unsigned int i;
3618
3619 for (i = 0; i < n; i++) {
3620 dst[i][0] = src[i * 4 + 0];
3621 dst[i][1] = src[i * 4 + 1];
3622 dst[i][2] = src[i * 4 + 2];
3623 dst[i][3] = 1;
3624 }
3625 }
3626
3627 static void
3628 unpack_int_rgba_XBGR32323232_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
3629 {
3630 unsigned int i;
3631
3632 for (i = 0; i < n; i++) {
3633 dst[i][0] = src[i * 4 + 0];
3634 dst[i][1] = src[i * 4 + 1];
3635 dst[i][2] = src[i * 4 + 2];
3636 dst[i][3] = 1;
3637 }
3638 }
3639
3640 static void
3641 unpack_int_rgba_ABGR2101010(const GLuint *src, GLuint dst[][4], GLuint n)
3642 {
3643 unsigned int i;
3644
3645 for (i = 0; i < n; i++) {
3646 GLuint tmp = src[i];
3647 dst[i][0] = (tmp >> 0) & 0x3ff;
3648 dst[i][1] = (tmp >> 10) & 0x3ff;
3649 dst[i][2] = (tmp >> 20) & 0x3ff;
3650 dst[i][3] = (tmp >> 30) & 0x3;
3651 }
3652 }
3653
3654 void
3655 _mesa_unpack_uint_rgba_row(mesa_format format, GLuint n,
3656 const void *src, GLuint dst[][4])
3657 {
3658 switch (format) {
3659 /* Since there won't be any sign extension happening, there's no need to
3660 * make separate paths for 32-bit-to-32-bit integer unpack.
3661 */
3662 case MESA_FORMAT_RGBA_UINT32:
3663 case MESA_FORMAT_RGBA_SINT32:
3664 unpack_int_rgba_RGBA_UINT32(src, dst, n);
3665 break;
3666
3667 case MESA_FORMAT_RGBA_UINT16:
3668 unpack_int_rgba_RGBA_UINT16(src, dst, n);
3669 break;
3670 case MESA_FORMAT_RGBA_SINT16:
3671 unpack_int_rgba_RGBA_INT16(src, dst, n);
3672 break;
3673
3674 case MESA_FORMAT_RGBA_UINT8:
3675 unpack_int_rgba_RGBA_UINT8(src, dst, n);
3676 break;
3677 case MESA_FORMAT_RGBA_SINT8:
3678 unpack_int_rgba_RGBA_INT8(src, dst, n);
3679 break;
3680
3681 case MESA_FORMAT_B8G8R8A8_UNORM:
3682 unpack_int_rgba_ARGB8888(src, dst, n);
3683 break;
3684
3685 case MESA_FORMAT_B8G8R8X8_UNORM:
3686 unpack_int_rgba_XRGB8888(src, dst, n);
3687 break;
3688
3689 case MESA_FORMAT_RGB_UINT32:
3690 case MESA_FORMAT_RGB_SINT32:
3691 unpack_int_rgba_RGB_UINT32(src, dst, n);
3692 break;
3693
3694 case MESA_FORMAT_RGB_UINT16:
3695 unpack_int_rgba_RGB_UINT16(src, dst, n);
3696 break;
3697 case MESA_FORMAT_RGB_SINT16:
3698 unpack_int_rgba_RGB_INT16(src, dst, n);
3699 break;
3700
3701 case MESA_FORMAT_RGB_UINT8:
3702 unpack_int_rgba_RGB_UINT8(src, dst, n);
3703 break;
3704 case MESA_FORMAT_RGB_SINT8:
3705 unpack_int_rgba_RGB_INT8(src, dst, n);
3706 break;
3707
3708 case MESA_FORMAT_RG_UINT32:
3709 case MESA_FORMAT_RG_SINT32:
3710 unpack_int_rgba_RG_UINT32(src, dst, n);
3711 break;
3712
3713 case MESA_FORMAT_RG_UINT16:
3714 unpack_int_rgba_RG_UINT16(src, dst, n);
3715 break;
3716 case MESA_FORMAT_RG_SINT16:
3717 unpack_int_rgba_RG_INT16(src, dst, n);
3718 break;
3719
3720 case MESA_FORMAT_RG_UINT8:
3721 unpack_int_rgba_RG_UINT8(src, dst, n);
3722 break;
3723 case MESA_FORMAT_RG_SINT8:
3724 unpack_int_rgba_RG_INT8(src, dst, n);
3725 break;
3726
3727 case MESA_FORMAT_R_UINT32:
3728 case MESA_FORMAT_R_SINT32:
3729 unpack_int_rgba_R_UINT32(src, dst, n);
3730 break;
3731
3732 case MESA_FORMAT_R_UINT16:
3733 unpack_int_rgba_R_UINT16(src, dst, n);
3734 break;
3735 case MESA_FORMAT_R_SINT16:
3736 unpack_int_rgba_R_INT16(src, dst, n);
3737 break;
3738
3739 case MESA_FORMAT_R_UINT8:
3740 unpack_int_rgba_R_UINT8(src, dst, n);
3741 break;
3742 case MESA_FORMAT_R_SINT8:
3743 unpack_int_rgba_R_INT8(src, dst, n);
3744 break;
3745
3746 case MESA_FORMAT_A_UINT32:
3747 case MESA_FORMAT_A_SINT32:
3748 unpack_int_rgba_ALPHA_UINT32(src, dst, n);
3749 break;
3750
3751 case MESA_FORMAT_A_UINT16:
3752 unpack_int_rgba_ALPHA_UINT16(src, dst, n);
3753 break;
3754 case MESA_FORMAT_A_SINT16:
3755 unpack_int_rgba_ALPHA_INT16(src, dst, n);
3756 break;
3757
3758 case MESA_FORMAT_A_UINT8:
3759 unpack_int_rgba_ALPHA_UINT8(src, dst, n);
3760 break;
3761 case MESA_FORMAT_A_SINT8:
3762 unpack_int_rgba_ALPHA_INT8(src, dst, n);
3763 break;
3764
3765 case MESA_FORMAT_L_UINT32:
3766 case MESA_FORMAT_L_SINT32:
3767 unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
3768 break;
3769 case MESA_FORMAT_L_UINT16:
3770 unpack_int_rgba_LUMINANCE_UINT16(src, dst, n);
3771 break;
3772 case MESA_FORMAT_L_SINT16:
3773 unpack_int_rgba_LUMINANCE_INT16(src, dst, n);
3774 break;
3775
3776 case MESA_FORMAT_L_UINT8:
3777 unpack_int_rgba_LUMINANCE_UINT8(src, dst, n);
3778 break;
3779 case MESA_FORMAT_L_SINT8:
3780 unpack_int_rgba_LUMINANCE_INT8(src, dst, n);
3781 break;
3782
3783 case MESA_FORMAT_LA_UINT32:
3784 case MESA_FORMAT_LA_SINT32:
3785 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
3786 break;
3787
3788 case MESA_FORMAT_LA_UINT16:
3789 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src, dst, n);
3790 break;
3791 case MESA_FORMAT_LA_SINT16:
3792 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src, dst, n);
3793 break;
3794
3795 case MESA_FORMAT_LA_UINT8:
3796 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src, dst, n);
3797 break;
3798 case MESA_FORMAT_LA_SINT8:
3799 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src, dst, n);
3800 break;
3801
3802 case MESA_FORMAT_I_UINT32:
3803 case MESA_FORMAT_I_SINT32:
3804 unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
3805 break;
3806
3807 case MESA_FORMAT_I_UINT16:
3808 unpack_int_rgba_INTENSITY_UINT16(src, dst, n);
3809 break;
3810 case MESA_FORMAT_I_SINT16:
3811 unpack_int_rgba_INTENSITY_INT16(src, dst, n);
3812 break;
3813
3814 case MESA_FORMAT_I_UINT8:
3815 unpack_int_rgba_INTENSITY_UINT8(src, dst, n);
3816 break;
3817 case MESA_FORMAT_I_SINT8:
3818 unpack_int_rgba_INTENSITY_INT8(src, dst, n);
3819 break;
3820
3821 case MESA_FORMAT_B10G10R10A2_UINT:
3822 unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
3823 break;
3824
3825 case MESA_FORMAT_R10G10B10A2_UINT:
3826 unpack_int_rgba_ABGR2101010_UINT(src, dst, n);
3827 break;
3828
3829 case MESA_FORMAT_B10G10R10A2_UNORM:
3830 unpack_int_rgba_ARGB2101010(src, dst, n);
3831 break;
3832
3833 case MESA_FORMAT_RGBX_UINT8:
3834 unpack_int_rgba_XBGR8888_UINT(src, dst, n);
3835 break;
3836
3837 case MESA_FORMAT_RGBX_SINT8:
3838 unpack_int_rgba_XBGR8888_SINT(src, dst, n);
3839 break;
3840
3841 case MESA_FORMAT_RGBX_UINT16:
3842 unpack_int_rgba_XBGR16161616_UINT(src, dst, n);
3843 break;
3844
3845 case MESA_FORMAT_RGBX_SINT16:
3846 unpack_int_rgba_XBGR16161616_SINT(src, dst, n);
3847 break;
3848
3849 case MESA_FORMAT_RGBX_UINT32:
3850 case MESA_FORMAT_RGBX_SINT32:
3851 unpack_int_rgba_XBGR32323232_UINT(src, dst, n);
3852 break;
3853
3854 case MESA_FORMAT_R10G10B10A2_UNORM:
3855 unpack_int_rgba_ABGR2101010(src, dst, n);
3856 break;
3857
3858 default:
3859 _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
3860 _mesa_get_format_name(format));
3861 return;
3862 }
3863 }
3864
3865 /**
3866 * Unpack a 2D rect of pixels returning float RGBA colors.
3867 * \param format the source image format
3868 * \param src start address of the source image
3869 * \param srcRowStride source image row stride in bytes
3870 * \param dst start address of the dest image
3871 * \param dstRowStride dest image row stride in bytes
3872 * \param x source image start X pos
3873 * \param y source image start Y pos
3874 * \param width width of rect region to convert
3875 * \param height height of rect region to convert
3876 */
3877 void
3878 _mesa_unpack_rgba_block(mesa_format format,
3879 const void *src, GLint srcRowStride,
3880 GLfloat dst[][4], GLint dstRowStride,
3881 GLuint x, GLuint y, GLuint width, GLuint height)
3882 {
3883 unpack_rgba_func unpack = get_unpack_rgba_function(format);
3884 const GLuint srcPixStride = _mesa_get_format_bytes(format);
3885 const GLuint dstPixStride = 4 * sizeof(GLfloat);
3886 const GLubyte *srcRow;
3887 GLubyte *dstRow;
3888 GLuint i;
3889
3890 /* XXX needs to be fixed for compressed formats */
3891
3892 srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
3893 dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
3894
3895 for (i = 0; i < height; i++) {
3896 unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
3897
3898 dstRow += dstRowStride;
3899 srcRow += srcRowStride;
3900 }
3901 }
3902
3903
3904
3905
3906 typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
3907
3908 static void
3909 unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
3910 {
3911 /* only return Z, not stencil data */
3912 const GLuint *s = ((const GLuint *) src);
3913 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
3914 GLuint i;
3915 for (i = 0; i < n; i++) {
3916 dst[i] = (GLfloat) ((s[i] >> 8) * scale);
3917 ASSERT(dst[i] >= 0.0F);
3918 ASSERT(dst[i] <= 1.0F);
3919 }
3920 }
3921
3922 static void
3923 unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
3924 {
3925 /* only return Z, not stencil data */
3926 const GLuint *s = ((const GLuint *) src);
3927 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
3928 GLuint i;
3929 for (i = 0; i < n; i++) {
3930 dst[i] = (GLfloat) ((s[i] & 0x00ffffff) * scale);
3931 ASSERT(dst[i] >= 0.0F);
3932 ASSERT(dst[i] <= 1.0F);
3933 }
3934 }
3935
3936 static void
3937 unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst)
3938 {
3939 const GLushort *s = ((const GLushort *) src);
3940 GLuint i;
3941 for (i = 0; i < n; i++) {
3942 dst[i] = s[i] * (1.0F / 65535.0F);
3943 }
3944 }
3945
3946 static void
3947 unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst)
3948 {
3949 const GLuint *s = ((const GLuint *) src);
3950 GLuint i;
3951 for (i = 0; i < n; i++) {
3952 dst[i] = s[i] * (1.0F / 0xffffffff);
3953 }
3954 }
3955
3956 static void
3957 unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst)
3958 {
3959 memcpy(dst, src, n * sizeof(float));
3960 }
3961
3962 static void
3963 unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
3964 {
3965 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
3966 GLuint i;
3967 for (i = 0; i < n; i++) {
3968 dst[i] = s[i].z;
3969 }
3970 }
3971
3972
3973
3974 /**
3975 * Unpack Z values.
3976 * The returned values will always be in the range [0.0, 1.0].
3977 */
3978 void
3979 _mesa_unpack_float_z_row(mesa_format format, GLuint n,
3980 const void *src, GLfloat *dst)
3981 {
3982 unpack_float_z_func unpack;
3983
3984 switch (format) {
3985 case MESA_FORMAT_S8_UINT_Z24_UNORM:
3986 case MESA_FORMAT_X8Z24_UNORM:
3987 unpack = unpack_float_z_Z24_X8;
3988 break;
3989 case MESA_FORMAT_Z24_UNORM_S8_UINT:
3990 case MESA_FORMAT_Z24_UNORM_X8_UINT:
3991 unpack = unpack_float_z_X8_Z24;
3992 break;
3993 case MESA_FORMAT_Z_UNORM16:
3994 unpack = unpack_float_z_Z16;
3995 break;
3996 case MESA_FORMAT_Z_UNORM32:
3997 unpack = unpack_float_z_Z32;
3998 break;
3999 case MESA_FORMAT_Z_FLOAT32:
4000 unpack = unpack_float_z_Z32F;
4001 break;
4002 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4003 unpack = unpack_float_z_Z32X24S8;
4004 break;
4005 default:
4006 _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
4007 _mesa_get_format_name(format));
4008 return;
4009 }
4010
4011 unpack(n, src, dst);
4012 }
4013
4014
4015
4016 typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
4017
4018 static void
4019 unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
4020 {
4021 /* only return Z, not stencil data */
4022 const GLuint *s = ((const GLuint *) src);
4023 GLuint i;
4024 for (i = 0; i < n; i++) {
4025 dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
4026 }
4027 }
4028
4029 static void
4030 unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
4031 {
4032 /* only return Z, not stencil data */
4033 const GLuint *s = ((const GLuint *) src);
4034 GLuint i;
4035 for (i = 0; i < n; i++) {
4036 dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
4037 }
4038 }
4039
4040 static void
4041 unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n)
4042 {
4043 const GLushort *s = ((const GLushort *)src);
4044 GLuint i;
4045 for (i = 0; i < n; i++) {
4046 dst[i] = (s[i] << 16) | s[i];
4047 }
4048 }
4049
4050 static void
4051 unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
4052 {
4053 memcpy(dst, src, n * sizeof(GLuint));
4054 }
4055
4056 static void
4057 unpack_uint_z_Z32_FLOAT(const void *src, GLuint *dst, GLuint n)
4058 {
4059 const float *s = (const float *)src;
4060 GLuint i;
4061 for (i = 0; i < n; i++) {
4062 dst[i] = FLOAT_TO_UINT(CLAMP(s[i], 0.0F, 1.0F));
4063 }
4064 }
4065
4066 static void
4067 unpack_uint_z_Z32_FLOAT_X24S8(const void *src, GLuint *dst, GLuint n)
4068 {
4069 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
4070 GLuint i;
4071
4072 for (i = 0; i < n; i++) {
4073 dst[i] = FLOAT_TO_UINT(CLAMP(s[i].z, 0.0F, 1.0F));
4074 }
4075 }
4076
4077
4078 /**
4079 * Unpack Z values.
4080 * The returned values will always be in the range [0, 0xffffffff].
4081 */
4082 void
4083 _mesa_unpack_uint_z_row(mesa_format format, GLuint n,
4084 const void *src, GLuint *dst)
4085 {
4086 unpack_uint_z_func unpack;
4087 const GLubyte *srcPtr = (GLubyte *) src;
4088
4089 switch (format) {
4090 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4091 case MESA_FORMAT_X8Z24_UNORM:
4092 unpack = unpack_uint_z_Z24_X8;
4093 break;
4094 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4095 case MESA_FORMAT_Z24_UNORM_X8_UINT:
4096 unpack = unpack_uint_z_X8_Z24;
4097 break;
4098 case MESA_FORMAT_Z_UNORM16:
4099 unpack = unpack_uint_z_Z16;
4100 break;
4101 case MESA_FORMAT_Z_UNORM32:
4102 unpack = unpack_uint_z_Z32;
4103 break;
4104 case MESA_FORMAT_Z_FLOAT32:
4105 unpack = unpack_uint_z_Z32_FLOAT;
4106 break;
4107 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4108 unpack = unpack_uint_z_Z32_FLOAT_X24S8;
4109 break;
4110 default:
4111 _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
4112 _mesa_get_format_name(format));
4113 return;
4114 }
4115
4116 unpack(srcPtr, dst, n);
4117 }
4118
4119
4120 static void
4121 unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
4122 {
4123 memcpy(dst, src, n);
4124 }
4125
4126 static void
4127 unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n)
4128 {
4129 GLuint i;
4130 const GLuint *src32 = src;
4131
4132 for (i = 0; i < n; i++)
4133 dst[i] = src32[i] & 0xff;
4134 }
4135
4136 static void
4137 unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n)
4138 {
4139 GLuint i;
4140 const GLuint *src32 = src;
4141
4142 for (i = 0; i < n; i++)
4143 dst[i] = src32[i] >> 24;
4144 }
4145
4146 static void
4147 unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n)
4148 {
4149 GLuint i;
4150 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
4151
4152 for (i = 0; i < n; i++)
4153 dst[i] = s[i].x24s8 & 0xff;
4154 }
4155
4156 void
4157 _mesa_unpack_ubyte_stencil_row(mesa_format format, GLuint n,
4158 const void *src, GLubyte *dst)
4159 {
4160 switch (format) {
4161 case MESA_FORMAT_S_UINT8:
4162 unpack_ubyte_s_S8(src, dst, n);
4163 break;
4164 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4165 unpack_ubyte_s_Z24_S8(src, dst, n);
4166 break;
4167 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4168 unpack_ubyte_s_S8_Z24(src, dst, n);
4169 break;
4170 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4171 unpack_ubyte_s_Z32_FLOAT_X24S8(src, dst, n);
4172 break;
4173 default:
4174 _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
4175 _mesa_get_format_name(format));
4176 return;
4177 }
4178 }
4179
4180 static void
4181 unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint *src, GLuint *dst, GLuint n)
4182 {
4183 GLuint i;
4184
4185 for (i = 0; i < n; i++) {
4186 GLuint val = src[i];
4187 dst[i] = val >> 24 | val << 8;
4188 }
4189 }
4190
4191 static void
4192 unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint *src, GLuint *dst, GLuint n)
4193 {
4194 memcpy(dst, src, n * 4);
4195 }
4196
4197 void
4198 _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
4199 const void *src, GLuint *dst)
4200 {
4201 switch (format) {
4202 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4203 unpack_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
4204 break;
4205 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4206 unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
4207 break;
4208 default:
4209 _mesa_problem(NULL,
4210 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
4211 _mesa_get_format_name(format));
4212 return;
4213 }
4214 }