mesa: add casts to fix unpack_SIGNED_GR1616()
[mesa.git] / src / mesa / main / format_unpack.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (c) 2011 VMware, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25 #include "colormac.h"
26 #include "format_unpack.h"
27 #include "macros.h"
28 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
29 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
30
31
32 /**
33 * Convert an 8-bit sRGB value from non-linear space to a
34 * linear RGB value in [0, 1].
35 * Implemented with a 256-entry lookup table.
36 */
37 static inline GLfloat
38 nonlinear_to_linear(GLubyte cs8)
39 {
40 static GLfloat table[256];
41 static GLboolean tableReady = GL_FALSE;
42 if (!tableReady) {
43 /* compute lookup table now */
44 GLuint i;
45 for (i = 0; i < 256; i++) {
46 const GLfloat cs = UBYTE_TO_FLOAT(i);
47 if (cs <= 0.04045) {
48 table[i] = cs / 12.92f;
49 }
50 else {
51 table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
52 }
53 }
54 tableReady = GL_TRUE;
55 }
56 return table[cs8];
57 }
58
59
60 typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);
61
62
63 static void
64 unpack_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
65 {
66 const GLuint *s = ((const GLuint *) src);
67 GLuint i;
68 for (i = 0; i < n; i++) {
69 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
70 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
71 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
72 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
73 }
74 }
75
76 static void
77 unpack_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
78 {
79 const GLuint *s = ((const GLuint *) src);
80 GLuint i;
81 for (i = 0; i < n; i++) {
82 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
83 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
84 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
85 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
86 }
87 }
88
89 static void
90 unpack_ARGB8888(const void *src, GLfloat dst[][4], GLuint n)
91 {
92 const GLuint *s = ((const GLuint *) src);
93 GLuint i;
94 for (i = 0; i < n; i++) {
95 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
96 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
97 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
98 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
99 }
100 }
101
102 static void
103 unpack_ARGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
104 {
105 const GLuint *s = ((const GLuint *) src);
106 GLuint i;
107 for (i = 0; i < n; i++) {
108 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
109 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
110 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
111 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
112 }
113 }
114
115 static void
116 unpack_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
117 {
118 const GLuint *s = ((const GLuint *) src);
119 GLuint i;
120 for (i = 0; i < n; i++) {
121 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
122 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
123 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
124 dst[i][ACOMP] = 1.0f;
125 }
126 }
127
128 static void
129 unpack_RGBX8888_REV(const void *src, GLfloat dst[][4], GLuint n)
130 {
131 const GLuint *s = ((const GLuint *) src);
132 GLuint i;
133 for (i = 0; i < n; i++) {
134 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
135 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
136 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
137 dst[i][ACOMP] = 1.0f;
138 }
139 }
140
141 static void
142 unpack_XRGB8888(const void *src, GLfloat dst[][4], GLuint n)
143 {
144 const GLuint *s = ((const GLuint *) src);
145 GLuint i;
146 for (i = 0; i < n; i++) {
147 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
148 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
149 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
150 dst[i][ACOMP] = 1.0f;
151 }
152 }
153
154 static void
155 unpack_XRGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
156 {
157 const GLuint *s = ((const GLuint *) src);
158 GLuint i;
159 for (i = 0; i < n; i++) {
160 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
161 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
162 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
163 dst[i][ACOMP] = 1.0f;
164 }
165 }
166
167 static void
168 unpack_RGB888(const void *src, GLfloat dst[][4], GLuint n)
169 {
170 const GLubyte *s = (const GLubyte *) src;
171 GLuint i;
172 for (i = 0; i < n; i++) {
173 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
174 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
175 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
176 dst[i][ACOMP] = 1.0F;
177 }
178 }
179
180 static void
181 unpack_BGR888(const void *src, GLfloat dst[][4], GLuint n)
182 {
183 const GLubyte *s = (const GLubyte *) src;
184 GLuint i;
185 for (i = 0; i < n; i++) {
186 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
187 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
188 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
189 dst[i][ACOMP] = 1.0F;
190 }
191 }
192
193 static void
194 unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n)
195 {
196 const GLushort *s = ((const GLushort *) src);
197 GLuint i;
198 for (i = 0; i < n; i++) {
199 dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
200 dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F);
201 dst[i][BCOMP] = ((s[i] ) & 0x1f) * (1.0F / 31.0F);
202 dst[i][ACOMP] = 1.0F;
203 }
204 }
205
206 static void
207 unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n)
208 {
209 const GLushort *s = ((const GLushort *) src);
210 GLuint i;
211 for (i = 0; i < n; i++) {
212 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
213 dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) );
214 dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >> 9) & 0x3) );
215 dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >> 2) & 0x7) );
216 dst[i][ACOMP] = 1.0F;
217 }
218 }
219
220 static void
221 unpack_ARGB4444(const void *src, GLfloat dst[][4], GLuint n)
222 {
223 const GLushort *s = ((const GLushort *) src);
224 GLuint i;
225 for (i = 0; i < n; i++) {
226 dst[i][RCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
227 dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
228 dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
229 dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
230 }
231 }
232
233 static void
234 unpack_ARGB4444_REV(const void *src, GLfloat dst[][4], GLuint n)
235 {
236 const GLushort *s = ((const GLushort *) src);
237 GLuint i;
238 for (i = 0; i < n; i++) {
239 dst[i][RCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
240 dst[i][GCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
241 dst[i][BCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
242 dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
243 }
244 }
245
246 static void
247 unpack_RGBA5551(const void *src, GLfloat dst[][4], GLuint n)
248 {
249 const GLushort *s = ((const GLushort *) src);
250 GLuint i;
251 for (i = 0; i < n; i++) {
252 dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
253 dst[i][GCOMP] = ((s[i] >> 6) & 0x1f) * (1.0F / 31.0F);
254 dst[i][BCOMP] = ((s[i] >> 1) & 0x1f) * (1.0F / 31.0F);
255 dst[i][ACOMP] = ((s[i] ) & 0x01) * 1.0F;
256 }
257 }
258
259 static void
260 unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n)
261 {
262 const GLushort *s = ((const GLushort *) src);
263 GLuint i;
264 for (i = 0; i < n; i++) {
265 dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
266 dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F);
267 dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F);
268 dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F;
269 }
270 }
271
272 static void
273 unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n)
274 {
275 const GLushort *s = ((const GLushort *) src);
276 GLuint i;
277 for (i = 0; i < n; i++) {
278 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
279 dst[i][RCOMP] = ((tmp >> 10) & 0x1f) * (1.0F / 31.0F);
280 dst[i][GCOMP] = ((tmp >> 5) & 0x1f) * (1.0F / 31.0F);
281 dst[i][BCOMP] = ((tmp >> 0) & 0x1f) * (1.0F / 31.0F);
282 dst[i][ACOMP] = ((tmp >> 15) & 0x01) * 1.0F;
283 }
284 }
285
286 static void
287 unpack_AL44(const void *src, GLfloat dst[][4], GLuint n)
288 {
289 const GLubyte *s = ((const GLubyte *) src);
290 GLuint i;
291 for (i = 0; i < n; i++) {
292 dst[i][RCOMP] =
293 dst[i][GCOMP] =
294 dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
295 dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
296 }
297 }
298
299 static void
300 unpack_AL88(const void *src, GLfloat dst[][4], GLuint n)
301 {
302 const GLushort *s = ((const GLushort *) src);
303 GLuint i;
304 for (i = 0; i < n; i++) {
305 dst[i][RCOMP] =
306 dst[i][GCOMP] =
307 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
308 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
309 }
310 }
311
312 static void
313 unpack_AL88_REV(const void *src, GLfloat dst[][4], GLuint n)
314 {
315 const GLushort *s = ((const GLushort *) src);
316 GLuint i;
317 for (i = 0; i < n; i++) {
318 dst[i][RCOMP] =
319 dst[i][GCOMP] =
320 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
321 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
322 }
323 }
324
325 static void
326 unpack_AL1616(const void *src, GLfloat dst[][4], GLuint n)
327 {
328 const GLuint *s = ((const GLuint *) src);
329 GLuint i;
330 for (i = 0; i < n; i++) {
331 dst[i][RCOMP] =
332 dst[i][GCOMP] =
333 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
334 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
335 }
336 }
337
338 static void
339 unpack_AL1616_REV(const void *src, GLfloat dst[][4], GLuint n)
340 {
341 const GLuint *s = ((const GLuint *) src);
342 GLuint i;
343 for (i = 0; i < n; i++) {
344 dst[i][RCOMP] =
345 dst[i][GCOMP] =
346 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
347 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
348 }
349 }
350
351 static void
352 unpack_RGB332(const void *src, GLfloat dst[][4], GLuint n)
353 {
354 const GLubyte *s = ((const GLubyte *) src);
355 GLuint i;
356 for (i = 0; i < n; i++) {
357 dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F);
358 dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F);
359 dst[i][BCOMP] = ((s[i] ) & 0x3) * (1.0F / 3.0F);
360 dst[i][ACOMP] = 1.0F;
361 }
362 }
363
364
365 static void
366 unpack_A8(const void *src, GLfloat dst[][4], GLuint n)
367 {
368 const GLubyte *s = ((const GLubyte *) src);
369 GLuint i;
370 for (i = 0; i < n; i++) {
371 dst[i][RCOMP] =
372 dst[i][GCOMP] =
373 dst[i][BCOMP] = 0.0F;
374 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
375 }
376 }
377
378 static void
379 unpack_A16(const void *src, GLfloat dst[][4], GLuint n)
380 {
381 const GLushort *s = ((const GLushort *) src);
382 GLuint i;
383 for (i = 0; i < n; i++) {
384 dst[i][RCOMP] =
385 dst[i][GCOMP] =
386 dst[i][BCOMP] = 0.0F;
387 dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
388 }
389 }
390
391 static void
392 unpack_L8(const void *src, GLfloat dst[][4], GLuint n)
393 {
394 const GLubyte *s = ((const GLubyte *) src);
395 GLuint i;
396 for (i = 0; i < n; i++) {
397 dst[i][RCOMP] =
398 dst[i][GCOMP] =
399 dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
400 dst[i][ACOMP] = 1.0F;
401 }
402 }
403
404 static void
405 unpack_L16(const void *src, GLfloat dst[][4], GLuint n)
406 {
407 const GLushort *s = ((const GLushort *) src);
408 GLuint i;
409 for (i = 0; i < n; i++) {
410 dst[i][RCOMP] =
411 dst[i][GCOMP] =
412 dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
413 dst[i][ACOMP] = 1.0F;
414 }
415 }
416
417 static void
418 unpack_I8(const void *src, GLfloat dst[][4], GLuint n)
419 {
420 const GLubyte *s = ((const GLubyte *) src);
421 GLuint i;
422 for (i = 0; i < n; i++) {
423 dst[i][RCOMP] =
424 dst[i][GCOMP] =
425 dst[i][BCOMP] =
426 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
427 }
428 }
429
430 static void
431 unpack_I16(const void *src, GLfloat dst[][4], GLuint n)
432 {
433 const GLushort *s = ((const GLushort *) src);
434 GLuint i;
435 for (i = 0; i < n; i++) {
436 dst[i][RCOMP] =
437 dst[i][GCOMP] =
438 dst[i][BCOMP] =
439 dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
440 }
441 }
442
443 static void
444 unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n)
445 {
446 GLuint i;
447 for (i = 0; i < n; i++) {
448 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
449 const GLushort *src1 = src0 + 1; /* odd */
450 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
451 const GLubyte cb = *src0 & 0xff; /* chroma U */
452 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
453 const GLubyte cr = *src1 & 0xff; /* chroma V */
454 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
455 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
456 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
457 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
458 r *= (1.0F / 255.0F);
459 g *= (1.0F / 255.0F);
460 b *= (1.0F / 255.0F);
461 dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
462 dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
463 dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
464 dst[i][ACOMP] = 1.0F;
465 }
466 }
467
468 static void
469 unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
470 {
471 GLuint i;
472 for (i = 0; i < n; i++) {
473 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
474 const GLushort *src1 = src0 + 1; /* odd */
475 const GLubyte y0 = *src0 & 0xff; /* luminance */
476 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
477 const GLubyte y1 = *src1 & 0xff; /* luminance */
478 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
479 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
480 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
481 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
482 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
483 r *= (1.0F / 255.0F);
484 g *= (1.0F / 255.0F);
485 b *= (1.0F / 255.0F);
486 dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
487 dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
488 dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
489 dst[i][ACOMP] = 1.0F;
490 }
491 }
492
493 static void
494 unpack_R8(const void *src, GLfloat dst[][4], GLuint n)
495 {
496 const GLubyte *s = ((const GLubyte *) src);
497 GLuint i;
498 for (i = 0; i < n; i++) {
499 dst[i][0] = UBYTE_TO_FLOAT(s[i]);
500 dst[i][1] =
501 dst[i][2] = 0.0F;
502 dst[i][3] = 1.0F;
503 }
504 }
505
506 static void
507 unpack_GR88(const void *src, GLfloat dst[][4], GLuint n)
508 {
509 const GLushort *s = ((const GLushort *) src);
510 GLuint i;
511 for (i = 0; i < n; i++) {
512 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
513 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
514 dst[i][BCOMP] = 0.0;
515 dst[i][ACOMP] = 1.0;
516 }
517 }
518
519 static void
520 unpack_RG88(const void *src, GLfloat dst[][4], GLuint n)
521 {
522 const GLushort *s = ((const GLushort *) src);
523 GLuint i;
524 for (i = 0; i < n; i++) {
525 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
526 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
527 dst[i][BCOMP] = 0.0;
528 dst[i][ACOMP] = 1.0;
529 }
530 }
531
532 static void
533 unpack_R16(const void *src, GLfloat dst[][4], GLuint n)
534 {
535 const GLushort *s = ((const GLushort *) src);
536 GLuint i;
537 for (i = 0; i < n; i++) {
538 dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]);
539 dst[i][GCOMP] = 0.0;
540 dst[i][BCOMP] = 0.0;
541 dst[i][ACOMP] = 1.0;
542 }
543 }
544
545 static void
546 unpack_RG1616(const void *src, GLfloat dst[][4], GLuint n)
547 {
548 const GLuint *s = ((const GLuint *) src);
549 GLuint i;
550 for (i = 0; i < n; i++) {
551 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
552 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
553 dst[i][BCOMP] = 0.0;
554 dst[i][ACOMP] = 1.0;
555 }
556 }
557
558 static void
559 unpack_RG1616_REV(const void *src, GLfloat dst[][4], GLuint n)
560 {
561 const GLuint *s = ((const GLuint *) src);
562 GLuint i;
563 for (i = 0; i < n; i++) {
564 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
565 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
566 dst[i][BCOMP] = 0.0;
567 dst[i][ACOMP] = 1.0;
568 }
569 }
570
571 static void
572 unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n)
573 {
574 const GLuint *s = ((const GLuint *) src);
575 GLuint i;
576 for (i = 0; i < n; i++) {
577 dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
578 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
579 dst[i][BCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
580 dst[i][ACOMP] = ((s[i] >> 30) & 0x03) * (1.0F / 3.0F);
581 }
582 }
583
584
585 static void
586 unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
587 {
588 /* only return Z, not stencil data */
589 const GLuint *s = ((const GLuint *) src);
590 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
591 GLuint i;
592 for (i = 0; i < n; i++) {
593 dst[i][0] =
594 dst[i][1] =
595 dst[i][2] = (s[i] >> 8) * scale;
596 dst[i][3] = 1.0F;
597 ASSERT(dst[i][0] >= 0.0F);
598 ASSERT(dst[i][0] <= 1.0F);
599 }
600 }
601
602 static void
603 unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
604 {
605 /* only return Z, not stencil data */
606 const GLuint *s = ((const GLuint *) src);
607 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
608 GLuint i;
609 for (i = 0; i < n; i++) {
610 dst[i][0] =
611 dst[i][1] =
612 dst[i][2] = (s[i] & 0x00ffffff) * scale;
613 dst[i][3] = 1.0F;
614 ASSERT(dst[i][0] >= 0.0F);
615 ASSERT(dst[i][0] <= 1.0F);
616 }
617 }
618
619 static void
620 unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
621 {
622 const GLushort *s = ((const GLushort *) src);
623 GLuint i;
624 for (i = 0; i < n; i++) {
625 dst[i][0] =
626 dst[i][1] =
627 dst[i][2] = s[i] * (1.0F / 65535.0F);
628 dst[i][3] = 1.0F;
629 }
630 }
631
632 static void
633 unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n)
634 {
635 unpack_S8_Z24(src, dst, n);
636 }
637
638 static void
639 unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n)
640 {
641 unpack_Z24_S8(src, dst, n);
642 }
643
644 static void
645 unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
646 {
647 const GLuint *s = ((const GLuint *) src);
648 GLuint i;
649 for (i = 0; i < n; i++) {
650 dst[i][0] =
651 dst[i][1] =
652 dst[i][2] = s[i] * (1.0F / 0xffffffff);
653 dst[i][3] = 1.0F;
654 }
655 }
656
657 static void
658 unpack_Z32_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
659 {
660 const GLfloat *s = ((const GLfloat *) src);
661 GLuint i;
662 for (i = 0; i < n; i++) {
663 dst[i][0] =
664 dst[i][1] =
665 dst[i][2] = s[i * 2];
666 dst[i][3] = 1.0F;
667 }
668 }
669
670 static void
671 unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[][4], GLuint n)
672 {
673 const GLfloat *s = ((const GLfloat *) src);
674 GLuint i;
675 for (i = 0; i < n; i++) {
676 dst[i][0] =
677 dst[i][1] =
678 dst[i][2] = s[i];
679 dst[i][3] = 1.0F;
680 }
681 }
682
683
684 static void
685 unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
686 {
687 /* should never be used */
688 GLuint i;
689 for (i = 0; i < n; i++) {
690 dst[i][0] =
691 dst[i][1] =
692 dst[i][2] = 0.0F;
693 dst[i][3] = 1.0F;
694 }
695 }
696
697
698 static void
699 unpack_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
700 {
701 const GLubyte *s = (const GLubyte *) src;
702 GLuint i;
703 for (i = 0; i < n; i++) {
704 dst[i][RCOMP] = nonlinear_to_linear(s[i*3+2]);
705 dst[i][GCOMP] = nonlinear_to_linear(s[i*3+1]);
706 dst[i][BCOMP] = nonlinear_to_linear(s[i*3+0]);
707 dst[i][ACOMP] = 1.0F;
708 }
709 }
710
711 static void
712 unpack_SRGBA8(const void *src, GLfloat dst[][4], GLuint n)
713 {
714 const GLuint *s = ((const GLuint *) src);
715 GLuint i;
716 for (i = 0; i < n; i++) {
717 dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 24) );
718 dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff );
719 dst[i][BCOMP] = nonlinear_to_linear( (s[i] >> 8) & 0xff );
720 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
721 }
722 }
723
724 static void
725 unpack_SARGB8(const void *src, GLfloat dst[][4], GLuint n)
726 {
727 const GLuint *s = ((const GLuint *) src);
728 GLuint i;
729 for (i = 0; i < n; i++) {
730 dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff );
731 dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 8) & 0xff );
732 dst[i][BCOMP] = nonlinear_to_linear( (s[i] ) & 0xff );
733 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
734 }
735 }
736
737 static void
738 unpack_SL8(const void *src, GLfloat dst[][4], GLuint n)
739 {
740 const GLubyte *s = ((const GLubyte *) src);
741 GLuint i;
742 for (i = 0; i < n; i++) {
743 dst[i][RCOMP] =
744 dst[i][GCOMP] =
745 dst[i][BCOMP] = nonlinear_to_linear(s[i]);
746 dst[i][ACOMP] = 1.0F;
747 }
748 }
749
750 static void
751 unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n)
752 {
753 const GLushort *s = (const GLushort *) src;
754 GLuint i;
755 for (i = 0; i < n; i++) {
756 dst[i][RCOMP] =
757 dst[i][GCOMP] =
758 dst[i][BCOMP] = nonlinear_to_linear(s[i] & 0xff);
759 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
760 }
761 }
762
763 static void
764 unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
765 {
766 }
767
768 static void
769 unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
770 {
771 }
772
773 static void
774 unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
775 {
776 }
777
778 static void
779 unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
780 {
781 }
782
783 static void
784 unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
785 {
786 }
787
788 static void
789 unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
790 {
791 }
792
793 static void
794 unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
795 {
796 }
797
798 static void
799 unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
800 {
801 }
802
803 static void
804 unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
805 {
806 }
807
808 static void
809 unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
810 {
811 }
812
813
814 static void
815 unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
816 {
817 const GLfloat *s = (const GLfloat *) src;
818 GLuint i;
819 for (i = 0; i < n; i++) {
820 dst[i][RCOMP] = s[i*4+0];
821 dst[i][GCOMP] = s[i*4+1];
822 dst[i][BCOMP] = s[i*4+2];
823 dst[i][ACOMP] = s[i*4+3];
824 }
825 }
826
827 static void
828 unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
829 {
830 const GLhalfARB *s = (const GLhalfARB *) src;
831 GLuint i;
832 for (i = 0; i < n; i++) {
833 dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
834 dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
835 dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
836 dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
837 }
838 }
839
840 static void
841 unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
842 {
843 const GLfloat *s = (const GLfloat *) src;
844 GLuint i;
845 for (i = 0; i < n; i++) {
846 dst[i][RCOMP] = s[i*3+0];
847 dst[i][GCOMP] = s[i*3+1];
848 dst[i][BCOMP] = s[i*3+2];
849 dst[i][ACOMP] = 1.0F;
850 }
851 }
852
853 static void
854 unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
855 {
856 const GLhalfARB *s = (const GLhalfARB *) src;
857 GLuint i;
858 for (i = 0; i < n; i++) {
859 dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]);
860 dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
861 dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
862 dst[i][ACOMP] = 1.0F;
863 }
864 }
865
866 static void
867 unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
868 {
869 const GLfloat *s = (const GLfloat *) src;
870 GLuint i;
871 for (i = 0; i < n; i++) {
872 dst[i][RCOMP] =
873 dst[i][GCOMP] =
874 dst[i][BCOMP] = 0.0F;
875 dst[i][ACOMP] = s[i];
876 }
877 }
878
879 static void
880 unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
881 {
882 const GLhalfARB *s = (const GLhalfARB *) src;
883 GLuint i;
884 for (i = 0; i < n; i++) {
885 dst[i][RCOMP] =
886 dst[i][GCOMP] =
887 dst[i][BCOMP] = 0.0F;
888 dst[i][ACOMP] = _mesa_half_to_float(s[i]);
889 }
890 }
891
892 static void
893 unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
894 {
895 const GLfloat *s = (const GLfloat *) src;
896 GLuint i;
897 for (i = 0; i < n; i++) {
898 dst[i][RCOMP] =
899 dst[i][GCOMP] =
900 dst[i][BCOMP] = s[i];
901 dst[i][ACOMP] = 1.0F;
902 }
903 }
904
905 static void
906 unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
907 {
908 const GLhalfARB *s = (const GLhalfARB *) src;
909 GLuint i;
910 for (i = 0; i < n; i++) {
911 dst[i][RCOMP] =
912 dst[i][GCOMP] =
913 dst[i][BCOMP] = _mesa_half_to_float(s[i]);
914 dst[i][ACOMP] = 1.0F;
915 }
916 }
917
918 static void
919 unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
920 {
921 const GLfloat *s = (const GLfloat *) src;
922 GLuint i;
923 for (i = 0; i < n; i++) {
924 dst[i][RCOMP] =
925 dst[i][GCOMP] =
926 dst[i][BCOMP] = s[i*2+0];
927 dst[i][ACOMP] = s[i*2+1];
928 }
929 }
930
931 static void
932 unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
933 {
934 const GLhalfARB *s = (const GLhalfARB *) src;
935 GLuint i;
936 for (i = 0; i < n; i++) {
937 dst[i][RCOMP] =
938 dst[i][GCOMP] =
939 dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
940 dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
941 }
942 }
943
944 static void
945 unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
946 {
947 const GLfloat *s = (const GLfloat *) src;
948 GLuint i;
949 for (i = 0; i < n; i++) {
950 dst[i][RCOMP] =
951 dst[i][GCOMP] =
952 dst[i][BCOMP] =
953 dst[i][ACOMP] = s[i];
954 }
955 }
956
957 static void
958 unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
959 {
960 const GLhalfARB *s = (const GLhalfARB *) src;
961 GLuint i;
962 for (i = 0; i < n; i++) {
963 dst[i][RCOMP] =
964 dst[i][GCOMP] =
965 dst[i][BCOMP] =
966 dst[i][ACOMP] = _mesa_half_to_float(s[i]);
967 }
968 }
969
970 static void
971 unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
972 {
973 const GLfloat *s = (const GLfloat *) src;
974 GLuint i;
975 for (i = 0; i < n; i++) {
976 dst[i][RCOMP] = s[i];
977 dst[i][GCOMP] = 0.0F;
978 dst[i][BCOMP] = 0.0F;
979 dst[i][ACOMP] = 1.0F;
980 }
981 }
982
983 static void
984 unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
985 {
986 const GLhalfARB *s = (const GLhalfARB *) src;
987 GLuint i;
988 for (i = 0; i < n; i++) {
989 dst[i][RCOMP] = _mesa_half_to_float(s[i]);
990 dst[i][GCOMP] = 0.0F;
991 dst[i][BCOMP] = 0.0F;
992 dst[i][ACOMP] = 1.0F;
993 }
994 }
995
996 static void
997 unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
998 {
999 const GLfloat *s = (const GLfloat *) src;
1000 GLuint i;
1001 for (i = 0; i < n; i++) {
1002 dst[i][RCOMP] = s[i*2+0];
1003 dst[i][GCOMP] = s[i*2+1];
1004 dst[i][BCOMP] = 0.0F;
1005 dst[i][ACOMP] = 1.0F;
1006 }
1007 }
1008
1009 static void
1010 unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1011 {
1012 const GLhalfARB *s = (const GLhalfARB *) src;
1013 GLuint i;
1014 for (i = 0; i < n; i++) {
1015 dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
1016 dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
1017 dst[i][BCOMP] = 0.0F;
1018 dst[i][ACOMP] = 1.0F;
1019 }
1020 }
1021
1022
1023 static void
1024 unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
1025 {
1026 const GLbyte *s = (const GLbyte *) src;
1027 GLuint i;
1028 for (i = 0; i < n; i++) {
1029 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1030 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1031 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1032 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1033 }
1034 }
1035
1036 static void
1037 unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
1038 {
1039 const GLshort *s = (const GLshort *) src;
1040 GLuint i;
1041 for (i = 0; i < n; i++) {
1042 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1043 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1044 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1045 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1046 }
1047 }
1048
1049 static void
1050 unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1051 {
1052 const GLint *s = (const GLint *) src;
1053 GLuint i;
1054 for (i = 0; i < n; i++) {
1055 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1056 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1057 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1058 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1059 }
1060 }
1061
1062 static void
1063 unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1064 {
1065 const GLubyte *s = (const GLubyte *) src;
1066 GLuint i;
1067 for (i = 0; i < n; i++) {
1068 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1069 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1070 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1071 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1072 }
1073 }
1074
1075 static void
1076 unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
1077 {
1078 const GLushort *s = (const GLushort *) src;
1079 GLuint i;
1080 for (i = 0; i < n; i++) {
1081 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1082 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1083 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1084 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1085 }
1086 }
1087
1088 static void
1089 unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
1090 {
1091 const GLuint *s = (const GLuint *) src;
1092 GLuint i;
1093 for (i = 0; i < n; i++) {
1094 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1095 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1096 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1097 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1098 }
1099 }
1100
1101 static void
1102 unpack_DUDV8(const void *src, GLfloat dst[][4], GLuint n)
1103 {
1104 const GLbyte *s = (const GLbyte *) src;
1105 GLuint i;
1106 for (i = 0; i < n; i++) {
1107 dst[i][RCOMP] = BYTE_TO_FLOAT(s[i*2+0]);
1108 dst[i][GCOMP] = BYTE_TO_FLOAT(s[i*2+1]);
1109 dst[i][BCOMP] = 0;
1110 dst[i][ACOMP] = 0;
1111 }
1112 }
1113
1114 static void
1115 unpack_SIGNED_R8(const void *src, GLfloat dst[][4], GLuint n)
1116 {
1117 const GLbyte *s = ((const GLbyte *) src);
1118 GLuint i;
1119 for (i = 0; i < n; i++) {
1120 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1121 dst[i][GCOMP] = 0.0F;
1122 dst[i][BCOMP] = 0.0F;
1123 dst[i][ACOMP] = 1.0F;
1124 }
1125 }
1126
1127 static void
1128 unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
1129 {
1130 const GLushort *s = ((const GLushort *) src);
1131 GLuint i;
1132 for (i = 0; i < n; i++) {
1133 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1134 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1135 dst[i][BCOMP] = 0.0F;
1136 dst[i][ACOMP] = 1.0F;
1137 }
1138 }
1139
1140 static void
1141 unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
1142 {
1143 const GLuint *s = ((const GLuint *) src);
1144 GLuint i;
1145 for (i = 0; i < n; i++) {
1146 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1147 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1148 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1149 dst[i][ACOMP] = 1.0f;
1150 }
1151 }
1152
1153 static void
1154 unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
1155 {
1156 const GLuint *s = ((const GLuint *) src);
1157 GLuint i;
1158 for (i = 0; i < n; i++) {
1159 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1160 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1161 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1162 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1163 }
1164 }
1165
1166 static void
1167 unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
1168 {
1169 const GLuint *s = ((const GLuint *) src);
1170 GLuint i;
1171 for (i = 0; i < n; i++) {
1172 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1173 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1174 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1175 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1176 }
1177 }
1178
1179 static void
1180 unpack_SIGNED_R16(const void *src, GLfloat dst[][4], GLuint n)
1181 {
1182 const GLshort *s = ((const GLshort *) src);
1183 GLuint i;
1184 for (i = 0; i < n; i++) {
1185 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1186 dst[i][GCOMP] = 0.0F;
1187 dst[i][BCOMP] = 0.0F;
1188 dst[i][ACOMP] = 1.0F;
1189 }
1190 }
1191
1192 static void
1193 unpack_SIGNED_GR1616(const void *src, GLfloat dst[][4], GLuint n)
1194 {
1195 const GLuint *s = ((const GLuint *) src);
1196 GLuint i;
1197 for (i = 0; i < n; i++) {
1198 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
1199 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
1200 dst[i][BCOMP] = 0.0F;
1201 dst[i][ACOMP] = 1.0F;
1202 }
1203 }
1204
1205 static void
1206 unpack_SIGNED_RGB_16(const void *src, GLfloat dst[][4], GLuint n)
1207 {
1208 const GLshort *s = (const GLshort *) src;
1209 GLuint i;
1210 for (i = 0; i < n; i++) {
1211 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] );
1212 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
1213 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
1214 dst[i][ACOMP] = 1.0F;
1215 }
1216 }
1217
1218 static void
1219 unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1220 {
1221 const GLshort *s = (const GLshort *) src;
1222 GLuint i;
1223 for (i = 0; i < n; i++) {
1224 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
1225 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
1226 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
1227 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
1228 }
1229 }
1230
1231 static void
1232 unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1233 {
1234 const GLushort *s = (const GLushort *) src;
1235 GLuint i;
1236 for (i = 0; i < n; i++) {
1237 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
1238 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
1239 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
1240 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
1241 }
1242 }
1243
1244 static void
1245 unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1246 {
1247 /* XXX to do */
1248 }
1249
1250 static void
1251 unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1252 {
1253 /* XXX to do */
1254 }
1255
1256 static void
1257 unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1258 {
1259 /* XXX to do */
1260 }
1261
1262 static void
1263 unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1264 {
1265 /* XXX to do */
1266 }
1267
1268 static void
1269 unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1270 {
1271 /* XXX to do */
1272 }
1273
1274 static void
1275 unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1276 {
1277 /* XXX to do */
1278 }
1279
1280 static void
1281 unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1282 {
1283 /* XXX to do */
1284 }
1285
1286 static void
1287 unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1288 {
1289 /* XXX to do */
1290 }
1291
1292 static void
1293 unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1294 {
1295 /* XXX to do */
1296 }
1297
1298 static void
1299 unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n)
1300 {
1301 const GLbyte *s = ((const GLbyte *) src);
1302 GLuint i;
1303 for (i = 0; i < n; i++) {
1304 dst[i][RCOMP] = 0.0F;
1305 dst[i][GCOMP] = 0.0F;
1306 dst[i][BCOMP] = 0.0F;
1307 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1308 }
1309 }
1310
1311 static void
1312 unpack_SIGNED_L8(const void *src, GLfloat dst[][4], GLuint n)
1313 {
1314 const GLbyte *s = ((const GLbyte *) src);
1315 GLuint i;
1316 for (i = 0; i < n; i++) {
1317 dst[i][RCOMP] =
1318 dst[i][GCOMP] =
1319 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1320 dst[i][ACOMP] = 1.0F;
1321 }
1322 }
1323
1324 static void
1325 unpack_SIGNED_AL88(const void *src, GLfloat dst[][4], GLuint n)
1326 {
1327 const GLshort *s = ((const GLshort *) src);
1328 GLuint i;
1329 for (i = 0; i < n; i++) {
1330 dst[i][RCOMP] =
1331 dst[i][GCOMP] =
1332 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1333 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1334 }
1335 }
1336
1337 static void
1338 unpack_SIGNED_I8(const void *src, GLfloat dst[][4], GLuint n)
1339 {
1340 const GLbyte *s = ((const GLbyte *) src);
1341 GLuint i;
1342 for (i = 0; i < n; i++) {
1343 dst[i][RCOMP] =
1344 dst[i][GCOMP] =
1345 dst[i][BCOMP] =
1346 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1347 }
1348 }
1349
1350 static void
1351 unpack_SIGNED_A16(const void *src, GLfloat dst[][4], GLuint n)
1352 {
1353 const GLshort *s = ((const GLshort *) src);
1354 GLuint i;
1355 for (i = 0; i < n; i++) {
1356 dst[i][RCOMP] = 0.0F;
1357 dst[i][GCOMP] = 0.0F;
1358 dst[i][BCOMP] = 0.0F;
1359 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1360 }
1361 }
1362
1363 static void
1364 unpack_SIGNED_L16(const void *src, GLfloat dst[][4], GLuint n)
1365 {
1366 const GLshort *s = ((const GLshort *) src);
1367 GLuint i;
1368 for (i = 0; i < n; i++) {
1369 dst[i][RCOMP] =
1370 dst[i][GCOMP] =
1371 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1372 dst[i][ACOMP] = 1.0F;
1373 }
1374 }
1375
1376 static void
1377 unpack_SIGNED_AL1616(const void *src, GLfloat dst[][4], GLuint n)
1378 {
1379 const GLshort *s = (const GLshort *) src;
1380 GLuint i;
1381 for (i = 0; i < n; i++) {
1382 dst[i][RCOMP] =
1383 dst[i][GCOMP] =
1384 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
1385 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
1386 }
1387 }
1388
1389 static void
1390 unpack_SIGNED_I16(const void *src, GLfloat dst[][4], GLuint n)
1391 {
1392 const GLshort *s = ((const GLshort *) src);
1393 GLuint i;
1394 for (i = 0; i < n; i++) {
1395 dst[i][RCOMP] =
1396 dst[i][GCOMP] =
1397 dst[i][BCOMP] =
1398 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1399 }
1400 }
1401
1402 static void
1403 unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
1404 {
1405 const GLuint *s = (const GLuint *) src;
1406 GLuint i;
1407 for (i = 0; i < n; i++) {
1408 rgb9e5_to_float3(s[i], dst[i]);
1409 dst[i][ACOMP] = 1.0F;
1410 }
1411 }
1412
1413 static void
1414 unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
1415 {
1416 const GLuint *s = (const GLuint *) src;
1417 GLuint i;
1418 for (i = 0; i < n; i++) {
1419 r11g11b10f_to_float3(s[i], dst[i]);
1420 dst[i][ACOMP] = 1.0F;
1421 }
1422 }
1423
1424
1425 /**
1426 * Return the unpacker function for the given format.
1427 */
1428 static unpack_rgba_func
1429 get_unpack_rgba_function(gl_format format)
1430 {
1431 static unpack_rgba_func table[MESA_FORMAT_COUNT];
1432 static GLboolean initialized = GL_FALSE;
1433
1434 if (!initialized) {
1435 table[MESA_FORMAT_NONE] = NULL;
1436
1437 table[MESA_FORMAT_RGBA8888] = unpack_RGBA8888;
1438 table[MESA_FORMAT_RGBA8888_REV] = unpack_RGBA8888_REV;
1439 table[MESA_FORMAT_ARGB8888] = unpack_ARGB8888;
1440 table[MESA_FORMAT_ARGB8888_REV] = unpack_ARGB8888_REV;
1441 table[MESA_FORMAT_RGBX8888] = unpack_RGBX8888;
1442 table[MESA_FORMAT_RGBX8888_REV] = unpack_RGBX8888_REV;
1443 table[MESA_FORMAT_XRGB8888] = unpack_XRGB8888;
1444 table[MESA_FORMAT_XRGB8888_REV] = unpack_XRGB8888_REV;
1445 table[MESA_FORMAT_RGB888] = unpack_RGB888;
1446 table[MESA_FORMAT_BGR888] = unpack_BGR888;
1447 table[MESA_FORMAT_RGB565] = unpack_RGB565;
1448 table[MESA_FORMAT_RGB565_REV] = unpack_RGB565_REV;
1449 table[MESA_FORMAT_ARGB4444] = unpack_ARGB4444;
1450 table[MESA_FORMAT_ARGB4444_REV] = unpack_ARGB4444_REV;
1451 table[MESA_FORMAT_RGBA5551] = unpack_RGBA5551;
1452 table[MESA_FORMAT_ARGB1555] = unpack_ARGB1555;
1453 table[MESA_FORMAT_ARGB1555_REV] = unpack_ARGB1555_REV;
1454 table[MESA_FORMAT_AL44] = unpack_AL44;
1455 table[MESA_FORMAT_AL88] = unpack_AL88;
1456 table[MESA_FORMAT_AL88_REV] = unpack_AL88_REV;
1457 table[MESA_FORMAT_AL1616] = unpack_AL1616;
1458 table[MESA_FORMAT_AL1616_REV] = unpack_AL1616_REV;
1459 table[MESA_FORMAT_RGB332] = unpack_RGB332;
1460 table[MESA_FORMAT_A8] = unpack_A8;
1461 table[MESA_FORMAT_A16] = unpack_A16;
1462 table[MESA_FORMAT_L8] = unpack_L8;
1463 table[MESA_FORMAT_L16] = unpack_L16;
1464 table[MESA_FORMAT_I8] = unpack_I8;
1465 table[MESA_FORMAT_I16] = unpack_I16;
1466 table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
1467 table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
1468 table[MESA_FORMAT_R8] = unpack_R8;
1469 table[MESA_FORMAT_GR88] = unpack_GR88;
1470 table[MESA_FORMAT_RG88] = unpack_RG88;
1471 table[MESA_FORMAT_R16] = unpack_R16;
1472 table[MESA_FORMAT_RG1616] = unpack_RG1616;
1473 table[MESA_FORMAT_RG1616_REV] = unpack_RG1616_REV;
1474 table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010;
1475 table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8;
1476 table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24;
1477 table[MESA_FORMAT_Z16] = unpack_Z16;
1478 table[MESA_FORMAT_X8_Z24] = unpack_X8_Z24;
1479 table[MESA_FORMAT_Z24_X8] = unpack_Z24_X8;
1480 table[MESA_FORMAT_Z32] = unpack_Z32;
1481 table[MESA_FORMAT_S8] = unpack_S8;
1482 table[MESA_FORMAT_SRGB8] = unpack_SRGB8;
1483 table[MESA_FORMAT_SRGBA8] = unpack_SRGBA8;
1484 table[MESA_FORMAT_SARGB8] = unpack_SARGB8;
1485 table[MESA_FORMAT_SL8] = unpack_SL8;
1486 table[MESA_FORMAT_SLA8] = unpack_SLA8;
1487 table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
1488 table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
1489 table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
1490 table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
1491
1492 table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
1493 table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
1494 table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
1495 table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
1496 table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
1497 table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
1498
1499 table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
1500 table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
1501 table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
1502 table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
1503 table[MESA_FORMAT_ALPHA_FLOAT32] = unpack_ALPHA_FLOAT32;
1504 table[MESA_FORMAT_ALPHA_FLOAT16] = unpack_ALPHA_FLOAT16;
1505 table[MESA_FORMAT_LUMINANCE_FLOAT32] = unpack_LUMINANCE_FLOAT32;
1506 table[MESA_FORMAT_LUMINANCE_FLOAT16] = unpack_LUMINANCE_FLOAT16;
1507 table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = unpack_LUMINANCE_ALPHA_FLOAT32;
1508 table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = unpack_LUMINANCE_ALPHA_FLOAT16;
1509 table[MESA_FORMAT_INTENSITY_FLOAT32] = unpack_INTENSITY_FLOAT32;
1510 table[MESA_FORMAT_INTENSITY_FLOAT16] = unpack_INTENSITY_FLOAT16;
1511 table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
1512 table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
1513 table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
1514 table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
1515
1516 table[MESA_FORMAT_RGBA_INT8] = unpack_RGBA_INT8;
1517 table[MESA_FORMAT_RGBA_INT16] = unpack_RGBA_INT16;
1518 table[MESA_FORMAT_RGBA_INT32] = unpack_RGBA_INT32;
1519 table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
1520 table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
1521 table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
1522
1523 table[MESA_FORMAT_DUDV8] = unpack_DUDV8;
1524 table[MESA_FORMAT_SIGNED_R8] = unpack_SIGNED_R8;
1525 table[MESA_FORMAT_SIGNED_RG88_REV] = unpack_SIGNED_RG88_REV;
1526 table[MESA_FORMAT_SIGNED_RGBX8888] = unpack_SIGNED_RGBX8888;
1527 table[MESA_FORMAT_SIGNED_RGBA8888] = unpack_SIGNED_RGBA8888;
1528 table[MESA_FORMAT_SIGNED_RGBA8888_REV] = unpack_SIGNED_RGBA8888_REV;
1529 table[MESA_FORMAT_SIGNED_R16] = unpack_SIGNED_R16;
1530 table[MESA_FORMAT_SIGNED_GR1616] = unpack_SIGNED_GR1616;
1531 table[MESA_FORMAT_SIGNED_RGB_16] = unpack_SIGNED_RGB_16;
1532 table[MESA_FORMAT_SIGNED_RGBA_16] = unpack_SIGNED_RGBA_16;
1533 table[MESA_FORMAT_RGBA_16] = unpack_RGBA_16;
1534
1535 table[MESA_FORMAT_RED_RGTC1] = unpack_RED_RGTC1;
1536 table[MESA_FORMAT_SIGNED_RED_RGTC1] = unpack_SIGNED_RED_RGTC1;
1537 table[MESA_FORMAT_RG_RGTC2] = unpack_RG_RGTC2;
1538 table[MESA_FORMAT_SIGNED_RG_RGTC2] = unpack_SIGNED_RG_RGTC2;
1539
1540 table[MESA_FORMAT_L_LATC1] = unpack_L_LATC1;
1541 table[MESA_FORMAT_SIGNED_L_LATC1] = unpack_SIGNED_L_LATC1;
1542 table[MESA_FORMAT_LA_LATC2] = unpack_LA_LATC2;
1543 table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_LA_LATC2;
1544
1545 table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
1546
1547 table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8;
1548 table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8;
1549 table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88;
1550 table[MESA_FORMAT_SIGNED_I8] = unpack_SIGNED_I8;
1551 table[MESA_FORMAT_SIGNED_A16] = unpack_SIGNED_A16;
1552 table[MESA_FORMAT_SIGNED_L16] = unpack_SIGNED_L16;
1553 table[MESA_FORMAT_SIGNED_AL1616] = unpack_SIGNED_AL1616;
1554 table[MESA_FORMAT_SIGNED_I16] = unpack_SIGNED_I16;
1555
1556 table[MESA_FORMAT_RGB9_E5_FLOAT] = unpack_RGB9_E5_FLOAT;
1557 table[MESA_FORMAT_R11_G11_B10_FLOAT] = unpack_R11_G11_B10_FLOAT;
1558
1559 table[MESA_FORMAT_Z32_FLOAT] = unpack_Z32_FLOAT;
1560 table[MESA_FORMAT_Z32_FLOAT_X24S8] = unpack_Z32_FLOAT_X24S8;
1561
1562 initialized = GL_TRUE;
1563 }
1564
1565 return table[format];
1566 }
1567
1568
1569 void
1570 _mesa_unpack_rgba_row(gl_format format, GLuint n,
1571 const void *src, GLfloat dst[][4])
1572 {
1573 unpack_rgba_func unpack = get_unpack_rgba_function(format);
1574 unpack(src, dst, n);
1575 }
1576
1577 static void
1578 unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1579 {
1580 memcpy(dst, src, n * 4 * sizeof(GLuint));
1581 }
1582
1583 static void
1584 unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1585 {
1586 unsigned int i;
1587
1588 for (i = 0; i < n; i++) {
1589 dst[i][0] = src[i * 3 + 0];
1590 dst[i][1] = src[i * 3 + 1];
1591 dst[i][2] = src[i * 3 + 2];
1592 dst[i][3] = 1;
1593 }
1594 }
1595
1596 static void
1597 unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1598 {
1599 unsigned int i;
1600
1601 for (i = 0; i < n; i++) {
1602 dst[i][0] = src[i * 2 + 0];
1603 dst[i][1] = src[i * 2 + 1];
1604 dst[i][2] = 0;
1605 dst[i][3] = 1;
1606 }
1607 }
1608
1609 static void
1610 unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1611 {
1612 unsigned int i;
1613
1614 for (i = 0; i < n; i++) {
1615 dst[i][0] = src[i];
1616 dst[i][1] = 0;
1617 dst[i][2] = 0;
1618 dst[i][3] = 1;
1619 }
1620 }
1621
1622 static void
1623 unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1624 {
1625 unsigned int i;
1626
1627 for (i = 0; i < n; i++) {
1628 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
1629 dst[i][3] = 1;
1630 }
1631 }
1632
1633 static void
1634 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1635 {
1636 unsigned int i;
1637
1638 for (i = 0; i < n; i++) {
1639 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
1640 dst[i][3] = src[i * 2 + 1];
1641 }
1642 }
1643
1644 static void
1645 unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1646 {
1647 unsigned int i;
1648
1649 for (i = 0; i < n; i++) {
1650 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
1651 }
1652 }
1653
1654 static void
1655 unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
1656 {
1657 unsigned int i;
1658
1659 for (i = 0; i < n; i++) {
1660 GLuint tmp = src[i];
1661 dst[i][0] = (tmp >> 20) & 0x3ff;
1662 dst[i][1] = (tmp >> 10) & 0x3ff;
1663 dst[i][2] = (tmp >> 0) & 0x3ff;
1664 dst[i][3] = (tmp >> 30) & 0x3;
1665 }
1666 }
1667
1668 void
1669 _mesa_unpack_int_rgba_row(gl_format format, GLuint n,
1670 const void *src, GLuint dst[][4])
1671 {
1672 switch (format) {
1673 /* Since there won't be any sign extension happening, there's no need to
1674 * make separate paths for 32-bit-to-32-bit integer unpack.
1675 */
1676 case MESA_FORMAT_RGBA_UINT32:
1677 case MESA_FORMAT_RGBA_INT32:
1678 unpack_int_rgba_RGBA_UINT32(src, dst, n);
1679 break;
1680 case MESA_FORMAT_RGB_UINT32:
1681 case MESA_FORMAT_RGB_INT32:
1682 unpack_int_rgba_RGB_UINT32(src, dst, n);
1683 break;
1684 case MESA_FORMAT_RG_UINT32:
1685 case MESA_FORMAT_RG_INT32:
1686 unpack_int_rgba_RG_UINT32(src, dst, n);
1687 break;
1688 case MESA_FORMAT_R_UINT32:
1689 case MESA_FORMAT_R_INT32:
1690 unpack_int_rgba_R_UINT32(src, dst, n);
1691 break;
1692
1693 case MESA_FORMAT_LUMINANCE_UINT32:
1694 case MESA_FORMAT_LUMINANCE_INT32:
1695 unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
1696 break;
1697 case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
1698 case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
1699 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
1700 break;
1701 case MESA_FORMAT_INTENSITY_UINT32:
1702 case MESA_FORMAT_INTENSITY_INT32:
1703 unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
1704 break;
1705
1706 case MESA_FORMAT_ARGB2101010_UINT:
1707 unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
1708 break;
1709 default:
1710 _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
1711 _mesa_get_format_name(format));
1712 return;
1713 }
1714 }
1715
1716 /**
1717 * Unpack a 2D rect of pixels returning float RGBA colors.
1718 * \param format the source image format
1719 * \param src start address of the source image
1720 * \param srcRowStride source image row stride in bytes
1721 * \param dst start address of the dest image
1722 * \param dstRowStride dest image row stride in bytes
1723 * \param x source image start X pos
1724 * \param y source image start Y pos
1725 * \param width width of rect region to convert
1726 * \param height height of rect region to convert
1727 */
1728 void
1729 _mesa_unpack_rgba_block(gl_format format,
1730 const void *src, GLint srcRowStride,
1731 GLfloat dst[][4], GLint dstRowStride,
1732 GLuint x, GLuint y, GLuint width, GLuint height)
1733 {
1734 unpack_rgba_func unpack = get_unpack_rgba_function(format);
1735 const GLuint srcPixStride = _mesa_get_format_bytes(format);
1736 const GLuint dstPixStride = 4 * sizeof(GLfloat);
1737 const GLubyte *srcRow;
1738 GLubyte *dstRow;
1739 GLuint i;
1740
1741 /* XXX needs to be fixed for compressed formats */
1742
1743 srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
1744 dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
1745
1746 for (i = 0; i < height; i++) {
1747 unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
1748
1749 dstRow += dstRowStride;
1750 srcRow += srcRowStride;
1751 }
1752 }
1753
1754
1755
1756
1757 typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
1758
1759 static void
1760 unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
1761 {
1762 /* only return Z, not stencil data */
1763 const GLuint *s = ((const GLuint *) src);
1764 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1765 GLuint i;
1766 for (i = 0; i < n; i++) {
1767 dst[i] = (s[i] >> 8) * scale;
1768 ASSERT(dst[i] >= 0.0F);
1769 ASSERT(dst[i] <= 1.0F);
1770 }
1771 }
1772
1773 static void
1774 unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
1775 {
1776 /* only return Z, not stencil data */
1777 const GLuint *s = ((const GLuint *) src);
1778 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1779 GLuint i;
1780 for (i = 0; i < n; i++) {
1781 dst[i] = (s[i] & 0x00ffffff) * scale;
1782 ASSERT(dst[i] >= 0.0F);
1783 ASSERT(dst[i] <= 1.0F);
1784 }
1785 }
1786
1787 static void
1788 unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst)
1789 {
1790 const GLushort *s = ((const GLushort *) src);
1791 GLuint i;
1792 for (i = 0; i < n; i++) {
1793 dst[i] = s[i] * (1.0F / 65535.0F);
1794 }
1795 }
1796
1797 static void
1798 unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst)
1799 {
1800 const GLuint *s = ((const GLuint *) src);
1801 GLuint i;
1802 for (i = 0; i < n; i++) {
1803 dst[i] = s[i] * (1.0F / 0xffffffff);
1804 }
1805 }
1806
1807 static void
1808 unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst)
1809 {
1810 memcpy(dst, src, n * sizeof(float));
1811 }
1812
1813 static void
1814 unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
1815 {
1816 const GLfloat *s = ((const GLfloat *) src);
1817 GLuint i;
1818 for (i = 0; i < n; i++) {
1819 dst[i] = s[i * 2];
1820 }
1821 }
1822
1823
1824
1825 void
1826 _mesa_unpack_float_z_row(gl_format format, GLuint n,
1827 const void *src, GLfloat *dst)
1828 {
1829 unpack_float_z_func unpack;
1830
1831 switch (format) {
1832 case MESA_FORMAT_Z24_S8:
1833 case MESA_FORMAT_Z24_X8:
1834 unpack = unpack_float_z_Z24_X8;
1835 break;
1836 case MESA_FORMAT_S8_Z24:
1837 case MESA_FORMAT_X8_Z24:
1838 unpack = unpack_float_z_X8_Z24;
1839 break;
1840 case MESA_FORMAT_Z16:
1841 unpack = unpack_float_z_Z16;
1842 break;
1843 case MESA_FORMAT_Z32:
1844 unpack = unpack_float_z_Z32;
1845 break;
1846 case MESA_FORMAT_Z32_FLOAT:
1847 unpack = unpack_float_z_Z32F;
1848 break;
1849 case MESA_FORMAT_Z32_FLOAT_X24S8:
1850 unpack = unpack_float_z_Z32X24S8;
1851 break;
1852 default:
1853 _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
1854 _mesa_get_format_name(format));
1855 return;
1856 }
1857
1858 unpack(n, src, dst);
1859 }
1860
1861
1862
1863 typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
1864
1865 static void
1866 unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
1867 {
1868 /* only return Z, not stencil data */
1869 const GLuint *s = ((const GLuint *) src);
1870 GLuint i;
1871 for (i = 0; i < n; i++) {
1872 dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
1873 }
1874 }
1875
1876 static void
1877 unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
1878 {
1879 /* only return Z, not stencil data */
1880 const GLuint *s = ((const GLuint *) src);
1881 GLuint i;
1882 for (i = 0; i < n; i++) {
1883 dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
1884 }
1885 }
1886
1887 static void
1888 unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n)
1889 {
1890 const GLushort *s = ((const GLushort *)src);
1891 GLuint i;
1892 for (i = 0; i < n; i++) {
1893 dst[i] = (s[i] << 16) | s[i];
1894 }
1895 }
1896
1897 static void
1898 unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
1899 {
1900 memcpy(dst, src, n * sizeof(GLuint));
1901 }
1902
1903
1904 void
1905 _mesa_unpack_uint_z_row(gl_format format, GLuint n,
1906 const void *src, GLuint *dst)
1907 {
1908 unpack_uint_z_func unpack;
1909 const GLubyte *srcPtr = (GLubyte *) src;
1910
1911 switch (format) {
1912 case MESA_FORMAT_Z24_S8:
1913 case MESA_FORMAT_Z24_X8:
1914 unpack = unpack_uint_z_Z24_X8;
1915 break;
1916 case MESA_FORMAT_S8_Z24:
1917 case MESA_FORMAT_X8_Z24:
1918 unpack = unpack_uint_z_X8_Z24;
1919 break;
1920 case MESA_FORMAT_Z16:
1921 unpack = unpack_uint_z_Z16;
1922 break;
1923 case MESA_FORMAT_Z32:
1924 unpack = unpack_uint_z_Z32;
1925 break;
1926 default:
1927 _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
1928 _mesa_get_format_name(format));
1929 return;
1930 }
1931
1932 unpack(srcPtr, dst, n);
1933 }
1934
1935
1936 static void
1937 unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
1938 {
1939 memcpy(dst, src, n);
1940 }
1941
1942 static void
1943 unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n)
1944 {
1945 GLuint i;
1946 const GLuint *src32 = src;
1947
1948 for (i = 0; i < n; i++)
1949 dst[i] = src32[i] & 0xff;
1950 }
1951
1952 static void
1953 unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n)
1954 {
1955 GLuint i;
1956 const GLuint *src32 = src;
1957
1958 for (i = 0; i < n; i++)
1959 dst[i] = src32[i] >> 24;
1960 }
1961
1962 static void
1963 unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n)
1964 {
1965 GLuint i;
1966 const GLuint *src32 = src;
1967
1968 for (i = 0; i < n; i++)
1969 dst[i] = src32[i * 2 + 1] & 0xff;
1970 }
1971
1972 void
1973 _mesa_unpack_ubyte_stencil_row(gl_format format, GLuint n,
1974 const void *src, GLubyte *dst)
1975 {
1976 switch (format) {
1977 case MESA_FORMAT_S8:
1978 unpack_ubyte_s_S8(src, dst, n);
1979 break;
1980 case MESA_FORMAT_Z24_S8:
1981 unpack_ubyte_s_Z24_S8(src, dst, n);
1982 break;
1983 case MESA_FORMAT_S8_Z24:
1984 unpack_ubyte_s_S8_Z24(src, dst, n);
1985 break;
1986 case MESA_FORMAT_Z32_FLOAT_X24S8:
1987 unpack_ubyte_s_Z32_FLOAT_X24S8(src, dst, n);
1988 break;
1989 default:
1990 _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
1991 _mesa_get_format_name(format));
1992 return;
1993 }
1994 }
1995
1996 static void
1997 unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint *src, GLuint *dst, GLuint n)
1998 {
1999 GLuint i;
2000
2001 for (i = 0; i < n; i++) {
2002 GLuint val = src[i];
2003 dst[i] = val >> 24 | val << 8;
2004 }
2005 }
2006
2007 static void
2008 unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint *src, GLuint *dst, GLuint n)
2009 {
2010 memcpy(dst, src, n * 4);
2011 }
2012
2013 void
2014 _mesa_unpack_uint_24_8_depth_stencil_row(gl_format format, GLuint n,
2015 const void *src, GLuint *dst)
2016 {
2017 switch (format) {
2018 case MESA_FORMAT_Z24_S8:
2019 unpack_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
2020 break;
2021 case MESA_FORMAT_S8_Z24:
2022 unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
2023 break;
2024 default:
2025 _mesa_problem(NULL,
2026 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
2027 _mesa_get_format_name(format));
2028 return;
2029 }
2030 }