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 /* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
28 #define EXPAND_1_8(X) ( (X) ? 0xff : 0x0 )
30 #define EXPAND_2_8(X) ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
32 #define EXPAND_3_8(X) ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
34 #define EXPAND_4_8(X) ( ((X) << 4) | (X) )
36 #define EXPAND_5_8(X) ( ((X) << 3) | ((X) >> 2) )
38 #define EXPAND_6_8(X) ( ((X) << 2) | ((X) >> 4) )
40 /**********************************************************************/
41 /* Unpack, returning GLfloat colors */
42 /**********************************************************************/
44 typedef void (*unpack_rgba_func
)(const void *src
, GLfloat dst
[][4], GLuint n
);
48 unpack_RGBA8888(const void *src
, GLfloat dst
[][4], GLuint n
)
50 const GLuint
*s
= ((const GLuint
*) src
);
52 for (i
= 0; i
< n
; i
++) {
53 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
54 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
55 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
56 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
61 unpack_RGBA8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
63 const GLuint
*s
= ((const GLuint
*) src
);
65 for (i
= 0; i
< n
; i
++) {
66 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
67 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
68 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
69 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
74 unpack_ARGB8888(const void *src
, GLfloat dst
[][4], GLuint n
)
76 const GLuint
*s
= ((const GLuint
*) src
);
78 for (i
= 0; i
< n
; i
++) {
79 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
80 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
81 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
82 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
87 unpack_ARGB8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
89 const GLuint
*s
= ((const GLuint
*) src
);
91 for (i
= 0; i
< n
; i
++) {
92 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
93 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
94 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
95 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
100 unpack_RGBX8888(const void *src
, GLfloat dst
[][4], GLuint n
)
102 const GLuint
*s
= ((const GLuint
*) src
);
104 for (i
= 0; i
< n
; i
++) {
105 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
106 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
107 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
108 dst
[i
][ACOMP
] = 1.0f
;
113 unpack_RGBX8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
115 const GLuint
*s
= ((const GLuint
*) src
);
117 for (i
= 0; i
< n
; i
++) {
118 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
119 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
120 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
121 dst
[i
][ACOMP
] = 1.0f
;
126 unpack_XRGB8888(const void *src
, GLfloat dst
[][4], GLuint n
)
128 const GLuint
*s
= ((const GLuint
*) src
);
130 for (i
= 0; i
< n
; i
++) {
131 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
132 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
133 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
134 dst
[i
][ACOMP
] = 1.0f
;
139 unpack_XRGB8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
141 const GLuint
*s
= ((const GLuint
*) src
);
143 for (i
= 0; i
< n
; i
++) {
144 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
145 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
146 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
147 dst
[i
][ACOMP
] = 1.0f
;
152 unpack_RGB888(const void *src
, GLfloat dst
[][4], GLuint n
)
154 const GLubyte
*s
= (const GLubyte
*) src
;
156 for (i
= 0; i
< n
; i
++) {
157 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+2] );
158 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+1] );
159 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+0] );
160 dst
[i
][ACOMP
] = 1.0F
;
165 unpack_BGR888(const void *src
, GLfloat dst
[][4], GLuint n
)
167 const GLubyte
*s
= (const GLubyte
*) src
;
169 for (i
= 0; i
< n
; i
++) {
170 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+0] );
171 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+1] );
172 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+2] );
173 dst
[i
][ACOMP
] = 1.0F
;
178 unpack_RGB565(const void *src
, GLfloat dst
[][4], GLuint n
)
180 const GLushort
*s
= ((const GLushort
*) src
);
182 for (i
= 0; i
< n
; i
++) {
183 dst
[i
][RCOMP
] = ((s
[i
] >> 11) & 0x1f) * (1.0F
/ 31.0F
);
184 dst
[i
][GCOMP
] = ((s
[i
] >> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
185 dst
[i
][BCOMP
] = ((s
[i
] ) & 0x1f) * (1.0F
/ 31.0F
);
186 dst
[i
][ACOMP
] = 1.0F
;
191 unpack_RGB565_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
193 const GLushort
*s
= ((const GLushort
*) src
);
195 for (i
= 0; i
< n
; i
++) {
196 GLuint t
= (s
[i
] >> 8) | (s
[i
] << 8); /* byte swap */
197 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( ((t
>> 8) & 0xf8) | ((t
>> 13) & 0x7) );
198 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( ((t
>> 3) & 0xfc) | ((t
>> 9) & 0x3) );
199 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( ((t
<< 3) & 0xf8) | ((t
>> 2) & 0x7) );
200 dst
[i
][ACOMP
] = 1.0F
;
205 unpack_ARGB4444(const void *src
, GLfloat dst
[][4], GLuint n
)
207 const GLushort
*s
= ((const GLushort
*) src
);
209 for (i
= 0; i
< n
; i
++) {
210 dst
[i
][RCOMP
] = ((s
[i
] >> 8) & 0xf) * (1.0F
/ 15.0F
);
211 dst
[i
][GCOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
212 dst
[i
][BCOMP
] = ((s
[i
] ) & 0xf) * (1.0F
/ 15.0F
);
213 dst
[i
][ACOMP
] = ((s
[i
] >> 12) & 0xf) * (1.0F
/ 15.0F
);
218 unpack_ARGB4444_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
220 const GLushort
*s
= ((const GLushort
*) src
);
222 for (i
= 0; i
< n
; i
++) {
223 dst
[i
][RCOMP
] = ((s
[i
] ) & 0xf) * (1.0F
/ 15.0F
);
224 dst
[i
][GCOMP
] = ((s
[i
] >> 12) & 0xf) * (1.0F
/ 15.0F
);
225 dst
[i
][BCOMP
] = ((s
[i
] >> 8) & 0xf) * (1.0F
/ 15.0F
);
226 dst
[i
][ACOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
231 unpack_RGBA5551(const void *src
, GLfloat dst
[][4], GLuint n
)
233 const GLushort
*s
= ((const GLushort
*) src
);
235 for (i
= 0; i
< n
; i
++) {
236 dst
[i
][RCOMP
] = ((s
[i
] >> 11) & 0x1f) * (1.0F
/ 31.0F
);
237 dst
[i
][GCOMP
] = ((s
[i
] >> 6) & 0x1f) * (1.0F
/ 31.0F
);
238 dst
[i
][BCOMP
] = ((s
[i
] >> 1) & 0x1f) * (1.0F
/ 31.0F
);
239 dst
[i
][ACOMP
] = ((s
[i
] ) & 0x01) * 1.0F
;
244 unpack_ARGB1555(const void *src
, GLfloat dst
[][4], GLuint n
)
246 const GLushort
*s
= ((const GLushort
*) src
);
248 for (i
= 0; i
< n
; i
++) {
249 dst
[i
][RCOMP
] = ((s
[i
] >> 10) & 0x1f) * (1.0F
/ 31.0F
);
250 dst
[i
][GCOMP
] = ((s
[i
] >> 5) & 0x1f) * (1.0F
/ 31.0F
);
251 dst
[i
][BCOMP
] = ((s
[i
] >> 0) & 0x1f) * (1.0F
/ 31.0F
);
252 dst
[i
][ACOMP
] = ((s
[i
] >> 15) & 0x01) * 1.0F
;
257 unpack_ARGB1555_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
259 const GLushort
*s
= ((const GLushort
*) src
);
261 for (i
= 0; i
< n
; i
++) {
262 GLushort tmp
= (s
[i
] << 8) | (s
[i
] >> 8); /* byteswap */
263 dst
[i
][RCOMP
] = ((tmp
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
264 dst
[i
][GCOMP
] = ((tmp
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
265 dst
[i
][BCOMP
] = ((tmp
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
266 dst
[i
][ACOMP
] = ((tmp
>> 15) & 0x01) * 1.0F
;
271 unpack_AL44(const void *src
, GLfloat dst
[][4], GLuint n
)
273 const GLubyte
*s
= ((const GLubyte
*) src
);
275 for (i
= 0; i
< n
; i
++) {
278 dst
[i
][BCOMP
] = (s
[i
] & 0xf) * (1.0F
/ 15.0F
);
279 dst
[i
][ACOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
284 unpack_AL88(const void *src
, GLfloat dst
[][4], GLuint n
)
286 const GLushort
*s
= ((const GLushort
*) src
);
288 for (i
= 0; i
< n
; i
++) {
291 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
292 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
297 unpack_AL88_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
299 const GLushort
*s
= ((const GLushort
*) src
);
301 for (i
= 0; i
< n
; i
++) {
304 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
305 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
310 unpack_AL1616(const void *src
, GLfloat dst
[][4], GLuint n
)
312 const GLuint
*s
= ((const GLuint
*) src
);
314 for (i
= 0; i
< n
; i
++) {
317 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
318 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
323 unpack_AL1616_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
325 const GLuint
*s
= ((const GLuint
*) src
);
327 for (i
= 0; i
< n
; i
++) {
330 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
331 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
336 unpack_RGB332(const void *src
, GLfloat dst
[][4], GLuint n
)
338 const GLubyte
*s
= ((const GLubyte
*) src
);
340 for (i
= 0; i
< n
; i
++) {
341 dst
[i
][RCOMP
] = ((s
[i
] >> 5) & 0x7) * (1.0F
/ 7.0F
);
342 dst
[i
][GCOMP
] = ((s
[i
] >> 2) & 0x7) * (1.0F
/ 7.0F
);
343 dst
[i
][BCOMP
] = ((s
[i
] ) & 0x3) * (1.0F
/ 3.0F
);
344 dst
[i
][ACOMP
] = 1.0F
;
350 unpack_A8(const void *src
, GLfloat dst
[][4], GLuint n
)
352 const GLubyte
*s
= ((const GLubyte
*) src
);
354 for (i
= 0; i
< n
; i
++) {
357 dst
[i
][BCOMP
] = 0.0F
;
358 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
]);
363 unpack_A16(const void *src
, GLfloat dst
[][4], GLuint n
)
365 const GLushort
*s
= ((const GLushort
*) src
);
367 for (i
= 0; i
< n
; i
++) {
370 dst
[i
][BCOMP
] = 0.0F
;
371 dst
[i
][ACOMP
] = USHORT_TO_FLOAT(s
[i
]);
376 unpack_L8(const void *src
, GLfloat dst
[][4], GLuint n
)
378 const GLubyte
*s
= ((const GLubyte
*) src
);
380 for (i
= 0; i
< n
; i
++) {
383 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT(s
[i
]);
384 dst
[i
][ACOMP
] = 1.0F
;
389 unpack_L16(const void *src
, GLfloat dst
[][4], GLuint n
)
391 const GLushort
*s
= ((const GLushort
*) src
);
393 for (i
= 0; i
< n
; i
++) {
396 dst
[i
][BCOMP
] = USHORT_TO_FLOAT(s
[i
]);
397 dst
[i
][ACOMP
] = 1.0F
;
402 unpack_I8(const void *src
, GLfloat dst
[][4], GLuint n
)
404 const GLubyte
*s
= ((const GLubyte
*) src
);
406 for (i
= 0; i
< n
; i
++) {
410 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
]);
415 unpack_I16(const void *src
, GLfloat dst
[][4], GLuint n
)
417 const GLushort
*s
= ((const GLushort
*) src
);
419 for (i
= 0; i
< n
; i
++) {
423 dst
[i
][ACOMP
] = USHORT_TO_FLOAT(s
[i
]);
428 unpack_YCBCR(const void *src
, GLfloat dst
[][4], GLuint n
)
431 for (i
= 0; i
< n
; i
++) {
432 const GLushort
*src0
= ((const GLushort
*) src
) + i
* 2; /* even */
433 const GLushort
*src1
= src0
+ 1; /* odd */
434 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
435 const GLubyte cb
= *src0
& 0xff; /* chroma U */
436 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
437 const GLubyte cr
= *src1
& 0xff; /* chroma V */
438 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
439 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
440 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
441 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
442 r
*= (1.0F
/ 255.0F
);
443 g
*= (1.0F
/ 255.0F
);
444 b
*= (1.0F
/ 255.0F
);
445 dst
[i
][RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
446 dst
[i
][GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
447 dst
[i
][BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
448 dst
[i
][ACOMP
] = 1.0F
;
453 unpack_YCBCR_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
456 for (i
= 0; i
< n
; i
++) {
457 const GLushort
*src0
= ((const GLushort
*) src
) + i
* 2; /* even */
458 const GLushort
*src1
= src0
+ 1; /* odd */
459 const GLubyte y0
= *src0
& 0xff; /* luminance */
460 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
461 const GLubyte y1
= *src1
& 0xff; /* luminance */
462 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
463 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
464 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
465 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
466 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
467 r
*= (1.0F
/ 255.0F
);
468 g
*= (1.0F
/ 255.0F
);
469 b
*= (1.0F
/ 255.0F
);
470 dst
[i
][RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
471 dst
[i
][GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
472 dst
[i
][BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
473 dst
[i
][ACOMP
] = 1.0F
;
479 unpack_Z24_S8(const void *src
, GLfloat dst
[][4], GLuint n
)
481 /* only return Z, not stencil data */
482 const GLuint
*s
= ((const GLuint
*) src
);
483 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
485 for (i
= 0; i
< n
; i
++) {
488 dst
[i
][2] = (s
[i
] >> 8) * scale
;
490 ASSERT(dst
[i
][0] >= 0.0F
);
491 ASSERT(dst
[i
][0] <= 1.0F
);
496 unpack_S8_Z24(const void *src
, GLfloat dst
[][4], GLuint n
)
498 /* only return Z, not stencil data */
499 const GLuint
*s
= ((const GLuint
*) src
);
500 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
502 for (i
= 0; i
< n
; i
++) {
505 dst
[i
][2] = (s
[i
] & 0x00ffffff) * scale
;
507 ASSERT(dst
[i
][0] >= 0.0F
);
508 ASSERT(dst
[i
][0] <= 1.0F
);
513 unpack_Z16(const void *src
, GLfloat dst
[][4], GLuint n
)
515 const GLushort
*s
= ((const GLushort
*) src
);
517 for (i
= 0; i
< n
; i
++) {
520 dst
[i
][2] = s
[i
] * (1.0F
/ 65535.0F
);
526 unpack_X8_Z24(const void *src
, GLfloat dst
[][4], GLuint n
)
528 unpack_S8_Z24(src
, dst
, n
);
532 unpack_Z24_X8(const void *src
, GLfloat dst
[][4], GLuint n
)
534 unpack_Z24_S8(src
, dst
, n
);
538 unpack_Z32(const void *src
, GLfloat dst
[][4], GLuint n
)
540 const GLuint
*s
= ((const GLuint
*) src
);
542 for (i
= 0; i
< n
; i
++) {
545 dst
[i
][2] = s
[i
] * (1.0F
/ 0xffffffff);
552 unpack_S8(const void *src
, GLfloat dst
[][4], GLuint n
)
554 /* should never be used */
556 for (i
= 0; i
< n
; i
++) {
565 unpack_RGBA_INT8(const void *src
, GLfloat dst
[][4], GLuint n
)
567 const GLbyte
*s
= (const GLbyte
*) src
;
569 for (i
= 0; i
< n
; i
++) {
570 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
571 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
572 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
573 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
578 unpack_RGBA_INT16(const void *src
, GLfloat dst
[][4], GLuint n
)
580 const GLshort
*s
= (const GLshort
*) src
;
582 for (i
= 0; i
< n
; i
++) {
583 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
584 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
585 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
586 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
591 unpack_RGBA_INT32(const void *src
, GLfloat dst
[][4], GLuint n
)
593 const GLint
*s
= (const GLint
*) src
;
595 for (i
= 0; i
< n
; i
++) {
596 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
597 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
598 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
599 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
604 unpack_RGBA_UINT8(const void *src
, GLfloat dst
[][4], GLuint n
)
606 const GLubyte
*s
= (const GLubyte
*) src
;
608 for (i
= 0; i
< n
; i
++) {
609 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
610 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
611 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
612 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
617 unpack_RGBA_UINT16(const void *src
, GLfloat dst
[][4], GLuint n
)
619 const GLushort
*s
= (const GLushort
*) src
;
621 for (i
= 0; i
< n
; i
++) {
622 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
623 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
624 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
625 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
630 unpack_RGBA_UINT32(const void *src
, GLfloat dst
[][4], GLuint n
)
632 const GLuint
*s
= (const GLuint
*) src
;
634 for (i
= 0; i
< n
; i
++) {
635 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
636 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
637 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
638 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
643 unpack_SIGNED_RGBA_16(const void *src
, GLfloat dst
[][4], GLuint n
)
645 const GLshort
*s
= (const GLshort
*) src
;
647 for (i
= 0; i
< n
; i
++) {
648 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+0] );
649 dst
[i
][GCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+1] );
650 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+2] );
651 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+3] );
656 unpack_RGBA_16(const void *src
, GLfloat dst
[][4], GLuint n
)
658 const GLushort
*s
= (const GLushort
*) src
;
660 for (i
= 0; i
< n
; i
++) {
661 dst
[i
][RCOMP
] = USHORT_TO_FLOAT( s
[i
*4+0] );
662 dst
[i
][GCOMP
] = USHORT_TO_FLOAT( s
[i
*4+1] );
663 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
*4+2] );
664 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
*4+3] );
670 * Return the unpacker function for the given format.
672 static unpack_rgba_func
673 get_unpack_rgba_function(gl_format format
)
675 static unpack_rgba_func table
[MESA_FORMAT_COUNT
];
676 static GLboolean initialized
= GL_FALSE
;
679 table
[MESA_FORMAT_NONE
] = NULL
;
681 table
[MESA_FORMAT_RGBA8888
] = unpack_RGBA8888
;
682 table
[MESA_FORMAT_RGBA8888_REV
] = unpack_RGBA8888_REV
;
683 table
[MESA_FORMAT_ARGB8888
] = unpack_ARGB8888
;
684 table
[MESA_FORMAT_ARGB8888_REV
] = unpack_ARGB8888_REV
;
685 table
[MESA_FORMAT_RGBX8888
] = unpack_RGBX8888
;
686 table
[MESA_FORMAT_RGBX8888_REV
] = unpack_RGBX8888_REV
;
687 table
[MESA_FORMAT_XRGB8888
] = unpack_XRGB8888
;
688 table
[MESA_FORMAT_XRGB8888_REV
] = unpack_XRGB8888_REV
;
689 table
[MESA_FORMAT_RGB888
] = unpack_RGB888
;
690 table
[MESA_FORMAT_BGR888
] = unpack_BGR888
;
691 table
[MESA_FORMAT_RGB565
] = unpack_RGB565
;
692 table
[MESA_FORMAT_RGB565_REV
] = unpack_RGB565_REV
;
693 table
[MESA_FORMAT_ARGB4444
] = unpack_ARGB4444
;
694 table
[MESA_FORMAT_ARGB4444_REV
] = unpack_ARGB4444_REV
;
695 table
[MESA_FORMAT_RGBA5551
] = unpack_RGBA5551
;
696 table
[MESA_FORMAT_ARGB1555
] = unpack_ARGB1555
;
697 table
[MESA_FORMAT_ARGB1555_REV
] = unpack_ARGB1555_REV
;
698 table
[MESA_FORMAT_AL44
] = unpack_AL44
;
699 table
[MESA_FORMAT_AL88
] = unpack_AL88
;
700 table
[MESA_FORMAT_AL88_REV
] = unpack_AL88_REV
;
701 table
[MESA_FORMAT_AL1616
] = unpack_AL1616
;
702 table
[MESA_FORMAT_AL1616_REV
] = unpack_AL1616_REV
;
703 table
[MESA_FORMAT_RGB332
] = unpack_RGB332
;
704 table
[MESA_FORMAT_A8
] = unpack_A8
;
705 table
[MESA_FORMAT_A16
] = unpack_A16
;
706 table
[MESA_FORMAT_L8
] = unpack_L8
;
707 table
[MESA_FORMAT_L16
] = unpack_L16
;
708 table
[MESA_FORMAT_I8
] = unpack_I8
;
709 table
[MESA_FORMAT_I16
] = unpack_I16
;
710 table
[MESA_FORMAT_YCBCR
] = unpack_YCBCR
;
711 table
[MESA_FORMAT_YCBCR_REV
] = unpack_YCBCR_REV
;
712 table
[MESA_FORMAT_Z16
] = unpack_Z16
;
713 table
[MESA_FORMAT_X8_Z24
] = unpack_X8_Z24
;
714 table
[MESA_FORMAT_Z24_X8
] = unpack_Z24_X8
;
715 table
[MESA_FORMAT_Z32
] = unpack_Z32
;
716 table
[MESA_FORMAT_S8
] = unpack_S8
;
718 table
[MESA_FORMAT_RGBA_INT8
] = unpack_RGBA_INT8
;
719 table
[MESA_FORMAT_RGBA_INT16
] = unpack_RGBA_INT16
;
720 table
[MESA_FORMAT_RGBA_INT32
] = unpack_RGBA_INT32
;
721 table
[MESA_FORMAT_RGBA_UINT8
] = unpack_RGBA_UINT8
;
722 table
[MESA_FORMAT_RGBA_UINT16
] = unpack_RGBA_UINT16
;
723 table
[MESA_FORMAT_RGBA_UINT32
] = unpack_RGBA_UINT32
;
725 table
[MESA_FORMAT_SIGNED_RGBA_16
] = unpack_SIGNED_RGBA_16
;
726 table
[MESA_FORMAT_RGBA_16
] = unpack_RGBA_16
;
728 initialized
= GL_TRUE
;
731 return table
[format
];
736 * Unpack rgba colors, returning as GLfloat values.
739 _mesa_unpack_rgba_row(gl_format format
, GLuint n
,
740 const void *src
, GLfloat dst
[][4])
742 unpack_rgba_func unpack
= get_unpack_rgba_function(format
);
747 /**********************************************************************/
748 /* Unpack, returning GLubyte colors */
749 /**********************************************************************/
753 unpack_ubyte_RGBA8888(const void *src
, GLubyte dst
[][4], GLuint n
)
755 const GLuint
*s
= ((const GLuint
*) src
);
757 for (i
= 0; i
< n
; i
++) {
758 dst
[i
][RCOMP
] = (s
[i
] >> 24);
759 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
760 dst
[i
][BCOMP
] = (s
[i
] >> 8) & 0xff;
761 dst
[i
][ACOMP
] = (s
[i
] ) & 0xff;
766 unpack_ubyte_RGBA8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
768 const GLuint
*s
= ((const GLuint
*) src
);
770 for (i
= 0; i
< n
; i
++) {
771 dst
[i
][RCOMP
] = (s
[i
] ) & 0xff;
772 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
773 dst
[i
][BCOMP
] = (s
[i
] >> 16) & 0xff;
774 dst
[i
][ACOMP
] = (s
[i
] >> 24);
779 unpack_ubyte_ARGB8888(const void *src
, GLubyte dst
[][4], GLuint n
)
781 const GLuint
*s
= ((const GLuint
*) src
);
783 for (i
= 0; i
< n
; i
++) {
784 dst
[i
][RCOMP
] = (s
[i
] >> 16) & 0xff;
785 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
786 dst
[i
][BCOMP
] = (s
[i
] ) & 0xff;
787 dst
[i
][ACOMP
] = (s
[i
] >> 24);
792 unpack_ubyte_ARGB8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
794 const GLuint
*s
= ((const GLuint
*) src
);
796 for (i
= 0; i
< n
; i
++) {
797 dst
[i
][RCOMP
] = (s
[i
] >> 8) & 0xff;
798 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
799 dst
[i
][BCOMP
] = (s
[i
] >> 24);
800 dst
[i
][ACOMP
] = (s
[i
] ) & 0xff;
805 unpack_ubyte_RGBX8888(const void *src
, GLubyte dst
[][4], GLuint n
)
807 const GLuint
*s
= ((const GLuint
*) src
);
809 for (i
= 0; i
< n
; i
++) {
810 dst
[i
][RCOMP
] = (s
[i
] >> 24);
811 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
812 dst
[i
][BCOMP
] = (s
[i
] >> 8) & 0xff;
813 dst
[i
][ACOMP
] = 0xff;
818 unpack_ubyte_RGBX8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
820 const GLuint
*s
= ((const GLuint
*) src
);
822 for (i
= 0; i
< n
; i
++) {
823 dst
[i
][RCOMP
] = (s
[i
] ) & 0xff;
824 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
825 dst
[i
][BCOMP
] = (s
[i
] >> 16) & 0xff;
826 dst
[i
][ACOMP
] = 0xff;
831 unpack_ubyte_XRGB8888(const void *src
, GLubyte dst
[][4], GLuint n
)
833 const GLuint
*s
= ((const GLuint
*) src
);
835 for (i
= 0; i
< n
; i
++) {
836 dst
[i
][RCOMP
] = (s
[i
] >> 16) & 0xff;
837 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
838 dst
[i
][BCOMP
] = (s
[i
] ) & 0xff;
839 dst
[i
][ACOMP
] = 0xff;
844 unpack_ubyte_XRGB8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
846 const GLuint
*s
= ((const GLuint
*) src
);
848 for (i
= 0; i
< n
; i
++) {
849 dst
[i
][RCOMP
] = (s
[i
] >> 8) & 0xff;
850 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
851 dst
[i
][BCOMP
] = (s
[i
] >> 24);
852 dst
[i
][ACOMP
] = 0xff;
857 unpack_ubyte_RGB888(const void *src
, GLubyte dst
[][4], GLuint n
)
859 const GLubyte
*s
= (const GLubyte
*) src
;
861 for (i
= 0; i
< n
; i
++) {
862 dst
[i
][RCOMP
] = s
[i
*3+2];
863 dst
[i
][GCOMP
] = s
[i
*3+1];
864 dst
[i
][BCOMP
] = s
[i
*3+0];
865 dst
[i
][ACOMP
] = 0xff;
870 unpack_ubyte_BGR888(const void *src
, GLubyte dst
[][4], GLuint n
)
872 const GLubyte
*s
= (const GLubyte
*) src
;
874 for (i
= 0; i
< n
; i
++) {
875 dst
[i
][RCOMP
] = s
[i
*3+0];
876 dst
[i
][GCOMP
] = s
[i
*3+1];
877 dst
[i
][BCOMP
] = s
[i
*3+2];
878 dst
[i
][ACOMP
] = 0xff;
883 unpack_ubyte_RGB565(const void *src
, GLubyte dst
[][4], GLuint n
)
885 const GLushort
*s
= ((const GLushort
*) src
);
887 for (i
= 0; i
< n
; i
++) {
888 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 11) & 0x1f);
889 dst
[i
][GCOMP
] = EXPAND_6_8((s
[i
] >> 5 ) & 0x3f);
890 dst
[i
][BCOMP
] = EXPAND_5_8( s
[i
] & 0x1f);
891 dst
[i
][ACOMP
] = 0xff;
896 unpack_ubyte_RGB565_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
898 const GLushort
*s
= ((const GLushort
*) src
);
900 for (i
= 0; i
< n
; i
++) {
901 GLuint t
= (s
[i
] >> 8) | (s
[i
] << 8); /* byte swap */
902 dst
[i
][RCOMP
] = EXPAND_5_8((t
>> 11) & 0x1f);
903 dst
[i
][GCOMP
] = EXPAND_6_8((t
>> 5 ) & 0x3f);
904 dst
[i
][BCOMP
] = EXPAND_5_8( t
& 0x1f);
905 dst
[i
][ACOMP
] = 0xff;
910 unpack_ubyte_ARGB4444(const void *src
, GLubyte dst
[][4], GLuint n
)
912 const GLushort
*s
= ((const GLushort
*) src
);
914 for (i
= 0; i
< n
; i
++) {
915 dst
[i
][RCOMP
] = EXPAND_4_8((s
[i
] >> 8) & 0xf);
916 dst
[i
][GCOMP
] = EXPAND_4_8((s
[i
] >> 4) & 0xf);
917 dst
[i
][BCOMP
] = EXPAND_4_8((s
[i
] ) & 0xf);
918 dst
[i
][ACOMP
] = EXPAND_4_8((s
[i
] >> 12) & 0xf);
923 unpack_ubyte_ARGB4444_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
925 const GLushort
*s
= ((const GLushort
*) src
);
927 for (i
= 0; i
< n
; i
++) {
928 dst
[i
][RCOMP
] = EXPAND_4_8((s
[i
] ) & 0xf);
929 dst
[i
][GCOMP
] = EXPAND_4_8((s
[i
] >> 12) & 0xf);
930 dst
[i
][BCOMP
] = EXPAND_4_8((s
[i
] >> 8) & 0xf);
931 dst
[i
][ACOMP
] = EXPAND_4_8((s
[i
] >> 4) & 0xf);
936 unpack_ubyte_RGBA5551(const void *src
, GLubyte dst
[][4], GLuint n
)
938 const GLushort
*s
= ((const GLushort
*) src
);
940 for (i
= 0; i
< n
; i
++) {
941 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 11) & 0x1f);
942 dst
[i
][GCOMP
] = EXPAND_5_8((s
[i
] >> 6) & 0x1f);
943 dst
[i
][BCOMP
] = EXPAND_5_8((s
[i
] >> 1) & 0x1f);
944 dst
[i
][ACOMP
] = EXPAND_1_8((s
[i
] ) & 0x01);
949 unpack_ubyte_ARGB1555(const void *src
, GLubyte dst
[][4], GLuint n
)
951 const GLushort
*s
= ((const GLushort
*) src
);
953 for (i
= 0; i
< n
; i
++) {
954 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 10) & 0x1f);
955 dst
[i
][GCOMP
] = EXPAND_5_8((s
[i
] >> 5) & 0x1f);
956 dst
[i
][BCOMP
] = EXPAND_5_8((s
[i
] >> 0) & 0x1f);
957 dst
[i
][ACOMP
] = EXPAND_1_8((s
[i
] >> 15) & 0x01);
962 unpack_ubyte_ARGB1555_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
964 const GLushort
*s
= ((const GLushort
*) src
);
966 for (i
= 0; i
< n
; i
++) {
967 GLushort tmp
= (s
[i
] << 8) | (s
[i
] >> 8); /* byteswap */
968 dst
[i
][RCOMP
] = EXPAND_5_8((tmp
>> 10) & 0x1f);
969 dst
[i
][GCOMP
] = EXPAND_5_8((tmp
>> 5) & 0x1f);
970 dst
[i
][BCOMP
] = EXPAND_5_8((tmp
>> 0) & 0x1f);
971 dst
[i
][ACOMP
] = EXPAND_1_8((tmp
>> 15) & 0x01);
976 unpack_ubyte_AL44(const void *src
, GLubyte dst
[][4], GLuint n
)
978 const GLubyte
*s
= ((const GLubyte
*) src
);
980 for (i
= 0; i
< n
; i
++) {
983 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] & 0xf);
984 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] >> 4);
989 unpack_ubyte_AL88(const void *src
, GLubyte dst
[][4], GLuint n
)
991 const GLushort
*s
= ((const GLushort
*) src
);
993 for (i
= 0; i
< n
; i
++) {
996 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] & 0xff);
997 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] >> 8);
1002 unpack_ubyte_AL88_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1004 const GLushort
*s
= ((const GLushort
*) src
);
1006 for (i
= 0; i
< n
; i
++) {
1009 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] >> 8);
1010 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] & 0xff);
1015 unpack_ubyte_RGB332(const void *src
, GLubyte dst
[][4], GLuint n
)
1017 const GLubyte
*s
= ((const GLubyte
*) src
);
1019 for (i
= 0; i
< n
; i
++) {
1020 dst
[i
][RCOMP
] = EXPAND_3_8((s
[i
] >> 5) & 0x7);
1021 dst
[i
][GCOMP
] = EXPAND_3_8((s
[i
] >> 2) & 0x7);
1022 dst
[i
][BCOMP
] = EXPAND_2_8((s
[i
] ) & 0x3);
1023 dst
[i
][ACOMP
] = 0xff;
1028 unpack_ubyte_A8(const void *src
, GLubyte dst
[][4], GLuint n
)
1030 const GLubyte
*s
= ((const GLubyte
*) src
);
1032 for (i
= 0; i
< n
; i
++) {
1036 dst
[i
][ACOMP
] = s
[i
];
1041 unpack_ubyte_L8(const void *src
, GLubyte dst
[][4], GLuint n
)
1043 const GLubyte
*s
= ((const GLubyte
*) src
);
1045 for (i
= 0; i
< n
; i
++) {
1048 dst
[i
][BCOMP
] = s
[i
];
1049 dst
[i
][ACOMP
] = 0xff;
1055 unpack_ubyte_I8(const void *src
, GLubyte dst
[][4], GLuint n
)
1057 const GLubyte
*s
= ((const GLubyte
*) src
);
1059 for (i
= 0; i
< n
; i
++) {
1063 dst
[i
][ACOMP
] = s
[i
];
1069 * Unpack rgba colors, returning as GLubyte values. This should usually
1070 * only be used for unpacking formats that use 8 bits or less per channel.
1073 _mesa_unpack_ubyte_rgba_row(gl_format format
, GLuint n
,
1074 const void *src
, GLubyte dst
[][4])
1077 case MESA_FORMAT_RGBA8888
:
1078 unpack_ubyte_RGBA8888(src
, dst
, n
);
1080 case MESA_FORMAT_RGBA8888_REV
:
1081 unpack_ubyte_RGBA8888_REV(src
, dst
, n
);
1083 case MESA_FORMAT_ARGB8888
:
1084 unpack_ubyte_ARGB8888(src
, dst
, n
);
1086 case MESA_FORMAT_ARGB8888_REV
:
1087 unpack_ubyte_ARGB8888_REV(src
, dst
, n
);
1089 case MESA_FORMAT_RGBX8888
:
1090 unpack_ubyte_RGBX8888(src
, dst
, n
);
1092 case MESA_FORMAT_RGBX8888_REV
:
1093 unpack_ubyte_RGBX8888_REV(src
, dst
, n
);
1095 case MESA_FORMAT_XRGB8888
:
1096 unpack_ubyte_XRGB8888(src
, dst
, n
);
1098 case MESA_FORMAT_XRGB8888_REV
:
1099 unpack_ubyte_XRGB8888_REV(src
, dst
, n
);
1101 case MESA_FORMAT_RGB888
:
1102 unpack_ubyte_RGB888(src
, dst
, n
);
1104 case MESA_FORMAT_BGR888
:
1105 unpack_ubyte_BGR888(src
, dst
, n
);
1107 case MESA_FORMAT_RGB565
:
1108 unpack_ubyte_RGB565(src
, dst
, n
);
1110 case MESA_FORMAT_RGB565_REV
:
1111 unpack_ubyte_RGB565_REV(src
, dst
, n
);
1113 case MESA_FORMAT_ARGB4444
:
1114 unpack_ubyte_ARGB4444(src
, dst
, n
);
1116 case MESA_FORMAT_ARGB4444_REV
:
1117 unpack_ubyte_ARGB4444_REV(src
, dst
, n
);
1119 case MESA_FORMAT_RGBA5551
:
1120 unpack_ubyte_RGBA5551(src
, dst
, n
);
1122 case MESA_FORMAT_ARGB1555
:
1123 unpack_ubyte_ARGB1555(src
, dst
, n
);
1125 case MESA_FORMAT_ARGB1555_REV
:
1126 unpack_ubyte_ARGB1555_REV(src
, dst
, n
);
1128 case MESA_FORMAT_AL44
:
1129 unpack_ubyte_AL44(src
, dst
, n
);
1131 case MESA_FORMAT_AL88
:
1132 unpack_ubyte_AL88(src
, dst
, n
);
1134 case MESA_FORMAT_AL88_REV
:
1135 unpack_ubyte_AL88_REV(src
, dst
, n
);
1137 case MESA_FORMAT_RGB332
:
1138 unpack_ubyte_RGB332(src
, dst
, n
);
1140 case MESA_FORMAT_A8
:
1141 unpack_ubyte_A8(src
, dst
, n
);
1143 case MESA_FORMAT_L8
:
1144 unpack_ubyte_L8(src
, dst
, n
);
1146 case MESA_FORMAT_I8
:
1147 unpack_ubyte_I8(src
, dst
, n
);
1150 /* get float values, convert to ubyte */
1152 GLfloat
*tmp
= (GLfloat
*) malloc(n
* 4 * sizeof(GLfloat
));
1155 _mesa_unpack_rgba_row(format
, n
, src
, (GLfloat (*)[4]) tmp
);
1156 for (i
= 0; i
< n
; i
++) {
1157 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][0], tmp
[i
*4+0]);
1158 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][1], tmp
[i
*4+1]);
1159 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][2], tmp
[i
*4+2]);
1160 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][3], tmp
[i
*4+3]);
1170 /**********************************************************************/
1171 /* Unpack, returning GLuint colors */
1172 /**********************************************************************/
1175 unpack_int_rgba_RGBA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
1177 memcpy(dst
, src
, n
* 4 * sizeof(GLuint
));
1181 unpack_int_rgba_RGBA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
1185 for (i
= 0; i
< n
; i
++) {
1186 dst
[i
][0] = src
[i
* 4 + 0];
1187 dst
[i
][1] = src
[i
* 4 + 1];
1188 dst
[i
][2] = src
[i
* 4 + 2];
1189 dst
[i
][3] = src
[i
* 4 + 3];
1194 unpack_int_rgba_RGBA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
1198 for (i
= 0; i
< n
; i
++) {
1199 dst
[i
][0] = src
[i
* 4 + 0];
1200 dst
[i
][1] = src
[i
* 4 + 1];
1201 dst
[i
][2] = src
[i
* 4 + 2];
1202 dst
[i
][3] = src
[i
* 4 + 3];
1207 unpack_int_rgba_RGBA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
1211 for (i
= 0; i
< n
; i
++) {
1212 dst
[i
][0] = src
[i
* 4 + 0];
1213 dst
[i
][1] = src
[i
* 4 + 1];
1214 dst
[i
][2] = src
[i
* 4 + 2];
1215 dst
[i
][3] = src
[i
* 4 + 3];
1220 unpack_int_rgba_RGBA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
1224 for (i
= 0; i
< n
; i
++) {
1225 dst
[i
][0] = src
[i
* 4 + 0];
1226 dst
[i
][1] = src
[i
* 4 + 1];
1227 dst
[i
][2] = src
[i
* 4 + 2];
1228 dst
[i
][3] = src
[i
* 4 + 3];
1233 unpack_int_rgba_RGB_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
1237 for (i
= 0; i
< n
; i
++) {
1238 dst
[i
][0] = src
[i
* 3 + 0];
1239 dst
[i
][1] = src
[i
* 3 + 1];
1240 dst
[i
][2] = src
[i
* 3 + 2];
1246 unpack_int_rgba_RGB_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
1250 for (i
= 0; i
< n
; i
++) {
1251 dst
[i
][0] = src
[i
* 3 + 0];
1252 dst
[i
][1] = src
[i
* 3 + 1];
1253 dst
[i
][2] = src
[i
* 3 + 2];
1259 unpack_int_rgba_RGB_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
1263 for (i
= 0; i
< n
; i
++) {
1264 dst
[i
][0] = src
[i
* 3 + 0];
1265 dst
[i
][1] = src
[i
* 3 + 1];
1266 dst
[i
][2] = src
[i
* 3 + 2];
1272 unpack_int_rgba_RGB_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
1276 for (i
= 0; i
< n
; i
++) {
1277 dst
[i
][0] = src
[i
* 3 + 0];
1278 dst
[i
][1] = src
[i
* 3 + 1];
1279 dst
[i
][2] = src
[i
* 3 + 2];
1285 unpack_int_rgba_RGB_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
1289 for (i
= 0; i
< n
; i
++) {
1290 dst
[i
][0] = src
[i
* 3 + 0];
1291 dst
[i
][1] = src
[i
* 3 + 1];
1292 dst
[i
][2] = src
[i
* 3 + 2];
1298 unpack_int_rgba_ALPHA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
1302 for (i
= 0; i
< n
; i
++) {
1303 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
1309 unpack_int_rgba_ALPHA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
1313 for (i
= 0; i
< n
; i
++) {
1314 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
1320 unpack_int_rgba_ALPHA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
1324 for (i
= 0; i
< n
; i
++) {
1325 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
1331 unpack_int_rgba_ALPHA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
1335 for (i
= 0; i
< n
; i
++) {
1336 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
1342 unpack_int_rgba_ALPHA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
1346 for (i
= 0; i
< n
; i
++) {
1347 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
1353 unpack_int_rgba_LUMINANCE_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
1357 for (i
= 0; i
< n
; i
++) {
1358 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
1364 unpack_int_rgba_LUMINANCE_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
1368 for (i
= 0; i
< n
; i
++) {
1369 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
1375 unpack_int_rgba_LUMINANCE_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
1379 for (i
= 0; i
< n
; i
++) {
1380 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
1386 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
1390 for (i
= 0; i
< n
; i
++) {
1391 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
1397 unpack_int_rgba_LUMINANCE_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
1401 for (i
= 0; i
< n
; i
++) {
1402 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
1409 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
1413 for (i
= 0; i
< n
; i
++) {
1414 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
1415 dst
[i
][3] = src
[i
* 2 + 1];
1420 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
1424 for (i
= 0; i
< n
; i
++) {
1425 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
1426 dst
[i
][3] = src
[i
* 2 + 1];
1431 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
1435 for (i
= 0; i
< n
; i
++) {
1436 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
1437 dst
[i
][3] = src
[i
* 2 + 1];
1442 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
1446 for (i
= 0; i
< n
; i
++) {
1447 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
1448 dst
[i
][3] = src
[i
* 2 + 1];
1453 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
1457 for (i
= 0; i
< n
; i
++) {
1458 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
1459 dst
[i
][3] = src
[i
* 2 + 1];
1464 unpack_int_rgba_INTENSITY_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
1468 for (i
= 0; i
< n
; i
++) {
1469 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
1474 unpack_int_rgba_INTENSITY_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
1478 for (i
= 0; i
< n
; i
++) {
1479 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
1484 unpack_int_rgba_INTENSITY_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
1488 for (i
= 0; i
< n
; i
++) {
1489 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
1494 unpack_int_rgba_INTENSITY_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
1498 for (i
= 0; i
< n
; i
++) {
1499 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
1504 unpack_int_rgba_INTENSITY_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
1508 for (i
= 0; i
< n
; i
++) {
1509 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
1514 _mesa_unpack_uint_rgba_row(gl_format format
, GLuint n
,
1515 const void *src
, GLuint dst
[][4])
1518 /* Since there won't be any sign extension happening, there's no need to
1519 * make separate paths for 32-bit-to-32-bit integer unpack.
1521 case MESA_FORMAT_RGBA_UINT32
:
1522 case MESA_FORMAT_RGBA_INT32
:
1523 unpack_int_rgba_RGBA_UINT32(src
, dst
, n
);
1526 case MESA_FORMAT_RGBA_UINT16
:
1527 unpack_int_rgba_RGBA_UINT16(src
, dst
, n
);
1529 case MESA_FORMAT_RGBA_INT16
:
1530 unpack_int_rgba_RGBA_INT16(src
, dst
, n
);
1533 case MESA_FORMAT_RGBA_UINT8
:
1534 unpack_int_rgba_RGBA_UINT8(src
, dst
, n
);
1536 case MESA_FORMAT_RGBA_INT8
:
1537 unpack_int_rgba_RGBA_INT8(src
, dst
, n
);
1540 case MESA_FORMAT_RGB_UINT32
:
1541 case MESA_FORMAT_RGB_INT32
:
1542 unpack_int_rgba_RGB_UINT32(src
, dst
, n
);
1545 case MESA_FORMAT_RGB_UINT16
:
1546 unpack_int_rgba_RGB_UINT16(src
, dst
, n
);
1548 case MESA_FORMAT_RGB_INT16
:
1549 unpack_int_rgba_RGB_INT16(src
, dst
, n
);
1552 case MESA_FORMAT_RGB_UINT8
:
1553 unpack_int_rgba_RGB_UINT8(src
, dst
, n
);
1555 case MESA_FORMAT_RGB_INT8
:
1556 unpack_int_rgba_RGB_INT8(src
, dst
, n
);
1559 case MESA_FORMAT_ALPHA_UINT32
:
1560 case MESA_FORMAT_ALPHA_INT32
:
1561 unpack_int_rgba_ALPHA_UINT32(src
, dst
, n
);
1564 case MESA_FORMAT_ALPHA_UINT16
:
1565 unpack_int_rgba_ALPHA_UINT16(src
, dst
, n
);
1567 case MESA_FORMAT_ALPHA_INT16
:
1568 unpack_int_rgba_ALPHA_INT16(src
, dst
, n
);
1571 case MESA_FORMAT_ALPHA_UINT8
:
1572 unpack_int_rgba_ALPHA_UINT8(src
, dst
, n
);
1574 case MESA_FORMAT_ALPHA_INT8
:
1575 unpack_int_rgba_ALPHA_INT8(src
, dst
, n
);
1578 case MESA_FORMAT_LUMINANCE_UINT32
:
1579 case MESA_FORMAT_LUMINANCE_INT32
:
1580 unpack_int_rgba_LUMINANCE_UINT32(src
, dst
, n
);
1582 case MESA_FORMAT_LUMINANCE_UINT16
:
1583 unpack_int_rgba_LUMINANCE_UINT16(src
, dst
, n
);
1585 case MESA_FORMAT_LUMINANCE_INT16
:
1586 unpack_int_rgba_LUMINANCE_INT16(src
, dst
, n
);
1589 case MESA_FORMAT_LUMINANCE_UINT8
:
1590 unpack_int_rgba_LUMINANCE_UINT8(src
, dst
, n
);
1592 case MESA_FORMAT_LUMINANCE_INT8
:
1593 unpack_int_rgba_LUMINANCE_INT8(src
, dst
, n
);
1596 case MESA_FORMAT_LUMINANCE_ALPHA_UINT32
:
1597 case MESA_FORMAT_LUMINANCE_ALPHA_INT32
:
1598 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src
, dst
, n
);
1601 case MESA_FORMAT_LUMINANCE_ALPHA_UINT16
:
1602 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src
, dst
, n
);
1604 case MESA_FORMAT_LUMINANCE_ALPHA_INT16
:
1605 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src
, dst
, n
);
1608 case MESA_FORMAT_LUMINANCE_ALPHA_UINT8
:
1609 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src
, dst
, n
);
1611 case MESA_FORMAT_LUMINANCE_ALPHA_INT8
:
1612 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src
, dst
, n
);
1615 case MESA_FORMAT_INTENSITY_UINT32
:
1616 case MESA_FORMAT_INTENSITY_INT32
:
1617 unpack_int_rgba_INTENSITY_UINT32(src
, dst
, n
);
1620 case MESA_FORMAT_INTENSITY_UINT16
:
1621 unpack_int_rgba_INTENSITY_UINT16(src
, dst
, n
);
1623 case MESA_FORMAT_INTENSITY_INT16
:
1624 unpack_int_rgba_INTENSITY_INT16(src
, dst
, n
);
1627 case MESA_FORMAT_INTENSITY_UINT8
:
1628 unpack_int_rgba_INTENSITY_UINT8(src
, dst
, n
);
1630 case MESA_FORMAT_INTENSITY_INT8
:
1631 unpack_int_rgba_INTENSITY_INT8(src
, dst
, n
);
1635 _mesa_problem(NULL
, "%s: bad format %s", __FUNCTION__
,
1636 _mesa_get_format_name(format
));
1642 * Unpack a 2D rect of pixels returning float RGBA colors.
1643 * \param format the source image format
1644 * \param src start address of the source image
1645 * \param srcRowStride source image row stride in bytes
1646 * \param dst start address of the dest image
1647 * \param dstRowStride dest image row stride in bytes
1648 * \param x source image start X pos
1649 * \param y source image start Y pos
1650 * \param width width of rect region to convert
1651 * \param height height of rect region to convert
1654 _mesa_unpack_rgba_block(gl_format format
,
1655 const void *src
, GLint srcRowStride
,
1656 GLfloat dst
[][4], GLint dstRowStride
,
1657 GLuint x
, GLuint y
, GLuint width
, GLuint height
)
1659 unpack_rgba_func unpack
= get_unpack_rgba_function(format
);
1660 const GLuint srcPixStride
= _mesa_get_format_bytes(format
);
1661 const GLuint dstPixStride
= 4 * sizeof(GLfloat
);
1662 const GLubyte
*srcRow
;
1666 /* XXX needs to be fixed for compressed formats */
1668 srcRow
= ((const GLubyte
*) src
) + srcRowStride
* y
+ srcPixStride
* x
;
1669 dstRow
= ((GLubyte
*) dst
) + dstRowStride
* y
+ dstPixStride
* x
;
1671 for (i
= 0; i
< height
; i
++) {
1672 unpack(srcRow
, (GLfloat (*)[4]) dstRow
, width
);
1674 dstRow
+= dstRowStride
;
1675 srcRow
+= srcRowStride
;
1682 typedef void (*unpack_float_z_func
)(GLuint n
, const void *src
, GLfloat
*dst
);
1685 unpack_float_z_Z24_X8(GLuint n
, const void *src
, GLfloat
*dst
)
1687 /* only return Z, not stencil data */
1688 const GLuint
*s
= ((const GLuint
*) src
);
1689 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
1691 for (i
= 0; i
< n
; i
++) {
1692 dst
[i
] = (s
[i
] >> 8) * scale
;
1693 ASSERT(dst
[i
] >= 0.0F
);
1694 ASSERT(dst
[i
] <= 1.0F
);
1699 unpack_float_z_X8_Z24(GLuint n
, const void *src
, GLfloat
*dst
)
1701 /* only return Z, not stencil data */
1702 const GLuint
*s
= ((const GLuint
*) src
);
1703 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
1705 for (i
= 0; i
< n
; i
++) {
1706 dst
[i
] = (s
[i
] & 0x00ffffff) * scale
;
1707 ASSERT(dst
[i
] >= 0.0F
);
1708 ASSERT(dst
[i
] <= 1.0F
);
1713 unpack_float_z_Z16(GLuint n
, const void *src
, GLfloat
*dst
)
1715 const GLushort
*s
= ((const GLushort
*) src
);
1717 for (i
= 0; i
< n
; i
++) {
1718 dst
[i
] = s
[i
] * (1.0F
/ 65535.0F
);
1723 unpack_float_z_Z32(GLuint n
, const void *src
, GLfloat
*dst
)
1725 const GLuint
*s
= ((const GLuint
*) src
);
1727 for (i
= 0; i
< n
; i
++) {
1728 dst
[i
] = s
[i
] * (1.0F
/ 0xffffffff);
1736 * The returned values will always be in the range [0.0, 1.0].
1739 _mesa_unpack_float_z_row(gl_format format
, GLuint n
,
1740 const void *src
, GLfloat
*dst
)
1742 unpack_float_z_func unpack
;
1745 case MESA_FORMAT_Z24_X8
:
1746 unpack
= unpack_float_z_Z24_X8
;
1748 case MESA_FORMAT_X8_Z24
:
1749 unpack
= unpack_float_z_X8_Z24
;
1751 case MESA_FORMAT_Z16
:
1752 unpack
= unpack_float_z_Z16
;
1754 case MESA_FORMAT_Z32
:
1755 unpack
= unpack_float_z_Z32
;
1758 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_float_z_row",
1759 _mesa_get_format_name(format
));
1763 unpack(n
, src
, dst
);
1768 typedef void (*unpack_uint_z_func
)(const void *src
, GLuint
*dst
, GLuint n
);
1771 unpack_uint_z_Z24_X8(const void *src
, GLuint
*dst
, GLuint n
)
1773 /* only return Z, not stencil data */
1774 const GLuint
*s
= ((const GLuint
*) src
);
1776 for (i
= 0; i
< n
; i
++) {
1777 dst
[i
] = (s
[i
] & 0xffffff00) | (s
[i
] >> 24);
1782 unpack_uint_z_X8_Z24(const void *src
, GLuint
*dst
, GLuint n
)
1784 /* only return Z, not stencil data */
1785 const GLuint
*s
= ((const GLuint
*) src
);
1787 for (i
= 0; i
< n
; i
++) {
1788 dst
[i
] = (s
[i
] << 8) | ((s
[i
] >> 16) & 0xff);
1793 unpack_uint_z_Z16(const void *src
, GLuint
*dst
, GLuint n
)
1795 const GLushort
*s
= ((const GLushort
*)src
);
1797 for (i
= 0; i
< n
; i
++) {
1798 dst
[i
] = (s
[i
] << 16) | s
[i
];
1803 unpack_uint_z_Z32(const void *src
, GLuint
*dst
, GLuint n
)
1805 memcpy(dst
, src
, n
* sizeof(GLuint
));
1811 * The returned values will always be in the range [0, 0xffffffff].
1814 _mesa_unpack_uint_z_row(gl_format format
, GLuint n
,
1815 const void *src
, GLuint
*dst
)
1817 unpack_uint_z_func unpack
;
1818 const GLubyte
*srcPtr
= (GLubyte
*) src
;
1821 case MESA_FORMAT_Z24_X8
:
1822 unpack
= unpack_uint_z_Z24_X8
;
1824 case MESA_FORMAT_X8_Z24
:
1825 unpack
= unpack_uint_z_X8_Z24
;
1827 case MESA_FORMAT_Z16
:
1828 unpack
= unpack_uint_z_Z16
;
1830 case MESA_FORMAT_Z32
:
1831 unpack
= unpack_uint_z_Z32
;
1834 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_uint_z_row",
1835 _mesa_get_format_name(format
));
1839 unpack(srcPtr
, dst
, n
);
1844 unpack_ubyte_s_S8(const void *src
, GLubyte
*dst
, GLuint n
)
1846 memcpy(dst
, src
, n
);
1850 _mesa_unpack_ubyte_stencil_row(gl_format format
, GLuint n
,
1851 const void *src
, GLubyte
*dst
)
1854 case MESA_FORMAT_S8
:
1855 unpack_ubyte_s_S8(src
, dst
, n
);
1858 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_ubyte_s_row",
1859 _mesa_get_format_name(format
));