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