2
* Mesa 3-D graphics library
4
* Copyright (c) 2011 VMware, Inc.
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:
13
* The above copyright notice and this permission notice shall be included
14
* in all copies or substantial portions of the Software.
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.
26
#include "format_unpack.h"
28
#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
29
#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
33
/* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
35
#define EXPAND_1_8(X) ( (X) ? 0xff : 0x0 )
37
#define EXPAND_2_8(X) ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
39
#define EXPAND_3_8(X) ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
41
#define EXPAND_4_8(X) ( ((X) << 4) | (X) )
43
#define EXPAND_5_8(X) ( ((X) << 3) | ((X) >> 2) )
45
#define EXPAND_6_8(X) ( ((X) << 2) | ((X) >> 4) )
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.
54
nonlinear_to_linear(GLubyte cs8)
56
static GLfloat table[256];
57
static GLboolean tableReady = GL_FALSE;
59
/* compute lookup table now */
61
for (i = 0; i < 256; i++) {
62
const GLfloat cs = UBYTE_TO_FLOAT(i);
64
table[i] = cs / 12.92f;
67
table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
76
/**********************************************************************/
77
/* Unpack, returning GLfloat colors */
78
/**********************************************************************/
80
typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);
84
unpack_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
86
const GLuint *s = ((const GLuint *) src);
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 );
97
unpack_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
99
const GLuint *s = ((const GLuint *) src);
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) );
110
unpack_ARGB8888(const void *src, GLfloat dst[][4], GLuint n)
112
const GLuint *s = ((const GLuint *) src);
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) );
123
unpack_ARGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
125
const GLuint *s = ((const GLuint *) src);
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 );
136
unpack_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
138
const GLuint *s = ((const GLuint *) src);
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;
149
unpack_RGBX8888_REV(const void *src, GLfloat dst[][4], GLuint n)
151
const GLuint *s = ((const GLuint *) src);
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;
162
unpack_XRGB8888(const void *src, GLfloat dst[][4], GLuint n)
164
const GLuint *s = ((const GLuint *) src);
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;
175
unpack_XRGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
177
const GLuint *s = ((const GLuint *) src);
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;
188
unpack_RGB888(const void *src, GLfloat dst[][4], GLuint n)
190
const GLubyte *s = (const GLubyte *) src;
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;
201
unpack_BGR888(const void *src, GLfloat dst[][4], GLuint n)
203
const GLubyte *s = (const GLubyte *) src;
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;
214
unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n)
216
const GLushort *s = ((const GLushort *) src);
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;
227
unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n)
229
const GLushort *s = ((const GLushort *) src);
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;
241
unpack_ARGB4444(const void *src, GLfloat dst[][4], GLuint n)
243
const GLushort *s = ((const GLushort *) src);
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);
254
unpack_ARGB4444_REV(const void *src, GLfloat dst[][4], GLuint n)
256
const GLushort *s = ((const GLushort *) src);
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);
267
unpack_RGBA5551(const void *src, GLfloat dst[][4], GLuint n)
269
const GLushort *s = ((const GLushort *) src);
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;
280
unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n)
282
const GLushort *s = ((const GLushort *) src);
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;
293
unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n)
295
const GLushort *s = ((const GLushort *) src);
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;
307
unpack_AL44(const void *src, GLfloat dst[][4], GLuint n)
309
const GLubyte *s = ((const GLubyte *) src);
311
for (i = 0; i < n; i++) {
314
dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
315
dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
320
unpack_AL88(const void *src, GLfloat dst[][4], GLuint n)
322
const GLushort *s = ((const GLushort *) src);
324
for (i = 0; i < n; i++) {
327
dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
328
dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
333
unpack_AL88_REV(const void *src, GLfloat dst[][4], GLuint n)
335
const GLushort *s = ((const GLushort *) src);
337
for (i = 0; i < n; i++) {
340
dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
341
dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
346
unpack_AL1616(const void *src, GLfloat dst[][4], GLuint n)
348
const GLuint *s = ((const GLuint *) src);
350
for (i = 0; i < n; i++) {
353
dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
354
dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
359
unpack_AL1616_REV(const void *src, GLfloat dst[][4], GLuint n)
361
const GLuint *s = ((const GLuint *) src);
363
for (i = 0; i < n; i++) {
366
dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
367
dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
372
unpack_RGB332(const void *src, GLfloat dst[][4], GLuint n)
374
const GLubyte *s = ((const GLubyte *) src);
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;
386
unpack_A8(const void *src, GLfloat dst[][4], GLuint n)
388
const GLubyte *s = ((const GLubyte *) src);
390
for (i = 0; i < n; i++) {
393
dst[i][BCOMP] = 0.0F;
394
dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
399
unpack_A16(const void *src, GLfloat dst[][4], GLuint n)
401
const GLushort *s = ((const GLushort *) src);
403
for (i = 0; i < n; i++) {
406
dst[i][BCOMP] = 0.0F;
407
dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
412
unpack_L8(const void *src, GLfloat dst[][4], GLuint n)
414
const GLubyte *s = ((const GLubyte *) src);
416
for (i = 0; i < n; i++) {
419
dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
420
dst[i][ACOMP] = 1.0F;
425
unpack_L16(const void *src, GLfloat dst[][4], GLuint n)
427
const GLushort *s = ((const GLushort *) src);
429
for (i = 0; i < n; i++) {
432
dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
433
dst[i][ACOMP] = 1.0F;
438
unpack_I8(const void *src, GLfloat dst[][4], GLuint n)
440
const GLubyte *s = ((const GLubyte *) src);
442
for (i = 0; i < n; i++) {
446
dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
451
unpack_I16(const void *src, GLfloat dst[][4], GLuint n)
453
const GLushort *s = ((const GLushort *) src);
455
for (i = 0; i < n; i++) {
459
dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
464
unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n)
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;
489
unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
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;
514
unpack_R8(const void *src, GLfloat dst[][4], GLuint n)
516
const GLubyte *s = ((const GLubyte *) src);
518
for (i = 0; i < n; i++) {
519
dst[i][0] = UBYTE_TO_FLOAT(s[i]);
527
unpack_GR88(const void *src, GLfloat dst[][4], GLuint n)
529
const GLushort *s = ((const GLushort *) src);
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 );
540
unpack_RG88(const void *src, GLfloat dst[][4], GLuint n)
542
const GLushort *s = ((const GLushort *) src);
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 );
553
unpack_R16(const void *src, GLfloat dst[][4], GLuint n)
555
const GLushort *s = ((const GLushort *) src);
557
for (i = 0; i < n; i++) {
558
dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]);
566
unpack_RG1616(const void *src, GLfloat dst[][4], GLuint n)
568
const GLuint *s = ((const GLuint *) src);
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 );
579
unpack_RG1616_REV(const void *src, GLfloat dst[][4], GLuint n)
581
const GLuint *s = ((const GLuint *) src);
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 );
592
unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n)
594
const GLuint *s = ((const GLuint *) src);
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);
606
unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
608
/* only return Z, not stencil data */
609
const GLuint *s = ((const GLuint *) src);
610
const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
612
for (i = 0; i < n; i++) {
615
dst[i][2] = (s[i] >> 8) * scale;
617
ASSERT(dst[i][0] >= 0.0F);
618
ASSERT(dst[i][0] <= 1.0F);
623
unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
625
/* only return Z, not stencil data */
626
const GLuint *s = ((const GLuint *) src);
627
const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
629
for (i = 0; i < n; i++) {
632
dst[i][2] = (s[i] & 0x00ffffff) * scale;
634
ASSERT(dst[i][0] >= 0.0F);
635
ASSERT(dst[i][0] <= 1.0F);
640
unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
642
const GLushort *s = ((const GLushort *) src);
644
for (i = 0; i < n; i++) {
647
dst[i][2] = s[i] * (1.0F / 65535.0F);
653
unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n)
655
unpack_S8_Z24(src, dst, n);
659
unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n)
661
unpack_Z24_S8(src, dst, n);
665
unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
667
const GLuint *s = ((const GLuint *) src);
669
for (i = 0; i < n; i++) {
672
dst[i][2] = s[i] * (1.0F / 0xffffffff);
678
unpack_Z32_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
680
const GLfloat *s = ((const GLfloat *) src);
682
for (i = 0; i < n; i++) {
685
dst[i][2] = s[i * 2];
691
unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[][4], GLuint n)
693
const GLfloat *s = ((const GLfloat *) src);
695
for (i = 0; i < n; i++) {
705
unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
707
/* should never be used */
709
for (i = 0; i < n; i++) {
719
unpack_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
721
const GLubyte *s = (const GLubyte *) src;
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;
732
unpack_SRGBA8(const void *src, GLfloat dst[][4], GLuint n)
734
const GLuint *s = ((const GLuint *) src);
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! */
745
unpack_SARGB8(const void *src, GLfloat dst[][4], GLuint n)
747
const GLuint *s = ((const GLuint *) src);
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! */
758
unpack_SL8(const void *src, GLfloat dst[][4], GLuint n)
760
const GLubyte *s = ((const GLubyte *) src);
762
for (i = 0; i < n; i++) {
765
dst[i][BCOMP] = nonlinear_to_linear(s[i]);
766
dst[i][ACOMP] = 1.0F;
771
unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n)
773
const GLushort *s = (const GLushort *) src;
775
for (i = 0; i < n; i++) {
778
dst[i][BCOMP] = nonlinear_to_linear(s[i] & 0xff);
779
dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
784
unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
789
unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
794
unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
799
unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
804
unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
809
unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
814
unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
819
unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
824
unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
829
unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
835
unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
837
const GLfloat *s = (const GLfloat *) src;
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];
848
unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
850
const GLhalfARB *s = (const GLhalfARB *) src;
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]);
861
unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
863
const GLfloat *s = (const GLfloat *) src;
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;
874
unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
876
const GLhalfARB *s = (const GLhalfARB *) src;
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;
887
unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
889
const GLfloat *s = (const GLfloat *) src;
891
for (i = 0; i < n; i++) {
894
dst[i][BCOMP] = 0.0F;
895
dst[i][ACOMP] = s[i];
900
unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
902
const GLhalfARB *s = (const GLhalfARB *) src;
904
for (i = 0; i < n; i++) {
907
dst[i][BCOMP] = 0.0F;
908
dst[i][ACOMP] = _mesa_half_to_float(s[i]);
913
unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
915
const GLfloat *s = (const GLfloat *) src;
917
for (i = 0; i < n; i++) {
920
dst[i][BCOMP] = s[i];
921
dst[i][ACOMP] = 1.0F;
926
unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
928
const GLhalfARB *s = (const GLhalfARB *) src;
930
for (i = 0; i < n; i++) {
933
dst[i][BCOMP] = _mesa_half_to_float(s[i]);
934
dst[i][ACOMP] = 1.0F;
939
unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
941
const GLfloat *s = (const GLfloat *) src;
943
for (i = 0; i < n; i++) {
946
dst[i][BCOMP] = s[i*2+0];
947
dst[i][ACOMP] = s[i*2+1];
952
unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
954
const GLhalfARB *s = (const GLhalfARB *) src;
956
for (i = 0; i < n; i++) {
959
dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
960
dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
965
unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
967
const GLfloat *s = (const GLfloat *) src;
969
for (i = 0; i < n; i++) {
973
dst[i][ACOMP] = s[i];
978
unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
980
const GLhalfARB *s = (const GLhalfARB *) src;
982
for (i = 0; i < n; i++) {
986
dst[i][ACOMP] = _mesa_half_to_float(s[i]);
991
unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
993
const GLfloat *s = (const GLfloat *) src;
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;
1004
unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1006
const GLhalfARB *s = (const GLhalfARB *) src;
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;
1017
unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1019
const GLfloat *s = (const GLfloat *) src;
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;
1030
unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1032
const GLhalfARB *s = (const GLhalfARB *) src;
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;
1044
unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
1046
const GLbyte *s = (const GLbyte *) src;
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];
1057
unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
1059
const GLshort *s = (const GLshort *) src;
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];
1070
unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1072
const GLint *s = (const GLint *) src;
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];
1083
unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1085
const GLubyte *s = (const GLubyte *) src;
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];
1096
unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1098
const GLushort *s = (const GLushort *) src;
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];
1109
unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1111
const GLuint *s = (const GLuint *) src;
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];
1122
unpack_DUDV8(const void *src, GLfloat dst[][4], GLuint n)
1124
const GLbyte *s = (const GLbyte *) src;
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]);
1135
unpack_SIGNED_R8(const void *src, GLfloat dst[][4], GLuint n)
1137
const GLbyte *s = ((const GLbyte *) src);
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;
1148
unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
1150
const GLushort *s = ((const GLushort *) src);
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;
1161
unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
1163
const GLuint *s = ((const GLuint *) src);
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;
1174
unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
1176
const GLuint *s = ((const GLuint *) src);
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] ) );
1187
unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
1189
const GLuint *s = ((const GLuint *) src);
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) );
1200
unpack_SIGNED_R16(const void *src, GLfloat dst[][4], GLuint n)
1202
const GLshort *s = ((const GLshort *) src);
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;
1213
unpack_SIGNED_GR1616(const void *src, GLfloat dst[][4], GLuint n)
1215
const GLuint *s = ((const GLuint *) src);
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;
1226
unpack_SIGNED_RGB_16(const void *src, GLfloat dst[][4], GLuint n)
1228
const GLshort *s = (const GLshort *) src;
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;
1239
unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1241
const GLshort *s = (const GLshort *) src;
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] );
1252
unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1254
const GLushort *s = (const GLushort *) src;
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] );
1265
unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1271
unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1277
unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1283
unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1289
unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1295
unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1301
unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1307
unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1313
unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1319
unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n)
1321
const GLbyte *s = ((const GLbyte *) src);
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] );
1332
unpack_SIGNED_L8(const void *src, GLfloat dst[][4], GLuint n)
1334
const GLbyte *s = ((const GLbyte *) src);
1336
for (i = 0; i < n; i++) {
1339
dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1340
dst[i][ACOMP] = 1.0F;
1345
unpack_SIGNED_AL88(const void *src, GLfloat dst[][4], GLuint n)
1347
const GLshort *s = ((const GLshort *) src);
1349
for (i = 0; i < n; i++) {
1352
dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1353
dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1358
unpack_SIGNED_I8(const void *src, GLfloat dst[][4], GLuint n)
1360
const GLbyte *s = ((const GLbyte *) src);
1362
for (i = 0; i < n; i++) {
1366
dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1371
unpack_SIGNED_A16(const void *src, GLfloat dst[][4], GLuint n)
1373
const GLshort *s = ((const GLshort *) src);
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] );
1384
unpack_SIGNED_L16(const void *src, GLfloat dst[][4], GLuint n)
1386
const GLshort *s = ((const GLshort *) src);
1388
for (i = 0; i < n; i++) {
1391
dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1392
dst[i][ACOMP] = 1.0F;
1397
unpack_SIGNED_AL1616(const void *src, GLfloat dst[][4], GLuint n)
1399
const GLshort *s = (const GLshort *) src;
1401
for (i = 0; i < n; i++) {
1404
dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
1405
dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
1410
unpack_SIGNED_I16(const void *src, GLfloat dst[][4], GLuint n)
1412
const GLshort *s = ((const GLshort *) src);
1414
for (i = 0; i < n; i++) {
1418
dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1423
unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
1425
const GLuint *s = (const GLuint *) src;
1427
for (i = 0; i < n; i++) {
1428
rgb9e5_to_float3(s[i], dst[i]);
1429
dst[i][ACOMP] = 1.0F;
1434
unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
1436
const GLuint *s = (const GLuint *) src;
1438
for (i = 0; i < n; i++) {
1439
r11g11b10f_to_float3(s[i], dst[i]);
1440
dst[i][ACOMP] = 1.0F;
1446
* Return the unpacker function for the given format.
1448
static unpack_rgba_func
1449
get_unpack_rgba_function(gl_format format)
1451
static unpack_rgba_func table[MESA_FORMAT_COUNT];
1452
static GLboolean initialized = GL_FALSE;
1455
table[MESA_FORMAT_NONE] = NULL;
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;
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;
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;
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;
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;
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;
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;
1565
table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
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;
1576
table[MESA_FORMAT_RGB9_E5_FLOAT] = unpack_RGB9_E5_FLOAT;
1577
table[MESA_FORMAT_R11_G11_B10_FLOAT] = unpack_R11_G11_B10_FLOAT;
1579
table[MESA_FORMAT_Z32_FLOAT] = unpack_Z32_FLOAT;
1580
table[MESA_FORMAT_Z32_FLOAT_X24S8] = unpack_Z32_FLOAT_X24S8;
1582
initialized = GL_TRUE;
1585
return table[format];
1590
* Unpack rgba colors, returning as GLfloat values.
1593
_mesa_unpack_rgba_row(gl_format format, GLuint n,
1594
const void *src, GLfloat dst[][4])
1596
unpack_rgba_func unpack = get_unpack_rgba_function(format);
1597
unpack(src, dst, n);
1601
/**********************************************************************/
1602
/* Unpack, returning GLubyte colors */
1603
/**********************************************************************/
1607
unpack_ubyte_RGBA8888(const void *src, GLubyte dst[][4], GLuint n)
1609
const GLuint *s = ((const GLuint *) src);
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;
1620
unpack_ubyte_RGBA8888_REV(const void *src, GLubyte dst[][4], GLuint n)
1622
const GLuint *s = ((const GLuint *) src);
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);
1633
unpack_ubyte_ARGB8888(const void *src, GLubyte dst[][4], GLuint n)
1635
const GLuint *s = ((const GLuint *) src);
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);
1646
unpack_ubyte_ARGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
1648
const GLuint *s = ((const GLuint *) src);
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;
1659
unpack_ubyte_RGBX8888(const void *src, GLubyte dst[][4], GLuint n)
1661
const GLuint *s = ((const GLuint *) src);
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;
1672
unpack_ubyte_RGBX8888_REV(const void *src, GLubyte dst[][4], GLuint n)
1674
const GLuint *s = ((const GLuint *) src);
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;
1685
unpack_ubyte_XRGB8888(const void *src, GLubyte dst[][4], GLuint n)
1687
const GLuint *s = ((const GLuint *) src);
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;
1698
unpack_ubyte_XRGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
1700
const GLuint *s = ((const GLuint *) src);
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;
1711
unpack_ubyte_RGB888(const void *src, GLubyte dst[][4], GLuint n)
1713
const GLubyte *s = (const GLubyte *) src;
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;
1724
unpack_ubyte_BGR888(const void *src, GLubyte dst[][4], GLuint n)
1726
const GLubyte *s = (const GLubyte *) src;
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;
1737
unpack_ubyte_RGB565(const void *src, GLubyte dst[][4], GLuint n)
1739
const GLushort *s = ((const GLushort *) src);
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;
1750
unpack_ubyte_RGB565_REV(const void *src, GLubyte dst[][4], GLuint n)
1752
const GLushort *s = ((const GLushort *) src);
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;
1764
unpack_ubyte_ARGB4444(const void *src, GLubyte dst[][4], GLuint n)
1766
const GLushort *s = ((const GLushort *) src);
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);
1777
unpack_ubyte_ARGB4444_REV(const void *src, GLubyte dst[][4], GLuint n)
1779
const GLushort *s = ((const GLushort *) src);
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);
1790
unpack_ubyte_RGBA5551(const void *src, GLubyte dst[][4], GLuint n)
1792
const GLushort *s = ((const GLushort *) src);
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);
1803
unpack_ubyte_ARGB1555(const void *src, GLubyte dst[][4], GLuint n)
1805
const GLushort *s = ((const GLushort *) src);
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);
1816
unpack_ubyte_ARGB1555_REV(const void *src, GLubyte dst[][4], GLuint n)
1818
const GLushort *s = ((const GLushort *) src);
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);
1830
unpack_ubyte_AL44(const void *src, GLubyte dst[][4], GLuint n)
1832
const GLubyte *s = ((const GLubyte *) src);
1834
for (i = 0; i < n; i++) {
1837
dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xf);
1838
dst[i][ACOMP] = EXPAND_4_8(s[i] >> 4);
1843
unpack_ubyte_AL88(const void *src, GLubyte dst[][4], GLuint n)
1845
const GLushort *s = ((const GLushort *) src);
1847
for (i = 0; i < n; i++) {
1850
dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xff);
1851
dst[i][ACOMP] = EXPAND_4_8(s[i] >> 8);
1856
unpack_ubyte_AL88_REV(const void *src, GLubyte dst[][4], GLuint n)
1858
const GLushort *s = ((const GLushort *) src);
1860
for (i = 0; i < n; i++) {
1863
dst[i][BCOMP] = EXPAND_4_8(s[i] >> 8);
1864
dst[i][ACOMP] = EXPAND_4_8(s[i] & 0xff);
1869
unpack_ubyte_RGB332(const void *src, GLubyte dst[][4], GLuint n)
1871
const GLubyte *s = ((const GLubyte *) src);
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;
1882
unpack_ubyte_A8(const void *src, GLubyte dst[][4], GLuint n)
1884
const GLubyte *s = ((const GLubyte *) src);
1886
for (i = 0; i < n; i++) {
1890
dst[i][ACOMP] = s[i];
1895
unpack_ubyte_L8(const void *src, GLubyte dst[][4], GLuint n)
1897
const GLubyte *s = ((const GLubyte *) src);
1899
for (i = 0; i < n; i++) {
1902
dst[i][BCOMP] = s[i];
1903
dst[i][ACOMP] = 0xff;
1909
unpack_ubyte_I8(const void *src, GLubyte dst[][4], GLuint n)
1911
const GLubyte *s = ((const GLubyte *) src);
1913
for (i = 0; i < n; i++) {
1917
dst[i][ACOMP] = s[i];
1922
unpack_ubyte_R8(const void *src, GLubyte dst[][4], GLuint n)
1924
const GLubyte *s = ((const GLubyte *) src);
1926
for (i = 0; i < n; i++) {
1935
unpack_ubyte_GR88(const void *src, GLubyte dst[][4], GLuint n)
1937
const GLushort *s = ((const GLushort *) src);
1939
for (i = 0; i < n; i++) {
1940
dst[i][RCOMP] = s[i] & 0xff;
1941
dst[i][GCOMP] = s[i] >> 8;
1943
dst[i][ACOMP] = 0xff;
1948
unpack_ubyte_RG88(const void *src, GLubyte dst[][4], GLuint n)
1950
const GLushort *s = ((const GLushort *) src);
1952
for (i = 0; i < n; i++) {
1953
dst[i][RCOMP] = s[i] >> 8;
1954
dst[i][GCOMP] = s[i] & 0xff;
1956
dst[i][ACOMP] = 0xff;
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.
1966
_mesa_unpack_ubyte_rgba_row(gl_format format, GLuint n,
1967
const void *src, GLubyte dst[][4])
1970
case MESA_FORMAT_RGBA8888:
1971
unpack_ubyte_RGBA8888(src, dst, n);
1973
case MESA_FORMAT_RGBA8888_REV:
1974
unpack_ubyte_RGBA8888_REV(src, dst, n);
1976
case MESA_FORMAT_ARGB8888:
1977
unpack_ubyte_ARGB8888(src, dst, n);
1979
case MESA_FORMAT_ARGB8888_REV:
1980
unpack_ubyte_ARGB8888_REV(src, dst, n);
1982
case MESA_FORMAT_RGBX8888:
1983
unpack_ubyte_RGBX8888(src, dst, n);
1985
case MESA_FORMAT_RGBX8888_REV:
1986
unpack_ubyte_RGBX8888_REV(src, dst, n);
1988
case MESA_FORMAT_XRGB8888:
1989
unpack_ubyte_XRGB8888(src, dst, n);
1991
case MESA_FORMAT_XRGB8888_REV:
1992
unpack_ubyte_XRGB8888_REV(src, dst, n);
1994
case MESA_FORMAT_RGB888:
1995
unpack_ubyte_RGB888(src, dst, n);
1997
case MESA_FORMAT_BGR888:
1998
unpack_ubyte_BGR888(src, dst, n);
2000
case MESA_FORMAT_RGB565:
2001
unpack_ubyte_RGB565(src, dst, n);
2003
case MESA_FORMAT_RGB565_REV:
2004
unpack_ubyte_RGB565_REV(src, dst, n);
2006
case MESA_FORMAT_ARGB4444:
2007
unpack_ubyte_ARGB4444(src, dst, n);
2009
case MESA_FORMAT_ARGB4444_REV:
2010
unpack_ubyte_ARGB4444_REV(src, dst, n);
2012
case MESA_FORMAT_RGBA5551:
2013
unpack_ubyte_RGBA5551(src, dst, n);
2015
case MESA_FORMAT_ARGB1555:
2016
unpack_ubyte_ARGB1555(src, dst, n);
2018
case MESA_FORMAT_ARGB1555_REV:
2019
unpack_ubyte_ARGB1555_REV(src, dst, n);
2021
case MESA_FORMAT_AL44:
2022
unpack_ubyte_AL44(src, dst, n);
2024
case MESA_FORMAT_AL88:
2025
unpack_ubyte_AL88(src, dst, n);
2027
case MESA_FORMAT_AL88_REV:
2028
unpack_ubyte_AL88_REV(src, dst, n);
2030
case MESA_FORMAT_RGB332:
2031
unpack_ubyte_RGB332(src, dst, n);
2033
case MESA_FORMAT_A8:
2034
unpack_ubyte_A8(src, dst, n);
2036
case MESA_FORMAT_L8:
2037
unpack_ubyte_L8(src, dst, n);
2039
case MESA_FORMAT_I8:
2040
unpack_ubyte_I8(src, dst, n);
2042
case MESA_FORMAT_R8:
2043
unpack_ubyte_R8(src, dst, n);
2045
case MESA_FORMAT_GR88:
2046
unpack_ubyte_GR88(src, dst, n);
2048
case MESA_FORMAT_RG88:
2049
unpack_ubyte_RG88(src, dst, n);
2052
/* get float values, convert to ubyte */
2054
GLfloat *tmp = (GLfloat *) malloc(n * 4 * sizeof(GLfloat));
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]);
2072
/**********************************************************************/
2073
/* Unpack, returning GLuint colors */
2074
/**********************************************************************/
2077
unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2079
memcpy(dst, src, n * 4 * sizeof(GLuint));
2083
unpack_int_rgba_RGBA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
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];
2096
unpack_int_rgba_RGBA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
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];
2109
unpack_int_rgba_RGBA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
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];
2122
unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
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];
2135
unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
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];
2148
unpack_int_rgba_RGB_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
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];
2161
unpack_int_rgba_RGB_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
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];
2174
unpack_int_rgba_RGB_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
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];
2187
unpack_int_rgba_RGB_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
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];
2200
unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2204
for (i = 0; i < n; i++) {
2205
dst[i][0] = src[i * 2 + 0];
2206
dst[i][1] = src[i * 2 + 1];
2213
unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2217
for (i = 0; i < n; i++) {
2226
unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2230
for (i = 0; i < n; i++) {
2231
dst[i][0] = dst[i][1] = dst[i][2] = src[i];
2237
unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
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];
2248
unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2252
for (i = 0; i < n; i++) {
2253
dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
2258
unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
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;
2272
_mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
2273
const void *src, GLuint dst[][4])
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.
2279
case MESA_FORMAT_RGBA_UINT32:
2280
case MESA_FORMAT_RGBA_INT32:
2281
unpack_int_rgba_RGBA_UINT32(src, dst, n);
2284
case MESA_FORMAT_RGBA_UINT16:
2285
unpack_int_rgba_RGBA_UINT16(src, dst, n);
2287
case MESA_FORMAT_RGBA_INT16:
2288
unpack_int_rgba_RGBA_INT16(src, dst, n);
2291
case MESA_FORMAT_RGBA_UINT8:
2292
unpack_int_rgba_RGBA_UINT8(src, dst, n);
2294
case MESA_FORMAT_RGBA_INT8:
2295
unpack_int_rgba_RGBA_INT8(src, dst, n);
2298
case MESA_FORMAT_RGB_UINT32:
2299
case MESA_FORMAT_RGB_INT32:
2300
unpack_int_rgba_RGB_UINT32(src, dst, n);
2303
case MESA_FORMAT_RGB_UINT16:
2304
unpack_int_rgba_RGB_UINT16(src, dst, n);
2306
case MESA_FORMAT_RGB_INT16:
2307
unpack_int_rgba_RGB_INT16(src, dst, n);
2310
case MESA_FORMAT_RGB_UINT8:
2311
unpack_int_rgba_RGB_UINT8(src, dst, n);
2313
case MESA_FORMAT_RGB_INT8:
2314
unpack_int_rgba_RGB_INT8(src, dst, n);
2317
case MESA_FORMAT_RG_UINT32:
2318
case MESA_FORMAT_RG_INT32:
2319
unpack_int_rgba_RG_UINT32(src, dst, n);
2321
case MESA_FORMAT_R_UINT32:
2322
case MESA_FORMAT_R_INT32:
2323
unpack_int_rgba_R_UINT32(src, dst, n);
2326
case MESA_FORMAT_LUMINANCE_UINT32:
2327
case MESA_FORMAT_LUMINANCE_INT32:
2328
unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
2330
case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
2331
case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
2332
unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
2334
case MESA_FORMAT_INTENSITY_UINT32:
2335
case MESA_FORMAT_INTENSITY_INT32:
2336
unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
2339
case MESA_FORMAT_ARGB2101010_UINT:
2340
unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
2343
_mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
2344
_mesa_get_format_name(format));
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
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)
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;
2374
/* XXX needs to be fixed for compressed formats */
2376
srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
2377
dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
2379
for (i = 0; i < height; i++) {
2380
unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
2382
dstRow += dstRowStride;
2383
srcRow += srcRowStride;
2390
typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
2393
unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
2395
/* only return Z, not stencil data */
2396
const GLuint *s = ((const GLuint *) src);
2397
const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
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);
2407
unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
2409
/* only return Z, not stencil data */
2410
const GLuint *s = ((const GLuint *) src);
2411
const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
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);
2421
unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst)
2423
const GLushort *s = ((const GLushort *) src);
2425
for (i = 0; i < n; i++) {
2426
dst[i] = s[i] * (1.0F / 65535.0F);
2431
unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst)
2433
const GLuint *s = ((const GLuint *) src);
2435
for (i = 0; i < n; i++) {
2436
dst[i] = s[i] * (1.0F / 0xffffffff);
2441
unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst)
2443
memcpy(dst, src, n * sizeof(float));
2447
unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
2449
const GLfloat *s = ((const GLfloat *) src);
2451
for (i = 0; i < n; i++) {
2460
* The returned values will always be in the range [0.0, 1.0].
2463
_mesa_unpack_float_z_row(gl_format format, GLuint n,
2464
const void *src, GLfloat *dst)
2466
unpack_float_z_func unpack;
2469
case MESA_FORMAT_Z24_S8:
2470
case MESA_FORMAT_Z24_X8:
2471
unpack = unpack_float_z_Z24_X8;
2473
case MESA_FORMAT_S8_Z24:
2474
case MESA_FORMAT_X8_Z24:
2475
unpack = unpack_float_z_X8_Z24;
2477
case MESA_FORMAT_Z16:
2478
unpack = unpack_float_z_Z16;
2480
case MESA_FORMAT_Z32:
2481
unpack = unpack_float_z_Z32;
2483
case MESA_FORMAT_Z32_FLOAT:
2484
unpack = unpack_float_z_Z32F;
2486
case MESA_FORMAT_Z32_FLOAT_X24S8:
2487
unpack = unpack_float_z_Z32X24S8;
2490
_mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
2491
_mesa_get_format_name(format));
2495
unpack(n, src, dst);
2500
typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
2503
unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
2505
/* only return Z, not stencil data */
2506
const GLuint *s = ((const GLuint *) src);
2508
for (i = 0; i < n; i++) {
2509
dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
2514
unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
2516
/* only return Z, not stencil data */
2517
const GLuint *s = ((const GLuint *) src);
2519
for (i = 0; i < n; i++) {
2520
dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
2525
unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n)
2527
const GLushort *s = ((const GLushort *)src);
2529
for (i = 0; i < n; i++) {
2530
dst[i] = (s[i] << 16) | s[i];
2535
unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
2537
memcpy(dst, src, n * sizeof(GLuint));
2543
* The returned values will always be in the range [0, 0xffffffff].
2546
_mesa_unpack_uint_z_row(gl_format format, GLuint n,
2547
const void *src, GLuint *dst)
2549
unpack_uint_z_func unpack;
2550
const GLubyte *srcPtr = (GLubyte *) src;
2553
case MESA_FORMAT_Z24_S8:
2554
case MESA_FORMAT_Z24_X8:
2555
unpack = unpack_uint_z_Z24_X8;
2557
case MESA_FORMAT_S8_Z24:
2558
case MESA_FORMAT_X8_Z24:
2559
unpack = unpack_uint_z_X8_Z24;
2561
case MESA_FORMAT_Z16:
2562
unpack = unpack_uint_z_Z16;
2564
case MESA_FORMAT_Z32:
2565
unpack = unpack_uint_z_Z32;
2568
_mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
2569
_mesa_get_format_name(format));
2573
unpack(srcPtr, dst, n);
2578
unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
2580
memcpy(dst, src, n);
2584
unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n)
2587
const GLuint *src32 = src;
2589
for (i = 0; i < n; i++)
2590
dst[i] = src32[i] & 0xff;
2594
unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n)
2597
const GLuint *src32 = src;
2599
for (i = 0; i < n; i++)
2600
dst[i] = src32[i] >> 24;
2604
unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n)
2607
const GLuint *src32 = src;
2609
for (i = 0; i < n; i++)
2610
dst[i] = src32[i * 2 + 1] & 0xff;
2614
_mesa_unpack_ubyte_stencil_row(gl_format format, GLuint n,
2615
const void *src, GLubyte *dst)
2618
case MESA_FORMAT_S8:
2619
unpack_ubyte_s_S8(src, dst, n);
2621
case MESA_FORMAT_Z24_S8:
2622
unpack_ubyte_s_Z24_S8(src, dst, n);
2624
case MESA_FORMAT_S8_Z24:
2625
unpack_ubyte_s_S8_Z24(src, dst, n);
2627
case MESA_FORMAT_Z32_FLOAT_X24S8:
2628
unpack_ubyte_s_Z32_FLOAT_X24S8(src, dst, n);
2631
_mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
2632
_mesa_get_format_name(format));
2638
unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint *src, GLuint *dst, GLuint n)
2642
for (i = 0; i < n; i++) {
2643
GLuint val = src[i];
2644
dst[i] = val >> 24 | val << 8;
2649
unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint *src, GLuint *dst, GLuint n)
2651
memcpy(dst, src, n * 4);
2655
_mesa_unpack_uint_24_8_depth_stencil_row(gl_format format, GLuint n,
2656
const void *src, GLuint *dst)
2659
case MESA_FORMAT_Z24_S8:
2660
unpack_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
2662
case MESA_FORMAT_S8_Z24:
2663
unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
2667
"bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
2668
_mesa_get_format_name(format));