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"
32 /** Helper struct for MESA_FORMAT_Z32_FLOAT_X24S8 */
40 /* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
42 #define EXPAND_1_8(X) ( (X) ? 0xff : 0x0 )
44 #define EXPAND_2_8(X) ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
46 #define EXPAND_3_8(X) ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
48 #define EXPAND_4_8(X) ( ((X) << 4) | (X) )
50 #define EXPAND_5_8(X) ( ((X) << 3) | ((X) >> 2) )
52 #define EXPAND_6_8(X) ( ((X) << 2) | ((X) >> 4) )
56 * Convert an 8-bit sRGB value from non-linear space to a
57 * linear RGB value in [0, 1].
58 * Implemented with a 256-entry lookup table.
61 _mesa_nonlinear_to_linear(GLubyte cs8
)
63 static GLfloat table
[256];
64 static GLboolean tableReady
= GL_FALSE
;
66 /* compute lookup table now */
68 for (i
= 0; i
< 256; i
++) {
69 const GLfloat cs
= UBYTE_TO_FLOAT(i
);
71 table
[i
] = cs
/ 12.92f
;
74 table
[i
] = (GLfloat
) pow((cs
+ 0.055) / 1.055, 2.4);
83 /**********************************************************************/
84 /* Unpack, returning GLfloat colors */
85 /**********************************************************************/
87 typedef void (*unpack_rgba_func
)(const void *src
, GLfloat dst
[][4], GLuint n
);
91 unpack_RGBA8888(const void *src
, GLfloat dst
[][4], GLuint n
)
93 const GLuint
*s
= ((const GLuint
*) src
);
95 for (i
= 0; i
< n
; i
++) {
96 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
97 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
98 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
99 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
104 unpack_RGBA8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
106 const GLuint
*s
= ((const GLuint
*) src
);
108 for (i
= 0; i
< n
; i
++) {
109 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
110 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
111 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
112 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
117 unpack_ARGB8888(const void *src
, GLfloat dst
[][4], GLuint n
)
119 const GLuint
*s
= ((const GLuint
*) src
);
121 for (i
= 0; i
< n
; i
++) {
122 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
123 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
124 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
125 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
130 unpack_ARGB8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
132 const GLuint
*s
= ((const GLuint
*) src
);
134 for (i
= 0; i
< n
; i
++) {
135 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
136 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
137 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
138 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
143 unpack_RGBX8888(const void *src
, GLfloat dst
[][4], GLuint n
)
145 const GLuint
*s
= ((const GLuint
*) src
);
147 for (i
= 0; i
< n
; i
++) {
148 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
149 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
150 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
151 dst
[i
][ACOMP
] = 1.0f
;
156 unpack_RGBX8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
158 const GLuint
*s
= ((const GLuint
*) src
);
160 for (i
= 0; i
< n
; i
++) {
161 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
162 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
163 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
164 dst
[i
][ACOMP
] = 1.0f
;
169 unpack_XRGB8888(const void *src
, GLfloat dst
[][4], GLuint n
)
171 const GLuint
*s
= ((const GLuint
*) src
);
173 for (i
= 0; i
< n
; i
++) {
174 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
175 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
176 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
177 dst
[i
][ACOMP
] = 1.0f
;
182 unpack_XRGB8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
184 const GLuint
*s
= ((const GLuint
*) src
);
186 for (i
= 0; i
< n
; i
++) {
187 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
188 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
189 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
190 dst
[i
][ACOMP
] = 1.0f
;
195 unpack_RGB888(const void *src
, GLfloat dst
[][4], GLuint n
)
197 const GLubyte
*s
= (const GLubyte
*) src
;
199 for (i
= 0; i
< n
; i
++) {
200 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+2] );
201 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+1] );
202 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+0] );
203 dst
[i
][ACOMP
] = 1.0F
;
208 unpack_BGR888(const void *src
, GLfloat dst
[][4], GLuint n
)
210 const GLubyte
*s
= (const GLubyte
*) src
;
212 for (i
= 0; i
< n
; i
++) {
213 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+0] );
214 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+1] );
215 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+2] );
216 dst
[i
][ACOMP
] = 1.0F
;
221 unpack_RGB565(const void *src
, GLfloat dst
[][4], GLuint n
)
223 const GLushort
*s
= ((const GLushort
*) src
);
225 for (i
= 0; i
< n
; i
++) {
226 dst
[i
][RCOMP
] = ((s
[i
] >> 11) & 0x1f) * (1.0F
/ 31.0F
);
227 dst
[i
][GCOMP
] = ((s
[i
] >> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
228 dst
[i
][BCOMP
] = ((s
[i
] ) & 0x1f) * (1.0F
/ 31.0F
);
229 dst
[i
][ACOMP
] = 1.0F
;
234 unpack_RGB565_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
236 const GLushort
*s
= ((const GLushort
*) src
);
238 for (i
= 0; i
< n
; i
++) {
239 GLuint t
= (s
[i
] >> 8) | (s
[i
] << 8); /* byte swap */
240 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( ((t
>> 8) & 0xf8) | ((t
>> 13) & 0x7) );
241 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( ((t
>> 3) & 0xfc) | ((t
>> 9) & 0x3) );
242 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( ((t
<< 3) & 0xf8) | ((t
>> 2) & 0x7) );
243 dst
[i
][ACOMP
] = 1.0F
;
248 unpack_ARGB4444(const void *src
, GLfloat dst
[][4], GLuint n
)
250 const GLushort
*s
= ((const GLushort
*) src
);
252 for (i
= 0; i
< n
; i
++) {
253 dst
[i
][RCOMP
] = ((s
[i
] >> 8) & 0xf) * (1.0F
/ 15.0F
);
254 dst
[i
][GCOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
255 dst
[i
][BCOMP
] = ((s
[i
] ) & 0xf) * (1.0F
/ 15.0F
);
256 dst
[i
][ACOMP
] = ((s
[i
] >> 12) & 0xf) * (1.0F
/ 15.0F
);
261 unpack_ARGB4444_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
263 const GLushort
*s
= ((const GLushort
*) src
);
265 for (i
= 0; i
< n
; i
++) {
266 dst
[i
][RCOMP
] = ((s
[i
] ) & 0xf) * (1.0F
/ 15.0F
);
267 dst
[i
][GCOMP
] = ((s
[i
] >> 12) & 0xf) * (1.0F
/ 15.0F
);
268 dst
[i
][BCOMP
] = ((s
[i
] >> 8) & 0xf) * (1.0F
/ 15.0F
);
269 dst
[i
][ACOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
274 unpack_RGBA5551(const void *src
, GLfloat dst
[][4], GLuint n
)
276 const GLushort
*s
= ((const GLushort
*) src
);
278 for (i
= 0; i
< n
; i
++) {
279 dst
[i
][RCOMP
] = ((s
[i
] >> 11) & 0x1f) * (1.0F
/ 31.0F
);
280 dst
[i
][GCOMP
] = ((s
[i
] >> 6) & 0x1f) * (1.0F
/ 31.0F
);
281 dst
[i
][BCOMP
] = ((s
[i
] >> 1) & 0x1f) * (1.0F
/ 31.0F
);
282 dst
[i
][ACOMP
] = ((s
[i
] ) & 0x01) * 1.0F
;
287 unpack_ARGB1555(const void *src
, GLfloat dst
[][4], GLuint n
)
289 const GLushort
*s
= ((const GLushort
*) src
);
291 for (i
= 0; i
< n
; i
++) {
292 dst
[i
][RCOMP
] = ((s
[i
] >> 10) & 0x1f) * (1.0F
/ 31.0F
);
293 dst
[i
][GCOMP
] = ((s
[i
] >> 5) & 0x1f) * (1.0F
/ 31.0F
);
294 dst
[i
][BCOMP
] = ((s
[i
] >> 0) & 0x1f) * (1.0F
/ 31.0F
);
295 dst
[i
][ACOMP
] = ((s
[i
] >> 15) & 0x01) * 1.0F
;
300 unpack_ARGB1555_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
302 const GLushort
*s
= ((const GLushort
*) src
);
304 for (i
= 0; i
< n
; i
++) {
305 GLushort tmp
= (s
[i
] << 8) | (s
[i
] >> 8); /* byteswap */
306 dst
[i
][RCOMP
] = ((tmp
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
307 dst
[i
][GCOMP
] = ((tmp
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
308 dst
[i
][BCOMP
] = ((tmp
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
309 dst
[i
][ACOMP
] = ((tmp
>> 15) & 0x01) * 1.0F
;
314 unpack_AL44(const void *src
, GLfloat dst
[][4], GLuint n
)
316 const GLubyte
*s
= ((const GLubyte
*) src
);
318 for (i
= 0; i
< n
; i
++) {
321 dst
[i
][BCOMP
] = (s
[i
] & 0xf) * (1.0F
/ 15.0F
);
322 dst
[i
][ACOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
327 unpack_AL88(const void *src
, GLfloat dst
[][4], GLuint n
)
329 const GLushort
*s
= ((const GLushort
*) src
);
331 for (i
= 0; i
< n
; i
++) {
334 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
335 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
340 unpack_AL88_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
342 const GLushort
*s
= ((const GLushort
*) src
);
344 for (i
= 0; i
< n
; i
++) {
347 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
348 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
353 unpack_AL1616(const void *src
, GLfloat dst
[][4], GLuint n
)
355 const GLuint
*s
= ((const GLuint
*) src
);
357 for (i
= 0; i
< n
; i
++) {
360 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
361 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
366 unpack_AL1616_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
368 const GLuint
*s
= ((const GLuint
*) src
);
370 for (i
= 0; i
< n
; i
++) {
373 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
374 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
379 unpack_RGB332(const void *src
, GLfloat dst
[][4], GLuint n
)
381 const GLubyte
*s
= ((const GLubyte
*) src
);
383 for (i
= 0; i
< n
; i
++) {
384 dst
[i
][RCOMP
] = ((s
[i
] >> 5) & 0x7) * (1.0F
/ 7.0F
);
385 dst
[i
][GCOMP
] = ((s
[i
] >> 2) & 0x7) * (1.0F
/ 7.0F
);
386 dst
[i
][BCOMP
] = ((s
[i
] ) & 0x3) * (1.0F
/ 3.0F
);
387 dst
[i
][ACOMP
] = 1.0F
;
393 unpack_A8(const void *src
, GLfloat dst
[][4], GLuint n
)
395 const GLubyte
*s
= ((const GLubyte
*) src
);
397 for (i
= 0; i
< n
; i
++) {
400 dst
[i
][BCOMP
] = 0.0F
;
401 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
]);
406 unpack_A16(const void *src
, GLfloat dst
[][4], GLuint n
)
408 const GLushort
*s
= ((const GLushort
*) src
);
410 for (i
= 0; i
< n
; i
++) {
413 dst
[i
][BCOMP
] = 0.0F
;
414 dst
[i
][ACOMP
] = USHORT_TO_FLOAT(s
[i
]);
419 unpack_L8(const void *src
, GLfloat dst
[][4], GLuint n
)
421 const GLubyte
*s
= ((const GLubyte
*) src
);
423 for (i
= 0; i
< n
; i
++) {
426 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT(s
[i
]);
427 dst
[i
][ACOMP
] = 1.0F
;
432 unpack_L16(const void *src
, GLfloat dst
[][4], GLuint n
)
434 const GLushort
*s
= ((const GLushort
*) src
);
436 for (i
= 0; i
< n
; i
++) {
439 dst
[i
][BCOMP
] = USHORT_TO_FLOAT(s
[i
]);
440 dst
[i
][ACOMP
] = 1.0F
;
445 unpack_I8(const void *src
, GLfloat dst
[][4], GLuint n
)
447 const GLubyte
*s
= ((const GLubyte
*) src
);
449 for (i
= 0; i
< n
; i
++) {
453 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
]);
458 unpack_I16(const void *src
, GLfloat dst
[][4], GLuint n
)
460 const GLushort
*s
= ((const GLushort
*) src
);
462 for (i
= 0; i
< n
; i
++) {
466 dst
[i
][ACOMP
] = USHORT_TO_FLOAT(s
[i
]);
471 unpack_YCBCR(const void *src
, GLfloat dst
[][4], GLuint n
)
474 for (i
= 0; i
< n
; i
++) {
475 const GLushort
*src0
= ((const GLushort
*) src
) + i
* 2; /* even */
476 const GLushort
*src1
= src0
+ 1; /* odd */
477 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
478 const GLubyte cb
= *src0
& 0xff; /* chroma U */
479 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
480 const GLubyte cr
= *src1
& 0xff; /* chroma V */
481 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
482 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
483 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
484 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
485 r
*= (1.0F
/ 255.0F
);
486 g
*= (1.0F
/ 255.0F
);
487 b
*= (1.0F
/ 255.0F
);
488 dst
[i
][RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
489 dst
[i
][GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
490 dst
[i
][BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
491 dst
[i
][ACOMP
] = 1.0F
;
496 unpack_YCBCR_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
499 for (i
= 0; i
< n
; i
++) {
500 const GLushort
*src0
= ((const GLushort
*) src
) + i
* 2; /* even */
501 const GLushort
*src1
= src0
+ 1; /* odd */
502 const GLubyte y0
= *src0
& 0xff; /* luminance */
503 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
504 const GLubyte y1
= *src1
& 0xff; /* luminance */
505 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
506 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
507 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
508 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
509 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
510 r
*= (1.0F
/ 255.0F
);
511 g
*= (1.0F
/ 255.0F
);
512 b
*= (1.0F
/ 255.0F
);
513 dst
[i
][RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
514 dst
[i
][GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
515 dst
[i
][BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
516 dst
[i
][ACOMP
] = 1.0F
;
521 unpack_R8(const void *src
, GLfloat dst
[][4], GLuint n
)
523 const GLubyte
*s
= ((const GLubyte
*) src
);
525 for (i
= 0; i
< n
; i
++) {
526 dst
[i
][0] = UBYTE_TO_FLOAT(s
[i
]);
534 unpack_GR88(const void *src
, GLfloat dst
[][4], GLuint n
)
536 const GLushort
*s
= ((const GLushort
*) src
);
538 for (i
= 0; i
< n
; i
++) {
539 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
540 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
547 unpack_RG88(const void *src
, GLfloat dst
[][4], GLuint n
)
549 const GLushort
*s
= ((const GLushort
*) src
);
551 for (i
= 0; i
< n
; i
++) {
552 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
553 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
560 unpack_R16(const void *src
, GLfloat dst
[][4], GLuint n
)
562 const GLushort
*s
= ((const GLushort
*) src
);
564 for (i
= 0; i
< n
; i
++) {
565 dst
[i
][RCOMP
] = USHORT_TO_FLOAT(s
[i
]);
573 unpack_RG1616(const void *src
, GLfloat dst
[][4], GLuint n
)
575 const GLuint
*s
= ((const GLuint
*) src
);
577 for (i
= 0; i
< n
; i
++) {
578 dst
[i
][RCOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
579 dst
[i
][GCOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
586 unpack_RG1616_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
588 const GLuint
*s
= ((const GLuint
*) src
);
590 for (i
= 0; i
< n
; i
++) {
591 dst
[i
][RCOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
592 dst
[i
][GCOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
599 unpack_ARGB2101010(const void *src
, GLfloat dst
[][4], GLuint n
)
601 const GLuint
*s
= ((const GLuint
*) src
);
603 for (i
= 0; i
< n
; i
++) {
604 dst
[i
][RCOMP
] = ((s
[i
] >> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
605 dst
[i
][GCOMP
] = ((s
[i
] >> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
606 dst
[i
][BCOMP
] = ((s
[i
] >> 0) & 0x3ff) * (1.0F
/ 1023.0F
);
607 dst
[i
][ACOMP
] = ((s
[i
] >> 30) & 0x03) * (1.0F
/ 3.0F
);
613 unpack_ABGR2101010_UINT(const void *src
, GLfloat dst
[][4], GLuint n
)
615 const GLuint
*s
= ((const GLuint
*) src
);
617 for (i
= 0; i
< n
; i
++) {
618 dst
[i
][RCOMP
] = (GLfloat
)((s
[i
] >> 0) & 0x3ff);
619 dst
[i
][GCOMP
] = (GLfloat
)((s
[i
] >> 10) & 0x3ff);
620 dst
[i
][BCOMP
] = (GLfloat
)((s
[i
] >> 20) & 0x3ff);
621 dst
[i
][ACOMP
] = (GLfloat
)((s
[i
] >> 30) & 0x03);
627 unpack_Z24_S8(const void *src
, GLfloat dst
[][4], GLuint n
)
629 /* only return Z, not stencil data */
630 const GLuint
*s
= ((const GLuint
*) src
);
631 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
633 for (i
= 0; i
< n
; i
++) {
636 dst
[i
][2] = (GLfloat
) ((s
[i
] >> 8) * scale
);
638 ASSERT(dst
[i
][0] >= 0.0F
);
639 ASSERT(dst
[i
][0] <= 1.0F
);
644 unpack_S8_Z24(const void *src
, GLfloat dst
[][4], GLuint n
)
646 /* only return Z, not stencil data */
647 const GLuint
*s
= ((const GLuint
*) src
);
648 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
650 for (i
= 0; i
< n
; i
++) {
653 dst
[i
][2] = (float) ((s
[i
] & 0x00ffffff) * scale
);
655 ASSERT(dst
[i
][0] >= 0.0F
);
656 ASSERT(dst
[i
][0] <= 1.0F
);
661 unpack_Z16(const void *src
, GLfloat dst
[][4], GLuint n
)
663 const GLushort
*s
= ((const GLushort
*) src
);
665 for (i
= 0; i
< n
; i
++) {
668 dst
[i
][2] = s
[i
] * (1.0F
/ 65535.0F
);
674 unpack_X8_Z24(const void *src
, GLfloat dst
[][4], GLuint n
)
676 unpack_S8_Z24(src
, dst
, n
);
680 unpack_Z24_X8(const void *src
, GLfloat dst
[][4], GLuint n
)
682 unpack_Z24_S8(src
, dst
, n
);
686 unpack_Z32(const void *src
, GLfloat dst
[][4], GLuint n
)
688 const GLuint
*s
= ((const GLuint
*) src
);
690 for (i
= 0; i
< n
; i
++) {
693 dst
[i
][2] = s
[i
] * (1.0F
/ 0xffffffff);
699 unpack_Z32_FLOAT(const void *src
, GLfloat dst
[][4], GLuint n
)
701 const GLfloat
*s
= ((const GLfloat
*) src
);
703 for (i
= 0; i
< n
; i
++) {
706 dst
[i
][2] = s
[i
* 2];
712 unpack_Z32_FLOAT_X24S8(const void *src
, GLfloat dst
[][4], GLuint n
)
714 const GLfloat
*s
= ((const GLfloat
*) src
);
716 for (i
= 0; i
< n
; i
++) {
726 unpack_S8(const void *src
, GLfloat dst
[][4], GLuint n
)
728 /* should never be used */
730 for (i
= 0; i
< n
; i
++) {
740 unpack_SRGB8(const void *src
, GLfloat dst
[][4], GLuint n
)
742 const GLubyte
*s
= (const GLubyte
*) src
;
744 for (i
= 0; i
< n
; i
++) {
745 dst
[i
][RCOMP
] = _mesa_nonlinear_to_linear(s
[i
*3+2]);
746 dst
[i
][GCOMP
] = _mesa_nonlinear_to_linear(s
[i
*3+1]);
747 dst
[i
][BCOMP
] = _mesa_nonlinear_to_linear(s
[i
*3+0]);
748 dst
[i
][ACOMP
] = 1.0F
;
753 unpack_SRGBA8(const void *src
, GLfloat dst
[][4], GLuint n
)
755 const GLuint
*s
= ((const GLuint
*) src
);
757 for (i
= 0; i
< n
; i
++) {
758 dst
[i
][RCOMP
] = _mesa_nonlinear_to_linear( (s
[i
] >> 24) );
759 dst
[i
][GCOMP
] = _mesa_nonlinear_to_linear( (s
[i
] >> 16) & 0xff );
760 dst
[i
][BCOMP
] = _mesa_nonlinear_to_linear( (s
[i
] >> 8) & 0xff );
761 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff ); /* linear! */
766 unpack_SARGB8(const void *src
, GLfloat dst
[][4], GLuint n
)
768 const GLuint
*s
= ((const GLuint
*) src
);
770 for (i
= 0; i
< n
; i
++) {
771 dst
[i
][RCOMP
] = _mesa_nonlinear_to_linear( (s
[i
] >> 16) & 0xff );
772 dst
[i
][GCOMP
] = _mesa_nonlinear_to_linear( (s
[i
] >> 8) & 0xff );
773 dst
[i
][BCOMP
] = _mesa_nonlinear_to_linear( (s
[i
] ) & 0xff );
774 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 24 ); /* linear! */
779 unpack_SL8(const void *src
, GLfloat dst
[][4], GLuint n
)
781 const GLubyte
*s
= ((const GLubyte
*) src
);
783 for (i
= 0; i
< n
; i
++) {
786 dst
[i
][BCOMP
] = _mesa_nonlinear_to_linear(s
[i
]);
787 dst
[i
][ACOMP
] = 1.0F
;
792 unpack_SLA8(const void *src
, GLfloat dst
[][4], GLuint n
)
794 const GLushort
*s
= (const GLushort
*) src
;
796 for (i
= 0; i
< n
; i
++) {
799 dst
[i
][BCOMP
] = _mesa_nonlinear_to_linear(s
[i
] & 0xff);
800 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
] >> 8); /* linear! */
805 unpack_SRGB_DXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
810 unpack_SRGBA_DXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
815 unpack_SRGBA_DXT3(const void *src
, GLfloat dst
[][4], GLuint n
)
820 unpack_SRGBA_DXT5(const void *src
, GLfloat dst
[][4], GLuint n
)
825 unpack_RGB_FXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
830 unpack_RGBA_FXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
835 unpack_RGB_DXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
840 unpack_RGBA_DXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
845 unpack_RGBA_DXT3(const void *src
, GLfloat dst
[][4], GLuint n
)
850 unpack_RGBA_DXT5(const void *src
, GLfloat dst
[][4], GLuint n
)
856 unpack_RGBA_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
858 const GLfloat
*s
= (const GLfloat
*) src
;
860 for (i
= 0; i
< n
; i
++) {
861 dst
[i
][RCOMP
] = s
[i
*4+0];
862 dst
[i
][GCOMP
] = s
[i
*4+1];
863 dst
[i
][BCOMP
] = s
[i
*4+2];
864 dst
[i
][ACOMP
] = s
[i
*4+3];
869 unpack_RGBA_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
871 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
873 for (i
= 0; i
< n
; i
++) {
874 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
*4+0]);
875 dst
[i
][GCOMP
] = _mesa_half_to_float(s
[i
*4+1]);
876 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
*4+2]);
877 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
*4+3]);
882 unpack_RGB_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
884 const GLfloat
*s
= (const GLfloat
*) src
;
886 for (i
= 0; i
< n
; i
++) {
887 dst
[i
][RCOMP
] = s
[i
*3+0];
888 dst
[i
][GCOMP
] = s
[i
*3+1];
889 dst
[i
][BCOMP
] = s
[i
*3+2];
890 dst
[i
][ACOMP
] = 1.0F
;
895 unpack_RGB_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
897 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
899 for (i
= 0; i
< n
; i
++) {
900 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
*3+0]);
901 dst
[i
][GCOMP
] = _mesa_half_to_float(s
[i
*3+1]);
902 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
*3+2]);
903 dst
[i
][ACOMP
] = 1.0F
;
908 unpack_ALPHA_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
910 const GLfloat
*s
= (const GLfloat
*) src
;
912 for (i
= 0; i
< n
; i
++) {
915 dst
[i
][BCOMP
] = 0.0F
;
916 dst
[i
][ACOMP
] = s
[i
];
921 unpack_ALPHA_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
923 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
925 for (i
= 0; i
< n
; i
++) {
928 dst
[i
][BCOMP
] = 0.0F
;
929 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
]);
934 unpack_LUMINANCE_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
936 const GLfloat
*s
= (const GLfloat
*) src
;
938 for (i
= 0; i
< n
; i
++) {
941 dst
[i
][BCOMP
] = s
[i
];
942 dst
[i
][ACOMP
] = 1.0F
;
947 unpack_LUMINANCE_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
949 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
951 for (i
= 0; i
< n
; i
++) {
954 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
]);
955 dst
[i
][ACOMP
] = 1.0F
;
960 unpack_LUMINANCE_ALPHA_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
962 const GLfloat
*s
= (const GLfloat
*) src
;
964 for (i
= 0; i
< n
; i
++) {
967 dst
[i
][BCOMP
] = s
[i
*2+0];
968 dst
[i
][ACOMP
] = s
[i
*2+1];
973 unpack_LUMINANCE_ALPHA_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
975 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
977 for (i
= 0; i
< n
; i
++) {
980 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
*2+0]);
981 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
*2+1]);
986 unpack_INTENSITY_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
988 const GLfloat
*s
= (const GLfloat
*) src
;
990 for (i
= 0; i
< n
; i
++) {
994 dst
[i
][ACOMP
] = s
[i
];
999 unpack_INTENSITY_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1001 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
1003 for (i
= 0; i
< n
; i
++) {
1007 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
]);
1012 unpack_R_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
1014 const GLfloat
*s
= (const GLfloat
*) src
;
1016 for (i
= 0; i
< n
; i
++) {
1017 dst
[i
][RCOMP
] = s
[i
];
1018 dst
[i
][GCOMP
] = 0.0F
;
1019 dst
[i
][BCOMP
] = 0.0F
;
1020 dst
[i
][ACOMP
] = 1.0F
;
1025 unpack_R_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1027 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
1029 for (i
= 0; i
< n
; i
++) {
1030 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
]);
1031 dst
[i
][GCOMP
] = 0.0F
;
1032 dst
[i
][BCOMP
] = 0.0F
;
1033 dst
[i
][ACOMP
] = 1.0F
;
1038 unpack_RG_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
1040 const GLfloat
*s
= (const GLfloat
*) src
;
1042 for (i
= 0; i
< n
; i
++) {
1043 dst
[i
][RCOMP
] = s
[i
*2+0];
1044 dst
[i
][GCOMP
] = s
[i
*2+1];
1045 dst
[i
][BCOMP
] = 0.0F
;
1046 dst
[i
][ACOMP
] = 1.0F
;
1051 unpack_RG_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1053 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
1055 for (i
= 0; i
< n
; i
++) {
1056 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
*2+0]);
1057 dst
[i
][GCOMP
] = _mesa_half_to_float(s
[i
*2+1]);
1058 dst
[i
][BCOMP
] = 0.0F
;
1059 dst
[i
][ACOMP
] = 1.0F
;
1065 unpack_RGBA_INT8(const void *src
, GLfloat dst
[][4], GLuint n
)
1067 const GLbyte
*s
= (const GLbyte
*) src
;
1069 for (i
= 0; i
< n
; i
++) {
1070 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1071 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1072 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1073 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1078 unpack_RGBA_INT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1080 const GLshort
*s
= (const GLshort
*) src
;
1082 for (i
= 0; i
< n
; i
++) {
1083 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1084 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1085 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1086 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1091 unpack_RGBA_INT32(const void *src
, GLfloat dst
[][4], GLuint n
)
1093 const GLint
*s
= (const GLint
*) src
;
1095 for (i
= 0; i
< n
; i
++) {
1096 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1097 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1098 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1099 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1104 unpack_RGBA_UINT8(const void *src
, GLfloat dst
[][4], GLuint n
)
1106 const GLubyte
*s
= (const GLubyte
*) src
;
1108 for (i
= 0; i
< n
; i
++) {
1109 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1110 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1111 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1112 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1117 unpack_RGBA_UINT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1119 const GLushort
*s
= (const GLushort
*) src
;
1121 for (i
= 0; i
< n
; i
++) {
1122 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1123 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1124 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1125 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1130 unpack_RGBA_UINT32(const void *src
, GLfloat dst
[][4], GLuint n
)
1132 const GLuint
*s
= (const GLuint
*) src
;
1134 for (i
= 0; i
< n
; i
++) {
1135 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1136 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1137 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1138 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1143 unpack_DUDV8(const void *src
, GLfloat dst
[][4], GLuint n
)
1145 const GLbyte
*s
= (const GLbyte
*) src
;
1147 for (i
= 0; i
< n
; i
++) {
1148 dst
[i
][RCOMP
] = BYTE_TO_FLOAT(s
[i
*2+0]);
1149 dst
[i
][GCOMP
] = BYTE_TO_FLOAT(s
[i
*2+1]);
1156 unpack_SIGNED_R8(const void *src
, GLfloat dst
[][4], GLuint n
)
1158 const GLbyte
*s
= ((const GLbyte
*) src
);
1160 for (i
= 0; i
< n
; i
++) {
1161 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( s
[i
] );
1162 dst
[i
][GCOMP
] = 0.0F
;
1163 dst
[i
][BCOMP
] = 0.0F
;
1164 dst
[i
][ACOMP
] = 1.0F
;
1169 unpack_SIGNED_RG88_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
1171 const GLushort
*s
= ((const GLushort
*) src
);
1173 for (i
= 0; i
< n
; i
++) {
1174 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] & 0xff) );
1175 dst
[i
][GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1176 dst
[i
][BCOMP
] = 0.0F
;
1177 dst
[i
][ACOMP
] = 1.0F
;
1182 unpack_SIGNED_RGBX8888(const void *src
, GLfloat dst
[][4], GLuint n
)
1184 const GLuint
*s
= ((const GLuint
*) src
);
1186 for (i
= 0; i
< n
; i
++) {
1187 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 24) );
1188 dst
[i
][GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 16) );
1189 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1190 dst
[i
][ACOMP
] = 1.0f
;
1195 unpack_SIGNED_RGBA8888(const void *src
, GLfloat dst
[][4], GLuint n
)
1197 const GLuint
*s
= ((const GLuint
*) src
);
1199 for (i
= 0; i
< n
; i
++) {
1200 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 24) );
1201 dst
[i
][GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 16) );
1202 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1203 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] ) );
1208 unpack_SIGNED_RGBA8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
1210 const GLuint
*s
= ((const GLuint
*) src
);
1212 for (i
= 0; i
< n
; i
++) {
1213 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] ) );
1214 dst
[i
][GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1215 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 16) );
1216 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 24) );
1221 unpack_SIGNED_R16(const void *src
, GLfloat dst
[][4], GLuint n
)
1223 const GLshort
*s
= ((const GLshort
*) src
);
1225 for (i
= 0; i
< n
; i
++) {
1226 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
] );
1227 dst
[i
][GCOMP
] = 0.0F
;
1228 dst
[i
][BCOMP
] = 0.0F
;
1229 dst
[i
][ACOMP
] = 1.0F
;
1234 unpack_SIGNED_GR1616(const void *src
, GLfloat dst
[][4], GLuint n
)
1236 const GLuint
*s
= ((const GLuint
*) src
);
1238 for (i
= 0; i
< n
; i
++) {
1239 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( (GLshort
) (s
[i
] & 0xffff) );
1240 dst
[i
][GCOMP
] = SHORT_TO_FLOAT_TEX( (GLshort
) (s
[i
] >> 16) );
1241 dst
[i
][BCOMP
] = 0.0F
;
1242 dst
[i
][ACOMP
] = 1.0F
;
1247 unpack_SIGNED_RGB_16(const void *src
, GLfloat dst
[][4], GLuint n
)
1249 const GLshort
*s
= (const GLshort
*) src
;
1251 for (i
= 0; i
< n
; i
++) {
1252 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*3+0] );
1253 dst
[i
][GCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*3+1] );
1254 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*3+2] );
1255 dst
[i
][ACOMP
] = 1.0F
;
1260 unpack_SIGNED_RGBA_16(const void *src
, GLfloat dst
[][4], GLuint n
)
1262 const GLshort
*s
= (const GLshort
*) src
;
1264 for (i
= 0; i
< n
; i
++) {
1265 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+0] );
1266 dst
[i
][GCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+1] );
1267 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+2] );
1268 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+3] );
1273 unpack_RGBA_16(const void *src
, GLfloat dst
[][4], GLuint n
)
1275 const GLushort
*s
= (const GLushort
*) src
;
1277 for (i
= 0; i
< n
; i
++) {
1278 dst
[i
][RCOMP
] = USHORT_TO_FLOAT( s
[i
*4+0] );
1279 dst
[i
][GCOMP
] = USHORT_TO_FLOAT( s
[i
*4+1] );
1280 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
*4+2] );
1281 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
*4+3] );
1286 unpack_RED_RGTC1(const void *src
, GLfloat dst
[][4], GLuint n
)
1292 unpack_SIGNED_RED_RGTC1(const void *src
, GLfloat dst
[][4], GLuint n
)
1298 unpack_RG_RGTC2(const void *src
, GLfloat dst
[][4], GLuint n
)
1304 unpack_SIGNED_RG_RGTC2(const void *src
, GLfloat dst
[][4], GLuint n
)
1310 unpack_L_LATC1(const void *src
, GLfloat dst
[][4], GLuint n
)
1316 unpack_SIGNED_L_LATC1(const void *src
, GLfloat dst
[][4], GLuint n
)
1322 unpack_LA_LATC2(const void *src
, GLfloat dst
[][4], GLuint n
)
1328 unpack_SIGNED_LA_LATC2(const void *src
, GLfloat dst
[][4], GLuint n
)
1334 unpack_ETC1_RGB8(const void *src
, GLfloat dst
[][4], GLuint n
)
1340 unpack_ETC2_RGB8(const void *src
, GLfloat dst
[][4], GLuint n
)
1346 unpack_ETC2_SRGB8(const void *src
, GLfloat dst
[][4], GLuint n
)
1352 unpack_ETC2_RGBA8_EAC(const void *src
, GLfloat dst
[][4], GLuint n
)
1358 unpack_ETC2_SRGB8_ALPHA8_EAC(const void *src
, GLfloat dst
[][4], GLuint n
)
1364 unpack_ETC2_R11_EAC(const void *src
, GLfloat dst
[][4], GLuint n
)
1370 unpack_ETC2_RG11_EAC(const void *src
, GLfloat dst
[][4], GLuint n
)
1376 unpack_ETC2_SIGNED_R11_EAC(const void *src
, GLfloat dst
[][4], GLuint n
)
1382 unpack_ETC2_SIGNED_RG11_EAC(const void *src
, GLfloat dst
[][4], GLuint n
)
1388 unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1(const void *src
, GLfloat dst
[][4],
1395 unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1(const void *src
, GLfloat dst
[][4],
1402 unpack_SIGNED_A8(const void *src
, GLfloat dst
[][4], GLuint n
)
1404 const GLbyte
*s
= ((const GLbyte
*) src
);
1406 for (i
= 0; i
< n
; i
++) {
1407 dst
[i
][RCOMP
] = 0.0F
;
1408 dst
[i
][GCOMP
] = 0.0F
;
1409 dst
[i
][BCOMP
] = 0.0F
;
1410 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( s
[i
] );
1415 unpack_SIGNED_L8(const void *src
, GLfloat dst
[][4], GLuint n
)
1417 const GLbyte
*s
= ((const GLbyte
*) src
);
1419 for (i
= 0; i
< n
; i
++) {
1422 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( s
[i
] );
1423 dst
[i
][ACOMP
] = 1.0F
;
1428 unpack_SIGNED_AL88(const void *src
, GLfloat dst
[][4], GLuint n
)
1430 const GLshort
*s
= ((const GLshort
*) src
);
1432 for (i
= 0; i
< n
; i
++) {
1435 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] & 0xff) );
1436 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1441 unpack_SIGNED_I8(const void *src
, GLfloat dst
[][4], GLuint n
)
1443 const GLbyte
*s
= ((const GLbyte
*) src
);
1445 for (i
= 0; i
< n
; i
++) {
1449 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( s
[i
] );
1454 unpack_SIGNED_A16(const void *src
, GLfloat dst
[][4], GLuint n
)
1456 const GLshort
*s
= ((const GLshort
*) src
);
1458 for (i
= 0; i
< n
; i
++) {
1459 dst
[i
][RCOMP
] = 0.0F
;
1460 dst
[i
][GCOMP
] = 0.0F
;
1461 dst
[i
][BCOMP
] = 0.0F
;
1462 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
] );
1467 unpack_SIGNED_L16(const void *src
, GLfloat dst
[][4], GLuint n
)
1469 const GLshort
*s
= ((const GLshort
*) src
);
1471 for (i
= 0; i
< n
; i
++) {
1474 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
] );
1475 dst
[i
][ACOMP
] = 1.0F
;
1480 unpack_SIGNED_AL1616(const void *src
, GLfloat dst
[][4], GLuint n
)
1482 const GLshort
*s
= (const GLshort
*) src
;
1484 for (i
= 0; i
< n
; i
++) {
1487 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*2+0] );
1488 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*2+1] );
1493 unpack_SIGNED_I16(const void *src
, GLfloat dst
[][4], GLuint n
)
1495 const GLshort
*s
= ((const GLshort
*) src
);
1497 for (i
= 0; i
< n
; i
++) {
1501 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
] );
1506 unpack_RGB9_E5_FLOAT(const void *src
, GLfloat dst
[][4], GLuint n
)
1508 const GLuint
*s
= (const GLuint
*) src
;
1510 for (i
= 0; i
< n
; i
++) {
1511 rgb9e5_to_float3(s
[i
], dst
[i
]);
1512 dst
[i
][ACOMP
] = 1.0F
;
1517 unpack_R11_G11_B10_FLOAT(const void *src
, GLfloat dst
[][4], GLuint n
)
1519 const GLuint
*s
= (const GLuint
*) src
;
1521 for (i
= 0; i
< n
; i
++) {
1522 r11g11b10f_to_float3(s
[i
], dst
[i
]);
1523 dst
[i
][ACOMP
] = 1.0F
;
1529 * Return the unpacker function for the given format.
1531 static unpack_rgba_func
1532 get_unpack_rgba_function(gl_format format
)
1534 static unpack_rgba_func table
[MESA_FORMAT_COUNT
];
1535 static GLboolean initialized
= GL_FALSE
;
1538 table
[MESA_FORMAT_NONE
] = NULL
;
1540 table
[MESA_FORMAT_RGBA8888
] = unpack_RGBA8888
;
1541 table
[MESA_FORMAT_RGBA8888_REV
] = unpack_RGBA8888_REV
;
1542 table
[MESA_FORMAT_ARGB8888
] = unpack_ARGB8888
;
1543 table
[MESA_FORMAT_ARGB8888_REV
] = unpack_ARGB8888_REV
;
1544 table
[MESA_FORMAT_RGBX8888
] = unpack_RGBX8888
;
1545 table
[MESA_FORMAT_RGBX8888_REV
] = unpack_RGBX8888_REV
;
1546 table
[MESA_FORMAT_XRGB8888
] = unpack_XRGB8888
;
1547 table
[MESA_FORMAT_XRGB8888_REV
] = unpack_XRGB8888_REV
;
1548 table
[MESA_FORMAT_RGB888
] = unpack_RGB888
;
1549 table
[MESA_FORMAT_BGR888
] = unpack_BGR888
;
1550 table
[MESA_FORMAT_RGB565
] = unpack_RGB565
;
1551 table
[MESA_FORMAT_RGB565_REV
] = unpack_RGB565_REV
;
1552 table
[MESA_FORMAT_ARGB4444
] = unpack_ARGB4444
;
1553 table
[MESA_FORMAT_ARGB4444_REV
] = unpack_ARGB4444_REV
;
1554 table
[MESA_FORMAT_RGBA5551
] = unpack_RGBA5551
;
1555 table
[MESA_FORMAT_ARGB1555
] = unpack_ARGB1555
;
1556 table
[MESA_FORMAT_ARGB1555_REV
] = unpack_ARGB1555_REV
;
1557 table
[MESA_FORMAT_AL44
] = unpack_AL44
;
1558 table
[MESA_FORMAT_AL88
] = unpack_AL88
;
1559 table
[MESA_FORMAT_AL88_REV
] = unpack_AL88_REV
;
1560 table
[MESA_FORMAT_AL1616
] = unpack_AL1616
;
1561 table
[MESA_FORMAT_AL1616_REV
] = unpack_AL1616_REV
;
1562 table
[MESA_FORMAT_RGB332
] = unpack_RGB332
;
1563 table
[MESA_FORMAT_A8
] = unpack_A8
;
1564 table
[MESA_FORMAT_A16
] = unpack_A16
;
1565 table
[MESA_FORMAT_L8
] = unpack_L8
;
1566 table
[MESA_FORMAT_L16
] = unpack_L16
;
1567 table
[MESA_FORMAT_I8
] = unpack_I8
;
1568 table
[MESA_FORMAT_I16
] = unpack_I16
;
1569 table
[MESA_FORMAT_YCBCR
] = unpack_YCBCR
;
1570 table
[MESA_FORMAT_YCBCR_REV
] = unpack_YCBCR_REV
;
1571 table
[MESA_FORMAT_R8
] = unpack_R8
;
1572 table
[MESA_FORMAT_GR88
] = unpack_GR88
;
1573 table
[MESA_FORMAT_RG88
] = unpack_RG88
;
1574 table
[MESA_FORMAT_R16
] = unpack_R16
;
1575 table
[MESA_FORMAT_RG1616
] = unpack_RG1616
;
1576 table
[MESA_FORMAT_RG1616_REV
] = unpack_RG1616_REV
;
1577 table
[MESA_FORMAT_ARGB2101010
] = unpack_ARGB2101010
;
1578 table
[MESA_FORMAT_ABGR2101010_UINT
] = unpack_ABGR2101010_UINT
;
1579 table
[MESA_FORMAT_Z24_S8
] = unpack_Z24_S8
;
1580 table
[MESA_FORMAT_S8_Z24
] = unpack_S8_Z24
;
1581 table
[MESA_FORMAT_Z16
] = unpack_Z16
;
1582 table
[MESA_FORMAT_X8_Z24
] = unpack_X8_Z24
;
1583 table
[MESA_FORMAT_Z24_X8
] = unpack_Z24_X8
;
1584 table
[MESA_FORMAT_Z32
] = unpack_Z32
;
1585 table
[MESA_FORMAT_S8
] = unpack_S8
;
1586 table
[MESA_FORMAT_SRGB8
] = unpack_SRGB8
;
1587 table
[MESA_FORMAT_SRGBA8
] = unpack_SRGBA8
;
1588 table
[MESA_FORMAT_SARGB8
] = unpack_SARGB8
;
1589 table
[MESA_FORMAT_SL8
] = unpack_SL8
;
1590 table
[MESA_FORMAT_SLA8
] = unpack_SLA8
;
1591 table
[MESA_FORMAT_SRGB_DXT1
] = unpack_SRGB_DXT1
;
1592 table
[MESA_FORMAT_SRGBA_DXT1
] = unpack_SRGBA_DXT1
;
1593 table
[MESA_FORMAT_SRGBA_DXT3
] = unpack_SRGBA_DXT3
;
1594 table
[MESA_FORMAT_SRGBA_DXT5
] = unpack_SRGBA_DXT5
;
1596 table
[MESA_FORMAT_RGB_FXT1
] = unpack_RGB_FXT1
;
1597 table
[MESA_FORMAT_RGBA_FXT1
] = unpack_RGBA_FXT1
;
1598 table
[MESA_FORMAT_RGB_DXT1
] = unpack_RGB_DXT1
;
1599 table
[MESA_FORMAT_RGBA_DXT1
] = unpack_RGBA_DXT1
;
1600 table
[MESA_FORMAT_RGBA_DXT3
] = unpack_RGBA_DXT3
;
1601 table
[MESA_FORMAT_RGBA_DXT5
] = unpack_RGBA_DXT5
;
1603 table
[MESA_FORMAT_RGBA_FLOAT32
] = unpack_RGBA_FLOAT32
;
1604 table
[MESA_FORMAT_RGBA_FLOAT16
] = unpack_RGBA_FLOAT16
;
1605 table
[MESA_FORMAT_RGB_FLOAT32
] = unpack_RGB_FLOAT32
;
1606 table
[MESA_FORMAT_RGB_FLOAT16
] = unpack_RGB_FLOAT16
;
1607 table
[MESA_FORMAT_ALPHA_FLOAT32
] = unpack_ALPHA_FLOAT32
;
1608 table
[MESA_FORMAT_ALPHA_FLOAT16
] = unpack_ALPHA_FLOAT16
;
1609 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = unpack_LUMINANCE_FLOAT32
;
1610 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = unpack_LUMINANCE_FLOAT16
;
1611 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = unpack_LUMINANCE_ALPHA_FLOAT32
;
1612 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = unpack_LUMINANCE_ALPHA_FLOAT16
;
1613 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = unpack_INTENSITY_FLOAT32
;
1614 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = unpack_INTENSITY_FLOAT16
;
1615 table
[MESA_FORMAT_R_FLOAT32
] = unpack_R_FLOAT32
;
1616 table
[MESA_FORMAT_R_FLOAT16
] = unpack_R_FLOAT16
;
1617 table
[MESA_FORMAT_RG_FLOAT32
] = unpack_RG_FLOAT32
;
1618 table
[MESA_FORMAT_RG_FLOAT16
] = unpack_RG_FLOAT16
;
1620 table
[MESA_FORMAT_RGBA_INT8
] = unpack_RGBA_INT8
;
1621 table
[MESA_FORMAT_RGBA_INT16
] = unpack_RGBA_INT16
;
1622 table
[MESA_FORMAT_RGBA_INT32
] = unpack_RGBA_INT32
;
1623 table
[MESA_FORMAT_RGBA_UINT8
] = unpack_RGBA_UINT8
;
1624 table
[MESA_FORMAT_RGBA_UINT16
] = unpack_RGBA_UINT16
;
1625 table
[MESA_FORMAT_RGBA_UINT32
] = unpack_RGBA_UINT32
;
1627 table
[MESA_FORMAT_DUDV8
] = unpack_DUDV8
;
1628 table
[MESA_FORMAT_SIGNED_R8
] = unpack_SIGNED_R8
;
1629 table
[MESA_FORMAT_SIGNED_RG88_REV
] = unpack_SIGNED_RG88_REV
;
1630 table
[MESA_FORMAT_SIGNED_RGBX8888
] = unpack_SIGNED_RGBX8888
;
1631 table
[MESA_FORMAT_SIGNED_RGBA8888
] = unpack_SIGNED_RGBA8888
;
1632 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = unpack_SIGNED_RGBA8888_REV
;
1633 table
[MESA_FORMAT_SIGNED_R16
] = unpack_SIGNED_R16
;
1634 table
[MESA_FORMAT_SIGNED_GR1616
] = unpack_SIGNED_GR1616
;
1635 table
[MESA_FORMAT_SIGNED_RGB_16
] = unpack_SIGNED_RGB_16
;
1636 table
[MESA_FORMAT_SIGNED_RGBA_16
] = unpack_SIGNED_RGBA_16
;
1637 table
[MESA_FORMAT_RGBA_16
] = unpack_RGBA_16
;
1639 table
[MESA_FORMAT_RED_RGTC1
] = unpack_RED_RGTC1
;
1640 table
[MESA_FORMAT_SIGNED_RED_RGTC1
] = unpack_SIGNED_RED_RGTC1
;
1641 table
[MESA_FORMAT_RG_RGTC2
] = unpack_RG_RGTC2
;
1642 table
[MESA_FORMAT_SIGNED_RG_RGTC2
] = unpack_SIGNED_RG_RGTC2
;
1644 table
[MESA_FORMAT_L_LATC1
] = unpack_L_LATC1
;
1645 table
[MESA_FORMAT_SIGNED_L_LATC1
] = unpack_SIGNED_L_LATC1
;
1646 table
[MESA_FORMAT_LA_LATC2
] = unpack_LA_LATC2
;
1647 table
[MESA_FORMAT_SIGNED_LA_LATC2
] = unpack_SIGNED_LA_LATC2
;
1649 table
[MESA_FORMAT_ETC1_RGB8
] = unpack_ETC1_RGB8
;
1650 table
[MESA_FORMAT_ETC2_RGB8
] = unpack_ETC2_RGB8
;
1651 table
[MESA_FORMAT_ETC2_SRGB8
] = unpack_ETC2_SRGB8
;
1652 table
[MESA_FORMAT_ETC2_RGBA8_EAC
] = unpack_ETC2_RGBA8_EAC
;
1653 table
[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
] = unpack_ETC2_SRGB8_ALPHA8_EAC
;
1654 table
[MESA_FORMAT_ETC2_R11_EAC
] = unpack_ETC2_R11_EAC
;
1655 table
[MESA_FORMAT_ETC2_RG11_EAC
] = unpack_ETC2_RG11_EAC
;
1656 table
[MESA_FORMAT_ETC2_SIGNED_R11_EAC
] = unpack_ETC2_SIGNED_R11_EAC
;
1657 table
[MESA_FORMAT_ETC2_SIGNED_RG11_EAC
] = unpack_ETC2_SIGNED_RG11_EAC
;
1658 table
[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
] =
1659 unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
1660 table
[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
] =
1661 unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
;
1662 table
[MESA_FORMAT_SIGNED_A8
] = unpack_SIGNED_A8
;
1663 table
[MESA_FORMAT_SIGNED_L8
] = unpack_SIGNED_L8
;
1664 table
[MESA_FORMAT_SIGNED_AL88
] = unpack_SIGNED_AL88
;
1665 table
[MESA_FORMAT_SIGNED_I8
] = unpack_SIGNED_I8
;
1666 table
[MESA_FORMAT_SIGNED_A16
] = unpack_SIGNED_A16
;
1667 table
[MESA_FORMAT_SIGNED_L16
] = unpack_SIGNED_L16
;
1668 table
[MESA_FORMAT_SIGNED_AL1616
] = unpack_SIGNED_AL1616
;
1669 table
[MESA_FORMAT_SIGNED_I16
] = unpack_SIGNED_I16
;
1671 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = unpack_RGB9_E5_FLOAT
;
1672 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = unpack_R11_G11_B10_FLOAT
;
1674 table
[MESA_FORMAT_Z32_FLOAT
] = unpack_Z32_FLOAT
;
1675 table
[MESA_FORMAT_Z32_FLOAT_X24S8
] = unpack_Z32_FLOAT_X24S8
;
1677 initialized
= GL_TRUE
;
1680 if (table
[format
] == NULL
) {
1681 _mesa_problem(NULL
, "unsupported unpack for format %s",
1682 _mesa_get_format_name(format
));
1685 return table
[format
];
1690 * Unpack rgba colors, returning as GLfloat values.
1693 _mesa_unpack_rgba_row(gl_format format
, GLuint n
,
1694 const void *src
, GLfloat dst
[][4])
1696 unpack_rgba_func unpack
= get_unpack_rgba_function(format
);
1697 unpack(src
, dst
, n
);
1701 /**********************************************************************/
1702 /* Unpack, returning GLubyte colors */
1703 /**********************************************************************/
1707 unpack_ubyte_RGBA8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1709 const GLuint
*s
= ((const GLuint
*) src
);
1711 for (i
= 0; i
< n
; i
++) {
1712 dst
[i
][RCOMP
] = (s
[i
] >> 24);
1713 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1714 dst
[i
][BCOMP
] = (s
[i
] >> 8) & 0xff;
1715 dst
[i
][ACOMP
] = (s
[i
] ) & 0xff;
1720 unpack_ubyte_RGBA8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1722 const GLuint
*s
= ((const GLuint
*) src
);
1724 for (i
= 0; i
< n
; i
++) {
1725 dst
[i
][RCOMP
] = (s
[i
] ) & 0xff;
1726 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1727 dst
[i
][BCOMP
] = (s
[i
] >> 16) & 0xff;
1728 dst
[i
][ACOMP
] = (s
[i
] >> 24);
1733 unpack_ubyte_ARGB8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1735 const GLuint
*s
= ((const GLuint
*) src
);
1737 for (i
= 0; i
< n
; i
++) {
1738 dst
[i
][RCOMP
] = (s
[i
] >> 16) & 0xff;
1739 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1740 dst
[i
][BCOMP
] = (s
[i
] ) & 0xff;
1741 dst
[i
][ACOMP
] = (s
[i
] >> 24);
1746 unpack_ubyte_ARGB8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1748 const GLuint
*s
= ((const GLuint
*) src
);
1750 for (i
= 0; i
< n
; i
++) {
1751 dst
[i
][RCOMP
] = (s
[i
] >> 8) & 0xff;
1752 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1753 dst
[i
][BCOMP
] = (s
[i
] >> 24);
1754 dst
[i
][ACOMP
] = (s
[i
] ) & 0xff;
1759 unpack_ubyte_RGBX8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1761 const GLuint
*s
= ((const GLuint
*) src
);
1763 for (i
= 0; i
< n
; i
++) {
1764 dst
[i
][RCOMP
] = (s
[i
] >> 24);
1765 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1766 dst
[i
][BCOMP
] = (s
[i
] >> 8) & 0xff;
1767 dst
[i
][ACOMP
] = 0xff;
1772 unpack_ubyte_RGBX8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1774 const GLuint
*s
= ((const GLuint
*) src
);
1776 for (i
= 0; i
< n
; i
++) {
1777 dst
[i
][RCOMP
] = (s
[i
] ) & 0xff;
1778 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1779 dst
[i
][BCOMP
] = (s
[i
] >> 16) & 0xff;
1780 dst
[i
][ACOMP
] = 0xff;
1785 unpack_ubyte_XRGB8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1787 const GLuint
*s
= ((const GLuint
*) src
);
1789 for (i
= 0; i
< n
; i
++) {
1790 dst
[i
][RCOMP
] = (s
[i
] >> 16) & 0xff;
1791 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1792 dst
[i
][BCOMP
] = (s
[i
] ) & 0xff;
1793 dst
[i
][ACOMP
] = 0xff;
1798 unpack_ubyte_XRGB8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1800 const GLuint
*s
= ((const GLuint
*) src
);
1802 for (i
= 0; i
< n
; i
++) {
1803 dst
[i
][RCOMP
] = (s
[i
] >> 8) & 0xff;
1804 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1805 dst
[i
][BCOMP
] = (s
[i
] >> 24);
1806 dst
[i
][ACOMP
] = 0xff;
1811 unpack_ubyte_RGB888(const void *src
, GLubyte dst
[][4], GLuint n
)
1813 const GLubyte
*s
= (const GLubyte
*) src
;
1815 for (i
= 0; i
< n
; i
++) {
1816 dst
[i
][RCOMP
] = s
[i
*3+2];
1817 dst
[i
][GCOMP
] = s
[i
*3+1];
1818 dst
[i
][BCOMP
] = s
[i
*3+0];
1819 dst
[i
][ACOMP
] = 0xff;
1824 unpack_ubyte_BGR888(const void *src
, GLubyte dst
[][4], GLuint n
)
1826 const GLubyte
*s
= (const GLubyte
*) src
;
1828 for (i
= 0; i
< n
; i
++) {
1829 dst
[i
][RCOMP
] = s
[i
*3+0];
1830 dst
[i
][GCOMP
] = s
[i
*3+1];
1831 dst
[i
][BCOMP
] = s
[i
*3+2];
1832 dst
[i
][ACOMP
] = 0xff;
1837 unpack_ubyte_RGB565(const void *src
, GLubyte dst
[][4], GLuint n
)
1839 const GLushort
*s
= ((const GLushort
*) src
);
1841 for (i
= 0; i
< n
; i
++) {
1842 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 11) & 0x1f);
1843 dst
[i
][GCOMP
] = EXPAND_6_8((s
[i
] >> 5 ) & 0x3f);
1844 dst
[i
][BCOMP
] = EXPAND_5_8( s
[i
] & 0x1f);
1845 dst
[i
][ACOMP
] = 0xff;
1850 unpack_ubyte_RGB565_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1852 const GLushort
*s
= ((const GLushort
*) src
);
1854 for (i
= 0; i
< n
; i
++) {
1855 GLuint t
= (s
[i
] >> 8) | (s
[i
] << 8); /* byte swap */
1856 dst
[i
][RCOMP
] = EXPAND_5_8((t
>> 11) & 0x1f);
1857 dst
[i
][GCOMP
] = EXPAND_6_8((t
>> 5 ) & 0x3f);
1858 dst
[i
][BCOMP
] = EXPAND_5_8( t
& 0x1f);
1859 dst
[i
][ACOMP
] = 0xff;
1864 unpack_ubyte_ARGB4444(const void *src
, GLubyte dst
[][4], GLuint n
)
1866 const GLushort
*s
= ((const GLushort
*) src
);
1868 for (i
= 0; i
< n
; i
++) {
1869 dst
[i
][RCOMP
] = EXPAND_4_8((s
[i
] >> 8) & 0xf);
1870 dst
[i
][GCOMP
] = EXPAND_4_8((s
[i
] >> 4) & 0xf);
1871 dst
[i
][BCOMP
] = EXPAND_4_8((s
[i
] ) & 0xf);
1872 dst
[i
][ACOMP
] = EXPAND_4_8((s
[i
] >> 12) & 0xf);
1877 unpack_ubyte_ARGB4444_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1879 const GLushort
*s
= ((const GLushort
*) src
);
1881 for (i
= 0; i
< n
; i
++) {
1882 dst
[i
][RCOMP
] = EXPAND_4_8((s
[i
] ) & 0xf);
1883 dst
[i
][GCOMP
] = EXPAND_4_8((s
[i
] >> 12) & 0xf);
1884 dst
[i
][BCOMP
] = EXPAND_4_8((s
[i
] >> 8) & 0xf);
1885 dst
[i
][ACOMP
] = EXPAND_4_8((s
[i
] >> 4) & 0xf);
1890 unpack_ubyte_RGBA5551(const void *src
, GLubyte dst
[][4], GLuint n
)
1892 const GLushort
*s
= ((const GLushort
*) src
);
1894 for (i
= 0; i
< n
; i
++) {
1895 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 11) & 0x1f);
1896 dst
[i
][GCOMP
] = EXPAND_5_8((s
[i
] >> 6) & 0x1f);
1897 dst
[i
][BCOMP
] = EXPAND_5_8((s
[i
] >> 1) & 0x1f);
1898 dst
[i
][ACOMP
] = EXPAND_1_8((s
[i
] ) & 0x01);
1903 unpack_ubyte_ARGB1555(const void *src
, GLubyte dst
[][4], GLuint n
)
1905 const GLushort
*s
= ((const GLushort
*) src
);
1907 for (i
= 0; i
< n
; i
++) {
1908 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 10) & 0x1f);
1909 dst
[i
][GCOMP
] = EXPAND_5_8((s
[i
] >> 5) & 0x1f);
1910 dst
[i
][BCOMP
] = EXPAND_5_8((s
[i
] >> 0) & 0x1f);
1911 dst
[i
][ACOMP
] = EXPAND_1_8((s
[i
] >> 15) & 0x01);
1916 unpack_ubyte_ARGB1555_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1918 const GLushort
*s
= ((const GLushort
*) src
);
1920 for (i
= 0; i
< n
; i
++) {
1921 GLushort tmp
= (s
[i
] << 8) | (s
[i
] >> 8); /* byteswap */
1922 dst
[i
][RCOMP
] = EXPAND_5_8((tmp
>> 10) & 0x1f);
1923 dst
[i
][GCOMP
] = EXPAND_5_8((tmp
>> 5) & 0x1f);
1924 dst
[i
][BCOMP
] = EXPAND_5_8((tmp
>> 0) & 0x1f);
1925 dst
[i
][ACOMP
] = EXPAND_1_8((tmp
>> 15) & 0x01);
1930 unpack_ubyte_AL44(const void *src
, GLubyte dst
[][4], GLuint n
)
1932 const GLubyte
*s
= ((const GLubyte
*) src
);
1934 for (i
= 0; i
< n
; i
++) {
1937 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] & 0xf);
1938 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] >> 4);
1943 unpack_ubyte_AL88(const void *src
, GLubyte dst
[][4], GLuint n
)
1945 const GLushort
*s
= ((const GLushort
*) src
);
1947 for (i
= 0; i
< n
; i
++) {
1950 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] & 0xff);
1951 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] >> 8);
1956 unpack_ubyte_AL88_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1958 const GLushort
*s
= ((const GLushort
*) src
);
1960 for (i
= 0; i
< n
; i
++) {
1963 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] >> 8);
1964 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] & 0xff);
1969 unpack_ubyte_RGB332(const void *src
, GLubyte dst
[][4], GLuint n
)
1971 const GLubyte
*s
= ((const GLubyte
*) src
);
1973 for (i
= 0; i
< n
; i
++) {
1974 dst
[i
][RCOMP
] = EXPAND_3_8((s
[i
] >> 5) & 0x7);
1975 dst
[i
][GCOMP
] = EXPAND_3_8((s
[i
] >> 2) & 0x7);
1976 dst
[i
][BCOMP
] = EXPAND_2_8((s
[i
] ) & 0x3);
1977 dst
[i
][ACOMP
] = 0xff;
1982 unpack_ubyte_A8(const void *src
, GLubyte dst
[][4], GLuint n
)
1984 const GLubyte
*s
= ((const GLubyte
*) src
);
1986 for (i
= 0; i
< n
; i
++) {
1990 dst
[i
][ACOMP
] = s
[i
];
1995 unpack_ubyte_L8(const void *src
, GLubyte dst
[][4], GLuint n
)
1997 const GLubyte
*s
= ((const GLubyte
*) src
);
1999 for (i
= 0; i
< n
; i
++) {
2002 dst
[i
][BCOMP
] = s
[i
];
2003 dst
[i
][ACOMP
] = 0xff;
2009 unpack_ubyte_I8(const void *src
, GLubyte dst
[][4], GLuint n
)
2011 const GLubyte
*s
= ((const GLubyte
*) src
);
2013 for (i
= 0; i
< n
; i
++) {
2017 dst
[i
][ACOMP
] = s
[i
];
2022 unpack_ubyte_R8(const void *src
, GLubyte dst
[][4], GLuint n
)
2024 const GLubyte
*s
= ((const GLubyte
*) src
);
2026 for (i
= 0; i
< n
; i
++) {
2035 unpack_ubyte_GR88(const void *src
, GLubyte dst
[][4], GLuint n
)
2037 const GLushort
*s
= ((const GLushort
*) src
);
2039 for (i
= 0; i
< n
; i
++) {
2040 dst
[i
][RCOMP
] = s
[i
] & 0xff;
2041 dst
[i
][GCOMP
] = s
[i
] >> 8;
2043 dst
[i
][ACOMP
] = 0xff;
2048 unpack_ubyte_RG88(const void *src
, GLubyte dst
[][4], GLuint n
)
2050 const GLushort
*s
= ((const GLushort
*) src
);
2052 for (i
= 0; i
< n
; i
++) {
2053 dst
[i
][RCOMP
] = s
[i
] >> 8;
2054 dst
[i
][GCOMP
] = s
[i
] & 0xff;
2056 dst
[i
][ACOMP
] = 0xff;
2062 * Unpack rgba colors, returning as GLubyte values. This should usually
2063 * only be used for unpacking formats that use 8 bits or less per channel.
2066 _mesa_unpack_ubyte_rgba_row(gl_format format
, GLuint n
,
2067 const void *src
, GLubyte dst
[][4])
2070 case MESA_FORMAT_RGBA8888
:
2071 unpack_ubyte_RGBA8888(src
, dst
, n
);
2073 case MESA_FORMAT_RGBA8888_REV
:
2074 unpack_ubyte_RGBA8888_REV(src
, dst
, n
);
2076 case MESA_FORMAT_ARGB8888
:
2077 unpack_ubyte_ARGB8888(src
, dst
, n
);
2079 case MESA_FORMAT_ARGB8888_REV
:
2080 unpack_ubyte_ARGB8888_REV(src
, dst
, n
);
2082 case MESA_FORMAT_RGBX8888
:
2083 unpack_ubyte_RGBX8888(src
, dst
, n
);
2085 case MESA_FORMAT_RGBX8888_REV
:
2086 unpack_ubyte_RGBX8888_REV(src
, dst
, n
);
2088 case MESA_FORMAT_XRGB8888
:
2089 unpack_ubyte_XRGB8888(src
, dst
, n
);
2091 case MESA_FORMAT_XRGB8888_REV
:
2092 unpack_ubyte_XRGB8888_REV(src
, dst
, n
);
2094 case MESA_FORMAT_RGB888
:
2095 unpack_ubyte_RGB888(src
, dst
, n
);
2097 case MESA_FORMAT_BGR888
:
2098 unpack_ubyte_BGR888(src
, dst
, n
);
2100 case MESA_FORMAT_RGB565
:
2101 unpack_ubyte_RGB565(src
, dst
, n
);
2103 case MESA_FORMAT_RGB565_REV
:
2104 unpack_ubyte_RGB565_REV(src
, dst
, n
);
2106 case MESA_FORMAT_ARGB4444
:
2107 unpack_ubyte_ARGB4444(src
, dst
, n
);
2109 case MESA_FORMAT_ARGB4444_REV
:
2110 unpack_ubyte_ARGB4444_REV(src
, dst
, n
);
2112 case MESA_FORMAT_RGBA5551
:
2113 unpack_ubyte_RGBA5551(src
, dst
, n
);
2115 case MESA_FORMAT_ARGB1555
:
2116 unpack_ubyte_ARGB1555(src
, dst
, n
);
2118 case MESA_FORMAT_ARGB1555_REV
:
2119 unpack_ubyte_ARGB1555_REV(src
, dst
, n
);
2121 case MESA_FORMAT_AL44
:
2122 unpack_ubyte_AL44(src
, dst
, n
);
2124 case MESA_FORMAT_AL88
:
2125 unpack_ubyte_AL88(src
, dst
, n
);
2127 case MESA_FORMAT_AL88_REV
:
2128 unpack_ubyte_AL88_REV(src
, dst
, n
);
2130 case MESA_FORMAT_RGB332
:
2131 unpack_ubyte_RGB332(src
, dst
, n
);
2133 case MESA_FORMAT_A8
:
2134 unpack_ubyte_A8(src
, dst
, n
);
2136 case MESA_FORMAT_L8
:
2137 unpack_ubyte_L8(src
, dst
, n
);
2139 case MESA_FORMAT_I8
:
2140 unpack_ubyte_I8(src
, dst
, n
);
2142 case MESA_FORMAT_R8
:
2143 unpack_ubyte_R8(src
, dst
, n
);
2145 case MESA_FORMAT_GR88
:
2146 unpack_ubyte_GR88(src
, dst
, n
);
2148 case MESA_FORMAT_RG88
:
2149 unpack_ubyte_RG88(src
, dst
, n
);
2152 /* get float values, convert to ubyte */
2154 GLfloat
*tmp
= malloc(n
* 4 * sizeof(GLfloat
));
2157 _mesa_unpack_rgba_row(format
, n
, src
, (GLfloat (*)[4]) tmp
);
2158 for (i
= 0; i
< n
; i
++) {
2159 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][0], tmp
[i
*4+0]);
2160 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][1], tmp
[i
*4+1]);
2161 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][2], tmp
[i
*4+2]);
2162 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][3], tmp
[i
*4+3]);
2172 /**********************************************************************/
2173 /* Unpack, returning GLuint colors */
2174 /**********************************************************************/
2177 unpack_int_rgba_RGBA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2179 memcpy(dst
, src
, n
* 4 * sizeof(GLuint
));
2183 unpack_int_rgba_RGBA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2187 for (i
= 0; i
< n
; i
++) {
2188 dst
[i
][0] = src
[i
* 4 + 0];
2189 dst
[i
][1] = src
[i
* 4 + 1];
2190 dst
[i
][2] = src
[i
* 4 + 2];
2191 dst
[i
][3] = src
[i
* 4 + 3];
2196 unpack_int_rgba_RGBA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2200 for (i
= 0; i
< n
; i
++) {
2201 dst
[i
][0] = src
[i
* 4 + 0];
2202 dst
[i
][1] = src
[i
* 4 + 1];
2203 dst
[i
][2] = src
[i
* 4 + 2];
2204 dst
[i
][3] = src
[i
* 4 + 3];
2209 unpack_int_rgba_RGBA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2213 for (i
= 0; i
< n
; i
++) {
2214 dst
[i
][0] = src
[i
* 4 + 0];
2215 dst
[i
][1] = src
[i
* 4 + 1];
2216 dst
[i
][2] = src
[i
* 4 + 2];
2217 dst
[i
][3] = src
[i
* 4 + 3];
2222 unpack_int_rgba_RGBA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2226 for (i
= 0; i
< n
; i
++) {
2227 dst
[i
][0] = src
[i
* 4 + 0];
2228 dst
[i
][1] = src
[i
* 4 + 1];
2229 dst
[i
][2] = src
[i
* 4 + 2];
2230 dst
[i
][3] = src
[i
* 4 + 3];
2235 unpack_int_rgba_ARGB8888(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2239 for (i
= 0; i
< n
; i
++) {
2240 dst
[i
][RCOMP
] = (GLubyte
) src
[i
* 4 + 2];
2241 dst
[i
][GCOMP
] = (GLubyte
) src
[i
* 4 + 1];
2242 dst
[i
][BCOMP
] = (GLubyte
) src
[i
* 4 + 0];
2243 dst
[i
][ACOMP
] = (GLubyte
) src
[i
* 4 + 3];
2248 unpack_int_rgba_XRGB8888(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2252 for (i
= 0; i
< n
; i
++) {
2253 dst
[i
][RCOMP
] = (GLubyte
) src
[i
* 4 + 2];
2254 dst
[i
][GCOMP
] = (GLubyte
) src
[i
* 4 + 1];
2255 dst
[i
][BCOMP
] = (GLubyte
) src
[i
* 4 + 0];
2256 dst
[i
][ACOMP
] = (GLubyte
) 0xff;
2261 unpack_int_rgba_RGB_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2265 for (i
= 0; i
< n
; i
++) {
2266 dst
[i
][0] = src
[i
* 3 + 0];
2267 dst
[i
][1] = src
[i
* 3 + 1];
2268 dst
[i
][2] = src
[i
* 3 + 2];
2274 unpack_int_rgba_RGB_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2278 for (i
= 0; i
< n
; i
++) {
2279 dst
[i
][0] = src
[i
* 3 + 0];
2280 dst
[i
][1] = src
[i
* 3 + 1];
2281 dst
[i
][2] = src
[i
* 3 + 2];
2287 unpack_int_rgba_RGB_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2291 for (i
= 0; i
< n
; i
++) {
2292 dst
[i
][0] = src
[i
* 3 + 0];
2293 dst
[i
][1] = src
[i
* 3 + 1];
2294 dst
[i
][2] = src
[i
* 3 + 2];
2300 unpack_int_rgba_RGB_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2304 for (i
= 0; i
< n
; i
++) {
2305 dst
[i
][0] = src
[i
* 3 + 0];
2306 dst
[i
][1] = src
[i
* 3 + 1];
2307 dst
[i
][2] = src
[i
* 3 + 2];
2313 unpack_int_rgba_RGB_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2317 for (i
= 0; i
< n
; i
++) {
2318 dst
[i
][0] = src
[i
* 3 + 0];
2319 dst
[i
][1] = src
[i
* 3 + 1];
2320 dst
[i
][2] = src
[i
* 3 + 2];
2326 unpack_int_rgba_RG_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2330 for (i
= 0; i
< n
; i
++) {
2331 dst
[i
][0] = src
[i
* 2 + 0];
2332 dst
[i
][1] = src
[i
* 2 + 1];
2339 unpack_int_rgba_RG_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2343 for (i
= 0; i
< n
; i
++) {
2344 dst
[i
][0] = src
[i
* 2 + 0];
2345 dst
[i
][1] = src
[i
* 2 + 1];
2352 unpack_int_rgba_RG_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2356 for (i
= 0; i
< n
; i
++) {
2357 dst
[i
][0] = src
[i
* 2 + 0];
2358 dst
[i
][1] = src
[i
* 2 + 1];
2365 unpack_int_rgba_RG_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2369 for (i
= 0; i
< n
; i
++) {
2370 dst
[i
][0] = src
[i
* 2 + 0];
2371 dst
[i
][1] = src
[i
* 2 + 1];
2378 unpack_int_rgba_RG_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2382 for (i
= 0; i
< n
; i
++) {
2383 dst
[i
][0] = src
[i
* 2 + 0];
2384 dst
[i
][1] = src
[i
* 2 + 1];
2391 unpack_int_rgba_R_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2395 for (i
= 0; i
< n
; i
++) {
2404 unpack_int_rgba_R_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2408 for (i
= 0; i
< n
; i
++) {
2417 unpack_int_rgba_R_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2421 for (i
= 0; i
< n
; i
++) {
2430 unpack_int_rgba_R_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2434 for (i
= 0; i
< n
; i
++) {
2443 unpack_int_rgba_R_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2447 for (i
= 0; i
< n
; i
++) {
2456 unpack_int_rgba_ALPHA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2460 for (i
= 0; i
< n
; i
++) {
2461 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2467 unpack_int_rgba_ALPHA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2471 for (i
= 0; i
< n
; i
++) {
2472 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2478 unpack_int_rgba_ALPHA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2482 for (i
= 0; i
< n
; i
++) {
2483 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2489 unpack_int_rgba_ALPHA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2493 for (i
= 0; i
< n
; i
++) {
2494 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2500 unpack_int_rgba_ALPHA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2504 for (i
= 0; i
< n
; i
++) {
2505 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2511 unpack_int_rgba_LUMINANCE_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2515 for (i
= 0; i
< n
; i
++) {
2516 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2522 unpack_int_rgba_LUMINANCE_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2526 for (i
= 0; i
< n
; i
++) {
2527 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2533 unpack_int_rgba_LUMINANCE_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2537 for (i
= 0; i
< n
; i
++) {
2538 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2544 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2548 for (i
= 0; i
< n
; i
++) {
2549 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2555 unpack_int_rgba_LUMINANCE_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2559 for (i
= 0; i
< n
; i
++) {
2560 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2567 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2571 for (i
= 0; i
< n
; i
++) {
2572 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2573 dst
[i
][3] = src
[i
* 2 + 1];
2578 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2582 for (i
= 0; i
< n
; i
++) {
2583 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2584 dst
[i
][3] = src
[i
* 2 + 1];
2589 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2593 for (i
= 0; i
< n
; i
++) {
2594 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2595 dst
[i
][3] = src
[i
* 2 + 1];
2600 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2604 for (i
= 0; i
< n
; i
++) {
2605 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2606 dst
[i
][3] = src
[i
* 2 + 1];
2611 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2615 for (i
= 0; i
< n
; i
++) {
2616 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2617 dst
[i
][3] = src
[i
* 2 + 1];
2622 unpack_int_rgba_INTENSITY_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2626 for (i
= 0; i
< n
; i
++) {
2627 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2632 unpack_int_rgba_INTENSITY_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2636 for (i
= 0; i
< n
; i
++) {
2637 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2642 unpack_int_rgba_INTENSITY_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2646 for (i
= 0; i
< n
; i
++) {
2647 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2652 unpack_int_rgba_INTENSITY_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2656 for (i
= 0; i
< n
; i
++) {
2657 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2662 unpack_int_rgba_INTENSITY_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2666 for (i
= 0; i
< n
; i
++) {
2667 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2672 unpack_int_rgba_ARGB2101010_UINT(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2676 for (i
= 0; i
< n
; i
++) {
2677 GLuint tmp
= src
[i
];
2678 dst
[i
][0] = (tmp
>> 20) & 0x3ff;
2679 dst
[i
][1] = (tmp
>> 10) & 0x3ff;
2680 dst
[i
][2] = (tmp
>> 0) & 0x3ff;
2681 dst
[i
][3] = (tmp
>> 30) & 0x3;
2686 unpack_int_rgba_ABGR2101010_UINT(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2690 for (i
= 0; i
< n
; i
++) {
2691 GLuint tmp
= src
[i
];
2692 dst
[i
][0] = (tmp
>> 0) & 0x3ff;
2693 dst
[i
][1] = (tmp
>> 10) & 0x3ff;
2694 dst
[i
][2] = (tmp
>> 20) & 0x3ff;
2695 dst
[i
][3] = (tmp
>> 30) & 0x3;
2700 unpack_int_rgba_ARGB2101010(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2704 for (i
= 0; i
< n
; i
++) {
2705 GLuint tmp
= src
[i
];
2706 dst
[i
][0] = (tmp
>> 20) & 0x3ff;
2707 dst
[i
][1] = (tmp
>> 10) & 0x3ff;
2708 dst
[i
][2] = (tmp
>> 0) & 0x3ff;
2709 dst
[i
][3] = (tmp
>> 30) & 0x3;
2714 _mesa_unpack_uint_rgba_row(gl_format format
, GLuint n
,
2715 const void *src
, GLuint dst
[][4])
2718 /* Since there won't be any sign extension happening, there's no need to
2719 * make separate paths for 32-bit-to-32-bit integer unpack.
2721 case MESA_FORMAT_RGBA_UINT32
:
2722 case MESA_FORMAT_RGBA_INT32
:
2723 unpack_int_rgba_RGBA_UINT32(src
, dst
, n
);
2726 case MESA_FORMAT_RGBA_UINT16
:
2727 unpack_int_rgba_RGBA_UINT16(src
, dst
, n
);
2729 case MESA_FORMAT_RGBA_INT16
:
2730 unpack_int_rgba_RGBA_INT16(src
, dst
, n
);
2733 case MESA_FORMAT_RGBA_UINT8
:
2734 unpack_int_rgba_RGBA_UINT8(src
, dst
, n
);
2736 case MESA_FORMAT_RGBA_INT8
:
2737 unpack_int_rgba_RGBA_INT8(src
, dst
, n
);
2740 case MESA_FORMAT_ARGB8888
:
2741 unpack_int_rgba_ARGB8888(src
, dst
, n
);
2744 case MESA_FORMAT_XRGB8888
:
2745 unpack_int_rgba_XRGB8888(src
, dst
, n
);
2748 case MESA_FORMAT_RGB_UINT32
:
2749 case MESA_FORMAT_RGB_INT32
:
2750 unpack_int_rgba_RGB_UINT32(src
, dst
, n
);
2753 case MESA_FORMAT_RGB_UINT16
:
2754 unpack_int_rgba_RGB_UINT16(src
, dst
, n
);
2756 case MESA_FORMAT_RGB_INT16
:
2757 unpack_int_rgba_RGB_INT16(src
, dst
, n
);
2760 case MESA_FORMAT_RGB_UINT8
:
2761 unpack_int_rgba_RGB_UINT8(src
, dst
, n
);
2763 case MESA_FORMAT_RGB_INT8
:
2764 unpack_int_rgba_RGB_INT8(src
, dst
, n
);
2767 case MESA_FORMAT_RG_UINT32
:
2768 case MESA_FORMAT_RG_INT32
:
2769 unpack_int_rgba_RG_UINT32(src
, dst
, n
);
2772 case MESA_FORMAT_RG_UINT16
:
2773 unpack_int_rgba_RG_UINT16(src
, dst
, n
);
2775 case MESA_FORMAT_RG_INT16
:
2776 unpack_int_rgba_RG_INT16(src
, dst
, n
);
2779 case MESA_FORMAT_RG_UINT8
:
2780 unpack_int_rgba_RG_UINT8(src
, dst
, n
);
2782 case MESA_FORMAT_RG_INT8
:
2783 unpack_int_rgba_RG_INT8(src
, dst
, n
);
2786 case MESA_FORMAT_R_UINT32
:
2787 case MESA_FORMAT_R_INT32
:
2788 unpack_int_rgba_R_UINT32(src
, dst
, n
);
2791 case MESA_FORMAT_R_UINT16
:
2792 unpack_int_rgba_R_UINT16(src
, dst
, n
);
2794 case MESA_FORMAT_R_INT16
:
2795 unpack_int_rgba_R_INT16(src
, dst
, n
);
2798 case MESA_FORMAT_R_UINT8
:
2799 unpack_int_rgba_R_UINT8(src
, dst
, n
);
2801 case MESA_FORMAT_R_INT8
:
2802 unpack_int_rgba_R_INT8(src
, dst
, n
);
2805 case MESA_FORMAT_ALPHA_UINT32
:
2806 case MESA_FORMAT_ALPHA_INT32
:
2807 unpack_int_rgba_ALPHA_UINT32(src
, dst
, n
);
2810 case MESA_FORMAT_ALPHA_UINT16
:
2811 unpack_int_rgba_ALPHA_UINT16(src
, dst
, n
);
2813 case MESA_FORMAT_ALPHA_INT16
:
2814 unpack_int_rgba_ALPHA_INT16(src
, dst
, n
);
2817 case MESA_FORMAT_ALPHA_UINT8
:
2818 unpack_int_rgba_ALPHA_UINT8(src
, dst
, n
);
2820 case MESA_FORMAT_ALPHA_INT8
:
2821 unpack_int_rgba_ALPHA_INT8(src
, dst
, n
);
2824 case MESA_FORMAT_LUMINANCE_UINT32
:
2825 case MESA_FORMAT_LUMINANCE_INT32
:
2826 unpack_int_rgba_LUMINANCE_UINT32(src
, dst
, n
);
2828 case MESA_FORMAT_LUMINANCE_UINT16
:
2829 unpack_int_rgba_LUMINANCE_UINT16(src
, dst
, n
);
2831 case MESA_FORMAT_LUMINANCE_INT16
:
2832 unpack_int_rgba_LUMINANCE_INT16(src
, dst
, n
);
2835 case MESA_FORMAT_LUMINANCE_UINT8
:
2836 unpack_int_rgba_LUMINANCE_UINT8(src
, dst
, n
);
2838 case MESA_FORMAT_LUMINANCE_INT8
:
2839 unpack_int_rgba_LUMINANCE_INT8(src
, dst
, n
);
2842 case MESA_FORMAT_LUMINANCE_ALPHA_UINT32
:
2843 case MESA_FORMAT_LUMINANCE_ALPHA_INT32
:
2844 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src
, dst
, n
);
2847 case MESA_FORMAT_LUMINANCE_ALPHA_UINT16
:
2848 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src
, dst
, n
);
2850 case MESA_FORMAT_LUMINANCE_ALPHA_INT16
:
2851 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src
, dst
, n
);
2854 case MESA_FORMAT_LUMINANCE_ALPHA_UINT8
:
2855 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src
, dst
, n
);
2857 case MESA_FORMAT_LUMINANCE_ALPHA_INT8
:
2858 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src
, dst
, n
);
2861 case MESA_FORMAT_INTENSITY_UINT32
:
2862 case MESA_FORMAT_INTENSITY_INT32
:
2863 unpack_int_rgba_INTENSITY_UINT32(src
, dst
, n
);
2866 case MESA_FORMAT_INTENSITY_UINT16
:
2867 unpack_int_rgba_INTENSITY_UINT16(src
, dst
, n
);
2869 case MESA_FORMAT_INTENSITY_INT16
:
2870 unpack_int_rgba_INTENSITY_INT16(src
, dst
, n
);
2873 case MESA_FORMAT_INTENSITY_UINT8
:
2874 unpack_int_rgba_INTENSITY_UINT8(src
, dst
, n
);
2876 case MESA_FORMAT_INTENSITY_INT8
:
2877 unpack_int_rgba_INTENSITY_INT8(src
, dst
, n
);
2880 case MESA_FORMAT_ARGB2101010_UINT
:
2881 unpack_int_rgba_ARGB2101010_UINT(src
, dst
, n
);
2884 case MESA_FORMAT_ABGR2101010_UINT
:
2885 unpack_int_rgba_ABGR2101010_UINT(src
, dst
, n
);
2888 case MESA_FORMAT_ARGB2101010
:
2889 unpack_int_rgba_ARGB2101010(src
, dst
, n
);
2893 _mesa_problem(NULL
, "%s: bad format %s", __FUNCTION__
,
2894 _mesa_get_format_name(format
));
2900 * Unpack a 2D rect of pixels returning float RGBA colors.
2901 * \param format the source image format
2902 * \param src start address of the source image
2903 * \param srcRowStride source image row stride in bytes
2904 * \param dst start address of the dest image
2905 * \param dstRowStride dest image row stride in bytes
2906 * \param x source image start X pos
2907 * \param y source image start Y pos
2908 * \param width width of rect region to convert
2909 * \param height height of rect region to convert
2912 _mesa_unpack_rgba_block(gl_format format
,
2913 const void *src
, GLint srcRowStride
,
2914 GLfloat dst
[][4], GLint dstRowStride
,
2915 GLuint x
, GLuint y
, GLuint width
, GLuint height
)
2917 unpack_rgba_func unpack
= get_unpack_rgba_function(format
);
2918 const GLuint srcPixStride
= _mesa_get_format_bytes(format
);
2919 const GLuint dstPixStride
= 4 * sizeof(GLfloat
);
2920 const GLubyte
*srcRow
;
2924 /* XXX needs to be fixed for compressed formats */
2926 srcRow
= ((const GLubyte
*) src
) + srcRowStride
* y
+ srcPixStride
* x
;
2927 dstRow
= ((GLubyte
*) dst
) + dstRowStride
* y
+ dstPixStride
* x
;
2929 for (i
= 0; i
< height
; i
++) {
2930 unpack(srcRow
, (GLfloat (*)[4]) dstRow
, width
);
2932 dstRow
+= dstRowStride
;
2933 srcRow
+= srcRowStride
;
2940 typedef void (*unpack_float_z_func
)(GLuint n
, const void *src
, GLfloat
*dst
);
2943 unpack_float_z_Z24_X8(GLuint n
, const void *src
, GLfloat
*dst
)
2945 /* only return Z, not stencil data */
2946 const GLuint
*s
= ((const GLuint
*) src
);
2947 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2949 for (i
= 0; i
< n
; i
++) {
2950 dst
[i
] = (GLfloat
) ((s
[i
] >> 8) * scale
);
2951 ASSERT(dst
[i
] >= 0.0F
);
2952 ASSERT(dst
[i
] <= 1.0F
);
2957 unpack_float_z_X8_Z24(GLuint n
, const void *src
, GLfloat
*dst
)
2959 /* only return Z, not stencil data */
2960 const GLuint
*s
= ((const GLuint
*) src
);
2961 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2963 for (i
= 0; i
< n
; i
++) {
2964 dst
[i
] = (GLfloat
) ((s
[i
] & 0x00ffffff) * scale
);
2965 ASSERT(dst
[i
] >= 0.0F
);
2966 ASSERT(dst
[i
] <= 1.0F
);
2971 unpack_float_z_Z16(GLuint n
, const void *src
, GLfloat
*dst
)
2973 const GLushort
*s
= ((const GLushort
*) src
);
2975 for (i
= 0; i
< n
; i
++) {
2976 dst
[i
] = s
[i
] * (1.0F
/ 65535.0F
);
2981 unpack_float_z_Z32(GLuint n
, const void *src
, GLfloat
*dst
)
2983 const GLuint
*s
= ((const GLuint
*) src
);
2985 for (i
= 0; i
< n
; i
++) {
2986 dst
[i
] = s
[i
] * (1.0F
/ 0xffffffff);
2991 unpack_float_z_Z32F(GLuint n
, const void *src
, GLfloat
*dst
)
2993 memcpy(dst
, src
, n
* sizeof(float));
2997 unpack_float_z_Z32X24S8(GLuint n
, const void *src
, GLfloat
*dst
)
2999 const struct z32f_x24s8
*s
= (const struct z32f_x24s8
*) src
;
3001 for (i
= 0; i
< n
; i
++) {
3010 * The returned values will always be in the range [0.0, 1.0].
3013 _mesa_unpack_float_z_row(gl_format format
, GLuint n
,
3014 const void *src
, GLfloat
*dst
)
3016 unpack_float_z_func unpack
;
3019 case MESA_FORMAT_Z24_S8
:
3020 case MESA_FORMAT_Z24_X8
:
3021 unpack
= unpack_float_z_Z24_X8
;
3023 case MESA_FORMAT_S8_Z24
:
3024 case MESA_FORMAT_X8_Z24
:
3025 unpack
= unpack_float_z_X8_Z24
;
3027 case MESA_FORMAT_Z16
:
3028 unpack
= unpack_float_z_Z16
;
3030 case MESA_FORMAT_Z32
:
3031 unpack
= unpack_float_z_Z32
;
3033 case MESA_FORMAT_Z32_FLOAT
:
3034 unpack
= unpack_float_z_Z32F
;
3036 case MESA_FORMAT_Z32_FLOAT_X24S8
:
3037 unpack
= unpack_float_z_Z32X24S8
;
3040 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_float_z_row",
3041 _mesa_get_format_name(format
));
3045 unpack(n
, src
, dst
);
3050 typedef void (*unpack_uint_z_func
)(const void *src
, GLuint
*dst
, GLuint n
);
3053 unpack_uint_z_Z24_X8(const void *src
, GLuint
*dst
, GLuint n
)
3055 /* only return Z, not stencil data */
3056 const GLuint
*s
= ((const GLuint
*) src
);
3058 for (i
= 0; i
< n
; i
++) {
3059 dst
[i
] = (s
[i
] & 0xffffff00) | (s
[i
] >> 24);
3064 unpack_uint_z_X8_Z24(const void *src
, GLuint
*dst
, GLuint n
)
3066 /* only return Z, not stencil data */
3067 const GLuint
*s
= ((const GLuint
*) src
);
3069 for (i
= 0; i
< n
; i
++) {
3070 dst
[i
] = (s
[i
] << 8) | ((s
[i
] >> 16) & 0xff);
3075 unpack_uint_z_Z16(const void *src
, GLuint
*dst
, GLuint n
)
3077 const GLushort
*s
= ((const GLushort
*)src
);
3079 for (i
= 0; i
< n
; i
++) {
3080 dst
[i
] = (s
[i
] << 16) | s
[i
];
3085 unpack_uint_z_Z32(const void *src
, GLuint
*dst
, GLuint n
)
3087 memcpy(dst
, src
, n
* sizeof(GLuint
));
3091 unpack_uint_z_Z32_FLOAT(const void *src
, GLuint
*dst
, GLuint n
)
3093 const float *s
= (const float *)src
;
3095 for (i
= 0; i
< n
; i
++) {
3096 dst
[i
] = FLOAT_TO_UINT(CLAMP(s
[i
], 0.0F
, 1.0F
));
3101 unpack_uint_z_Z32_FLOAT_X24S8(const void *src
, GLuint
*dst
, GLuint n
)
3103 const struct z32f_x24s8
*s
= (const struct z32f_x24s8
*) src
;
3106 for (i
= 0; i
< n
; i
++) {
3107 dst
[i
] = FLOAT_TO_UINT(CLAMP(s
[i
].z
, 0.0F
, 1.0F
));
3114 * The returned values will always be in the range [0, 0xffffffff].
3117 _mesa_unpack_uint_z_row(gl_format format
, GLuint n
,
3118 const void *src
, GLuint
*dst
)
3120 unpack_uint_z_func unpack
;
3121 const GLubyte
*srcPtr
= (GLubyte
*) src
;
3124 case MESA_FORMAT_Z24_S8
:
3125 case MESA_FORMAT_Z24_X8
:
3126 unpack
= unpack_uint_z_Z24_X8
;
3128 case MESA_FORMAT_S8_Z24
:
3129 case MESA_FORMAT_X8_Z24
:
3130 unpack
= unpack_uint_z_X8_Z24
;
3132 case MESA_FORMAT_Z16
:
3133 unpack
= unpack_uint_z_Z16
;
3135 case MESA_FORMAT_Z32
:
3136 unpack
= unpack_uint_z_Z32
;
3138 case MESA_FORMAT_Z32_FLOAT
:
3139 unpack
= unpack_uint_z_Z32_FLOAT
;
3141 case MESA_FORMAT_Z32_FLOAT_X24S8
:
3142 unpack
= unpack_uint_z_Z32_FLOAT_X24S8
;
3145 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_uint_z_row",
3146 _mesa_get_format_name(format
));
3150 unpack(srcPtr
, dst
, n
);
3155 unpack_ubyte_s_S8(const void *src
, GLubyte
*dst
, GLuint n
)
3157 memcpy(dst
, src
, n
);
3161 unpack_ubyte_s_Z24_S8(const void *src
, GLubyte
*dst
, GLuint n
)
3164 const GLuint
*src32
= src
;
3166 for (i
= 0; i
< n
; i
++)
3167 dst
[i
] = src32
[i
] & 0xff;
3171 unpack_ubyte_s_S8_Z24(const void *src
, GLubyte
*dst
, GLuint n
)
3174 const GLuint
*src32
= src
;
3176 for (i
= 0; i
< n
; i
++)
3177 dst
[i
] = src32
[i
] >> 24;
3181 unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src
, GLubyte
*dst
, GLuint n
)
3184 const struct z32f_x24s8
*s
= (const struct z32f_x24s8
*) src
;
3186 for (i
= 0; i
< n
; i
++)
3187 dst
[i
] = s
[i
].x24s8
& 0xff;
3191 _mesa_unpack_ubyte_stencil_row(gl_format format
, GLuint n
,
3192 const void *src
, GLubyte
*dst
)
3195 case MESA_FORMAT_S8
:
3196 unpack_ubyte_s_S8(src
, dst
, n
);
3198 case MESA_FORMAT_Z24_S8
:
3199 unpack_ubyte_s_Z24_S8(src
, dst
, n
);
3201 case MESA_FORMAT_S8_Z24
:
3202 unpack_ubyte_s_S8_Z24(src
, dst
, n
);
3204 case MESA_FORMAT_Z32_FLOAT_X24S8
:
3205 unpack_ubyte_s_Z32_FLOAT_X24S8(src
, dst
, n
);
3208 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_ubyte_s_row",
3209 _mesa_get_format_name(format
));
3215 unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint
*src
, GLuint
*dst
, GLuint n
)
3219 for (i
= 0; i
< n
; i
++) {
3220 GLuint val
= src
[i
];
3221 dst
[i
] = val
>> 24 | val
<< 8;
3226 unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint
*src
, GLuint
*dst
, GLuint n
)
3228 memcpy(dst
, src
, n
* 4);
3232 _mesa_unpack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
3233 const void *src
, GLuint
*dst
)
3236 case MESA_FORMAT_Z24_S8
:
3237 unpack_uint_24_8_depth_stencil_Z24_S8(src
, dst
, n
);
3239 case MESA_FORMAT_S8_Z24
:
3240 unpack_uint_24_8_depth_stencil_S8_Z24(src
, dst
, n
);
3244 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
3245 _mesa_get_format_name(format
));