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