[SDK] Provide .const macro for gas
[reactos.git] / dll / opengl / 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 #include <precomp.h>
25
26 /* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
27
28 #define EXPAND_1_8(X) ( (X) ? 0xff : 0x0 )
29
30 #define EXPAND_2_8(X) ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
31
32 #define EXPAND_3_8(X) ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
33
34 #define EXPAND_4_8(X) ( ((X) << 4) | (X) )
35
36 #define EXPAND_5_8(X) ( ((X) << 3) | ((X) >> 2) )
37
38 #define EXPAND_6_8(X) ( ((X) << 2) | ((X) >> 4) )
39
40 /**********************************************************************/
41 /* Unpack, returning GLfloat colors */
42 /**********************************************************************/
43
44 typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);
45
46
47 static void
48 unpack_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
49 {
50 const GLuint *s = ((const GLuint *) src);
51 GLuint i;
52 for (i = 0; i < n; i++) {
53 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
54 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
55 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
56 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
57 }
58 }
59
60 static void
61 unpack_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
62 {
63 const GLuint *s = ((const GLuint *) src);
64 GLuint i;
65 for (i = 0; i < n; i++) {
66 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
67 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
68 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
69 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
70 }
71 }
72
73 static void
74 unpack_ARGB8888(const void *src, GLfloat dst[][4], GLuint n)
75 {
76 const GLuint *s = ((const GLuint *) src);
77 GLuint i;
78 for (i = 0; i < n; i++) {
79 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
80 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
81 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
82 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
83 }
84 }
85
86 static void
87 unpack_ARGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
88 {
89 const GLuint *s = ((const GLuint *) src);
90 GLuint i;
91 for (i = 0; i < n; i++) {
92 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
93 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
94 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
95 dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
96 }
97 }
98
99 static void
100 unpack_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
101 {
102 const GLuint *s = ((const GLuint *) src);
103 GLuint i;
104 for (i = 0; i < n; i++) {
105 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
106 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
107 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
108 dst[i][ACOMP] = 1.0f;
109 }
110 }
111
112 static void
113 unpack_RGBX8888_REV(const void *src, GLfloat dst[][4], GLuint n)
114 {
115 const GLuint *s = ((const GLuint *) src);
116 GLuint i;
117 for (i = 0; i < n; i++) {
118 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
119 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
120 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
121 dst[i][ACOMP] = 1.0f;
122 }
123 }
124
125 static void
126 unpack_XRGB8888(const void *src, GLfloat dst[][4], GLuint n)
127 {
128 const GLuint *s = ((const GLuint *) src);
129 GLuint i;
130 for (i = 0; i < n; i++) {
131 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
132 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
133 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] ) & 0xff );
134 dst[i][ACOMP] = 1.0f;
135 }
136 }
137
138 static void
139 unpack_XRGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
140 {
141 const GLuint *s = ((const GLuint *) src);
142 GLuint i;
143 for (i = 0; i < n; i++) {
144 dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 8) & 0xff );
145 dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
146 dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24) );
147 dst[i][ACOMP] = 1.0f;
148 }
149 }
150
151 static void
152 unpack_RGB888(const void *src, GLfloat dst[][4], GLuint n)
153 {
154 const GLubyte *s = (const GLubyte *) src;
155 GLuint i;
156 for (i = 0; i < n; i++) {
157 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
158 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
159 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
160 dst[i][ACOMP] = 1.0F;
161 }
162 }
163
164 static void
165 unpack_BGR888(const void *src, GLfloat dst[][4], GLuint n)
166 {
167 const GLubyte *s = (const GLubyte *) src;
168 GLuint i;
169 for (i = 0; i < n; i++) {
170 dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
171 dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
172 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
173 dst[i][ACOMP] = 1.0F;
174 }
175 }
176
177 static void
178 unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n)
179 {
180 const GLushort *s = ((const GLushort *) src);
181 GLuint i;
182 for (i = 0; i < n; i++) {
183 dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
184 dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F);
185 dst[i][BCOMP] = ((s[i] ) & 0x1f) * (1.0F / 31.0F);
186 dst[i][ACOMP] = 1.0F;
187 }
188 }
189
190 static void
191 unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n)
192 {
193 const GLushort *s = ((const GLushort *) src);
194 GLuint i;
195 for (i = 0; i < n; i++) {
196 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
197 dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) );
198 dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >> 9) & 0x3) );
199 dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >> 2) & 0x7) );
200 dst[i][ACOMP] = 1.0F;
201 }
202 }
203
204 static void
205 unpack_ARGB4444(const void *src, GLfloat dst[][4], GLuint n)
206 {
207 const GLushort *s = ((const GLushort *) src);
208 GLuint i;
209 for (i = 0; i < n; i++) {
210 dst[i][RCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
211 dst[i][GCOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
212 dst[i][BCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
213 dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
214 }
215 }
216
217 static void
218 unpack_ARGB4444_REV(const void *src, GLfloat dst[][4], GLuint n)
219 {
220 const GLushort *s = ((const GLushort *) src);
221 GLuint i;
222 for (i = 0; i < n; i++) {
223 dst[i][RCOMP] = ((s[i] ) & 0xf) * (1.0F / 15.0F);
224 dst[i][GCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
225 dst[i][BCOMP] = ((s[i] >> 8) & 0xf) * (1.0F / 15.0F);
226 dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
227 }
228 }
229
230 static void
231 unpack_RGBA5551(const void *src, GLfloat dst[][4], GLuint n)
232 {
233 const GLushort *s = ((const GLushort *) src);
234 GLuint i;
235 for (i = 0; i < n; i++) {
236 dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
237 dst[i][GCOMP] = ((s[i] >> 6) & 0x1f) * (1.0F / 31.0F);
238 dst[i][BCOMP] = ((s[i] >> 1) & 0x1f) * (1.0F / 31.0F);
239 dst[i][ACOMP] = ((s[i] ) & 0x01) * 1.0F;
240 }
241 }
242
243 static void
244 unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n)
245 {
246 const GLushort *s = ((const GLushort *) src);
247 GLuint i;
248 for (i = 0; i < n; i++) {
249 dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
250 dst[i][GCOMP] = ((s[i] >> 5) & 0x1f) * (1.0F / 31.0F);
251 dst[i][BCOMP] = ((s[i] >> 0) & 0x1f) * (1.0F / 31.0F);
252 dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F;
253 }
254 }
255
256 static void
257 unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n)
258 {
259 const GLushort *s = ((const GLushort *) src);
260 GLuint i;
261 for (i = 0; i < n; i++) {
262 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
263 dst[i][RCOMP] = ((tmp >> 10) & 0x1f) * (1.0F / 31.0F);
264 dst[i][GCOMP] = ((tmp >> 5) & 0x1f) * (1.0F / 31.0F);
265 dst[i][BCOMP] = ((tmp >> 0) & 0x1f) * (1.0F / 31.0F);
266 dst[i][ACOMP] = ((tmp >> 15) & 0x01) * 1.0F;
267 }
268 }
269
270 static void
271 unpack_AL44(const void *src, GLfloat dst[][4], GLuint n)
272 {
273 const GLubyte *s = ((const GLubyte *) src);
274 GLuint i;
275 for (i = 0; i < n; i++) {
276 dst[i][RCOMP] =
277 dst[i][GCOMP] =
278 dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
279 dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
280 }
281 }
282
283 static void
284 unpack_AL88(const void *src, GLfloat dst[][4], GLuint n)
285 {
286 const GLushort *s = ((const GLushort *) src);
287 GLuint i;
288 for (i = 0; i < n; i++) {
289 dst[i][RCOMP] =
290 dst[i][GCOMP] =
291 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
292 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
293 }
294 }
295
296 static void
297 unpack_AL88_REV(const void *src, GLfloat dst[][4], GLuint n)
298 {
299 const GLushort *s = ((const GLushort *) src);
300 GLuint i;
301 for (i = 0; i < n; i++) {
302 dst[i][RCOMP] =
303 dst[i][GCOMP] =
304 dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
305 dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
306 }
307 }
308
309 static void
310 unpack_AL1616(const void *src, GLfloat dst[][4], GLuint n)
311 {
312 const GLuint *s = ((const GLuint *) src);
313 GLuint i;
314 for (i = 0; i < n; i++) {
315 dst[i][RCOMP] =
316 dst[i][GCOMP] =
317 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
318 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
319 }
320 }
321
322 static void
323 unpack_AL1616_REV(const void *src, GLfloat dst[][4], GLuint n)
324 {
325 const GLuint *s = ((const GLuint *) src);
326 GLuint i;
327 for (i = 0; i < n; i++) {
328 dst[i][RCOMP] =
329 dst[i][GCOMP] =
330 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
331 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
332 }
333 }
334
335 static void
336 unpack_RGB332(const void *src, GLfloat dst[][4], GLuint n)
337 {
338 const GLubyte *s = ((const GLubyte *) src);
339 GLuint i;
340 for (i = 0; i < n; i++) {
341 dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F);
342 dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F);
343 dst[i][BCOMP] = ((s[i] ) & 0x3) * (1.0F / 3.0F);
344 dst[i][ACOMP] = 1.0F;
345 }
346 }
347
348
349 static void
350 unpack_A8(const void *src, GLfloat dst[][4], GLuint n)
351 {
352 const GLubyte *s = ((const GLubyte *) src);
353 GLuint i;
354 for (i = 0; i < n; i++) {
355 dst[i][RCOMP] =
356 dst[i][GCOMP] =
357 dst[i][BCOMP] = 0.0F;
358 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
359 }
360 }
361
362 static void
363 unpack_A16(const void *src, GLfloat dst[][4], GLuint n)
364 {
365 const GLushort *s = ((const GLushort *) src);
366 GLuint i;
367 for (i = 0; i < n; i++) {
368 dst[i][RCOMP] =
369 dst[i][GCOMP] =
370 dst[i][BCOMP] = 0.0F;
371 dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
372 }
373 }
374
375 static void
376 unpack_L8(const void *src, GLfloat dst[][4], GLuint n)
377 {
378 const GLubyte *s = ((const GLubyte *) src);
379 GLuint i;
380 for (i = 0; i < n; i++) {
381 dst[i][RCOMP] =
382 dst[i][GCOMP] =
383 dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
384 dst[i][ACOMP] = 1.0F;
385 }
386 }
387
388 static void
389 unpack_L16(const void *src, GLfloat dst[][4], GLuint n)
390 {
391 const GLushort *s = ((const GLushort *) src);
392 GLuint i;
393 for (i = 0; i < n; i++) {
394 dst[i][RCOMP] =
395 dst[i][GCOMP] =
396 dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
397 dst[i][ACOMP] = 1.0F;
398 }
399 }
400
401 static void
402 unpack_I8(const void *src, GLfloat dst[][4], GLuint n)
403 {
404 const GLubyte *s = ((const GLubyte *) src);
405 GLuint i;
406 for (i = 0; i < n; i++) {
407 dst[i][RCOMP] =
408 dst[i][GCOMP] =
409 dst[i][BCOMP] =
410 dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
411 }
412 }
413
414 static void
415 unpack_I16(const void *src, GLfloat dst[][4], GLuint n)
416 {
417 const GLushort *s = ((const GLushort *) src);
418 GLuint i;
419 for (i = 0; i < n; i++) {
420 dst[i][RCOMP] =
421 dst[i][GCOMP] =
422 dst[i][BCOMP] =
423 dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
424 }
425 }
426
427 static void
428 unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n)
429 {
430 GLuint i;
431 for (i = 0; i < n; i++) {
432 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
433 const GLushort *src1 = src0 + 1; /* odd */
434 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
435 const GLubyte cb = *src0 & 0xff; /* chroma U */
436 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
437 const GLubyte cr = *src1 & 0xff; /* chroma V */
438 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
439 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
440 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
441 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
442 r *= (1.0F / 255.0F);
443 g *= (1.0F / 255.0F);
444 b *= (1.0F / 255.0F);
445 dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
446 dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
447 dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
448 dst[i][ACOMP] = 1.0F;
449 }
450 }
451
452 static void
453 unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
454 {
455 GLuint i;
456 for (i = 0; i < n; i++) {
457 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
458 const GLushort *src1 = src0 + 1; /* odd */
459 const GLubyte y0 = *src0 & 0xff; /* luminance */
460 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
461 const GLubyte y1 = *src1 & 0xff; /* luminance */
462 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
463 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
464 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
465 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
466 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
467 r *= (1.0F / 255.0F);
468 g *= (1.0F / 255.0F);
469 b *= (1.0F / 255.0F);
470 dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
471 dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
472 dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
473 dst[i][ACOMP] = 1.0F;
474 }
475 }
476
477
478 static void
479 unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
480 {
481 /* only return Z, not stencil data */
482 const GLuint *s = ((const GLuint *) src);
483 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
484 GLuint i;
485 for (i = 0; i < n; i++) {
486 dst[i][0] =
487 dst[i][1] =
488 dst[i][2] = (s[i] >> 8) * scale;
489 dst[i][3] = 1.0F;
490 ASSERT(dst[i][0] >= 0.0F);
491 ASSERT(dst[i][0] <= 1.0F);
492 }
493 }
494
495 static void
496 unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
497 {
498 /* only return Z, not stencil data */
499 const GLuint *s = ((const GLuint *) src);
500 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
501 GLuint i;
502 for (i = 0; i < n; i++) {
503 dst[i][0] =
504 dst[i][1] =
505 dst[i][2] = (s[i] & 0x00ffffff) * scale;
506 dst[i][3] = 1.0F;
507 ASSERT(dst[i][0] >= 0.0F);
508 ASSERT(dst[i][0] <= 1.0F);
509 }
510 }
511
512 static void
513 unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
514 {
515 const GLushort *s = ((const GLushort *) src);
516 GLuint i;
517 for (i = 0; i < n; i++) {
518 dst[i][0] =
519 dst[i][1] =
520 dst[i][2] = s[i] * (1.0F / 65535.0F);
521 dst[i][3] = 1.0F;
522 }
523 }
524
525 static void
526 unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n)
527 {
528 unpack_S8_Z24(src, dst, n);
529 }
530
531 static void
532 unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n)
533 {
534 unpack_Z24_S8(src, dst, n);
535 }
536
537 static void
538 unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
539 {
540 const GLuint *s = ((const GLuint *) src);
541 GLuint i;
542 for (i = 0; i < n; i++) {
543 dst[i][0] =
544 dst[i][1] =
545 dst[i][2] = s[i] * (1.0F / 0xffffffff);
546 dst[i][3] = 1.0F;
547 }
548 }
549
550
551 static void
552 unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
553 {
554 /* should never be used */
555 GLuint i;
556 for (i = 0; i < n; i++) {
557 dst[i][0] =
558 dst[i][1] =
559 dst[i][2] = 0.0F;
560 dst[i][3] = 1.0F;
561 }
562 }
563
564 static void
565 unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
566 {
567 const GLbyte *s = (const GLbyte *) src;
568 GLuint i;
569 for (i = 0; i < n; i++) {
570 dst[i][RCOMP] = (GLfloat) s[i*4+0];
571 dst[i][GCOMP] = (GLfloat) s[i*4+1];
572 dst[i][BCOMP] = (GLfloat) s[i*4+2];
573 dst[i][ACOMP] = (GLfloat) s[i*4+3];
574 }
575 }
576
577 static void
578 unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
579 {
580 const GLshort *s = (const GLshort *) src;
581 GLuint i;
582 for (i = 0; i < n; i++) {
583 dst[i][RCOMP] = (GLfloat) s[i*4+0];
584 dst[i][GCOMP] = (GLfloat) s[i*4+1];
585 dst[i][BCOMP] = (GLfloat) s[i*4+2];
586 dst[i][ACOMP] = (GLfloat) s[i*4+3];
587 }
588 }
589
590 static void
591 unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
592 {
593 const GLint *s = (const GLint *) src;
594 GLuint i;
595 for (i = 0; i < n; i++) {
596 dst[i][RCOMP] = (GLfloat) s[i*4+0];
597 dst[i][GCOMP] = (GLfloat) s[i*4+1];
598 dst[i][BCOMP] = (GLfloat) s[i*4+2];
599 dst[i][ACOMP] = (GLfloat) s[i*4+3];
600 }
601 }
602
603 static void
604 unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
605 {
606 const GLubyte *s = (const GLubyte *) src;
607 GLuint i;
608 for (i = 0; i < n; i++) {
609 dst[i][RCOMP] = (GLfloat) s[i*4+0];
610 dst[i][GCOMP] = (GLfloat) s[i*4+1];
611 dst[i][BCOMP] = (GLfloat) s[i*4+2];
612 dst[i][ACOMP] = (GLfloat) s[i*4+3];
613 }
614 }
615
616 static void
617 unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
618 {
619 const GLushort *s = (const GLushort *) src;
620 GLuint i;
621 for (i = 0; i < n; i++) {
622 dst[i][RCOMP] = (GLfloat) s[i*4+0];
623 dst[i][GCOMP] = (GLfloat) s[i*4+1];
624 dst[i][BCOMP] = (GLfloat) s[i*4+2];
625 dst[i][ACOMP] = (GLfloat) s[i*4+3];
626 }
627 }
628
629 static void
630 unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
631 {
632 const GLuint *s = (const GLuint *) src;
633 GLuint i;
634 for (i = 0; i < n; i++) {
635 dst[i][RCOMP] = (GLfloat) s[i*4+0];
636 dst[i][GCOMP] = (GLfloat) s[i*4+1];
637 dst[i][BCOMP] = (GLfloat) s[i*4+2];
638 dst[i][ACOMP] = (GLfloat) s[i*4+3];
639 }
640 }
641
642 static void
643 unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
644 {
645 const GLshort *s = (const GLshort *) src;
646 GLuint i;
647 for (i = 0; i < n; i++) {
648 dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
649 dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
650 dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
651 dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
652 }
653 }
654
655 static void
656 unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
657 {
658 const GLushort *s = (const GLushort *) src;
659 GLuint i;
660 for (i = 0; i < n; i++) {
661 dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
662 dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
663 dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
664 dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
665 }
666 }
667
668
669 /**
670 * Return the unpacker function for the given format.
671 */
672 static unpack_rgba_func
673 get_unpack_rgba_function(gl_format format)
674 {
675 static unpack_rgba_func table[MESA_FORMAT_COUNT];
676 static GLboolean initialized = GL_FALSE;
677
678 if (!initialized) {
679 table[MESA_FORMAT_NONE] = NULL;
680
681 table[MESA_FORMAT_RGBA8888] = unpack_RGBA8888;
682 table[MESA_FORMAT_RGBA8888_REV] = unpack_RGBA8888_REV;
683 table[MESA_FORMAT_ARGB8888] = unpack_ARGB8888;
684 table[MESA_FORMAT_ARGB8888_REV] = unpack_ARGB8888_REV;
685 table[MESA_FORMAT_RGBX8888] = unpack_RGBX8888;
686 table[MESA_FORMAT_RGBX8888_REV] = unpack_RGBX8888_REV;
687 table[MESA_FORMAT_XRGB8888] = unpack_XRGB8888;
688 table[MESA_FORMAT_XRGB8888_REV] = unpack_XRGB8888_REV;
689 table[MESA_FORMAT_RGB888] = unpack_RGB888;
690 table[MESA_FORMAT_BGR888] = unpack_BGR888;
691 table[MESA_FORMAT_RGB565] = unpack_RGB565;
692 table[MESA_FORMAT_RGB565_REV] = unpack_RGB565_REV;
693 table[MESA_FORMAT_ARGB4444] = unpack_ARGB4444;
694 table[MESA_FORMAT_ARGB4444_REV] = unpack_ARGB4444_REV;
695 table[MESA_FORMAT_RGBA5551] = unpack_RGBA5551;
696 table[MESA_FORMAT_ARGB1555] = unpack_ARGB1555;
697 table[MESA_FORMAT_ARGB1555_REV] = unpack_ARGB1555_REV;
698 table[MESA_FORMAT_AL44] = unpack_AL44;
699 table[MESA_FORMAT_AL88] = unpack_AL88;
700 table[MESA_FORMAT_AL88_REV] = unpack_AL88_REV;
701 table[MESA_FORMAT_AL1616] = unpack_AL1616;
702 table[MESA_FORMAT_AL1616_REV] = unpack_AL1616_REV;
703 table[MESA_FORMAT_RGB332] = unpack_RGB332;
704 table[MESA_FORMAT_A8] = unpack_A8;
705 table[MESA_FORMAT_A16] = unpack_A16;
706 table[MESA_FORMAT_L8] = unpack_L8;
707 table[MESA_FORMAT_L16] = unpack_L16;
708 table[MESA_FORMAT_I8] = unpack_I8;
709 table[MESA_FORMAT_I16] = unpack_I16;
710 table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
711 table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
712 table[MESA_FORMAT_Z16] = unpack_Z16;
713 table[MESA_FORMAT_X8_Z24] = unpack_X8_Z24;
714 table[MESA_FORMAT_Z24_X8] = unpack_Z24_X8;
715 table[MESA_FORMAT_Z32] = unpack_Z32;
716 table[MESA_FORMAT_S8] = unpack_S8;
717
718 table[MESA_FORMAT_RGBA_INT8] = unpack_RGBA_INT8;
719 table[MESA_FORMAT_RGBA_INT16] = unpack_RGBA_INT16;
720 table[MESA_FORMAT_RGBA_INT32] = unpack_RGBA_INT32;
721 table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
722 table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
723 table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
724
725 table[MESA_FORMAT_SIGNED_RGBA_16] = unpack_SIGNED_RGBA_16;
726 table[MESA_FORMAT_RGBA_16] = unpack_RGBA_16;
727
728 initialized = GL_TRUE;
729 }
730
731 return table[format];
732 }
733
734
735 /**
736 * Unpack rgba colors, returning as GLfloat values.
737 */
738 void
739 _mesa_unpack_rgba_row(gl_format format, GLuint n,
740 const void *src, GLfloat dst[][4])
741 {
742 unpack_rgba_func unpack = get_unpack_rgba_function(format);
743 unpack(src, dst, n);
744 }
745
746
747 /**********************************************************************/
748 /* Unpack, returning GLubyte colors */
749 /**********************************************************************/
750
751
752 static void
753 unpack_ubyte_RGBA8888(const void *src, GLubyte dst[][4], GLuint n)
754 {
755 const GLuint *s = ((const GLuint *) src);
756 GLuint i;
757 for (i = 0; i < n; i++) {
758 dst[i][RCOMP] = (s[i] >> 24);
759 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
760 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
761 dst[i][ACOMP] = (s[i] ) & 0xff;
762 }
763 }
764
765 static void
766 unpack_ubyte_RGBA8888_REV(const void *src, GLubyte dst[][4], GLuint n)
767 {
768 const GLuint *s = ((const GLuint *) src);
769 GLuint i;
770 for (i = 0; i < n; i++) {
771 dst[i][RCOMP] = (s[i] ) & 0xff;
772 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
773 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
774 dst[i][ACOMP] = (s[i] >> 24);
775 }
776 }
777
778 static void
779 unpack_ubyte_ARGB8888(const void *src, GLubyte dst[][4], GLuint n)
780 {
781 const GLuint *s = ((const GLuint *) src);
782 GLuint i;
783 for (i = 0; i < n; i++) {
784 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
785 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
786 dst[i][BCOMP] = (s[i] ) & 0xff;
787 dst[i][ACOMP] = (s[i] >> 24);
788 }
789 }
790
791 static void
792 unpack_ubyte_ARGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
793 {
794 const GLuint *s = ((const GLuint *) src);
795 GLuint i;
796 for (i = 0; i < n; i++) {
797 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
798 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
799 dst[i][BCOMP] = (s[i] >> 24);
800 dst[i][ACOMP] = (s[i] ) & 0xff;
801 }
802 }
803
804 static void
805 unpack_ubyte_RGBX8888(const void *src, GLubyte dst[][4], GLuint n)
806 {
807 const GLuint *s = ((const GLuint *) src);
808 GLuint i;
809 for (i = 0; i < n; i++) {
810 dst[i][RCOMP] = (s[i] >> 24);
811 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
812 dst[i][BCOMP] = (s[i] >> 8) & 0xff;
813 dst[i][ACOMP] = 0xff;
814 }
815 }
816
817 static void
818 unpack_ubyte_RGBX8888_REV(const void *src, GLubyte dst[][4], GLuint n)
819 {
820 const GLuint *s = ((const GLuint *) src);
821 GLuint i;
822 for (i = 0; i < n; i++) {
823 dst[i][RCOMP] = (s[i] ) & 0xff;
824 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
825 dst[i][BCOMP] = (s[i] >> 16) & 0xff;
826 dst[i][ACOMP] = 0xff;
827 }
828 }
829
830 static void
831 unpack_ubyte_XRGB8888(const void *src, GLubyte dst[][4], GLuint n)
832 {
833 const GLuint *s = ((const GLuint *) src);
834 GLuint i;
835 for (i = 0; i < n; i++) {
836 dst[i][RCOMP] = (s[i] >> 16) & 0xff;
837 dst[i][GCOMP] = (s[i] >> 8) & 0xff;
838 dst[i][BCOMP] = (s[i] ) & 0xff;
839 dst[i][ACOMP] = 0xff;
840 }
841 }
842
843 static void
844 unpack_ubyte_XRGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
845 {
846 const GLuint *s = ((const GLuint *) src);
847 GLuint i;
848 for (i = 0; i < n; i++) {
849 dst[i][RCOMP] = (s[i] >> 8) & 0xff;
850 dst[i][GCOMP] = (s[i] >> 16) & 0xff;
851 dst[i][BCOMP] = (s[i] >> 24);
852 dst[i][ACOMP] = 0xff;
853 }
854 }
855
856 static void
857 unpack_ubyte_RGB888(const void *src, GLubyte dst[][4], GLuint n)
858 {
859 const GLubyte *s = (const GLubyte *) src;
860 GLuint i;
861 for (i = 0; i < n; i++) {
862 dst[i][RCOMP] = s[i*3+2];
863 dst[i][GCOMP] = s[i*3+1];
864 dst[i][BCOMP] = s[i*3+0];
865 dst[i][ACOMP] = 0xff;
866 }
867 }
868
869 static void
870 unpack_ubyte_BGR888(const void *src, GLubyte dst[][4], GLuint n)
871 {
872 const GLubyte *s = (const GLubyte *) src;
873 GLuint i;
874 for (i = 0; i < n; i++) {
875 dst[i][RCOMP] = s[i*3+0];
876 dst[i][GCOMP] = s[i*3+1];
877 dst[i][BCOMP] = s[i*3+2];
878 dst[i][ACOMP] = 0xff;
879 }
880 }
881
882 static void
883 unpack_ubyte_RGB565(const void *src, GLubyte dst[][4], GLuint n)
884 {
885 const GLushort *s = ((const GLushort *) src);
886 GLuint i;
887 for (i = 0; i < n; i++) {
888 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
889 dst[i][GCOMP] = EXPAND_6_8((s[i] >> 5 ) & 0x3f);
890 dst[i][BCOMP] = EXPAND_5_8( s[i] & 0x1f);
891 dst[i][ACOMP] = 0xff;
892 }
893 }
894
895 static void
896 unpack_ubyte_RGB565_REV(const void *src, GLubyte dst[][4], GLuint n)
897 {
898 const GLushort *s = ((const GLushort *) src);
899 GLuint i;
900 for (i = 0; i < n; i++) {
901 GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
902 dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);
903 dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);
904 dst[i][BCOMP] = EXPAND_5_8( t & 0x1f);
905 dst[i][ACOMP] = 0xff;
906 }
907 }
908
909 static void
910 unpack_ubyte_ARGB4444(const void *src, GLubyte dst[][4], GLuint n)
911 {
912 const GLushort *s = ((const GLushort *) src);
913 GLuint i;
914 for (i = 0; i < n; i++) {
915 dst[i][RCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
916 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
917 dst[i][BCOMP] = EXPAND_4_8((s[i] ) & 0xf);
918 dst[i][ACOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
919 }
920 }
921
922 static void
923 unpack_ubyte_ARGB4444_REV(const void *src, GLubyte dst[][4], GLuint n)
924 {
925 const GLushort *s = ((const GLushort *) src);
926 GLuint i;
927 for (i = 0; i < n; i++) {
928 dst[i][RCOMP] = EXPAND_4_8((s[i] ) & 0xf);
929 dst[i][GCOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
930 dst[i][BCOMP] = EXPAND_4_8((s[i] >> 8) & 0xf);
931 dst[i][ACOMP] = EXPAND_4_8((s[i] >> 4) & 0xf);
932 }
933 }
934
935 static void
936 unpack_ubyte_RGBA5551(const void *src, GLubyte dst[][4], GLuint n)
937 {
938 const GLushort *s = ((const GLushort *) src);
939 GLuint i;
940 for (i = 0; i < n; i++) {
941 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
942 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 6) & 0x1f);
943 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 1) & 0x1f);
944 dst[i][ACOMP] = EXPAND_1_8((s[i] ) & 0x01);
945 }
946 }
947
948 static void
949 unpack_ubyte_ARGB1555(const void *src, GLubyte dst[][4], GLuint n)
950 {
951 const GLushort *s = ((const GLushort *) src);
952 GLuint i;
953 for (i = 0; i < n; i++) {
954 dst[i][RCOMP] = EXPAND_5_8((s[i] >> 10) & 0x1f);
955 dst[i][GCOMP] = EXPAND_5_8((s[i] >> 5) & 0x1f);
956 dst[i][BCOMP] = EXPAND_5_8((s[i] >> 0) & 0x1f);
957 dst[i][ACOMP] = EXPAND_1_8((s[i] >> 15) & 0x01);
958 }
959 }
960
961 static void
962 unpack_ubyte_ARGB1555_REV(const void *src, GLubyte dst[][4], GLuint n)
963 {
964 const GLushort *s = ((const GLushort *) src);
965 GLuint i;
966 for (i = 0; i < n; i++) {
967 GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
968 dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
969 dst[i][GCOMP] = EXPAND_5_8((tmp >> 5) & 0x1f);
970 dst[i][BCOMP] = EXPAND_5_8((tmp >> 0) & 0x1f);
971 dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
972 }
973 }
974
975 static void
976 unpack_ubyte_AL44(const void *src, GLubyte dst[][4], GLuint n)
977 {
978 const GLubyte *s = ((const GLubyte *) src);
979 GLuint i;
980 for (i = 0; i < n; i++) {
981 dst[i][RCOMP] =
982 dst[i][GCOMP] =
983 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xf);
984 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 4);
985 }
986 }
987
988 static void
989 unpack_ubyte_AL88(const void *src, GLubyte dst[][4], GLuint n)
990 {
991 const GLushort *s = ((const GLushort *) src);
992 GLuint i;
993 for (i = 0; i < n; i++) {
994 dst[i][RCOMP] =
995 dst[i][GCOMP] =
996 dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xff);
997 dst[i][ACOMP] = EXPAND_4_8(s[i] >> 8);
998 }
999 }
1000
1001 static void
1002 unpack_ubyte_AL88_REV(const void *src, GLubyte dst[][4], GLuint n)
1003 {
1004 const GLushort *s = ((const GLushort *) src);
1005 GLuint i;
1006 for (i = 0; i < n; i++) {
1007 dst[i][RCOMP] =
1008 dst[i][GCOMP] =
1009 dst[i][BCOMP] = EXPAND_4_8(s[i] >> 8);
1010 dst[i][ACOMP] = EXPAND_4_8(s[i] & 0xff);
1011 }
1012 }
1013
1014 static void
1015 unpack_ubyte_RGB332(const void *src, GLubyte dst[][4], GLuint n)
1016 {
1017 const GLubyte *s = ((const GLubyte *) src);
1018 GLuint i;
1019 for (i = 0; i < n; i++) {
1020 dst[i][RCOMP] = EXPAND_3_8((s[i] >> 5) & 0x7);
1021 dst[i][GCOMP] = EXPAND_3_8((s[i] >> 2) & 0x7);
1022 dst[i][BCOMP] = EXPAND_2_8((s[i] ) & 0x3);
1023 dst[i][ACOMP] = 0xff;
1024 }
1025 }
1026
1027 static void
1028 unpack_ubyte_A8(const void *src, GLubyte dst[][4], GLuint n)
1029 {
1030 const GLubyte *s = ((const GLubyte *) src);
1031 GLuint i;
1032 for (i = 0; i < n; i++) {
1033 dst[i][RCOMP] =
1034 dst[i][GCOMP] =
1035 dst[i][BCOMP] = 0;
1036 dst[i][ACOMP] = s[i];
1037 }
1038 }
1039
1040 static void
1041 unpack_ubyte_L8(const void *src, GLubyte dst[][4], GLuint n)
1042 {
1043 const GLubyte *s = ((const GLubyte *) src);
1044 GLuint i;
1045 for (i = 0; i < n; i++) {
1046 dst[i][RCOMP] =
1047 dst[i][GCOMP] =
1048 dst[i][BCOMP] = s[i];
1049 dst[i][ACOMP] = 0xff;
1050 }
1051 }
1052
1053
1054 static void
1055 unpack_ubyte_I8(const void *src, GLubyte dst[][4], GLuint n)
1056 {
1057 const GLubyte *s = ((const GLubyte *) src);
1058 GLuint i;
1059 for (i = 0; i < n; i++) {
1060 dst[i][RCOMP] =
1061 dst[i][GCOMP] =
1062 dst[i][BCOMP] =
1063 dst[i][ACOMP] = s[i];
1064 }
1065 }
1066
1067
1068 /**
1069 * Unpack rgba colors, returning as GLubyte values. This should usually
1070 * only be used for unpacking formats that use 8 bits or less per channel.
1071 */
1072 void
1073 _mesa_unpack_ubyte_rgba_row(gl_format format, GLuint n,
1074 const void *src, GLubyte dst[][4])
1075 {
1076 switch (format) {
1077 case MESA_FORMAT_RGBA8888:
1078 unpack_ubyte_RGBA8888(src, dst, n);
1079 break;
1080 case MESA_FORMAT_RGBA8888_REV:
1081 unpack_ubyte_RGBA8888_REV(src, dst, n);
1082 break;
1083 case MESA_FORMAT_ARGB8888:
1084 unpack_ubyte_ARGB8888(src, dst, n);
1085 break;
1086 case MESA_FORMAT_ARGB8888_REV:
1087 unpack_ubyte_ARGB8888_REV(src, dst, n);
1088 break;
1089 case MESA_FORMAT_RGBX8888:
1090 unpack_ubyte_RGBX8888(src, dst, n);
1091 break;
1092 case MESA_FORMAT_RGBX8888_REV:
1093 unpack_ubyte_RGBX8888_REV(src, dst, n);
1094 break;
1095 case MESA_FORMAT_XRGB8888:
1096 unpack_ubyte_XRGB8888(src, dst, n);
1097 break;
1098 case MESA_FORMAT_XRGB8888_REV:
1099 unpack_ubyte_XRGB8888_REV(src, dst, n);
1100 break;
1101 case MESA_FORMAT_RGB888:
1102 unpack_ubyte_RGB888(src, dst, n);
1103 break;
1104 case MESA_FORMAT_BGR888:
1105 unpack_ubyte_BGR888(src, dst, n);
1106 break;
1107 case MESA_FORMAT_RGB565:
1108 unpack_ubyte_RGB565(src, dst, n);
1109 break;
1110 case MESA_FORMAT_RGB565_REV:
1111 unpack_ubyte_RGB565_REV(src, dst, n);
1112 break;
1113 case MESA_FORMAT_ARGB4444:
1114 unpack_ubyte_ARGB4444(src, dst, n);
1115 break;
1116 case MESA_FORMAT_ARGB4444_REV:
1117 unpack_ubyte_ARGB4444_REV(src, dst, n);
1118 break;
1119 case MESA_FORMAT_RGBA5551:
1120 unpack_ubyte_RGBA5551(src, dst, n);
1121 break;
1122 case MESA_FORMAT_ARGB1555:
1123 unpack_ubyte_ARGB1555(src, dst, n);
1124 break;
1125 case MESA_FORMAT_ARGB1555_REV:
1126 unpack_ubyte_ARGB1555_REV(src, dst, n);
1127 break;
1128 case MESA_FORMAT_AL44:
1129 unpack_ubyte_AL44(src, dst, n);
1130 break;
1131 case MESA_FORMAT_AL88:
1132 unpack_ubyte_AL88(src, dst, n);
1133 break;
1134 case MESA_FORMAT_AL88_REV:
1135 unpack_ubyte_AL88_REV(src, dst, n);
1136 break;
1137 case MESA_FORMAT_RGB332:
1138 unpack_ubyte_RGB332(src, dst, n);
1139 break;
1140 case MESA_FORMAT_A8:
1141 unpack_ubyte_A8(src, dst, n);
1142 break;
1143 case MESA_FORMAT_L8:
1144 unpack_ubyte_L8(src, dst, n);
1145 break;
1146 case MESA_FORMAT_I8:
1147 unpack_ubyte_I8(src, dst, n);
1148 break;
1149 default:
1150 /* get float values, convert to ubyte */
1151 {
1152 GLfloat *tmp = (GLfloat *) malloc(n * 4 * sizeof(GLfloat));
1153 if (tmp) {
1154 GLuint i;
1155 _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
1156 for (i = 0; i < n; i++) {
1157 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][0], tmp[i*4+0]);
1158 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][1], tmp[i*4+1]);
1159 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][2], tmp[i*4+2]);
1160 UNCLAMPED_FLOAT_TO_UBYTE(dst[i][3], tmp[i*4+3]);
1161 }
1162 free(tmp);
1163 }
1164 }
1165 break;
1166 }
1167 }
1168
1169
1170 /**********************************************************************/
1171 /* Unpack, returning GLuint colors */
1172 /**********************************************************************/
1173
1174 static void
1175 unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1176 {
1177 memcpy(dst, src, n * 4 * sizeof(GLuint));
1178 }
1179
1180 static void
1181 unpack_int_rgba_RGBA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
1182 {
1183 unsigned int i;
1184
1185 for (i = 0; i < n; i++) {
1186 dst[i][0] = src[i * 4 + 0];
1187 dst[i][1] = src[i * 4 + 1];
1188 dst[i][2] = src[i * 4 + 2];
1189 dst[i][3] = src[i * 4 + 3];
1190 }
1191 }
1192
1193 static void
1194 unpack_int_rgba_RGBA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
1195 {
1196 unsigned int i;
1197
1198 for (i = 0; i < n; i++) {
1199 dst[i][0] = src[i * 4 + 0];
1200 dst[i][1] = src[i * 4 + 1];
1201 dst[i][2] = src[i * 4 + 2];
1202 dst[i][3] = src[i * 4 + 3];
1203 }
1204 }
1205
1206 static void
1207 unpack_int_rgba_RGBA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
1208 {
1209 unsigned int i;
1210
1211 for (i = 0; i < n; i++) {
1212 dst[i][0] = src[i * 4 + 0];
1213 dst[i][1] = src[i * 4 + 1];
1214 dst[i][2] = src[i * 4 + 2];
1215 dst[i][3] = src[i * 4 + 3];
1216 }
1217 }
1218
1219 static void
1220 unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
1221 {
1222 unsigned int i;
1223
1224 for (i = 0; i < n; i++) {
1225 dst[i][0] = src[i * 4 + 0];
1226 dst[i][1] = src[i * 4 + 1];
1227 dst[i][2] = src[i * 4 + 2];
1228 dst[i][3] = src[i * 4 + 3];
1229 }
1230 }
1231
1232 static void
1233 unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1234 {
1235 unsigned int i;
1236
1237 for (i = 0; i < n; i++) {
1238 dst[i][0] = src[i * 3 + 0];
1239 dst[i][1] = src[i * 3 + 1];
1240 dst[i][2] = src[i * 3 + 2];
1241 dst[i][3] = 1;
1242 }
1243 }
1244
1245 static void
1246 unpack_int_rgba_RGB_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
1247 {
1248 unsigned int i;
1249
1250 for (i = 0; i < n; i++) {
1251 dst[i][0] = src[i * 3 + 0];
1252 dst[i][1] = src[i * 3 + 1];
1253 dst[i][2] = src[i * 3 + 2];
1254 dst[i][3] = 1;
1255 }
1256 }
1257
1258 static void
1259 unpack_int_rgba_RGB_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
1260 {
1261 unsigned int i;
1262
1263 for (i = 0; i < n; i++) {
1264 dst[i][0] = src[i * 3 + 0];
1265 dst[i][1] = src[i * 3 + 1];
1266 dst[i][2] = src[i * 3 + 2];
1267 dst[i][3] = 1;
1268 }
1269 }
1270
1271 static void
1272 unpack_int_rgba_RGB_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
1273 {
1274 unsigned int i;
1275
1276 for (i = 0; i < n; i++) {
1277 dst[i][0] = src[i * 3 + 0];
1278 dst[i][1] = src[i * 3 + 1];
1279 dst[i][2] = src[i * 3 + 2];
1280 dst[i][3] = 1;
1281 }
1282 }
1283
1284 static void
1285 unpack_int_rgba_RGB_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
1286 {
1287 unsigned int i;
1288
1289 for (i = 0; i < n; i++) {
1290 dst[i][0] = src[i * 3 + 0];
1291 dst[i][1] = src[i * 3 + 1];
1292 dst[i][2] = src[i * 3 + 2];
1293 dst[i][3] = 1;
1294 }
1295 }
1296
1297 static void
1298 unpack_int_rgba_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1299 {
1300 unsigned int i;
1301
1302 for (i = 0; i < n; i++) {
1303 dst[i][0] = dst[i][1] = dst[i][2] = 0;
1304 dst[i][3] = src[i];
1305 }
1306 }
1307
1308 static void
1309 unpack_int_rgba_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
1310 {
1311 unsigned int i;
1312
1313 for (i = 0; i < n; i++) {
1314 dst[i][0] = dst[i][1] = dst[i][2] = 0;
1315 dst[i][3] = src[i];
1316 }
1317 }
1318
1319 static void
1320 unpack_int_rgba_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
1321 {
1322 unsigned int i;
1323
1324 for (i = 0; i < n; i++) {
1325 dst[i][0] = dst[i][1] = dst[i][2] = 0;
1326 dst[i][3] = src[i];
1327 }
1328 }
1329
1330 static void
1331 unpack_int_rgba_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
1332 {
1333 unsigned int i;
1334
1335 for (i = 0; i < n; i++) {
1336 dst[i][0] = dst[i][1] = dst[i][2] = 0;
1337 dst[i][3] = src[i];
1338 }
1339 }
1340
1341 static void
1342 unpack_int_rgba_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
1343 {
1344 unsigned int i;
1345
1346 for (i = 0; i < n; i++) {
1347 dst[i][0] = dst[i][1] = dst[i][2] = 0;
1348 dst[i][3] = src[i];
1349 }
1350 }
1351
1352 static void
1353 unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1354 {
1355 unsigned int i;
1356
1357 for (i = 0; i < n; i++) {
1358 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
1359 dst[i][3] = 1;
1360 }
1361 }
1362
1363 static void
1364 unpack_int_rgba_LUMINANCE_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
1365 {
1366 unsigned int i;
1367
1368 for (i = 0; i < n; i++) {
1369 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
1370 dst[i][3] = 1;
1371 }
1372 }
1373
1374 static void
1375 unpack_int_rgba_LUMINANCE_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
1376 {
1377 unsigned int i;
1378
1379 for (i = 0; i < n; i++) {
1380 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
1381 dst[i][3] = 1;
1382 }
1383 }
1384
1385 static void
1386 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
1387 {
1388 unsigned int i;
1389
1390 for (i = 0; i < n; i++) {
1391 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
1392 dst[i][3] = 1;
1393 }
1394 }
1395
1396 static void
1397 unpack_int_rgba_LUMINANCE_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
1398 {
1399 unsigned int i;
1400
1401 for (i = 0; i < n; i++) {
1402 dst[i][0] = dst[i][1] = dst[i][2] = src[i];
1403 dst[i][3] = 1;
1404 }
1405 }
1406
1407
1408 static void
1409 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1410 {
1411 unsigned int i;
1412
1413 for (i = 0; i < n; i++) {
1414 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
1415 dst[i][3] = src[i * 2 + 1];
1416 }
1417 }
1418
1419 static void
1420 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
1421 {
1422 unsigned int i;
1423
1424 for (i = 0; i < n; i++) {
1425 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
1426 dst[i][3] = src[i * 2 + 1];
1427 }
1428 }
1429
1430 static void
1431 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
1432 {
1433 unsigned int i;
1434
1435 for (i = 0; i < n; i++) {
1436 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
1437 dst[i][3] = src[i * 2 + 1];
1438 }
1439 }
1440
1441 static void
1442 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
1443 {
1444 unsigned int i;
1445
1446 for (i = 0; i < n; i++) {
1447 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
1448 dst[i][3] = src[i * 2 + 1];
1449 }
1450 }
1451
1452 static void
1453 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
1454 {
1455 unsigned int i;
1456
1457 for (i = 0; i < n; i++) {
1458 dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
1459 dst[i][3] = src[i * 2 + 1];
1460 }
1461 }
1462
1463 static void
1464 unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
1465 {
1466 unsigned int i;
1467
1468 for (i = 0; i < n; i++) {
1469 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
1470 }
1471 }
1472
1473 static void
1474 unpack_int_rgba_INTENSITY_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
1475 {
1476 unsigned int i;
1477
1478 for (i = 0; i < n; i++) {
1479 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
1480 }
1481 }
1482
1483 static void
1484 unpack_int_rgba_INTENSITY_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
1485 {
1486 unsigned int i;
1487
1488 for (i = 0; i < n; i++) {
1489 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
1490 }
1491 }
1492
1493 static void
1494 unpack_int_rgba_INTENSITY_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
1495 {
1496 unsigned int i;
1497
1498 for (i = 0; i < n; i++) {
1499 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
1500 }
1501 }
1502
1503 static void
1504 unpack_int_rgba_INTENSITY_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
1505 {
1506 unsigned int i;
1507
1508 for (i = 0; i < n; i++) {
1509 dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
1510 }
1511 }
1512
1513 void
1514 _mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
1515 const void *src, GLuint dst[][4])
1516 {
1517 switch (format) {
1518 /* Since there won't be any sign extension happening, there's no need to
1519 * make separate paths for 32-bit-to-32-bit integer unpack.
1520 */
1521 case MESA_FORMAT_RGBA_UINT32:
1522 case MESA_FORMAT_RGBA_INT32:
1523 unpack_int_rgba_RGBA_UINT32(src, dst, n);
1524 break;
1525
1526 case MESA_FORMAT_RGBA_UINT16:
1527 unpack_int_rgba_RGBA_UINT16(src, dst, n);
1528 break;
1529 case MESA_FORMAT_RGBA_INT16:
1530 unpack_int_rgba_RGBA_INT16(src, dst, n);
1531 break;
1532
1533 case MESA_FORMAT_RGBA_UINT8:
1534 unpack_int_rgba_RGBA_UINT8(src, dst, n);
1535 break;
1536 case MESA_FORMAT_RGBA_INT8:
1537 unpack_int_rgba_RGBA_INT8(src, dst, n);
1538 break;
1539
1540 case MESA_FORMAT_RGB_UINT32:
1541 case MESA_FORMAT_RGB_INT32:
1542 unpack_int_rgba_RGB_UINT32(src, dst, n);
1543 break;
1544
1545 case MESA_FORMAT_RGB_UINT16:
1546 unpack_int_rgba_RGB_UINT16(src, dst, n);
1547 break;
1548 case MESA_FORMAT_RGB_INT16:
1549 unpack_int_rgba_RGB_INT16(src, dst, n);
1550 break;
1551
1552 case MESA_FORMAT_RGB_UINT8:
1553 unpack_int_rgba_RGB_UINT8(src, dst, n);
1554 break;
1555 case MESA_FORMAT_RGB_INT8:
1556 unpack_int_rgba_RGB_INT8(src, dst, n);
1557 break;
1558
1559 case MESA_FORMAT_ALPHA_UINT32:
1560 case MESA_FORMAT_ALPHA_INT32:
1561 unpack_int_rgba_ALPHA_UINT32(src, dst, n);
1562 break;
1563
1564 case MESA_FORMAT_ALPHA_UINT16:
1565 unpack_int_rgba_ALPHA_UINT16(src, dst, n);
1566 break;
1567 case MESA_FORMAT_ALPHA_INT16:
1568 unpack_int_rgba_ALPHA_INT16(src, dst, n);
1569 break;
1570
1571 case MESA_FORMAT_ALPHA_UINT8:
1572 unpack_int_rgba_ALPHA_UINT8(src, dst, n);
1573 break;
1574 case MESA_FORMAT_ALPHA_INT8:
1575 unpack_int_rgba_ALPHA_INT8(src, dst, n);
1576 break;
1577
1578 case MESA_FORMAT_LUMINANCE_UINT32:
1579 case MESA_FORMAT_LUMINANCE_INT32:
1580 unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
1581 break;
1582 case MESA_FORMAT_LUMINANCE_UINT16:
1583 unpack_int_rgba_LUMINANCE_UINT16(src, dst, n);
1584 break;
1585 case MESA_FORMAT_LUMINANCE_INT16:
1586 unpack_int_rgba_LUMINANCE_INT16(src, dst, n);
1587 break;
1588
1589 case MESA_FORMAT_LUMINANCE_UINT8:
1590 unpack_int_rgba_LUMINANCE_UINT8(src, dst, n);
1591 break;
1592 case MESA_FORMAT_LUMINANCE_INT8:
1593 unpack_int_rgba_LUMINANCE_INT8(src, dst, n);
1594 break;
1595
1596 case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
1597 case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
1598 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
1599 break;
1600
1601 case MESA_FORMAT_LUMINANCE_ALPHA_UINT16:
1602 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src, dst, n);
1603 break;
1604 case MESA_FORMAT_LUMINANCE_ALPHA_INT16:
1605 unpack_int_rgba_LUMINANCE_ALPHA_INT16(src, dst, n);
1606 break;
1607
1608 case MESA_FORMAT_LUMINANCE_ALPHA_UINT8:
1609 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src, dst, n);
1610 break;
1611 case MESA_FORMAT_LUMINANCE_ALPHA_INT8:
1612 unpack_int_rgba_LUMINANCE_ALPHA_INT8(src, dst, n);
1613 break;
1614
1615 case MESA_FORMAT_INTENSITY_UINT32:
1616 case MESA_FORMAT_INTENSITY_INT32:
1617 unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
1618 break;
1619
1620 case MESA_FORMAT_INTENSITY_UINT16:
1621 unpack_int_rgba_INTENSITY_UINT16(src, dst, n);
1622 break;
1623 case MESA_FORMAT_INTENSITY_INT16:
1624 unpack_int_rgba_INTENSITY_INT16(src, dst, n);
1625 break;
1626
1627 case MESA_FORMAT_INTENSITY_UINT8:
1628 unpack_int_rgba_INTENSITY_UINT8(src, dst, n);
1629 break;
1630 case MESA_FORMAT_INTENSITY_INT8:
1631 unpack_int_rgba_INTENSITY_INT8(src, dst, n);
1632 break;
1633
1634 default:
1635 _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
1636 _mesa_get_format_name(format));
1637 return;
1638 }
1639 }
1640
1641 /**
1642 * Unpack a 2D rect of pixels returning float RGBA colors.
1643 * \param format the source image format
1644 * \param src start address of the source image
1645 * \param srcRowStride source image row stride in bytes
1646 * \param dst start address of the dest image
1647 * \param dstRowStride dest image row stride in bytes
1648 * \param x source image start X pos
1649 * \param y source image start Y pos
1650 * \param width width of rect region to convert
1651 * \param height height of rect region to convert
1652 */
1653 void
1654 _mesa_unpack_rgba_block(gl_format format,
1655 const void *src, GLint srcRowStride,
1656 GLfloat dst[][4], GLint dstRowStride,
1657 GLuint x, GLuint y, GLuint width, GLuint height)
1658 {
1659 unpack_rgba_func unpack = get_unpack_rgba_function(format);
1660 const GLuint srcPixStride = _mesa_get_format_bytes(format);
1661 const GLuint dstPixStride = 4 * sizeof(GLfloat);
1662 const GLubyte *srcRow;
1663 GLubyte *dstRow;
1664 GLuint i;
1665
1666 /* XXX needs to be fixed for compressed formats */
1667
1668 srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
1669 dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
1670
1671 for (i = 0; i < height; i++) {
1672 unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
1673
1674 dstRow += dstRowStride;
1675 srcRow += srcRowStride;
1676 }
1677 }
1678
1679
1680
1681
1682 typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
1683
1684 static void
1685 unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
1686 {
1687 /* only return Z, not stencil data */
1688 const GLuint *s = ((const GLuint *) src);
1689 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
1690 GLuint i;
1691 for (i = 0; i < n; i++) {
1692 dst[i] = (s[i] >> 8) * scale;
1693 ASSERT(dst[i] >= 0.0F);
1694 ASSERT(dst[i] <= 1.0F);
1695 }
1696 }
1697
1698 static void
1699 unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
1700 {
1701 /* only return Z, not stencil data */
1702 const GLuint *s = ((const GLuint *) src);
1703 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
1704 GLuint i;
1705 for (i = 0; i < n; i++) {
1706 dst[i] = (s[i] & 0x00ffffff) * scale;
1707 ASSERT(dst[i] >= 0.0F);
1708 ASSERT(dst[i] <= 1.0F);
1709 }
1710 }
1711
1712 static void
1713 unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst)
1714 {
1715 const GLushort *s = ((const GLushort *) src);
1716 GLuint i;
1717 for (i = 0; i < n; i++) {
1718 dst[i] = s[i] * (1.0F / 65535.0F);
1719 }
1720 }
1721
1722 static void
1723 unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst)
1724 {
1725 const GLuint *s = ((const GLuint *) src);
1726 GLuint i;
1727 for (i = 0; i < n; i++) {
1728 dst[i] = s[i] * (1.0F / 0xffffffff);
1729 }
1730 }
1731
1732
1733
1734 /**
1735 * Unpack Z values.
1736 * The returned values will always be in the range [0.0, 1.0].
1737 */
1738 void
1739 _mesa_unpack_float_z_row(gl_format format, GLuint n,
1740 const void *src, GLfloat *dst)
1741 {
1742 unpack_float_z_func unpack;
1743
1744 switch (format) {
1745 case MESA_FORMAT_Z24_X8:
1746 unpack = unpack_float_z_Z24_X8;
1747 break;
1748 case MESA_FORMAT_X8_Z24:
1749 unpack = unpack_float_z_X8_Z24;
1750 break;
1751 case MESA_FORMAT_Z16:
1752 unpack = unpack_float_z_Z16;
1753 break;
1754 case MESA_FORMAT_Z32:
1755 unpack = unpack_float_z_Z32;
1756 break;
1757 default:
1758 _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
1759 _mesa_get_format_name(format));
1760 return;
1761 }
1762
1763 unpack(n, src, dst);
1764 }
1765
1766
1767
1768 typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
1769
1770 static void
1771 unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
1772 {
1773 /* only return Z, not stencil data */
1774 const GLuint *s = ((const GLuint *) src);
1775 GLuint i;
1776 for (i = 0; i < n; i++) {
1777 dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
1778 }
1779 }
1780
1781 static void
1782 unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
1783 {
1784 /* only return Z, not stencil data */
1785 const GLuint *s = ((const GLuint *) src);
1786 GLuint i;
1787 for (i = 0; i < n; i++) {
1788 dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
1789 }
1790 }
1791
1792 static void
1793 unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n)
1794 {
1795 const GLushort *s = ((const GLushort *)src);
1796 GLuint i;
1797 for (i = 0; i < n; i++) {
1798 dst[i] = (s[i] << 16) | s[i];
1799 }
1800 }
1801
1802 static void
1803 unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
1804 {
1805 memcpy(dst, src, n * sizeof(GLuint));
1806 }
1807
1808
1809 /**
1810 * Unpack Z values.
1811 * The returned values will always be in the range [0, 0xffffffff].
1812 */
1813 void
1814 _mesa_unpack_uint_z_row(gl_format format, GLuint n,
1815 const void *src, GLuint *dst)
1816 {
1817 unpack_uint_z_func unpack;
1818 const GLubyte *srcPtr = (GLubyte *) src;
1819
1820 switch (format) {
1821 case MESA_FORMAT_Z24_X8:
1822 unpack = unpack_uint_z_Z24_X8;
1823 break;
1824 case MESA_FORMAT_X8_Z24:
1825 unpack = unpack_uint_z_X8_Z24;
1826 break;
1827 case MESA_FORMAT_Z16:
1828 unpack = unpack_uint_z_Z16;
1829 break;
1830 case MESA_FORMAT_Z32:
1831 unpack = unpack_uint_z_Z32;
1832 break;
1833 default:
1834 _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
1835 _mesa_get_format_name(format));
1836 return;
1837 }
1838
1839 unpack(srcPtr, dst, n);
1840 }
1841
1842
1843 static void
1844 unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
1845 {
1846 memcpy(dst, src, n);
1847 }
1848
1849 void
1850 _mesa_unpack_ubyte_stencil_row(gl_format format, GLuint n,
1851 const void *src, GLubyte *dst)
1852 {
1853 switch (format) {
1854 case MESA_FORMAT_S8:
1855 unpack_ubyte_s_S8(src, dst, n);
1856 break;
1857 default:
1858 _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
1859 _mesa_get_format_name(format));
1860 return;
1861 }
1862 }