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