2348ef60583cd7b0127585d69aa69be6d5822ccd
[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] >> 4) & 0xf) * (1.0F / 15.0F);
271 dst[i][GCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
272 dst[i][BCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
273 dst[i][ACOMP] = ((s[i] ) & 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_SABGR8(const void *src, GLfloat dst[][4], GLuint n)
801 {
802 const GLuint *s = ((const GLuint *) src);
803 GLuint i;
804 for (i = 0; i < n; i++) {
805 dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff );
806 dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff );
807 dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
808 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
809 }
810 }
811
812 static void
813 unpack_SL8(const void *src, GLfloat dst[][4], GLuint n)
814 {
815 const GLubyte *s = ((const GLubyte *) 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]);
821 dst[i][ACOMP] = 1.0F;
822 }
823 }
824
825 static void
826 unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n)
827 {
828 const GLushort *s = (const GLushort *) src;
829 GLuint i;
830 for (i = 0; i < n; i++) {
831 dst[i][RCOMP] =
832 dst[i][GCOMP] =
833 dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i] & 0xff);
834 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
835 }
836 }
837
838 static void
839 unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
840 {
841 }
842
843 static void
844 unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
845 {
846 }
847
848 static void
849 unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
850 {
851 }
852
853 static void
854 unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
855 {
856 }
857
858 static void
859 unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
860 {
861 }
862
863 static void
864 unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
865 {
866 }
867
868 static void
869 unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
870 {
871 }
872
873 static void
874 unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
875 {
876 }
877
878 static void
879 unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
880 {
881 }
882
883 static void
884 unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
885 {
886 }
887
888
889 static void
890 unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
891 {
892 const GLfloat *s = (const GLfloat *) src;
893 GLuint i;
894 for (i = 0; i < n; i++) {
895 dst[i][RCOMP] = s[i*4+0];
896 dst[i][GCOMP] = s[i*4+1];
897 dst[i][BCOMP] = s[i*4+2];
898 dst[i][ACOMP] = s[i*4+3];
899 }
900 }
901
902 static void
903 unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
904 {
905 const GLhalfARB *s = (const GLhalfARB *) src;
906 GLuint i;
907 for (i = 0; i < n; i++) {
908 dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
909 dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
910 dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
911 dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
912 }
913 }
914
915 static void
916 unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
917 {
918 const GLfloat *s = (const GLfloat *) src;
919 GLuint i;
920 for (i = 0; i < n; i++) {
921 dst[i][RCOMP] = s[i*3+0];
922 dst[i][GCOMP] = s[i*3+1];
923 dst[i][BCOMP] = s[i*3+2];
924 dst[i][ACOMP] = 1.0F;
925 }
926 }
927
928 static void
929 unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
930 {
931 const GLhalfARB *s = (const GLhalfARB *) src;
932 GLuint i;
933 for (i = 0; i < n; i++) {
934 dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]);
935 dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
936 dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
937 dst[i][ACOMP] = 1.0F;
938 }
939 }
940
941 static void
942 unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
943 {
944 const GLfloat *s = (const GLfloat *) 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] = s[i];
951 }
952 }
953
954 static void
955 unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
956 {
957 const GLhalfARB *s = (const GLhalfARB *) src;
958 GLuint i;
959 for (i = 0; i < n; i++) {
960 dst[i][RCOMP] =
961 dst[i][GCOMP] =
962 dst[i][BCOMP] = 0.0F;
963 dst[i][ACOMP] = _mesa_half_to_float(s[i]);
964 }
965 }
966
967 static void
968 unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
969 {
970 const GLfloat *s = (const GLfloat *) src;
971 GLuint i;
972 for (i = 0; i < n; i++) {
973 dst[i][RCOMP] =
974 dst[i][GCOMP] =
975 dst[i][BCOMP] = s[i];
976 dst[i][ACOMP] = 1.0F;
977 }
978 }
979
980 static void
981 unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
982 {
983 const GLhalfARB *s = (const GLhalfARB *) src;
984 GLuint i;
985 for (i = 0; i < n; i++) {
986 dst[i][RCOMP] =
987 dst[i][GCOMP] =
988 dst[i][BCOMP] = _mesa_half_to_float(s[i]);
989 dst[i][ACOMP] = 1.0F;
990 }
991 }
992
993 static void
994 unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
995 {
996 const GLfloat *s = (const GLfloat *) src;
997 GLuint i;
998 for (i = 0; i < n; i++) {
999 dst[i][RCOMP] =
1000 dst[i][GCOMP] =
1001 dst[i][BCOMP] = s[i*2+0];
1002 dst[i][ACOMP] = s[i*2+1];
1003 }
1004 }
1005
1006 static void
1007 unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1008 {
1009 const GLhalfARB *s = (const GLhalfARB *) src;
1010 GLuint i;
1011 for (i = 0; i < n; i++) {
1012 dst[i][RCOMP] =
1013 dst[i][GCOMP] =
1014 dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
1015 dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
1016 }
1017 }
1018
1019 static void
1020 unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1021 {
1022 const GLfloat *s = (const GLfloat *) 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] = s[i];
1029 }
1030 }
1031
1032 static void
1033 unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1034 {
1035 const GLhalfARB *s = (const GLhalfARB *) src;
1036 GLuint i;
1037 for (i = 0; i < n; i++) {
1038 dst[i][RCOMP] =
1039 dst[i][GCOMP] =
1040 dst[i][BCOMP] =
1041 dst[i][ACOMP] = _mesa_half_to_float(s[i]);
1042 }
1043 }
1044
1045 static void
1046 unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1047 {
1048 const GLfloat *s = (const GLfloat *) src;
1049 GLuint i;
1050 for (i = 0; i < n; i++) {
1051 dst[i][RCOMP] = 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_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1060 {
1061 const GLhalfARB *s = (const GLhalfARB *) src;
1062 GLuint i;
1063 for (i = 0; i < n; i++) {
1064 dst[i][RCOMP] = _mesa_half_to_float(s[i]);
1065 dst[i][GCOMP] = 0.0F;
1066 dst[i][BCOMP] = 0.0F;
1067 dst[i][ACOMP] = 1.0F;
1068 }
1069 }
1070
1071 static void
1072 unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1073 {
1074 const GLfloat *s = (const GLfloat *) src;
1075 GLuint i;
1076 for (i = 0; i < n; i++) {
1077 dst[i][RCOMP] = s[i*2+0];
1078 dst[i][GCOMP] = s[i*2+1];
1079 dst[i][BCOMP] = 0.0F;
1080 dst[i][ACOMP] = 1.0F;
1081 }
1082 }
1083
1084 static void
1085 unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1086 {
1087 const GLhalfARB *s = (const GLhalfARB *) src;
1088 GLuint i;
1089 for (i = 0; i < n; i++) {
1090 dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
1091 dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
1092 dst[i][BCOMP] = 0.0F;
1093 dst[i][ACOMP] = 1.0F;
1094 }
1095 }
1096
1097 static void
1098 unpack_ALPHA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1099 {
1100 const GLubyte *s = (const GLubyte *) 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_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1112 {
1113 const GLushort *s = (const GLushort *) 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_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1125 {
1126 const GLuint *s = (const GLuint *) 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_INT8(const void *src, GLfloat dst[][4], GLuint n)
1138 {
1139 const GLbyte *s = (const GLbyte *) 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_INT16(const void *src, GLfloat dst[][4], GLuint n)
1151 {
1152 const GLshort *s = (const GLshort *) 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_ALPHA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1164 {
1165 const GLint *s = (const GLint *) src;
1166 GLuint i;
1167 for (i = 0; i < n; i++) {
1168 dst[i][RCOMP] =
1169 dst[i][GCOMP] =
1170 dst[i][BCOMP] = 0.0;
1171 dst[i][ACOMP] = (GLfloat) s[i];
1172 }
1173 }
1174
1175 static void
1176 unpack_INTENSITY_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1177 {
1178 const GLubyte *s = (const GLubyte *) 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_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1190 {
1191 const GLushort *s = (const GLushort *) 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_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1203 {
1204 const GLuint *s = (const GLuint *) 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_INT8(const void *src, GLfloat dst[][4], GLuint n)
1216 {
1217 const GLbyte *s = (const GLbyte *) 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_INT16(const void *src, GLfloat dst[][4], GLuint n)
1229 {
1230 const GLshort *s = (const GLshort *) 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_INTENSITY_INT32(const void *src, GLfloat dst[][4], GLuint n)
1242 {
1243 const GLint *s = (const GLint *) src;
1244 GLuint i;
1245 for (i = 0; i < n; i++) {
1246 dst[i][RCOMP] =
1247 dst[i][GCOMP] =
1248 dst[i][BCOMP] =
1249 dst[i][ACOMP] = (GLfloat) s[i];
1250 }
1251 }
1252
1253 static void
1254 unpack_LUMINANCE_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1255 {
1256 const GLubyte *s = (const GLubyte *) src;
1257 GLuint i;
1258 for (i = 0; i < n; i++) {
1259 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1260 dst[i][ACOMP] = 1.0;
1261 }
1262 }
1263
1264 static void
1265 unpack_LUMINANCE_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1266 {
1267 const GLushort *s = (const GLushort *) src;
1268 GLuint i;
1269 for (i = 0; i < n; i++) {
1270 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1271 dst[i][ACOMP] = 1.0;
1272 }
1273 }
1274
1275 static void
1276 unpack_LUMINANCE_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1277 {
1278 const GLuint *s = (const GLuint *) src;
1279 GLuint i;
1280 for (i = 0; i < n; i++) {
1281 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1282 dst[i][ACOMP] = 1.0;
1283 }
1284 }
1285
1286 static void
1287 unpack_LUMINANCE_INT8(const void *src, GLfloat dst[][4], GLuint n)
1288 {
1289 const GLbyte *s = (const GLbyte *) src;
1290 GLuint i;
1291 for (i = 0; i < n; i++) {
1292 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1293 dst[i][ACOMP] = 1.0;
1294 }
1295 }
1296
1297 static void
1298 unpack_LUMINANCE_INT16(const void *src, GLfloat dst[][4], GLuint n)
1299 {
1300 const GLshort *s = (const GLshort *) src;
1301 GLuint i;
1302 for (i = 0; i < n; i++) {
1303 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1304 dst[i][ACOMP] = 1.0;
1305 }
1306 }
1307
1308 static void
1309 unpack_LUMINANCE_INT32(const void *src, GLfloat dst[][4], GLuint n)
1310 {
1311 const GLint *s = (const GLint *) src;
1312 GLuint i;
1313 for (i = 0; i < n; i++) {
1314 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1315 dst[i][ACOMP] = 1.0;
1316 }
1317 }
1318
1319 static void
1320 unpack_LUMINANCE_ALPHA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1321 {
1322 const GLubyte *s = (const GLubyte *) 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_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1334 {
1335 const GLushort *s = (const GLushort *) 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_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1347 {
1348 const GLuint *s = (const GLuint *) 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_INT8(const void *src, GLfloat dst[][4], GLuint n)
1360 {
1361 const GLbyte *s = (const GLbyte *) 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_INT16(const void *src, GLfloat dst[][4], GLuint n)
1373 {
1374 const GLshort *s = (const GLshort *) 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_LUMINANCE_ALPHA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1386 {
1387 const GLint *s = (const GLint *) src;
1388 GLuint i;
1389 for (i = 0; i < n; i++) {
1390 dst[i][RCOMP] =
1391 dst[i][GCOMP] =
1392 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1393 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1394 }
1395 }
1396
1397 static void
1398 unpack_R_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];
1404 dst[i][GCOMP] = 0.0;
1405 dst[i][BCOMP] = 0.0;
1406 dst[i][ACOMP] = 1.0;
1407 }
1408 }
1409
1410 static void
1411 unpack_RG_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*2+0];
1417 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1418 dst[i][BCOMP] = 0.0;
1419 dst[i][ACOMP] = 1.0;
1420 }
1421 }
1422
1423 static void
1424 unpack_RGB_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*3+0];
1430 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1431 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1432 dst[i][ACOMP] = 1.0;
1433 }
1434 }
1435
1436 static void
1437 unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
1438 {
1439 const GLbyte *s = (const GLbyte *) src;
1440 GLuint i;
1441 for (i = 0; i < n; i++) {
1442 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1443 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1444 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1445 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1446 }
1447 }
1448
1449 static void
1450 unpack_R_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];
1456 dst[i][GCOMP] = 0.0;
1457 dst[i][BCOMP] = 0.0;
1458 dst[i][ACOMP] = 1.0;
1459 }
1460 }
1461
1462 static void
1463 unpack_RG_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*2+0];
1469 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1470 dst[i][BCOMP] = 0.0;
1471 dst[i][ACOMP] = 1.0;
1472 }
1473 }
1474
1475 static void
1476 unpack_RGB_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*3+0];
1482 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1483 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1484 dst[i][ACOMP] = 1.0;
1485 }
1486 }
1487
1488 static void
1489 unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
1490 {
1491 const GLshort *s = (const GLshort *) src;
1492 GLuint i;
1493 for (i = 0; i < n; i++) {
1494 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1495 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1496 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1497 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1498 }
1499 }
1500
1501 static void
1502 unpack_R_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];
1508 dst[i][GCOMP] = 0.0;
1509 dst[i][BCOMP] = 0.0;
1510 dst[i][ACOMP] = 1.0;
1511 }
1512 }
1513
1514 static void
1515 unpack_RG_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*2+0];
1521 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1522 dst[i][BCOMP] = 0.0;
1523 dst[i][ACOMP] = 1.0;
1524 }
1525 }
1526
1527 static void
1528 unpack_RGB_INT32(const void *src, GLfloat dst[][4], GLuint n)
1529 {
1530 const GLint *s = (const GLint *) src;
1531 GLuint i;
1532 for (i = 0; i < n; i++) {
1533 dst[i][RCOMP] = (GLfloat) s[i*3+0];
1534 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1535 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1536 dst[i][ACOMP] = 1.0;
1537 }
1538 }
1539
1540
1541 static void
1542 unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1543 {
1544 const GLint *s = (const GLint *) src;
1545 GLuint i;
1546 for (i = 0; i < n; i++) {
1547 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1548 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1549 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1550 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1551 }
1552 }
1553
1554 static void
1555 unpack_R_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];
1561 dst[i][GCOMP] = 0.0;
1562 dst[i][BCOMP] = 0.0;
1563 dst[i][ACOMP] = 1.0;
1564 }
1565 }
1566
1567 static void
1568 unpack_RG_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*2+0];
1574 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1575 dst[i][BCOMP] = 0.0;
1576 dst[i][ACOMP] = 1.0;
1577 }
1578 }
1579
1580 static void
1581 unpack_RGB_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*3+0];
1587 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1588 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1589 dst[i][ACOMP] = 1.0;
1590 }
1591 }
1592
1593 static void
1594 unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1595 {
1596 const GLubyte *s = (const GLubyte *) src;
1597 GLuint i;
1598 for (i = 0; i < n; i++) {
1599 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1600 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1601 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1602 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1603 }
1604 }
1605
1606 static void
1607 unpack_R_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];
1613 dst[i][GCOMP] = 0.0;
1614 dst[i][BCOMP] = 0.0;
1615 dst[i][ACOMP] = 1.0;
1616 }
1617 }
1618
1619 static void
1620 unpack_RG_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*2+0];
1626 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1627 dst[i][BCOMP] = 0.0;
1628 dst[i][ACOMP] = 1.0;
1629 }
1630 }
1631
1632 static void
1633 unpack_RGB_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*3+0];
1639 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1640 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1641 dst[i][ACOMP] = 1.0;
1642 }
1643 }
1644
1645 static void
1646 unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1647 {
1648 const GLushort *s = (const GLushort *) src;
1649 GLuint i;
1650 for (i = 0; i < n; i++) {
1651 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1652 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1653 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1654 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1655 }
1656 }
1657
1658 static void
1659 unpack_R_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];
1665 dst[i][GCOMP] = 0.0;
1666 dst[i][BCOMP] = 0.0;
1667 dst[i][ACOMP] = 1.0;
1668 }
1669 }
1670
1671 static void
1672 unpack_RG_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*2+0];
1678 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1679 dst[i][BCOMP] = 0.0;
1680 dst[i][ACOMP] = 1.0;
1681 }
1682 }
1683
1684 static void
1685 unpack_RGB_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*3+0];
1691 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1692 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1693 dst[i][ACOMP] = 1.0;
1694 }
1695 }
1696
1697 static void
1698 unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1699 {
1700 const GLuint *s = (const GLuint *) src;
1701 GLuint i;
1702 for (i = 0; i < n; i++) {
1703 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1704 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1705 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1706 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1707 }
1708 }
1709
1710 static void
1711 unpack_DUDV8(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(s[i*2+0]);
1717 dst[i][GCOMP] = BYTE_TO_FLOAT(s[i*2+1]);
1718 dst[i][BCOMP] = 0;
1719 dst[i][ACOMP] = 0;
1720 }
1721 }
1722
1723 static void
1724 unpack_SIGNED_R8(const void *src, GLfloat dst[][4], GLuint n)
1725 {
1726 const GLbyte *s = ((const GLbyte *) src);
1727 GLuint i;
1728 for (i = 0; i < n; i++) {
1729 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1730 dst[i][GCOMP] = 0.0F;
1731 dst[i][BCOMP] = 0.0F;
1732 dst[i][ACOMP] = 1.0F;
1733 }
1734 }
1735
1736 static void
1737 unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
1738 {
1739 const GLushort *s = ((const GLushort *) src);
1740 GLuint i;
1741 for (i = 0; i < n; i++) {
1742 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1743 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1744 dst[i][BCOMP] = 0.0F;
1745 dst[i][ACOMP] = 1.0F;
1746 }
1747 }
1748
1749 static void
1750 unpack_SIGNED_RGBX8888(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] = 1.0f;
1759 }
1760 }
1761
1762 static void
1763 unpack_SIGNED_RGBA8888(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] >> 24) );
1769 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1770 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1771 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1772 }
1773 }
1774
1775 static void
1776 unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
1777 {
1778 const GLuint *s = ((const GLuint *) src);
1779 GLuint i;
1780 for (i = 0; i < n; i++) {
1781 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1782 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1783 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1784 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1785 }
1786 }
1787
1788 static void
1789 unpack_SIGNED_R16(const void *src, GLfloat dst[][4], GLuint n)
1790 {
1791 const GLshort *s = ((const GLshort *) src);
1792 GLuint i;
1793 for (i = 0; i < n; i++) {
1794 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1795 dst[i][GCOMP] = 0.0F;
1796 dst[i][BCOMP] = 0.0F;
1797 dst[i][ACOMP] = 1.0F;
1798 }
1799 }
1800
1801 static void
1802 unpack_SIGNED_GR1616(const void *src, GLfloat dst[][4], GLuint n)
1803 {
1804 const GLuint *s = ((const GLuint *) src);
1805 GLuint i;
1806 for (i = 0; i < n; i++) {
1807 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
1808 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
1809 dst[i][BCOMP] = 0.0F;
1810 dst[i][ACOMP] = 1.0F;
1811 }
1812 }
1813
1814 static void
1815 unpack_SIGNED_RGB_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*3+0] );
1821 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
1822 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
1823 dst[i][ACOMP] = 1.0F;
1824 }
1825 }
1826
1827 static void
1828 unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1829 {
1830 const GLshort *s = (const GLshort *) src;
1831 GLuint i;
1832 for (i = 0; i < n; i++) {
1833 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
1834 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
1835 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
1836 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
1837 }
1838 }
1839
1840 static void
1841 unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1842 {
1843 const GLushort *s = (const GLushort *) src;
1844 GLuint i;
1845 for (i = 0; i < n; i++) {
1846 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
1847 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
1848 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
1849 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
1850 }
1851 }
1852
1853 static void
1854 unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1855 {
1856 /* XXX to do */
1857 }
1858
1859 static void
1860 unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1861 {
1862 /* XXX to do */
1863 }
1864
1865 static void
1866 unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1867 {
1868 /* XXX to do */
1869 }
1870
1871 static void
1872 unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1873 {
1874 /* XXX to do */
1875 }
1876
1877 static void
1878 unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1879 {
1880 /* XXX to do */
1881 }
1882
1883 static void
1884 unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1885 {
1886 /* XXX to do */
1887 }
1888
1889 static void
1890 unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1891 {
1892 /* XXX to do */
1893 }
1894
1895 static void
1896 unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1897 {
1898 /* XXX to do */
1899 }
1900
1901 static void
1902 unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1903 {
1904 /* XXX to do */
1905 }
1906
1907 static void
1908 unpack_ETC2_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1909 {
1910 /* XXX to do */
1911 }
1912
1913 static void
1914 unpack_ETC2_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
1915 {
1916 /* XXX to do */
1917 }
1918
1919 static void
1920 unpack_ETC2_RGBA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
1921 {
1922 /* XXX to do */
1923 }
1924
1925 static void
1926 unpack_ETC2_SRGB8_ALPHA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
1927 {
1928 /* XXX to do */
1929 }
1930
1931 static void
1932 unpack_ETC2_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1933 {
1934 /* XXX to do */
1935 }
1936
1937 static void
1938 unpack_ETC2_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1939 {
1940 /* XXX to do */
1941 }
1942
1943 static void
1944 unpack_ETC2_SIGNED_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1945 {
1946 /* XXX to do */
1947 }
1948
1949 static void
1950 unpack_ETC2_SIGNED_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1951 {
1952 /* XXX to do */
1953 }
1954
1955 static void
1956 unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
1957 GLuint n)
1958 {
1959 /* XXX to do */
1960 }
1961
1962 static void
1963 unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
1964 GLuint n)
1965 {
1966 /* XXX to do */
1967 }
1968
1969 static void
1970 unpack_SIGNED_A8(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] = 0.0F;
1976 dst[i][GCOMP] = 0.0F;
1977 dst[i][BCOMP] = 0.0F;
1978 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1979 }
1980 }
1981
1982 static void
1983 unpack_SIGNED_L8(const void *src, GLfloat dst[][4], GLuint n)
1984 {
1985 const GLbyte *s = ((const GLbyte *) 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( s[i] );
1991 dst[i][ACOMP] = 1.0F;
1992 }
1993 }
1994
1995 static void
1996 unpack_SIGNED_AL88(const void *src, GLfloat dst[][4], GLuint n)
1997 {
1998 const GLshort *s = ((const GLshort *) src);
1999 GLuint i;
2000 for (i = 0; i < n; i++) {
2001 dst[i][RCOMP] =
2002 dst[i][GCOMP] =
2003 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
2004 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
2005 }
2006 }
2007
2008 static void
2009 unpack_SIGNED_I8(const void *src, GLfloat dst[][4], GLuint n)
2010 {
2011 const GLbyte *s = ((const GLbyte *) src);
2012 GLuint i;
2013 for (i = 0; i < n; i++) {
2014 dst[i][RCOMP] =
2015 dst[i][GCOMP] =
2016 dst[i][BCOMP] =
2017 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
2018 }
2019 }
2020
2021 static void
2022 unpack_SIGNED_A16(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] = 0.0F;
2028 dst[i][GCOMP] = 0.0F;
2029 dst[i][BCOMP] = 0.0F;
2030 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
2031 }
2032 }
2033
2034 static void
2035 unpack_SIGNED_L16(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] );
2043 dst[i][ACOMP] = 1.0F;
2044 }
2045 }
2046
2047 static void
2048 unpack_SIGNED_AL1616(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] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
2056 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
2057 }
2058 }
2059
2060 static void
2061 unpack_SIGNED_I16(const void *src, GLfloat dst[][4], GLuint n)
2062 {
2063 const GLshort *s = ((const GLshort *) src);
2064 GLuint i;
2065 for (i = 0; i < n; i++) {
2066 dst[i][RCOMP] =
2067 dst[i][GCOMP] =
2068 dst[i][BCOMP] =
2069 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
2070 }
2071 }
2072
2073 static void
2074 unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2075 {
2076 const GLuint *s = (const GLuint *) src;
2077 GLuint i;
2078 for (i = 0; i < n; i++) {
2079 rgb9e5_to_float3(s[i], dst[i]);
2080 dst[i][ACOMP] = 1.0F;
2081 }
2082 }
2083
2084 static void
2085 unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2086 {
2087 const GLuint *s = (const GLuint *) src;
2088 GLuint i;
2089 for (i = 0; i < n; i++) {
2090 r11g11b10f_to_float3(s[i], dst[i]);
2091 dst[i][ACOMP] = 1.0F;
2092 }
2093 }
2094
2095 static void
2096 unpack_XRGB4444_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] >> 8) & 0xf) * (1.0F / 15.0F);
2102 dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
2103 dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
2104 dst[i][ACOMP] = 1.0;
2105 }
2106 }
2107
2108 static void
2109 unpack_XRGB1555_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2110 {
2111 const GLushort *s = ((const GLushort *) src);
2112 GLuint i;
2113 for (i = 0; i < n; i++) {
2114 dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
2115 dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F);
2116 dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F);
2117 dst[i][ACOMP] = 1.0;
2118 }
2119 }
2120
2121 static void
2122 unpack_XBGR8888_SNORM(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] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
2128 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
2129 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
2130 dst[i][ACOMP] = 1.0;
2131 }
2132 }
2133
2134 static void
2135 unpack_XBGR8888_SRGB(const void *src, GLfloat dst[][4], GLuint n)
2136 {
2137 const GLuint *s = ((const GLuint *) src);
2138 GLuint i;
2139 for (i = 0; i < n; i++) {
2140 dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff );
2141 dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff );
2142 dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
2143 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
2144 }
2145 }
2146
2147 static void
2148 unpack_XBGR8888_UINT(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_XBGR8888_SINT(const void *src, GLfloat dst[][4], GLuint n)
2162 {
2163 const GLbyte *s = (const GLbyte *) src;
2164 GLuint i;
2165 for (i = 0; i < n; i++) {
2166 dst[i][RCOMP] = s[i*4+0];
2167 dst[i][GCOMP] = s[i*4+1];
2168 dst[i][BCOMP] = s[i*4+2];
2169 dst[i][ACOMP] = 1.0;
2170 }
2171 }
2172
2173 static void
2174 unpack_XRGB2101010_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2175 {
2176 const GLuint *s = ((const GLuint *) src);
2177 GLuint i;
2178 for (i = 0; i < n; i++) {
2179 dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
2180 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
2181 dst[i][BCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
2182 dst[i][ACOMP] = 1.0;
2183 }
2184 }
2185
2186 static void
2187 unpack_XBGR16161616_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2188 {
2189 const GLushort *s = (const GLushort *) src;
2190 GLuint i;
2191 for (i = 0; i < n; i++) {
2192 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
2193 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
2194 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
2195 dst[i][ACOMP] = 1.0;
2196 }
2197 }
2198
2199 static void
2200 unpack_XBGR16161616_SNORM(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] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
2206 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
2207 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
2208 dst[i][ACOMP] = 1.0;
2209 }
2210 }
2211
2212 static void
2213 unpack_XBGR16161616_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2214 {
2215 const GLshort *s = (const GLshort *) src;
2216 GLuint i;
2217 for (i = 0; i < n; i++) {
2218 dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
2219 dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
2220 dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
2221 dst[i][ACOMP] = 1.0;
2222 }
2223 }
2224
2225 static void
2226 unpack_XBGR16161616_UINT(const void *src, GLfloat dst[][4], GLuint n)
2227 {
2228 const GLushort *s = (const GLushort *) 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_XBGR16161616_SINT(const void *src, GLfloat dst[][4], GLuint n)
2240 {
2241 const GLshort *s = (const GLshort *) src;
2242 GLuint i;
2243 for (i = 0; i < n; i++) {
2244 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2245 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2246 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2247 dst[i][ACOMP] = 1.0;
2248 }
2249 }
2250
2251 static void
2252 unpack_XBGR32323232_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2253 {
2254 const GLfloat *s = (const GLfloat *) src;
2255 GLuint i;
2256 for (i = 0; i < n; i++) {
2257 dst[i][RCOMP] = s[i*4+0];
2258 dst[i][GCOMP] = s[i*4+1];
2259 dst[i][BCOMP] = s[i*4+2];
2260 dst[i][ACOMP] = 1.0;
2261 }
2262 }
2263
2264 static void
2265 unpack_XBGR32323232_UINT(const void *src, GLfloat dst[][4], GLuint n)
2266 {
2267 const GLuint *s = (const GLuint *) 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_XBGR32323232_SINT(const void *src, GLfloat dst[][4], GLuint n)
2279 {
2280 const GLint *s = (const GLint *) src;
2281 GLuint i;
2282 for (i = 0; i < n; i++) {
2283 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2284 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2285 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2286 dst[i][ACOMP] = 1.0;
2287 }
2288 }
2289
2290 static void
2291 unpack_ABGR2101010(const void *src, GLfloat dst[][4], GLuint n)
2292 {
2293 const GLuint *s = ((const GLuint *) src);
2294 GLuint i;
2295 for (i = 0; i < n; i++) {
2296 dst[i][RCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
2297 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
2298 dst[i][BCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
2299 dst[i][ACOMP] = ((s[i] >> 30) & 0x03) * (1.0F / 3.0F);
2300 }
2301 }
2302
2303 static void
2304 unpack_SIGNED_RG88(const void *src, GLfloat dst[][4], GLuint n)
2305 {
2306 const GLushort *s = ((const GLushort *) src);
2307 GLuint i;
2308 for (i = 0; i < n; i++) {
2309 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
2310 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
2311 dst[i][BCOMP] = 0.0F;
2312 dst[i][ACOMP] = 1.0F;
2313 }
2314 }
2315
2316 static void
2317 unpack_SIGNED_RG1616(const void *src, GLfloat dst[][4], GLuint n)
2318 {
2319 const GLuint *s = ((const GLuint *) src);
2320 GLuint i;
2321 for (i = 0; i < n; i++) {
2322 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
2323 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
2324 dst[i][BCOMP] = 0.0F;
2325 dst[i][ACOMP] = 1.0F;
2326 }
2327 }
2328
2329 static void
2330 unpack_XRGB8888_SRGB(const void *src, GLfloat dst[][4], GLuint n)
2331 {
2332 const GLuint *s = ((const GLuint *) src);
2333 GLuint i;
2334 for (i = 0; i < n; i++) {
2335 dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
2336 dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff );
2337 dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff );
2338 dst[i][ACOMP] = 1.0F;
2339 }
2340 }
2341
2342 /**
2343 * Return the unpacker function for the given format.
2344 */
2345 static unpack_rgba_func
2346 get_unpack_rgba_function(mesa_format format)
2347 {
2348 static unpack_rgba_func table[MESA_FORMAT_COUNT];
2349 static GLboolean initialized = GL_FALSE;
2350
2351 if (!initialized) {
2352 table[MESA_FORMAT_NONE] = NULL;
2353
2354 table[MESA_FORMAT_A8B8G8R8_UNORM] = unpack_RGBA8888;
2355 table[MESA_FORMAT_R8G8B8A8_UNORM] = unpack_RGBA8888_REV;
2356 table[MESA_FORMAT_B8G8R8A8_UNORM] = unpack_ARGB8888;
2357 table[MESA_FORMAT_A8R8G8B8_UNORM] = unpack_ARGB8888_REV;
2358 table[MESA_FORMAT_X8B8G8R8_UNORM] = unpack_RGBX8888;
2359 table[MESA_FORMAT_R8G8B8X8_UNORM] = unpack_RGBX8888_REV;
2360 table[MESA_FORMAT_B8G8R8X8_UNORM] = unpack_XRGB8888;
2361 table[MESA_FORMAT_X8R8G8B8_UNORM] = unpack_XRGB8888_REV;
2362 table[MESA_FORMAT_BGR_UNORM8] = unpack_RGB888;
2363 table[MESA_FORMAT_RGB_UNORM8] = unpack_BGR888;
2364 table[MESA_FORMAT_B5G6R5_UNORM] = unpack_RGB565;
2365 table[MESA_FORMAT_R5G6B5_UNORM] = unpack_RGB565_REV;
2366 table[MESA_FORMAT_B4G4R4A4_UNORM] = unpack_ARGB4444;
2367 table[MESA_FORMAT_A4R4G4B4_UNORM] = unpack_ARGB4444_REV;
2368 table[MESA_FORMAT_A1B5G5R5_UNORM] = unpack_RGBA5551;
2369 table[MESA_FORMAT_B5G5R5A1_UNORM] = unpack_ARGB1555;
2370 table[MESA_FORMAT_A1R5G5B5_UNORM] = unpack_ARGB1555_REV;
2371 table[MESA_FORMAT_L4A4_UNORM] = unpack_AL44;
2372 table[MESA_FORMAT_L8A8_UNORM] = unpack_AL88;
2373 table[MESA_FORMAT_A8L8_UNORM] = unpack_AL88_REV;
2374 table[MESA_FORMAT_L16A16_UNORM] = unpack_AL1616;
2375 table[MESA_FORMAT_A16L16_UNORM] = unpack_AL1616_REV;
2376 table[MESA_FORMAT_B2G3R3_UNORM] = unpack_RGB332;
2377 table[MESA_FORMAT_A_UNORM8] = unpack_A8;
2378 table[MESA_FORMAT_A_UNORM16] = unpack_A16;
2379 table[MESA_FORMAT_L_UNORM8] = unpack_L8;
2380 table[MESA_FORMAT_L_UNORM16] = unpack_L16;
2381 table[MESA_FORMAT_I_UNORM8] = unpack_I8;
2382 table[MESA_FORMAT_I_UNORM16] = unpack_I16;
2383 table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
2384 table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
2385 table[MESA_FORMAT_R_UNORM8] = unpack_R8;
2386 table[MESA_FORMAT_R8G8_UNORM] = unpack_GR88;
2387 table[MESA_FORMAT_G8R8_UNORM] = unpack_RG88;
2388 table[MESA_FORMAT_R_UNORM16] = unpack_R16;
2389 table[MESA_FORMAT_R16G16_UNORM] = unpack_GR1616;
2390 table[MESA_FORMAT_G16R16_UNORM] = unpack_RG1616;
2391 table[MESA_FORMAT_B10G10R10A2_UNORM] = unpack_ARGB2101010;
2392 table[MESA_FORMAT_B10G10R10A2_UINT] = unpack_ARGB2101010_UINT;
2393 table[MESA_FORMAT_R10G10B10A2_UINT] = unpack_ABGR2101010_UINT;
2394 table[MESA_FORMAT_S8_UINT_Z24_UNORM] = unpack_Z24_S8;
2395 table[MESA_FORMAT_Z24_UNORM_S8_UINT] = unpack_S8_Z24;
2396 table[MESA_FORMAT_Z_UNORM16] = unpack_Z16;
2397 table[MESA_FORMAT_Z24_UNORM_X8_UINT] = unpack_X8_Z24;
2398 table[MESA_FORMAT_X8Z24_UNORM] = unpack_Z24_X8;
2399 table[MESA_FORMAT_Z_UNORM32] = unpack_Z32;
2400 table[MESA_FORMAT_S_UINT8] = unpack_S8;
2401 table[MESA_FORMAT_BGR_SRGB8] = unpack_SRGB8;
2402 table[MESA_FORMAT_A8B8G8R8_SRGB] = unpack_SRGBA8;
2403 table[MESA_FORMAT_B8G8R8A8_SRGB] = unpack_SARGB8;
2404 table[MESA_FORMAT_R8G8B8A8_SRGB] = unpack_SABGR8;
2405 table[MESA_FORMAT_L_SRGB8] = unpack_SL8;
2406 table[MESA_FORMAT_L8A8_SRGB] = unpack_SLA8;
2407 table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
2408 table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
2409 table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
2410 table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
2411
2412 table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
2413 table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
2414 table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
2415 table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
2416 table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
2417 table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
2418
2419 table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
2420 table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
2421 table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
2422 table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
2423 table[MESA_FORMAT_A_FLOAT32] = unpack_ALPHA_FLOAT32;
2424 table[MESA_FORMAT_A_FLOAT16] = unpack_ALPHA_FLOAT16;
2425 table[MESA_FORMAT_L_FLOAT32] = unpack_LUMINANCE_FLOAT32;
2426 table[MESA_FORMAT_L_FLOAT16] = unpack_LUMINANCE_FLOAT16;
2427 table[MESA_FORMAT_LA_FLOAT32] = unpack_LUMINANCE_ALPHA_FLOAT32;
2428 table[MESA_FORMAT_LA_FLOAT16] = unpack_LUMINANCE_ALPHA_FLOAT16;
2429 table[MESA_FORMAT_I_FLOAT32] = unpack_INTENSITY_FLOAT32;
2430 table[MESA_FORMAT_I_FLOAT16] = unpack_INTENSITY_FLOAT16;
2431 table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
2432 table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
2433 table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
2434 table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
2435
2436 table[MESA_FORMAT_A_UINT8] = unpack_ALPHA_UINT8;
2437 table[MESA_FORMAT_A_UINT16] = unpack_ALPHA_UINT16;
2438 table[MESA_FORMAT_A_UINT32] = unpack_ALPHA_UINT32;
2439 table[MESA_FORMAT_A_SINT8] = unpack_ALPHA_INT8;
2440 table[MESA_FORMAT_A_SINT16] = unpack_ALPHA_INT16;
2441 table[MESA_FORMAT_A_SINT32] = unpack_ALPHA_INT32;
2442
2443 table[MESA_FORMAT_I_UINT8] = unpack_INTENSITY_UINT8;
2444 table[MESA_FORMAT_I_UINT16] = unpack_INTENSITY_UINT16;
2445 table[MESA_FORMAT_I_UINT32] = unpack_INTENSITY_UINT32;
2446 table[MESA_FORMAT_I_SINT8] = unpack_INTENSITY_INT8;
2447 table[MESA_FORMAT_I_SINT16] = unpack_INTENSITY_INT16;
2448 table[MESA_FORMAT_I_SINT32] = unpack_INTENSITY_INT32;
2449
2450 table[MESA_FORMAT_L_UINT8] = unpack_LUMINANCE_UINT8;
2451 table[MESA_FORMAT_L_UINT16] = unpack_LUMINANCE_UINT16;
2452 table[MESA_FORMAT_L_UINT32] = unpack_LUMINANCE_UINT32;
2453 table[MESA_FORMAT_L_SINT8] = unpack_LUMINANCE_INT8;
2454 table[MESA_FORMAT_L_SINT16] = unpack_LUMINANCE_INT16;
2455 table[MESA_FORMAT_L_SINT32] = unpack_LUMINANCE_INT32;
2456
2457 table[MESA_FORMAT_LA_UINT8] = unpack_LUMINANCE_ALPHA_UINT8;
2458 table[MESA_FORMAT_LA_UINT16] = unpack_LUMINANCE_ALPHA_UINT16;
2459 table[MESA_FORMAT_LA_UINT32] = unpack_LUMINANCE_ALPHA_UINT32;
2460 table[MESA_FORMAT_LA_SINT8] = unpack_LUMINANCE_ALPHA_INT8;
2461 table[MESA_FORMAT_LA_SINT16] = unpack_LUMINANCE_ALPHA_INT16;
2462 table[MESA_FORMAT_LA_SINT32] = unpack_LUMINANCE_ALPHA_INT32;
2463
2464 table[MESA_FORMAT_R_SINT8] = unpack_R_INT8;
2465 table[MESA_FORMAT_RG_SINT8] = unpack_RG_INT8;
2466 table[MESA_FORMAT_RGB_SINT8] = unpack_RGB_INT8;
2467 table[MESA_FORMAT_RGBA_SINT8] = unpack_RGBA_INT8;
2468 table[MESA_FORMAT_R_SINT16] = unpack_R_INT16;
2469 table[MESA_FORMAT_RG_SINT16] = unpack_RG_INT16;
2470 table[MESA_FORMAT_RGB_SINT16] = unpack_RGB_INT16;
2471 table[MESA_FORMAT_RGBA_SINT16] = unpack_RGBA_INT16;
2472 table[MESA_FORMAT_R_SINT32] = unpack_R_INT32;
2473 table[MESA_FORMAT_RG_SINT32] = unpack_RG_INT32;
2474 table[MESA_FORMAT_RGB_SINT32] = unpack_RGB_INT32;
2475 table[MESA_FORMAT_RGBA_SINT32] = unpack_RGBA_INT32;
2476 table[MESA_FORMAT_R_UINT8] = unpack_R_UINT8;
2477 table[MESA_FORMAT_RG_UINT8] = unpack_RG_UINT8;
2478 table[MESA_FORMAT_RGB_UINT8] = unpack_RGB_UINT8;
2479 table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
2480 table[MESA_FORMAT_R_UINT16] = unpack_R_UINT16;
2481 table[MESA_FORMAT_RG_UINT16] = unpack_RG_UINT16;
2482 table[MESA_FORMAT_RGB_UINT16] = unpack_RGB_UINT16;
2483 table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
2484 table[MESA_FORMAT_R_UINT32] = unpack_R_UINT32;
2485 table[MESA_FORMAT_RG_UINT32] = unpack_RG_UINT32;
2486 table[MESA_FORMAT_RGB_UINT32] = unpack_RGB_UINT32;
2487 table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
2488
2489 table[MESA_FORMAT_DUDV8] = unpack_DUDV8;
2490 table[MESA_FORMAT_R_SNORM8] = unpack_SIGNED_R8;
2491 table[MESA_FORMAT_R8G8_SNORM] = unpack_SIGNED_RG88_REV;
2492 table[MESA_FORMAT_X8B8G8R8_SNORM] = unpack_SIGNED_RGBX8888;
2493 table[MESA_FORMAT_A8B8G8R8_SNORM] = unpack_SIGNED_RGBA8888;
2494 table[MESA_FORMAT_R8G8B8A8_SNORM] = unpack_SIGNED_RGBA8888_REV;
2495 table[MESA_FORMAT_R_SNORM16] = unpack_SIGNED_R16;
2496 table[MESA_FORMAT_R16G16_SNORM] = unpack_SIGNED_GR1616;
2497 table[MESA_FORMAT_RGB_SNORM16] = unpack_SIGNED_RGB_16;
2498 table[MESA_FORMAT_RGBA_SNORM16] = unpack_SIGNED_RGBA_16;
2499 table[MESA_FORMAT_RGBA_UNORM16] = unpack_RGBA_16;
2500
2501 table[MESA_FORMAT_R_RGTC1_UNORM] = unpack_RED_RGTC1;
2502 table[MESA_FORMAT_R_RGTC1_SNORM] = unpack_SIGNED_RED_RGTC1;
2503 table[MESA_FORMAT_RG_RGTC2_UNORM] = unpack_RG_RGTC2;
2504 table[MESA_FORMAT_RG_RGTC2_SNORM] = unpack_SIGNED_RG_RGTC2;
2505
2506 table[MESA_FORMAT_L_LATC1_UNORM] = unpack_L_LATC1;
2507 table[MESA_FORMAT_L_LATC1_SNORM] = unpack_SIGNED_L_LATC1;
2508 table[MESA_FORMAT_LA_LATC2_UNORM] = unpack_LA_LATC2;
2509 table[MESA_FORMAT_LA_LATC2_SNORM] = unpack_SIGNED_LA_LATC2;
2510
2511 table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
2512 table[MESA_FORMAT_ETC2_RGB8] = unpack_ETC2_RGB8;
2513 table[MESA_FORMAT_ETC2_SRGB8] = unpack_ETC2_SRGB8;
2514 table[MESA_FORMAT_ETC2_RGBA8_EAC] = unpack_ETC2_RGBA8_EAC;
2515 table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = unpack_ETC2_SRGB8_ALPHA8_EAC;
2516 table[MESA_FORMAT_ETC2_R11_EAC] = unpack_ETC2_R11_EAC;
2517 table[MESA_FORMAT_ETC2_RG11_EAC] = unpack_ETC2_RG11_EAC;
2518 table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = unpack_ETC2_SIGNED_R11_EAC;
2519 table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = unpack_ETC2_SIGNED_RG11_EAC;
2520 table[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] =
2521 unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
2522 table[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] =
2523 unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
2524 table[MESA_FORMAT_A_SNORM8] = unpack_SIGNED_A8;
2525 table[MESA_FORMAT_L_SNORM8] = unpack_SIGNED_L8;
2526 table[MESA_FORMAT_L8A8_SNORM] = unpack_SIGNED_AL88;
2527 table[MESA_FORMAT_I_SNORM8] = unpack_SIGNED_I8;
2528 table[MESA_FORMAT_A_SNORM16] = unpack_SIGNED_A16;
2529 table[MESA_FORMAT_L_SNORM16] = unpack_SIGNED_L16;
2530 table[MESA_FORMAT_LA_SNORM16] = unpack_SIGNED_AL1616;
2531 table[MESA_FORMAT_I_SNORM16] = unpack_SIGNED_I16;
2532
2533 table[MESA_FORMAT_R9G9B9E5_FLOAT] = unpack_RGB9_E5_FLOAT;
2534 table[MESA_FORMAT_R11G11B10_FLOAT] = unpack_R11_G11_B10_FLOAT;
2535
2536 table[MESA_FORMAT_Z_FLOAT32] = unpack_Z32_FLOAT;
2537 table[MESA_FORMAT_Z32_FLOAT_S8X24_UINT] = unpack_Z32_FLOAT_X24S8;
2538
2539 table[MESA_FORMAT_B4G4R4X4_UNORM] = unpack_XRGB4444_UNORM;
2540 table[MESA_FORMAT_B5G5R5X1_UNORM] = unpack_XRGB1555_UNORM;
2541 table[MESA_FORMAT_R8G8B8X8_SNORM] = unpack_XBGR8888_SNORM;
2542 table[MESA_FORMAT_R8G8B8X8_SRGB] = unpack_XBGR8888_SRGB;
2543 table[MESA_FORMAT_RGBX_UINT8] = unpack_XBGR8888_UINT;
2544 table[MESA_FORMAT_RGBX_SINT8] = unpack_XBGR8888_SINT;
2545 table[MESA_FORMAT_B10G10R10X2_UNORM] = unpack_XRGB2101010_UNORM;
2546 table[MESA_FORMAT_RGBX_UNORM16] = unpack_XBGR16161616_UNORM;
2547 table[MESA_FORMAT_RGBX_SNORM16] = unpack_XBGR16161616_SNORM;
2548 table[MESA_FORMAT_RGBX_FLOAT16] = unpack_XBGR16161616_FLOAT;
2549 table[MESA_FORMAT_RGBX_UINT16] = unpack_XBGR16161616_UINT;
2550 table[MESA_FORMAT_RGBX_SINT16] = unpack_XBGR16161616_SINT;
2551 table[MESA_FORMAT_RGBX_FLOAT32] = unpack_XBGR32323232_FLOAT;
2552 table[MESA_FORMAT_RGBX_UINT32] = unpack_XBGR32323232_UINT;
2553 table[MESA_FORMAT_RGBX_SINT32] = unpack_XBGR32323232_SINT;
2554
2555 table[MESA_FORMAT_R10G10B10A2_UNORM] = unpack_ABGR2101010;
2556
2557 table[MESA_FORMAT_G8R8_SNORM] = unpack_SIGNED_RG88;
2558 table[MESA_FORMAT_G16R16_SNORM] = unpack_SIGNED_RG1616;
2559
2560 table[MESA_FORMAT_B8G8R8X8_SRGB] = unpack_XRGB8888_SRGB;
2561
2562 initialized = GL_TRUE;
2563 }
2564
2565 if (table[format] == NULL) {
2566 _mesa_problem(NULL, "unsupported unpack for format %s",
2567 _mesa_get_format_name(format));
2568 }
2569
2570 return table[format];
2571 }
2572
2573
2574 /**
2575 * Unpack rgba colors, returning as GLfloat values.
2576 */
2577 void
2578 _mesa_unpack_rgba_row(mesa_format format, GLuint n,
2579 const void *src, GLfloat dst[][4])
2580 {
2581 unpack_rgba_func unpack = get_unpack_rgba_function(format);
2582 unpack(src, dst, n);
2583 }
2584
2585
2586 /**********************************************************************/
2587 /* Unpack, returning GLubyte colors */
2588 /**********************************************************************/
2589
2590
2591 static void
2592 unpack_ubyte_RGBA8888(const void *src, GLubyte dst[][4], GLuint n)
2593 {
2594 const GLuint *s = ((const GLuint *) src);
2595 GLuint i;
2596 for (i = 0; i < n; i++) {
2597 dst[i][RCOMP] = (s[i] >> 24);
2598 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2599 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
2600 dst[i][ACOMP] = (s[i] ) & 0xff;
2601 }
2602 }
2603
2604 static void
2605 unpack_ubyte_RGBA8888_REV(const void *src, GLubyte dst[][4], GLuint n)
2606 {
2607 const GLuint *s = ((const GLuint *) src);
2608 GLuint i;
2609 for (i = 0; i < n; i++) {
2610 dst[i][RCOMP] = (s[i] ) & 0xff;
2611 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2612 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
2613 dst[i][ACOMP] = (s[i] >> 24);
2614 }
2615 }
2616
2617 static void
2618 unpack_ubyte_ARGB8888(const void *src, GLubyte dst[][4], GLuint n)
2619 {
2620 const GLuint *s = ((const GLuint *) src);
2621 GLuint i;
2622 for (i = 0; i < n; i++) {
2623 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
2624 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2625 dst[i][BCOMP] = (s[i] ) & 0xff;
2626 dst[i][ACOMP] = (s[i] >> 24);
2627 }
2628 }
2629
2630 static void
2631 unpack_ubyte_ARGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
2632 {
2633 const GLuint *s = ((const GLuint *) src);
2634 GLuint i;
2635 for (i = 0; i < n; i++) {
2636 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
2637 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2638 dst[i][BCOMP] = (s[i] >> 24);
2639 dst[i][ACOMP] = (s[i] ) & 0xff;
2640 }
2641 }
2642
2643 static void
2644 unpack_ubyte_RGBX8888(const void *src, GLubyte dst[][4], GLuint n)
2645 {
2646 const GLuint *s = ((const GLuint *) src);
2647 GLuint i;
2648 for (i = 0; i < n; i++) {
2649 dst[i][RCOMP] = (s[i] >> 24);
2650 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2651 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
2652 dst[i][ACOMP] = 0xff;
2653 }
2654 }
2655
2656 static void
2657 unpack_ubyte_RGBX8888_REV(const void *src, GLubyte dst[][4], GLuint n)
2658 {
2659 const GLuint *s = ((const GLuint *) src);
2660 GLuint i;
2661 for (i = 0; i < n; i++) {
2662 dst[i][RCOMP] = (s[i] ) & 0xff;
2663 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2664 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
2665 dst[i][ACOMP] = 0xff;
2666 }
2667 }
2668
2669 static void
2670 unpack_ubyte_XRGB8888(const void *src, GLubyte dst[][4], GLuint n)
2671 {
2672 const GLuint *s = ((const GLuint *) src);
2673 GLuint i;
2674 for (i = 0; i < n; i++) {
2675 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
2676 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2677 dst[i][BCOMP] = (s[i] ) & 0xff;
2678 dst[i][ACOMP] = 0xff;
2679 }
2680 }
2681
2682 static void
2683 unpack_ubyte_XRGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
2684 {
2685 const GLuint *s = ((const GLuint *) src);
2686 GLuint i;
2687 for (i = 0; i < n; i++) {
2688 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
2689 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2690 dst[i][BCOMP] = (s[i] >> 24);
2691 dst[i][ACOMP] = 0xff;
2692 }
2693 }
2694
2695 static void
2696 unpack_ubyte_RGB888(const void *src, GLubyte dst[][4], GLuint n)
2697 {
2698 const GLubyte *s = (const GLubyte *) src;
2699 GLuint i;
2700 for (i = 0; i < n; i++) {
2701 dst[i][RCOMP] = s[i*3+2];
2702 dst[i][GCOMP] = s[i*3+1];
2703 dst[i][BCOMP] = s[i*3+0];
2704 dst[i][ACOMP] = 0xff;
2705 }
2706 }
2707
2708 static void
2709 unpack_ubyte_BGR888(const void *src, GLubyte dst[][4], GLuint n)
2710 {
2711 const GLubyte *s = (const GLubyte *) src;
2712 GLuint i;
2713 for (i = 0; i < n; i++) {
2714 dst[i][RCOMP] = s[i*3+0];
2715 dst[i][GCOMP] = s[i*3+1];
2716 dst[i][BCOMP] = s[i*3+2];
2717 dst[i][ACOMP] = 0xff;
2718 }
2719 }
2720
2721 static void
2722 unpack_ubyte_RGB565(const void *src, GLubyte dst[][4], GLuint n)
2723 {
2724 const GLushort *s = ((const GLushort *) src);
2725 GLuint i;
2726 for (i = 0; i < n; i++) {
2727 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
2728 dst[i][GCOMP] = EXPAND_6_8((s[i] >> 5 ) & 0x3f);
2729 dst[i][BCOMP] = EXPAND_5_8( s[i] & 0x1f);
2730 dst[i][ACOMP] = 0xff;
2731 }
2732 }
2733
2734 static void
2735 unpack_ubyte_RGB565_REV(const void *src, GLubyte dst[][4], GLuint n)
2736 {
2737 /* Warning: this function does not match the current Mesa definition
2738 * of MESA_FORMAT_R5G6B5_UNORM.
2739 */
2740 const GLushort *s = ((const GLushort *) src);
2741 GLuint i;
2742 for (i = 0; i < n; i++) {
2743 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
2744 dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);
2745 dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);
2746 dst[i][BCOMP] = EXPAND_5_8( t & 0x1f);
2747 dst[i][ACOMP] = 0xff;
2748 }
2749 }
2750
2751 static void
2752 unpack_ubyte_ARGB4444(const void *src, GLubyte dst[][4], GLuint n)
2753 {
2754 const GLushort *s = ((const GLushort *) src);
2755 GLuint i;
2756 for (i = 0; i < n; i++) {
2757 dst[i][RCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
2758 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
2759 dst[i][BCOMP] = EXPAND_4_8((s[i] ) & 0xf);
2760 dst[i][ACOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
2761 }
2762 }
2763
2764 static void
2765 unpack_ubyte_ARGB4444_REV(const void *src, GLubyte dst[][4], GLuint n)
2766 {
2767 const GLushort *s = ((const GLushort *) src);
2768 GLuint i;
2769 for (i = 0; i < n; i++) {
2770 dst[i][RCOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
2771 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
2772 dst[i][BCOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
2773 dst[i][ACOMP] = EXPAND_4_8((s[i] ) & 0xf);
2774 }
2775 }
2776
2777 static void
2778 unpack_ubyte_RGBA5551(const void *src, GLubyte dst[][4], GLuint n)
2779 {
2780 const GLushort *s = ((const GLushort *) src);
2781 GLuint i;
2782 for (i = 0; i < n; i++) {
2783 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
2784 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 6) & 0x1f);
2785 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 1) & 0x1f);
2786 dst[i][ACOMP] = EXPAND_1_8((s[i] ) & 0x01);
2787 }
2788 }
2789
2790 static void
2791 unpack_ubyte_ARGB1555(const void *src, GLubyte dst[][4], GLuint n)
2792 {
2793 const GLushort *s = ((const GLushort *) src);
2794 GLuint i;
2795 for (i = 0; i < n; i++) {
2796 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 10) & 0x1f);
2797 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 5) & 0x1f);
2798 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 0) & 0x1f);
2799 dst[i][ACOMP] = EXPAND_1_8((s[i] >> 15) & 0x01);
2800 }
2801 }
2802
2803 static void
2804 unpack_ubyte_ARGB1555_REV(const void *src, GLubyte dst[][4], GLuint n)
2805 {
2806 /* Warning: this function does not match the current Mesa definition
2807 * of MESA_FORMAT_A1R5G5B5_UNORM.
2808 */
2809 const GLushort *s = ((const GLushort *) src);
2810 GLuint i;
2811 for (i = 0; i < n; i++) {
2812 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
2813 dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
2814 dst[i][GCOMP] = EXPAND_5_8((tmp >> 5) & 0x1f);
2815 dst[i][BCOMP] = EXPAND_5_8((tmp >> 0) & 0x1f);
2816 dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
2817 }
2818 }
2819
2820 static void
2821 unpack_ubyte_AL44(const void *src, GLubyte dst[][4], GLuint n)
2822 {
2823 const GLubyte *s = ((const GLubyte *) src);
2824 GLuint i;
2825 for (i = 0; i < n; i++) {
2826 dst[i][RCOMP] =
2827 dst[i][GCOMP] =
2828 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xf);
2829 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 4);
2830 }
2831 }
2832
2833 static void
2834 unpack_ubyte_AL88(const void *src, GLubyte dst[][4], GLuint n)
2835 {
2836 const GLushort *s = ((const GLushort *) src);
2837 GLuint i;
2838 for (i = 0; i < n; i++) {
2839 dst[i][RCOMP] =
2840 dst[i][GCOMP] =
2841 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xff);
2842 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 8);
2843 }
2844 }
2845
2846 static void
2847 unpack_ubyte_AL88_REV(const void *src, GLubyte dst[][4], GLuint n)
2848 {
2849 const GLushort *s = ((const GLushort *) src);
2850 GLuint i;
2851 for (i = 0; i < n; i++) {
2852 dst[i][RCOMP] =
2853 dst[i][GCOMP] =
2854 dst[i][BCOMP] = EXPAND_4_8(s[i] >> 8);
2855 dst[i][ACOMP] = EXPAND_4_8(s[i] & 0xff);
2856 }
2857 }
2858
2859 static void
2860 unpack_ubyte_RGB332(const void *src, GLubyte dst[][4], GLuint n)
2861 {
2862 const GLubyte *s = ((const GLubyte *) src);
2863 GLuint i;
2864 for (i = 0; i < n; i++) {
2865 dst[i][RCOMP] = EXPAND_3_8((s[i] >> 5) & 0x7);
2866 dst[i][GCOMP] = EXPAND_3_8((s[i] >> 2) & 0x7);
2867 dst[i][BCOMP] = EXPAND_2_8((s[i] ) & 0x3);
2868 dst[i][ACOMP] = 0xff;
2869 }
2870 }
2871
2872 static void
2873 unpack_ubyte_A8(const void *src, GLubyte dst[][4], GLuint n)
2874 {
2875 const GLubyte *s = ((const GLubyte *) src);
2876 GLuint i;
2877 for (i = 0; i < n; i++) {
2878 dst[i][RCOMP] =
2879 dst[i][GCOMP] =
2880 dst[i][BCOMP] = 0;
2881 dst[i][ACOMP] = s[i];
2882 }
2883 }
2884
2885 static void
2886 unpack_ubyte_L8(const void *src, GLubyte dst[][4], GLuint n)
2887 {
2888 const GLubyte *s = ((const GLubyte *) src);
2889 GLuint i;
2890 for (i = 0; i < n; i++) {
2891 dst[i][RCOMP] =
2892 dst[i][GCOMP] =
2893 dst[i][BCOMP] = s[i];
2894 dst[i][ACOMP] = 0xff;
2895 }
2896 }
2897
2898
2899 static void
2900 unpack_ubyte_I8(const void *src, GLubyte dst[][4], GLuint n)
2901 {
2902 const GLubyte *s = ((const GLubyte *) src);
2903 GLuint i;
2904 for (i = 0; i < n; i++) {
2905 dst[i][RCOMP] =
2906 dst[i][GCOMP] =
2907 dst[i][BCOMP] =
2908 dst[i][ACOMP] = s[i];
2909 }
2910 }
2911
2912 static void
2913 unpack_ubyte_R8(const void *src, GLubyte dst[][4], GLuint n)
2914 {
2915 const GLubyte *s = ((const GLubyte *) src);
2916 GLuint i;
2917 for (i = 0; i < n; i++) {
2918 dst[i][0] = s[i];
2919 dst[i][1] =
2920 dst[i][2] = 0;
2921 dst[i][3] = 0xff;
2922 }
2923 }
2924
2925 static void
2926 unpack_ubyte_GR88(const void *src, GLubyte dst[][4], GLuint n)
2927 {
2928 const GLushort *s = ((const GLushort *) src);
2929 GLuint i;
2930 for (i = 0; i < n; i++) {
2931 dst[i][RCOMP] = s[i] & 0xff;
2932 dst[i][GCOMP] = s[i] >> 8;
2933 dst[i][BCOMP] = 0;
2934 dst[i][ACOMP] = 0xff;
2935 }
2936 }
2937
2938 static void
2939 unpack_ubyte_RG88(const void *src, GLubyte dst[][4], GLuint n)
2940 {
2941 const GLushort *s = ((const GLushort *) src);
2942 GLuint i;
2943 for (i = 0; i < n; i++) {
2944 dst[i][RCOMP] = s[i] >> 8;
2945 dst[i][GCOMP] = s[i] & 0xff;
2946 dst[i][BCOMP] = 0;
2947 dst[i][ACOMP] = 0xff;
2948 }
2949 }
2950
2951
2952 /**
2953 * Unpack rgba colors, returning as GLubyte values. This should usually
2954 * only be used for unpacking formats that use 8 bits or less per channel.
2955 */
2956 void
2957 _mesa_unpack_ubyte_rgba_row(mesa_format format, GLuint n,
2958 const void *src, GLubyte dst[][4])
2959 {
2960 switch (format) {
2961 case MESA_FORMAT_A8B8G8R8_UNORM:
2962 unpack_ubyte_RGBA8888(src, dst, n);
2963 break;
2964 case MESA_FORMAT_R8G8B8A8_UNORM:
2965 unpack_ubyte_RGBA8888_REV(src, dst, n);
2966 break;
2967 case MESA_FORMAT_B8G8R8A8_UNORM:
2968 unpack_ubyte_ARGB8888(src, dst, n);
2969 break;
2970 case MESA_FORMAT_A8R8G8B8_UNORM:
2971 unpack_ubyte_ARGB8888_REV(src, dst, n);
2972 break;
2973 case MESA_FORMAT_X8B8G8R8_UNORM:
2974 unpack_ubyte_RGBX8888(src, dst, n);
2975 break;
2976 case MESA_FORMAT_R8G8B8X8_UNORM:
2977 unpack_ubyte_RGBX8888_REV(src, dst, n);
2978 break;
2979 case MESA_FORMAT_B8G8R8X8_UNORM:
2980 unpack_ubyte_XRGB8888(src, dst, n);
2981 break;
2982 case MESA_FORMAT_X8R8G8B8_UNORM:
2983 unpack_ubyte_XRGB8888_REV(src, dst, n);
2984 break;
2985 case MESA_FORMAT_BGR_UNORM8:
2986 unpack_ubyte_RGB888(src, dst, n);
2987 break;
2988 case MESA_FORMAT_RGB_UNORM8:
2989 unpack_ubyte_BGR888(src, dst, n);
2990 break;
2991 case MESA_FORMAT_B5G6R5_UNORM:
2992 unpack_ubyte_RGB565(src, dst, n);
2993 break;
2994 case MESA_FORMAT_R5G6B5_UNORM:
2995 unpack_ubyte_RGB565_REV(src, dst, n);
2996 break;
2997 case MESA_FORMAT_B4G4R4A4_UNORM:
2998 unpack_ubyte_ARGB4444(src, dst, n);
2999 break;
3000 case MESA_FORMAT_A4R4G4B4_UNORM:
3001 unpack_ubyte_ARGB4444_REV(src, dst, n);
3002 break;
3003 case MESA_FORMAT_A1B5G5R5_UNORM:
3004 unpack_ubyte_RGBA5551(src, dst, n);
3005 break;
3006 case MESA_FORMAT_B5G5R5A1_UNORM:
3007 unpack_ubyte_ARGB1555(src, dst, n);
3008 break;
3009 case MESA_FORMAT_A1R5G5B5_UNORM:
3010 unpack_ubyte_ARGB1555_REV(src, dst, n);
3011 break;
3012 case MESA_FORMAT_L4A4_UNORM:
3013 unpack_ubyte_AL44(src, dst, n);
3014 break;
3015 case MESA_FORMAT_L8A8_UNORM:
3016 unpack_ubyte_AL88(src, dst, n);
3017 break;
3018 case MESA_FORMAT_A8L8_UNORM:
3019 unpack_ubyte_AL88_REV(src, dst, n);
3020 break;
3021 case MESA_FORMAT_B2G3R3_UNORM:
3022 unpack_ubyte_RGB332(src, dst, n);
3023 break;
3024 case MESA_FORMAT_A_UNORM8:
3025 unpack_ubyte_A8(src, dst, n);
3026 break;
3027 case MESA_FORMAT_L_UNORM8:
3028 unpack_ubyte_L8(src, dst, n);
3029 break;
3030 case MESA_FORMAT_I_UNORM8:
3031 unpack_ubyte_I8(src, dst, n);
3032 break;
3033 case MESA_FORMAT_R_UNORM8:
3034 unpack_ubyte_R8(src, dst, n);
3035 break;
3036 case MESA_FORMAT_R8G8_UNORM:
3037 unpack_ubyte_GR88(src, dst, n);
3038 break;
3039 case MESA_FORMAT_G8R8_UNORM:
3040 unpack_ubyte_RG88(src, dst, n);
3041 break;
3042 default:
3043 /* get float values, convert to ubyte */
3044 {
3045 GLfloat *tmp = malloc(n * 4 * sizeof(GLfloat));
3046 if (tmp) {
3047 GLuint i;
3048 _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
3049 for (i = 0; i < n; i++) {
3050 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][0], tmp[i*4+0]);
3051 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][1], tmp[i*4+1]);
3052 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][2], tmp[i*4+2]);
3053 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][3], tmp[i*4+3]);
3054 }
3055 free(tmp);
3056 }
3057 }
3058 break;
3059 }
3060 }
3061
3062
3063 /**********************************************************************/
3064 /* Unpack, returning GLuint colors */
3065 /**********************************************************************/
3066
3067 static void
3068 unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3069 {
3070 memcpy(dst, src, n * 4 * sizeof(GLuint));
3071 }
3072
3073 static void
3074 unpack_int_rgba_RGBA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3075 {
3076 unsigned int i;
3077
3078 for (i = 0; i < n; i++) {
3079 dst[i][0] = src[i * 4 + 0];
3080 dst[i][1] = src[i * 4 + 1];
3081 dst[i][2] = src[i * 4 + 2];
3082 dst[i][3] = src[i * 4 + 3];
3083 }
3084 }
3085
3086 static void
3087 unpack_int_rgba_RGBA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3088 {
3089 unsigned int i;
3090
3091 for (i = 0; i < n; i++) {
3092 dst[i][0] = src[i * 4 + 0];
3093 dst[i][1] = src[i * 4 + 1];
3094 dst[i][2] = src[i * 4 + 2];
3095 dst[i][3] = src[i * 4 + 3];
3096 }
3097 }
3098
3099 static void
3100 unpack_int_rgba_RGBA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3101 {
3102 unsigned int i;
3103
3104 for (i = 0; i < n; i++) {
3105 dst[i][0] = src[i * 4 + 0];
3106 dst[i][1] = src[i * 4 + 1];
3107 dst[i][2] = src[i * 4 + 2];
3108 dst[i][3] = src[i * 4 + 3];
3109 }
3110 }
3111
3112 static void
3113 unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3114 {
3115 unsigned int i;
3116
3117 for (i = 0; i < n; i++) {
3118 dst[i][0] = src[i * 4 + 0];
3119 dst[i][1] = src[i * 4 + 1];
3120 dst[i][2] = src[i * 4 + 2];
3121 dst[i][3] = src[i * 4 + 3];
3122 }
3123 }
3124
3125 static void
3126 unpack_int_rgba_ARGB8888(const GLbyte *src, GLuint dst[][4], GLuint n)
3127 {
3128 unsigned int i;
3129
3130 for (i = 0; i < n; i++) {
3131 dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
3132 dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
3133 dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
3134 dst[i][ACOMP] = (GLubyte) src[i * 4 + 3];
3135 }
3136 }
3137
3138 static void
3139 unpack_int_rgba_XRGB8888(const GLbyte *src, GLuint dst[][4], GLuint n)
3140 {
3141 unsigned int i;
3142
3143 for (i = 0; i < n; i++) {
3144 dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
3145 dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
3146 dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
3147 dst[i][ACOMP] = (GLubyte) 0xff;
3148 }
3149 }
3150
3151 static void
3152 unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3153 {
3154 unsigned int i;
3155
3156 for (i = 0; i < n; i++) {
3157 dst[i][0] = src[i * 3 + 0];
3158 dst[i][1] = src[i * 3 + 1];
3159 dst[i][2] = src[i * 3 + 2];
3160 dst[i][3] = 1;
3161 }
3162 }
3163
3164 static void
3165 unpack_int_rgba_RGB_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3166 {
3167 unsigned int i;
3168
3169 for (i = 0; i < n; i++) {
3170 dst[i][0] = src[i * 3 + 0];
3171 dst[i][1] = src[i * 3 + 1];
3172 dst[i][2] = src[i * 3 + 2];
3173 dst[i][3] = 1;
3174 }
3175 }
3176
3177 static void
3178 unpack_int_rgba_RGB_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3179 {
3180 unsigned int i;
3181
3182 for (i = 0; i < n; i++) {
3183 dst[i][0] = src[i * 3 + 0];
3184 dst[i][1] = src[i * 3 + 1];
3185 dst[i][2] = src[i * 3 + 2];
3186 dst[i][3] = 1;
3187 }
3188 }
3189
3190 static void
3191 unpack_int_rgba_RGB_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3192 {
3193 unsigned int i;
3194
3195 for (i = 0; i < n; i++) {
3196 dst[i][0] = src[i * 3 + 0];
3197 dst[i][1] = src[i * 3 + 1];
3198 dst[i][2] = src[i * 3 + 2];
3199 dst[i][3] = 1;
3200 }
3201 }
3202
3203 static void
3204 unpack_int_rgba_RGB_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3205 {
3206 unsigned int i;
3207
3208 for (i = 0; i < n; i++) {
3209 dst[i][0] = src[i * 3 + 0];
3210 dst[i][1] = src[i * 3 + 1];
3211 dst[i][2] = src[i * 3 + 2];
3212 dst[i][3] = 1;
3213 }
3214 }
3215
3216 static void
3217 unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3218 {
3219 unsigned int i;
3220
3221 for (i = 0; i < n; i++) {
3222 dst[i][0] = src[i * 2 + 0];
3223 dst[i][1] = src[i * 2 + 1];
3224 dst[i][2] = 0;
3225 dst[i][3] = 1;
3226 }
3227 }
3228
3229 static void
3230 unpack_int_rgba_RG_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3231 {
3232 unsigned int i;
3233
3234 for (i = 0; i < n; i++) {
3235 dst[i][0] = src[i * 2 + 0];
3236 dst[i][1] = src[i * 2 + 1];
3237 dst[i][2] = 0;
3238 dst[i][3] = 1;
3239 }
3240 }
3241
3242 static void
3243 unpack_int_rgba_RG_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3244 {
3245 unsigned int i;
3246
3247 for (i = 0; i < n; i++) {
3248 dst[i][0] = src[i * 2 + 0];
3249 dst[i][1] = src[i * 2 + 1];
3250 dst[i][2] = 0;
3251 dst[i][3] = 1;
3252 }
3253 }
3254
3255 static void
3256 unpack_int_rgba_RG_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3257 {
3258 unsigned int i;
3259
3260 for (i = 0; i < n; i++) {
3261 dst[i][0] = src[i * 2 + 0];
3262 dst[i][1] = src[i * 2 + 1];
3263 dst[i][2] = 0;
3264 dst[i][3] = 1;
3265 }
3266 }
3267
3268 static void
3269 unpack_int_rgba_RG_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3270 {
3271 unsigned int i;
3272
3273 for (i = 0; i < n; i++) {
3274 dst[i][0] = src[i * 2 + 0];
3275 dst[i][1] = src[i * 2 + 1];
3276 dst[i][2] = 0;
3277 dst[i][3] = 1;
3278 }
3279 }
3280
3281 static void
3282 unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3283 {
3284 unsigned int i;
3285
3286 for (i = 0; i < n; i++) {
3287 dst[i][0] = src[i];
3288 dst[i][1] = 0;
3289 dst[i][2] = 0;
3290 dst[i][3] = 1;
3291 }
3292 }
3293
3294 static void
3295 unpack_int_rgba_R_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3296 {
3297 unsigned int i;
3298
3299 for (i = 0; i < n; i++) {
3300 dst[i][0] = src[i];
3301 dst[i][1] = 0;
3302 dst[i][2] = 0;
3303 dst[i][3] = 1;
3304 }
3305 }
3306
3307 static void
3308 unpack_int_rgba_R_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3309 {
3310 unsigned int i;
3311
3312 for (i = 0; i < n; i++) {
3313 dst[i][0] = src[i];
3314 dst[i][1] = 0;
3315 dst[i][2] = 0;
3316 dst[i][3] = 1;
3317 }
3318 }
3319
3320 static void
3321 unpack_int_rgba_R_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3322 {
3323 unsigned int i;
3324
3325 for (i = 0; i < n; i++) {
3326 dst[i][0] = src[i];
3327 dst[i][1] = 0;
3328 dst[i][2] = 0;
3329 dst[i][3] = 1;
3330 }
3331 }
3332
3333 static void
3334 unpack_int_rgba_R_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3335 {
3336 unsigned int i;
3337
3338 for (i = 0; i < n; i++) {
3339 dst[i][0] = src[i];
3340 dst[i][1] = 0;
3341 dst[i][2] = 0;
3342 dst[i][3] = 1;
3343 }
3344 }
3345
3346 static void
3347 unpack_int_rgba_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3348 {
3349 unsigned int i;
3350
3351 for (i = 0; i < n; i++) {
3352 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3353 dst[i][3] = src[i];
3354 }
3355 }
3356
3357 static void
3358 unpack_int_rgba_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3359 {
3360 unsigned int i;
3361
3362 for (i = 0; i < n; i++) {
3363 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3364 dst[i][3] = src[i];
3365 }
3366 }
3367
3368 static void
3369 unpack_int_rgba_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3370 {
3371 unsigned int i;
3372
3373 for (i = 0; i < n; i++) {
3374 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3375 dst[i][3] = src[i];
3376 }
3377 }
3378
3379 static void
3380 unpack_int_rgba_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3381 {
3382 unsigned int i;
3383
3384 for (i = 0; i < n; i++) {
3385 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3386 dst[i][3] = src[i];
3387 }
3388 }
3389
3390 static void
3391 unpack_int_rgba_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3392 {
3393 unsigned int i;
3394
3395 for (i = 0; i < n; i++) {
3396 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3397 dst[i][3] = src[i];
3398 }
3399 }
3400
3401 static void
3402 unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3403 {
3404 unsigned int i;
3405
3406 for (i = 0; i < n; i++) {
3407 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3408 dst[i][3] = 1;
3409 }
3410 }
3411
3412 static void
3413 unpack_int_rgba_LUMINANCE_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3414 {
3415 unsigned int i;
3416
3417 for (i = 0; i < n; i++) {
3418 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3419 dst[i][3] = 1;
3420 }
3421 }
3422
3423 static void
3424 unpack_int_rgba_LUMINANCE_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3425 {
3426 unsigned int i;
3427
3428 for (i = 0; i < n; i++) {
3429 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3430 dst[i][3] = 1;
3431 }
3432 }
3433
3434 static void
3435 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3436 {
3437 unsigned int i;
3438
3439 for (i = 0; i < n; i++) {
3440 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3441 dst[i][3] = 1;
3442 }
3443 }
3444
3445 static void
3446 unpack_int_rgba_LUMINANCE_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3447 {
3448 unsigned int i;
3449
3450 for (i = 0; i < n; i++) {
3451 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3452 dst[i][3] = 1;
3453 }
3454 }
3455
3456
3457 static void
3458 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3459 {
3460 unsigned int i;
3461
3462 for (i = 0; i < n; i++) {
3463 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3464 dst[i][3] = src[i * 2 + 1];
3465 }
3466 }
3467
3468 static void
3469 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3470 {
3471 unsigned int i;
3472
3473 for (i = 0; i < n; i++) {
3474 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3475 dst[i][3] = src[i * 2 + 1];
3476 }
3477 }
3478
3479 static void
3480 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3481 {
3482 unsigned int i;
3483
3484 for (i = 0; i < n; i++) {
3485 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3486 dst[i][3] = src[i * 2 + 1];
3487 }
3488 }
3489
3490 static void
3491 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3492 {
3493 unsigned int i;
3494
3495 for (i = 0; i < n; i++) {
3496 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3497 dst[i][3] = src[i * 2 + 1];
3498 }
3499 }
3500
3501 static void
3502 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3503 {
3504 unsigned int i;
3505
3506 for (i = 0; i < n; i++) {
3507 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3508 dst[i][3] = src[i * 2 + 1];
3509 }
3510 }
3511
3512 static void
3513 unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3514 {
3515 unsigned int i;
3516
3517 for (i = 0; i < n; i++) {
3518 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3519 }
3520 }
3521
3522 static void
3523 unpack_int_rgba_INTENSITY_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3524 {
3525 unsigned int i;
3526
3527 for (i = 0; i < n; i++) {
3528 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3529 }
3530 }
3531
3532 static void
3533 unpack_int_rgba_INTENSITY_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3534 {
3535 unsigned int i;
3536
3537 for (i = 0; i < n; i++) {
3538 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3539 }
3540 }
3541
3542 static void
3543 unpack_int_rgba_INTENSITY_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3544 {
3545 unsigned int i;
3546
3547 for (i = 0; i < n; i++) {
3548 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3549 }
3550 }
3551
3552 static void
3553 unpack_int_rgba_INTENSITY_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3554 {
3555 unsigned int i;
3556
3557 for (i = 0; i < n; i++) {
3558 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3559 }
3560 }
3561
3562 static void
3563 unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
3564 {
3565 unsigned int i;
3566
3567 for (i = 0; i < n; i++) {
3568 GLuint tmp = src[i];
3569 dst[i][0] = (tmp >> 20) & 0x3ff;
3570 dst[i][1] = (tmp >> 10) & 0x3ff;
3571 dst[i][2] = (tmp >> 0) & 0x3ff;
3572 dst[i][3] = (tmp >> 30) & 0x3;
3573 }
3574 }
3575
3576 static void
3577 unpack_int_rgba_ABGR2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
3578 {
3579 unsigned int i;
3580
3581 for (i = 0; i < n; i++) {
3582 GLuint tmp = src[i];
3583 dst[i][0] = (tmp >> 0) & 0x3ff;
3584 dst[i][1] = (tmp >> 10) & 0x3ff;
3585 dst[i][2] = (tmp >> 20) & 0x3ff;
3586 dst[i][3] = (tmp >> 30) & 0x3;
3587 }
3588 }
3589
3590 static void
3591 unpack_int_rgba_ARGB2101010(const GLuint *src, GLuint dst[][4], GLuint n)
3592 {
3593 unsigned int i;
3594
3595 for (i = 0; i < n; i++) {
3596 GLuint tmp = src[i];
3597 dst[i][0] = (tmp >> 20) & 0x3ff;
3598 dst[i][1] = (tmp >> 10) & 0x3ff;
3599 dst[i][2] = (tmp >> 0) & 0x3ff;
3600 dst[i][3] = (tmp >> 30) & 0x3;
3601 }
3602 }
3603
3604 static void
3605 unpack_int_rgba_XBGR8888_UINT(const GLubyte *src, GLuint dst[][4], GLuint n)
3606 {
3607 unsigned int i;
3608
3609 for (i = 0; i < n; i++) {
3610 dst[i][0] = src[i * 4 + 0];
3611 dst[i][1] = src[i * 4 + 1];
3612 dst[i][2] = src[i * 4 + 2];
3613 dst[i][3] = 1;
3614 }
3615 }
3616
3617 static void
3618 unpack_int_rgba_XBGR8888_SINT(const GLbyte *src, GLuint dst[][4], GLuint n)
3619 {
3620 unsigned int i;
3621
3622 for (i = 0; i < n; i++) {
3623 dst[i][0] = src[i * 4 + 0];
3624 dst[i][1] = src[i * 4 + 1];
3625 dst[i][2] = src[i * 4 + 2];
3626 dst[i][3] = 1;
3627 }
3628 }
3629
3630 static void
3631 unpack_int_rgba_XBGR16161616_UINT(const GLushort *src, GLuint dst[][4], GLuint n)
3632 {
3633 unsigned int i;
3634
3635 for (i = 0; i < n; i++) {
3636 dst[i][0] = src[i * 4 + 0];
3637 dst[i][1] = src[i * 4 + 1];
3638 dst[i][2] = src[i * 4 + 2];
3639 dst[i][3] = 1;
3640 }
3641 }
3642
3643 static void
3644 unpack_int_rgba_XBGR16161616_SINT(const GLshort *src, GLuint dst[][4], GLuint n)
3645 {
3646 unsigned int i;
3647
3648 for (i = 0; i < n; i++) {
3649 dst[i][0] = src[i * 4 + 0];
3650 dst[i][1] = src[i * 4 + 1];
3651 dst[i][2] = src[i * 4 + 2];
3652 dst[i][3] = 1;
3653 }
3654 }
3655
3656 static void
3657 unpack_int_rgba_XBGR32323232_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
3658 {
3659 unsigned int i;
3660
3661 for (i = 0; i < n; i++) {
3662 dst[i][0] = src[i * 4 + 0];
3663 dst[i][1] = src[i * 4 + 1];
3664 dst[i][2] = src[i * 4 + 2];
3665 dst[i][3] = 1;
3666 }
3667 }
3668
3669 static void
3670 unpack_int_rgba_ABGR2101010(const GLuint *src, GLuint dst[][4], GLuint n)
3671 {
3672 unsigned int i;
3673
3674 for (i = 0; i < n; i++) {
3675 GLuint tmp = src[i];
3676 dst[i][0] = (tmp >> 0) & 0x3ff;
3677 dst[i][1] = (tmp >> 10) & 0x3ff;
3678 dst[i][2] = (tmp >> 20) & 0x3ff;
3679 dst[i][3] = (tmp >> 30) & 0x3;
3680 }
3681 }
3682
3683 void
3684 _mesa_unpack_uint_rgba_row(mesa_format format, GLuint n,
3685 const void *src, GLuint dst[][4])
3686 {
3687 switch (format) {
3688 /* Since there won't be any sign extension happening, there's no need to
3689 * make separate paths for 32-bit-to-32-bit integer unpack.
3690 */
3691 case MESA_FORMAT_RGBA_UINT32:
3692 case MESA_FORMAT_RGBA_SINT32:
3693 unpack_int_rgba_RGBA_UINT32(src, dst, n);
3694 break;
3695
3696 case MESA_FORMAT_RGBA_UINT16:
3697 unpack_int_rgba_RGBA_UINT16(src, dst, n);
3698 break;
3699 case MESA_FORMAT_RGBA_SINT16:
3700 unpack_int_rgba_RGBA_INT16(src, dst, n);
3701 break;
3702
3703 case MESA_FORMAT_RGBA_UINT8:
3704 unpack_int_rgba_RGBA_UINT8(src, dst, n);
3705 break;
3706 case MESA_FORMAT_RGBA_SINT8:
3707 unpack_int_rgba_RGBA_INT8(src, dst, n);
3708 break;
3709
3710 case MESA_FORMAT_B8G8R8A8_UNORM:
3711 unpack_int_rgba_ARGB8888(src, dst, n);
3712 break;
3713
3714 case MESA_FORMAT_B8G8R8X8_UNORM:
3715 unpack_int_rgba_XRGB8888(src, dst, n);
3716 break;
3717
3718 case MESA_FORMAT_RGB_UINT32:
3719 case MESA_FORMAT_RGB_SINT32:
3720 unpack_int_rgba_RGB_UINT32(src, dst, n);
3721 break;
3722
3723 case MESA_FORMAT_RGB_UINT16:
3724 unpack_int_rgba_RGB_UINT16(src, dst, n);
3725 break;
3726 case MESA_FORMAT_RGB_SINT16:
3727 unpack_int_rgba_RGB_INT16(src, dst, n);
3728 break;
3729
3730 case MESA_FORMAT_RGB_UINT8:
3731 unpack_int_rgba_RGB_UINT8(src, dst, n);
3732 break;
3733 case MESA_FORMAT_RGB_SINT8:
3734 unpack_int_rgba_RGB_INT8(src, dst, n);
3735 break;
3736
3737 case MESA_FORMAT_RG_UINT32:
3738 case MESA_FORMAT_RG_SINT32:
3739 unpack_int_rgba_RG_UINT32(src, dst, n);
3740 break;
3741
3742 case MESA_FORMAT_RG_UINT16:
3743 unpack_int_rgba_RG_UINT16(src, dst, n);
3744 break;
3745 case MESA_FORMAT_RG_SINT16:
3746 unpack_int_rgba_RG_INT16(src, dst, n);
3747 break;
3748
3749 case MESA_FORMAT_RG_UINT8:
3750 unpack_int_rgba_RG_UINT8(src, dst, n);
3751 break;
3752 case MESA_FORMAT_RG_SINT8:
3753 unpack_int_rgba_RG_INT8(src, dst, n);
3754 break;
3755
3756 case MESA_FORMAT_R_UINT32:
3757 case MESA_FORMAT_R_SINT32:
3758 unpack_int_rgba_R_UINT32(src, dst, n);
3759 break;
3760
3761 case MESA_FORMAT_R_UINT16:
3762 unpack_int_rgba_R_UINT16(src, dst, n);
3763 break;
3764 case MESA_FORMAT_R_SINT16:
3765 unpack_int_rgba_R_INT16(src, dst, n);
3766 break;
3767
3768 case MESA_FORMAT_R_UINT8:
3769 unpack_int_rgba_R_UINT8(src, dst, n);
3770 break;
3771 case MESA_FORMAT_R_SINT8:
3772 unpack_int_rgba_R_INT8(src, dst, n);
3773 break;
3774
3775 case MESA_FORMAT_A_UINT32:
3776 case MESA_FORMAT_A_SINT32:
3777 unpack_int_rgba_ALPHA_UINT32(src, dst, n);
3778 break;
3779
3780 case MESA_FORMAT_A_UINT16:
3781 unpack_int_rgba_ALPHA_UINT16(src, dst, n);
3782 break;
3783 case MESA_FORMAT_A_SINT16:
3784 unpack_int_rgba_ALPHA_INT16(src, dst, n);
3785 break;
3786
3787 case MESA_FORMAT_A_UINT8:
3788 unpack_int_rgba_ALPHA_UINT8(src, dst, n);
3789 break;
3790 case MESA_FORMAT_A_SINT8:
3791 unpack_int_rgba_ALPHA_INT8(src, dst, n);
3792 break;
3793
3794 case MESA_FORMAT_L_UINT32:
3795 case MESA_FORMAT_L_SINT32:
3796 unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
3797 break;
3798 case MESA_FORMAT_L_UINT16:
3799 unpack_int_rgba_LUMINANCE_UINT16(src, dst, n);
3800 break;
3801 case MESA_FORMAT_L_SINT16:
3802 unpack_int_rgba_LUMINANCE_INT16(src, dst, n);
3803 break;
3804
3805 case MESA_FORMAT_L_UINT8:
3806 unpack_int_rgba_LUMINANCE_UINT8(src, dst, n);
3807 break;
3808 case MESA_FORMAT_L_SINT8:
3809 unpack_int_rgba_LUMINANCE_INT8(src, dst, n);
3810 break;
3811
3812 case MESA_FORMAT_LA_UINT32:
3813 case MESA_FORMAT_LA_SINT32:
3814 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
3815 break;
3816
3817 case MESA_FORMAT_LA_UINT16:
3818 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src, dst, n);
3819 break;
3820 case MESA_FORMAT_LA_SINT16:
3821 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src, dst, n);
3822 break;
3823
3824 case MESA_FORMAT_LA_UINT8:
3825 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src, dst, n);
3826 break;
3827 case MESA_FORMAT_LA_SINT8:
3828 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src, dst, n);
3829 break;
3830
3831 case MESA_FORMAT_I_UINT32:
3832 case MESA_FORMAT_I_SINT32:
3833 unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
3834 break;
3835
3836 case MESA_FORMAT_I_UINT16:
3837 unpack_int_rgba_INTENSITY_UINT16(src, dst, n);
3838 break;
3839 case MESA_FORMAT_I_SINT16:
3840 unpack_int_rgba_INTENSITY_INT16(src, dst, n);
3841 break;
3842
3843 case MESA_FORMAT_I_UINT8:
3844 unpack_int_rgba_INTENSITY_UINT8(src, dst, n);
3845 break;
3846 case MESA_FORMAT_I_SINT8:
3847 unpack_int_rgba_INTENSITY_INT8(src, dst, n);
3848 break;
3849
3850 case MESA_FORMAT_B10G10R10A2_UINT:
3851 unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
3852 break;
3853
3854 case MESA_FORMAT_R10G10B10A2_UINT:
3855 unpack_int_rgba_ABGR2101010_UINT(src, dst, n);
3856 break;
3857
3858 case MESA_FORMAT_B10G10R10A2_UNORM:
3859 unpack_int_rgba_ARGB2101010(src, dst, n);
3860 break;
3861
3862 case MESA_FORMAT_RGBX_UINT8:
3863 unpack_int_rgba_XBGR8888_UINT(src, dst, n);
3864 break;
3865
3866 case MESA_FORMAT_RGBX_SINT8:
3867 unpack_int_rgba_XBGR8888_SINT(src, dst, n);
3868 break;
3869
3870 case MESA_FORMAT_RGBX_UINT16:
3871 unpack_int_rgba_XBGR16161616_UINT(src, dst, n);
3872 break;
3873
3874 case MESA_FORMAT_RGBX_SINT16:
3875 unpack_int_rgba_XBGR16161616_SINT(src, dst, n);
3876 break;
3877
3878 case MESA_FORMAT_RGBX_UINT32:
3879 case MESA_FORMAT_RGBX_SINT32:
3880 unpack_int_rgba_XBGR32323232_UINT(src, dst, n);
3881 break;
3882
3883 case MESA_FORMAT_R10G10B10A2_UNORM:
3884 unpack_int_rgba_ABGR2101010(src, dst, n);
3885 break;
3886
3887 default:
3888 _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
3889 _mesa_get_format_name(format));
3890 return;
3891 }
3892 }
3893
3894 /**
3895 * Unpack a 2D rect of pixels returning float RGBA colors.
3896 * \param format the source image format
3897 * \param src start address of the source image
3898 * \param srcRowStride source image row stride in bytes
3899 * \param dst start address of the dest image
3900 * \param dstRowStride dest image row stride in bytes
3901 * \param x source image start X pos
3902 * \param y source image start Y pos
3903 * \param width width of rect region to convert
3904 * \param height height of rect region to convert
3905 */
3906 void
3907 _mesa_unpack_rgba_block(mesa_format format,
3908 const void *src, GLint srcRowStride,
3909 GLfloat dst[][4], GLint dstRowStride,
3910 GLuint x, GLuint y, GLuint width, GLuint height)
3911 {
3912 unpack_rgba_func unpack = get_unpack_rgba_function(format);
3913 const GLuint srcPixStride = _mesa_get_format_bytes(format);
3914 const GLuint dstPixStride = 4 * sizeof(GLfloat);
3915 const GLubyte *srcRow;
3916 GLubyte *dstRow;
3917 GLuint i;
3918
3919 /* XXX needs to be fixed for compressed formats */
3920
3921 srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
3922 dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
3923
3924 for (i = 0; i < height; i++) {
3925 unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
3926
3927 dstRow += dstRowStride;
3928 srcRow += srcRowStride;
3929 }
3930 }
3931
3932
3933
3934
3935 typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
3936
3937 static void
3938 unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
3939 {
3940 /* only return Z, not stencil data */
3941 const GLuint *s = ((const GLuint *) src);
3942 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
3943 GLuint i;
3944 for (i = 0; i < n; i++) {
3945 dst[i] = (GLfloat) ((s[i] >> 8) * scale);
3946 ASSERT(dst[i] >= 0.0F);
3947 ASSERT(dst[i] <= 1.0F);
3948 }
3949 }
3950
3951 static void
3952 unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
3953 {
3954 /* only return Z, not stencil data */
3955 const GLuint *s = ((const GLuint *) src);
3956 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
3957 GLuint i;
3958 for (i = 0; i < n; i++) {
3959 dst[i] = (GLfloat) ((s[i] & 0x00ffffff) * scale);
3960 ASSERT(dst[i] >= 0.0F);
3961 ASSERT(dst[i] <= 1.0F);
3962 }
3963 }
3964
3965 static void
3966 unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst)
3967 {
3968 const GLushort *s = ((const GLushort *) src);
3969 GLuint i;
3970 for (i = 0; i < n; i++) {
3971 dst[i] = s[i] * (1.0F / 65535.0F);
3972 }
3973 }
3974
3975 static void
3976 unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst)
3977 {
3978 const GLuint *s = ((const GLuint *) src);
3979 GLuint i;
3980 for (i = 0; i < n; i++) {
3981 dst[i] = s[i] * (1.0F / 0xffffffff);
3982 }
3983 }
3984
3985 static void
3986 unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst)
3987 {
3988 memcpy(dst, src, n * sizeof(float));
3989 }
3990
3991 static void
3992 unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
3993 {
3994 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
3995 GLuint i;
3996 for (i = 0; i < n; i++) {
3997 dst[i] = s[i].z;
3998 }
3999 }
4000
4001
4002
4003 /**
4004 * Unpack Z values.
4005 * The returned values will always be in the range [0.0, 1.0].
4006 */
4007 void
4008 _mesa_unpack_float_z_row(mesa_format format, GLuint n,
4009 const void *src, GLfloat *dst)
4010 {
4011 unpack_float_z_func unpack;
4012
4013 switch (format) {
4014 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4015 case MESA_FORMAT_X8Z24_UNORM:
4016 unpack = unpack_float_z_Z24_X8;
4017 break;
4018 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4019 case MESA_FORMAT_Z24_UNORM_X8_UINT:
4020 unpack = unpack_float_z_X8_Z24;
4021 break;
4022 case MESA_FORMAT_Z_UNORM16:
4023 unpack = unpack_float_z_Z16;
4024 break;
4025 case MESA_FORMAT_Z_UNORM32:
4026 unpack = unpack_float_z_Z32;
4027 break;
4028 case MESA_FORMAT_Z_FLOAT32:
4029 unpack = unpack_float_z_Z32F;
4030 break;
4031 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4032 unpack = unpack_float_z_Z32X24S8;
4033 break;
4034 default:
4035 _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
4036 _mesa_get_format_name(format));
4037 return;
4038 }
4039
4040 unpack(n, src, dst);
4041 }
4042
4043
4044
4045 typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
4046
4047 static void
4048 unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
4049 {
4050 /* only return Z, not stencil data */
4051 const GLuint *s = ((const GLuint *) src);
4052 GLuint i;
4053 for (i = 0; i < n; i++) {
4054 dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
4055 }
4056 }
4057
4058 static void
4059 unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
4060 {
4061 /* only return Z, not stencil data */
4062 const GLuint *s = ((const GLuint *) src);
4063 GLuint i;
4064 for (i = 0; i < n; i++) {
4065 dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
4066 }
4067 }
4068
4069 static void
4070 unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n)
4071 {
4072 const GLushort *s = ((const GLushort *)src);
4073 GLuint i;
4074 for (i = 0; i < n; i++) {
4075 dst[i] = (s[i] << 16) | s[i];
4076 }
4077 }
4078
4079 static void
4080 unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
4081 {
4082 memcpy(dst, src, n * sizeof(GLuint));
4083 }
4084
4085 static void
4086 unpack_uint_z_Z32_FLOAT(const void *src, GLuint *dst, GLuint n)
4087 {
4088 const float *s = (const float *)src;
4089 GLuint i;
4090 for (i = 0; i < n; i++) {
4091 dst[i] = FLOAT_TO_UINT(CLAMP(s[i], 0.0F, 1.0F));
4092 }
4093 }
4094
4095 static void
4096 unpack_uint_z_Z32_FLOAT_X24S8(const void *src, GLuint *dst, GLuint n)
4097 {
4098 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
4099 GLuint i;
4100
4101 for (i = 0; i < n; i++) {
4102 dst[i] = FLOAT_TO_UINT(CLAMP(s[i].z, 0.0F, 1.0F));
4103 }
4104 }
4105
4106
4107 /**
4108 * Unpack Z values.
4109 * The returned values will always be in the range [0, 0xffffffff].
4110 */
4111 void
4112 _mesa_unpack_uint_z_row(mesa_format format, GLuint n,
4113 const void *src, GLuint *dst)
4114 {
4115 unpack_uint_z_func unpack;
4116 const GLubyte *srcPtr = (GLubyte *) src;
4117
4118 switch (format) {
4119 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4120 case MESA_FORMAT_X8Z24_UNORM:
4121 unpack = unpack_uint_z_Z24_X8;
4122 break;
4123 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4124 case MESA_FORMAT_Z24_UNORM_X8_UINT:
4125 unpack = unpack_uint_z_X8_Z24;
4126 break;
4127 case MESA_FORMAT_Z_UNORM16:
4128 unpack = unpack_uint_z_Z16;
4129 break;
4130 case MESA_FORMAT_Z_UNORM32:
4131 unpack = unpack_uint_z_Z32;
4132 break;
4133 case MESA_FORMAT_Z_FLOAT32:
4134 unpack = unpack_uint_z_Z32_FLOAT;
4135 break;
4136 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4137 unpack = unpack_uint_z_Z32_FLOAT_X24S8;
4138 break;
4139 default:
4140 _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
4141 _mesa_get_format_name(format));
4142 return;
4143 }
4144
4145 unpack(srcPtr, dst, n);
4146 }
4147
4148
4149 static void
4150 unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
4151 {
4152 memcpy(dst, src, n);
4153 }
4154
4155 static void
4156 unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n)
4157 {
4158 GLuint i;
4159 const GLuint *src32 = src;
4160
4161 for (i = 0; i < n; i++)
4162 dst[i] = src32[i] & 0xff;
4163 }
4164
4165 static void
4166 unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n)
4167 {
4168 GLuint i;
4169 const GLuint *src32 = src;
4170
4171 for (i = 0; i < n; i++)
4172 dst[i] = src32[i] >> 24;
4173 }
4174
4175 static void
4176 unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n)
4177 {
4178 GLuint i;
4179 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
4180
4181 for (i = 0; i < n; i++)
4182 dst[i] = s[i].x24s8 & 0xff;
4183 }
4184
4185 void
4186 _mesa_unpack_ubyte_stencil_row(mesa_format format, GLuint n,
4187 const void *src, GLubyte *dst)
4188 {
4189 switch (format) {
4190 case MESA_FORMAT_S_UINT8:
4191 unpack_ubyte_s_S8(src, dst, n);
4192 break;
4193 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4194 unpack_ubyte_s_Z24_S8(src, dst, n);
4195 break;
4196 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4197 unpack_ubyte_s_S8_Z24(src, dst, n);
4198 break;
4199 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4200 unpack_ubyte_s_Z32_FLOAT_X24S8(src, dst, n);
4201 break;
4202 default:
4203 _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
4204 _mesa_get_format_name(format));
4205 return;
4206 }
4207 }
4208
4209 static void
4210 unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint *src, GLuint *dst, GLuint n)
4211 {
4212 GLuint i;
4213
4214 for (i = 0; i < n; i++) {
4215 GLuint val = src[i];
4216 dst[i] = val >> 24 | val << 8;
4217 }
4218 }
4219
4220 static void
4221 unpack_uint_24_8_depth_stencil_Z32_S8X24(const GLuint *src,
4222 GLuint *dst, GLuint n)
4223 {
4224 GLuint i;
4225
4226 for (i = 0; i < n; i++) {
4227 /* 8 bytes per pixel (float + uint32) */
4228 GLfloat zf = ((GLfloat *) src)[i * 2 + 0];
4229 GLuint z24 = (GLuint) (zf * (GLfloat) 0xffffff);
4230 GLuint s = src[i * 2 + 1] & 0xff;
4231 dst[i] = (z24 << 8) | s;
4232 }
4233 }
4234
4235 static void
4236 unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint *src, GLuint *dst, GLuint n)
4237 {
4238 memcpy(dst, src, n * 4);
4239 }
4240
4241 /**
4242 * Unpack depth/stencil returning as GL_UNSIGNED_INT_24_8.
4243 * \param format the source data format
4244 */
4245 void
4246 _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
4247 const void *src, GLuint *dst)
4248 {
4249 switch (format) {
4250 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4251 unpack_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
4252 break;
4253 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4254 unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
4255 break;
4256 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4257 unpack_uint_24_8_depth_stencil_Z32_S8X24(src, dst, n);
4258 break;
4259 default:
4260 _mesa_problem(NULL,
4261 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
4262 _mesa_get_format_name(format));
4263 return;
4264 }
4265 }