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"
31 /* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
33 #define EXPAND_1_8(X) ( (X) ? 0xff : 0x0 )
35 #define EXPAND_2_8(X) ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
37 #define EXPAND_3_8(X) ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
39 #define EXPAND_4_8(X) ( ((X) << 4) | (X) )
41 #define EXPAND_5_8(X) ( ((X) << 3) | ((X) >> 2) )
43 #define EXPAND_6_8(X) ( ((X) << 2) | ((X) >> 4) )
47 * Convert an 8-bit sRGB value from non-linear space to a
48 * linear RGB value in [0, 1].
49 * Implemented with a 256-entry lookup table.
52 nonlinear_to_linear(GLubyte cs8
)
54 static GLfloat table
[256];
55 static GLboolean tableReady
= GL_FALSE
;
57 /* compute lookup table now */
59 for (i
= 0; i
< 256; i
++) {
60 const GLfloat cs
= UBYTE_TO_FLOAT(i
);
62 table
[i
] = cs
/ 12.92f
;
65 table
[i
] = (GLfloat
) pow((cs
+ 0.055) / 1.055, 2.4);
74 /**********************************************************************/
75 /* Unpack, returning GLfloat colors */
76 /**********************************************************************/
78 typedef void (*unpack_rgba_func
)(const void *src
, GLfloat dst
[][4], GLuint n
);
82 unpack_RGBA8888(const void *src
, GLfloat dst
[][4], GLuint n
)
84 const GLuint
*s
= ((const GLuint
*) src
);
86 for (i
= 0; i
< n
; i
++) {
87 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
88 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
89 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
90 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
95 unpack_RGBA8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
97 const GLuint
*s
= ((const GLuint
*) src
);
99 for (i
= 0; i
< n
; i
++) {
100 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
101 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
102 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
103 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
108 unpack_ARGB8888(const void *src
, GLfloat dst
[][4], GLuint n
)
110 const GLuint
*s
= ((const GLuint
*) src
);
112 for (i
= 0; i
< n
; i
++) {
113 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
114 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
115 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
116 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
121 unpack_ARGB8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
123 const GLuint
*s
= ((const GLuint
*) src
);
125 for (i
= 0; i
< n
; i
++) {
126 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
127 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
128 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
129 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
134 unpack_RGBX8888(const void *src
, GLfloat dst
[][4], GLuint n
)
136 const GLuint
*s
= ((const GLuint
*) src
);
138 for (i
= 0; i
< n
; i
++) {
139 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
140 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
141 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
142 dst
[i
][ACOMP
] = 1.0f
;
147 unpack_RGBX8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
149 const GLuint
*s
= ((const GLuint
*) src
);
151 for (i
= 0; i
< n
; i
++) {
152 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
153 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
154 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
155 dst
[i
][ACOMP
] = 1.0f
;
160 unpack_XRGB8888(const void *src
, GLfloat dst
[][4], GLuint n
)
162 const GLuint
*s
= ((const GLuint
*) src
);
164 for (i
= 0; i
< n
; i
++) {
165 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
166 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
167 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
168 dst
[i
][ACOMP
] = 1.0f
;
173 unpack_XRGB8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
175 const GLuint
*s
= ((const GLuint
*) src
);
177 for (i
= 0; i
< n
; i
++) {
178 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
179 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
180 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
181 dst
[i
][ACOMP
] = 1.0f
;
186 unpack_RGB888(const void *src
, GLfloat dst
[][4], GLuint n
)
188 const GLubyte
*s
= (const GLubyte
*) src
;
190 for (i
= 0; i
< n
; i
++) {
191 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+2] );
192 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+1] );
193 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+0] );
194 dst
[i
][ACOMP
] = 1.0F
;
199 unpack_BGR888(const void *src
, GLfloat dst
[][4], GLuint n
)
201 const GLubyte
*s
= (const GLubyte
*) src
;
203 for (i
= 0; i
< n
; i
++) {
204 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+0] );
205 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+1] );
206 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+2] );
207 dst
[i
][ACOMP
] = 1.0F
;
212 unpack_RGB565(const void *src
, GLfloat dst
[][4], GLuint n
)
214 const GLushort
*s
= ((const GLushort
*) src
);
216 for (i
= 0; i
< n
; i
++) {
217 dst
[i
][RCOMP
] = ((s
[i
] >> 11) & 0x1f) * (1.0F
/ 31.0F
);
218 dst
[i
][GCOMP
] = ((s
[i
] >> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
219 dst
[i
][BCOMP
] = ((s
[i
] ) & 0x1f) * (1.0F
/ 31.0F
);
220 dst
[i
][ACOMP
] = 1.0F
;
225 unpack_RGB565_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
227 const GLushort
*s
= ((const GLushort
*) src
);
229 for (i
= 0; i
< n
; i
++) {
230 GLuint t
= (s
[i
] >> 8) | (s
[i
] << 8); /* byte swap */
231 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( ((t
>> 8) & 0xf8) | ((t
>> 13) & 0x7) );
232 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( ((t
>> 3) & 0xfc) | ((t
>> 9) & 0x3) );
233 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( ((t
<< 3) & 0xf8) | ((t
>> 2) & 0x7) );
234 dst
[i
][ACOMP
] = 1.0F
;
239 unpack_ARGB4444(const void *src
, GLfloat dst
[][4], GLuint n
)
241 const GLushort
*s
= ((const GLushort
*) src
);
243 for (i
= 0; i
< n
; i
++) {
244 dst
[i
][RCOMP
] = ((s
[i
] >> 8) & 0xf) * (1.0F
/ 15.0F
);
245 dst
[i
][GCOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
246 dst
[i
][BCOMP
] = ((s
[i
] ) & 0xf) * (1.0F
/ 15.0F
);
247 dst
[i
][ACOMP
] = ((s
[i
] >> 12) & 0xf) * (1.0F
/ 15.0F
);
252 unpack_ARGB4444_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
254 const GLushort
*s
= ((const GLushort
*) src
);
256 for (i
= 0; i
< n
; i
++) {
257 dst
[i
][RCOMP
] = ((s
[i
] ) & 0xf) * (1.0F
/ 15.0F
);
258 dst
[i
][GCOMP
] = ((s
[i
] >> 12) & 0xf) * (1.0F
/ 15.0F
);
259 dst
[i
][BCOMP
] = ((s
[i
] >> 8) & 0xf) * (1.0F
/ 15.0F
);
260 dst
[i
][ACOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
265 unpack_RGBA5551(const void *src
, GLfloat dst
[][4], GLuint n
)
267 const GLushort
*s
= ((const GLushort
*) src
);
269 for (i
= 0; i
< n
; i
++) {
270 dst
[i
][RCOMP
] = ((s
[i
] >> 11) & 0x1f) * (1.0F
/ 31.0F
);
271 dst
[i
][GCOMP
] = ((s
[i
] >> 6) & 0x1f) * (1.0F
/ 31.0F
);
272 dst
[i
][BCOMP
] = ((s
[i
] >> 1) & 0x1f) * (1.0F
/ 31.0F
);
273 dst
[i
][ACOMP
] = ((s
[i
] ) & 0x01) * 1.0F
;
278 unpack_ARGB1555(const void *src
, GLfloat dst
[][4], GLuint n
)
280 const GLushort
*s
= ((const GLushort
*) src
);
282 for (i
= 0; i
< n
; i
++) {
283 dst
[i
][RCOMP
] = ((s
[i
] >> 10) & 0x1f) * (1.0F
/ 31.0F
);
284 dst
[i
][GCOMP
] = ((s
[i
] >> 5) & 0x1f) * (1.0F
/ 31.0F
);
285 dst
[i
][BCOMP
] = ((s
[i
] >> 0) & 0x1f) * (1.0F
/ 31.0F
);
286 dst
[i
][ACOMP
] = ((s
[i
] >> 15) & 0x01) * 1.0F
;
291 unpack_ARGB1555_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
293 const GLushort
*s
= ((const GLushort
*) src
);
295 for (i
= 0; i
< n
; i
++) {
296 GLushort tmp
= (s
[i
] << 8) | (s
[i
] >> 8); /* byteswap */
297 dst
[i
][RCOMP
] = ((tmp
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
298 dst
[i
][GCOMP
] = ((tmp
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
299 dst
[i
][BCOMP
] = ((tmp
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
300 dst
[i
][ACOMP
] = ((tmp
>> 15) & 0x01) * 1.0F
;
305 unpack_AL44(const void *src
, GLfloat dst
[][4], GLuint n
)
307 const GLubyte
*s
= ((const GLubyte
*) src
);
309 for (i
= 0; i
< n
; i
++) {
312 dst
[i
][BCOMP
] = (s
[i
] & 0xf) * (1.0F
/ 15.0F
);
313 dst
[i
][ACOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
318 unpack_AL88(const void *src
, GLfloat dst
[][4], GLuint n
)
320 const GLushort
*s
= ((const GLushort
*) src
);
322 for (i
= 0; i
< n
; i
++) {
325 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
326 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
331 unpack_AL88_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
333 const GLushort
*s
= ((const GLushort
*) src
);
335 for (i
= 0; i
< n
; i
++) {
338 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
339 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
344 unpack_AL1616(const void *src
, GLfloat dst
[][4], GLuint n
)
346 const GLuint
*s
= ((const GLuint
*) src
);
348 for (i
= 0; i
< n
; i
++) {
351 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
352 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
357 unpack_AL1616_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
359 const GLuint
*s
= ((const GLuint
*) src
);
361 for (i
= 0; i
< n
; i
++) {
364 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
365 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
370 unpack_RGB332(const void *src
, GLfloat dst
[][4], GLuint n
)
372 const GLubyte
*s
= ((const GLubyte
*) src
);
374 for (i
= 0; i
< n
; i
++) {
375 dst
[i
][RCOMP
] = ((s
[i
] >> 5) & 0x7) * (1.0F
/ 7.0F
);
376 dst
[i
][GCOMP
] = ((s
[i
] >> 2) & 0x7) * (1.0F
/ 7.0F
);
377 dst
[i
][BCOMP
] = ((s
[i
] ) & 0x3) * (1.0F
/ 3.0F
);
378 dst
[i
][ACOMP
] = 1.0F
;
384 unpack_A8(const void *src
, GLfloat dst
[][4], GLuint n
)
386 const GLubyte
*s
= ((const GLubyte
*) src
);
388 for (i
= 0; i
< n
; i
++) {
391 dst
[i
][BCOMP
] = 0.0F
;
392 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
]);
397 unpack_A16(const void *src
, GLfloat dst
[][4], GLuint n
)
399 const GLushort
*s
= ((const GLushort
*) src
);
401 for (i
= 0; i
< n
; i
++) {
404 dst
[i
][BCOMP
] = 0.0F
;
405 dst
[i
][ACOMP
] = USHORT_TO_FLOAT(s
[i
]);
410 unpack_L8(const void *src
, GLfloat dst
[][4], GLuint n
)
412 const GLubyte
*s
= ((const GLubyte
*) src
);
414 for (i
= 0; i
< n
; i
++) {
417 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT(s
[i
]);
418 dst
[i
][ACOMP
] = 1.0F
;
423 unpack_L16(const void *src
, GLfloat dst
[][4], GLuint n
)
425 const GLushort
*s
= ((const GLushort
*) src
);
427 for (i
= 0; i
< n
; i
++) {
430 dst
[i
][BCOMP
] = USHORT_TO_FLOAT(s
[i
]);
431 dst
[i
][ACOMP
] = 1.0F
;
436 unpack_I8(const void *src
, GLfloat dst
[][4], GLuint n
)
438 const GLubyte
*s
= ((const GLubyte
*) src
);
440 for (i
= 0; i
< n
; i
++) {
444 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
]);
449 unpack_I16(const void *src
, GLfloat dst
[][4], GLuint n
)
451 const GLushort
*s
= ((const GLushort
*) src
);
453 for (i
= 0; i
< n
; i
++) {
457 dst
[i
][ACOMP
] = USHORT_TO_FLOAT(s
[i
]);
462 unpack_YCBCR(const void *src
, GLfloat dst
[][4], GLuint n
)
465 for (i
= 0; i
< n
; i
++) {
466 const GLushort
*src0
= ((const GLushort
*) src
) + i
* 2; /* even */
467 const GLushort
*src1
= src0
+ 1; /* odd */
468 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
469 const GLubyte cb
= *src0
& 0xff; /* chroma U */
470 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
471 const GLubyte cr
= *src1
& 0xff; /* chroma V */
472 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
473 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
474 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
475 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
476 r
*= (1.0F
/ 255.0F
);
477 g
*= (1.0F
/ 255.0F
);
478 b
*= (1.0F
/ 255.0F
);
479 dst
[i
][RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
480 dst
[i
][GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
481 dst
[i
][BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
482 dst
[i
][ACOMP
] = 1.0F
;
487 unpack_YCBCR_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
490 for (i
= 0; i
< n
; i
++) {
491 const GLushort
*src0
= ((const GLushort
*) src
) + i
* 2; /* even */
492 const GLushort
*src1
= src0
+ 1; /* odd */
493 const GLubyte y0
= *src0
& 0xff; /* luminance */
494 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
495 const GLubyte y1
= *src1
& 0xff; /* luminance */
496 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
497 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
498 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
499 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
500 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
501 r
*= (1.0F
/ 255.0F
);
502 g
*= (1.0F
/ 255.0F
);
503 b
*= (1.0F
/ 255.0F
);
504 dst
[i
][RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
505 dst
[i
][GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
506 dst
[i
][BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
507 dst
[i
][ACOMP
] = 1.0F
;
512 unpack_R8(const void *src
, GLfloat dst
[][4], GLuint n
)
514 const GLubyte
*s
= ((const GLubyte
*) src
);
516 for (i
= 0; i
< n
; i
++) {
517 dst
[i
][0] = UBYTE_TO_FLOAT(s
[i
]);
525 unpack_GR88(const void *src
, GLfloat dst
[][4], GLuint n
)
527 const GLushort
*s
= ((const GLushort
*) src
);
529 for (i
= 0; i
< n
; i
++) {
530 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
531 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
538 unpack_RG88(const void *src
, GLfloat dst
[][4], GLuint n
)
540 const GLushort
*s
= ((const GLushort
*) src
);
542 for (i
= 0; i
< n
; i
++) {
543 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
544 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
551 unpack_R16(const void *src
, GLfloat dst
[][4], GLuint n
)
553 const GLushort
*s
= ((const GLushort
*) src
);
555 for (i
= 0; i
< n
; i
++) {
556 dst
[i
][RCOMP
] = USHORT_TO_FLOAT(s
[i
]);
564 unpack_RG1616(const void *src
, GLfloat dst
[][4], GLuint n
)
566 const GLuint
*s
= ((const GLuint
*) src
);
568 for (i
= 0; i
< n
; i
++) {
569 dst
[i
][RCOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
570 dst
[i
][GCOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
577 unpack_RG1616_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
579 const GLuint
*s
= ((const GLuint
*) src
);
581 for (i
= 0; i
< n
; i
++) {
582 dst
[i
][RCOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
583 dst
[i
][GCOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
590 unpack_ARGB2101010(const void *src
, GLfloat dst
[][4], GLuint n
)
592 const GLuint
*s
= ((const GLuint
*) src
);
594 for (i
= 0; i
< n
; i
++) {
595 dst
[i
][RCOMP
] = ((s
[i
] >> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
596 dst
[i
][GCOMP
] = ((s
[i
] >> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
597 dst
[i
][BCOMP
] = ((s
[i
] >> 0) & 0x3ff) * (1.0F
/ 1023.0F
);
598 dst
[i
][ACOMP
] = ((s
[i
] >> 30) & 0x03) * (1.0F
/ 3.0F
);
604 unpack_Z24_S8(const void *src
, GLfloat dst
[][4], GLuint n
)
606 /* only return Z, not stencil data */
607 const GLuint
*s
= ((const GLuint
*) src
);
608 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
610 for (i
= 0; i
< n
; i
++) {
613 dst
[i
][2] = (s
[i
] >> 8) * scale
;
615 ASSERT(dst
[i
][0] >= 0.0F
);
616 ASSERT(dst
[i
][0] <= 1.0F
);
621 unpack_S8_Z24(const void *src
, GLfloat dst
[][4], GLuint n
)
623 /* only return Z, not stencil data */
624 const GLuint
*s
= ((const GLuint
*) src
);
625 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
627 for (i
= 0; i
< n
; i
++) {
630 dst
[i
][2] = (s
[i
] & 0x00ffffff) * scale
;
632 ASSERT(dst
[i
][0] >= 0.0F
);
633 ASSERT(dst
[i
][0] <= 1.0F
);
638 unpack_Z16(const void *src
, GLfloat dst
[][4], GLuint n
)
640 const GLushort
*s
= ((const GLushort
*) src
);
642 for (i
= 0; i
< n
; i
++) {
645 dst
[i
][2] = s
[i
] * (1.0F
/ 65535.0F
);
651 unpack_X8_Z24(const void *src
, GLfloat dst
[][4], GLuint n
)
653 unpack_S8_Z24(src
, dst
, n
);
657 unpack_Z24_X8(const void *src
, GLfloat dst
[][4], GLuint n
)
659 unpack_Z24_S8(src
, dst
, n
);
663 unpack_Z32(const void *src
, GLfloat dst
[][4], GLuint n
)
665 const GLuint
*s
= ((const GLuint
*) src
);
667 for (i
= 0; i
< n
; i
++) {
670 dst
[i
][2] = s
[i
] * (1.0F
/ 0xffffffff);
676 unpack_Z32_FLOAT(const void *src
, GLfloat dst
[][4], GLuint n
)
678 const GLfloat
*s
= ((const GLfloat
*) src
);
680 for (i
= 0; i
< n
; i
++) {
683 dst
[i
][2] = s
[i
* 2];
689 unpack_Z32_FLOAT_X24S8(const void *src
, GLfloat dst
[][4], GLuint n
)
691 const GLfloat
*s
= ((const GLfloat
*) src
);
693 for (i
= 0; i
< n
; i
++) {
703 unpack_S8(const void *src
, GLfloat dst
[][4], GLuint n
)
705 /* should never be used */
707 for (i
= 0; i
< n
; i
++) {
717 unpack_SRGB8(const void *src
, GLfloat dst
[][4], GLuint n
)
719 const GLubyte
*s
= (const GLubyte
*) src
;
721 for (i
= 0; i
< n
; i
++) {
722 dst
[i
][RCOMP
] = nonlinear_to_linear(s
[i
*3+2]);
723 dst
[i
][GCOMP
] = nonlinear_to_linear(s
[i
*3+1]);
724 dst
[i
][BCOMP
] = nonlinear_to_linear(s
[i
*3+0]);
725 dst
[i
][ACOMP
] = 1.0F
;
730 unpack_SRGBA8(const void *src
, GLfloat dst
[][4], GLuint n
)
732 const GLuint
*s
= ((const GLuint
*) src
);
734 for (i
= 0; i
< n
; i
++) {
735 dst
[i
][RCOMP
] = nonlinear_to_linear( (s
[i
] >> 24) );
736 dst
[i
][GCOMP
] = nonlinear_to_linear( (s
[i
] >> 16) & 0xff );
737 dst
[i
][BCOMP
] = nonlinear_to_linear( (s
[i
] >> 8) & 0xff );
738 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff ); /* linear! */
743 unpack_SARGB8(const void *src
, GLfloat dst
[][4], GLuint n
)
745 const GLuint
*s
= ((const GLuint
*) src
);
747 for (i
= 0; i
< n
; i
++) {
748 dst
[i
][RCOMP
] = nonlinear_to_linear( (s
[i
] >> 16) & 0xff );
749 dst
[i
][GCOMP
] = nonlinear_to_linear( (s
[i
] >> 8) & 0xff );
750 dst
[i
][BCOMP
] = nonlinear_to_linear( (s
[i
] ) & 0xff );
751 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 24 ); /* linear! */
756 unpack_SL8(const void *src
, GLfloat dst
[][4], GLuint n
)
758 const GLubyte
*s
= ((const GLubyte
*) src
);
760 for (i
= 0; i
< n
; i
++) {
763 dst
[i
][BCOMP
] = nonlinear_to_linear(s
[i
]);
764 dst
[i
][ACOMP
] = 1.0F
;
769 unpack_SLA8(const void *src
, GLfloat dst
[][4], GLuint n
)
771 const GLushort
*s
= (const GLushort
*) src
;
773 for (i
= 0; i
< n
; i
++) {
776 dst
[i
][BCOMP
] = nonlinear_to_linear(s
[i
] & 0xff);
777 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
] >> 8); /* linear! */
782 unpack_SRGB_DXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
787 unpack_SRGBA_DXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
792 unpack_SRGBA_DXT3(const void *src
, GLfloat dst
[][4], GLuint n
)
797 unpack_SRGBA_DXT5(const void *src
, GLfloat dst
[][4], GLuint n
)
802 unpack_RGB_FXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
807 unpack_RGBA_FXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
812 unpack_RGB_DXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
817 unpack_RGBA_DXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
822 unpack_RGBA_DXT3(const void *src
, GLfloat dst
[][4], GLuint n
)
827 unpack_RGBA_DXT5(const void *src
, GLfloat dst
[][4], GLuint n
)
833 unpack_RGBA_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
835 const GLfloat
*s
= (const GLfloat
*) src
;
837 for (i
= 0; i
< n
; i
++) {
838 dst
[i
][RCOMP
] = s
[i
*4+0];
839 dst
[i
][GCOMP
] = s
[i
*4+1];
840 dst
[i
][BCOMP
] = s
[i
*4+2];
841 dst
[i
][ACOMP
] = s
[i
*4+3];
846 unpack_RGBA_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
848 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
850 for (i
= 0; i
< n
; i
++) {
851 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
*4+0]);
852 dst
[i
][GCOMP
] = _mesa_half_to_float(s
[i
*4+1]);
853 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
*4+2]);
854 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
*4+3]);
859 unpack_RGB_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
861 const GLfloat
*s
= (const GLfloat
*) src
;
863 for (i
= 0; i
< n
; i
++) {
864 dst
[i
][RCOMP
] = s
[i
*3+0];
865 dst
[i
][GCOMP
] = s
[i
*3+1];
866 dst
[i
][BCOMP
] = s
[i
*3+2];
867 dst
[i
][ACOMP
] = 1.0F
;
872 unpack_RGB_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
874 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
876 for (i
= 0; i
< n
; i
++) {
877 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
*3+0]);
878 dst
[i
][GCOMP
] = _mesa_half_to_float(s
[i
*3+1]);
879 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
*3+2]);
880 dst
[i
][ACOMP
] = 1.0F
;
885 unpack_ALPHA_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
887 const GLfloat
*s
= (const GLfloat
*) src
;
889 for (i
= 0; i
< n
; i
++) {
892 dst
[i
][BCOMP
] = 0.0F
;
893 dst
[i
][ACOMP
] = s
[i
];
898 unpack_ALPHA_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
900 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
902 for (i
= 0; i
< n
; i
++) {
905 dst
[i
][BCOMP
] = 0.0F
;
906 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
]);
911 unpack_LUMINANCE_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
913 const GLfloat
*s
= (const GLfloat
*) src
;
915 for (i
= 0; i
< n
; i
++) {
918 dst
[i
][BCOMP
] = s
[i
];
919 dst
[i
][ACOMP
] = 1.0F
;
924 unpack_LUMINANCE_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
926 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
928 for (i
= 0; i
< n
; i
++) {
931 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
]);
932 dst
[i
][ACOMP
] = 1.0F
;
937 unpack_LUMINANCE_ALPHA_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
939 const GLfloat
*s
= (const GLfloat
*) src
;
941 for (i
= 0; i
< n
; i
++) {
944 dst
[i
][BCOMP
] = s
[i
*2+0];
945 dst
[i
][ACOMP
] = s
[i
*2+1];
950 unpack_LUMINANCE_ALPHA_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
952 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
954 for (i
= 0; i
< n
; i
++) {
957 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
*2+0]);
958 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
*2+1]);
963 unpack_INTENSITY_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
965 const GLfloat
*s
= (const GLfloat
*) src
;
967 for (i
= 0; i
< n
; i
++) {
971 dst
[i
][ACOMP
] = s
[i
];
976 unpack_INTENSITY_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
978 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
980 for (i
= 0; i
< n
; i
++) {
984 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
]);
989 unpack_R_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
991 const GLfloat
*s
= (const GLfloat
*) src
;
993 for (i
= 0; i
< n
; i
++) {
994 dst
[i
][RCOMP
] = s
[i
];
995 dst
[i
][GCOMP
] = 0.0F
;
996 dst
[i
][BCOMP
] = 0.0F
;
997 dst
[i
][ACOMP
] = 1.0F
;
1002 unpack_R_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1004 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
1006 for (i
= 0; i
< n
; i
++) {
1007 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
]);
1008 dst
[i
][GCOMP
] = 0.0F
;
1009 dst
[i
][BCOMP
] = 0.0F
;
1010 dst
[i
][ACOMP
] = 1.0F
;
1015 unpack_RG_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
1017 const GLfloat
*s
= (const GLfloat
*) src
;
1019 for (i
= 0; i
< n
; i
++) {
1020 dst
[i
][RCOMP
] = s
[i
*2+0];
1021 dst
[i
][GCOMP
] = s
[i
*2+1];
1022 dst
[i
][BCOMP
] = 0.0F
;
1023 dst
[i
][ACOMP
] = 1.0F
;
1028 unpack_RG_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1030 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
1032 for (i
= 0; i
< n
; i
++) {
1033 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
*2+0]);
1034 dst
[i
][GCOMP
] = _mesa_half_to_float(s
[i
*2+1]);
1035 dst
[i
][BCOMP
] = 0.0F
;
1036 dst
[i
][ACOMP
] = 1.0F
;
1042 unpack_RGBA_INT8(const void *src
, GLfloat dst
[][4], GLuint n
)
1044 const GLbyte
*s
= (const GLbyte
*) src
;
1046 for (i
= 0; i
< n
; i
++) {
1047 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1048 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1049 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1050 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1055 unpack_RGBA_INT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1057 const GLshort
*s
= (const GLshort
*) src
;
1059 for (i
= 0; i
< n
; i
++) {
1060 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1061 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1062 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1063 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1068 unpack_RGBA_INT32(const void *src
, GLfloat dst
[][4], GLuint n
)
1070 const GLint
*s
= (const GLint
*) src
;
1072 for (i
= 0; i
< n
; i
++) {
1073 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1074 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1075 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1076 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1081 unpack_RGBA_UINT8(const void *src
, GLfloat dst
[][4], GLuint n
)
1083 const GLubyte
*s
= (const GLubyte
*) src
;
1085 for (i
= 0; i
< n
; i
++) {
1086 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1087 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1088 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1089 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1094 unpack_RGBA_UINT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1096 const GLushort
*s
= (const GLushort
*) src
;
1098 for (i
= 0; i
< n
; i
++) {
1099 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1100 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1101 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1102 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1107 unpack_RGBA_UINT32(const void *src
, GLfloat dst
[][4], GLuint n
)
1109 const GLuint
*s
= (const GLuint
*) src
;
1111 for (i
= 0; i
< n
; i
++) {
1112 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1113 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1114 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1115 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1120 unpack_DUDV8(const void *src
, GLfloat dst
[][4], GLuint n
)
1122 const GLbyte
*s
= (const GLbyte
*) src
;
1124 for (i
= 0; i
< n
; i
++) {
1125 dst
[i
][RCOMP
] = BYTE_TO_FLOAT(s
[i
*2+0]);
1126 dst
[i
][GCOMP
] = BYTE_TO_FLOAT(s
[i
*2+1]);
1133 unpack_SIGNED_R8(const void *src
, GLfloat dst
[][4], GLuint n
)
1135 const GLbyte
*s
= ((const GLbyte
*) src
);
1137 for (i
= 0; i
< n
; i
++) {
1138 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( s
[i
] );
1139 dst
[i
][GCOMP
] = 0.0F
;
1140 dst
[i
][BCOMP
] = 0.0F
;
1141 dst
[i
][ACOMP
] = 1.0F
;
1146 unpack_SIGNED_RG88_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
1148 const GLushort
*s
= ((const GLushort
*) src
);
1150 for (i
= 0; i
< n
; i
++) {
1151 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] & 0xff) );
1152 dst
[i
][GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1153 dst
[i
][BCOMP
] = 0.0F
;
1154 dst
[i
][ACOMP
] = 1.0F
;
1159 unpack_SIGNED_RGBX8888(const void *src
, GLfloat dst
[][4], GLuint n
)
1161 const GLuint
*s
= ((const GLuint
*) src
);
1163 for (i
= 0; i
< n
; i
++) {
1164 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 24) );
1165 dst
[i
][GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 16) );
1166 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1167 dst
[i
][ACOMP
] = 1.0f
;
1172 unpack_SIGNED_RGBA8888(const void *src
, GLfloat dst
[][4], GLuint n
)
1174 const GLuint
*s
= ((const GLuint
*) src
);
1176 for (i
= 0; i
< n
; i
++) {
1177 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 24) );
1178 dst
[i
][GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 16) );
1179 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1180 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] ) );
1185 unpack_SIGNED_RGBA8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
1187 const GLuint
*s
= ((const GLuint
*) src
);
1189 for (i
= 0; i
< n
; i
++) {
1190 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] ) );
1191 dst
[i
][GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1192 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 16) );
1193 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 24) );
1198 unpack_SIGNED_R16(const void *src
, GLfloat dst
[][4], GLuint n
)
1200 const GLshort
*s
= ((const GLshort
*) src
);
1202 for (i
= 0; i
< n
; i
++) {
1203 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
] );
1204 dst
[i
][GCOMP
] = 0.0F
;
1205 dst
[i
][BCOMP
] = 0.0F
;
1206 dst
[i
][ACOMP
] = 1.0F
;
1211 unpack_SIGNED_GR1616(const void *src
, GLfloat dst
[][4], GLuint n
)
1213 const GLuint
*s
= ((const GLuint
*) src
);
1215 for (i
= 0; i
< n
; i
++) {
1216 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( (GLshort
) (s
[i
] & 0xffff) );
1217 dst
[i
][GCOMP
] = SHORT_TO_FLOAT_TEX( (GLshort
) (s
[i
] >> 16) );
1218 dst
[i
][BCOMP
] = 0.0F
;
1219 dst
[i
][ACOMP
] = 1.0F
;
1224 unpack_SIGNED_RGB_16(const void *src
, GLfloat dst
[][4], GLuint n
)
1226 const GLshort
*s
= (const GLshort
*) src
;
1228 for (i
= 0; i
< n
; i
++) {
1229 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*3+0] );
1230 dst
[i
][GCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*3+1] );
1231 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*3+2] );
1232 dst
[i
][ACOMP
] = 1.0F
;
1237 unpack_SIGNED_RGBA_16(const void *src
, GLfloat dst
[][4], GLuint n
)
1239 const GLshort
*s
= (const GLshort
*) src
;
1241 for (i
= 0; i
< n
; i
++) {
1242 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+0] );
1243 dst
[i
][GCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+1] );
1244 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+2] );
1245 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+3] );
1250 unpack_RGBA_16(const void *src
, GLfloat dst
[][4], GLuint n
)
1252 const GLushort
*s
= (const GLushort
*) src
;
1254 for (i
= 0; i
< n
; i
++) {
1255 dst
[i
][RCOMP
] = USHORT_TO_FLOAT( s
[i
*4+0] );
1256 dst
[i
][GCOMP
] = USHORT_TO_FLOAT( s
[i
*4+1] );
1257 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
*4+2] );
1258 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
*4+3] );
1263 unpack_RED_RGTC1(const void *src
, GLfloat dst
[][4], GLuint n
)
1269 unpack_SIGNED_RED_RGTC1(const void *src
, GLfloat dst
[][4], GLuint n
)
1275 unpack_RG_RGTC2(const void *src
, GLfloat dst
[][4], GLuint n
)
1281 unpack_SIGNED_RG_RGTC2(const void *src
, GLfloat dst
[][4], GLuint n
)
1287 unpack_L_LATC1(const void *src
, GLfloat dst
[][4], GLuint n
)
1293 unpack_SIGNED_L_LATC1(const void *src
, GLfloat dst
[][4], GLuint n
)
1299 unpack_LA_LATC2(const void *src
, GLfloat dst
[][4], GLuint n
)
1305 unpack_SIGNED_LA_LATC2(const void *src
, GLfloat dst
[][4], GLuint n
)
1311 unpack_SIGNED_A8(const void *src
, GLfloat dst
[][4], GLuint n
)
1313 const GLbyte
*s
= ((const GLbyte
*) src
);
1315 for (i
= 0; i
< n
; i
++) {
1316 dst
[i
][RCOMP
] = 0.0F
;
1317 dst
[i
][GCOMP
] = 0.0F
;
1318 dst
[i
][BCOMP
] = 0.0F
;
1319 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( s
[i
] );
1324 unpack_SIGNED_L8(const void *src
, GLfloat dst
[][4], GLuint n
)
1326 const GLbyte
*s
= ((const GLbyte
*) src
);
1328 for (i
= 0; i
< n
; i
++) {
1331 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( s
[i
] );
1332 dst
[i
][ACOMP
] = 1.0F
;
1337 unpack_SIGNED_AL88(const void *src
, GLfloat dst
[][4], GLuint n
)
1339 const GLshort
*s
= ((const GLshort
*) src
);
1341 for (i
= 0; i
< n
; i
++) {
1344 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] & 0xff) );
1345 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1350 unpack_SIGNED_I8(const void *src
, GLfloat dst
[][4], GLuint n
)
1352 const GLbyte
*s
= ((const GLbyte
*) src
);
1354 for (i
= 0; i
< n
; i
++) {
1358 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( s
[i
] );
1363 unpack_SIGNED_A16(const void *src
, GLfloat dst
[][4], GLuint n
)
1365 const GLshort
*s
= ((const GLshort
*) src
);
1367 for (i
= 0; i
< n
; i
++) {
1368 dst
[i
][RCOMP
] = 0.0F
;
1369 dst
[i
][GCOMP
] = 0.0F
;
1370 dst
[i
][BCOMP
] = 0.0F
;
1371 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
] );
1376 unpack_SIGNED_L16(const void *src
, GLfloat dst
[][4], GLuint n
)
1378 const GLshort
*s
= ((const GLshort
*) src
);
1380 for (i
= 0; i
< n
; i
++) {
1383 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
] );
1384 dst
[i
][ACOMP
] = 1.0F
;
1389 unpack_SIGNED_AL1616(const void *src
, GLfloat dst
[][4], GLuint n
)
1391 const GLshort
*s
= (const GLshort
*) src
;
1393 for (i
= 0; i
< n
; i
++) {
1396 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*2+0] );
1397 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*2+1] );
1402 unpack_SIGNED_I16(const void *src
, GLfloat dst
[][4], GLuint n
)
1404 const GLshort
*s
= ((const GLshort
*) src
);
1406 for (i
= 0; i
< n
; i
++) {
1410 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
] );
1416 * Return the unpacker function for the given format.
1418 static unpack_rgba_func
1419 get_unpack_rgba_function(gl_format format
)
1421 static unpack_rgba_func table
[MESA_FORMAT_COUNT
];
1422 static GLboolean initialized
= GL_FALSE
;
1425 table
[MESA_FORMAT_NONE
] = NULL
;
1427 table
[MESA_FORMAT_RGBA8888
] = unpack_RGBA8888
;
1428 table
[MESA_FORMAT_RGBA8888_REV
] = unpack_RGBA8888_REV
;
1429 table
[MESA_FORMAT_ARGB8888
] = unpack_ARGB8888
;
1430 table
[MESA_FORMAT_ARGB8888_REV
] = unpack_ARGB8888_REV
;
1431 table
[MESA_FORMAT_RGBX8888
] = unpack_RGBX8888
;
1432 table
[MESA_FORMAT_RGBX8888_REV
] = unpack_RGBX8888_REV
;
1433 table
[MESA_FORMAT_XRGB8888
] = unpack_XRGB8888
;
1434 table
[MESA_FORMAT_XRGB8888_REV
] = unpack_XRGB8888_REV
;
1435 table
[MESA_FORMAT_RGB888
] = unpack_RGB888
;
1436 table
[MESA_FORMAT_BGR888
] = unpack_BGR888
;
1437 table
[MESA_FORMAT_RGB565
] = unpack_RGB565
;
1438 table
[MESA_FORMAT_RGB565_REV
] = unpack_RGB565_REV
;
1439 table
[MESA_FORMAT_ARGB4444
] = unpack_ARGB4444
;
1440 table
[MESA_FORMAT_ARGB4444_REV
] = unpack_ARGB4444_REV
;
1441 table
[MESA_FORMAT_RGBA5551
] = unpack_RGBA5551
;
1442 table
[MESA_FORMAT_ARGB1555
] = unpack_ARGB1555
;
1443 table
[MESA_FORMAT_ARGB1555_REV
] = unpack_ARGB1555_REV
;
1444 table
[MESA_FORMAT_AL44
] = unpack_AL44
;
1445 table
[MESA_FORMAT_AL88
] = unpack_AL88
;
1446 table
[MESA_FORMAT_AL88_REV
] = unpack_AL88_REV
;
1447 table
[MESA_FORMAT_AL1616
] = unpack_AL1616
;
1448 table
[MESA_FORMAT_AL1616_REV
] = unpack_AL1616_REV
;
1449 table
[MESA_FORMAT_RGB332
] = unpack_RGB332
;
1450 table
[MESA_FORMAT_A8
] = unpack_A8
;
1451 table
[MESA_FORMAT_A16
] = unpack_A16
;
1452 table
[MESA_FORMAT_L8
] = unpack_L8
;
1453 table
[MESA_FORMAT_L16
] = unpack_L16
;
1454 table
[MESA_FORMAT_I8
] = unpack_I8
;
1455 table
[MESA_FORMAT_I16
] = unpack_I16
;
1456 table
[MESA_FORMAT_YCBCR
] = unpack_YCBCR
;
1457 table
[MESA_FORMAT_YCBCR_REV
] = unpack_YCBCR_REV
;
1458 table
[MESA_FORMAT_R8
] = unpack_R8
;
1459 table
[MESA_FORMAT_GR88
] = unpack_GR88
;
1460 table
[MESA_FORMAT_RG88
] = unpack_RG88
;
1461 table
[MESA_FORMAT_R16
] = unpack_R16
;
1462 table
[MESA_FORMAT_RG1616
] = unpack_RG1616
;
1463 table
[MESA_FORMAT_RG1616_REV
] = unpack_RG1616_REV
;
1464 table
[MESA_FORMAT_ARGB2101010
] = unpack_ARGB2101010
;
1465 table
[MESA_FORMAT_Z24_S8
] = unpack_Z24_S8
;
1466 table
[MESA_FORMAT_S8_Z24
] = unpack_S8_Z24
;
1467 table
[MESA_FORMAT_Z16
] = unpack_Z16
;
1468 table
[MESA_FORMAT_X8_Z24
] = unpack_X8_Z24
;
1469 table
[MESA_FORMAT_Z24_X8
] = unpack_Z24_X8
;
1470 table
[MESA_FORMAT_Z32
] = unpack_Z32
;
1471 table
[MESA_FORMAT_S8
] = unpack_S8
;
1472 table
[MESA_FORMAT_SRGB8
] = unpack_SRGB8
;
1473 table
[MESA_FORMAT_SRGBA8
] = unpack_SRGBA8
;
1474 table
[MESA_FORMAT_SARGB8
] = unpack_SARGB8
;
1475 table
[MESA_FORMAT_SL8
] = unpack_SL8
;
1476 table
[MESA_FORMAT_SLA8
] = unpack_SLA8
;
1477 table
[MESA_FORMAT_SRGB_DXT1
] = unpack_SRGB_DXT1
;
1478 table
[MESA_FORMAT_SRGBA_DXT1
] = unpack_SRGBA_DXT1
;
1479 table
[MESA_FORMAT_SRGBA_DXT3
] = unpack_SRGBA_DXT3
;
1480 table
[MESA_FORMAT_SRGBA_DXT5
] = unpack_SRGBA_DXT5
;
1482 table
[MESA_FORMAT_RGB_FXT1
] = unpack_RGB_FXT1
;
1483 table
[MESA_FORMAT_RGBA_FXT1
] = unpack_RGBA_FXT1
;
1484 table
[MESA_FORMAT_RGB_DXT1
] = unpack_RGB_DXT1
;
1485 table
[MESA_FORMAT_RGBA_DXT1
] = unpack_RGBA_DXT1
;
1486 table
[MESA_FORMAT_RGBA_DXT3
] = unpack_RGBA_DXT3
;
1487 table
[MESA_FORMAT_RGBA_DXT5
] = unpack_RGBA_DXT5
;
1489 table
[MESA_FORMAT_RGBA_FLOAT32
] = unpack_RGBA_FLOAT32
;
1490 table
[MESA_FORMAT_RGBA_FLOAT16
] = unpack_RGBA_FLOAT16
;
1491 table
[MESA_FORMAT_RGB_FLOAT32
] = unpack_RGB_FLOAT32
;
1492 table
[MESA_FORMAT_RGB_FLOAT16
] = unpack_RGB_FLOAT16
;
1493 table
[MESA_FORMAT_ALPHA_FLOAT32
] = unpack_ALPHA_FLOAT32
;
1494 table
[MESA_FORMAT_ALPHA_FLOAT16
] = unpack_ALPHA_FLOAT16
;
1495 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = unpack_LUMINANCE_FLOAT32
;
1496 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = unpack_LUMINANCE_FLOAT16
;
1497 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = unpack_LUMINANCE_ALPHA_FLOAT32
;
1498 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = unpack_LUMINANCE_ALPHA_FLOAT16
;
1499 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = unpack_INTENSITY_FLOAT32
;
1500 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = unpack_INTENSITY_FLOAT16
;
1501 table
[MESA_FORMAT_R_FLOAT32
] = unpack_R_FLOAT32
;
1502 table
[MESA_FORMAT_R_FLOAT16
] = unpack_R_FLOAT16
;
1503 table
[MESA_FORMAT_RG_FLOAT32
] = unpack_RG_FLOAT32
;
1504 table
[MESA_FORMAT_RG_FLOAT16
] = unpack_RG_FLOAT16
;
1506 table
[MESA_FORMAT_RGBA_INT8
] = unpack_RGBA_INT8
;
1507 table
[MESA_FORMAT_RGBA_INT16
] = unpack_RGBA_INT16
;
1508 table
[MESA_FORMAT_RGBA_INT32
] = unpack_RGBA_INT32
;
1509 table
[MESA_FORMAT_RGBA_UINT8
] = unpack_RGBA_UINT8
;
1510 table
[MESA_FORMAT_RGBA_UINT16
] = unpack_RGBA_UINT16
;
1511 table
[MESA_FORMAT_RGBA_UINT32
] = unpack_RGBA_UINT32
;
1513 table
[MESA_FORMAT_DUDV8
] = unpack_DUDV8
;
1514 table
[MESA_FORMAT_SIGNED_R8
] = unpack_SIGNED_R8
;
1515 table
[MESA_FORMAT_SIGNED_RG88_REV
] = unpack_SIGNED_RG88_REV
;
1516 table
[MESA_FORMAT_SIGNED_RGBX8888
] = unpack_SIGNED_RGBX8888
;
1517 table
[MESA_FORMAT_SIGNED_RGBA8888
] = unpack_SIGNED_RGBA8888
;
1518 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = unpack_SIGNED_RGBA8888_REV
;
1519 table
[MESA_FORMAT_SIGNED_R16
] = unpack_SIGNED_R16
;
1520 table
[MESA_FORMAT_SIGNED_GR1616
] = unpack_SIGNED_GR1616
;
1521 table
[MESA_FORMAT_SIGNED_RGB_16
] = unpack_SIGNED_RGB_16
;
1522 table
[MESA_FORMAT_SIGNED_RGBA_16
] = unpack_SIGNED_RGBA_16
;
1523 table
[MESA_FORMAT_RGBA_16
] = unpack_RGBA_16
;
1525 table
[MESA_FORMAT_RED_RGTC1
] = unpack_RED_RGTC1
;
1526 table
[MESA_FORMAT_SIGNED_RED_RGTC1
] = unpack_SIGNED_RED_RGTC1
;
1527 table
[MESA_FORMAT_RG_RGTC2
] = unpack_RG_RGTC2
;
1528 table
[MESA_FORMAT_SIGNED_RG_RGTC2
] = unpack_SIGNED_RG_RGTC2
;
1530 table
[MESA_FORMAT_L_LATC1
] = unpack_L_LATC1
;
1531 table
[MESA_FORMAT_SIGNED_L_LATC1
] = unpack_SIGNED_L_LATC1
;
1532 table
[MESA_FORMAT_LA_LATC2
] = unpack_LA_LATC2
;
1533 table
[MESA_FORMAT_SIGNED_LA_LATC2
] = unpack_SIGNED_LA_LATC2
;
1535 table
[MESA_FORMAT_SIGNED_A8
] = unpack_SIGNED_A8
;
1536 table
[MESA_FORMAT_SIGNED_L8
] = unpack_SIGNED_L8
;
1537 table
[MESA_FORMAT_SIGNED_AL88
] = unpack_SIGNED_AL88
;
1538 table
[MESA_FORMAT_SIGNED_I8
] = unpack_SIGNED_I8
;
1539 table
[MESA_FORMAT_SIGNED_A16
] = unpack_SIGNED_A16
;
1540 table
[MESA_FORMAT_SIGNED_L16
] = unpack_SIGNED_L16
;
1541 table
[MESA_FORMAT_SIGNED_AL1616
] = unpack_SIGNED_AL1616
;
1542 table
[MESA_FORMAT_SIGNED_I16
] = unpack_SIGNED_I16
;
1544 table
[MESA_FORMAT_Z32_FLOAT
] = unpack_Z32_FLOAT
;
1545 table
[MESA_FORMAT_Z32_FLOAT_X24S8
] = unpack_Z32_FLOAT_X24S8
;
1547 initialized
= GL_TRUE
;
1550 return table
[format
];
1555 * Unpack rgba colors, returning as GLfloat values.
1558 _mesa_unpack_rgba_row(gl_format format
, GLuint n
,
1559 const void *src
, GLfloat dst
[][4])
1561 unpack_rgba_func unpack
= get_unpack_rgba_function(format
);
1562 unpack(src
, dst
, n
);
1566 /**********************************************************************/
1567 /* Unpack, returning GLubyte colors */
1568 /**********************************************************************/
1572 unpack_ubyte_RGBA8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1574 const GLuint
*s
= ((const GLuint
*) src
);
1576 for (i
= 0; i
< n
; i
++) {
1577 dst
[i
][RCOMP
] = (s
[i
] >> 24);
1578 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1579 dst
[i
][BCOMP
] = (s
[i
] >> 8) & 0xff;
1580 dst
[i
][ACOMP
] = (s
[i
] ) & 0xff;
1585 unpack_ubyte_RGBA8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1587 const GLuint
*s
= ((const GLuint
*) src
);
1589 for (i
= 0; i
< n
; i
++) {
1590 dst
[i
][RCOMP
] = (s
[i
] ) & 0xff;
1591 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1592 dst
[i
][BCOMP
] = (s
[i
] >> 16) & 0xff;
1593 dst
[i
][ACOMP
] = (s
[i
] >> 24);
1598 unpack_ubyte_ARGB8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1600 const GLuint
*s
= ((const GLuint
*) src
);
1602 for (i
= 0; i
< n
; i
++) {
1603 dst
[i
][RCOMP
] = (s
[i
] >> 16) & 0xff;
1604 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1605 dst
[i
][BCOMP
] = (s
[i
] ) & 0xff;
1606 dst
[i
][ACOMP
] = (s
[i
] >> 24);
1611 unpack_ubyte_ARGB8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1613 const GLuint
*s
= ((const GLuint
*) src
);
1615 for (i
= 0; i
< n
; i
++) {
1616 dst
[i
][RCOMP
] = (s
[i
] >> 8) & 0xff;
1617 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1618 dst
[i
][BCOMP
] = (s
[i
] >> 24);
1619 dst
[i
][ACOMP
] = (s
[i
] ) & 0xff;
1624 unpack_ubyte_RGBX8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1626 const GLuint
*s
= ((const GLuint
*) src
);
1628 for (i
= 0; i
< n
; i
++) {
1629 dst
[i
][RCOMP
] = (s
[i
] >> 24);
1630 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1631 dst
[i
][BCOMP
] = (s
[i
] >> 8) & 0xff;
1632 dst
[i
][ACOMP
] = 0xff;
1637 unpack_ubyte_RGBX8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1639 const GLuint
*s
= ((const GLuint
*) src
);
1641 for (i
= 0; i
< n
; i
++) {
1642 dst
[i
][RCOMP
] = (s
[i
] ) & 0xff;
1643 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1644 dst
[i
][BCOMP
] = (s
[i
] >> 16) & 0xff;
1645 dst
[i
][ACOMP
] = 0xff;
1650 unpack_ubyte_XRGB8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1652 const GLuint
*s
= ((const GLuint
*) src
);
1654 for (i
= 0; i
< n
; i
++) {
1655 dst
[i
][RCOMP
] = (s
[i
] >> 16) & 0xff;
1656 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1657 dst
[i
][BCOMP
] = (s
[i
] ) & 0xff;
1658 dst
[i
][ACOMP
] = 0xff;
1663 unpack_ubyte_XRGB8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1665 const GLuint
*s
= ((const GLuint
*) src
);
1667 for (i
= 0; i
< n
; i
++) {
1668 dst
[i
][RCOMP
] = (s
[i
] >> 8) & 0xff;
1669 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1670 dst
[i
][BCOMP
] = (s
[i
] >> 24);
1671 dst
[i
][ACOMP
] = 0xff;
1676 unpack_ubyte_RGB888(const void *src
, GLubyte dst
[][4], GLuint n
)
1678 const GLubyte
*s
= (const GLubyte
*) src
;
1680 for (i
= 0; i
< n
; i
++) {
1681 dst
[i
][RCOMP
] = s
[i
*3+2];
1682 dst
[i
][GCOMP
] = s
[i
*3+1];
1683 dst
[i
][BCOMP
] = s
[i
*3+0];
1684 dst
[i
][ACOMP
] = 0xff;
1689 unpack_ubyte_BGR888(const void *src
, GLubyte dst
[][4], GLuint n
)
1691 const GLubyte
*s
= (const GLubyte
*) src
;
1693 for (i
= 0; i
< n
; i
++) {
1694 dst
[i
][RCOMP
] = s
[i
*3+0];
1695 dst
[i
][GCOMP
] = s
[i
*3+1];
1696 dst
[i
][BCOMP
] = s
[i
*3+2];
1697 dst
[i
][ACOMP
] = 0xff;
1702 unpack_ubyte_RGB565(const void *src
, GLubyte dst
[][4], GLuint n
)
1704 const GLushort
*s
= ((const GLushort
*) src
);
1706 for (i
= 0; i
< n
; i
++) {
1707 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 11) & 0x1f);
1708 dst
[i
][GCOMP
] = EXPAND_6_8((s
[i
] >> 5 ) & 0x3f);
1709 dst
[i
][BCOMP
] = EXPAND_5_8( s
[i
] & 0x1f);
1710 dst
[i
][ACOMP
] = 0xff;
1715 unpack_ubyte_RGB565_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1717 const GLushort
*s
= ((const GLushort
*) src
);
1719 for (i
= 0; i
< n
; i
++) {
1720 GLuint t
= (s
[i
] >> 8) | (s
[i
] << 8); /* byte swap */
1721 dst
[i
][RCOMP
] = EXPAND_5_8((t
>> 11) & 0x1f);
1722 dst
[i
][GCOMP
] = EXPAND_6_8((t
>> 5 ) & 0x3f);
1723 dst
[i
][BCOMP
] = EXPAND_5_8( t
& 0x1f);
1724 dst
[i
][ACOMP
] = 0xff;
1729 unpack_ubyte_ARGB4444(const void *src
, GLubyte dst
[][4], GLuint n
)
1731 const GLushort
*s
= ((const GLushort
*) src
);
1733 for (i
= 0; i
< n
; i
++) {
1734 dst
[i
][RCOMP
] = EXPAND_4_8((s
[i
] >> 8) & 0xf);
1735 dst
[i
][GCOMP
] = EXPAND_4_8((s
[i
] >> 4) & 0xf);
1736 dst
[i
][BCOMP
] = EXPAND_4_8((s
[i
] ) & 0xf);
1737 dst
[i
][ACOMP
] = EXPAND_4_8((s
[i
] >> 12) & 0xf);
1742 unpack_ubyte_ARGB4444_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1744 const GLushort
*s
= ((const GLushort
*) src
);
1746 for (i
= 0; i
< n
; i
++) {
1747 dst
[i
][RCOMP
] = EXPAND_4_8((s
[i
] ) & 0xf);
1748 dst
[i
][GCOMP
] = EXPAND_4_8((s
[i
] >> 12) & 0xf);
1749 dst
[i
][BCOMP
] = EXPAND_4_8((s
[i
] >> 8) & 0xf);
1750 dst
[i
][ACOMP
] = EXPAND_4_8((s
[i
] >> 4) & 0xf);
1755 unpack_ubyte_RGBA5551(const void *src
, GLubyte dst
[][4], GLuint n
)
1757 const GLushort
*s
= ((const GLushort
*) src
);
1759 for (i
= 0; i
< n
; i
++) {
1760 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 11) & 0x1f);
1761 dst
[i
][GCOMP
] = EXPAND_5_8((s
[i
] >> 6) & 0x1f);
1762 dst
[i
][BCOMP
] = EXPAND_5_8((s
[i
] >> 1) & 0x1f);
1763 dst
[i
][ACOMP
] = EXPAND_1_8((s
[i
] ) & 0x01);
1768 unpack_ubyte_ARGB1555(const void *src
, GLubyte dst
[][4], GLuint n
)
1770 const GLushort
*s
= ((const GLushort
*) src
);
1772 for (i
= 0; i
< n
; i
++) {
1773 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 10) & 0x1f);
1774 dst
[i
][GCOMP
] = EXPAND_5_8((s
[i
] >> 5) & 0x1f);
1775 dst
[i
][BCOMP
] = EXPAND_5_8((s
[i
] >> 0) & 0x1f);
1776 dst
[i
][ACOMP
] = EXPAND_1_8((s
[i
] >> 15) & 0x01);
1781 unpack_ubyte_ARGB1555_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1783 const GLushort
*s
= ((const GLushort
*) src
);
1785 for (i
= 0; i
< n
; i
++) {
1786 GLushort tmp
= (s
[i
] << 8) | (s
[i
] >> 8); /* byteswap */
1787 dst
[i
][RCOMP
] = EXPAND_5_8((tmp
>> 10) & 0x1f);
1788 dst
[i
][GCOMP
] = EXPAND_5_8((tmp
>> 5) & 0x1f);
1789 dst
[i
][BCOMP
] = EXPAND_5_8((tmp
>> 0) & 0x1f);
1790 dst
[i
][ACOMP
] = EXPAND_1_8((tmp
>> 15) & 0x01);
1795 unpack_ubyte_AL44(const void *src
, GLubyte dst
[][4], GLuint n
)
1797 const GLubyte
*s
= ((const GLubyte
*) src
);
1799 for (i
= 0; i
< n
; i
++) {
1802 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] & 0xf);
1803 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] >> 4);
1808 unpack_ubyte_AL88(const void *src
, GLubyte dst
[][4], GLuint n
)
1810 const GLushort
*s
= ((const GLushort
*) src
);
1812 for (i
= 0; i
< n
; i
++) {
1815 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] & 0xff);
1816 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] >> 8);
1821 unpack_ubyte_AL88_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1823 const GLushort
*s
= ((const GLushort
*) src
);
1825 for (i
= 0; i
< n
; i
++) {
1828 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] >> 8);
1829 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] & 0xff);
1834 unpack_ubyte_RGB332(const void *src
, GLubyte dst
[][4], GLuint n
)
1836 const GLubyte
*s
= ((const GLubyte
*) src
);
1838 for (i
= 0; i
< n
; i
++) {
1839 dst
[i
][RCOMP
] = EXPAND_3_8((s
[i
] >> 5) & 0x7);
1840 dst
[i
][GCOMP
] = EXPAND_3_8((s
[i
] >> 2) & 0x7);
1841 dst
[i
][BCOMP
] = EXPAND_2_8((s
[i
] ) & 0x3);
1842 dst
[i
][ACOMP
] = 0xff;
1847 unpack_ubyte_A8(const void *src
, GLubyte dst
[][4], GLuint n
)
1849 const GLubyte
*s
= ((const GLubyte
*) src
);
1851 for (i
= 0; i
< n
; i
++) {
1855 dst
[i
][ACOMP
] = s
[i
];
1860 unpack_ubyte_L8(const void *src
, GLubyte dst
[][4], GLuint n
)
1862 const GLubyte
*s
= ((const GLubyte
*) src
);
1864 for (i
= 0; i
< n
; i
++) {
1867 dst
[i
][BCOMP
] = s
[i
];
1868 dst
[i
][ACOMP
] = 0xff;
1874 unpack_ubyte_I8(const void *src
, GLubyte dst
[][4], GLuint n
)
1876 const GLubyte
*s
= ((const GLubyte
*) src
);
1878 for (i
= 0; i
< n
; i
++) {
1882 dst
[i
][ACOMP
] = s
[i
];
1887 unpack_ubyte_R8(const void *src
, GLubyte dst
[][4], GLuint n
)
1889 const GLubyte
*s
= ((const GLubyte
*) src
);
1891 for (i
= 0; i
< n
; i
++) {
1900 unpack_ubyte_GR88(const void *src
, GLubyte dst
[][4], GLuint n
)
1902 const GLushort
*s
= ((const GLushort
*) src
);
1904 for (i
= 0; i
< n
; i
++) {
1905 dst
[i
][RCOMP
] = s
[i
] & 0xff;
1906 dst
[i
][GCOMP
] = s
[i
] >> 8;
1908 dst
[i
][ACOMP
] = 0xff;
1913 unpack_ubyte_RG88(const void *src
, GLubyte dst
[][4], GLuint n
)
1915 const GLushort
*s
= ((const GLushort
*) src
);
1917 for (i
= 0; i
< n
; i
++) {
1918 dst
[i
][RCOMP
] = s
[i
] >> 8;
1919 dst
[i
][GCOMP
] = s
[i
] & 0xff;
1921 dst
[i
][ACOMP
] = 0xff;
1927 * Unpack rgba colors, returning as GLubyte values. This should usually
1928 * only be used for unpacking formats that use 8 bits or less per channel.
1931 _mesa_unpack_ubyte_rgba_row(gl_format format
, GLuint n
,
1932 const void *src
, GLubyte dst
[][4])
1935 case MESA_FORMAT_RGBA8888
:
1936 unpack_ubyte_RGBA8888(src
, dst
, n
);
1938 case MESA_FORMAT_RGBA8888_REV
:
1939 unpack_ubyte_RGBA8888_REV(src
, dst
, n
);
1941 case MESA_FORMAT_ARGB8888
:
1942 unpack_ubyte_ARGB8888(src
, dst
, n
);
1944 case MESA_FORMAT_ARGB8888_REV
:
1945 unpack_ubyte_ARGB8888_REV(src
, dst
, n
);
1947 case MESA_FORMAT_RGBX8888
:
1948 unpack_ubyte_RGBX8888(src
, dst
, n
);
1950 case MESA_FORMAT_RGBX8888_REV
:
1951 unpack_ubyte_RGBX8888_REV(src
, dst
, n
);
1953 case MESA_FORMAT_XRGB8888
:
1954 unpack_ubyte_XRGB8888(src
, dst
, n
);
1956 case MESA_FORMAT_XRGB8888_REV
:
1957 unpack_ubyte_XRGB8888_REV(src
, dst
, n
);
1959 case MESA_FORMAT_RGB888
:
1960 unpack_ubyte_RGB888(src
, dst
, n
);
1962 case MESA_FORMAT_BGR888
:
1963 unpack_ubyte_BGR888(src
, dst
, n
);
1965 case MESA_FORMAT_RGB565
:
1966 unpack_ubyte_RGB565(src
, dst
, n
);
1968 case MESA_FORMAT_RGB565_REV
:
1969 unpack_ubyte_RGB565_REV(src
, dst
, n
);
1971 case MESA_FORMAT_ARGB4444
:
1972 unpack_ubyte_ARGB4444(src
, dst
, n
);
1974 case MESA_FORMAT_ARGB4444_REV
:
1975 unpack_ubyte_ARGB4444_REV(src
, dst
, n
);
1977 case MESA_FORMAT_RGBA5551
:
1978 unpack_ubyte_RGBA5551(src
, dst
, n
);
1980 case MESA_FORMAT_ARGB1555
:
1981 unpack_ubyte_ARGB1555(src
, dst
, n
);
1983 case MESA_FORMAT_ARGB1555_REV
:
1984 unpack_ubyte_ARGB1555_REV(src
, dst
, n
);
1986 case MESA_FORMAT_AL44
:
1987 unpack_ubyte_AL44(src
, dst
, n
);
1989 case MESA_FORMAT_AL88
:
1990 unpack_ubyte_AL88(src
, dst
, n
);
1992 case MESA_FORMAT_AL88_REV
:
1993 unpack_ubyte_AL88_REV(src
, dst
, n
);
1995 case MESA_FORMAT_RGB332
:
1996 unpack_ubyte_RGB332(src
, dst
, n
);
1998 case MESA_FORMAT_A8
:
1999 unpack_ubyte_A8(src
, dst
, n
);
2001 case MESA_FORMAT_L8
:
2002 unpack_ubyte_L8(src
, dst
, n
);
2004 case MESA_FORMAT_I8
:
2005 unpack_ubyte_I8(src
, dst
, n
);
2007 case MESA_FORMAT_R8
:
2008 unpack_ubyte_R8(src
, dst
, n
);
2010 case MESA_FORMAT_GR88
:
2011 unpack_ubyte_GR88(src
, dst
, n
);
2013 case MESA_FORMAT_RG88
:
2014 unpack_ubyte_RG88(src
, dst
, n
);
2017 /* get float values, convert to ubyte */
2019 GLfloat
*tmp
= (GLfloat
*) malloc(n
* 4 * sizeof(GLfloat
));
2022 _mesa_unpack_rgba_row(format
, n
, src
, (GLfloat (*)[4]) tmp
);
2023 for (i
= 0; i
< n
; i
++) {
2024 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][0], tmp
[i
*4+0]);
2025 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][1], tmp
[i
*4+1]);
2026 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][2], tmp
[i
*4+2]);
2027 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][3], tmp
[i
*4+3]);
2037 /**********************************************************************/
2038 /* Unpack, returning GLuint colors */
2039 /**********************************************************************/
2042 unpack_int_rgba_RGBA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2044 memcpy(dst
, src
, n
* 4 * sizeof(GLuint
));
2048 unpack_int_rgba_RGBA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2052 for (i
= 0; i
< n
; i
++) {
2053 dst
[i
][0] = src
[i
* 4 + 0];
2054 dst
[i
][1] = src
[i
* 4 + 1];
2055 dst
[i
][2] = src
[i
* 4 + 2];
2056 dst
[i
][3] = src
[i
* 4 + 3];
2061 unpack_int_rgba_RGBA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2065 for (i
= 0; i
< n
; i
++) {
2066 dst
[i
][0] = src
[i
* 4 + 0];
2067 dst
[i
][1] = src
[i
* 4 + 1];
2068 dst
[i
][2] = src
[i
* 4 + 2];
2069 dst
[i
][3] = src
[i
* 4 + 3];
2074 unpack_int_rgba_RGBA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2078 for (i
= 0; i
< n
; i
++) {
2079 dst
[i
][0] = src
[i
* 4 + 0];
2080 dst
[i
][1] = src
[i
* 4 + 1];
2081 dst
[i
][2] = src
[i
* 4 + 2];
2082 dst
[i
][3] = src
[i
* 4 + 3];
2087 unpack_int_rgba_RGBA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2091 for (i
= 0; i
< n
; i
++) {
2092 dst
[i
][0] = src
[i
* 4 + 0];
2093 dst
[i
][1] = src
[i
* 4 + 1];
2094 dst
[i
][2] = src
[i
* 4 + 2];
2095 dst
[i
][3] = src
[i
* 4 + 3];
2100 unpack_int_rgba_RGB_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2104 for (i
= 0; i
< n
; i
++) {
2105 dst
[i
][0] = src
[i
* 3 + 0];
2106 dst
[i
][1] = src
[i
* 3 + 1];
2107 dst
[i
][2] = src
[i
* 3 + 2];
2113 unpack_int_rgba_RGB_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2117 for (i
= 0; i
< n
; i
++) {
2118 dst
[i
][0] = src
[i
* 3 + 0];
2119 dst
[i
][1] = src
[i
* 3 + 1];
2120 dst
[i
][2] = src
[i
* 3 + 2];
2126 unpack_int_rgba_RGB_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2130 for (i
= 0; i
< n
; i
++) {
2131 dst
[i
][0] = src
[i
* 3 + 0];
2132 dst
[i
][1] = src
[i
* 3 + 1];
2133 dst
[i
][2] = src
[i
* 3 + 2];
2139 unpack_int_rgba_RGB_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2143 for (i
= 0; i
< n
; i
++) {
2144 dst
[i
][0] = src
[i
* 3 + 0];
2145 dst
[i
][1] = src
[i
* 3 + 1];
2146 dst
[i
][2] = src
[i
* 3 + 2];
2152 unpack_int_rgba_RGB_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2156 for (i
= 0; i
< n
; i
++) {
2157 dst
[i
][0] = src
[i
* 3 + 0];
2158 dst
[i
][1] = src
[i
* 3 + 1];
2159 dst
[i
][2] = src
[i
* 3 + 2];
2165 unpack_int_rgba_RG_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2169 for (i
= 0; i
< n
; i
++) {
2170 dst
[i
][0] = src
[i
* 2 + 0];
2171 dst
[i
][1] = src
[i
* 2 + 1];
2178 unpack_int_rgba_RG_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2182 for (i
= 0; i
< n
; i
++) {
2183 dst
[i
][0] = src
[i
* 2 + 0];
2184 dst
[i
][1] = src
[i
* 2 + 1];
2191 unpack_int_rgba_RG_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2195 for (i
= 0; i
< n
; i
++) {
2196 dst
[i
][0] = src
[i
* 2 + 0];
2197 dst
[i
][1] = src
[i
* 2 + 1];
2204 unpack_int_rgba_RG_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2208 for (i
= 0; i
< n
; i
++) {
2209 dst
[i
][0] = src
[i
* 2 + 0];
2210 dst
[i
][1] = src
[i
* 2 + 1];
2217 unpack_int_rgba_RG_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2221 for (i
= 0; i
< n
; i
++) {
2222 dst
[i
][0] = src
[i
* 2 + 0];
2223 dst
[i
][1] = src
[i
* 2 + 1];
2230 unpack_int_rgba_R_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2234 for (i
= 0; i
< n
; i
++) {
2243 unpack_int_rgba_R_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2247 for (i
= 0; i
< n
; i
++) {
2256 unpack_int_rgba_R_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2260 for (i
= 0; i
< n
; i
++) {
2269 unpack_int_rgba_R_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2273 for (i
= 0; i
< n
; i
++) {
2282 unpack_int_rgba_R_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2286 for (i
= 0; i
< n
; i
++) {
2295 unpack_int_rgba_ALPHA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2299 for (i
= 0; i
< n
; i
++) {
2300 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2306 unpack_int_rgba_ALPHA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2310 for (i
= 0; i
< n
; i
++) {
2311 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2317 unpack_int_rgba_ALPHA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2321 for (i
= 0; i
< n
; i
++) {
2322 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2328 unpack_int_rgba_ALPHA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2332 for (i
= 0; i
< n
; i
++) {
2333 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2339 unpack_int_rgba_ALPHA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2343 for (i
= 0; i
< n
; i
++) {
2344 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2350 unpack_int_rgba_LUMINANCE_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2354 for (i
= 0; i
< n
; i
++) {
2355 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2361 unpack_int_rgba_LUMINANCE_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2365 for (i
= 0; i
< n
; i
++) {
2366 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2372 unpack_int_rgba_LUMINANCE_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2376 for (i
= 0; i
< n
; i
++) {
2377 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2383 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2387 for (i
= 0; i
< n
; i
++) {
2388 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2394 unpack_int_rgba_LUMINANCE_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2398 for (i
= 0; i
< n
; i
++) {
2399 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2406 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2410 for (i
= 0; i
< n
; i
++) {
2411 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2412 dst
[i
][3] = src
[i
* 2 + 1];
2417 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2421 for (i
= 0; i
< n
; i
++) {
2422 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2423 dst
[i
][3] = src
[i
* 2 + 1];
2428 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2432 for (i
= 0; i
< n
; i
++) {
2433 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2434 dst
[i
][3] = src
[i
* 2 + 1];
2439 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2443 for (i
= 0; i
< n
; i
++) {
2444 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2445 dst
[i
][3] = src
[i
* 2 + 1];
2450 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2454 for (i
= 0; i
< n
; i
++) {
2455 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2456 dst
[i
][3] = src
[i
* 2 + 1];
2461 unpack_int_rgba_INTENSITY_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2465 for (i
= 0; i
< n
; i
++) {
2466 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2471 unpack_int_rgba_INTENSITY_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2475 for (i
= 0; i
< n
; i
++) {
2476 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2481 unpack_int_rgba_INTENSITY_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2485 for (i
= 0; i
< n
; i
++) {
2486 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2491 unpack_int_rgba_INTENSITY_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2495 for (i
= 0; i
< n
; i
++) {
2496 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2501 unpack_int_rgba_INTENSITY_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2505 for (i
= 0; i
< n
; i
++) {
2506 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2511 _mesa_unpack_uint_rgba_row(gl_format format
, GLuint n
,
2512 const void *src
, GLuint dst
[][4])
2515 /* Since there won't be any sign extension happening, there's no need to
2516 * make separate paths for 32-bit-to-32-bit integer unpack.
2518 case MESA_FORMAT_RGBA_UINT32
:
2519 case MESA_FORMAT_RGBA_INT32
:
2520 unpack_int_rgba_RGBA_UINT32(src
, dst
, n
);
2523 case MESA_FORMAT_RGBA_UINT16
:
2524 unpack_int_rgba_RGBA_UINT16(src
, dst
, n
);
2526 case MESA_FORMAT_RGBA_INT16
:
2527 unpack_int_rgba_RGBA_INT16(src
, dst
, n
);
2530 case MESA_FORMAT_RGBA_UINT8
:
2531 unpack_int_rgba_RGBA_UINT8(src
, dst
, n
);
2533 case MESA_FORMAT_RGBA_INT8
:
2534 unpack_int_rgba_RGBA_INT8(src
, dst
, n
);
2537 case MESA_FORMAT_RGB_UINT32
:
2538 case MESA_FORMAT_RGB_INT32
:
2539 unpack_int_rgba_RGB_UINT32(src
, dst
, n
);
2542 case MESA_FORMAT_RGB_UINT16
:
2543 unpack_int_rgba_RGB_UINT16(src
, dst
, n
);
2545 case MESA_FORMAT_RGB_INT16
:
2546 unpack_int_rgba_RGB_INT16(src
, dst
, n
);
2549 case MESA_FORMAT_RGB_UINT8
:
2550 unpack_int_rgba_RGB_UINT8(src
, dst
, n
);
2552 case MESA_FORMAT_RGB_INT8
:
2553 unpack_int_rgba_RGB_INT8(src
, dst
, n
);
2556 case MESA_FORMAT_RG_UINT32
:
2557 case MESA_FORMAT_RG_INT32
:
2558 unpack_int_rgba_RG_UINT32(src
, dst
, n
);
2561 case MESA_FORMAT_RG_UINT16
:
2562 unpack_int_rgba_RG_UINT16(src
, dst
, n
);
2564 case MESA_FORMAT_RG_INT16
:
2565 unpack_int_rgba_RG_INT16(src
, dst
, n
);
2568 case MESA_FORMAT_RG_UINT8
:
2569 unpack_int_rgba_RG_UINT8(src
, dst
, n
);
2571 case MESA_FORMAT_RG_INT8
:
2572 unpack_int_rgba_RG_INT8(src
, dst
, n
);
2575 case MESA_FORMAT_R_UINT32
:
2576 case MESA_FORMAT_R_INT32
:
2577 unpack_int_rgba_R_UINT32(src
, dst
, n
);
2580 case MESA_FORMAT_R_UINT16
:
2581 unpack_int_rgba_R_UINT16(src
, dst
, n
);
2583 case MESA_FORMAT_R_INT16
:
2584 unpack_int_rgba_R_INT16(src
, dst
, n
);
2587 case MESA_FORMAT_R_UINT8
:
2588 unpack_int_rgba_R_UINT8(src
, dst
, n
);
2590 case MESA_FORMAT_R_INT8
:
2591 unpack_int_rgba_R_INT8(src
, dst
, n
);
2594 case MESA_FORMAT_ALPHA_UINT32
:
2595 case MESA_FORMAT_ALPHA_INT32
:
2596 unpack_int_rgba_ALPHA_UINT32(src
, dst
, n
);
2599 case MESA_FORMAT_ALPHA_UINT16
:
2600 unpack_int_rgba_ALPHA_UINT16(src
, dst
, n
);
2602 case MESA_FORMAT_ALPHA_INT16
:
2603 unpack_int_rgba_ALPHA_INT16(src
, dst
, n
);
2606 case MESA_FORMAT_ALPHA_UINT8
:
2607 unpack_int_rgba_ALPHA_UINT8(src
, dst
, n
);
2609 case MESA_FORMAT_ALPHA_INT8
:
2610 unpack_int_rgba_ALPHA_INT8(src
, dst
, n
);
2613 case MESA_FORMAT_LUMINANCE_UINT32
:
2614 case MESA_FORMAT_LUMINANCE_INT32
:
2615 unpack_int_rgba_LUMINANCE_UINT32(src
, dst
, n
);
2617 case MESA_FORMAT_LUMINANCE_UINT16
:
2618 unpack_int_rgba_LUMINANCE_UINT16(src
, dst
, n
);
2620 case MESA_FORMAT_LUMINANCE_INT16
:
2621 unpack_int_rgba_LUMINANCE_INT16(src
, dst
, n
);
2624 case MESA_FORMAT_LUMINANCE_UINT8
:
2625 unpack_int_rgba_LUMINANCE_UINT8(src
, dst
, n
);
2627 case MESA_FORMAT_LUMINANCE_INT8
:
2628 unpack_int_rgba_LUMINANCE_INT8(src
, dst
, n
);
2631 case MESA_FORMAT_LUMINANCE_ALPHA_UINT32
:
2632 case MESA_FORMAT_LUMINANCE_ALPHA_INT32
:
2633 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src
, dst
, n
);
2636 case MESA_FORMAT_LUMINANCE_ALPHA_UINT16
:
2637 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src
, dst
, n
);
2639 case MESA_FORMAT_LUMINANCE_ALPHA_INT16
:
2640 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src
, dst
, n
);
2643 case MESA_FORMAT_LUMINANCE_ALPHA_UINT8
:
2644 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src
, dst
, n
);
2646 case MESA_FORMAT_LUMINANCE_ALPHA_INT8
:
2647 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src
, dst
, n
);
2650 case MESA_FORMAT_INTENSITY_UINT32
:
2651 case MESA_FORMAT_INTENSITY_INT32
:
2652 unpack_int_rgba_INTENSITY_UINT32(src
, dst
, n
);
2655 case MESA_FORMAT_INTENSITY_UINT16
:
2656 unpack_int_rgba_INTENSITY_UINT16(src
, dst
, n
);
2658 case MESA_FORMAT_INTENSITY_INT16
:
2659 unpack_int_rgba_INTENSITY_INT16(src
, dst
, n
);
2662 case MESA_FORMAT_INTENSITY_UINT8
:
2663 unpack_int_rgba_INTENSITY_UINT8(src
, dst
, n
);
2665 case MESA_FORMAT_INTENSITY_INT8
:
2666 unpack_int_rgba_INTENSITY_INT8(src
, dst
, n
);
2670 _mesa_problem(NULL
, "%s: bad format %s", __FUNCTION__
,
2671 _mesa_get_format_name(format
));
2677 * Unpack a 2D rect of pixels returning float RGBA colors.
2678 * \param format the source image format
2679 * \param src start address of the source image
2680 * \param srcRowStride source image row stride in bytes
2681 * \param dst start address of the dest image
2682 * \param dstRowStride dest image row stride in bytes
2683 * \param x source image start X pos
2684 * \param y source image start Y pos
2685 * \param width width of rect region to convert
2686 * \param height height of rect region to convert
2689 _mesa_unpack_rgba_block(gl_format format
,
2690 const void *src
, GLint srcRowStride
,
2691 GLfloat dst
[][4], GLint dstRowStride
,
2692 GLuint x
, GLuint y
, GLuint width
, GLuint height
)
2694 unpack_rgba_func unpack
= get_unpack_rgba_function(format
);
2695 const GLuint srcPixStride
= _mesa_get_format_bytes(format
);
2696 const GLuint dstPixStride
= 4 * sizeof(GLfloat
);
2697 const GLubyte
*srcRow
;
2701 /* XXX needs to be fixed for compressed formats */
2703 srcRow
= ((const GLubyte
*) src
) + srcRowStride
* y
+ srcPixStride
* x
;
2704 dstRow
= ((GLubyte
*) dst
) + dstRowStride
* y
+ dstPixStride
* x
;
2706 for (i
= 0; i
< height
; i
++) {
2707 unpack(srcRow
, (GLfloat (*)[4]) dstRow
, width
);
2709 dstRow
+= dstRowStride
;
2710 srcRow
+= srcRowStride
;
2717 typedef void (*unpack_float_z_func
)(GLuint n
, const void *src
, GLfloat
*dst
);
2720 unpack_float_z_Z24_X8(GLuint n
, const void *src
, GLfloat
*dst
)
2722 /* only return Z, not stencil data */
2723 const GLuint
*s
= ((const GLuint
*) src
);
2724 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2726 for (i
= 0; i
< n
; i
++) {
2727 dst
[i
] = (s
[i
] >> 8) * scale
;
2728 ASSERT(dst
[i
] >= 0.0F
);
2729 ASSERT(dst
[i
] <= 1.0F
);
2734 unpack_float_z_X8_Z24(GLuint n
, const void *src
, GLfloat
*dst
)
2736 /* only return Z, not stencil data */
2737 const GLuint
*s
= ((const GLuint
*) src
);
2738 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2740 for (i
= 0; i
< n
; i
++) {
2741 dst
[i
] = (s
[i
] & 0x00ffffff) * scale
;
2742 ASSERT(dst
[i
] >= 0.0F
);
2743 ASSERT(dst
[i
] <= 1.0F
);
2748 unpack_float_z_Z16(GLuint n
, const void *src
, GLfloat
*dst
)
2750 const GLushort
*s
= ((const GLushort
*) src
);
2752 for (i
= 0; i
< n
; i
++) {
2753 dst
[i
] = s
[i
] * (1.0F
/ 65535.0F
);
2758 unpack_float_z_Z32(GLuint n
, const void *src
, GLfloat
*dst
)
2760 const GLuint
*s
= ((const GLuint
*) src
);
2762 for (i
= 0; i
< n
; i
++) {
2763 dst
[i
] = s
[i
] * (1.0F
/ 0xffffffff);
2768 unpack_float_z_Z32F(GLuint n
, const void *src
, GLfloat
*dst
)
2770 memcpy(dst
, src
, n
* sizeof(float));
2774 unpack_float_z_Z32X24S8(GLuint n
, const void *src
, GLfloat
*dst
)
2776 const GLfloat
*s
= ((const GLfloat
*) src
);
2778 for (i
= 0; i
< n
; i
++) {
2787 * The returned values will always be in the range [0.0, 1.0].
2790 _mesa_unpack_float_z_row(gl_format format
, GLuint n
,
2791 const void *src
, GLfloat
*dst
)
2793 unpack_float_z_func unpack
;
2796 case MESA_FORMAT_Z24_S8
:
2797 case MESA_FORMAT_Z24_X8
:
2798 unpack
= unpack_float_z_Z24_X8
;
2800 case MESA_FORMAT_S8_Z24
:
2801 case MESA_FORMAT_X8_Z24
:
2802 unpack
= unpack_float_z_X8_Z24
;
2804 case MESA_FORMAT_Z16
:
2805 unpack
= unpack_float_z_Z16
;
2807 case MESA_FORMAT_Z32
:
2808 unpack
= unpack_float_z_Z32
;
2810 case MESA_FORMAT_Z32_FLOAT
:
2811 unpack
= unpack_float_z_Z32F
;
2813 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2814 unpack
= unpack_float_z_Z32X24S8
;
2817 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_float_z_row",
2818 _mesa_get_format_name(format
));
2822 unpack(n
, src
, dst
);
2827 typedef void (*unpack_uint_z_func
)(const void *src
, GLuint
*dst
, GLuint n
);
2830 unpack_uint_z_Z24_X8(const void *src
, GLuint
*dst
, GLuint n
)
2832 /* only return Z, not stencil data */
2833 const GLuint
*s
= ((const GLuint
*) src
);
2835 for (i
= 0; i
< n
; i
++) {
2836 dst
[i
] = (s
[i
] & 0xffffff00) | (s
[i
] >> 24);
2841 unpack_uint_z_X8_Z24(const void *src
, GLuint
*dst
, GLuint n
)
2843 /* only return Z, not stencil data */
2844 const GLuint
*s
= ((const GLuint
*) src
);
2846 for (i
= 0; i
< n
; i
++) {
2847 dst
[i
] = (s
[i
] << 8) | ((s
[i
] >> 16) & 0xff);
2852 unpack_uint_z_Z16(const void *src
, GLuint
*dst
, GLuint n
)
2854 const GLushort
*s
= ((const GLushort
*)src
);
2856 for (i
= 0; i
< n
; i
++) {
2857 dst
[i
] = (s
[i
] << 16) | s
[i
];
2862 unpack_uint_z_Z32(const void *src
, GLuint
*dst
, GLuint n
)
2864 memcpy(dst
, src
, n
* sizeof(GLuint
));
2868 unpack_uint_z_Z32_FLOAT(const void *src
, GLuint
*dst
, GLuint n
)
2870 const float *s
= (const float *)src
;
2872 for (i
= 0; i
< n
; i
++) {
2873 dst
[i
] = FLOAT_TO_UINT(CLAMP(s
[i
], 0.0F
, 1.0F
));
2878 unpack_uint_z_Z32_FLOAT_X24S8(const void *src
, GLuint
*dst
, GLuint n
)
2885 const struct z32f_x24s8
*s
= (const struct z32f_x24s8
*) src
;
2888 for (i
= 0; i
< n
; i
++) {
2889 dst
[i
] = FLOAT_TO_UINT(CLAMP(s
[i
].z
, 0.0F
, 1.0F
));
2896 * The returned values will always be in the range [0, 0xffffffff].
2899 _mesa_unpack_uint_z_row(gl_format format
, GLuint n
,
2900 const void *src
, GLuint
*dst
)
2902 unpack_uint_z_func unpack
;
2903 const GLubyte
*srcPtr
= (GLubyte
*) src
;
2906 case MESA_FORMAT_Z24_S8
:
2907 case MESA_FORMAT_Z24_X8
:
2908 unpack
= unpack_uint_z_Z24_X8
;
2910 case MESA_FORMAT_S8_Z24
:
2911 case MESA_FORMAT_X8_Z24
:
2912 unpack
= unpack_uint_z_X8_Z24
;
2914 case MESA_FORMAT_Z16
:
2915 unpack
= unpack_uint_z_Z16
;
2917 case MESA_FORMAT_Z32
:
2918 unpack
= unpack_uint_z_Z32
;
2920 case MESA_FORMAT_Z32_FLOAT
:
2921 unpack
= unpack_uint_z_Z32_FLOAT
;
2923 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2924 unpack
= unpack_uint_z_Z32_FLOAT_X24S8
;
2927 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_uint_z_row",
2928 _mesa_get_format_name(format
));
2932 unpack(srcPtr
, dst
, n
);
2937 unpack_ubyte_s_S8(const void *src
, GLubyte
*dst
, GLuint n
)
2939 memcpy(dst
, src
, n
);
2943 unpack_ubyte_s_Z24_S8(const void *src
, GLubyte
*dst
, GLuint n
)
2946 const GLuint
*src32
= src
;
2948 for (i
= 0; i
< n
; i
++)
2949 dst
[i
] = src32
[i
] & 0xff;
2953 unpack_ubyte_s_S8_Z24(const void *src
, GLubyte
*dst
, GLuint n
)
2956 const GLuint
*src32
= src
;
2958 for (i
= 0; i
< n
; i
++)
2959 dst
[i
] = src32
[i
] >> 24;
2963 unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src
, GLubyte
*dst
, GLuint n
)
2966 const GLuint
*src32
= src
;
2968 for (i
= 0; i
< n
; i
++)
2969 dst
[i
] = src32
[i
* 2 + 1] & 0xff;
2973 _mesa_unpack_ubyte_stencil_row(gl_format format
, GLuint n
,
2974 const void *src
, GLubyte
*dst
)
2977 case MESA_FORMAT_S8
:
2978 unpack_ubyte_s_S8(src
, dst
, n
);
2980 case MESA_FORMAT_Z24_S8
:
2981 unpack_ubyte_s_Z24_S8(src
, dst
, n
);
2983 case MESA_FORMAT_S8_Z24
:
2984 unpack_ubyte_s_S8_Z24(src
, dst
, n
);
2986 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2987 unpack_ubyte_s_Z32_FLOAT_X24S8(src
, dst
, n
);
2990 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_ubyte_s_row",
2991 _mesa_get_format_name(format
));
2997 unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint
*src
, GLuint
*dst
, GLuint n
)
3001 for (i
= 0; i
< n
; i
++) {
3002 GLuint val
= src
[i
];
3003 dst
[i
] = val
>> 24 | val
<< 8;
3008 unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint
*src
, GLuint
*dst
, GLuint n
)
3010 memcpy(dst
, src
, n
* 4);
3014 _mesa_unpack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
3015 const void *src
, GLuint
*dst
)
3018 case MESA_FORMAT_Z24_S8
:
3019 unpack_uint_24_8_depth_stencil_Z24_S8(src
, dst
, n
);
3021 case MESA_FORMAT_S8_Z24
:
3022 unpack_uint_24_8_depth_stencil_S8_Z24(src
, dst
, n
);
3026 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
3027 _mesa_get_format_name(format
));