03221c307dbc460bc7594c64f3959ab9b633a404
[mesa.git] / src / mesa / main / format_unpack.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (c) 2011 VMware, Inc.
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include "colormac.h"
27 #include "format_unpack.h"
28 #include "macros.h"
29 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
30 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
31
32
33 /** Helper struct for MESA_FORMAT_Z32_FLOAT_X24S8 */
34 struct z32f_x24s8
35 {
36 float z;
37 uint32_t x24s8;
38 };
39
40
41 /* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
42
43 #define EXPAND_1_8(X) ( (X) ? 0xff : 0x0 )
44
45 #define EXPAND_2_8(X) ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
46
47 #define EXPAND_3_8(X) ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
48
49 #define EXPAND_4_8(X) ( ((X) << 4) | (X) )
50
51 #define EXPAND_5_8(X) ( ((X) << 3) | ((X) >> 2) )
52
53 #define EXPAND_6_8(X) ( ((X) << 2) | ((X) >> 4) )
54
55
56 /**
57 * Convert an 8-bit sRGB value from non-linear space to a
58 * linear RGB value in [0, 1].
59 * Implemented with a 256-entry lookup table.
60 */
61 GLfloat
62 _mesa_nonlinear_to_linear(GLubyte cs8)
63 {
64 static GLfloat table[256];
65 static GLboolean tableReady = GL_FALSE;
66 if (!tableReady) {
67 /* compute lookup table now */
68 GLuint i;
69 for (i = 0; i < 256; i++) {
70 const GLfloat cs = UBYTE_TO_FLOAT(i);
71 if (cs <= 0.04045) {
72 table[i] = cs / 12.92f;
73 }
74 else {
75 table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
76 }
77 }
78 tableReady = GL_TRUE;
79 }
80 return table[cs8];
81 }
82
83
84 /**********************************************************************/
85 /* Unpack, returning GLfloat colors */
86 /**********************************************************************/
87
88 typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);
89
90
91 static void
92 unpack_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
93 {
94 const GLuint *s = ((const GLuint *) src);
95 GLuint i;
96 for (i = 0; i < n; i++) {
97 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
98 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
99 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
100 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
101 }
102 }
103
104 static void
105 unpack_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
106 {
107 const GLuint *s = ((const GLuint *) src);
108 GLuint i;
109 for (i = 0; i < n; i++) {
110 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
111 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
112 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
113 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
114 }
115 }
116
117 static void
118 unpack_ARGB8888(const void *src, GLfloat dst[][4], GLuint n)
119 {
120 const GLuint *s = ((const GLuint *) src);
121 GLuint i;
122 for (i = 0; i < n; i++) {
123 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
124 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
125 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
126 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
127 }
128 }
129
130 static void
131 unpack_ARGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
132 {
133 const GLuint *s = ((const GLuint *) src);
134 GLuint i;
135 for (i = 0; i < n; i++) {
136 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
137 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
138 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
139 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
140 }
141 }
142
143 static void
144 unpack_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
145 {
146 const GLuint *s = ((const GLuint *) src);
147 GLuint i;
148 for (i = 0; i < n; i++) {
149 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
150 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
151 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
152 dst[i][ACOMP] = 1.0f;
153 }
154 }
155
156 static void
157 unpack_RGBX8888_REV(const void *src, GLfloat dst[][4], GLuint n)
158 {
159 const GLuint *s = ((const GLuint *) src);
160 GLuint i;
161 for (i = 0; i < n; i++) {
162 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
163 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
164 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
165 dst[i][ACOMP] = 1.0f;
166 }
167 }
168
169 static void
170 unpack_XRGB8888(const void *src, GLfloat dst[][4], GLuint n)
171 {
172 const GLuint *s = ((const GLuint *) src);
173 GLuint i;
174 for (i = 0; i < n; i++) {
175 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
176 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
177 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
178 dst[i][ACOMP] = 1.0f;
179 }
180 }
181
182 static void
183 unpack_XRGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
184 {
185 const GLuint *s = ((const GLuint *) src);
186 GLuint i;
187 for (i = 0; i < n; i++) {
188 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
189 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
190 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
191 dst[i][ACOMP] = 1.0f;
192 }
193 }
194
195 static void
196 unpack_RGB888(const void *src, GLfloat dst[][4], GLuint n)
197 {
198 const GLubyte *s = (const GLubyte *) src;
199 GLuint i;
200 for (i = 0; i < n; i++) {
201 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
202 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
203 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
204 dst[i][ACOMP] = 1.0F;
205 }
206 }
207
208 static void
209 unpack_BGR888(const void *src, GLfloat dst[][4], GLuint n)
210 {
211 const GLubyte *s = (const GLubyte *) src;
212 GLuint i;
213 for (i = 0; i < n; i++) {
214 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
215 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
216 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
217 dst[i][ACOMP] = 1.0F;
218 }
219 }
220
221 static void
222 unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n)
223 {
224 const GLushort *s = ((const GLushort *) src);
225 GLuint i;
226 for (i = 0; i < n; i++) {
227 dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
228 dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F);
229 dst[i][BCOMP] = ((s[i] ) & 0x1f) * (1.0F / 31.0F);
230 dst[i][ACOMP] = 1.0F;
231 }
232 }
233
234 static void
235 unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n)
236 {
237 const GLushort *s = ((const GLushort *) src);
238 GLuint i;
239 for (i = 0; i < n; i++) {
240 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
241 dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) );
242 dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >> 9) & 0x3) );
243 dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >> 2) & 0x7) );
244 dst[i][ACOMP] = 1.0F;
245 }
246 }
247
248 static void
249 unpack_ARGB4444(const void *src, GLfloat dst[][4], GLuint n)
250 {
251 const GLushort *s = ((const GLushort *) src);
252 GLuint i;
253 for (i = 0; i < n; i++) {
254 dst[i][RCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
255 dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
256 dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
257 dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
258 }
259 }
260
261 static void
262 unpack_ARGB4444_REV(const void *src, GLfloat dst[][4], GLuint n)
263 {
264 const GLushort *s = ((const GLushort *) src);
265 GLuint i;
266 for (i = 0; i < n; i++) {
267 dst[i][RCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
268 dst[i][GCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
269 dst[i][BCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
270 dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
271 }
272 }
273
274 static void
275 unpack_RGBA5551(const void *src, GLfloat dst[][4], GLuint n)
276 {
277 const GLushort *s = ((const GLushort *) src);
278 GLuint i;
279 for (i = 0; i < n; i++) {
280 dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
281 dst[i][GCOMP] = ((s[i] >> 6) & 0x1f) * (1.0F / 31.0F);
282 dst[i][BCOMP] = ((s[i] >> 1) & 0x1f) * (1.0F / 31.0F);
283 dst[i][ACOMP] = ((s[i] ) & 0x01) * 1.0F;
284 }
285 }
286
287 static void
288 unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n)
289 {
290 const GLushort *s = ((const GLushort *) src);
291 GLuint i;
292 for (i = 0; i < n; i++) {
293 dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
294 dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F);
295 dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F);
296 dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F;
297 }
298 }
299
300 static void
301 unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n)
302 {
303 const GLushort *s = ((const GLushort *) src);
304 GLuint i;
305 for (i = 0; i < n; i++) {
306 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
307 dst[i][RCOMP] = ((tmp >> 10) & 0x1f) * (1.0F / 31.0F);
308 dst[i][GCOMP] = ((tmp >> 5) & 0x1f) * (1.0F / 31.0F);
309 dst[i][BCOMP] = ((tmp >> 0) & 0x1f) * (1.0F / 31.0F);
310 dst[i][ACOMP] = ((tmp >> 15) & 0x01) * 1.0F;
311 }
312 }
313
314 static void
315 unpack_AL44(const void *src, GLfloat dst[][4], GLuint n)
316 {
317 const GLubyte *s = ((const GLubyte *) src);
318 GLuint i;
319 for (i = 0; i < n; i++) {
320 dst[i][RCOMP] =
321 dst[i][GCOMP] =
322 dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
323 dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
324 }
325 }
326
327 static void
328 unpack_AL88(const void *src, GLfloat dst[][4], GLuint n)
329 {
330 const GLushort *s = ((const GLushort *) src);
331 GLuint i;
332 for (i = 0; i < n; i++) {
333 dst[i][RCOMP] =
334 dst[i][GCOMP] =
335 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
336 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
337 }
338 }
339
340 static void
341 unpack_AL88_REV(const void *src, GLfloat dst[][4], GLuint n)
342 {
343 const GLushort *s = ((const GLushort *) src);
344 GLuint i;
345 for (i = 0; i < n; i++) {
346 dst[i][RCOMP] =
347 dst[i][GCOMP] =
348 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
349 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
350 }
351 }
352
353 static void
354 unpack_AL1616(const void *src, GLfloat dst[][4], GLuint n)
355 {
356 const GLuint *s = ((const GLuint *) src);
357 GLuint i;
358 for (i = 0; i < n; i++) {
359 dst[i][RCOMP] =
360 dst[i][GCOMP] =
361 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
362 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
363 }
364 }
365
366 static void
367 unpack_AL1616_REV(const void *src, GLfloat dst[][4], GLuint n)
368 {
369 const GLuint *s = ((const GLuint *) src);
370 GLuint i;
371 for (i = 0; i < n; i++) {
372 dst[i][RCOMP] =
373 dst[i][GCOMP] =
374 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
375 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
376 }
377 }
378
379 static void
380 unpack_RGB332(const void *src, GLfloat dst[][4], GLuint n)
381 {
382 const GLubyte *s = ((const GLubyte *) src);
383 GLuint i;
384 for (i = 0; i < n; i++) {
385 dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F);
386 dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F);
387 dst[i][BCOMP] = ((s[i] ) & 0x3) * (1.0F / 3.0F);
388 dst[i][ACOMP] = 1.0F;
389 }
390 }
391
392
393 static void
394 unpack_A8(const void *src, GLfloat dst[][4], GLuint n)
395 {
396 const GLubyte *s = ((const GLubyte *) src);
397 GLuint i;
398 for (i = 0; i < n; i++) {
399 dst[i][RCOMP] =
400 dst[i][GCOMP] =
401 dst[i][BCOMP] = 0.0F;
402 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
403 }
404 }
405
406 static void
407 unpack_A16(const void *src, GLfloat dst[][4], GLuint n)
408 {
409 const GLushort *s = ((const GLushort *) src);
410 GLuint i;
411 for (i = 0; i < n; i++) {
412 dst[i][RCOMP] =
413 dst[i][GCOMP] =
414 dst[i][BCOMP] = 0.0F;
415 dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
416 }
417 }
418
419 static void
420 unpack_L8(const void *src, GLfloat dst[][4], GLuint n)
421 {
422 const GLubyte *s = ((const GLubyte *) src);
423 GLuint i;
424 for (i = 0; i < n; i++) {
425 dst[i][RCOMP] =
426 dst[i][GCOMP] =
427 dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
428 dst[i][ACOMP] = 1.0F;
429 }
430 }
431
432 static void
433 unpack_L16(const void *src, GLfloat dst[][4], GLuint n)
434 {
435 const GLushort *s = ((const GLushort *) src);
436 GLuint i;
437 for (i = 0; i < n; i++) {
438 dst[i][RCOMP] =
439 dst[i][GCOMP] =
440 dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
441 dst[i][ACOMP] = 1.0F;
442 }
443 }
444
445 static void
446 unpack_I8(const void *src, GLfloat dst[][4], GLuint n)
447 {
448 const GLubyte *s = ((const GLubyte *) src);
449 GLuint i;
450 for (i = 0; i < n; i++) {
451 dst[i][RCOMP] =
452 dst[i][GCOMP] =
453 dst[i][BCOMP] =
454 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
455 }
456 }
457
458 static void
459 unpack_I16(const void *src, GLfloat dst[][4], GLuint n)
460 {
461 const GLushort *s = ((const GLushort *) src);
462 GLuint i;
463 for (i = 0; i < n; i++) {
464 dst[i][RCOMP] =
465 dst[i][GCOMP] =
466 dst[i][BCOMP] =
467 dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
468 }
469 }
470
471 static void
472 unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n)
473 {
474 GLuint i;
475 for (i = 0; i < n; i++) {
476 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
477 const GLushort *src1 = src0 + 1; /* odd */
478 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
479 const GLubyte cb = *src0 & 0xff; /* chroma U */
480 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
481 const GLubyte cr = *src1 & 0xff; /* chroma V */
482 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
483 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
484 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
485 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
486 r *= (1.0F / 255.0F);
487 g *= (1.0F / 255.0F);
488 b *= (1.0F / 255.0F);
489 dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
490 dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
491 dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
492 dst[i][ACOMP] = 1.0F;
493 }
494 }
495
496 static void
497 unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
498 {
499 GLuint i;
500 for (i = 0; i < n; i++) {
501 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
502 const GLushort *src1 = src0 + 1; /* odd */
503 const GLubyte y0 = *src0 & 0xff; /* luminance */
504 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
505 const GLubyte y1 = *src1 & 0xff; /* luminance */
506 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
507 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
508 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
509 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
510 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
511 r *= (1.0F / 255.0F);
512 g *= (1.0F / 255.0F);
513 b *= (1.0F / 255.0F);
514 dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
515 dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
516 dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
517 dst[i][ACOMP] = 1.0F;
518 }
519 }
520
521 static void
522 unpack_R8(const void *src, GLfloat dst[][4], GLuint n)
523 {
524 const GLubyte *s = ((const GLubyte *) src);
525 GLuint i;
526 for (i = 0; i < n; i++) {
527 dst[i][0] = UBYTE_TO_FLOAT(s[i]);
528 dst[i][1] =
529 dst[i][2] = 0.0F;
530 dst[i][3] = 1.0F;
531 }
532 }
533
534 static void
535 unpack_GR88(const void *src, GLfloat dst[][4], GLuint n)
536 {
537 const GLushort *s = ((const GLushort *) src);
538 GLuint i;
539 for (i = 0; i < n; i++) {
540 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
541 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
542 dst[i][BCOMP] = 0.0;
543 dst[i][ACOMP] = 1.0;
544 }
545 }
546
547 static void
548 unpack_RG88(const void *src, GLfloat dst[][4], GLuint n)
549 {
550 const GLushort *s = ((const GLushort *) src);
551 GLuint i;
552 for (i = 0; i < n; i++) {
553 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
554 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
555 dst[i][BCOMP] = 0.0;
556 dst[i][ACOMP] = 1.0;
557 }
558 }
559
560 static void
561 unpack_R16(const void *src, GLfloat dst[][4], GLuint n)
562 {
563 const GLushort *s = ((const GLushort *) src);
564 GLuint i;
565 for (i = 0; i < n; i++) {
566 dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]);
567 dst[i][GCOMP] = 0.0;
568 dst[i][BCOMP] = 0.0;
569 dst[i][ACOMP] = 1.0;
570 }
571 }
572
573 static void
574 unpack_GR1616(const void *src, GLfloat dst[][4], GLuint n)
575 {
576 const GLuint *s = ((const GLuint *) src);
577 GLuint i;
578 for (i = 0; i < n; i++) {
579 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
580 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
581 dst[i][BCOMP] = 0.0;
582 dst[i][ACOMP] = 1.0;
583 }
584 }
585
586 static void
587 unpack_RG1616(const void *src, GLfloat dst[][4], GLuint n)
588 {
589 const GLuint *s = ((const GLuint *) src);
590 GLuint i;
591 for (i = 0; i < n; i++) {
592 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
593 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
594 dst[i][BCOMP] = 0.0;
595 dst[i][ACOMP] = 1.0;
596 }
597 }
598
599 static void
600 unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n)
601 {
602 const GLuint *s = ((const GLuint *) src);
603 GLuint i;
604 for (i = 0; i < n; i++) {
605 dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
606 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
607 dst[i][BCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
608 dst[i][ACOMP] = ((s[i] >> 30) & 0x03) * (1.0F / 3.0F);
609 }
610 }
611
612
613 static void
614 unpack_ABGR2101010_UINT(const void *src, GLfloat dst[][4], GLuint n)
615 {
616 const GLuint *s = ((const GLuint *) src);
617 GLuint i;
618 for (i = 0; i < n; i++) {
619 dst[i][RCOMP] = (GLfloat)((s[i] >> 0) & 0x3ff);
620 dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff);
621 dst[i][BCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff);
622 dst[i][ACOMP] = (GLfloat)((s[i] >> 30) & 0x03);
623 }
624 }
625
626
627 static void
628 unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
629 {
630 /* only return Z, not stencil data */
631 const GLuint *s = ((const GLuint *) src);
632 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
633 GLuint i;
634 for (i = 0; i < n; i++) {
635 dst[i][0] =
636 dst[i][1] =
637 dst[i][2] = (GLfloat) ((s[i] >> 8) * scale);
638 dst[i][3] = 1.0F;
639 ASSERT(dst[i][0] >= 0.0F);
640 ASSERT(dst[i][0] <= 1.0F);
641 }
642 }
643
644 static void
645 unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
646 {
647 /* only return Z, not stencil data */
648 const GLuint *s = ((const GLuint *) src);
649 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
650 GLuint i;
651 for (i = 0; i < n; i++) {
652 dst[i][0] =
653 dst[i][1] =
654 dst[i][2] = (float) ((s[i] & 0x00ffffff) * scale);
655 dst[i][3] = 1.0F;
656 ASSERT(dst[i][0] >= 0.0F);
657 ASSERT(dst[i][0] <= 1.0F);
658 }
659 }
660
661 static void
662 unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
663 {
664 const GLushort *s = ((const GLushort *) src);
665 GLuint i;
666 for (i = 0; i < n; i++) {
667 dst[i][0] =
668 dst[i][1] =
669 dst[i][2] = s[i] * (1.0F / 65535.0F);
670 dst[i][3] = 1.0F;
671 }
672 }
673
674 static void
675 unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n)
676 {
677 unpack_S8_Z24(src, dst, n);
678 }
679
680 static void
681 unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n)
682 {
683 unpack_Z24_S8(src, dst, n);
684 }
685
686 static void
687 unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
688 {
689 const GLuint *s = ((const GLuint *) src);
690 GLuint i;
691 for (i = 0; i < n; i++) {
692 dst[i][0] =
693 dst[i][1] =
694 dst[i][2] = s[i] * (1.0F / 0xffffffff);
695 dst[i][3] = 1.0F;
696 }
697 }
698
699 static void
700 unpack_Z32_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
701 {
702 const GLfloat *s = ((const GLfloat *) src);
703 GLuint i;
704 for (i = 0; i < n; i++) {
705 dst[i][0] =
706 dst[i][1] =
707 dst[i][2] = s[i * 2];
708 dst[i][3] = 1.0F;
709 }
710 }
711
712 static void
713 unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[][4], GLuint n)
714 {
715 const GLfloat *s = ((const GLfloat *) src);
716 GLuint i;
717 for (i = 0; i < n; i++) {
718 dst[i][0] =
719 dst[i][1] =
720 dst[i][2] = s[i];
721 dst[i][3] = 1.0F;
722 }
723 }
724
725
726 static void
727 unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
728 {
729 /* should never be used */
730 GLuint i;
731 for (i = 0; i < n; i++) {
732 dst[i][0] =
733 dst[i][1] =
734 dst[i][2] = 0.0F;
735 dst[i][3] = 1.0F;
736 }
737 }
738
739
740 static void
741 unpack_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
742 {
743 const GLubyte *s = (const GLubyte *) src;
744 GLuint i;
745 for (i = 0; i < n; i++) {
746 dst[i][RCOMP] = _mesa_nonlinear_to_linear(s[i*3+2]);
747 dst[i][GCOMP] = _mesa_nonlinear_to_linear(s[i*3+1]);
748 dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i*3+0]);
749 dst[i][ACOMP] = 1.0F;
750 }
751 }
752
753 static void
754 unpack_SRGBA8(const void *src, GLfloat dst[][4], GLuint n)
755 {
756 const GLuint *s = ((const GLuint *) src);
757 GLuint i;
758 for (i = 0; i < n; i++) {
759 dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 24) );
760 dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
761 dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff );
762 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
763 }
764 }
765
766 static void
767 unpack_SARGB8(const void *src, GLfloat dst[][4], GLuint n)
768 {
769 const GLuint *s = ((const GLuint *) src);
770 GLuint i;
771 for (i = 0; i < n; i++) {
772 dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
773 dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff );
774 dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff );
775 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
776 }
777 }
778
779 static void
780 unpack_SL8(const void *src, GLfloat dst[][4], GLuint n)
781 {
782 const GLubyte *s = ((const GLubyte *) src);
783 GLuint i;
784 for (i = 0; i < n; i++) {
785 dst[i][RCOMP] =
786 dst[i][GCOMP] =
787 dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i]);
788 dst[i][ACOMP] = 1.0F;
789 }
790 }
791
792 static void
793 unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n)
794 {
795 const GLushort *s = (const GLushort *) src;
796 GLuint i;
797 for (i = 0; i < n; i++) {
798 dst[i][RCOMP] =
799 dst[i][GCOMP] =
800 dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i] & 0xff);
801 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
802 }
803 }
804
805 static void
806 unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
807 {
808 }
809
810 static void
811 unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
812 {
813 }
814
815 static void
816 unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
817 {
818 }
819
820 static void
821 unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
822 {
823 }
824
825 static void
826 unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
827 {
828 }
829
830 static void
831 unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
832 {
833 }
834
835 static void
836 unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
837 {
838 }
839
840 static void
841 unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
842 {
843 }
844
845 static void
846 unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
847 {
848 }
849
850 static void
851 unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
852 {
853 }
854
855
856 static void
857 unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
858 {
859 const GLfloat *s = (const GLfloat *) src;
860 GLuint i;
861 for (i = 0; i < n; i++) {
862 dst[i][RCOMP] = s[i*4+0];
863 dst[i][GCOMP] = s[i*4+1];
864 dst[i][BCOMP] = s[i*4+2];
865 dst[i][ACOMP] = s[i*4+3];
866 }
867 }
868
869 static void
870 unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
871 {
872 const GLhalfARB *s = (const GLhalfARB *) src;
873 GLuint i;
874 for (i = 0; i < n; i++) {
875 dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
876 dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
877 dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
878 dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
879 }
880 }
881
882 static void
883 unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
884 {
885 const GLfloat *s = (const GLfloat *) src;
886 GLuint i;
887 for (i = 0; i < n; i++) {
888 dst[i][RCOMP] = s[i*3+0];
889 dst[i][GCOMP] = s[i*3+1];
890 dst[i][BCOMP] = s[i*3+2];
891 dst[i][ACOMP] = 1.0F;
892 }
893 }
894
895 static void
896 unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
897 {
898 const GLhalfARB *s = (const GLhalfARB *) src;
899 GLuint i;
900 for (i = 0; i < n; i++) {
901 dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]);
902 dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
903 dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
904 dst[i][ACOMP] = 1.0F;
905 }
906 }
907
908 static void
909 unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
910 {
911 const GLfloat *s = (const GLfloat *) src;
912 GLuint i;
913 for (i = 0; i < n; i++) {
914 dst[i][RCOMP] =
915 dst[i][GCOMP] =
916 dst[i][BCOMP] = 0.0F;
917 dst[i][ACOMP] = s[i];
918 }
919 }
920
921 static void
922 unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
923 {
924 const GLhalfARB *s = (const GLhalfARB *) src;
925 GLuint i;
926 for (i = 0; i < n; i++) {
927 dst[i][RCOMP] =
928 dst[i][GCOMP] =
929 dst[i][BCOMP] = 0.0F;
930 dst[i][ACOMP] = _mesa_half_to_float(s[i]);
931 }
932 }
933
934 static void
935 unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
936 {
937 const GLfloat *s = (const GLfloat *) src;
938 GLuint i;
939 for (i = 0; i < n; i++) {
940 dst[i][RCOMP] =
941 dst[i][GCOMP] =
942 dst[i][BCOMP] = s[i];
943 dst[i][ACOMP] = 1.0F;
944 }
945 }
946
947 static void
948 unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
949 {
950 const GLhalfARB *s = (const GLhalfARB *) src;
951 GLuint i;
952 for (i = 0; i < n; i++) {
953 dst[i][RCOMP] =
954 dst[i][GCOMP] =
955 dst[i][BCOMP] = _mesa_half_to_float(s[i]);
956 dst[i][ACOMP] = 1.0F;
957 }
958 }
959
960 static void
961 unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
962 {
963 const GLfloat *s = (const GLfloat *) src;
964 GLuint i;
965 for (i = 0; i < n; i++) {
966 dst[i][RCOMP] =
967 dst[i][GCOMP] =
968 dst[i][BCOMP] = s[i*2+0];
969 dst[i][ACOMP] = s[i*2+1];
970 }
971 }
972
973 static void
974 unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
975 {
976 const GLhalfARB *s = (const GLhalfARB *) src;
977 GLuint i;
978 for (i = 0; i < n; i++) {
979 dst[i][RCOMP] =
980 dst[i][GCOMP] =
981 dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
982 dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
983 }
984 }
985
986 static void
987 unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
988 {
989 const GLfloat *s = (const GLfloat *) src;
990 GLuint i;
991 for (i = 0; i < n; i++) {
992 dst[i][RCOMP] =
993 dst[i][GCOMP] =
994 dst[i][BCOMP] =
995 dst[i][ACOMP] = s[i];
996 }
997 }
998
999 static void
1000 unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1001 {
1002 const GLhalfARB *s = (const GLhalfARB *) src;
1003 GLuint i;
1004 for (i = 0; i < n; i++) {
1005 dst[i][RCOMP] =
1006 dst[i][GCOMP] =
1007 dst[i][BCOMP] =
1008 dst[i][ACOMP] = _mesa_half_to_float(s[i]);
1009 }
1010 }
1011
1012 static void
1013 unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1014 {
1015 const GLfloat *s = (const GLfloat *) src;
1016 GLuint i;
1017 for (i = 0; i < n; i++) {
1018 dst[i][RCOMP] = s[i];
1019 dst[i][GCOMP] = 0.0F;
1020 dst[i][BCOMP] = 0.0F;
1021 dst[i][ACOMP] = 1.0F;
1022 }
1023 }
1024
1025 static void
1026 unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1027 {
1028 const GLhalfARB *s = (const GLhalfARB *) src;
1029 GLuint i;
1030 for (i = 0; i < n; i++) {
1031 dst[i][RCOMP] = _mesa_half_to_float(s[i]);
1032 dst[i][GCOMP] = 0.0F;
1033 dst[i][BCOMP] = 0.0F;
1034 dst[i][ACOMP] = 1.0F;
1035 }
1036 }
1037
1038 static void
1039 unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1040 {
1041 const GLfloat *s = (const GLfloat *) src;
1042 GLuint i;
1043 for (i = 0; i < n; i++) {
1044 dst[i][RCOMP] = s[i*2+0];
1045 dst[i][GCOMP] = s[i*2+1];
1046 dst[i][BCOMP] = 0.0F;
1047 dst[i][ACOMP] = 1.0F;
1048 }
1049 }
1050
1051 static void
1052 unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1053 {
1054 const GLhalfARB *s = (const GLhalfARB *) src;
1055 GLuint i;
1056 for (i = 0; i < n; i++) {
1057 dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
1058 dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
1059 dst[i][BCOMP] = 0.0F;
1060 dst[i][ACOMP] = 1.0F;
1061 }
1062 }
1063
1064
1065 static void
1066 unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
1067 {
1068 const GLbyte *s = (const GLbyte *) src;
1069 GLuint i;
1070 for (i = 0; i < n; i++) {
1071 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1072 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1073 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1074 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1075 }
1076 }
1077
1078 static void
1079 unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
1080 {
1081 const GLshort *s = (const GLshort *) src;
1082 GLuint i;
1083 for (i = 0; i < n; i++) {
1084 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1085 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1086 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1087 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1088 }
1089 }
1090
1091 static void
1092 unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1093 {
1094 const GLint *s = (const GLint *) src;
1095 GLuint i;
1096 for (i = 0; i < n; i++) {
1097 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1098 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1099 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1100 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1101 }
1102 }
1103
1104 static void
1105 unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1106 {
1107 const GLubyte *s = (const GLubyte *) src;
1108 GLuint i;
1109 for (i = 0; i < n; i++) {
1110 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1111 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1112 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1113 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1114 }
1115 }
1116
1117 static void
1118 unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1119 {
1120 const GLushort *s = (const GLushort *) src;
1121 GLuint i;
1122 for (i = 0; i < n; i++) {
1123 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1124 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1125 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1126 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1127 }
1128 }
1129
1130 static void
1131 unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1132 {
1133 const GLuint *s = (const GLuint *) src;
1134 GLuint i;
1135 for (i = 0; i < n; i++) {
1136 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1137 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1138 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1139 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1140 }
1141 }
1142
1143 static void
1144 unpack_DUDV8(const void *src, GLfloat dst[][4], GLuint n)
1145 {
1146 const GLbyte *s = (const GLbyte *) src;
1147 GLuint i;
1148 for (i = 0; i < n; i++) {
1149 dst[i][RCOMP] = BYTE_TO_FLOAT(s[i*2+0]);
1150 dst[i][GCOMP] = BYTE_TO_FLOAT(s[i*2+1]);
1151 dst[i][BCOMP] = 0;
1152 dst[i][ACOMP] = 0;
1153 }
1154 }
1155
1156 static void
1157 unpack_SIGNED_R8(const void *src, GLfloat dst[][4], GLuint n)
1158 {
1159 const GLbyte *s = ((const GLbyte *) src);
1160 GLuint i;
1161 for (i = 0; i < n; i++) {
1162 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1163 dst[i][GCOMP] = 0.0F;
1164 dst[i][BCOMP] = 0.0F;
1165 dst[i][ACOMP] = 1.0F;
1166 }
1167 }
1168
1169 static void
1170 unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
1171 {
1172 const GLushort *s = ((const GLushort *) src);
1173 GLuint i;
1174 for (i = 0; i < n; i++) {
1175 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1176 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1177 dst[i][BCOMP] = 0.0F;
1178 dst[i][ACOMP] = 1.0F;
1179 }
1180 }
1181
1182 static void
1183 unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
1184 {
1185 const GLuint *s = ((const GLuint *) src);
1186 GLuint i;
1187 for (i = 0; i < n; i++) {
1188 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1189 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1190 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1191 dst[i][ACOMP] = 1.0f;
1192 }
1193 }
1194
1195 static void
1196 unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
1197 {
1198 const GLuint *s = ((const GLuint *) src);
1199 GLuint i;
1200 for (i = 0; i < n; i++) {
1201 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1202 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1203 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1204 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1205 }
1206 }
1207
1208 static void
1209 unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
1210 {
1211 const GLuint *s = ((const GLuint *) src);
1212 GLuint i;
1213 for (i = 0; i < n; i++) {
1214 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1215 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1216 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1217 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1218 }
1219 }
1220
1221 static void
1222 unpack_SIGNED_R16(const void *src, GLfloat dst[][4], GLuint n)
1223 {
1224 const GLshort *s = ((const GLshort *) src);
1225 GLuint i;
1226 for (i = 0; i < n; i++) {
1227 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1228 dst[i][GCOMP] = 0.0F;
1229 dst[i][BCOMP] = 0.0F;
1230 dst[i][ACOMP] = 1.0F;
1231 }
1232 }
1233
1234 static void
1235 unpack_SIGNED_GR1616(const void *src, GLfloat dst[][4], GLuint n)
1236 {
1237 const GLuint *s = ((const GLuint *) src);
1238 GLuint i;
1239 for (i = 0; i < n; i++) {
1240 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
1241 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
1242 dst[i][BCOMP] = 0.0F;
1243 dst[i][ACOMP] = 1.0F;
1244 }
1245 }
1246
1247 static void
1248 unpack_SIGNED_RGB_16(const void *src, GLfloat dst[][4], GLuint n)
1249 {
1250 const GLshort *s = (const GLshort *) src;
1251 GLuint i;
1252 for (i = 0; i < n; i++) {
1253 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] );
1254 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
1255 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
1256 dst[i][ACOMP] = 1.0F;
1257 }
1258 }
1259
1260 static void
1261 unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1262 {
1263 const GLshort *s = (const GLshort *) src;
1264 GLuint i;
1265 for (i = 0; i < n; i++) {
1266 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
1267 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
1268 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
1269 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
1270 }
1271 }
1272
1273 static void
1274 unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1275 {
1276 const GLushort *s = (const GLushort *) src;
1277 GLuint i;
1278 for (i = 0; i < n; i++) {
1279 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
1280 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
1281 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
1282 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
1283 }
1284 }
1285
1286 static void
1287 unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1288 {
1289 /* XXX to do */
1290 }
1291
1292 static void
1293 unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1294 {
1295 /* XXX to do */
1296 }
1297
1298 static void
1299 unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1300 {
1301 /* XXX to do */
1302 }
1303
1304 static void
1305 unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1306 {
1307 /* XXX to do */
1308 }
1309
1310 static void
1311 unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1312 {
1313 /* XXX to do */
1314 }
1315
1316 static void
1317 unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1318 {
1319 /* XXX to do */
1320 }
1321
1322 static void
1323 unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1324 {
1325 /* XXX to do */
1326 }
1327
1328 static void
1329 unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1330 {
1331 /* XXX to do */
1332 }
1333
1334 static void
1335 unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1336 {
1337 /* XXX to do */
1338 }
1339
1340 static void
1341 unpack_ETC2_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1342 {
1343 /* XXX to do */
1344 }
1345
1346 static void
1347 unpack_ETC2_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
1348 {
1349 /* XXX to do */
1350 }
1351
1352 static void
1353 unpack_ETC2_RGBA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
1354 {
1355 /* XXX to do */
1356 }
1357
1358 static void
1359 unpack_ETC2_SRGB8_ALPHA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
1360 {
1361 /* XXX to do */
1362 }
1363
1364 static void
1365 unpack_ETC2_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1366 {
1367 /* XXX to do */
1368 }
1369
1370 static void
1371 unpack_ETC2_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1372 {
1373 /* XXX to do */
1374 }
1375
1376 static void
1377 unpack_ETC2_SIGNED_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1378 {
1379 /* XXX to do */
1380 }
1381
1382 static void
1383 unpack_ETC2_SIGNED_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1384 {
1385 /* XXX to do */
1386 }
1387
1388 static void
1389 unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
1390 GLuint n)
1391 {
1392 /* XXX to do */
1393 }
1394
1395 static void
1396 unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
1397 GLuint n)
1398 {
1399 /* XXX to do */
1400 }
1401
1402 static void
1403 unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n)
1404 {
1405 const GLbyte *s = ((const GLbyte *) src);
1406 GLuint i;
1407 for (i = 0; i < n; i++) {
1408 dst[i][RCOMP] = 0.0F;
1409 dst[i][GCOMP] = 0.0F;
1410 dst[i][BCOMP] = 0.0F;
1411 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1412 }
1413 }
1414
1415 static void
1416 unpack_SIGNED_L8(const void *src, GLfloat dst[][4], GLuint n)
1417 {
1418 const GLbyte *s = ((const GLbyte *) src);
1419 GLuint i;
1420 for (i = 0; i < n; i++) {
1421 dst[i][RCOMP] =
1422 dst[i][GCOMP] =
1423 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1424 dst[i][ACOMP] = 1.0F;
1425 }
1426 }
1427
1428 static void
1429 unpack_SIGNED_AL88(const void *src, GLfloat dst[][4], GLuint n)
1430 {
1431 const GLshort *s = ((const GLshort *) src);
1432 GLuint i;
1433 for (i = 0; i < n; i++) {
1434 dst[i][RCOMP] =
1435 dst[i][GCOMP] =
1436 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1437 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1438 }
1439 }
1440
1441 static void
1442 unpack_SIGNED_I8(const void *src, GLfloat dst[][4], GLuint n)
1443 {
1444 const GLbyte *s = ((const GLbyte *) src);
1445 GLuint i;
1446 for (i = 0; i < n; i++) {
1447 dst[i][RCOMP] =
1448 dst[i][GCOMP] =
1449 dst[i][BCOMP] =
1450 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1451 }
1452 }
1453
1454 static void
1455 unpack_SIGNED_A16(const void *src, GLfloat dst[][4], GLuint n)
1456 {
1457 const GLshort *s = ((const GLshort *) src);
1458 GLuint i;
1459 for (i = 0; i < n; i++) {
1460 dst[i][RCOMP] = 0.0F;
1461 dst[i][GCOMP] = 0.0F;
1462 dst[i][BCOMP] = 0.0F;
1463 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1464 }
1465 }
1466
1467 static void
1468 unpack_SIGNED_L16(const void *src, GLfloat dst[][4], GLuint n)
1469 {
1470 const GLshort *s = ((const GLshort *) src);
1471 GLuint i;
1472 for (i = 0; i < n; i++) {
1473 dst[i][RCOMP] =
1474 dst[i][GCOMP] =
1475 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1476 dst[i][ACOMP] = 1.0F;
1477 }
1478 }
1479
1480 static void
1481 unpack_SIGNED_AL1616(const void *src, GLfloat dst[][4], GLuint n)
1482 {
1483 const GLshort *s = (const GLshort *) src;
1484 GLuint i;
1485 for (i = 0; i < n; i++) {
1486 dst[i][RCOMP] =
1487 dst[i][GCOMP] =
1488 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
1489 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
1490 }
1491 }
1492
1493 static void
1494 unpack_SIGNED_I16(const void *src, GLfloat dst[][4], GLuint n)
1495 {
1496 const GLshort *s = ((const GLshort *) src);
1497 GLuint i;
1498 for (i = 0; i < n; i++) {
1499 dst[i][RCOMP] =
1500 dst[i][GCOMP] =
1501 dst[i][BCOMP] =
1502 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1503 }
1504 }
1505
1506 static void
1507 unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
1508 {
1509 const GLuint *s = (const GLuint *) src;
1510 GLuint i;
1511 for (i = 0; i < n; i++) {
1512 rgb9e5_to_float3(s[i], dst[i]);
1513 dst[i][ACOMP] = 1.0F;
1514 }
1515 }
1516
1517 static void
1518 unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
1519 {
1520 const GLuint *s = (const GLuint *) src;
1521 GLuint i;
1522 for (i = 0; i < n; i++) {
1523 r11g11b10f_to_float3(s[i], dst[i]);
1524 dst[i][ACOMP] = 1.0F;
1525 }
1526 }
1527
1528 static void
1529 unpack_XRGB4444_UNORM(const void *src, GLfloat dst[][4], GLuint n)
1530 {
1531 const GLushort *s = ((const GLushort *) src);
1532 GLuint i;
1533 for (i = 0; i < n; i++) {
1534 dst[i][RCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
1535 dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
1536 dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
1537 dst[i][ACOMP] = 1.0;
1538 }
1539 }
1540
1541 static void
1542 unpack_XRGB1555_UNORM(const void *src, GLfloat dst[][4], GLuint n)
1543 {
1544 const GLushort *s = ((const GLushort *) src);
1545 GLuint i;
1546 for (i = 0; i < n; i++) {
1547 dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
1548 dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F);
1549 dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F);
1550 dst[i][ACOMP] = 1.0;
1551 }
1552 }
1553
1554 static void
1555 unpack_XBGR8888_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1556 {
1557 const GLuint *s = ((const GLuint *) src);
1558 GLuint i;
1559 for (i = 0; i < n; i++) {
1560 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1561 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1562 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1563 dst[i][ACOMP] = 1.0;
1564 }
1565 }
1566
1567 static void
1568 unpack_XBGR8888_SRGB(const void *src, GLfloat dst[][4], GLuint n)
1569 {
1570 const GLuint *s = ((const GLuint *) src);
1571 GLuint i;
1572 for (i = 0; i < n; i++) {
1573 dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] ) & 0xff );
1574 dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 8) & 0xff );
1575 dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
1576 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
1577 }
1578 }
1579
1580 static void
1581 unpack_XBGR8888_UINT(const void *src, GLfloat dst[][4], GLuint n)
1582 {
1583 const GLbyte *s = (const GLbyte *) src;
1584 GLuint i;
1585 for (i = 0; i < n; i++) {
1586 dst[i][RCOMP] = s[i*4+0];
1587 dst[i][GCOMP] = s[i*4+1];
1588 dst[i][BCOMP] = s[i*4+2];
1589 dst[i][ACOMP] = 1.0;
1590 }
1591 }
1592
1593 static void
1594 unpack_XBGR8888_SINT(const void *src, GLfloat dst[][4], GLuint n)
1595 {
1596 const GLbyte *s = (const GLbyte *) src;
1597 GLuint i;
1598 for (i = 0; i < n; i++) {
1599 dst[i][RCOMP] = s[i*4+0];
1600 dst[i][GCOMP] = s[i*4+1];
1601 dst[i][BCOMP] = s[i*4+2];
1602 dst[i][ACOMP] = 1.0;
1603 }
1604 }
1605
1606 static void
1607 unpack_XRGB2101010_UNORM(const void *src, GLfloat dst[][4], GLuint n)
1608 {
1609 const GLuint *s = ((const GLuint *) src);
1610 GLuint i;
1611 for (i = 0; i < n; i++) {
1612 dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
1613 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
1614 dst[i][BCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
1615 dst[i][ACOMP] = 1.0;
1616 }
1617 }
1618
1619 static void
1620 unpack_XBGR16161616_UNORM(const void *src, GLfloat dst[][4], GLuint n)
1621 {
1622 const GLushort *s = (const GLushort *) src;
1623 GLuint i;
1624 for (i = 0; i < n; i++) {
1625 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
1626 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
1627 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
1628 dst[i][ACOMP] = 1.0;
1629 }
1630 }
1631
1632 static void
1633 unpack_XBGR16161616_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1634 {
1635 const GLshort *s = (const GLshort *) src;
1636 GLuint i;
1637 for (i = 0; i < n; i++) {
1638 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
1639 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
1640 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
1641 dst[i][ACOMP] = 1.0;
1642 }
1643 }
1644
1645 static void
1646 unpack_XBGR16161616_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
1647 {
1648 const GLshort *s = (const GLshort *) src;
1649 GLuint i;
1650 for (i = 0; i < n; i++) {
1651 dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
1652 dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
1653 dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
1654 dst[i][ACOMP] = 1.0;
1655 }
1656 }
1657
1658 static void
1659 unpack_XBGR16161616_UINT(const void *src, GLfloat dst[][4], GLuint n)
1660 {
1661 const GLushort *s = (const GLushort *) src;
1662 GLuint i;
1663 for (i = 0; i < n; i++) {
1664 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1665 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1666 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1667 dst[i][ACOMP] = 1.0;
1668 }
1669 }
1670
1671 static void
1672 unpack_XBGR16161616_SINT(const void *src, GLfloat dst[][4], GLuint n)
1673 {
1674 const GLshort *s = (const GLshort *) src;
1675 GLuint i;
1676 for (i = 0; i < n; i++) {
1677 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1678 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1679 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1680 dst[i][ACOMP] = 1.0;
1681 }
1682 }
1683
1684 static void
1685 unpack_XBGR32323232_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
1686 {
1687 const GLfloat *s = (const GLfloat *) src;
1688 GLuint i;
1689 for (i = 0; i < n; i++) {
1690 dst[i][RCOMP] = s[i*4+0];
1691 dst[i][GCOMP] = s[i*4+1];
1692 dst[i][BCOMP] = s[i*4+2];
1693 dst[i][ACOMP] = 1.0;
1694 }
1695 }
1696
1697 static void
1698 unpack_XBGR32323232_UINT(const void *src, GLfloat dst[][4], GLuint n)
1699 {
1700 const GLuint *s = (const GLuint *) src;
1701 GLuint i;
1702 for (i = 0; i < n; i++) {
1703 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1704 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1705 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1706 dst[i][ACOMP] = 1.0;
1707 }
1708 }
1709
1710 static void
1711 unpack_XBGR32323232_SINT(const void *src, GLfloat dst[][4], GLuint n)
1712 {
1713 const GLint *s = (const GLint *) src;
1714 GLuint i;
1715 for (i = 0; i < n; i++) {
1716 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1717 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1718 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1719 dst[i][ACOMP] = 1.0;
1720 }
1721 }
1722
1723
1724 /**
1725 * Return the unpacker function for the given format.
1726 */
1727 static unpack_rgba_func
1728 get_unpack_rgba_function(gl_format format)
1729 {
1730 static unpack_rgba_func table[MESA_FORMAT_COUNT];
1731 static GLboolean initialized = GL_FALSE;
1732
1733 if (!initialized) {
1734 table[MESA_FORMAT_NONE] = NULL;
1735
1736 table[MESA_FORMAT_RGBA8888] = unpack_RGBA8888;
1737 table[MESA_FORMAT_RGBA8888_REV] = unpack_RGBA8888_REV;
1738 table[MESA_FORMAT_ARGB8888] = unpack_ARGB8888;
1739 table[MESA_FORMAT_ARGB8888_REV] = unpack_ARGB8888_REV;
1740 table[MESA_FORMAT_RGBX8888] = unpack_RGBX8888;
1741 table[MESA_FORMAT_RGBX8888_REV] = unpack_RGBX8888_REV;
1742 table[MESA_FORMAT_XRGB8888] = unpack_XRGB8888;
1743 table[MESA_FORMAT_XRGB8888_REV] = unpack_XRGB8888_REV;
1744 table[MESA_FORMAT_RGB888] = unpack_RGB888;
1745 table[MESA_FORMAT_BGR888] = unpack_BGR888;
1746 table[MESA_FORMAT_RGB565] = unpack_RGB565;
1747 table[MESA_FORMAT_RGB565_REV] = unpack_RGB565_REV;
1748 table[MESA_FORMAT_ARGB4444] = unpack_ARGB4444;
1749 table[MESA_FORMAT_ARGB4444_REV] = unpack_ARGB4444_REV;
1750 table[MESA_FORMAT_RGBA5551] = unpack_RGBA5551;
1751 table[MESA_FORMAT_ARGB1555] = unpack_ARGB1555;
1752 table[MESA_FORMAT_ARGB1555_REV] = unpack_ARGB1555_REV;
1753 table[MESA_FORMAT_AL44] = unpack_AL44;
1754 table[MESA_FORMAT_AL88] = unpack_AL88;
1755 table[MESA_FORMAT_AL88_REV] = unpack_AL88_REV;
1756 table[MESA_FORMAT_AL1616] = unpack_AL1616;
1757 table[MESA_FORMAT_AL1616_REV] = unpack_AL1616_REV;
1758 table[MESA_FORMAT_RGB332] = unpack_RGB332;
1759 table[MESA_FORMAT_A8] = unpack_A8;
1760 table[MESA_FORMAT_A16] = unpack_A16;
1761 table[MESA_FORMAT_L8] = unpack_L8;
1762 table[MESA_FORMAT_L16] = unpack_L16;
1763 table[MESA_FORMAT_I8] = unpack_I8;
1764 table[MESA_FORMAT_I16] = unpack_I16;
1765 table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
1766 table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
1767 table[MESA_FORMAT_R8] = unpack_R8;
1768 table[MESA_FORMAT_GR88] = unpack_GR88;
1769 table[MESA_FORMAT_RG88] = unpack_RG88;
1770 table[MESA_FORMAT_R16] = unpack_R16;
1771 table[MESA_FORMAT_GR1616] = unpack_GR1616;
1772 table[MESA_FORMAT_RG1616] = unpack_RG1616;
1773 table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010;
1774 table[MESA_FORMAT_ABGR2101010_UINT] = unpack_ABGR2101010_UINT;
1775 table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8;
1776 table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24;
1777 table[MESA_FORMAT_Z16] = unpack_Z16;
1778 table[MESA_FORMAT_X8_Z24] = unpack_X8_Z24;
1779 table[MESA_FORMAT_Z24_X8] = unpack_Z24_X8;
1780 table[MESA_FORMAT_Z32] = unpack_Z32;
1781 table[MESA_FORMAT_S8] = unpack_S8;
1782 table[MESA_FORMAT_SRGB8] = unpack_SRGB8;
1783 table[MESA_FORMAT_SRGBA8] = unpack_SRGBA8;
1784 table[MESA_FORMAT_SARGB8] = unpack_SARGB8;
1785 table[MESA_FORMAT_SL8] = unpack_SL8;
1786 table[MESA_FORMAT_SLA8] = unpack_SLA8;
1787 table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
1788 table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
1789 table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
1790 table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
1791
1792 table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
1793 table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
1794 table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
1795 table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
1796 table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
1797 table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
1798
1799 table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
1800 table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
1801 table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
1802 table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
1803 table[MESA_FORMAT_ALPHA_FLOAT32] = unpack_ALPHA_FLOAT32;
1804 table[MESA_FORMAT_ALPHA_FLOAT16] = unpack_ALPHA_FLOAT16;
1805 table[MESA_FORMAT_LUMINANCE_FLOAT32] = unpack_LUMINANCE_FLOAT32;
1806 table[MESA_FORMAT_LUMINANCE_FLOAT16] = unpack_LUMINANCE_FLOAT16;
1807 table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = unpack_LUMINANCE_ALPHA_FLOAT32;
1808 table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = unpack_LUMINANCE_ALPHA_FLOAT16;
1809 table[MESA_FORMAT_INTENSITY_FLOAT32] = unpack_INTENSITY_FLOAT32;
1810 table[MESA_FORMAT_INTENSITY_FLOAT16] = unpack_INTENSITY_FLOAT16;
1811 table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
1812 table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
1813 table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
1814 table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
1815
1816 table[MESA_FORMAT_RGBA_INT8] = unpack_RGBA_INT8;
1817 table[MESA_FORMAT_RGBA_INT16] = unpack_RGBA_INT16;
1818 table[MESA_FORMAT_RGBA_INT32] = unpack_RGBA_INT32;
1819 table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
1820 table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
1821 table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
1822
1823 table[MESA_FORMAT_DUDV8] = unpack_DUDV8;
1824 table[MESA_FORMAT_SIGNED_R8] = unpack_SIGNED_R8;
1825 table[MESA_FORMAT_SIGNED_RG88_REV] = unpack_SIGNED_RG88_REV;
1826 table[MESA_FORMAT_SIGNED_RGBX8888] = unpack_SIGNED_RGBX8888;
1827 table[MESA_FORMAT_SIGNED_RGBA8888] = unpack_SIGNED_RGBA8888;
1828 table[MESA_FORMAT_SIGNED_RGBA8888_REV] = unpack_SIGNED_RGBA8888_REV;
1829 table[MESA_FORMAT_SIGNED_R16] = unpack_SIGNED_R16;
1830 table[MESA_FORMAT_SIGNED_GR1616] = unpack_SIGNED_GR1616;
1831 table[MESA_FORMAT_SIGNED_RGB_16] = unpack_SIGNED_RGB_16;
1832 table[MESA_FORMAT_SIGNED_RGBA_16] = unpack_SIGNED_RGBA_16;
1833 table[MESA_FORMAT_RGBA_16] = unpack_RGBA_16;
1834
1835 table[MESA_FORMAT_RED_RGTC1] = unpack_RED_RGTC1;
1836 table[MESA_FORMAT_SIGNED_RED_RGTC1] = unpack_SIGNED_RED_RGTC1;
1837 table[MESA_FORMAT_RG_RGTC2] = unpack_RG_RGTC2;
1838 table[MESA_FORMAT_SIGNED_RG_RGTC2] = unpack_SIGNED_RG_RGTC2;
1839
1840 table[MESA_FORMAT_L_LATC1] = unpack_L_LATC1;
1841 table[MESA_FORMAT_SIGNED_L_LATC1] = unpack_SIGNED_L_LATC1;
1842 table[MESA_FORMAT_LA_LATC2] = unpack_LA_LATC2;
1843 table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_LA_LATC2;
1844
1845 table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
1846 table[MESA_FORMAT_ETC2_RGB8] = unpack_ETC2_RGB8;
1847 table[MESA_FORMAT_ETC2_SRGB8] = unpack_ETC2_SRGB8;
1848 table[MESA_FORMAT_ETC2_RGBA8_EAC] = unpack_ETC2_RGBA8_EAC;
1849 table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = unpack_ETC2_SRGB8_ALPHA8_EAC;
1850 table[MESA_FORMAT_ETC2_R11_EAC] = unpack_ETC2_R11_EAC;
1851 table[MESA_FORMAT_ETC2_RG11_EAC] = unpack_ETC2_RG11_EAC;
1852 table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = unpack_ETC2_SIGNED_R11_EAC;
1853 table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = unpack_ETC2_SIGNED_RG11_EAC;
1854 table[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] =
1855 unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
1856 table[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] =
1857 unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
1858 table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8;
1859 table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8;
1860 table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88;
1861 table[MESA_FORMAT_SIGNED_I8] = unpack_SIGNED_I8;
1862 table[MESA_FORMAT_SIGNED_A16] = unpack_SIGNED_A16;
1863 table[MESA_FORMAT_SIGNED_L16] = unpack_SIGNED_L16;
1864 table[MESA_FORMAT_SIGNED_AL1616] = unpack_SIGNED_AL1616;
1865 table[MESA_FORMAT_SIGNED_I16] = unpack_SIGNED_I16;
1866
1867 table[MESA_FORMAT_RGB9_E5_FLOAT] = unpack_RGB9_E5_FLOAT;
1868 table[MESA_FORMAT_R11_G11_B10_FLOAT] = unpack_R11_G11_B10_FLOAT;
1869
1870 table[MESA_FORMAT_Z32_FLOAT] = unpack_Z32_FLOAT;
1871 table[MESA_FORMAT_Z32_FLOAT_X24S8] = unpack_Z32_FLOAT_X24S8;
1872
1873 table[MESA_FORMAT_XRGB4444_UNORM] = unpack_XRGB4444_UNORM;
1874 table[MESA_FORMAT_XRGB1555_UNORM] = unpack_XRGB1555_UNORM;
1875 table[MESA_FORMAT_XBGR8888_SNORM] = unpack_XBGR8888_SNORM;
1876 table[MESA_FORMAT_XBGR8888_SRGB] = unpack_XBGR8888_SRGB;
1877 table[MESA_FORMAT_XBGR8888_UINT] = unpack_XBGR8888_UINT;
1878 table[MESA_FORMAT_XBGR8888_SINT] = unpack_XBGR8888_SINT;
1879 table[MESA_FORMAT_XRGB2101010_UNORM] = unpack_XRGB2101010_UNORM;
1880 table[MESA_FORMAT_XBGR16161616_UNORM] = unpack_XBGR16161616_UNORM;
1881 table[MESA_FORMAT_XBGR16161616_SNORM] = unpack_XBGR16161616_SNORM;
1882 table[MESA_FORMAT_XBGR16161616_FLOAT] = unpack_XBGR16161616_FLOAT;
1883 table[MESA_FORMAT_XBGR16161616_UINT] = unpack_XBGR16161616_UINT;
1884 table[MESA_FORMAT_XBGR16161616_SINT] = unpack_XBGR16161616_SINT;
1885 table[MESA_FORMAT_XBGR32323232_FLOAT] = unpack_XBGR32323232_FLOAT;
1886 table[MESA_FORMAT_XBGR32323232_UINT] = unpack_XBGR32323232_UINT;
1887 table[MESA_FORMAT_XBGR32323232_SINT] = unpack_XBGR32323232_SINT;
1888
1889 initialized = GL_TRUE;
1890 }
1891
1892 if (table[format] == NULL) {
1893 _mesa_problem(NULL, "unsupported unpack for format %s",
1894 _mesa_get_format_name(format));
1895 }
1896
1897 return table[format];
1898 }
1899
1900
1901 /**
1902 * Unpack rgba colors, returning as GLfloat values.
1903 */
1904 void
1905 _mesa_unpack_rgba_row(gl_format format, GLuint n,
1906 const void *src, GLfloat dst[][4])
1907 {
1908 unpack_rgba_func unpack = get_unpack_rgba_function(format);
1909 unpack(src, dst, n);
1910 }
1911
1912
1913 /**********************************************************************/
1914 /* Unpack, returning GLubyte colors */
1915 /**********************************************************************/
1916
1917
1918 static void
1919 unpack_ubyte_RGBA8888(const void *src, GLubyte dst[][4], GLuint n)
1920 {
1921 const GLuint *s = ((const GLuint *) src);
1922 GLuint i;
1923 for (i = 0; i < n; i++) {
1924 dst[i][RCOMP] = (s[i] >> 24);
1925 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
1926 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
1927 dst[i][ACOMP] = (s[i] ) & 0xff;
1928 }
1929 }
1930
1931 static void
1932 unpack_ubyte_RGBA8888_REV(const void *src, GLubyte dst[][4], GLuint n)
1933 {
1934 const GLuint *s = ((const GLuint *) src);
1935 GLuint i;
1936 for (i = 0; i < n; i++) {
1937 dst[i][RCOMP] = (s[i] ) & 0xff;
1938 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
1939 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
1940 dst[i][ACOMP] = (s[i] >> 24);
1941 }
1942 }
1943
1944 static void
1945 unpack_ubyte_ARGB8888(const void *src, GLubyte dst[][4], GLuint n)
1946 {
1947 const GLuint *s = ((const GLuint *) src);
1948 GLuint i;
1949 for (i = 0; i < n; i++) {
1950 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
1951 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
1952 dst[i][BCOMP] = (s[i] ) & 0xff;
1953 dst[i][ACOMP] = (s[i] >> 24);
1954 }
1955 }
1956
1957 static void
1958 unpack_ubyte_ARGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
1959 {
1960 const GLuint *s = ((const GLuint *) src);
1961 GLuint i;
1962 for (i = 0; i < n; i++) {
1963 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
1964 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
1965 dst[i][BCOMP] = (s[i] >> 24);
1966 dst[i][ACOMP] = (s[i] ) & 0xff;
1967 }
1968 }
1969
1970 static void
1971 unpack_ubyte_RGBX8888(const void *src, GLubyte dst[][4], GLuint n)
1972 {
1973 const GLuint *s = ((const GLuint *) src);
1974 GLuint i;
1975 for (i = 0; i < n; i++) {
1976 dst[i][RCOMP] = (s[i] >> 24);
1977 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
1978 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
1979 dst[i][ACOMP] = 0xff;
1980 }
1981 }
1982
1983 static void
1984 unpack_ubyte_RGBX8888_REV(const void *src, GLubyte dst[][4], GLuint n)
1985 {
1986 const GLuint *s = ((const GLuint *) src);
1987 GLuint i;
1988 for (i = 0; i < n; i++) {
1989 dst[i][RCOMP] = (s[i] ) & 0xff;
1990 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
1991 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
1992 dst[i][ACOMP] = 0xff;
1993 }
1994 }
1995
1996 static void
1997 unpack_ubyte_XRGB8888(const void *src, GLubyte dst[][4], GLuint n)
1998 {
1999 const GLuint *s = ((const GLuint *) src);
2000 GLuint i;
2001 for (i = 0; i < n; i++) {
2002 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
2003 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2004 dst[i][BCOMP] = (s[i] ) & 0xff;
2005 dst[i][ACOMP] = 0xff;
2006 }
2007 }
2008
2009 static void
2010 unpack_ubyte_XRGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
2011 {
2012 const GLuint *s = ((const GLuint *) src);
2013 GLuint i;
2014 for (i = 0; i < n; i++) {
2015 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
2016 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2017 dst[i][BCOMP] = (s[i] >> 24);
2018 dst[i][ACOMP] = 0xff;
2019 }
2020 }
2021
2022 static void
2023 unpack_ubyte_RGB888(const void *src, GLubyte dst[][4], GLuint n)
2024 {
2025 const GLubyte *s = (const GLubyte *) src;
2026 GLuint i;
2027 for (i = 0; i < n; i++) {
2028 dst[i][RCOMP] = s[i*3+2];
2029 dst[i][GCOMP] = s[i*3+1];
2030 dst[i][BCOMP] = s[i*3+0];
2031 dst[i][ACOMP] = 0xff;
2032 }
2033 }
2034
2035 static void
2036 unpack_ubyte_BGR888(const void *src, GLubyte dst[][4], GLuint n)
2037 {
2038 const GLubyte *s = (const GLubyte *) src;
2039 GLuint i;
2040 for (i = 0; i < n; i++) {
2041 dst[i][RCOMP] = s[i*3+0];
2042 dst[i][GCOMP] = s[i*3+1];
2043 dst[i][BCOMP] = s[i*3+2];
2044 dst[i][ACOMP] = 0xff;
2045 }
2046 }
2047
2048 static void
2049 unpack_ubyte_RGB565(const void *src, GLubyte dst[][4], GLuint n)
2050 {
2051 const GLushort *s = ((const GLushort *) src);
2052 GLuint i;
2053 for (i = 0; i < n; i++) {
2054 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
2055 dst[i][GCOMP] = EXPAND_6_8((s[i] >> 5 ) & 0x3f);
2056 dst[i][BCOMP] = EXPAND_5_8( s[i] & 0x1f);
2057 dst[i][ACOMP] = 0xff;
2058 }
2059 }
2060
2061 static void
2062 unpack_ubyte_RGB565_REV(const void *src, GLubyte dst[][4], GLuint n)
2063 {
2064 const GLushort *s = ((const GLushort *) src);
2065 GLuint i;
2066 for (i = 0; i < n; i++) {
2067 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
2068 dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);
2069 dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);
2070 dst[i][BCOMP] = EXPAND_5_8( t & 0x1f);
2071 dst[i][ACOMP] = 0xff;
2072 }
2073 }
2074
2075 static void
2076 unpack_ubyte_ARGB4444(const void *src, GLubyte dst[][4], GLuint n)
2077 {
2078 const GLushort *s = ((const GLushort *) src);
2079 GLuint i;
2080 for (i = 0; i < n; i++) {
2081 dst[i][RCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
2082 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
2083 dst[i][BCOMP] = EXPAND_4_8((s[i] ) & 0xf);
2084 dst[i][ACOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
2085 }
2086 }
2087
2088 static void
2089 unpack_ubyte_ARGB4444_REV(const void *src, GLubyte dst[][4], GLuint n)
2090 {
2091 const GLushort *s = ((const GLushort *) src);
2092 GLuint i;
2093 for (i = 0; i < n; i++) {
2094 dst[i][RCOMP] = EXPAND_4_8((s[i] ) & 0xf);
2095 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
2096 dst[i][BCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
2097 dst[i][ACOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
2098 }
2099 }
2100
2101 static void
2102 unpack_ubyte_RGBA5551(const void *src, GLubyte dst[][4], GLuint n)
2103 {
2104 const GLushort *s = ((const GLushort *) src);
2105 GLuint i;
2106 for (i = 0; i < n; i++) {
2107 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
2108 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 6) & 0x1f);
2109 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 1) & 0x1f);
2110 dst[i][ACOMP] = EXPAND_1_8((s[i] ) & 0x01);
2111 }
2112 }
2113
2114 static void
2115 unpack_ubyte_ARGB1555(const void *src, GLubyte dst[][4], GLuint n)
2116 {
2117 const GLushort *s = ((const GLushort *) src);
2118 GLuint i;
2119 for (i = 0; i < n; i++) {
2120 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 10) & 0x1f);
2121 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 5) & 0x1f);
2122 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 0) & 0x1f);
2123 dst[i][ACOMP] = EXPAND_1_8((s[i] >> 15) & 0x01);
2124 }
2125 }
2126
2127 static void
2128 unpack_ubyte_ARGB1555_REV(const void *src, GLubyte dst[][4], GLuint n)
2129 {
2130 const GLushort *s = ((const GLushort *) src);
2131 GLuint i;
2132 for (i = 0; i < n; i++) {
2133 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
2134 dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
2135 dst[i][GCOMP] = EXPAND_5_8((tmp >> 5) & 0x1f);
2136 dst[i][BCOMP] = EXPAND_5_8((tmp >> 0) & 0x1f);
2137 dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
2138 }
2139 }
2140
2141 static void
2142 unpack_ubyte_AL44(const void *src, GLubyte dst[][4], GLuint n)
2143 {
2144 const GLubyte *s = ((const GLubyte *) src);
2145 GLuint i;
2146 for (i = 0; i < n; i++) {
2147 dst[i][RCOMP] =
2148 dst[i][GCOMP] =
2149 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xf);
2150 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 4);
2151 }
2152 }
2153
2154 static void
2155 unpack_ubyte_AL88(const void *src, GLubyte dst[][4], GLuint n)
2156 {
2157 const GLushort *s = ((const GLushort *) src);
2158 GLuint i;
2159 for (i = 0; i < n; i++) {
2160 dst[i][RCOMP] =
2161 dst[i][GCOMP] =
2162 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xff);
2163 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 8);
2164 }
2165 }
2166
2167 static void
2168 unpack_ubyte_AL88_REV(const void *src, GLubyte dst[][4], GLuint n)
2169 {
2170 const GLushort *s = ((const GLushort *) src);
2171 GLuint i;
2172 for (i = 0; i < n; i++) {
2173 dst[i][RCOMP] =
2174 dst[i][GCOMP] =
2175 dst[i][BCOMP] = EXPAND_4_8(s[i] >> 8);
2176 dst[i][ACOMP] = EXPAND_4_8(s[i] & 0xff);
2177 }
2178 }
2179
2180 static void
2181 unpack_ubyte_RGB332(const void *src, GLubyte dst[][4], GLuint n)
2182 {
2183 const GLubyte *s = ((const GLubyte *) src);
2184 GLuint i;
2185 for (i = 0; i < n; i++) {
2186 dst[i][RCOMP] = EXPAND_3_8((s[i] >> 5) & 0x7);
2187 dst[i][GCOMP] = EXPAND_3_8((s[i] >> 2) & 0x7);
2188 dst[i][BCOMP] = EXPAND_2_8((s[i] ) & 0x3);
2189 dst[i][ACOMP] = 0xff;
2190 }
2191 }
2192
2193 static void
2194 unpack_ubyte_A8(const void *src, GLubyte dst[][4], GLuint n)
2195 {
2196 const GLubyte *s = ((const GLubyte *) src);
2197 GLuint i;
2198 for (i = 0; i < n; i++) {
2199 dst[i][RCOMP] =
2200 dst[i][GCOMP] =
2201 dst[i][BCOMP] = 0;
2202 dst[i][ACOMP] = s[i];
2203 }
2204 }
2205
2206 static void
2207 unpack_ubyte_L8(const void *src, GLubyte dst[][4], GLuint n)
2208 {
2209 const GLubyte *s = ((const GLubyte *) src);
2210 GLuint i;
2211 for (i = 0; i < n; i++) {
2212 dst[i][RCOMP] =
2213 dst[i][GCOMP] =
2214 dst[i][BCOMP] = s[i];
2215 dst[i][ACOMP] = 0xff;
2216 }
2217 }
2218
2219
2220 static void
2221 unpack_ubyte_I8(const void *src, GLubyte dst[][4], GLuint n)
2222 {
2223 const GLubyte *s = ((const GLubyte *) src);
2224 GLuint i;
2225 for (i = 0; i < n; i++) {
2226 dst[i][RCOMP] =
2227 dst[i][GCOMP] =
2228 dst[i][BCOMP] =
2229 dst[i][ACOMP] = s[i];
2230 }
2231 }
2232
2233 static void
2234 unpack_ubyte_R8(const void *src, GLubyte dst[][4], GLuint n)
2235 {
2236 const GLubyte *s = ((const GLubyte *) src);
2237 GLuint i;
2238 for (i = 0; i < n; i++) {
2239 dst[i][0] = s[i];
2240 dst[i][1] =
2241 dst[i][2] = 0;
2242 dst[i][3] = 0xff;
2243 }
2244 }
2245
2246 static void
2247 unpack_ubyte_GR88(const void *src, GLubyte dst[][4], GLuint n)
2248 {
2249 const GLushort *s = ((const GLushort *) src);
2250 GLuint i;
2251 for (i = 0; i < n; i++) {
2252 dst[i][RCOMP] = s[i] & 0xff;
2253 dst[i][GCOMP] = s[i] >> 8;
2254 dst[i][BCOMP] = 0;
2255 dst[i][ACOMP] = 0xff;
2256 }
2257 }
2258
2259 static void
2260 unpack_ubyte_RG88(const void *src, GLubyte dst[][4], GLuint n)
2261 {
2262 const GLushort *s = ((const GLushort *) src);
2263 GLuint i;
2264 for (i = 0; i < n; i++) {
2265 dst[i][RCOMP] = s[i] >> 8;
2266 dst[i][GCOMP] = s[i] & 0xff;
2267 dst[i][BCOMP] = 0;
2268 dst[i][ACOMP] = 0xff;
2269 }
2270 }
2271
2272
2273 /**
2274 * Unpack rgba colors, returning as GLubyte values. This should usually
2275 * only be used for unpacking formats that use 8 bits or less per channel.
2276 */
2277 void
2278 _mesa_unpack_ubyte_rgba_row(gl_format format, GLuint n,
2279 const void *src, GLubyte dst[][4])
2280 {
2281 switch (format) {
2282 case MESA_FORMAT_RGBA8888:
2283 unpack_ubyte_RGBA8888(src, dst, n);
2284 break;
2285 case MESA_FORMAT_RGBA8888_REV:
2286 unpack_ubyte_RGBA8888_REV(src, dst, n);
2287 break;
2288 case MESA_FORMAT_ARGB8888:
2289 unpack_ubyte_ARGB8888(src, dst, n);
2290 break;
2291 case MESA_FORMAT_ARGB8888_REV:
2292 unpack_ubyte_ARGB8888_REV(src, dst, n);
2293 break;
2294 case MESA_FORMAT_RGBX8888:
2295 unpack_ubyte_RGBX8888(src, dst, n);
2296 break;
2297 case MESA_FORMAT_RGBX8888_REV:
2298 unpack_ubyte_RGBX8888_REV(src, dst, n);
2299 break;
2300 case MESA_FORMAT_XRGB8888:
2301 unpack_ubyte_XRGB8888(src, dst, n);
2302 break;
2303 case MESA_FORMAT_XRGB8888_REV:
2304 unpack_ubyte_XRGB8888_REV(src, dst, n);
2305 break;
2306 case MESA_FORMAT_RGB888:
2307 unpack_ubyte_RGB888(src, dst, n);
2308 break;
2309 case MESA_FORMAT_BGR888:
2310 unpack_ubyte_BGR888(src, dst, n);
2311 break;
2312 case MESA_FORMAT_RGB565:
2313 unpack_ubyte_RGB565(src, dst, n);
2314 break;
2315 case MESA_FORMAT_RGB565_REV:
2316 unpack_ubyte_RGB565_REV(src, dst, n);
2317 break;
2318 case MESA_FORMAT_ARGB4444:
2319 unpack_ubyte_ARGB4444(src, dst, n);
2320 break;
2321 case MESA_FORMAT_ARGB4444_REV:
2322 unpack_ubyte_ARGB4444_REV(src, dst, n);
2323 break;
2324 case MESA_FORMAT_RGBA5551:
2325 unpack_ubyte_RGBA5551(src, dst, n);
2326 break;
2327 case MESA_FORMAT_ARGB1555:
2328 unpack_ubyte_ARGB1555(src, dst, n);
2329 break;
2330 case MESA_FORMAT_ARGB1555_REV:
2331 unpack_ubyte_ARGB1555_REV(src, dst, n);
2332 break;
2333 case MESA_FORMAT_AL44:
2334 unpack_ubyte_AL44(src, dst, n);
2335 break;
2336 case MESA_FORMAT_AL88:
2337 unpack_ubyte_AL88(src, dst, n);
2338 break;
2339 case MESA_FORMAT_AL88_REV:
2340 unpack_ubyte_AL88_REV(src, dst, n);
2341 break;
2342 case MESA_FORMAT_RGB332:
2343 unpack_ubyte_RGB332(src, dst, n);
2344 break;
2345 case MESA_FORMAT_A8:
2346 unpack_ubyte_A8(src, dst, n);
2347 break;
2348 case MESA_FORMAT_L8:
2349 unpack_ubyte_L8(src, dst, n);
2350 break;
2351 case MESA_FORMAT_I8:
2352 unpack_ubyte_I8(src, dst, n);
2353 break;
2354 case MESA_FORMAT_R8:
2355 unpack_ubyte_R8(src, dst, n);
2356 break;
2357 case MESA_FORMAT_GR88:
2358 unpack_ubyte_GR88(src, dst, n);
2359 break;
2360 case MESA_FORMAT_RG88:
2361 unpack_ubyte_RG88(src, dst, n);
2362 break;
2363 default:
2364 /* get float values, convert to ubyte */
2365 {
2366 GLfloat *tmp = malloc(n * 4 * sizeof(GLfloat));
2367 if (tmp) {
2368 GLuint i;
2369 _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
2370 for (i = 0; i < n; i++) {
2371 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][0], tmp[i*4+0]);
2372 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][1], tmp[i*4+1]);
2373 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][2], tmp[i*4+2]);
2374 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][3], tmp[i*4+3]);
2375 }
2376 free(tmp);
2377 }
2378 }
2379 break;
2380 }
2381 }
2382
2383
2384 /**********************************************************************/
2385 /* Unpack, returning GLuint colors */
2386 /**********************************************************************/
2387
2388 static void
2389 unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2390 {
2391 memcpy(dst, src, n * 4 * sizeof(GLuint));
2392 }
2393
2394 static void
2395 unpack_int_rgba_RGBA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2396 {
2397 unsigned int i;
2398
2399 for (i = 0; i < n; i++) {
2400 dst[i][0] = src[i * 4 + 0];
2401 dst[i][1] = src[i * 4 + 1];
2402 dst[i][2] = src[i * 4 + 2];
2403 dst[i][3] = src[i * 4 + 3];
2404 }
2405 }
2406
2407 static void
2408 unpack_int_rgba_RGBA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2409 {
2410 unsigned int i;
2411
2412 for (i = 0; i < n; i++) {
2413 dst[i][0] = src[i * 4 + 0];
2414 dst[i][1] = src[i * 4 + 1];
2415 dst[i][2] = src[i * 4 + 2];
2416 dst[i][3] = src[i * 4 + 3];
2417 }
2418 }
2419
2420 static void
2421 unpack_int_rgba_RGBA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2422 {
2423 unsigned int i;
2424
2425 for (i = 0; i < n; i++) {
2426 dst[i][0] = src[i * 4 + 0];
2427 dst[i][1] = src[i * 4 + 1];
2428 dst[i][2] = src[i * 4 + 2];
2429 dst[i][3] = src[i * 4 + 3];
2430 }
2431 }
2432
2433 static void
2434 unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2435 {
2436 unsigned int i;
2437
2438 for (i = 0; i < n; i++) {
2439 dst[i][0] = src[i * 4 + 0];
2440 dst[i][1] = src[i * 4 + 1];
2441 dst[i][2] = src[i * 4 + 2];
2442 dst[i][3] = src[i * 4 + 3];
2443 }
2444 }
2445
2446 static void
2447 unpack_int_rgba_ARGB8888(const GLbyte *src, GLuint dst[][4], GLuint n)
2448 {
2449 unsigned int i;
2450
2451 for (i = 0; i < n; i++) {
2452 dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
2453 dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
2454 dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
2455 dst[i][ACOMP] = (GLubyte) src[i * 4 + 3];
2456 }
2457 }
2458
2459 static void
2460 unpack_int_rgba_XRGB8888(const GLbyte *src, GLuint dst[][4], GLuint n)
2461 {
2462 unsigned int i;
2463
2464 for (i = 0; i < n; i++) {
2465 dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
2466 dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
2467 dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
2468 dst[i][ACOMP] = (GLubyte) 0xff;
2469 }
2470 }
2471
2472 static void
2473 unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2474 {
2475 unsigned int i;
2476
2477 for (i = 0; i < n; i++) {
2478 dst[i][0] = src[i * 3 + 0];
2479 dst[i][1] = src[i * 3 + 1];
2480 dst[i][2] = src[i * 3 + 2];
2481 dst[i][3] = 1;
2482 }
2483 }
2484
2485 static void
2486 unpack_int_rgba_RGB_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2487 {
2488 unsigned int i;
2489
2490 for (i = 0; i < n; i++) {
2491 dst[i][0] = src[i * 3 + 0];
2492 dst[i][1] = src[i * 3 + 1];
2493 dst[i][2] = src[i * 3 + 2];
2494 dst[i][3] = 1;
2495 }
2496 }
2497
2498 static void
2499 unpack_int_rgba_RGB_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2500 {
2501 unsigned int i;
2502
2503 for (i = 0; i < n; i++) {
2504 dst[i][0] = src[i * 3 + 0];
2505 dst[i][1] = src[i * 3 + 1];
2506 dst[i][2] = src[i * 3 + 2];
2507 dst[i][3] = 1;
2508 }
2509 }
2510
2511 static void
2512 unpack_int_rgba_RGB_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2513 {
2514 unsigned int i;
2515
2516 for (i = 0; i < n; i++) {
2517 dst[i][0] = src[i * 3 + 0];
2518 dst[i][1] = src[i * 3 + 1];
2519 dst[i][2] = src[i * 3 + 2];
2520 dst[i][3] = 1;
2521 }
2522 }
2523
2524 static void
2525 unpack_int_rgba_RGB_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2526 {
2527 unsigned int i;
2528
2529 for (i = 0; i < n; i++) {
2530 dst[i][0] = src[i * 3 + 0];
2531 dst[i][1] = src[i * 3 + 1];
2532 dst[i][2] = src[i * 3 + 2];
2533 dst[i][3] = 1;
2534 }
2535 }
2536
2537 static void
2538 unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2539 {
2540 unsigned int i;
2541
2542 for (i = 0; i < n; i++) {
2543 dst[i][0] = src[i * 2 + 0];
2544 dst[i][1] = src[i * 2 + 1];
2545 dst[i][2] = 0;
2546 dst[i][3] = 1;
2547 }
2548 }
2549
2550 static void
2551 unpack_int_rgba_RG_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2552 {
2553 unsigned int i;
2554
2555 for (i = 0; i < n; i++) {
2556 dst[i][0] = src[i * 2 + 0];
2557 dst[i][1] = src[i * 2 + 1];
2558 dst[i][2] = 0;
2559 dst[i][3] = 1;
2560 }
2561 }
2562
2563 static void
2564 unpack_int_rgba_RG_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2565 {
2566 unsigned int i;
2567
2568 for (i = 0; i < n; i++) {
2569 dst[i][0] = src[i * 2 + 0];
2570 dst[i][1] = src[i * 2 + 1];
2571 dst[i][2] = 0;
2572 dst[i][3] = 1;
2573 }
2574 }
2575
2576 static void
2577 unpack_int_rgba_RG_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2578 {
2579 unsigned int i;
2580
2581 for (i = 0; i < n; i++) {
2582 dst[i][0] = src[i * 2 + 0];
2583 dst[i][1] = src[i * 2 + 1];
2584 dst[i][2] = 0;
2585 dst[i][3] = 1;
2586 }
2587 }
2588
2589 static void
2590 unpack_int_rgba_RG_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2591 {
2592 unsigned int i;
2593
2594 for (i = 0; i < n; i++) {
2595 dst[i][0] = src[i * 2 + 0];
2596 dst[i][1] = src[i * 2 + 1];
2597 dst[i][2] = 0;
2598 dst[i][3] = 1;
2599 }
2600 }
2601
2602 static void
2603 unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2604 {
2605 unsigned int i;
2606
2607 for (i = 0; i < n; i++) {
2608 dst[i][0] = src[i];
2609 dst[i][1] = 0;
2610 dst[i][2] = 0;
2611 dst[i][3] = 1;
2612 }
2613 }
2614
2615 static void
2616 unpack_int_rgba_R_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2617 {
2618 unsigned int i;
2619
2620 for (i = 0; i < n; i++) {
2621 dst[i][0] = src[i];
2622 dst[i][1] = 0;
2623 dst[i][2] = 0;
2624 dst[i][3] = 1;
2625 }
2626 }
2627
2628 static void
2629 unpack_int_rgba_R_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2630 {
2631 unsigned int i;
2632
2633 for (i = 0; i < n; i++) {
2634 dst[i][0] = src[i];
2635 dst[i][1] = 0;
2636 dst[i][2] = 0;
2637 dst[i][3] = 1;
2638 }
2639 }
2640
2641 static void
2642 unpack_int_rgba_R_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2643 {
2644 unsigned int i;
2645
2646 for (i = 0; i < n; i++) {
2647 dst[i][0] = src[i];
2648 dst[i][1] = 0;
2649 dst[i][2] = 0;
2650 dst[i][3] = 1;
2651 }
2652 }
2653
2654 static void
2655 unpack_int_rgba_R_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2656 {
2657 unsigned int i;
2658
2659 for (i = 0; i < n; i++) {
2660 dst[i][0] = src[i];
2661 dst[i][1] = 0;
2662 dst[i][2] = 0;
2663 dst[i][3] = 1;
2664 }
2665 }
2666
2667 static void
2668 unpack_int_rgba_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2669 {
2670 unsigned int i;
2671
2672 for (i = 0; i < n; i++) {
2673 dst[i][0] = dst[i][1] = dst[i][2] = 0;
2674 dst[i][3] = src[i];
2675 }
2676 }
2677
2678 static void
2679 unpack_int_rgba_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2680 {
2681 unsigned int i;
2682
2683 for (i = 0; i < n; i++) {
2684 dst[i][0] = dst[i][1] = dst[i][2] = 0;
2685 dst[i][3] = src[i];
2686 }
2687 }
2688
2689 static void
2690 unpack_int_rgba_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2691 {
2692 unsigned int i;
2693
2694 for (i = 0; i < n; i++) {
2695 dst[i][0] = dst[i][1] = dst[i][2] = 0;
2696 dst[i][3] = src[i];
2697 }
2698 }
2699
2700 static void
2701 unpack_int_rgba_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2702 {
2703 unsigned int i;
2704
2705 for (i = 0; i < n; i++) {
2706 dst[i][0] = dst[i][1] = dst[i][2] = 0;
2707 dst[i][3] = src[i];
2708 }
2709 }
2710
2711 static void
2712 unpack_int_rgba_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2713 {
2714 unsigned int i;
2715
2716 for (i = 0; i < n; i++) {
2717 dst[i][0] = dst[i][1] = dst[i][2] = 0;
2718 dst[i][3] = src[i];
2719 }
2720 }
2721
2722 static void
2723 unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2724 {
2725 unsigned int i;
2726
2727 for (i = 0; i < n; i++) {
2728 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
2729 dst[i][3] = 1;
2730 }
2731 }
2732
2733 static void
2734 unpack_int_rgba_LUMINANCE_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2735 {
2736 unsigned int i;
2737
2738 for (i = 0; i < n; i++) {
2739 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
2740 dst[i][3] = 1;
2741 }
2742 }
2743
2744 static void
2745 unpack_int_rgba_LUMINANCE_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2746 {
2747 unsigned int i;
2748
2749 for (i = 0; i < n; i++) {
2750 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
2751 dst[i][3] = 1;
2752 }
2753 }
2754
2755 static void
2756 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2757 {
2758 unsigned int i;
2759
2760 for (i = 0; i < n; i++) {
2761 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
2762 dst[i][3] = 1;
2763 }
2764 }
2765
2766 static void
2767 unpack_int_rgba_LUMINANCE_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2768 {
2769 unsigned int i;
2770
2771 for (i = 0; i < n; i++) {
2772 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
2773 dst[i][3] = 1;
2774 }
2775 }
2776
2777
2778 static void
2779 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2780 {
2781 unsigned int i;
2782
2783 for (i = 0; i < n; i++) {
2784 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
2785 dst[i][3] = src[i * 2 + 1];
2786 }
2787 }
2788
2789 static void
2790 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2791 {
2792 unsigned int i;
2793
2794 for (i = 0; i < n; i++) {
2795 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
2796 dst[i][3] = src[i * 2 + 1];
2797 }
2798 }
2799
2800 static void
2801 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2802 {
2803 unsigned int i;
2804
2805 for (i = 0; i < n; i++) {
2806 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
2807 dst[i][3] = src[i * 2 + 1];
2808 }
2809 }
2810
2811 static void
2812 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2813 {
2814 unsigned int i;
2815
2816 for (i = 0; i < n; i++) {
2817 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
2818 dst[i][3] = src[i * 2 + 1];
2819 }
2820 }
2821
2822 static void
2823 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2824 {
2825 unsigned int i;
2826
2827 for (i = 0; i < n; i++) {
2828 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
2829 dst[i][3] = src[i * 2 + 1];
2830 }
2831 }
2832
2833 static void
2834 unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2835 {
2836 unsigned int i;
2837
2838 for (i = 0; i < n; i++) {
2839 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
2840 }
2841 }
2842
2843 static void
2844 unpack_int_rgba_INTENSITY_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2845 {
2846 unsigned int i;
2847
2848 for (i = 0; i < n; i++) {
2849 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
2850 }
2851 }
2852
2853 static void
2854 unpack_int_rgba_INTENSITY_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2855 {
2856 unsigned int i;
2857
2858 for (i = 0; i < n; i++) {
2859 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
2860 }
2861 }
2862
2863 static void
2864 unpack_int_rgba_INTENSITY_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2865 {
2866 unsigned int i;
2867
2868 for (i = 0; i < n; i++) {
2869 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
2870 }
2871 }
2872
2873 static void
2874 unpack_int_rgba_INTENSITY_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2875 {
2876 unsigned int i;
2877
2878 for (i = 0; i < n; i++) {
2879 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
2880 }
2881 }
2882
2883 static void
2884 unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
2885 {
2886 unsigned int i;
2887
2888 for (i = 0; i < n; i++) {
2889 GLuint tmp = src[i];
2890 dst[i][0] = (tmp >> 20) & 0x3ff;
2891 dst[i][1] = (tmp >> 10) & 0x3ff;
2892 dst[i][2] = (tmp >> 0) & 0x3ff;
2893 dst[i][3] = (tmp >> 30) & 0x3;
2894 }
2895 }
2896
2897 static void
2898 unpack_int_rgba_ABGR2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
2899 {
2900 unsigned int i;
2901
2902 for (i = 0; i < n; i++) {
2903 GLuint tmp = src[i];
2904 dst[i][0] = (tmp >> 0) & 0x3ff;
2905 dst[i][1] = (tmp >> 10) & 0x3ff;
2906 dst[i][2] = (tmp >> 20) & 0x3ff;
2907 dst[i][3] = (tmp >> 30) & 0x3;
2908 }
2909 }
2910
2911 static void
2912 unpack_int_rgba_ARGB2101010(const GLuint *src, GLuint dst[][4], GLuint n)
2913 {
2914 unsigned int i;
2915
2916 for (i = 0; i < n; i++) {
2917 GLuint tmp = src[i];
2918 dst[i][0] = (tmp >> 20) & 0x3ff;
2919 dst[i][1] = (tmp >> 10) & 0x3ff;
2920 dst[i][2] = (tmp >> 0) & 0x3ff;
2921 dst[i][3] = (tmp >> 30) & 0x3;
2922 }
2923 }
2924
2925 static void
2926 unpack_int_rgba_XBGR8888_UINT(const GLubyte *src, GLuint dst[][4], GLuint n)
2927 {
2928 unsigned int i;
2929
2930 for (i = 0; i < n; i++) {
2931 dst[i][0] = src[i * 4 + 0];
2932 dst[i][1] = src[i * 4 + 1];
2933 dst[i][2] = src[i * 4 + 2];
2934 dst[i][3] = 1;
2935 }
2936 }
2937
2938 static void
2939 unpack_int_rgba_XBGR8888_SINT(const GLbyte *src, GLuint dst[][4], GLuint n)
2940 {
2941 unsigned int i;
2942
2943 for (i = 0; i < n; i++) {
2944 dst[i][0] = src[i * 4 + 0];
2945 dst[i][1] = src[i * 4 + 1];
2946 dst[i][2] = src[i * 4 + 2];
2947 dst[i][3] = 1;
2948 }
2949 }
2950
2951 static void
2952 unpack_int_rgba_XBGR16161616_UINT(const GLushort *src, GLuint dst[][4], GLuint n)
2953 {
2954 unsigned int i;
2955
2956 for (i = 0; i < n; i++) {
2957 dst[i][0] = src[i * 4 + 0];
2958 dst[i][1] = src[i * 4 + 1];
2959 dst[i][2] = src[i * 4 + 2];
2960 dst[i][3] = 1;
2961 }
2962 }
2963
2964 static void
2965 unpack_int_rgba_XBGR16161616_SINT(const GLshort *src, GLuint dst[][4], GLuint n)
2966 {
2967 unsigned int i;
2968
2969 for (i = 0; i < n; i++) {
2970 dst[i][0] = src[i * 4 + 0];
2971 dst[i][1] = src[i * 4 + 1];
2972 dst[i][2] = src[i * 4 + 2];
2973 dst[i][3] = 1;
2974 }
2975 }
2976
2977 static void
2978 unpack_int_rgba_XBGR32323232_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
2979 {
2980 unsigned int i;
2981
2982 for (i = 0; i < n; i++) {
2983 dst[i][0] = src[i * 4 + 0];
2984 dst[i][1] = src[i * 4 + 1];
2985 dst[i][2] = src[i * 4 + 2];
2986 dst[i][3] = 1;
2987 }
2988 }
2989
2990 void
2991 _mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
2992 const void *src, GLuint dst[][4])
2993 {
2994 switch (format) {
2995 /* Since there won't be any sign extension happening, there's no need to
2996 * make separate paths for 32-bit-to-32-bit integer unpack.
2997 */
2998 case MESA_FORMAT_RGBA_UINT32:
2999 case MESA_FORMAT_RGBA_INT32:
3000 unpack_int_rgba_RGBA_UINT32(src, dst, n);
3001 break;
3002
3003 case MESA_FORMAT_RGBA_UINT16:
3004 unpack_int_rgba_RGBA_UINT16(src, dst, n);
3005 break;
3006 case MESA_FORMAT_RGBA_INT16:
3007 unpack_int_rgba_RGBA_INT16(src, dst, n);
3008 break;
3009
3010 case MESA_FORMAT_RGBA_UINT8:
3011 unpack_int_rgba_RGBA_UINT8(src, dst, n);
3012 break;
3013 case MESA_FORMAT_RGBA_INT8:
3014 unpack_int_rgba_RGBA_INT8(src, dst, n);
3015 break;
3016
3017 case MESA_FORMAT_ARGB8888:
3018 unpack_int_rgba_ARGB8888(src, dst, n);
3019 break;
3020
3021 case MESA_FORMAT_XRGB8888:
3022 unpack_int_rgba_XRGB8888(src, dst, n);
3023 break;
3024
3025 case MESA_FORMAT_RGB_UINT32:
3026 case MESA_FORMAT_RGB_INT32:
3027 unpack_int_rgba_RGB_UINT32(src, dst, n);
3028 break;
3029
3030 case MESA_FORMAT_RGB_UINT16:
3031 unpack_int_rgba_RGB_UINT16(src, dst, n);
3032 break;
3033 case MESA_FORMAT_RGB_INT16:
3034 unpack_int_rgba_RGB_INT16(src, dst, n);
3035 break;
3036
3037 case MESA_FORMAT_RGB_UINT8:
3038 unpack_int_rgba_RGB_UINT8(src, dst, n);
3039 break;
3040 case MESA_FORMAT_RGB_INT8:
3041 unpack_int_rgba_RGB_INT8(src, dst, n);
3042 break;
3043
3044 case MESA_FORMAT_RG_UINT32:
3045 case MESA_FORMAT_RG_INT32:
3046 unpack_int_rgba_RG_UINT32(src, dst, n);
3047 break;
3048
3049 case MESA_FORMAT_RG_UINT16:
3050 unpack_int_rgba_RG_UINT16(src, dst, n);
3051 break;
3052 case MESA_FORMAT_RG_INT16:
3053 unpack_int_rgba_RG_INT16(src, dst, n);
3054 break;
3055
3056 case MESA_FORMAT_RG_UINT8:
3057 unpack_int_rgba_RG_UINT8(src, dst, n);
3058 break;
3059 case MESA_FORMAT_RG_INT8:
3060 unpack_int_rgba_RG_INT8(src, dst, n);
3061 break;
3062
3063 case MESA_FORMAT_R_UINT32:
3064 case MESA_FORMAT_R_INT32:
3065 unpack_int_rgba_R_UINT32(src, dst, n);
3066 break;
3067
3068 case MESA_FORMAT_R_UINT16:
3069 unpack_int_rgba_R_UINT16(src, dst, n);
3070 break;
3071 case MESA_FORMAT_R_INT16:
3072 unpack_int_rgba_R_INT16(src, dst, n);
3073 break;
3074
3075 case MESA_FORMAT_R_UINT8:
3076 unpack_int_rgba_R_UINT8(src, dst, n);
3077 break;
3078 case MESA_FORMAT_R_INT8:
3079 unpack_int_rgba_R_INT8(src, dst, n);
3080 break;
3081
3082 case MESA_FORMAT_ALPHA_UINT32:
3083 case MESA_FORMAT_ALPHA_INT32:
3084 unpack_int_rgba_ALPHA_UINT32(src, dst, n);
3085 break;
3086
3087 case MESA_FORMAT_ALPHA_UINT16:
3088 unpack_int_rgba_ALPHA_UINT16(src, dst, n);
3089 break;
3090 case MESA_FORMAT_ALPHA_INT16:
3091 unpack_int_rgba_ALPHA_INT16(src, dst, n);
3092 break;
3093
3094 case MESA_FORMAT_ALPHA_UINT8:
3095 unpack_int_rgba_ALPHA_UINT8(src, dst, n);
3096 break;
3097 case MESA_FORMAT_ALPHA_INT8:
3098 unpack_int_rgba_ALPHA_INT8(src, dst, n);
3099 break;
3100
3101 case MESA_FORMAT_LUMINANCE_UINT32:
3102 case MESA_FORMAT_LUMINANCE_INT32:
3103 unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
3104 break;
3105 case MESA_FORMAT_LUMINANCE_UINT16:
3106 unpack_int_rgba_LUMINANCE_UINT16(src, dst, n);
3107 break;
3108 case MESA_FORMAT_LUMINANCE_INT16:
3109 unpack_int_rgba_LUMINANCE_INT16(src, dst, n);
3110 break;
3111
3112 case MESA_FORMAT_LUMINANCE_UINT8:
3113 unpack_int_rgba_LUMINANCE_UINT8(src, dst, n);
3114 break;
3115 case MESA_FORMAT_LUMINANCE_INT8:
3116 unpack_int_rgba_LUMINANCE_INT8(src, dst, n);
3117 break;
3118
3119 case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
3120 case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
3121 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
3122 break;
3123
3124 case MESA_FORMAT_LUMINANCE_ALPHA_UINT16:
3125 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src, dst, n);
3126 break;
3127 case MESA_FORMAT_LUMINANCE_ALPHA_INT16:
3128 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src, dst, n);
3129 break;
3130
3131 case MESA_FORMAT_LUMINANCE_ALPHA_UINT8:
3132 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src, dst, n);
3133 break;
3134 case MESA_FORMAT_LUMINANCE_ALPHA_INT8:
3135 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src, dst, n);
3136 break;
3137
3138 case MESA_FORMAT_INTENSITY_UINT32:
3139 case MESA_FORMAT_INTENSITY_INT32:
3140 unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
3141 break;
3142
3143 case MESA_FORMAT_INTENSITY_UINT16:
3144 unpack_int_rgba_INTENSITY_UINT16(src, dst, n);
3145 break;
3146 case MESA_FORMAT_INTENSITY_INT16:
3147 unpack_int_rgba_INTENSITY_INT16(src, dst, n);
3148 break;
3149
3150 case MESA_FORMAT_INTENSITY_UINT8:
3151 unpack_int_rgba_INTENSITY_UINT8(src, dst, n);
3152 break;
3153 case MESA_FORMAT_INTENSITY_INT8:
3154 unpack_int_rgba_INTENSITY_INT8(src, dst, n);
3155 break;
3156
3157 case MESA_FORMAT_ARGB2101010_UINT:
3158 unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
3159 break;
3160
3161 case MESA_FORMAT_ABGR2101010_UINT:
3162 unpack_int_rgba_ABGR2101010_UINT(src, dst, n);
3163 break;
3164
3165 case MESA_FORMAT_ARGB2101010:
3166 unpack_int_rgba_ARGB2101010(src, dst, n);
3167 break;
3168
3169 case MESA_FORMAT_XBGR8888_UINT:
3170 unpack_int_rgba_XBGR8888_UINT(src, dst, n);
3171 break;
3172
3173 case MESA_FORMAT_XBGR8888_SINT:
3174 unpack_int_rgba_XBGR8888_SINT(src, dst, n);
3175 break;
3176
3177 case MESA_FORMAT_XBGR16161616_UINT:
3178 unpack_int_rgba_XBGR16161616_UINT(src, dst, n);
3179 break;
3180
3181 case MESA_FORMAT_XBGR16161616_SINT:
3182 unpack_int_rgba_XBGR16161616_SINT(src, dst, n);
3183 break;
3184
3185 case MESA_FORMAT_XBGR32323232_UINT:
3186 case MESA_FORMAT_XBGR32323232_SINT:
3187 unpack_int_rgba_XBGR32323232_UINT(src, dst, n);
3188 break;
3189
3190 default:
3191 _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
3192 _mesa_get_format_name(format));
3193 return;
3194 }
3195 }
3196
3197 /**
3198 * Unpack a 2D rect of pixels returning float RGBA colors.
3199 * \param format the source image format
3200 * \param src start address of the source image
3201 * \param srcRowStride source image row stride in bytes
3202 * \param dst start address of the dest image
3203 * \param dstRowStride dest image row stride in bytes
3204 * \param x source image start X pos
3205 * \param y source image start Y pos
3206 * \param width width of rect region to convert
3207 * \param height height of rect region to convert
3208 */
3209 void
3210 _mesa_unpack_rgba_block(gl_format format,
3211 const void *src, GLint srcRowStride,
3212 GLfloat dst[][4], GLint dstRowStride,
3213 GLuint x, GLuint y, GLuint width, GLuint height)
3214 {
3215 unpack_rgba_func unpack = get_unpack_rgba_function(format);
3216 const GLuint srcPixStride = _mesa_get_format_bytes(format);
3217 const GLuint dstPixStride = 4 * sizeof(GLfloat);
3218 const GLubyte *srcRow;
3219 GLubyte *dstRow;
3220 GLuint i;
3221
3222 /* XXX needs to be fixed for compressed formats */
3223
3224 srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
3225 dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
3226
3227 for (i = 0; i < height; i++) {
3228 unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
3229
3230 dstRow += dstRowStride;
3231 srcRow += srcRowStride;
3232 }
3233 }
3234
3235
3236
3237
3238 typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
3239
3240 static void
3241 unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
3242 {
3243 /* only return Z, not stencil data */
3244 const GLuint *s = ((const GLuint *) src);
3245 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
3246 GLuint i;
3247 for (i = 0; i < n; i++) {
3248 dst[i] = (GLfloat) ((s[i] >> 8) * scale);
3249 ASSERT(dst[i] >= 0.0F);
3250 ASSERT(dst[i] <= 1.0F);
3251 }
3252 }
3253
3254 static void
3255 unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
3256 {
3257 /* only return Z, not stencil data */
3258 const GLuint *s = ((const GLuint *) src);
3259 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
3260 GLuint i;
3261 for (i = 0; i < n; i++) {
3262 dst[i] = (GLfloat) ((s[i] & 0x00ffffff) * scale);
3263 ASSERT(dst[i] >= 0.0F);
3264 ASSERT(dst[i] <= 1.0F);
3265 }
3266 }
3267
3268 static void
3269 unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst)
3270 {
3271 const GLushort *s = ((const GLushort *) src);
3272 GLuint i;
3273 for (i = 0; i < n; i++) {
3274 dst[i] = s[i] * (1.0F / 65535.0F);
3275 }
3276 }
3277
3278 static void
3279 unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst)
3280 {
3281 const GLuint *s = ((const GLuint *) src);
3282 GLuint i;
3283 for (i = 0; i < n; i++) {
3284 dst[i] = s[i] * (1.0F / 0xffffffff);
3285 }
3286 }
3287
3288 static void
3289 unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst)
3290 {
3291 memcpy(dst, src, n * sizeof(float));
3292 }
3293
3294 static void
3295 unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
3296 {
3297 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
3298 GLuint i;
3299 for (i = 0; i < n; i++) {
3300 dst[i] = s[i].z;
3301 }
3302 }
3303
3304
3305
3306 /**
3307 * Unpack Z values.
3308 * The returned values will always be in the range [0.0, 1.0].
3309 */
3310 void
3311 _mesa_unpack_float_z_row(gl_format format, GLuint n,
3312 const void *src, GLfloat *dst)
3313 {
3314 unpack_float_z_func unpack;
3315
3316 switch (format) {
3317 case MESA_FORMAT_Z24_S8:
3318 case MESA_FORMAT_Z24_X8:
3319 unpack = unpack_float_z_Z24_X8;
3320 break;
3321 case MESA_FORMAT_S8_Z24:
3322 case MESA_FORMAT_X8_Z24:
3323 unpack = unpack_float_z_X8_Z24;
3324 break;
3325 case MESA_FORMAT_Z16:
3326 unpack = unpack_float_z_Z16;
3327 break;
3328 case MESA_FORMAT_Z32:
3329 unpack = unpack_float_z_Z32;
3330 break;
3331 case MESA_FORMAT_Z32_FLOAT:
3332 unpack = unpack_float_z_Z32F;
3333 break;
3334 case MESA_FORMAT_Z32_FLOAT_X24S8:
3335 unpack = unpack_float_z_Z32X24S8;
3336 break;
3337 default:
3338 _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
3339 _mesa_get_format_name(format));
3340 return;
3341 }
3342
3343 unpack(n, src, dst);
3344 }
3345
3346
3347
3348 typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
3349
3350 static void
3351 unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
3352 {
3353 /* only return Z, not stencil data */
3354 const GLuint *s = ((const GLuint *) src);
3355 GLuint i;
3356 for (i = 0; i < n; i++) {
3357 dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
3358 }
3359 }
3360
3361 static void
3362 unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
3363 {
3364 /* only return Z, not stencil data */
3365 const GLuint *s = ((const GLuint *) src);
3366 GLuint i;
3367 for (i = 0; i < n; i++) {
3368 dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
3369 }
3370 }
3371
3372 static void
3373 unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n)
3374 {
3375 const GLushort *s = ((const GLushort *)src);
3376 GLuint i;
3377 for (i = 0; i < n; i++) {
3378 dst[i] = (s[i] << 16) | s[i];
3379 }
3380 }
3381
3382 static void
3383 unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
3384 {
3385 memcpy(dst, src, n * sizeof(GLuint));
3386 }
3387
3388 static void
3389 unpack_uint_z_Z32_FLOAT(const void *src, GLuint *dst, GLuint n)
3390 {
3391 const float *s = (const float *)src;
3392 GLuint i;
3393 for (i = 0; i < n; i++) {
3394 dst[i] = FLOAT_TO_UINT(CLAMP(s[i], 0.0F, 1.0F));
3395 }
3396 }
3397
3398 static void
3399 unpack_uint_z_Z32_FLOAT_X24S8(const void *src, GLuint *dst, GLuint n)
3400 {
3401 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
3402 GLuint i;
3403
3404 for (i = 0; i < n; i++) {
3405 dst[i] = FLOAT_TO_UINT(CLAMP(s[i].z, 0.0F, 1.0F));
3406 }
3407 }
3408
3409
3410 /**
3411 * Unpack Z values.
3412 * The returned values will always be in the range [0, 0xffffffff].
3413 */
3414 void
3415 _mesa_unpack_uint_z_row(gl_format format, GLuint n,
3416 const void *src, GLuint *dst)
3417 {
3418 unpack_uint_z_func unpack;
3419 const GLubyte *srcPtr = (GLubyte *) src;
3420
3421 switch (format) {
3422 case MESA_FORMAT_Z24_S8:
3423 case MESA_FORMAT_Z24_X8:
3424 unpack = unpack_uint_z_Z24_X8;
3425 break;
3426 case MESA_FORMAT_S8_Z24:
3427 case MESA_FORMAT_X8_Z24:
3428 unpack = unpack_uint_z_X8_Z24;
3429 break;
3430 case MESA_FORMAT_Z16:
3431 unpack = unpack_uint_z_Z16;
3432 break;
3433 case MESA_FORMAT_Z32:
3434 unpack = unpack_uint_z_Z32;
3435 break;
3436 case MESA_FORMAT_Z32_FLOAT:
3437 unpack = unpack_uint_z_Z32_FLOAT;
3438 break;
3439 case MESA_FORMAT_Z32_FLOAT_X24S8:
3440 unpack = unpack_uint_z_Z32_FLOAT_X24S8;
3441 break;
3442 default:
3443 _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
3444 _mesa_get_format_name(format));
3445 return;
3446 }
3447
3448 unpack(srcPtr, dst, n);
3449 }
3450
3451
3452 static void
3453 unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
3454 {
3455 memcpy(dst, src, n);
3456 }
3457
3458 static void
3459 unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n)
3460 {
3461 GLuint i;
3462 const GLuint *src32 = src;
3463
3464 for (i = 0; i < n; i++)
3465 dst[i] = src32[i] & 0xff;
3466 }
3467
3468 static void
3469 unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n)
3470 {
3471 GLuint i;
3472 const GLuint *src32 = src;
3473
3474 for (i = 0; i < n; i++)
3475 dst[i] = src32[i] >> 24;
3476 }
3477
3478 static void
3479 unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n)
3480 {
3481 GLuint i;
3482 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
3483
3484 for (i = 0; i < n; i++)
3485 dst[i] = s[i].x24s8 & 0xff;
3486 }
3487
3488 void
3489 _mesa_unpack_ubyte_stencil_row(gl_format format, GLuint n,
3490 const void *src, GLubyte *dst)
3491 {
3492 switch (format) {
3493 case MESA_FORMAT_S8:
3494 unpack_ubyte_s_S8(src, dst, n);
3495 break;
3496 case MESA_FORMAT_Z24_S8:
3497 unpack_ubyte_s_Z24_S8(src, dst, n);
3498 break;
3499 case MESA_FORMAT_S8_Z24:
3500 unpack_ubyte_s_S8_Z24(src, dst, n);
3501 break;
3502 case MESA_FORMAT_Z32_FLOAT_X24S8:
3503 unpack_ubyte_s_Z32_FLOAT_X24S8(src, dst, n);
3504 break;
3505 default:
3506 _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
3507 _mesa_get_format_name(format));
3508 return;
3509 }
3510 }
3511
3512 static void
3513 unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint *src, GLuint *dst, GLuint n)
3514 {
3515 GLuint i;
3516
3517 for (i = 0; i < n; i++) {
3518 GLuint val = src[i];
3519 dst[i] = val >> 24 | val << 8;
3520 }
3521 }
3522
3523 static void
3524 unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint *src, GLuint *dst, GLuint n)
3525 {
3526 memcpy(dst, src, n * 4);
3527 }
3528
3529 void
3530 _mesa_unpack_uint_24_8_depth_stencil_row(gl_format format, GLuint n,
3531 const void *src, GLuint *dst)
3532 {
3533 switch (format) {
3534 case MESA_FORMAT_Z24_S8:
3535 unpack_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
3536 break;
3537 case MESA_FORMAT_S8_Z24:
3538 unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
3539 break;
3540 default:
3541 _mesa_problem(NULL,
3542 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
3543 _mesa_get_format_name(format));
3544 return;
3545 }
3546 }