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"
29 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
30 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
32 #include "u_format_rgb9e5.h"
33 #include "u_format_r11g11b10f.h"
38 /* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
40 #define EXPAND_1_8(X) ( (X) ? 0xff : 0x0 )
42 #define EXPAND_2_8(X) ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
44 #define EXPAND_3_8(X) ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
46 #define EXPAND_4_8(X) ( ((X) << 4) | (X) )
48 #define EXPAND_5_8(X) ( ((X) << 3) | ((X) >> 2) )
50 #define EXPAND_6_8(X) ( ((X) << 2) | ((X) >> 4) )
54 * Convert an 8-bit sRGB value from non-linear space to a
55 * linear RGB value in [0, 1].
56 * Implemented with a 256-entry lookup table.
59 nonlinear_to_linear(GLubyte cs8
)
61 static GLfloat table
[256];
62 static GLboolean tableReady
= GL_FALSE
;
64 /* compute lookup table now */
66 for (i
= 0; i
< 256; i
++) {
67 const GLfloat cs
= UBYTE_TO_FLOAT(i
);
69 table
[i
] = cs
/ 12.92f
;
72 table
[i
] = (GLfloat
) pow((cs
+ 0.055) / 1.055, 2.4);
81 /**********************************************************************/
82 /* Unpack, returning GLfloat colors */
83 /**********************************************************************/
85 typedef void (*unpack_rgba_func
)(const void *src
, GLfloat dst
[][4], GLuint n
);
89 unpack_RGBA8888(const void *src
, GLfloat dst
[][4], GLuint n
)
91 const GLuint
*s
= ((const GLuint
*) src
);
93 for (i
= 0; i
< n
; i
++) {
94 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
95 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
96 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
97 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
102 unpack_RGBA8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
104 const GLuint
*s
= ((const GLuint
*) src
);
106 for (i
= 0; i
< n
; i
++) {
107 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
108 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
109 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
110 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
115 unpack_ARGB8888(const void *src
, GLfloat dst
[][4], GLuint n
)
117 const GLuint
*s
= ((const GLuint
*) src
);
119 for (i
= 0; i
< n
; i
++) {
120 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
121 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
122 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
123 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
128 unpack_ARGB8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
130 const GLuint
*s
= ((const GLuint
*) src
);
132 for (i
= 0; i
< n
; i
++) {
133 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
134 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
135 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
136 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
141 unpack_RGBX8888(const void *src
, GLfloat dst
[][4], GLuint n
)
143 const GLuint
*s
= ((const GLuint
*) src
);
145 for (i
= 0; i
< n
; i
++) {
146 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
147 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
148 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
149 dst
[i
][ACOMP
] = 1.0f
;
154 unpack_RGBX8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
156 const GLuint
*s
= ((const GLuint
*) src
);
158 for (i
= 0; i
< n
; i
++) {
159 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
160 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
161 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
162 dst
[i
][ACOMP
] = 1.0f
;
167 unpack_XRGB8888(const void *src
, GLfloat dst
[][4], GLuint n
)
169 const GLuint
*s
= ((const GLuint
*) src
);
171 for (i
= 0; i
< n
; i
++) {
172 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
173 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
174 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
175 dst
[i
][ACOMP
] = 1.0f
;
180 unpack_XRGB8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
182 const GLuint
*s
= ((const GLuint
*) src
);
184 for (i
= 0; i
< n
; i
++) {
185 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
186 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
187 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
188 dst
[i
][ACOMP
] = 1.0f
;
193 unpack_RGB888(const void *src
, GLfloat dst
[][4], GLuint n
)
195 const GLubyte
*s
= (const GLubyte
*) src
;
197 for (i
= 0; i
< n
; i
++) {
198 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+2] );
199 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+1] );
200 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+0] );
201 dst
[i
][ACOMP
] = 1.0F
;
206 unpack_BGR888(const void *src
, GLfloat dst
[][4], GLuint n
)
208 const GLubyte
*s
= (const GLubyte
*) src
;
210 for (i
= 0; i
< n
; i
++) {
211 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+0] );
212 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+1] );
213 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+2] );
214 dst
[i
][ACOMP
] = 1.0F
;
219 unpack_RGB565(const void *src
, GLfloat dst
[][4], GLuint n
)
221 const GLushort
*s
= ((const GLushort
*) src
);
223 for (i
= 0; i
< n
; i
++) {
224 dst
[i
][RCOMP
] = ((s
[i
] >> 11) & 0x1f) * (1.0F
/ 31.0F
);
225 dst
[i
][GCOMP
] = ((s
[i
] >> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
226 dst
[i
][BCOMP
] = ((s
[i
] ) & 0x1f) * (1.0F
/ 31.0F
);
227 dst
[i
][ACOMP
] = 1.0F
;
232 unpack_RGB565_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
234 const GLushort
*s
= ((const GLushort
*) src
);
236 for (i
= 0; i
< n
; i
++) {
237 GLuint t
= (s
[i
] >> 8) | (s
[i
] << 8); /* byte swap */
238 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( ((t
>> 8) & 0xf8) | ((t
>> 13) & 0x7) );
239 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( ((t
>> 3) & 0xfc) | ((t
>> 9) & 0x3) );
240 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( ((t
<< 3) & 0xf8) | ((t
>> 2) & 0x7) );
241 dst
[i
][ACOMP
] = 1.0F
;
246 unpack_ARGB4444(const void *src
, GLfloat dst
[][4], GLuint n
)
248 const GLushort
*s
= ((const GLushort
*) src
);
250 for (i
= 0; i
< n
; i
++) {
251 dst
[i
][RCOMP
] = ((s
[i
] >> 8) & 0xf) * (1.0F
/ 15.0F
);
252 dst
[i
][GCOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
253 dst
[i
][BCOMP
] = ((s
[i
] ) & 0xf) * (1.0F
/ 15.0F
);
254 dst
[i
][ACOMP
] = ((s
[i
] >> 12) & 0xf) * (1.0F
/ 15.0F
);
259 unpack_ARGB4444_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
261 const GLushort
*s
= ((const GLushort
*) src
);
263 for (i
= 0; i
< n
; i
++) {
264 dst
[i
][RCOMP
] = ((s
[i
] ) & 0xf) * (1.0F
/ 15.0F
);
265 dst
[i
][GCOMP
] = ((s
[i
] >> 12) & 0xf) * (1.0F
/ 15.0F
);
266 dst
[i
][BCOMP
] = ((s
[i
] >> 8) & 0xf) * (1.0F
/ 15.0F
);
267 dst
[i
][ACOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
272 unpack_RGBA5551(const void *src
, GLfloat dst
[][4], GLuint n
)
274 const GLushort
*s
= ((const GLushort
*) src
);
276 for (i
= 0; i
< n
; i
++) {
277 dst
[i
][RCOMP
] = ((s
[i
] >> 11) & 0x1f) * (1.0F
/ 31.0F
);
278 dst
[i
][GCOMP
] = ((s
[i
] >> 6) & 0x1f) * (1.0F
/ 31.0F
);
279 dst
[i
][BCOMP
] = ((s
[i
] >> 1) & 0x1f) * (1.0F
/ 31.0F
);
280 dst
[i
][ACOMP
] = ((s
[i
] ) & 0x01) * 1.0F
;
285 unpack_ARGB1555(const void *src
, GLfloat dst
[][4], GLuint n
)
287 const GLushort
*s
= ((const GLushort
*) src
);
289 for (i
= 0; i
< n
; i
++) {
290 dst
[i
][RCOMP
] = ((s
[i
] >> 10) & 0x1f) * (1.0F
/ 31.0F
);
291 dst
[i
][GCOMP
] = ((s
[i
] >> 5) & 0x1f) * (1.0F
/ 31.0F
);
292 dst
[i
][BCOMP
] = ((s
[i
] >> 0) & 0x1f) * (1.0F
/ 31.0F
);
293 dst
[i
][ACOMP
] = ((s
[i
] >> 15) & 0x01) * 1.0F
;
298 unpack_ARGB1555_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
300 const GLushort
*s
= ((const GLushort
*) src
);
302 for (i
= 0; i
< n
; i
++) {
303 GLushort tmp
= (s
[i
] << 8) | (s
[i
] >> 8); /* byteswap */
304 dst
[i
][RCOMP
] = ((tmp
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
305 dst
[i
][GCOMP
] = ((tmp
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
306 dst
[i
][BCOMP
] = ((tmp
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
307 dst
[i
][ACOMP
] = ((tmp
>> 15) & 0x01) * 1.0F
;
312 unpack_AL44(const void *src
, GLfloat dst
[][4], GLuint n
)
314 const GLubyte
*s
= ((const GLubyte
*) src
);
316 for (i
= 0; i
< n
; i
++) {
319 dst
[i
][BCOMP
] = (s
[i
] & 0xf) * (1.0F
/ 15.0F
);
320 dst
[i
][ACOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
325 unpack_AL88(const void *src
, GLfloat dst
[][4], GLuint n
)
327 const GLushort
*s
= ((const GLushort
*) src
);
329 for (i
= 0; i
< n
; i
++) {
332 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
333 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
338 unpack_AL88_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
340 const GLushort
*s
= ((const GLushort
*) src
);
342 for (i
= 0; i
< n
; i
++) {
345 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
346 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
351 unpack_AL1616(const void *src
, GLfloat dst
[][4], GLuint n
)
353 const GLuint
*s
= ((const GLuint
*) src
);
355 for (i
= 0; i
< n
; i
++) {
358 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
359 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
364 unpack_AL1616_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
366 const GLuint
*s
= ((const GLuint
*) src
);
368 for (i
= 0; i
< n
; i
++) {
371 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
372 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
377 unpack_RGB332(const void *src
, GLfloat dst
[][4], GLuint n
)
379 const GLubyte
*s
= ((const GLubyte
*) src
);
381 for (i
= 0; i
< n
; i
++) {
382 dst
[i
][RCOMP
] = ((s
[i
] >> 5) & 0x7) * (1.0F
/ 7.0F
);
383 dst
[i
][GCOMP
] = ((s
[i
] >> 2) & 0x7) * (1.0F
/ 7.0F
);
384 dst
[i
][BCOMP
] = ((s
[i
] ) & 0x3) * (1.0F
/ 3.0F
);
385 dst
[i
][ACOMP
] = 1.0F
;
391 unpack_A8(const void *src
, GLfloat dst
[][4], GLuint n
)
393 const GLubyte
*s
= ((const GLubyte
*) src
);
395 for (i
= 0; i
< n
; i
++) {
398 dst
[i
][BCOMP
] = 0.0F
;
399 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
]);
404 unpack_A16(const void *src
, GLfloat dst
[][4], GLuint n
)
406 const GLushort
*s
= ((const GLushort
*) src
);
408 for (i
= 0; i
< n
; i
++) {
411 dst
[i
][BCOMP
] = 0.0F
;
412 dst
[i
][ACOMP
] = USHORT_TO_FLOAT(s
[i
]);
417 unpack_L8(const void *src
, GLfloat dst
[][4], GLuint n
)
419 const GLubyte
*s
= ((const GLubyte
*) src
);
421 for (i
= 0; i
< n
; i
++) {
424 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT(s
[i
]);
425 dst
[i
][ACOMP
] = 1.0F
;
430 unpack_L16(const void *src
, GLfloat dst
[][4], GLuint n
)
432 const GLushort
*s
= ((const GLushort
*) src
);
434 for (i
= 0; i
< n
; i
++) {
437 dst
[i
][BCOMP
] = USHORT_TO_FLOAT(s
[i
]);
438 dst
[i
][ACOMP
] = 1.0F
;
443 unpack_I8(const void *src
, GLfloat dst
[][4], GLuint n
)
445 const GLubyte
*s
= ((const GLubyte
*) src
);
447 for (i
= 0; i
< n
; i
++) {
451 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
]);
456 unpack_I16(const void *src
, GLfloat dst
[][4], GLuint n
)
458 const GLushort
*s
= ((const GLushort
*) src
);
460 for (i
= 0; i
< n
; i
++) {
464 dst
[i
][ACOMP
] = USHORT_TO_FLOAT(s
[i
]);
469 unpack_YCBCR(const void *src
, GLfloat dst
[][4], GLuint n
)
472 for (i
= 0; i
< n
; i
++) {
473 const GLushort
*src0
= ((const GLushort
*) src
) + i
* 2; /* even */
474 const GLushort
*src1
= src0
+ 1; /* odd */
475 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
476 const GLubyte cb
= *src0
& 0xff; /* chroma U */
477 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
478 const GLubyte cr
= *src1
& 0xff; /* chroma V */
479 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
480 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
481 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
482 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
483 r
*= (1.0F
/ 255.0F
);
484 g
*= (1.0F
/ 255.0F
);
485 b
*= (1.0F
/ 255.0F
);
486 dst
[i
][RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
487 dst
[i
][GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
488 dst
[i
][BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
489 dst
[i
][ACOMP
] = 1.0F
;
494 unpack_YCBCR_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
497 for (i
= 0; i
< n
; i
++) {
498 const GLushort
*src0
= ((const GLushort
*) src
) + i
* 2; /* even */
499 const GLushort
*src1
= src0
+ 1; /* odd */
500 const GLubyte y0
= *src0
& 0xff; /* luminance */
501 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
502 const GLubyte y1
= *src1
& 0xff; /* luminance */
503 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
504 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
505 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
506 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
507 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
508 r
*= (1.0F
/ 255.0F
);
509 g
*= (1.0F
/ 255.0F
);
510 b
*= (1.0F
/ 255.0F
);
511 dst
[i
][RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
512 dst
[i
][GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
513 dst
[i
][BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
514 dst
[i
][ACOMP
] = 1.0F
;
519 unpack_R8(const void *src
, GLfloat dst
[][4], GLuint n
)
521 const GLubyte
*s
= ((const GLubyte
*) src
);
523 for (i
= 0; i
< n
; i
++) {
524 dst
[i
][0] = UBYTE_TO_FLOAT(s
[i
]);
532 unpack_GR88(const void *src
, GLfloat dst
[][4], GLuint n
)
534 const GLushort
*s
= ((const GLushort
*) src
);
536 for (i
= 0; i
< n
; i
++) {
537 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
538 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
545 unpack_RG88(const void *src
, GLfloat dst
[][4], GLuint n
)
547 const GLushort
*s
= ((const GLushort
*) src
);
549 for (i
= 0; i
< n
; i
++) {
550 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
551 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
558 unpack_R16(const void *src
, GLfloat dst
[][4], GLuint n
)
560 const GLushort
*s
= ((const GLushort
*) src
);
562 for (i
= 0; i
< n
; i
++) {
563 dst
[i
][RCOMP
] = USHORT_TO_FLOAT(s
[i
]);
571 unpack_RG1616(const void *src
, GLfloat dst
[][4], GLuint n
)
573 const GLuint
*s
= ((const GLuint
*) src
);
575 for (i
= 0; i
< n
; i
++) {
576 dst
[i
][RCOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
577 dst
[i
][GCOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
584 unpack_RG1616_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
586 const GLuint
*s
= ((const GLuint
*) src
);
588 for (i
= 0; i
< n
; i
++) {
589 dst
[i
][RCOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
590 dst
[i
][GCOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
597 unpack_ARGB2101010(const void *src
, GLfloat dst
[][4], GLuint n
)
599 const GLuint
*s
= ((const GLuint
*) src
);
601 for (i
= 0; i
< n
; i
++) {
602 dst
[i
][RCOMP
] = ((s
[i
] >> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
603 dst
[i
][GCOMP
] = ((s
[i
] >> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
604 dst
[i
][BCOMP
] = ((s
[i
] >> 0) & 0x3ff) * (1.0F
/ 1023.0F
);
605 dst
[i
][ACOMP
] = ((s
[i
] >> 30) & 0x03) * (1.0F
/ 3.0F
);
611 unpack_Z24_S8(const void *src
, GLfloat dst
[][4], GLuint n
)
613 /* only return Z, not stencil data */
614 const GLuint
*s
= ((const GLuint
*) src
);
615 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
617 for (i
= 0; i
< n
; i
++) {
620 dst
[i
][2] = (s
[i
] >> 8) * scale
;
622 ASSERT(dst
[i
][0] >= 0.0F
);
623 ASSERT(dst
[i
][0] <= 1.0F
);
628 unpack_S8_Z24(const void *src
, GLfloat dst
[][4], GLuint n
)
630 /* only return Z, not stencil data */
631 const GLuint
*s
= ((const GLuint
*) src
);
632 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
634 for (i
= 0; i
< n
; i
++) {
637 dst
[i
][2] = (s
[i
] & 0x00ffffff) * scale
;
639 ASSERT(dst
[i
][0] >= 0.0F
);
640 ASSERT(dst
[i
][0] <= 1.0F
);
645 unpack_Z16(const void *src
, GLfloat dst
[][4], GLuint n
)
647 const GLushort
*s
= ((const GLushort
*) src
);
649 for (i
= 0; i
< n
; i
++) {
652 dst
[i
][2] = s
[i
] * (1.0F
/ 65535.0F
);
658 unpack_X8_Z24(const void *src
, GLfloat dst
[][4], GLuint n
)
660 unpack_S8_Z24(src
, dst
, n
);
664 unpack_Z24_X8(const void *src
, GLfloat dst
[][4], GLuint n
)
666 unpack_Z24_S8(src
, dst
, n
);
670 unpack_Z32(const void *src
, GLfloat dst
[][4], GLuint n
)
672 const GLuint
*s
= ((const GLuint
*) src
);
674 for (i
= 0; i
< n
; i
++) {
677 dst
[i
][2] = s
[i
] * (1.0F
/ 0xffffffff);
683 unpack_Z32_FLOAT(const void *src
, GLfloat dst
[][4], GLuint n
)
685 const GLfloat
*s
= ((const GLfloat
*) src
);
687 for (i
= 0; i
< n
; i
++) {
690 dst
[i
][2] = s
[i
* 2];
696 unpack_Z32_FLOAT_X24S8(const void *src
, GLfloat dst
[][4], GLuint n
)
698 const GLfloat
*s
= ((const GLfloat
*) src
);
700 for (i
= 0; i
< n
; i
++) {
710 unpack_S8(const void *src
, GLfloat dst
[][4], GLuint n
)
712 /* should never be used */
714 for (i
= 0; i
< n
; i
++) {
724 unpack_SRGB8(const void *src
, GLfloat dst
[][4], GLuint n
)
726 const GLubyte
*s
= (const GLubyte
*) src
;
728 for (i
= 0; i
< n
; i
++) {
729 dst
[i
][RCOMP
] = nonlinear_to_linear(s
[i
*3+2]);
730 dst
[i
][GCOMP
] = nonlinear_to_linear(s
[i
*3+1]);
731 dst
[i
][BCOMP
] = nonlinear_to_linear(s
[i
*3+0]);
732 dst
[i
][ACOMP
] = 1.0F
;
737 unpack_SRGBA8(const void *src
, GLfloat dst
[][4], GLuint n
)
739 const GLuint
*s
= ((const GLuint
*) src
);
741 for (i
= 0; i
< n
; i
++) {
742 dst
[i
][RCOMP
] = nonlinear_to_linear( (s
[i
] >> 24) );
743 dst
[i
][GCOMP
] = nonlinear_to_linear( (s
[i
] >> 16) & 0xff );
744 dst
[i
][BCOMP
] = nonlinear_to_linear( (s
[i
] >> 8) & 0xff );
745 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff ); /* linear! */
750 unpack_SARGB8(const void *src
, GLfloat dst
[][4], GLuint n
)
752 const GLuint
*s
= ((const GLuint
*) src
);
754 for (i
= 0; i
< n
; i
++) {
755 dst
[i
][RCOMP
] = nonlinear_to_linear( (s
[i
] >> 16) & 0xff );
756 dst
[i
][GCOMP
] = nonlinear_to_linear( (s
[i
] >> 8) & 0xff );
757 dst
[i
][BCOMP
] = nonlinear_to_linear( (s
[i
] ) & 0xff );
758 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 24 ); /* linear! */
763 unpack_SL8(const void *src
, GLfloat dst
[][4], GLuint n
)
765 const GLubyte
*s
= ((const GLubyte
*) src
);
767 for (i
= 0; i
< n
; i
++) {
770 dst
[i
][BCOMP
] = nonlinear_to_linear(s
[i
]);
771 dst
[i
][ACOMP
] = 1.0F
;
776 unpack_SLA8(const void *src
, GLfloat dst
[][4], GLuint n
)
778 const GLushort
*s
= (const GLushort
*) src
;
780 for (i
= 0; i
< n
; i
++) {
783 dst
[i
][BCOMP
] = nonlinear_to_linear(s
[i
] & 0xff);
784 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
] >> 8); /* linear! */
789 unpack_SRGB_DXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
794 unpack_SRGBA_DXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
799 unpack_SRGBA_DXT3(const void *src
, GLfloat dst
[][4], GLuint n
)
804 unpack_SRGBA_DXT5(const void *src
, GLfloat dst
[][4], GLuint n
)
809 unpack_RGB_FXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
814 unpack_RGBA_FXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
819 unpack_RGB_DXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
824 unpack_RGBA_DXT1(const void *src
, GLfloat dst
[][4], GLuint n
)
829 unpack_RGBA_DXT3(const void *src
, GLfloat dst
[][4], GLuint n
)
834 unpack_RGBA_DXT5(const void *src
, GLfloat dst
[][4], GLuint n
)
840 unpack_RGBA_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
842 const GLfloat
*s
= (const GLfloat
*) src
;
844 for (i
= 0; i
< n
; i
++) {
845 dst
[i
][RCOMP
] = s
[i
*4+0];
846 dst
[i
][GCOMP
] = s
[i
*4+1];
847 dst
[i
][BCOMP
] = s
[i
*4+2];
848 dst
[i
][ACOMP
] = s
[i
*4+3];
853 unpack_RGBA_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
855 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
857 for (i
= 0; i
< n
; i
++) {
858 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
*4+0]);
859 dst
[i
][GCOMP
] = _mesa_half_to_float(s
[i
*4+1]);
860 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
*4+2]);
861 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
*4+3]);
866 unpack_RGB_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
868 const GLfloat
*s
= (const GLfloat
*) src
;
870 for (i
= 0; i
< n
; i
++) {
871 dst
[i
][RCOMP
] = s
[i
*3+0];
872 dst
[i
][GCOMP
] = s
[i
*3+1];
873 dst
[i
][BCOMP
] = s
[i
*3+2];
874 dst
[i
][ACOMP
] = 1.0F
;
879 unpack_RGB_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
881 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
883 for (i
= 0; i
< n
; i
++) {
884 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
*3+0]);
885 dst
[i
][GCOMP
] = _mesa_half_to_float(s
[i
*3+1]);
886 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
*3+2]);
887 dst
[i
][ACOMP
] = 1.0F
;
892 unpack_ALPHA_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
894 const GLfloat
*s
= (const GLfloat
*) src
;
896 for (i
= 0; i
< n
; i
++) {
899 dst
[i
][BCOMP
] = 0.0F
;
900 dst
[i
][ACOMP
] = s
[i
];
905 unpack_ALPHA_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
907 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
909 for (i
= 0; i
< n
; i
++) {
912 dst
[i
][BCOMP
] = 0.0F
;
913 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
]);
918 unpack_LUMINANCE_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
920 const GLfloat
*s
= (const GLfloat
*) src
;
922 for (i
= 0; i
< n
; i
++) {
925 dst
[i
][BCOMP
] = s
[i
];
926 dst
[i
][ACOMP
] = 1.0F
;
931 unpack_LUMINANCE_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
933 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
935 for (i
= 0; i
< n
; i
++) {
938 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
]);
939 dst
[i
][ACOMP
] = 1.0F
;
944 unpack_LUMINANCE_ALPHA_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
946 const GLfloat
*s
= (const GLfloat
*) src
;
948 for (i
= 0; i
< n
; i
++) {
951 dst
[i
][BCOMP
] = s
[i
*2+0];
952 dst
[i
][ACOMP
] = s
[i
*2+1];
957 unpack_LUMINANCE_ALPHA_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
959 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
961 for (i
= 0; i
< n
; i
++) {
964 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
*2+0]);
965 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
*2+1]);
970 unpack_INTENSITY_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
972 const GLfloat
*s
= (const GLfloat
*) src
;
974 for (i
= 0; i
< n
; i
++) {
978 dst
[i
][ACOMP
] = s
[i
];
983 unpack_INTENSITY_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
985 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
987 for (i
= 0; i
< n
; i
++) {
991 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
]);
996 unpack_R_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
998 const GLfloat
*s
= (const GLfloat
*) src
;
1000 for (i
= 0; i
< n
; i
++) {
1001 dst
[i
][RCOMP
] = s
[i
];
1002 dst
[i
][GCOMP
] = 0.0F
;
1003 dst
[i
][BCOMP
] = 0.0F
;
1004 dst
[i
][ACOMP
] = 1.0F
;
1009 unpack_R_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1011 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
1013 for (i
= 0; i
< n
; i
++) {
1014 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
]);
1015 dst
[i
][GCOMP
] = 0.0F
;
1016 dst
[i
][BCOMP
] = 0.0F
;
1017 dst
[i
][ACOMP
] = 1.0F
;
1022 unpack_RG_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
1024 const GLfloat
*s
= (const GLfloat
*) src
;
1026 for (i
= 0; i
< n
; i
++) {
1027 dst
[i
][RCOMP
] = s
[i
*2+0];
1028 dst
[i
][GCOMP
] = s
[i
*2+1];
1029 dst
[i
][BCOMP
] = 0.0F
;
1030 dst
[i
][ACOMP
] = 1.0F
;
1035 unpack_RG_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1037 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
1039 for (i
= 0; i
< n
; i
++) {
1040 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
*2+0]);
1041 dst
[i
][GCOMP
] = _mesa_half_to_float(s
[i
*2+1]);
1042 dst
[i
][BCOMP
] = 0.0F
;
1043 dst
[i
][ACOMP
] = 1.0F
;
1049 unpack_RGBA_INT8(const void *src
, GLfloat dst
[][4], GLuint n
)
1051 const GLbyte
*s
= (const GLbyte
*) src
;
1053 for (i
= 0; i
< n
; i
++) {
1054 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1055 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1056 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1057 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1062 unpack_RGBA_INT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1064 const GLshort
*s
= (const GLshort
*) src
;
1066 for (i
= 0; i
< n
; i
++) {
1067 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1068 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1069 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1070 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1075 unpack_RGBA_INT32(const void *src
, GLfloat dst
[][4], GLuint n
)
1077 const GLint
*s
= (const GLint
*) src
;
1079 for (i
= 0; i
< n
; i
++) {
1080 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1081 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1082 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1083 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1088 unpack_RGBA_UINT8(const void *src
, GLfloat dst
[][4], GLuint n
)
1090 const GLubyte
*s
= (const GLubyte
*) src
;
1092 for (i
= 0; i
< n
; i
++) {
1093 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1094 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1095 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1096 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1101 unpack_RGBA_UINT16(const void *src
, GLfloat dst
[][4], GLuint n
)
1103 const GLushort
*s
= (const GLushort
*) src
;
1105 for (i
= 0; i
< n
; i
++) {
1106 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1107 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1108 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1109 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1114 unpack_RGBA_UINT32(const void *src
, GLfloat dst
[][4], GLuint n
)
1116 const GLuint
*s
= (const GLuint
*) src
;
1118 for (i
= 0; i
< n
; i
++) {
1119 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
1120 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
1121 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
1122 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
1127 unpack_DUDV8(const void *src
, GLfloat dst
[][4], GLuint n
)
1129 const GLbyte
*s
= (const GLbyte
*) src
;
1131 for (i
= 0; i
< n
; i
++) {
1132 dst
[i
][RCOMP
] = BYTE_TO_FLOAT(s
[i
*2+0]);
1133 dst
[i
][GCOMP
] = BYTE_TO_FLOAT(s
[i
*2+1]);
1140 unpack_SIGNED_R8(const void *src
, GLfloat dst
[][4], GLuint n
)
1142 const GLbyte
*s
= ((const GLbyte
*) src
);
1144 for (i
= 0; i
< n
; i
++) {
1145 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( s
[i
] );
1146 dst
[i
][GCOMP
] = 0.0F
;
1147 dst
[i
][BCOMP
] = 0.0F
;
1148 dst
[i
][ACOMP
] = 1.0F
;
1153 unpack_SIGNED_RG88_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
1155 const GLushort
*s
= ((const GLushort
*) src
);
1157 for (i
= 0; i
< n
; i
++) {
1158 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] & 0xff) );
1159 dst
[i
][GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1160 dst
[i
][BCOMP
] = 0.0F
;
1161 dst
[i
][ACOMP
] = 1.0F
;
1166 unpack_SIGNED_RGBX8888(const void *src
, GLfloat dst
[][4], GLuint n
)
1168 const GLuint
*s
= ((const GLuint
*) src
);
1170 for (i
= 0; i
< n
; i
++) {
1171 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 24) );
1172 dst
[i
][GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 16) );
1173 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1174 dst
[i
][ACOMP
] = 1.0f
;
1179 unpack_SIGNED_RGBA8888(const void *src
, GLfloat dst
[][4], GLuint n
)
1181 const GLuint
*s
= ((const GLuint
*) src
);
1183 for (i
= 0; i
< n
; i
++) {
1184 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 24) );
1185 dst
[i
][GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 16) );
1186 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1187 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] ) );
1192 unpack_SIGNED_RGBA8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
1194 const GLuint
*s
= ((const GLuint
*) src
);
1196 for (i
= 0; i
< n
; i
++) {
1197 dst
[i
][RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] ) );
1198 dst
[i
][GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1199 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 16) );
1200 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 24) );
1205 unpack_SIGNED_R16(const void *src
, GLfloat dst
[][4], GLuint n
)
1207 const GLshort
*s
= ((const GLshort
*) src
);
1209 for (i
= 0; i
< n
; i
++) {
1210 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
] );
1211 dst
[i
][GCOMP
] = 0.0F
;
1212 dst
[i
][BCOMP
] = 0.0F
;
1213 dst
[i
][ACOMP
] = 1.0F
;
1218 unpack_SIGNED_GR1616(const void *src
, GLfloat dst
[][4], GLuint n
)
1220 const GLuint
*s
= ((const GLuint
*) src
);
1222 for (i
= 0; i
< n
; i
++) {
1223 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( (GLshort
) (s
[i
] & 0xffff) );
1224 dst
[i
][GCOMP
] = SHORT_TO_FLOAT_TEX( (GLshort
) (s
[i
] >> 16) );
1225 dst
[i
][BCOMP
] = 0.0F
;
1226 dst
[i
][ACOMP
] = 1.0F
;
1231 unpack_SIGNED_RGB_16(const void *src
, GLfloat dst
[][4], GLuint n
)
1233 const GLshort
*s
= (const GLshort
*) src
;
1235 for (i
= 0; i
< n
; i
++) {
1236 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*3+0] );
1237 dst
[i
][GCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*3+1] );
1238 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*3+2] );
1239 dst
[i
][ACOMP
] = 1.0F
;
1244 unpack_SIGNED_RGBA_16(const void *src
, GLfloat dst
[][4], GLuint n
)
1246 const GLshort
*s
= (const GLshort
*) src
;
1248 for (i
= 0; i
< n
; i
++) {
1249 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+0] );
1250 dst
[i
][GCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+1] );
1251 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+2] );
1252 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+3] );
1257 unpack_RGBA_16(const void *src
, GLfloat dst
[][4], GLuint n
)
1259 const GLushort
*s
= (const GLushort
*) src
;
1261 for (i
= 0; i
< n
; i
++) {
1262 dst
[i
][RCOMP
] = USHORT_TO_FLOAT( s
[i
*4+0] );
1263 dst
[i
][GCOMP
] = USHORT_TO_FLOAT( s
[i
*4+1] );
1264 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
*4+2] );
1265 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
*4+3] );
1270 unpack_RED_RGTC1(const void *src
, GLfloat dst
[][4], GLuint n
)
1276 unpack_SIGNED_RED_RGTC1(const void *src
, GLfloat dst
[][4], GLuint n
)
1282 unpack_RG_RGTC2(const void *src
, GLfloat dst
[][4], GLuint n
)
1288 unpack_SIGNED_RG_RGTC2(const void *src
, GLfloat dst
[][4], GLuint n
)
1294 unpack_L_LATC1(const void *src
, GLfloat dst
[][4], GLuint n
)
1300 unpack_SIGNED_L_LATC1(const void *src
, GLfloat dst
[][4], GLuint n
)
1306 unpack_LA_LATC2(const void *src
, GLfloat dst
[][4], GLuint n
)
1312 unpack_SIGNED_LA_LATC2(const void *src
, GLfloat dst
[][4], GLuint n
)
1318 unpack_ETC1_RGB8(const void *src
, GLfloat dst
[][4], GLuint n
)
1324 unpack_SIGNED_A8(const void *src
, GLfloat dst
[][4], GLuint n
)
1326 const GLbyte
*s
= ((const GLbyte
*) src
);
1328 for (i
= 0; i
< n
; i
++) {
1329 dst
[i
][RCOMP
] = 0.0F
;
1330 dst
[i
][GCOMP
] = 0.0F
;
1331 dst
[i
][BCOMP
] = 0.0F
;
1332 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( s
[i
] );
1337 unpack_SIGNED_L8(const void *src
, GLfloat dst
[][4], GLuint n
)
1339 const GLbyte
*s
= ((const GLbyte
*) src
);
1341 for (i
= 0; i
< n
; i
++) {
1344 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( s
[i
] );
1345 dst
[i
][ACOMP
] = 1.0F
;
1350 unpack_SIGNED_AL88(const void *src
, GLfloat dst
[][4], GLuint n
)
1352 const GLshort
*s
= ((const GLshort
*) src
);
1354 for (i
= 0; i
< n
; i
++) {
1357 dst
[i
][BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] & 0xff) );
1358 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
[i
] >> 8) );
1363 unpack_SIGNED_I8(const void *src
, GLfloat dst
[][4], GLuint n
)
1365 const GLbyte
*s
= ((const GLbyte
*) src
);
1367 for (i
= 0; i
< n
; i
++) {
1371 dst
[i
][ACOMP
] = BYTE_TO_FLOAT_TEX( s
[i
] );
1376 unpack_SIGNED_A16(const void *src
, GLfloat dst
[][4], GLuint n
)
1378 const GLshort
*s
= ((const GLshort
*) src
);
1380 for (i
= 0; i
< n
; i
++) {
1381 dst
[i
][RCOMP
] = 0.0F
;
1382 dst
[i
][GCOMP
] = 0.0F
;
1383 dst
[i
][BCOMP
] = 0.0F
;
1384 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
] );
1389 unpack_SIGNED_L16(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
] );
1397 dst
[i
][ACOMP
] = 1.0F
;
1402 unpack_SIGNED_AL1616(const void *src
, GLfloat dst
[][4], GLuint n
)
1404 const GLshort
*s
= (const GLshort
*) src
;
1406 for (i
= 0; i
< n
; i
++) {
1409 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*2+0] );
1410 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*2+1] );
1415 unpack_SIGNED_I16(const void *src
, GLfloat dst
[][4], GLuint n
)
1417 const GLshort
*s
= ((const GLshort
*) src
);
1419 for (i
= 0; i
< n
; i
++) {
1423 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
] );
1428 unpack_RGB9_E5_FLOAT(const void *src
, GLfloat dst
[][4], GLuint n
)
1430 const GLuint
*s
= (const GLuint
*) src
;
1432 for (i
= 0; i
< n
; i
++) {
1433 rgb9e5_to_float3(s
[i
], dst
[i
]);
1434 dst
[i
][ACOMP
] = 1.0F
;
1439 unpack_R11_G11_B10_FLOAT(const void *src
, GLfloat dst
[][4], GLuint n
)
1441 const GLuint
*s
= (const GLuint
*) src
;
1443 for (i
= 0; i
< n
; i
++) {
1444 r11g11b10f_to_float3(s
[i
], dst
[i
]);
1445 dst
[i
][ACOMP
] = 1.0F
;
1451 * Return the unpacker function for the given format.
1453 static unpack_rgba_func
1454 get_unpack_rgba_function(gl_format format
)
1456 static unpack_rgba_func table
[MESA_FORMAT_COUNT
];
1457 static GLboolean initialized
= GL_FALSE
;
1460 table
[MESA_FORMAT_NONE
] = NULL
;
1462 table
[MESA_FORMAT_RGBA8888
] = unpack_RGBA8888
;
1463 table
[MESA_FORMAT_RGBA8888_REV
] = unpack_RGBA8888_REV
;
1464 table
[MESA_FORMAT_ARGB8888
] = unpack_ARGB8888
;
1465 table
[MESA_FORMAT_ARGB8888_REV
] = unpack_ARGB8888_REV
;
1466 table
[MESA_FORMAT_RGBX8888
] = unpack_RGBX8888
;
1467 table
[MESA_FORMAT_RGBX8888_REV
] = unpack_RGBX8888_REV
;
1468 table
[MESA_FORMAT_XRGB8888
] = unpack_XRGB8888
;
1469 table
[MESA_FORMAT_XRGB8888_REV
] = unpack_XRGB8888_REV
;
1470 table
[MESA_FORMAT_RGB888
] = unpack_RGB888
;
1471 table
[MESA_FORMAT_BGR888
] = unpack_BGR888
;
1472 table
[MESA_FORMAT_RGB565
] = unpack_RGB565
;
1473 table
[MESA_FORMAT_RGB565_REV
] = unpack_RGB565_REV
;
1474 table
[MESA_FORMAT_ARGB4444
] = unpack_ARGB4444
;
1475 table
[MESA_FORMAT_ARGB4444_REV
] = unpack_ARGB4444_REV
;
1476 table
[MESA_FORMAT_RGBA5551
] = unpack_RGBA5551
;
1477 table
[MESA_FORMAT_ARGB1555
] = unpack_ARGB1555
;
1478 table
[MESA_FORMAT_ARGB1555_REV
] = unpack_ARGB1555_REV
;
1479 table
[MESA_FORMAT_AL44
] = unpack_AL44
;
1480 table
[MESA_FORMAT_AL88
] = unpack_AL88
;
1481 table
[MESA_FORMAT_AL88_REV
] = unpack_AL88_REV
;
1482 table
[MESA_FORMAT_AL1616
] = unpack_AL1616
;
1483 table
[MESA_FORMAT_AL1616_REV
] = unpack_AL1616_REV
;
1484 table
[MESA_FORMAT_RGB332
] = unpack_RGB332
;
1485 table
[MESA_FORMAT_A8
] = unpack_A8
;
1486 table
[MESA_FORMAT_A16
] = unpack_A16
;
1487 table
[MESA_FORMAT_L8
] = unpack_L8
;
1488 table
[MESA_FORMAT_L16
] = unpack_L16
;
1489 table
[MESA_FORMAT_I8
] = unpack_I8
;
1490 table
[MESA_FORMAT_I16
] = unpack_I16
;
1491 table
[MESA_FORMAT_YCBCR
] = unpack_YCBCR
;
1492 table
[MESA_FORMAT_YCBCR_REV
] = unpack_YCBCR_REV
;
1493 table
[MESA_FORMAT_R8
] = unpack_R8
;
1494 table
[MESA_FORMAT_GR88
] = unpack_GR88
;
1495 table
[MESA_FORMAT_RG88
] = unpack_RG88
;
1496 table
[MESA_FORMAT_R16
] = unpack_R16
;
1497 table
[MESA_FORMAT_RG1616
] = unpack_RG1616
;
1498 table
[MESA_FORMAT_RG1616_REV
] = unpack_RG1616_REV
;
1499 table
[MESA_FORMAT_ARGB2101010
] = unpack_ARGB2101010
;
1500 table
[MESA_FORMAT_Z24_S8
] = unpack_Z24_S8
;
1501 table
[MESA_FORMAT_S8_Z24
] = unpack_S8_Z24
;
1502 table
[MESA_FORMAT_Z16
] = unpack_Z16
;
1503 table
[MESA_FORMAT_X8_Z24
] = unpack_X8_Z24
;
1504 table
[MESA_FORMAT_Z24_X8
] = unpack_Z24_X8
;
1505 table
[MESA_FORMAT_Z32
] = unpack_Z32
;
1506 table
[MESA_FORMAT_S8
] = unpack_S8
;
1507 table
[MESA_FORMAT_SRGB8
] = unpack_SRGB8
;
1508 table
[MESA_FORMAT_SRGBA8
] = unpack_SRGBA8
;
1509 table
[MESA_FORMAT_SARGB8
] = unpack_SARGB8
;
1510 table
[MESA_FORMAT_SL8
] = unpack_SL8
;
1511 table
[MESA_FORMAT_SLA8
] = unpack_SLA8
;
1512 table
[MESA_FORMAT_SRGB_DXT1
] = unpack_SRGB_DXT1
;
1513 table
[MESA_FORMAT_SRGBA_DXT1
] = unpack_SRGBA_DXT1
;
1514 table
[MESA_FORMAT_SRGBA_DXT3
] = unpack_SRGBA_DXT3
;
1515 table
[MESA_FORMAT_SRGBA_DXT5
] = unpack_SRGBA_DXT5
;
1517 table
[MESA_FORMAT_RGB_FXT1
] = unpack_RGB_FXT1
;
1518 table
[MESA_FORMAT_RGBA_FXT1
] = unpack_RGBA_FXT1
;
1519 table
[MESA_FORMAT_RGB_DXT1
] = unpack_RGB_DXT1
;
1520 table
[MESA_FORMAT_RGBA_DXT1
] = unpack_RGBA_DXT1
;
1521 table
[MESA_FORMAT_RGBA_DXT3
] = unpack_RGBA_DXT3
;
1522 table
[MESA_FORMAT_RGBA_DXT5
] = unpack_RGBA_DXT5
;
1524 table
[MESA_FORMAT_RGBA_FLOAT32
] = unpack_RGBA_FLOAT32
;
1525 table
[MESA_FORMAT_RGBA_FLOAT16
] = unpack_RGBA_FLOAT16
;
1526 table
[MESA_FORMAT_RGB_FLOAT32
] = unpack_RGB_FLOAT32
;
1527 table
[MESA_FORMAT_RGB_FLOAT16
] = unpack_RGB_FLOAT16
;
1528 table
[MESA_FORMAT_ALPHA_FLOAT32
] = unpack_ALPHA_FLOAT32
;
1529 table
[MESA_FORMAT_ALPHA_FLOAT16
] = unpack_ALPHA_FLOAT16
;
1530 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = unpack_LUMINANCE_FLOAT32
;
1531 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = unpack_LUMINANCE_FLOAT16
;
1532 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = unpack_LUMINANCE_ALPHA_FLOAT32
;
1533 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = unpack_LUMINANCE_ALPHA_FLOAT16
;
1534 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = unpack_INTENSITY_FLOAT32
;
1535 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = unpack_INTENSITY_FLOAT16
;
1536 table
[MESA_FORMAT_R_FLOAT32
] = unpack_R_FLOAT32
;
1537 table
[MESA_FORMAT_R_FLOAT16
] = unpack_R_FLOAT16
;
1538 table
[MESA_FORMAT_RG_FLOAT32
] = unpack_RG_FLOAT32
;
1539 table
[MESA_FORMAT_RG_FLOAT16
] = unpack_RG_FLOAT16
;
1541 table
[MESA_FORMAT_RGBA_INT8
] = unpack_RGBA_INT8
;
1542 table
[MESA_FORMAT_RGBA_INT16
] = unpack_RGBA_INT16
;
1543 table
[MESA_FORMAT_RGBA_INT32
] = unpack_RGBA_INT32
;
1544 table
[MESA_FORMAT_RGBA_UINT8
] = unpack_RGBA_UINT8
;
1545 table
[MESA_FORMAT_RGBA_UINT16
] = unpack_RGBA_UINT16
;
1546 table
[MESA_FORMAT_RGBA_UINT32
] = unpack_RGBA_UINT32
;
1548 table
[MESA_FORMAT_DUDV8
] = unpack_DUDV8
;
1549 table
[MESA_FORMAT_SIGNED_R8
] = unpack_SIGNED_R8
;
1550 table
[MESA_FORMAT_SIGNED_RG88_REV
] = unpack_SIGNED_RG88_REV
;
1551 table
[MESA_FORMAT_SIGNED_RGBX8888
] = unpack_SIGNED_RGBX8888
;
1552 table
[MESA_FORMAT_SIGNED_RGBA8888
] = unpack_SIGNED_RGBA8888
;
1553 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = unpack_SIGNED_RGBA8888_REV
;
1554 table
[MESA_FORMAT_SIGNED_R16
] = unpack_SIGNED_R16
;
1555 table
[MESA_FORMAT_SIGNED_GR1616
] = unpack_SIGNED_GR1616
;
1556 table
[MESA_FORMAT_SIGNED_RGB_16
] = unpack_SIGNED_RGB_16
;
1557 table
[MESA_FORMAT_SIGNED_RGBA_16
] = unpack_SIGNED_RGBA_16
;
1558 table
[MESA_FORMAT_RGBA_16
] = unpack_RGBA_16
;
1560 table
[MESA_FORMAT_RED_RGTC1
] = unpack_RED_RGTC1
;
1561 table
[MESA_FORMAT_SIGNED_RED_RGTC1
] = unpack_SIGNED_RED_RGTC1
;
1562 table
[MESA_FORMAT_RG_RGTC2
] = unpack_RG_RGTC2
;
1563 table
[MESA_FORMAT_SIGNED_RG_RGTC2
] = unpack_SIGNED_RG_RGTC2
;
1565 table
[MESA_FORMAT_L_LATC1
] = unpack_L_LATC1
;
1566 table
[MESA_FORMAT_SIGNED_L_LATC1
] = unpack_SIGNED_L_LATC1
;
1567 table
[MESA_FORMAT_LA_LATC2
] = unpack_LA_LATC2
;
1568 table
[MESA_FORMAT_SIGNED_LA_LATC2
] = unpack_SIGNED_LA_LATC2
;
1570 table
[MESA_FORMAT_ETC1_RGB8
] = unpack_ETC1_RGB8
;
1572 table
[MESA_FORMAT_SIGNED_A8
] = unpack_SIGNED_A8
;
1573 table
[MESA_FORMAT_SIGNED_L8
] = unpack_SIGNED_L8
;
1574 table
[MESA_FORMAT_SIGNED_AL88
] = unpack_SIGNED_AL88
;
1575 table
[MESA_FORMAT_SIGNED_I8
] = unpack_SIGNED_I8
;
1576 table
[MESA_FORMAT_SIGNED_A16
] = unpack_SIGNED_A16
;
1577 table
[MESA_FORMAT_SIGNED_L16
] = unpack_SIGNED_L16
;
1578 table
[MESA_FORMAT_SIGNED_AL1616
] = unpack_SIGNED_AL1616
;
1579 table
[MESA_FORMAT_SIGNED_I16
] = unpack_SIGNED_I16
;
1581 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = unpack_RGB9_E5_FLOAT
;
1582 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = unpack_R11_G11_B10_FLOAT
;
1584 table
[MESA_FORMAT_Z32_FLOAT
] = unpack_Z32_FLOAT
;
1585 table
[MESA_FORMAT_Z32_FLOAT_X24S8
] = unpack_Z32_FLOAT_X24S8
;
1587 initialized
= GL_TRUE
;
1590 return table
[format
];
1595 * Unpack rgba colors, returning as GLfloat values.
1598 _mesa_unpack_rgba_row(gl_format format
, GLuint n
,
1599 const void *src
, GLfloat dst
[][4])
1601 unpack_rgba_func unpack
= get_unpack_rgba_function(format
);
1602 unpack(src
, dst
, n
);
1606 /**********************************************************************/
1607 /* Unpack, returning GLubyte colors */
1608 /**********************************************************************/
1612 unpack_ubyte_RGBA8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1614 const GLuint
*s
= ((const GLuint
*) src
);
1616 for (i
= 0; i
< n
; i
++) {
1617 dst
[i
][RCOMP
] = (s
[i
] >> 24);
1618 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1619 dst
[i
][BCOMP
] = (s
[i
] >> 8) & 0xff;
1620 dst
[i
][ACOMP
] = (s
[i
] ) & 0xff;
1625 unpack_ubyte_RGBA8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1627 const GLuint
*s
= ((const GLuint
*) src
);
1629 for (i
= 0; i
< n
; i
++) {
1630 dst
[i
][RCOMP
] = (s
[i
] ) & 0xff;
1631 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1632 dst
[i
][BCOMP
] = (s
[i
] >> 16) & 0xff;
1633 dst
[i
][ACOMP
] = (s
[i
] >> 24);
1638 unpack_ubyte_ARGB8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1640 const GLuint
*s
= ((const GLuint
*) src
);
1642 for (i
= 0; i
< n
; i
++) {
1643 dst
[i
][RCOMP
] = (s
[i
] >> 16) & 0xff;
1644 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1645 dst
[i
][BCOMP
] = (s
[i
] ) & 0xff;
1646 dst
[i
][ACOMP
] = (s
[i
] >> 24);
1651 unpack_ubyte_ARGB8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1653 const GLuint
*s
= ((const GLuint
*) src
);
1655 for (i
= 0; i
< n
; i
++) {
1656 dst
[i
][RCOMP
] = (s
[i
] >> 8) & 0xff;
1657 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1658 dst
[i
][BCOMP
] = (s
[i
] >> 24);
1659 dst
[i
][ACOMP
] = (s
[i
] ) & 0xff;
1664 unpack_ubyte_RGBX8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1666 const GLuint
*s
= ((const GLuint
*) src
);
1668 for (i
= 0; i
< n
; i
++) {
1669 dst
[i
][RCOMP
] = (s
[i
] >> 24);
1670 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1671 dst
[i
][BCOMP
] = (s
[i
] >> 8) & 0xff;
1672 dst
[i
][ACOMP
] = 0xff;
1677 unpack_ubyte_RGBX8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1679 const GLuint
*s
= ((const GLuint
*) src
);
1681 for (i
= 0; i
< n
; i
++) {
1682 dst
[i
][RCOMP
] = (s
[i
] ) & 0xff;
1683 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1684 dst
[i
][BCOMP
] = (s
[i
] >> 16) & 0xff;
1685 dst
[i
][ACOMP
] = 0xff;
1690 unpack_ubyte_XRGB8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1692 const GLuint
*s
= ((const GLuint
*) src
);
1694 for (i
= 0; i
< n
; i
++) {
1695 dst
[i
][RCOMP
] = (s
[i
] >> 16) & 0xff;
1696 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1697 dst
[i
][BCOMP
] = (s
[i
] ) & 0xff;
1698 dst
[i
][ACOMP
] = 0xff;
1703 unpack_ubyte_XRGB8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1705 const GLuint
*s
= ((const GLuint
*) src
);
1707 for (i
= 0; i
< n
; i
++) {
1708 dst
[i
][RCOMP
] = (s
[i
] >> 8) & 0xff;
1709 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1710 dst
[i
][BCOMP
] = (s
[i
] >> 24);
1711 dst
[i
][ACOMP
] = 0xff;
1716 unpack_ubyte_RGB888(const void *src
, GLubyte dst
[][4], GLuint n
)
1718 const GLubyte
*s
= (const GLubyte
*) src
;
1720 for (i
= 0; i
< n
; i
++) {
1721 dst
[i
][RCOMP
] = s
[i
*3+2];
1722 dst
[i
][GCOMP
] = s
[i
*3+1];
1723 dst
[i
][BCOMP
] = s
[i
*3+0];
1724 dst
[i
][ACOMP
] = 0xff;
1729 unpack_ubyte_BGR888(const void *src
, GLubyte dst
[][4], GLuint n
)
1731 const GLubyte
*s
= (const GLubyte
*) src
;
1733 for (i
= 0; i
< n
; i
++) {
1734 dst
[i
][RCOMP
] = s
[i
*3+0];
1735 dst
[i
][GCOMP
] = s
[i
*3+1];
1736 dst
[i
][BCOMP
] = s
[i
*3+2];
1737 dst
[i
][ACOMP
] = 0xff;
1742 unpack_ubyte_RGB565(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_5_8((s
[i
] >> 11) & 0x1f);
1748 dst
[i
][GCOMP
] = EXPAND_6_8((s
[i
] >> 5 ) & 0x3f);
1749 dst
[i
][BCOMP
] = EXPAND_5_8( s
[i
] & 0x1f);
1750 dst
[i
][ACOMP
] = 0xff;
1755 unpack_ubyte_RGB565_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1757 const GLushort
*s
= ((const GLushort
*) src
);
1759 for (i
= 0; i
< n
; i
++) {
1760 GLuint t
= (s
[i
] >> 8) | (s
[i
] << 8); /* byte swap */
1761 dst
[i
][RCOMP
] = EXPAND_5_8((t
>> 11) & 0x1f);
1762 dst
[i
][GCOMP
] = EXPAND_6_8((t
>> 5 ) & 0x3f);
1763 dst
[i
][BCOMP
] = EXPAND_5_8( t
& 0x1f);
1764 dst
[i
][ACOMP
] = 0xff;
1769 unpack_ubyte_ARGB4444(const void *src
, GLubyte dst
[][4], GLuint n
)
1771 const GLushort
*s
= ((const GLushort
*) src
);
1773 for (i
= 0; i
< n
; i
++) {
1774 dst
[i
][RCOMP
] = EXPAND_4_8((s
[i
] >> 8) & 0xf);
1775 dst
[i
][GCOMP
] = EXPAND_4_8((s
[i
] >> 4) & 0xf);
1776 dst
[i
][BCOMP
] = EXPAND_4_8((s
[i
] ) & 0xf);
1777 dst
[i
][ACOMP
] = EXPAND_4_8((s
[i
] >> 12) & 0xf);
1782 unpack_ubyte_ARGB4444_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1784 const GLushort
*s
= ((const GLushort
*) src
);
1786 for (i
= 0; i
< n
; i
++) {
1787 dst
[i
][RCOMP
] = EXPAND_4_8((s
[i
] ) & 0xf);
1788 dst
[i
][GCOMP
] = EXPAND_4_8((s
[i
] >> 12) & 0xf);
1789 dst
[i
][BCOMP
] = EXPAND_4_8((s
[i
] >> 8) & 0xf);
1790 dst
[i
][ACOMP
] = EXPAND_4_8((s
[i
] >> 4) & 0xf);
1795 unpack_ubyte_RGBA5551(const void *src
, GLubyte dst
[][4], GLuint n
)
1797 const GLushort
*s
= ((const GLushort
*) src
);
1799 for (i
= 0; i
< n
; i
++) {
1800 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 11) & 0x1f);
1801 dst
[i
][GCOMP
] = EXPAND_5_8((s
[i
] >> 6) & 0x1f);
1802 dst
[i
][BCOMP
] = EXPAND_5_8((s
[i
] >> 1) & 0x1f);
1803 dst
[i
][ACOMP
] = EXPAND_1_8((s
[i
] ) & 0x01);
1808 unpack_ubyte_ARGB1555(const void *src
, GLubyte dst
[][4], GLuint n
)
1810 const GLushort
*s
= ((const GLushort
*) src
);
1812 for (i
= 0; i
< n
; i
++) {
1813 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 10) & 0x1f);
1814 dst
[i
][GCOMP
] = EXPAND_5_8((s
[i
] >> 5) & 0x1f);
1815 dst
[i
][BCOMP
] = EXPAND_5_8((s
[i
] >> 0) & 0x1f);
1816 dst
[i
][ACOMP
] = EXPAND_1_8((s
[i
] >> 15) & 0x01);
1821 unpack_ubyte_ARGB1555_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1823 const GLushort
*s
= ((const GLushort
*) src
);
1825 for (i
= 0; i
< n
; i
++) {
1826 GLushort tmp
= (s
[i
] << 8) | (s
[i
] >> 8); /* byteswap */
1827 dst
[i
][RCOMP
] = EXPAND_5_8((tmp
>> 10) & 0x1f);
1828 dst
[i
][GCOMP
] = EXPAND_5_8((tmp
>> 5) & 0x1f);
1829 dst
[i
][BCOMP
] = EXPAND_5_8((tmp
>> 0) & 0x1f);
1830 dst
[i
][ACOMP
] = EXPAND_1_8((tmp
>> 15) & 0x01);
1835 unpack_ubyte_AL44(const void *src
, GLubyte dst
[][4], GLuint n
)
1837 const GLubyte
*s
= ((const GLubyte
*) src
);
1839 for (i
= 0; i
< n
; i
++) {
1842 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] & 0xf);
1843 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] >> 4);
1848 unpack_ubyte_AL88(const void *src
, GLubyte dst
[][4], GLuint n
)
1850 const GLushort
*s
= ((const GLushort
*) src
);
1852 for (i
= 0; i
< n
; i
++) {
1855 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] & 0xff);
1856 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] >> 8);
1861 unpack_ubyte_AL88_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1863 const GLushort
*s
= ((const GLushort
*) src
);
1865 for (i
= 0; i
< n
; i
++) {
1868 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] >> 8);
1869 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] & 0xff);
1874 unpack_ubyte_RGB332(const void *src
, GLubyte dst
[][4], GLuint n
)
1876 const GLubyte
*s
= ((const GLubyte
*) src
);
1878 for (i
= 0; i
< n
; i
++) {
1879 dst
[i
][RCOMP
] = EXPAND_3_8((s
[i
] >> 5) & 0x7);
1880 dst
[i
][GCOMP
] = EXPAND_3_8((s
[i
] >> 2) & 0x7);
1881 dst
[i
][BCOMP
] = EXPAND_2_8((s
[i
] ) & 0x3);
1882 dst
[i
][ACOMP
] = 0xff;
1887 unpack_ubyte_A8(const void *src
, GLubyte dst
[][4], GLuint n
)
1889 const GLubyte
*s
= ((const GLubyte
*) src
);
1891 for (i
= 0; i
< n
; i
++) {
1895 dst
[i
][ACOMP
] = s
[i
];
1900 unpack_ubyte_L8(const void *src
, GLubyte dst
[][4], GLuint n
)
1902 const GLubyte
*s
= ((const GLubyte
*) src
);
1904 for (i
= 0; i
< n
; i
++) {
1907 dst
[i
][BCOMP
] = s
[i
];
1908 dst
[i
][ACOMP
] = 0xff;
1914 unpack_ubyte_I8(const void *src
, GLubyte dst
[][4], GLuint n
)
1916 const GLubyte
*s
= ((const GLubyte
*) src
);
1918 for (i
= 0; i
< n
; i
++) {
1922 dst
[i
][ACOMP
] = s
[i
];
1927 unpack_ubyte_R8(const void *src
, GLubyte dst
[][4], GLuint n
)
1929 const GLubyte
*s
= ((const GLubyte
*) src
);
1931 for (i
= 0; i
< n
; i
++) {
1940 unpack_ubyte_GR88(const void *src
, GLubyte dst
[][4], GLuint n
)
1942 const GLushort
*s
= ((const GLushort
*) src
);
1944 for (i
= 0; i
< n
; i
++) {
1945 dst
[i
][RCOMP
] = s
[i
] & 0xff;
1946 dst
[i
][GCOMP
] = s
[i
] >> 8;
1948 dst
[i
][ACOMP
] = 0xff;
1953 unpack_ubyte_RG88(const void *src
, GLubyte dst
[][4], GLuint n
)
1955 const GLushort
*s
= ((const GLushort
*) src
);
1957 for (i
= 0; i
< n
; i
++) {
1958 dst
[i
][RCOMP
] = s
[i
] >> 8;
1959 dst
[i
][GCOMP
] = s
[i
] & 0xff;
1961 dst
[i
][ACOMP
] = 0xff;
1967 * Unpack rgba colors, returning as GLubyte values. This should usually
1968 * only be used for unpacking formats that use 8 bits or less per channel.
1971 _mesa_unpack_ubyte_rgba_row(gl_format format
, GLuint n
,
1972 const void *src
, GLubyte dst
[][4])
1975 case MESA_FORMAT_RGBA8888
:
1976 unpack_ubyte_RGBA8888(src
, dst
, n
);
1978 case MESA_FORMAT_RGBA8888_REV
:
1979 unpack_ubyte_RGBA8888_REV(src
, dst
, n
);
1981 case MESA_FORMAT_ARGB8888
:
1982 unpack_ubyte_ARGB8888(src
, dst
, n
);
1984 case MESA_FORMAT_ARGB8888_REV
:
1985 unpack_ubyte_ARGB8888_REV(src
, dst
, n
);
1987 case MESA_FORMAT_RGBX8888
:
1988 unpack_ubyte_RGBX8888(src
, dst
, n
);
1990 case MESA_FORMAT_RGBX8888_REV
:
1991 unpack_ubyte_RGBX8888_REV(src
, dst
, n
);
1993 case MESA_FORMAT_XRGB8888
:
1994 unpack_ubyte_XRGB8888(src
, dst
, n
);
1996 case MESA_FORMAT_XRGB8888_REV
:
1997 unpack_ubyte_XRGB8888_REV(src
, dst
, n
);
1999 case MESA_FORMAT_RGB888
:
2000 unpack_ubyte_RGB888(src
, dst
, n
);
2002 case MESA_FORMAT_BGR888
:
2003 unpack_ubyte_BGR888(src
, dst
, n
);
2005 case MESA_FORMAT_RGB565
:
2006 unpack_ubyte_RGB565(src
, dst
, n
);
2008 case MESA_FORMAT_RGB565_REV
:
2009 unpack_ubyte_RGB565_REV(src
, dst
, n
);
2011 case MESA_FORMAT_ARGB4444
:
2012 unpack_ubyte_ARGB4444(src
, dst
, n
);
2014 case MESA_FORMAT_ARGB4444_REV
:
2015 unpack_ubyte_ARGB4444_REV(src
, dst
, n
);
2017 case MESA_FORMAT_RGBA5551
:
2018 unpack_ubyte_RGBA5551(src
, dst
, n
);
2020 case MESA_FORMAT_ARGB1555
:
2021 unpack_ubyte_ARGB1555(src
, dst
, n
);
2023 case MESA_FORMAT_ARGB1555_REV
:
2024 unpack_ubyte_ARGB1555_REV(src
, dst
, n
);
2026 case MESA_FORMAT_AL44
:
2027 unpack_ubyte_AL44(src
, dst
, n
);
2029 case MESA_FORMAT_AL88
:
2030 unpack_ubyte_AL88(src
, dst
, n
);
2032 case MESA_FORMAT_AL88_REV
:
2033 unpack_ubyte_AL88_REV(src
, dst
, n
);
2035 case MESA_FORMAT_RGB332
:
2036 unpack_ubyte_RGB332(src
, dst
, n
);
2038 case MESA_FORMAT_A8
:
2039 unpack_ubyte_A8(src
, dst
, n
);
2041 case MESA_FORMAT_L8
:
2042 unpack_ubyte_L8(src
, dst
, n
);
2044 case MESA_FORMAT_I8
:
2045 unpack_ubyte_I8(src
, dst
, n
);
2047 case MESA_FORMAT_R8
:
2048 unpack_ubyte_R8(src
, dst
, n
);
2050 case MESA_FORMAT_GR88
:
2051 unpack_ubyte_GR88(src
, dst
, n
);
2053 case MESA_FORMAT_RG88
:
2054 unpack_ubyte_RG88(src
, dst
, n
);
2057 /* get float values, convert to ubyte */
2059 GLfloat
*tmp
= (GLfloat
*) malloc(n
* 4 * sizeof(GLfloat
));
2062 _mesa_unpack_rgba_row(format
, n
, src
, (GLfloat (*)[4]) tmp
);
2063 for (i
= 0; i
< n
; i
++) {
2064 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][0], tmp
[i
*4+0]);
2065 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][1], tmp
[i
*4+1]);
2066 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][2], tmp
[i
*4+2]);
2067 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][3], tmp
[i
*4+3]);
2077 /**********************************************************************/
2078 /* Unpack, returning GLuint colors */
2079 /**********************************************************************/
2082 unpack_int_rgba_RGBA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2084 memcpy(dst
, src
, n
* 4 * sizeof(GLuint
));
2088 unpack_int_rgba_RGBA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2092 for (i
= 0; i
< n
; i
++) {
2093 dst
[i
][0] = src
[i
* 4 + 0];
2094 dst
[i
][1] = src
[i
* 4 + 1];
2095 dst
[i
][2] = src
[i
* 4 + 2];
2096 dst
[i
][3] = src
[i
* 4 + 3];
2101 unpack_int_rgba_RGBA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2105 for (i
= 0; i
< n
; i
++) {
2106 dst
[i
][0] = src
[i
* 4 + 0];
2107 dst
[i
][1] = src
[i
* 4 + 1];
2108 dst
[i
][2] = src
[i
* 4 + 2];
2109 dst
[i
][3] = src
[i
* 4 + 3];
2114 unpack_int_rgba_RGBA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2118 for (i
= 0; i
< n
; i
++) {
2119 dst
[i
][0] = src
[i
* 4 + 0];
2120 dst
[i
][1] = src
[i
* 4 + 1];
2121 dst
[i
][2] = src
[i
* 4 + 2];
2122 dst
[i
][3] = src
[i
* 4 + 3];
2127 unpack_int_rgba_RGBA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2131 for (i
= 0; i
< n
; i
++) {
2132 dst
[i
][0] = src
[i
* 4 + 0];
2133 dst
[i
][1] = src
[i
* 4 + 1];
2134 dst
[i
][2] = src
[i
* 4 + 2];
2135 dst
[i
][3] = src
[i
* 4 + 3];
2140 unpack_int_rgba_RGB_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2144 for (i
= 0; i
< n
; i
++) {
2145 dst
[i
][0] = src
[i
* 3 + 0];
2146 dst
[i
][1] = src
[i
* 3 + 1];
2147 dst
[i
][2] = src
[i
* 3 + 2];
2153 unpack_int_rgba_RGB_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2157 for (i
= 0; i
< n
; i
++) {
2158 dst
[i
][0] = src
[i
* 3 + 0];
2159 dst
[i
][1] = src
[i
* 3 + 1];
2160 dst
[i
][2] = src
[i
* 3 + 2];
2166 unpack_int_rgba_RGB_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2170 for (i
= 0; i
< n
; i
++) {
2171 dst
[i
][0] = src
[i
* 3 + 0];
2172 dst
[i
][1] = src
[i
* 3 + 1];
2173 dst
[i
][2] = src
[i
* 3 + 2];
2179 unpack_int_rgba_RGB_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2183 for (i
= 0; i
< n
; i
++) {
2184 dst
[i
][0] = src
[i
* 3 + 0];
2185 dst
[i
][1] = src
[i
* 3 + 1];
2186 dst
[i
][2] = src
[i
* 3 + 2];
2192 unpack_int_rgba_RGB_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2196 for (i
= 0; i
< n
; i
++) {
2197 dst
[i
][0] = src
[i
* 3 + 0];
2198 dst
[i
][1] = src
[i
* 3 + 1];
2199 dst
[i
][2] = src
[i
* 3 + 2];
2205 unpack_int_rgba_RG_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2209 for (i
= 0; i
< n
; i
++) {
2210 dst
[i
][0] = src
[i
* 2 + 0];
2211 dst
[i
][1] = src
[i
* 2 + 1];
2218 unpack_int_rgba_RG_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2222 for (i
= 0; i
< n
; i
++) {
2223 dst
[i
][0] = src
[i
* 2 + 0];
2224 dst
[i
][1] = src
[i
* 2 + 1];
2231 unpack_int_rgba_RG_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2235 for (i
= 0; i
< n
; i
++) {
2236 dst
[i
][0] = src
[i
* 2 + 0];
2237 dst
[i
][1] = src
[i
* 2 + 1];
2244 unpack_int_rgba_RG_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2248 for (i
= 0; i
< n
; i
++) {
2249 dst
[i
][0] = src
[i
* 2 + 0];
2250 dst
[i
][1] = src
[i
* 2 + 1];
2257 unpack_int_rgba_RG_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2261 for (i
= 0; i
< n
; i
++) {
2262 dst
[i
][0] = src
[i
* 2 + 0];
2263 dst
[i
][1] = src
[i
* 2 + 1];
2270 unpack_int_rgba_R_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2274 for (i
= 0; i
< n
; i
++) {
2283 unpack_int_rgba_R_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2287 for (i
= 0; i
< n
; i
++) {
2296 unpack_int_rgba_R_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2300 for (i
= 0; i
< n
; i
++) {
2309 unpack_int_rgba_R_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2313 for (i
= 0; i
< n
; i
++) {
2322 unpack_int_rgba_R_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2326 for (i
= 0; i
< n
; i
++) {
2335 unpack_int_rgba_ALPHA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2339 for (i
= 0; i
< n
; i
++) {
2340 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2346 unpack_int_rgba_ALPHA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2350 for (i
= 0; i
< n
; i
++) {
2351 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2357 unpack_int_rgba_ALPHA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2361 for (i
= 0; i
< n
; i
++) {
2362 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2368 unpack_int_rgba_ALPHA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2372 for (i
= 0; i
< n
; i
++) {
2373 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2379 unpack_int_rgba_ALPHA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2383 for (i
= 0; i
< n
; i
++) {
2384 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
2390 unpack_int_rgba_LUMINANCE_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2394 for (i
= 0; i
< n
; i
++) {
2395 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2401 unpack_int_rgba_LUMINANCE_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2405 for (i
= 0; i
< n
; i
++) {
2406 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2412 unpack_int_rgba_LUMINANCE_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2416 for (i
= 0; i
< n
; i
++) {
2417 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2423 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2427 for (i
= 0; i
< n
; i
++) {
2428 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2434 unpack_int_rgba_LUMINANCE_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2438 for (i
= 0; i
< n
; i
++) {
2439 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
2446 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2450 for (i
= 0; i
< n
; i
++) {
2451 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2452 dst
[i
][3] = src
[i
* 2 + 1];
2457 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2461 for (i
= 0; i
< n
; i
++) {
2462 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2463 dst
[i
][3] = src
[i
* 2 + 1];
2468 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2472 for (i
= 0; i
< n
; i
++) {
2473 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2474 dst
[i
][3] = src
[i
* 2 + 1];
2479 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2483 for (i
= 0; i
< n
; i
++) {
2484 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2485 dst
[i
][3] = src
[i
* 2 + 1];
2490 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2494 for (i
= 0; i
< n
; i
++) {
2495 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
2496 dst
[i
][3] = src
[i
* 2 + 1];
2501 unpack_int_rgba_INTENSITY_UINT32(const GLuint
*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 unpack_int_rgba_INTENSITY_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
2515 for (i
= 0; i
< n
; i
++) {
2516 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2521 unpack_int_rgba_INTENSITY_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
2525 for (i
= 0; i
< n
; i
++) {
2526 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2531 unpack_int_rgba_INTENSITY_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
2535 for (i
= 0; i
< n
; i
++) {
2536 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2541 unpack_int_rgba_INTENSITY_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
2545 for (i
= 0; i
< n
; i
++) {
2546 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
2551 unpack_int_rgba_ARGB2101010_UINT(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
2555 for (i
= 0; i
< n
; i
++) {
2556 GLuint tmp
= src
[i
];
2557 dst
[i
][0] = (tmp
>> 20) & 0x3ff;
2558 dst
[i
][1] = (tmp
>> 10) & 0x3ff;
2559 dst
[i
][2] = (tmp
>> 0) & 0x3ff;
2560 dst
[i
][3] = (tmp
>> 30) & 0x3;
2565 _mesa_unpack_uint_rgba_row(gl_format format
, GLuint n
,
2566 const void *src
, GLuint dst
[][4])
2569 /* Since there won't be any sign extension happening, there's no need to
2570 * make separate paths for 32-bit-to-32-bit integer unpack.
2572 case MESA_FORMAT_RGBA_UINT32
:
2573 case MESA_FORMAT_RGBA_INT32
:
2574 unpack_int_rgba_RGBA_UINT32(src
, dst
, n
);
2577 case MESA_FORMAT_RGBA_UINT16
:
2578 unpack_int_rgba_RGBA_UINT16(src
, dst
, n
);
2580 case MESA_FORMAT_RGBA_INT16
:
2581 unpack_int_rgba_RGBA_INT16(src
, dst
, n
);
2584 case MESA_FORMAT_RGBA_UINT8
:
2585 unpack_int_rgba_RGBA_UINT8(src
, dst
, n
);
2587 case MESA_FORMAT_RGBA_INT8
:
2588 unpack_int_rgba_RGBA_INT8(src
, dst
, n
);
2591 case MESA_FORMAT_RGB_UINT32
:
2592 case MESA_FORMAT_RGB_INT32
:
2593 unpack_int_rgba_RGB_UINT32(src
, dst
, n
);
2596 case MESA_FORMAT_RGB_UINT16
:
2597 unpack_int_rgba_RGB_UINT16(src
, dst
, n
);
2599 case MESA_FORMAT_RGB_INT16
:
2600 unpack_int_rgba_RGB_INT16(src
, dst
, n
);
2603 case MESA_FORMAT_RGB_UINT8
:
2604 unpack_int_rgba_RGB_UINT8(src
, dst
, n
);
2606 case MESA_FORMAT_RGB_INT8
:
2607 unpack_int_rgba_RGB_INT8(src
, dst
, n
);
2610 case MESA_FORMAT_RG_UINT32
:
2611 case MESA_FORMAT_RG_INT32
:
2612 unpack_int_rgba_RG_UINT32(src
, dst
, n
);
2615 case MESA_FORMAT_RG_UINT16
:
2616 unpack_int_rgba_RG_UINT16(src
, dst
, n
);
2618 case MESA_FORMAT_RG_INT16
:
2619 unpack_int_rgba_RG_INT16(src
, dst
, n
);
2622 case MESA_FORMAT_RG_UINT8
:
2623 unpack_int_rgba_RG_UINT8(src
, dst
, n
);
2625 case MESA_FORMAT_RG_INT8
:
2626 unpack_int_rgba_RG_INT8(src
, dst
, n
);
2629 case MESA_FORMAT_R_UINT32
:
2630 case MESA_FORMAT_R_INT32
:
2631 unpack_int_rgba_R_UINT32(src
, dst
, n
);
2634 case MESA_FORMAT_R_UINT16
:
2635 unpack_int_rgba_R_UINT16(src
, dst
, n
);
2637 case MESA_FORMAT_R_INT16
:
2638 unpack_int_rgba_R_INT16(src
, dst
, n
);
2641 case MESA_FORMAT_R_UINT8
:
2642 unpack_int_rgba_R_UINT8(src
, dst
, n
);
2644 case MESA_FORMAT_R_INT8
:
2645 unpack_int_rgba_R_INT8(src
, dst
, n
);
2648 case MESA_FORMAT_ALPHA_UINT32
:
2649 case MESA_FORMAT_ALPHA_INT32
:
2650 unpack_int_rgba_ALPHA_UINT32(src
, dst
, n
);
2653 case MESA_FORMAT_ALPHA_UINT16
:
2654 unpack_int_rgba_ALPHA_UINT16(src
, dst
, n
);
2656 case MESA_FORMAT_ALPHA_INT16
:
2657 unpack_int_rgba_ALPHA_INT16(src
, dst
, n
);
2660 case MESA_FORMAT_ALPHA_UINT8
:
2661 unpack_int_rgba_ALPHA_UINT8(src
, dst
, n
);
2663 case MESA_FORMAT_ALPHA_INT8
:
2664 unpack_int_rgba_ALPHA_INT8(src
, dst
, n
);
2667 case MESA_FORMAT_LUMINANCE_UINT32
:
2668 case MESA_FORMAT_LUMINANCE_INT32
:
2669 unpack_int_rgba_LUMINANCE_UINT32(src
, dst
, n
);
2671 case MESA_FORMAT_LUMINANCE_UINT16
:
2672 unpack_int_rgba_LUMINANCE_UINT16(src
, dst
, n
);
2674 case MESA_FORMAT_LUMINANCE_INT16
:
2675 unpack_int_rgba_LUMINANCE_INT16(src
, dst
, n
);
2678 case MESA_FORMAT_LUMINANCE_UINT8
:
2679 unpack_int_rgba_LUMINANCE_UINT8(src
, dst
, n
);
2681 case MESA_FORMAT_LUMINANCE_INT8
:
2682 unpack_int_rgba_LUMINANCE_INT8(src
, dst
, n
);
2685 case MESA_FORMAT_LUMINANCE_ALPHA_UINT32
:
2686 case MESA_FORMAT_LUMINANCE_ALPHA_INT32
:
2687 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src
, dst
, n
);
2690 case MESA_FORMAT_LUMINANCE_ALPHA_UINT16
:
2691 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src
, dst
, n
);
2693 case MESA_FORMAT_LUMINANCE_ALPHA_INT16
:
2694 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src
, dst
, n
);
2697 case MESA_FORMAT_LUMINANCE_ALPHA_UINT8
:
2698 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src
, dst
, n
);
2700 case MESA_FORMAT_LUMINANCE_ALPHA_INT8
:
2701 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src
, dst
, n
);
2704 case MESA_FORMAT_INTENSITY_UINT32
:
2705 case MESA_FORMAT_INTENSITY_INT32
:
2706 unpack_int_rgba_INTENSITY_UINT32(src
, dst
, n
);
2709 case MESA_FORMAT_INTENSITY_UINT16
:
2710 unpack_int_rgba_INTENSITY_UINT16(src
, dst
, n
);
2712 case MESA_FORMAT_INTENSITY_INT16
:
2713 unpack_int_rgba_INTENSITY_INT16(src
, dst
, n
);
2716 case MESA_FORMAT_INTENSITY_UINT8
:
2717 unpack_int_rgba_INTENSITY_UINT8(src
, dst
, n
);
2719 case MESA_FORMAT_INTENSITY_INT8
:
2720 unpack_int_rgba_INTENSITY_INT8(src
, dst
, n
);
2723 case MESA_FORMAT_ARGB2101010_UINT
:
2724 unpack_int_rgba_ARGB2101010_UINT(src
, dst
, n
);
2727 _mesa_problem(NULL
, "%s: bad format %s", __FUNCTION__
,
2728 _mesa_get_format_name(format
));
2734 * Unpack a 2D rect of pixels returning float RGBA colors.
2735 * \param format the source image format
2736 * \param src start address of the source image
2737 * \param srcRowStride source image row stride in bytes
2738 * \param dst start address of the dest image
2739 * \param dstRowStride dest image row stride in bytes
2740 * \param x source image start X pos
2741 * \param y source image start Y pos
2742 * \param width width of rect region to convert
2743 * \param height height of rect region to convert
2746 _mesa_unpack_rgba_block(gl_format format
,
2747 const void *src
, GLint srcRowStride
,
2748 GLfloat dst
[][4], GLint dstRowStride
,
2749 GLuint x
, GLuint y
, GLuint width
, GLuint height
)
2751 unpack_rgba_func unpack
= get_unpack_rgba_function(format
);
2752 const GLuint srcPixStride
= _mesa_get_format_bytes(format
);
2753 const GLuint dstPixStride
= 4 * sizeof(GLfloat
);
2754 const GLubyte
*srcRow
;
2758 /* XXX needs to be fixed for compressed formats */
2760 srcRow
= ((const GLubyte
*) src
) + srcRowStride
* y
+ srcPixStride
* x
;
2761 dstRow
= ((GLubyte
*) dst
) + dstRowStride
* y
+ dstPixStride
* x
;
2763 for (i
= 0; i
< height
; i
++) {
2764 unpack(srcRow
, (GLfloat (*)[4]) dstRow
, width
);
2766 dstRow
+= dstRowStride
;
2767 srcRow
+= srcRowStride
;
2774 typedef void (*unpack_float_z_func
)(GLuint n
, const void *src
, GLfloat
*dst
);
2777 unpack_float_z_Z24_X8(GLuint n
, const void *src
, GLfloat
*dst
)
2779 /* only return Z, not stencil data */
2780 const GLuint
*s
= ((const GLuint
*) src
);
2781 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2783 for (i
= 0; i
< n
; i
++) {
2784 dst
[i
] = (s
[i
] >> 8) * scale
;
2785 ASSERT(dst
[i
] >= 0.0F
);
2786 ASSERT(dst
[i
] <= 1.0F
);
2791 unpack_float_z_X8_Z24(GLuint n
, const void *src
, GLfloat
*dst
)
2793 /* only return Z, not stencil data */
2794 const GLuint
*s
= ((const GLuint
*) src
);
2795 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2797 for (i
= 0; i
< n
; i
++) {
2798 dst
[i
] = (s
[i
] & 0x00ffffff) * scale
;
2799 ASSERT(dst
[i
] >= 0.0F
);
2800 ASSERT(dst
[i
] <= 1.0F
);
2805 unpack_float_z_Z16(GLuint n
, const void *src
, GLfloat
*dst
)
2807 const GLushort
*s
= ((const GLushort
*) src
);
2809 for (i
= 0; i
< n
; i
++) {
2810 dst
[i
] = s
[i
] * (1.0F
/ 65535.0F
);
2815 unpack_float_z_Z32(GLuint n
, const void *src
, GLfloat
*dst
)
2817 const GLuint
*s
= ((const GLuint
*) src
);
2819 for (i
= 0; i
< n
; i
++) {
2820 dst
[i
] = s
[i
] * (1.0F
/ 0xffffffff);
2825 unpack_float_z_Z32F(GLuint n
, const void *src
, GLfloat
*dst
)
2827 memcpy(dst
, src
, n
* sizeof(float));
2831 unpack_float_z_Z32X24S8(GLuint n
, const void *src
, GLfloat
*dst
)
2833 const GLfloat
*s
= ((const GLfloat
*) src
);
2835 for (i
= 0; i
< n
; i
++) {
2844 * The returned values will always be in the range [0.0, 1.0].
2847 _mesa_unpack_float_z_row(gl_format format
, GLuint n
,
2848 const void *src
, GLfloat
*dst
)
2850 unpack_float_z_func unpack
;
2853 case MESA_FORMAT_Z24_S8
:
2854 case MESA_FORMAT_Z24_X8
:
2855 unpack
= unpack_float_z_Z24_X8
;
2857 case MESA_FORMAT_S8_Z24
:
2858 case MESA_FORMAT_X8_Z24
:
2859 unpack
= unpack_float_z_X8_Z24
;
2861 case MESA_FORMAT_Z16
:
2862 unpack
= unpack_float_z_Z16
;
2864 case MESA_FORMAT_Z32
:
2865 unpack
= unpack_float_z_Z32
;
2867 case MESA_FORMAT_Z32_FLOAT
:
2868 unpack
= unpack_float_z_Z32F
;
2870 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2871 unpack
= unpack_float_z_Z32X24S8
;
2874 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_float_z_row",
2875 _mesa_get_format_name(format
));
2879 unpack(n
, src
, dst
);
2884 typedef void (*unpack_uint_z_func
)(const void *src
, GLuint
*dst
, GLuint n
);
2887 unpack_uint_z_Z24_X8(const void *src
, GLuint
*dst
, GLuint n
)
2889 /* only return Z, not stencil data */
2890 const GLuint
*s
= ((const GLuint
*) src
);
2892 for (i
= 0; i
< n
; i
++) {
2893 dst
[i
] = (s
[i
] & 0xffffff00) | (s
[i
] >> 24);
2898 unpack_uint_z_X8_Z24(const void *src
, GLuint
*dst
, GLuint n
)
2900 /* only return Z, not stencil data */
2901 const GLuint
*s
= ((const GLuint
*) src
);
2903 for (i
= 0; i
< n
; i
++) {
2904 dst
[i
] = (s
[i
] << 8) | ((s
[i
] >> 16) & 0xff);
2909 unpack_uint_z_Z16(const void *src
, GLuint
*dst
, GLuint n
)
2911 const GLushort
*s
= ((const GLushort
*)src
);
2913 for (i
= 0; i
< n
; i
++) {
2914 dst
[i
] = (s
[i
] << 16) | s
[i
];
2919 unpack_uint_z_Z32(const void *src
, GLuint
*dst
, GLuint n
)
2921 memcpy(dst
, src
, n
* sizeof(GLuint
));
2925 unpack_uint_z_Z32_FLOAT(const void *src
, GLuint
*dst
, GLuint n
)
2927 const float *s
= (const float *)src
;
2929 for (i
= 0; i
< n
; i
++) {
2930 dst
[i
] = FLOAT_TO_UINT(CLAMP(s
[i
], 0.0F
, 1.0F
));
2935 unpack_uint_z_Z32_FLOAT_X24S8(const void *src
, GLuint
*dst
, GLuint n
)
2942 const struct z32f_x24s8
*s
= (const struct z32f_x24s8
*) src
;
2945 for (i
= 0; i
< n
; i
++) {
2946 dst
[i
] = FLOAT_TO_UINT(CLAMP(s
[i
].z
, 0.0F
, 1.0F
));
2953 * The returned values will always be in the range [0, 0xffffffff].
2956 _mesa_unpack_uint_z_row(gl_format format
, GLuint n
,
2957 const void *src
, GLuint
*dst
)
2959 unpack_uint_z_func unpack
;
2960 const GLubyte
*srcPtr
= (GLubyte
*) src
;
2963 case MESA_FORMAT_Z24_S8
:
2964 case MESA_FORMAT_Z24_X8
:
2965 unpack
= unpack_uint_z_Z24_X8
;
2967 case MESA_FORMAT_S8_Z24
:
2968 case MESA_FORMAT_X8_Z24
:
2969 unpack
= unpack_uint_z_X8_Z24
;
2971 case MESA_FORMAT_Z16
:
2972 unpack
= unpack_uint_z_Z16
;
2974 case MESA_FORMAT_Z32
:
2975 unpack
= unpack_uint_z_Z32
;
2977 case MESA_FORMAT_Z32_FLOAT
:
2978 unpack
= unpack_uint_z_Z32_FLOAT
;
2980 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2981 unpack
= unpack_uint_z_Z32_FLOAT_X24S8
;
2984 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_uint_z_row",
2985 _mesa_get_format_name(format
));
2989 unpack(srcPtr
, dst
, n
);
2994 unpack_ubyte_s_S8(const void *src
, GLubyte
*dst
, GLuint n
)
2996 memcpy(dst
, src
, n
);
3000 unpack_ubyte_s_Z24_S8(const void *src
, GLubyte
*dst
, GLuint n
)
3003 const GLuint
*src32
= src
;
3005 for (i
= 0; i
< n
; i
++)
3006 dst
[i
] = src32
[i
] & 0xff;
3010 unpack_ubyte_s_S8_Z24(const void *src
, GLubyte
*dst
, GLuint n
)
3013 const GLuint
*src32
= src
;
3015 for (i
= 0; i
< n
; i
++)
3016 dst
[i
] = src32
[i
] >> 24;
3020 unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src
, GLubyte
*dst
, GLuint n
)
3023 const GLuint
*src32
= src
;
3025 for (i
= 0; i
< n
; i
++)
3026 dst
[i
] = src32
[i
* 2 + 1] & 0xff;
3030 _mesa_unpack_ubyte_stencil_row(gl_format format
, GLuint n
,
3031 const void *src
, GLubyte
*dst
)
3034 case MESA_FORMAT_S8
:
3035 unpack_ubyte_s_S8(src
, dst
, n
);
3037 case MESA_FORMAT_Z24_S8
:
3038 unpack_ubyte_s_Z24_S8(src
, dst
, n
);
3040 case MESA_FORMAT_S8_Z24
:
3041 unpack_ubyte_s_S8_Z24(src
, dst
, n
);
3043 case MESA_FORMAT_Z32_FLOAT_X24S8
:
3044 unpack_ubyte_s_Z32_FLOAT_X24S8(src
, dst
, n
);
3047 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_ubyte_s_row",
3048 _mesa_get_format_name(format
));
3054 unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint
*src
, GLuint
*dst
, GLuint n
)
3058 for (i
= 0; i
< n
; i
++) {
3059 GLuint val
= src
[i
];
3060 dst
[i
] = val
>> 24 | val
<< 8;
3065 unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint
*src
, GLuint
*dst
, GLuint n
)
3067 memcpy(dst
, src
, n
* 4);
3071 _mesa_unpack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
3072 const void *src
, GLuint
*dst
)
3075 case MESA_FORMAT_Z24_S8
:
3076 unpack_uint_24_8_depth_stencil_Z24_S8(src
, dst
, n
);
3078 case MESA_FORMAT_S8_Z24
:
3079 unpack_uint_24_8_depth_stencil_S8_Z24(src
, dst
, n
);
3083 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
3084 _mesa_get_format_name(format
));