~ubuntu-branches/ubuntu/precise/mesa/precise-updates

« back to all changes in this revision

Viewing changes to src/mesa/main/format_unpack.c

  • Committer: Package Import Robot
  • Author(s): Robert Hooker
  • Date: 2012-02-02 12:05:48 UTC
  • mfrom: (1.7.1) (3.3.27 sid)
  • Revision ID: package-import@ubuntu.com-20120202120548-nvkma85jq0h4coix
Tags: 8.0~rc2-0ubuntu4
Drop drisearchdir handling, it is no longer needed with multiarch
and dri-alternates being removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
/* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
 
34
 
 
35
#define EXPAND_1_8(X)  ( (X) ? 0xff : 0x0 )
 
36
 
 
37
#define EXPAND_2_8(X)  ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
 
38
 
 
39
#define EXPAND_3_8(X)  ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
 
40
 
 
41
#define EXPAND_4_8(X)  ( ((X) << 4) | (X) )
 
42
 
 
43
#define EXPAND_5_8(X)  ( ((X) << 3) | ((X) >> 2) )
 
44
 
 
45
#define EXPAND_6_8(X)  ( ((X) << 2) | ((X) >> 4) )
 
46
 
 
47
 
 
48
/**
 
49
 * Convert an 8-bit sRGB value from non-linear space to a
 
50
 * linear RGB value in [0, 1].
 
51
 * Implemented with a 256-entry lookup table.
 
52
 */
 
53
static inline GLfloat
 
54
nonlinear_to_linear(GLubyte cs8)
 
55
{
 
56
   static GLfloat table[256];
 
57
   static GLboolean tableReady = GL_FALSE;
 
58
   if (!tableReady) {
 
59
      /* compute lookup table now */
 
60
      GLuint i;
 
61
      for (i = 0; i < 256; i++) {
 
62
         const GLfloat cs = UBYTE_TO_FLOAT(i);
 
63
         if (cs <= 0.04045) {
 
64
            table[i] = cs / 12.92f;
 
65
         }
 
66
         else {
 
67
            table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
 
68
         }
 
69
      }
 
70
      tableReady = GL_TRUE;
 
71
   }
 
72
   return table[cs8];
 
73
}
 
74
 
 
75
 
 
76
/**********************************************************************/
 
77
/*  Unpack, returning GLfloat colors                                  */
 
78
/**********************************************************************/
 
79
 
 
80
typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);
 
81
 
 
82
 
 
83
static void
 
84
unpack_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
 
85
{
 
86
   const GLuint *s = ((const GLuint *) src);
 
87
   GLuint i;
 
88
   for (i = 0; i < n; i++) {
 
89
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
 
90
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
 
91
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
 
92
      dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
 
93
   }
 
94
}
 
95
 
 
96
static void
 
97
unpack_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
 
98
{
 
99
   const GLuint *s = ((const GLuint *) src);
 
100
   GLuint i;
 
101
   for (i = 0; i < n; i++) {
 
102
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
 
103
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
 
104
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
 
105
      dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
 
106
   }
 
107
}
 
108
 
 
109
static void
 
110
unpack_ARGB8888(const void *src, GLfloat dst[][4], GLuint n)
 
111
{
 
112
   const GLuint *s = ((const GLuint *) src);
 
113
   GLuint i;
 
114
   for (i = 0; i < n; i++) {
 
115
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
 
116
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
 
117
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
 
118
      dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
 
119
   }
 
120
}
 
121
 
 
122
static void
 
123
unpack_ARGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
 
124
{
 
125
   const GLuint *s = ((const GLuint *) src);
 
126
   GLuint i;
 
127
   for (i = 0; i < n; i++) {
 
128
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
 
129
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
 
130
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
 
131
      dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
 
132
   }
 
133
}
 
134
 
 
135
static void
 
136
unpack_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
 
137
{
 
138
   const GLuint *s = ((const GLuint *) src);
 
139
   GLuint i;
 
140
   for (i = 0; i < n; i++) {
 
141
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
 
142
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
 
143
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
 
144
      dst[i][ACOMP] = 1.0f;
 
145
   }
 
146
}
 
147
 
 
148
static void
 
149
unpack_RGBX8888_REV(const void *src, GLfloat dst[][4], GLuint n)
 
150
{
 
151
   const GLuint *s = ((const GLuint *) src);
 
152
   GLuint i;
 
153
   for (i = 0; i < n; i++) {
 
154
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
 
155
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
 
156
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
 
157
      dst[i][ACOMP] = 1.0f;
 
158
   }
 
159
}
 
160
 
 
161
static void
 
162
unpack_XRGB8888(const void *src, GLfloat dst[][4], GLuint n)
 
163
{
 
164
   const GLuint *s = ((const GLuint *) src);
 
165
   GLuint i;
 
166
   for (i = 0; i < n; i++) {
 
167
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
 
168
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
 
169
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
 
170
      dst[i][ACOMP] = 1.0f;
 
171
   }
 
172
}
 
173
 
 
174
static void
 
175
unpack_XRGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
 
176
{
 
177
   const GLuint *s = ((const GLuint *) src);
 
178
   GLuint i;
 
179
   for (i = 0; i < n; i++) {
 
180
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
 
181
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
 
182
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
 
183
      dst[i][ACOMP] = 1.0f;
 
184
   }
 
185
}
 
186
 
 
187
static void
 
188
unpack_RGB888(const void *src, GLfloat dst[][4], GLuint n)
 
189
{
 
190
   const GLubyte *s = (const GLubyte *) src;
 
191
   GLuint i;
 
192
   for (i = 0; i < n; i++) {
 
193
      dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
 
194
      dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
 
195
      dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
 
196
      dst[i][ACOMP] = 1.0F;
 
197
   }
 
198
}
 
199
 
 
200
static void
 
201
unpack_BGR888(const void *src, GLfloat dst[][4], GLuint n)
 
202
{
 
203
   const GLubyte *s = (const GLubyte *) src;
 
204
   GLuint i;
 
205
   for (i = 0; i < n; i++) {
 
206
      dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
 
207
      dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
 
208
      dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
 
209
      dst[i][ACOMP] = 1.0F;
 
210
   }
 
211
}
 
212
 
 
213
static void
 
214
unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n)
 
215
{
 
216
   const GLushort *s = ((const GLushort *) src);
 
217
   GLuint i;
 
218
   for (i = 0; i < n; i++) {
 
219
      dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
 
220
      dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F);
 
221
      dst[i][BCOMP] = ((s[i]      ) & 0x1f) * (1.0F / 31.0F);
 
222
      dst[i][ACOMP] = 1.0F;
 
223
   }
 
224
}
 
225
 
 
226
static void
 
227
unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n)
 
228
{
 
229
   const GLushort *s = ((const GLushort *) src);
 
230
   GLuint i;
 
231
   for (i = 0; i < n; i++) {
 
232
      GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
 
233
      dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) );
 
234
      dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >>  9) & 0x3) );
 
235
      dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >>  2) & 0x7) );
 
236
      dst[i][ACOMP] = 1.0F;
 
237
   }
 
238
}
 
239
 
 
240
static void
 
241
unpack_ARGB4444(const void *src, GLfloat dst[][4], GLuint n)
 
242
{
 
243
   const GLushort *s = ((const GLushort *) src);
 
244
   GLuint i;
 
245
   for (i = 0; i < n; i++) {
 
246
      dst[i][RCOMP] = ((s[i] >>  8) & 0xf) * (1.0F / 15.0F);
 
247
      dst[i][GCOMP] = ((s[i] >>  4) & 0xf) * (1.0F / 15.0F);
 
248
      dst[i][BCOMP] = ((s[i]      ) & 0xf) * (1.0F / 15.0F);
 
249
      dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
 
250
   }
 
251
}
 
252
 
 
253
static void
 
254
unpack_ARGB4444_REV(const void *src, GLfloat dst[][4], GLuint n)
 
255
{
 
256
   const GLushort *s = ((const GLushort *) src);
 
257
   GLuint i;
 
258
   for (i = 0; i < n; i++) {
 
259
      dst[i][RCOMP] = ((s[i]      ) & 0xf) * (1.0F / 15.0F);
 
260
      dst[i][GCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
 
261
      dst[i][BCOMP] = ((s[i] >>  8) & 0xf) * (1.0F / 15.0F);
 
262
      dst[i][ACOMP] = ((s[i] >>  4) & 0xf) * (1.0F / 15.0F);
 
263
   }
 
264
}
 
265
 
 
266
static void
 
267
unpack_RGBA5551(const void *src, GLfloat dst[][4], GLuint n)
 
268
{
 
269
   const GLushort *s = ((const GLushort *) src);
 
270
   GLuint i;
 
271
   for (i = 0; i < n; i++) {
 
272
      dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
 
273
      dst[i][GCOMP] = ((s[i] >>  6) & 0x1f) * (1.0F / 31.0F);
 
274
      dst[i][BCOMP] = ((s[i] >>  1) & 0x1f) * (1.0F / 31.0F);
 
275
      dst[i][ACOMP] = ((s[i]      ) & 0x01) * 1.0F;
 
276
   }
 
277
}
 
278
 
 
279
static void
 
280
unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n)
 
281
{
 
282
   const GLushort *s = ((const GLushort *) src);
 
283
   GLuint i;
 
284
   for (i = 0; i < n; i++) {
 
285
      dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
 
286
      dst[i][GCOMP] = ((s[i] >>  5) & 0x1f) * (1.0F / 31.0F);
 
287
      dst[i][BCOMP] = ((s[i] >>  0) & 0x1f) * (1.0F / 31.0F);
 
288
      dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F;
 
289
   }
 
290
}
 
291
 
 
292
static void
 
293
unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n)
 
294
{
 
295
   const GLushort *s = ((const GLushort *) src);
 
296
   GLuint i;
 
297
   for (i = 0; i < n; i++) {
 
298
      GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
 
299
      dst[i][RCOMP] = ((tmp >> 10) & 0x1f) * (1.0F / 31.0F);
 
300
      dst[i][GCOMP] = ((tmp >>  5) & 0x1f) * (1.0F / 31.0F);
 
301
      dst[i][BCOMP] = ((tmp >>  0) & 0x1f) * (1.0F / 31.0F);
 
302
      dst[i][ACOMP] = ((tmp >> 15) & 0x01) * 1.0F;
 
303
   }
 
304
}
 
305
 
 
306
static void
 
307
unpack_AL44(const void *src, GLfloat dst[][4], GLuint n)
 
308
{
 
309
   const GLubyte *s = ((const GLubyte *) src);
 
310
   GLuint i;
 
311
   for (i = 0; i < n; i++) {
 
312
      dst[i][RCOMP] =
 
313
      dst[i][GCOMP] =
 
314
      dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
 
315
      dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
 
316
   }
 
317
}
 
318
 
 
319
static void
 
320
unpack_AL88(const void *src, GLfloat dst[][4], GLuint n)
 
321
{
 
322
   const GLushort *s = ((const GLushort *) src);
 
323
   GLuint i;
 
324
   for (i = 0; i < n; i++) {
 
325
      dst[i][RCOMP] = 
 
326
      dst[i][GCOMP] = 
 
327
      dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
 
328
      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
 
329
   }
 
330
}
 
331
 
 
332
static void
 
333
unpack_AL88_REV(const void *src, GLfloat dst[][4], GLuint n)
 
334
{
 
335
   const GLushort *s = ((const GLushort *) src);
 
336
   GLuint i;
 
337
   for (i = 0; i < n; i++) {
 
338
      dst[i][RCOMP] = 
 
339
      dst[i][GCOMP] = 
 
340
      dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
 
341
      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
 
342
   }
 
343
}
 
344
 
 
345
static void
 
346
unpack_AL1616(const void *src, GLfloat dst[][4], GLuint n)
 
347
{
 
348
   const GLuint *s = ((const GLuint *) src);
 
349
   GLuint i;
 
350
   for (i = 0; i < n; i++) {
 
351
      dst[i][RCOMP] =
 
352
      dst[i][GCOMP] =
 
353
      dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
 
354
      dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
 
355
   }
 
356
}
 
357
 
 
358
static void
 
359
unpack_AL1616_REV(const void *src, GLfloat dst[][4], GLuint n)
 
360
{
 
361
   const GLuint *s = ((const GLuint *) src);
 
362
   GLuint i;
 
363
   for (i = 0; i < n; i++) {
 
364
      dst[i][RCOMP] =
 
365
      dst[i][GCOMP] =
 
366
      dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
 
367
      dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
 
368
   }
 
369
}
 
370
 
 
371
static void
 
372
unpack_RGB332(const void *src, GLfloat dst[][4], GLuint n)
 
373
{
 
374
   const GLubyte *s = ((const GLubyte *) src);
 
375
   GLuint i;
 
376
   for (i = 0; i < n; i++) {
 
377
      dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F);
 
378
      dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F);
 
379
      dst[i][BCOMP] = ((s[i]     ) & 0x3) * (1.0F / 3.0F);
 
380
      dst[i][ACOMP] = 1.0F;
 
381
   }
 
382
}
 
383
 
 
384
 
 
385
static void
 
386
unpack_A8(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] =
 
392
      dst[i][GCOMP] =
 
393
      dst[i][BCOMP] = 0.0F;
 
394
      dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
 
395
   }
 
396
}
 
397
 
 
398
static void
 
399
unpack_A16(const void *src, GLfloat dst[][4], GLuint n)
 
400
{
 
401
   const GLushort *s = ((const GLushort *) src);
 
402
   GLuint i;
 
403
   for (i = 0; i < n; i++) {
 
404
      dst[i][RCOMP] =
 
405
      dst[i][GCOMP] =
 
406
      dst[i][BCOMP] = 0.0F;
 
407
      dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
 
408
   }
 
409
}
 
410
 
 
411
static void
 
412
unpack_L8(const void *src, GLfloat dst[][4], GLuint n)
 
413
{
 
414
   const GLubyte *s = ((const GLubyte *) src);
 
415
   GLuint i;
 
416
   for (i = 0; i < n; i++) {
 
417
      dst[i][RCOMP] =
 
418
      dst[i][GCOMP] =
 
419
      dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
 
420
      dst[i][ACOMP] = 1.0F;
 
421
   }
 
422
}
 
423
 
 
424
static void
 
425
unpack_L16(const void *src, GLfloat dst[][4], GLuint n)
 
426
{
 
427
   const GLushort *s = ((const GLushort *) src);
 
428
   GLuint i;
 
429
   for (i = 0; i < n; i++) {
 
430
      dst[i][RCOMP] =
 
431
      dst[i][GCOMP] =
 
432
      dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
 
433
      dst[i][ACOMP] = 1.0F;
 
434
   }
 
435
}
 
436
 
 
437
static void
 
438
unpack_I8(const void *src, GLfloat dst[][4], GLuint n)
 
439
{
 
440
   const GLubyte *s = ((const GLubyte *) src);
 
441
   GLuint i;
 
442
   for (i = 0; i < n; i++) {
 
443
      dst[i][RCOMP] =
 
444
      dst[i][GCOMP] =
 
445
      dst[i][BCOMP] =
 
446
      dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
 
447
   }
 
448
}
 
449
 
 
450
static void
 
451
unpack_I16(const void *src, GLfloat dst[][4], GLuint n)
 
452
{
 
453
   const GLushort *s = ((const GLushort *) src);
 
454
   GLuint i;
 
455
   for (i = 0; i < n; i++) {
 
456
      dst[i][RCOMP] =
 
457
      dst[i][GCOMP] =
 
458
      dst[i][BCOMP] =
 
459
      dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
 
460
   }
 
461
}
 
462
 
 
463
static void
 
464
unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n)
 
465
{
 
466
   GLuint i;
 
467
   for (i = 0; i < n; i++) {
 
468
      const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
 
469
      const GLushort *src1 = src0 + 1;         /* odd */
 
470
      const GLubyte y0 = (*src0 >> 8) & 0xff;  /* luminance */
 
471
      const GLubyte cb = *src0 & 0xff;         /* chroma U */
 
472
      const GLubyte y1 = (*src1 >> 8) & 0xff;  /* luminance */
 
473
      const GLubyte cr = *src1 & 0xff;         /* chroma V */
 
474
      const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
 
475
      GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
 
476
      GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
 
477
      GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
 
478
      r *= (1.0F / 255.0F);
 
479
      g *= (1.0F / 255.0F);
 
480
      b *= (1.0F / 255.0F);
 
481
      dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
 
482
      dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
 
483
      dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
 
484
      dst[i][ACOMP] = 1.0F;
 
485
   }
 
486
}
 
487
 
 
488
static void
 
489
unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
 
490
{
 
491
   GLuint i;
 
492
   for (i = 0; i < n; i++) {
 
493
      const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
 
494
      const GLushort *src1 = src0 + 1;         /* odd */
 
495
      const GLubyte y0 = *src0 & 0xff;         /* luminance */
 
496
      const GLubyte cr = (*src0 >> 8) & 0xff;  /* chroma V */
 
497
      const GLubyte y1 = *src1 & 0xff;         /* luminance */
 
498
      const GLubyte cb = (*src1 >> 8) & 0xff;  /* chroma U */
 
499
      const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
 
500
      GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
 
501
      GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
 
502
      GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
 
503
      r *= (1.0F / 255.0F);
 
504
      g *= (1.0F / 255.0F);
 
505
      b *= (1.0F / 255.0F);
 
506
      dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
 
507
      dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
 
508
      dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
 
509
      dst[i][ACOMP] = 1.0F;
 
510
   }
 
511
}
 
512
 
 
513
static void
 
514
unpack_R8(const void *src, GLfloat dst[][4], GLuint n)
 
515
{
 
516
   const GLubyte *s = ((const GLubyte *) src);
 
517
   GLuint i;
 
518
   for (i = 0; i < n; i++) {
 
519
      dst[i][0] = UBYTE_TO_FLOAT(s[i]);
 
520
      dst[i][1] =
 
521
      dst[i][2] = 0.0F;
 
522
      dst[i][3] = 1.0F;
 
523
   }
 
524
}
 
525
 
 
526
static void
 
527
unpack_GR88(const void *src, GLfloat dst[][4], GLuint n)
 
528
{
 
529
   const GLushort *s = ((const GLushort *) src);
 
530
   GLuint i;
 
531
   for (i = 0; i < n; i++) {
 
532
      dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
 
533
      dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
 
534
      dst[i][BCOMP] = 0.0;
 
535
      dst[i][ACOMP] = 1.0;
 
536
   }
 
537
}
 
538
 
 
539
static void
 
540
unpack_RG88(const void *src, GLfloat dst[][4], GLuint n)
 
541
{
 
542
   const GLushort *s = ((const GLushort *) src);
 
543
   GLuint i;
 
544
   for (i = 0; i < n; i++) {
 
545
      dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
 
546
      dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
 
547
      dst[i][BCOMP] = 0.0;
 
548
      dst[i][ACOMP] = 1.0;
 
549
   }
 
550
}
 
551
 
 
552
static void
 
553
unpack_R16(const void *src, GLfloat dst[][4], GLuint n)
 
554
{
 
555
   const GLushort *s = ((const GLushort *) src);
 
556
   GLuint i;
 
557
   for (i = 0; i < n; i++) {
 
558
      dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]);
 
559
      dst[i][GCOMP] = 0.0;
 
560
      dst[i][BCOMP] = 0.0;
 
561
      dst[i][ACOMP] = 1.0;
 
562
   }
 
563
}
 
564
 
 
565
static void
 
566
unpack_RG1616(const void *src, GLfloat dst[][4], GLuint n)
 
567
{
 
568
   const GLuint *s = ((const GLuint *) src);
 
569
   GLuint i;
 
570
   for (i = 0; i < n; i++) {
 
571
      dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
 
572
      dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
 
573
      dst[i][BCOMP] = 0.0;
 
574
      dst[i][ACOMP] = 1.0;
 
575
   }
 
576
}
 
577
 
 
578
static void
 
579
unpack_RG1616_REV(const void *src, GLfloat dst[][4], GLuint n)
 
580
{
 
581
   const GLuint *s = ((const GLuint *) src);
 
582
   GLuint i;
 
583
   for (i = 0; i < n; i++) {
 
584
      dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
 
585
      dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
 
586
      dst[i][BCOMP] = 0.0;
 
587
      dst[i][ACOMP] = 1.0;
 
588
   }
 
589
}
 
590
 
 
591
static void
 
592
unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n)
 
593
{
 
594
   const GLuint *s = ((const GLuint *) src);
 
595
   GLuint i;
 
596
   for (i = 0; i < n; i++) {
 
597
      dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
 
598
      dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
 
599
      dst[i][BCOMP] = ((s[i] >>  0) & 0x3ff) * (1.0F / 1023.0F);
 
600
      dst[i][ACOMP] = ((s[i] >> 30) &  0x03) * (1.0F / 3.0F);
 
601
   }
 
602
}
 
603
 
 
604
 
 
605
static void
 
606
unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
 
607
{
 
608
   /* only return Z, not stencil data */
 
609
   const GLuint *s = ((const GLuint *) src);
 
610
   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
 
611
   GLuint i;
 
612
   for (i = 0; i < n; i++) {
 
613
      dst[i][0] =
 
614
      dst[i][1] =
 
615
      dst[i][2] = (s[i] >> 8) * scale;
 
616
      dst[i][3] = 1.0F;
 
617
      ASSERT(dst[i][0] >= 0.0F);
 
618
      ASSERT(dst[i][0] <= 1.0F);
 
619
   }
 
620
}
 
621
 
 
622
static void
 
623
unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
 
624
{
 
625
   /* only return Z, not stencil data */
 
626
   const GLuint *s = ((const GLuint *) src);
 
627
   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
 
628
   GLuint i;
 
629
   for (i = 0; i < n; i++) {
 
630
      dst[i][0] =
 
631
      dst[i][1] =
 
632
      dst[i][2] = (s[i] & 0x00ffffff) * scale;
 
633
      dst[i][3] = 1.0F;
 
634
      ASSERT(dst[i][0] >= 0.0F);
 
635
      ASSERT(dst[i][0] <= 1.0F);
 
636
   }
 
637
}
 
638
 
 
639
static void
 
640
unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
 
641
{
 
642
   const GLushort *s = ((const GLushort *) src);
 
643
   GLuint i;
 
644
   for (i = 0; i < n; i++) {
 
645
      dst[i][0] =
 
646
      dst[i][1] =
 
647
      dst[i][2] = s[i] * (1.0F / 65535.0F);
 
648
      dst[i][3] = 1.0F;
 
649
   }
 
650
}
 
651
 
 
652
static void
 
653
unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n)
 
654
{
 
655
   unpack_S8_Z24(src, dst, n);
 
656
}
 
657
 
 
658
static void
 
659
unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n)
 
660
{
 
661
   unpack_Z24_S8(src, dst, n);
 
662
}
 
663
 
 
664
static void
 
665
unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
 
666
{
 
667
   const GLuint *s = ((const GLuint *) src);
 
668
   GLuint i;
 
669
   for (i = 0; i < n; i++) {
 
670
      dst[i][0] =
 
671
      dst[i][1] =
 
672
      dst[i][2] = s[i] * (1.0F / 0xffffffff);
 
673
      dst[i][3] = 1.0F;
 
674
   }
 
675
}
 
676
 
 
677
static void
 
678
unpack_Z32_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
 
679
{
 
680
   const GLfloat *s = ((const GLfloat *) src);
 
681
   GLuint i;
 
682
   for (i = 0; i < n; i++) {
 
683
      dst[i][0] =
 
684
      dst[i][1] =
 
685
      dst[i][2] = s[i * 2];
 
686
      dst[i][3] = 1.0F;
 
687
   }
 
688
}
 
689
 
 
690
static void
 
691
unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[][4], GLuint n)
 
692
{
 
693
   const GLfloat *s = ((const GLfloat *) src);
 
694
   GLuint i;
 
695
   for (i = 0; i < n; i++) {
 
696
      dst[i][0] =
 
697
      dst[i][1] =
 
698
      dst[i][2] = s[i];
 
699
      dst[i][3] = 1.0F;
 
700
   }
 
701
}
 
702
 
 
703
 
 
704
static void
 
705
unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
 
706
{
 
707
   /* should never be used */
 
708
   GLuint i;
 
709
   for (i = 0; i < n; i++) {
 
710
      dst[i][0] =
 
711
      dst[i][1] =
 
712
      dst[i][2] = 0.0F;
 
713
      dst[i][3] = 1.0F;
 
714
   }
 
715
}
 
716
 
 
717
 
 
718
static void
 
719
unpack_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
 
720
{
 
721
   const GLubyte *s = (const GLubyte *) src;
 
722
   GLuint i;
 
723
   for (i = 0; i < n; i++) {
 
724
      dst[i][RCOMP] = nonlinear_to_linear(s[i*3+2]);
 
725
      dst[i][GCOMP] = nonlinear_to_linear(s[i*3+1]);
 
726
      dst[i][BCOMP] = nonlinear_to_linear(s[i*3+0]);
 
727
      dst[i][ACOMP] = 1.0F;
 
728
   }
 
729
}
 
730
 
 
731
static void
 
732
unpack_SRGBA8(const void *src, GLfloat dst[][4], GLuint n)
 
733
{
 
734
   const GLuint *s = ((const GLuint *) src);
 
735
   GLuint i;
 
736
   for (i = 0; i < n; i++) {
 
737
      dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 24) );
 
738
      dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff );
 
739
      dst[i][BCOMP] = nonlinear_to_linear( (s[i] >>  8) & 0xff );
 
740
      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
 
741
   }
 
742
}
 
743
 
 
744
static void
 
745
unpack_SARGB8(const void *src, GLfloat dst[][4], GLuint n)
 
746
{
 
747
   const GLuint *s = ((const GLuint *) src);
 
748
   GLuint i;
 
749
   for (i = 0; i < n; i++) {
 
750
      dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff );
 
751
      dst[i][GCOMP] = nonlinear_to_linear( (s[i] >>  8) & 0xff );
 
752
      dst[i][BCOMP] = nonlinear_to_linear( (s[i]      ) & 0xff );
 
753
      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
 
754
   }
 
755
}
 
756
 
 
757
static void
 
758
unpack_SL8(const void *src, GLfloat dst[][4], GLuint n)
 
759
{
 
760
   const GLubyte *s = ((const GLubyte *) src);
 
761
   GLuint i;
 
762
   for (i = 0; i < n; i++) {
 
763
      dst[i][RCOMP] = 
 
764
      dst[i][GCOMP] = 
 
765
      dst[i][BCOMP] = nonlinear_to_linear(s[i]);
 
766
      dst[i][ACOMP] = 1.0F;
 
767
   }
 
768
}
 
769
 
 
770
static void
 
771
unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n)
 
772
{
 
773
   const GLushort *s = (const GLushort *) src;
 
774
   GLuint i;
 
775
   for (i = 0; i < n; i++) {
 
776
      dst[i][RCOMP] =
 
777
      dst[i][GCOMP] =
 
778
      dst[i][BCOMP] = nonlinear_to_linear(s[i] & 0xff);
 
779
      dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
 
780
   }
 
781
}
 
782
 
 
783
static void
 
784
unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
 
785
{
 
786
}
 
787
 
 
788
static void
 
789
unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
 
790
{
 
791
}
 
792
 
 
793
static void
 
794
unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
 
795
{
 
796
}
 
797
 
 
798
static void
 
799
unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
 
800
{
 
801
}
 
802
 
 
803
static void
 
804
unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
 
805
{
 
806
}
 
807
 
 
808
static void
 
809
unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
 
810
{
 
811
}
 
812
 
 
813
static void
 
814
unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
 
815
{
 
816
}
 
817
 
 
818
static void
 
819
unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
 
820
{
 
821
}
 
822
 
 
823
static void
 
824
unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
 
825
{
 
826
}
 
827
 
 
828
static void
 
829
unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
 
830
{
 
831
}
 
832
 
 
833
 
 
834
static void
 
835
unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
 
836
{
 
837
   const GLfloat *s = (const GLfloat *) src;
 
838
   GLuint i;
 
839
   for (i = 0; i < n; i++) {
 
840
      dst[i][RCOMP] = s[i*4+0];
 
841
      dst[i][GCOMP] = s[i*4+1];
 
842
      dst[i][BCOMP] = s[i*4+2];
 
843
      dst[i][ACOMP] = s[i*4+3];
 
844
   }
 
845
}
 
846
 
 
847
static void
 
848
unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
 
849
{
 
850
   const GLhalfARB *s = (const GLhalfARB *) src;
 
851
   GLuint i;
 
852
   for (i = 0; i < n; i++) {
 
853
      dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
 
854
      dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
 
855
      dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
 
856
      dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
 
857
   }
 
858
}
 
859
 
 
860
static void
 
861
unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
 
862
{
 
863
   const GLfloat *s = (const GLfloat *) src;
 
864
   GLuint i;
 
865
   for (i = 0; i < n; i++) {
 
866
      dst[i][RCOMP] = s[i*3+0];
 
867
      dst[i][GCOMP] = s[i*3+1];
 
868
      dst[i][BCOMP] = s[i*3+2];
 
869
      dst[i][ACOMP] = 1.0F;
 
870
   }
 
871
}
 
872
 
 
873
static void
 
874
unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
 
875
{
 
876
   const GLhalfARB *s = (const GLhalfARB *) src;
 
877
   GLuint i;
 
878
   for (i = 0; i < n; i++) {
 
879
      dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]);
 
880
      dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
 
881
      dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
 
882
      dst[i][ACOMP] = 1.0F;
 
883
   }
 
884
}
 
885
 
 
886
static void
 
887
unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
 
888
{
 
889
   const GLfloat *s = (const GLfloat *) src;
 
890
   GLuint i;
 
891
   for (i = 0; i < n; i++) {
 
892
      dst[i][RCOMP] =
 
893
      dst[i][GCOMP] =
 
894
      dst[i][BCOMP] = 0.0F;
 
895
      dst[i][ACOMP] = s[i];
 
896
   }
 
897
}
 
898
 
 
899
static void
 
900
unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
 
901
{
 
902
   const GLhalfARB *s = (const GLhalfARB *) src;
 
903
   GLuint i;
 
904
   for (i = 0; i < n; i++) {
 
905
      dst[i][RCOMP] =
 
906
      dst[i][GCOMP] =
 
907
      dst[i][BCOMP] = 0.0F;
 
908
      dst[i][ACOMP] = _mesa_half_to_float(s[i]);
 
909
   }
 
910
}
 
911
 
 
912
static void
 
913
unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
 
914
{
 
915
   const GLfloat *s = (const GLfloat *) src;
 
916
   GLuint i;
 
917
   for (i = 0; i < n; i++) {
 
918
      dst[i][RCOMP] =
 
919
      dst[i][GCOMP] =
 
920
      dst[i][BCOMP] = s[i];
 
921
      dst[i][ACOMP] = 1.0F;
 
922
   }
 
923
}
 
924
 
 
925
static void
 
926
unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
 
927
{
 
928
   const GLhalfARB *s = (const GLhalfARB *) src;
 
929
   GLuint i;
 
930
   for (i = 0; i < n; i++) {
 
931
      dst[i][RCOMP] =
 
932
      dst[i][GCOMP] =
 
933
      dst[i][BCOMP] = _mesa_half_to_float(s[i]);
 
934
      dst[i][ACOMP] = 1.0F;
 
935
   }
 
936
}
 
937
 
 
938
static void
 
939
unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
 
940
{
 
941
   const GLfloat *s = (const GLfloat *) src;
 
942
   GLuint i;
 
943
   for (i = 0; i < n; i++) {
 
944
      dst[i][RCOMP] =
 
945
      dst[i][GCOMP] =
 
946
      dst[i][BCOMP] = s[i*2+0];
 
947
      dst[i][ACOMP] = s[i*2+1];
 
948
   }
 
949
}
 
950
 
 
951
static void
 
952
unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
 
953
{
 
954
   const GLhalfARB *s = (const GLhalfARB *) src;
 
955
   GLuint i;
 
956
   for (i = 0; i < n; i++) {
 
957
      dst[i][RCOMP] =
 
958
      dst[i][GCOMP] =
 
959
      dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
 
960
      dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
 
961
   }
 
962
}
 
963
 
 
964
static void
 
965
unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
 
966
{
 
967
   const GLfloat *s = (const GLfloat *) src;
 
968
   GLuint i;
 
969
   for (i = 0; i < n; i++) {
 
970
      dst[i][RCOMP] =
 
971
      dst[i][GCOMP] =
 
972
      dst[i][BCOMP] =
 
973
      dst[i][ACOMP] = s[i];
 
974
   }
 
975
}
 
976
 
 
977
static void
 
978
unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
 
979
{
 
980
   const GLhalfARB *s = (const GLhalfARB *) src;
 
981
   GLuint i;
 
982
   for (i = 0; i < n; i++) {
 
983
      dst[i][RCOMP] =
 
984
      dst[i][GCOMP] =
 
985
      dst[i][BCOMP] =
 
986
      dst[i][ACOMP] = _mesa_half_to_float(s[i]);
 
987
   }
 
988
}
 
989
 
 
990
static void
 
991
unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
 
992
{
 
993
   const GLfloat *s = (const GLfloat *) src;
 
994
   GLuint i;
 
995
   for (i = 0; i < n; i++) {
 
996
      dst[i][RCOMP] = s[i];
 
997
      dst[i][GCOMP] = 0.0F;
 
998
      dst[i][BCOMP] = 0.0F;
 
999
      dst[i][ACOMP] = 1.0F;
 
1000
   }
 
1001
}
 
1002
 
 
1003
static void
 
1004
unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
 
1005
{
 
1006
   const GLhalfARB *s = (const GLhalfARB *) src;
 
1007
   GLuint i;
 
1008
   for (i = 0; i < n; i++) {
 
1009
      dst[i][RCOMP] = _mesa_half_to_float(s[i]);
 
1010
      dst[i][GCOMP] = 0.0F;
 
1011
      dst[i][BCOMP] = 0.0F;
 
1012
      dst[i][ACOMP] = 1.0F;
 
1013
   }
 
1014
}
 
1015
 
 
1016
static void
 
1017
unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
 
1018
{
 
1019
   const GLfloat *s = (const GLfloat *) src;
 
1020
   GLuint i;
 
1021
   for (i = 0; i < n; i++) {
 
1022
      dst[i][RCOMP] = s[i*2+0];
 
1023
      dst[i][GCOMP] = s[i*2+1];
 
1024
      dst[i][BCOMP] = 0.0F;
 
1025
      dst[i][ACOMP] = 1.0F;
 
1026
   }
 
1027
}
 
1028
 
 
1029
static void
 
1030
unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
 
1031
{
 
1032
   const GLhalfARB *s = (const GLhalfARB *) src;
 
1033
   GLuint i;
 
1034
   for (i = 0; i < n; i++) {
 
1035
      dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
 
1036
      dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
 
1037
      dst[i][BCOMP] = 0.0F;
 
1038
      dst[i][ACOMP] = 1.0F;
 
1039
   }
 
1040
}
 
1041
 
 
1042
 
 
1043
static void
 
1044
unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
 
1045
{
 
1046
   const GLbyte *s = (const GLbyte *) src;
 
1047
   GLuint i;
 
1048
   for (i = 0; i < n; i++) {
 
1049
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
 
1050
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
 
1051
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
 
1052
      dst[i][ACOMP] = (GLfloat) s[i*4+3];
 
1053
   }
 
1054
}
 
1055
 
 
1056
static void
 
1057
unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
 
1058
{
 
1059
   const GLshort *s = (const GLshort *) src;
 
1060
   GLuint i;
 
1061
   for (i = 0; i < n; i++) {
 
1062
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
 
1063
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
 
1064
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
 
1065
      dst[i][ACOMP] = (GLfloat) s[i*4+3];
 
1066
   }
 
1067
}
 
1068
 
 
1069
static void
 
1070
unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
 
1071
{
 
1072
   const GLint *s = (const GLint *) src;
 
1073
   GLuint i;
 
1074
   for (i = 0; i < n; i++) {
 
1075
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
 
1076
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
 
1077
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
 
1078
      dst[i][ACOMP] = (GLfloat) s[i*4+3];
 
1079
   }
 
1080
}
 
1081
 
 
1082
static void
 
1083
unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
 
1084
{
 
1085
   const GLubyte *s = (const GLubyte *) src;
 
1086
   GLuint i;
 
1087
   for (i = 0; i < n; i++) {
 
1088
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
 
1089
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
 
1090
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
 
1091
      dst[i][ACOMP] = (GLfloat) s[i*4+3];
 
1092
   }
 
1093
}
 
1094
 
 
1095
static void
 
1096
unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
 
1097
{
 
1098
   const GLushort *s = (const GLushort *) src;
 
1099
   GLuint i;
 
1100
   for (i = 0; i < n; i++) {
 
1101
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
 
1102
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
 
1103
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
 
1104
      dst[i][ACOMP] = (GLfloat) s[i*4+3];
 
1105
   }
 
1106
}
 
1107
 
 
1108
static void
 
1109
unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
 
1110
{
 
1111
   const GLuint *s = (const GLuint *) src;
 
1112
   GLuint i;
 
1113
   for (i = 0; i < n; i++) {
 
1114
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
 
1115
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
 
1116
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
 
1117
      dst[i][ACOMP] = (GLfloat) s[i*4+3];
 
1118
   }
 
1119
}
 
1120
 
 
1121
static void
 
1122
unpack_DUDV8(const void *src, GLfloat dst[][4], GLuint n)
 
1123
{
 
1124
   const GLbyte *s = (const GLbyte *) src;
 
1125
   GLuint i;
 
1126
   for (i = 0; i < n; i++) {
 
1127
      dst[i][RCOMP] = BYTE_TO_FLOAT(s[i*2+0]);
 
1128
      dst[i][GCOMP] = BYTE_TO_FLOAT(s[i*2+1]);
 
1129
      dst[i][BCOMP] = 0;
 
1130
      dst[i][ACOMP] = 0;
 
1131
   }
 
1132
}
 
1133
 
 
1134
static void
 
1135
unpack_SIGNED_R8(const void *src, GLfloat dst[][4], GLuint n)
 
1136
{
 
1137
   const GLbyte *s = ((const GLbyte *) src);
 
1138
   GLuint i;
 
1139
   for (i = 0; i < n; i++) {
 
1140
      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
 
1141
      dst[i][GCOMP] = 0.0F;
 
1142
      dst[i][BCOMP] = 0.0F;
 
1143
      dst[i][ACOMP] = 1.0F;
 
1144
   }
 
1145
}
 
1146
 
 
1147
static void
 
1148
unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
 
1149
{
 
1150
   const GLushort *s = ((const GLushort *) src);
 
1151
   GLuint i;
 
1152
   for (i = 0; i < n; i++) {
 
1153
      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
 
1154
      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
 
1155
      dst[i][BCOMP] = 0.0F;
 
1156
      dst[i][ACOMP] = 1.0F;
 
1157
   }
 
1158
}
 
1159
 
 
1160
static void
 
1161
unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
 
1162
{
 
1163
   const GLuint *s = ((const GLuint *) src);
 
1164
   GLuint i;
 
1165
   for (i = 0; i < n; i++) {
 
1166
      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
 
1167
      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
 
1168
      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
 
1169
      dst[i][ACOMP] = 1.0f;
 
1170
   }
 
1171
}
 
1172
 
 
1173
static void
 
1174
unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
 
1175
{
 
1176
   const GLuint *s = ((const GLuint *) src);
 
1177
   GLuint i;
 
1178
   for (i = 0; i < n; i++) {
 
1179
      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
 
1180
      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
 
1181
      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
 
1182
      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i]      ) );
 
1183
   }
 
1184
}
 
1185
 
 
1186
static void
 
1187
unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
 
1188
{
 
1189
   const GLuint *s = ((const GLuint *) src);
 
1190
   GLuint i;
 
1191
   for (i = 0; i < n; i++) {
 
1192
      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i]      ) );
 
1193
      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
 
1194
      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
 
1195
      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
 
1196
   }
 
1197
}
 
1198
 
 
1199
static void
 
1200
unpack_SIGNED_R16(const void *src, GLfloat dst[][4], GLuint n)
 
1201
{
 
1202
   const GLshort *s = ((const GLshort *) src);
 
1203
   GLuint i;
 
1204
   for (i = 0; i < n; i++) {
 
1205
      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
 
1206
      dst[i][GCOMP] = 0.0F;
 
1207
      dst[i][BCOMP] = 0.0F;
 
1208
      dst[i][ACOMP] = 1.0F;
 
1209
   }
 
1210
}
 
1211
 
 
1212
static void
 
1213
unpack_SIGNED_GR1616(const void *src, GLfloat dst[][4], GLuint n)
 
1214
{
 
1215
   const GLuint *s = ((const GLuint *) src);
 
1216
   GLuint i;
 
1217
   for (i = 0; i < n; i++) {
 
1218
      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
 
1219
      dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
 
1220
      dst[i][BCOMP] = 0.0F;
 
1221
      dst[i][ACOMP] = 1.0F;
 
1222
   }
 
1223
}
 
1224
 
 
1225
static void
 
1226
unpack_SIGNED_RGB_16(const void *src, GLfloat dst[][4], GLuint n)
 
1227
{
 
1228
   const GLshort *s = (const GLshort *) src;
 
1229
   GLuint i;
 
1230
   for (i = 0; i < n; i++) {
 
1231
      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] );
 
1232
      dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
 
1233
      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
 
1234
      dst[i][ACOMP] = 1.0F;
 
1235
   }
 
1236
}
 
1237
 
 
1238
static void
 
1239
unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
 
1240
{
 
1241
   const GLshort *s = (const GLshort *) src;
 
1242
   GLuint i;
 
1243
   for (i = 0; i < n; i++) {
 
1244
      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
 
1245
      dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
 
1246
      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
 
1247
      dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
 
1248
   }
 
1249
}
 
1250
 
 
1251
static void
 
1252
unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
 
1253
{
 
1254
   const GLushort *s = (const GLushort *) src;
 
1255
   GLuint i;
 
1256
   for (i = 0; i < n; i++) {
 
1257
      dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
 
1258
      dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
 
1259
      dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
 
1260
      dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
 
1261
   }
 
1262
}
 
1263
 
 
1264
static void
 
1265
unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
 
1266
{
 
1267
   /* XXX to do */
 
1268
}
 
1269
 
 
1270
static void
 
1271
unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
 
1272
{
 
1273
   /* XXX to do */
 
1274
}
 
1275
 
 
1276
static void
 
1277
unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
 
1278
{
 
1279
   /* XXX to do */
 
1280
}
 
1281
 
 
1282
static void
 
1283
unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
 
1284
{
 
1285
   /* XXX to do */
 
1286
}
 
1287
 
 
1288
static void
 
1289
unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
 
1290
{
 
1291
   /* XXX to do */
 
1292
}
 
1293
 
 
1294
static void
 
1295
unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
 
1296
{
 
1297
   /* XXX to do */
 
1298
}
 
1299
 
 
1300
static void
 
1301
unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
 
1302
{
 
1303
   /* XXX to do */
 
1304
}
 
1305
 
 
1306
static void
 
1307
unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
 
1308
{
 
1309
   /* XXX to do */
 
1310
}
 
1311
 
 
1312
static void
 
1313
unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
 
1314
{
 
1315
   /* XXX to do */
 
1316
}
 
1317
 
 
1318
static void
 
1319
unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n)
 
1320
{
 
1321
   const GLbyte *s = ((const GLbyte *) src);
 
1322
   GLuint i;
 
1323
   for (i = 0; i < n; i++) {
 
1324
      dst[i][RCOMP] = 0.0F;
 
1325
      dst[i][GCOMP] = 0.0F;
 
1326
      dst[i][BCOMP] = 0.0F;
 
1327
      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
 
1328
   }
 
1329
}
 
1330
 
 
1331
static void
 
1332
unpack_SIGNED_L8(const void *src, GLfloat dst[][4], GLuint n)
 
1333
{
 
1334
   const GLbyte *s = ((const GLbyte *) src);
 
1335
   GLuint i;
 
1336
   for (i = 0; i < n; i++) {
 
1337
      dst[i][RCOMP] =
 
1338
      dst[i][GCOMP] =
 
1339
      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
 
1340
      dst[i][ACOMP] = 1.0F;
 
1341
   }
 
1342
}
 
1343
 
 
1344
static void
 
1345
unpack_SIGNED_AL88(const void *src, GLfloat dst[][4], GLuint n)
 
1346
{
 
1347
   const GLshort *s = ((const GLshort *) src);
 
1348
   GLuint i;
 
1349
   for (i = 0; i < n; i++) {
 
1350
      dst[i][RCOMP] =
 
1351
      dst[i][GCOMP] =
 
1352
      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
 
1353
      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
 
1354
   }
 
1355
}
 
1356
 
 
1357
static void
 
1358
unpack_SIGNED_I8(const void *src, GLfloat dst[][4], GLuint n)
 
1359
{
 
1360
   const GLbyte *s = ((const GLbyte *) src);
 
1361
   GLuint i;
 
1362
   for (i = 0; i < n; i++) {
 
1363
      dst[i][RCOMP] =
 
1364
      dst[i][GCOMP] =
 
1365
      dst[i][BCOMP] =
 
1366
      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
 
1367
   }
 
1368
}
 
1369
 
 
1370
static void
 
1371
unpack_SIGNED_A16(const void *src, GLfloat dst[][4], GLuint n)
 
1372
{
 
1373
   const GLshort *s = ((const GLshort *) src);
 
1374
   GLuint i;
 
1375
   for (i = 0; i < n; i++) {
 
1376
      dst[i][RCOMP] = 0.0F;
 
1377
      dst[i][GCOMP] = 0.0F;
 
1378
      dst[i][BCOMP] = 0.0F;
 
1379
      dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
 
1380
   }
 
1381
}
 
1382
 
 
1383
static void
 
1384
unpack_SIGNED_L16(const void *src, GLfloat dst[][4], GLuint n)
 
1385
{
 
1386
   const GLshort *s = ((const GLshort *) src);
 
1387
   GLuint i;
 
1388
   for (i = 0; i < n; i++) {
 
1389
      dst[i][RCOMP] =
 
1390
      dst[i][GCOMP] =
 
1391
      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
 
1392
      dst[i][ACOMP] = 1.0F;
 
1393
   }
 
1394
}
 
1395
 
 
1396
static void
 
1397
unpack_SIGNED_AL1616(const void *src, GLfloat dst[][4], GLuint n)
 
1398
{
 
1399
   const GLshort *s = (const GLshort *) src;
 
1400
   GLuint i;
 
1401
   for (i = 0; i < n; i++) {
 
1402
      dst[i][RCOMP] =
 
1403
      dst[i][GCOMP] =
 
1404
      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
 
1405
      dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
 
1406
   }
 
1407
}
 
1408
 
 
1409
static void
 
1410
unpack_SIGNED_I16(const void *src, GLfloat dst[][4], GLuint n)
 
1411
{
 
1412
   const GLshort *s = ((const GLshort *) src);
 
1413
   GLuint i;
 
1414
   for (i = 0; i < n; i++) {
 
1415
      dst[i][RCOMP] =
 
1416
      dst[i][GCOMP] =
 
1417
      dst[i][BCOMP] =
 
1418
      dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
 
1419
   }
 
1420
}
 
1421
 
 
1422
static void
 
1423
unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
 
1424
{
 
1425
   const GLuint *s = (const GLuint *) src;
 
1426
   GLuint i;
 
1427
   for (i = 0; i < n; i++) {
 
1428
      rgb9e5_to_float3(s[i], dst[i]);
 
1429
      dst[i][ACOMP] = 1.0F;
 
1430
   }
 
1431
}
 
1432
 
 
1433
static void
 
1434
unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
 
1435
{
 
1436
   const GLuint *s = (const GLuint *) src;
 
1437
   GLuint i;
 
1438
   for (i = 0; i < n; i++) {
 
1439
      r11g11b10f_to_float3(s[i], dst[i]);
 
1440
      dst[i][ACOMP] = 1.0F;
 
1441
   }
 
1442
}
 
1443
 
 
1444
 
 
1445
/**
 
1446
 * Return the unpacker function for the given format.
 
1447
 */
 
1448
static unpack_rgba_func
 
1449
get_unpack_rgba_function(gl_format format)
 
1450
{
 
1451
   static unpack_rgba_func table[MESA_FORMAT_COUNT];
 
1452
   static GLboolean initialized = GL_FALSE;
 
1453
 
 
1454
   if (!initialized) {
 
1455
      table[MESA_FORMAT_NONE] = NULL;
 
1456
 
 
1457
      table[MESA_FORMAT_RGBA8888] = unpack_RGBA8888;
 
1458
      table[MESA_FORMAT_RGBA8888_REV] = unpack_RGBA8888_REV;
 
1459
      table[MESA_FORMAT_ARGB8888] = unpack_ARGB8888;
 
1460
      table[MESA_FORMAT_ARGB8888_REV] = unpack_ARGB8888_REV;
 
1461
      table[MESA_FORMAT_RGBX8888] = unpack_RGBX8888;
 
1462
      table[MESA_FORMAT_RGBX8888_REV] = unpack_RGBX8888_REV;
 
1463
      table[MESA_FORMAT_XRGB8888] = unpack_XRGB8888;
 
1464
      table[MESA_FORMAT_XRGB8888_REV] = unpack_XRGB8888_REV;
 
1465
      table[MESA_FORMAT_RGB888] = unpack_RGB888;
 
1466
      table[MESA_FORMAT_BGR888] = unpack_BGR888;
 
1467
      table[MESA_FORMAT_RGB565] = unpack_RGB565;
 
1468
      table[MESA_FORMAT_RGB565_REV] = unpack_RGB565_REV;
 
1469
      table[MESA_FORMAT_ARGB4444] = unpack_ARGB4444;
 
1470
      table[MESA_FORMAT_ARGB4444_REV] = unpack_ARGB4444_REV;
 
1471
      table[MESA_FORMAT_RGBA5551] = unpack_RGBA5551;
 
1472
      table[MESA_FORMAT_ARGB1555] = unpack_ARGB1555;
 
1473
      table[MESA_FORMAT_ARGB1555_REV] = unpack_ARGB1555_REV;
 
1474
      table[MESA_FORMAT_AL44] = unpack_AL44;
 
1475
      table[MESA_FORMAT_AL88] = unpack_AL88;
 
1476
      table[MESA_FORMAT_AL88_REV] = unpack_AL88_REV;
 
1477
      table[MESA_FORMAT_AL1616] = unpack_AL1616;
 
1478
      table[MESA_FORMAT_AL1616_REV] = unpack_AL1616_REV;
 
1479
      table[MESA_FORMAT_RGB332] = unpack_RGB332;
 
1480
      table[MESA_FORMAT_A8] = unpack_A8;
 
1481
      table[MESA_FORMAT_A16] = unpack_A16;
 
1482
      table[MESA_FORMAT_L8] = unpack_L8;
 
1483
      table[MESA_FORMAT_L16] = unpack_L16;
 
1484
      table[MESA_FORMAT_I8] = unpack_I8;
 
1485
      table[MESA_FORMAT_I16] = unpack_I16;
 
1486
      table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
 
1487
      table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
 
1488
      table[MESA_FORMAT_R8] = unpack_R8;
 
1489
      table[MESA_FORMAT_GR88] = unpack_GR88;
 
1490
      table[MESA_FORMAT_RG88] = unpack_RG88;
 
1491
      table[MESA_FORMAT_R16] = unpack_R16;
 
1492
      table[MESA_FORMAT_RG1616] = unpack_RG1616;
 
1493
      table[MESA_FORMAT_RG1616_REV] = unpack_RG1616_REV;
 
1494
      table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010;
 
1495
      table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8;
 
1496
      table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24;
 
1497
      table[MESA_FORMAT_Z16] = unpack_Z16;
 
1498
      table[MESA_FORMAT_X8_Z24] = unpack_X8_Z24;
 
1499
      table[MESA_FORMAT_Z24_X8] = unpack_Z24_X8;
 
1500
      table[MESA_FORMAT_Z32] = unpack_Z32;
 
1501
      table[MESA_FORMAT_S8] = unpack_S8;
 
1502
      table[MESA_FORMAT_SRGB8] = unpack_SRGB8;
 
1503
      table[MESA_FORMAT_SRGBA8] = unpack_SRGBA8;
 
1504
      table[MESA_FORMAT_SARGB8] = unpack_SARGB8;
 
1505
      table[MESA_FORMAT_SL8] = unpack_SL8;
 
1506
      table[MESA_FORMAT_SLA8] = unpack_SLA8;
 
1507
      table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
 
1508
      table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
 
1509
      table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
 
1510
      table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
 
1511
 
 
1512
      table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
 
1513
      table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
 
1514
      table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
 
1515
      table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
 
1516
      table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
 
1517
      table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
 
1518
 
 
1519
      table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
 
1520
      table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
 
1521
      table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
 
1522
      table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
 
1523
      table[MESA_FORMAT_ALPHA_FLOAT32] = unpack_ALPHA_FLOAT32;
 
1524
      table[MESA_FORMAT_ALPHA_FLOAT16] = unpack_ALPHA_FLOAT16;
 
1525
      table[MESA_FORMAT_LUMINANCE_FLOAT32] = unpack_LUMINANCE_FLOAT32;
 
1526
      table[MESA_FORMAT_LUMINANCE_FLOAT16] = unpack_LUMINANCE_FLOAT16;
 
1527
      table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = unpack_LUMINANCE_ALPHA_FLOAT32;
 
1528
      table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = unpack_LUMINANCE_ALPHA_FLOAT16;
 
1529
      table[MESA_FORMAT_INTENSITY_FLOAT32] = unpack_INTENSITY_FLOAT32;
 
1530
      table[MESA_FORMAT_INTENSITY_FLOAT16] = unpack_INTENSITY_FLOAT16;
 
1531
      table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
 
1532
      table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
 
1533
      table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
 
1534
      table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
 
1535
 
 
1536
      table[MESA_FORMAT_RGBA_INT8] = unpack_RGBA_INT8;
 
1537
      table[MESA_FORMAT_RGBA_INT16] = unpack_RGBA_INT16;
 
1538
      table[MESA_FORMAT_RGBA_INT32] = unpack_RGBA_INT32;
 
1539
      table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
 
1540
      table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
 
1541
      table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
 
1542
 
 
1543
      table[MESA_FORMAT_DUDV8] = unpack_DUDV8;
 
1544
      table[MESA_FORMAT_SIGNED_R8] = unpack_SIGNED_R8;
 
1545
      table[MESA_FORMAT_SIGNED_RG88_REV] = unpack_SIGNED_RG88_REV;
 
1546
      table[MESA_FORMAT_SIGNED_RGBX8888] = unpack_SIGNED_RGBX8888;
 
1547
      table[MESA_FORMAT_SIGNED_RGBA8888] = unpack_SIGNED_RGBA8888;
 
1548
      table[MESA_FORMAT_SIGNED_RGBA8888_REV] = unpack_SIGNED_RGBA8888_REV;
 
1549
      table[MESA_FORMAT_SIGNED_R16] = unpack_SIGNED_R16;
 
1550
      table[MESA_FORMAT_SIGNED_GR1616] = unpack_SIGNED_GR1616;
 
1551
      table[MESA_FORMAT_SIGNED_RGB_16] = unpack_SIGNED_RGB_16;
 
1552
      table[MESA_FORMAT_SIGNED_RGBA_16] = unpack_SIGNED_RGBA_16;
 
1553
      table[MESA_FORMAT_RGBA_16] = unpack_RGBA_16;
 
1554
 
 
1555
      table[MESA_FORMAT_RED_RGTC1] = unpack_RED_RGTC1;
 
1556
      table[MESA_FORMAT_SIGNED_RED_RGTC1] = unpack_SIGNED_RED_RGTC1;
 
1557
      table[MESA_FORMAT_RG_RGTC2] = unpack_RG_RGTC2;
 
1558
      table[MESA_FORMAT_SIGNED_RG_RGTC2] = unpack_SIGNED_RG_RGTC2;
 
1559
 
 
1560
      table[MESA_FORMAT_L_LATC1] = unpack_L_LATC1;
 
1561
      table[MESA_FORMAT_SIGNED_L_LATC1] = unpack_SIGNED_L_LATC1;
 
1562
      table[MESA_FORMAT_LA_LATC2] = unpack_LA_LATC2;
 
1563
      table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_LA_LATC2;
 
1564
 
 
1565
      table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
 
1566
 
 
1567
      table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8;
 
1568
      table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8;
 
1569
      table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88;
 
1570
      table[MESA_FORMAT_SIGNED_I8] = unpack_SIGNED_I8;
 
1571
      table[MESA_FORMAT_SIGNED_A16] = unpack_SIGNED_A16;
 
1572
      table[MESA_FORMAT_SIGNED_L16] = unpack_SIGNED_L16;
 
1573
      table[MESA_FORMAT_SIGNED_AL1616] = unpack_SIGNED_AL1616;
 
1574
      table[MESA_FORMAT_SIGNED_I16] = unpack_SIGNED_I16;
 
1575
 
 
1576
      table[MESA_FORMAT_RGB9_E5_FLOAT] = unpack_RGB9_E5_FLOAT;
 
1577
      table[MESA_FORMAT_R11_G11_B10_FLOAT] = unpack_R11_G11_B10_FLOAT;
 
1578
 
 
1579
      table[MESA_FORMAT_Z32_FLOAT] = unpack_Z32_FLOAT;
 
1580
      table[MESA_FORMAT_Z32_FLOAT_X24S8] = unpack_Z32_FLOAT_X24S8;
 
1581
 
 
1582
      initialized = GL_TRUE;
 
1583
   }
 
1584
 
 
1585
   return table[format];
 
1586
}
 
1587
 
 
1588
 
 
1589
/**
 
1590
 * Unpack rgba colors, returning as GLfloat values.
 
1591
 */
 
1592
void
 
1593
_mesa_unpack_rgba_row(gl_format format, GLuint n,
 
1594
                      const void *src, GLfloat dst[][4])
 
1595
{
 
1596
   unpack_rgba_func unpack = get_unpack_rgba_function(format);
 
1597
   unpack(src, dst, n);
 
1598
}
 
1599
 
 
1600
 
 
1601
/**********************************************************************/
 
1602
/*  Unpack, returning GLubyte colors                                  */
 
1603
/**********************************************************************/
 
1604
 
 
1605
 
 
1606
static void
 
1607
unpack_ubyte_RGBA8888(const void *src, GLubyte dst[][4], GLuint n)
 
1608
{
 
1609
   const GLuint *s = ((const GLuint *) src);
 
1610
   GLuint i;
 
1611
   for (i = 0; i < n; i++) {
 
1612
      dst[i][RCOMP] = (s[i] >> 24);
 
1613
      dst[i][GCOMP] = (s[i] >> 16) & 0xff;
 
1614
      dst[i][BCOMP] = (s[i] >>  8) & 0xff;
 
1615
      dst[i][ACOMP] = (s[i]      ) & 0xff;
 
1616
   }
 
1617
}
 
1618
 
 
1619
static void
 
1620
unpack_ubyte_RGBA8888_REV(const void *src, GLubyte dst[][4], GLuint n)
 
1621
{
 
1622
   const GLuint *s = ((const GLuint *) src);
 
1623
   GLuint i;
 
1624
   for (i = 0; i < n; i++) {
 
1625
      dst[i][RCOMP] = (s[i]      ) & 0xff;
 
1626
      dst[i][GCOMP] = (s[i] >>  8) & 0xff;
 
1627
      dst[i][BCOMP] = (s[i] >> 16) & 0xff;
 
1628
      dst[i][ACOMP] = (s[i] >> 24);
 
1629
   }
 
1630
}
 
1631
 
 
1632
static void
 
1633
unpack_ubyte_ARGB8888(const void *src, GLubyte dst[][4], GLuint n)
 
1634
{
 
1635
   const GLuint *s = ((const GLuint *) src);
 
1636
   GLuint i;
 
1637
   for (i = 0; i < n; i++) {
 
1638
      dst[i][RCOMP] = (s[i] >> 16) & 0xff;
 
1639
      dst[i][GCOMP] = (s[i] >>  8) & 0xff;
 
1640
      dst[i][BCOMP] = (s[i]      ) & 0xff;
 
1641
      dst[i][ACOMP] = (s[i] >> 24);
 
1642
   }
 
1643
}
 
1644
 
 
1645
static void
 
1646
unpack_ubyte_ARGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
 
1647
{
 
1648
   const GLuint *s = ((const GLuint *) src);
 
1649
   GLuint i;
 
1650
   for (i = 0; i < n; i++) {
 
1651
      dst[i][RCOMP] = (s[i] >>  8) & 0xff;
 
1652
      dst[i][GCOMP] = (s[i] >> 16) & 0xff;
 
1653
      dst[i][BCOMP] = (s[i] >> 24);
 
1654
      dst[i][ACOMP] = (s[i]      ) & 0xff;
 
1655
   }
 
1656
}
 
1657
 
 
1658
static void
 
1659
unpack_ubyte_RGBX8888(const void *src, GLubyte 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] = (s[i] >> 24);
 
1665
      dst[i][GCOMP] = (s[i] >> 16) & 0xff;
 
1666
      dst[i][BCOMP] = (s[i] >>  8) & 0xff;
 
1667
      dst[i][ACOMP] = 0xff;
 
1668
   }
 
1669
}
 
1670
 
 
1671
static void
 
1672
unpack_ubyte_RGBX8888_REV(const void *src, GLubyte 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] = (s[i]      ) & 0xff;
 
1678
      dst[i][GCOMP] = (s[i] >>  8) & 0xff;
 
1679
      dst[i][BCOMP] = (s[i] >> 16) & 0xff;
 
1680
      dst[i][ACOMP] = 0xff;
 
1681
   }
 
1682
}
 
1683
 
 
1684
static void
 
1685
unpack_ubyte_XRGB8888(const void *src, GLubyte 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] = (s[i] >> 16) & 0xff;
 
1691
      dst[i][GCOMP] = (s[i] >>  8) & 0xff;
 
1692
      dst[i][BCOMP] = (s[i]      ) & 0xff;
 
1693
      dst[i][ACOMP] = 0xff;
 
1694
   }
 
1695
}
 
1696
 
 
1697
static void
 
1698
unpack_ubyte_XRGB8888_REV(const void *src, GLubyte 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] = (s[i] >>  8) & 0xff;
 
1704
      dst[i][GCOMP] = (s[i] >> 16) & 0xff;
 
1705
      dst[i][BCOMP] = (s[i] >> 24);
 
1706
      dst[i][ACOMP] = 0xff;
 
1707
   }
 
1708
}
 
1709
 
 
1710
static void
 
1711
unpack_ubyte_RGB888(const void *src, GLubyte dst[][4], GLuint n)
 
1712
{
 
1713
   const GLubyte *s = (const GLubyte *) src;
 
1714
   GLuint i;
 
1715
   for (i = 0; i < n; i++) {
 
1716
      dst[i][RCOMP] = s[i*3+2];
 
1717
      dst[i][GCOMP] = s[i*3+1];
 
1718
      dst[i][BCOMP] = s[i*3+0];
 
1719
      dst[i][ACOMP] = 0xff;
 
1720
   }
 
1721
}
 
1722
 
 
1723
static void
 
1724
unpack_ubyte_BGR888(const void *src, GLubyte dst[][4], GLuint n)
 
1725
{
 
1726
   const GLubyte *s = (const GLubyte *) src;
 
1727
   GLuint i;
 
1728
   for (i = 0; i < n; i++) {
 
1729
      dst[i][RCOMP] = s[i*3+0];
 
1730
      dst[i][GCOMP] = s[i*3+1];
 
1731
      dst[i][BCOMP] = s[i*3+2];
 
1732
      dst[i][ACOMP] = 0xff;
 
1733
   }
 
1734
}
 
1735
 
 
1736
static void
 
1737
unpack_ubyte_RGB565(const void *src, GLubyte 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] = EXPAND_5_8((s[i] >> 11) & 0x1f);
 
1743
      dst[i][GCOMP] = EXPAND_6_8((s[i] >> 5 ) & 0x3f);
 
1744
      dst[i][BCOMP] = EXPAND_5_8( s[i]        & 0x1f);
 
1745
      dst[i][ACOMP] = 0xff;
 
1746
   }
 
1747
}
 
1748
 
 
1749
static void
 
1750
unpack_ubyte_RGB565_REV(const void *src, GLubyte dst[][4], GLuint n)
 
1751
{
 
1752
   const GLushort *s = ((const GLushort *) src);
 
1753
   GLuint i;
 
1754
   for (i = 0; i < n; i++) {
 
1755
      GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
 
1756
      dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);
 
1757
      dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);
 
1758
      dst[i][BCOMP] = EXPAND_5_8( t        & 0x1f);
 
1759
      dst[i][ACOMP] = 0xff;
 
1760
   }
 
1761
}
 
1762
 
 
1763
static void
 
1764
unpack_ubyte_ARGB4444(const void *src, GLubyte dst[][4], GLuint n)
 
1765
{
 
1766
   const GLushort *s = ((const GLushort *) src);
 
1767
   GLuint i;
 
1768
   for (i = 0; i < n; i++) {
 
1769
      dst[i][RCOMP] = EXPAND_4_8((s[i] >>  8) & 0xf);
 
1770
      dst[i][GCOMP] = EXPAND_4_8((s[i] >>  4) & 0xf);
 
1771
      dst[i][BCOMP] = EXPAND_4_8((s[i]      ) & 0xf);
 
1772
      dst[i][ACOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
 
1773
   }
 
1774
}
 
1775
 
 
1776
static void
 
1777
unpack_ubyte_ARGB4444_REV(const void *src, GLubyte dst[][4], GLuint n)
 
1778
{
 
1779
   const GLushort *s = ((const GLushort *) src);
 
1780
   GLuint i;
 
1781
   for (i = 0; i < n; i++) {
 
1782
      dst[i][RCOMP] = EXPAND_4_8((s[i]      ) & 0xf);
 
1783
      dst[i][GCOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
 
1784
      dst[i][BCOMP] = EXPAND_4_8((s[i] >>  8) & 0xf);
 
1785
      dst[i][ACOMP] = EXPAND_4_8((s[i] >>  4) & 0xf);
 
1786
   }
 
1787
}
 
1788
 
 
1789
static void
 
1790
unpack_ubyte_RGBA5551(const void *src, GLubyte dst[][4], GLuint n)
 
1791
{
 
1792
   const GLushort *s = ((const GLushort *) src);
 
1793
   GLuint i;
 
1794
   for (i = 0; i < n; i++) {
 
1795
      dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
 
1796
      dst[i][GCOMP] = EXPAND_5_8((s[i] >>  6) & 0x1f);
 
1797
      dst[i][BCOMP] = EXPAND_5_8((s[i] >>  1) & 0x1f);
 
1798
      dst[i][ACOMP] = EXPAND_1_8((s[i]      ) & 0x01);
 
1799
   }
 
1800
}
 
1801
 
 
1802
static void
 
1803
unpack_ubyte_ARGB1555(const void *src, GLubyte dst[][4], GLuint n)
 
1804
{
 
1805
   const GLushort *s = ((const GLushort *) src);
 
1806
   GLuint i;
 
1807
   for (i = 0; i < n; i++) {
 
1808
      dst[i][RCOMP] = EXPAND_5_8((s[i] >> 10) & 0x1f);
 
1809
      dst[i][GCOMP] = EXPAND_5_8((s[i] >>  5) & 0x1f);
 
1810
      dst[i][BCOMP] = EXPAND_5_8((s[i] >>  0) & 0x1f);
 
1811
      dst[i][ACOMP] = EXPAND_1_8((s[i] >> 15) & 0x01);
 
1812
   }
 
1813
}
 
1814
 
 
1815
static void
 
1816
unpack_ubyte_ARGB1555_REV(const void *src, GLubyte dst[][4], GLuint n)
 
1817
{
 
1818
   const GLushort *s = ((const GLushort *) src);
 
1819
   GLuint i;
 
1820
   for (i = 0; i < n; i++) {
 
1821
      GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
 
1822
      dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
 
1823
      dst[i][GCOMP] = EXPAND_5_8((tmp >>  5) & 0x1f);
 
1824
      dst[i][BCOMP] = EXPAND_5_8((tmp >>  0) & 0x1f);
 
1825
      dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
 
1826
   }
 
1827
}
 
1828
 
 
1829
static void
 
1830
unpack_ubyte_AL44(const void *src, GLubyte dst[][4], GLuint n)
 
1831
{
 
1832
   const GLubyte *s = ((const GLubyte *) src);
 
1833
   GLuint i;
 
1834
   for (i = 0; i < n; i++) {
 
1835
      dst[i][RCOMP] =
 
1836
      dst[i][GCOMP] =
 
1837
      dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xf);
 
1838
      dst[i][ACOMP] = EXPAND_4_8(s[i] >> 4);
 
1839
   }
 
1840
}
 
1841
 
 
1842
static void
 
1843
unpack_ubyte_AL88(const void *src, GLubyte dst[][4], GLuint n)
 
1844
{
 
1845
   const GLushort *s = ((const GLushort *) src);
 
1846
   GLuint i;
 
1847
   for (i = 0; i < n; i++) {
 
1848
      dst[i][RCOMP] = 
 
1849
      dst[i][GCOMP] = 
 
1850
      dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xff);
 
1851
      dst[i][ACOMP] = EXPAND_4_8(s[i] >> 8);
 
1852
   }
 
1853
}
 
1854
 
 
1855
static void
 
1856
unpack_ubyte_AL88_REV(const void *src, GLubyte dst[][4], GLuint n)
 
1857
{
 
1858
   const GLushort *s = ((const GLushort *) src);
 
1859
   GLuint i;
 
1860
   for (i = 0; i < n; i++) {
 
1861
      dst[i][RCOMP] = 
 
1862
      dst[i][GCOMP] = 
 
1863
      dst[i][BCOMP] = EXPAND_4_8(s[i] >> 8);
 
1864
      dst[i][ACOMP] = EXPAND_4_8(s[i] & 0xff);
 
1865
   }
 
1866
}
 
1867
 
 
1868
static void
 
1869
unpack_ubyte_RGB332(const void *src, GLubyte dst[][4], GLuint n)
 
1870
{
 
1871
   const GLubyte *s = ((const GLubyte *) src);
 
1872
   GLuint i;
 
1873
   for (i = 0; i < n; i++) {
 
1874
      dst[i][RCOMP] = EXPAND_3_8((s[i] >> 5) & 0x7);
 
1875
      dst[i][GCOMP] = EXPAND_3_8((s[i] >> 2) & 0x7);
 
1876
      dst[i][BCOMP] = EXPAND_2_8((s[i]     ) & 0x3);
 
1877
      dst[i][ACOMP] = 0xff;
 
1878
   }
 
1879
}
 
1880
 
 
1881
static void
 
1882
unpack_ubyte_A8(const void *src, GLubyte dst[][4], GLuint n)
 
1883
{
 
1884
   const GLubyte *s = ((const GLubyte *) src);
 
1885
   GLuint i;
 
1886
   for (i = 0; i < n; i++) {
 
1887
      dst[i][RCOMP] =
 
1888
      dst[i][GCOMP] =
 
1889
      dst[i][BCOMP] = 0;
 
1890
      dst[i][ACOMP] = s[i];
 
1891
   }
 
1892
}
 
1893
 
 
1894
static void
 
1895
unpack_ubyte_L8(const void *src, GLubyte dst[][4], GLuint n)
 
1896
{
 
1897
   const GLubyte *s = ((const GLubyte *) src);
 
1898
   GLuint i;
 
1899
   for (i = 0; i < n; i++) {
 
1900
      dst[i][RCOMP] =
 
1901
      dst[i][GCOMP] =
 
1902
      dst[i][BCOMP] = s[i];
 
1903
      dst[i][ACOMP] = 0xff;
 
1904
   }
 
1905
}
 
1906
 
 
1907
 
 
1908
static void
 
1909
unpack_ubyte_I8(const void *src, GLubyte dst[][4], GLuint n)
 
1910
{
 
1911
   const GLubyte *s = ((const GLubyte *) src);
 
1912
   GLuint i;
 
1913
   for (i = 0; i < n; i++) {
 
1914
      dst[i][RCOMP] =
 
1915
      dst[i][GCOMP] =
 
1916
      dst[i][BCOMP] =
 
1917
      dst[i][ACOMP] = s[i];
 
1918
   }
 
1919
}
 
1920
 
 
1921
static void
 
1922
unpack_ubyte_R8(const void *src, GLubyte dst[][4], GLuint n)
 
1923
{
 
1924
   const GLubyte *s = ((const GLubyte *) src);
 
1925
   GLuint i;
 
1926
   for (i = 0; i < n; i++) {
 
1927
      dst[i][0] = s[i];
 
1928
      dst[i][1] =
 
1929
      dst[i][2] = 0;
 
1930
      dst[i][3] = 0xff;
 
1931
   }
 
1932
}
 
1933
 
 
1934
static void
 
1935
unpack_ubyte_GR88(const void *src, GLubyte dst[][4], GLuint n)
 
1936
{
 
1937
   const GLushort *s = ((const GLushort *) src);
 
1938
   GLuint i;
 
1939
   for (i = 0; i < n; i++) {
 
1940
      dst[i][RCOMP] = s[i] & 0xff;
 
1941
      dst[i][GCOMP] = s[i] >> 8;
 
1942
      dst[i][BCOMP] = 0;
 
1943
      dst[i][ACOMP] = 0xff;
 
1944
   }
 
1945
}
 
1946
 
 
1947
static void
 
1948
unpack_ubyte_RG88(const void *src, GLubyte dst[][4], GLuint n)
 
1949
{
 
1950
   const GLushort *s = ((const GLushort *) src);
 
1951
   GLuint i;
 
1952
   for (i = 0; i < n; i++) {
 
1953
      dst[i][RCOMP] = s[i] >> 8;
 
1954
      dst[i][GCOMP] = s[i] & 0xff;
 
1955
      dst[i][BCOMP] = 0;
 
1956
      dst[i][ACOMP] = 0xff;
 
1957
   }
 
1958
}
 
1959
 
 
1960
 
 
1961
/**
 
1962
 * Unpack rgba colors, returning as GLubyte values.  This should usually
 
1963
 * only be used for unpacking formats that use 8 bits or less per channel.
 
1964
 */
 
1965
void
 
1966
_mesa_unpack_ubyte_rgba_row(gl_format format, GLuint n,
 
1967
                            const void *src, GLubyte dst[][4])
 
1968
{
 
1969
   switch (format) {
 
1970
   case MESA_FORMAT_RGBA8888:
 
1971
      unpack_ubyte_RGBA8888(src, dst, n);
 
1972
      break;
 
1973
   case MESA_FORMAT_RGBA8888_REV:
 
1974
      unpack_ubyte_RGBA8888_REV(src, dst, n);
 
1975
      break;
 
1976
   case MESA_FORMAT_ARGB8888:
 
1977
      unpack_ubyte_ARGB8888(src, dst, n);
 
1978
      break;
 
1979
   case MESA_FORMAT_ARGB8888_REV:
 
1980
      unpack_ubyte_ARGB8888_REV(src, dst, n);
 
1981
      break;
 
1982
   case MESA_FORMAT_RGBX8888:
 
1983
      unpack_ubyte_RGBX8888(src, dst, n);
 
1984
      break;
 
1985
   case MESA_FORMAT_RGBX8888_REV:
 
1986
      unpack_ubyte_RGBX8888_REV(src, dst, n);
 
1987
      break;
 
1988
   case MESA_FORMAT_XRGB8888:
 
1989
      unpack_ubyte_XRGB8888(src, dst, n);
 
1990
      break;
 
1991
   case MESA_FORMAT_XRGB8888_REV:
 
1992
      unpack_ubyte_XRGB8888_REV(src, dst, n);
 
1993
      break;
 
1994
   case MESA_FORMAT_RGB888:
 
1995
      unpack_ubyte_RGB888(src, dst, n);
 
1996
      break;
 
1997
   case MESA_FORMAT_BGR888:
 
1998
      unpack_ubyte_BGR888(src, dst, n);
 
1999
      break;
 
2000
   case MESA_FORMAT_RGB565:
 
2001
      unpack_ubyte_RGB565(src, dst, n);
 
2002
      break;
 
2003
   case MESA_FORMAT_RGB565_REV:
 
2004
      unpack_ubyte_RGB565_REV(src, dst, n);
 
2005
      break;
 
2006
   case MESA_FORMAT_ARGB4444:
 
2007
      unpack_ubyte_ARGB4444(src, dst, n);
 
2008
      break;
 
2009
   case MESA_FORMAT_ARGB4444_REV:
 
2010
      unpack_ubyte_ARGB4444_REV(src, dst, n);
 
2011
      break;
 
2012
   case MESA_FORMAT_RGBA5551:
 
2013
      unpack_ubyte_RGBA5551(src, dst, n);
 
2014
      break;
 
2015
   case MESA_FORMAT_ARGB1555:
 
2016
      unpack_ubyte_ARGB1555(src, dst, n);
 
2017
      break;
 
2018
   case MESA_FORMAT_ARGB1555_REV:
 
2019
      unpack_ubyte_ARGB1555_REV(src, dst, n);
 
2020
      break;
 
2021
   case MESA_FORMAT_AL44:
 
2022
      unpack_ubyte_AL44(src, dst, n);
 
2023
      break;
 
2024
   case MESA_FORMAT_AL88:
 
2025
      unpack_ubyte_AL88(src, dst, n);
 
2026
      break;
 
2027
   case MESA_FORMAT_AL88_REV:
 
2028
      unpack_ubyte_AL88_REV(src, dst, n);
 
2029
      break;
 
2030
   case MESA_FORMAT_RGB332:
 
2031
      unpack_ubyte_RGB332(src, dst, n);
 
2032
      break;
 
2033
   case MESA_FORMAT_A8:
 
2034
      unpack_ubyte_A8(src, dst, n);
 
2035
      break;
 
2036
   case MESA_FORMAT_L8:
 
2037
      unpack_ubyte_L8(src, dst, n);
 
2038
      break;
 
2039
   case MESA_FORMAT_I8:
 
2040
      unpack_ubyte_I8(src, dst, n);
 
2041
      break;
 
2042
   case MESA_FORMAT_R8:
 
2043
      unpack_ubyte_R8(src, dst, n);
 
2044
      break;
 
2045
   case MESA_FORMAT_GR88:
 
2046
      unpack_ubyte_GR88(src, dst, n);
 
2047
      break;
 
2048
   case MESA_FORMAT_RG88:
 
2049
      unpack_ubyte_RG88(src, dst, n);
 
2050
      break;
 
2051
   default:
 
2052
      /* get float values, convert to ubyte */
 
2053
      {
 
2054
         GLfloat *tmp = (GLfloat *) malloc(n * 4 * sizeof(GLfloat));
 
2055
         if (tmp) {
 
2056
            GLuint i;
 
2057
            _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
 
2058
            for (i = 0; i < n; i++) {
 
2059
               UNCLAMPED_FLOAT_TO_UBYTE(dst[i][0], tmp[i*4+0]);
 
2060
               UNCLAMPED_FLOAT_TO_UBYTE(dst[i][1], tmp[i*4+1]);
 
2061
               UNCLAMPED_FLOAT_TO_UBYTE(dst[i][2], tmp[i*4+2]);
 
2062
               UNCLAMPED_FLOAT_TO_UBYTE(dst[i][3], tmp[i*4+3]);
 
2063
            }
 
2064
            free(tmp);
 
2065
         }
 
2066
      }
 
2067
      break;
 
2068
   }
 
2069
}
 
2070
 
 
2071
 
 
2072
/**********************************************************************/
 
2073
/*  Unpack, returning GLuint colors                                   */
 
2074
/**********************************************************************/
 
2075
 
 
2076
static void
 
2077
unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 
2078
{
 
2079
   memcpy(dst, src, n * 4 * sizeof(GLuint));
 
2080
}
 
2081
 
 
2082
static void
 
2083
unpack_int_rgba_RGBA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
 
2084
{
 
2085
   unsigned int i;
 
2086
 
 
2087
   for (i = 0; i < n; i++) {
 
2088
      dst[i][0] = src[i * 4 + 0];
 
2089
      dst[i][1] = src[i * 4 + 1];
 
2090
      dst[i][2] = src[i * 4 + 2];
 
2091
      dst[i][3] = src[i * 4 + 3];
 
2092
   }
 
2093
}
 
2094
 
 
2095
static void
 
2096
unpack_int_rgba_RGBA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
 
2097
{
 
2098
   unsigned int i;
 
2099
 
 
2100
   for (i = 0; i < n; i++) {
 
2101
      dst[i][0] = src[i * 4 + 0];
 
2102
      dst[i][1] = src[i * 4 + 1];
 
2103
      dst[i][2] = src[i * 4 + 2];
 
2104
      dst[i][3] = src[i * 4 + 3];
 
2105
   }
 
2106
}
 
2107
 
 
2108
static void
 
2109
unpack_int_rgba_RGBA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
 
2110
{
 
2111
   unsigned int i;
 
2112
 
 
2113
   for (i = 0; i < n; i++) {
 
2114
      dst[i][0] = src[i * 4 + 0];
 
2115
      dst[i][1] = src[i * 4 + 1];
 
2116
      dst[i][2] = src[i * 4 + 2];
 
2117
      dst[i][3] = src[i * 4 + 3];
 
2118
   }
 
2119
}
 
2120
 
 
2121
static void
 
2122
unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
 
2123
{
 
2124
   unsigned int i;
 
2125
 
 
2126
   for (i = 0; i < n; i++) {
 
2127
      dst[i][0] = src[i * 4 + 0];
 
2128
      dst[i][1] = src[i * 4 + 1];
 
2129
      dst[i][2] = src[i * 4 + 2];
 
2130
      dst[i][3] = src[i * 4 + 3];
 
2131
   }
 
2132
}
 
2133
 
 
2134
static void
 
2135
unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 
2136
{
 
2137
   unsigned int i;
 
2138
 
 
2139
   for (i = 0; i < n; i++) {
 
2140
      dst[i][0] = src[i * 3 + 0];
 
2141
      dst[i][1] = src[i * 3 + 1];
 
2142
      dst[i][2] = src[i * 3 + 2];
 
2143
      dst[i][3] = 1;
 
2144
   }
 
2145
}
 
2146
 
 
2147
static void
 
2148
unpack_int_rgba_RGB_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
 
2149
{
 
2150
   unsigned int i;
 
2151
 
 
2152
   for (i = 0; i < n; i++) {
 
2153
      dst[i][0] = src[i * 3 + 0];
 
2154
      dst[i][1] = src[i * 3 + 1];
 
2155
      dst[i][2] = src[i * 3 + 2];
 
2156
      dst[i][3] = 1;
 
2157
   }
 
2158
}
 
2159
 
 
2160
static void
 
2161
unpack_int_rgba_RGB_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
 
2162
{
 
2163
   unsigned int i;
 
2164
 
 
2165
   for (i = 0; i < n; i++) {
 
2166
      dst[i][0] = src[i * 3 + 0];
 
2167
      dst[i][1] = src[i * 3 + 1];
 
2168
      dst[i][2] = src[i * 3 + 2];
 
2169
      dst[i][3] = 1;
 
2170
   }
 
2171
}
 
2172
 
 
2173
static void
 
2174
unpack_int_rgba_RGB_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
 
2175
{
 
2176
   unsigned int i;
 
2177
 
 
2178
   for (i = 0; i < n; i++) {
 
2179
      dst[i][0] = src[i * 3 + 0];
 
2180
      dst[i][1] = src[i * 3 + 1];
 
2181
      dst[i][2] = src[i * 3 + 2];
 
2182
      dst[i][3] = 1;
 
2183
   }
 
2184
}
 
2185
 
 
2186
static void
 
2187
unpack_int_rgba_RGB_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
 
2188
{
 
2189
   unsigned int i;
 
2190
 
 
2191
   for (i = 0; i < n; i++) {
 
2192
      dst[i][0] = src[i * 3 + 0];
 
2193
      dst[i][1] = src[i * 3 + 1];
 
2194
      dst[i][2] = src[i * 3 + 2];
 
2195
      dst[i][3] = 1;
 
2196
   }
 
2197
}
 
2198
 
 
2199
static void
 
2200
unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 
2201
{
 
2202
   unsigned int i;
 
2203
 
 
2204
   for (i = 0; i < n; i++) {
 
2205
      dst[i][0] = src[i * 2 + 0];
 
2206
      dst[i][1] = src[i * 2 + 1];
 
2207
      dst[i][2] = 0;
 
2208
      dst[i][3] = 1;
 
2209
   }
 
2210
}
 
2211
 
 
2212
static void
 
2213
unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 
2214
{
 
2215
   unsigned int i;
 
2216
 
 
2217
   for (i = 0; i < n; i++) {
 
2218
      dst[i][0] = src[i];
 
2219
      dst[i][1] = 0;
 
2220
      dst[i][2] = 0;
 
2221
      dst[i][3] = 1;
 
2222
   }
 
2223
}
 
2224
 
 
2225
static void
 
2226
unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 
2227
{
 
2228
   unsigned int i;
 
2229
 
 
2230
   for (i = 0; i < n; i++) {
 
2231
      dst[i][0] = dst[i][1] = dst[i][2] = src[i];
 
2232
      dst[i][3] = 1;
 
2233
   }
 
2234
}
 
2235
 
 
2236
static void
 
2237
unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 
2238
{
 
2239
   unsigned int i;
 
2240
 
 
2241
   for (i = 0; i < n; i++) {
 
2242
      dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
 
2243
      dst[i][3] = src[i * 2 + 1];
 
2244
   }
 
2245
}
 
2246
 
 
2247
static void
 
2248
unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 
2249
{
 
2250
   unsigned int i;
 
2251
 
 
2252
   for (i = 0; i < n; i++) {
 
2253
      dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
 
2254
   }
 
2255
}
 
2256
 
 
2257
static void
 
2258
unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
 
2259
{
 
2260
   unsigned int i;
 
2261
 
 
2262
   for (i = 0; i < n; i++) {
 
2263
      GLuint tmp = src[i];
 
2264
      dst[i][0] = (tmp >> 20) & 0x3ff;
 
2265
      dst[i][1] = (tmp >> 10) & 0x3ff;
 
2266
      dst[i][2] = (tmp >> 0) & 0x3ff;
 
2267
      dst[i][3] = (tmp >> 30) & 0x3;
 
2268
   }
 
2269
}
 
2270
 
 
2271
void
 
2272
_mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
 
2273
                           const void *src, GLuint dst[][4])
 
2274
{
 
2275
   switch (format) {
 
2276
      /* Since there won't be any sign extension happening, there's no need to
 
2277
       * make separate paths for 32-bit-to-32-bit integer unpack.
 
2278
       */
 
2279
   case MESA_FORMAT_RGBA_UINT32:
 
2280
   case MESA_FORMAT_RGBA_INT32:
 
2281
      unpack_int_rgba_RGBA_UINT32(src, dst, n);
 
2282
      break;
 
2283
 
 
2284
   case MESA_FORMAT_RGBA_UINT16:
 
2285
      unpack_int_rgba_RGBA_UINT16(src, dst, n);
 
2286
      break;
 
2287
   case MESA_FORMAT_RGBA_INT16:
 
2288
      unpack_int_rgba_RGBA_INT16(src, dst, n);
 
2289
      break;
 
2290
 
 
2291
   case MESA_FORMAT_RGBA_UINT8:
 
2292
      unpack_int_rgba_RGBA_UINT8(src, dst, n);
 
2293
      break;
 
2294
   case MESA_FORMAT_RGBA_INT8:
 
2295
      unpack_int_rgba_RGBA_INT8(src, dst, n);
 
2296
      break;
 
2297
 
 
2298
   case MESA_FORMAT_RGB_UINT32:
 
2299
   case MESA_FORMAT_RGB_INT32:
 
2300
      unpack_int_rgba_RGB_UINT32(src, dst, n);
 
2301
      break;
 
2302
 
 
2303
   case MESA_FORMAT_RGB_UINT16:
 
2304
      unpack_int_rgba_RGB_UINT16(src, dst, n);
 
2305
      break;
 
2306
   case MESA_FORMAT_RGB_INT16:
 
2307
      unpack_int_rgba_RGB_INT16(src, dst, n);
 
2308
      break;
 
2309
 
 
2310
   case MESA_FORMAT_RGB_UINT8:
 
2311
      unpack_int_rgba_RGB_UINT8(src, dst, n);
 
2312
      break;
 
2313
   case MESA_FORMAT_RGB_INT8:
 
2314
      unpack_int_rgba_RGB_INT8(src, dst, n);
 
2315
      break;
 
2316
 
 
2317
   case MESA_FORMAT_RG_UINT32:
 
2318
   case MESA_FORMAT_RG_INT32:
 
2319
      unpack_int_rgba_RG_UINT32(src, dst, n);
 
2320
      break;
 
2321
   case MESA_FORMAT_R_UINT32:
 
2322
   case MESA_FORMAT_R_INT32:
 
2323
      unpack_int_rgba_R_UINT32(src, dst, n);
 
2324
      break;
 
2325
 
 
2326
   case MESA_FORMAT_LUMINANCE_UINT32:
 
2327
   case MESA_FORMAT_LUMINANCE_INT32:
 
2328
      unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
 
2329
      break;
 
2330
   case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
 
2331
   case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
 
2332
      unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
 
2333
      break;
 
2334
   case MESA_FORMAT_INTENSITY_UINT32:
 
2335
   case MESA_FORMAT_INTENSITY_INT32:
 
2336
      unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
 
2337
      break;
 
2338
 
 
2339
   case MESA_FORMAT_ARGB2101010_UINT:
 
2340
      unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
 
2341
      break;
 
2342
   default:
 
2343
      _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
 
2344
                    _mesa_get_format_name(format));
 
2345
      return;
 
2346
   }
 
2347
}
 
2348
 
 
2349
/**
 
2350
 * Unpack a 2D rect of pixels returning float RGBA colors.
 
2351
 * \param format  the source image format
 
2352
 * \param src  start address of the source image
 
2353
 * \param srcRowStride  source image row stride in bytes
 
2354
 * \param dst  start address of the dest image
 
2355
 * \param dstRowStride  dest image row stride in bytes
 
2356
 * \param x  source image start X pos
 
2357
 * \param y  source image start Y pos
 
2358
 * \param width  width of rect region to convert
 
2359
 * \param height  height of rect region to convert
 
2360
 */
 
2361
void
 
2362
_mesa_unpack_rgba_block(gl_format format,
 
2363
                        const void *src, GLint srcRowStride,
 
2364
                        GLfloat dst[][4], GLint dstRowStride,
 
2365
                        GLuint x, GLuint y, GLuint width, GLuint height)
 
2366
{
 
2367
   unpack_rgba_func unpack = get_unpack_rgba_function(format);
 
2368
   const GLuint srcPixStride = _mesa_get_format_bytes(format);
 
2369
   const GLuint dstPixStride = 4 * sizeof(GLfloat);
 
2370
   const GLubyte *srcRow;
 
2371
   GLubyte *dstRow;
 
2372
   GLuint i;
 
2373
 
 
2374
   /* XXX needs to be fixed for compressed formats */
 
2375
 
 
2376
   srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
 
2377
   dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
 
2378
 
 
2379
   for (i = 0; i < height; i++) {
 
2380
      unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
 
2381
 
 
2382
      dstRow += dstRowStride;
 
2383
      srcRow += srcRowStride;
 
2384
   }
 
2385
}
 
2386
 
 
2387
 
 
2388
 
 
2389
 
 
2390
typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
 
2391
 
 
2392
static void
 
2393
unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
 
2394
{
 
2395
   /* only return Z, not stencil data */
 
2396
   const GLuint *s = ((const GLuint *) src);
 
2397
   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
 
2398
   GLuint i;
 
2399
   for (i = 0; i < n; i++) {
 
2400
      dst[i] = (s[i] >> 8) * scale;
 
2401
      ASSERT(dst[i] >= 0.0F);
 
2402
      ASSERT(dst[i] <= 1.0F);
 
2403
   }
 
2404
}
 
2405
 
 
2406
static void
 
2407
unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
 
2408
{
 
2409
   /* only return Z, not stencil data */
 
2410
   const GLuint *s = ((const GLuint *) src);
 
2411
   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
 
2412
   GLuint i;
 
2413
   for (i = 0; i < n; i++) {
 
2414
      dst[i] = (s[i] & 0x00ffffff) * scale;
 
2415
      ASSERT(dst[i] >= 0.0F);
 
2416
      ASSERT(dst[i] <= 1.0F);
 
2417
   }
 
2418
}
 
2419
 
 
2420
static void
 
2421
unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst)
 
2422
{
 
2423
   const GLushort *s = ((const GLushort *) src);
 
2424
   GLuint i;
 
2425
   for (i = 0; i < n; i++) {
 
2426
      dst[i] = s[i] * (1.0F / 65535.0F);
 
2427
   }
 
2428
}
 
2429
 
 
2430
static void
 
2431
unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst)
 
2432
{
 
2433
   const GLuint *s = ((const GLuint *) src);
 
2434
   GLuint i;
 
2435
   for (i = 0; i < n; i++) {
 
2436
      dst[i] = s[i] * (1.0F / 0xffffffff);
 
2437
   }
 
2438
}
 
2439
 
 
2440
static void
 
2441
unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst)
 
2442
{
 
2443
   memcpy(dst, src, n * sizeof(float));
 
2444
}
 
2445
 
 
2446
static void
 
2447
unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
 
2448
{
 
2449
   const GLfloat *s = ((const GLfloat *) src);
 
2450
   GLuint i;
 
2451
   for (i = 0; i < n; i++) {
 
2452
      dst[i] = s[i * 2];
 
2453
   }
 
2454
}
 
2455
 
 
2456
 
 
2457
 
 
2458
/**
 
2459
 * Unpack Z values.
 
2460
 * The returned values will always be in the range [0.0, 1.0].
 
2461
 */
 
2462
void
 
2463
_mesa_unpack_float_z_row(gl_format format, GLuint n,
 
2464
                         const void *src, GLfloat *dst)
 
2465
{
 
2466
   unpack_float_z_func unpack;
 
2467
 
 
2468
   switch (format) {
 
2469
   case MESA_FORMAT_Z24_S8:
 
2470
   case MESA_FORMAT_Z24_X8:
 
2471
      unpack = unpack_float_z_Z24_X8;
 
2472
      break;
 
2473
   case MESA_FORMAT_S8_Z24:
 
2474
   case MESA_FORMAT_X8_Z24:
 
2475
      unpack = unpack_float_z_X8_Z24;
 
2476
      break;
 
2477
   case MESA_FORMAT_Z16:
 
2478
      unpack = unpack_float_z_Z16;
 
2479
      break;
 
2480
   case MESA_FORMAT_Z32:
 
2481
      unpack = unpack_float_z_Z32;
 
2482
      break;
 
2483
   case MESA_FORMAT_Z32_FLOAT:
 
2484
      unpack = unpack_float_z_Z32F;
 
2485
      break;
 
2486
   case MESA_FORMAT_Z32_FLOAT_X24S8:
 
2487
      unpack = unpack_float_z_Z32X24S8;
 
2488
      break;
 
2489
   default:
 
2490
      _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
 
2491
                    _mesa_get_format_name(format));
 
2492
      return;
 
2493
   }
 
2494
 
 
2495
   unpack(n, src, dst);
 
2496
}
 
2497
 
 
2498
 
 
2499
 
 
2500
typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
 
2501
 
 
2502
static void
 
2503
unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
 
2504
{
 
2505
   /* only return Z, not stencil data */
 
2506
   const GLuint *s = ((const GLuint *) src);
 
2507
   GLuint i;
 
2508
   for (i = 0; i < n; i++) {
 
2509
      dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
 
2510
   }
 
2511
}
 
2512
 
 
2513
static void
 
2514
unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
 
2515
{
 
2516
   /* only return Z, not stencil data */
 
2517
   const GLuint *s = ((const GLuint *) src);
 
2518
   GLuint i;
 
2519
   for (i = 0; i < n; i++) {
 
2520
      dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
 
2521
   }
 
2522
}
 
2523
 
 
2524
static void
 
2525
unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n)
 
2526
{
 
2527
   const GLushort *s = ((const GLushort *)src);
 
2528
   GLuint i;
 
2529
   for (i = 0; i < n; i++) {
 
2530
      dst[i] = (s[i] << 16) | s[i];
 
2531
   }
 
2532
}
 
2533
 
 
2534
static void
 
2535
unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
 
2536
{
 
2537
   memcpy(dst, src, n * sizeof(GLuint));
 
2538
}
 
2539
 
 
2540
 
 
2541
/**
 
2542
 * Unpack Z values.
 
2543
 * The returned values will always be in the range [0, 0xffffffff].
 
2544
 */
 
2545
void
 
2546
_mesa_unpack_uint_z_row(gl_format format, GLuint n,
 
2547
                        const void *src, GLuint *dst)
 
2548
{
 
2549
   unpack_uint_z_func unpack;
 
2550
   const GLubyte *srcPtr = (GLubyte *) src;
 
2551
 
 
2552
   switch (format) {
 
2553
   case MESA_FORMAT_Z24_S8:
 
2554
   case MESA_FORMAT_Z24_X8:
 
2555
      unpack = unpack_uint_z_Z24_X8;
 
2556
      break;
 
2557
   case MESA_FORMAT_S8_Z24:
 
2558
   case MESA_FORMAT_X8_Z24:
 
2559
      unpack = unpack_uint_z_X8_Z24;
 
2560
      break;
 
2561
   case MESA_FORMAT_Z16:
 
2562
      unpack = unpack_uint_z_Z16;
 
2563
      break;
 
2564
   case MESA_FORMAT_Z32:
 
2565
      unpack = unpack_uint_z_Z32;
 
2566
      break;
 
2567
   default:
 
2568
      _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
 
2569
                    _mesa_get_format_name(format));
 
2570
      return;
 
2571
   }
 
2572
 
 
2573
   unpack(srcPtr, dst, n);
 
2574
}
 
2575
 
 
2576
 
 
2577
static void
 
2578
unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
 
2579
{
 
2580
   memcpy(dst, src, n);
 
2581
}
 
2582
 
 
2583
static void
 
2584
unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n)
 
2585
{
 
2586
   GLuint i;
 
2587
   const GLuint *src32 = src;
 
2588
 
 
2589
   for (i = 0; i < n; i++)
 
2590
      dst[i] = src32[i] & 0xff;
 
2591
}
 
2592
 
 
2593
static void
 
2594
unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n)
 
2595
{
 
2596
   GLuint i;
 
2597
   const GLuint *src32 = src;
 
2598
 
 
2599
   for (i = 0; i < n; i++)
 
2600
      dst[i] = src32[i] >> 24;
 
2601
}
 
2602
 
 
2603
static void
 
2604
unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n)
 
2605
{
 
2606
   GLuint i;
 
2607
   const GLuint *src32 = src;
 
2608
 
 
2609
   for (i = 0; i < n; i++)
 
2610
      dst[i] = src32[i * 2 + 1] & 0xff;
 
2611
}
 
2612
 
 
2613
void
 
2614
_mesa_unpack_ubyte_stencil_row(gl_format format, GLuint n,
 
2615
                               const void *src, GLubyte *dst)
 
2616
{
 
2617
   switch (format) {
 
2618
   case MESA_FORMAT_S8:
 
2619
      unpack_ubyte_s_S8(src, dst, n);
 
2620
      break;
 
2621
   case MESA_FORMAT_Z24_S8:
 
2622
      unpack_ubyte_s_Z24_S8(src, dst, n);
 
2623
      break;
 
2624
   case MESA_FORMAT_S8_Z24:
 
2625
      unpack_ubyte_s_S8_Z24(src, dst, n);
 
2626
      break;
 
2627
   case MESA_FORMAT_Z32_FLOAT_X24S8:
 
2628
      unpack_ubyte_s_Z32_FLOAT_X24S8(src, dst, n);
 
2629
      break;
 
2630
   default:
 
2631
      _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
 
2632
                    _mesa_get_format_name(format));
 
2633
      return;
 
2634
   }
 
2635
}
 
2636
 
 
2637
static void
 
2638
unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint *src, GLuint *dst, GLuint n)
 
2639
{
 
2640
   GLuint i;
 
2641
 
 
2642
   for (i = 0; i < n; i++) {
 
2643
      GLuint val = src[i];
 
2644
      dst[i] = val >> 24 | val << 8;
 
2645
   }
 
2646
}
 
2647
 
 
2648
static void
 
2649
unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint *src, GLuint *dst, GLuint n)
 
2650
{
 
2651
   memcpy(dst, src, n * 4);
 
2652
}
 
2653
 
 
2654
void
 
2655
_mesa_unpack_uint_24_8_depth_stencil_row(gl_format format, GLuint n,
 
2656
                                         const void *src, GLuint *dst)
 
2657
{
 
2658
   switch (format) {
 
2659
   case MESA_FORMAT_Z24_S8:
 
2660
      unpack_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
 
2661
      break;
 
2662
   case MESA_FORMAT_S8_Z24:
 
2663
      unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
 
2664
      break;
 
2665
   default:
 
2666
      _mesa_problem(NULL,
 
2667
                    "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
 
2668
                    _mesa_get_format_name(format));
 
2669
      return;
 
2670
   }
 
2671
}