[MESA/OPENGL32]
[reactos.git] / reactos / dll / opengl / mesa / 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 #if 0
29 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
30 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
31 #else
32 #include "u_format_rgb9e5.h"
33 #include "u_format_r11g11b10f.h"
34 #endif
35
36
37
38 /* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
39
40 #define EXPAND_1_8(X) ( (X) ? 0xff : 0x0 )
41
42 #define EXPAND_2_8(X) ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
43
44 #define EXPAND_3_8(X) ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
45
46 #define EXPAND_4_8(X) ( ((X) << 4) | (X) )
47
48 #define EXPAND_5_8(X) ( ((X) << 3) | ((X) >> 2) )
49
50 #define EXPAND_6_8(X) ( ((X) << 2) | ((X) >> 4) )
51
52
53 /**
54 * Convert an 8-bit sRGB value from non-linear space to a
55 * linear RGB value in [0, 1].
56 * Implemented with a 256-entry lookup table.
57 */
58 static inline GLfloat
59 nonlinear_to_linear(GLubyte cs8)
60 {
61 static GLfloat table[256];
62 static GLboolean tableReady = GL_FALSE;
63 if (!tableReady) {
64 /* compute lookup table now */
65 GLuint i;
66 for (i = 0; i < 256; i++) {
67 const GLfloat cs = UBYTE_TO_FLOAT(i);
68 if (cs <= 0.04045) {
69 table[i] = cs / 12.92f;
70 }
71 else {
72 table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
73 }
74 }
75 tableReady = GL_TRUE;
76 }
77 return table[cs8];
78 }
79
80
81 /**********************************************************************/
82 /* Unpack, returning GLfloat colors */
83 /**********************************************************************/
84
85 typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);
86
87
88 static void
89 unpack_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
90 {
91 const GLuint *s = ((const GLuint *) src);
92 GLuint i;
93 for (i = 0; i < n; i++) {
94 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
95 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
96 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
97 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
98 }
99 }
100
101 static void
102 unpack_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
103 {
104 const GLuint *s = ((const GLuint *) src);
105 GLuint i;
106 for (i = 0; i < n; i++) {
107 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
108 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
109 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
110 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
111 }
112 }
113
114 static void
115 unpack_ARGB8888(const void *src, GLfloat dst[][4], GLuint n)
116 {
117 const GLuint *s = ((const GLuint *) src);
118 GLuint i;
119 for (i = 0; i < n; i++) {
120 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
121 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
122 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
123 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
124 }
125 }
126
127 static void
128 unpack_ARGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
129 {
130 const GLuint *s = ((const GLuint *) src);
131 GLuint i;
132 for (i = 0; i < n; i++) {
133 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
134 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
135 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
136 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
137 }
138 }
139
140 static void
141 unpack_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
142 {
143 const GLuint *s = ((const GLuint *) src);
144 GLuint i;
145 for (i = 0; i < n; i++) {
146 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
147 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
148 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
149 dst[i][ACOMP] = 1.0f;
150 }
151 }
152
153 static void
154 unpack_RGBX8888_REV(const void *src, GLfloat dst[][4], GLuint n)
155 {
156 const GLuint *s = ((const GLuint *) src);
157 GLuint i;
158 for (i = 0; i < n; i++) {
159 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
160 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
161 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
162 dst[i][ACOMP] = 1.0f;
163 }
164 }
165
166 static void
167 unpack_XRGB8888(const void *src, GLfloat dst[][4], GLuint n)
168 {
169 const GLuint *s = ((const GLuint *) src);
170 GLuint i;
171 for (i = 0; i < n; i++) {
172 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
173 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
174 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
175 dst[i][ACOMP] = 1.0f;
176 }
177 }
178
179 static void
180 unpack_XRGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
181 {
182 const GLuint *s = ((const GLuint *) src);
183 GLuint i;
184 for (i = 0; i < n; i++) {
185 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
186 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
187 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
188 dst[i][ACOMP] = 1.0f;
189 }
190 }
191
192 static void
193 unpack_RGB888(const void *src, GLfloat dst[][4], GLuint n)
194 {
195 const GLubyte *s = (const GLubyte *) src;
196 GLuint i;
197 for (i = 0; i < n; i++) {
198 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
199 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
200 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
201 dst[i][ACOMP] = 1.0F;
202 }
203 }
204
205 static void
206 unpack_BGR888(const void *src, GLfloat dst[][4], GLuint n)
207 {
208 const GLubyte *s = (const GLubyte *) src;
209 GLuint i;
210 for (i = 0; i < n; i++) {
211 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
212 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
213 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
214 dst[i][ACOMP] = 1.0F;
215 }
216 }
217
218 static void
219 unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n)
220 {
221 const GLushort *s = ((const GLushort *) src);
222 GLuint i;
223 for (i = 0; i < n; i++) {
224 dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
225 dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F);
226 dst[i][BCOMP] = ((s[i] ) & 0x1f) * (1.0F / 31.0F);
227 dst[i][ACOMP] = 1.0F;
228 }
229 }
230
231 static void
232 unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n)
233 {
234 const GLushort *s = ((const GLushort *) src);
235 GLuint i;
236 for (i = 0; i < n; i++) {
237 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
238 dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) );
239 dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >> 9) & 0x3) );
240 dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >> 2) & 0x7) );
241 dst[i][ACOMP] = 1.0F;
242 }
243 }
244
245 static void
246 unpack_ARGB4444(const void *src, GLfloat dst[][4], GLuint n)
247 {
248 const GLushort *s = ((const GLushort *) src);
249 GLuint i;
250 for (i = 0; i < n; i++) {
251 dst[i][RCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
252 dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
253 dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
254 dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
255 }
256 }
257
258 static void
259 unpack_ARGB4444_REV(const void *src, GLfloat dst[][4], GLuint n)
260 {
261 const GLushort *s = ((const GLushort *) src);
262 GLuint i;
263 for (i = 0; i < n; i++) {
264 dst[i][RCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
265 dst[i][GCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
266 dst[i][BCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
267 dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
268 }
269 }
270
271 static void
272 unpack_RGBA5551(const void *src, GLfloat dst[][4], GLuint n)
273 {
274 const GLushort *s = ((const GLushort *) src);
275 GLuint i;
276 for (i = 0; i < n; i++) {
277 dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
278 dst[i][GCOMP] = ((s[i] >> 6) & 0x1f) * (1.0F / 31.0F);
279 dst[i][BCOMP] = ((s[i] >> 1) & 0x1f) * (1.0F / 31.0F);
280 dst[i][ACOMP] = ((s[i] ) & 0x01) * 1.0F;
281 }
282 }
283
284 static void
285 unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n)
286 {
287 const GLushort *s = ((const GLushort *) src);
288 GLuint i;
289 for (i = 0; i < n; i++) {
290 dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
291 dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F);
292 dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F);
293 dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F;
294 }
295 }
296
297 static void
298 unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n)
299 {
300 const GLushort *s = ((const GLushort *) src);
301 GLuint i;
302 for (i = 0; i < n; i++) {
303 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
304 dst[i][RCOMP] = ((tmp >> 10) & 0x1f) * (1.0F / 31.0F);
305 dst[i][GCOMP] = ((tmp >> 5) & 0x1f) * (1.0F / 31.0F);
306 dst[i][BCOMP] = ((tmp >> 0) & 0x1f) * (1.0F / 31.0F);
307 dst[i][ACOMP] = ((tmp >> 15) & 0x01) * 1.0F;
308 }
309 }
310
311 static void
312 unpack_AL44(const void *src, GLfloat dst[][4], GLuint n)
313 {
314 const GLubyte *s = ((const GLubyte *) src);
315 GLuint i;
316 for (i = 0; i < n; i++) {
317 dst[i][RCOMP] =
318 dst[i][GCOMP] =
319 dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
320 dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
321 }
322 }
323
324 static void
325 unpack_AL88(const void *src, GLfloat dst[][4], GLuint n)
326 {
327 const GLushort *s = ((const GLushort *) src);
328 GLuint i;
329 for (i = 0; i < n; i++) {
330 dst[i][RCOMP] =
331 dst[i][GCOMP] =
332 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
333 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
334 }
335 }
336
337 static void
338 unpack_AL88_REV(const void *src, GLfloat dst[][4], GLuint n)
339 {
340 const GLushort *s = ((const GLushort *) src);
341 GLuint i;
342 for (i = 0; i < n; i++) {
343 dst[i][RCOMP] =
344 dst[i][GCOMP] =
345 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
346 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
347 }
348 }
349
350 static void
351 unpack_AL1616(const void *src, GLfloat dst[][4], GLuint n)
352 {
353 const GLuint *s = ((const GLuint *) src);
354 GLuint i;
355 for (i = 0; i < n; i++) {
356 dst[i][RCOMP] =
357 dst[i][GCOMP] =
358 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
359 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
360 }
361 }
362
363 static void
364 unpack_AL1616_REV(const void *src, GLfloat dst[][4], GLuint n)
365 {
366 const GLuint *s = ((const GLuint *) src);
367 GLuint i;
368 for (i = 0; i < n; i++) {
369 dst[i][RCOMP] =
370 dst[i][GCOMP] =
371 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
372 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
373 }
374 }
375
376 static void
377 unpack_RGB332(const void *src, GLfloat dst[][4], GLuint n)
378 {
379 const GLubyte *s = ((const GLubyte *) src);
380 GLuint i;
381 for (i = 0; i < n; i++) {
382 dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F);
383 dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F);
384 dst[i][BCOMP] = ((s[i] ) & 0x3) * (1.0F / 3.0F);
385 dst[i][ACOMP] = 1.0F;
386 }
387 }
388
389
390 static void
391 unpack_A8(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] = 0.0F;
399 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
400 }
401 }
402
403 static void
404 unpack_A16(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] = 0.0F;
412 dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
413 }
414 }
415
416 static void
417 unpack_L8(const void *src, GLfloat dst[][4], GLuint n)
418 {
419 const GLubyte *s = ((const GLubyte *) src);
420 GLuint i;
421 for (i = 0; i < n; i++) {
422 dst[i][RCOMP] =
423 dst[i][GCOMP] =
424 dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
425 dst[i][ACOMP] = 1.0F;
426 }
427 }
428
429 static void
430 unpack_L16(const void *src, GLfloat dst[][4], GLuint n)
431 {
432 const GLushort *s = ((const GLushort *) src);
433 GLuint i;
434 for (i = 0; i < n; i++) {
435 dst[i][RCOMP] =
436 dst[i][GCOMP] =
437 dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
438 dst[i][ACOMP] = 1.0F;
439 }
440 }
441
442 static void
443 unpack_I8(const void *src, GLfloat dst[][4], GLuint n)
444 {
445 const GLubyte *s = ((const GLubyte *) src);
446 GLuint i;
447 for (i = 0; i < n; i++) {
448 dst[i][RCOMP] =
449 dst[i][GCOMP] =
450 dst[i][BCOMP] =
451 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
452 }
453 }
454
455 static void
456 unpack_I16(const void *src, GLfloat dst[][4], GLuint n)
457 {
458 const GLushort *s = ((const GLushort *) src);
459 GLuint i;
460 for (i = 0; i < n; i++) {
461 dst[i][RCOMP] =
462 dst[i][GCOMP] =
463 dst[i][BCOMP] =
464 dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
465 }
466 }
467
468 static void
469 unpack_YCBCR(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 >> 8) & 0xff; /* luminance */
476 const GLubyte cb = *src0 & 0xff; /* chroma U */
477 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
478 const GLubyte cr = *src1 & 0xff; /* chroma V */
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_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
495 {
496 GLuint i;
497 for (i = 0; i < n; i++) {
498 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
499 const GLushort *src1 = src0 + 1; /* odd */
500 const GLubyte y0 = *src0 & 0xff; /* luminance */
501 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
502 const GLubyte y1 = *src1 & 0xff; /* luminance */
503 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
504 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
505 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
506 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
507 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
508 r *= (1.0F / 255.0F);
509 g *= (1.0F / 255.0F);
510 b *= (1.0F / 255.0F);
511 dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
512 dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
513 dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
514 dst[i][ACOMP] = 1.0F;
515 }
516 }
517
518 static void
519 unpack_R8(const void *src, GLfloat dst[][4], GLuint n)
520 {
521 const GLubyte *s = ((const GLubyte *) src);
522 GLuint i;
523 for (i = 0; i < n; i++) {
524 dst[i][0] = UBYTE_TO_FLOAT(s[i]);
525 dst[i][1] =
526 dst[i][2] = 0.0F;
527 dst[i][3] = 1.0F;
528 }
529 }
530
531 static void
532 unpack_GR88(const void *src, GLfloat dst[][4], GLuint n)
533 {
534 const GLushort *s = ((const GLushort *) src);
535 GLuint i;
536 for (i = 0; i < n; i++) {
537 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
538 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
539 dst[i][BCOMP] = 0.0;
540 dst[i][ACOMP] = 1.0;
541 }
542 }
543
544 static void
545 unpack_RG88(const void *src, GLfloat dst[][4], GLuint n)
546 {
547 const GLushort *s = ((const GLushort *) src);
548 GLuint i;
549 for (i = 0; i < n; i++) {
550 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
551 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
552 dst[i][BCOMP] = 0.0;
553 dst[i][ACOMP] = 1.0;
554 }
555 }
556
557 static void
558 unpack_R16(const void *src, GLfloat dst[][4], GLuint n)
559 {
560 const GLushort *s = ((const GLushort *) src);
561 GLuint i;
562 for (i = 0; i < n; i++) {
563 dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]);
564 dst[i][GCOMP] = 0.0;
565 dst[i][BCOMP] = 0.0;
566 dst[i][ACOMP] = 1.0;
567 }
568 }
569
570 static void
571 unpack_RG1616(const void *src, GLfloat dst[][4], GLuint n)
572 {
573 const GLuint *s = ((const GLuint *) src);
574 GLuint i;
575 for (i = 0; i < n; i++) {
576 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
577 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
578 dst[i][BCOMP] = 0.0;
579 dst[i][ACOMP] = 1.0;
580 }
581 }
582
583 static void
584 unpack_RG1616_REV(const void *src, GLfloat dst[][4], GLuint n)
585 {
586 const GLuint *s = ((const GLuint *) src);
587 GLuint i;
588 for (i = 0; i < n; i++) {
589 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
590 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
591 dst[i][BCOMP] = 0.0;
592 dst[i][ACOMP] = 1.0;
593 }
594 }
595
596 static void
597 unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n)
598 {
599 const GLuint *s = ((const GLuint *) src);
600 GLuint i;
601 for (i = 0; i < n; i++) {
602 dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
603 dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
604 dst[i][BCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
605 dst[i][ACOMP] = ((s[i] >> 30) & 0x03) * (1.0F / 3.0F);
606 }
607 }
608
609
610 static void
611 unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
612 {
613 /* only return Z, not stencil data */
614 const GLuint *s = ((const GLuint *) src);
615 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
616 GLuint i;
617 for (i = 0; i < n; i++) {
618 dst[i][0] =
619 dst[i][1] =
620 dst[i][2] = (s[i] >> 8) * scale;
621 dst[i][3] = 1.0F;
622 ASSERT(dst[i][0] >= 0.0F);
623 ASSERT(dst[i][0] <= 1.0F);
624 }
625 }
626
627 static void
628 unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
629 {
630 /* only return Z, not stencil data */
631 const GLuint *s = ((const GLuint *) src);
632 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
633 GLuint i;
634 for (i = 0; i < n; i++) {
635 dst[i][0] =
636 dst[i][1] =
637 dst[i][2] = (s[i] & 0x00ffffff) * scale;
638 dst[i][3] = 1.0F;
639 ASSERT(dst[i][0] >= 0.0F);
640 ASSERT(dst[i][0] <= 1.0F);
641 }
642 }
643
644 static void
645 unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
646 {
647 const GLushort *s = ((const GLushort *) 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 / 65535.0F);
653 dst[i][3] = 1.0F;
654 }
655 }
656
657 static void
658 unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n)
659 {
660 unpack_S8_Z24(src, dst, n);
661 }
662
663 static void
664 unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n)
665 {
666 unpack_Z24_S8(src, dst, n);
667 }
668
669 static void
670 unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
671 {
672 const GLuint *s = ((const GLuint *) src);
673 GLuint i;
674 for (i = 0; i < n; i++) {
675 dst[i][0] =
676 dst[i][1] =
677 dst[i][2] = s[i] * (1.0F / 0xffffffff);
678 dst[i][3] = 1.0F;
679 }
680 }
681
682 static void
683 unpack_Z32_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
684 {
685 const GLfloat *s = ((const GLfloat *) src);
686 GLuint i;
687 for (i = 0; i < n; i++) {
688 dst[i][0] =
689 dst[i][1] =
690 dst[i][2] = s[i * 2];
691 dst[i][3] = 1.0F;
692 }
693 }
694
695 static void
696 unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[][4], GLuint n)
697 {
698 const GLfloat *s = ((const GLfloat *) src);
699 GLuint i;
700 for (i = 0; i < n; i++) {
701 dst[i][0] =
702 dst[i][1] =
703 dst[i][2] = s[i];
704 dst[i][3] = 1.0F;
705 }
706 }
707
708
709 static void
710 unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
711 {
712 /* should never be used */
713 GLuint i;
714 for (i = 0; i < n; i++) {
715 dst[i][0] =
716 dst[i][1] =
717 dst[i][2] = 0.0F;
718 dst[i][3] = 1.0F;
719 }
720 }
721
722
723 static void
724 unpack_SRGB8(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] = nonlinear_to_linear(s[i*3+2]);
730 dst[i][GCOMP] = nonlinear_to_linear(s[i*3+1]);
731 dst[i][BCOMP] = nonlinear_to_linear(s[i*3+0]);
732 dst[i][ACOMP] = 1.0F;
733 }
734 }
735
736 static void
737 unpack_SRGBA8(const void *src, GLfloat dst[][4], GLuint n)
738 {
739 const GLuint *s = ((const GLuint *) src);
740 GLuint i;
741 for (i = 0; i < n; i++) {
742 dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 24) );
743 dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff );
744 dst[i][BCOMP] = nonlinear_to_linear( (s[i] >> 8) & 0xff );
745 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
746 }
747 }
748
749 static void
750 unpack_SARGB8(const void *src, GLfloat dst[][4], GLuint n)
751 {
752 const GLuint *s = ((const GLuint *) src);
753 GLuint i;
754 for (i = 0; i < n; i++) {
755 dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff );
756 dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 8) & 0xff );
757 dst[i][BCOMP] = nonlinear_to_linear( (s[i] ) & 0xff );
758 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
759 }
760 }
761
762 static void
763 unpack_SL8(const void *src, GLfloat dst[][4], GLuint n)
764 {
765 const GLubyte *s = ((const GLubyte *) src);
766 GLuint i;
767 for (i = 0; i < n; i++) {
768 dst[i][RCOMP] =
769 dst[i][GCOMP] =
770 dst[i][BCOMP] = nonlinear_to_linear(s[i]);
771 dst[i][ACOMP] = 1.0F;
772 }
773 }
774
775 static void
776 unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n)
777 {
778 const GLushort *s = (const GLushort *) src;
779 GLuint i;
780 for (i = 0; i < n; i++) {
781 dst[i][RCOMP] =
782 dst[i][GCOMP] =
783 dst[i][BCOMP] = nonlinear_to_linear(s[i] & 0xff);
784 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
785 }
786 }
787
788 static void
789 unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
790 {
791 }
792
793 static void
794 unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
795 {
796 }
797
798 static void
799 unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
800 {
801 }
802
803 static void
804 unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
805 {
806 }
807
808 static void
809 unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
810 {
811 }
812
813 static void
814 unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
815 {
816 }
817
818 static void
819 unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
820 {
821 }
822
823 static void
824 unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
825 {
826 }
827
828 static void
829 unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
830 {
831 }
832
833 static void
834 unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
835 {
836 }
837
838
839 static void
840 unpack_RGBA_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] = s[i*4+0];
846 dst[i][GCOMP] = s[i*4+1];
847 dst[i][BCOMP] = s[i*4+2];
848 dst[i][ACOMP] = s[i*4+3];
849 }
850 }
851
852 static void
853 unpack_RGBA_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] = _mesa_half_to_float(s[i*4+0]);
859 dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
860 dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
861 dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
862 }
863 }
864
865 static void
866 unpack_RGB_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] = s[i*3+0];
872 dst[i][GCOMP] = s[i*3+1];
873 dst[i][BCOMP] = s[i*3+2];
874 dst[i][ACOMP] = 1.0F;
875 }
876 }
877
878 static void
879 unpack_RGB_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] = _mesa_half_to_float(s[i*3+0]);
885 dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
886 dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
887 dst[i][ACOMP] = 1.0F;
888 }
889 }
890
891 static void
892 unpack_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] = 0.0F;
900 dst[i][ACOMP] = s[i];
901 }
902 }
903
904 static void
905 unpack_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] = 0.0F;
913 dst[i][ACOMP] = _mesa_half_to_float(s[i]);
914 }
915 }
916
917 static void
918 unpack_LUMINANCE_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] = s[i];
926 dst[i][ACOMP] = 1.0F;
927 }
928 }
929
930 static void
931 unpack_LUMINANCE_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] = _mesa_half_to_float(s[i]);
939 dst[i][ACOMP] = 1.0F;
940 }
941 }
942
943 static void
944 unpack_LUMINANCE_ALPHA_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] =
950 dst[i][GCOMP] =
951 dst[i][BCOMP] = s[i*2+0];
952 dst[i][ACOMP] = s[i*2+1];
953 }
954 }
955
956 static void
957 unpack_LUMINANCE_ALPHA_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] =
963 dst[i][GCOMP] =
964 dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
965 dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
966 }
967 }
968
969 static void
970 unpack_INTENSITY_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] =
976 dst[i][GCOMP] =
977 dst[i][BCOMP] =
978 dst[i][ACOMP] = s[i];
979 }
980 }
981
982 static void
983 unpack_INTENSITY_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] =
989 dst[i][GCOMP] =
990 dst[i][BCOMP] =
991 dst[i][ACOMP] = _mesa_half_to_float(s[i]);
992 }
993 }
994
995 static void
996 unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
997 {
998 const GLfloat *s = (const GLfloat *) src;
999 GLuint i;
1000 for (i = 0; i < n; i++) {
1001 dst[i][RCOMP] = s[i];
1002 dst[i][GCOMP] = 0.0F;
1003 dst[i][BCOMP] = 0.0F;
1004 dst[i][ACOMP] = 1.0F;
1005 }
1006 }
1007
1008 static void
1009 unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1010 {
1011 const GLhalfARB *s = (const GLhalfARB *) src;
1012 GLuint i;
1013 for (i = 0; i < n; i++) {
1014 dst[i][RCOMP] = _mesa_half_to_float(s[i]);
1015 dst[i][GCOMP] = 0.0F;
1016 dst[i][BCOMP] = 0.0F;
1017 dst[i][ACOMP] = 1.0F;
1018 }
1019 }
1020
1021 static void
1022 unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
1023 {
1024 const GLfloat *s = (const GLfloat *) src;
1025 GLuint i;
1026 for (i = 0; i < n; i++) {
1027 dst[i][RCOMP] = s[i*2+0];
1028 dst[i][GCOMP] = s[i*2+1];
1029 dst[i][BCOMP] = 0.0F;
1030 dst[i][ACOMP] = 1.0F;
1031 }
1032 }
1033
1034 static void
1035 unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
1036 {
1037 const GLhalfARB *s = (const GLhalfARB *) src;
1038 GLuint i;
1039 for (i = 0; i < n; i++) {
1040 dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
1041 dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
1042 dst[i][BCOMP] = 0.0F;
1043 dst[i][ACOMP] = 1.0F;
1044 }
1045 }
1046
1047
1048 static void
1049 unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
1050 {
1051 const GLbyte *s = (const GLbyte *) 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_INT16(const void *src, GLfloat dst[][4], GLuint n)
1063 {
1064 const GLshort *s = (const GLshort *) 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_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
1076 {
1077 const GLint *s = (const GLint *) src;
1078 GLuint i;
1079 for (i = 0; i < n; i++) {
1080 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1081 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1082 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1083 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1084 }
1085 }
1086
1087 static void
1088 unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
1089 {
1090 const GLubyte *s = (const GLubyte *) src;
1091 GLuint i;
1092 for (i = 0; i < n; i++) {
1093 dst[i][RCOMP] = (GLfloat) s[i*4+0];
1094 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1095 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1096 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1097 }
1098 }
1099
1100 static void
1101 unpack_RGBA_UINT16(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] = (GLfloat) s[i*4+0];
1107 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1108 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1109 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1110 }
1111 }
1112
1113 static void
1114 unpack_RGBA_UINT32(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] = (GLfloat) s[i*4+0];
1120 dst[i][GCOMP] = (GLfloat) s[i*4+1];
1121 dst[i][BCOMP] = (GLfloat) s[i*4+2];
1122 dst[i][ACOMP] = (GLfloat) s[i*4+3];
1123 }
1124 }
1125
1126 static void
1127 unpack_DUDV8(const void *src, GLfloat dst[][4], GLuint n)
1128 {
1129 const GLbyte *s = (const GLbyte *) src;
1130 GLuint i;
1131 for (i = 0; i < n; i++) {
1132 dst[i][RCOMP] = BYTE_TO_FLOAT(s[i*2+0]);
1133 dst[i][GCOMP] = BYTE_TO_FLOAT(s[i*2+1]);
1134 dst[i][BCOMP] = 0;
1135 dst[i][ACOMP] = 0;
1136 }
1137 }
1138
1139 static void
1140 unpack_SIGNED_R8(const void *src, GLfloat dst[][4], GLuint n)
1141 {
1142 const GLbyte *s = ((const GLbyte *) src);
1143 GLuint i;
1144 for (i = 0; i < n; i++) {
1145 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1146 dst[i][GCOMP] = 0.0F;
1147 dst[i][BCOMP] = 0.0F;
1148 dst[i][ACOMP] = 1.0F;
1149 }
1150 }
1151
1152 static void
1153 unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
1154 {
1155 const GLushort *s = ((const GLushort *) src);
1156 GLuint i;
1157 for (i = 0; i < n; i++) {
1158 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1159 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1160 dst[i][BCOMP] = 0.0F;
1161 dst[i][ACOMP] = 1.0F;
1162 }
1163 }
1164
1165 static void
1166 unpack_SIGNED_RGBX8888(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] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1172 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1173 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1174 dst[i][ACOMP] = 1.0f;
1175 }
1176 }
1177
1178 static void
1179 unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
1180 {
1181 const GLuint *s = ((const GLuint *) src);
1182 GLuint i;
1183 for (i = 0; i < n; i++) {
1184 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1185 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1186 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1187 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1188 }
1189 }
1190
1191 static void
1192 unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
1193 {
1194 const GLuint *s = ((const GLuint *) src);
1195 GLuint i;
1196 for (i = 0; i < n; i++) {
1197 dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] ) );
1198 dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1199 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
1200 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
1201 }
1202 }
1203
1204 static void
1205 unpack_SIGNED_R16(const void *src, GLfloat dst[][4], GLuint n)
1206 {
1207 const GLshort *s = ((const GLshort *) src);
1208 GLuint i;
1209 for (i = 0; i < n; i++) {
1210 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1211 dst[i][GCOMP] = 0.0F;
1212 dst[i][BCOMP] = 0.0F;
1213 dst[i][ACOMP] = 1.0F;
1214 }
1215 }
1216
1217 static void
1218 unpack_SIGNED_GR1616(const void *src, GLfloat dst[][4], GLuint n)
1219 {
1220 const GLuint *s = ((const GLuint *) src);
1221 GLuint i;
1222 for (i = 0; i < n; i++) {
1223 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
1224 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
1225 dst[i][BCOMP] = 0.0F;
1226 dst[i][ACOMP] = 1.0F;
1227 }
1228 }
1229
1230 static void
1231 unpack_SIGNED_RGB_16(const void *src, GLfloat dst[][4], GLuint n)
1232 {
1233 const GLshort *s = (const GLshort *) src;
1234 GLuint i;
1235 for (i = 0; i < n; i++) {
1236 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] );
1237 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
1238 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
1239 dst[i][ACOMP] = 1.0F;
1240 }
1241 }
1242
1243 static void
1244 unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1245 {
1246 const GLshort *s = (const GLshort *) src;
1247 GLuint i;
1248 for (i = 0; i < n; i++) {
1249 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
1250 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
1251 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
1252 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
1253 }
1254 }
1255
1256 static void
1257 unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
1258 {
1259 const GLushort *s = (const GLushort *) src;
1260 GLuint i;
1261 for (i = 0; i < n; i++) {
1262 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
1263 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
1264 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
1265 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
1266 }
1267 }
1268
1269 static void
1270 unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1271 {
1272 /* XXX to do */
1273 }
1274
1275 static void
1276 unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
1277 {
1278 /* XXX to do */
1279 }
1280
1281 static void
1282 unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1283 {
1284 /* XXX to do */
1285 }
1286
1287 static void
1288 unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
1289 {
1290 /* XXX to do */
1291 }
1292
1293 static void
1294 unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1295 {
1296 /* XXX to do */
1297 }
1298
1299 static void
1300 unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
1301 {
1302 /* XXX to do */
1303 }
1304
1305 static void
1306 unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1307 {
1308 /* XXX to do */
1309 }
1310
1311 static void
1312 unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
1313 {
1314 /* XXX to do */
1315 }
1316
1317 static void
1318 unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
1319 {
1320 /* XXX to do */
1321 }
1322
1323 static void
1324 unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n)
1325 {
1326 const GLbyte *s = ((const GLbyte *) src);
1327 GLuint i;
1328 for (i = 0; i < n; i++) {
1329 dst[i][RCOMP] = 0.0F;
1330 dst[i][GCOMP] = 0.0F;
1331 dst[i][BCOMP] = 0.0F;
1332 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1333 }
1334 }
1335
1336 static void
1337 unpack_SIGNED_L8(const void *src, GLfloat dst[][4], GLuint n)
1338 {
1339 const GLbyte *s = ((const GLbyte *) src);
1340 GLuint i;
1341 for (i = 0; i < n; i++) {
1342 dst[i][RCOMP] =
1343 dst[i][GCOMP] =
1344 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1345 dst[i][ACOMP] = 1.0F;
1346 }
1347 }
1348
1349 static void
1350 unpack_SIGNED_AL88(const void *src, GLfloat dst[][4], GLuint n)
1351 {
1352 const GLshort *s = ((const GLshort *) src);
1353 GLuint i;
1354 for (i = 0; i < n; i++) {
1355 dst[i][RCOMP] =
1356 dst[i][GCOMP] =
1357 dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
1358 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
1359 }
1360 }
1361
1362 static void
1363 unpack_SIGNED_I8(const void *src, GLfloat dst[][4], GLuint n)
1364 {
1365 const GLbyte *s = ((const GLbyte *) src);
1366 GLuint i;
1367 for (i = 0; i < n; i++) {
1368 dst[i][RCOMP] =
1369 dst[i][GCOMP] =
1370 dst[i][BCOMP] =
1371 dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
1372 }
1373 }
1374
1375 static void
1376 unpack_SIGNED_A16(const void *src, GLfloat dst[][4], GLuint n)
1377 {
1378 const GLshort *s = ((const GLshort *) src);
1379 GLuint i;
1380 for (i = 0; i < n; i++) {
1381 dst[i][RCOMP] = 0.0F;
1382 dst[i][GCOMP] = 0.0F;
1383 dst[i][BCOMP] = 0.0F;
1384 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1385 }
1386 }
1387
1388 static void
1389 unpack_SIGNED_L16(const void *src, GLfloat dst[][4], GLuint n)
1390 {
1391 const GLshort *s = ((const GLshort *) src);
1392 GLuint i;
1393 for (i = 0; i < n; i++) {
1394 dst[i][RCOMP] =
1395 dst[i][GCOMP] =
1396 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1397 dst[i][ACOMP] = 1.0F;
1398 }
1399 }
1400
1401 static void
1402 unpack_SIGNED_AL1616(const void *src, GLfloat dst[][4], GLuint n)
1403 {
1404 const GLshort *s = (const GLshort *) src;
1405 GLuint i;
1406 for (i = 0; i < n; i++) {
1407 dst[i][RCOMP] =
1408 dst[i][GCOMP] =
1409 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
1410 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
1411 }
1412 }
1413
1414 static void
1415 unpack_SIGNED_I16(const void *src, GLfloat dst[][4], GLuint n)
1416 {
1417 const GLshort *s = ((const GLshort *) src);
1418 GLuint i;
1419 for (i = 0; i < n; i++) {
1420 dst[i][RCOMP] =
1421 dst[i][GCOMP] =
1422 dst[i][BCOMP] =
1423 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
1424 }
1425 }
1426
1427 static void
1428 unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
1429 {
1430 const GLuint *s = (const GLuint *) src;
1431 GLuint i;
1432 for (i = 0; i < n; i++) {
1433 rgb9e5_to_float3(s[i], dst[i]);
1434 dst[i][ACOMP] = 1.0F;
1435 }
1436 }
1437
1438 static void
1439 unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
1440 {
1441 const GLuint *s = (const GLuint *) src;
1442 GLuint i;
1443 for (i = 0; i < n; i++) {
1444 r11g11b10f_to_float3(s[i], dst[i]);
1445 dst[i][ACOMP] = 1.0F;
1446 }
1447 }
1448
1449
1450 /**
1451 * Return the unpacker function for the given format.
1452 */
1453 static unpack_rgba_func
1454 get_unpack_rgba_function(gl_format format)
1455 {
1456 static unpack_rgba_func table[MESA_FORMAT_COUNT];
1457 static GLboolean initialized = GL_FALSE;
1458
1459 if (!initialized) {
1460 table[MESA_FORMAT_NONE] = NULL;
1461
1462 table[MESA_FORMAT_RGBA8888] = unpack_RGBA8888;
1463 table[MESA_FORMAT_RGBA8888_REV] = unpack_RGBA8888_REV;
1464 table[MESA_FORMAT_ARGB8888] = unpack_ARGB8888;
1465 table[MESA_FORMAT_ARGB8888_REV] = unpack_ARGB8888_REV;
1466 table[MESA_FORMAT_RGBX8888] = unpack_RGBX8888;
1467 table[MESA_FORMAT_RGBX8888_REV] = unpack_RGBX8888_REV;
1468 table[MESA_FORMAT_XRGB8888] = unpack_XRGB8888;
1469 table[MESA_FORMAT_XRGB8888_REV] = unpack_XRGB8888_REV;
1470 table[MESA_FORMAT_RGB888] = unpack_RGB888;
1471 table[MESA_FORMAT_BGR888] = unpack_BGR888;
1472 table[MESA_FORMAT_RGB565] = unpack_RGB565;
1473 table[MESA_FORMAT_RGB565_REV] = unpack_RGB565_REV;
1474 table[MESA_FORMAT_ARGB4444] = unpack_ARGB4444;
1475 table[MESA_FORMAT_ARGB4444_REV] = unpack_ARGB4444_REV;
1476 table[MESA_FORMAT_RGBA5551] = unpack_RGBA5551;
1477 table[MESA_FORMAT_ARGB1555] = unpack_ARGB1555;
1478 table[MESA_FORMAT_ARGB1555_REV] = unpack_ARGB1555_REV;
1479 table[MESA_FORMAT_AL44] = unpack_AL44;
1480 table[MESA_FORMAT_AL88] = unpack_AL88;
1481 table[MESA_FORMAT_AL88_REV] = unpack_AL88_REV;
1482 table[MESA_FORMAT_AL1616] = unpack_AL1616;
1483 table[MESA_FORMAT_AL1616_REV] = unpack_AL1616_REV;
1484 table[MESA_FORMAT_RGB332] = unpack_RGB332;
1485 table[MESA_FORMAT_A8] = unpack_A8;
1486 table[MESA_FORMAT_A16] = unpack_A16;
1487 table[MESA_FORMAT_L8] = unpack_L8;
1488 table[MESA_FORMAT_L16] = unpack_L16;
1489 table[MESA_FORMAT_I8] = unpack_I8;
1490 table[MESA_FORMAT_I16] = unpack_I16;
1491 table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
1492 table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
1493 table[MESA_FORMAT_R8] = unpack_R8;
1494 table[MESA_FORMAT_GR88] = unpack_GR88;
1495 table[MESA_FORMAT_RG88] = unpack_RG88;
1496 table[MESA_FORMAT_R16] = unpack_R16;
1497 table[MESA_FORMAT_RG1616] = unpack_RG1616;
1498 table[MESA_FORMAT_RG1616_REV] = unpack_RG1616_REV;
1499 table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010;
1500 table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8;
1501 table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24;
1502 table[MESA_FORMAT_Z16] = unpack_Z16;
1503 table[MESA_FORMAT_X8_Z24] = unpack_X8_Z24;
1504 table[MESA_FORMAT_Z24_X8] = unpack_Z24_X8;
1505 table[MESA_FORMAT_Z32] = unpack_Z32;
1506 table[MESA_FORMAT_S8] = unpack_S8;
1507 table[MESA_FORMAT_SRGB8] = unpack_SRGB8;
1508 table[MESA_FORMAT_SRGBA8] = unpack_SRGBA8;
1509 table[MESA_FORMAT_SARGB8] = unpack_SARGB8;
1510 table[MESA_FORMAT_SL8] = unpack_SL8;
1511 table[MESA_FORMAT_SLA8] = unpack_SLA8;
1512 table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
1513 table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
1514 table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
1515 table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
1516
1517 table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
1518 table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
1519 table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
1520 table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
1521 table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
1522 table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
1523
1524 table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
1525 table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
1526 table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
1527 table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
1528 table[MESA_FORMAT_ALPHA_FLOAT32] = unpack_ALPHA_FLOAT32;
1529 table[MESA_FORMAT_ALPHA_FLOAT16] = unpack_ALPHA_FLOAT16;
1530 table[MESA_FORMAT_LUMINANCE_FLOAT32] = unpack_LUMINANCE_FLOAT32;
1531 table[MESA_FORMAT_LUMINANCE_FLOAT16] = unpack_LUMINANCE_FLOAT16;
1532 table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = unpack_LUMINANCE_ALPHA_FLOAT32;
1533 table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = unpack_LUMINANCE_ALPHA_FLOAT16;
1534 table[MESA_FORMAT_INTENSITY_FLOAT32] = unpack_INTENSITY_FLOAT32;
1535 table[MESA_FORMAT_INTENSITY_FLOAT16] = unpack_INTENSITY_FLOAT16;
1536 table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
1537 table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
1538 table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
1539 table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
1540
1541 table[MESA_FORMAT_RGBA_INT8] = unpack_RGBA_INT8;
1542 table[MESA_FORMAT_RGBA_INT16] = unpack_RGBA_INT16;
1543 table[MESA_FORMAT_RGBA_INT32] = unpack_RGBA_INT32;
1544 table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
1545 table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
1546 table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
1547
1548 table[MESA_FORMAT_DUDV8] = unpack_DUDV8;
1549 table[MESA_FORMAT_SIGNED_R8] = unpack_SIGNED_R8;
1550 table[MESA_FORMAT_SIGNED_RG88_REV] = unpack_SIGNED_RG88_REV;
1551 table[MESA_FORMAT_SIGNED_RGBX8888] = unpack_SIGNED_RGBX8888;
1552 table[MESA_FORMAT_SIGNED_RGBA8888] = unpack_SIGNED_RGBA8888;
1553 table[MESA_FORMAT_SIGNED_RGBA8888_REV] = unpack_SIGNED_RGBA8888_REV;
1554 table[MESA_FORMAT_SIGNED_R16] = unpack_SIGNED_R16;
1555 table[MESA_FORMAT_SIGNED_GR1616] = unpack_SIGNED_GR1616;
1556 table[MESA_FORMAT_SIGNED_RGB_16] = unpack_SIGNED_RGB_16;
1557 table[MESA_FORMAT_SIGNED_RGBA_16] = unpack_SIGNED_RGBA_16;
1558 table[MESA_FORMAT_RGBA_16] = unpack_RGBA_16;
1559
1560 table[MESA_FORMAT_RED_RGTC1] = unpack_RED_RGTC1;
1561 table[MESA_FORMAT_SIGNED_RED_RGTC1] = unpack_SIGNED_RED_RGTC1;
1562 table[MESA_FORMAT_RG_RGTC2] = unpack_RG_RGTC2;
1563 table[MESA_FORMAT_SIGNED_RG_RGTC2] = unpack_SIGNED_RG_RGTC2;
1564
1565 table[MESA_FORMAT_L_LATC1] = unpack_L_LATC1;
1566 table[MESA_FORMAT_SIGNED_L_LATC1] = unpack_SIGNED_L_LATC1;
1567 table[MESA_FORMAT_LA_LATC2] = unpack_LA_LATC2;
1568 table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_LA_LATC2;
1569
1570 table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
1571
1572 table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8;
1573 table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8;
1574 table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88;
1575 table[MESA_FORMAT_SIGNED_I8] = unpack_SIGNED_I8;
1576 table[MESA_FORMAT_SIGNED_A16] = unpack_SIGNED_A16;
1577 table[MESA_FORMAT_SIGNED_L16] = unpack_SIGNED_L16;
1578 table[MESA_FORMAT_SIGNED_AL1616] = unpack_SIGNED_AL1616;
1579 table[MESA_FORMAT_SIGNED_I16] = unpack_SIGNED_I16;
1580
1581 table[MESA_FORMAT_RGB9_E5_FLOAT] = unpack_RGB9_E5_FLOAT;
1582 table[MESA_FORMAT_R11_G11_B10_FLOAT] = unpack_R11_G11_B10_FLOAT;
1583
1584 table[MESA_FORMAT_Z32_FLOAT] = unpack_Z32_FLOAT;
1585 table[MESA_FORMAT_Z32_FLOAT_X24S8] = unpack_Z32_FLOAT_X24S8;
1586
1587 initialized = GL_TRUE;
1588 }
1589
1590 return table[format];
1591 }
1592
1593
1594 /**
1595 * Unpack rgba colors, returning as GLfloat values.
1596 */
1597 void
1598 _mesa_unpack_rgba_row(gl_format format, GLuint n,
1599 const void *src, GLfloat dst[][4])
1600 {
1601 unpack_rgba_func unpack = get_unpack_rgba_function(format);
1602 unpack(src, dst, n);
1603 }
1604
1605
1606 /**********************************************************************/
1607 /* Unpack, returning GLubyte colors */
1608 /**********************************************************************/
1609
1610
1611 static void
1612 unpack_ubyte_RGBA8888(const void *src, GLubyte dst[][4], GLuint n)
1613 {
1614 const GLuint *s = ((const GLuint *) src);
1615 GLuint i;
1616 for (i = 0; i < n; i++) {
1617 dst[i][RCOMP] = (s[i] >> 24);
1618 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
1619 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
1620 dst[i][ACOMP] = (s[i] ) & 0xff;
1621 }
1622 }
1623
1624 static void
1625 unpack_ubyte_RGBA8888_REV(const void *src, GLubyte dst[][4], GLuint n)
1626 {
1627 const GLuint *s = ((const GLuint *) src);
1628 GLuint i;
1629 for (i = 0; i < n; i++) {
1630 dst[i][RCOMP] = (s[i] ) & 0xff;
1631 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
1632 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
1633 dst[i][ACOMP] = (s[i] >> 24);
1634 }
1635 }
1636
1637 static void
1638 unpack_ubyte_ARGB8888(const void *src, GLubyte dst[][4], GLuint n)
1639 {
1640 const GLuint *s = ((const GLuint *) src);
1641 GLuint i;
1642 for (i = 0; i < n; i++) {
1643 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
1644 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
1645 dst[i][BCOMP] = (s[i] ) & 0xff;
1646 dst[i][ACOMP] = (s[i] >> 24);
1647 }
1648 }
1649
1650 static void
1651 unpack_ubyte_ARGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
1652 {
1653 const GLuint *s = ((const GLuint *) src);
1654 GLuint i;
1655 for (i = 0; i < n; i++) {
1656 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
1657 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
1658 dst[i][BCOMP] = (s[i] >> 24);
1659 dst[i][ACOMP] = (s[i] ) & 0xff;
1660 }
1661 }
1662
1663 static void
1664 unpack_ubyte_RGBX8888(const void *src, GLubyte dst[][4], GLuint n)
1665 {
1666 const GLuint *s = ((const GLuint *) src);
1667 GLuint i;
1668 for (i = 0; i < n; i++) {
1669 dst[i][RCOMP] = (s[i] >> 24);
1670 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
1671 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
1672 dst[i][ACOMP] = 0xff;
1673 }
1674 }
1675
1676 static void
1677 unpack_ubyte_RGBX8888_REV(const void *src, GLubyte dst[][4], GLuint n)
1678 {
1679 const GLuint *s = ((const GLuint *) src);
1680 GLuint i;
1681 for (i = 0; i < n; i++) {
1682 dst[i][RCOMP] = (s[i] ) & 0xff;
1683 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
1684 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
1685 dst[i][ACOMP] = 0xff;
1686 }
1687 }
1688
1689 static void
1690 unpack_ubyte_XRGB8888(const void *src, GLubyte dst[][4], GLuint n)
1691 {
1692 const GLuint *s = ((const GLuint *) src);
1693 GLuint i;
1694 for (i = 0; i < n; i++) {
1695 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
1696 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
1697 dst[i][BCOMP] = (s[i] ) & 0xff;
1698 dst[i][ACOMP] = 0xff;
1699 }
1700 }
1701
1702 static void
1703 unpack_ubyte_XRGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
1704 {
1705 const GLuint *s = ((const GLuint *) src);
1706 GLuint i;
1707 for (i = 0; i < n; i++) {
1708 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
1709 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
1710 dst[i][BCOMP] = (s[i] >> 24);
1711 dst[i][ACOMP] = 0xff;
1712 }
1713 }
1714
1715 static void
1716 unpack_ubyte_RGB888(const void *src, GLubyte dst[][4], GLuint n)
1717 {
1718 const GLubyte *s = (const GLubyte *) src;
1719 GLuint i;
1720 for (i = 0; i < n; i++) {
1721 dst[i][RCOMP] = s[i*3+2];
1722 dst[i][GCOMP] = s[i*3+1];
1723 dst[i][BCOMP] = s[i*3+0];
1724 dst[i][ACOMP] = 0xff;
1725 }
1726 }
1727
1728 static void
1729 unpack_ubyte_BGR888(const void *src, GLubyte dst[][4], GLuint n)
1730 {
1731 const GLubyte *s = (const GLubyte *) src;
1732 GLuint i;
1733 for (i = 0; i < n; i++) {
1734 dst[i][RCOMP] = s[i*3+0];
1735 dst[i][GCOMP] = s[i*3+1];
1736 dst[i][BCOMP] = s[i*3+2];
1737 dst[i][ACOMP] = 0xff;
1738 }
1739 }
1740
1741 static void
1742 unpack_ubyte_RGB565(const void *src, GLubyte dst[][4], GLuint n)
1743 {
1744 const GLushort *s = ((const GLushort *) src);
1745 GLuint i;
1746 for (i = 0; i < n; i++) {
1747 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
1748 dst[i][GCOMP] = EXPAND_6_8((s[i] >> 5 ) & 0x3f);
1749 dst[i][BCOMP] = EXPAND_5_8( s[i] & 0x1f);
1750 dst[i][ACOMP] = 0xff;
1751 }
1752 }
1753
1754 static void
1755 unpack_ubyte_RGB565_REV(const void *src, GLubyte dst[][4], GLuint n)
1756 {
1757 const GLushort *s = ((const GLushort *) src);
1758 GLuint i;
1759 for (i = 0; i < n; i++) {
1760 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
1761 dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);
1762 dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);
1763 dst[i][BCOMP] = EXPAND_5_8( t & 0x1f);
1764 dst[i][ACOMP] = 0xff;
1765 }
1766 }
1767
1768 static void
1769 unpack_ubyte_ARGB4444(const void *src, GLubyte dst[][4], GLuint n)
1770 {
1771 const GLushort *s = ((const GLushort *) src);
1772 GLuint i;
1773 for (i = 0; i < n; i++) {
1774 dst[i][RCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
1775 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
1776 dst[i][BCOMP] = EXPAND_4_8((s[i] ) & 0xf);
1777 dst[i][ACOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
1778 }
1779 }
1780
1781 static void
1782 unpack_ubyte_ARGB4444_REV(const void *src, GLubyte dst[][4], GLuint n)
1783 {
1784 const GLushort *s = ((const GLushort *) src);
1785 GLuint i;
1786 for (i = 0; i < n; i++) {
1787 dst[i][RCOMP] = EXPAND_4_8((s[i] ) & 0xf);
1788 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
1789 dst[i][BCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
1790 dst[i][ACOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
1791 }
1792 }
1793
1794 static void
1795 unpack_ubyte_RGBA5551(const void *src, GLubyte dst[][4], GLuint n)
1796 {
1797 const GLushort *s = ((const GLushort *) src);
1798 GLuint i;
1799 for (i = 0; i < n; i++) {
1800 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
1801 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 6) & 0x1f);
1802 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 1) & 0x1f);
1803 dst[i][ACOMP] = EXPAND_1_8((s[i] ) & 0x01);
1804 }
1805 }
1806
1807 static void
1808 unpack_ubyte_ARGB1555(const void *src, GLubyte dst[][4], GLuint n)
1809 {
1810 const GLushort *s = ((const GLushort *) src);
1811 GLuint i;
1812 for (i = 0; i < n; i++) {
1813 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 10) & 0x1f);
1814 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 5) & 0x1f);
1815 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 0) & 0x1f);
1816 dst[i][ACOMP] = EXPAND_1_8((s[i] >> 15) & 0x01);
1817 }
1818 }
1819
1820 static void
1821 unpack_ubyte_ARGB1555_REV(const void *src, GLubyte dst[][4], GLuint n)
1822 {
1823 const GLushort *s = ((const GLushort *) src);
1824 GLuint i;
1825 for (i = 0; i < n; i++) {
1826 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
1827 dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
1828 dst[i][GCOMP] = EXPAND_5_8((tmp >> 5) & 0x1f);
1829 dst[i][BCOMP] = EXPAND_5_8((tmp >> 0) & 0x1f);
1830 dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
1831 }
1832 }
1833
1834 static void
1835 unpack_ubyte_AL44(const void *src, GLubyte dst[][4], GLuint n)
1836 {
1837 const GLubyte *s = ((const GLubyte *) src);
1838 GLuint i;
1839 for (i = 0; i < n; i++) {
1840 dst[i][RCOMP] =
1841 dst[i][GCOMP] =
1842 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xf);
1843 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 4);
1844 }
1845 }
1846
1847 static void
1848 unpack_ubyte_AL88(const void *src, GLubyte dst[][4], GLuint n)
1849 {
1850 const GLushort *s = ((const GLushort *) src);
1851 GLuint i;
1852 for (i = 0; i < n; i++) {
1853 dst[i][RCOMP] =
1854 dst[i][GCOMP] =
1855 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xff);
1856 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 8);
1857 }
1858 }
1859
1860 static void
1861 unpack_ubyte_AL88_REV(const void *src, GLubyte dst[][4], GLuint n)
1862 {
1863 const GLushort *s = ((const GLushort *) src);
1864 GLuint i;
1865 for (i = 0; i < n; i++) {
1866 dst[i][RCOMP] =
1867 dst[i][GCOMP] =
1868 dst[i][BCOMP] = EXPAND_4_8(s[i] >> 8);
1869 dst[i][ACOMP] = EXPAND_4_8(s[i] & 0xff);
1870 }
1871 }
1872
1873 static void
1874 unpack_ubyte_RGB332(const void *src, GLubyte dst[][4], GLuint n)
1875 {
1876 const GLubyte *s = ((const GLubyte *) src);
1877 GLuint i;
1878 for (i = 0; i < n; i++) {
1879 dst[i][RCOMP] = EXPAND_3_8((s[i] >> 5) & 0x7);
1880 dst[i][GCOMP] = EXPAND_3_8((s[i] >> 2) & 0x7);
1881 dst[i][BCOMP] = EXPAND_2_8((s[i] ) & 0x3);
1882 dst[i][ACOMP] = 0xff;
1883 }
1884 }
1885
1886 static void
1887 unpack_ubyte_A8(const void *src, GLubyte dst[][4], GLuint n)
1888 {
1889 const GLubyte *s = ((const GLubyte *) src);
1890 GLuint i;
1891 for (i = 0; i < n; i++) {
1892 dst[i][RCOMP] =
1893 dst[i][GCOMP] =
1894 dst[i][BCOMP] = 0;
1895 dst[i][ACOMP] = s[i];
1896 }
1897 }
1898
1899 static void
1900 unpack_ubyte_L8(const void *src, GLubyte dst[][4], GLuint n)
1901 {
1902 const GLubyte *s = ((const GLubyte *) src);
1903 GLuint i;
1904 for (i = 0; i < n; i++) {
1905 dst[i][RCOMP] =
1906 dst[i][GCOMP] =
1907 dst[i][BCOMP] = s[i];
1908 dst[i][ACOMP] = 0xff;
1909 }
1910 }
1911
1912
1913 static void
1914 unpack_ubyte_I8(const void *src, GLubyte dst[][4], GLuint n)
1915 {
1916 const GLubyte *s = ((const GLubyte *) src);
1917 GLuint i;
1918 for (i = 0; i < n; i++) {
1919 dst[i][RCOMP] =
1920 dst[i][GCOMP] =
1921 dst[i][BCOMP] =
1922 dst[i][ACOMP] = s[i];
1923 }
1924 }
1925
1926 static void
1927 unpack_ubyte_R8(const void *src, GLubyte dst[][4], GLuint n)
1928 {
1929 const GLubyte *s = ((const GLubyte *) src);
1930 GLuint i;
1931 for (i = 0; i < n; i++) {
1932 dst[i][0] = s[i];
1933 dst[i][1] =
1934 dst[i][2] = 0;
1935 dst[i][3] = 0xff;
1936 }
1937 }
1938
1939 static void
1940 unpack_ubyte_GR88(const void *src, GLubyte dst[][4], GLuint n)
1941 {
1942 const GLushort *s = ((const GLushort *) src);
1943 GLuint i;
1944 for (i = 0; i < n; i++) {
1945 dst[i][RCOMP] = s[i] & 0xff;
1946 dst[i][GCOMP] = s[i] >> 8;
1947 dst[i][BCOMP] = 0;
1948 dst[i][ACOMP] = 0xff;
1949 }
1950 }
1951
1952 static void
1953 unpack_ubyte_RG88(const void *src, GLubyte dst[][4], GLuint n)
1954 {
1955 const GLushort *s = ((const GLushort *) src);
1956 GLuint i;
1957 for (i = 0; i < n; i++) {
1958 dst[i][RCOMP] = s[i] >> 8;
1959 dst[i][GCOMP] = s[i] & 0xff;
1960 dst[i][BCOMP] = 0;
1961 dst[i][ACOMP] = 0xff;
1962 }
1963 }
1964
1965
1966 /**
1967 * Unpack rgba colors, returning as GLubyte values. This should usually
1968 * only be used for unpacking formats that use 8 bits or less per channel.
1969 */
1970 void
1971 _mesa_unpack_ubyte_rgba_row(gl_format format, GLuint n,
1972 const void *src, GLubyte dst[][4])
1973 {
1974 switch (format) {
1975 case MESA_FORMAT_RGBA8888:
1976 unpack_ubyte_RGBA8888(src, dst, n);
1977 break;
1978 case MESA_FORMAT_RGBA8888_REV:
1979 unpack_ubyte_RGBA8888_REV(src, dst, n);
1980 break;
1981 case MESA_FORMAT_ARGB8888:
1982 unpack_ubyte_ARGB8888(src, dst, n);
1983 break;
1984 case MESA_FORMAT_ARGB8888_REV:
1985 unpack_ubyte_ARGB8888_REV(src, dst, n);
1986 break;
1987 case MESA_FORMAT_RGBX8888:
1988 unpack_ubyte_RGBX8888(src, dst, n);
1989 break;
1990 case MESA_FORMAT_RGBX8888_REV:
1991 unpack_ubyte_RGBX8888_REV(src, dst, n);
1992 break;
1993 case MESA_FORMAT_XRGB8888:
1994 unpack_ubyte_XRGB8888(src, dst, n);
1995 break;
1996 case MESA_FORMAT_XRGB8888_REV:
1997 unpack_ubyte_XRGB8888_REV(src, dst, n);
1998 break;
1999 case MESA_FORMAT_RGB888:
2000 unpack_ubyte_RGB888(src, dst, n);
2001 break;
2002 case MESA_FORMAT_BGR888:
2003 unpack_ubyte_BGR888(src, dst, n);
2004 break;
2005 case MESA_FORMAT_RGB565:
2006 unpack_ubyte_RGB565(src, dst, n);
2007 break;
2008 case MESA_FORMAT_RGB565_REV:
2009 unpack_ubyte_RGB565_REV(src, dst, n);
2010 break;
2011 case MESA_FORMAT_ARGB4444:
2012 unpack_ubyte_ARGB4444(src, dst, n);
2013 break;
2014 case MESA_FORMAT_ARGB4444_REV:
2015 unpack_ubyte_ARGB4444_REV(src, dst, n);
2016 break;
2017 case MESA_FORMAT_RGBA5551:
2018 unpack_ubyte_RGBA5551(src, dst, n);
2019 break;
2020 case MESA_FORMAT_ARGB1555:
2021 unpack_ubyte_ARGB1555(src, dst, n);
2022 break;
2023 case MESA_FORMAT_ARGB1555_REV:
2024 unpack_ubyte_ARGB1555_REV(src, dst, n);
2025 break;
2026 case MESA_FORMAT_AL44:
2027 unpack_ubyte_AL44(src, dst, n);
2028 break;
2029 case MESA_FORMAT_AL88:
2030 unpack_ubyte_AL88(src, dst, n);
2031 break;
2032 case MESA_FORMAT_AL88_REV:
2033 unpack_ubyte_AL88_REV(src, dst, n);
2034 break;
2035 case MESA_FORMAT_RGB332:
2036 unpack_ubyte_RGB332(src, dst, n);
2037 break;
2038 case MESA_FORMAT_A8:
2039 unpack_ubyte_A8(src, dst, n);
2040 break;
2041 case MESA_FORMAT_L8:
2042 unpack_ubyte_L8(src, dst, n);
2043 break;
2044 case MESA_FORMAT_I8:
2045 unpack_ubyte_I8(src, dst, n);
2046 break;
2047 case MESA_FORMAT_R8:
2048 unpack_ubyte_R8(src, dst, n);
2049 break;
2050 case MESA_FORMAT_GR88:
2051 unpack_ubyte_GR88(src, dst, n);
2052 break;
2053 case MESA_FORMAT_RG88:
2054 unpack_ubyte_RG88(src, dst, n);
2055 break;
2056 default:
2057 /* get float values, convert to ubyte */
2058 {
2059 GLfloat *tmp = (GLfloat *) malloc(n * 4 * sizeof(GLfloat));
2060 if (tmp) {
2061 GLuint i;
2062 _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
2063 for (i = 0; i < n; i++) {
2064 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][0], tmp[i*4+0]);
2065 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][1], tmp[i*4+1]);
2066 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][2], tmp[i*4+2]);
2067 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][3], tmp[i*4+3]);
2068 }
2069 free(tmp);
2070 }
2071 }
2072 break;
2073 }
2074 }
2075
2076
2077 /**********************************************************************/
2078 /* Unpack, returning GLuint colors */
2079 /**********************************************************************/
2080
2081 static void
2082 unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2083 {
2084 memcpy(dst, src, n * 4 * sizeof(GLuint));
2085 }
2086
2087 static void
2088 unpack_int_rgba_RGBA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2089 {
2090 unsigned int i;
2091
2092 for (i = 0; i < n; i++) {
2093 dst[i][0] = src[i * 4 + 0];
2094 dst[i][1] = src[i * 4 + 1];
2095 dst[i][2] = src[i * 4 + 2];
2096 dst[i][3] = src[i * 4 + 3];
2097 }
2098 }
2099
2100 static void
2101 unpack_int_rgba_RGBA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2102 {
2103 unsigned int i;
2104
2105 for (i = 0; i < n; i++) {
2106 dst[i][0] = src[i * 4 + 0];
2107 dst[i][1] = src[i * 4 + 1];
2108 dst[i][2] = src[i * 4 + 2];
2109 dst[i][3] = src[i * 4 + 3];
2110 }
2111 }
2112
2113 static void
2114 unpack_int_rgba_RGBA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2115 {
2116 unsigned int i;
2117
2118 for (i = 0; i < n; i++) {
2119 dst[i][0] = src[i * 4 + 0];
2120 dst[i][1] = src[i * 4 + 1];
2121 dst[i][2] = src[i * 4 + 2];
2122 dst[i][3] = src[i * 4 + 3];
2123 }
2124 }
2125
2126 static void
2127 unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2128 {
2129 unsigned int i;
2130
2131 for (i = 0; i < n; i++) {
2132 dst[i][0] = src[i * 4 + 0];
2133 dst[i][1] = src[i * 4 + 1];
2134 dst[i][2] = src[i * 4 + 2];
2135 dst[i][3] = src[i * 4 + 3];
2136 }
2137 }
2138
2139 static void
2140 unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2141 {
2142 unsigned int i;
2143
2144 for (i = 0; i < n; i++) {
2145 dst[i][0] = src[i * 3 + 0];
2146 dst[i][1] = src[i * 3 + 1];
2147 dst[i][2] = src[i * 3 + 2];
2148 dst[i][3] = 1;
2149 }
2150 }
2151
2152 static void
2153 unpack_int_rgba_RGB_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2154 {
2155 unsigned int i;
2156
2157 for (i = 0; i < n; i++) {
2158 dst[i][0] = src[i * 3 + 0];
2159 dst[i][1] = src[i * 3 + 1];
2160 dst[i][2] = src[i * 3 + 2];
2161 dst[i][3] = 1;
2162 }
2163 }
2164
2165 static void
2166 unpack_int_rgba_RGB_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2167 {
2168 unsigned int i;
2169
2170 for (i = 0; i < n; i++) {
2171 dst[i][0] = src[i * 3 + 0];
2172 dst[i][1] = src[i * 3 + 1];
2173 dst[i][2] = src[i * 3 + 2];
2174 dst[i][3] = 1;
2175 }
2176 }
2177
2178 static void
2179 unpack_int_rgba_RGB_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2180 {
2181 unsigned int i;
2182
2183 for (i = 0; i < n; i++) {
2184 dst[i][0] = src[i * 3 + 0];
2185 dst[i][1] = src[i * 3 + 1];
2186 dst[i][2] = src[i * 3 + 2];
2187 dst[i][3] = 1;
2188 }
2189 }
2190
2191 static void
2192 unpack_int_rgba_RGB_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2193 {
2194 unsigned int i;
2195
2196 for (i = 0; i < n; i++) {
2197 dst[i][0] = src[i * 3 + 0];
2198 dst[i][1] = src[i * 3 + 1];
2199 dst[i][2] = src[i * 3 + 2];
2200 dst[i][3] = 1;
2201 }
2202 }
2203
2204 static void
2205 unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2206 {
2207 unsigned int i;
2208
2209 for (i = 0; i < n; i++) {
2210 dst[i][0] = src[i * 2 + 0];
2211 dst[i][1] = src[i * 2 + 1];
2212 dst[i][2] = 0;
2213 dst[i][3] = 1;
2214 }
2215 }
2216
2217 static void
2218 unpack_int_rgba_RG_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2219 {
2220 unsigned int i;
2221
2222 for (i = 0; i < n; i++) {
2223 dst[i][0] = src[i * 2 + 0];
2224 dst[i][1] = src[i * 2 + 1];
2225 dst[i][2] = 0;
2226 dst[i][3] = 1;
2227 }
2228 }
2229
2230 static void
2231 unpack_int_rgba_RG_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2232 {
2233 unsigned int i;
2234
2235 for (i = 0; i < n; i++) {
2236 dst[i][0] = src[i * 2 + 0];
2237 dst[i][1] = src[i * 2 + 1];
2238 dst[i][2] = 0;
2239 dst[i][3] = 1;
2240 }
2241 }
2242
2243 static void
2244 unpack_int_rgba_RG_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2245 {
2246 unsigned int i;
2247
2248 for (i = 0; i < n; i++) {
2249 dst[i][0] = src[i * 2 + 0];
2250 dst[i][1] = src[i * 2 + 1];
2251 dst[i][2] = 0;
2252 dst[i][3] = 1;
2253 }
2254 }
2255
2256 static void
2257 unpack_int_rgba_RG_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2258 {
2259 unsigned int i;
2260
2261 for (i = 0; i < n; i++) {
2262 dst[i][0] = src[i * 2 + 0];
2263 dst[i][1] = src[i * 2 + 1];
2264 dst[i][2] = 0;
2265 dst[i][3] = 1;
2266 }
2267 }
2268
2269 static void
2270 unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2271 {
2272 unsigned int i;
2273
2274 for (i = 0; i < n; i++) {
2275 dst[i][0] = src[i];
2276 dst[i][1] = 0;
2277 dst[i][2] = 0;
2278 dst[i][3] = 1;
2279 }
2280 }
2281
2282 static void
2283 unpack_int_rgba_R_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2284 {
2285 unsigned int i;
2286
2287 for (i = 0; i < n; i++) {
2288 dst[i][0] = src[i];
2289 dst[i][1] = 0;
2290 dst[i][2] = 0;
2291 dst[i][3] = 1;
2292 }
2293 }
2294
2295 static void
2296 unpack_int_rgba_R_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2297 {
2298 unsigned int i;
2299
2300 for (i = 0; i < n; i++) {
2301 dst[i][0] = src[i];
2302 dst[i][1] = 0;
2303 dst[i][2] = 0;
2304 dst[i][3] = 1;
2305 }
2306 }
2307
2308 static void
2309 unpack_int_rgba_R_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2310 {
2311 unsigned int i;
2312
2313 for (i = 0; i < n; i++) {
2314 dst[i][0] = src[i];
2315 dst[i][1] = 0;
2316 dst[i][2] = 0;
2317 dst[i][3] = 1;
2318 }
2319 }
2320
2321 static void
2322 unpack_int_rgba_R_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2323 {
2324 unsigned int i;
2325
2326 for (i = 0; i < n; i++) {
2327 dst[i][0] = src[i];
2328 dst[i][1] = 0;
2329 dst[i][2] = 0;
2330 dst[i][3] = 1;
2331 }
2332 }
2333
2334 static void
2335 unpack_int_rgba_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2336 {
2337 unsigned int i;
2338
2339 for (i = 0; i < n; i++) {
2340 dst[i][0] = dst[i][1] = dst[i][2] = 0;
2341 dst[i][3] = src[i];
2342 }
2343 }
2344
2345 static void
2346 unpack_int_rgba_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2347 {
2348 unsigned int i;
2349
2350 for (i = 0; i < n; i++) {
2351 dst[i][0] = dst[i][1] = dst[i][2] = 0;
2352 dst[i][3] = src[i];
2353 }
2354 }
2355
2356 static void
2357 unpack_int_rgba_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2358 {
2359 unsigned int i;
2360
2361 for (i = 0; i < n; i++) {
2362 dst[i][0] = dst[i][1] = dst[i][2] = 0;
2363 dst[i][3] = src[i];
2364 }
2365 }
2366
2367 static void
2368 unpack_int_rgba_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2369 {
2370 unsigned int i;
2371
2372 for (i = 0; i < n; i++) {
2373 dst[i][0] = dst[i][1] = dst[i][2] = 0;
2374 dst[i][3] = src[i];
2375 }
2376 }
2377
2378 static void
2379 unpack_int_rgba_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2380 {
2381 unsigned int i;
2382
2383 for (i = 0; i < n; i++) {
2384 dst[i][0] = dst[i][1] = dst[i][2] = 0;
2385 dst[i][3] = src[i];
2386 }
2387 }
2388
2389 static void
2390 unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2391 {
2392 unsigned int i;
2393
2394 for (i = 0; i < n; i++) {
2395 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
2396 dst[i][3] = 1;
2397 }
2398 }
2399
2400 static void
2401 unpack_int_rgba_LUMINANCE_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2402 {
2403 unsigned int i;
2404
2405 for (i = 0; i < n; i++) {
2406 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
2407 dst[i][3] = 1;
2408 }
2409 }
2410
2411 static void
2412 unpack_int_rgba_LUMINANCE_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2413 {
2414 unsigned int i;
2415
2416 for (i = 0; i < n; i++) {
2417 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
2418 dst[i][3] = 1;
2419 }
2420 }
2421
2422 static void
2423 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2424 {
2425 unsigned int i;
2426
2427 for (i = 0; i < n; i++) {
2428 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
2429 dst[i][3] = 1;
2430 }
2431 }
2432
2433 static void
2434 unpack_int_rgba_LUMINANCE_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2435 {
2436 unsigned int i;
2437
2438 for (i = 0; i < n; i++) {
2439 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
2440 dst[i][3] = 1;
2441 }
2442 }
2443
2444
2445 static void
2446 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2447 {
2448 unsigned int i;
2449
2450 for (i = 0; i < n; i++) {
2451 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
2452 dst[i][3] = src[i * 2 + 1];
2453 }
2454 }
2455
2456 static void
2457 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2458 {
2459 unsigned int i;
2460
2461 for (i = 0; i < n; i++) {
2462 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
2463 dst[i][3] = src[i * 2 + 1];
2464 }
2465 }
2466
2467 static void
2468 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2469 {
2470 unsigned int i;
2471
2472 for (i = 0; i < n; i++) {
2473 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
2474 dst[i][3] = src[i * 2 + 1];
2475 }
2476 }
2477
2478 static void
2479 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2480 {
2481 unsigned int i;
2482
2483 for (i = 0; i < n; i++) {
2484 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
2485 dst[i][3] = src[i * 2 + 1];
2486 }
2487 }
2488
2489 static void
2490 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2491 {
2492 unsigned int i;
2493
2494 for (i = 0; i < n; i++) {
2495 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
2496 dst[i][3] = src[i * 2 + 1];
2497 }
2498 }
2499
2500 static void
2501 unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
2502 {
2503 unsigned int i;
2504
2505 for (i = 0; i < n; i++) {
2506 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
2507 }
2508 }
2509
2510 static void
2511 unpack_int_rgba_INTENSITY_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
2512 {
2513 unsigned int i;
2514
2515 for (i = 0; i < n; i++) {
2516 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
2517 }
2518 }
2519
2520 static void
2521 unpack_int_rgba_INTENSITY_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
2522 {
2523 unsigned int i;
2524
2525 for (i = 0; i < n; i++) {
2526 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
2527 }
2528 }
2529
2530 static void
2531 unpack_int_rgba_INTENSITY_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
2532 {
2533 unsigned int i;
2534
2535 for (i = 0; i < n; i++) {
2536 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
2537 }
2538 }
2539
2540 static void
2541 unpack_int_rgba_INTENSITY_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
2542 {
2543 unsigned int i;
2544
2545 for (i = 0; i < n; i++) {
2546 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
2547 }
2548 }
2549
2550 static void
2551 unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
2552 {
2553 unsigned int i;
2554
2555 for (i = 0; i < n; i++) {
2556 GLuint tmp = src[i];
2557 dst[i][0] = (tmp >> 20) & 0x3ff;
2558 dst[i][1] = (tmp >> 10) & 0x3ff;
2559 dst[i][2] = (tmp >> 0) & 0x3ff;
2560 dst[i][3] = (tmp >> 30) & 0x3;
2561 }
2562 }
2563
2564 void
2565 _mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
2566 const void *src, GLuint dst[][4])
2567 {
2568 switch (format) {
2569 /* Since there won't be any sign extension happening, there's no need to
2570 * make separate paths for 32-bit-to-32-bit integer unpack.
2571 */
2572 case MESA_FORMAT_RGBA_UINT32:
2573 case MESA_FORMAT_RGBA_INT32:
2574 unpack_int_rgba_RGBA_UINT32(src, dst, n);
2575 break;
2576
2577 case MESA_FORMAT_RGBA_UINT16:
2578 unpack_int_rgba_RGBA_UINT16(src, dst, n);
2579 break;
2580 case MESA_FORMAT_RGBA_INT16:
2581 unpack_int_rgba_RGBA_INT16(src, dst, n);
2582 break;
2583
2584 case MESA_FORMAT_RGBA_UINT8:
2585 unpack_int_rgba_RGBA_UINT8(src, dst, n);
2586 break;
2587 case MESA_FORMAT_RGBA_INT8:
2588 unpack_int_rgba_RGBA_INT8(src, dst, n);
2589 break;
2590
2591 case MESA_FORMAT_RGB_UINT32:
2592 case MESA_FORMAT_RGB_INT32:
2593 unpack_int_rgba_RGB_UINT32(src, dst, n);
2594 break;
2595
2596 case MESA_FORMAT_RGB_UINT16:
2597 unpack_int_rgba_RGB_UINT16(src, dst, n);
2598 break;
2599 case MESA_FORMAT_RGB_INT16:
2600 unpack_int_rgba_RGB_INT16(src, dst, n);
2601 break;
2602
2603 case MESA_FORMAT_RGB_UINT8:
2604 unpack_int_rgba_RGB_UINT8(src, dst, n);
2605 break;
2606 case MESA_FORMAT_RGB_INT8:
2607 unpack_int_rgba_RGB_INT8(src, dst, n);
2608 break;
2609
2610 case MESA_FORMAT_RG_UINT32:
2611 case MESA_FORMAT_RG_INT32:
2612 unpack_int_rgba_RG_UINT32(src, dst, n);
2613 break;
2614
2615 case MESA_FORMAT_RG_UINT16:
2616 unpack_int_rgba_RG_UINT16(src, dst, n);
2617 break;
2618 case MESA_FORMAT_RG_INT16:
2619 unpack_int_rgba_RG_INT16(src, dst, n);
2620 break;
2621
2622 case MESA_FORMAT_RG_UINT8:
2623 unpack_int_rgba_RG_UINT8(src, dst, n);
2624 break;
2625 case MESA_FORMAT_RG_INT8:
2626 unpack_int_rgba_RG_INT8(src, dst, n);
2627 break;
2628
2629 case MESA_FORMAT_R_UINT32:
2630 case MESA_FORMAT_R_INT32:
2631 unpack_int_rgba_R_UINT32(src, dst, n);
2632 break;
2633
2634 case MESA_FORMAT_R_UINT16:
2635 unpack_int_rgba_R_UINT16(src, dst, n);
2636 break;
2637 case MESA_FORMAT_R_INT16:
2638 unpack_int_rgba_R_INT16(src, dst, n);
2639 break;
2640
2641 case MESA_FORMAT_R_UINT8:
2642 unpack_int_rgba_R_UINT8(src, dst, n);
2643 break;
2644 case MESA_FORMAT_R_INT8:
2645 unpack_int_rgba_R_INT8(src, dst, n);
2646 break;
2647
2648 case MESA_FORMAT_ALPHA_UINT32:
2649 case MESA_FORMAT_ALPHA_INT32:
2650 unpack_int_rgba_ALPHA_UINT32(src, dst, n);
2651 break;
2652
2653 case MESA_FORMAT_ALPHA_UINT16:
2654 unpack_int_rgba_ALPHA_UINT16(src, dst, n);
2655 break;
2656 case MESA_FORMAT_ALPHA_INT16:
2657 unpack_int_rgba_ALPHA_INT16(src, dst, n);
2658 break;
2659
2660 case MESA_FORMAT_ALPHA_UINT8:
2661 unpack_int_rgba_ALPHA_UINT8(src, dst, n);
2662 break;
2663 case MESA_FORMAT_ALPHA_INT8:
2664 unpack_int_rgba_ALPHA_INT8(src, dst, n);
2665 break;
2666
2667 case MESA_FORMAT_LUMINANCE_UINT32:
2668 case MESA_FORMAT_LUMINANCE_INT32:
2669 unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
2670 break;
2671 case MESA_FORMAT_LUMINANCE_UINT16:
2672 unpack_int_rgba_LUMINANCE_UINT16(src, dst, n);
2673 break;
2674 case MESA_FORMAT_LUMINANCE_INT16:
2675 unpack_int_rgba_LUMINANCE_INT16(src, dst, n);
2676 break;
2677
2678 case MESA_FORMAT_LUMINANCE_UINT8:
2679 unpack_int_rgba_LUMINANCE_UINT8(src, dst, n);
2680 break;
2681 case MESA_FORMAT_LUMINANCE_INT8:
2682 unpack_int_rgba_LUMINANCE_INT8(src, dst, n);
2683 break;
2684
2685 case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
2686 case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
2687 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
2688 break;
2689
2690 case MESA_FORMAT_LUMINANCE_ALPHA_UINT16:
2691 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src, dst, n);
2692 break;
2693 case MESA_FORMAT_LUMINANCE_ALPHA_INT16:
2694 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src, dst, n);
2695 break;
2696
2697 case MESA_FORMAT_LUMINANCE_ALPHA_UINT8:
2698 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src, dst, n);
2699 break;
2700 case MESA_FORMAT_LUMINANCE_ALPHA_INT8:
2701 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src, dst, n);
2702 break;
2703
2704 case MESA_FORMAT_INTENSITY_UINT32:
2705 case MESA_FORMAT_INTENSITY_INT32:
2706 unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
2707 break;
2708
2709 case MESA_FORMAT_INTENSITY_UINT16:
2710 unpack_int_rgba_INTENSITY_UINT16(src, dst, n);
2711 break;
2712 case MESA_FORMAT_INTENSITY_INT16:
2713 unpack_int_rgba_INTENSITY_INT16(src, dst, n);
2714 break;
2715
2716 case MESA_FORMAT_INTENSITY_UINT8:
2717 unpack_int_rgba_INTENSITY_UINT8(src, dst, n);
2718 break;
2719 case MESA_FORMAT_INTENSITY_INT8:
2720 unpack_int_rgba_INTENSITY_INT8(src, dst, n);
2721 break;
2722
2723 case MESA_FORMAT_ARGB2101010_UINT:
2724 unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
2725 break;
2726 default:
2727 _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
2728 _mesa_get_format_name(format));
2729 return;
2730 }
2731 }
2732
2733 /**
2734 * Unpack a 2D rect of pixels returning float RGBA colors.
2735 * \param format the source image format
2736 * \param src start address of the source image
2737 * \param srcRowStride source image row stride in bytes
2738 * \param dst start address of the dest image
2739 * \param dstRowStride dest image row stride in bytes
2740 * \param x source image start X pos
2741 * \param y source image start Y pos
2742 * \param width width of rect region to convert
2743 * \param height height of rect region to convert
2744 */
2745 void
2746 _mesa_unpack_rgba_block(gl_format format,
2747 const void *src, GLint srcRowStride,
2748 GLfloat dst[][4], GLint dstRowStride,
2749 GLuint x, GLuint y, GLuint width, GLuint height)
2750 {
2751 unpack_rgba_func unpack = get_unpack_rgba_function(format);
2752 const GLuint srcPixStride = _mesa_get_format_bytes(format);
2753 const GLuint dstPixStride = 4 * sizeof(GLfloat);
2754 const GLubyte *srcRow;
2755 GLubyte *dstRow;
2756 GLuint i;
2757
2758 /* XXX needs to be fixed for compressed formats */
2759
2760 srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
2761 dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
2762
2763 for (i = 0; i < height; i++) {
2764 unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
2765
2766 dstRow += dstRowStride;
2767 srcRow += srcRowStride;
2768 }
2769 }
2770
2771
2772
2773
2774 typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
2775
2776 static void
2777 unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
2778 {
2779 /* only return Z, not stencil data */
2780 const GLuint *s = ((const GLuint *) src);
2781 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
2782 GLuint i;
2783 for (i = 0; i < n; i++) {
2784 dst[i] = (s[i] >> 8) * scale;
2785 ASSERT(dst[i] >= 0.0F);
2786 ASSERT(dst[i] <= 1.0F);
2787 }
2788 }
2789
2790 static void
2791 unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
2792 {
2793 /* only return Z, not stencil data */
2794 const GLuint *s = ((const GLuint *) src);
2795 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
2796 GLuint i;
2797 for (i = 0; i < n; i++) {
2798 dst[i] = (s[i] & 0x00ffffff) * scale;
2799 ASSERT(dst[i] >= 0.0F);
2800 ASSERT(dst[i] <= 1.0F);
2801 }
2802 }
2803
2804 static void
2805 unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst)
2806 {
2807 const GLushort *s = ((const GLushort *) src);
2808 GLuint i;
2809 for (i = 0; i < n; i++) {
2810 dst[i] = s[i] * (1.0F / 65535.0F);
2811 }
2812 }
2813
2814 static void
2815 unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst)
2816 {
2817 const GLuint *s = ((const GLuint *) src);
2818 GLuint i;
2819 for (i = 0; i < n; i++) {
2820 dst[i] = s[i] * (1.0F / 0xffffffff);
2821 }
2822 }
2823
2824 static void
2825 unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst)
2826 {
2827 memcpy(dst, src, n * sizeof(float));
2828 }
2829
2830 static void
2831 unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
2832 {
2833 const GLfloat *s = ((const GLfloat *) src);
2834 GLuint i;
2835 for (i = 0; i < n; i++) {
2836 dst[i] = s[i * 2];
2837 }
2838 }
2839
2840
2841
2842 /**
2843 * Unpack Z values.
2844 * The returned values will always be in the range [0.0, 1.0].
2845 */
2846 void
2847 _mesa_unpack_float_z_row(gl_format format, GLuint n,
2848 const void *src, GLfloat *dst)
2849 {
2850 unpack_float_z_func unpack;
2851
2852 switch (format) {
2853 case MESA_FORMAT_Z24_S8:
2854 case MESA_FORMAT_Z24_X8:
2855 unpack = unpack_float_z_Z24_X8;
2856 break;
2857 case MESA_FORMAT_S8_Z24:
2858 case MESA_FORMAT_X8_Z24:
2859 unpack = unpack_float_z_X8_Z24;
2860 break;
2861 case MESA_FORMAT_Z16:
2862 unpack = unpack_float_z_Z16;
2863 break;
2864 case MESA_FORMAT_Z32:
2865 unpack = unpack_float_z_Z32;
2866 break;
2867 case MESA_FORMAT_Z32_FLOAT:
2868 unpack = unpack_float_z_Z32F;
2869 break;
2870 case MESA_FORMAT_Z32_FLOAT_X24S8:
2871 unpack = unpack_float_z_Z32X24S8;
2872 break;
2873 default:
2874 _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
2875 _mesa_get_format_name(format));
2876 return;
2877 }
2878
2879 unpack(n, src, dst);
2880 }
2881
2882
2883
2884 typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
2885
2886 static void
2887 unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
2888 {
2889 /* only return Z, not stencil data */
2890 const GLuint *s = ((const GLuint *) src);
2891 GLuint i;
2892 for (i = 0; i < n; i++) {
2893 dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
2894 }
2895 }
2896
2897 static void
2898 unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
2899 {
2900 /* only return Z, not stencil data */
2901 const GLuint *s = ((const GLuint *) src);
2902 GLuint i;
2903 for (i = 0; i < n; i++) {
2904 dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
2905 }
2906 }
2907
2908 static void
2909 unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n)
2910 {
2911 const GLushort *s = ((const GLushort *)src);
2912 GLuint i;
2913 for (i = 0; i < n; i++) {
2914 dst[i] = (s[i] << 16) | s[i];
2915 }
2916 }
2917
2918 static void
2919 unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
2920 {
2921 memcpy(dst, src, n * sizeof(GLuint));
2922 }
2923
2924 static void
2925 unpack_uint_z_Z32_FLOAT(const void *src, GLuint *dst, GLuint n)
2926 {
2927 const float *s = (const float *)src;
2928 GLuint i;
2929 for (i = 0; i < n; i++) {
2930 dst[i] = FLOAT_TO_UINT(CLAMP(s[i], 0.0F, 1.0F));
2931 }
2932 }
2933
2934 static void
2935 unpack_uint_z_Z32_FLOAT_X24S8(const void *src, GLuint *dst, GLuint n)
2936 {
2937 struct z32f_x24s8 {
2938 float z;
2939 uint32_t x24s8;
2940 };
2941
2942 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
2943 GLuint i;
2944
2945 for (i = 0; i < n; i++) {
2946 dst[i] = FLOAT_TO_UINT(CLAMP(s[i].z, 0.0F, 1.0F));
2947 }
2948 }
2949
2950
2951 /**
2952 * Unpack Z values.
2953 * The returned values will always be in the range [0, 0xffffffff].
2954 */
2955 void
2956 _mesa_unpack_uint_z_row(gl_format format, GLuint n,
2957 const void *src, GLuint *dst)
2958 {
2959 unpack_uint_z_func unpack;
2960 const GLubyte *srcPtr = (GLubyte *) src;
2961
2962 switch (format) {
2963 case MESA_FORMAT_Z24_S8:
2964 case MESA_FORMAT_Z24_X8:
2965 unpack = unpack_uint_z_Z24_X8;
2966 break;
2967 case MESA_FORMAT_S8_Z24:
2968 case MESA_FORMAT_X8_Z24:
2969 unpack = unpack_uint_z_X8_Z24;
2970 break;
2971 case MESA_FORMAT_Z16:
2972 unpack = unpack_uint_z_Z16;
2973 break;
2974 case MESA_FORMAT_Z32:
2975 unpack = unpack_uint_z_Z32;
2976 break;
2977 case MESA_FORMAT_Z32_FLOAT:
2978 unpack = unpack_uint_z_Z32_FLOAT;
2979 break;
2980 case MESA_FORMAT_Z32_FLOAT_X24S8:
2981 unpack = unpack_uint_z_Z32_FLOAT_X24S8;
2982 break;
2983 default:
2984 _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
2985 _mesa_get_format_name(format));
2986 return;
2987 }
2988
2989 unpack(srcPtr, dst, n);
2990 }
2991
2992
2993 static void
2994 unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
2995 {
2996 memcpy(dst, src, n);
2997 }
2998
2999 static void
3000 unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n)
3001 {
3002 GLuint i;
3003 const GLuint *src32 = src;
3004
3005 for (i = 0; i < n; i++)
3006 dst[i] = src32[i] & 0xff;
3007 }
3008
3009 static void
3010 unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n)
3011 {
3012 GLuint i;
3013 const GLuint *src32 = src;
3014
3015 for (i = 0; i < n; i++)
3016 dst[i] = src32[i] >> 24;
3017 }
3018
3019 static void
3020 unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n)
3021 {
3022 GLuint i;
3023 const GLuint *src32 = src;
3024
3025 for (i = 0; i < n; i++)
3026 dst[i] = src32[i * 2 + 1] & 0xff;
3027 }
3028
3029 void
3030 _mesa_unpack_ubyte_stencil_row(gl_format format, GLuint n,
3031 const void *src, GLubyte *dst)
3032 {
3033 switch (format) {
3034 case MESA_FORMAT_S8:
3035 unpack_ubyte_s_S8(src, dst, n);
3036 break;
3037 case MESA_FORMAT_Z24_S8:
3038 unpack_ubyte_s_Z24_S8(src, dst, n);
3039 break;
3040 case MESA_FORMAT_S8_Z24:
3041 unpack_ubyte_s_S8_Z24(src, dst, n);
3042 break;
3043 case MESA_FORMAT_Z32_FLOAT_X24S8:
3044 unpack_ubyte_s_Z32_FLOAT_X24S8(src, dst, n);
3045 break;
3046 default:
3047 _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
3048 _mesa_get_format_name(format));
3049 return;
3050 }
3051 }
3052
3053 static void
3054 unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint *src, GLuint *dst, GLuint n)
3055 {
3056 GLuint i;
3057
3058 for (i = 0; i < n; i++) {
3059 GLuint val = src[i];
3060 dst[i] = val >> 24 | val << 8;
3061 }
3062 }
3063
3064 static void
3065 unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint *src, GLuint *dst, GLuint n)
3066 {
3067 memcpy(dst, src, n * 4);
3068 }
3069
3070 void
3071 _mesa_unpack_uint_24_8_depth_stencil_row(gl_format format, GLuint n,
3072 const void *src, GLuint *dst)
3073 {
3074 switch (format) {
3075 case MESA_FORMAT_Z24_S8:
3076 unpack_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
3077 break;
3078 case MESA_FORMAT_S8_Z24:
3079 unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
3080 break;
3081 default:
3082 _mesa_problem(NULL,
3083 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
3084 _mesa_get_format_name(format));
3085 return;
3086 }
3087 }