mesa: Add MESA_FORMAT_A8L8_{SNORM,SRGB}
[mesa.git] / src / mesa / main / format_unpack.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (c) 2011 VMware, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include "colormac.h"
27 #include "format_unpack.h"
28 #include "macros.h"
29 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
30 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
31 #include "util/format_srgb.h"
32
33
34 /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
35 struct z32f_x24s8
36 {
37 float z;
38 uint32_t x24s8;
39 };
40
41
42 /* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
43
44 #define EXPAND_1_8(X) ( (X) ? 0xff : 0x0 )
45
46 #define EXPAND_2_8(X) ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
47
48 #define EXPAND_3_8(X) ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
49
50 #define EXPAND_4_8(X) ( ((X) << 4) | (X) )
51
52 #define EXPAND_5_8(X) ( ((X) << 3) | ((X) >> 2) )
53
54 #define EXPAND_6_8(X) ( ((X) << 2) | ((X) >> 4) )
55
56
57 /**********************************************************************/
58 /* Unpack, returning GLfloat colors */
59 /**********************************************************************/
60
61 typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);
62
63
64 static void
65 unpack_A8B8G8R8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
66 {
67 const GLuint *s = ((const GLuint *) src);
68 GLuint i;
69 for (i = 0; i < n; i++) {
70 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
71 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
72 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
73 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
74 }
75 }
76
77 static void
78 unpack_R8G8B8A8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
79 {
80 const GLuint *s = ((const GLuint *) src);
81 GLuint i;
82 for (i = 0; i < n; i++) {
83 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
84 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
85 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
86 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
87 }
88 }
89
90 static void
91 unpack_B8G8R8A8_UNORM(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] >> 16) & 0xff );
97 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
98 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
99 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
100 }
101 }
102
103 static void
104 unpack_A8R8G8B8_UNORM(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] >> 8) & 0xff );
110 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
111 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
112 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
113 }
114 }
115
116 static void
117 unpack_RGBX8888(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] >> 24) );
123 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
124 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
125 dst[i][ACOMP] = 1.0f;
126 }
127 }
128
129 static void
130 unpack_RGBX8888_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] ) & 0xff );
136 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
137 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
138 dst[i][ACOMP] = 1.0f;
139 }
140 }
141
142 static void
143 unpack_B8G8R8X8_UNORM(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] >> 16) & 0xff );
149 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
150 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
151 dst[i][ACOMP] = 1.0f;
152 }
153 }
154
155 static void
156 unpack_X8R8G8B8_UNORM(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] >> 8) & 0xff );
162 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
163 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
164 dst[i][ACOMP] = 1.0f;
165 }
166 }
167
168 static void
169 unpack_BGR_UNORM8(const void *src, GLfloat dst[][4], GLuint n)
170 {
171 const GLubyte *s = (const GLubyte *) src;
172 GLuint i;
173 for (i = 0; i < n; i++) {
174 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
175 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
176 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
177 dst[i][ACOMP] = 1.0F;
178 }
179 }
180
181 static void
182 unpack_RGB_UNORM8(const void *src, GLfloat dst[][4], GLuint n)
183 {
184 const GLubyte *s = (const GLubyte *) src;
185 GLuint i;
186 for (i = 0; i < n; i++) {
187 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
188 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
189 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
190 dst[i][ACOMP] = 1.0F;
191 }
192 }
193
194 static void
195 unpack_B5G6R5_UNORM(const void *src, GLfloat dst[][4], GLuint n)
196 {
197 const GLushort *s = ((const GLushort *) src);
198 GLuint i;
199 for (i = 0; i < n; i++) {
200 dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
201 dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F);
202 dst[i][BCOMP] = ((s[i] ) & 0x1f) * (1.0F / 31.0F);
203 dst[i][ACOMP] = 1.0F;
204 }
205 }
206
207 static void
208 unpack_R5G6B5_UNORM(const void *src, GLfloat dst[][4], GLuint n)
209 {
210 /* Warning: this function does not match the current Mesa definition
211 * of MESA_FORMAT_R5G6B5_UNORM.
212 */
213 const GLushort *s = ((const GLushort *) src);
214 GLuint i;
215 for (i = 0; i < n; i++) {
216 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
217 dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) );
218 dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >> 9) & 0x3) );
219 dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >> 2) & 0x7) );
220 dst[i][ACOMP] = 1.0F;
221 }
222 }
223
224 static void
225 unpack_B4G4R4A4_UNORM(const void *src, GLfloat dst[][4], GLuint n)
226 {
227 const GLushort *s = ((const GLushort *) src);
228 GLuint i;
229 for (i = 0; i < n; i++) {
230 dst[i][RCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
231 dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
232 dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
233 dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
234 }
235 }
236
237 static void
238 unpack_A4R4G4B4_UNORM(const void *src, GLfloat dst[][4], GLuint n)
239 {
240 const GLushort *s = ((const GLushort *) src);
241 GLuint i;
242 for (i = 0; i < n; i++) {
243 dst[i][RCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
244 dst[i][GCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
245 dst[i][BCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
246 dst[i][ACOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
247 }
248 }
249
250 static void
251 unpack_A1B5G5R5_UNORM(const void *src, GLfloat dst[][4], GLuint n)
252 {
253 const GLushort *s = ((const GLushort *) src);
254 GLuint i;
255 for (i = 0; i < n; i++) {
256 dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
257 dst[i][GCOMP] = ((s[i] >> 6) & 0x1f) * (1.0F / 31.0F);
258 dst[i][BCOMP] = ((s[i] >> 1) & 0x1f) * (1.0F / 31.0F);
259 dst[i][ACOMP] = ((s[i] ) & 0x01) * 1.0F;
260 }
261 }
262
263 static void
264 unpack_B5G5R5A1_UNORM(const void *src, GLfloat dst[][4], GLuint n)
265 {
266 const GLushort *s = ((const GLushort *) src);
267 GLuint i;
268 for (i = 0; i < n; i++) {
269 dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
270 dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F);
271 dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F);
272 dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F;
273 }
274 }
275
276 static void
277 unpack_A1R5G5B5_UNORM(const void *src, GLfloat dst[][4], GLuint n)
278 {
279 /* Warning: this function does not match the current Mesa definition
280 * of MESA_FORMAT_A1R5G5B5_UNORM.
281 */
282 const GLushort *s = ((const GLushort *) src);
283 GLuint i;
284 for (i = 0; i < n; i++) {
285 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
286 dst[i][RCOMP] = ((tmp >> 10) & 0x1f) * (1.0F / 31.0F);
287 dst[i][GCOMP] = ((tmp >> 5) & 0x1f) * (1.0F / 31.0F);
288 dst[i][BCOMP] = ((tmp >> 0) & 0x1f) * (1.0F / 31.0F);
289 dst[i][ACOMP] = ((tmp >> 15) & 0x01) * 1.0F;
290 }
291 }
292
293 static void
294 unpack_L4A4_UNORM(const void *src, GLfloat dst[][4], GLuint n)
295 {
296 const GLubyte *s = ((const GLubyte *) src);
297 GLuint i;
298 for (i = 0; i < n; i++) {
299 dst[i][RCOMP] =
300 dst[i][GCOMP] =
301 dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
302 dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
303 }
304 }
305
306 static void
307 unpack_L8A8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
308 {
309 const GLushort *s = ((const GLushort *) src);
310 GLuint i;
311 for (i = 0; i < n; i++) {
312 dst[i][RCOMP] =
313 dst[i][GCOMP] =
314 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
315 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
316 }
317 }
318
319 static void
320 unpack_A8L8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
321 {
322 const GLushort *s = ((const GLushort *) src);
323 GLuint i;
324 for (i = 0; i < n; i++) {
325 dst[i][RCOMP] =
326 dst[i][GCOMP] =
327 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
328 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
329 }
330 }
331
332 static void
333 unpack_L16A16_UNORM(const void *src, GLfloat dst[][4], GLuint n)
334 {
335 const GLuint *s = ((const GLuint *) src);
336 GLuint i;
337 for (i = 0; i < n; i++) {
338 dst[i][RCOMP] =
339 dst[i][GCOMP] =
340 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
341 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
342 }
343 }
344
345 static void
346 unpack_A16L16_UNORM(const void *src, GLfloat dst[][4], GLuint n)
347 {
348 const GLuint *s = ((const GLuint *) src);
349 GLuint i;
350 for (i = 0; i < n; i++) {
351 dst[i][RCOMP] =
352 dst[i][GCOMP] =
353 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
354 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
355 }
356 }
357
358 static void
359 unpack_B2G3R3_UNORM(const void *src, GLfloat dst[][4], GLuint n)
360 {
361 const GLubyte *s = ((const GLubyte *) src);
362 GLuint i;
363 for (i = 0; i < n; i++) {
364 dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F);
365 dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F);
366 dst[i][BCOMP] = ((s[i] ) & 0x3) * (1.0F / 3.0F);
367 dst[i][ACOMP] = 1.0F;
368 }
369 }
370
371
372 static void
373 unpack_A_UNORM8(const void *src, GLfloat dst[][4], GLuint n)
374 {
375 const GLubyte *s = ((const GLubyte *) src);
376 GLuint i;
377 for (i = 0; i < n; i++) {
378 dst[i][RCOMP] =
379 dst[i][GCOMP] =
380 dst[i][BCOMP] = 0.0F;
381 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
382 }
383 }
384
385 static void
386 unpack_A_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
387 {
388 const GLushort *s = ((const GLushort *) src);
389 GLuint i;
390 for (i = 0; i < n; i++) {
391 dst[i][RCOMP] =
392 dst[i][GCOMP] =
393 dst[i][BCOMP] = 0.0F;
394 dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
395 }
396 }
397
398 static void
399 unpack_L_UNORM8(const void *src, GLfloat dst[][4], GLuint n)
400 {
401 const GLubyte *s = ((const GLubyte *) src);
402 GLuint i;
403 for (i = 0; i < n; i++) {
404 dst[i][RCOMP] =
405 dst[i][GCOMP] =
406 dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
407 dst[i][ACOMP] = 1.0F;
408 }
409 }
410
411 static void
412 unpack_L_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
413 {
414 const GLushort *s = ((const GLushort *) src);
415 GLuint i;
416 for (i = 0; i < n; i++) {
417 dst[i][RCOMP] =
418 dst[i][GCOMP] =
419 dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
420 dst[i][ACOMP] = 1.0F;
421 }
422 }
423
424 static void
425 unpack_I_UNORM8(const void *src, GLfloat dst[][4], GLuint n)
426 {
427 const GLubyte *s = ((const GLubyte *) src);
428 GLuint i;
429 for (i = 0; i < n; i++) {
430 dst[i][RCOMP] =
431 dst[i][GCOMP] =
432 dst[i][BCOMP] =
433 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
434 }
435 }
436
437 static void
438 unpack_I_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
439 {
440 const GLushort *s = ((const GLushort *) src);
441 GLuint i;
442 for (i = 0; i < n; i++) {
443 dst[i][RCOMP] =
444 dst[i][GCOMP] =
445 dst[i][BCOMP] =
446 dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
447 }
448 }
449
450 static void
451 unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n)
452 {
453 GLuint i;
454 for (i = 0; i < n; i++) {
455 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
456 const GLushort *src1 = src0 + 1; /* odd */
457 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
458 const GLubyte cb = *src0 & 0xff; /* chroma U */
459 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
460 const GLubyte cr = *src1 & 0xff; /* chroma V */
461 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
462 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
463 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
464 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
465 r *= (1.0F / 255.0F);
466 g *= (1.0F / 255.0F);
467 b *= (1.0F / 255.0F);
468 dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
469 dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
470 dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
471 dst[i][ACOMP] = 1.0F;
472 }
473 }
474
475 static void
476 unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
477 {
478 GLuint i;
479 for (i = 0; i < n; i++) {
480 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
481 const GLushort *src1 = src0 + 1; /* odd */
482 const GLubyte y0 = *src0 & 0xff; /* luminance */
483 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
484 const GLubyte y1 = *src1 & 0xff; /* luminance */
485 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
486 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
487 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
488 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
489 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
490 r *= (1.0F / 255.0F);
491 g *= (1.0F / 255.0F);
492 b *= (1.0F / 255.0F);
493 dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
494 dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
495 dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
496 dst[i][ACOMP] = 1.0F;
497 }
498 }
499
500 static void
501 unpack_R_UNORM8(const void *src, GLfloat dst[][4], GLuint n)
502 {
503 const GLubyte *s = ((const GLubyte *) src);
504 GLuint i;
505 for (i = 0; i < n; i++) {
506 dst[i][0] = UBYTE_TO_FLOAT(s[i]);
507 dst[i][1] =
508 dst[i][2] = 0.0F;
509 dst[i][3] = 1.0F;
510 }
511 }
512
513 static void
514 unpack_R8G8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
515 {
516 const GLushort *s = ((const GLushort *) src);
517 GLuint i;
518 for (i = 0; i < n; i++) {
519 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
520 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
521 dst[i][BCOMP] = 0.0;
522 dst[i][ACOMP] = 1.0;
523 }
524 }
525
526 static void
527 unpack_G8R8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
528 {
529 const GLushort *s = ((const GLushort *) src);
530 GLuint i;
531 for (i = 0; i < n; i++) {
532 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
533 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
534 dst[i][BCOMP] = 0.0;
535 dst[i][ACOMP] = 1.0;
536 }
537 }
538
539 static void
540 unpack_R_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
541 {
542 const GLushort *s = ((const GLushort *) src);
543 GLuint i;
544 for (i = 0; i < n; i++) {
545 dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]);
546 dst[i][GCOMP] = 0.0;
547 dst[i][BCOMP] = 0.0;
548 dst[i][ACOMP] = 1.0;
549 }
550 }
551
552 static void
553 unpack_R16G16_UNORM(const void *src, GLfloat dst[][4], GLuint n)
554 {
555 const GLuint *s = ((const GLuint *) src);
556 GLuint i;
557 for (i = 0; i < n; i++) {
558 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
559 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
560 dst[i][BCOMP] = 0.0;
561 dst[i][ACOMP] = 1.0;
562 }
563 }
564
565 static void
566 unpack_G16R16_UNORM(const void *src, GLfloat dst[][4], GLuint n)
567 {
568 const GLuint *s = ((const GLuint *) src);
569 GLuint i;
570 for (i = 0; i < n; i++) {
571 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
572 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
573 dst[i][BCOMP] = 0.0;
574 dst[i][ACOMP] = 1.0;
575 }
576 }
577
578 static void
579 unpack_B10G10R10A2_UNORM(const void *src, GLfloat dst[][4], GLuint n)
580 {
581 const GLuint *s = ((const GLuint *) src);
582 GLuint i;
583 for (i = 0; i < n; i++) {
584 dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
585 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
586 dst[i][BCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
587 dst[i][ACOMP] = ((s[i] >> 30) & 0x03) * (1.0F / 3.0F);
588 }
589 }
590
591
592 static void
593 unpack_B10G10R10A2_UINT(const void *src, GLfloat dst[][4], GLuint n)
594 {
595 const GLuint *s = (const GLuint *) src;
596 GLuint i;
597 for (i = 0; i < n; i++) {
598 dst[i][RCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff);
599 dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff);
600 dst[i][BCOMP] = (GLfloat)((s[i] >> 0) & 0x3ff);
601 dst[i][ACOMP] = (GLfloat)((s[i] >> 30) & 0x03);
602 }
603 }
604
605
606 static void
607 unpack_R10G10B10A2_UINT(const void *src, GLfloat dst[][4], GLuint n)
608 {
609 const GLuint *s = ((const GLuint *) src);
610 GLuint i;
611 for (i = 0; i < n; i++) {
612 dst[i][RCOMP] = (GLfloat)((s[i] >> 0) & 0x3ff);
613 dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff);
614 dst[i][BCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff);
615 dst[i][ACOMP] = (GLfloat)((s[i] >> 30) & 0x03);
616 }
617 }
618
619
620 static void
621 unpack_S8_UINT_Z24_UNORM(const void *src, GLfloat dst[][4], GLuint n)
622 {
623 /* only return Z, not stencil data */
624 const GLuint *s = ((const GLuint *) src);
625 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
626 GLuint i;
627 for (i = 0; i < n; i++) {
628 dst[i][0] =
629 dst[i][1] =
630 dst[i][2] = (GLfloat) ((s[i] >> 8) * scale);
631 dst[i][3] = 1.0F;
632 ASSERT(dst[i][0] >= 0.0F);
633 ASSERT(dst[i][0] <= 1.0F);
634 }
635 }
636
637 static void
638 unpack_Z24_UNORM_S8_UINT(const void *src, GLfloat dst[][4], GLuint n)
639 {
640 /* only return Z, not stencil data */
641 const GLuint *s = ((const GLuint *) src);
642 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
643 GLuint i;
644 for (i = 0; i < n; i++) {
645 dst[i][0] =
646 dst[i][1] =
647 dst[i][2] = (float) ((s[i] & 0x00ffffff) * scale);
648 dst[i][3] = 1.0F;
649 ASSERT(dst[i][0] >= 0.0F);
650 ASSERT(dst[i][0] <= 1.0F);
651 }
652 }
653
654 static void
655 unpack_Z_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
656 {
657 const GLushort *s = ((const GLushort *) src);
658 GLuint i;
659 for (i = 0; i < n; i++) {
660 dst[i][0] =
661 dst[i][1] =
662 dst[i][2] = s[i] * (1.0F / 65535.0F);
663 dst[i][3] = 1.0F;
664 }
665 }
666
667 static void
668 unpack_Z24_UNORM_X8_UINT(const void *src, GLfloat dst[][4], GLuint n)
669 {
670 unpack_Z24_UNORM_S8_UINT(src, dst, n);
671 }
672
673 static void
674 unpack_X8_UINT_Z24_UNORM(const void *src, GLfloat dst[][4], GLuint n)
675 {
676 unpack_S8_UINT_Z24_UNORM(src, dst, n);
677 }
678
679 static void
680 unpack_Z_UNORM32(const void *src, GLfloat dst[][4], GLuint n)
681 {
682 const GLuint *s = ((const GLuint *) src);
683 GLuint i;
684 for (i = 0; i < n; i++) {
685 dst[i][0] =
686 dst[i][1] =
687 dst[i][2] = s[i] * (1.0F / 0xffffffff);
688 dst[i][3] = 1.0F;
689 }
690 }
691
692 static void
693 unpack_Z32_FLOAT_S8X24_UINT(const void *src, GLfloat dst[][4], GLuint n)
694 {
695 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
696 GLuint i;
697 for (i = 0; i < n; i++) {
698 dst[i][0] =
699 dst[i][1] =
700 dst[i][2] = s[i].z;
701 dst[i][3] = 1.0F;
702 }
703 }
704
705 static void
706 unpack_Z_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
707 {
708 const GLfloat *s = ((const GLfloat *) src);
709 GLuint i;
710 for (i = 0; i < n; i++) {
711 dst[i][0] =
712 dst[i][1] =
713 dst[i][2] = s[i];
714 dst[i][3] = 1.0F;
715 }
716 }
717
718
719 static void
720 unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
721 {
722 /* should never be used */
723 GLuint i;
724 for (i = 0; i < n; i++) {
725 dst[i][0] =
726 dst[i][1] =
727 dst[i][2] = 0.0F;
728 dst[i][3] = 1.0F;
729 }
730 }
731
732
733 static void
734 unpack_BGR_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
735 {
736 const GLubyte *s = (const GLubyte *) src;
737 GLuint i;
738 for (i = 0; i < n; i++) {
739 dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float(s[i*3+2]);
740 dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float(s[i*3+1]);
741 dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i*3+0]);
742 dst[i][ACOMP] = 1.0F;
743 }
744 }
745
746 static void
747 unpack_A8B8G8R8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
748 {
749 const GLuint *s = ((const GLuint *) src);
750 GLuint i;
751 for (i = 0; i < n; i++) {
752 dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 24) );
753 dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
754 dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff );
755 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
756 }
757 }
758
759 static void
760 unpack_B8G8R8A8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
761 {
762 const GLuint *s = ((const GLuint *) src);
763 GLuint i;
764 for (i = 0; i < n; i++) {
765 dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
766 dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff );
767 dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff );
768 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
769 }
770 }
771
772 static void
773 unpack_R8G8B8A8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
774 {
775 const GLuint *s = ((const GLuint *) src);
776 GLuint i;
777 for (i = 0; i < n; i++) {
778 dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff );
779 dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff );
780 dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
781 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
782 }
783 }
784
785 static void
786 unpack_L_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
787 {
788 const GLubyte *s = ((const GLubyte *) src);
789 GLuint i;
790 for (i = 0; i < n; i++) {
791 dst[i][RCOMP] =
792 dst[i][GCOMP] =
793 dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i]);
794 dst[i][ACOMP] = 1.0F;
795 }
796 }
797
798 static void
799 unpack_L8A8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
800 {
801 const GLushort *s = (const GLushort *) src;
802 GLuint i;
803 for (i = 0; i < n; i++) {
804 dst[i][RCOMP] =
805 dst[i][GCOMP] =
806 dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i] & 0xff);
807 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
808 }
809 }
810
811 static void
812 unpack_A8L8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
813 {
814 const GLushort *s = (const GLushort *) src;
815 GLuint i;
816 for (i = 0; i < n; i++) {
817 dst[i][RCOMP] =
818 dst[i][GCOMP] =
819 dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i] >> 8);
820 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] & 0xff); /* linear! */
821 }
822 }
823
824 static void
825 unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
826 {
827 }
828
829 static void
830 unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
831 {
832 }
833
834 static void
835 unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
836 {
837 }
838
839 static void
840 unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
841 {
842 }
843
844 static void
845 unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
846 {
847 }
848
849 static void
850 unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
851 {
852 }
853
854 static void
855 unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
856 {
857 }
858
859 static void
860 unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
861 {
862 }
863
864 static void
865 unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
866 {
867 }
868
869 static void
870 unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
871 {
872 }
873
874
875 static void
876 unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
877 {
878 const GLfloat *s = (const GLfloat *) src;
879 GLuint i;
880 for (i = 0; i < n; i++) {
881 dst[i][RCOMP] = s[i*4+0];
882 dst[i][GCOMP] = s[i*4+1];
883 dst[i][BCOMP] = s[i*4+2];
884 dst[i][ACOMP] = s[i*4+3];
885 }
886 }
887
888 static void
889 unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
890 {
891 const GLhalfARB *s = (const GLhalfARB *) src;
892 GLuint i;
893 for (i = 0; i < n; i++) {
894 dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
895 dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
896 dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
897 dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
898 }
899 }
900
901 static void
902 unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
903 {
904 const GLfloat *s = (const GLfloat *) src;
905 GLuint i;
906 for (i = 0; i < n; i++) {
907 dst[i][RCOMP] = s[i*3+0];
908 dst[i][GCOMP] = s[i*3+1];
909 dst[i][BCOMP] = s[i*3+2];
910 dst[i][ACOMP] = 1.0F;
911 }
912 }
913
914 static void
915 unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
916 {
917 const GLhalfARB *s = (const GLhalfARB *) src;
918 GLuint i;
919 for (i = 0; i < n; i++) {
920 dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]);
921 dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
922 dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
923 dst[i][ACOMP] = 1.0F;
924 }
925 }
926
927 static void
928 unpack_A_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
929 {
930 const GLfloat *s = (const GLfloat *) src;
931 GLuint i;
932 for (i = 0; i < n; i++) {
933 dst[i][RCOMP] =
934 dst[i][GCOMP] =
935 dst[i][BCOMP] = 0.0F;
936 dst[i][ACOMP] = s[i];
937 }
938 }
939
940 static void
941 unpack_A_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
942 {
943 const GLhalfARB *s = (const GLhalfARB *) src;
944 GLuint i;
945 for (i = 0; i < n; i++) {
946 dst[i][RCOMP] =
947 dst[i][GCOMP] =
948 dst[i][BCOMP] = 0.0F;
949 dst[i][ACOMP] = _mesa_half_to_float(s[i]);
950 }
951 }
952
953 static void
954 unpack_L_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
955 {
956 const GLfloat *s = (const GLfloat *) src;
957 GLuint i;
958 for (i = 0; i < n; i++) {
959 dst[i][RCOMP] =
960 dst[i][GCOMP] =
961 dst[i][BCOMP] = s[i];
962 dst[i][ACOMP] = 1.0F;
963 }
964 }
965
966 static void
967 unpack_L_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
968 {
969 const GLhalfARB *s = (const GLhalfARB *) src;
970 GLuint i;
971 for (i = 0; i < n; i++) {
972 dst[i][RCOMP] =
973 dst[i][GCOMP] =
974 dst[i][BCOMP] = _mesa_half_to_float(s[i]);
975 dst[i][ACOMP] = 1.0F;
976 }
977 }
978
979 static void
980 unpack_LA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
981 {
982 const GLfloat *s = (const GLfloat *) src;
983 GLuint i;
984 for (i = 0; i < n; i++) {
985 dst[i][RCOMP] =
986 dst[i][GCOMP] =
987 dst[i][BCOMP] = s[i*2+0];
988 dst[i][ACOMP] = s[i*2+1];
989 }
990 }
991
992 static void
993 unpack_LA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
994 {
995 const GLhalfARB *s = (const GLhalfARB *) src;
996 GLuint i;
997 for (i = 0; i < n; i++) {
998 dst[i][RCOMP] =
999 dst[i][GCOMP] =
1000 dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
1001 dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
1002 }
1003 }
1004
1005 static void
1006 unpack_I_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1007 {
1008 const GLfloat *s = (const GLfloat *) src;
1009 GLuint i;
1010 for (i = 0; i < n; i++) {
1011 dst[i][RCOMP] =
1012 dst[i][GCOMP] =
1013 dst[i][BCOMP] =
1014 dst[i][ACOMP] = s[i];
1015 }
1016 }
1017
1018 static void
1019 unpack_I_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1020 {
1021 const GLhalfARB *s = (const GLhalfARB *) src;
1022 GLuint i;
1023 for (i = 0; i < n; i++) {
1024 dst[i][RCOMP] =
1025 dst[i][GCOMP] =
1026 dst[i][BCOMP] =
1027 dst[i][ACOMP] = _mesa_half_to_float(s[i]);
1028 }
1029 }
1030
1031 static void
1032 unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1033 {
1034 const GLfloat *s = (const GLfloat *) src;
1035 GLuint i;
1036 for (i = 0; i < n; i++) {
1037 dst[i][RCOMP] = s[i];
1038 dst[i][GCOMP] = 0.0F;
1039 dst[i][BCOMP] = 0.0F;
1040 dst[i][ACOMP] = 1.0F;
1041 }
1042 }
1043
1044 static void
1045 unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1046 {
1047 const GLhalfARB *s = (const GLhalfARB *) src;
1048 GLuint i;
1049 for (i = 0; i < n; i++) {
1050 dst[i][RCOMP] = _mesa_half_to_float(s[i]);
1051 dst[i][GCOMP] = 0.0F;
1052 dst[i][BCOMP] = 0.0F;
1053 dst[i][ACOMP] = 1.0F;
1054 }
1055 }
1056
1057 static void
1058 unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1059 {
1060 const GLfloat *s = (const GLfloat *) src;
1061 GLuint i;
1062 for (i = 0; i < n; i++) {
1063 dst[i][RCOMP] = s[i*2+0];
1064 dst[i][GCOMP] = s[i*2+1];
1065 dst[i][BCOMP] = 0.0F;
1066 dst[i][ACOMP] = 1.0F;
1067 }
1068 }
1069
1070 static void
1071 unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1072 {
1073 const GLhalfARB *s = (const GLhalfARB *) src;
1074 GLuint i;
1075 for (i = 0; i < n; i++) {
1076 dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
1077 dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
1078 dst[i][BCOMP] = 0.0F;
1079 dst[i][ACOMP] = 1.0F;
1080 }
1081 }
1082
1083 static void
1084 unpack_ALPHA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1085 {
1086 const GLubyte *s = (const GLubyte *) src;
1087 GLuint i;
1088 for (i = 0; i < n; i++) {
1089 dst[i][RCOMP] =
1090 dst[i][GCOMP] =
1091 dst[i][BCOMP] = 0.0;
1092 dst[i][ACOMP] = (GLfloat) s[i];
1093 }
1094 }
1095
1096 static void
1097 unpack_ALPHA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1098 {
1099 const GLushort *s = (const GLushort *) src;
1100 GLuint i;
1101 for (i = 0; i < n; i++) {
1102 dst[i][RCOMP] =
1103 dst[i][GCOMP] =
1104 dst[i][BCOMP] = 0.0;
1105 dst[i][ACOMP] = (GLfloat) s[i];
1106 }
1107 }
1108
1109 static void
1110 unpack_ALPHA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1111 {
1112 const GLuint *s = (const GLuint *) src;
1113 GLuint i;
1114 for (i = 0; i < n; i++) {
1115 dst[i][RCOMP] =
1116 dst[i][GCOMP] =
1117 dst[i][BCOMP] = 0.0;
1118 dst[i][ACOMP] = (GLfloat) s[i];
1119 }
1120 }
1121
1122 static void
1123 unpack_ALPHA_INT8(const void *src, GLfloat dst[][4], GLuint n)
1124 {
1125 const GLbyte *s = (const GLbyte *) src;
1126 GLuint i;
1127 for (i = 0; i < n; i++) {
1128 dst[i][RCOMP] =
1129 dst[i][GCOMP] =
1130 dst[i][BCOMP] = 0.0;
1131 dst[i][ACOMP] = (GLfloat) s[i];
1132 }
1133 }
1134
1135 static void
1136 unpack_ALPHA_INT16(const void *src, GLfloat dst[][4], GLuint n)
1137 {
1138 const GLshort *s = (const GLshort *) src;
1139 GLuint i;
1140 for (i = 0; i < n; i++) {
1141 dst[i][RCOMP] =
1142 dst[i][GCOMP] =
1143 dst[i][BCOMP] = 0.0;
1144 dst[i][ACOMP] = (GLfloat) s[i];
1145 }
1146 }
1147
1148 static void
1149 unpack_ALPHA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1150 {
1151 const GLint *s = (const GLint *) src;
1152 GLuint i;
1153 for (i = 0; i < n; i++) {
1154 dst[i][RCOMP] =
1155 dst[i][GCOMP] =
1156 dst[i][BCOMP] = 0.0;
1157 dst[i][ACOMP] = (GLfloat) s[i];
1158 }
1159 }
1160
1161 static void
1162 unpack_INTENSITY_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1163 {
1164 const GLubyte *s = (const GLubyte *) src;
1165 GLuint i;
1166 for (i = 0; i < n; i++) {
1167 dst[i][RCOMP] =
1168 dst[i][GCOMP] =
1169 dst[i][BCOMP] =
1170 dst[i][ACOMP] = (GLfloat) s[i];
1171 }
1172 }
1173
1174 static void
1175 unpack_INTENSITY_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1176 {
1177 const GLushort *s = (const GLushort *) src;
1178 GLuint i;
1179 for (i = 0; i < n; i++) {
1180 dst[i][RCOMP] =
1181 dst[i][GCOMP] =
1182 dst[i][BCOMP] =
1183 dst[i][ACOMP] = (GLfloat) s[i];
1184 }
1185 }
1186
1187 static void
1188 unpack_INTENSITY_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1189 {
1190 const GLuint *s = (const GLuint *) src;
1191 GLuint i;
1192 for (i = 0; i < n; i++) {
1193 dst[i][RCOMP] =
1194 dst[i][GCOMP] =
1195 dst[i][BCOMP] =
1196 dst[i][ACOMP] = (GLfloat) s[i];
1197 }
1198 }
1199
1200 static void
1201 unpack_INTENSITY_INT8(const void *src, GLfloat dst[][4], GLuint n)
1202 {
1203 const GLbyte *s = (const GLbyte *) src;
1204 GLuint i;
1205 for (i = 0; i < n; i++) {
1206 dst[i][RCOMP] =
1207 dst[i][GCOMP] =
1208 dst[i][BCOMP] =
1209 dst[i][ACOMP] = (GLfloat) s[i];
1210 }
1211 }
1212
1213 static void
1214 unpack_INTENSITY_INT16(const void *src, GLfloat dst[][4], GLuint n)
1215 {
1216 const GLshort *s = (const GLshort *) src;
1217 GLuint i;
1218 for (i = 0; i < n; i++) {
1219 dst[i][RCOMP] =
1220 dst[i][GCOMP] =
1221 dst[i][BCOMP] =
1222 dst[i][ACOMP] = (GLfloat) s[i];
1223 }
1224 }
1225
1226 static void
1227 unpack_INTENSITY_INT32(const void *src, GLfloat dst[][4], GLuint n)
1228 {
1229 const GLint *s = (const GLint *) src;
1230 GLuint i;
1231 for (i = 0; i < n; i++) {
1232 dst[i][RCOMP] =
1233 dst[i][GCOMP] =
1234 dst[i][BCOMP] =
1235 dst[i][ACOMP] = (GLfloat) s[i];
1236 }
1237 }
1238
1239 static void
1240 unpack_LUMINANCE_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1241 {
1242 const GLubyte *s = (const GLubyte *) src;
1243 GLuint i;
1244 for (i = 0; i < n; i++) {
1245 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1246 dst[i][ACOMP] = 1.0;
1247 }
1248 }
1249
1250 static void
1251 unpack_LUMINANCE_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1252 {
1253 const GLushort *s = (const GLushort *) src;
1254 GLuint i;
1255 for (i = 0; i < n; i++) {
1256 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1257 dst[i][ACOMP] = 1.0;
1258 }
1259 }
1260
1261 static void
1262 unpack_LUMINANCE_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1263 {
1264 const GLuint *s = (const GLuint *) src;
1265 GLuint i;
1266 for (i = 0; i < n; i++) {
1267 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1268 dst[i][ACOMP] = 1.0;
1269 }
1270 }
1271
1272 static void
1273 unpack_LUMINANCE_INT8(const void *src, GLfloat dst[][4], GLuint n)
1274 {
1275 const GLbyte *s = (const GLbyte *) src;
1276 GLuint i;
1277 for (i = 0; i < n; i++) {
1278 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1279 dst[i][ACOMP] = 1.0;
1280 }
1281 }
1282
1283 static void
1284 unpack_LUMINANCE_INT16(const void *src, GLfloat dst[][4], GLuint n)
1285 {
1286 const GLshort *s = (const GLshort *) src;
1287 GLuint i;
1288 for (i = 0; i < n; i++) {
1289 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1290 dst[i][ACOMP] = 1.0;
1291 }
1292 }
1293
1294 static void
1295 unpack_LUMINANCE_INT32(const void *src, GLfloat dst[][4], GLuint n)
1296 {
1297 const GLint *s = (const GLint *) src;
1298 GLuint i;
1299 for (i = 0; i < n; i++) {
1300 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1301 dst[i][ACOMP] = 1.0;
1302 }
1303 }
1304
1305 static void
1306 unpack_LUMINANCE_ALPHA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1307 {
1308 const GLubyte *s = (const GLubyte *) src;
1309 GLuint i;
1310 for (i = 0; i < n; i++) {
1311 dst[i][RCOMP] =
1312 dst[i][GCOMP] =
1313 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1314 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1315 }
1316 }
1317
1318 static void
1319 unpack_LUMINANCE_ALPHA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1320 {
1321 const GLushort *s = (const GLushort *) src;
1322 GLuint i;
1323 for (i = 0; i < n; i++) {
1324 dst[i][RCOMP] =
1325 dst[i][GCOMP] =
1326 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1327 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1328 }
1329 }
1330
1331 static void
1332 unpack_LUMINANCE_ALPHA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1333 {
1334 const GLuint *s = (const GLuint *) src;
1335 GLuint i;
1336 for (i = 0; i < n; i++) {
1337 dst[i][RCOMP] =
1338 dst[i][GCOMP] =
1339 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1340 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1341 }
1342 }
1343
1344 static void
1345 unpack_LUMINANCE_ALPHA_INT8(const void *src, GLfloat dst[][4], GLuint n)
1346 {
1347 const GLbyte *s = (const GLbyte *) src;
1348 GLuint i;
1349 for (i = 0; i < n; i++) {
1350 dst[i][RCOMP] =
1351 dst[i][GCOMP] =
1352 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1353 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1354 }
1355 }
1356
1357 static void
1358 unpack_LUMINANCE_ALPHA_INT16(const void *src, GLfloat dst[][4], GLuint n)
1359 {
1360 const GLshort *s = (const GLshort *) src;
1361 GLuint i;
1362 for (i = 0; i < n; i++) {
1363 dst[i][RCOMP] =
1364 dst[i][GCOMP] =
1365 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1366 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1367 }
1368 }
1369
1370 static void
1371 unpack_LUMINANCE_ALPHA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1372 {
1373 const GLint *s = (const GLint *) src;
1374 GLuint i;
1375 for (i = 0; i < n; i++) {
1376 dst[i][RCOMP] =
1377 dst[i][GCOMP] =
1378 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1379 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1380 }
1381 }
1382
1383 static void
1384 unpack_R_INT8(const void *src, GLfloat dst[][4], GLuint n)
1385 {
1386 const GLbyte *s = (const GLbyte *) src;
1387 GLuint i;
1388 for (i = 0; i < n; i++) {
1389 dst[i][RCOMP] = (GLfloat) s[i];
1390 dst[i][GCOMP] = 0.0;
1391 dst[i][BCOMP] = 0.0;
1392 dst[i][ACOMP] = 1.0;
1393 }
1394 }
1395
1396 static void
1397 unpack_RG_INT8(const void *src, GLfloat dst[][4], GLuint n)
1398 {
1399 const GLbyte *s = (const GLbyte *) src;
1400 GLuint i;
1401 for (i = 0; i < n; i++) {
1402 dst[i][RCOMP] = (GLfloat) s[i*2+0];
1403 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1404 dst[i][BCOMP] = 0.0;
1405 dst[i][ACOMP] = 1.0;
1406 }
1407 }
1408
1409 static void
1410 unpack_RGB_INT8(const void *src, GLfloat dst[][4], GLuint n)
1411 {
1412 const GLbyte *s = (const GLbyte *) src;
1413 GLuint i;
1414 for (i = 0; i < n; i++) {
1415 dst[i][RCOMP] = (GLfloat) s[i*3+0];
1416 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1417 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1418 dst[i][ACOMP] = 1.0;
1419 }
1420 }
1421
1422 static void
1423 unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
1424 {
1425 const GLbyte *s = (const GLbyte *) src;
1426 GLuint i;
1427 for (i = 0; i < n; i++) {
1428 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1429 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1430 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1431 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1432 }
1433 }
1434
1435 static void
1436 unpack_R_INT16(const void *src, GLfloat dst[][4], GLuint n)
1437 {
1438 const GLshort *s = (const GLshort *) src;
1439 GLuint i;
1440 for (i = 0; i < n; i++) {
1441 dst[i][RCOMP] = (GLfloat) s[i];
1442 dst[i][GCOMP] = 0.0;
1443 dst[i][BCOMP] = 0.0;
1444 dst[i][ACOMP] = 1.0;
1445 }
1446 }
1447
1448 static void
1449 unpack_RG_INT16(const void *src, GLfloat dst[][4], GLuint n)
1450 {
1451 const GLshort *s = (const GLshort *) src;
1452 GLuint i;
1453 for (i = 0; i < n; i++) {
1454 dst[i][RCOMP] = (GLfloat) s[i*2+0];
1455 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1456 dst[i][BCOMP] = 0.0;
1457 dst[i][ACOMP] = 1.0;
1458 }
1459 }
1460
1461 static void
1462 unpack_RGB_INT16(const void *src, GLfloat dst[][4], GLuint n)
1463 {
1464 const GLshort *s = (const GLshort *) src;
1465 GLuint i;
1466 for (i = 0; i < n; i++) {
1467 dst[i][RCOMP] = (GLfloat) s[i*3+0];
1468 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1469 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1470 dst[i][ACOMP] = 1.0;
1471 }
1472 }
1473
1474 static void
1475 unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
1476 {
1477 const GLshort *s = (const GLshort *) src;
1478 GLuint i;
1479 for (i = 0; i < n; i++) {
1480 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1481 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1482 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1483 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1484 }
1485 }
1486
1487 static void
1488 unpack_R_INT32(const void *src, GLfloat dst[][4], GLuint n)
1489 {
1490 const GLint *s = (const GLint *) src;
1491 GLuint i;
1492 for (i = 0; i < n; i++) {
1493 dst[i][RCOMP] = (GLfloat) s[i];
1494 dst[i][GCOMP] = 0.0;
1495 dst[i][BCOMP] = 0.0;
1496 dst[i][ACOMP] = 1.0;
1497 }
1498 }
1499
1500 static void
1501 unpack_RG_INT32(const void *src, GLfloat dst[][4], GLuint n)
1502 {
1503 const GLint *s = (const GLint *) src;
1504 GLuint i;
1505 for (i = 0; i < n; i++) {
1506 dst[i][RCOMP] = (GLfloat) s[i*2+0];
1507 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1508 dst[i][BCOMP] = 0.0;
1509 dst[i][ACOMP] = 1.0;
1510 }
1511 }
1512
1513 static void
1514 unpack_RGB_INT32(const void *src, GLfloat dst[][4], GLuint n)
1515 {
1516 const GLint *s = (const GLint *) src;
1517 GLuint i;
1518 for (i = 0; i < n; i++) {
1519 dst[i][RCOMP] = (GLfloat) s[i*3+0];
1520 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1521 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1522 dst[i][ACOMP] = 1.0;
1523 }
1524 }
1525
1526
1527 static void
1528 unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1529 {
1530 const GLint *s = (const GLint *) src;
1531 GLuint i;
1532 for (i = 0; i < n; i++) {
1533 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1534 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1535 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1536 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1537 }
1538 }
1539
1540 static void
1541 unpack_R_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1542 {
1543 const GLubyte *s = (const GLubyte *) src;
1544 GLuint i;
1545 for (i = 0; i < n; i++) {
1546 dst[i][RCOMP] = (GLfloat) s[i];
1547 dst[i][GCOMP] = 0.0;
1548 dst[i][BCOMP] = 0.0;
1549 dst[i][ACOMP] = 1.0;
1550 }
1551 }
1552
1553 static void
1554 unpack_RG_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1555 {
1556 const GLubyte *s = (const GLubyte *) src;
1557 GLuint i;
1558 for (i = 0; i < n; i++) {
1559 dst[i][RCOMP] = (GLfloat) s[i*2+0];
1560 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1561 dst[i][BCOMP] = 0.0;
1562 dst[i][ACOMP] = 1.0;
1563 }
1564 }
1565
1566 static void
1567 unpack_RGB_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1568 {
1569 const GLubyte *s = (const GLubyte *) src;
1570 GLuint i;
1571 for (i = 0; i < n; i++) {
1572 dst[i][RCOMP] = (GLfloat) s[i*3+0];
1573 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1574 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1575 dst[i][ACOMP] = 1.0;
1576 }
1577 }
1578
1579 static void
1580 unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1581 {
1582 const GLubyte *s = (const GLubyte *) src;
1583 GLuint i;
1584 for (i = 0; i < n; i++) {
1585 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1586 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1587 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1588 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1589 }
1590 }
1591
1592 static void
1593 unpack_R_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1594 {
1595 const GLushort *s = (const GLushort *) src;
1596 GLuint i;
1597 for (i = 0; i < n; i++) {
1598 dst[i][RCOMP] = (GLfloat) s[i];
1599 dst[i][GCOMP] = 0.0;
1600 dst[i][BCOMP] = 0.0;
1601 dst[i][ACOMP] = 1.0;
1602 }
1603 }
1604
1605 static void
1606 unpack_RG_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1607 {
1608 const GLushort *s = (const GLushort *) src;
1609 GLuint i;
1610 for (i = 0; i < n; i++) {
1611 dst[i][RCOMP] = (GLfloat) s[i*2+0];
1612 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1613 dst[i][BCOMP] = 0.0;
1614 dst[i][ACOMP] = 1.0;
1615 }
1616 }
1617
1618 static void
1619 unpack_RGB_UINT16(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] = (GLfloat) s[i*3+0];
1625 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1626 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1627 dst[i][ACOMP] = 1.0;
1628 }
1629 }
1630
1631 static void
1632 unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1633 {
1634 const GLushort *s = (const GLushort *) src;
1635 GLuint i;
1636 for (i = 0; i < n; i++) {
1637 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1638 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1639 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1640 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1641 }
1642 }
1643
1644 static void
1645 unpack_R_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1646 {
1647 const GLuint *s = (const GLuint *) src;
1648 GLuint i;
1649 for (i = 0; i < n; i++) {
1650 dst[i][RCOMP] = (GLfloat) s[i];
1651 dst[i][GCOMP] = 0.0;
1652 dst[i][BCOMP] = 0.0;
1653 dst[i][ACOMP] = 1.0;
1654 }
1655 }
1656
1657 static void
1658 unpack_RG_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1659 {
1660 const GLuint *s = (const GLuint *) src;
1661 GLuint i;
1662 for (i = 0; i < n; i++) {
1663 dst[i][RCOMP] = (GLfloat) s[i*2+0];
1664 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1665 dst[i][BCOMP] = 0.0;
1666 dst[i][ACOMP] = 1.0;
1667 }
1668 }
1669
1670 static void
1671 unpack_RGB_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1672 {
1673 const GLuint *s = (const GLuint *) src;
1674 GLuint i;
1675 for (i = 0; i < n; i++) {
1676 dst[i][RCOMP] = (GLfloat) s[i*3+0];
1677 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1678 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1679 dst[i][ACOMP] = 1.0;
1680 }
1681 }
1682
1683 static void
1684 unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1685 {
1686 const GLuint *s = (const GLuint *) src;
1687 GLuint i;
1688 for (i = 0; i < n; i++) {
1689 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1690 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1691 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1692 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1693 }
1694 }
1695
1696 static void
1697 unpack_R_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
1698 {
1699 const GLbyte *s = ((const GLbyte *) src);
1700 GLuint i;
1701 for (i = 0; i < n; i++) {
1702 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1703 dst[i][GCOMP] = 0.0F;
1704 dst[i][BCOMP] = 0.0F;
1705 dst[i][ACOMP] = 1.0F;
1706 }
1707 }
1708
1709 static void
1710 unpack_R8G8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1711 {
1712 const GLushort *s = ((const GLushort *) src);
1713 GLuint i;
1714 for (i = 0; i < n; i++) {
1715 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1716 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1717 dst[i][BCOMP] = 0.0F;
1718 dst[i][ACOMP] = 1.0F;
1719 }
1720 }
1721
1722 static void
1723 unpack_X8B8G8R8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1724 {
1725 const GLuint *s = ((const GLuint *) src);
1726 GLuint i;
1727 for (i = 0; i < n; i++) {
1728 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1729 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1730 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1731 dst[i][ACOMP] = 1.0f;
1732 }
1733 }
1734
1735 static void
1736 unpack_A8B8G8R8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1737 {
1738 const GLuint *s = ((const GLuint *) src);
1739 GLuint i;
1740 for (i = 0; i < n; i++) {
1741 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1742 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1743 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1744 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1745 }
1746 }
1747
1748 static void
1749 unpack_R8G8B8A8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1750 {
1751 const GLuint *s = ((const GLuint *) src);
1752 GLuint i;
1753 for (i = 0; i < n; i++) {
1754 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1755 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1756 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1757 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1758 }
1759 }
1760
1761 static void
1762 unpack_R_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
1763 {
1764 const GLshort *s = ((const GLshort *) src);
1765 GLuint i;
1766 for (i = 0; i < n; i++) {
1767 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1768 dst[i][GCOMP] = 0.0F;
1769 dst[i][BCOMP] = 0.0F;
1770 dst[i][ACOMP] = 1.0F;
1771 }
1772 }
1773
1774 static void
1775 unpack_R16G16_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1776 {
1777 const GLuint *s = ((const GLuint *) src);
1778 GLuint i;
1779 for (i = 0; i < n; i++) {
1780 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
1781 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
1782 dst[i][BCOMP] = 0.0F;
1783 dst[i][ACOMP] = 1.0F;
1784 }
1785 }
1786
1787 static void
1788 unpack_RGB_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
1789 {
1790 const GLshort *s = (const GLshort *) src;
1791 GLuint i;
1792 for (i = 0; i < n; i++) {
1793 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] );
1794 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
1795 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
1796 dst[i][ACOMP] = 1.0F;
1797 }
1798 }
1799
1800 static void
1801 unpack_RGBA_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
1802 {
1803 const GLshort *s = (const GLshort *) src;
1804 GLuint i;
1805 for (i = 0; i < n; i++) {
1806 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
1807 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
1808 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
1809 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
1810 }
1811 }
1812
1813 static void
1814 unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1815 {
1816 const GLushort *s = (const GLushort *) src;
1817 GLuint i;
1818 for (i = 0; i < n; i++) {
1819 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
1820 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
1821 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
1822 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
1823 }
1824 }
1825
1826 static void
1827 unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1828 {
1829 /* XXX to do */
1830 }
1831
1832 static void
1833 unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1834 {
1835 /* XXX to do */
1836 }
1837
1838 static void
1839 unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1840 {
1841 /* XXX to do */
1842 }
1843
1844 static void
1845 unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1846 {
1847 /* XXX to do */
1848 }
1849
1850 static void
1851 unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1852 {
1853 /* XXX to do */
1854 }
1855
1856 static void
1857 unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1858 {
1859 /* XXX to do */
1860 }
1861
1862 static void
1863 unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1864 {
1865 /* XXX to do */
1866 }
1867
1868 static void
1869 unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1870 {
1871 /* XXX to do */
1872 }
1873
1874 static void
1875 unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1876 {
1877 /* XXX to do */
1878 }
1879
1880 static void
1881 unpack_ETC2_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1882 {
1883 /* XXX to do */
1884 }
1885
1886 static void
1887 unpack_ETC2_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
1888 {
1889 /* XXX to do */
1890 }
1891
1892 static void
1893 unpack_ETC2_RGBA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
1894 {
1895 /* XXX to do */
1896 }
1897
1898 static void
1899 unpack_ETC2_SRGB8_ALPHA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
1900 {
1901 /* XXX to do */
1902 }
1903
1904 static void
1905 unpack_ETC2_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1906 {
1907 /* XXX to do */
1908 }
1909
1910 static void
1911 unpack_ETC2_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1912 {
1913 /* XXX to do */
1914 }
1915
1916 static void
1917 unpack_ETC2_SIGNED_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1918 {
1919 /* XXX to do */
1920 }
1921
1922 static void
1923 unpack_ETC2_SIGNED_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1924 {
1925 /* XXX to do */
1926 }
1927
1928 static void
1929 unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
1930 GLuint n)
1931 {
1932 /* XXX to do */
1933 }
1934
1935 static void
1936 unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
1937 GLuint n)
1938 {
1939 /* XXX to do */
1940 }
1941
1942 static void
1943 unpack_A_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
1944 {
1945 const GLbyte *s = ((const GLbyte *) src);
1946 GLuint i;
1947 for (i = 0; i < n; i++) {
1948 dst[i][RCOMP] = 0.0F;
1949 dst[i][GCOMP] = 0.0F;
1950 dst[i][BCOMP] = 0.0F;
1951 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1952 }
1953 }
1954
1955 static void
1956 unpack_L_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
1957 {
1958 const GLbyte *s = ((const GLbyte *) src);
1959 GLuint i;
1960 for (i = 0; i < n; i++) {
1961 dst[i][RCOMP] =
1962 dst[i][GCOMP] =
1963 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1964 dst[i][ACOMP] = 1.0F;
1965 }
1966 }
1967
1968 static void
1969 unpack_L8A8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1970 {
1971 const GLshort *s = ((const GLshort *) src);
1972 GLuint i;
1973 for (i = 0; i < n; i++) {
1974 dst[i][RCOMP] =
1975 dst[i][GCOMP] =
1976 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1977 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1978 }
1979 }
1980
1981
1982 static void
1983 unpack_A8L8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1984 {
1985 const GLshort *s = ((const GLshort *) src);
1986 GLuint i;
1987 for (i = 0; i < n; i++) {
1988 dst[i][RCOMP] =
1989 dst[i][GCOMP] =
1990 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1991 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1992 }
1993 }
1994
1995 static void
1996 unpack_I_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
1997 {
1998 const GLbyte *s = ((const GLbyte *) src);
1999 GLuint i;
2000 for (i = 0; i < n; i++) {
2001 dst[i][RCOMP] =
2002 dst[i][GCOMP] =
2003 dst[i][BCOMP] =
2004 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
2005 }
2006 }
2007
2008 static void
2009 unpack_A_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
2010 {
2011 const GLshort *s = ((const GLshort *) src);
2012 GLuint i;
2013 for (i = 0; i < n; i++) {
2014 dst[i][RCOMP] = 0.0F;
2015 dst[i][GCOMP] = 0.0F;
2016 dst[i][BCOMP] = 0.0F;
2017 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
2018 }
2019 }
2020
2021 static void
2022 unpack_L_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
2023 {
2024 const GLshort *s = ((const GLshort *) src);
2025 GLuint i;
2026 for (i = 0; i < n; i++) {
2027 dst[i][RCOMP] =
2028 dst[i][GCOMP] =
2029 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
2030 dst[i][ACOMP] = 1.0F;
2031 }
2032 }
2033
2034 static void
2035 unpack_LA_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
2036 {
2037 const GLshort *s = (const GLshort *) src;
2038 GLuint i;
2039 for (i = 0; i < n; i++) {
2040 dst[i][RCOMP] =
2041 dst[i][GCOMP] =
2042 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
2043 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
2044 }
2045 }
2046
2047 static void
2048 unpack_I_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
2049 {
2050 const GLshort *s = ((const GLshort *) src);
2051 GLuint i;
2052 for (i = 0; i < n; i++) {
2053 dst[i][RCOMP] =
2054 dst[i][GCOMP] =
2055 dst[i][BCOMP] =
2056 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
2057 }
2058 }
2059
2060 static void
2061 unpack_R9G9B9E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2062 {
2063 const GLuint *s = (const GLuint *) src;
2064 GLuint i;
2065 for (i = 0; i < n; i++) {
2066 rgb9e5_to_float3(s[i], dst[i]);
2067 dst[i][ACOMP] = 1.0F;
2068 }
2069 }
2070
2071 static void
2072 unpack_R11G11B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2073 {
2074 const GLuint *s = (const GLuint *) src;
2075 GLuint i;
2076 for (i = 0; i < n; i++) {
2077 r11g11b10f_to_float3(s[i], dst[i]);
2078 dst[i][ACOMP] = 1.0F;
2079 }
2080 }
2081
2082 static void
2083 unpack_XRGB4444_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2084 {
2085 const GLushort *s = ((const GLushort *) src);
2086 GLuint i;
2087 for (i = 0; i < n; i++) {
2088 dst[i][RCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
2089 dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
2090 dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
2091 dst[i][ACOMP] = 1.0;
2092 }
2093 }
2094
2095 static void
2096 unpack_XRGB1555_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2097 {
2098 const GLushort *s = ((const GLushort *) src);
2099 GLuint i;
2100 for (i = 0; i < n; i++) {
2101 dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
2102 dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F);
2103 dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F);
2104 dst[i][ACOMP] = 1.0;
2105 }
2106 }
2107
2108 static void
2109 unpack_R8G8B8X8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
2110 {
2111 const GLuint *s = ((const GLuint *) src);
2112 GLuint i;
2113 for (i = 0; i < n; i++) {
2114 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
2115 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
2116 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
2117 dst[i][ACOMP] = 1.0;
2118 }
2119 }
2120
2121 static void
2122 unpack_R8G8B8X8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
2123 {
2124 const GLuint *s = ((const GLuint *) src);
2125 GLuint i;
2126 for (i = 0; i < n; i++) {
2127 dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff );
2128 dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff );
2129 dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
2130 dst[i][ACOMP] = 1.0f;
2131 }
2132 }
2133
2134 static void
2135 unpack_XBGR8888_UINT(const void *src, GLfloat dst[][4], GLuint n)
2136 {
2137 const GLbyte *s = (const GLbyte *) src;
2138 GLuint i;
2139 for (i = 0; i < n; i++) {
2140 dst[i][RCOMP] = s[i*4+0];
2141 dst[i][GCOMP] = s[i*4+1];
2142 dst[i][BCOMP] = s[i*4+2];
2143 dst[i][ACOMP] = 1.0;
2144 }
2145 }
2146
2147 static void
2148 unpack_XBGR8888_SINT(const void *src, GLfloat dst[][4], GLuint n)
2149 {
2150 const GLbyte *s = (const GLbyte *) src;
2151 GLuint i;
2152 for (i = 0; i < n; i++) {
2153 dst[i][RCOMP] = s[i*4+0];
2154 dst[i][GCOMP] = s[i*4+1];
2155 dst[i][BCOMP] = s[i*4+2];
2156 dst[i][ACOMP] = 1.0;
2157 }
2158 }
2159
2160 static void
2161 unpack_B10G10R10X2_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2162 {
2163 const GLuint *s = ((const GLuint *) src);
2164 GLuint i;
2165 for (i = 0; i < n; i++) {
2166 dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
2167 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
2168 dst[i][BCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
2169 dst[i][ACOMP] = 1.0;
2170 }
2171 }
2172
2173 static void
2174 unpack_RGBX_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
2175 {
2176 const GLushort *s = (const GLushort *) src;
2177 GLuint i;
2178 for (i = 0; i < n; i++) {
2179 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
2180 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
2181 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
2182 dst[i][ACOMP] = 1.0;
2183 }
2184 }
2185
2186 static void
2187 unpack_RGBX_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
2188 {
2189 const GLshort *s = (const GLshort *) src;
2190 GLuint i;
2191 for (i = 0; i < n; i++) {
2192 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
2193 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
2194 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
2195 dst[i][ACOMP] = 1.0;
2196 }
2197 }
2198
2199 static void
2200 unpack_XBGR16161616_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2201 {
2202 const GLshort *s = (const GLshort *) src;
2203 GLuint i;
2204 for (i = 0; i < n; i++) {
2205 dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
2206 dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
2207 dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
2208 dst[i][ACOMP] = 1.0;
2209 }
2210 }
2211
2212 static void
2213 unpack_XBGR16161616_UINT(const void *src, GLfloat dst[][4], GLuint n)
2214 {
2215 const GLushort *s = (const GLushort *) src;
2216 GLuint i;
2217 for (i = 0; i < n; i++) {
2218 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2219 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2220 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2221 dst[i][ACOMP] = 1.0;
2222 }
2223 }
2224
2225 static void
2226 unpack_XBGR16161616_SINT(const void *src, GLfloat dst[][4], GLuint n)
2227 {
2228 const GLshort *s = (const GLshort *) src;
2229 GLuint i;
2230 for (i = 0; i < n; i++) {
2231 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2232 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2233 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2234 dst[i][ACOMP] = 1.0;
2235 }
2236 }
2237
2238 static void
2239 unpack_RGBX_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
2240 {
2241 const GLfloat *s = (const GLfloat *) src;
2242 GLuint i;
2243 for (i = 0; i < n; i++) {
2244 dst[i][RCOMP] = s[i*4+0];
2245 dst[i][GCOMP] = s[i*4+1];
2246 dst[i][BCOMP] = s[i*4+2];
2247 dst[i][ACOMP] = 1.0;
2248 }
2249 }
2250
2251 static void
2252 unpack_XBGR32323232_UINT(const void *src, GLfloat dst[][4], GLuint n)
2253 {
2254 const GLuint *s = (const GLuint *) src;
2255 GLuint i;
2256 for (i = 0; i < n; i++) {
2257 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2258 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2259 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2260 dst[i][ACOMP] = 1.0;
2261 }
2262 }
2263
2264 static void
2265 unpack_XBGR32323232_SINT(const void *src, GLfloat dst[][4], GLuint n)
2266 {
2267 const GLint *s = (const GLint *) src;
2268 GLuint i;
2269 for (i = 0; i < n; i++) {
2270 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2271 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2272 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2273 dst[i][ACOMP] = 1.0;
2274 }
2275 }
2276
2277 static void
2278 unpack_R10G10B10A2_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2279 {
2280 const GLuint *s = ((const GLuint *) src);
2281 GLuint i;
2282 for (i = 0; i < n; i++) {
2283 dst[i][RCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
2284 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
2285 dst[i][BCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
2286 dst[i][ACOMP] = ((s[i] >> 30) & 0x03) * (1.0F / 3.0F);
2287 }
2288 }
2289
2290 static void
2291 unpack_G8R8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
2292 {
2293 const GLushort *s = ((const GLushort *) src);
2294 GLuint i;
2295 for (i = 0; i < n; i++) {
2296 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
2297 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
2298 dst[i][BCOMP] = 0.0F;
2299 dst[i][ACOMP] = 1.0F;
2300 }
2301 }
2302
2303 static void
2304 unpack_G16R16_SNORM(const void *src, GLfloat dst[][4], GLuint n)
2305 {
2306 const GLuint *s = ((const GLuint *) src);
2307 GLuint i;
2308 for (i = 0; i < n; i++) {
2309 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
2310 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
2311 dst[i][BCOMP] = 0.0F;
2312 dst[i][ACOMP] = 1.0F;
2313 }
2314 }
2315
2316 static void
2317 unpack_B8G8R8X8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
2318 {
2319 const GLuint *s = ((const GLuint *) src);
2320 GLuint i;
2321 for (i = 0; i < n; i++) {
2322 dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
2323 dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff );
2324 dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff );
2325 dst[i][ACOMP] = 1.0F;
2326 }
2327 }
2328
2329 /**
2330 * Return the unpacker function for the given format.
2331 */
2332 static unpack_rgba_func
2333 get_unpack_rgba_function(mesa_format format)
2334 {
2335 static unpack_rgba_func table[MESA_FORMAT_COUNT];
2336 static GLboolean initialized = GL_FALSE;
2337
2338 if (!initialized) {
2339 table[MESA_FORMAT_NONE] = NULL;
2340
2341 table[MESA_FORMAT_A8B8G8R8_UNORM] = unpack_A8B8G8R8_UNORM;
2342 table[MESA_FORMAT_R8G8B8A8_UNORM] = unpack_R8G8B8A8_UNORM;
2343 table[MESA_FORMAT_B8G8R8A8_UNORM] = unpack_B8G8R8A8_UNORM;
2344 table[MESA_FORMAT_A8R8G8B8_UNORM] = unpack_A8R8G8B8_UNORM;
2345 table[MESA_FORMAT_X8B8G8R8_UNORM] = unpack_RGBX8888;
2346 table[MESA_FORMAT_R8G8B8X8_UNORM] = unpack_RGBX8888_REV;
2347 table[MESA_FORMAT_B8G8R8X8_UNORM] = unpack_B8G8R8X8_UNORM;
2348 table[MESA_FORMAT_X8R8G8B8_UNORM] = unpack_X8R8G8B8_UNORM;
2349 table[MESA_FORMAT_BGR_UNORM8] = unpack_BGR_UNORM8;
2350 table[MESA_FORMAT_RGB_UNORM8] = unpack_RGB_UNORM8;
2351 table[MESA_FORMAT_B5G6R5_UNORM] = unpack_B5G6R5_UNORM;
2352 table[MESA_FORMAT_R5G6B5_UNORM] = unpack_R5G6B5_UNORM;
2353 table[MESA_FORMAT_B4G4R4A4_UNORM] = unpack_B4G4R4A4_UNORM;
2354 table[MESA_FORMAT_A4R4G4B4_UNORM] = unpack_A4R4G4B4_UNORM;
2355 table[MESA_FORMAT_A1B5G5R5_UNORM] = unpack_A1B5G5R5_UNORM;
2356 table[MESA_FORMAT_B5G5R5A1_UNORM] = unpack_B5G5R5A1_UNORM;
2357 table[MESA_FORMAT_A1R5G5B5_UNORM] = unpack_A1R5G5B5_UNORM;
2358 table[MESA_FORMAT_L4A4_UNORM] = unpack_L4A4_UNORM;
2359 table[MESA_FORMAT_L8A8_UNORM] = unpack_L8A8_UNORM;
2360 table[MESA_FORMAT_A8L8_UNORM] = unpack_A8L8_UNORM;
2361 table[MESA_FORMAT_L16A16_UNORM] = unpack_L16A16_UNORM;
2362 table[MESA_FORMAT_A16L16_UNORM] = unpack_A16L16_UNORM;
2363 table[MESA_FORMAT_B2G3R3_UNORM] = unpack_B2G3R3_UNORM;
2364 table[MESA_FORMAT_A_UNORM8] = unpack_A_UNORM8;
2365 table[MESA_FORMAT_A_UNORM16] = unpack_A_UNORM16;
2366 table[MESA_FORMAT_L_UNORM8] = unpack_L_UNORM8;
2367 table[MESA_FORMAT_L_UNORM16] = unpack_L_UNORM16;
2368 table[MESA_FORMAT_I_UNORM8] = unpack_I_UNORM8;
2369 table[MESA_FORMAT_I_UNORM16] = unpack_I_UNORM16;
2370 table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
2371 table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
2372 table[MESA_FORMAT_R_UNORM8] = unpack_R_UNORM8;
2373 table[MESA_FORMAT_R8G8_UNORM] = unpack_R8G8_UNORM;
2374 table[MESA_FORMAT_G8R8_UNORM] = unpack_G8R8_UNORM;
2375 table[MESA_FORMAT_R_UNORM16] = unpack_R_UNORM16;
2376 table[MESA_FORMAT_R16G16_UNORM] = unpack_R16G16_UNORM;
2377 table[MESA_FORMAT_G16R16_UNORM] = unpack_G16R16_UNORM;
2378 table[MESA_FORMAT_B10G10R10A2_UNORM] = unpack_B10G10R10A2_UNORM;
2379 table[MESA_FORMAT_B10G10R10A2_UINT] = unpack_B10G10R10A2_UINT;
2380 table[MESA_FORMAT_R10G10B10A2_UINT] = unpack_R10G10B10A2_UINT;
2381 table[MESA_FORMAT_S8_UINT_Z24_UNORM] = unpack_S8_UINT_Z24_UNORM;
2382 table[MESA_FORMAT_Z24_UNORM_S8_UINT] = unpack_Z24_UNORM_S8_UINT;
2383 table[MESA_FORMAT_Z_UNORM16] = unpack_Z_UNORM16;
2384 table[MESA_FORMAT_Z24_UNORM_X8_UINT] = unpack_Z24_UNORM_X8_UINT;
2385 table[MESA_FORMAT_X8_UINT_Z24_UNORM] = unpack_X8_UINT_Z24_UNORM;
2386 table[MESA_FORMAT_Z_UNORM32] = unpack_Z_UNORM32;
2387 table[MESA_FORMAT_S_UINT8] = unpack_S8;
2388 table[MESA_FORMAT_BGR_SRGB8] = unpack_BGR_SRGB8;
2389 table[MESA_FORMAT_A8B8G8R8_SRGB] = unpack_A8B8G8R8_SRGB;
2390 table[MESA_FORMAT_B8G8R8A8_SRGB] = unpack_B8G8R8A8_SRGB;
2391 table[MESA_FORMAT_R8G8B8A8_SRGB] = unpack_R8G8B8A8_SRGB;
2392 table[MESA_FORMAT_L_SRGB8] = unpack_L_SRGB8;
2393 table[MESA_FORMAT_L8A8_SRGB] = unpack_L8A8_SRGB;
2394 table[MESA_FORMAT_A8L8_SRGB] = unpack_A8L8_SRGB;
2395 table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
2396 table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
2397 table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
2398 table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
2399
2400 table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
2401 table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
2402 table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
2403 table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
2404 table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
2405 table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
2406
2407 table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
2408 table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
2409 table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
2410 table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
2411 table[MESA_FORMAT_A_FLOAT32] = unpack_A_FLOAT32;
2412 table[MESA_FORMAT_A_FLOAT16] = unpack_A_FLOAT16;
2413 table[MESA_FORMAT_L_FLOAT32] = unpack_L_FLOAT32;
2414 table[MESA_FORMAT_L_FLOAT16] = unpack_L_FLOAT16;
2415 table[MESA_FORMAT_LA_FLOAT32] = unpack_LA_FLOAT32;
2416 table[MESA_FORMAT_LA_FLOAT16] = unpack_LA_FLOAT16;
2417 table[MESA_FORMAT_I_FLOAT32] = unpack_I_FLOAT32;
2418 table[MESA_FORMAT_I_FLOAT16] = unpack_I_FLOAT16;
2419 table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
2420 table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
2421 table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
2422 table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
2423
2424 table[MESA_FORMAT_A_UINT8] = unpack_ALPHA_UINT8;
2425 table[MESA_FORMAT_A_UINT16] = unpack_ALPHA_UINT16;
2426 table[MESA_FORMAT_A_UINT32] = unpack_ALPHA_UINT32;
2427 table[MESA_FORMAT_A_SINT8] = unpack_ALPHA_INT8;
2428 table[MESA_FORMAT_A_SINT16] = unpack_ALPHA_INT16;
2429 table[MESA_FORMAT_A_SINT32] = unpack_ALPHA_INT32;
2430
2431 table[MESA_FORMAT_I_UINT8] = unpack_INTENSITY_UINT8;
2432 table[MESA_FORMAT_I_UINT16] = unpack_INTENSITY_UINT16;
2433 table[MESA_FORMAT_I_UINT32] = unpack_INTENSITY_UINT32;
2434 table[MESA_FORMAT_I_SINT8] = unpack_INTENSITY_INT8;
2435 table[MESA_FORMAT_I_SINT16] = unpack_INTENSITY_INT16;
2436 table[MESA_FORMAT_I_SINT32] = unpack_INTENSITY_INT32;
2437
2438 table[MESA_FORMAT_L_UINT8] = unpack_LUMINANCE_UINT8;
2439 table[MESA_FORMAT_L_UINT16] = unpack_LUMINANCE_UINT16;
2440 table[MESA_FORMAT_L_UINT32] = unpack_LUMINANCE_UINT32;
2441 table[MESA_FORMAT_L_SINT8] = unpack_LUMINANCE_INT8;
2442 table[MESA_FORMAT_L_SINT16] = unpack_LUMINANCE_INT16;
2443 table[MESA_FORMAT_L_SINT32] = unpack_LUMINANCE_INT32;
2444
2445 table[MESA_FORMAT_LA_UINT8] = unpack_LUMINANCE_ALPHA_UINT8;
2446 table[MESA_FORMAT_LA_UINT16] = unpack_LUMINANCE_ALPHA_UINT16;
2447 table[MESA_FORMAT_LA_UINT32] = unpack_LUMINANCE_ALPHA_UINT32;
2448 table[MESA_FORMAT_LA_SINT8] = unpack_LUMINANCE_ALPHA_INT8;
2449 table[MESA_FORMAT_LA_SINT16] = unpack_LUMINANCE_ALPHA_INT16;
2450 table[MESA_FORMAT_LA_SINT32] = unpack_LUMINANCE_ALPHA_INT32;
2451
2452 table[MESA_FORMAT_R_SINT8] = unpack_R_INT8;
2453 table[MESA_FORMAT_RG_SINT8] = unpack_RG_INT8;
2454 table[MESA_FORMAT_RGB_SINT8] = unpack_RGB_INT8;
2455 table[MESA_FORMAT_RGBA_SINT8] = unpack_RGBA_INT8;
2456 table[MESA_FORMAT_R_SINT16] = unpack_R_INT16;
2457 table[MESA_FORMAT_RG_SINT16] = unpack_RG_INT16;
2458 table[MESA_FORMAT_RGB_SINT16] = unpack_RGB_INT16;
2459 table[MESA_FORMAT_RGBA_SINT16] = unpack_RGBA_INT16;
2460 table[MESA_FORMAT_R_SINT32] = unpack_R_INT32;
2461 table[MESA_FORMAT_RG_SINT32] = unpack_RG_INT32;
2462 table[MESA_FORMAT_RGB_SINT32] = unpack_RGB_INT32;
2463 table[MESA_FORMAT_RGBA_SINT32] = unpack_RGBA_INT32;
2464 table[MESA_FORMAT_R_UINT8] = unpack_R_UINT8;
2465 table[MESA_FORMAT_RG_UINT8] = unpack_RG_UINT8;
2466 table[MESA_FORMAT_RGB_UINT8] = unpack_RGB_UINT8;
2467 table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
2468 table[MESA_FORMAT_R_UINT16] = unpack_R_UINT16;
2469 table[MESA_FORMAT_RG_UINT16] = unpack_RG_UINT16;
2470 table[MESA_FORMAT_RGB_UINT16] = unpack_RGB_UINT16;
2471 table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
2472 table[MESA_FORMAT_R_UINT32] = unpack_R_UINT32;
2473 table[MESA_FORMAT_RG_UINT32] = unpack_RG_UINT32;
2474 table[MESA_FORMAT_RGB_UINT32] = unpack_RGB_UINT32;
2475 table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
2476
2477 table[MESA_FORMAT_R_SNORM8] = unpack_R_SNORM8;
2478 table[MESA_FORMAT_R8G8_SNORM] = unpack_R8G8_SNORM;
2479 table[MESA_FORMAT_X8B8G8R8_SNORM] = unpack_X8B8G8R8_SNORM;
2480 table[MESA_FORMAT_A8B8G8R8_SNORM] = unpack_A8B8G8R8_SNORM;
2481 table[MESA_FORMAT_R8G8B8A8_SNORM] = unpack_R8G8B8A8_SNORM;
2482 table[MESA_FORMAT_R_SNORM16] = unpack_R_SNORM16;
2483 table[MESA_FORMAT_R16G16_SNORM] = unpack_R16G16_SNORM;
2484 table[MESA_FORMAT_RGB_SNORM16] = unpack_RGB_SNORM16;
2485 table[MESA_FORMAT_RGBA_SNORM16] = unpack_RGBA_SNORM16;
2486 table[MESA_FORMAT_RGBA_UNORM16] = unpack_RGBA_16;
2487
2488 table[MESA_FORMAT_R_RGTC1_UNORM] = unpack_RED_RGTC1;
2489 table[MESA_FORMAT_R_RGTC1_SNORM] = unpack_SIGNED_RED_RGTC1;
2490 table[MESA_FORMAT_RG_RGTC2_UNORM] = unpack_RG_RGTC2;
2491 table[MESA_FORMAT_RG_RGTC2_SNORM] = unpack_SIGNED_RG_RGTC2;
2492
2493 table[MESA_FORMAT_L_LATC1_UNORM] = unpack_L_LATC1;
2494 table[MESA_FORMAT_L_LATC1_SNORM] = unpack_SIGNED_L_LATC1;
2495 table[MESA_FORMAT_LA_LATC2_UNORM] = unpack_LA_LATC2;
2496 table[MESA_FORMAT_LA_LATC2_SNORM] = unpack_SIGNED_LA_LATC2;
2497
2498 table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
2499 table[MESA_FORMAT_ETC2_RGB8] = unpack_ETC2_RGB8;
2500 table[MESA_FORMAT_ETC2_SRGB8] = unpack_ETC2_SRGB8;
2501 table[MESA_FORMAT_ETC2_RGBA8_EAC] = unpack_ETC2_RGBA8_EAC;
2502 table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = unpack_ETC2_SRGB8_ALPHA8_EAC;
2503 table[MESA_FORMAT_ETC2_R11_EAC] = unpack_ETC2_R11_EAC;
2504 table[MESA_FORMAT_ETC2_RG11_EAC] = unpack_ETC2_RG11_EAC;
2505 table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = unpack_ETC2_SIGNED_R11_EAC;
2506 table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = unpack_ETC2_SIGNED_RG11_EAC;
2507 table[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] =
2508 unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
2509 table[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] =
2510 unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
2511 table[MESA_FORMAT_A_SNORM8] = unpack_A_SNORM8;
2512 table[MESA_FORMAT_L_SNORM8] = unpack_L_SNORM8;
2513 table[MESA_FORMAT_L8A8_SNORM] = unpack_L8A8_SNORM;
2514 table[MESA_FORMAT_A8L8_SNORM] = unpack_A8L8_SNORM;
2515 table[MESA_FORMAT_I_SNORM8] = unpack_I_SNORM8;
2516 table[MESA_FORMAT_A_SNORM16] = unpack_A_SNORM16;
2517 table[MESA_FORMAT_L_SNORM16] = unpack_L_SNORM16;
2518 table[MESA_FORMAT_LA_SNORM16] = unpack_LA_SNORM16;
2519 table[MESA_FORMAT_I_SNORM16] = unpack_I_SNORM16;
2520
2521 table[MESA_FORMAT_R9G9B9E5_FLOAT] = unpack_R9G9B9E5_FLOAT;
2522 table[MESA_FORMAT_R11G11B10_FLOAT] = unpack_R11G11B10_FLOAT;
2523
2524 table[MESA_FORMAT_Z_FLOAT32] = unpack_Z_FLOAT32;
2525 table[MESA_FORMAT_Z32_FLOAT_S8X24_UINT] = unpack_Z32_FLOAT_S8X24_UINT;
2526
2527 table[MESA_FORMAT_B4G4R4X4_UNORM] = unpack_XRGB4444_UNORM;
2528 table[MESA_FORMAT_B5G5R5X1_UNORM] = unpack_XRGB1555_UNORM;
2529 table[MESA_FORMAT_R8G8B8X8_SNORM] = unpack_R8G8B8X8_SNORM;
2530 table[MESA_FORMAT_R8G8B8X8_SRGB] = unpack_R8G8B8X8_SRGB;
2531 table[MESA_FORMAT_RGBX_UINT8] = unpack_XBGR8888_UINT;
2532 table[MESA_FORMAT_RGBX_SINT8] = unpack_XBGR8888_SINT;
2533 table[MESA_FORMAT_B10G10R10X2_UNORM] = unpack_B10G10R10X2_UNORM;
2534 table[MESA_FORMAT_RGBX_UNORM16] = unpack_RGBX_UNORM16;
2535 table[MESA_FORMAT_RGBX_SNORM16] = unpack_RGBX_SNORM16;
2536 table[MESA_FORMAT_RGBX_FLOAT16] = unpack_XBGR16161616_FLOAT;
2537 table[MESA_FORMAT_RGBX_UINT16] = unpack_XBGR16161616_UINT;
2538 table[MESA_FORMAT_RGBX_SINT16] = unpack_XBGR16161616_SINT;
2539 table[MESA_FORMAT_RGBX_FLOAT32] = unpack_RGBX_FLOAT32;
2540 table[MESA_FORMAT_RGBX_UINT32] = unpack_XBGR32323232_UINT;
2541 table[MESA_FORMAT_RGBX_SINT32] = unpack_XBGR32323232_SINT;
2542
2543 table[MESA_FORMAT_R10G10B10A2_UNORM] = unpack_R10G10B10A2_UNORM;
2544
2545 table[MESA_FORMAT_G8R8_SNORM] = unpack_G8R8_SNORM;
2546 table[MESA_FORMAT_G16R16_SNORM] = unpack_G16R16_SNORM;
2547
2548 table[MESA_FORMAT_B8G8R8X8_SRGB] = unpack_B8G8R8X8_SRGB;
2549
2550 initialized = GL_TRUE;
2551 }
2552
2553 if (table[format] == NULL) {
2554 _mesa_problem(NULL, "unsupported unpack for format %s",
2555 _mesa_get_format_name(format));
2556 }
2557
2558 return table[format];
2559 }
2560
2561
2562 /**
2563 * Unpack rgba colors, returning as GLfloat values.
2564 */
2565 void
2566 _mesa_unpack_rgba_row(mesa_format format, GLuint n,
2567 const void *src, GLfloat dst[][4])
2568 {
2569 unpack_rgba_func unpack = get_unpack_rgba_function(format);
2570 unpack(src, dst, n);
2571 }
2572
2573
2574 /**********************************************************************/
2575 /* Unpack, returning GLubyte colors */
2576 /**********************************************************************/
2577
2578
2579 static void
2580 unpack_ubyte_A8B8G8R8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2581 {
2582 const GLuint *s = ((const GLuint *) src);
2583 GLuint i;
2584 for (i = 0; i < n; i++) {
2585 dst[i][RCOMP] = (s[i] >> 24);
2586 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2587 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
2588 dst[i][ACOMP] = (s[i] ) & 0xff;
2589 }
2590 }
2591
2592 static void
2593 unpack_ubyte_R8G8B8A8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2594 {
2595 const GLuint *s = ((const GLuint *) src);
2596 GLuint i;
2597 for (i = 0; i < n; i++) {
2598 dst[i][RCOMP] = (s[i] ) & 0xff;
2599 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2600 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
2601 dst[i][ACOMP] = (s[i] >> 24);
2602 }
2603 }
2604
2605 static void
2606 unpack_ubyte_B8G8R8A8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2607 {
2608 const GLuint *s = ((const GLuint *) src);
2609 GLuint i;
2610 for (i = 0; i < n; i++) {
2611 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
2612 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2613 dst[i][BCOMP] = (s[i] ) & 0xff;
2614 dst[i][ACOMP] = (s[i] >> 24);
2615 }
2616 }
2617
2618 static void
2619 unpack_ubyte_A8R8G8B8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2620 {
2621 const GLuint *s = ((const GLuint *) src);
2622 GLuint i;
2623 for (i = 0; i < n; i++) {
2624 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
2625 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2626 dst[i][BCOMP] = (s[i] >> 24);
2627 dst[i][ACOMP] = (s[i] ) & 0xff;
2628 }
2629 }
2630
2631 static void
2632 unpack_ubyte_RGBX8888(const void *src, GLubyte dst[][4], GLuint n)
2633 {
2634 const GLuint *s = ((const GLuint *) src);
2635 GLuint i;
2636 for (i = 0; i < n; i++) {
2637 dst[i][RCOMP] = (s[i] >> 24);
2638 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2639 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
2640 dst[i][ACOMP] = 0xff;
2641 }
2642 }
2643
2644 static void
2645 unpack_ubyte_RGBX8888_REV(const void *src, GLubyte dst[][4], GLuint n)
2646 {
2647 const GLuint *s = ((const GLuint *) src);
2648 GLuint i;
2649 for (i = 0; i < n; i++) {
2650 dst[i][RCOMP] = (s[i] ) & 0xff;
2651 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2652 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
2653 dst[i][ACOMP] = 0xff;
2654 }
2655 }
2656
2657 static void
2658 unpack_ubyte_B8G8R8X8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2659 {
2660 const GLuint *s = ((const GLuint *) src);
2661 GLuint i;
2662 for (i = 0; i < n; i++) {
2663 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
2664 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2665 dst[i][BCOMP] = (s[i] ) & 0xff;
2666 dst[i][ACOMP] = 0xff;
2667 }
2668 }
2669
2670 static void
2671 unpack_ubyte_X8R8G8B8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2672 {
2673 const GLuint *s = ((const GLuint *) src);
2674 GLuint i;
2675 for (i = 0; i < n; i++) {
2676 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
2677 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2678 dst[i][BCOMP] = (s[i] >> 24);
2679 dst[i][ACOMP] = 0xff;
2680 }
2681 }
2682
2683 static void
2684 unpack_ubyte_BGR_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
2685 {
2686 const GLubyte *s = (const GLubyte *) src;
2687 GLuint i;
2688 for (i = 0; i < n; i++) {
2689 dst[i][RCOMP] = s[i*3+2];
2690 dst[i][GCOMP] = s[i*3+1];
2691 dst[i][BCOMP] = s[i*3+0];
2692 dst[i][ACOMP] = 0xff;
2693 }
2694 }
2695
2696 static void
2697 unpack_ubyte_RGB_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
2698 {
2699 const GLubyte *s = (const GLubyte *) src;
2700 GLuint i;
2701 for (i = 0; i < n; i++) {
2702 dst[i][RCOMP] = s[i*3+0];
2703 dst[i][GCOMP] = s[i*3+1];
2704 dst[i][BCOMP] = s[i*3+2];
2705 dst[i][ACOMP] = 0xff;
2706 }
2707 }
2708
2709 static void
2710 unpack_ubyte_B5G6R5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2711 {
2712 const GLushort *s = ((const GLushort *) src);
2713 GLuint i;
2714 for (i = 0; i < n; i++) {
2715 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
2716 dst[i][GCOMP] = EXPAND_6_8((s[i] >> 5 ) & 0x3f);
2717 dst[i][BCOMP] = EXPAND_5_8( s[i] & 0x1f);
2718 dst[i][ACOMP] = 0xff;
2719 }
2720 }
2721
2722 static void
2723 unpack_ubyte_R5G6B5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2724 {
2725 /* Warning: this function does not match the current Mesa definition
2726 * of MESA_FORMAT_R5G6B5_UNORM.
2727 */
2728 const GLushort *s = ((const GLushort *) src);
2729 GLuint i;
2730 for (i = 0; i < n; i++) {
2731 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
2732 dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);
2733 dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);
2734 dst[i][BCOMP] = EXPAND_5_8( t & 0x1f);
2735 dst[i][ACOMP] = 0xff;
2736 }
2737 }
2738
2739 static void
2740 unpack_ubyte_B4G4R4A4_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2741 {
2742 const GLushort *s = ((const GLushort *) src);
2743 GLuint i;
2744 for (i = 0; i < n; i++) {
2745 dst[i][RCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
2746 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
2747 dst[i][BCOMP] = EXPAND_4_8((s[i] ) & 0xf);
2748 dst[i][ACOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
2749 }
2750 }
2751
2752 static void
2753 unpack_ubyte_A4R4G4B4_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2754 {
2755 const GLushort *s = ((const GLushort *) src);
2756 GLuint i;
2757 for (i = 0; i < n; i++) {
2758 dst[i][RCOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
2759 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
2760 dst[i][BCOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
2761 dst[i][ACOMP] = EXPAND_4_8((s[i] ) & 0xf);
2762 }
2763 }
2764
2765 static void
2766 unpack_ubyte_A1B5G5R5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2767 {
2768 const GLushort *s = ((const GLushort *) src);
2769 GLuint i;
2770 for (i = 0; i < n; i++) {
2771 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
2772 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 6) & 0x1f);
2773 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 1) & 0x1f);
2774 dst[i][ACOMP] = EXPAND_1_8((s[i] ) & 0x01);
2775 }
2776 }
2777
2778 static void
2779 unpack_ubyte_B5G5R5A1_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2780 {
2781 const GLushort *s = ((const GLushort *) src);
2782 GLuint i;
2783 for (i = 0; i < n; i++) {
2784 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 10) & 0x1f);
2785 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 5) & 0x1f);
2786 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 0) & 0x1f);
2787 dst[i][ACOMP] = EXPAND_1_8((s[i] >> 15) & 0x01);
2788 }
2789 }
2790
2791 static void
2792 unpack_ubyte_A1R5G5B5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2793 {
2794 /* Warning: this function does not match the current Mesa definition
2795 * of MESA_FORMAT_A1R5G5B5_UNORM.
2796 */
2797 const GLushort *s = ((const GLushort *) src);
2798 GLuint i;
2799 for (i = 0; i < n; i++) {
2800 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
2801 dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
2802 dst[i][GCOMP] = EXPAND_5_8((tmp >> 5) & 0x1f);
2803 dst[i][BCOMP] = EXPAND_5_8((tmp >> 0) & 0x1f);
2804 dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
2805 }
2806 }
2807
2808 static void
2809 unpack_ubyte_L4A4_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2810 {
2811 const GLubyte *s = ((const GLubyte *) src);
2812 GLuint i;
2813 for (i = 0; i < n; i++) {
2814 dst[i][RCOMP] =
2815 dst[i][GCOMP] =
2816 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xf);
2817 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 4);
2818 }
2819 }
2820
2821 static void
2822 unpack_ubyte_L8A8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2823 {
2824 const GLushort *s = ((const GLushort *) src);
2825 GLuint i;
2826 for (i = 0; i < n; i++) {
2827 dst[i][RCOMP] =
2828 dst[i][GCOMP] =
2829 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xff);
2830 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 8);
2831 }
2832 }
2833
2834 static void
2835 unpack_ubyte_A8L8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2836 {
2837 const GLushort *s = ((const GLushort *) src);
2838 GLuint i;
2839 for (i = 0; i < n; i++) {
2840 dst[i][RCOMP] =
2841 dst[i][GCOMP] =
2842 dst[i][BCOMP] = EXPAND_4_8(s[i] >> 8);
2843 dst[i][ACOMP] = EXPAND_4_8(s[i] & 0xff);
2844 }
2845 }
2846
2847 static void
2848 unpack_ubyte_B2G3R3_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2849 {
2850 const GLubyte *s = ((const GLubyte *) src);
2851 GLuint i;
2852 for (i = 0; i < n; i++) {
2853 dst[i][RCOMP] = EXPAND_3_8((s[i] >> 5) & 0x7);
2854 dst[i][GCOMP] = EXPAND_3_8((s[i] >> 2) & 0x7);
2855 dst[i][BCOMP] = EXPAND_2_8((s[i] ) & 0x3);
2856 dst[i][ACOMP] = 0xff;
2857 }
2858 }
2859
2860 static void
2861 unpack_ubyte_A_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
2862 {
2863 const GLubyte *s = ((const GLubyte *) src);
2864 GLuint i;
2865 for (i = 0; i < n; i++) {
2866 dst[i][RCOMP] =
2867 dst[i][GCOMP] =
2868 dst[i][BCOMP] = 0;
2869 dst[i][ACOMP] = s[i];
2870 }
2871 }
2872
2873 static void
2874 unpack_ubyte_L_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
2875 {
2876 const GLubyte *s = ((const GLubyte *) src);
2877 GLuint i;
2878 for (i = 0; i < n; i++) {
2879 dst[i][RCOMP] =
2880 dst[i][GCOMP] =
2881 dst[i][BCOMP] = s[i];
2882 dst[i][ACOMP] = 0xff;
2883 }
2884 }
2885
2886
2887 static void
2888 unpack_ubyte_I_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
2889 {
2890 const GLubyte *s = ((const GLubyte *) src);
2891 GLuint i;
2892 for (i = 0; i < n; i++) {
2893 dst[i][RCOMP] =
2894 dst[i][GCOMP] =
2895 dst[i][BCOMP] =
2896 dst[i][ACOMP] = s[i];
2897 }
2898 }
2899
2900 static void
2901 unpack_ubyte_R_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
2902 {
2903 const GLubyte *s = ((const GLubyte *) src);
2904 GLuint i;
2905 for (i = 0; i < n; i++) {
2906 dst[i][0] = s[i];
2907 dst[i][1] =
2908 dst[i][2] = 0;
2909 dst[i][3] = 0xff;
2910 }
2911 }
2912
2913 static void
2914 unpack_ubyte_R8G8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2915 {
2916 const GLushort *s = ((const GLushort *) src);
2917 GLuint i;
2918 for (i = 0; i < n; i++) {
2919 dst[i][RCOMP] = s[i] & 0xff;
2920 dst[i][GCOMP] = s[i] >> 8;
2921 dst[i][BCOMP] = 0;
2922 dst[i][ACOMP] = 0xff;
2923 }
2924 }
2925
2926 static void
2927 unpack_ubyte_G8R8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2928 {
2929 const GLushort *s = ((const GLushort *) src);
2930 GLuint i;
2931 for (i = 0; i < n; i++) {
2932 dst[i][RCOMP] = s[i] >> 8;
2933 dst[i][GCOMP] = s[i] & 0xff;
2934 dst[i][BCOMP] = 0;
2935 dst[i][ACOMP] = 0xff;
2936 }
2937 }
2938
2939
2940 /**
2941 * Unpack rgba colors, returning as GLubyte values. This should usually
2942 * only be used for unpacking formats that use 8 bits or less per channel.
2943 */
2944 void
2945 _mesa_unpack_ubyte_rgba_row(mesa_format format, GLuint n,
2946 const void *src, GLubyte dst[][4])
2947 {
2948 switch (format) {
2949 case MESA_FORMAT_A8B8G8R8_UNORM:
2950 unpack_ubyte_A8B8G8R8_UNORM(src, dst, n);
2951 break;
2952 case MESA_FORMAT_R8G8B8A8_UNORM:
2953 unpack_ubyte_R8G8B8A8_UNORM(src, dst, n);
2954 break;
2955 case MESA_FORMAT_B8G8R8A8_UNORM:
2956 unpack_ubyte_B8G8R8A8_UNORM(src, dst, n);
2957 break;
2958 case MESA_FORMAT_A8R8G8B8_UNORM:
2959 unpack_ubyte_A8R8G8B8_UNORM(src, dst, n);
2960 break;
2961 case MESA_FORMAT_X8B8G8R8_UNORM:
2962 unpack_ubyte_RGBX8888(src, dst, n);
2963 break;
2964 case MESA_FORMAT_R8G8B8X8_UNORM:
2965 unpack_ubyte_RGBX8888_REV(src, dst, n);
2966 break;
2967 case MESA_FORMAT_B8G8R8X8_UNORM:
2968 unpack_ubyte_B8G8R8X8_UNORM(src, dst, n);
2969 break;
2970 case MESA_FORMAT_X8R8G8B8_UNORM:
2971 unpack_ubyte_X8R8G8B8_UNORM(src, dst, n);
2972 break;
2973 case MESA_FORMAT_BGR_UNORM8:
2974 unpack_ubyte_BGR_UNORM8(src, dst, n);
2975 break;
2976 case MESA_FORMAT_RGB_UNORM8:
2977 unpack_ubyte_RGB_UNORM8(src, dst, n);
2978 break;
2979 case MESA_FORMAT_B5G6R5_UNORM:
2980 unpack_ubyte_B5G6R5_UNORM(src, dst, n);
2981 break;
2982 case MESA_FORMAT_R5G6B5_UNORM:
2983 unpack_ubyte_R5G6B5_UNORM(src, dst, n);
2984 break;
2985 case MESA_FORMAT_B4G4R4A4_UNORM:
2986 unpack_ubyte_B4G4R4A4_UNORM(src, dst, n);
2987 break;
2988 case MESA_FORMAT_A4R4G4B4_UNORM:
2989 unpack_ubyte_A4R4G4B4_UNORM(src, dst, n);
2990 break;
2991 case MESA_FORMAT_A1B5G5R5_UNORM:
2992 unpack_ubyte_A1B5G5R5_UNORM(src, dst, n);
2993 break;
2994 case MESA_FORMAT_B5G5R5A1_UNORM:
2995 unpack_ubyte_B5G5R5A1_UNORM(src, dst, n);
2996 break;
2997 case MESA_FORMAT_A1R5G5B5_UNORM:
2998 unpack_ubyte_A1R5G5B5_UNORM(src, dst, n);
2999 break;
3000 case MESA_FORMAT_L4A4_UNORM:
3001 unpack_ubyte_L4A4_UNORM(src, dst, n);
3002 break;
3003 case MESA_FORMAT_L8A8_UNORM:
3004 unpack_ubyte_L8A8_UNORM(src, dst, n);
3005 break;
3006 case MESA_FORMAT_A8L8_UNORM:
3007 unpack_ubyte_A8L8_UNORM(src, dst, n);
3008 break;
3009 case MESA_FORMAT_B2G3R3_UNORM:
3010 unpack_ubyte_B2G3R3_UNORM(src, dst, n);
3011 break;
3012 case MESA_FORMAT_A_UNORM8:
3013 unpack_ubyte_A_UNORM8(src, dst, n);
3014 break;
3015 case MESA_FORMAT_L_UNORM8:
3016 unpack_ubyte_L_UNORM8(src, dst, n);
3017 break;
3018 case MESA_FORMAT_I_UNORM8:
3019 unpack_ubyte_I_UNORM8(src, dst, n);
3020 break;
3021 case MESA_FORMAT_R_UNORM8:
3022 unpack_ubyte_R_UNORM8(src, dst, n);
3023 break;
3024 case MESA_FORMAT_R8G8_UNORM:
3025 unpack_ubyte_R8G8_UNORM(src, dst, n);
3026 break;
3027 case MESA_FORMAT_G8R8_UNORM:
3028 unpack_ubyte_G8R8_UNORM(src, dst, n);
3029 break;
3030 default:
3031 /* get float values, convert to ubyte */
3032 {
3033 GLfloat *tmp = malloc(n * 4 * sizeof(GLfloat));
3034 if (tmp) {
3035 GLuint i;
3036 _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
3037 for (i = 0; i < n; i++) {
3038 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][0], tmp[i*4+0]);
3039 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][1], tmp[i*4+1]);
3040 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][2], tmp[i*4+2]);
3041 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][3], tmp[i*4+3]);
3042 }
3043 free(tmp);
3044 }
3045 }
3046 break;
3047 }
3048 }
3049
3050
3051 /**********************************************************************/
3052 /* Unpack, returning GLuint colors */
3053 /**********************************************************************/
3054
3055 static void
3056 unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3057 {
3058 memcpy(dst, src, n * 4 * sizeof(GLuint));
3059 }
3060
3061 static void
3062 unpack_int_rgba_RGBA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3063 {
3064 unsigned int i;
3065
3066 for (i = 0; i < n; i++) {
3067 dst[i][0] = src[i * 4 + 0];
3068 dst[i][1] = src[i * 4 + 1];
3069 dst[i][2] = src[i * 4 + 2];
3070 dst[i][3] = src[i * 4 + 3];
3071 }
3072 }
3073
3074 static void
3075 unpack_int_rgba_RGBA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3076 {
3077 unsigned int i;
3078
3079 for (i = 0; i < n; i++) {
3080 dst[i][0] = src[i * 4 + 0];
3081 dst[i][1] = src[i * 4 + 1];
3082 dst[i][2] = src[i * 4 + 2];
3083 dst[i][3] = src[i * 4 + 3];
3084 }
3085 }
3086
3087 static void
3088 unpack_int_rgba_RGBA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3089 {
3090 unsigned int i;
3091
3092 for (i = 0; i < n; i++) {
3093 dst[i][0] = src[i * 4 + 0];
3094 dst[i][1] = src[i * 4 + 1];
3095 dst[i][2] = src[i * 4 + 2];
3096 dst[i][3] = src[i * 4 + 3];
3097 }
3098 }
3099
3100 static void
3101 unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3102 {
3103 unsigned int i;
3104
3105 for (i = 0; i < n; i++) {
3106 dst[i][0] = src[i * 4 + 0];
3107 dst[i][1] = src[i * 4 + 1];
3108 dst[i][2] = src[i * 4 + 2];
3109 dst[i][3] = src[i * 4 + 3];
3110 }
3111 }
3112
3113 static void
3114 unpack_int_rgba_B8G8R8A8_UNORM(const GLbyte *src, GLuint dst[][4], GLuint n)
3115 {
3116 unsigned int i;
3117
3118 for (i = 0; i < n; i++) {
3119 dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
3120 dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
3121 dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
3122 dst[i][ACOMP] = (GLubyte) src[i * 4 + 3];
3123 }
3124 }
3125
3126 static void
3127 unpack_int_rgba_B8G8R8X8_UNORM(const GLbyte *src, GLuint dst[][4], GLuint n)
3128 {
3129 unsigned int i;
3130
3131 for (i = 0; i < n; i++) {
3132 dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
3133 dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
3134 dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
3135 dst[i][ACOMP] = (GLubyte) 0xff;
3136 }
3137 }
3138
3139 static void
3140 unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3141 {
3142 unsigned int i;
3143
3144 for (i = 0; i < n; i++) {
3145 dst[i][0] = src[i * 3 + 0];
3146 dst[i][1] = src[i * 3 + 1];
3147 dst[i][2] = src[i * 3 + 2];
3148 dst[i][3] = 1;
3149 }
3150 }
3151
3152 static void
3153 unpack_int_rgba_RGB_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3154 {
3155 unsigned int i;
3156
3157 for (i = 0; i < n; i++) {
3158 dst[i][0] = src[i * 3 + 0];
3159 dst[i][1] = src[i * 3 + 1];
3160 dst[i][2] = src[i * 3 + 2];
3161 dst[i][3] = 1;
3162 }
3163 }
3164
3165 static void
3166 unpack_int_rgba_RGB_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3167 {
3168 unsigned int i;
3169
3170 for (i = 0; i < n; i++) {
3171 dst[i][0] = src[i * 3 + 0];
3172 dst[i][1] = src[i * 3 + 1];
3173 dst[i][2] = src[i * 3 + 2];
3174 dst[i][3] = 1;
3175 }
3176 }
3177
3178 static void
3179 unpack_int_rgba_RGB_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3180 {
3181 unsigned int i;
3182
3183 for (i = 0; i < n; i++) {
3184 dst[i][0] = src[i * 3 + 0];
3185 dst[i][1] = src[i * 3 + 1];
3186 dst[i][2] = src[i * 3 + 2];
3187 dst[i][3] = 1;
3188 }
3189 }
3190
3191 static void
3192 unpack_int_rgba_RGB_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3193 {
3194 unsigned int i;
3195
3196 for (i = 0; i < n; i++) {
3197 dst[i][0] = src[i * 3 + 0];
3198 dst[i][1] = src[i * 3 + 1];
3199 dst[i][2] = src[i * 3 + 2];
3200 dst[i][3] = 1;
3201 }
3202 }
3203
3204 static void
3205 unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3206 {
3207 unsigned int i;
3208
3209 for (i = 0; i < n; i++) {
3210 dst[i][0] = src[i * 2 + 0];
3211 dst[i][1] = src[i * 2 + 1];
3212 dst[i][2] = 0;
3213 dst[i][3] = 1;
3214 }
3215 }
3216
3217 static void
3218 unpack_int_rgba_RG_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3219 {
3220 unsigned int i;
3221
3222 for (i = 0; i < n; i++) {
3223 dst[i][0] = src[i * 2 + 0];
3224 dst[i][1] = src[i * 2 + 1];
3225 dst[i][2] = 0;
3226 dst[i][3] = 1;
3227 }
3228 }
3229
3230 static void
3231 unpack_int_rgba_RG_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3232 {
3233 unsigned int i;
3234
3235 for (i = 0; i < n; i++) {
3236 dst[i][0] = src[i * 2 + 0];
3237 dst[i][1] = src[i * 2 + 1];
3238 dst[i][2] = 0;
3239 dst[i][3] = 1;
3240 }
3241 }
3242
3243 static void
3244 unpack_int_rgba_RG_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3245 {
3246 unsigned int i;
3247
3248 for (i = 0; i < n; i++) {
3249 dst[i][0] = src[i * 2 + 0];
3250 dst[i][1] = src[i * 2 + 1];
3251 dst[i][2] = 0;
3252 dst[i][3] = 1;
3253 }
3254 }
3255
3256 static void
3257 unpack_int_rgba_RG_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3258 {
3259 unsigned int i;
3260
3261 for (i = 0; i < n; i++) {
3262 dst[i][0] = src[i * 2 + 0];
3263 dst[i][1] = src[i * 2 + 1];
3264 dst[i][2] = 0;
3265 dst[i][3] = 1;
3266 }
3267 }
3268
3269 static void
3270 unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3271 {
3272 unsigned int i;
3273
3274 for (i = 0; i < n; i++) {
3275 dst[i][0] = src[i];
3276 dst[i][1] = 0;
3277 dst[i][2] = 0;
3278 dst[i][3] = 1;
3279 }
3280 }
3281
3282 static void
3283 unpack_int_rgba_R_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3284 {
3285 unsigned int i;
3286
3287 for (i = 0; i < n; i++) {
3288 dst[i][0] = src[i];
3289 dst[i][1] = 0;
3290 dst[i][2] = 0;
3291 dst[i][3] = 1;
3292 }
3293 }
3294
3295 static void
3296 unpack_int_rgba_R_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3297 {
3298 unsigned int i;
3299
3300 for (i = 0; i < n; i++) {
3301 dst[i][0] = src[i];
3302 dst[i][1] = 0;
3303 dst[i][2] = 0;
3304 dst[i][3] = 1;
3305 }
3306 }
3307
3308 static void
3309 unpack_int_rgba_R_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3310 {
3311 unsigned int i;
3312
3313 for (i = 0; i < n; i++) {
3314 dst[i][0] = src[i];
3315 dst[i][1] = 0;
3316 dst[i][2] = 0;
3317 dst[i][3] = 1;
3318 }
3319 }
3320
3321 static void
3322 unpack_int_rgba_R_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3323 {
3324 unsigned int i;
3325
3326 for (i = 0; i < n; i++) {
3327 dst[i][0] = src[i];
3328 dst[i][1] = 0;
3329 dst[i][2] = 0;
3330 dst[i][3] = 1;
3331 }
3332 }
3333
3334 static void
3335 unpack_int_rgba_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3336 {
3337 unsigned int i;
3338
3339 for (i = 0; i < n; i++) {
3340 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3341 dst[i][3] = src[i];
3342 }
3343 }
3344
3345 static void
3346 unpack_int_rgba_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3347 {
3348 unsigned int i;
3349
3350 for (i = 0; i < n; i++) {
3351 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3352 dst[i][3] = src[i];
3353 }
3354 }
3355
3356 static void
3357 unpack_int_rgba_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3358 {
3359 unsigned int i;
3360
3361 for (i = 0; i < n; i++) {
3362 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3363 dst[i][3] = src[i];
3364 }
3365 }
3366
3367 static void
3368 unpack_int_rgba_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3369 {
3370 unsigned int i;
3371
3372 for (i = 0; i < n; i++) {
3373 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3374 dst[i][3] = src[i];
3375 }
3376 }
3377
3378 static void
3379 unpack_int_rgba_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3380 {
3381 unsigned int i;
3382
3383 for (i = 0; i < n; i++) {
3384 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3385 dst[i][3] = src[i];
3386 }
3387 }
3388
3389 static void
3390 unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3391 {
3392 unsigned int i;
3393
3394 for (i = 0; i < n; i++) {
3395 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3396 dst[i][3] = 1;
3397 }
3398 }
3399
3400 static void
3401 unpack_int_rgba_LUMINANCE_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3402 {
3403 unsigned int i;
3404
3405 for (i = 0; i < n; i++) {
3406 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3407 dst[i][3] = 1;
3408 }
3409 }
3410
3411 static void
3412 unpack_int_rgba_LUMINANCE_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3413 {
3414 unsigned int i;
3415
3416 for (i = 0; i < n; i++) {
3417 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3418 dst[i][3] = 1;
3419 }
3420 }
3421
3422 static void
3423 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3424 {
3425 unsigned int i;
3426
3427 for (i = 0; i < n; i++) {
3428 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3429 dst[i][3] = 1;
3430 }
3431 }
3432
3433 static void
3434 unpack_int_rgba_LUMINANCE_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3435 {
3436 unsigned int i;
3437
3438 for (i = 0; i < n; i++) {
3439 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3440 dst[i][3] = 1;
3441 }
3442 }
3443
3444
3445 static void
3446 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3447 {
3448 unsigned int i;
3449
3450 for (i = 0; i < n; i++) {
3451 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3452 dst[i][3] = src[i * 2 + 1];
3453 }
3454 }
3455
3456 static void
3457 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3458 {
3459 unsigned int i;
3460
3461 for (i = 0; i < n; i++) {
3462 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3463 dst[i][3] = src[i * 2 + 1];
3464 }
3465 }
3466
3467 static void
3468 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3469 {
3470 unsigned int i;
3471
3472 for (i = 0; i < n; i++) {
3473 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3474 dst[i][3] = src[i * 2 + 1];
3475 }
3476 }
3477
3478 static void
3479 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3480 {
3481 unsigned int i;
3482
3483 for (i = 0; i < n; i++) {
3484 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3485 dst[i][3] = src[i * 2 + 1];
3486 }
3487 }
3488
3489 static void
3490 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3491 {
3492 unsigned int i;
3493
3494 for (i = 0; i < n; i++) {
3495 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3496 dst[i][3] = src[i * 2 + 1];
3497 }
3498 }
3499
3500 static void
3501 unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3502 {
3503 unsigned int i;
3504
3505 for (i = 0; i < n; i++) {
3506 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3507 }
3508 }
3509
3510 static void
3511 unpack_int_rgba_INTENSITY_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3512 {
3513 unsigned int i;
3514
3515 for (i = 0; i < n; i++) {
3516 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3517 }
3518 }
3519
3520 static void
3521 unpack_int_rgba_INTENSITY_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3522 {
3523 unsigned int i;
3524
3525 for (i = 0; i < n; i++) {
3526 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3527 }
3528 }
3529
3530 static void
3531 unpack_int_rgba_INTENSITY_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3532 {
3533 unsigned int i;
3534
3535 for (i = 0; i < n; i++) {
3536 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3537 }
3538 }
3539
3540 static void
3541 unpack_int_rgba_INTENSITY_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3542 {
3543 unsigned int i;
3544
3545 for (i = 0; i < n; i++) {
3546 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3547 }
3548 }
3549
3550 static void
3551 unpack_int_rgba_B10G10R10A2_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
3552 {
3553 unsigned int i;
3554
3555 for (i = 0; i < n; i++) {
3556 GLuint tmp = src[i];
3557 dst[i][0] = (tmp >> 20) & 0x3ff;
3558 dst[i][1] = (tmp >> 10) & 0x3ff;
3559 dst[i][2] = (tmp >> 0) & 0x3ff;
3560 dst[i][3] = (tmp >> 30) & 0x3;
3561 }
3562 }
3563
3564 static void
3565 unpack_int_rgba_R10G10B10A2_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
3566 {
3567 unsigned int i;
3568
3569 for (i = 0; i < n; i++) {
3570 GLuint tmp = src[i];
3571 dst[i][0] = (tmp >> 0) & 0x3ff;
3572 dst[i][1] = (tmp >> 10) & 0x3ff;
3573 dst[i][2] = (tmp >> 20) & 0x3ff;
3574 dst[i][3] = (tmp >> 30) & 0x3;
3575 }
3576 }
3577
3578 static void
3579 unpack_int_rgba_B10G10R10A2_UNORM(const GLuint *src, GLuint dst[][4], GLuint n)
3580 {
3581 unsigned int i;
3582
3583 for (i = 0; i < n; i++) {
3584 GLuint tmp = src[i];
3585 dst[i][0] = (tmp >> 20) & 0x3ff;
3586 dst[i][1] = (tmp >> 10) & 0x3ff;
3587 dst[i][2] = (tmp >> 0) & 0x3ff;
3588 dst[i][3] = (tmp >> 30) & 0x3;
3589 }
3590 }
3591
3592 static void
3593 unpack_int_rgba_XBGR8888_UINT(const GLubyte *src, GLuint dst[][4], GLuint n)
3594 {
3595 unsigned int i;
3596
3597 for (i = 0; i < n; i++) {
3598 dst[i][0] = src[i * 4 + 0];
3599 dst[i][1] = src[i * 4 + 1];
3600 dst[i][2] = src[i * 4 + 2];
3601 dst[i][3] = 1;
3602 }
3603 }
3604
3605 static void
3606 unpack_int_rgba_XBGR8888_SINT(const GLbyte *src, GLuint dst[][4], GLuint n)
3607 {
3608 unsigned int i;
3609
3610 for (i = 0; i < n; i++) {
3611 dst[i][0] = src[i * 4 + 0];
3612 dst[i][1] = src[i * 4 + 1];
3613 dst[i][2] = src[i * 4 + 2];
3614 dst[i][3] = 1;
3615 }
3616 }
3617
3618 static void
3619 unpack_int_rgba_XBGR16161616_UINT(const GLushort *src, GLuint dst[][4], GLuint n)
3620 {
3621 unsigned int i;
3622
3623 for (i = 0; i < n; i++) {
3624 dst[i][0] = src[i * 4 + 0];
3625 dst[i][1] = src[i * 4 + 1];
3626 dst[i][2] = src[i * 4 + 2];
3627 dst[i][3] = 1;
3628 }
3629 }
3630
3631 static void
3632 unpack_int_rgba_XBGR16161616_SINT(const GLshort *src, GLuint dst[][4], GLuint n)
3633 {
3634 unsigned int i;
3635
3636 for (i = 0; i < n; i++) {
3637 dst[i][0] = src[i * 4 + 0];
3638 dst[i][1] = src[i * 4 + 1];
3639 dst[i][2] = src[i * 4 + 2];
3640 dst[i][3] = 1;
3641 }
3642 }
3643
3644 static void
3645 unpack_int_rgba_XBGR32323232_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
3646 {
3647 unsigned int i;
3648
3649 for (i = 0; i < n; i++) {
3650 dst[i][0] = src[i * 4 + 0];
3651 dst[i][1] = src[i * 4 + 1];
3652 dst[i][2] = src[i * 4 + 2];
3653 dst[i][3] = 1;
3654 }
3655 }
3656
3657 static void
3658 unpack_int_rgba_R10G10B10A2_UNORM(const GLuint *src, GLuint dst[][4], GLuint n)
3659 {
3660 unsigned int i;
3661
3662 for (i = 0; i < n; i++) {
3663 GLuint tmp = src[i];
3664 dst[i][0] = (tmp >> 0) & 0x3ff;
3665 dst[i][1] = (tmp >> 10) & 0x3ff;
3666 dst[i][2] = (tmp >> 20) & 0x3ff;
3667 dst[i][3] = (tmp >> 30) & 0x3;
3668 }
3669 }
3670
3671 void
3672 _mesa_unpack_uint_rgba_row(mesa_format format, GLuint n,
3673 const void *src, GLuint dst[][4])
3674 {
3675 switch (format) {
3676 /* Since there won't be any sign extension happening, there's no need to
3677 * make separate paths for 32-bit-to-32-bit integer unpack.
3678 */
3679 case MESA_FORMAT_RGBA_UINT32:
3680 case MESA_FORMAT_RGBA_SINT32:
3681 unpack_int_rgba_RGBA_UINT32(src, dst, n);
3682 break;
3683
3684 case MESA_FORMAT_RGBA_UINT16:
3685 unpack_int_rgba_RGBA_UINT16(src, dst, n);
3686 break;
3687 case MESA_FORMAT_RGBA_SINT16:
3688 unpack_int_rgba_RGBA_INT16(src, dst, n);
3689 break;
3690
3691 case MESA_FORMAT_RGBA_UINT8:
3692 unpack_int_rgba_RGBA_UINT8(src, dst, n);
3693 break;
3694 case MESA_FORMAT_RGBA_SINT8:
3695 unpack_int_rgba_RGBA_INT8(src, dst, n);
3696 break;
3697
3698 case MESA_FORMAT_B8G8R8A8_UNORM:
3699 unpack_int_rgba_B8G8R8A8_UNORM(src, dst, n);
3700 break;
3701
3702 case MESA_FORMAT_B8G8R8X8_UNORM:
3703 unpack_int_rgba_B8G8R8X8_UNORM(src, dst, n);
3704 break;
3705
3706 case MESA_FORMAT_RGB_UINT32:
3707 case MESA_FORMAT_RGB_SINT32:
3708 unpack_int_rgba_RGB_UINT32(src, dst, n);
3709 break;
3710
3711 case MESA_FORMAT_RGB_UINT16:
3712 unpack_int_rgba_RGB_UINT16(src, dst, n);
3713 break;
3714 case MESA_FORMAT_RGB_SINT16:
3715 unpack_int_rgba_RGB_INT16(src, dst, n);
3716 break;
3717
3718 case MESA_FORMAT_RGB_UINT8:
3719 unpack_int_rgba_RGB_UINT8(src, dst, n);
3720 break;
3721 case MESA_FORMAT_RGB_SINT8:
3722 unpack_int_rgba_RGB_INT8(src, dst, n);
3723 break;
3724
3725 case MESA_FORMAT_RG_UINT32:
3726 case MESA_FORMAT_RG_SINT32:
3727 unpack_int_rgba_RG_UINT32(src, dst, n);
3728 break;
3729
3730 case MESA_FORMAT_RG_UINT16:
3731 unpack_int_rgba_RG_UINT16(src, dst, n);
3732 break;
3733 case MESA_FORMAT_RG_SINT16:
3734 unpack_int_rgba_RG_INT16(src, dst, n);
3735 break;
3736
3737 case MESA_FORMAT_RG_UINT8:
3738 unpack_int_rgba_RG_UINT8(src, dst, n);
3739 break;
3740 case MESA_FORMAT_RG_SINT8:
3741 unpack_int_rgba_RG_INT8(src, dst, n);
3742 break;
3743
3744 case MESA_FORMAT_R_UINT32:
3745 case MESA_FORMAT_R_SINT32:
3746 unpack_int_rgba_R_UINT32(src, dst, n);
3747 break;
3748
3749 case MESA_FORMAT_R_UINT16:
3750 unpack_int_rgba_R_UINT16(src, dst, n);
3751 break;
3752 case MESA_FORMAT_R_SINT16:
3753 unpack_int_rgba_R_INT16(src, dst, n);
3754 break;
3755
3756 case MESA_FORMAT_R_UINT8:
3757 unpack_int_rgba_R_UINT8(src, dst, n);
3758 break;
3759 case MESA_FORMAT_R_SINT8:
3760 unpack_int_rgba_R_INT8(src, dst, n);
3761 break;
3762
3763 case MESA_FORMAT_A_UINT32:
3764 case MESA_FORMAT_A_SINT32:
3765 unpack_int_rgba_ALPHA_UINT32(src, dst, n);
3766 break;
3767
3768 case MESA_FORMAT_A_UINT16:
3769 unpack_int_rgba_ALPHA_UINT16(src, dst, n);
3770 break;
3771 case MESA_FORMAT_A_SINT16:
3772 unpack_int_rgba_ALPHA_INT16(src, dst, n);
3773 break;
3774
3775 case MESA_FORMAT_A_UINT8:
3776 unpack_int_rgba_ALPHA_UINT8(src, dst, n);
3777 break;
3778 case MESA_FORMAT_A_SINT8:
3779 unpack_int_rgba_ALPHA_INT8(src, dst, n);
3780 break;
3781
3782 case MESA_FORMAT_L_UINT32:
3783 case MESA_FORMAT_L_SINT32:
3784 unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
3785 break;
3786 case MESA_FORMAT_L_UINT16:
3787 unpack_int_rgba_LUMINANCE_UINT16(src, dst, n);
3788 break;
3789 case MESA_FORMAT_L_SINT16:
3790 unpack_int_rgba_LUMINANCE_INT16(src, dst, n);
3791 break;
3792
3793 case MESA_FORMAT_L_UINT8:
3794 unpack_int_rgba_LUMINANCE_UINT8(src, dst, n);
3795 break;
3796 case MESA_FORMAT_L_SINT8:
3797 unpack_int_rgba_LUMINANCE_INT8(src, dst, n);
3798 break;
3799
3800 case MESA_FORMAT_LA_UINT32:
3801 case MESA_FORMAT_LA_SINT32:
3802 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
3803 break;
3804
3805 case MESA_FORMAT_LA_UINT16:
3806 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src, dst, n);
3807 break;
3808 case MESA_FORMAT_LA_SINT16:
3809 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src, dst, n);
3810 break;
3811
3812 case MESA_FORMAT_LA_UINT8:
3813 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src, dst, n);
3814 break;
3815 case MESA_FORMAT_LA_SINT8:
3816 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src, dst, n);
3817 break;
3818
3819 case MESA_FORMAT_I_UINT32:
3820 case MESA_FORMAT_I_SINT32:
3821 unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
3822 break;
3823
3824 case MESA_FORMAT_I_UINT16:
3825 unpack_int_rgba_INTENSITY_UINT16(src, dst, n);
3826 break;
3827 case MESA_FORMAT_I_SINT16:
3828 unpack_int_rgba_INTENSITY_INT16(src, dst, n);
3829 break;
3830
3831 case MESA_FORMAT_I_UINT8:
3832 unpack_int_rgba_INTENSITY_UINT8(src, dst, n);
3833 break;
3834 case MESA_FORMAT_I_SINT8:
3835 unpack_int_rgba_INTENSITY_INT8(src, dst, n);
3836 break;
3837
3838 case MESA_FORMAT_B10G10R10A2_UINT:
3839 unpack_int_rgba_B10G10R10A2_UINT(src, dst, n);
3840 break;
3841
3842 case MESA_FORMAT_R10G10B10A2_UINT:
3843 unpack_int_rgba_R10G10B10A2_UINT(src, dst, n);
3844 break;
3845
3846 case MESA_FORMAT_B10G10R10A2_UNORM:
3847 unpack_int_rgba_B10G10R10A2_UNORM(src, dst, n);
3848 break;
3849
3850 case MESA_FORMAT_RGBX_UINT8:
3851 unpack_int_rgba_XBGR8888_UINT(src, dst, n);
3852 break;
3853
3854 case MESA_FORMAT_RGBX_SINT8:
3855 unpack_int_rgba_XBGR8888_SINT(src, dst, n);
3856 break;
3857
3858 case MESA_FORMAT_RGBX_UINT16:
3859 unpack_int_rgba_XBGR16161616_UINT(src, dst, n);
3860 break;
3861
3862 case MESA_FORMAT_RGBX_SINT16:
3863 unpack_int_rgba_XBGR16161616_SINT(src, dst, n);
3864 break;
3865
3866 case MESA_FORMAT_RGBX_UINT32:
3867 case MESA_FORMAT_RGBX_SINT32:
3868 unpack_int_rgba_XBGR32323232_UINT(src, dst, n);
3869 break;
3870
3871 case MESA_FORMAT_R10G10B10A2_UNORM:
3872 unpack_int_rgba_R10G10B10A2_UNORM(src, dst, n);
3873 break;
3874
3875 default:
3876 _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
3877 _mesa_get_format_name(format));
3878 return;
3879 }
3880 }
3881
3882 /**
3883 * Unpack a 2D rect of pixels returning float RGBA colors.
3884 * \param format the source image format
3885 * \param src start address of the source image
3886 * \param srcRowStride source image row stride in bytes
3887 * \param dst start address of the dest image
3888 * \param dstRowStride dest image row stride in bytes
3889 * \param x source image start X pos
3890 * \param y source image start Y pos
3891 * \param width width of rect region to convert
3892 * \param height height of rect region to convert
3893 */
3894 void
3895 _mesa_unpack_rgba_block(mesa_format format,
3896 const void *src, GLint srcRowStride,
3897 GLfloat dst[][4], GLint dstRowStride,
3898 GLuint x, GLuint y, GLuint width, GLuint height)
3899 {
3900 unpack_rgba_func unpack = get_unpack_rgba_function(format);
3901 const GLuint srcPixStride = _mesa_get_format_bytes(format);
3902 const GLuint dstPixStride = 4 * sizeof(GLfloat);
3903 const GLubyte *srcRow;
3904 GLubyte *dstRow;
3905 GLuint i;
3906
3907 /* XXX needs to be fixed for compressed formats */
3908
3909 srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
3910 dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
3911
3912 for (i = 0; i < height; i++) {
3913 unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
3914
3915 dstRow += dstRowStride;
3916 srcRow += srcRowStride;
3917 }
3918 }
3919
3920
3921
3922
3923 typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
3924
3925 static void
3926 unpack_float_z_X8_UINT_Z24_UNORM(GLuint n, const void *src, GLfloat *dst)
3927 {
3928 /* only return Z, not stencil data */
3929 const GLuint *s = ((const GLuint *) src);
3930 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
3931 GLuint i;
3932 for (i = 0; i < n; i++) {
3933 dst[i] = (GLfloat) ((s[i] >> 8) * scale);
3934 ASSERT(dst[i] >= 0.0F);
3935 ASSERT(dst[i] <= 1.0F);
3936 }
3937 }
3938
3939 static void
3940 unpack_float_z_Z24_UNORM_X8_UINT(GLuint n, const void *src, GLfloat *dst)
3941 {
3942 /* only return Z, not stencil data */
3943 const GLuint *s = ((const GLuint *) src);
3944 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
3945 GLuint i;
3946 for (i = 0; i < n; i++) {
3947 dst[i] = (GLfloat) ((s[i] & 0x00ffffff) * scale);
3948 ASSERT(dst[i] >= 0.0F);
3949 ASSERT(dst[i] <= 1.0F);
3950 }
3951 }
3952
3953 static void
3954 unpack_float_Z_UNORM16(GLuint n, const void *src, GLfloat *dst)
3955 {
3956 const GLushort *s = ((const GLushort *) src);
3957 GLuint i;
3958 for (i = 0; i < n; i++) {
3959 dst[i] = s[i] * (1.0F / 65535.0F);
3960 }
3961 }
3962
3963 static void
3964 unpack_float_Z_UNORM32(GLuint n, const void *src, GLfloat *dst)
3965 {
3966 const GLuint *s = ((const GLuint *) src);
3967 GLuint i;
3968 for (i = 0; i < n; i++) {
3969 dst[i] = s[i] * (1.0F / 0xffffffff);
3970 }
3971 }
3972
3973 static void
3974 unpack_float_Z_FLOAT32(GLuint n, const void *src, GLfloat *dst)
3975 {
3976 memcpy(dst, src, n * sizeof(float));
3977 }
3978
3979 static void
3980 unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
3981 {
3982 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
3983 GLuint i;
3984 for (i = 0; i < n; i++) {
3985 dst[i] = s[i].z;
3986 }
3987 }
3988
3989
3990
3991 /**
3992 * Unpack Z values.
3993 * The returned values will always be in the range [0.0, 1.0].
3994 */
3995 void
3996 _mesa_unpack_float_z_row(mesa_format format, GLuint n,
3997 const void *src, GLfloat *dst)
3998 {
3999 unpack_float_z_func unpack;
4000
4001 switch (format) {
4002 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4003 case MESA_FORMAT_X8_UINT_Z24_UNORM:
4004 unpack = unpack_float_z_X8_UINT_Z24_UNORM;
4005 break;
4006 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4007 case MESA_FORMAT_Z24_UNORM_X8_UINT:
4008 unpack = unpack_float_z_Z24_UNORM_X8_UINT;
4009 break;
4010 case MESA_FORMAT_Z_UNORM16:
4011 unpack = unpack_float_Z_UNORM16;
4012 break;
4013 case MESA_FORMAT_Z_UNORM32:
4014 unpack = unpack_float_Z_UNORM32;
4015 break;
4016 case MESA_FORMAT_Z_FLOAT32:
4017 unpack = unpack_float_Z_FLOAT32;
4018 break;
4019 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4020 unpack = unpack_float_z_Z32X24S8;
4021 break;
4022 default:
4023 _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
4024 _mesa_get_format_name(format));
4025 return;
4026 }
4027
4028 unpack(n, src, dst);
4029 }
4030
4031
4032
4033 typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
4034
4035 static void
4036 unpack_uint_z_X8_UINT_Z24_UNORM(const void *src, GLuint *dst, GLuint n)
4037 {
4038 /* only return Z, not stencil data */
4039 const GLuint *s = ((const GLuint *) src);
4040 GLuint i;
4041 for (i = 0; i < n; i++) {
4042 dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
4043 }
4044 }
4045
4046 static void
4047 unpack_uint_z_Z24_UNORM_X8_UINT(const void *src, GLuint *dst, GLuint n)
4048 {
4049 /* only return Z, not stencil data */
4050 const GLuint *s = ((const GLuint *) src);
4051 GLuint i;
4052 for (i = 0; i < n; i++) {
4053 dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
4054 }
4055 }
4056
4057 static void
4058 unpack_uint_Z_UNORM16(const void *src, GLuint *dst, GLuint n)
4059 {
4060 const GLushort *s = ((const GLushort *)src);
4061 GLuint i;
4062 for (i = 0; i < n; i++) {
4063 dst[i] = (s[i] << 16) | s[i];
4064 }
4065 }
4066
4067 static void
4068 unpack_uint_Z_UNORM32(const void *src, GLuint *dst, GLuint n)
4069 {
4070 memcpy(dst, src, n * sizeof(GLuint));
4071 }
4072
4073 static void
4074 unpack_uint_Z_FLOAT32(const void *src, GLuint *dst, GLuint n)
4075 {
4076 const float *s = (const float *)src;
4077 GLuint i;
4078 for (i = 0; i < n; i++) {
4079 dst[i] = FLOAT_TO_UINT(CLAMP(s[i], 0.0F, 1.0F));
4080 }
4081 }
4082
4083 static void
4084 unpack_uint_Z_FLOAT32_X24S8(const void *src, GLuint *dst, GLuint n)
4085 {
4086 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
4087 GLuint i;
4088
4089 for (i = 0; i < n; i++) {
4090 dst[i] = FLOAT_TO_UINT(CLAMP(s[i].z, 0.0F, 1.0F));
4091 }
4092 }
4093
4094
4095 /**
4096 * Unpack Z values.
4097 * The returned values will always be in the range [0, 0xffffffff].
4098 */
4099 void
4100 _mesa_unpack_uint_z_row(mesa_format format, GLuint n,
4101 const void *src, GLuint *dst)
4102 {
4103 unpack_uint_z_func unpack;
4104 const GLubyte *srcPtr = (GLubyte *) src;
4105
4106 switch (format) {
4107 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4108 case MESA_FORMAT_X8_UINT_Z24_UNORM:
4109 unpack = unpack_uint_z_X8_UINT_Z24_UNORM;
4110 break;
4111 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4112 case MESA_FORMAT_Z24_UNORM_X8_UINT:
4113 unpack = unpack_uint_z_Z24_UNORM_X8_UINT;
4114 break;
4115 case MESA_FORMAT_Z_UNORM16:
4116 unpack = unpack_uint_Z_UNORM16;
4117 break;
4118 case MESA_FORMAT_Z_UNORM32:
4119 unpack = unpack_uint_Z_UNORM32;
4120 break;
4121 case MESA_FORMAT_Z_FLOAT32:
4122 unpack = unpack_uint_Z_FLOAT32;
4123 break;
4124 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4125 unpack = unpack_uint_Z_FLOAT32_X24S8;
4126 break;
4127 default:
4128 _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
4129 _mesa_get_format_name(format));
4130 return;
4131 }
4132
4133 unpack(srcPtr, dst, n);
4134 }
4135
4136
4137 static void
4138 unpack_ubyte_s_S_UINT8(const void *src, GLubyte *dst, GLuint n)
4139 {
4140 memcpy(dst, src, n);
4141 }
4142
4143 static void
4144 unpack_ubyte_s_S8_UINT_Z24_UNORM(const void *src, GLubyte *dst, GLuint n)
4145 {
4146 GLuint i;
4147 const GLuint *src32 = src;
4148
4149 for (i = 0; i < n; i++)
4150 dst[i] = src32[i] & 0xff;
4151 }
4152
4153 static void
4154 unpack_ubyte_s_Z24_UNORM_S8_UINT(const void *src, GLubyte *dst, GLuint n)
4155 {
4156 GLuint i;
4157 const GLuint *src32 = src;
4158
4159 for (i = 0; i < n; i++)
4160 dst[i] = src32[i] >> 24;
4161 }
4162
4163 static void
4164 unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(const void *src, GLubyte *dst, GLuint n)
4165 {
4166 GLuint i;
4167 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
4168
4169 for (i = 0; i < n; i++)
4170 dst[i] = s[i].x24s8 & 0xff;
4171 }
4172
4173 void
4174 _mesa_unpack_ubyte_stencil_row(mesa_format format, GLuint n,
4175 const void *src, GLubyte *dst)
4176 {
4177 switch (format) {
4178 case MESA_FORMAT_S_UINT8:
4179 unpack_ubyte_s_S_UINT8(src, dst, n);
4180 break;
4181 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4182 unpack_ubyte_s_S8_UINT_Z24_UNORM(src, dst, n);
4183 break;
4184 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4185 unpack_ubyte_s_Z24_UNORM_S8_UINT(src, dst, n);
4186 break;
4187 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4188 unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(src, dst, n);
4189 break;
4190 default:
4191 _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
4192 _mesa_get_format_name(format));
4193 return;
4194 }
4195 }
4196
4197 static void
4198 unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(const GLuint *src, GLuint *dst, GLuint n)
4199 {
4200 GLuint i;
4201
4202 for (i = 0; i < n; i++) {
4203 GLuint val = src[i];
4204 dst[i] = val >> 24 | val << 8;
4205 }
4206 }
4207
4208 static void
4209 unpack_uint_24_8_depth_stencil_Z32_S8X24(const GLuint *src,
4210 GLuint *dst, GLuint n)
4211 {
4212 GLuint i;
4213
4214 for (i = 0; i < n; i++) {
4215 /* 8 bytes per pixel (float + uint32) */
4216 GLfloat zf = ((GLfloat *) src)[i * 2 + 0];
4217 GLuint z24 = (GLuint) (zf * (GLfloat) 0xffffff);
4218 GLuint s = src[i * 2 + 1] & 0xff;
4219 dst[i] = (z24 << 8) | s;
4220 }
4221 }
4222
4223 static void
4224 unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(const GLuint *src, GLuint *dst, GLuint n)
4225 {
4226 memcpy(dst, src, n * 4);
4227 }
4228
4229 /**
4230 * Unpack depth/stencil returning as GL_UNSIGNED_INT_24_8.
4231 * \param format the source data format
4232 */
4233 void
4234 _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
4235 const void *src, GLuint *dst)
4236 {
4237 switch (format) {
4238 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4239 unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(src, dst, n);
4240 break;
4241 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4242 unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(src, dst, n);
4243 break;
4244 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4245 unpack_uint_24_8_depth_stencil_Z32_S8X24(src, dst, n);
4246 break;
4247 default:
4248 _mesa_problem(NULL,
4249 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
4250 _mesa_get_format_name(format));
4251 return;
4252 }
4253 }
4254
4255 static void
4256 unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(const GLuint *src,
4257 GLuint *dst, GLuint n)
4258 {
4259 GLuint i;
4260 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
4261 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
4262
4263 for (i = 0; i < n; i++) {
4264 const GLuint z24 = src[i] & 0xffffff;
4265 d[i].z = z24 * scale;
4266 d[i].x24s8 = src[i] >> 24;
4267 assert(d[i].z >= 0.0f);
4268 assert(d[i].z <= 1.0f);
4269 }
4270 }
4271
4272 static void
4273 unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(const GLuint *src,
4274 GLuint *dst, GLuint n)
4275 {
4276 memcpy(dst, src, n * sizeof(struct z32f_x24s8));
4277 }
4278
4279 static void
4280 unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(const GLuint *src,
4281 GLuint *dst, GLuint n)
4282 {
4283 GLuint i;
4284 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
4285 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
4286
4287 for (i = 0; i < n; i++) {
4288 const GLuint z24 = src[i] >> 8;
4289 d[i].z = z24 * scale;
4290 d[i].x24s8 = src[i] & 0xff;
4291 assert(d[i].z >= 0.0f);
4292 assert(d[i].z <= 1.0f);
4293 }
4294 }
4295
4296 /**
4297 * Unpack depth/stencil returning as GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
4298 * \param format the source data format
4299 *
4300 * In GL_FLOAT_32_UNSIGNED_INT_24_8_REV lower 4 bytes contain float
4301 * component and higher 4 bytes contain packed 24-bit and 8-bit
4302 * components.
4303 *
4304 * 31 30 29 28 ... 4 3 2 1 0 31 30 29 ... 9 8 7 6 5 ... 2 1 0
4305 * +-------------------------+ +--------------------------------+
4306 * | Float Component | | Unused | 8 bit stencil |
4307 * +-------------------------+ +--------------------------------+
4308 * lower 4 bytes higher 4 bytes
4309 */
4310 void
4311 _mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
4312 const void *src, GLuint *dst)
4313 {
4314 switch (format) {
4315 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4316 unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(src, dst, n);
4317 break;
4318 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4319 unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(src, dst, n);
4320 break;
4321 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4322 unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(src, dst, n);
4323 break;
4324 default:
4325 _mesa_problem(NULL,
4326 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
4327 _mesa_get_format_name(format));
4328 return;
4329 }
4330 }
4331
4332 /**
4333 * Unpack depth/stencil
4334 * \param format the source data format
4335 * \param type the destination data type
4336 */
4337 void
4338 _mesa_unpack_depth_stencil_row(mesa_format format, GLuint n,
4339 const void *src, GLenum type,
4340 GLuint *dst)
4341 {
4342 assert(type == GL_UNSIGNED_INT_24_8 ||
4343 type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
4344
4345 switch (type) {
4346 case GL_UNSIGNED_INT_24_8:
4347 _mesa_unpack_uint_24_8_depth_stencil_row(format, n, src, dst);
4348 break;
4349 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
4350 _mesa_unpack_float_32_uint_24_8_depth_stencil_row(format, n, src, dst);
4351 break;
4352 default:
4353 _mesa_problem(NULL,
4354 "bad type 0x%x in _mesa_unpack_depth_stencil_row",
4355 type);
4356 return;
4357 }
4358 }