mesa/main: Use the RGB <-> sRGB conversion functions in libmesautil
[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_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
813 {
814 }
815
816 static void
817 unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
818 {
819 }
820
821 static void
822 unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
823 {
824 }
825
826 static void
827 unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
828 {
829 }
830
831 static void
832 unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
833 {
834 }
835
836 static void
837 unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
838 {
839 }
840
841 static void
842 unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
843 {
844 }
845
846 static void
847 unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
848 {
849 }
850
851 static void
852 unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
853 {
854 }
855
856 static void
857 unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
858 {
859 }
860
861
862 static void
863 unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
864 {
865 const GLfloat *s = (const GLfloat *) src;
866 GLuint i;
867 for (i = 0; i < n; i++) {
868 dst[i][RCOMP] = s[i*4+0];
869 dst[i][GCOMP] = s[i*4+1];
870 dst[i][BCOMP] = s[i*4+2];
871 dst[i][ACOMP] = s[i*4+3];
872 }
873 }
874
875 static void
876 unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
877 {
878 const GLhalfARB *s = (const GLhalfARB *) src;
879 GLuint i;
880 for (i = 0; i < n; i++) {
881 dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
882 dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
883 dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
884 dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
885 }
886 }
887
888 static void
889 unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
890 {
891 const GLfloat *s = (const GLfloat *) src;
892 GLuint i;
893 for (i = 0; i < n; i++) {
894 dst[i][RCOMP] = s[i*3+0];
895 dst[i][GCOMP] = s[i*3+1];
896 dst[i][BCOMP] = s[i*3+2];
897 dst[i][ACOMP] = 1.0F;
898 }
899 }
900
901 static void
902 unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
903 {
904 const GLhalfARB *s = (const GLhalfARB *) src;
905 GLuint i;
906 for (i = 0; i < n; i++) {
907 dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]);
908 dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
909 dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
910 dst[i][ACOMP] = 1.0F;
911 }
912 }
913
914 static void
915 unpack_A_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
916 {
917 const GLfloat *s = (const GLfloat *) src;
918 GLuint i;
919 for (i = 0; i < n; i++) {
920 dst[i][RCOMP] =
921 dst[i][GCOMP] =
922 dst[i][BCOMP] = 0.0F;
923 dst[i][ACOMP] = s[i];
924 }
925 }
926
927 static void
928 unpack_A_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
929 {
930 const GLhalfARB *s = (const GLhalfARB *) 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] = _mesa_half_to_float(s[i]);
937 }
938 }
939
940 static void
941 unpack_L_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
942 {
943 const GLfloat *s = (const GLfloat *) src;
944 GLuint i;
945 for (i = 0; i < n; i++) {
946 dst[i][RCOMP] =
947 dst[i][GCOMP] =
948 dst[i][BCOMP] = s[i];
949 dst[i][ACOMP] = 1.0F;
950 }
951 }
952
953 static void
954 unpack_L_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
955 {
956 const GLhalfARB *s = (const GLhalfARB *) src;
957 GLuint i;
958 for (i = 0; i < n; i++) {
959 dst[i][RCOMP] =
960 dst[i][GCOMP] =
961 dst[i][BCOMP] = _mesa_half_to_float(s[i]);
962 dst[i][ACOMP] = 1.0F;
963 }
964 }
965
966 static void
967 unpack_LA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
968 {
969 const GLfloat *s = (const GLfloat *) src;
970 GLuint i;
971 for (i = 0; i < n; i++) {
972 dst[i][RCOMP] =
973 dst[i][GCOMP] =
974 dst[i][BCOMP] = s[i*2+0];
975 dst[i][ACOMP] = s[i*2+1];
976 }
977 }
978
979 static void
980 unpack_LA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
981 {
982 const GLhalfARB *s = (const GLhalfARB *) src;
983 GLuint i;
984 for (i = 0; i < n; i++) {
985 dst[i][RCOMP] =
986 dst[i][GCOMP] =
987 dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
988 dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
989 }
990 }
991
992 static void
993 unpack_I_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
994 {
995 const GLfloat *s = (const GLfloat *) src;
996 GLuint i;
997 for (i = 0; i < n; i++) {
998 dst[i][RCOMP] =
999 dst[i][GCOMP] =
1000 dst[i][BCOMP] =
1001 dst[i][ACOMP] = s[i];
1002 }
1003 }
1004
1005 static void
1006 unpack_I_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1007 {
1008 const GLhalfARB *s = (const GLhalfARB *) 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] = _mesa_half_to_float(s[i]);
1015 }
1016 }
1017
1018 static void
1019 unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1020 {
1021 const GLfloat *s = (const GLfloat *) src;
1022 GLuint i;
1023 for (i = 0; i < n; i++) {
1024 dst[i][RCOMP] = s[i];
1025 dst[i][GCOMP] = 0.0F;
1026 dst[i][BCOMP] = 0.0F;
1027 dst[i][ACOMP] = 1.0F;
1028 }
1029 }
1030
1031 static void
1032 unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1033 {
1034 const GLhalfARB *s = (const GLhalfARB *) src;
1035 GLuint i;
1036 for (i = 0; i < n; i++) {
1037 dst[i][RCOMP] = _mesa_half_to_float(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_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1046 {
1047 const GLfloat *s = (const GLfloat *) src;
1048 GLuint i;
1049 for (i = 0; i < n; i++) {
1050 dst[i][RCOMP] = s[i*2+0];
1051 dst[i][GCOMP] = s[i*2+1];
1052 dst[i][BCOMP] = 0.0F;
1053 dst[i][ACOMP] = 1.0F;
1054 }
1055 }
1056
1057 static void
1058 unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1059 {
1060 const GLhalfARB *s = (const GLhalfARB *) src;
1061 GLuint i;
1062 for (i = 0; i < n; i++) {
1063 dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
1064 dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
1065 dst[i][BCOMP] = 0.0F;
1066 dst[i][ACOMP] = 1.0F;
1067 }
1068 }
1069
1070 static void
1071 unpack_ALPHA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1072 {
1073 const GLubyte *s = (const GLubyte *) src;
1074 GLuint i;
1075 for (i = 0; i < n; i++) {
1076 dst[i][RCOMP] =
1077 dst[i][GCOMP] =
1078 dst[i][BCOMP] = 0.0;
1079 dst[i][ACOMP] = (GLfloat) s[i];
1080 }
1081 }
1082
1083 static void
1084 unpack_ALPHA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1085 {
1086 const GLushort *s = (const GLushort *) 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_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1098 {
1099 const GLuint *s = (const GLuint *) 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_INT8(const void *src, GLfloat dst[][4], GLuint n)
1111 {
1112 const GLbyte *s = (const GLbyte *) 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_INT16(const void *src, GLfloat dst[][4], GLuint n)
1124 {
1125 const GLshort *s = (const GLshort *) 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_INT32(const void *src, GLfloat dst[][4], GLuint n)
1137 {
1138 const GLint *s = (const GLint *) 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_INTENSITY_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1150 {
1151 const GLubyte *s = (const GLubyte *) src;
1152 GLuint i;
1153 for (i = 0; i < n; i++) {
1154 dst[i][RCOMP] =
1155 dst[i][GCOMP] =
1156 dst[i][BCOMP] =
1157 dst[i][ACOMP] = (GLfloat) s[i];
1158 }
1159 }
1160
1161 static void
1162 unpack_INTENSITY_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1163 {
1164 const GLushort *s = (const GLushort *) 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_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1176 {
1177 const GLuint *s = (const GLuint *) 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_INT8(const void *src, GLfloat dst[][4], GLuint n)
1189 {
1190 const GLbyte *s = (const GLbyte *) 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_INT16(const void *src, GLfloat dst[][4], GLuint n)
1202 {
1203 const GLshort *s = (const GLshort *) 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_INT32(const void *src, GLfloat dst[][4], GLuint n)
1215 {
1216 const GLint *s = (const GLint *) 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_LUMINANCE_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1228 {
1229 const GLubyte *s = (const GLubyte *) src;
1230 GLuint i;
1231 for (i = 0; i < n; i++) {
1232 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1233 dst[i][ACOMP] = 1.0;
1234 }
1235 }
1236
1237 static void
1238 unpack_LUMINANCE_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1239 {
1240 const GLushort *s = (const GLushort *) src;
1241 GLuint i;
1242 for (i = 0; i < n; i++) {
1243 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1244 dst[i][ACOMP] = 1.0;
1245 }
1246 }
1247
1248 static void
1249 unpack_LUMINANCE_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1250 {
1251 const GLuint *s = (const GLuint *) src;
1252 GLuint i;
1253 for (i = 0; i < n; i++) {
1254 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1255 dst[i][ACOMP] = 1.0;
1256 }
1257 }
1258
1259 static void
1260 unpack_LUMINANCE_INT8(const void *src, GLfloat dst[][4], GLuint n)
1261 {
1262 const GLbyte *s = (const GLbyte *) src;
1263 GLuint i;
1264 for (i = 0; i < n; i++) {
1265 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1266 dst[i][ACOMP] = 1.0;
1267 }
1268 }
1269
1270 static void
1271 unpack_LUMINANCE_INT16(const void *src, GLfloat dst[][4], GLuint n)
1272 {
1273 const GLshort *s = (const GLshort *) src;
1274 GLuint i;
1275 for (i = 0; i < n; i++) {
1276 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1277 dst[i][ACOMP] = 1.0;
1278 }
1279 }
1280
1281 static void
1282 unpack_LUMINANCE_INT32(const void *src, GLfloat dst[][4], GLuint n)
1283 {
1284 const GLint *s = (const GLint *) src;
1285 GLuint i;
1286 for (i = 0; i < n; i++) {
1287 dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
1288 dst[i][ACOMP] = 1.0;
1289 }
1290 }
1291
1292 static void
1293 unpack_LUMINANCE_ALPHA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1294 {
1295 const GLubyte *s = (const GLubyte *) src;
1296 GLuint i;
1297 for (i = 0; i < n; i++) {
1298 dst[i][RCOMP] =
1299 dst[i][GCOMP] =
1300 dst[i][BCOMP] = (GLfloat) s[2*i+0];
1301 dst[i][ACOMP] = (GLfloat) s[2*i+1];
1302 }
1303 }
1304
1305 static void
1306 unpack_LUMINANCE_ALPHA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1307 {
1308 const GLushort *s = (const GLushort *) 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_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1320 {
1321 const GLuint *s = (const GLuint *) 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_INT8(const void *src, GLfloat dst[][4], GLuint n)
1333 {
1334 const GLbyte *s = (const GLbyte *) 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_INT16(const void *src, GLfloat dst[][4], GLuint n)
1346 {
1347 const GLshort *s = (const GLshort *) 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_INT32(const void *src, GLfloat dst[][4], GLuint n)
1359 {
1360 const GLint *s = (const GLint *) 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_R_INT8(const void *src, GLfloat dst[][4], GLuint n)
1372 {
1373 const GLbyte *s = (const GLbyte *) src;
1374 GLuint i;
1375 for (i = 0; i < n; i++) {
1376 dst[i][RCOMP] = (GLfloat) s[i];
1377 dst[i][GCOMP] = 0.0;
1378 dst[i][BCOMP] = 0.0;
1379 dst[i][ACOMP] = 1.0;
1380 }
1381 }
1382
1383 static void
1384 unpack_RG_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*2+0];
1390 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1391 dst[i][BCOMP] = 0.0;
1392 dst[i][ACOMP] = 1.0;
1393 }
1394 }
1395
1396 static void
1397 unpack_RGB_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*3+0];
1403 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1404 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1405 dst[i][ACOMP] = 1.0;
1406 }
1407 }
1408
1409 static void
1410 unpack_RGBA_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*4+0];
1416 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1417 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1418 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1419 }
1420 }
1421
1422 static void
1423 unpack_R_INT16(const void *src, GLfloat dst[][4], GLuint n)
1424 {
1425 const GLshort *s = (const GLshort *) src;
1426 GLuint i;
1427 for (i = 0; i < n; i++) {
1428 dst[i][RCOMP] = (GLfloat) s[i];
1429 dst[i][GCOMP] = 0.0;
1430 dst[i][BCOMP] = 0.0;
1431 dst[i][ACOMP] = 1.0;
1432 }
1433 }
1434
1435 static void
1436 unpack_RG_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*2+0];
1442 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1443 dst[i][BCOMP] = 0.0;
1444 dst[i][ACOMP] = 1.0;
1445 }
1446 }
1447
1448 static void
1449 unpack_RGB_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*3+0];
1455 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1456 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1457 dst[i][ACOMP] = 1.0;
1458 }
1459 }
1460
1461 static void
1462 unpack_RGBA_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*4+0];
1468 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1469 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1470 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1471 }
1472 }
1473
1474 static void
1475 unpack_R_INT32(const void *src, GLfloat dst[][4], GLuint n)
1476 {
1477 const GLint *s = (const GLint *) src;
1478 GLuint i;
1479 for (i = 0; i < n; i++) {
1480 dst[i][RCOMP] = (GLfloat) s[i];
1481 dst[i][GCOMP] = 0.0;
1482 dst[i][BCOMP] = 0.0;
1483 dst[i][ACOMP] = 1.0;
1484 }
1485 }
1486
1487 static void
1488 unpack_RG_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*2+0];
1494 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1495 dst[i][BCOMP] = 0.0;
1496 dst[i][ACOMP] = 1.0;
1497 }
1498 }
1499
1500 static void
1501 unpack_RGB_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*3+0];
1507 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1508 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1509 dst[i][ACOMP] = 1.0;
1510 }
1511 }
1512
1513
1514 static void
1515 unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1516 {
1517 const GLint *s = (const GLint *) src;
1518 GLuint i;
1519 for (i = 0; i < n; i++) {
1520 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1521 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1522 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1523 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1524 }
1525 }
1526
1527 static void
1528 unpack_R_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1529 {
1530 const GLubyte *s = (const GLubyte *) src;
1531 GLuint i;
1532 for (i = 0; i < n; i++) {
1533 dst[i][RCOMP] = (GLfloat) s[i];
1534 dst[i][GCOMP] = 0.0;
1535 dst[i][BCOMP] = 0.0;
1536 dst[i][ACOMP] = 1.0;
1537 }
1538 }
1539
1540 static void
1541 unpack_RG_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*2+0];
1547 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1548 dst[i][BCOMP] = 0.0;
1549 dst[i][ACOMP] = 1.0;
1550 }
1551 }
1552
1553 static void
1554 unpack_RGB_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*3+0];
1560 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1561 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1562 dst[i][ACOMP] = 1.0;
1563 }
1564 }
1565
1566 static void
1567 unpack_RGBA_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*4+0];
1573 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1574 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1575 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1576 }
1577 }
1578
1579 static void
1580 unpack_R_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1581 {
1582 const GLushort *s = (const GLushort *) src;
1583 GLuint i;
1584 for (i = 0; i < n; i++) {
1585 dst[i][RCOMP] = (GLfloat) s[i];
1586 dst[i][GCOMP] = 0.0;
1587 dst[i][BCOMP] = 0.0;
1588 dst[i][ACOMP] = 1.0;
1589 }
1590 }
1591
1592 static void
1593 unpack_RG_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*2+0];
1599 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1600 dst[i][BCOMP] = 0.0;
1601 dst[i][ACOMP] = 1.0;
1602 }
1603 }
1604
1605 static void
1606 unpack_RGB_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*3+0];
1612 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1613 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1614 dst[i][ACOMP] = 1.0;
1615 }
1616 }
1617
1618 static void
1619 unpack_RGBA_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*4+0];
1625 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1626 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1627 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1628 }
1629 }
1630
1631 static void
1632 unpack_R_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1633 {
1634 const GLuint *s = (const GLuint *) src;
1635 GLuint i;
1636 for (i = 0; i < n; i++) {
1637 dst[i][RCOMP] = (GLfloat) s[i];
1638 dst[i][GCOMP] = 0.0;
1639 dst[i][BCOMP] = 0.0;
1640 dst[i][ACOMP] = 1.0;
1641 }
1642 }
1643
1644 static void
1645 unpack_RG_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*2+0];
1651 dst[i][GCOMP] = (GLfloat) s[i*2+1];
1652 dst[i][BCOMP] = 0.0;
1653 dst[i][ACOMP] = 1.0;
1654 }
1655 }
1656
1657 static void
1658 unpack_RGB_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*3+0];
1664 dst[i][GCOMP] = (GLfloat) s[i*3+1];
1665 dst[i][BCOMP] = (GLfloat) s[i*3+2];
1666 dst[i][ACOMP] = 1.0;
1667 }
1668 }
1669
1670 static void
1671 unpack_RGBA_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*4+0];
1677 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1678 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1679 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1680 }
1681 }
1682
1683 static void
1684 unpack_R_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
1685 {
1686 const GLbyte *s = ((const GLbyte *) src);
1687 GLuint i;
1688 for (i = 0; i < n; i++) {
1689 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1690 dst[i][GCOMP] = 0.0F;
1691 dst[i][BCOMP] = 0.0F;
1692 dst[i][ACOMP] = 1.0F;
1693 }
1694 }
1695
1696 static void
1697 unpack_R8G8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1698 {
1699 const GLushort *s = ((const GLushort *) src);
1700 GLuint i;
1701 for (i = 0; i < n; i++) {
1702 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1703 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1704 dst[i][BCOMP] = 0.0F;
1705 dst[i][ACOMP] = 1.0F;
1706 }
1707 }
1708
1709 static void
1710 unpack_X8B8G8R8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1711 {
1712 const GLuint *s = ((const GLuint *) src);
1713 GLuint i;
1714 for (i = 0; i < n; i++) {
1715 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1716 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1717 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1718 dst[i][ACOMP] = 1.0f;
1719 }
1720 }
1721
1722 static void
1723 unpack_A8B8G8R8_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] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1732 }
1733 }
1734
1735 static void
1736 unpack_R8G8B8A8_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] ) );
1742 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1743 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1744 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1745 }
1746 }
1747
1748 static void
1749 unpack_R_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
1750 {
1751 const GLshort *s = ((const GLshort *) src);
1752 GLuint i;
1753 for (i = 0; i < n; i++) {
1754 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1755 dst[i][GCOMP] = 0.0F;
1756 dst[i][BCOMP] = 0.0F;
1757 dst[i][ACOMP] = 1.0F;
1758 }
1759 }
1760
1761 static void
1762 unpack_R16G16_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1763 {
1764 const GLuint *s = ((const GLuint *) src);
1765 GLuint i;
1766 for (i = 0; i < n; i++) {
1767 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
1768 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
1769 dst[i][BCOMP] = 0.0F;
1770 dst[i][ACOMP] = 1.0F;
1771 }
1772 }
1773
1774 static void
1775 unpack_RGB_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
1776 {
1777 const GLshort *s = (const GLshort *) src;
1778 GLuint i;
1779 for (i = 0; i < n; i++) {
1780 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] );
1781 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
1782 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
1783 dst[i][ACOMP] = 1.0F;
1784 }
1785 }
1786
1787 static void
1788 unpack_RGBA_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*4+0] );
1794 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
1795 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
1796 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
1797 }
1798 }
1799
1800 static void
1801 unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1802 {
1803 const GLushort *s = (const GLushort *) src;
1804 GLuint i;
1805 for (i = 0; i < n; i++) {
1806 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
1807 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
1808 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
1809 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
1810 }
1811 }
1812
1813 static void
1814 unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1815 {
1816 /* XXX to do */
1817 }
1818
1819 static void
1820 unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1821 {
1822 /* XXX to do */
1823 }
1824
1825 static void
1826 unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1827 {
1828 /* XXX to do */
1829 }
1830
1831 static void
1832 unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1833 {
1834 /* XXX to do */
1835 }
1836
1837 static void
1838 unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1839 {
1840 /* XXX to do */
1841 }
1842
1843 static void
1844 unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1845 {
1846 /* XXX to do */
1847 }
1848
1849 static void
1850 unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1851 {
1852 /* XXX to do */
1853 }
1854
1855 static void
1856 unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1857 {
1858 /* XXX to do */
1859 }
1860
1861 static void
1862 unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1863 {
1864 /* XXX to do */
1865 }
1866
1867 static void
1868 unpack_ETC2_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1869 {
1870 /* XXX to do */
1871 }
1872
1873 static void
1874 unpack_ETC2_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
1875 {
1876 /* XXX to do */
1877 }
1878
1879 static void
1880 unpack_ETC2_RGBA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
1881 {
1882 /* XXX to do */
1883 }
1884
1885 static void
1886 unpack_ETC2_SRGB8_ALPHA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
1887 {
1888 /* XXX to do */
1889 }
1890
1891 static void
1892 unpack_ETC2_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1893 {
1894 /* XXX to do */
1895 }
1896
1897 static void
1898 unpack_ETC2_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1899 {
1900 /* XXX to do */
1901 }
1902
1903 static void
1904 unpack_ETC2_SIGNED_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1905 {
1906 /* XXX to do */
1907 }
1908
1909 static void
1910 unpack_ETC2_SIGNED_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
1911 {
1912 /* XXX to do */
1913 }
1914
1915 static void
1916 unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
1917 GLuint n)
1918 {
1919 /* XXX to do */
1920 }
1921
1922 static void
1923 unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
1924 GLuint n)
1925 {
1926 /* XXX to do */
1927 }
1928
1929 static void
1930 unpack_A_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
1931 {
1932 const GLbyte *s = ((const GLbyte *) src);
1933 GLuint i;
1934 for (i = 0; i < n; i++) {
1935 dst[i][RCOMP] = 0.0F;
1936 dst[i][GCOMP] = 0.0F;
1937 dst[i][BCOMP] = 0.0F;
1938 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1939 }
1940 }
1941
1942 static void
1943 unpack_L_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] =
1949 dst[i][GCOMP] =
1950 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1951 dst[i][ACOMP] = 1.0F;
1952 }
1953 }
1954
1955 static void
1956 unpack_L8A8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
1957 {
1958 const GLshort *s = ((const GLshort *) 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( (GLbyte) (s[i] & 0xff) );
1964 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1965 }
1966 }
1967
1968 static void
1969 unpack_I_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
1970 {
1971 const GLbyte *s = ((const GLbyte *) src);
1972 GLuint i;
1973 for (i = 0; i < n; i++) {
1974 dst[i][RCOMP] =
1975 dst[i][GCOMP] =
1976 dst[i][BCOMP] =
1977 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1978 }
1979 }
1980
1981 static void
1982 unpack_A_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
1983 {
1984 const GLshort *s = ((const GLshort *) src);
1985 GLuint i;
1986 for (i = 0; i < n; i++) {
1987 dst[i][RCOMP] = 0.0F;
1988 dst[i][GCOMP] = 0.0F;
1989 dst[i][BCOMP] = 0.0F;
1990 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1991 }
1992 }
1993
1994 static void
1995 unpack_L_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
1996 {
1997 const GLshort *s = ((const GLshort *) src);
1998 GLuint i;
1999 for (i = 0; i < n; i++) {
2000 dst[i][RCOMP] =
2001 dst[i][GCOMP] =
2002 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
2003 dst[i][ACOMP] = 1.0F;
2004 }
2005 }
2006
2007 static void
2008 unpack_LA_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
2009 {
2010 const GLshort *s = (const GLshort *) src;
2011 GLuint i;
2012 for (i = 0; i < n; i++) {
2013 dst[i][RCOMP] =
2014 dst[i][GCOMP] =
2015 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
2016 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
2017 }
2018 }
2019
2020 static void
2021 unpack_I_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
2022 {
2023 const GLshort *s = ((const GLshort *) src);
2024 GLuint i;
2025 for (i = 0; i < n; i++) {
2026 dst[i][RCOMP] =
2027 dst[i][GCOMP] =
2028 dst[i][BCOMP] =
2029 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
2030 }
2031 }
2032
2033 static void
2034 unpack_R9G9B9E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2035 {
2036 const GLuint *s = (const GLuint *) src;
2037 GLuint i;
2038 for (i = 0; i < n; i++) {
2039 rgb9e5_to_float3(s[i], dst[i]);
2040 dst[i][ACOMP] = 1.0F;
2041 }
2042 }
2043
2044 static void
2045 unpack_R11G11B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2046 {
2047 const GLuint *s = (const GLuint *) src;
2048 GLuint i;
2049 for (i = 0; i < n; i++) {
2050 r11g11b10f_to_float3(s[i], dst[i]);
2051 dst[i][ACOMP] = 1.0F;
2052 }
2053 }
2054
2055 static void
2056 unpack_XRGB4444_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2057 {
2058 const GLushort *s = ((const GLushort *) src);
2059 GLuint i;
2060 for (i = 0; i < n; i++) {
2061 dst[i][RCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
2062 dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
2063 dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
2064 dst[i][ACOMP] = 1.0;
2065 }
2066 }
2067
2068 static void
2069 unpack_XRGB1555_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2070 {
2071 const GLushort *s = ((const GLushort *) src);
2072 GLuint i;
2073 for (i = 0; i < n; i++) {
2074 dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
2075 dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F);
2076 dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F);
2077 dst[i][ACOMP] = 1.0;
2078 }
2079 }
2080
2081 static void
2082 unpack_XBGR8888_SNORM(const void *src, GLfloat dst[][4], GLuint n)
2083 {
2084 const GLuint *s = ((const GLuint *) src);
2085 GLuint i;
2086 for (i = 0; i < n; i++) {
2087 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
2088 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
2089 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
2090 dst[i][ACOMP] = 1.0;
2091 }
2092 }
2093
2094 static void
2095 unpack_R8G8B8X8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
2096 {
2097 const GLuint *s = ((const GLuint *) src);
2098 GLuint i;
2099 for (i = 0; i < n; i++) {
2100 dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff );
2101 dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff );
2102 dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
2103 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
2104 }
2105 }
2106
2107 static void
2108 unpack_XBGR8888_UINT(const void *src, GLfloat dst[][4], GLuint n)
2109 {
2110 const GLbyte *s = (const GLbyte *) src;
2111 GLuint i;
2112 for (i = 0; i < n; i++) {
2113 dst[i][RCOMP] = s[i*4+0];
2114 dst[i][GCOMP] = s[i*4+1];
2115 dst[i][BCOMP] = s[i*4+2];
2116 dst[i][ACOMP] = 1.0;
2117 }
2118 }
2119
2120 static void
2121 unpack_XBGR8888_SINT(const void *src, GLfloat dst[][4], GLuint n)
2122 {
2123 const GLbyte *s = (const GLbyte *) src;
2124 GLuint i;
2125 for (i = 0; i < n; i++) {
2126 dst[i][RCOMP] = s[i*4+0];
2127 dst[i][GCOMP] = s[i*4+1];
2128 dst[i][BCOMP] = s[i*4+2];
2129 dst[i][ACOMP] = 1.0;
2130 }
2131 }
2132
2133 static void
2134 unpack_B10G10R10X2_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2135 {
2136 const GLuint *s = ((const GLuint *) src);
2137 GLuint i;
2138 for (i = 0; i < n; i++) {
2139 dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
2140 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
2141 dst[i][BCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
2142 dst[i][ACOMP] = 1.0;
2143 }
2144 }
2145
2146 static void
2147 unpack_RGBX_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
2148 {
2149 const GLushort *s = (const GLushort *) src;
2150 GLuint i;
2151 for (i = 0; i < n; i++) {
2152 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
2153 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
2154 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
2155 dst[i][ACOMP] = 1.0;
2156 }
2157 }
2158
2159 static void
2160 unpack_RGBX_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
2161 {
2162 const GLshort *s = (const GLshort *) src;
2163 GLuint i;
2164 for (i = 0; i < n; i++) {
2165 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
2166 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
2167 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
2168 dst[i][ACOMP] = 1.0;
2169 }
2170 }
2171
2172 static void
2173 unpack_XBGR16161616_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
2174 {
2175 const GLshort *s = (const GLshort *) src;
2176 GLuint i;
2177 for (i = 0; i < n; i++) {
2178 dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
2179 dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
2180 dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
2181 dst[i][ACOMP] = 1.0;
2182 }
2183 }
2184
2185 static void
2186 unpack_XBGR16161616_UINT(const void *src, GLfloat dst[][4], GLuint n)
2187 {
2188 const GLushort *s = (const GLushort *) src;
2189 GLuint i;
2190 for (i = 0; i < n; i++) {
2191 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2192 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2193 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2194 dst[i][ACOMP] = 1.0;
2195 }
2196 }
2197
2198 static void
2199 unpack_XBGR16161616_SINT(const void *src, GLfloat dst[][4], GLuint n)
2200 {
2201 const GLshort *s = (const GLshort *) src;
2202 GLuint i;
2203 for (i = 0; i < n; i++) {
2204 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2205 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2206 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2207 dst[i][ACOMP] = 1.0;
2208 }
2209 }
2210
2211 static void
2212 unpack_RGBX_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
2213 {
2214 const GLfloat *s = (const GLfloat *) src;
2215 GLuint i;
2216 for (i = 0; i < n; i++) {
2217 dst[i][RCOMP] = s[i*4+0];
2218 dst[i][GCOMP] = s[i*4+1];
2219 dst[i][BCOMP] = s[i*4+2];
2220 dst[i][ACOMP] = 1.0;
2221 }
2222 }
2223
2224 static void
2225 unpack_XBGR32323232_UINT(const void *src, GLfloat dst[][4], GLuint n)
2226 {
2227 const GLuint *s = (const GLuint *) src;
2228 GLuint i;
2229 for (i = 0; i < n; i++) {
2230 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2231 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2232 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2233 dst[i][ACOMP] = 1.0;
2234 }
2235 }
2236
2237 static void
2238 unpack_XBGR32323232_SINT(const void *src, GLfloat dst[][4], GLuint n)
2239 {
2240 const GLint *s = (const GLint *) src;
2241 GLuint i;
2242 for (i = 0; i < n; i++) {
2243 dst[i][RCOMP] = (GLfloat) s[i*4+0];
2244 dst[i][GCOMP] = (GLfloat) s[i*4+1];
2245 dst[i][BCOMP] = (GLfloat) s[i*4+2];
2246 dst[i][ACOMP] = 1.0;
2247 }
2248 }
2249
2250 static void
2251 unpack_R10G10B10A2_UNORM(const void *src, GLfloat dst[][4], GLuint n)
2252 {
2253 const GLuint *s = ((const GLuint *) src);
2254 GLuint i;
2255 for (i = 0; i < n; i++) {
2256 dst[i][RCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
2257 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
2258 dst[i][BCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
2259 dst[i][ACOMP] = ((s[i] >> 30) & 0x03) * (1.0F / 3.0F);
2260 }
2261 }
2262
2263 static void
2264 unpack_G8R8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
2265 {
2266 const GLushort *s = ((const GLushort *) src);
2267 GLuint i;
2268 for (i = 0; i < n; i++) {
2269 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
2270 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
2271 dst[i][BCOMP] = 0.0F;
2272 dst[i][ACOMP] = 1.0F;
2273 }
2274 }
2275
2276 static void
2277 unpack_G16R16_SNORM(const void *src, GLfloat dst[][4], GLuint n)
2278 {
2279 const GLuint *s = ((const GLuint *) src);
2280 GLuint i;
2281 for (i = 0; i < n; i++) {
2282 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
2283 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
2284 dst[i][BCOMP] = 0.0F;
2285 dst[i][ACOMP] = 1.0F;
2286 }
2287 }
2288
2289 static void
2290 unpack_B8G8R8X8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
2291 {
2292 const GLuint *s = ((const GLuint *) src);
2293 GLuint i;
2294 for (i = 0; i < n; i++) {
2295 dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
2296 dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 8) & 0xff );
2297 dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] ) & 0xff );
2298 dst[i][ACOMP] = 1.0F;
2299 }
2300 }
2301
2302 /**
2303 * Return the unpacker function for the given format.
2304 */
2305 static unpack_rgba_func
2306 get_unpack_rgba_function(mesa_format format)
2307 {
2308 static unpack_rgba_func table[MESA_FORMAT_COUNT];
2309 static GLboolean initialized = GL_FALSE;
2310
2311 if (!initialized) {
2312 table[MESA_FORMAT_NONE] = NULL;
2313
2314 table[MESA_FORMAT_A8B8G8R8_UNORM] = unpack_A8B8G8R8_UNORM;
2315 table[MESA_FORMAT_R8G8B8A8_UNORM] = unpack_R8G8B8A8_UNORM;
2316 table[MESA_FORMAT_B8G8R8A8_UNORM] = unpack_B8G8R8A8_UNORM;
2317 table[MESA_FORMAT_A8R8G8B8_UNORM] = unpack_A8R8G8B8_UNORM;
2318 table[MESA_FORMAT_X8B8G8R8_UNORM] = unpack_RGBX8888;
2319 table[MESA_FORMAT_R8G8B8X8_UNORM] = unpack_RGBX8888_REV;
2320 table[MESA_FORMAT_B8G8R8X8_UNORM] = unpack_B8G8R8X8_UNORM;
2321 table[MESA_FORMAT_X8R8G8B8_UNORM] = unpack_X8R8G8B8_UNORM;
2322 table[MESA_FORMAT_BGR_UNORM8] = unpack_BGR_UNORM8;
2323 table[MESA_FORMAT_RGB_UNORM8] = unpack_RGB_UNORM8;
2324 table[MESA_FORMAT_B5G6R5_UNORM] = unpack_B5G6R5_UNORM;
2325 table[MESA_FORMAT_R5G6B5_UNORM] = unpack_R5G6B5_UNORM;
2326 table[MESA_FORMAT_B4G4R4A4_UNORM] = unpack_B4G4R4A4_UNORM;
2327 table[MESA_FORMAT_A4R4G4B4_UNORM] = unpack_A4R4G4B4_UNORM;
2328 table[MESA_FORMAT_A1B5G5R5_UNORM] = unpack_A1B5G5R5_UNORM;
2329 table[MESA_FORMAT_B5G5R5A1_UNORM] = unpack_B5G5R5A1_UNORM;
2330 table[MESA_FORMAT_A1R5G5B5_UNORM] = unpack_A1R5G5B5_UNORM;
2331 table[MESA_FORMAT_L4A4_UNORM] = unpack_L4A4_UNORM;
2332 table[MESA_FORMAT_L8A8_UNORM] = unpack_L8A8_UNORM;
2333 table[MESA_FORMAT_A8L8_UNORM] = unpack_A8L8_UNORM;
2334 table[MESA_FORMAT_L16A16_UNORM] = unpack_L16A16_UNORM;
2335 table[MESA_FORMAT_A16L16_UNORM] = unpack_A16L16_UNORM;
2336 table[MESA_FORMAT_B2G3R3_UNORM] = unpack_B2G3R3_UNORM;
2337 table[MESA_FORMAT_A_UNORM8] = unpack_A_UNORM8;
2338 table[MESA_FORMAT_A_UNORM16] = unpack_A_UNORM16;
2339 table[MESA_FORMAT_L_UNORM8] = unpack_L_UNORM8;
2340 table[MESA_FORMAT_L_UNORM16] = unpack_L_UNORM16;
2341 table[MESA_FORMAT_I_UNORM8] = unpack_I_UNORM8;
2342 table[MESA_FORMAT_I_UNORM16] = unpack_I_UNORM16;
2343 table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
2344 table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
2345 table[MESA_FORMAT_R_UNORM8] = unpack_R_UNORM8;
2346 table[MESA_FORMAT_R8G8_UNORM] = unpack_R8G8_UNORM;
2347 table[MESA_FORMAT_G8R8_UNORM] = unpack_G8R8_UNORM;
2348 table[MESA_FORMAT_R_UNORM16] = unpack_R_UNORM16;
2349 table[MESA_FORMAT_R16G16_UNORM] = unpack_R16G16_UNORM;
2350 table[MESA_FORMAT_G16R16_UNORM] = unpack_G16R16_UNORM;
2351 table[MESA_FORMAT_B10G10R10A2_UNORM] = unpack_B10G10R10A2_UNORM;
2352 table[MESA_FORMAT_B10G10R10A2_UINT] = unpack_B10G10R10A2_UINT;
2353 table[MESA_FORMAT_R10G10B10A2_UINT] = unpack_R10G10B10A2_UINT;
2354 table[MESA_FORMAT_S8_UINT_Z24_UNORM] = unpack_S8_UINT_Z24_UNORM;
2355 table[MESA_FORMAT_Z24_UNORM_S8_UINT] = unpack_Z24_UNORM_S8_UINT;
2356 table[MESA_FORMAT_Z_UNORM16] = unpack_Z_UNORM16;
2357 table[MESA_FORMAT_Z24_UNORM_X8_UINT] = unpack_Z24_UNORM_X8_UINT;
2358 table[MESA_FORMAT_X8_UINT_Z24_UNORM] = unpack_X8_UINT_Z24_UNORM;
2359 table[MESA_FORMAT_Z_UNORM32] = unpack_Z_UNORM32;
2360 table[MESA_FORMAT_S_UINT8] = unpack_S8;
2361 table[MESA_FORMAT_BGR_SRGB8] = unpack_BGR_SRGB8;
2362 table[MESA_FORMAT_A8B8G8R8_SRGB] = unpack_A8B8G8R8_SRGB;
2363 table[MESA_FORMAT_B8G8R8A8_SRGB] = unpack_B8G8R8A8_SRGB;
2364 table[MESA_FORMAT_R8G8B8A8_SRGB] = unpack_R8G8B8A8_SRGB;
2365 table[MESA_FORMAT_L_SRGB8] = unpack_L_SRGB8;
2366 table[MESA_FORMAT_L8A8_SRGB] = unpack_L8A8_SRGB;
2367 table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
2368 table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
2369 table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
2370 table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
2371
2372 table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
2373 table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
2374 table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
2375 table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
2376 table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
2377 table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
2378
2379 table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
2380 table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
2381 table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
2382 table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
2383 table[MESA_FORMAT_A_FLOAT32] = unpack_A_FLOAT32;
2384 table[MESA_FORMAT_A_FLOAT16] = unpack_A_FLOAT16;
2385 table[MESA_FORMAT_L_FLOAT32] = unpack_L_FLOAT32;
2386 table[MESA_FORMAT_L_FLOAT16] = unpack_L_FLOAT16;
2387 table[MESA_FORMAT_LA_FLOAT32] = unpack_LA_FLOAT32;
2388 table[MESA_FORMAT_LA_FLOAT16] = unpack_LA_FLOAT16;
2389 table[MESA_FORMAT_I_FLOAT32] = unpack_I_FLOAT32;
2390 table[MESA_FORMAT_I_FLOAT16] = unpack_I_FLOAT16;
2391 table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
2392 table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
2393 table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
2394 table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
2395
2396 table[MESA_FORMAT_A_UINT8] = unpack_ALPHA_UINT8;
2397 table[MESA_FORMAT_A_UINT16] = unpack_ALPHA_UINT16;
2398 table[MESA_FORMAT_A_UINT32] = unpack_ALPHA_UINT32;
2399 table[MESA_FORMAT_A_SINT8] = unpack_ALPHA_INT8;
2400 table[MESA_FORMAT_A_SINT16] = unpack_ALPHA_INT16;
2401 table[MESA_FORMAT_A_SINT32] = unpack_ALPHA_INT32;
2402
2403 table[MESA_FORMAT_I_UINT8] = unpack_INTENSITY_UINT8;
2404 table[MESA_FORMAT_I_UINT16] = unpack_INTENSITY_UINT16;
2405 table[MESA_FORMAT_I_UINT32] = unpack_INTENSITY_UINT32;
2406 table[MESA_FORMAT_I_SINT8] = unpack_INTENSITY_INT8;
2407 table[MESA_FORMAT_I_SINT16] = unpack_INTENSITY_INT16;
2408 table[MESA_FORMAT_I_SINT32] = unpack_INTENSITY_INT32;
2409
2410 table[MESA_FORMAT_L_UINT8] = unpack_LUMINANCE_UINT8;
2411 table[MESA_FORMAT_L_UINT16] = unpack_LUMINANCE_UINT16;
2412 table[MESA_FORMAT_L_UINT32] = unpack_LUMINANCE_UINT32;
2413 table[MESA_FORMAT_L_SINT8] = unpack_LUMINANCE_INT8;
2414 table[MESA_FORMAT_L_SINT16] = unpack_LUMINANCE_INT16;
2415 table[MESA_FORMAT_L_SINT32] = unpack_LUMINANCE_INT32;
2416
2417 table[MESA_FORMAT_LA_UINT8] = unpack_LUMINANCE_ALPHA_UINT8;
2418 table[MESA_FORMAT_LA_UINT16] = unpack_LUMINANCE_ALPHA_UINT16;
2419 table[MESA_FORMAT_LA_UINT32] = unpack_LUMINANCE_ALPHA_UINT32;
2420 table[MESA_FORMAT_LA_SINT8] = unpack_LUMINANCE_ALPHA_INT8;
2421 table[MESA_FORMAT_LA_SINT16] = unpack_LUMINANCE_ALPHA_INT16;
2422 table[MESA_FORMAT_LA_SINT32] = unpack_LUMINANCE_ALPHA_INT32;
2423
2424 table[MESA_FORMAT_R_SINT8] = unpack_R_INT8;
2425 table[MESA_FORMAT_RG_SINT8] = unpack_RG_INT8;
2426 table[MESA_FORMAT_RGB_SINT8] = unpack_RGB_INT8;
2427 table[MESA_FORMAT_RGBA_SINT8] = unpack_RGBA_INT8;
2428 table[MESA_FORMAT_R_SINT16] = unpack_R_INT16;
2429 table[MESA_FORMAT_RG_SINT16] = unpack_RG_INT16;
2430 table[MESA_FORMAT_RGB_SINT16] = unpack_RGB_INT16;
2431 table[MESA_FORMAT_RGBA_SINT16] = unpack_RGBA_INT16;
2432 table[MESA_FORMAT_R_SINT32] = unpack_R_INT32;
2433 table[MESA_FORMAT_RG_SINT32] = unpack_RG_INT32;
2434 table[MESA_FORMAT_RGB_SINT32] = unpack_RGB_INT32;
2435 table[MESA_FORMAT_RGBA_SINT32] = unpack_RGBA_INT32;
2436 table[MESA_FORMAT_R_UINT8] = unpack_R_UINT8;
2437 table[MESA_FORMAT_RG_UINT8] = unpack_RG_UINT8;
2438 table[MESA_FORMAT_RGB_UINT8] = unpack_RGB_UINT8;
2439 table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
2440 table[MESA_FORMAT_R_UINT16] = unpack_R_UINT16;
2441 table[MESA_FORMAT_RG_UINT16] = unpack_RG_UINT16;
2442 table[MESA_FORMAT_RGB_UINT16] = unpack_RGB_UINT16;
2443 table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
2444 table[MESA_FORMAT_R_UINT32] = unpack_R_UINT32;
2445 table[MESA_FORMAT_RG_UINT32] = unpack_RG_UINT32;
2446 table[MESA_FORMAT_RGB_UINT32] = unpack_RGB_UINT32;
2447 table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
2448
2449 table[MESA_FORMAT_R_SNORM8] = unpack_R_SNORM8;
2450 table[MESA_FORMAT_R8G8_SNORM] = unpack_R8G8_SNORM;
2451 table[MESA_FORMAT_X8B8G8R8_SNORM] = unpack_X8B8G8R8_SNORM;
2452 table[MESA_FORMAT_A8B8G8R8_SNORM] = unpack_A8B8G8R8_SNORM;
2453 table[MESA_FORMAT_R8G8B8A8_SNORM] = unpack_R8G8B8A8_SNORM;
2454 table[MESA_FORMAT_R_SNORM16] = unpack_R_SNORM16;
2455 table[MESA_FORMAT_R16G16_SNORM] = unpack_R16G16_SNORM;
2456 table[MESA_FORMAT_RGB_SNORM16] = unpack_RGB_SNORM16;
2457 table[MESA_FORMAT_RGBA_SNORM16] = unpack_RGBA_SNORM16;
2458 table[MESA_FORMAT_RGBA_UNORM16] = unpack_RGBA_16;
2459
2460 table[MESA_FORMAT_R_RGTC1_UNORM] = unpack_RED_RGTC1;
2461 table[MESA_FORMAT_R_RGTC1_SNORM] = unpack_SIGNED_RED_RGTC1;
2462 table[MESA_FORMAT_RG_RGTC2_UNORM] = unpack_RG_RGTC2;
2463 table[MESA_FORMAT_RG_RGTC2_SNORM] = unpack_SIGNED_RG_RGTC2;
2464
2465 table[MESA_FORMAT_L_LATC1_UNORM] = unpack_L_LATC1;
2466 table[MESA_FORMAT_L_LATC1_SNORM] = unpack_SIGNED_L_LATC1;
2467 table[MESA_FORMAT_LA_LATC2_UNORM] = unpack_LA_LATC2;
2468 table[MESA_FORMAT_LA_LATC2_SNORM] = unpack_SIGNED_LA_LATC2;
2469
2470 table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
2471 table[MESA_FORMAT_ETC2_RGB8] = unpack_ETC2_RGB8;
2472 table[MESA_FORMAT_ETC2_SRGB8] = unpack_ETC2_SRGB8;
2473 table[MESA_FORMAT_ETC2_RGBA8_EAC] = unpack_ETC2_RGBA8_EAC;
2474 table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = unpack_ETC2_SRGB8_ALPHA8_EAC;
2475 table[MESA_FORMAT_ETC2_R11_EAC] = unpack_ETC2_R11_EAC;
2476 table[MESA_FORMAT_ETC2_RG11_EAC] = unpack_ETC2_RG11_EAC;
2477 table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = unpack_ETC2_SIGNED_R11_EAC;
2478 table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = unpack_ETC2_SIGNED_RG11_EAC;
2479 table[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] =
2480 unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
2481 table[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] =
2482 unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
2483 table[MESA_FORMAT_A_SNORM8] = unpack_A_SNORM8;
2484 table[MESA_FORMAT_L_SNORM8] = unpack_L_SNORM8;
2485 table[MESA_FORMAT_L8A8_SNORM] = unpack_L8A8_SNORM;
2486 table[MESA_FORMAT_I_SNORM8] = unpack_I_SNORM8;
2487 table[MESA_FORMAT_A_SNORM16] = unpack_A_SNORM16;
2488 table[MESA_FORMAT_L_SNORM16] = unpack_L_SNORM16;
2489 table[MESA_FORMAT_LA_SNORM16] = unpack_LA_SNORM16;
2490 table[MESA_FORMAT_I_SNORM16] = unpack_I_SNORM16;
2491
2492 table[MESA_FORMAT_R9G9B9E5_FLOAT] = unpack_R9G9B9E5_FLOAT;
2493 table[MESA_FORMAT_R11G11B10_FLOAT] = unpack_R11G11B10_FLOAT;
2494
2495 table[MESA_FORMAT_Z_FLOAT32] = unpack_Z_FLOAT32;
2496 table[MESA_FORMAT_Z32_FLOAT_S8X24_UINT] = unpack_Z32_FLOAT_S8X24_UINT;
2497
2498 table[MESA_FORMAT_B4G4R4X4_UNORM] = unpack_XRGB4444_UNORM;
2499 table[MESA_FORMAT_B5G5R5X1_UNORM] = unpack_XRGB1555_UNORM;
2500 table[MESA_FORMAT_R8G8B8X8_SNORM] = unpack_XBGR8888_SNORM;
2501 table[MESA_FORMAT_R8G8B8X8_SRGB] = unpack_R8G8B8X8_SRGB;
2502 table[MESA_FORMAT_RGBX_UINT8] = unpack_XBGR8888_UINT;
2503 table[MESA_FORMAT_RGBX_SINT8] = unpack_XBGR8888_SINT;
2504 table[MESA_FORMAT_B10G10R10X2_UNORM] = unpack_B10G10R10X2_UNORM;
2505 table[MESA_FORMAT_RGBX_UNORM16] = unpack_RGBX_UNORM16;
2506 table[MESA_FORMAT_RGBX_SNORM16] = unpack_RGBX_SNORM16;
2507 table[MESA_FORMAT_RGBX_FLOAT16] = unpack_XBGR16161616_FLOAT;
2508 table[MESA_FORMAT_RGBX_UINT16] = unpack_XBGR16161616_UINT;
2509 table[MESA_FORMAT_RGBX_SINT16] = unpack_XBGR16161616_SINT;
2510 table[MESA_FORMAT_RGBX_FLOAT32] = unpack_RGBX_FLOAT32;
2511 table[MESA_FORMAT_RGBX_UINT32] = unpack_XBGR32323232_UINT;
2512 table[MESA_FORMAT_RGBX_SINT32] = unpack_XBGR32323232_SINT;
2513
2514 table[MESA_FORMAT_R10G10B10A2_UNORM] = unpack_R10G10B10A2_UNORM;
2515
2516 table[MESA_FORMAT_G8R8_SNORM] = unpack_G8R8_SNORM;
2517 table[MESA_FORMAT_G16R16_SNORM] = unpack_G16R16_SNORM;
2518
2519 table[MESA_FORMAT_B8G8R8X8_SRGB] = unpack_B8G8R8X8_SRGB;
2520
2521 initialized = GL_TRUE;
2522 }
2523
2524 if (table[format] == NULL) {
2525 _mesa_problem(NULL, "unsupported unpack for format %s",
2526 _mesa_get_format_name(format));
2527 }
2528
2529 return table[format];
2530 }
2531
2532
2533 /**
2534 * Unpack rgba colors, returning as GLfloat values.
2535 */
2536 void
2537 _mesa_unpack_rgba_row(mesa_format format, GLuint n,
2538 const void *src, GLfloat dst[][4])
2539 {
2540 unpack_rgba_func unpack = get_unpack_rgba_function(format);
2541 unpack(src, dst, n);
2542 }
2543
2544
2545 /**********************************************************************/
2546 /* Unpack, returning GLubyte colors */
2547 /**********************************************************************/
2548
2549
2550 static void
2551 unpack_ubyte_A8B8G8R8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2552 {
2553 const GLuint *s = ((const GLuint *) src);
2554 GLuint i;
2555 for (i = 0; i < n; i++) {
2556 dst[i][RCOMP] = (s[i] >> 24);
2557 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2558 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
2559 dst[i][ACOMP] = (s[i] ) & 0xff;
2560 }
2561 }
2562
2563 static void
2564 unpack_ubyte_R8G8B8A8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2565 {
2566 const GLuint *s = ((const GLuint *) src);
2567 GLuint i;
2568 for (i = 0; i < n; i++) {
2569 dst[i][RCOMP] = (s[i] ) & 0xff;
2570 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2571 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
2572 dst[i][ACOMP] = (s[i] >> 24);
2573 }
2574 }
2575
2576 static void
2577 unpack_ubyte_B8G8R8A8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2578 {
2579 const GLuint *s = ((const GLuint *) src);
2580 GLuint i;
2581 for (i = 0; i < n; i++) {
2582 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
2583 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2584 dst[i][BCOMP] = (s[i] ) & 0xff;
2585 dst[i][ACOMP] = (s[i] >> 24);
2586 }
2587 }
2588
2589 static void
2590 unpack_ubyte_A8R8G8B8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2591 {
2592 const GLuint *s = ((const GLuint *) src);
2593 GLuint i;
2594 for (i = 0; i < n; i++) {
2595 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
2596 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2597 dst[i][BCOMP] = (s[i] >> 24);
2598 dst[i][ACOMP] = (s[i] ) & 0xff;
2599 }
2600 }
2601
2602 static void
2603 unpack_ubyte_RGBX8888(const void *src, GLubyte dst[][4], GLuint n)
2604 {
2605 const GLuint *s = ((const GLuint *) src);
2606 GLuint i;
2607 for (i = 0; i < n; i++) {
2608 dst[i][RCOMP] = (s[i] >> 24);
2609 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2610 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
2611 dst[i][ACOMP] = 0xff;
2612 }
2613 }
2614
2615 static void
2616 unpack_ubyte_RGBX8888_REV(const void *src, GLubyte dst[][4], GLuint n)
2617 {
2618 const GLuint *s = ((const GLuint *) src);
2619 GLuint i;
2620 for (i = 0; i < n; i++) {
2621 dst[i][RCOMP] = (s[i] ) & 0xff;
2622 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2623 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
2624 dst[i][ACOMP] = 0xff;
2625 }
2626 }
2627
2628 static void
2629 unpack_ubyte_B8G8R8X8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2630 {
2631 const GLuint *s = ((const GLuint *) src);
2632 GLuint i;
2633 for (i = 0; i < n; i++) {
2634 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
2635 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
2636 dst[i][BCOMP] = (s[i] ) & 0xff;
2637 dst[i][ACOMP] = 0xff;
2638 }
2639 }
2640
2641 static void
2642 unpack_ubyte_X8R8G8B8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2643 {
2644 const GLuint *s = ((const GLuint *) src);
2645 GLuint i;
2646 for (i = 0; i < n; i++) {
2647 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
2648 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
2649 dst[i][BCOMP] = (s[i] >> 24);
2650 dst[i][ACOMP] = 0xff;
2651 }
2652 }
2653
2654 static void
2655 unpack_ubyte_BGR_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
2656 {
2657 const GLubyte *s = (const GLubyte *) src;
2658 GLuint i;
2659 for (i = 0; i < n; i++) {
2660 dst[i][RCOMP] = s[i*3+2];
2661 dst[i][GCOMP] = s[i*3+1];
2662 dst[i][BCOMP] = s[i*3+0];
2663 dst[i][ACOMP] = 0xff;
2664 }
2665 }
2666
2667 static void
2668 unpack_ubyte_RGB_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
2669 {
2670 const GLubyte *s = (const GLubyte *) src;
2671 GLuint i;
2672 for (i = 0; i < n; i++) {
2673 dst[i][RCOMP] = s[i*3+0];
2674 dst[i][GCOMP] = s[i*3+1];
2675 dst[i][BCOMP] = s[i*3+2];
2676 dst[i][ACOMP] = 0xff;
2677 }
2678 }
2679
2680 static void
2681 unpack_ubyte_B5G6R5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2682 {
2683 const GLushort *s = ((const GLushort *) src);
2684 GLuint i;
2685 for (i = 0; i < n; i++) {
2686 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
2687 dst[i][GCOMP] = EXPAND_6_8((s[i] >> 5 ) & 0x3f);
2688 dst[i][BCOMP] = EXPAND_5_8( s[i] & 0x1f);
2689 dst[i][ACOMP] = 0xff;
2690 }
2691 }
2692
2693 static void
2694 unpack_ubyte_R5G6B5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2695 {
2696 /* Warning: this function does not match the current Mesa definition
2697 * of MESA_FORMAT_R5G6B5_UNORM.
2698 */
2699 const GLushort *s = ((const GLushort *) src);
2700 GLuint i;
2701 for (i = 0; i < n; i++) {
2702 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
2703 dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);
2704 dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);
2705 dst[i][BCOMP] = EXPAND_5_8( t & 0x1f);
2706 dst[i][ACOMP] = 0xff;
2707 }
2708 }
2709
2710 static void
2711 unpack_ubyte_B4G4R4A4_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2712 {
2713 const GLushort *s = ((const GLushort *) src);
2714 GLuint i;
2715 for (i = 0; i < n; i++) {
2716 dst[i][RCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
2717 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
2718 dst[i][BCOMP] = EXPAND_4_8((s[i] ) & 0xf);
2719 dst[i][ACOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
2720 }
2721 }
2722
2723 static void
2724 unpack_ubyte_A4R4G4B4_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2725 {
2726 const GLushort *s = ((const GLushort *) src);
2727 GLuint i;
2728 for (i = 0; i < n; i++) {
2729 dst[i][RCOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
2730 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
2731 dst[i][BCOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
2732 dst[i][ACOMP] = EXPAND_4_8((s[i] ) & 0xf);
2733 }
2734 }
2735
2736 static void
2737 unpack_ubyte_A1B5G5R5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2738 {
2739 const GLushort *s = ((const GLushort *) src);
2740 GLuint i;
2741 for (i = 0; i < n; i++) {
2742 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
2743 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 6) & 0x1f);
2744 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 1) & 0x1f);
2745 dst[i][ACOMP] = EXPAND_1_8((s[i] ) & 0x01);
2746 }
2747 }
2748
2749 static void
2750 unpack_ubyte_B5G5R5A1_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2751 {
2752 const GLushort *s = ((const GLushort *) src);
2753 GLuint i;
2754 for (i = 0; i < n; i++) {
2755 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 10) & 0x1f);
2756 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 5) & 0x1f);
2757 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 0) & 0x1f);
2758 dst[i][ACOMP] = EXPAND_1_8((s[i] >> 15) & 0x01);
2759 }
2760 }
2761
2762 static void
2763 unpack_ubyte_A1R5G5B5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2764 {
2765 /* Warning: this function does not match the current Mesa definition
2766 * of MESA_FORMAT_A1R5G5B5_UNORM.
2767 */
2768 const GLushort *s = ((const GLushort *) src);
2769 GLuint i;
2770 for (i = 0; i < n; i++) {
2771 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
2772 dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
2773 dst[i][GCOMP] = EXPAND_5_8((tmp >> 5) & 0x1f);
2774 dst[i][BCOMP] = EXPAND_5_8((tmp >> 0) & 0x1f);
2775 dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
2776 }
2777 }
2778
2779 static void
2780 unpack_ubyte_L4A4_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2781 {
2782 const GLubyte *s = ((const GLubyte *) src);
2783 GLuint i;
2784 for (i = 0; i < n; i++) {
2785 dst[i][RCOMP] =
2786 dst[i][GCOMP] =
2787 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xf);
2788 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 4);
2789 }
2790 }
2791
2792 static void
2793 unpack_ubyte_L8A8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2794 {
2795 const GLushort *s = ((const GLushort *) src);
2796 GLuint i;
2797 for (i = 0; i < n; i++) {
2798 dst[i][RCOMP] =
2799 dst[i][GCOMP] =
2800 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xff);
2801 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 8);
2802 }
2803 }
2804
2805 static void
2806 unpack_ubyte_A8L8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2807 {
2808 const GLushort *s = ((const GLushort *) src);
2809 GLuint i;
2810 for (i = 0; i < n; i++) {
2811 dst[i][RCOMP] =
2812 dst[i][GCOMP] =
2813 dst[i][BCOMP] = EXPAND_4_8(s[i] >> 8);
2814 dst[i][ACOMP] = EXPAND_4_8(s[i] & 0xff);
2815 }
2816 }
2817
2818 static void
2819 unpack_ubyte_B2G3R3_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2820 {
2821 const GLubyte *s = ((const GLubyte *) src);
2822 GLuint i;
2823 for (i = 0; i < n; i++) {
2824 dst[i][RCOMP] = EXPAND_3_8((s[i] >> 5) & 0x7);
2825 dst[i][GCOMP] = EXPAND_3_8((s[i] >> 2) & 0x7);
2826 dst[i][BCOMP] = EXPAND_2_8((s[i] ) & 0x3);
2827 dst[i][ACOMP] = 0xff;
2828 }
2829 }
2830
2831 static void
2832 unpack_ubyte_A_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
2833 {
2834 const GLubyte *s = ((const GLubyte *) src);
2835 GLuint i;
2836 for (i = 0; i < n; i++) {
2837 dst[i][RCOMP] =
2838 dst[i][GCOMP] =
2839 dst[i][BCOMP] = 0;
2840 dst[i][ACOMP] = s[i];
2841 }
2842 }
2843
2844 static void
2845 unpack_ubyte_L_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
2846 {
2847 const GLubyte *s = ((const GLubyte *) src);
2848 GLuint i;
2849 for (i = 0; i < n; i++) {
2850 dst[i][RCOMP] =
2851 dst[i][GCOMP] =
2852 dst[i][BCOMP] = s[i];
2853 dst[i][ACOMP] = 0xff;
2854 }
2855 }
2856
2857
2858 static void
2859 unpack_ubyte_I_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
2860 {
2861 const GLubyte *s = ((const GLubyte *) src);
2862 GLuint i;
2863 for (i = 0; i < n; i++) {
2864 dst[i][RCOMP] =
2865 dst[i][GCOMP] =
2866 dst[i][BCOMP] =
2867 dst[i][ACOMP] = s[i];
2868 }
2869 }
2870
2871 static void
2872 unpack_ubyte_R_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
2873 {
2874 const GLubyte *s = ((const GLubyte *) src);
2875 GLuint i;
2876 for (i = 0; i < n; i++) {
2877 dst[i][0] = s[i];
2878 dst[i][1] =
2879 dst[i][2] = 0;
2880 dst[i][3] = 0xff;
2881 }
2882 }
2883
2884 static void
2885 unpack_ubyte_R8G8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2886 {
2887 const GLushort *s = ((const GLushort *) src);
2888 GLuint i;
2889 for (i = 0; i < n; i++) {
2890 dst[i][RCOMP] = s[i] & 0xff;
2891 dst[i][GCOMP] = s[i] >> 8;
2892 dst[i][BCOMP] = 0;
2893 dst[i][ACOMP] = 0xff;
2894 }
2895 }
2896
2897 static void
2898 unpack_ubyte_G8R8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
2899 {
2900 const GLushort *s = ((const GLushort *) src);
2901 GLuint i;
2902 for (i = 0; i < n; i++) {
2903 dst[i][RCOMP] = s[i] >> 8;
2904 dst[i][GCOMP] = s[i] & 0xff;
2905 dst[i][BCOMP] = 0;
2906 dst[i][ACOMP] = 0xff;
2907 }
2908 }
2909
2910
2911 /**
2912 * Unpack rgba colors, returning as GLubyte values. This should usually
2913 * only be used for unpacking formats that use 8 bits or less per channel.
2914 */
2915 void
2916 _mesa_unpack_ubyte_rgba_row(mesa_format format, GLuint n,
2917 const void *src, GLubyte dst[][4])
2918 {
2919 switch (format) {
2920 case MESA_FORMAT_A8B8G8R8_UNORM:
2921 unpack_ubyte_A8B8G8R8_UNORM(src, dst, n);
2922 break;
2923 case MESA_FORMAT_R8G8B8A8_UNORM:
2924 unpack_ubyte_R8G8B8A8_UNORM(src, dst, n);
2925 break;
2926 case MESA_FORMAT_B8G8R8A8_UNORM:
2927 unpack_ubyte_B8G8R8A8_UNORM(src, dst, n);
2928 break;
2929 case MESA_FORMAT_A8R8G8B8_UNORM:
2930 unpack_ubyte_A8R8G8B8_UNORM(src, dst, n);
2931 break;
2932 case MESA_FORMAT_X8B8G8R8_UNORM:
2933 unpack_ubyte_RGBX8888(src, dst, n);
2934 break;
2935 case MESA_FORMAT_R8G8B8X8_UNORM:
2936 unpack_ubyte_RGBX8888_REV(src, dst, n);
2937 break;
2938 case MESA_FORMAT_B8G8R8X8_UNORM:
2939 unpack_ubyte_B8G8R8X8_UNORM(src, dst, n);
2940 break;
2941 case MESA_FORMAT_X8R8G8B8_UNORM:
2942 unpack_ubyte_X8R8G8B8_UNORM(src, dst, n);
2943 break;
2944 case MESA_FORMAT_BGR_UNORM8:
2945 unpack_ubyte_BGR_UNORM8(src, dst, n);
2946 break;
2947 case MESA_FORMAT_RGB_UNORM8:
2948 unpack_ubyte_RGB_UNORM8(src, dst, n);
2949 break;
2950 case MESA_FORMAT_B5G6R5_UNORM:
2951 unpack_ubyte_B5G6R5_UNORM(src, dst, n);
2952 break;
2953 case MESA_FORMAT_R5G6B5_UNORM:
2954 unpack_ubyte_R5G6B5_UNORM(src, dst, n);
2955 break;
2956 case MESA_FORMAT_B4G4R4A4_UNORM:
2957 unpack_ubyte_B4G4R4A4_UNORM(src, dst, n);
2958 break;
2959 case MESA_FORMAT_A4R4G4B4_UNORM:
2960 unpack_ubyte_A4R4G4B4_UNORM(src, dst, n);
2961 break;
2962 case MESA_FORMAT_A1B5G5R5_UNORM:
2963 unpack_ubyte_A1B5G5R5_UNORM(src, dst, n);
2964 break;
2965 case MESA_FORMAT_B5G5R5A1_UNORM:
2966 unpack_ubyte_B5G5R5A1_UNORM(src, dst, n);
2967 break;
2968 case MESA_FORMAT_A1R5G5B5_UNORM:
2969 unpack_ubyte_A1R5G5B5_UNORM(src, dst, n);
2970 break;
2971 case MESA_FORMAT_L4A4_UNORM:
2972 unpack_ubyte_L4A4_UNORM(src, dst, n);
2973 break;
2974 case MESA_FORMAT_L8A8_UNORM:
2975 unpack_ubyte_L8A8_UNORM(src, dst, n);
2976 break;
2977 case MESA_FORMAT_A8L8_UNORM:
2978 unpack_ubyte_A8L8_UNORM(src, dst, n);
2979 break;
2980 case MESA_FORMAT_B2G3R3_UNORM:
2981 unpack_ubyte_B2G3R3_UNORM(src, dst, n);
2982 break;
2983 case MESA_FORMAT_A_UNORM8:
2984 unpack_ubyte_A_UNORM8(src, dst, n);
2985 break;
2986 case MESA_FORMAT_L_UNORM8:
2987 unpack_ubyte_L_UNORM8(src, dst, n);
2988 break;
2989 case MESA_FORMAT_I_UNORM8:
2990 unpack_ubyte_I_UNORM8(src, dst, n);
2991 break;
2992 case MESA_FORMAT_R_UNORM8:
2993 unpack_ubyte_R_UNORM8(src, dst, n);
2994 break;
2995 case MESA_FORMAT_R8G8_UNORM:
2996 unpack_ubyte_R8G8_UNORM(src, dst, n);
2997 break;
2998 case MESA_FORMAT_G8R8_UNORM:
2999 unpack_ubyte_G8R8_UNORM(src, dst, n);
3000 break;
3001 default:
3002 /* get float values, convert to ubyte */
3003 {
3004 GLfloat *tmp = malloc(n * 4 * sizeof(GLfloat));
3005 if (tmp) {
3006 GLuint i;
3007 _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
3008 for (i = 0; i < n; i++) {
3009 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][0], tmp[i*4+0]);
3010 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][1], tmp[i*4+1]);
3011 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][2], tmp[i*4+2]);
3012 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][3], tmp[i*4+3]);
3013 }
3014 free(tmp);
3015 }
3016 }
3017 break;
3018 }
3019 }
3020
3021
3022 /**********************************************************************/
3023 /* Unpack, returning GLuint colors */
3024 /**********************************************************************/
3025
3026 static void
3027 unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3028 {
3029 memcpy(dst, src, n * 4 * sizeof(GLuint));
3030 }
3031
3032 static void
3033 unpack_int_rgba_RGBA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3034 {
3035 unsigned int i;
3036
3037 for (i = 0; i < n; i++) {
3038 dst[i][0] = src[i * 4 + 0];
3039 dst[i][1] = src[i * 4 + 1];
3040 dst[i][2] = src[i * 4 + 2];
3041 dst[i][3] = src[i * 4 + 3];
3042 }
3043 }
3044
3045 static void
3046 unpack_int_rgba_RGBA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3047 {
3048 unsigned int i;
3049
3050 for (i = 0; i < n; i++) {
3051 dst[i][0] = src[i * 4 + 0];
3052 dst[i][1] = src[i * 4 + 1];
3053 dst[i][2] = src[i * 4 + 2];
3054 dst[i][3] = src[i * 4 + 3];
3055 }
3056 }
3057
3058 static void
3059 unpack_int_rgba_RGBA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3060 {
3061 unsigned int i;
3062
3063 for (i = 0; i < n; i++) {
3064 dst[i][0] = src[i * 4 + 0];
3065 dst[i][1] = src[i * 4 + 1];
3066 dst[i][2] = src[i * 4 + 2];
3067 dst[i][3] = src[i * 4 + 3];
3068 }
3069 }
3070
3071 static void
3072 unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3073 {
3074 unsigned int i;
3075
3076 for (i = 0; i < n; i++) {
3077 dst[i][0] = src[i * 4 + 0];
3078 dst[i][1] = src[i * 4 + 1];
3079 dst[i][2] = src[i * 4 + 2];
3080 dst[i][3] = src[i * 4 + 3];
3081 }
3082 }
3083
3084 static void
3085 unpack_int_rgba_B8G8R8A8_UNORM(const GLbyte *src, GLuint dst[][4], GLuint n)
3086 {
3087 unsigned int i;
3088
3089 for (i = 0; i < n; i++) {
3090 dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
3091 dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
3092 dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
3093 dst[i][ACOMP] = (GLubyte) src[i * 4 + 3];
3094 }
3095 }
3096
3097 static void
3098 unpack_int_rgba_B8G8R8X8_UNORM(const GLbyte *src, GLuint dst[][4], GLuint n)
3099 {
3100 unsigned int i;
3101
3102 for (i = 0; i < n; i++) {
3103 dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
3104 dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
3105 dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
3106 dst[i][ACOMP] = (GLubyte) 0xff;
3107 }
3108 }
3109
3110 static void
3111 unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3112 {
3113 unsigned int i;
3114
3115 for (i = 0; i < n; i++) {
3116 dst[i][0] = src[i * 3 + 0];
3117 dst[i][1] = src[i * 3 + 1];
3118 dst[i][2] = src[i * 3 + 2];
3119 dst[i][3] = 1;
3120 }
3121 }
3122
3123 static void
3124 unpack_int_rgba_RGB_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3125 {
3126 unsigned int i;
3127
3128 for (i = 0; i < n; i++) {
3129 dst[i][0] = src[i * 3 + 0];
3130 dst[i][1] = src[i * 3 + 1];
3131 dst[i][2] = src[i * 3 + 2];
3132 dst[i][3] = 1;
3133 }
3134 }
3135
3136 static void
3137 unpack_int_rgba_RGB_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3138 {
3139 unsigned int i;
3140
3141 for (i = 0; i < n; i++) {
3142 dst[i][0] = src[i * 3 + 0];
3143 dst[i][1] = src[i * 3 + 1];
3144 dst[i][2] = src[i * 3 + 2];
3145 dst[i][3] = 1;
3146 }
3147 }
3148
3149 static void
3150 unpack_int_rgba_RGB_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3151 {
3152 unsigned int i;
3153
3154 for (i = 0; i < n; i++) {
3155 dst[i][0] = src[i * 3 + 0];
3156 dst[i][1] = src[i * 3 + 1];
3157 dst[i][2] = src[i * 3 + 2];
3158 dst[i][3] = 1;
3159 }
3160 }
3161
3162 static void
3163 unpack_int_rgba_RGB_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3164 {
3165 unsigned int i;
3166
3167 for (i = 0; i < n; i++) {
3168 dst[i][0] = src[i * 3 + 0];
3169 dst[i][1] = src[i * 3 + 1];
3170 dst[i][2] = src[i * 3 + 2];
3171 dst[i][3] = 1;
3172 }
3173 }
3174
3175 static void
3176 unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3177 {
3178 unsigned int i;
3179
3180 for (i = 0; i < n; i++) {
3181 dst[i][0] = src[i * 2 + 0];
3182 dst[i][1] = src[i * 2 + 1];
3183 dst[i][2] = 0;
3184 dst[i][3] = 1;
3185 }
3186 }
3187
3188 static void
3189 unpack_int_rgba_RG_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3190 {
3191 unsigned int i;
3192
3193 for (i = 0; i < n; i++) {
3194 dst[i][0] = src[i * 2 + 0];
3195 dst[i][1] = src[i * 2 + 1];
3196 dst[i][2] = 0;
3197 dst[i][3] = 1;
3198 }
3199 }
3200
3201 static void
3202 unpack_int_rgba_RG_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3203 {
3204 unsigned int i;
3205
3206 for (i = 0; i < n; i++) {
3207 dst[i][0] = src[i * 2 + 0];
3208 dst[i][1] = src[i * 2 + 1];
3209 dst[i][2] = 0;
3210 dst[i][3] = 1;
3211 }
3212 }
3213
3214 static void
3215 unpack_int_rgba_RG_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3216 {
3217 unsigned int i;
3218
3219 for (i = 0; i < n; i++) {
3220 dst[i][0] = src[i * 2 + 0];
3221 dst[i][1] = src[i * 2 + 1];
3222 dst[i][2] = 0;
3223 dst[i][3] = 1;
3224 }
3225 }
3226
3227 static void
3228 unpack_int_rgba_RG_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3229 {
3230 unsigned int i;
3231
3232 for (i = 0; i < n; i++) {
3233 dst[i][0] = src[i * 2 + 0];
3234 dst[i][1] = src[i * 2 + 1];
3235 dst[i][2] = 0;
3236 dst[i][3] = 1;
3237 }
3238 }
3239
3240 static void
3241 unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3242 {
3243 unsigned int i;
3244
3245 for (i = 0; i < n; i++) {
3246 dst[i][0] = src[i];
3247 dst[i][1] = 0;
3248 dst[i][2] = 0;
3249 dst[i][3] = 1;
3250 }
3251 }
3252
3253 static void
3254 unpack_int_rgba_R_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3255 {
3256 unsigned int i;
3257
3258 for (i = 0; i < n; i++) {
3259 dst[i][0] = src[i];
3260 dst[i][1] = 0;
3261 dst[i][2] = 0;
3262 dst[i][3] = 1;
3263 }
3264 }
3265
3266 static void
3267 unpack_int_rgba_R_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3268 {
3269 unsigned int i;
3270
3271 for (i = 0; i < n; i++) {
3272 dst[i][0] = src[i];
3273 dst[i][1] = 0;
3274 dst[i][2] = 0;
3275 dst[i][3] = 1;
3276 }
3277 }
3278
3279 static void
3280 unpack_int_rgba_R_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3281 {
3282 unsigned int i;
3283
3284 for (i = 0; i < n; i++) {
3285 dst[i][0] = src[i];
3286 dst[i][1] = 0;
3287 dst[i][2] = 0;
3288 dst[i][3] = 1;
3289 }
3290 }
3291
3292 static void
3293 unpack_int_rgba_R_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3294 {
3295 unsigned int i;
3296
3297 for (i = 0; i < n; i++) {
3298 dst[i][0] = src[i];
3299 dst[i][1] = 0;
3300 dst[i][2] = 0;
3301 dst[i][3] = 1;
3302 }
3303 }
3304
3305 static void
3306 unpack_int_rgba_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3307 {
3308 unsigned int i;
3309
3310 for (i = 0; i < n; i++) {
3311 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3312 dst[i][3] = src[i];
3313 }
3314 }
3315
3316 static void
3317 unpack_int_rgba_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3318 {
3319 unsigned int i;
3320
3321 for (i = 0; i < n; i++) {
3322 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3323 dst[i][3] = src[i];
3324 }
3325 }
3326
3327 static void
3328 unpack_int_rgba_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3329 {
3330 unsigned int i;
3331
3332 for (i = 0; i < n; i++) {
3333 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3334 dst[i][3] = src[i];
3335 }
3336 }
3337
3338 static void
3339 unpack_int_rgba_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3340 {
3341 unsigned int i;
3342
3343 for (i = 0; i < n; i++) {
3344 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3345 dst[i][3] = src[i];
3346 }
3347 }
3348
3349 static void
3350 unpack_int_rgba_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3351 {
3352 unsigned int i;
3353
3354 for (i = 0; i < n; i++) {
3355 dst[i][0] = dst[i][1] = dst[i][2] = 0;
3356 dst[i][3] = src[i];
3357 }
3358 }
3359
3360 static void
3361 unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3362 {
3363 unsigned int i;
3364
3365 for (i = 0; i < n; i++) {
3366 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3367 dst[i][3] = 1;
3368 }
3369 }
3370
3371 static void
3372 unpack_int_rgba_LUMINANCE_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3373 {
3374 unsigned int i;
3375
3376 for (i = 0; i < n; i++) {
3377 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3378 dst[i][3] = 1;
3379 }
3380 }
3381
3382 static void
3383 unpack_int_rgba_LUMINANCE_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3384 {
3385 unsigned int i;
3386
3387 for (i = 0; i < n; i++) {
3388 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3389 dst[i][3] = 1;
3390 }
3391 }
3392
3393 static void
3394 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3395 {
3396 unsigned int i;
3397
3398 for (i = 0; i < n; i++) {
3399 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3400 dst[i][3] = 1;
3401 }
3402 }
3403
3404 static void
3405 unpack_int_rgba_LUMINANCE_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3406 {
3407 unsigned int i;
3408
3409 for (i = 0; i < n; i++) {
3410 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
3411 dst[i][3] = 1;
3412 }
3413 }
3414
3415
3416 static void
3417 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3418 {
3419 unsigned int i;
3420
3421 for (i = 0; i < n; i++) {
3422 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3423 dst[i][3] = src[i * 2 + 1];
3424 }
3425 }
3426
3427 static void
3428 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3429 {
3430 unsigned int i;
3431
3432 for (i = 0; i < n; i++) {
3433 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3434 dst[i][3] = src[i * 2 + 1];
3435 }
3436 }
3437
3438 static void
3439 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3440 {
3441 unsigned int i;
3442
3443 for (i = 0; i < n; i++) {
3444 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3445 dst[i][3] = src[i * 2 + 1];
3446 }
3447 }
3448
3449 static void
3450 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3451 {
3452 unsigned int i;
3453
3454 for (i = 0; i < n; i++) {
3455 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3456 dst[i][3] = src[i * 2 + 1];
3457 }
3458 }
3459
3460 static void
3461 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3462 {
3463 unsigned int i;
3464
3465 for (i = 0; i < n; i++) {
3466 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
3467 dst[i][3] = src[i * 2 + 1];
3468 }
3469 }
3470
3471 static void
3472 unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
3473 {
3474 unsigned int i;
3475
3476 for (i = 0; i < n; i++) {
3477 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3478 }
3479 }
3480
3481 static void
3482 unpack_int_rgba_INTENSITY_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
3483 {
3484 unsigned int i;
3485
3486 for (i = 0; i < n; i++) {
3487 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3488 }
3489 }
3490
3491 static void
3492 unpack_int_rgba_INTENSITY_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
3493 {
3494 unsigned int i;
3495
3496 for (i = 0; i < n; i++) {
3497 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3498 }
3499 }
3500
3501 static void
3502 unpack_int_rgba_INTENSITY_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
3503 {
3504 unsigned int i;
3505
3506 for (i = 0; i < n; i++) {
3507 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3508 }
3509 }
3510
3511 static void
3512 unpack_int_rgba_INTENSITY_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
3513 {
3514 unsigned int i;
3515
3516 for (i = 0; i < n; i++) {
3517 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
3518 }
3519 }
3520
3521 static void
3522 unpack_int_rgba_B10G10R10A2_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
3523 {
3524 unsigned int i;
3525
3526 for (i = 0; i < n; i++) {
3527 GLuint tmp = src[i];
3528 dst[i][0] = (tmp >> 20) & 0x3ff;
3529 dst[i][1] = (tmp >> 10) & 0x3ff;
3530 dst[i][2] = (tmp >> 0) & 0x3ff;
3531 dst[i][3] = (tmp >> 30) & 0x3;
3532 }
3533 }
3534
3535 static void
3536 unpack_int_rgba_R10G10B10A2_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
3537 {
3538 unsigned int i;
3539
3540 for (i = 0; i < n; i++) {
3541 GLuint tmp = src[i];
3542 dst[i][0] = (tmp >> 0) & 0x3ff;
3543 dst[i][1] = (tmp >> 10) & 0x3ff;
3544 dst[i][2] = (tmp >> 20) & 0x3ff;
3545 dst[i][3] = (tmp >> 30) & 0x3;
3546 }
3547 }
3548
3549 static void
3550 unpack_int_rgba_B10G10R10A2_UNORM(const GLuint *src, GLuint dst[][4], GLuint n)
3551 {
3552 unsigned int i;
3553
3554 for (i = 0; i < n; i++) {
3555 GLuint tmp = src[i];
3556 dst[i][0] = (tmp >> 20) & 0x3ff;
3557 dst[i][1] = (tmp >> 10) & 0x3ff;
3558 dst[i][2] = (tmp >> 0) & 0x3ff;
3559 dst[i][3] = (tmp >> 30) & 0x3;
3560 }
3561 }
3562
3563 static void
3564 unpack_int_rgba_XBGR8888_UINT(const GLubyte *src, GLuint dst[][4], GLuint n)
3565 {
3566 unsigned int i;
3567
3568 for (i = 0; i < n; i++) {
3569 dst[i][0] = src[i * 4 + 0];
3570 dst[i][1] = src[i * 4 + 1];
3571 dst[i][2] = src[i * 4 + 2];
3572 dst[i][3] = 1;
3573 }
3574 }
3575
3576 static void
3577 unpack_int_rgba_XBGR8888_SINT(const GLbyte *src, GLuint dst[][4], GLuint n)
3578 {
3579 unsigned int i;
3580
3581 for (i = 0; i < n; i++) {
3582 dst[i][0] = src[i * 4 + 0];
3583 dst[i][1] = src[i * 4 + 1];
3584 dst[i][2] = src[i * 4 + 2];
3585 dst[i][3] = 1;
3586 }
3587 }
3588
3589 static void
3590 unpack_int_rgba_XBGR16161616_UINT(const GLushort *src, GLuint dst[][4], GLuint n)
3591 {
3592 unsigned int i;
3593
3594 for (i = 0; i < n; i++) {
3595 dst[i][0] = src[i * 4 + 0];
3596 dst[i][1] = src[i * 4 + 1];
3597 dst[i][2] = src[i * 4 + 2];
3598 dst[i][3] = 1;
3599 }
3600 }
3601
3602 static void
3603 unpack_int_rgba_XBGR16161616_SINT(const GLshort *src, GLuint dst[][4], GLuint n)
3604 {
3605 unsigned int i;
3606
3607 for (i = 0; i < n; i++) {
3608 dst[i][0] = src[i * 4 + 0];
3609 dst[i][1] = src[i * 4 + 1];
3610 dst[i][2] = src[i * 4 + 2];
3611 dst[i][3] = 1;
3612 }
3613 }
3614
3615 static void
3616 unpack_int_rgba_XBGR32323232_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
3617 {
3618 unsigned int i;
3619
3620 for (i = 0; i < n; i++) {
3621 dst[i][0] = src[i * 4 + 0];
3622 dst[i][1] = src[i * 4 + 1];
3623 dst[i][2] = src[i * 4 + 2];
3624 dst[i][3] = 1;
3625 }
3626 }
3627
3628 static void
3629 unpack_int_rgba_R10G10B10A2_UNORM(const GLuint *src, GLuint dst[][4], GLuint n)
3630 {
3631 unsigned int i;
3632
3633 for (i = 0; i < n; i++) {
3634 GLuint tmp = src[i];
3635 dst[i][0] = (tmp >> 0) & 0x3ff;
3636 dst[i][1] = (tmp >> 10) & 0x3ff;
3637 dst[i][2] = (tmp >> 20) & 0x3ff;
3638 dst[i][3] = (tmp >> 30) & 0x3;
3639 }
3640 }
3641
3642 void
3643 _mesa_unpack_uint_rgba_row(mesa_format format, GLuint n,
3644 const void *src, GLuint dst[][4])
3645 {
3646 switch (format) {
3647 /* Since there won't be any sign extension happening, there's no need to
3648 * make separate paths for 32-bit-to-32-bit integer unpack.
3649 */
3650 case MESA_FORMAT_RGBA_UINT32:
3651 case MESA_FORMAT_RGBA_SINT32:
3652 unpack_int_rgba_RGBA_UINT32(src, dst, n);
3653 break;
3654
3655 case MESA_FORMAT_RGBA_UINT16:
3656 unpack_int_rgba_RGBA_UINT16(src, dst, n);
3657 break;
3658 case MESA_FORMAT_RGBA_SINT16:
3659 unpack_int_rgba_RGBA_INT16(src, dst, n);
3660 break;
3661
3662 case MESA_FORMAT_RGBA_UINT8:
3663 unpack_int_rgba_RGBA_UINT8(src, dst, n);
3664 break;
3665 case MESA_FORMAT_RGBA_SINT8:
3666 unpack_int_rgba_RGBA_INT8(src, dst, n);
3667 break;
3668
3669 case MESA_FORMAT_B8G8R8A8_UNORM:
3670 unpack_int_rgba_B8G8R8A8_UNORM(src, dst, n);
3671 break;
3672
3673 case MESA_FORMAT_B8G8R8X8_UNORM:
3674 unpack_int_rgba_B8G8R8X8_UNORM(src, dst, n);
3675 break;
3676
3677 case MESA_FORMAT_RGB_UINT32:
3678 case MESA_FORMAT_RGB_SINT32:
3679 unpack_int_rgba_RGB_UINT32(src, dst, n);
3680 break;
3681
3682 case MESA_FORMAT_RGB_UINT16:
3683 unpack_int_rgba_RGB_UINT16(src, dst, n);
3684 break;
3685 case MESA_FORMAT_RGB_SINT16:
3686 unpack_int_rgba_RGB_INT16(src, dst, n);
3687 break;
3688
3689 case MESA_FORMAT_RGB_UINT8:
3690 unpack_int_rgba_RGB_UINT8(src, dst, n);
3691 break;
3692 case MESA_FORMAT_RGB_SINT8:
3693 unpack_int_rgba_RGB_INT8(src, dst, n);
3694 break;
3695
3696 case MESA_FORMAT_RG_UINT32:
3697 case MESA_FORMAT_RG_SINT32:
3698 unpack_int_rgba_RG_UINT32(src, dst, n);
3699 break;
3700
3701 case MESA_FORMAT_RG_UINT16:
3702 unpack_int_rgba_RG_UINT16(src, dst, n);
3703 break;
3704 case MESA_FORMAT_RG_SINT16:
3705 unpack_int_rgba_RG_INT16(src, dst, n);
3706 break;
3707
3708 case MESA_FORMAT_RG_UINT8:
3709 unpack_int_rgba_RG_UINT8(src, dst, n);
3710 break;
3711 case MESA_FORMAT_RG_SINT8:
3712 unpack_int_rgba_RG_INT8(src, dst, n);
3713 break;
3714
3715 case MESA_FORMAT_R_UINT32:
3716 case MESA_FORMAT_R_SINT32:
3717 unpack_int_rgba_R_UINT32(src, dst, n);
3718 break;
3719
3720 case MESA_FORMAT_R_UINT16:
3721 unpack_int_rgba_R_UINT16(src, dst, n);
3722 break;
3723 case MESA_FORMAT_R_SINT16:
3724 unpack_int_rgba_R_INT16(src, dst, n);
3725 break;
3726
3727 case MESA_FORMAT_R_UINT8:
3728 unpack_int_rgba_R_UINT8(src, dst, n);
3729 break;
3730 case MESA_FORMAT_R_SINT8:
3731 unpack_int_rgba_R_INT8(src, dst, n);
3732 break;
3733
3734 case MESA_FORMAT_A_UINT32:
3735 case MESA_FORMAT_A_SINT32:
3736 unpack_int_rgba_ALPHA_UINT32(src, dst, n);
3737 break;
3738
3739 case MESA_FORMAT_A_UINT16:
3740 unpack_int_rgba_ALPHA_UINT16(src, dst, n);
3741 break;
3742 case MESA_FORMAT_A_SINT16:
3743 unpack_int_rgba_ALPHA_INT16(src, dst, n);
3744 break;
3745
3746 case MESA_FORMAT_A_UINT8:
3747 unpack_int_rgba_ALPHA_UINT8(src, dst, n);
3748 break;
3749 case MESA_FORMAT_A_SINT8:
3750 unpack_int_rgba_ALPHA_INT8(src, dst, n);
3751 break;
3752
3753 case MESA_FORMAT_L_UINT32:
3754 case MESA_FORMAT_L_SINT32:
3755 unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
3756 break;
3757 case MESA_FORMAT_L_UINT16:
3758 unpack_int_rgba_LUMINANCE_UINT16(src, dst, n);
3759 break;
3760 case MESA_FORMAT_L_SINT16:
3761 unpack_int_rgba_LUMINANCE_INT16(src, dst, n);
3762 break;
3763
3764 case MESA_FORMAT_L_UINT8:
3765 unpack_int_rgba_LUMINANCE_UINT8(src, dst, n);
3766 break;
3767 case MESA_FORMAT_L_SINT8:
3768 unpack_int_rgba_LUMINANCE_INT8(src, dst, n);
3769 break;
3770
3771 case MESA_FORMAT_LA_UINT32:
3772 case MESA_FORMAT_LA_SINT32:
3773 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
3774 break;
3775
3776 case MESA_FORMAT_LA_UINT16:
3777 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src, dst, n);
3778 break;
3779 case MESA_FORMAT_LA_SINT16:
3780 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src, dst, n);
3781 break;
3782
3783 case MESA_FORMAT_LA_UINT8:
3784 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src, dst, n);
3785 break;
3786 case MESA_FORMAT_LA_SINT8:
3787 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src, dst, n);
3788 break;
3789
3790 case MESA_FORMAT_I_UINT32:
3791 case MESA_FORMAT_I_SINT32:
3792 unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
3793 break;
3794
3795 case MESA_FORMAT_I_UINT16:
3796 unpack_int_rgba_INTENSITY_UINT16(src, dst, n);
3797 break;
3798 case MESA_FORMAT_I_SINT16:
3799 unpack_int_rgba_INTENSITY_INT16(src, dst, n);
3800 break;
3801
3802 case MESA_FORMAT_I_UINT8:
3803 unpack_int_rgba_INTENSITY_UINT8(src, dst, n);
3804 break;
3805 case MESA_FORMAT_I_SINT8:
3806 unpack_int_rgba_INTENSITY_INT8(src, dst, n);
3807 break;
3808
3809 case MESA_FORMAT_B10G10R10A2_UINT:
3810 unpack_int_rgba_B10G10R10A2_UINT(src, dst, n);
3811 break;
3812
3813 case MESA_FORMAT_R10G10B10A2_UINT:
3814 unpack_int_rgba_R10G10B10A2_UINT(src, dst, n);
3815 break;
3816
3817 case MESA_FORMAT_B10G10R10A2_UNORM:
3818 unpack_int_rgba_B10G10R10A2_UNORM(src, dst, n);
3819 break;
3820
3821 case MESA_FORMAT_RGBX_UINT8:
3822 unpack_int_rgba_XBGR8888_UINT(src, dst, n);
3823 break;
3824
3825 case MESA_FORMAT_RGBX_SINT8:
3826 unpack_int_rgba_XBGR8888_SINT(src, dst, n);
3827 break;
3828
3829 case MESA_FORMAT_RGBX_UINT16:
3830 unpack_int_rgba_XBGR16161616_UINT(src, dst, n);
3831 break;
3832
3833 case MESA_FORMAT_RGBX_SINT16:
3834 unpack_int_rgba_XBGR16161616_SINT(src, dst, n);
3835 break;
3836
3837 case MESA_FORMAT_RGBX_UINT32:
3838 case MESA_FORMAT_RGBX_SINT32:
3839 unpack_int_rgba_XBGR32323232_UINT(src, dst, n);
3840 break;
3841
3842 case MESA_FORMAT_R10G10B10A2_UNORM:
3843 unpack_int_rgba_R10G10B10A2_UNORM(src, dst, n);
3844 break;
3845
3846 default:
3847 _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
3848 _mesa_get_format_name(format));
3849 return;
3850 }
3851 }
3852
3853 /**
3854 * Unpack a 2D rect of pixels returning float RGBA colors.
3855 * \param format the source image format
3856 * \param src start address of the source image
3857 * \param srcRowStride source image row stride in bytes
3858 * \param dst start address of the dest image
3859 * \param dstRowStride dest image row stride in bytes
3860 * \param x source image start X pos
3861 * \param y source image start Y pos
3862 * \param width width of rect region to convert
3863 * \param height height of rect region to convert
3864 */
3865 void
3866 _mesa_unpack_rgba_block(mesa_format format,
3867 const void *src, GLint srcRowStride,
3868 GLfloat dst[][4], GLint dstRowStride,
3869 GLuint x, GLuint y, GLuint width, GLuint height)
3870 {
3871 unpack_rgba_func unpack = get_unpack_rgba_function(format);
3872 const GLuint srcPixStride = _mesa_get_format_bytes(format);
3873 const GLuint dstPixStride = 4 * sizeof(GLfloat);
3874 const GLubyte *srcRow;
3875 GLubyte *dstRow;
3876 GLuint i;
3877
3878 /* XXX needs to be fixed for compressed formats */
3879
3880 srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
3881 dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
3882
3883 for (i = 0; i < height; i++) {
3884 unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
3885
3886 dstRow += dstRowStride;
3887 srcRow += srcRowStride;
3888 }
3889 }
3890
3891
3892
3893
3894 typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
3895
3896 static void
3897 unpack_float_z_X8_UINT_Z24_UNORM(GLuint n, const void *src, GLfloat *dst)
3898 {
3899 /* only return Z, not stencil data */
3900 const GLuint *s = ((const GLuint *) src);
3901 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
3902 GLuint i;
3903 for (i = 0; i < n; i++) {
3904 dst[i] = (GLfloat) ((s[i] >> 8) * scale);
3905 ASSERT(dst[i] >= 0.0F);
3906 ASSERT(dst[i] <= 1.0F);
3907 }
3908 }
3909
3910 static void
3911 unpack_float_z_Z24_UNORM_X8_UINT(GLuint n, const void *src, GLfloat *dst)
3912 {
3913 /* only return Z, not stencil data */
3914 const GLuint *s = ((const GLuint *) src);
3915 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
3916 GLuint i;
3917 for (i = 0; i < n; i++) {
3918 dst[i] = (GLfloat) ((s[i] & 0x00ffffff) * scale);
3919 ASSERT(dst[i] >= 0.0F);
3920 ASSERT(dst[i] <= 1.0F);
3921 }
3922 }
3923
3924 static void
3925 unpack_float_Z_UNORM16(GLuint n, const void *src, GLfloat *dst)
3926 {
3927 const GLushort *s = ((const GLushort *) src);
3928 GLuint i;
3929 for (i = 0; i < n; i++) {
3930 dst[i] = s[i] * (1.0F / 65535.0F);
3931 }
3932 }
3933
3934 static void
3935 unpack_float_Z_UNORM32(GLuint n, const void *src, GLfloat *dst)
3936 {
3937 const GLuint *s = ((const GLuint *) src);
3938 GLuint i;
3939 for (i = 0; i < n; i++) {
3940 dst[i] = s[i] * (1.0F / 0xffffffff);
3941 }
3942 }
3943
3944 static void
3945 unpack_float_Z_FLOAT32(GLuint n, const void *src, GLfloat *dst)
3946 {
3947 memcpy(dst, src, n * sizeof(float));
3948 }
3949
3950 static void
3951 unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
3952 {
3953 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
3954 GLuint i;
3955 for (i = 0; i < n; i++) {
3956 dst[i] = s[i].z;
3957 }
3958 }
3959
3960
3961
3962 /**
3963 * Unpack Z values.
3964 * The returned values will always be in the range [0.0, 1.0].
3965 */
3966 void
3967 _mesa_unpack_float_z_row(mesa_format format, GLuint n,
3968 const void *src, GLfloat *dst)
3969 {
3970 unpack_float_z_func unpack;
3971
3972 switch (format) {
3973 case MESA_FORMAT_S8_UINT_Z24_UNORM:
3974 case MESA_FORMAT_X8_UINT_Z24_UNORM:
3975 unpack = unpack_float_z_X8_UINT_Z24_UNORM;
3976 break;
3977 case MESA_FORMAT_Z24_UNORM_S8_UINT:
3978 case MESA_FORMAT_Z24_UNORM_X8_UINT:
3979 unpack = unpack_float_z_Z24_UNORM_X8_UINT;
3980 break;
3981 case MESA_FORMAT_Z_UNORM16:
3982 unpack = unpack_float_Z_UNORM16;
3983 break;
3984 case MESA_FORMAT_Z_UNORM32:
3985 unpack = unpack_float_Z_UNORM32;
3986 break;
3987 case MESA_FORMAT_Z_FLOAT32:
3988 unpack = unpack_float_Z_FLOAT32;
3989 break;
3990 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
3991 unpack = unpack_float_z_Z32X24S8;
3992 break;
3993 default:
3994 _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
3995 _mesa_get_format_name(format));
3996 return;
3997 }
3998
3999 unpack(n, src, dst);
4000 }
4001
4002
4003
4004 typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
4005
4006 static void
4007 unpack_uint_z_X8_UINT_Z24_UNORM(const void *src, GLuint *dst, GLuint n)
4008 {
4009 /* only return Z, not stencil data */
4010 const GLuint *s = ((const GLuint *) src);
4011 GLuint i;
4012 for (i = 0; i < n; i++) {
4013 dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
4014 }
4015 }
4016
4017 static void
4018 unpack_uint_z_Z24_UNORM_X8_UINT(const void *src, GLuint *dst, GLuint n)
4019 {
4020 /* only return Z, not stencil data */
4021 const GLuint *s = ((const GLuint *) src);
4022 GLuint i;
4023 for (i = 0; i < n; i++) {
4024 dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
4025 }
4026 }
4027
4028 static void
4029 unpack_uint_Z_UNORM16(const void *src, GLuint *dst, GLuint n)
4030 {
4031 const GLushort *s = ((const GLushort *)src);
4032 GLuint i;
4033 for (i = 0; i < n; i++) {
4034 dst[i] = (s[i] << 16) | s[i];
4035 }
4036 }
4037
4038 static void
4039 unpack_uint_Z_UNORM32(const void *src, GLuint *dst, GLuint n)
4040 {
4041 memcpy(dst, src, n * sizeof(GLuint));
4042 }
4043
4044 static void
4045 unpack_uint_Z_FLOAT32(const void *src, GLuint *dst, GLuint n)
4046 {
4047 const float *s = (const float *)src;
4048 GLuint i;
4049 for (i = 0; i < n; i++) {
4050 dst[i] = FLOAT_TO_UINT(CLAMP(s[i], 0.0F, 1.0F));
4051 }
4052 }
4053
4054 static void
4055 unpack_uint_Z_FLOAT32_X24S8(const void *src, GLuint *dst, GLuint n)
4056 {
4057 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
4058 GLuint i;
4059
4060 for (i = 0; i < n; i++) {
4061 dst[i] = FLOAT_TO_UINT(CLAMP(s[i].z, 0.0F, 1.0F));
4062 }
4063 }
4064
4065
4066 /**
4067 * Unpack Z values.
4068 * The returned values will always be in the range [0, 0xffffffff].
4069 */
4070 void
4071 _mesa_unpack_uint_z_row(mesa_format format, GLuint n,
4072 const void *src, GLuint *dst)
4073 {
4074 unpack_uint_z_func unpack;
4075 const GLubyte *srcPtr = (GLubyte *) src;
4076
4077 switch (format) {
4078 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4079 case MESA_FORMAT_X8_UINT_Z24_UNORM:
4080 unpack = unpack_uint_z_X8_UINT_Z24_UNORM;
4081 break;
4082 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4083 case MESA_FORMAT_Z24_UNORM_X8_UINT:
4084 unpack = unpack_uint_z_Z24_UNORM_X8_UINT;
4085 break;
4086 case MESA_FORMAT_Z_UNORM16:
4087 unpack = unpack_uint_Z_UNORM16;
4088 break;
4089 case MESA_FORMAT_Z_UNORM32:
4090 unpack = unpack_uint_Z_UNORM32;
4091 break;
4092 case MESA_FORMAT_Z_FLOAT32:
4093 unpack = unpack_uint_Z_FLOAT32;
4094 break;
4095 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4096 unpack = unpack_uint_Z_FLOAT32_X24S8;
4097 break;
4098 default:
4099 _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
4100 _mesa_get_format_name(format));
4101 return;
4102 }
4103
4104 unpack(srcPtr, dst, n);
4105 }
4106
4107
4108 static void
4109 unpack_ubyte_s_S_UINT8(const void *src, GLubyte *dst, GLuint n)
4110 {
4111 memcpy(dst, src, n);
4112 }
4113
4114 static void
4115 unpack_ubyte_s_S8_UINT_Z24_UNORM(const void *src, GLubyte *dst, GLuint n)
4116 {
4117 GLuint i;
4118 const GLuint *src32 = src;
4119
4120 for (i = 0; i < n; i++)
4121 dst[i] = src32[i] & 0xff;
4122 }
4123
4124 static void
4125 unpack_ubyte_s_Z24_UNORM_S8_UINT(const void *src, GLubyte *dst, GLuint n)
4126 {
4127 GLuint i;
4128 const GLuint *src32 = src;
4129
4130 for (i = 0; i < n; i++)
4131 dst[i] = src32[i] >> 24;
4132 }
4133
4134 static void
4135 unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(const void *src, GLubyte *dst, GLuint n)
4136 {
4137 GLuint i;
4138 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
4139
4140 for (i = 0; i < n; i++)
4141 dst[i] = s[i].x24s8 & 0xff;
4142 }
4143
4144 void
4145 _mesa_unpack_ubyte_stencil_row(mesa_format format, GLuint n,
4146 const void *src, GLubyte *dst)
4147 {
4148 switch (format) {
4149 case MESA_FORMAT_S_UINT8:
4150 unpack_ubyte_s_S_UINT8(src, dst, n);
4151 break;
4152 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4153 unpack_ubyte_s_S8_UINT_Z24_UNORM(src, dst, n);
4154 break;
4155 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4156 unpack_ubyte_s_Z24_UNORM_S8_UINT(src, dst, n);
4157 break;
4158 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4159 unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(src, dst, n);
4160 break;
4161 default:
4162 _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
4163 _mesa_get_format_name(format));
4164 return;
4165 }
4166 }
4167
4168 static void
4169 unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(const GLuint *src, GLuint *dst, GLuint n)
4170 {
4171 GLuint i;
4172
4173 for (i = 0; i < n; i++) {
4174 GLuint val = src[i];
4175 dst[i] = val >> 24 | val << 8;
4176 }
4177 }
4178
4179 static void
4180 unpack_uint_24_8_depth_stencil_Z32_S8X24(const GLuint *src,
4181 GLuint *dst, GLuint n)
4182 {
4183 GLuint i;
4184
4185 for (i = 0; i < n; i++) {
4186 /* 8 bytes per pixel (float + uint32) */
4187 GLfloat zf = ((GLfloat *) src)[i * 2 + 0];
4188 GLuint z24 = (GLuint) (zf * (GLfloat) 0xffffff);
4189 GLuint s = src[i * 2 + 1] & 0xff;
4190 dst[i] = (z24 << 8) | s;
4191 }
4192 }
4193
4194 static void
4195 unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(const GLuint *src, GLuint *dst, GLuint n)
4196 {
4197 memcpy(dst, src, n * 4);
4198 }
4199
4200 /**
4201 * Unpack depth/stencil returning as GL_UNSIGNED_INT_24_8.
4202 * \param format the source data format
4203 */
4204 void
4205 _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
4206 const void *src, GLuint *dst)
4207 {
4208 switch (format) {
4209 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4210 unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(src, dst, n);
4211 break;
4212 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4213 unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(src, dst, n);
4214 break;
4215 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4216 unpack_uint_24_8_depth_stencil_Z32_S8X24(src, dst, n);
4217 break;
4218 default:
4219 _mesa_problem(NULL,
4220 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
4221 _mesa_get_format_name(format));
4222 return;
4223 }
4224 }
4225
4226 static void
4227 unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(const GLuint *src,
4228 GLuint *dst, GLuint n)
4229 {
4230 GLuint i;
4231 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
4232 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
4233
4234 for (i = 0; i < n; i++) {
4235 const GLuint z24 = src[i] & 0xffffff;
4236 d[i].z = z24 * scale;
4237 d[i].x24s8 = src[i] >> 24;
4238 assert(d[i].z >= 0.0f);
4239 assert(d[i].z <= 1.0f);
4240 }
4241 }
4242
4243 static void
4244 unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(const GLuint *src,
4245 GLuint *dst, GLuint n)
4246 {
4247 memcpy(dst, src, n * sizeof(struct z32f_x24s8));
4248 }
4249
4250 static void
4251 unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(const GLuint *src,
4252 GLuint *dst, GLuint n)
4253 {
4254 GLuint i;
4255 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
4256 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
4257
4258 for (i = 0; i < n; i++) {
4259 const GLuint z24 = src[i] >> 8;
4260 d[i].z = z24 * scale;
4261 d[i].x24s8 = src[i] & 0xff;
4262 assert(d[i].z >= 0.0f);
4263 assert(d[i].z <= 1.0f);
4264 }
4265 }
4266
4267 /**
4268 * Unpack depth/stencil returning as GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
4269 * \param format the source data format
4270 *
4271 * In GL_FLOAT_32_UNSIGNED_INT_24_8_REV lower 4 bytes contain float
4272 * component and higher 4 bytes contain packed 24-bit and 8-bit
4273 * components.
4274 *
4275 * 31 30 29 28 ... 4 3 2 1 0 31 30 29 ... 9 8 7 6 5 ... 2 1 0
4276 * +-------------------------+ +--------------------------------+
4277 * | Float Component | | Unused | 8 bit stencil |
4278 * +-------------------------+ +--------------------------------+
4279 * lower 4 bytes higher 4 bytes
4280 */
4281 void
4282 _mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
4283 const void *src, GLuint *dst)
4284 {
4285 switch (format) {
4286 case MESA_FORMAT_S8_UINT_Z24_UNORM:
4287 unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(src, dst, n);
4288 break;
4289 case MESA_FORMAT_Z24_UNORM_S8_UINT:
4290 unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(src, dst, n);
4291 break;
4292 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
4293 unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(src, dst, n);
4294 break;
4295 default:
4296 _mesa_problem(NULL,
4297 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
4298 _mesa_get_format_name(format));
4299 return;
4300 }
4301 }
4302
4303 /**
4304 * Unpack depth/stencil
4305 * \param format the source data format
4306 * \param type the destination data type
4307 */
4308 void
4309 _mesa_unpack_depth_stencil_row(mesa_format format, GLuint n,
4310 const void *src, GLenum type,
4311 GLuint *dst)
4312 {
4313 assert(type == GL_UNSIGNED_INT_24_8 ||
4314 type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
4315
4316 switch (type) {
4317 case GL_UNSIGNED_INT_24_8:
4318 _mesa_unpack_uint_24_8_depth_stencil_row(format, n, src, dst);
4319 break;
4320 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
4321 _mesa_unpack_float_32_uint_24_8_depth_stencil_row(format, n, src, dst);
4322 break;
4323 default:
4324 _mesa_problem(NULL,
4325 "bad type 0x%x in _mesa_unpack_depth_stencil_row",
4326 type);
4327 return;
4328 }
4329 }