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_RG_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2217 for (i
= 0; i
< n
; i
++) {
2218 dst
[i
][0] = src
[i
* 2 + 0];
2219 dst
[i
][1] = src
[i
* 2 + 1];
2226 unpack_int_rgba_RG_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2230 for (i
= 0; i
< n
; i
++) {
2231 dst
[i
][0] = src
[i
* 2 + 0];
2232 dst
[i
][1] = src
[i
* 2 + 1];
2239 unpack_int_rgba_RG_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2243 for (i
= 0; i
< n
; i
++) {
2244 dst
[i
][0] = src
[i
* 2 + 0];
2245 dst
[i
][1] = src
[i
* 2 + 1];
2252 unpack_int_rgba_RG_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2256 for (i
= 0; i
< n
; i
++) {
2257 dst
[i
][0] = src
[i
* 2 + 0];
2258 dst
[i
][1] = src
[i
* 2 + 1];
2265 unpack_int_rgba_R_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2269 for (i
= 0; i
< n
; i
++) {
2278 unpack_int_rgba_R_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2282 for (i
= 0; i
< n
; i
++) {
2291 unpack_int_rgba_R_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2295 for (i
= 0; i
< n
; i
++) {
2304 unpack_int_rgba_R_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2308 for (i
= 0; i
< n
; i
++) {
2317 unpack_int_rgba_R_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2321 for (i
= 0; i
< n
; i
++) {
2330 unpack_int_rgba_ALPHA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2334 for (i
= 0; i
< n
; i
++) {
2335 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2341 unpack_int_rgba_ALPHA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2345 for (i
= 0; i
< n
; i
++) {
2346 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2352 unpack_int_rgba_ALPHA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2356 for (i
= 0; i
< n
; i
++) {
2357 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2363 unpack_int_rgba_ALPHA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2367 for (i
= 0; i
< n
; i
++) {
2368 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2374 unpack_int_rgba_ALPHA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2378 for (i
= 0; i
< n
; i
++) {
2379 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2385 unpack_int_rgba_LUMINANCE_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2389 for (i
= 0; i
< n
; i
++) {
2390 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2396 unpack_int_rgba_LUMINANCE_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2400 for (i
= 0; i
< n
; i
++) {
2401 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2407 unpack_int_rgba_LUMINANCE_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2411 for (i
= 0; i
< n
; i
++) {
2412 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2418 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2422 for (i
= 0; i
< n
; i
++) {
2423 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2429 unpack_int_rgba_LUMINANCE_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2433 for (i
= 0; i
< n
; i
++) {
2434 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2441 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2445 for (i
= 0; i
< n
; i
++) {
2446 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2447 dst
[i
][3] = src
[i
* 2 + 1];
2452 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2456 for (i
= 0; i
< n
; i
++) {
2457 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2458 dst
[i
][3] = src
[i
* 2 + 1];
2463 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2467 for (i
= 0; i
< n
; i
++) {
2468 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2469 dst
[i
][3] = src
[i
* 2 + 1];
2474 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2478 for (i
= 0; i
< n
; i
++) {
2479 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2480 dst
[i
][3] = src
[i
* 2 + 1];
2485 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2489 for (i
= 0; i
< n
; i
++) {
2490 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2491 dst
[i
][3] = src
[i
* 2 + 1];
2496 unpack_int_rgba_INTENSITY_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2500 for (i
= 0; i
< n
; i
++) {
2501 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2506 unpack_int_rgba_INTENSITY_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2510 for (i
= 0; i
< n
; i
++) {
2511 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2516 unpack_int_rgba_INTENSITY_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2520 for (i
= 0; i
< n
; i
++) {
2521 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2526 unpack_int_rgba_INTENSITY_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2530 for (i
= 0; i
< n
; i
++) {
2531 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2536 unpack_int_rgba_INTENSITY_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2540 for (i
= 0; i
< n
; i
++) {
2541 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2546 unpack_int_rgba_ARGB2101010_UINT(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2550 for (i
= 0; i
< n
; i
++) {
2551 GLuint tmp
= src
[i
];
2552 dst
[i
][0] = (tmp
>> 20) & 0x3ff;
2553 dst
[i
][1] = (tmp
>> 10) & 0x3ff;
2554 dst
[i
][2] = (tmp
>> 0) & 0x3ff;
2555 dst
[i
][3] = (tmp
>> 30) & 0x3;
2560 _mesa_unpack_uint_rgba_row(gl_format format
, GLuint n
,
2561 const void *src
, GLuint dst
[][4])
2564 /* Since there won't be any sign extension happening, there's no need to
2565 * make separate paths for 32-bit-to-32-bit integer unpack.
2567 case MESA_FORMAT_RGBA_UINT32
:
2568 case MESA_FORMAT_RGBA_INT32
:
2569 unpack_int_rgba_RGBA_UINT32(src
, dst
, n
);
2572 case MESA_FORMAT_RGBA_UINT16
:
2573 unpack_int_rgba_RGBA_UINT16(src
, dst
, n
);
2575 case MESA_FORMAT_RGBA_INT16
:
2576 unpack_int_rgba_RGBA_INT16(src
, dst
, n
);
2579 case MESA_FORMAT_RGBA_UINT8
:
2580 unpack_int_rgba_RGBA_UINT8(src
, dst
, n
);
2582 case MESA_FORMAT_RGBA_INT8
:
2583 unpack_int_rgba_RGBA_INT8(src
, dst
, n
);
2586 case MESA_FORMAT_RGB_UINT32
:
2587 case MESA_FORMAT_RGB_INT32
:
2588 unpack_int_rgba_RGB_UINT32(src
, dst
, n
);
2591 case MESA_FORMAT_RGB_UINT16
:
2592 unpack_int_rgba_RGB_UINT16(src
, dst
, n
);
2594 case MESA_FORMAT_RGB_INT16
:
2595 unpack_int_rgba_RGB_INT16(src
, dst
, n
);
2598 case MESA_FORMAT_RGB_UINT8
:
2599 unpack_int_rgba_RGB_UINT8(src
, dst
, n
);
2601 case MESA_FORMAT_RGB_INT8
:
2602 unpack_int_rgba_RGB_INT8(src
, dst
, n
);
2605 case MESA_FORMAT_RG_UINT32
:
2606 case MESA_FORMAT_RG_INT32
:
2607 unpack_int_rgba_RG_UINT32(src
, dst
, n
);
2610 case MESA_FORMAT_RG_UINT16
:
2611 unpack_int_rgba_RG_UINT16(src
, dst
, n
);
2613 case MESA_FORMAT_RG_INT16
:
2614 unpack_int_rgba_RG_INT16(src
, dst
, n
);
2617 case MESA_FORMAT_RG_UINT8
:
2618 unpack_int_rgba_RG_UINT8(src
, dst
, n
);
2620 case MESA_FORMAT_RG_INT8
:
2621 unpack_int_rgba_RG_INT8(src
, dst
, n
);
2624 case MESA_FORMAT_R_UINT32
:
2625 case MESA_FORMAT_R_INT32
:
2626 unpack_int_rgba_R_UINT32(src
, dst
, n
);
2629 case MESA_FORMAT_R_UINT16
:
2630 unpack_int_rgba_R_UINT16(src
, dst
, n
);
2632 case MESA_FORMAT_R_INT16
:
2633 unpack_int_rgba_R_INT16(src
, dst
, n
);
2636 case MESA_FORMAT_R_UINT8
:
2637 unpack_int_rgba_R_UINT8(src
, dst
, n
);
2639 case MESA_FORMAT_R_INT8
:
2640 unpack_int_rgba_R_INT8(src
, dst
, n
);
2643 case MESA_FORMAT_ALPHA_UINT32
:
2644 case MESA_FORMAT_ALPHA_INT32
:
2645 unpack_int_rgba_ALPHA_UINT32(src
, dst
, n
);
2648 case MESA_FORMAT_ALPHA_UINT16
:
2649 unpack_int_rgba_ALPHA_UINT16(src
, dst
, n
);
2651 case MESA_FORMAT_ALPHA_INT16
:
2652 unpack_int_rgba_ALPHA_INT16(src
, dst
, n
);
2655 case MESA_FORMAT_ALPHA_UINT8
:
2656 unpack_int_rgba_ALPHA_UINT8(src
, dst
, n
);
2658 case MESA_FORMAT_ALPHA_INT8
:
2659 unpack_int_rgba_ALPHA_INT8(src
, dst
, n
);
2662 case MESA_FORMAT_LUMINANCE_UINT32
:
2663 case MESA_FORMAT_LUMINANCE_INT32
:
2664 unpack_int_rgba_LUMINANCE_UINT32(src
, dst
, n
);
2666 case MESA_FORMAT_LUMINANCE_UINT16
:
2667 unpack_int_rgba_LUMINANCE_UINT16(src
, dst
, n
);
2669 case MESA_FORMAT_LUMINANCE_INT16
:
2670 unpack_int_rgba_LUMINANCE_INT16(src
, dst
, n
);
2673 case MESA_FORMAT_LUMINANCE_UINT8
:
2674 unpack_int_rgba_LUMINANCE_UINT8(src
, dst
, n
);
2676 case MESA_FORMAT_LUMINANCE_INT8
:
2677 unpack_int_rgba_LUMINANCE_INT8(src
, dst
, n
);
2680 case MESA_FORMAT_LUMINANCE_ALPHA_UINT32
:
2681 case MESA_FORMAT_LUMINANCE_ALPHA_INT32
:
2682 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src
, dst
, n
);
2685 case MESA_FORMAT_LUMINANCE_ALPHA_UINT16
:
2686 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src
, dst
, n
);
2688 case MESA_FORMAT_LUMINANCE_ALPHA_INT16
:
2689 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src
, dst
, n
);
2692 case MESA_FORMAT_LUMINANCE_ALPHA_UINT8
:
2693 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src
, dst
, n
);
2695 case MESA_FORMAT_LUMINANCE_ALPHA_INT8
:
2696 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src
, dst
, n
);
2699 case MESA_FORMAT_INTENSITY_UINT32
:
2700 case MESA_FORMAT_INTENSITY_INT32
:
2701 unpack_int_rgba_INTENSITY_UINT32(src
, dst
, n
);
2704 case MESA_FORMAT_INTENSITY_UINT16
:
2705 unpack_int_rgba_INTENSITY_UINT16(src
, dst
, n
);
2707 case MESA_FORMAT_INTENSITY_INT16
:
2708 unpack_int_rgba_INTENSITY_INT16(src
, dst
, n
);
2711 case MESA_FORMAT_INTENSITY_UINT8
:
2712 unpack_int_rgba_INTENSITY_UINT8(src
, dst
, n
);
2714 case MESA_FORMAT_INTENSITY_INT8
:
2715 unpack_int_rgba_INTENSITY_INT8(src
, dst
, n
);
2718 case MESA_FORMAT_ARGB2101010_UINT
:
2719 unpack_int_rgba_ARGB2101010_UINT(src
, dst
, n
);
2722 _mesa_problem(NULL
, "%s: bad format %s", __FUNCTION__
,
2723 _mesa_get_format_name(format
));
2729 * Unpack a 2D rect of pixels returning float RGBA colors.
2730 * \param format the source image format
2731 * \param src start address of the source image
2732 * \param srcRowStride source image row stride in bytes
2733 * \param dst start address of the dest image
2734 * \param dstRowStride dest image row stride in bytes
2735 * \param x source image start X pos
2736 * \param y source image start Y pos
2737 * \param width width of rect region to convert
2738 * \param height height of rect region to convert
2741 _mesa_unpack_rgba_block(gl_format format
,
2742 const void *src
, GLint srcRowStride
,
2743 GLfloat dst
[][4], GLint dstRowStride
,
2744 GLuint x
, GLuint y
, GLuint width
, GLuint height
)
2746 unpack_rgba_func unpack
= get_unpack_rgba_function(format
);
2747 const GLuint srcPixStride
= _mesa_get_format_bytes(format
);
2748 const GLuint dstPixStride
= 4 * sizeof(GLfloat
);
2749 const GLubyte
*srcRow
;
2753 /* XXX needs to be fixed for compressed formats */
2755 srcRow
= ((const GLubyte
*) src
) + srcRowStride
* y
+ srcPixStride
* x
;
2756 dstRow
= ((GLubyte
*) dst
) + dstRowStride
* y
+ dstPixStride
* x
;
2758 for (i
= 0; i
< height
; i
++) {
2759 unpack(srcRow
, (GLfloat (*)[4]) dstRow
, width
);
2761 dstRow
+= dstRowStride
;
2762 srcRow
+= srcRowStride
;
2769 typedef void (*unpack_float_z_func
)(GLuint n
, const void *src
, GLfloat
*dst
);
2772 unpack_float_z_Z24_X8(GLuint n
, const void *src
, GLfloat
*dst
)
2774 /* only return Z, not stencil data */
2775 const GLuint
*s
= ((const GLuint
*) src
);
2776 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2778 for (i
= 0; i
< n
; i
++) {
2779 dst
[i
] = (s
[i
] >> 8) * scale
;
2780 ASSERT(dst
[i
] >= 0.0F
);
2781 ASSERT(dst
[i
] <= 1.0F
);
2786 unpack_float_z_X8_Z24(GLuint n
, const void *src
, GLfloat
*dst
)
2788 /* only return Z, not stencil data */
2789 const GLuint
*s
= ((const GLuint
*) src
);
2790 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2792 for (i
= 0; i
< n
; i
++) {
2793 dst
[i
] = (s
[i
] & 0x00ffffff) * scale
;
2794 ASSERT(dst
[i
] >= 0.0F
);
2795 ASSERT(dst
[i
] <= 1.0F
);
2800 unpack_float_z_Z16(GLuint n
, const void *src
, GLfloat
*dst
)
2802 const GLushort
*s
= ((const GLushort
*) src
);
2804 for (i
= 0; i
< n
; i
++) {
2805 dst
[i
] = s
[i
] * (1.0F
/ 65535.0F
);
2810 unpack_float_z_Z32(GLuint n
, const void *src
, GLfloat
*dst
)
2812 const GLuint
*s
= ((const GLuint
*) src
);
2814 for (i
= 0; i
< n
; i
++) {
2815 dst
[i
] = s
[i
] * (1.0F
/ 0xffffffff);
2820 unpack_float_z_Z32F(GLuint n
, const void *src
, GLfloat
*dst
)
2822 memcpy(dst
, src
, n
* sizeof(float));
2826 unpack_float_z_Z32X24S8(GLuint n
, const void *src
, GLfloat
*dst
)
2828 const GLfloat
*s
= ((const GLfloat
*) src
);
2830 for (i
= 0; i
< n
; i
++) {
2839 * The returned values will always be in the range [0.0, 1.0].
2842 _mesa_unpack_float_z_row(gl_format format
, GLuint n
,
2843 const void *src
, GLfloat
*dst
)
2845 unpack_float_z_func unpack
;
2848 case MESA_FORMAT_Z24_S8
:
2849 case MESA_FORMAT_Z24_X8
:
2850 unpack
= unpack_float_z_Z24_X8
;
2852 case MESA_FORMAT_S8_Z24
:
2853 case MESA_FORMAT_X8_Z24
:
2854 unpack
= unpack_float_z_X8_Z24
;
2856 case MESA_FORMAT_Z16
:
2857 unpack
= unpack_float_z_Z16
;
2859 case MESA_FORMAT_Z32
:
2860 unpack
= unpack_float_z_Z32
;
2862 case MESA_FORMAT_Z32_FLOAT
:
2863 unpack
= unpack_float_z_Z32F
;
2865 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2866 unpack
= unpack_float_z_Z32X24S8
;
2869 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_float_z_row",
2870 _mesa_get_format_name(format
));
2874 unpack(n
, src
, dst
);
2879 typedef void (*unpack_uint_z_func
)(const void *src
, GLuint
*dst
, GLuint n
);
2882 unpack_uint_z_Z24_X8(const void *src
, GLuint
*dst
, GLuint n
)
2884 /* only return Z, not stencil data */
2885 const GLuint
*s
= ((const GLuint
*) src
);
2887 for (i
= 0; i
< n
; i
++) {
2888 dst
[i
] = (s
[i
] & 0xffffff00) | (s
[i
] >> 24);
2893 unpack_uint_z_X8_Z24(const void *src
, GLuint
*dst
, GLuint n
)
2895 /* only return Z, not stencil data */
2896 const GLuint
*s
= ((const GLuint
*) src
);
2898 for (i
= 0; i
< n
; i
++) {
2899 dst
[i
] = (s
[i
] << 8) | ((s
[i
] >> 16) & 0xff);
2904 unpack_uint_z_Z16(const void *src
, GLuint
*dst
, GLuint n
)
2906 const GLushort
*s
= ((const GLushort
*)src
);
2908 for (i
= 0; i
< n
; i
++) {
2909 dst
[i
] = (s
[i
] << 16) | s
[i
];
2914 unpack_uint_z_Z32(const void *src
, GLuint
*dst
, GLuint n
)
2916 memcpy(dst
, src
, n
* sizeof(GLuint
));
2920 unpack_uint_z_Z32_FLOAT(const void *src
, GLuint
*dst
, GLuint n
)
2922 const float *s
= (const float *)src
;
2924 for (i
= 0; i
< n
; i
++) {
2925 dst
[i
] = FLOAT_TO_UINT(IROUND(CLAMP((s
[i
]), 0.0F
, 1.0F
)));
2930 unpack_uint_z_Z32_FLOAT_X24S8(const void *src
, GLuint
*dst
, GLuint n
)
2937 const struct z32f_x24s8
*s
= (const struct z32f_x24s8
*) src
;
2940 for (i
= 0; i
< n
; i
++) {
2941 dst
[i
] = FLOAT_TO_UINT(IROUND(CLAMP((s
[i
].z
), 0.0F
, 1.0F
)));
2948 * The returned values will always be in the range [0, 0xffffffff].
2951 _mesa_unpack_uint_z_row(gl_format format
, GLuint n
,
2952 const void *src
, GLuint
*dst
)
2954 unpack_uint_z_func unpack
;
2955 const GLubyte
*srcPtr
= (GLubyte
*) src
;
2958 case MESA_FORMAT_Z24_S8
:
2959 case MESA_FORMAT_Z24_X8
:
2960 unpack
= unpack_uint_z_Z24_X8
;
2962 case MESA_FORMAT_S8_Z24
:
2963 case MESA_FORMAT_X8_Z24
:
2964 unpack
= unpack_uint_z_X8_Z24
;
2966 case MESA_FORMAT_Z16
:
2967 unpack
= unpack_uint_z_Z16
;
2969 case MESA_FORMAT_Z32
:
2970 unpack
= unpack_uint_z_Z32
;
2972 case MESA_FORMAT_Z32_FLOAT
:
2973 unpack
= unpack_uint_z_Z32_FLOAT
;
2975 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2976 unpack
= unpack_uint_z_Z32_FLOAT_X24S8
;
2979 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_uint_z_row",
2980 _mesa_get_format_name(format
));
2984 unpack(srcPtr
, dst
, n
);
2989 unpack_ubyte_s_S8(const void *src
, GLubyte
*dst
, GLuint n
)
2991 memcpy(dst
, src
, n
);
2995 unpack_ubyte_s_Z24_S8(const void *src
, GLubyte
*dst
, GLuint n
)
2998 const GLuint
*src32
= src
;
3000 for (i
= 0; i
< n
; i
++)
3001 dst
[i
] = src32
[i
] & 0xff;
3005 unpack_ubyte_s_S8_Z24(const void *src
, GLubyte
*dst
, GLuint n
)
3008 const GLuint
*src32
= src
;
3010 for (i
= 0; i
< n
; i
++)
3011 dst
[i
] = src32
[i
] >> 24;
3015 unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src
, GLubyte
*dst
, GLuint n
)
3018 const GLuint
*src32
= src
;
3020 for (i
= 0; i
< n
; i
++)
3021 dst
[i
] = src32
[i
* 2 + 1] & 0xff;
3025 _mesa_unpack_ubyte_stencil_row(gl_format format
, GLuint n
,
3026 const void *src
, GLubyte
*dst
)
3029 case MESA_FORMAT_S8
:
3030 unpack_ubyte_s_S8(src
, dst
, n
);
3032 case MESA_FORMAT_Z24_S8
:
3033 unpack_ubyte_s_Z24_S8(src
, dst
, n
);
3035 case MESA_FORMAT_S8_Z24
:
3036 unpack_ubyte_s_S8_Z24(src
, dst
, n
);
3038 case MESA_FORMAT_Z32_FLOAT_X24S8
:
3039 unpack_ubyte_s_Z32_FLOAT_X24S8(src
, dst
, n
);
3042 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_ubyte_s_row",
3043 _mesa_get_format_name(format
));
3049 unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint
*src
, GLuint
*dst
, GLuint n
)
3053 for (i
= 0; i
< n
; i
++) {
3054 GLuint val
= src
[i
];
3055 dst
[i
] = val
>> 24 | val
<< 8;
3060 unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint
*src
, GLuint
*dst
, GLuint n
)
3062 memcpy(dst
, src
, n
* 4);
3066 _mesa_unpack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
3067 const void *src
, GLuint
*dst
)
3070 case MESA_FORMAT_Z24_S8
:
3071 unpack_uint_24_8_depth_stencil_Z24_S8(src
, dst
, n
);
3073 case MESA_FORMAT_S8_Z24
:
3074 unpack_uint_24_8_depth_stencil_S8_Z24(src
, dst
, n
);
3078 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
3079 _mesa_get_format_name(format
));