format_unpack.c revision 858d1f0b1cb9087f7eefcb3b8147e06457505ce0
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 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25#include "colormac.h"
26#include "format_unpack.h"
27#include "macros.h"
28#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
29#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
30
31
32/**
33 * Convert an 8-bit sRGB value from non-linear space to a
34 * linear RGB value in [0, 1].
35 * Implemented with a 256-entry lookup table.
36 */
37static inline GLfloat
38nonlinear_to_linear(GLubyte cs8)
39{
40   static GLfloat table[256];
41   static GLboolean tableReady = GL_FALSE;
42   if (!tableReady) {
43      /* compute lookup table now */
44      GLuint i;
45      for (i = 0; i < 256; i++) {
46         const GLfloat cs = UBYTE_TO_FLOAT(i);
47         if (cs <= 0.04045) {
48            table[i] = cs / 12.92f;
49         }
50         else {
51            table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
52         }
53      }
54      tableReady = GL_TRUE;
55   }
56   return table[cs8];
57}
58
59
60typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);
61
62
63static void
64unpack_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
65{
66   const GLuint *s = ((const GLuint *) src);
67   GLuint i;
68   for (i = 0; i < n; i++) {
69      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
70      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
71      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
72      dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
73   }
74}
75
76static void
77unpack_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
78{
79   const GLuint *s = ((const GLuint *) src);
80   GLuint i;
81   for (i = 0; i < n; i++) {
82      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
83      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
84      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
85      dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
86   }
87}
88
89static void
90unpack_ARGB8888(const void *src, GLfloat dst[][4], GLuint n)
91{
92   const GLuint *s = ((const GLuint *) src);
93   GLuint i;
94   for (i = 0; i < n; i++) {
95      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
96      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
97      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
98      dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
99   }
100}
101
102static void
103unpack_ARGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
104{
105   const GLuint *s = ((const GLuint *) src);
106   GLuint i;
107   for (i = 0; i < n; i++) {
108      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
109      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
110      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
111      dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
112   }
113}
114
115static void
116unpack_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
117{
118   const GLuint *s = ((const GLuint *) src);
119   GLuint i;
120   for (i = 0; i < n; i++) {
121      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
122      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
123      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
124      dst[i][ACOMP] = 1.0f;
125   }
126}
127
128static void
129unpack_RGBX8888_REV(const void *src, GLfloat dst[][4], GLuint n)
130{
131   const GLuint *s = ((const GLuint *) src);
132   GLuint i;
133   for (i = 0; i < n; i++) {
134      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
135      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
136      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
137      dst[i][ACOMP] = 1.0f;
138   }
139}
140
141static void
142unpack_XRGB8888(const void *src, GLfloat dst[][4], GLuint n)
143{
144   const GLuint *s = ((const GLuint *) src);
145   GLuint i;
146   for (i = 0; i < n; i++) {
147      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
148      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
149      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
150      dst[i][ACOMP] = 1.0f;
151   }
152}
153
154static void
155unpack_XRGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
156{
157   const GLuint *s = ((const GLuint *) src);
158   GLuint i;
159   for (i = 0; i < n; i++) {
160      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
161      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
162      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
163      dst[i][ACOMP] = 1.0f;
164   }
165}
166
167static void
168unpack_RGB888(const void *src, GLfloat dst[][4], GLuint n)
169{
170   const GLubyte *s = (const GLubyte *) src;
171   GLuint i;
172   for (i = 0; i < n; i++) {
173      dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
174      dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
175      dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
176      dst[i][ACOMP] = 1.0F;
177   }
178}
179
180static void
181unpack_BGR888(const void *src, GLfloat dst[][4], GLuint n)
182{
183   const GLubyte *s = (const GLubyte *) src;
184   GLuint i;
185   for (i = 0; i < n; i++) {
186      dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
187      dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
188      dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
189      dst[i][ACOMP] = 1.0F;
190   }
191}
192
193static void
194unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n)
195{
196   const GLushort *s = ((const GLushort *) src);
197   GLuint i;
198   for (i = 0; i < n; i++) {
199      dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
200      dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F);
201      dst[i][BCOMP] = ((s[i]      ) & 0x1f) * (1.0F / 31.0F);
202      dst[i][ACOMP] = 1.0F;
203   }
204}
205
206static void
207unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n)
208{
209   const GLushort *s = ((const GLushort *) src);
210   GLuint i;
211   for (i = 0; i < n; i++) {
212      GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
213      dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) );
214      dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >>  9) & 0x3) );
215      dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >>  2) & 0x7) );
216      dst[i][ACOMP] = 1.0F;
217   }
218}
219
220static void
221unpack_ARGB4444(const void *src, GLfloat dst[][4], GLuint n)
222{
223   const GLushort *s = ((const GLushort *) src);
224   GLuint i;
225   for (i = 0; i < n; i++) {
226      dst[i][RCOMP] = ((s[i] >>  8) & 0xf) * (1.0F / 15.0F);
227      dst[i][GCOMP] = ((s[i] >>  4) & 0xf) * (1.0F / 15.0F);
228      dst[i][BCOMP] = ((s[i]      ) & 0xf) * (1.0F / 15.0F);
229      dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
230   }
231}
232
233static void
234unpack_ARGB4444_REV(const void *src, GLfloat dst[][4], GLuint n)
235{
236   const GLushort *s = ((const GLushort *) src);
237   GLuint i;
238   for (i = 0; i < n; i++) {
239      dst[i][RCOMP] = ((s[i]      ) & 0xf) * (1.0F / 15.0F);
240      dst[i][GCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
241      dst[i][BCOMP] = ((s[i] >>  8) & 0xf) * (1.0F / 15.0F);
242      dst[i][ACOMP] = ((s[i] >>  4) & 0xf) * (1.0F / 15.0F);
243   }
244}
245
246static void
247unpack_RGBA5551(const void *src, GLfloat dst[][4], GLuint n)
248{
249   const GLushort *s = ((const GLushort *) src);
250   GLuint i;
251   for (i = 0; i < n; i++) {
252      dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
253      dst[i][GCOMP] = ((s[i] >>  6) & 0x1f) * (1.0F / 31.0F);
254      dst[i][BCOMP] = ((s[i] >>  1) & 0x1f) * (1.0F / 31.0F);
255      dst[i][ACOMP] = ((s[i]      ) & 0x01) * 1.0F;
256   }
257}
258
259static void
260unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n)
261{
262   const GLushort *s = ((const GLushort *) src);
263   GLuint i;
264   for (i = 0; i < n; i++) {
265      dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
266      dst[i][GCOMP] = ((s[i] >>  5) & 0x1f) * (1.0F / 31.0F);
267      dst[i][BCOMP] = ((s[i] >>  0) & 0x1f) * (1.0F / 31.0F);
268      dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F;
269   }
270}
271
272static void
273unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n)
274{
275   const GLushort *s = ((const GLushort *) src);
276   GLuint i;
277   for (i = 0; i < n; i++) {
278      dst[i][RCOMP] = UBYTE_TO_FLOAT( ((s[i] >>  7) & 0xf8) | ((s[i] >> 12) & 0x7) );
279      dst[i][GCOMP] = UBYTE_TO_FLOAT( ((s[i] >>  2) & 0xf8) | ((s[i] >>  7) & 0x7) );
280      dst[i][BCOMP] = UBYTE_TO_FLOAT( ((s[i] <<  3) & 0xf8) | ((s[i] >>  2) & 0x7) );
281      dst[i][ACOMP] = UBYTE_TO_FLOAT( ((s[i] >> 15) & 0x01) * 255 );
282   }
283}
284
285static void
286unpack_AL44(const void *src, GLfloat dst[][4], GLuint n)
287{
288   const GLubyte *s = ((const GLubyte *) src);
289   GLuint i;
290   for (i = 0; i < n; i++) {
291      dst[i][RCOMP] =
292      dst[i][GCOMP] =
293      dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
294      dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
295   }
296}
297
298static void
299unpack_AL88(const void *src, GLfloat dst[][4], GLuint n)
300{
301   const GLushort *s = ((const GLushort *) src);
302   GLuint i;
303   for (i = 0; i < n; i++) {
304      dst[i][RCOMP] =
305      dst[i][GCOMP] =
306      dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
307      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
308   }
309}
310
311static void
312unpack_AL88_REV(const void *src, GLfloat dst[][4], GLuint n)
313{
314   const GLushort *s = ((const GLushort *) src);
315   GLuint i;
316   for (i = 0; i < n; i++) {
317      dst[i][RCOMP] =
318      dst[i][GCOMP] =
319      dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
320      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
321   }
322}
323
324static void
325unpack_AL1616(const void *src, GLfloat dst[][4], GLuint n)
326{
327   const GLuint *s = ((const GLuint *) src);
328   GLuint i;
329   for (i = 0; i < n; i++) {
330      dst[i][RCOMP] =
331      dst[i][GCOMP] =
332      dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
333      dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
334   }
335}
336
337static void
338unpack_AL1616_REV(const void *src, GLfloat dst[][4], GLuint n)
339{
340   const GLuint *s = ((const GLuint *) src);
341   GLuint i;
342   for (i = 0; i < n; i++) {
343      dst[i][RCOMP] =
344      dst[i][GCOMP] =
345      dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
346      dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
347   }
348}
349
350static void
351unpack_RGB332(const void *src, GLfloat dst[][4], GLuint n)
352{
353   const GLubyte *s = ((const GLubyte *) src);
354   GLuint i;
355   for (i = 0; i < n; i++) {
356      dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F);
357      dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F);
358      dst[i][BCOMP] = ((s[i]     ) & 0x3) * (1.0F / 3.0F);
359      dst[i][ACOMP] = 1.0F;
360   }
361}
362
363
364static void
365unpack_A8(const void *src, GLfloat dst[][4], GLuint n)
366{
367   const GLubyte *s = ((const GLubyte *) src);
368   GLuint i;
369   for (i = 0; i < n; i++) {
370      dst[i][RCOMP] =
371      dst[i][GCOMP] =
372      dst[i][BCOMP] = 0.0F;
373      dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
374   }
375}
376
377static void
378unpack_A16(const void *src, GLfloat dst[][4], GLuint n)
379{
380   const GLushort *s = ((const GLushort *) src);
381   GLuint i;
382   for (i = 0; i < n; i++) {
383      dst[i][RCOMP] =
384      dst[i][GCOMP] =
385      dst[i][BCOMP] = 0.0F;
386      dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
387   }
388}
389
390static void
391unpack_L8(const void *src, GLfloat dst[][4], GLuint n)
392{
393   const GLubyte *s = ((const GLubyte *) src);
394   GLuint i;
395   for (i = 0; i < n; i++) {
396      dst[i][RCOMP] =
397      dst[i][GCOMP] =
398      dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
399      dst[i][ACOMP] = 1.0F;
400   }
401}
402
403static void
404unpack_L16(const void *src, GLfloat dst[][4], GLuint n)
405{
406   const GLushort *s = ((const GLushort *) src);
407   GLuint i;
408   for (i = 0; i < n; i++) {
409      dst[i][RCOMP] =
410      dst[i][GCOMP] =
411      dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
412      dst[i][ACOMP] = 1.0F;
413   }
414}
415
416static void
417unpack_I8(const void *src, GLfloat dst[][4], GLuint n)
418{
419   const GLubyte *s = ((const GLubyte *) src);
420   GLuint i;
421   for (i = 0; i < n; i++) {
422      dst[i][RCOMP] =
423      dst[i][GCOMP] =
424      dst[i][BCOMP] =
425      dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
426   }
427}
428
429static void
430unpack_I16(const void *src, GLfloat dst[][4], GLuint n)
431{
432   const GLushort *s = ((const GLushort *) src);
433   GLuint i;
434   for (i = 0; i < n; i++) {
435      dst[i][RCOMP] =
436      dst[i][GCOMP] =
437      dst[i][BCOMP] =
438      dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
439   }
440}
441
442static void
443unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n)
444{
445   GLuint i;
446   for (i = 0; i < n; i++) {
447      const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
448      const GLushort *src1 = src0 + 1;         /* odd */
449      const GLubyte y0 = (*src0 >> 8) & 0xff;  /* luminance */
450      const GLubyte cb = *src0 & 0xff;         /* chroma U */
451      const GLubyte y1 = (*src1 >> 8) & 0xff;  /* luminance */
452      const GLubyte cr = *src1 & 0xff;         /* chroma V */
453      const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
454      GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
455      GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
456      GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
457      r *= (1.0F / 255.0F);
458      g *= (1.0F / 255.0F);
459      b *= (1.0F / 255.0F);
460      dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
461      dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
462      dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
463      dst[i][ACOMP] = 1.0F;
464   }
465}
466
467static void
468unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
469{
470   GLuint i;
471   for (i = 0; i < n; i++) {
472      const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
473      const GLushort *src1 = src0 + 1;         /* odd */
474      const GLubyte y0 = *src0 & 0xff;         /* luminance */
475      const GLubyte cr = (*src0 >> 8) & 0xff;  /* chroma V */
476      const GLubyte y1 = *src1 & 0xff;         /* luminance */
477      const GLubyte cb = (*src1 >> 8) & 0xff;  /* chroma U */
478      const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
479      GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
480      GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
481      GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
482      r *= (1.0F / 255.0F);
483      g *= (1.0F / 255.0F);
484      b *= (1.0F / 255.0F);
485      dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
486      dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
487      dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
488      dst[i][ACOMP] = 1.0F;
489   }
490}
491
492static void
493unpack_R8(const void *src, GLfloat dst[][4], GLuint n)
494{
495   const GLubyte *s = ((const GLubyte *) src);
496   GLuint i;
497   for (i = 0; i < n; i++) {
498      dst[i][0] = UBYTE_TO_FLOAT(s[i]);
499      dst[i][1] =
500      dst[i][2] = 0.0F;
501      dst[i][3] = 1.0F;
502   }
503}
504
505static void
506unpack_RG88(const void *src, GLfloat dst[][4], GLuint n)
507{
508   const GLushort *s = ((const GLushort *) src);
509   GLuint i;
510   for (i = 0; i < n; i++) {
511      dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
512      dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
513      dst[i][BCOMP] = 0.0;
514      dst[i][ACOMP] = 1.0;
515   }
516}
517
518static void
519unpack_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
520{
521   const GLushort *s = ((const GLushort *) src);
522   GLuint i;
523   for (i = 0; i < n; i++) {
524      dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
525      dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
526      dst[i][BCOMP] = 0.0;
527      dst[i][ACOMP] = 1.0;
528   }
529}
530
531static void
532unpack_R16(const void *src, GLfloat dst[][4], GLuint n)
533{
534   const GLushort *s = ((const GLushort *) src);
535   GLuint i;
536   for (i = 0; i < n; i++) {
537      dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]);
538      dst[i][GCOMP] = 0.0;
539      dst[i][BCOMP] = 0.0;
540      dst[i][ACOMP] = 1.0;
541   }
542}
543
544static void
545unpack_RG1616(const void *src, GLfloat dst[][4], GLuint n)
546{
547   const GLuint *s = ((const GLuint *) src);
548   GLuint i;
549   for (i = 0; i < n; i++) {
550      dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
551      dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
552      dst[i][BCOMP] = 0.0;
553      dst[i][ACOMP] = 1.0;
554   }
555}
556
557static void
558unpack_RG1616_REV(const void *src, GLfloat dst[][4], GLuint n)
559{
560   const GLuint *s = ((const GLuint *) src);
561   GLuint i;
562   for (i = 0; i < n; i++) {
563      dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
564      dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
565      dst[i][BCOMP] = 0.0;
566      dst[i][ACOMP] = 1.0;
567   }
568}
569
570static void
571unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n)
572{
573   const GLuint *s = ((const GLuint *) src);
574   GLuint i;
575   for (i = 0; i < n; i++) {
576      dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
577      dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
578      dst[i][BCOMP] = ((s[i] >>  0) & 0x3ff) * (1.0F / 1023.0F);
579      dst[i][ACOMP] = ((s[i] >> 30) &  0x03) * (1.0F / 3.0F);
580   }
581}
582
583
584static void
585unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
586{
587   /* only return Z, not stencil data */
588   const GLuint *s = ((const GLuint *) src);
589   const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
590   GLuint i;
591   for (i = 0; i < n; i++) {
592      dst[i][0] =
593      dst[i][1] =
594      dst[i][2] = (s[i] >> 8) * scale;
595      dst[i][3] = 1.0F;
596      ASSERT(dst[i][0] >= 0.0F);
597      ASSERT(dst[i][0] <= 1.0F);
598   }
599}
600
601static void
602unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
603{
604   /* only return Z, not stencil data */
605   const GLuint *s = ((const GLuint *) src);
606   const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
607   GLuint i;
608   for (i = 0; i < n; i++) {
609      dst[i][0] =
610      dst[i][1] =
611      dst[i][2] = (s[i] & 0x00ffffff) * scale;
612      dst[i][3] = 1.0F;
613      ASSERT(dst[i][0] >= 0.0F);
614      ASSERT(dst[i][0] <= 1.0F);
615   }
616}
617
618static void
619unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
620{
621   const GLushort *s = ((const GLushort *) src);
622   GLuint i;
623   for (i = 0; i < n; i++) {
624      dst[i][0] =
625      dst[i][1] =
626      dst[i][2] = s[i] * (1.0F / 65535.0F);
627      dst[i][3] = 1.0F;
628   }
629}
630
631static void
632unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n)
633{
634   unpack_S8_Z24(src, dst, n);
635}
636
637static void
638unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n)
639{
640   unpack_Z24_S8(src, dst, n);
641}
642
643static void
644unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
645{
646   const GLuint *s = ((const GLuint *) src);
647   GLuint i;
648   for (i = 0; i < n; i++) {
649      dst[i][0] =
650      dst[i][1] =
651      dst[i][2] = s[i] * (1.0F / 0xffffffff);
652      dst[i][3] = 1.0F;
653   }
654}
655
656static void
657unpack_Z32_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
658{
659   const GLfloat *s = ((const GLfloat *) src);
660   GLuint i;
661   for (i = 0; i < n; i++) {
662      dst[i][0] =
663      dst[i][1] =
664      dst[i][2] = s[i * 2];
665      dst[i][3] = 1.0F;
666   }
667}
668
669static void
670unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[][4], GLuint n)
671{
672   const GLfloat *s = ((const GLfloat *) src);
673   GLuint i;
674   for (i = 0; i < n; i++) {
675      dst[i][0] =
676      dst[i][1] =
677      dst[i][2] = s[i];
678      dst[i][3] = 1.0F;
679   }
680}
681
682
683static void
684unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
685{
686   /* should never be used */
687   GLuint i;
688   for (i = 0; i < n; i++) {
689      dst[i][0] =
690      dst[i][1] =
691      dst[i][2] = 0.0F;
692      dst[i][3] = 1.0F;
693   }
694}
695
696
697static void
698unpack_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
699{
700   const GLubyte *s = (const GLubyte *) src;
701   GLuint i;
702   for (i = 0; i < n; i++) {
703      dst[i][RCOMP] = nonlinear_to_linear(s[i*3+2]);
704      dst[i][GCOMP] = nonlinear_to_linear(s[i*3+1]);
705      dst[i][BCOMP] = nonlinear_to_linear(s[i*3+0]);
706      dst[i][ACOMP] = 1.0F;
707   }
708}
709
710static void
711unpack_SRGBA8(const void *src, GLfloat dst[][4], GLuint n)
712{
713   const GLuint *s = ((const GLuint *) src);
714   GLuint i;
715   for (i = 0; i < n; i++) {
716      dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 24) );
717      dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff );
718      dst[i][BCOMP] = nonlinear_to_linear( (s[i] >>  8) & 0xff );
719      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
720   }
721}
722
723static void
724unpack_SARGB8(const void *src, GLfloat dst[][4], GLuint n)
725{
726   const GLuint *s = ((const GLuint *) src);
727   GLuint i;
728   for (i = 0; i < n; i++) {
729      dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff );
730      dst[i][GCOMP] = nonlinear_to_linear( (s[i] >>  8) & 0xff );
731      dst[i][BCOMP] = nonlinear_to_linear( (s[i]      ) & 0xff );
732      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
733   }
734}
735
736static void
737unpack_SL8(const void *src, GLfloat dst[][4], GLuint n)
738{
739   const GLubyte *s = ((const GLubyte *) src);
740   GLuint i;
741   for (i = 0; i < n; i++) {
742      dst[i][RCOMP] =
743      dst[i][GCOMP] =
744      dst[i][BCOMP] = nonlinear_to_linear(s[i]);
745      dst[i][ACOMP] = 1.0F;
746   }
747}
748
749static void
750unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n)
751{
752   const GLubyte *s = (const GLubyte *) src;
753   GLuint i;
754   for (i = 0; i < n; i++) {
755      dst[i][RCOMP] =
756      dst[i][GCOMP] =
757      dst[i][BCOMP] = nonlinear_to_linear(s[i*2+0]);
758      dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i*2+1]); /* linear! */
759   }
760}
761
762static void
763unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
764{
765}
766
767static void
768unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
769{
770}
771
772static void
773unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
774{
775}
776
777static void
778unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
779{
780}
781
782static void
783unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
784{
785}
786
787static void
788unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
789{
790}
791
792static void
793unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
794{
795}
796
797static void
798unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
799{
800}
801
802static void
803unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
804{
805}
806
807static void
808unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
809{
810}
811
812
813static void
814unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
815{
816   const GLfloat *s = (const GLfloat *) src;
817   GLuint i;
818   for (i = 0; i < n; i++) {
819      dst[i][RCOMP] = s[i*4+0];
820      dst[i][GCOMP] = s[i*4+1];
821      dst[i][BCOMP] = s[i*4+2];
822      dst[i][ACOMP] = s[i*4+3];
823   }
824}
825
826static void
827unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
828{
829   const GLhalfARB *s = (const GLhalfARB *) src;
830   GLuint i;
831   for (i = 0; i < n; i++) {
832      dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
833      dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
834      dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
835      dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
836   }
837}
838
839static void
840unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
841{
842   const GLfloat *s = (const GLfloat *) src;
843   GLuint i;
844   for (i = 0; i < n; i++) {
845      dst[i][RCOMP] = s[i*3+0];
846      dst[i][GCOMP] = s[i*3+1];
847      dst[i][BCOMP] = s[i*3+2];
848      dst[i][ACOMP] = 1.0F;
849   }
850}
851
852static void
853unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
854{
855   const GLhalfARB *s = (const GLhalfARB *) src;
856   GLuint i;
857   for (i = 0; i < n; i++) {
858      dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]);
859      dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
860      dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
861      dst[i][ACOMP] = 1.0F;
862   }
863}
864
865static void
866unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
867{
868   const GLfloat *s = (const GLfloat *) src;
869   GLuint i;
870   for (i = 0; i < n; i++) {
871      dst[i][RCOMP] =
872      dst[i][GCOMP] =
873      dst[i][BCOMP] = 0.0F;
874      dst[i][ACOMP] = s[i];
875   }
876}
877
878static void
879unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
880{
881   const GLhalfARB *s = (const GLhalfARB *) src;
882   GLuint i;
883   for (i = 0; i < n; i++) {
884      dst[i][RCOMP] =
885      dst[i][GCOMP] =
886      dst[i][BCOMP] = 0.0F;
887      dst[i][ACOMP] = _mesa_half_to_float(s[i]);
888   }
889}
890
891static void
892unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
893{
894   const GLfloat *s = (const GLfloat *) src;
895   GLuint i;
896   for (i = 0; i < n; i++) {
897      dst[i][RCOMP] =
898      dst[i][GCOMP] =
899      dst[i][BCOMP] = s[i];
900      dst[i][ACOMP] = 1.0F;
901   }
902}
903
904static void
905unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
906{
907   const GLhalfARB *s = (const GLhalfARB *) src;
908   GLuint i;
909   for (i = 0; i < n; i++) {
910      dst[i][RCOMP] =
911      dst[i][GCOMP] =
912      dst[i][BCOMP] = _mesa_half_to_float(s[i]);
913      dst[i][ACOMP] = 1.0F;
914   }
915}
916
917static void
918unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
919{
920   const GLfloat *s = (const GLfloat *) src;
921   GLuint i;
922   for (i = 0; i < n; i++) {
923      dst[i][RCOMP] =
924      dst[i][GCOMP] =
925      dst[i][BCOMP] = s[i*2+0];
926      dst[i][ACOMP] = s[i*2+1];
927   }
928}
929
930static void
931unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
932{
933   const GLhalfARB *s = (const GLhalfARB *) src;
934   GLuint i;
935   for (i = 0; i < n; i++) {
936      dst[i][RCOMP] =
937      dst[i][GCOMP] =
938      dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
939      dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
940   }
941}
942
943static void
944unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
945{
946   const GLfloat *s = (const GLfloat *) src;
947   GLuint i;
948   for (i = 0; i < n; i++) {
949      dst[i][RCOMP] =
950      dst[i][GCOMP] =
951      dst[i][BCOMP] =
952      dst[i][ACOMP] = s[i];
953   }
954}
955
956static void
957unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
958{
959   const GLhalfARB *s = (const GLhalfARB *) src;
960   GLuint i;
961   for (i = 0; i < n; i++) {
962      dst[i][RCOMP] =
963      dst[i][GCOMP] =
964      dst[i][BCOMP] =
965      dst[i][ACOMP] = _mesa_half_to_float(s[i]);
966   }
967}
968
969static void
970unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
971{
972   const GLfloat *s = (const GLfloat *) src;
973   GLuint i;
974   for (i = 0; i < n; i++) {
975      dst[i][RCOMP] = s[i];
976      dst[i][GCOMP] = 0.0F;
977      dst[i][BCOMP] = 0.0F;
978      dst[i][ACOMP] = 1.0F;
979   }
980}
981
982static void
983unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
984{
985   const GLhalfARB *s = (const GLhalfARB *) src;
986   GLuint i;
987   for (i = 0; i < n; i++) {
988      dst[i][RCOMP] = _mesa_half_to_float(s[i]);
989      dst[i][GCOMP] = 0.0F;
990      dst[i][BCOMP] = 0.0F;
991      dst[i][ACOMP] = 1.0F;
992   }
993}
994
995static void
996unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
997{
998   const GLfloat *s = (const GLfloat *) src;
999   GLuint i;
1000   for (i = 0; i < n; i++) {
1001      dst[i][RCOMP] = s[i*2+0];
1002      dst[i][GCOMP] = s[i*2+1];
1003      dst[i][BCOMP] = 0.0F;
1004      dst[i][ACOMP] = 1.0F;
1005   }
1006}
1007
1008static void
1009unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1010{
1011   const GLhalfARB *s = (const GLhalfARB *) src;
1012   GLuint i;
1013   for (i = 0; i < n; i++) {
1014      dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
1015      dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
1016      dst[i][BCOMP] = 0.0F;
1017      dst[i][ACOMP] = 1.0F;
1018   }
1019}
1020
1021
1022static void
1023unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
1024{
1025   const GLbyte *s = (const GLbyte *) src;
1026   GLuint i;
1027   for (i = 0; i < n; i++) {
1028      dst[i][RCOMP] = (GLfloat) s[i*4+0];
1029      dst[i][GCOMP] = (GLfloat) s[i*4+1];
1030      dst[i][BCOMP] = (GLfloat) s[i*4+2];
1031      dst[i][ACOMP] = (GLfloat) s[i*4+3];
1032   }
1033}
1034
1035static void
1036unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
1037{
1038   const GLshort *s = (const GLshort *) src;
1039   GLuint i;
1040   for (i = 0; i < n; i++) {
1041      dst[i][RCOMP] = (GLfloat) s[i*4+0];
1042      dst[i][GCOMP] = (GLfloat) s[i*4+1];
1043      dst[i][BCOMP] = (GLfloat) s[i*4+2];
1044      dst[i][ACOMP] = (GLfloat) s[i*4+3];
1045   }
1046}
1047
1048static void
1049unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1050{
1051   const GLint *s = (const GLint *) src;
1052   GLuint i;
1053   for (i = 0; i < n; i++) {
1054      dst[i][RCOMP] = (GLfloat) s[i*4+0];
1055      dst[i][GCOMP] = (GLfloat) s[i*4+1];
1056      dst[i][BCOMP] = (GLfloat) s[i*4+2];
1057      dst[i][ACOMP] = (GLfloat) s[i*4+3];
1058   }
1059}
1060
1061static void
1062unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1063{
1064   const GLubyte *s = (const GLubyte *) src;
1065   GLuint i;
1066   for (i = 0; i < n; i++) {
1067      dst[i][RCOMP] = (GLfloat) s[i*4+0];
1068      dst[i][GCOMP] = (GLfloat) s[i*4+1];
1069      dst[i][BCOMP] = (GLfloat) s[i*4+2];
1070      dst[i][ACOMP] = (GLfloat) s[i*4+3];
1071   }
1072}
1073
1074static void
1075unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1076{
1077   const GLushort *s = (const GLushort *) src;
1078   GLuint i;
1079   for (i = 0; i < n; i++) {
1080      dst[i][RCOMP] = (GLfloat) s[i*4+0];
1081      dst[i][GCOMP] = (GLfloat) s[i*4+1];
1082      dst[i][BCOMP] = (GLfloat) s[i*4+2];
1083      dst[i][ACOMP] = (GLfloat) s[i*4+3];
1084   }
1085}
1086
1087static void
1088unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1089{
1090   const GLuint *s = (const GLuint *) src;
1091   GLuint i;
1092   for (i = 0; i < n; i++) {
1093      dst[i][RCOMP] = (GLfloat) s[i*4+0];
1094      dst[i][GCOMP] = (GLfloat) s[i*4+1];
1095      dst[i][BCOMP] = (GLfloat) s[i*4+2];
1096      dst[i][ACOMP] = (GLfloat) s[i*4+3];
1097   }
1098}
1099
1100static void
1101unpack_DUDV8(const void *src, GLfloat dst[][4], GLuint n)
1102{
1103   const GLbyte *s = (const GLbyte *) src;
1104   GLuint i;
1105   for (i = 0; i < n; i++) {
1106      dst[i][RCOMP] = BYTE_TO_FLOAT(s[i*2+0]);
1107      dst[i][GCOMP] = BYTE_TO_FLOAT(s[i*2+1]);
1108      dst[i][BCOMP] = 0;
1109      dst[i][ACOMP] = 0;
1110   }
1111}
1112
1113static void
1114unpack_SIGNED_R8(const void *src, GLfloat dst[][4], GLuint n)
1115{
1116   const GLbyte *s = ((const GLbyte *) src);
1117   GLuint i;
1118   for (i = 0; i < n; i++) {
1119      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1120      dst[i][GCOMP] = 0.0F;
1121      dst[i][BCOMP] = 0.0F;
1122      dst[i][ACOMP] = 1.0F;
1123   }
1124}
1125
1126static void
1127unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
1128{
1129   const GLushort *s = ((const GLushort *) src);
1130   GLuint i;
1131   for (i = 0; i < n; i++) {
1132      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1133      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1134      dst[i][BCOMP] = 0.0F;
1135      dst[i][ACOMP] = 1.0F;
1136   }
1137}
1138
1139static void
1140unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
1141{
1142   const GLuint *s = ((const GLuint *) src);
1143   GLuint i;
1144   for (i = 0; i < n; i++) {
1145      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1146      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1147      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
1148      dst[i][ACOMP] = 1.0f;
1149   }
1150}
1151
1152static void
1153unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
1154{
1155   const GLuint *s = ((const GLuint *) src);
1156   GLuint i;
1157   for (i = 0; i < n; i++) {
1158      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1159      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1160      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
1161      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i]      ) );
1162   }
1163}
1164
1165static void
1166unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
1167{
1168   const GLuint *s = ((const GLuint *) src);
1169   GLuint i;
1170   for (i = 0; i < n; i++) {
1171      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i]      ) );
1172      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
1173      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1174      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1175   }
1176}
1177
1178static void
1179unpack_SIGNED_R16(const void *src, GLfloat dst[][4], GLuint n)
1180{
1181   const GLshort *s = ((const GLshort *) src);
1182   GLuint i;
1183   for (i = 0; i < n; i++) {
1184      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1185      dst[i][GCOMP] = 0.0F;
1186      dst[i][BCOMP] = 0.0F;
1187      dst[i][ACOMP] = 1.0F;
1188   }
1189}
1190
1191static void
1192unpack_SIGNED_GR1616(const void *src, GLfloat dst[][4], GLuint n)
1193{
1194   const GLuint *s = ((const GLuint *) src);
1195   GLuint i;
1196   for (i = 0; i < n; i++) {
1197      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] & 0xffff );
1198      dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i] >> 16 );
1199      dst[i][BCOMP] = 0.0F;
1200      dst[i][ACOMP] = 1.0F;
1201   }
1202}
1203
1204static void
1205unpack_SIGNED_RGB_16(const void *src, GLfloat dst[][4], GLuint n)
1206{
1207   const GLshort *s = (const GLshort *) src;
1208   GLuint i;
1209   for (i = 0; i < n; i++) {
1210      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] );
1211      dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
1212      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
1213      dst[i][ACOMP] = 1.0F;
1214   }
1215}
1216
1217static void
1218unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1219{
1220   const GLshort *s = (const GLshort *) src;
1221   GLuint i;
1222   for (i = 0; i < n; i++) {
1223      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
1224      dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
1225      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
1226      dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
1227   }
1228}
1229
1230static void
1231unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1232{
1233   const GLushort *s = (const GLushort *) src;
1234   GLuint i;
1235   for (i = 0; i < n; i++) {
1236      dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
1237      dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
1238      dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
1239      dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
1240   }
1241}
1242
1243static void
1244unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1245{
1246   /* XXX to do */
1247}
1248
1249static void
1250unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1251{
1252   /* XXX to do */
1253}
1254
1255static void
1256unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1257{
1258   /* XXX to do */
1259}
1260
1261static void
1262unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1263{
1264   /* XXX to do */
1265}
1266
1267static void
1268unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1269{
1270   /* XXX to do */
1271}
1272
1273static void
1274unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1275{
1276   /* XXX to do */
1277}
1278
1279static void
1280unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1281{
1282   /* XXX to do */
1283}
1284
1285static void
1286unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1287{
1288   /* XXX to do */
1289}
1290
1291static void
1292unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n)
1293{
1294   const GLbyte *s = ((const GLbyte *) src);
1295   GLuint i;
1296   for (i = 0; i < n; i++) {
1297      dst[i][RCOMP] = 0.0F;
1298      dst[i][GCOMP] = 0.0F;
1299      dst[i][BCOMP] = 0.0F;
1300      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1301   }
1302}
1303
1304static void
1305unpack_SIGNED_L8(const void *src, GLfloat dst[][4], GLuint n)
1306{
1307   const GLbyte *s = ((const GLbyte *) src);
1308   GLuint i;
1309   for (i = 0; i < n; i++) {
1310      dst[i][RCOMP] =
1311      dst[i][GCOMP] =
1312      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1313      dst[i][ACOMP] = 1.0F;
1314   }
1315}
1316
1317static void
1318unpack_SIGNED_AL88(const void *src, GLfloat dst[][4], GLuint n)
1319{
1320   const GLshort *s = ((const GLshort *) src);
1321   GLuint i;
1322   for (i = 0; i < n; i++) {
1323      dst[i][RCOMP] =
1324      dst[i][GCOMP] =
1325      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1326      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1327   }
1328}
1329
1330static void
1331unpack_SIGNED_I8(const void *src, GLfloat dst[][4], GLuint n)
1332{
1333   const GLbyte *s = ((const GLbyte *) src);
1334   GLuint i;
1335   for (i = 0; i < n; i++) {
1336      dst[i][RCOMP] =
1337      dst[i][GCOMP] =
1338      dst[i][BCOMP] =
1339      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1340   }
1341}
1342
1343static void
1344unpack_SIGNED_A16(const void *src, GLfloat dst[][4], GLuint n)
1345{
1346   const GLshort *s = ((const GLshort *) src);
1347   GLuint i;
1348   for (i = 0; i < n; i++) {
1349      dst[i][RCOMP] = 0.0F;
1350      dst[i][GCOMP] = 0.0F;
1351      dst[i][BCOMP] = 0.0F;
1352      dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1353   }
1354}
1355
1356static void
1357unpack_SIGNED_L16(const void *src, GLfloat dst[][4], GLuint n)
1358{
1359   const GLshort *s = ((const GLshort *) src);
1360   GLuint i;
1361   for (i = 0; i < n; i++) {
1362      dst[i][RCOMP] =
1363      dst[i][GCOMP] =
1364      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1365      dst[i][ACOMP] = 1.0F;
1366   }
1367}
1368
1369static void
1370unpack_SIGNED_AL1616(const void *src, GLfloat dst[][4], GLuint n)
1371{
1372   const GLshort *s = (const GLshort *) src;
1373   GLuint i;
1374   for (i = 0; i < n; i++) {
1375      dst[i][RCOMP] =
1376      dst[i][GCOMP] =
1377      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
1378      dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
1379   }
1380}
1381
1382static void
1383unpack_SIGNED_I16(const void *src, GLfloat dst[][4], GLuint n)
1384{
1385   const GLshort *s = ((const GLshort *) src);
1386   GLuint i;
1387   for (i = 0; i < n; i++) {
1388      dst[i][RCOMP] =
1389      dst[i][GCOMP] =
1390      dst[i][BCOMP] =
1391      dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1392   }
1393}
1394
1395static void
1396unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
1397{
1398   const GLuint *s = (const GLuint *) src;
1399   GLuint i;
1400   for (i = 0; i < n; i++) {
1401      rgb9e5_to_float3(s[i], dst[i]);
1402      dst[i][ACOMP] = 1.0F;
1403   }
1404}
1405
1406static void
1407unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
1408{
1409   const GLuint *s = (const GLuint *) src;
1410   GLuint i;
1411   for (i = 0; i < n; i++) {
1412      r11g11b10f_to_float3(s[i], dst[i]);
1413      dst[i][ACOMP] = 1.0F;
1414   }
1415}
1416
1417
1418/**
1419 * Return the unpacker function for the given format.
1420 */
1421static unpack_rgba_func
1422get_unpack_rgba_function(gl_format format)
1423{
1424   static unpack_rgba_func table[MESA_FORMAT_COUNT];
1425   static GLboolean initialized = GL_FALSE;
1426
1427   if (!initialized) {
1428      table[MESA_FORMAT_NONE] = NULL;
1429
1430      table[MESA_FORMAT_RGBA8888] = unpack_RGBA8888;
1431      table[MESA_FORMAT_RGBA8888_REV] = unpack_RGBA8888_REV;
1432      table[MESA_FORMAT_ARGB8888] = unpack_ARGB8888;
1433      table[MESA_FORMAT_ARGB8888_REV] = unpack_ARGB8888_REV;
1434      table[MESA_FORMAT_RGBX8888] = unpack_RGBX8888;
1435      table[MESA_FORMAT_RGBX8888_REV] = unpack_RGBX8888_REV;
1436      table[MESA_FORMAT_XRGB8888] = unpack_XRGB8888;
1437      table[MESA_FORMAT_XRGB8888_REV] = unpack_XRGB8888_REV;
1438      table[MESA_FORMAT_RGB888] = unpack_RGB888;
1439      table[MESA_FORMAT_BGR888] = unpack_BGR888;
1440      table[MESA_FORMAT_RGB565] = unpack_RGB565;
1441      table[MESA_FORMAT_RGB565_REV] = unpack_RGB565_REV;
1442      table[MESA_FORMAT_ARGB4444] = unpack_ARGB4444;
1443      table[MESA_FORMAT_ARGB4444_REV] = unpack_ARGB4444_REV;
1444      table[MESA_FORMAT_RGBA5551] = unpack_RGBA5551;
1445      table[MESA_FORMAT_ARGB1555] = unpack_ARGB1555;
1446      table[MESA_FORMAT_ARGB1555_REV] = unpack_ARGB1555_REV;
1447      table[MESA_FORMAT_AL44] = unpack_AL44;
1448      table[MESA_FORMAT_AL88] = unpack_AL88;
1449      table[MESA_FORMAT_AL88_REV] = unpack_AL88_REV;
1450      table[MESA_FORMAT_AL1616] = unpack_AL1616;
1451      table[MESA_FORMAT_AL1616_REV] = unpack_AL1616_REV;
1452      table[MESA_FORMAT_RGB332] = unpack_RGB332;
1453      table[MESA_FORMAT_A8] = unpack_A8;
1454      table[MESA_FORMAT_A16] = unpack_A16;
1455      table[MESA_FORMAT_L8] = unpack_L8;
1456      table[MESA_FORMAT_L16] = unpack_L16;
1457      table[MESA_FORMAT_I8] = unpack_I8;
1458      table[MESA_FORMAT_I16] = unpack_I16;
1459      table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
1460      table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
1461      table[MESA_FORMAT_R8] = unpack_R8;
1462      table[MESA_FORMAT_RG88] = unpack_RG88;
1463      table[MESA_FORMAT_RG88_REV] = unpack_RG88_REV;
1464      table[MESA_FORMAT_R16] = unpack_R16;
1465      table[MESA_FORMAT_RG1616] = unpack_RG1616;
1466      table[MESA_FORMAT_RG1616_REV] = unpack_RG1616_REV;
1467      table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010;
1468      table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8;
1469      table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24;
1470      table[MESA_FORMAT_Z16] = unpack_Z16;
1471      table[MESA_FORMAT_X8_Z24] = unpack_X8_Z24;
1472      table[MESA_FORMAT_Z24_X8] = unpack_Z24_X8;
1473      table[MESA_FORMAT_Z32] = unpack_Z32;
1474      table[MESA_FORMAT_S8] = unpack_S8;
1475      table[MESA_FORMAT_SRGB8] = unpack_SRGB8;
1476      table[MESA_FORMAT_SRGBA8] = unpack_SRGBA8;
1477      table[MESA_FORMAT_SARGB8] = unpack_SARGB8;
1478      table[MESA_FORMAT_SL8] = unpack_SL8;
1479      table[MESA_FORMAT_SLA8] = unpack_SLA8;
1480      table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
1481      table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
1482      table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
1483      table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
1484
1485      table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
1486      table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
1487      table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
1488      table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
1489      table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
1490      table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
1491
1492      table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
1493      table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
1494      table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
1495      table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
1496      table[MESA_FORMAT_ALPHA_FLOAT32] = unpack_ALPHA_FLOAT32;
1497      table[MESA_FORMAT_ALPHA_FLOAT16] = unpack_ALPHA_FLOAT16;
1498      table[MESA_FORMAT_LUMINANCE_FLOAT32] = unpack_LUMINANCE_FLOAT32;
1499      table[MESA_FORMAT_LUMINANCE_FLOAT16] = unpack_LUMINANCE_FLOAT16;
1500      table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = unpack_LUMINANCE_ALPHA_FLOAT32;
1501      table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = unpack_LUMINANCE_ALPHA_FLOAT16;
1502      table[MESA_FORMAT_INTENSITY_FLOAT32] = unpack_INTENSITY_FLOAT32;
1503      table[MESA_FORMAT_INTENSITY_FLOAT16] = unpack_INTENSITY_FLOAT16;
1504      table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
1505      table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
1506      table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
1507      table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
1508
1509      table[MESA_FORMAT_RGBA_INT8] = unpack_RGBA_INT8;
1510      table[MESA_FORMAT_RGBA_INT16] = unpack_RGBA_INT16;
1511      table[MESA_FORMAT_RGBA_INT32] = unpack_RGBA_INT32;
1512      table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
1513      table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
1514      table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
1515
1516      table[MESA_FORMAT_DUDV8] = unpack_DUDV8;
1517      table[MESA_FORMAT_SIGNED_R8] = unpack_SIGNED_R8;
1518      table[MESA_FORMAT_SIGNED_RG88_REV] = unpack_SIGNED_RG88_REV;
1519      table[MESA_FORMAT_SIGNED_RGBX8888] = unpack_SIGNED_RGBX8888;
1520      table[MESA_FORMAT_SIGNED_RGBA8888] = unpack_SIGNED_RGBA8888;
1521      table[MESA_FORMAT_SIGNED_RGBA8888_REV] = unpack_SIGNED_RGBA8888_REV;
1522      table[MESA_FORMAT_SIGNED_R16] = unpack_SIGNED_R16;
1523      table[MESA_FORMAT_SIGNED_GR1616] = unpack_SIGNED_GR1616;
1524      table[MESA_FORMAT_SIGNED_RGB_16] = unpack_SIGNED_RGB_16;
1525      table[MESA_FORMAT_SIGNED_RGBA_16] = unpack_SIGNED_RGBA_16;
1526      table[MESA_FORMAT_RGBA_16] = unpack_RGBA_16;
1527
1528      table[MESA_FORMAT_RED_RGTC1] = unpack_RED_RGTC1;
1529      table[MESA_FORMAT_SIGNED_RED_RGTC1] = unpack_SIGNED_RED_RGTC1;
1530      table[MESA_FORMAT_RG_RGTC2] = unpack_RG_RGTC2;
1531      table[MESA_FORMAT_SIGNED_RG_RGTC2] = unpack_SIGNED_RG_RGTC2;
1532
1533      table[MESA_FORMAT_L_LATC1] = unpack_L_LATC1;
1534      table[MESA_FORMAT_SIGNED_L_LATC1] = unpack_SIGNED_L_LATC1;
1535      table[MESA_FORMAT_LA_LATC2] = unpack_LA_LATC2;
1536      table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_LA_LATC2;
1537
1538      table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8;
1539      table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8;
1540      table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88;
1541      table[MESA_FORMAT_SIGNED_I8] = unpack_SIGNED_I8;
1542      table[MESA_FORMAT_SIGNED_A16] = unpack_SIGNED_A16;
1543      table[MESA_FORMAT_SIGNED_L16] = unpack_SIGNED_L16;
1544      table[MESA_FORMAT_SIGNED_AL1616] = unpack_SIGNED_AL1616;
1545      table[MESA_FORMAT_SIGNED_I16] = unpack_SIGNED_I16;
1546
1547      table[MESA_FORMAT_RGB9_E5_FLOAT] = unpack_RGB9_E5_FLOAT;
1548      table[MESA_FORMAT_R11_G11_B10_FLOAT] = unpack_R11_G11_B10_FLOAT;
1549
1550      table[MESA_FORMAT_Z32_FLOAT] = unpack_Z32_FLOAT;
1551      table[MESA_FORMAT_Z32_FLOAT_X24S8] = unpack_Z32_FLOAT_X24S8;
1552
1553      initialized = GL_TRUE;
1554   }
1555
1556   return table[format];
1557}
1558
1559
1560void
1561_mesa_unpack_rgba_row(gl_format format, GLuint n,
1562                      const void *src, GLfloat dst[][4])
1563{
1564   unpack_rgba_func unpack = get_unpack_rgba_function(format);
1565   unpack(src, dst, n);
1566}
1567
1568static void
1569unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1570{
1571   memcpy(dst, src, n * 4 * sizeof(GLuint));
1572}
1573
1574static void
1575unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1576{
1577   unsigned int i;
1578
1579   for (i = 0; i < n; i++) {
1580      dst[i][0] = src[i * 3 + 0];
1581      dst[i][1] = src[i * 3 + 1];
1582      dst[i][2] = src[i * 3 + 2];
1583      dst[i][3] = 1;
1584   }
1585}
1586
1587static void
1588unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1589{
1590   unsigned int i;
1591
1592   for (i = 0; i < n; i++) {
1593      dst[i][0] = src[i * 2 + 0];
1594      dst[i][1] = src[i * 2 + 1];
1595      dst[i][2] = 0;
1596      dst[i][3] = 1;
1597   }
1598}
1599
1600static void
1601unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1602{
1603   unsigned int i;
1604
1605   for (i = 0; i < n; i++) {
1606      dst[i][0] = src[i];
1607      dst[i][1] = 0;
1608      dst[i][2] = 0;
1609      dst[i][3] = 1;
1610   }
1611}
1612
1613static void
1614unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1615{
1616   unsigned int i;
1617
1618   for (i = 0; i < n; i++) {
1619      dst[i][0] = dst[i][1] = dst[i][2] = src[i];
1620      dst[i][3] = 1;
1621   }
1622}
1623
1624static void
1625unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1626{
1627   unsigned int i;
1628
1629   for (i = 0; i < n; i++) {
1630      dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
1631      dst[i][3] = src[i * 2 + 1];
1632   }
1633}
1634
1635static void
1636unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1637{
1638   unsigned int i;
1639
1640   for (i = 0; i < n; i++) {
1641      dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
1642   }
1643}
1644
1645static void
1646unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
1647{
1648   unsigned int i;
1649
1650   for (i = 0; i < n; i++) {
1651      GLuint tmp = src[i];
1652      dst[i][0] = (tmp >> 20) & 0x3ff;
1653      dst[i][1] = (tmp >> 10) & 0x3ff;
1654      dst[i][2] = (tmp >> 0) & 0x3ff;
1655      dst[i][3] = (tmp >> 30) & 0x3;
1656   }
1657}
1658
1659void
1660_mesa_unpack_int_rgba_row(gl_format format, GLuint n,
1661			  const void *src, GLuint dst[][4])
1662{
1663   switch (format) {
1664      /* Since there won't be any sign extension happening, there's no need to
1665       * make separate paths for 32-bit-to-32-bit integer unpack.
1666       */
1667   case MESA_FORMAT_RGBA_UINT32:
1668   case MESA_FORMAT_RGBA_INT32:
1669      unpack_int_rgba_RGBA_UINT32(src, dst, n);
1670      break;
1671   case MESA_FORMAT_RGB_UINT32:
1672   case MESA_FORMAT_RGB_INT32:
1673      unpack_int_rgba_RGB_UINT32(src, dst, n);
1674      break;
1675   case MESA_FORMAT_RG_UINT32:
1676   case MESA_FORMAT_RG_INT32:
1677      unpack_int_rgba_RG_UINT32(src, dst, n);
1678      break;
1679   case MESA_FORMAT_R_UINT32:
1680   case MESA_FORMAT_R_INT32:
1681      unpack_int_rgba_R_UINT32(src, dst, n);
1682      break;
1683
1684   case MESA_FORMAT_LUMINANCE_UINT32:
1685   case MESA_FORMAT_LUMINANCE_INT32:
1686      unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
1687      break;
1688   case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
1689   case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
1690      unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
1691      break;
1692   case MESA_FORMAT_INTENSITY_UINT32:
1693   case MESA_FORMAT_INTENSITY_INT32:
1694      unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
1695      break;
1696
1697   case MESA_FORMAT_ARGB2101010_UINT:
1698      unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
1699      break;
1700   default:
1701      _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
1702                    _mesa_get_format_name(format));
1703      return;
1704   }
1705}
1706
1707/**
1708 * Unpack a 2D rect of pixels returning float RGBA colors.
1709 * \param format  the source image format
1710 * \param src  start address of the source image
1711 * \param srcRowStride  source image row stride in bytes
1712 * \param dst  start address of the dest image
1713 * \param dstRowStride  dest image row stride in bytes
1714 * \param x  source image start X pos
1715 * \param y  source image start Y pos
1716 * \param width  width of rect region to convert
1717 * \param height  height of rect region to convert
1718 */
1719void
1720_mesa_unpack_rgba_block(gl_format format,
1721                        const void *src, GLint srcRowStride,
1722                        GLfloat dst[][4], GLint dstRowStride,
1723                        GLuint x, GLuint y, GLuint width, GLuint height)
1724{
1725   unpack_rgba_func unpack = get_unpack_rgba_function(format);
1726   const GLuint srcPixStride = _mesa_get_format_bytes(format);
1727   const GLuint dstPixStride = 4 * sizeof(GLfloat);
1728   const GLubyte *srcRow;
1729   GLubyte *dstRow;
1730   GLuint i;
1731
1732   /* XXX needs to be fixed for compressed formats */
1733
1734   srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
1735   dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
1736
1737   for (i = 0; i < height; i++) {
1738      unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
1739
1740      dstRow += dstRowStride;
1741      srcRow += srcRowStride;
1742   }
1743}
1744
1745
1746
1747
1748typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
1749
1750static void
1751unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
1752{
1753   /* only return Z, not stencil data */
1754   const GLuint *s = ((const GLuint *) src);
1755   const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1756   GLuint i;
1757   for (i = 0; i < n; i++) {
1758      dst[i] = (s[i] >> 8) * scale;
1759      ASSERT(dst[i] >= 0.0F);
1760      ASSERT(dst[i] <= 1.0F);
1761   }
1762}
1763
1764static void
1765unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
1766{
1767   /* only return Z, not stencil data */
1768   const GLuint *s = ((const GLuint *) src);
1769   const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1770   GLuint i;
1771   for (i = 0; i < n; i++) {
1772      dst[i] = (s[i] & 0x00ffffff) * scale;
1773      ASSERT(dst[i] >= 0.0F);
1774      ASSERT(dst[i] <= 1.0F);
1775   }
1776}
1777
1778static void
1779unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst)
1780{
1781   const GLushort *s = ((const GLushort *) src);
1782   GLuint i;
1783   for (i = 0; i < n; i++) {
1784      dst[i] = s[i] * (1.0F / 65535.0F);
1785   }
1786}
1787
1788static void
1789unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst)
1790{
1791   const GLuint *s = ((const GLuint *) src);
1792   GLuint i;
1793   for (i = 0; i < n; i++) {
1794      dst[i] = s[i] * (1.0F / 0xffffffff);
1795   }
1796}
1797
1798static void
1799unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst)
1800{
1801   memcpy(dst, src, n * sizeof(float));
1802}
1803
1804static void
1805unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
1806{
1807   const GLfloat *s = ((const GLfloat *) src);
1808   GLuint i;
1809   for (i = 0; i < n; i++) {
1810      dst[i] = s[i * 2];
1811   }
1812}
1813
1814
1815
1816void
1817_mesa_unpack_float_z_row(gl_format format, GLuint n,
1818                         const void *src, GLfloat *dst)
1819{
1820   unpack_float_z_func unpack;
1821
1822   switch (format) {
1823   case MESA_FORMAT_Z24_S8:
1824   case MESA_FORMAT_Z24_X8:
1825      unpack = unpack_float_z_Z24_X8;
1826      break;
1827   case MESA_FORMAT_S8_Z24:
1828   case MESA_FORMAT_X8_Z24:
1829      unpack = unpack_float_z_X8_Z24;
1830      break;
1831   case MESA_FORMAT_Z16:
1832      unpack = unpack_float_z_Z16;
1833      break;
1834   case MESA_FORMAT_Z32:
1835      unpack = unpack_float_z_Z32;
1836      break;
1837   case MESA_FORMAT_Z32_FLOAT:
1838      unpack = unpack_float_z_Z32F;
1839      break;
1840   case MESA_FORMAT_Z32_FLOAT_X24S8:
1841      unpack = unpack_float_z_Z32X24S8;
1842      break;
1843   default:
1844      _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
1845                    _mesa_get_format_name(format));
1846      return;
1847   }
1848
1849   unpack(n, src, dst);
1850}
1851
1852
1853
1854typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
1855
1856static void
1857unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
1858{
1859   /* only return Z, not stencil data */
1860   const GLuint *s = ((const GLuint *) src);
1861   GLuint i;
1862   for (i = 0; i < n; i++) {
1863      dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
1864   }
1865}
1866
1867static void
1868unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
1869{
1870   /* only return Z, not stencil data */
1871   const GLuint *s = ((const GLuint *) src);
1872   GLuint i;
1873   for (i = 0; i < n; i++) {
1874      dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
1875   }
1876}
1877
1878static void
1879unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n)
1880{
1881   const GLushort *s = ((const GLushort *)src);
1882   GLuint i;
1883   for (i = 0; i < n; i++) {
1884      dst[i] = (s[i] << 16) | s[i];
1885   }
1886}
1887
1888static void
1889unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
1890{
1891   memcpy(dst, src, n * sizeof(GLuint));
1892}
1893
1894
1895void
1896_mesa_unpack_uint_z_row(gl_format format, GLuint n,
1897                        const void *src, GLuint *dst)
1898{
1899   unpack_uint_z_func unpack;
1900   const GLubyte *srcPtr = (GLubyte *) src;
1901
1902   switch (format) {
1903   case MESA_FORMAT_Z24_S8:
1904   case MESA_FORMAT_Z24_X8:
1905      unpack = unpack_uint_z_Z24_X8;
1906      break;
1907   case MESA_FORMAT_S8_Z24:
1908   case MESA_FORMAT_X8_Z24:
1909      unpack = unpack_uint_z_X8_Z24;
1910      break;
1911   case MESA_FORMAT_Z16:
1912      unpack = unpack_uint_z_Z16;
1913      break;
1914   case MESA_FORMAT_Z32:
1915      unpack = unpack_uint_z_Z32;
1916      break;
1917   default:
1918      _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
1919                    _mesa_get_format_name(format));
1920      return;
1921   }
1922
1923   unpack(srcPtr, dst, n);
1924}
1925
1926
1927static void
1928unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
1929{
1930   memcpy(dst, src, n);
1931}
1932
1933static void
1934unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n)
1935{
1936   GLuint i;
1937   const GLuint *src32 = src;
1938
1939   for (i = 0; i < n; i++)
1940      dst[i] = src32[i] & 0xff;
1941}
1942
1943static void
1944unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n)
1945{
1946   GLuint i;
1947   const GLuint *src32 = src;
1948
1949   for (i = 0; i < n; i++)
1950      dst[i] = src32[i] >> 24;
1951}
1952
1953static void
1954unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n)
1955{
1956   GLuint i;
1957   const GLuint *src32 = src;
1958
1959   for (i = 0; i < n; i++)
1960      dst[i] = src32[i * 2 + 1] & 0xff;
1961}
1962
1963void
1964_mesa_unpack_ubyte_stencil_row(gl_format format, GLuint n,
1965			       const void *src, GLubyte *dst)
1966{
1967   switch (format) {
1968   case MESA_FORMAT_S8:
1969      unpack_ubyte_s_S8(src, dst, n);
1970      break;
1971   case MESA_FORMAT_Z24_S8:
1972      unpack_ubyte_s_Z24_S8(src, dst, n);
1973      break;
1974   case MESA_FORMAT_S8_Z24:
1975      unpack_ubyte_s_S8_Z24(src, dst, n);
1976      break;
1977   case MESA_FORMAT_Z32_FLOAT_X24S8:
1978      unpack_ubyte_s_Z32_FLOAT_X24S8(src, dst, n);
1979      break;
1980   default:
1981      _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
1982                    _mesa_get_format_name(format));
1983      return;
1984   }
1985}
1986
1987static void
1988unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint *src, GLuint *dst, GLuint n)
1989{
1990   GLuint i;
1991
1992   for (i = 0; i < n; i++) {
1993      GLuint val = src[i];
1994      dst[i] = val >> 24 | val << 8;
1995   }
1996}
1997
1998static void
1999unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint *src, GLuint *dst, GLuint n)
2000{
2001   memcpy(dst, src, n * 4);
2002}
2003
2004void
2005_mesa_unpack_uint_24_8_depth_stencil_row(gl_format format, GLuint n,
2006					 const void *src, GLuint *dst)
2007{
2008   switch (format) {
2009   case MESA_FORMAT_Z24_S8:
2010      unpack_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
2011      break;
2012   case MESA_FORMAT_S8_Z24:
2013      unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
2014      break;
2015   default:
2016      _mesa_problem(NULL,
2017                    "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
2018                    _mesa_get_format_name(format));
2019      return;
2020   }
2021}
2022