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