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