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) )
42 * Convert an 8-bit sRGB value from non-linear space to a
43 * linear RGB value in [0, 1].
44 * Implemented with a 256-entry lookup table.
47 nonlinear_to_linear(GLubyte cs8
)
49 static GLfloat table
[256];
50 static GLboolean tableReady
= GL_FALSE
;
52 /* compute lookup table now */
54 for (i
= 0; i
< 256; i
++) {
55 const GLfloat cs
= UBYTE_TO_FLOAT(i
);
57 table
[i
] = cs
/ 12.92f
;
60 table
[i
] = (GLfloat
) pow((cs
+ 0.055) / 1.055, 2.4);
69 /**********************************************************************/
70 /* Unpack, returning GLfloat colors */
71 /**********************************************************************/
73 typedef void (*unpack_rgba_func
)(const void *src
, GLfloat dst
[][4], GLuint n
);
77 unpack_RGBA8888(const void *src
, GLfloat dst
[][4], GLuint n
)
79 const GLuint
*s
= ((const GLuint
*) src
);
81 for (i
= 0; i
< n
; i
++) {
82 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
83 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
84 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
85 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
90 unpack_RGBA8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
92 const GLuint
*s
= ((const GLuint
*) src
);
94 for (i
= 0; i
< n
; i
++) {
95 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
96 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
97 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
98 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
103 unpack_ARGB8888(const void *src
, GLfloat dst
[][4], GLuint n
)
105 const GLuint
*s
= ((const GLuint
*) src
);
107 for (i
= 0; i
< n
; i
++) {
108 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
109 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
110 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
111 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
116 unpack_ARGB8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
118 const GLuint
*s
= ((const GLuint
*) src
);
120 for (i
= 0; i
< n
; i
++) {
121 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
122 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
123 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
124 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
129 unpack_RGBX8888(const void *src
, GLfloat dst
[][4], GLuint n
)
131 const GLuint
*s
= ((const GLuint
*) src
);
133 for (i
= 0; i
< n
; i
++) {
134 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
135 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
136 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
137 dst
[i
][ACOMP
] = 1.0f
;
142 unpack_RGBX8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
144 const GLuint
*s
= ((const GLuint
*) src
);
146 for (i
= 0; i
< n
; i
++) {
147 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
148 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
149 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
150 dst
[i
][ACOMP
] = 1.0f
;
155 unpack_XRGB8888(const void *src
, GLfloat dst
[][4], GLuint n
)
157 const GLuint
*s
= ((const GLuint
*) src
);
159 for (i
= 0; i
< n
; i
++) {
160 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
161 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
162 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] ) & 0xff );
163 dst
[i
][ACOMP
] = 1.0f
;
168 unpack_XRGB8888_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
170 const GLuint
*s
= ((const GLuint
*) src
);
172 for (i
= 0; i
< n
; i
++) {
173 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 8) & 0xff );
174 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 16) & 0xff );
175 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( (s
[i
] >> 24) );
176 dst
[i
][ACOMP
] = 1.0f
;
181 unpack_RGB888(const void *src
, GLfloat dst
[][4], GLuint n
)
183 const GLubyte
*s
= (const GLubyte
*) src
;
185 for (i
= 0; i
< n
; i
++) {
186 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+2] );
187 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+1] );
188 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+0] );
189 dst
[i
][ACOMP
] = 1.0F
;
194 unpack_BGR888(const void *src
, GLfloat dst
[][4], GLuint n
)
196 const GLubyte
*s
= (const GLubyte
*) src
;
198 for (i
= 0; i
< n
; i
++) {
199 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+0] );
200 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+1] );
201 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
*3+2] );
202 dst
[i
][ACOMP
] = 1.0F
;
207 unpack_RGB565(const void *src
, GLfloat dst
[][4], GLuint n
)
209 const GLushort
*s
= ((const GLushort
*) src
);
211 for (i
= 0; i
< n
; i
++) {
212 dst
[i
][RCOMP
] = ((s
[i
] >> 11) & 0x1f) * (1.0F
/ 31.0F
);
213 dst
[i
][GCOMP
] = ((s
[i
] >> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
214 dst
[i
][BCOMP
] = ((s
[i
] ) & 0x1f) * (1.0F
/ 31.0F
);
215 dst
[i
][ACOMP
] = 1.0F
;
220 unpack_RGB565_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
222 const GLushort
*s
= ((const GLushort
*) src
);
224 for (i
= 0; i
< n
; i
++) {
225 GLuint t
= (s
[i
] >> 8) | (s
[i
] << 8); /* byte swap */
226 dst
[i
][RCOMP
] = UBYTE_TO_FLOAT( ((t
>> 8) & 0xf8) | ((t
>> 13) & 0x7) );
227 dst
[i
][GCOMP
] = UBYTE_TO_FLOAT( ((t
>> 3) & 0xfc) | ((t
>> 9) & 0x3) );
228 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( ((t
<< 3) & 0xf8) | ((t
>> 2) & 0x7) );
229 dst
[i
][ACOMP
] = 1.0F
;
234 unpack_ARGB4444(const void *src
, GLfloat dst
[][4], GLuint n
)
236 const GLushort
*s
= ((const GLushort
*) src
);
238 for (i
= 0; i
< n
; i
++) {
239 dst
[i
][RCOMP
] = ((s
[i
] >> 8) & 0xf) * (1.0F
/ 15.0F
);
240 dst
[i
][GCOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
241 dst
[i
][BCOMP
] = ((s
[i
] ) & 0xf) * (1.0F
/ 15.0F
);
242 dst
[i
][ACOMP
] = ((s
[i
] >> 12) & 0xf) * (1.0F
/ 15.0F
);
247 unpack_ARGB4444_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
249 const GLushort
*s
= ((const GLushort
*) src
);
251 for (i
= 0; i
< n
; i
++) {
252 dst
[i
][RCOMP
] = ((s
[i
] ) & 0xf) * (1.0F
/ 15.0F
);
253 dst
[i
][GCOMP
] = ((s
[i
] >> 12) & 0xf) * (1.0F
/ 15.0F
);
254 dst
[i
][BCOMP
] = ((s
[i
] >> 8) & 0xf) * (1.0F
/ 15.0F
);
255 dst
[i
][ACOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
260 unpack_RGBA5551(const void *src
, GLfloat dst
[][4], GLuint n
)
262 const GLushort
*s
= ((const GLushort
*) src
);
264 for (i
= 0; i
< n
; i
++) {
265 dst
[i
][RCOMP
] = ((s
[i
] >> 11) & 0x1f) * (1.0F
/ 31.0F
);
266 dst
[i
][GCOMP
] = ((s
[i
] >> 6) & 0x1f) * (1.0F
/ 31.0F
);
267 dst
[i
][BCOMP
] = ((s
[i
] >> 1) & 0x1f) * (1.0F
/ 31.0F
);
268 dst
[i
][ACOMP
] = ((s
[i
] ) & 0x01) * 1.0F
;
273 unpack_ARGB1555(const void *src
, GLfloat dst
[][4], GLuint n
)
275 const GLushort
*s
= ((const GLushort
*) src
);
277 for (i
= 0; i
< n
; i
++) {
278 dst
[i
][RCOMP
] = ((s
[i
] >> 10) & 0x1f) * (1.0F
/ 31.0F
);
279 dst
[i
][GCOMP
] = ((s
[i
] >> 5) & 0x1f) * (1.0F
/ 31.0F
);
280 dst
[i
][BCOMP
] = ((s
[i
] >> 0) & 0x1f) * (1.0F
/ 31.0F
);
281 dst
[i
][ACOMP
] = ((s
[i
] >> 15) & 0x01) * 1.0F
;
286 unpack_ARGB1555_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
288 const GLushort
*s
= ((const GLushort
*) src
);
290 for (i
= 0; i
< n
; i
++) {
291 GLushort tmp
= (s
[i
] << 8) | (s
[i
] >> 8); /* byteswap */
292 dst
[i
][RCOMP
] = ((tmp
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
293 dst
[i
][GCOMP
] = ((tmp
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
294 dst
[i
][BCOMP
] = ((tmp
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
295 dst
[i
][ACOMP
] = ((tmp
>> 15) & 0x01) * 1.0F
;
300 unpack_AL44(const void *src
, GLfloat dst
[][4], GLuint n
)
302 const GLubyte
*s
= ((const GLubyte
*) src
);
304 for (i
= 0; i
< n
; i
++) {
307 dst
[i
][BCOMP
] = (s
[i
] & 0xf) * (1.0F
/ 15.0F
);
308 dst
[i
][ACOMP
] = ((s
[i
] >> 4) & 0xf) * (1.0F
/ 15.0F
);
313 unpack_AL88(const void *src
, GLfloat dst
[][4], GLuint n
)
315 const GLushort
*s
= ((const GLushort
*) src
);
317 for (i
= 0; i
< n
; i
++) {
320 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
321 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
326 unpack_AL88_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
328 const GLushort
*s
= ((const GLushort
*) src
);
330 for (i
= 0; i
< n
; i
++) {
333 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT( s
[i
] >> 8 );
334 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT( s
[i
] & 0xff );
339 unpack_AL1616(const void *src
, GLfloat dst
[][4], GLuint n
)
341 const GLuint
*s
= ((const GLuint
*) src
);
343 for (i
= 0; i
< n
; i
++) {
346 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
347 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
352 unpack_AL1616_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
354 const GLuint
*s
= ((const GLuint
*) src
);
356 for (i
= 0; i
< n
; i
++) {
359 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
] >> 16 );
360 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
] & 0xffff );
365 unpack_RGB332(const void *src
, GLfloat dst
[][4], GLuint n
)
367 const GLubyte
*s
= ((const GLubyte
*) src
);
369 for (i
= 0; i
< n
; i
++) {
370 dst
[i
][RCOMP
] = ((s
[i
] >> 5) & 0x7) * (1.0F
/ 7.0F
);
371 dst
[i
][GCOMP
] = ((s
[i
] >> 2) & 0x7) * (1.0F
/ 7.0F
);
372 dst
[i
][BCOMP
] = ((s
[i
] ) & 0x3) * (1.0F
/ 3.0F
);
373 dst
[i
][ACOMP
] = 1.0F
;
379 unpack_A8(const void *src
, GLfloat dst
[][4], GLuint n
)
381 const GLubyte
*s
= ((const GLubyte
*) src
);
383 for (i
= 0; i
< n
; i
++) {
386 dst
[i
][BCOMP
] = 0.0F
;
387 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
]);
392 unpack_A16(const void *src
, GLfloat dst
[][4], GLuint n
)
394 const GLushort
*s
= ((const GLushort
*) src
);
396 for (i
= 0; i
< n
; i
++) {
399 dst
[i
][BCOMP
] = 0.0F
;
400 dst
[i
][ACOMP
] = USHORT_TO_FLOAT(s
[i
]);
405 unpack_L8(const void *src
, GLfloat dst
[][4], GLuint n
)
407 const GLubyte
*s
= ((const GLubyte
*) src
);
409 for (i
= 0; i
< n
; i
++) {
412 dst
[i
][BCOMP
] = UBYTE_TO_FLOAT(s
[i
]);
413 dst
[i
][ACOMP
] = 1.0F
;
418 unpack_L16(const void *src
, GLfloat dst
[][4], GLuint n
)
420 const GLushort
*s
= ((const GLushort
*) src
);
422 for (i
= 0; i
< n
; i
++) {
425 dst
[i
][BCOMP
] = USHORT_TO_FLOAT(s
[i
]);
426 dst
[i
][ACOMP
] = 1.0F
;
431 unpack_I8(const void *src
, GLfloat dst
[][4], GLuint n
)
433 const GLubyte
*s
= ((const GLubyte
*) src
);
435 for (i
= 0; i
< n
; i
++) {
439 dst
[i
][ACOMP
] = UBYTE_TO_FLOAT(s
[i
]);
444 unpack_I16(const void *src
, GLfloat dst
[][4], GLuint n
)
446 const GLushort
*s
= ((const GLushort
*) src
);
448 for (i
= 0; i
< n
; i
++) {
452 dst
[i
][ACOMP
] = USHORT_TO_FLOAT(s
[i
]);
457 unpack_YCBCR(const void *src
, GLfloat dst
[][4], GLuint n
)
460 for (i
= 0; i
< n
; i
++) {
461 const GLushort
*src0
= ((const GLushort
*) src
) + i
* 2; /* even */
462 const GLushort
*src1
= src0
+ 1; /* odd */
463 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
464 const GLubyte cb
= *src0
& 0xff; /* chroma U */
465 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
466 const GLubyte cr
= *src1
& 0xff; /* chroma V */
467 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
468 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
469 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
470 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
471 r
*= (1.0F
/ 255.0F
);
472 g
*= (1.0F
/ 255.0F
);
473 b
*= (1.0F
/ 255.0F
);
474 dst
[i
][RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
475 dst
[i
][GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
476 dst
[i
][BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
477 dst
[i
][ACOMP
] = 1.0F
;
482 unpack_YCBCR_REV(const void *src
, GLfloat dst
[][4], GLuint n
)
485 for (i
= 0; i
< n
; i
++) {
486 const GLushort
*src0
= ((const GLushort
*) src
) + i
* 2; /* even */
487 const GLushort
*src1
= src0
+ 1; /* odd */
488 const GLubyte y0
= *src0
& 0xff; /* luminance */
489 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
490 const GLubyte y1
= *src1
& 0xff; /* luminance */
491 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
492 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
493 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
494 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
495 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
496 r
*= (1.0F
/ 255.0F
);
497 g
*= (1.0F
/ 255.0F
);
498 b
*= (1.0F
/ 255.0F
);
499 dst
[i
][RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
500 dst
[i
][GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
501 dst
[i
][BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
502 dst
[i
][ACOMP
] = 1.0F
;
508 unpack_Z24_S8(const void *src
, GLfloat dst
[][4], GLuint n
)
510 /* only return Z, not stencil data */
511 const GLuint
*s
= ((const GLuint
*) src
);
512 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
514 for (i
= 0; i
< n
; i
++) {
517 dst
[i
][2] = (s
[i
] >> 8) * scale
;
519 ASSERT(dst
[i
][0] >= 0.0F
);
520 ASSERT(dst
[i
][0] <= 1.0F
);
525 unpack_S8_Z24(const void *src
, GLfloat dst
[][4], GLuint n
)
527 /* only return Z, not stencil data */
528 const GLuint
*s
= ((const GLuint
*) src
);
529 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
531 for (i
= 0; i
< n
; i
++) {
534 dst
[i
][2] = (s
[i
] & 0x00ffffff) * scale
;
536 ASSERT(dst
[i
][0] >= 0.0F
);
537 ASSERT(dst
[i
][0] <= 1.0F
);
542 unpack_Z16(const void *src
, GLfloat dst
[][4], GLuint n
)
544 const GLushort
*s
= ((const GLushort
*) src
);
546 for (i
= 0; i
< n
; i
++) {
549 dst
[i
][2] = s
[i
] * (1.0F
/ 65535.0F
);
555 unpack_X8_Z24(const void *src
, GLfloat dst
[][4], GLuint n
)
557 unpack_S8_Z24(src
, dst
, n
);
561 unpack_Z24_X8(const void *src
, GLfloat dst
[][4], GLuint n
)
563 unpack_Z24_S8(src
, dst
, n
);
567 unpack_Z32(const void *src
, GLfloat dst
[][4], GLuint n
)
569 const GLuint
*s
= ((const GLuint
*) src
);
571 for (i
= 0; i
< n
; i
++) {
574 dst
[i
][2] = s
[i
] * (1.0F
/ 0xffffffff);
581 unpack_S8(const void *src
, GLfloat dst
[][4], GLuint n
)
583 /* should never be used */
585 for (i
= 0; i
< n
; i
++) {
594 unpack_RGBA_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
596 const GLfloat
*s
= (const GLfloat
*) src
;
598 for (i
= 0; i
< n
; i
++) {
599 dst
[i
][RCOMP
] = s
[i
*4+0];
600 dst
[i
][GCOMP
] = s
[i
*4+1];
601 dst
[i
][BCOMP
] = s
[i
*4+2];
602 dst
[i
][ACOMP
] = s
[i
*4+3];
607 unpack_RGBA_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
609 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
611 for (i
= 0; i
< n
; i
++) {
612 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
*4+0]);
613 dst
[i
][GCOMP
] = _mesa_half_to_float(s
[i
*4+1]);
614 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
*4+2]);
615 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
*4+3]);
620 unpack_RGB_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
622 const GLfloat
*s
= (const GLfloat
*) src
;
624 for (i
= 0; i
< n
; i
++) {
625 dst
[i
][RCOMP
] = s
[i
*3+0];
626 dst
[i
][GCOMP
] = s
[i
*3+1];
627 dst
[i
][BCOMP
] = s
[i
*3+2];
628 dst
[i
][ACOMP
] = 1.0F
;
633 unpack_RGB_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
635 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
637 for (i
= 0; i
< n
; i
++) {
638 dst
[i
][RCOMP
] = _mesa_half_to_float(s
[i
*3+0]);
639 dst
[i
][GCOMP
] = _mesa_half_to_float(s
[i
*3+1]);
640 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
*3+2]);
641 dst
[i
][ACOMP
] = 1.0F
;
646 unpack_ALPHA_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
648 const GLfloat
*s
= (const GLfloat
*) src
;
650 for (i
= 0; i
< n
; i
++) {
653 dst
[i
][BCOMP
] = 0.0F
;
654 dst
[i
][ACOMP
] = s
[i
];
659 unpack_ALPHA_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
661 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
663 for (i
= 0; i
< n
; i
++) {
666 dst
[i
][BCOMP
] = 0.0F
;
667 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
]);
672 unpack_LUMINANCE_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
674 const GLfloat
*s
= (const GLfloat
*) src
;
676 for (i
= 0; i
< n
; i
++) {
679 dst
[i
][BCOMP
] = s
[i
];
680 dst
[i
][ACOMP
] = 1.0F
;
685 unpack_LUMINANCE_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
687 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
689 for (i
= 0; i
< n
; i
++) {
692 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
]);
693 dst
[i
][ACOMP
] = 1.0F
;
698 unpack_LUMINANCE_ALPHA_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
700 const GLfloat
*s
= (const GLfloat
*) src
;
702 for (i
= 0; i
< n
; i
++) {
705 dst
[i
][BCOMP
] = s
[i
*2+0];
706 dst
[i
][ACOMP
] = s
[i
*2+1];
711 unpack_LUMINANCE_ALPHA_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
713 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
715 for (i
= 0; i
< n
; i
++) {
718 dst
[i
][BCOMP
] = _mesa_half_to_float(s
[i
*2+0]);
719 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
*2+1]);
724 unpack_INTENSITY_FLOAT32(const void *src
, GLfloat dst
[][4], GLuint n
)
726 const GLfloat
*s
= (const GLfloat
*) src
;
728 for (i
= 0; i
< n
; i
++) {
732 dst
[i
][ACOMP
] = s
[i
];
737 unpack_INTENSITY_FLOAT16(const void *src
, GLfloat dst
[][4], GLuint n
)
739 const GLhalfARB
*s
= (const GLhalfARB
*) src
;
741 for (i
= 0; i
< n
; i
++) {
745 dst
[i
][ACOMP
] = _mesa_half_to_float(s
[i
]);
750 unpack_RGBA_INT8(const void *src
, GLfloat dst
[][4], GLuint n
)
752 const GLbyte
*s
= (const GLbyte
*) src
;
754 for (i
= 0; i
< n
; i
++) {
755 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
756 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
757 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
758 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
763 unpack_RGBA_INT16(const void *src
, GLfloat dst
[][4], GLuint n
)
765 const GLshort
*s
= (const GLshort
*) src
;
767 for (i
= 0; i
< n
; i
++) {
768 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
769 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
770 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
771 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
776 unpack_RGBA_INT32(const void *src
, GLfloat dst
[][4], GLuint n
)
778 const GLint
*s
= (const GLint
*) src
;
780 for (i
= 0; i
< n
; i
++) {
781 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
782 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
783 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
784 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
789 unpack_RGBA_UINT8(const void *src
, GLfloat dst
[][4], GLuint n
)
791 const GLubyte
*s
= (const GLubyte
*) src
;
793 for (i
= 0; i
< n
; i
++) {
794 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
795 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
796 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
797 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
802 unpack_RGBA_UINT16(const void *src
, GLfloat dst
[][4], GLuint n
)
804 const GLushort
*s
= (const GLushort
*) src
;
806 for (i
= 0; i
< n
; i
++) {
807 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
808 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
809 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
810 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
815 unpack_RGBA_UINT32(const void *src
, GLfloat dst
[][4], GLuint n
)
817 const GLuint
*s
= (const GLuint
*) src
;
819 for (i
= 0; i
< n
; i
++) {
820 dst
[i
][RCOMP
] = (GLfloat
) s
[i
*4+0];
821 dst
[i
][GCOMP
] = (GLfloat
) s
[i
*4+1];
822 dst
[i
][BCOMP
] = (GLfloat
) s
[i
*4+2];
823 dst
[i
][ACOMP
] = (GLfloat
) s
[i
*4+3];
828 unpack_SIGNED_RGBA_16(const void *src
, GLfloat dst
[][4], GLuint n
)
830 const GLshort
*s
= (const GLshort
*) src
;
832 for (i
= 0; i
< n
; i
++) {
833 dst
[i
][RCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+0] );
834 dst
[i
][GCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+1] );
835 dst
[i
][BCOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+2] );
836 dst
[i
][ACOMP
] = SHORT_TO_FLOAT_TEX( s
[i
*4+3] );
841 unpack_RGBA_16(const void *src
, GLfloat dst
[][4], GLuint n
)
843 const GLushort
*s
= (const GLushort
*) src
;
845 for (i
= 0; i
< n
; i
++) {
846 dst
[i
][RCOMP
] = USHORT_TO_FLOAT( s
[i
*4+0] );
847 dst
[i
][GCOMP
] = USHORT_TO_FLOAT( s
[i
*4+1] );
848 dst
[i
][BCOMP
] = USHORT_TO_FLOAT( s
[i
*4+2] );
849 dst
[i
][ACOMP
] = USHORT_TO_FLOAT( s
[i
*4+3] );
855 * Return the unpacker function for the given format.
857 static unpack_rgba_func
858 get_unpack_rgba_function(gl_format format
)
860 static unpack_rgba_func table
[MESA_FORMAT_COUNT
];
861 static GLboolean initialized
= GL_FALSE
;
864 table
[MESA_FORMAT_NONE
] = NULL
;
866 table
[MESA_FORMAT_RGBA8888
] = unpack_RGBA8888
;
867 table
[MESA_FORMAT_RGBA8888_REV
] = unpack_RGBA8888_REV
;
868 table
[MESA_FORMAT_ARGB8888
] = unpack_ARGB8888
;
869 table
[MESA_FORMAT_ARGB8888_REV
] = unpack_ARGB8888_REV
;
870 table
[MESA_FORMAT_RGBX8888
] = unpack_RGBX8888
;
871 table
[MESA_FORMAT_RGBX8888_REV
] = unpack_RGBX8888_REV
;
872 table
[MESA_FORMAT_XRGB8888
] = unpack_XRGB8888
;
873 table
[MESA_FORMAT_XRGB8888_REV
] = unpack_XRGB8888_REV
;
874 table
[MESA_FORMAT_RGB888
] = unpack_RGB888
;
875 table
[MESA_FORMAT_BGR888
] = unpack_BGR888
;
876 table
[MESA_FORMAT_RGB565
] = unpack_RGB565
;
877 table
[MESA_FORMAT_RGB565_REV
] = unpack_RGB565_REV
;
878 table
[MESA_FORMAT_ARGB4444
] = unpack_ARGB4444
;
879 table
[MESA_FORMAT_ARGB4444_REV
] = unpack_ARGB4444_REV
;
880 table
[MESA_FORMAT_RGBA5551
] = unpack_RGBA5551
;
881 table
[MESA_FORMAT_ARGB1555
] = unpack_ARGB1555
;
882 table
[MESA_FORMAT_ARGB1555_REV
] = unpack_ARGB1555_REV
;
883 table
[MESA_FORMAT_AL44
] = unpack_AL44
;
884 table
[MESA_FORMAT_AL88
] = unpack_AL88
;
885 table
[MESA_FORMAT_AL88_REV
] = unpack_AL88_REV
;
886 table
[MESA_FORMAT_AL1616
] = unpack_AL1616
;
887 table
[MESA_FORMAT_AL1616_REV
] = unpack_AL1616_REV
;
888 table
[MESA_FORMAT_RGB332
] = unpack_RGB332
;
889 table
[MESA_FORMAT_A8
] = unpack_A8
;
890 table
[MESA_FORMAT_A16
] = unpack_A16
;
891 table
[MESA_FORMAT_L8
] = unpack_L8
;
892 table
[MESA_FORMAT_L16
] = unpack_L16
;
893 table
[MESA_FORMAT_I8
] = unpack_I8
;
894 table
[MESA_FORMAT_I16
] = unpack_I16
;
895 table
[MESA_FORMAT_YCBCR
] = unpack_YCBCR
;
896 table
[MESA_FORMAT_YCBCR_REV
] = unpack_YCBCR_REV
;
897 table
[MESA_FORMAT_Z16
] = unpack_Z16
;
898 table
[MESA_FORMAT_X8_Z24
] = unpack_X8_Z24
;
899 table
[MESA_FORMAT_Z24_X8
] = unpack_Z24_X8
;
900 table
[MESA_FORMAT_Z32
] = unpack_Z32
;
901 table
[MESA_FORMAT_S8
] = unpack_S8
;
903 table
[MESA_FORMAT_RGBA_FLOAT32
] = unpack_RGBA_FLOAT32
;
904 table
[MESA_FORMAT_RGBA_FLOAT16
] = unpack_RGBA_FLOAT16
;
905 table
[MESA_FORMAT_RGB_FLOAT32
] = unpack_RGB_FLOAT32
;
906 table
[MESA_FORMAT_RGB_FLOAT16
] = unpack_RGB_FLOAT16
;
907 table
[MESA_FORMAT_ALPHA_FLOAT32
] = unpack_ALPHA_FLOAT32
;
908 table
[MESA_FORMAT_ALPHA_FLOAT16
] = unpack_ALPHA_FLOAT16
;
909 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = unpack_LUMINANCE_FLOAT32
;
910 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = unpack_LUMINANCE_FLOAT16
;
911 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = unpack_LUMINANCE_ALPHA_FLOAT32
;
912 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = unpack_LUMINANCE_ALPHA_FLOAT16
;
913 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = unpack_INTENSITY_FLOAT32
;
914 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = unpack_INTENSITY_FLOAT16
;
916 table
[MESA_FORMAT_RGBA_INT8
] = unpack_RGBA_INT8
;
917 table
[MESA_FORMAT_RGBA_INT16
] = unpack_RGBA_INT16
;
918 table
[MESA_FORMAT_RGBA_INT32
] = unpack_RGBA_INT32
;
919 table
[MESA_FORMAT_RGBA_UINT8
] = unpack_RGBA_UINT8
;
920 table
[MESA_FORMAT_RGBA_UINT16
] = unpack_RGBA_UINT16
;
921 table
[MESA_FORMAT_RGBA_UINT32
] = unpack_RGBA_UINT32
;
923 table
[MESA_FORMAT_SIGNED_RGBA_16
] = unpack_SIGNED_RGBA_16
;
924 table
[MESA_FORMAT_RGBA_16
] = unpack_RGBA_16
;
926 initialized
= GL_TRUE
;
929 return table
[format
];
934 * Unpack rgba colors, returning as GLfloat values.
937 _mesa_unpack_rgba_row(gl_format format
, GLuint n
,
938 const void *src
, GLfloat dst
[][4])
940 unpack_rgba_func unpack
= get_unpack_rgba_function(format
);
945 /**********************************************************************/
946 /* Unpack, returning GLubyte colors */
947 /**********************************************************************/
951 unpack_ubyte_RGBA8888(const void *src
, GLubyte dst
[][4], GLuint n
)
953 const GLuint
*s
= ((const GLuint
*) src
);
955 for (i
= 0; i
< n
; i
++) {
956 dst
[i
][RCOMP
] = (s
[i
] >> 24);
957 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
958 dst
[i
][BCOMP
] = (s
[i
] >> 8) & 0xff;
959 dst
[i
][ACOMP
] = (s
[i
] ) & 0xff;
964 unpack_ubyte_RGBA8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
966 const GLuint
*s
= ((const GLuint
*) src
);
968 for (i
= 0; i
< n
; i
++) {
969 dst
[i
][RCOMP
] = (s
[i
] ) & 0xff;
970 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
971 dst
[i
][BCOMP
] = (s
[i
] >> 16) & 0xff;
972 dst
[i
][ACOMP
] = (s
[i
] >> 24);
977 unpack_ubyte_ARGB8888(const void *src
, GLubyte dst
[][4], GLuint n
)
979 const GLuint
*s
= ((const GLuint
*) src
);
981 for (i
= 0; i
< n
; i
++) {
982 dst
[i
][RCOMP
] = (s
[i
] >> 16) & 0xff;
983 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
984 dst
[i
][BCOMP
] = (s
[i
] ) & 0xff;
985 dst
[i
][ACOMP
] = (s
[i
] >> 24);
990 unpack_ubyte_ARGB8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
992 const GLuint
*s
= ((const GLuint
*) src
);
994 for (i
= 0; i
< n
; i
++) {
995 dst
[i
][RCOMP
] = (s
[i
] >> 8) & 0xff;
996 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
997 dst
[i
][BCOMP
] = (s
[i
] >> 24);
998 dst
[i
][ACOMP
] = (s
[i
] ) & 0xff;
1003 unpack_ubyte_RGBX8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1005 const GLuint
*s
= ((const GLuint
*) src
);
1007 for (i
= 0; i
< n
; i
++) {
1008 dst
[i
][RCOMP
] = (s
[i
] >> 24);
1009 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1010 dst
[i
][BCOMP
] = (s
[i
] >> 8) & 0xff;
1011 dst
[i
][ACOMP
] = 0xff;
1016 unpack_ubyte_RGBX8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1018 const GLuint
*s
= ((const GLuint
*) src
);
1020 for (i
= 0; i
< n
; i
++) {
1021 dst
[i
][RCOMP
] = (s
[i
] ) & 0xff;
1022 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1023 dst
[i
][BCOMP
] = (s
[i
] >> 16) & 0xff;
1024 dst
[i
][ACOMP
] = 0xff;
1029 unpack_ubyte_XRGB8888(const void *src
, GLubyte dst
[][4], GLuint n
)
1031 const GLuint
*s
= ((const GLuint
*) src
);
1033 for (i
= 0; i
< n
; i
++) {
1034 dst
[i
][RCOMP
] = (s
[i
] >> 16) & 0xff;
1035 dst
[i
][GCOMP
] = (s
[i
] >> 8) & 0xff;
1036 dst
[i
][BCOMP
] = (s
[i
] ) & 0xff;
1037 dst
[i
][ACOMP
] = 0xff;
1042 unpack_ubyte_XRGB8888_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1044 const GLuint
*s
= ((const GLuint
*) src
);
1046 for (i
= 0; i
< n
; i
++) {
1047 dst
[i
][RCOMP
] = (s
[i
] >> 8) & 0xff;
1048 dst
[i
][GCOMP
] = (s
[i
] >> 16) & 0xff;
1049 dst
[i
][BCOMP
] = (s
[i
] >> 24);
1050 dst
[i
][ACOMP
] = 0xff;
1055 unpack_ubyte_RGB888(const void *src
, GLubyte dst
[][4], GLuint n
)
1057 const GLubyte
*s
= (const GLubyte
*) src
;
1059 for (i
= 0; i
< n
; i
++) {
1060 dst
[i
][RCOMP
] = s
[i
*3+2];
1061 dst
[i
][GCOMP
] = s
[i
*3+1];
1062 dst
[i
][BCOMP
] = s
[i
*3+0];
1063 dst
[i
][ACOMP
] = 0xff;
1068 unpack_ubyte_BGR888(const void *src
, GLubyte dst
[][4], GLuint n
)
1070 const GLubyte
*s
= (const GLubyte
*) src
;
1072 for (i
= 0; i
< n
; i
++) {
1073 dst
[i
][RCOMP
] = s
[i
*3+0];
1074 dst
[i
][GCOMP
] = s
[i
*3+1];
1075 dst
[i
][BCOMP
] = s
[i
*3+2];
1076 dst
[i
][ACOMP
] = 0xff;
1081 unpack_ubyte_RGB565(const void *src
, GLubyte dst
[][4], GLuint n
)
1083 const GLushort
*s
= ((const GLushort
*) src
);
1085 for (i
= 0; i
< n
; i
++) {
1086 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 11) & 0x1f);
1087 dst
[i
][GCOMP
] = EXPAND_6_8((s
[i
] >> 5 ) & 0x3f);
1088 dst
[i
][BCOMP
] = EXPAND_5_8( s
[i
] & 0x1f);
1089 dst
[i
][ACOMP
] = 0xff;
1094 unpack_ubyte_RGB565_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1096 const GLushort
*s
= ((const GLushort
*) src
);
1098 for (i
= 0; i
< n
; i
++) {
1099 GLuint t
= (s
[i
] >> 8) | (s
[i
] << 8); /* byte swap */
1100 dst
[i
][RCOMP
] = EXPAND_5_8((t
>> 11) & 0x1f);
1101 dst
[i
][GCOMP
] = EXPAND_6_8((t
>> 5 ) & 0x3f);
1102 dst
[i
][BCOMP
] = EXPAND_5_8( t
& 0x1f);
1103 dst
[i
][ACOMP
] = 0xff;
1108 unpack_ubyte_ARGB4444(const void *src
, GLubyte dst
[][4], GLuint n
)
1110 const GLushort
*s
= ((const GLushort
*) src
);
1112 for (i
= 0; i
< n
; i
++) {
1113 dst
[i
][RCOMP
] = EXPAND_4_8((s
[i
] >> 8) & 0xf);
1114 dst
[i
][GCOMP
] = EXPAND_4_8((s
[i
] >> 4) & 0xf);
1115 dst
[i
][BCOMP
] = EXPAND_4_8((s
[i
] ) & 0xf);
1116 dst
[i
][ACOMP
] = EXPAND_4_8((s
[i
] >> 12) & 0xf);
1121 unpack_ubyte_ARGB4444_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1123 const GLushort
*s
= ((const GLushort
*) src
);
1125 for (i
= 0; i
< n
; i
++) {
1126 dst
[i
][RCOMP
] = EXPAND_4_8((s
[i
] ) & 0xf);
1127 dst
[i
][GCOMP
] = EXPAND_4_8((s
[i
] >> 12) & 0xf);
1128 dst
[i
][BCOMP
] = EXPAND_4_8((s
[i
] >> 8) & 0xf);
1129 dst
[i
][ACOMP
] = EXPAND_4_8((s
[i
] >> 4) & 0xf);
1134 unpack_ubyte_RGBA5551(const void *src
, GLubyte dst
[][4], GLuint n
)
1136 const GLushort
*s
= ((const GLushort
*) src
);
1138 for (i
= 0; i
< n
; i
++) {
1139 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 11) & 0x1f);
1140 dst
[i
][GCOMP
] = EXPAND_5_8((s
[i
] >> 6) & 0x1f);
1141 dst
[i
][BCOMP
] = EXPAND_5_8((s
[i
] >> 1) & 0x1f);
1142 dst
[i
][ACOMP
] = EXPAND_1_8((s
[i
] ) & 0x01);
1147 unpack_ubyte_ARGB1555(const void *src
, GLubyte dst
[][4], GLuint n
)
1149 const GLushort
*s
= ((const GLushort
*) src
);
1151 for (i
= 0; i
< n
; i
++) {
1152 dst
[i
][RCOMP
] = EXPAND_5_8((s
[i
] >> 10) & 0x1f);
1153 dst
[i
][GCOMP
] = EXPAND_5_8((s
[i
] >> 5) & 0x1f);
1154 dst
[i
][BCOMP
] = EXPAND_5_8((s
[i
] >> 0) & 0x1f);
1155 dst
[i
][ACOMP
] = EXPAND_1_8((s
[i
] >> 15) & 0x01);
1160 unpack_ubyte_ARGB1555_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1162 const GLushort
*s
= ((const GLushort
*) src
);
1164 for (i
= 0; i
< n
; i
++) {
1165 GLushort tmp
= (s
[i
] << 8) | (s
[i
] >> 8); /* byteswap */
1166 dst
[i
][RCOMP
] = EXPAND_5_8((tmp
>> 10) & 0x1f);
1167 dst
[i
][GCOMP
] = EXPAND_5_8((tmp
>> 5) & 0x1f);
1168 dst
[i
][BCOMP
] = EXPAND_5_8((tmp
>> 0) & 0x1f);
1169 dst
[i
][ACOMP
] = EXPAND_1_8((tmp
>> 15) & 0x01);
1174 unpack_ubyte_AL44(const void *src
, GLubyte dst
[][4], GLuint n
)
1176 const GLubyte
*s
= ((const GLubyte
*) src
);
1178 for (i
= 0; i
< n
; i
++) {
1181 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] & 0xf);
1182 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] >> 4);
1187 unpack_ubyte_AL88(const void *src
, GLubyte dst
[][4], GLuint n
)
1189 const GLushort
*s
= ((const GLushort
*) src
);
1191 for (i
= 0; i
< n
; i
++) {
1194 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] & 0xff);
1195 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] >> 8);
1200 unpack_ubyte_AL88_REV(const void *src
, GLubyte dst
[][4], GLuint n
)
1202 const GLushort
*s
= ((const GLushort
*) src
);
1204 for (i
= 0; i
< n
; i
++) {
1207 dst
[i
][BCOMP
] = EXPAND_4_8(s
[i
] >> 8);
1208 dst
[i
][ACOMP
] = EXPAND_4_8(s
[i
] & 0xff);
1213 unpack_ubyte_RGB332(const void *src
, GLubyte dst
[][4], GLuint n
)
1215 const GLubyte
*s
= ((const GLubyte
*) src
);
1217 for (i
= 0; i
< n
; i
++) {
1218 dst
[i
][RCOMP
] = EXPAND_3_8((s
[i
] >> 5) & 0x7);
1219 dst
[i
][GCOMP
] = EXPAND_3_8((s
[i
] >> 2) & 0x7);
1220 dst
[i
][BCOMP
] = EXPAND_2_8((s
[i
] ) & 0x3);
1221 dst
[i
][ACOMP
] = 0xff;
1226 unpack_ubyte_A8(const void *src
, GLubyte dst
[][4], GLuint n
)
1228 const GLubyte
*s
= ((const GLubyte
*) src
);
1230 for (i
= 0; i
< n
; i
++) {
1234 dst
[i
][ACOMP
] = s
[i
];
1239 unpack_ubyte_L8(const void *src
, GLubyte dst
[][4], GLuint n
)
1241 const GLubyte
*s
= ((const GLubyte
*) src
);
1243 for (i
= 0; i
< n
; i
++) {
1246 dst
[i
][BCOMP
] = s
[i
];
1247 dst
[i
][ACOMP
] = 0xff;
1253 unpack_ubyte_I8(const void *src
, GLubyte dst
[][4], GLuint n
)
1255 const GLubyte
*s
= ((const GLubyte
*) src
);
1257 for (i
= 0; i
< n
; i
++) {
1261 dst
[i
][ACOMP
] = s
[i
];
1267 * Unpack rgba colors, returning as GLubyte values. This should usually
1268 * only be used for unpacking formats that use 8 bits or less per channel.
1271 _mesa_unpack_ubyte_rgba_row(gl_format format
, GLuint n
,
1272 const void *src
, GLubyte dst
[][4])
1275 case MESA_FORMAT_RGBA8888
:
1276 unpack_ubyte_RGBA8888(src
, dst
, n
);
1278 case MESA_FORMAT_RGBA8888_REV
:
1279 unpack_ubyte_RGBA8888_REV(src
, dst
, n
);
1281 case MESA_FORMAT_ARGB8888
:
1282 unpack_ubyte_ARGB8888(src
, dst
, n
);
1284 case MESA_FORMAT_ARGB8888_REV
:
1285 unpack_ubyte_ARGB8888_REV(src
, dst
, n
);
1287 case MESA_FORMAT_RGBX8888
:
1288 unpack_ubyte_RGBX8888(src
, dst
, n
);
1290 case MESA_FORMAT_RGBX8888_REV
:
1291 unpack_ubyte_RGBX8888_REV(src
, dst
, n
);
1293 case MESA_FORMAT_XRGB8888
:
1294 unpack_ubyte_XRGB8888(src
, dst
, n
);
1296 case MESA_FORMAT_XRGB8888_REV
:
1297 unpack_ubyte_XRGB8888_REV(src
, dst
, n
);
1299 case MESA_FORMAT_RGB888
:
1300 unpack_ubyte_RGB888(src
, dst
, n
);
1302 case MESA_FORMAT_BGR888
:
1303 unpack_ubyte_BGR888(src
, dst
, n
);
1305 case MESA_FORMAT_RGB565
:
1306 unpack_ubyte_RGB565(src
, dst
, n
);
1308 case MESA_FORMAT_RGB565_REV
:
1309 unpack_ubyte_RGB565_REV(src
, dst
, n
);
1311 case MESA_FORMAT_ARGB4444
:
1312 unpack_ubyte_ARGB4444(src
, dst
, n
);
1314 case MESA_FORMAT_ARGB4444_REV
:
1315 unpack_ubyte_ARGB4444_REV(src
, dst
, n
);
1317 case MESA_FORMAT_RGBA5551
:
1318 unpack_ubyte_RGBA5551(src
, dst
, n
);
1320 case MESA_FORMAT_ARGB1555
:
1321 unpack_ubyte_ARGB1555(src
, dst
, n
);
1323 case MESA_FORMAT_ARGB1555_REV
:
1324 unpack_ubyte_ARGB1555_REV(src
, dst
, n
);
1326 case MESA_FORMAT_AL44
:
1327 unpack_ubyte_AL44(src
, dst
, n
);
1329 case MESA_FORMAT_AL88
:
1330 unpack_ubyte_AL88(src
, dst
, n
);
1332 case MESA_FORMAT_AL88_REV
:
1333 unpack_ubyte_AL88_REV(src
, dst
, n
);
1335 case MESA_FORMAT_RGB332
:
1336 unpack_ubyte_RGB332(src
, dst
, n
);
1338 case MESA_FORMAT_A8
:
1339 unpack_ubyte_A8(src
, dst
, n
);
1341 case MESA_FORMAT_L8
:
1342 unpack_ubyte_L8(src
, dst
, n
);
1344 case MESA_FORMAT_I8
:
1345 unpack_ubyte_I8(src
, dst
, n
);
1348 /* get float values, convert to ubyte */
1350 GLfloat
*tmp
= (GLfloat
*) malloc(n
* 4 * sizeof(GLfloat
));
1353 _mesa_unpack_rgba_row(format
, n
, src
, (GLfloat (*)[4]) tmp
);
1354 for (i
= 0; i
< n
; i
++) {
1355 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][0], tmp
[i
*4+0]);
1356 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][1], tmp
[i
*4+1]);
1357 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][2], tmp
[i
*4+2]);
1358 UNCLAMPED_FLOAT_TO_UBYTE(dst
[i
][3], tmp
[i
*4+3]);
1368 /**********************************************************************/
1369 /* Unpack, returning GLuint colors */
1370 /**********************************************************************/
1373 unpack_int_rgba_RGBA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
1375 memcpy(dst
, src
, n
* 4 * sizeof(GLuint
));
1379 unpack_int_rgba_RGBA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
1383 for (i
= 0; i
< n
; i
++) {
1384 dst
[i
][0] = src
[i
* 4 + 0];
1385 dst
[i
][1] = src
[i
* 4 + 1];
1386 dst
[i
][2] = src
[i
* 4 + 2];
1387 dst
[i
][3] = src
[i
* 4 + 3];
1392 unpack_int_rgba_RGBA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
1396 for (i
= 0; i
< n
; i
++) {
1397 dst
[i
][0] = src
[i
* 4 + 0];
1398 dst
[i
][1] = src
[i
* 4 + 1];
1399 dst
[i
][2] = src
[i
* 4 + 2];
1400 dst
[i
][3] = src
[i
* 4 + 3];
1405 unpack_int_rgba_RGBA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
1409 for (i
= 0; i
< n
; i
++) {
1410 dst
[i
][0] = src
[i
* 4 + 0];
1411 dst
[i
][1] = src
[i
* 4 + 1];
1412 dst
[i
][2] = src
[i
* 4 + 2];
1413 dst
[i
][3] = src
[i
* 4 + 3];
1418 unpack_int_rgba_RGBA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
1422 for (i
= 0; i
< n
; i
++) {
1423 dst
[i
][0] = src
[i
* 4 + 0];
1424 dst
[i
][1] = src
[i
* 4 + 1];
1425 dst
[i
][2] = src
[i
* 4 + 2];
1426 dst
[i
][3] = src
[i
* 4 + 3];
1431 unpack_int_rgba_RGB_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
1435 for (i
= 0; i
< n
; i
++) {
1436 dst
[i
][0] = src
[i
* 3 + 0];
1437 dst
[i
][1] = src
[i
* 3 + 1];
1438 dst
[i
][2] = src
[i
* 3 + 2];
1444 unpack_int_rgba_RGB_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
1448 for (i
= 0; i
< n
; i
++) {
1449 dst
[i
][0] = src
[i
* 3 + 0];
1450 dst
[i
][1] = src
[i
* 3 + 1];
1451 dst
[i
][2] = src
[i
* 3 + 2];
1457 unpack_int_rgba_RGB_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
1461 for (i
= 0; i
< n
; i
++) {
1462 dst
[i
][0] = src
[i
* 3 + 0];
1463 dst
[i
][1] = src
[i
* 3 + 1];
1464 dst
[i
][2] = src
[i
* 3 + 2];
1470 unpack_int_rgba_RGB_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
1474 for (i
= 0; i
< n
; i
++) {
1475 dst
[i
][0] = src
[i
* 3 + 0];
1476 dst
[i
][1] = src
[i
* 3 + 1];
1477 dst
[i
][2] = src
[i
* 3 + 2];
1483 unpack_int_rgba_RGB_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
1487 for (i
= 0; i
< n
; i
++) {
1488 dst
[i
][0] = src
[i
* 3 + 0];
1489 dst
[i
][1] = src
[i
* 3 + 1];
1490 dst
[i
][2] = src
[i
* 3 + 2];
1496 unpack_int_rgba_ALPHA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
1500 for (i
= 0; i
< n
; i
++) {
1501 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
1507 unpack_int_rgba_ALPHA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
1511 for (i
= 0; i
< n
; i
++) {
1512 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
1518 unpack_int_rgba_ALPHA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
1522 for (i
= 0; i
< n
; i
++) {
1523 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
1529 unpack_int_rgba_ALPHA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
1533 for (i
= 0; i
< n
; i
++) {
1534 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
1540 unpack_int_rgba_ALPHA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
1544 for (i
= 0; i
< n
; i
++) {
1545 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = 0;
1551 unpack_int_rgba_LUMINANCE_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
1555 for (i
= 0; i
< n
; i
++) {
1556 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
1562 unpack_int_rgba_LUMINANCE_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
1566 for (i
= 0; i
< n
; i
++) {
1567 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
1573 unpack_int_rgba_LUMINANCE_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
1577 for (i
= 0; i
< n
; i
++) {
1578 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
1584 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
1588 for (i
= 0; i
< n
; i
++) {
1589 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
1595 unpack_int_rgba_LUMINANCE_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
1599 for (i
= 0; i
< n
; i
++) {
1600 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
];
1607 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
1611 for (i
= 0; i
< n
; i
++) {
1612 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
1613 dst
[i
][3] = src
[i
* 2 + 1];
1618 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
1622 for (i
= 0; i
< n
; i
++) {
1623 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
1624 dst
[i
][3] = src
[i
* 2 + 1];
1629 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
1633 for (i
= 0; i
< n
; i
++) {
1634 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
1635 dst
[i
][3] = src
[i
* 2 + 1];
1640 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
1644 for (i
= 0; i
< n
; i
++) {
1645 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
1646 dst
[i
][3] = src
[i
* 2 + 1];
1651 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
1655 for (i
= 0; i
< n
; i
++) {
1656 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = src
[i
* 2 + 0];
1657 dst
[i
][3] = src
[i
* 2 + 1];
1662 unpack_int_rgba_INTENSITY_UINT32(const GLuint
*src
, GLuint dst
[][4], GLuint n
)
1666 for (i
= 0; i
< n
; i
++) {
1667 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
1672 unpack_int_rgba_INTENSITY_UINT16(const GLushort
*src
, GLuint dst
[][4], GLuint n
)
1676 for (i
= 0; i
< n
; i
++) {
1677 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
1682 unpack_int_rgba_INTENSITY_INT16(const GLshort
*src
, GLuint dst
[][4], GLuint n
)
1686 for (i
= 0; i
< n
; i
++) {
1687 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
1692 unpack_int_rgba_INTENSITY_UINT8(const GLubyte
*src
, GLuint dst
[][4], GLuint n
)
1696 for (i
= 0; i
< n
; i
++) {
1697 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
1702 unpack_int_rgba_INTENSITY_INT8(const GLbyte
*src
, GLuint dst
[][4], GLuint n
)
1706 for (i
= 0; i
< n
; i
++) {
1707 dst
[i
][0] = dst
[i
][1] = dst
[i
][2] = dst
[i
][3] = src
[i
];
1712 _mesa_unpack_uint_rgba_row(gl_format format
, GLuint n
,
1713 const void *src
, GLuint dst
[][4])
1716 /* Since there won't be any sign extension happening, there's no need to
1717 * make separate paths for 32-bit-to-32-bit integer unpack.
1719 case MESA_FORMAT_RGBA_UINT32
:
1720 case MESA_FORMAT_RGBA_INT32
:
1721 unpack_int_rgba_RGBA_UINT32(src
, dst
, n
);
1724 case MESA_FORMAT_RGBA_UINT16
:
1725 unpack_int_rgba_RGBA_UINT16(src
, dst
, n
);
1727 case MESA_FORMAT_RGBA_INT16
:
1728 unpack_int_rgba_RGBA_INT16(src
, dst
, n
);
1731 case MESA_FORMAT_RGBA_UINT8
:
1732 unpack_int_rgba_RGBA_UINT8(src
, dst
, n
);
1734 case MESA_FORMAT_RGBA_INT8
:
1735 unpack_int_rgba_RGBA_INT8(src
, dst
, n
);
1738 case MESA_FORMAT_RGB_UINT32
:
1739 case MESA_FORMAT_RGB_INT32
:
1740 unpack_int_rgba_RGB_UINT32(src
, dst
, n
);
1743 case MESA_FORMAT_RGB_UINT16
:
1744 unpack_int_rgba_RGB_UINT16(src
, dst
, n
);
1746 case MESA_FORMAT_RGB_INT16
:
1747 unpack_int_rgba_RGB_INT16(src
, dst
, n
);
1750 case MESA_FORMAT_RGB_UINT8
:
1751 unpack_int_rgba_RGB_UINT8(src
, dst
, n
);
1753 case MESA_FORMAT_RGB_INT8
:
1754 unpack_int_rgba_RGB_INT8(src
, dst
, n
);
1757 case MESA_FORMAT_ALPHA_UINT32
:
1758 case MESA_FORMAT_ALPHA_INT32
:
1759 unpack_int_rgba_ALPHA_UINT32(src
, dst
, n
);
1762 case MESA_FORMAT_ALPHA_UINT16
:
1763 unpack_int_rgba_ALPHA_UINT16(src
, dst
, n
);
1765 case MESA_FORMAT_ALPHA_INT16
:
1766 unpack_int_rgba_ALPHA_INT16(src
, dst
, n
);
1769 case MESA_FORMAT_ALPHA_UINT8
:
1770 unpack_int_rgba_ALPHA_UINT8(src
, dst
, n
);
1772 case MESA_FORMAT_ALPHA_INT8
:
1773 unpack_int_rgba_ALPHA_INT8(src
, dst
, n
);
1776 case MESA_FORMAT_LUMINANCE_UINT32
:
1777 case MESA_FORMAT_LUMINANCE_INT32
:
1778 unpack_int_rgba_LUMINANCE_UINT32(src
, dst
, n
);
1780 case MESA_FORMAT_LUMINANCE_UINT16
:
1781 unpack_int_rgba_LUMINANCE_UINT16(src
, dst
, n
);
1783 case MESA_FORMAT_LUMINANCE_INT16
:
1784 unpack_int_rgba_LUMINANCE_INT16(src
, dst
, n
);
1787 case MESA_FORMAT_LUMINANCE_UINT8
:
1788 unpack_int_rgba_LUMINANCE_UINT8(src
, dst
, n
);
1790 case MESA_FORMAT_LUMINANCE_INT8
:
1791 unpack_int_rgba_LUMINANCE_INT8(src
, dst
, n
);
1794 case MESA_FORMAT_LUMINANCE_ALPHA_UINT32
:
1795 case MESA_FORMAT_LUMINANCE_ALPHA_INT32
:
1796 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src
, dst
, n
);
1799 case MESA_FORMAT_LUMINANCE_ALPHA_UINT16
:
1800 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src
, dst
, n
);
1802 case MESA_FORMAT_LUMINANCE_ALPHA_INT16
:
1803 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src
, dst
, n
);
1806 case MESA_FORMAT_LUMINANCE_ALPHA_UINT8
:
1807 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src
, dst
, n
);
1809 case MESA_FORMAT_LUMINANCE_ALPHA_INT8
:
1810 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src
, dst
, n
);
1813 case MESA_FORMAT_INTENSITY_UINT32
:
1814 case MESA_FORMAT_INTENSITY_INT32
:
1815 unpack_int_rgba_INTENSITY_UINT32(src
, dst
, n
);
1818 case MESA_FORMAT_INTENSITY_UINT16
:
1819 unpack_int_rgba_INTENSITY_UINT16(src
, dst
, n
);
1821 case MESA_FORMAT_INTENSITY_INT16
:
1822 unpack_int_rgba_INTENSITY_INT16(src
, dst
, n
);
1825 case MESA_FORMAT_INTENSITY_UINT8
:
1826 unpack_int_rgba_INTENSITY_UINT8(src
, dst
, n
);
1828 case MESA_FORMAT_INTENSITY_INT8
:
1829 unpack_int_rgba_INTENSITY_INT8(src
, dst
, n
);
1833 _mesa_problem(NULL
, "%s: bad format %s", __FUNCTION__
,
1834 _mesa_get_format_name(format
));
1840 * Unpack a 2D rect of pixels returning float RGBA colors.
1841 * \param format the source image format
1842 * \param src start address of the source image
1843 * \param srcRowStride source image row stride in bytes
1844 * \param dst start address of the dest image
1845 * \param dstRowStride dest image row stride in bytes
1846 * \param x source image start X pos
1847 * \param y source image start Y pos
1848 * \param width width of rect region to convert
1849 * \param height height of rect region to convert
1852 _mesa_unpack_rgba_block(gl_format format
,
1853 const void *src
, GLint srcRowStride
,
1854 GLfloat dst
[][4], GLint dstRowStride
,
1855 GLuint x
, GLuint y
, GLuint width
, GLuint height
)
1857 unpack_rgba_func unpack
= get_unpack_rgba_function(format
);
1858 const GLuint srcPixStride
= _mesa_get_format_bytes(format
);
1859 const GLuint dstPixStride
= 4 * sizeof(GLfloat
);
1860 const GLubyte
*srcRow
;
1864 /* XXX needs to be fixed for compressed formats */
1866 srcRow
= ((const GLubyte
*) src
) + srcRowStride
* y
+ srcPixStride
* x
;
1867 dstRow
= ((GLubyte
*) dst
) + dstRowStride
* y
+ dstPixStride
* x
;
1869 for (i
= 0; i
< height
; i
++) {
1870 unpack(srcRow
, (GLfloat (*)[4]) dstRow
, width
);
1872 dstRow
+= dstRowStride
;
1873 srcRow
+= srcRowStride
;
1880 typedef void (*unpack_float_z_func
)(GLuint n
, const void *src
, GLfloat
*dst
);
1883 unpack_float_z_Z24_X8(GLuint n
, const void *src
, GLfloat
*dst
)
1885 /* only return Z, not stencil data */
1886 const GLuint
*s
= ((const GLuint
*) src
);
1887 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
1889 for (i
= 0; i
< n
; i
++) {
1890 dst
[i
] = (s
[i
] >> 8) * scale
;
1891 ASSERT(dst
[i
] >= 0.0F
);
1892 ASSERT(dst
[i
] <= 1.0F
);
1897 unpack_float_z_X8_Z24(GLuint n
, const void *src
, GLfloat
*dst
)
1899 /* only return Z, not stencil data */
1900 const GLuint
*s
= ((const GLuint
*) src
);
1901 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
1903 for (i
= 0; i
< n
; i
++) {
1904 dst
[i
] = (s
[i
] & 0x00ffffff) * scale
;
1905 ASSERT(dst
[i
] >= 0.0F
);
1906 ASSERT(dst
[i
] <= 1.0F
);
1911 unpack_float_z_Z16(GLuint n
, const void *src
, GLfloat
*dst
)
1913 const GLushort
*s
= ((const GLushort
*) src
);
1915 for (i
= 0; i
< n
; i
++) {
1916 dst
[i
] = s
[i
] * (1.0F
/ 65535.0F
);
1921 unpack_float_z_Z32(GLuint n
, const void *src
, GLfloat
*dst
)
1923 const GLuint
*s
= ((const GLuint
*) src
);
1925 for (i
= 0; i
< n
; i
++) {
1926 dst
[i
] = s
[i
] * (1.0F
/ 0xffffffff);
1934 * The returned values will always be in the range [0.0, 1.0].
1937 _mesa_unpack_float_z_row(gl_format format
, GLuint n
,
1938 const void *src
, GLfloat
*dst
)
1940 unpack_float_z_func unpack
;
1943 case MESA_FORMAT_Z24_X8
:
1944 unpack
= unpack_float_z_Z24_X8
;
1946 case MESA_FORMAT_X8_Z24
:
1947 unpack
= unpack_float_z_X8_Z24
;
1949 case MESA_FORMAT_Z16
:
1950 unpack
= unpack_float_z_Z16
;
1952 case MESA_FORMAT_Z32
:
1953 unpack
= unpack_float_z_Z32
;
1956 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_float_z_row",
1957 _mesa_get_format_name(format
));
1961 unpack(n
, src
, dst
);
1966 typedef void (*unpack_uint_z_func
)(const void *src
, GLuint
*dst
, GLuint n
);
1969 unpack_uint_z_Z24_X8(const void *src
, GLuint
*dst
, GLuint n
)
1971 /* only return Z, not stencil data */
1972 const GLuint
*s
= ((const GLuint
*) src
);
1974 for (i
= 0; i
< n
; i
++) {
1975 dst
[i
] = (s
[i
] & 0xffffff00) | (s
[i
] >> 24);
1980 unpack_uint_z_X8_Z24(const void *src
, GLuint
*dst
, GLuint n
)
1982 /* only return Z, not stencil data */
1983 const GLuint
*s
= ((const GLuint
*) src
);
1985 for (i
= 0; i
< n
; i
++) {
1986 dst
[i
] = (s
[i
] << 8) | ((s
[i
] >> 16) & 0xff);
1991 unpack_uint_z_Z16(const void *src
, GLuint
*dst
, GLuint n
)
1993 const GLushort
*s
= ((const GLushort
*)src
);
1995 for (i
= 0; i
< n
; i
++) {
1996 dst
[i
] = (s
[i
] << 16) | s
[i
];
2001 unpack_uint_z_Z32(const void *src
, GLuint
*dst
, GLuint n
)
2003 memcpy(dst
, src
, n
* sizeof(GLuint
));
2009 * The returned values will always be in the range [0, 0xffffffff].
2012 _mesa_unpack_uint_z_row(gl_format format
, GLuint n
,
2013 const void *src
, GLuint
*dst
)
2015 unpack_uint_z_func unpack
;
2016 const GLubyte
*srcPtr
= (GLubyte
*) src
;
2019 case MESA_FORMAT_Z24_X8
:
2020 unpack
= unpack_uint_z_Z24_X8
;
2022 case MESA_FORMAT_X8_Z24
:
2023 unpack
= unpack_uint_z_X8_Z24
;
2025 case MESA_FORMAT_Z16
:
2026 unpack
= unpack_uint_z_Z16
;
2028 case MESA_FORMAT_Z32
:
2029 unpack
= unpack_uint_z_Z32
;
2032 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_uint_z_row",
2033 _mesa_get_format_name(format
));
2037 unpack(srcPtr
, dst
, n
);
2042 unpack_ubyte_s_S8(const void *src
, GLubyte
*dst
, GLuint n
)
2044 memcpy(dst
, src
, n
);
2048 _mesa_unpack_ubyte_stencil_row(gl_format format
, GLuint n
,
2049 const void *src
, GLubyte
*dst
)
2052 case MESA_FORMAT_S8
:
2053 unpack_ubyte_s_S8(src
, dst
, n
);
2056 _mesa_problem(NULL
, "bad format %s in _mesa_unpack_ubyte_s_row",
2057 _mesa_get_format_name(format
));