1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (c) 2011 VMware, Inc.
5 * Copyright (c) 2014 Intel Corporation.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /**
28 * Color, depth, stencil packing functions.
29 * Used to pack basic color, depth and stencil formats to specific
30 * hardware formats.
31 *
32 * There are both per-pixel and per-row packing functions:
33 * - The former will be used by swrast to write values to the color, depth,
34 * stencil buffers when drawing points, lines and masked spans.
35 * - The later will be used for image-oriented functions like glDrawPixels,
36 * glAccum, and glTexImage.
37 */
38
39 #include <stdint.h>
40
41 #include "format_unpack.h"
42 #include "format_utils.h"
43 #include "macros.h"
44 #include "util/format_rgb9e5.h"
45 #include "util/format_r11g11b10f.h"
46 #include "util/format_srgb.h"
47
48 #define UNPACK(SRC, OFFSET, BITS) (((SRC) >> (OFFSET)) & MAX_UINT(BITS))
49
50
51
52 /* float unpacking functions */
53
54
55 static inline void
unpack_float_a8b8g8r8_unorm(const void * void_src,GLfloat dst[4])56 unpack_float_a8b8g8r8_unorm(const void *void_src, GLfloat dst[4])
57 {
58 uint32_t *src = (uint32_t *)void_src;
59 uint8_t a = UNPACK(*src, 0, 8);
60 uint8_t b = UNPACK(*src, 8, 8);
61 uint8_t g = UNPACK(*src, 16, 8);
62 uint8_t r = UNPACK(*src, 24, 8);
63
64
65
66 dst[0] = _mesa_unorm_to_float(r, 8);
67
68
69 dst[1] = _mesa_unorm_to_float(g, 8);
70
71
72 dst[2] = _mesa_unorm_to_float(b, 8);
73
74
75 dst[3] = _mesa_unorm_to_float(a, 8);
76 }
77
78 static inline void
unpack_float_x8b8g8r8_unorm(const void * void_src,GLfloat dst[4])79 unpack_float_x8b8g8r8_unorm(const void *void_src, GLfloat dst[4])
80 {
81 uint32_t *src = (uint32_t *)void_src;
82 uint8_t b = UNPACK(*src, 8, 8);
83 uint8_t g = UNPACK(*src, 16, 8);
84 uint8_t r = UNPACK(*src, 24, 8);
85
86
87
88 dst[0] = _mesa_unorm_to_float(r, 8);
89
90
91 dst[1] = _mesa_unorm_to_float(g, 8);
92
93
94 dst[2] = _mesa_unorm_to_float(b, 8);
95
96 dst[3] = 1.0f;
97 }
98
99 static inline void
unpack_float_r8g8b8a8_unorm(const void * void_src,GLfloat dst[4])100 unpack_float_r8g8b8a8_unorm(const void *void_src, GLfloat dst[4])
101 {
102 uint32_t *src = (uint32_t *)void_src;
103 uint8_t r = UNPACK(*src, 0, 8);
104 uint8_t g = UNPACK(*src, 8, 8);
105 uint8_t b = UNPACK(*src, 16, 8);
106 uint8_t a = UNPACK(*src, 24, 8);
107
108
109
110 dst[0] = _mesa_unorm_to_float(r, 8);
111
112
113 dst[1] = _mesa_unorm_to_float(g, 8);
114
115
116 dst[2] = _mesa_unorm_to_float(b, 8);
117
118
119 dst[3] = _mesa_unorm_to_float(a, 8);
120 }
121
122 static inline void
unpack_float_r8g8b8x8_unorm(const void * void_src,GLfloat dst[4])123 unpack_float_r8g8b8x8_unorm(const void *void_src, GLfloat dst[4])
124 {
125 uint32_t *src = (uint32_t *)void_src;
126 uint8_t r = UNPACK(*src, 0, 8);
127 uint8_t g = UNPACK(*src, 8, 8);
128 uint8_t b = UNPACK(*src, 16, 8);
129
130
131
132 dst[0] = _mesa_unorm_to_float(r, 8);
133
134
135 dst[1] = _mesa_unorm_to_float(g, 8);
136
137
138 dst[2] = _mesa_unorm_to_float(b, 8);
139
140 dst[3] = 1.0f;
141 }
142
143 static inline void
unpack_float_b8g8r8a8_unorm(const void * void_src,GLfloat dst[4])144 unpack_float_b8g8r8a8_unorm(const void *void_src, GLfloat dst[4])
145 {
146 uint32_t *src = (uint32_t *)void_src;
147 uint8_t b = UNPACK(*src, 0, 8);
148 uint8_t g = UNPACK(*src, 8, 8);
149 uint8_t r = UNPACK(*src, 16, 8);
150 uint8_t a = UNPACK(*src, 24, 8);
151
152
153
154 dst[0] = _mesa_unorm_to_float(r, 8);
155
156
157 dst[1] = _mesa_unorm_to_float(g, 8);
158
159
160 dst[2] = _mesa_unorm_to_float(b, 8);
161
162
163 dst[3] = _mesa_unorm_to_float(a, 8);
164 }
165
166 static inline void
unpack_float_b8g8r8x8_unorm(const void * void_src,GLfloat dst[4])167 unpack_float_b8g8r8x8_unorm(const void *void_src, GLfloat dst[4])
168 {
169 uint32_t *src = (uint32_t *)void_src;
170 uint8_t b = UNPACK(*src, 0, 8);
171 uint8_t g = UNPACK(*src, 8, 8);
172 uint8_t r = UNPACK(*src, 16, 8);
173
174
175
176 dst[0] = _mesa_unorm_to_float(r, 8);
177
178
179 dst[1] = _mesa_unorm_to_float(g, 8);
180
181
182 dst[2] = _mesa_unorm_to_float(b, 8);
183
184 dst[3] = 1.0f;
185 }
186
187 static inline void
unpack_float_a8r8g8b8_unorm(const void * void_src,GLfloat dst[4])188 unpack_float_a8r8g8b8_unorm(const void *void_src, GLfloat dst[4])
189 {
190 uint32_t *src = (uint32_t *)void_src;
191 uint8_t a = UNPACK(*src, 0, 8);
192 uint8_t r = UNPACK(*src, 8, 8);
193 uint8_t g = UNPACK(*src, 16, 8);
194 uint8_t b = UNPACK(*src, 24, 8);
195
196
197
198 dst[0] = _mesa_unorm_to_float(r, 8);
199
200
201 dst[1] = _mesa_unorm_to_float(g, 8);
202
203
204 dst[2] = _mesa_unorm_to_float(b, 8);
205
206
207 dst[3] = _mesa_unorm_to_float(a, 8);
208 }
209
210 static inline void
unpack_float_x8r8g8b8_unorm(const void * void_src,GLfloat dst[4])211 unpack_float_x8r8g8b8_unorm(const void *void_src, GLfloat dst[4])
212 {
213 uint32_t *src = (uint32_t *)void_src;
214 uint8_t r = UNPACK(*src, 8, 8);
215 uint8_t g = UNPACK(*src, 16, 8);
216 uint8_t b = UNPACK(*src, 24, 8);
217
218
219
220 dst[0] = _mesa_unorm_to_float(r, 8);
221
222
223 dst[1] = _mesa_unorm_to_float(g, 8);
224
225
226 dst[2] = _mesa_unorm_to_float(b, 8);
227
228 dst[3] = 1.0f;
229 }
230
231 static inline void
unpack_float_l16a16_unorm(const void * void_src,GLfloat dst[4])232 unpack_float_l16a16_unorm(const void *void_src, GLfloat dst[4])
233 {
234 uint32_t *src = (uint32_t *)void_src;
235 uint16_t l = UNPACK(*src, 0, 16);
236 uint16_t a = UNPACK(*src, 16, 16);
237
238
239
240 dst[0] = _mesa_unorm_to_float(l, 16);
241
242
243 dst[1] = _mesa_unorm_to_float(l, 16);
244
245
246 dst[2] = _mesa_unorm_to_float(l, 16);
247
248
249 dst[3] = _mesa_unorm_to_float(a, 16);
250 }
251
252 static inline void
unpack_float_a16l16_unorm(const void * void_src,GLfloat dst[4])253 unpack_float_a16l16_unorm(const void *void_src, GLfloat dst[4])
254 {
255 uint32_t *src = (uint32_t *)void_src;
256 uint16_t a = UNPACK(*src, 0, 16);
257 uint16_t l = UNPACK(*src, 16, 16);
258
259
260
261 dst[0] = _mesa_unorm_to_float(l, 16);
262
263
264 dst[1] = _mesa_unorm_to_float(l, 16);
265
266
267 dst[2] = _mesa_unorm_to_float(l, 16);
268
269
270 dst[3] = _mesa_unorm_to_float(a, 16);
271 }
272
273 static inline void
unpack_float_b5g6r5_unorm(const void * void_src,GLfloat dst[4])274 unpack_float_b5g6r5_unorm(const void *void_src, GLfloat dst[4])
275 {
276 uint16_t *src = (uint16_t *)void_src;
277 uint8_t b = UNPACK(*src, 0, 5);
278 uint8_t g = UNPACK(*src, 5, 6);
279 uint8_t r = UNPACK(*src, 11, 5);
280
281
282
283 dst[0] = _mesa_unorm_to_float(r, 5);
284
285
286 dst[1] = _mesa_unorm_to_float(g, 6);
287
288
289 dst[2] = _mesa_unorm_to_float(b, 5);
290
291 dst[3] = 1.0f;
292 }
293
294 static inline void
unpack_float_r5g6b5_unorm(const void * void_src,GLfloat dst[4])295 unpack_float_r5g6b5_unorm(const void *void_src, GLfloat dst[4])
296 {
297 uint16_t *src = (uint16_t *)void_src;
298 uint8_t r = UNPACK(*src, 0, 5);
299 uint8_t g = UNPACK(*src, 5, 6);
300 uint8_t b = UNPACK(*src, 11, 5);
301
302
303
304 dst[0] = _mesa_unorm_to_float(r, 5);
305
306
307 dst[1] = _mesa_unorm_to_float(g, 6);
308
309
310 dst[2] = _mesa_unorm_to_float(b, 5);
311
312 dst[3] = 1.0f;
313 }
314
315 static inline void
unpack_float_b4g4r4a4_unorm(const void * void_src,GLfloat dst[4])316 unpack_float_b4g4r4a4_unorm(const void *void_src, GLfloat dst[4])
317 {
318 uint16_t *src = (uint16_t *)void_src;
319 uint8_t b = UNPACK(*src, 0, 4);
320 uint8_t g = UNPACK(*src, 4, 4);
321 uint8_t r = UNPACK(*src, 8, 4);
322 uint8_t a = UNPACK(*src, 12, 4);
323
324
325
326 dst[0] = _mesa_unorm_to_float(r, 4);
327
328
329 dst[1] = _mesa_unorm_to_float(g, 4);
330
331
332 dst[2] = _mesa_unorm_to_float(b, 4);
333
334
335 dst[3] = _mesa_unorm_to_float(a, 4);
336 }
337
338 static inline void
unpack_float_b4g4r4x4_unorm(const void * void_src,GLfloat dst[4])339 unpack_float_b4g4r4x4_unorm(const void *void_src, GLfloat dst[4])
340 {
341 uint16_t *src = (uint16_t *)void_src;
342 uint8_t b = UNPACK(*src, 0, 4);
343 uint8_t g = UNPACK(*src, 4, 4);
344 uint8_t r = UNPACK(*src, 8, 4);
345
346
347
348 dst[0] = _mesa_unorm_to_float(r, 4);
349
350
351 dst[1] = _mesa_unorm_to_float(g, 4);
352
353
354 dst[2] = _mesa_unorm_to_float(b, 4);
355
356 dst[3] = 1.0f;
357 }
358
359 static inline void
unpack_float_a4r4g4b4_unorm(const void * void_src,GLfloat dst[4])360 unpack_float_a4r4g4b4_unorm(const void *void_src, GLfloat dst[4])
361 {
362 uint16_t *src = (uint16_t *)void_src;
363 uint8_t a = UNPACK(*src, 0, 4);
364 uint8_t r = UNPACK(*src, 4, 4);
365 uint8_t g = UNPACK(*src, 8, 4);
366 uint8_t b = UNPACK(*src, 12, 4);
367
368
369
370 dst[0] = _mesa_unorm_to_float(r, 4);
371
372
373 dst[1] = _mesa_unorm_to_float(g, 4);
374
375
376 dst[2] = _mesa_unorm_to_float(b, 4);
377
378
379 dst[3] = _mesa_unorm_to_float(a, 4);
380 }
381
382 static inline void
unpack_float_a1b5g5r5_unorm(const void * void_src,GLfloat dst[4])383 unpack_float_a1b5g5r5_unorm(const void *void_src, GLfloat dst[4])
384 {
385 uint16_t *src = (uint16_t *)void_src;
386 uint8_t a = UNPACK(*src, 0, 1);
387 uint8_t b = UNPACK(*src, 1, 5);
388 uint8_t g = UNPACK(*src, 6, 5);
389 uint8_t r = UNPACK(*src, 11, 5);
390
391
392
393 dst[0] = _mesa_unorm_to_float(r, 5);
394
395
396 dst[1] = _mesa_unorm_to_float(g, 5);
397
398
399 dst[2] = _mesa_unorm_to_float(b, 5);
400
401
402 dst[3] = _mesa_unorm_to_float(a, 1);
403 }
404
405 static inline void
unpack_float_x1b5g5r5_unorm(const void * void_src,GLfloat dst[4])406 unpack_float_x1b5g5r5_unorm(const void *void_src, GLfloat dst[4])
407 {
408 uint16_t *src = (uint16_t *)void_src;
409 uint8_t b = UNPACK(*src, 1, 5);
410 uint8_t g = UNPACK(*src, 6, 5);
411 uint8_t r = UNPACK(*src, 11, 5);
412
413
414
415 dst[0] = _mesa_unorm_to_float(r, 5);
416
417
418 dst[1] = _mesa_unorm_to_float(g, 5);
419
420
421 dst[2] = _mesa_unorm_to_float(b, 5);
422
423 dst[3] = 1.0f;
424 }
425
426 static inline void
unpack_float_b5g5r5a1_unorm(const void * void_src,GLfloat dst[4])427 unpack_float_b5g5r5a1_unorm(const void *void_src, GLfloat dst[4])
428 {
429 uint16_t *src = (uint16_t *)void_src;
430 uint8_t b = UNPACK(*src, 0, 5);
431 uint8_t g = UNPACK(*src, 5, 5);
432 uint8_t r = UNPACK(*src, 10, 5);
433 uint8_t a = UNPACK(*src, 15, 1);
434
435
436
437 dst[0] = _mesa_unorm_to_float(r, 5);
438
439
440 dst[1] = _mesa_unorm_to_float(g, 5);
441
442
443 dst[2] = _mesa_unorm_to_float(b, 5);
444
445
446 dst[3] = _mesa_unorm_to_float(a, 1);
447 }
448
449 static inline void
unpack_float_b5g5r5x1_unorm(const void * void_src,GLfloat dst[4])450 unpack_float_b5g5r5x1_unorm(const void *void_src, GLfloat dst[4])
451 {
452 uint16_t *src = (uint16_t *)void_src;
453 uint8_t b = UNPACK(*src, 0, 5);
454 uint8_t g = UNPACK(*src, 5, 5);
455 uint8_t r = UNPACK(*src, 10, 5);
456
457
458
459 dst[0] = _mesa_unorm_to_float(r, 5);
460
461
462 dst[1] = _mesa_unorm_to_float(g, 5);
463
464
465 dst[2] = _mesa_unorm_to_float(b, 5);
466
467 dst[3] = 1.0f;
468 }
469
470 static inline void
unpack_float_a1r5g5b5_unorm(const void * void_src,GLfloat dst[4])471 unpack_float_a1r5g5b5_unorm(const void *void_src, GLfloat dst[4])
472 {
473 uint16_t *src = (uint16_t *)void_src;
474 uint8_t a = UNPACK(*src, 0, 1);
475 uint8_t r = UNPACK(*src, 1, 5);
476 uint8_t g = UNPACK(*src, 6, 5);
477 uint8_t b = UNPACK(*src, 11, 5);
478
479
480
481 dst[0] = _mesa_unorm_to_float(r, 5);
482
483
484 dst[1] = _mesa_unorm_to_float(g, 5);
485
486
487 dst[2] = _mesa_unorm_to_float(b, 5);
488
489
490 dst[3] = _mesa_unorm_to_float(a, 1);
491 }
492
493 static inline void
unpack_float_l8a8_unorm(const void * void_src,GLfloat dst[4])494 unpack_float_l8a8_unorm(const void *void_src, GLfloat dst[4])
495 {
496 uint16_t *src = (uint16_t *)void_src;
497 uint8_t l = UNPACK(*src, 0, 8);
498 uint8_t a = UNPACK(*src, 8, 8);
499
500
501
502 dst[0] = _mesa_unorm_to_float(l, 8);
503
504
505 dst[1] = _mesa_unorm_to_float(l, 8);
506
507
508 dst[2] = _mesa_unorm_to_float(l, 8);
509
510
511 dst[3] = _mesa_unorm_to_float(a, 8);
512 }
513
514 static inline void
unpack_float_a8l8_unorm(const void * void_src,GLfloat dst[4])515 unpack_float_a8l8_unorm(const void *void_src, GLfloat dst[4])
516 {
517 uint16_t *src = (uint16_t *)void_src;
518 uint8_t a = UNPACK(*src, 0, 8);
519 uint8_t l = UNPACK(*src, 8, 8);
520
521
522
523 dst[0] = _mesa_unorm_to_float(l, 8);
524
525
526 dst[1] = _mesa_unorm_to_float(l, 8);
527
528
529 dst[2] = _mesa_unorm_to_float(l, 8);
530
531
532 dst[3] = _mesa_unorm_to_float(a, 8);
533 }
534
535 static inline void
unpack_float_r8g8_unorm(const void * void_src,GLfloat dst[4])536 unpack_float_r8g8_unorm(const void *void_src, GLfloat dst[4])
537 {
538 uint16_t *src = (uint16_t *)void_src;
539 uint8_t r = UNPACK(*src, 0, 8);
540 uint8_t g = UNPACK(*src, 8, 8);
541
542
543
544 dst[0] = _mesa_unorm_to_float(r, 8);
545
546
547 dst[1] = _mesa_unorm_to_float(g, 8);
548
549 dst[2] = 0.0f;
550
551 dst[3] = 1.0f;
552 }
553
554 static inline void
unpack_float_g8r8_unorm(const void * void_src,GLfloat dst[4])555 unpack_float_g8r8_unorm(const void *void_src, GLfloat dst[4])
556 {
557 uint16_t *src = (uint16_t *)void_src;
558 uint8_t g = UNPACK(*src, 0, 8);
559 uint8_t r = UNPACK(*src, 8, 8);
560
561
562
563 dst[0] = _mesa_unorm_to_float(r, 8);
564
565
566 dst[1] = _mesa_unorm_to_float(g, 8);
567
568 dst[2] = 0.0f;
569
570 dst[3] = 1.0f;
571 }
572
573 static inline void
unpack_float_l4a4_unorm(const void * void_src,GLfloat dst[4])574 unpack_float_l4a4_unorm(const void *void_src, GLfloat dst[4])
575 {
576 uint8_t *src = (uint8_t *)void_src;
577 uint8_t l = UNPACK(*src, 0, 4);
578 uint8_t a = UNPACK(*src, 4, 4);
579
580
581
582 dst[0] = _mesa_unorm_to_float(l, 4);
583
584
585 dst[1] = _mesa_unorm_to_float(l, 4);
586
587
588 dst[2] = _mesa_unorm_to_float(l, 4);
589
590
591 dst[3] = _mesa_unorm_to_float(a, 4);
592 }
593
594 static inline void
unpack_float_b2g3r3_unorm(const void * void_src,GLfloat dst[4])595 unpack_float_b2g3r3_unorm(const void *void_src, GLfloat dst[4])
596 {
597 uint8_t *src = (uint8_t *)void_src;
598 uint8_t b = UNPACK(*src, 0, 2);
599 uint8_t g = UNPACK(*src, 2, 3);
600 uint8_t r = UNPACK(*src, 5, 3);
601
602
603
604 dst[0] = _mesa_unorm_to_float(r, 3);
605
606
607 dst[1] = _mesa_unorm_to_float(g, 3);
608
609
610 dst[2] = _mesa_unorm_to_float(b, 2);
611
612 dst[3] = 1.0f;
613 }
614
615 static inline void
unpack_float_r16g16_unorm(const void * void_src,GLfloat dst[4])616 unpack_float_r16g16_unorm(const void *void_src, GLfloat dst[4])
617 {
618 uint32_t *src = (uint32_t *)void_src;
619 uint16_t r = UNPACK(*src, 0, 16);
620 uint16_t g = UNPACK(*src, 16, 16);
621
622
623
624 dst[0] = _mesa_unorm_to_float(r, 16);
625
626
627 dst[1] = _mesa_unorm_to_float(g, 16);
628
629 dst[2] = 0.0f;
630
631 dst[3] = 1.0f;
632 }
633
634 static inline void
unpack_float_g16r16_unorm(const void * void_src,GLfloat dst[4])635 unpack_float_g16r16_unorm(const void *void_src, GLfloat dst[4])
636 {
637 uint32_t *src = (uint32_t *)void_src;
638 uint16_t g = UNPACK(*src, 0, 16);
639 uint16_t r = UNPACK(*src, 16, 16);
640
641
642
643 dst[0] = _mesa_unorm_to_float(r, 16);
644
645
646 dst[1] = _mesa_unorm_to_float(g, 16);
647
648 dst[2] = 0.0f;
649
650 dst[3] = 1.0f;
651 }
652
653 static inline void
unpack_float_b10g10r10a2_unorm(const void * void_src,GLfloat dst[4])654 unpack_float_b10g10r10a2_unorm(const void *void_src, GLfloat dst[4])
655 {
656 uint32_t *src = (uint32_t *)void_src;
657 uint16_t b = UNPACK(*src, 0, 10);
658 uint16_t g = UNPACK(*src, 10, 10);
659 uint16_t r = UNPACK(*src, 20, 10);
660 uint8_t a = UNPACK(*src, 30, 2);
661
662
663
664 dst[0] = _mesa_unorm_to_float(r, 10);
665
666
667 dst[1] = _mesa_unorm_to_float(g, 10);
668
669
670 dst[2] = _mesa_unorm_to_float(b, 10);
671
672
673 dst[3] = _mesa_unorm_to_float(a, 2);
674 }
675
676 static inline void
unpack_float_b10g10r10x2_unorm(const void * void_src,GLfloat dst[4])677 unpack_float_b10g10r10x2_unorm(const void *void_src, GLfloat dst[4])
678 {
679 uint32_t *src = (uint32_t *)void_src;
680 uint16_t b = UNPACK(*src, 0, 10);
681 uint16_t g = UNPACK(*src, 10, 10);
682 uint16_t r = UNPACK(*src, 20, 10);
683
684
685
686 dst[0] = _mesa_unorm_to_float(r, 10);
687
688
689 dst[1] = _mesa_unorm_to_float(g, 10);
690
691
692 dst[2] = _mesa_unorm_to_float(b, 10);
693
694 dst[3] = 1.0f;
695 }
696
697 static inline void
unpack_float_r10g10b10a2_unorm(const void * void_src,GLfloat dst[4])698 unpack_float_r10g10b10a2_unorm(const void *void_src, GLfloat dst[4])
699 {
700 uint32_t *src = (uint32_t *)void_src;
701 uint16_t r = UNPACK(*src, 0, 10);
702 uint16_t g = UNPACK(*src, 10, 10);
703 uint16_t b = UNPACK(*src, 20, 10);
704 uint8_t a = UNPACK(*src, 30, 2);
705
706
707
708 dst[0] = _mesa_unorm_to_float(r, 10);
709
710
711 dst[1] = _mesa_unorm_to_float(g, 10);
712
713
714 dst[2] = _mesa_unorm_to_float(b, 10);
715
716
717 dst[3] = _mesa_unorm_to_float(a, 2);
718 }
719
720 static inline void
unpack_float_r10g10b10x2_unorm(const void * void_src,GLfloat dst[4])721 unpack_float_r10g10b10x2_unorm(const void *void_src, GLfloat dst[4])
722 {
723 uint32_t *src = (uint32_t *)void_src;
724 uint16_t r = UNPACK(*src, 0, 10);
725 uint16_t g = UNPACK(*src, 10, 10);
726 uint16_t b = UNPACK(*src, 20, 10);
727
728
729
730 dst[0] = _mesa_unorm_to_float(r, 10);
731
732
733 dst[1] = _mesa_unorm_to_float(g, 10);
734
735
736 dst[2] = _mesa_unorm_to_float(b, 10);
737
738 dst[3] = 1.0f;
739 }
740
741 static inline void
unpack_float_r3g3b2_unorm(const void * void_src,GLfloat dst[4])742 unpack_float_r3g3b2_unorm(const void *void_src, GLfloat dst[4])
743 {
744 uint8_t *src = (uint8_t *)void_src;
745 uint8_t r = UNPACK(*src, 0, 3);
746 uint8_t g = UNPACK(*src, 3, 3);
747 uint8_t b = UNPACK(*src, 6, 2);
748
749
750
751 dst[0] = _mesa_unorm_to_float(r, 3);
752
753
754 dst[1] = _mesa_unorm_to_float(g, 3);
755
756
757 dst[2] = _mesa_unorm_to_float(b, 2);
758
759 dst[3] = 1.0f;
760 }
761
762 static inline void
unpack_float_a4b4g4r4_unorm(const void * void_src,GLfloat dst[4])763 unpack_float_a4b4g4r4_unorm(const void *void_src, GLfloat dst[4])
764 {
765 uint16_t *src = (uint16_t *)void_src;
766 uint8_t a = UNPACK(*src, 0, 4);
767 uint8_t b = UNPACK(*src, 4, 4);
768 uint8_t g = UNPACK(*src, 8, 4);
769 uint8_t r = UNPACK(*src, 12, 4);
770
771
772
773 dst[0] = _mesa_unorm_to_float(r, 4);
774
775
776 dst[1] = _mesa_unorm_to_float(g, 4);
777
778
779 dst[2] = _mesa_unorm_to_float(b, 4);
780
781
782 dst[3] = _mesa_unorm_to_float(a, 4);
783 }
784
785 static inline void
unpack_float_r4g4b4a4_unorm(const void * void_src,GLfloat dst[4])786 unpack_float_r4g4b4a4_unorm(const void *void_src, GLfloat dst[4])
787 {
788 uint16_t *src = (uint16_t *)void_src;
789 uint8_t r = UNPACK(*src, 0, 4);
790 uint8_t g = UNPACK(*src, 4, 4);
791 uint8_t b = UNPACK(*src, 8, 4);
792 uint8_t a = UNPACK(*src, 12, 4);
793
794
795
796 dst[0] = _mesa_unorm_to_float(r, 4);
797
798
799 dst[1] = _mesa_unorm_to_float(g, 4);
800
801
802 dst[2] = _mesa_unorm_to_float(b, 4);
803
804
805 dst[3] = _mesa_unorm_to_float(a, 4);
806 }
807
808 static inline void
unpack_float_r5g5b5a1_unorm(const void * void_src,GLfloat dst[4])809 unpack_float_r5g5b5a1_unorm(const void *void_src, GLfloat dst[4])
810 {
811 uint16_t *src = (uint16_t *)void_src;
812 uint8_t r = UNPACK(*src, 0, 5);
813 uint8_t g = UNPACK(*src, 5, 5);
814 uint8_t b = UNPACK(*src, 10, 5);
815 uint8_t a = UNPACK(*src, 15, 1);
816
817
818
819 dst[0] = _mesa_unorm_to_float(r, 5);
820
821
822 dst[1] = _mesa_unorm_to_float(g, 5);
823
824
825 dst[2] = _mesa_unorm_to_float(b, 5);
826
827
828 dst[3] = _mesa_unorm_to_float(a, 1);
829 }
830
831 static inline void
unpack_float_a2b10g10r10_unorm(const void * void_src,GLfloat dst[4])832 unpack_float_a2b10g10r10_unorm(const void *void_src, GLfloat dst[4])
833 {
834 uint32_t *src = (uint32_t *)void_src;
835 uint8_t a = UNPACK(*src, 0, 2);
836 uint16_t b = UNPACK(*src, 2, 10);
837 uint16_t g = UNPACK(*src, 12, 10);
838 uint16_t r = UNPACK(*src, 22, 10);
839
840
841
842 dst[0] = _mesa_unorm_to_float(r, 10);
843
844
845 dst[1] = _mesa_unorm_to_float(g, 10);
846
847
848 dst[2] = _mesa_unorm_to_float(b, 10);
849
850
851 dst[3] = _mesa_unorm_to_float(a, 2);
852 }
853
854 static inline void
unpack_float_a2r10g10b10_unorm(const void * void_src,GLfloat dst[4])855 unpack_float_a2r10g10b10_unorm(const void *void_src, GLfloat dst[4])
856 {
857 uint32_t *src = (uint32_t *)void_src;
858 uint8_t a = UNPACK(*src, 0, 2);
859 uint16_t r = UNPACK(*src, 2, 10);
860 uint16_t g = UNPACK(*src, 12, 10);
861 uint16_t b = UNPACK(*src, 22, 10);
862
863
864
865 dst[0] = _mesa_unorm_to_float(r, 10);
866
867
868 dst[1] = _mesa_unorm_to_float(g, 10);
869
870
871 dst[2] = _mesa_unorm_to_float(b, 10);
872
873
874 dst[3] = _mesa_unorm_to_float(a, 2);
875 }
876
877 static inline void
unpack_float_a_unorm8(const void * void_src,GLfloat dst[4])878 unpack_float_a_unorm8(const void *void_src, GLfloat dst[4])
879 {
880 uint8_t *src = (uint8_t *)void_src;
881 uint8_t a = src[0];
882
883
884 dst[0] = 0.0f;
885
886 dst[1] = 0.0f;
887
888 dst[2] = 0.0f;
889
890
891 dst[3] = _mesa_unorm_to_float(a, 8);
892 }
893
894 static inline void
unpack_float_a_unorm16(const void * void_src,GLfloat dst[4])895 unpack_float_a_unorm16(const void *void_src, GLfloat dst[4])
896 {
897 uint16_t *src = (uint16_t *)void_src;
898 uint16_t a = src[0];
899
900
901 dst[0] = 0.0f;
902
903 dst[1] = 0.0f;
904
905 dst[2] = 0.0f;
906
907
908 dst[3] = _mesa_unorm_to_float(a, 16);
909 }
910
911 static inline void
unpack_float_l_unorm8(const void * void_src,GLfloat dst[4])912 unpack_float_l_unorm8(const void *void_src, GLfloat dst[4])
913 {
914 uint8_t *src = (uint8_t *)void_src;
915 uint8_t l = src[0];
916
917
918
919 dst[0] = _mesa_unorm_to_float(l, 8);
920
921
922 dst[1] = _mesa_unorm_to_float(l, 8);
923
924
925 dst[2] = _mesa_unorm_to_float(l, 8);
926
927 dst[3] = 1.0f;
928 }
929
930 static inline void
unpack_float_l_unorm16(const void * void_src,GLfloat dst[4])931 unpack_float_l_unorm16(const void *void_src, GLfloat dst[4])
932 {
933 uint16_t *src = (uint16_t *)void_src;
934 uint16_t l = src[0];
935
936
937
938 dst[0] = _mesa_unorm_to_float(l, 16);
939
940
941 dst[1] = _mesa_unorm_to_float(l, 16);
942
943
944 dst[2] = _mesa_unorm_to_float(l, 16);
945
946 dst[3] = 1.0f;
947 }
948
949 static inline void
unpack_float_i_unorm8(const void * void_src,GLfloat dst[4])950 unpack_float_i_unorm8(const void *void_src, GLfloat dst[4])
951 {
952 uint8_t *src = (uint8_t *)void_src;
953 uint8_t i = src[0];
954
955
956
957 dst[0] = _mesa_unorm_to_float(i, 8);
958
959
960 dst[1] = _mesa_unorm_to_float(i, 8);
961
962
963 dst[2] = _mesa_unorm_to_float(i, 8);
964
965
966 dst[3] = _mesa_unorm_to_float(i, 8);
967 }
968
969 static inline void
unpack_float_i_unorm16(const void * void_src,GLfloat dst[4])970 unpack_float_i_unorm16(const void *void_src, GLfloat dst[4])
971 {
972 uint16_t *src = (uint16_t *)void_src;
973 uint16_t i = src[0];
974
975
976
977 dst[0] = _mesa_unorm_to_float(i, 16);
978
979
980 dst[1] = _mesa_unorm_to_float(i, 16);
981
982
983 dst[2] = _mesa_unorm_to_float(i, 16);
984
985
986 dst[3] = _mesa_unorm_to_float(i, 16);
987 }
988
989 static inline void
unpack_float_r_unorm8(const void * void_src,GLfloat dst[4])990 unpack_float_r_unorm8(const void *void_src, GLfloat dst[4])
991 {
992 uint8_t *src = (uint8_t *)void_src;
993 uint8_t r = src[0];
994
995
996
997 dst[0] = _mesa_unorm_to_float(r, 8);
998
999 dst[1] = 0.0f;
1000
1001 dst[2] = 0.0f;
1002
1003 dst[3] = 1.0f;
1004 }
1005
1006 static inline void
unpack_float_r_unorm16(const void * void_src,GLfloat dst[4])1007 unpack_float_r_unorm16(const void *void_src, GLfloat dst[4])
1008 {
1009 uint16_t *src = (uint16_t *)void_src;
1010 uint16_t r = src[0];
1011
1012
1013
1014 dst[0] = _mesa_unorm_to_float(r, 16);
1015
1016 dst[1] = 0.0f;
1017
1018 dst[2] = 0.0f;
1019
1020 dst[3] = 1.0f;
1021 }
1022
1023 static inline void
unpack_float_bgr_unorm8(const void * void_src,GLfloat dst[4])1024 unpack_float_bgr_unorm8(const void *void_src, GLfloat dst[4])
1025 {
1026 uint8_t *src = (uint8_t *)void_src;
1027 uint8_t b = src[0];
1028 uint8_t g = src[1];
1029 uint8_t r = src[2];
1030
1031
1032
1033 dst[0] = _mesa_unorm_to_float(r, 8);
1034
1035
1036 dst[1] = _mesa_unorm_to_float(g, 8);
1037
1038
1039 dst[2] = _mesa_unorm_to_float(b, 8);
1040
1041 dst[3] = 1.0f;
1042 }
1043
1044 static inline void
unpack_float_rgb_unorm8(const void * void_src,GLfloat dst[4])1045 unpack_float_rgb_unorm8(const void *void_src, GLfloat dst[4])
1046 {
1047 uint8_t *src = (uint8_t *)void_src;
1048 uint8_t r = src[0];
1049 uint8_t g = src[1];
1050 uint8_t b = src[2];
1051
1052
1053
1054 dst[0] = _mesa_unorm_to_float(r, 8);
1055
1056
1057 dst[1] = _mesa_unorm_to_float(g, 8);
1058
1059
1060 dst[2] = _mesa_unorm_to_float(b, 8);
1061
1062 dst[3] = 1.0f;
1063 }
1064
1065 static inline void
unpack_float_rgba_unorm16(const void * void_src,GLfloat dst[4])1066 unpack_float_rgba_unorm16(const void *void_src, GLfloat dst[4])
1067 {
1068 uint16_t *src = (uint16_t *)void_src;
1069 uint16_t r = src[0];
1070 uint16_t g = src[1];
1071 uint16_t b = src[2];
1072 uint16_t a = src[3];
1073
1074
1075
1076 dst[0] = _mesa_unorm_to_float(r, 16);
1077
1078
1079 dst[1] = _mesa_unorm_to_float(g, 16);
1080
1081
1082 dst[2] = _mesa_unorm_to_float(b, 16);
1083
1084
1085 dst[3] = _mesa_unorm_to_float(a, 16);
1086 }
1087
1088 static inline void
unpack_float_rgbx_unorm16(const void * void_src,GLfloat dst[4])1089 unpack_float_rgbx_unorm16(const void *void_src, GLfloat dst[4])
1090 {
1091 uint16_t *src = (uint16_t *)void_src;
1092 uint16_t r = src[0];
1093 uint16_t g = src[1];
1094 uint16_t b = src[2];
1095
1096
1097
1098 dst[0] = _mesa_unorm_to_float(r, 16);
1099
1100
1101 dst[1] = _mesa_unorm_to_float(g, 16);
1102
1103
1104 dst[2] = _mesa_unorm_to_float(b, 16);
1105
1106 dst[3] = 1.0f;
1107 }
1108
1109 static inline void
unpack_float_a8b8g8r8_snorm(const void * void_src,GLfloat dst[4])1110 unpack_float_a8b8g8r8_snorm(const void *void_src, GLfloat dst[4])
1111 {
1112 uint32_t *src = (uint32_t *)void_src;
1113 int8_t a = UNPACK(*src, 0, 8);
1114 int8_t b = UNPACK(*src, 8, 8);
1115 int8_t g = UNPACK(*src, 16, 8);
1116 int8_t r = UNPACK(*src, 24, 8);
1117
1118
1119
1120 dst[0] = _mesa_snorm_to_float(r, 8);
1121
1122
1123 dst[1] = _mesa_snorm_to_float(g, 8);
1124
1125
1126 dst[2] = _mesa_snorm_to_float(b, 8);
1127
1128
1129 dst[3] = _mesa_snorm_to_float(a, 8);
1130 }
1131
1132 static inline void
unpack_float_x8b8g8r8_snorm(const void * void_src,GLfloat dst[4])1133 unpack_float_x8b8g8r8_snorm(const void *void_src, GLfloat dst[4])
1134 {
1135 uint32_t *src = (uint32_t *)void_src;
1136 int8_t b = UNPACK(*src, 8, 8);
1137 int8_t g = UNPACK(*src, 16, 8);
1138 int8_t r = UNPACK(*src, 24, 8);
1139
1140
1141
1142 dst[0] = _mesa_snorm_to_float(r, 8);
1143
1144
1145 dst[1] = _mesa_snorm_to_float(g, 8);
1146
1147
1148 dst[2] = _mesa_snorm_to_float(b, 8);
1149
1150 dst[3] = 1.0f;
1151 }
1152
1153 static inline void
unpack_float_r8g8b8a8_snorm(const void * void_src,GLfloat dst[4])1154 unpack_float_r8g8b8a8_snorm(const void *void_src, GLfloat dst[4])
1155 {
1156 uint32_t *src = (uint32_t *)void_src;
1157 int8_t r = UNPACK(*src, 0, 8);
1158 int8_t g = UNPACK(*src, 8, 8);
1159 int8_t b = UNPACK(*src, 16, 8);
1160 int8_t a = UNPACK(*src, 24, 8);
1161
1162
1163
1164 dst[0] = _mesa_snorm_to_float(r, 8);
1165
1166
1167 dst[1] = _mesa_snorm_to_float(g, 8);
1168
1169
1170 dst[2] = _mesa_snorm_to_float(b, 8);
1171
1172
1173 dst[3] = _mesa_snorm_to_float(a, 8);
1174 }
1175
1176 static inline void
unpack_float_r8g8b8x8_snorm(const void * void_src,GLfloat dst[4])1177 unpack_float_r8g8b8x8_snorm(const void *void_src, GLfloat dst[4])
1178 {
1179 uint32_t *src = (uint32_t *)void_src;
1180 int8_t r = UNPACK(*src, 0, 8);
1181 int8_t g = UNPACK(*src, 8, 8);
1182 int8_t b = UNPACK(*src, 16, 8);
1183
1184
1185
1186 dst[0] = _mesa_snorm_to_float(r, 8);
1187
1188
1189 dst[1] = _mesa_snorm_to_float(g, 8);
1190
1191
1192 dst[2] = _mesa_snorm_to_float(b, 8);
1193
1194 dst[3] = 1.0f;
1195 }
1196
1197 static inline void
unpack_float_r16g16_snorm(const void * void_src,GLfloat dst[4])1198 unpack_float_r16g16_snorm(const void *void_src, GLfloat dst[4])
1199 {
1200 uint32_t *src = (uint32_t *)void_src;
1201 int16_t r = UNPACK(*src, 0, 16);
1202 int16_t g = UNPACK(*src, 16, 16);
1203
1204
1205
1206 dst[0] = _mesa_snorm_to_float(r, 16);
1207
1208
1209 dst[1] = _mesa_snorm_to_float(g, 16);
1210
1211 dst[2] = 0.0f;
1212
1213 dst[3] = 1.0f;
1214 }
1215
1216 static inline void
unpack_float_g16r16_snorm(const void * void_src,GLfloat dst[4])1217 unpack_float_g16r16_snorm(const void *void_src, GLfloat dst[4])
1218 {
1219 uint32_t *src = (uint32_t *)void_src;
1220 int16_t g = UNPACK(*src, 0, 16);
1221 int16_t r = UNPACK(*src, 16, 16);
1222
1223
1224
1225 dst[0] = _mesa_snorm_to_float(r, 16);
1226
1227
1228 dst[1] = _mesa_snorm_to_float(g, 16);
1229
1230 dst[2] = 0.0f;
1231
1232 dst[3] = 1.0f;
1233 }
1234
1235 static inline void
unpack_float_r8g8_snorm(const void * void_src,GLfloat dst[4])1236 unpack_float_r8g8_snorm(const void *void_src, GLfloat dst[4])
1237 {
1238 uint16_t *src = (uint16_t *)void_src;
1239 int8_t r = UNPACK(*src, 0, 8);
1240 int8_t g = UNPACK(*src, 8, 8);
1241
1242
1243
1244 dst[0] = _mesa_snorm_to_float(r, 8);
1245
1246
1247 dst[1] = _mesa_snorm_to_float(g, 8);
1248
1249 dst[2] = 0.0f;
1250
1251 dst[3] = 1.0f;
1252 }
1253
1254 static inline void
unpack_float_g8r8_snorm(const void * void_src,GLfloat dst[4])1255 unpack_float_g8r8_snorm(const void *void_src, GLfloat dst[4])
1256 {
1257 uint16_t *src = (uint16_t *)void_src;
1258 int8_t g = UNPACK(*src, 0, 8);
1259 int8_t r = UNPACK(*src, 8, 8);
1260
1261
1262
1263 dst[0] = _mesa_snorm_to_float(r, 8);
1264
1265
1266 dst[1] = _mesa_snorm_to_float(g, 8);
1267
1268 dst[2] = 0.0f;
1269
1270 dst[3] = 1.0f;
1271 }
1272
1273 static inline void
unpack_float_l8a8_snorm(const void * void_src,GLfloat dst[4])1274 unpack_float_l8a8_snorm(const void *void_src, GLfloat dst[4])
1275 {
1276 uint16_t *src = (uint16_t *)void_src;
1277 int8_t l = UNPACK(*src, 0, 8);
1278 int8_t a = UNPACK(*src, 8, 8);
1279
1280
1281
1282 dst[0] = _mesa_snorm_to_float(l, 8);
1283
1284
1285 dst[1] = _mesa_snorm_to_float(l, 8);
1286
1287
1288 dst[2] = _mesa_snorm_to_float(l, 8);
1289
1290
1291 dst[3] = _mesa_snorm_to_float(a, 8);
1292 }
1293
1294 static inline void
unpack_float_a8l8_snorm(const void * void_src,GLfloat dst[4])1295 unpack_float_a8l8_snorm(const void *void_src, GLfloat dst[4])
1296 {
1297 uint16_t *src = (uint16_t *)void_src;
1298 int8_t a = UNPACK(*src, 0, 8);
1299 int8_t l = UNPACK(*src, 8, 8);
1300
1301
1302
1303 dst[0] = _mesa_snorm_to_float(l, 8);
1304
1305
1306 dst[1] = _mesa_snorm_to_float(l, 8);
1307
1308
1309 dst[2] = _mesa_snorm_to_float(l, 8);
1310
1311
1312 dst[3] = _mesa_snorm_to_float(a, 8);
1313 }
1314
1315 static inline void
unpack_float_a_snorm8(const void * void_src,GLfloat dst[4])1316 unpack_float_a_snorm8(const void *void_src, GLfloat dst[4])
1317 {
1318 int8_t *src = (int8_t *)void_src;
1319 int8_t a = src[0];
1320
1321
1322 dst[0] = 0.0f;
1323
1324 dst[1] = 0.0f;
1325
1326 dst[2] = 0.0f;
1327
1328
1329 dst[3] = _mesa_snorm_to_float(a, 8);
1330 }
1331
1332 static inline void
unpack_float_a_snorm16(const void * void_src,GLfloat dst[4])1333 unpack_float_a_snorm16(const void *void_src, GLfloat dst[4])
1334 {
1335 int16_t *src = (int16_t *)void_src;
1336 int16_t a = src[0];
1337
1338
1339 dst[0] = 0.0f;
1340
1341 dst[1] = 0.0f;
1342
1343 dst[2] = 0.0f;
1344
1345
1346 dst[3] = _mesa_snorm_to_float(a, 16);
1347 }
1348
1349 static inline void
unpack_float_l_snorm8(const void * void_src,GLfloat dst[4])1350 unpack_float_l_snorm8(const void *void_src, GLfloat dst[4])
1351 {
1352 int8_t *src = (int8_t *)void_src;
1353 int8_t l = src[0];
1354
1355
1356
1357 dst[0] = _mesa_snorm_to_float(l, 8);
1358
1359
1360 dst[1] = _mesa_snorm_to_float(l, 8);
1361
1362
1363 dst[2] = _mesa_snorm_to_float(l, 8);
1364
1365 dst[3] = 1.0f;
1366 }
1367
1368 static inline void
unpack_float_l_snorm16(const void * void_src,GLfloat dst[4])1369 unpack_float_l_snorm16(const void *void_src, GLfloat dst[4])
1370 {
1371 int16_t *src = (int16_t *)void_src;
1372 int16_t l = src[0];
1373
1374
1375
1376 dst[0] = _mesa_snorm_to_float(l, 16);
1377
1378
1379 dst[1] = _mesa_snorm_to_float(l, 16);
1380
1381
1382 dst[2] = _mesa_snorm_to_float(l, 16);
1383
1384 dst[3] = 1.0f;
1385 }
1386
1387 static inline void
unpack_float_i_snorm8(const void * void_src,GLfloat dst[4])1388 unpack_float_i_snorm8(const void *void_src, GLfloat dst[4])
1389 {
1390 int8_t *src = (int8_t *)void_src;
1391 int8_t i = src[0];
1392
1393
1394
1395 dst[0] = _mesa_snorm_to_float(i, 8);
1396
1397
1398 dst[1] = _mesa_snorm_to_float(i, 8);
1399
1400
1401 dst[2] = _mesa_snorm_to_float(i, 8);
1402
1403
1404 dst[3] = _mesa_snorm_to_float(i, 8);
1405 }
1406
1407 static inline void
unpack_float_i_snorm16(const void * void_src,GLfloat dst[4])1408 unpack_float_i_snorm16(const void *void_src, GLfloat dst[4])
1409 {
1410 int16_t *src = (int16_t *)void_src;
1411 int16_t i = src[0];
1412
1413
1414
1415 dst[0] = _mesa_snorm_to_float(i, 16);
1416
1417
1418 dst[1] = _mesa_snorm_to_float(i, 16);
1419
1420
1421 dst[2] = _mesa_snorm_to_float(i, 16);
1422
1423
1424 dst[3] = _mesa_snorm_to_float(i, 16);
1425 }
1426
1427 static inline void
unpack_float_r_snorm8(const void * void_src,GLfloat dst[4])1428 unpack_float_r_snorm8(const void *void_src, GLfloat dst[4])
1429 {
1430 int8_t *src = (int8_t *)void_src;
1431 int8_t r = src[0];
1432
1433
1434
1435 dst[0] = _mesa_snorm_to_float(r, 8);
1436
1437 dst[1] = 0.0f;
1438
1439 dst[2] = 0.0f;
1440
1441 dst[3] = 1.0f;
1442 }
1443
1444 static inline void
unpack_float_r_snorm16(const void * void_src,GLfloat dst[4])1445 unpack_float_r_snorm16(const void *void_src, GLfloat dst[4])
1446 {
1447 int16_t *src = (int16_t *)void_src;
1448 int16_t r = src[0];
1449
1450
1451
1452 dst[0] = _mesa_snorm_to_float(r, 16);
1453
1454 dst[1] = 0.0f;
1455
1456 dst[2] = 0.0f;
1457
1458 dst[3] = 1.0f;
1459 }
1460
1461 static inline void
unpack_float_la_snorm16(const void * void_src,GLfloat dst[4])1462 unpack_float_la_snorm16(const void *void_src, GLfloat dst[4])
1463 {
1464 int16_t *src = (int16_t *)void_src;
1465 int16_t l = src[0];
1466 int16_t a = src[1];
1467
1468
1469
1470 dst[0] = _mesa_snorm_to_float(l, 16);
1471
1472
1473 dst[1] = _mesa_snorm_to_float(l, 16);
1474
1475
1476 dst[2] = _mesa_snorm_to_float(l, 16);
1477
1478
1479 dst[3] = _mesa_snorm_to_float(a, 16);
1480 }
1481
1482 static inline void
unpack_float_rgb_snorm16(const void * void_src,GLfloat dst[4])1483 unpack_float_rgb_snorm16(const void *void_src, GLfloat dst[4])
1484 {
1485 int16_t *src = (int16_t *)void_src;
1486 int16_t r = src[0];
1487 int16_t g = src[1];
1488 int16_t b = src[2];
1489
1490
1491
1492 dst[0] = _mesa_snorm_to_float(r, 16);
1493
1494
1495 dst[1] = _mesa_snorm_to_float(g, 16);
1496
1497
1498 dst[2] = _mesa_snorm_to_float(b, 16);
1499
1500 dst[3] = 1.0f;
1501 }
1502
1503 static inline void
unpack_float_rgba_snorm16(const void * void_src,GLfloat dst[4])1504 unpack_float_rgba_snorm16(const void *void_src, GLfloat dst[4])
1505 {
1506 int16_t *src = (int16_t *)void_src;
1507 int16_t r = src[0];
1508 int16_t g = src[1];
1509 int16_t b = src[2];
1510 int16_t a = src[3];
1511
1512
1513
1514 dst[0] = _mesa_snorm_to_float(r, 16);
1515
1516
1517 dst[1] = _mesa_snorm_to_float(g, 16);
1518
1519
1520 dst[2] = _mesa_snorm_to_float(b, 16);
1521
1522
1523 dst[3] = _mesa_snorm_to_float(a, 16);
1524 }
1525
1526 static inline void
unpack_float_rgbx_snorm16(const void * void_src,GLfloat dst[4])1527 unpack_float_rgbx_snorm16(const void *void_src, GLfloat dst[4])
1528 {
1529 int16_t *src = (int16_t *)void_src;
1530 int16_t r = src[0];
1531 int16_t g = src[1];
1532 int16_t b = src[2];
1533
1534
1535
1536 dst[0] = _mesa_snorm_to_float(r, 16);
1537
1538
1539 dst[1] = _mesa_snorm_to_float(g, 16);
1540
1541
1542 dst[2] = _mesa_snorm_to_float(b, 16);
1543
1544 dst[3] = 1.0f;
1545 }
1546
1547 static inline void
unpack_float_a8b8g8r8_srgb(const void * void_src,GLfloat dst[4])1548 unpack_float_a8b8g8r8_srgb(const void *void_src, GLfloat dst[4])
1549 {
1550 uint32_t *src = (uint32_t *)void_src;
1551 uint8_t a = UNPACK(*src, 0, 8);
1552 uint8_t b = UNPACK(*src, 8, 8);
1553 uint8_t g = UNPACK(*src, 16, 8);
1554 uint8_t r = UNPACK(*src, 24, 8);
1555
1556
1557
1558
1559 dst[0] = util_format_srgb_8unorm_to_linear_float(r);
1560
1561
1562
1563 dst[1] = util_format_srgb_8unorm_to_linear_float(g);
1564
1565
1566
1567 dst[2] = util_format_srgb_8unorm_to_linear_float(b);
1568
1569
1570 dst[3] = _mesa_unorm_to_float(a, 8);
1571 }
1572
1573 static inline void
unpack_float_b8g8r8a8_srgb(const void * void_src,GLfloat dst[4])1574 unpack_float_b8g8r8a8_srgb(const void *void_src, GLfloat dst[4])
1575 {
1576 uint32_t *src = (uint32_t *)void_src;
1577 uint8_t b = UNPACK(*src, 0, 8);
1578 uint8_t g = UNPACK(*src, 8, 8);
1579 uint8_t r = UNPACK(*src, 16, 8);
1580 uint8_t a = UNPACK(*src, 24, 8);
1581
1582
1583
1584
1585 dst[0] = util_format_srgb_8unorm_to_linear_float(r);
1586
1587
1588
1589 dst[1] = util_format_srgb_8unorm_to_linear_float(g);
1590
1591
1592
1593 dst[2] = util_format_srgb_8unorm_to_linear_float(b);
1594
1595
1596 dst[3] = _mesa_unorm_to_float(a, 8);
1597 }
1598
1599 static inline void
unpack_float_a8r8g8b8_srgb(const void * void_src,GLfloat dst[4])1600 unpack_float_a8r8g8b8_srgb(const void *void_src, GLfloat dst[4])
1601 {
1602 uint32_t *src = (uint32_t *)void_src;
1603 uint8_t a = UNPACK(*src, 0, 8);
1604 uint8_t r = UNPACK(*src, 8, 8);
1605 uint8_t g = UNPACK(*src, 16, 8);
1606 uint8_t b = UNPACK(*src, 24, 8);
1607
1608
1609
1610
1611 dst[0] = util_format_srgb_8unorm_to_linear_float(r);
1612
1613
1614
1615 dst[1] = util_format_srgb_8unorm_to_linear_float(g);
1616
1617
1618
1619 dst[2] = util_format_srgb_8unorm_to_linear_float(b);
1620
1621
1622 dst[3] = _mesa_unorm_to_float(a, 8);
1623 }
1624
1625 static inline void
unpack_float_b8g8r8x8_srgb(const void * void_src,GLfloat dst[4])1626 unpack_float_b8g8r8x8_srgb(const void *void_src, GLfloat dst[4])
1627 {
1628 uint32_t *src = (uint32_t *)void_src;
1629 uint8_t b = UNPACK(*src, 0, 8);
1630 uint8_t g = UNPACK(*src, 8, 8);
1631 uint8_t r = UNPACK(*src, 16, 8);
1632
1633
1634
1635
1636 dst[0] = util_format_srgb_8unorm_to_linear_float(r);
1637
1638
1639
1640 dst[1] = util_format_srgb_8unorm_to_linear_float(g);
1641
1642
1643
1644 dst[2] = util_format_srgb_8unorm_to_linear_float(b);
1645
1646 dst[3] = 1.0f;
1647 }
1648
1649 static inline void
unpack_float_x8r8g8b8_srgb(const void * void_src,GLfloat dst[4])1650 unpack_float_x8r8g8b8_srgb(const void *void_src, GLfloat dst[4])
1651 {
1652 uint32_t *src = (uint32_t *)void_src;
1653 uint8_t r = UNPACK(*src, 8, 8);
1654 uint8_t g = UNPACK(*src, 16, 8);
1655 uint8_t b = UNPACK(*src, 24, 8);
1656
1657
1658
1659
1660 dst[0] = util_format_srgb_8unorm_to_linear_float(r);
1661
1662
1663
1664 dst[1] = util_format_srgb_8unorm_to_linear_float(g);
1665
1666
1667
1668 dst[2] = util_format_srgb_8unorm_to_linear_float(b);
1669
1670 dst[3] = 1.0f;
1671 }
1672
1673 static inline void
unpack_float_r8g8b8a8_srgb(const void * void_src,GLfloat dst[4])1674 unpack_float_r8g8b8a8_srgb(const void *void_src, GLfloat dst[4])
1675 {
1676 uint32_t *src = (uint32_t *)void_src;
1677 uint8_t r = UNPACK(*src, 0, 8);
1678 uint8_t g = UNPACK(*src, 8, 8);
1679 uint8_t b = UNPACK(*src, 16, 8);
1680 uint8_t a = UNPACK(*src, 24, 8);
1681
1682
1683
1684
1685 dst[0] = util_format_srgb_8unorm_to_linear_float(r);
1686
1687
1688
1689 dst[1] = util_format_srgb_8unorm_to_linear_float(g);
1690
1691
1692
1693 dst[2] = util_format_srgb_8unorm_to_linear_float(b);
1694
1695
1696 dst[3] = _mesa_unorm_to_float(a, 8);
1697 }
1698
1699 static inline void
unpack_float_r8g8b8x8_srgb(const void * void_src,GLfloat dst[4])1700 unpack_float_r8g8b8x8_srgb(const void *void_src, GLfloat dst[4])
1701 {
1702 uint32_t *src = (uint32_t *)void_src;
1703 uint8_t r = UNPACK(*src, 0, 8);
1704 uint8_t g = UNPACK(*src, 8, 8);
1705 uint8_t b = UNPACK(*src, 16, 8);
1706
1707
1708
1709
1710 dst[0] = util_format_srgb_8unorm_to_linear_float(r);
1711
1712
1713
1714 dst[1] = util_format_srgb_8unorm_to_linear_float(g);
1715
1716
1717
1718 dst[2] = util_format_srgb_8unorm_to_linear_float(b);
1719
1720 dst[3] = 1.0f;
1721 }
1722
1723 static inline void
unpack_float_x8b8g8r8_srgb(const void * void_src,GLfloat dst[4])1724 unpack_float_x8b8g8r8_srgb(const void *void_src, GLfloat dst[4])
1725 {
1726 uint32_t *src = (uint32_t *)void_src;
1727 uint8_t b = UNPACK(*src, 8, 8);
1728 uint8_t g = UNPACK(*src, 16, 8);
1729 uint8_t r = UNPACK(*src, 24, 8);
1730
1731
1732
1733
1734 dst[0] = util_format_srgb_8unorm_to_linear_float(r);
1735
1736
1737
1738 dst[1] = util_format_srgb_8unorm_to_linear_float(g);
1739
1740
1741
1742 dst[2] = util_format_srgb_8unorm_to_linear_float(b);
1743
1744 dst[3] = 1.0f;
1745 }
1746
1747 static inline void
unpack_float_l8a8_srgb(const void * void_src,GLfloat dst[4])1748 unpack_float_l8a8_srgb(const void *void_src, GLfloat dst[4])
1749 {
1750 uint16_t *src = (uint16_t *)void_src;
1751 uint8_t l = UNPACK(*src, 0, 8);
1752 uint8_t a = UNPACK(*src, 8, 8);
1753
1754
1755
1756 dst[0] = _mesa_unorm_to_float(l, 8);
1757
1758
1759 dst[1] = _mesa_unorm_to_float(l, 8);
1760
1761
1762 dst[2] = _mesa_unorm_to_float(l, 8);
1763
1764
1765 dst[3] = _mesa_unorm_to_float(a, 8);
1766 }
1767
1768 static inline void
unpack_float_a8l8_srgb(const void * void_src,GLfloat dst[4])1769 unpack_float_a8l8_srgb(const void *void_src, GLfloat dst[4])
1770 {
1771 uint16_t *src = (uint16_t *)void_src;
1772 uint8_t a = UNPACK(*src, 0, 8);
1773 uint8_t l = UNPACK(*src, 8, 8);
1774
1775
1776
1777 dst[0] = _mesa_unorm_to_float(l, 8);
1778
1779
1780 dst[1] = _mesa_unorm_to_float(l, 8);
1781
1782
1783 dst[2] = _mesa_unorm_to_float(l, 8);
1784
1785
1786 dst[3] = _mesa_unorm_to_float(a, 8);
1787 }
1788
1789 static inline void
unpack_float_l_srgb8(const void * void_src,GLfloat dst[4])1790 unpack_float_l_srgb8(const void *void_src, GLfloat dst[4])
1791 {
1792 uint8_t *src = (uint8_t *)void_src;
1793 uint8_t l = src[0];
1794
1795
1796
1797 dst[0] = _mesa_unorm_to_float(l, 8);
1798
1799
1800 dst[1] = _mesa_unorm_to_float(l, 8);
1801
1802
1803 dst[2] = _mesa_unorm_to_float(l, 8);
1804
1805 dst[3] = 1.0f;
1806 }
1807
1808 static inline void
unpack_float_bgr_srgb8(const void * void_src,GLfloat dst[4])1809 unpack_float_bgr_srgb8(const void *void_src, GLfloat dst[4])
1810 {
1811 uint8_t *src = (uint8_t *)void_src;
1812 uint8_t b = src[0];
1813 uint8_t g = src[1];
1814 uint8_t r = src[2];
1815
1816
1817
1818
1819 dst[0] = util_format_srgb_8unorm_to_linear_float(r);
1820
1821
1822
1823 dst[1] = util_format_srgb_8unorm_to_linear_float(g);
1824
1825
1826
1827 dst[2] = util_format_srgb_8unorm_to_linear_float(b);
1828
1829 dst[3] = 1.0f;
1830 }
1831
1832 static inline void
unpack_float_a_float16(const void * void_src,GLfloat dst[4])1833 unpack_float_a_float16(const void *void_src, GLfloat dst[4])
1834 {
1835 uint16_t *src = (uint16_t *)void_src;
1836 uint16_t a = src[0];
1837
1838
1839 dst[0] = 0.0f;
1840
1841 dst[1] = 0.0f;
1842
1843 dst[2] = 0.0f;
1844
1845
1846 dst[3] = _mesa_half_to_float(a);
1847 }
1848
1849 static inline void
unpack_float_a_float32(const void * void_src,GLfloat dst[4])1850 unpack_float_a_float32(const void *void_src, GLfloat dst[4])
1851 {
1852 float *src = (float *)void_src;
1853 float a = src[0];
1854
1855
1856 dst[0] = 0.0f;
1857
1858 dst[1] = 0.0f;
1859
1860 dst[2] = 0.0f;
1861
1862
1863 dst[3] = a;
1864 }
1865
1866 static inline void
unpack_float_l_float16(const void * void_src,GLfloat dst[4])1867 unpack_float_l_float16(const void *void_src, GLfloat dst[4])
1868 {
1869 uint16_t *src = (uint16_t *)void_src;
1870 uint16_t l = src[0];
1871
1872
1873
1874 dst[0] = _mesa_half_to_float(l);
1875
1876
1877 dst[1] = _mesa_half_to_float(l);
1878
1879
1880 dst[2] = _mesa_half_to_float(l);
1881
1882 dst[3] = 1.0f;
1883 }
1884
1885 static inline void
unpack_float_l_float32(const void * void_src,GLfloat dst[4])1886 unpack_float_l_float32(const void *void_src, GLfloat dst[4])
1887 {
1888 float *src = (float *)void_src;
1889 float l = src[0];
1890
1891
1892
1893 dst[0] = l;
1894
1895
1896 dst[1] = l;
1897
1898
1899 dst[2] = l;
1900
1901 dst[3] = 1.0f;
1902 }
1903
1904 static inline void
unpack_float_la_float16(const void * void_src,GLfloat dst[4])1905 unpack_float_la_float16(const void *void_src, GLfloat dst[4])
1906 {
1907 uint16_t *src = (uint16_t *)void_src;
1908 uint16_t l = src[0];
1909 uint16_t a = src[1];
1910
1911
1912
1913 dst[0] = _mesa_half_to_float(l);
1914
1915
1916 dst[1] = _mesa_half_to_float(l);
1917
1918
1919 dst[2] = _mesa_half_to_float(l);
1920
1921
1922 dst[3] = _mesa_half_to_float(a);
1923 }
1924
1925 static inline void
unpack_float_la_float32(const void * void_src,GLfloat dst[4])1926 unpack_float_la_float32(const void *void_src, GLfloat dst[4])
1927 {
1928 float *src = (float *)void_src;
1929 float l = src[0];
1930 float a = src[1];
1931
1932
1933
1934 dst[0] = l;
1935
1936
1937 dst[1] = l;
1938
1939
1940 dst[2] = l;
1941
1942
1943 dst[3] = a;
1944 }
1945
1946 static inline void
unpack_float_i_float16(const void * void_src,GLfloat dst[4])1947 unpack_float_i_float16(const void *void_src, GLfloat dst[4])
1948 {
1949 uint16_t *src = (uint16_t *)void_src;
1950 uint16_t i = src[0];
1951
1952
1953
1954 dst[0] = _mesa_half_to_float(i);
1955
1956
1957 dst[1] = _mesa_half_to_float(i);
1958
1959
1960 dst[2] = _mesa_half_to_float(i);
1961
1962
1963 dst[3] = _mesa_half_to_float(i);
1964 }
1965
1966 static inline void
unpack_float_i_float32(const void * void_src,GLfloat dst[4])1967 unpack_float_i_float32(const void *void_src, GLfloat dst[4])
1968 {
1969 float *src = (float *)void_src;
1970 float i = src[0];
1971
1972
1973
1974 dst[0] = i;
1975
1976
1977 dst[1] = i;
1978
1979
1980 dst[2] = i;
1981
1982
1983 dst[3] = i;
1984 }
1985
1986 static inline void
unpack_float_r_float16(const void * void_src,GLfloat dst[4])1987 unpack_float_r_float16(const void *void_src, GLfloat dst[4])
1988 {
1989 uint16_t *src = (uint16_t *)void_src;
1990 uint16_t r = src[0];
1991
1992
1993
1994 dst[0] = _mesa_half_to_float(r);
1995
1996 dst[1] = 0.0f;
1997
1998 dst[2] = 0.0f;
1999
2000 dst[3] = 1.0f;
2001 }
2002
2003 static inline void
unpack_float_r_float32(const void * void_src,GLfloat dst[4])2004 unpack_float_r_float32(const void *void_src, GLfloat dst[4])
2005 {
2006 float *src = (float *)void_src;
2007 float r = src[0];
2008
2009
2010
2011 dst[0] = r;
2012
2013 dst[1] = 0.0f;
2014
2015 dst[2] = 0.0f;
2016
2017 dst[3] = 1.0f;
2018 }
2019
2020 static inline void
unpack_float_rg_float16(const void * void_src,GLfloat dst[4])2021 unpack_float_rg_float16(const void *void_src, GLfloat dst[4])
2022 {
2023 uint16_t *src = (uint16_t *)void_src;
2024 uint16_t r = src[0];
2025 uint16_t g = src[1];
2026
2027
2028
2029 dst[0] = _mesa_half_to_float(r);
2030
2031
2032 dst[1] = _mesa_half_to_float(g);
2033
2034 dst[2] = 0.0f;
2035
2036 dst[3] = 1.0f;
2037 }
2038
2039 static inline void
unpack_float_rg_float32(const void * void_src,GLfloat dst[4])2040 unpack_float_rg_float32(const void *void_src, GLfloat dst[4])
2041 {
2042 float *src = (float *)void_src;
2043 float r = src[0];
2044 float g = src[1];
2045
2046
2047
2048 dst[0] = r;
2049
2050
2051 dst[1] = g;
2052
2053 dst[2] = 0.0f;
2054
2055 dst[3] = 1.0f;
2056 }
2057
2058 static inline void
unpack_float_rgb_float16(const void * void_src,GLfloat dst[4])2059 unpack_float_rgb_float16(const void *void_src, GLfloat dst[4])
2060 {
2061 uint16_t *src = (uint16_t *)void_src;
2062 uint16_t r = src[0];
2063 uint16_t g = src[1];
2064 uint16_t b = src[2];
2065
2066
2067
2068 dst[0] = _mesa_half_to_float(r);
2069
2070
2071 dst[1] = _mesa_half_to_float(g);
2072
2073
2074 dst[2] = _mesa_half_to_float(b);
2075
2076 dst[3] = 1.0f;
2077 }
2078
2079 static inline void
unpack_float_rgb_float32(const void * void_src,GLfloat dst[4])2080 unpack_float_rgb_float32(const void *void_src, GLfloat dst[4])
2081 {
2082 float *src = (float *)void_src;
2083 float r = src[0];
2084 float g = src[1];
2085 float b = src[2];
2086
2087
2088
2089 dst[0] = r;
2090
2091
2092 dst[1] = g;
2093
2094
2095 dst[2] = b;
2096
2097 dst[3] = 1.0f;
2098 }
2099
2100 static inline void
unpack_float_rgba_float16(const void * void_src,GLfloat dst[4])2101 unpack_float_rgba_float16(const void *void_src, GLfloat dst[4])
2102 {
2103 uint16_t *src = (uint16_t *)void_src;
2104 uint16_t r = src[0];
2105 uint16_t g = src[1];
2106 uint16_t b = src[2];
2107 uint16_t a = src[3];
2108
2109
2110
2111 dst[0] = _mesa_half_to_float(r);
2112
2113
2114 dst[1] = _mesa_half_to_float(g);
2115
2116
2117 dst[2] = _mesa_half_to_float(b);
2118
2119
2120 dst[3] = _mesa_half_to_float(a);
2121 }
2122
2123 static inline void
unpack_float_rgba_float32(const void * void_src,GLfloat dst[4])2124 unpack_float_rgba_float32(const void *void_src, GLfloat dst[4])
2125 {
2126 float *src = (float *)void_src;
2127 float r = src[0];
2128 float g = src[1];
2129 float b = src[2];
2130 float a = src[3];
2131
2132
2133
2134 dst[0] = r;
2135
2136
2137 dst[1] = g;
2138
2139
2140 dst[2] = b;
2141
2142
2143 dst[3] = a;
2144 }
2145
2146 static inline void
unpack_float_rgbx_float16(const void * void_src,GLfloat dst[4])2147 unpack_float_rgbx_float16(const void *void_src, GLfloat dst[4])
2148 {
2149 uint16_t *src = (uint16_t *)void_src;
2150 uint16_t r = src[0];
2151 uint16_t g = src[1];
2152 uint16_t b = src[2];
2153
2154
2155
2156 dst[0] = _mesa_half_to_float(r);
2157
2158
2159 dst[1] = _mesa_half_to_float(g);
2160
2161
2162 dst[2] = _mesa_half_to_float(b);
2163
2164 dst[3] = 1.0f;
2165 }
2166
2167 static inline void
unpack_float_rgbx_float32(const void * void_src,GLfloat dst[4])2168 unpack_float_rgbx_float32(const void *void_src, GLfloat dst[4])
2169 {
2170 float *src = (float *)void_src;
2171 float r = src[0];
2172 float g = src[1];
2173 float b = src[2];
2174
2175
2176
2177 dst[0] = r;
2178
2179
2180 dst[1] = g;
2181
2182
2183 dst[2] = b;
2184
2185 dst[3] = 1.0f;
2186 }
2187
2188 static void
unpack_float_r9g9b9e5_float(const void * src,GLfloat dst[4])2189 unpack_float_r9g9b9e5_float(const void *src, GLfloat dst[4])
2190 {
2191 rgb9e5_to_float3(*(const GLuint *)src, dst);
2192 dst[3] = 1.0f;
2193 }
2194
2195 static void
unpack_float_r11g11b10_float(const void * src,GLfloat dst[4])2196 unpack_float_r11g11b10_float(const void *src, GLfloat dst[4])
2197 {
2198 r11g11b10f_to_float3(*(const GLuint *)src, dst);
2199 dst[3] = 1.0f;
2200 }
2201
2202 static void
unpack_float_ycbcr(const void * src,GLfloat dst[][4],GLuint n)2203 unpack_float_ycbcr(const void *src, GLfloat dst[][4], GLuint n)
2204 {
2205 GLuint i;
2206 for (i = 0; i < n; i++) {
2207 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
2208 const GLushort *src1 = src0 + 1; /* odd */
2209 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
2210 const GLubyte cb = *src0 & 0xff; /* chroma U */
2211 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
2212 const GLubyte cr = *src1 & 0xff; /* chroma V */
2213 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
2214 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
2215 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
2216 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
2217 r *= (1.0F / 255.0F);
2218 g *= (1.0F / 255.0F);
2219 b *= (1.0F / 255.0F);
2220 dst[i][0] = CLAMP(r, 0.0F, 1.0F);
2221 dst[i][1] = CLAMP(g, 0.0F, 1.0F);
2222 dst[i][2] = CLAMP(b, 0.0F, 1.0F);
2223 dst[i][3] = 1.0F;
2224 }
2225 }
2226
2227 static void
unpack_float_ycbcr_rev(const void * src,GLfloat dst[][4],GLuint n)2228 unpack_float_ycbcr_rev(const void *src, GLfloat dst[][4], GLuint n)
2229 {
2230 GLuint i;
2231 for (i = 0; i < n; i++) {
2232 const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
2233 const GLushort *src1 = src0 + 1; /* odd */
2234 const GLubyte y0 = *src0 & 0xff; /* luminance */
2235 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
2236 const GLubyte y1 = *src1 & 0xff; /* luminance */
2237 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
2238 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
2239 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
2240 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
2241 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
2242 r *= (1.0F / 255.0F);
2243 g *= (1.0F / 255.0F);
2244 b *= (1.0F / 255.0F);
2245 dst[i][0] = CLAMP(r, 0.0F, 1.0F);
2246 dst[i][1] = CLAMP(g, 0.0F, 1.0F);
2247 dst[i][2] = CLAMP(b, 0.0F, 1.0F);
2248 dst[i][3] = 1.0F;
2249 }
2250 }
2251
2252 /* ubyte packing functions */
2253
2254
2255 static inline void
unpack_ubyte_a8b8g8r8_unorm(const void * void_src,GLubyte dst[4])2256 unpack_ubyte_a8b8g8r8_unorm(const void *void_src, GLubyte dst[4])
2257 {
2258 uint32_t *src = (uint32_t *)void_src;
2259 uint8_t a = UNPACK(*src, 0, 8);
2260 uint8_t b = UNPACK(*src, 8, 8);
2261 uint8_t g = UNPACK(*src, 16, 8);
2262 uint8_t r = UNPACK(*src, 24, 8);
2263
2264
2265
2266 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
2267
2268
2269 dst[1] = _mesa_unorm_to_unorm(g, 8, 8);
2270
2271
2272 dst[2] = _mesa_unorm_to_unorm(b, 8, 8);
2273
2274
2275 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
2276 }
2277
2278 static inline void
unpack_ubyte_x8b8g8r8_unorm(const void * void_src,GLubyte dst[4])2279 unpack_ubyte_x8b8g8r8_unorm(const void *void_src, GLubyte dst[4])
2280 {
2281 uint32_t *src = (uint32_t *)void_src;
2282 uint8_t b = UNPACK(*src, 8, 8);
2283 uint8_t g = UNPACK(*src, 16, 8);
2284 uint8_t r = UNPACK(*src, 24, 8);
2285
2286
2287
2288 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
2289
2290
2291 dst[1] = _mesa_unorm_to_unorm(g, 8, 8);
2292
2293
2294 dst[2] = _mesa_unorm_to_unorm(b, 8, 8);
2295
2296 dst[3] = 255;
2297 }
2298
2299 static inline void
unpack_ubyte_r8g8b8a8_unorm(const void * void_src,GLubyte dst[4])2300 unpack_ubyte_r8g8b8a8_unorm(const void *void_src, GLubyte dst[4])
2301 {
2302 uint32_t *src = (uint32_t *)void_src;
2303 uint8_t r = UNPACK(*src, 0, 8);
2304 uint8_t g = UNPACK(*src, 8, 8);
2305 uint8_t b = UNPACK(*src, 16, 8);
2306 uint8_t a = UNPACK(*src, 24, 8);
2307
2308
2309
2310 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
2311
2312
2313 dst[1] = _mesa_unorm_to_unorm(g, 8, 8);
2314
2315
2316 dst[2] = _mesa_unorm_to_unorm(b, 8, 8);
2317
2318
2319 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
2320 }
2321
2322 static inline void
unpack_ubyte_r8g8b8x8_unorm(const void * void_src,GLubyte dst[4])2323 unpack_ubyte_r8g8b8x8_unorm(const void *void_src, GLubyte dst[4])
2324 {
2325 uint32_t *src = (uint32_t *)void_src;
2326 uint8_t r = UNPACK(*src, 0, 8);
2327 uint8_t g = UNPACK(*src, 8, 8);
2328 uint8_t b = UNPACK(*src, 16, 8);
2329
2330
2331
2332 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
2333
2334
2335 dst[1] = _mesa_unorm_to_unorm(g, 8, 8);
2336
2337
2338 dst[2] = _mesa_unorm_to_unorm(b, 8, 8);
2339
2340 dst[3] = 255;
2341 }
2342
2343 static inline void
unpack_ubyte_b8g8r8a8_unorm(const void * void_src,GLubyte dst[4])2344 unpack_ubyte_b8g8r8a8_unorm(const void *void_src, GLubyte dst[4])
2345 {
2346 uint32_t *src = (uint32_t *)void_src;
2347 uint8_t b = UNPACK(*src, 0, 8);
2348 uint8_t g = UNPACK(*src, 8, 8);
2349 uint8_t r = UNPACK(*src, 16, 8);
2350 uint8_t a = UNPACK(*src, 24, 8);
2351
2352
2353
2354 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
2355
2356
2357 dst[1] = _mesa_unorm_to_unorm(g, 8, 8);
2358
2359
2360 dst[2] = _mesa_unorm_to_unorm(b, 8, 8);
2361
2362
2363 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
2364 }
2365
2366 static inline void
unpack_ubyte_b8g8r8x8_unorm(const void * void_src,GLubyte dst[4])2367 unpack_ubyte_b8g8r8x8_unorm(const void *void_src, GLubyte dst[4])
2368 {
2369 uint32_t *src = (uint32_t *)void_src;
2370 uint8_t b = UNPACK(*src, 0, 8);
2371 uint8_t g = UNPACK(*src, 8, 8);
2372 uint8_t r = UNPACK(*src, 16, 8);
2373
2374
2375
2376 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
2377
2378
2379 dst[1] = _mesa_unorm_to_unorm(g, 8, 8);
2380
2381
2382 dst[2] = _mesa_unorm_to_unorm(b, 8, 8);
2383
2384 dst[3] = 255;
2385 }
2386
2387 static inline void
unpack_ubyte_a8r8g8b8_unorm(const void * void_src,GLubyte dst[4])2388 unpack_ubyte_a8r8g8b8_unorm(const void *void_src, GLubyte dst[4])
2389 {
2390 uint32_t *src = (uint32_t *)void_src;
2391 uint8_t a = UNPACK(*src, 0, 8);
2392 uint8_t r = UNPACK(*src, 8, 8);
2393 uint8_t g = UNPACK(*src, 16, 8);
2394 uint8_t b = UNPACK(*src, 24, 8);
2395
2396
2397
2398 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
2399
2400
2401 dst[1] = _mesa_unorm_to_unorm(g, 8, 8);
2402
2403
2404 dst[2] = _mesa_unorm_to_unorm(b, 8, 8);
2405
2406
2407 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
2408 }
2409
2410 static inline void
unpack_ubyte_x8r8g8b8_unorm(const void * void_src,GLubyte dst[4])2411 unpack_ubyte_x8r8g8b8_unorm(const void *void_src, GLubyte dst[4])
2412 {
2413 uint32_t *src = (uint32_t *)void_src;
2414 uint8_t r = UNPACK(*src, 8, 8);
2415 uint8_t g = UNPACK(*src, 16, 8);
2416 uint8_t b = UNPACK(*src, 24, 8);
2417
2418
2419
2420 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
2421
2422
2423 dst[1] = _mesa_unorm_to_unorm(g, 8, 8);
2424
2425
2426 dst[2] = _mesa_unorm_to_unorm(b, 8, 8);
2427
2428 dst[3] = 255;
2429 }
2430
2431 static inline void
unpack_ubyte_l16a16_unorm(const void * void_src,GLubyte dst[4])2432 unpack_ubyte_l16a16_unorm(const void *void_src, GLubyte dst[4])
2433 {
2434 uint32_t *src = (uint32_t *)void_src;
2435 uint16_t l = UNPACK(*src, 0, 16);
2436 uint16_t a = UNPACK(*src, 16, 16);
2437
2438
2439
2440 dst[0] = _mesa_unorm_to_unorm(l, 16, 8);
2441
2442
2443 dst[1] = _mesa_unorm_to_unorm(l, 16, 8);
2444
2445
2446 dst[2] = _mesa_unorm_to_unorm(l, 16, 8);
2447
2448
2449 dst[3] = _mesa_unorm_to_unorm(a, 16, 8);
2450 }
2451
2452 static inline void
unpack_ubyte_a16l16_unorm(const void * void_src,GLubyte dst[4])2453 unpack_ubyte_a16l16_unorm(const void *void_src, GLubyte dst[4])
2454 {
2455 uint32_t *src = (uint32_t *)void_src;
2456 uint16_t a = UNPACK(*src, 0, 16);
2457 uint16_t l = UNPACK(*src, 16, 16);
2458
2459
2460
2461 dst[0] = _mesa_unorm_to_unorm(l, 16, 8);
2462
2463
2464 dst[1] = _mesa_unorm_to_unorm(l, 16, 8);
2465
2466
2467 dst[2] = _mesa_unorm_to_unorm(l, 16, 8);
2468
2469
2470 dst[3] = _mesa_unorm_to_unorm(a, 16, 8);
2471 }
2472
2473 static inline void
unpack_ubyte_b5g6r5_unorm(const void * void_src,GLubyte dst[4])2474 unpack_ubyte_b5g6r5_unorm(const void *void_src, GLubyte dst[4])
2475 {
2476 uint16_t *src = (uint16_t *)void_src;
2477 uint8_t b = UNPACK(*src, 0, 5);
2478 uint8_t g = UNPACK(*src, 5, 6);
2479 uint8_t r = UNPACK(*src, 11, 5);
2480
2481
2482
2483 dst[0] = _mesa_unorm_to_unorm(r, 5, 8);
2484
2485
2486 dst[1] = _mesa_unorm_to_unorm(g, 6, 8);
2487
2488
2489 dst[2] = _mesa_unorm_to_unorm(b, 5, 8);
2490
2491 dst[3] = 255;
2492 }
2493
2494 static inline void
unpack_ubyte_r5g6b5_unorm(const void * void_src,GLubyte dst[4])2495 unpack_ubyte_r5g6b5_unorm(const void *void_src, GLubyte dst[4])
2496 {
2497 uint16_t *src = (uint16_t *)void_src;
2498 uint8_t r = UNPACK(*src, 0, 5);
2499 uint8_t g = UNPACK(*src, 5, 6);
2500 uint8_t b = UNPACK(*src, 11, 5);
2501
2502
2503
2504 dst[0] = _mesa_unorm_to_unorm(r, 5, 8);
2505
2506
2507 dst[1] = _mesa_unorm_to_unorm(g, 6, 8);
2508
2509
2510 dst[2] = _mesa_unorm_to_unorm(b, 5, 8);
2511
2512 dst[3] = 255;
2513 }
2514
2515 static inline void
unpack_ubyte_b4g4r4a4_unorm(const void * void_src,GLubyte dst[4])2516 unpack_ubyte_b4g4r4a4_unorm(const void *void_src, GLubyte dst[4])
2517 {
2518 uint16_t *src = (uint16_t *)void_src;
2519 uint8_t b = UNPACK(*src, 0, 4);
2520 uint8_t g = UNPACK(*src, 4, 4);
2521 uint8_t r = UNPACK(*src, 8, 4);
2522 uint8_t a = UNPACK(*src, 12, 4);
2523
2524
2525
2526 dst[0] = _mesa_unorm_to_unorm(r, 4, 8);
2527
2528
2529 dst[1] = _mesa_unorm_to_unorm(g, 4, 8);
2530
2531
2532 dst[2] = _mesa_unorm_to_unorm(b, 4, 8);
2533
2534
2535 dst[3] = _mesa_unorm_to_unorm(a, 4, 8);
2536 }
2537
2538 static inline void
unpack_ubyte_b4g4r4x4_unorm(const void * void_src,GLubyte dst[4])2539 unpack_ubyte_b4g4r4x4_unorm(const void *void_src, GLubyte dst[4])
2540 {
2541 uint16_t *src = (uint16_t *)void_src;
2542 uint8_t b = UNPACK(*src, 0, 4);
2543 uint8_t g = UNPACK(*src, 4, 4);
2544 uint8_t r = UNPACK(*src, 8, 4);
2545
2546
2547
2548 dst[0] = _mesa_unorm_to_unorm(r, 4, 8);
2549
2550
2551 dst[1] = _mesa_unorm_to_unorm(g, 4, 8);
2552
2553
2554 dst[2] = _mesa_unorm_to_unorm(b, 4, 8);
2555
2556 dst[3] = 255;
2557 }
2558
2559 static inline void
unpack_ubyte_a4r4g4b4_unorm(const void * void_src,GLubyte dst[4])2560 unpack_ubyte_a4r4g4b4_unorm(const void *void_src, GLubyte dst[4])
2561 {
2562 uint16_t *src = (uint16_t *)void_src;
2563 uint8_t a = UNPACK(*src, 0, 4);
2564 uint8_t r = UNPACK(*src, 4, 4);
2565 uint8_t g = UNPACK(*src, 8, 4);
2566 uint8_t b = UNPACK(*src, 12, 4);
2567
2568
2569
2570 dst[0] = _mesa_unorm_to_unorm(r, 4, 8);
2571
2572
2573 dst[1] = _mesa_unorm_to_unorm(g, 4, 8);
2574
2575
2576 dst[2] = _mesa_unorm_to_unorm(b, 4, 8);
2577
2578
2579 dst[3] = _mesa_unorm_to_unorm(a, 4, 8);
2580 }
2581
2582 static inline void
unpack_ubyte_a1b5g5r5_unorm(const void * void_src,GLubyte dst[4])2583 unpack_ubyte_a1b5g5r5_unorm(const void *void_src, GLubyte dst[4])
2584 {
2585 uint16_t *src = (uint16_t *)void_src;
2586 uint8_t a = UNPACK(*src, 0, 1);
2587 uint8_t b = UNPACK(*src, 1, 5);
2588 uint8_t g = UNPACK(*src, 6, 5);
2589 uint8_t r = UNPACK(*src, 11, 5);
2590
2591
2592
2593 dst[0] = _mesa_unorm_to_unorm(r, 5, 8);
2594
2595
2596 dst[1] = _mesa_unorm_to_unorm(g, 5, 8);
2597
2598
2599 dst[2] = _mesa_unorm_to_unorm(b, 5, 8);
2600
2601
2602 dst[3] = _mesa_unorm_to_unorm(a, 1, 8);
2603 }
2604
2605 static inline void
unpack_ubyte_x1b5g5r5_unorm(const void * void_src,GLubyte dst[4])2606 unpack_ubyte_x1b5g5r5_unorm(const void *void_src, GLubyte dst[4])
2607 {
2608 uint16_t *src = (uint16_t *)void_src;
2609 uint8_t b = UNPACK(*src, 1, 5);
2610 uint8_t g = UNPACK(*src, 6, 5);
2611 uint8_t r = UNPACK(*src, 11, 5);
2612
2613
2614
2615 dst[0] = _mesa_unorm_to_unorm(r, 5, 8);
2616
2617
2618 dst[1] = _mesa_unorm_to_unorm(g, 5, 8);
2619
2620
2621 dst[2] = _mesa_unorm_to_unorm(b, 5, 8);
2622
2623 dst[3] = 255;
2624 }
2625
2626 static inline void
unpack_ubyte_b5g5r5a1_unorm(const void * void_src,GLubyte dst[4])2627 unpack_ubyte_b5g5r5a1_unorm(const void *void_src, GLubyte dst[4])
2628 {
2629 uint16_t *src = (uint16_t *)void_src;
2630 uint8_t b = UNPACK(*src, 0, 5);
2631 uint8_t g = UNPACK(*src, 5, 5);
2632 uint8_t r = UNPACK(*src, 10, 5);
2633 uint8_t a = UNPACK(*src, 15, 1);
2634
2635
2636
2637 dst[0] = _mesa_unorm_to_unorm(r, 5, 8);
2638
2639
2640 dst[1] = _mesa_unorm_to_unorm(g, 5, 8);
2641
2642
2643 dst[2] = _mesa_unorm_to_unorm(b, 5, 8);
2644
2645
2646 dst[3] = _mesa_unorm_to_unorm(a, 1, 8);
2647 }
2648
2649 static inline void
unpack_ubyte_b5g5r5x1_unorm(const void * void_src,GLubyte dst[4])2650 unpack_ubyte_b5g5r5x1_unorm(const void *void_src, GLubyte dst[4])
2651 {
2652 uint16_t *src = (uint16_t *)void_src;
2653 uint8_t b = UNPACK(*src, 0, 5);
2654 uint8_t g = UNPACK(*src, 5, 5);
2655 uint8_t r = UNPACK(*src, 10, 5);
2656
2657
2658
2659 dst[0] = _mesa_unorm_to_unorm(r, 5, 8);
2660
2661
2662 dst[1] = _mesa_unorm_to_unorm(g, 5, 8);
2663
2664
2665 dst[2] = _mesa_unorm_to_unorm(b, 5, 8);
2666
2667 dst[3] = 255;
2668 }
2669
2670 static inline void
unpack_ubyte_a1r5g5b5_unorm(const void * void_src,GLubyte dst[4])2671 unpack_ubyte_a1r5g5b5_unorm(const void *void_src, GLubyte dst[4])
2672 {
2673 uint16_t *src = (uint16_t *)void_src;
2674 uint8_t a = UNPACK(*src, 0, 1);
2675 uint8_t r = UNPACK(*src, 1, 5);
2676 uint8_t g = UNPACK(*src, 6, 5);
2677 uint8_t b = UNPACK(*src, 11, 5);
2678
2679
2680
2681 dst[0] = _mesa_unorm_to_unorm(r, 5, 8);
2682
2683
2684 dst[1] = _mesa_unorm_to_unorm(g, 5, 8);
2685
2686
2687 dst[2] = _mesa_unorm_to_unorm(b, 5, 8);
2688
2689
2690 dst[3] = _mesa_unorm_to_unorm(a, 1, 8);
2691 }
2692
2693 static inline void
unpack_ubyte_l8a8_unorm(const void * void_src,GLubyte dst[4])2694 unpack_ubyte_l8a8_unorm(const void *void_src, GLubyte dst[4])
2695 {
2696 uint16_t *src = (uint16_t *)void_src;
2697 uint8_t l = UNPACK(*src, 0, 8);
2698 uint8_t a = UNPACK(*src, 8, 8);
2699
2700
2701
2702 dst[0] = _mesa_unorm_to_unorm(l, 8, 8);
2703
2704
2705 dst[1] = _mesa_unorm_to_unorm(l, 8, 8);
2706
2707
2708 dst[2] = _mesa_unorm_to_unorm(l, 8, 8);
2709
2710
2711 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
2712 }
2713
2714 static inline void
unpack_ubyte_a8l8_unorm(const void * void_src,GLubyte dst[4])2715 unpack_ubyte_a8l8_unorm(const void *void_src, GLubyte dst[4])
2716 {
2717 uint16_t *src = (uint16_t *)void_src;
2718 uint8_t a = UNPACK(*src, 0, 8);
2719 uint8_t l = UNPACK(*src, 8, 8);
2720
2721
2722
2723 dst[0] = _mesa_unorm_to_unorm(l, 8, 8);
2724
2725
2726 dst[1] = _mesa_unorm_to_unorm(l, 8, 8);
2727
2728
2729 dst[2] = _mesa_unorm_to_unorm(l, 8, 8);
2730
2731
2732 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
2733 }
2734
2735 static inline void
unpack_ubyte_r8g8_unorm(const void * void_src,GLubyte dst[4])2736 unpack_ubyte_r8g8_unorm(const void *void_src, GLubyte dst[4])
2737 {
2738 uint16_t *src = (uint16_t *)void_src;
2739 uint8_t r = UNPACK(*src, 0, 8);
2740 uint8_t g = UNPACK(*src, 8, 8);
2741
2742
2743
2744 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
2745
2746
2747 dst[1] = _mesa_unorm_to_unorm(g, 8, 8);
2748
2749 dst[2] = 0;
2750
2751 dst[3] = 255;
2752 }
2753
2754 static inline void
unpack_ubyte_g8r8_unorm(const void * void_src,GLubyte dst[4])2755 unpack_ubyte_g8r8_unorm(const void *void_src, GLubyte dst[4])
2756 {
2757 uint16_t *src = (uint16_t *)void_src;
2758 uint8_t g = UNPACK(*src, 0, 8);
2759 uint8_t r = UNPACK(*src, 8, 8);
2760
2761
2762
2763 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
2764
2765
2766 dst[1] = _mesa_unorm_to_unorm(g, 8, 8);
2767
2768 dst[2] = 0;
2769
2770 dst[3] = 255;
2771 }
2772
2773 static inline void
unpack_ubyte_l4a4_unorm(const void * void_src,GLubyte dst[4])2774 unpack_ubyte_l4a4_unorm(const void *void_src, GLubyte dst[4])
2775 {
2776 uint8_t *src = (uint8_t *)void_src;
2777 uint8_t l = UNPACK(*src, 0, 4);
2778 uint8_t a = UNPACK(*src, 4, 4);
2779
2780
2781
2782 dst[0] = _mesa_unorm_to_unorm(l, 4, 8);
2783
2784
2785 dst[1] = _mesa_unorm_to_unorm(l, 4, 8);
2786
2787
2788 dst[2] = _mesa_unorm_to_unorm(l, 4, 8);
2789
2790
2791 dst[3] = _mesa_unorm_to_unorm(a, 4, 8);
2792 }
2793
2794 static inline void
unpack_ubyte_b2g3r3_unorm(const void * void_src,GLubyte dst[4])2795 unpack_ubyte_b2g3r3_unorm(const void *void_src, GLubyte dst[4])
2796 {
2797 uint8_t *src = (uint8_t *)void_src;
2798 uint8_t b = UNPACK(*src, 0, 2);
2799 uint8_t g = UNPACK(*src, 2, 3);
2800 uint8_t r = UNPACK(*src, 5, 3);
2801
2802
2803
2804 dst[0] = _mesa_unorm_to_unorm(r, 3, 8);
2805
2806
2807 dst[1] = _mesa_unorm_to_unorm(g, 3, 8);
2808
2809
2810 dst[2] = _mesa_unorm_to_unorm(b, 2, 8);
2811
2812 dst[3] = 255;
2813 }
2814
2815 static inline void
unpack_ubyte_r16g16_unorm(const void * void_src,GLubyte dst[4])2816 unpack_ubyte_r16g16_unorm(const void *void_src, GLubyte dst[4])
2817 {
2818 uint32_t *src = (uint32_t *)void_src;
2819 uint16_t r = UNPACK(*src, 0, 16);
2820 uint16_t g = UNPACK(*src, 16, 16);
2821
2822
2823
2824 dst[0] = _mesa_unorm_to_unorm(r, 16, 8);
2825
2826
2827 dst[1] = _mesa_unorm_to_unorm(g, 16, 8);
2828
2829 dst[2] = 0;
2830
2831 dst[3] = 255;
2832 }
2833
2834 static inline void
unpack_ubyte_g16r16_unorm(const void * void_src,GLubyte dst[4])2835 unpack_ubyte_g16r16_unorm(const void *void_src, GLubyte dst[4])
2836 {
2837 uint32_t *src = (uint32_t *)void_src;
2838 uint16_t g = UNPACK(*src, 0, 16);
2839 uint16_t r = UNPACK(*src, 16, 16);
2840
2841
2842
2843 dst[0] = _mesa_unorm_to_unorm(r, 16, 8);
2844
2845
2846 dst[1] = _mesa_unorm_to_unorm(g, 16, 8);
2847
2848 dst[2] = 0;
2849
2850 dst[3] = 255;
2851 }
2852
2853 static inline void
unpack_ubyte_b10g10r10a2_unorm(const void * void_src,GLubyte dst[4])2854 unpack_ubyte_b10g10r10a2_unorm(const void *void_src, GLubyte dst[4])
2855 {
2856 uint32_t *src = (uint32_t *)void_src;
2857 uint16_t b = UNPACK(*src, 0, 10);
2858 uint16_t g = UNPACK(*src, 10, 10);
2859 uint16_t r = UNPACK(*src, 20, 10);
2860 uint8_t a = UNPACK(*src, 30, 2);
2861
2862
2863
2864 dst[0] = _mesa_unorm_to_unorm(r, 10, 8);
2865
2866
2867 dst[1] = _mesa_unorm_to_unorm(g, 10, 8);
2868
2869
2870 dst[2] = _mesa_unorm_to_unorm(b, 10, 8);
2871
2872
2873 dst[3] = _mesa_unorm_to_unorm(a, 2, 8);
2874 }
2875
2876 static inline void
unpack_ubyte_b10g10r10x2_unorm(const void * void_src,GLubyte dst[4])2877 unpack_ubyte_b10g10r10x2_unorm(const void *void_src, GLubyte dst[4])
2878 {
2879 uint32_t *src = (uint32_t *)void_src;
2880 uint16_t b = UNPACK(*src, 0, 10);
2881 uint16_t g = UNPACK(*src, 10, 10);
2882 uint16_t r = UNPACK(*src, 20, 10);
2883
2884
2885
2886 dst[0] = _mesa_unorm_to_unorm(r, 10, 8);
2887
2888
2889 dst[1] = _mesa_unorm_to_unorm(g, 10, 8);
2890
2891
2892 dst[2] = _mesa_unorm_to_unorm(b, 10, 8);
2893
2894 dst[3] = 255;
2895 }
2896
2897 static inline void
unpack_ubyte_r10g10b10a2_unorm(const void * void_src,GLubyte dst[4])2898 unpack_ubyte_r10g10b10a2_unorm(const void *void_src, GLubyte dst[4])
2899 {
2900 uint32_t *src = (uint32_t *)void_src;
2901 uint16_t r = UNPACK(*src, 0, 10);
2902 uint16_t g = UNPACK(*src, 10, 10);
2903 uint16_t b = UNPACK(*src, 20, 10);
2904 uint8_t a = UNPACK(*src, 30, 2);
2905
2906
2907
2908 dst[0] = _mesa_unorm_to_unorm(r, 10, 8);
2909
2910
2911 dst[1] = _mesa_unorm_to_unorm(g, 10, 8);
2912
2913
2914 dst[2] = _mesa_unorm_to_unorm(b, 10, 8);
2915
2916
2917 dst[3] = _mesa_unorm_to_unorm(a, 2, 8);
2918 }
2919
2920 static inline void
unpack_ubyte_r10g10b10x2_unorm(const void * void_src,GLubyte dst[4])2921 unpack_ubyte_r10g10b10x2_unorm(const void *void_src, GLubyte dst[4])
2922 {
2923 uint32_t *src = (uint32_t *)void_src;
2924 uint16_t r = UNPACK(*src, 0, 10);
2925 uint16_t g = UNPACK(*src, 10, 10);
2926 uint16_t b = UNPACK(*src, 20, 10);
2927
2928
2929
2930 dst[0] = _mesa_unorm_to_unorm(r, 10, 8);
2931
2932
2933 dst[1] = _mesa_unorm_to_unorm(g, 10, 8);
2934
2935
2936 dst[2] = _mesa_unorm_to_unorm(b, 10, 8);
2937
2938 dst[3] = 255;
2939 }
2940
2941 static inline void
unpack_ubyte_r3g3b2_unorm(const void * void_src,GLubyte dst[4])2942 unpack_ubyte_r3g3b2_unorm(const void *void_src, GLubyte dst[4])
2943 {
2944 uint8_t *src = (uint8_t *)void_src;
2945 uint8_t r = UNPACK(*src, 0, 3);
2946 uint8_t g = UNPACK(*src, 3, 3);
2947 uint8_t b = UNPACK(*src, 6, 2);
2948
2949
2950
2951 dst[0] = _mesa_unorm_to_unorm(r, 3, 8);
2952
2953
2954 dst[1] = _mesa_unorm_to_unorm(g, 3, 8);
2955
2956
2957 dst[2] = _mesa_unorm_to_unorm(b, 2, 8);
2958
2959 dst[3] = 255;
2960 }
2961
2962 static inline void
unpack_ubyte_a4b4g4r4_unorm(const void * void_src,GLubyte dst[4])2963 unpack_ubyte_a4b4g4r4_unorm(const void *void_src, GLubyte dst[4])
2964 {
2965 uint16_t *src = (uint16_t *)void_src;
2966 uint8_t a = UNPACK(*src, 0, 4);
2967 uint8_t b = UNPACK(*src, 4, 4);
2968 uint8_t g = UNPACK(*src, 8, 4);
2969 uint8_t r = UNPACK(*src, 12, 4);
2970
2971
2972
2973 dst[0] = _mesa_unorm_to_unorm(r, 4, 8);
2974
2975
2976 dst[1] = _mesa_unorm_to_unorm(g, 4, 8);
2977
2978
2979 dst[2] = _mesa_unorm_to_unorm(b, 4, 8);
2980
2981
2982 dst[3] = _mesa_unorm_to_unorm(a, 4, 8);
2983 }
2984
2985 static inline void
unpack_ubyte_r4g4b4a4_unorm(const void * void_src,GLubyte dst[4])2986 unpack_ubyte_r4g4b4a4_unorm(const void *void_src, GLubyte dst[4])
2987 {
2988 uint16_t *src = (uint16_t *)void_src;
2989 uint8_t r = UNPACK(*src, 0, 4);
2990 uint8_t g = UNPACK(*src, 4, 4);
2991 uint8_t b = UNPACK(*src, 8, 4);
2992 uint8_t a = UNPACK(*src, 12, 4);
2993
2994
2995
2996 dst[0] = _mesa_unorm_to_unorm(r, 4, 8);
2997
2998
2999 dst[1] = _mesa_unorm_to_unorm(g, 4, 8);
3000
3001
3002 dst[2] = _mesa_unorm_to_unorm(b, 4, 8);
3003
3004
3005 dst[3] = _mesa_unorm_to_unorm(a, 4, 8);
3006 }
3007
3008 static inline void
unpack_ubyte_r5g5b5a1_unorm(const void * void_src,GLubyte dst[4])3009 unpack_ubyte_r5g5b5a1_unorm(const void *void_src, GLubyte dst[4])
3010 {
3011 uint16_t *src = (uint16_t *)void_src;
3012 uint8_t r = UNPACK(*src, 0, 5);
3013 uint8_t g = UNPACK(*src, 5, 5);
3014 uint8_t b = UNPACK(*src, 10, 5);
3015 uint8_t a = UNPACK(*src, 15, 1);
3016
3017
3018
3019 dst[0] = _mesa_unorm_to_unorm(r, 5, 8);
3020
3021
3022 dst[1] = _mesa_unorm_to_unorm(g, 5, 8);
3023
3024
3025 dst[2] = _mesa_unorm_to_unorm(b, 5, 8);
3026
3027
3028 dst[3] = _mesa_unorm_to_unorm(a, 1, 8);
3029 }
3030
3031 static inline void
unpack_ubyte_a2b10g10r10_unorm(const void * void_src,GLubyte dst[4])3032 unpack_ubyte_a2b10g10r10_unorm(const void *void_src, GLubyte dst[4])
3033 {
3034 uint32_t *src = (uint32_t *)void_src;
3035 uint8_t a = UNPACK(*src, 0, 2);
3036 uint16_t b = UNPACK(*src, 2, 10);
3037 uint16_t g = UNPACK(*src, 12, 10);
3038 uint16_t r = UNPACK(*src, 22, 10);
3039
3040
3041
3042 dst[0] = _mesa_unorm_to_unorm(r, 10, 8);
3043
3044
3045 dst[1] = _mesa_unorm_to_unorm(g, 10, 8);
3046
3047
3048 dst[2] = _mesa_unorm_to_unorm(b, 10, 8);
3049
3050
3051 dst[3] = _mesa_unorm_to_unorm(a, 2, 8);
3052 }
3053
3054 static inline void
unpack_ubyte_a2r10g10b10_unorm(const void * void_src,GLubyte dst[4])3055 unpack_ubyte_a2r10g10b10_unorm(const void *void_src, GLubyte dst[4])
3056 {
3057 uint32_t *src = (uint32_t *)void_src;
3058 uint8_t a = UNPACK(*src, 0, 2);
3059 uint16_t r = UNPACK(*src, 2, 10);
3060 uint16_t g = UNPACK(*src, 12, 10);
3061 uint16_t b = UNPACK(*src, 22, 10);
3062
3063
3064
3065 dst[0] = _mesa_unorm_to_unorm(r, 10, 8);
3066
3067
3068 dst[1] = _mesa_unorm_to_unorm(g, 10, 8);
3069
3070
3071 dst[2] = _mesa_unorm_to_unorm(b, 10, 8);
3072
3073
3074 dst[3] = _mesa_unorm_to_unorm(a, 2, 8);
3075 }
3076
3077 static inline void
unpack_ubyte_a_unorm8(const void * void_src,GLubyte dst[4])3078 unpack_ubyte_a_unorm8(const void *void_src, GLubyte dst[4])
3079 {
3080 uint8_t *src = (uint8_t *)void_src;
3081 uint8_t a = src[0];
3082
3083
3084 dst[0] = 0;
3085
3086 dst[1] = 0;
3087
3088 dst[2] = 0;
3089
3090
3091 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
3092 }
3093
3094 static inline void
unpack_ubyte_a_unorm16(const void * void_src,GLubyte dst[4])3095 unpack_ubyte_a_unorm16(const void *void_src, GLubyte dst[4])
3096 {
3097 uint16_t *src = (uint16_t *)void_src;
3098 uint16_t a = src[0];
3099
3100
3101 dst[0] = 0;
3102
3103 dst[1] = 0;
3104
3105 dst[2] = 0;
3106
3107
3108 dst[3] = _mesa_unorm_to_unorm(a, 16, 8);
3109 }
3110
3111 static inline void
unpack_ubyte_l_unorm8(const void * void_src,GLubyte dst[4])3112 unpack_ubyte_l_unorm8(const void *void_src, GLubyte dst[4])
3113 {
3114 uint8_t *src = (uint8_t *)void_src;
3115 uint8_t l = src[0];
3116
3117
3118
3119 dst[0] = _mesa_unorm_to_unorm(l, 8, 8);
3120
3121
3122 dst[1] = _mesa_unorm_to_unorm(l, 8, 8);
3123
3124
3125 dst[2] = _mesa_unorm_to_unorm(l, 8, 8);
3126
3127 dst[3] = 255;
3128 }
3129
3130 static inline void
unpack_ubyte_l_unorm16(const void * void_src,GLubyte dst[4])3131 unpack_ubyte_l_unorm16(const void *void_src, GLubyte dst[4])
3132 {
3133 uint16_t *src = (uint16_t *)void_src;
3134 uint16_t l = src[0];
3135
3136
3137
3138 dst[0] = _mesa_unorm_to_unorm(l, 16, 8);
3139
3140
3141 dst[1] = _mesa_unorm_to_unorm(l, 16, 8);
3142
3143
3144 dst[2] = _mesa_unorm_to_unorm(l, 16, 8);
3145
3146 dst[3] = 255;
3147 }
3148
3149 static inline void
unpack_ubyte_i_unorm8(const void * void_src,GLubyte dst[4])3150 unpack_ubyte_i_unorm8(const void *void_src, GLubyte dst[4])
3151 {
3152 uint8_t *src = (uint8_t *)void_src;
3153 uint8_t i = src[0];
3154
3155
3156
3157 dst[0] = _mesa_unorm_to_unorm(i, 8, 8);
3158
3159
3160 dst[1] = _mesa_unorm_to_unorm(i, 8, 8);
3161
3162
3163 dst[2] = _mesa_unorm_to_unorm(i, 8, 8);
3164
3165
3166 dst[3] = _mesa_unorm_to_unorm(i, 8, 8);
3167 }
3168
3169 static inline void
unpack_ubyte_i_unorm16(const void * void_src,GLubyte dst[4])3170 unpack_ubyte_i_unorm16(const void *void_src, GLubyte dst[4])
3171 {
3172 uint16_t *src = (uint16_t *)void_src;
3173 uint16_t i = src[0];
3174
3175
3176
3177 dst[0] = _mesa_unorm_to_unorm(i, 16, 8);
3178
3179
3180 dst[1] = _mesa_unorm_to_unorm(i, 16, 8);
3181
3182
3183 dst[2] = _mesa_unorm_to_unorm(i, 16, 8);
3184
3185
3186 dst[3] = _mesa_unorm_to_unorm(i, 16, 8);
3187 }
3188
3189 static inline void
unpack_ubyte_r_unorm8(const void * void_src,GLubyte dst[4])3190 unpack_ubyte_r_unorm8(const void *void_src, GLubyte dst[4])
3191 {
3192 uint8_t *src = (uint8_t *)void_src;
3193 uint8_t r = src[0];
3194
3195
3196
3197 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
3198
3199 dst[1] = 0;
3200
3201 dst[2] = 0;
3202
3203 dst[3] = 255;
3204 }
3205
3206 static inline void
unpack_ubyte_r_unorm16(const void * void_src,GLubyte dst[4])3207 unpack_ubyte_r_unorm16(const void *void_src, GLubyte dst[4])
3208 {
3209 uint16_t *src = (uint16_t *)void_src;
3210 uint16_t r = src[0];
3211
3212
3213
3214 dst[0] = _mesa_unorm_to_unorm(r, 16, 8);
3215
3216 dst[1] = 0;
3217
3218 dst[2] = 0;
3219
3220 dst[3] = 255;
3221 }
3222
3223 static inline void
unpack_ubyte_bgr_unorm8(const void * void_src,GLubyte dst[4])3224 unpack_ubyte_bgr_unorm8(const void *void_src, GLubyte dst[4])
3225 {
3226 uint8_t *src = (uint8_t *)void_src;
3227 uint8_t b = src[0];
3228 uint8_t g = src[1];
3229 uint8_t r = src[2];
3230
3231
3232
3233 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
3234
3235
3236 dst[1] = _mesa_unorm_to_unorm(g, 8, 8);
3237
3238
3239 dst[2] = _mesa_unorm_to_unorm(b, 8, 8);
3240
3241 dst[3] = 255;
3242 }
3243
3244 static inline void
unpack_ubyte_rgb_unorm8(const void * void_src,GLubyte dst[4])3245 unpack_ubyte_rgb_unorm8(const void *void_src, GLubyte dst[4])
3246 {
3247 uint8_t *src = (uint8_t *)void_src;
3248 uint8_t r = src[0];
3249 uint8_t g = src[1];
3250 uint8_t b = src[2];
3251
3252
3253
3254 dst[0] = _mesa_unorm_to_unorm(r, 8, 8);
3255
3256
3257 dst[1] = _mesa_unorm_to_unorm(g, 8, 8);
3258
3259
3260 dst[2] = _mesa_unorm_to_unorm(b, 8, 8);
3261
3262 dst[3] = 255;
3263 }
3264
3265 static inline void
unpack_ubyte_rgba_unorm16(const void * void_src,GLubyte dst[4])3266 unpack_ubyte_rgba_unorm16(const void *void_src, GLubyte dst[4])
3267 {
3268 uint16_t *src = (uint16_t *)void_src;
3269 uint16_t r = src[0];
3270 uint16_t g = src[1];
3271 uint16_t b = src[2];
3272 uint16_t a = src[3];
3273
3274
3275
3276 dst[0] = _mesa_unorm_to_unorm(r, 16, 8);
3277
3278
3279 dst[1] = _mesa_unorm_to_unorm(g, 16, 8);
3280
3281
3282 dst[2] = _mesa_unorm_to_unorm(b, 16, 8);
3283
3284
3285 dst[3] = _mesa_unorm_to_unorm(a, 16, 8);
3286 }
3287
3288 static inline void
unpack_ubyte_rgbx_unorm16(const void * void_src,GLubyte dst[4])3289 unpack_ubyte_rgbx_unorm16(const void *void_src, GLubyte dst[4])
3290 {
3291 uint16_t *src = (uint16_t *)void_src;
3292 uint16_t r = src[0];
3293 uint16_t g = src[1];
3294 uint16_t b = src[2];
3295
3296
3297
3298 dst[0] = _mesa_unorm_to_unorm(r, 16, 8);
3299
3300
3301 dst[1] = _mesa_unorm_to_unorm(g, 16, 8);
3302
3303
3304 dst[2] = _mesa_unorm_to_unorm(b, 16, 8);
3305
3306 dst[3] = 255;
3307 }
3308
3309 static inline void
unpack_ubyte_a8b8g8r8_snorm(const void * void_src,GLubyte dst[4])3310 unpack_ubyte_a8b8g8r8_snorm(const void *void_src, GLubyte dst[4])
3311 {
3312 uint32_t *src = (uint32_t *)void_src;
3313 int8_t a = UNPACK(*src, 0, 8);
3314 int8_t b = UNPACK(*src, 8, 8);
3315 int8_t g = UNPACK(*src, 16, 8);
3316 int8_t r = UNPACK(*src, 24, 8);
3317
3318
3319
3320 dst[0] = _mesa_snorm_to_unorm(r, 8, 8);
3321
3322
3323 dst[1] = _mesa_snorm_to_unorm(g, 8, 8);
3324
3325
3326 dst[2] = _mesa_snorm_to_unorm(b, 8, 8);
3327
3328
3329 dst[3] = _mesa_snorm_to_unorm(a, 8, 8);
3330 }
3331
3332 static inline void
unpack_ubyte_x8b8g8r8_snorm(const void * void_src,GLubyte dst[4])3333 unpack_ubyte_x8b8g8r8_snorm(const void *void_src, GLubyte dst[4])
3334 {
3335 uint32_t *src = (uint32_t *)void_src;
3336 int8_t b = UNPACK(*src, 8, 8);
3337 int8_t g = UNPACK(*src, 16, 8);
3338 int8_t r = UNPACK(*src, 24, 8);
3339
3340
3341
3342 dst[0] = _mesa_snorm_to_unorm(r, 8, 8);
3343
3344
3345 dst[1] = _mesa_snorm_to_unorm(g, 8, 8);
3346
3347
3348 dst[2] = _mesa_snorm_to_unorm(b, 8, 8);
3349
3350 dst[3] = 255;
3351 }
3352
3353 static inline void
unpack_ubyte_r8g8b8a8_snorm(const void * void_src,GLubyte dst[4])3354 unpack_ubyte_r8g8b8a8_snorm(const void *void_src, GLubyte dst[4])
3355 {
3356 uint32_t *src = (uint32_t *)void_src;
3357 int8_t r = UNPACK(*src, 0, 8);
3358 int8_t g = UNPACK(*src, 8, 8);
3359 int8_t b = UNPACK(*src, 16, 8);
3360 int8_t a = UNPACK(*src, 24, 8);
3361
3362
3363
3364 dst[0] = _mesa_snorm_to_unorm(r, 8, 8);
3365
3366
3367 dst[1] = _mesa_snorm_to_unorm(g, 8, 8);
3368
3369
3370 dst[2] = _mesa_snorm_to_unorm(b, 8, 8);
3371
3372
3373 dst[3] = _mesa_snorm_to_unorm(a, 8, 8);
3374 }
3375
3376 static inline void
unpack_ubyte_r8g8b8x8_snorm(const void * void_src,GLubyte dst[4])3377 unpack_ubyte_r8g8b8x8_snorm(const void *void_src, GLubyte dst[4])
3378 {
3379 uint32_t *src = (uint32_t *)void_src;
3380 int8_t r = UNPACK(*src, 0, 8);
3381 int8_t g = UNPACK(*src, 8, 8);
3382 int8_t b = UNPACK(*src, 16, 8);
3383
3384
3385
3386 dst[0] = _mesa_snorm_to_unorm(r, 8, 8);
3387
3388
3389 dst[1] = _mesa_snorm_to_unorm(g, 8, 8);
3390
3391
3392 dst[2] = _mesa_snorm_to_unorm(b, 8, 8);
3393
3394 dst[3] = 255;
3395 }
3396
3397 static inline void
unpack_ubyte_r16g16_snorm(const void * void_src,GLubyte dst[4])3398 unpack_ubyte_r16g16_snorm(const void *void_src, GLubyte dst[4])
3399 {
3400 uint32_t *src = (uint32_t *)void_src;
3401 int16_t r = UNPACK(*src, 0, 16);
3402 int16_t g = UNPACK(*src, 16, 16);
3403
3404
3405
3406 dst[0] = _mesa_snorm_to_unorm(r, 16, 8);
3407
3408
3409 dst[1] = _mesa_snorm_to_unorm(g, 16, 8);
3410
3411 dst[2] = 0;
3412
3413 dst[3] = 255;
3414 }
3415
3416 static inline void
unpack_ubyte_g16r16_snorm(const void * void_src,GLubyte dst[4])3417 unpack_ubyte_g16r16_snorm(const void *void_src, GLubyte dst[4])
3418 {
3419 uint32_t *src = (uint32_t *)void_src;
3420 int16_t g = UNPACK(*src, 0, 16);
3421 int16_t r = UNPACK(*src, 16, 16);
3422
3423
3424
3425 dst[0] = _mesa_snorm_to_unorm(r, 16, 8);
3426
3427
3428 dst[1] = _mesa_snorm_to_unorm(g, 16, 8);
3429
3430 dst[2] = 0;
3431
3432 dst[3] = 255;
3433 }
3434
3435 static inline void
unpack_ubyte_r8g8_snorm(const void * void_src,GLubyte dst[4])3436 unpack_ubyte_r8g8_snorm(const void *void_src, GLubyte dst[4])
3437 {
3438 uint16_t *src = (uint16_t *)void_src;
3439 int8_t r = UNPACK(*src, 0, 8);
3440 int8_t g = UNPACK(*src, 8, 8);
3441
3442
3443
3444 dst[0] = _mesa_snorm_to_unorm(r, 8, 8);
3445
3446
3447 dst[1] = _mesa_snorm_to_unorm(g, 8, 8);
3448
3449 dst[2] = 0;
3450
3451 dst[3] = 255;
3452 }
3453
3454 static inline void
unpack_ubyte_g8r8_snorm(const void * void_src,GLubyte dst[4])3455 unpack_ubyte_g8r8_snorm(const void *void_src, GLubyte dst[4])
3456 {
3457 uint16_t *src = (uint16_t *)void_src;
3458 int8_t g = UNPACK(*src, 0, 8);
3459 int8_t r = UNPACK(*src, 8, 8);
3460
3461
3462
3463 dst[0] = _mesa_snorm_to_unorm(r, 8, 8);
3464
3465
3466 dst[1] = _mesa_snorm_to_unorm(g, 8, 8);
3467
3468 dst[2] = 0;
3469
3470 dst[3] = 255;
3471 }
3472
3473 static inline void
unpack_ubyte_l8a8_snorm(const void * void_src,GLubyte dst[4])3474 unpack_ubyte_l8a8_snorm(const void *void_src, GLubyte dst[4])
3475 {
3476 uint16_t *src = (uint16_t *)void_src;
3477 int8_t l = UNPACK(*src, 0, 8);
3478 int8_t a = UNPACK(*src, 8, 8);
3479
3480
3481
3482 dst[0] = _mesa_snorm_to_unorm(l, 8, 8);
3483
3484
3485 dst[1] = _mesa_snorm_to_unorm(l, 8, 8);
3486
3487
3488 dst[2] = _mesa_snorm_to_unorm(l, 8, 8);
3489
3490
3491 dst[3] = _mesa_snorm_to_unorm(a, 8, 8);
3492 }
3493
3494 static inline void
unpack_ubyte_a8l8_snorm(const void * void_src,GLubyte dst[4])3495 unpack_ubyte_a8l8_snorm(const void *void_src, GLubyte dst[4])
3496 {
3497 uint16_t *src = (uint16_t *)void_src;
3498 int8_t a = UNPACK(*src, 0, 8);
3499 int8_t l = UNPACK(*src, 8, 8);
3500
3501
3502
3503 dst[0] = _mesa_snorm_to_unorm(l, 8, 8);
3504
3505
3506 dst[1] = _mesa_snorm_to_unorm(l, 8, 8);
3507
3508
3509 dst[2] = _mesa_snorm_to_unorm(l, 8, 8);
3510
3511
3512 dst[3] = _mesa_snorm_to_unorm(a, 8, 8);
3513 }
3514
3515 static inline void
unpack_ubyte_a_snorm8(const void * void_src,GLubyte dst[4])3516 unpack_ubyte_a_snorm8(const void *void_src, GLubyte dst[4])
3517 {
3518 int8_t *src = (int8_t *)void_src;
3519 int8_t a = src[0];
3520
3521
3522 dst[0] = 0;
3523
3524 dst[1] = 0;
3525
3526 dst[2] = 0;
3527
3528
3529 dst[3] = _mesa_snorm_to_unorm(a, 8, 8);
3530 }
3531
3532 static inline void
unpack_ubyte_a_snorm16(const void * void_src,GLubyte dst[4])3533 unpack_ubyte_a_snorm16(const void *void_src, GLubyte dst[4])
3534 {
3535 int16_t *src = (int16_t *)void_src;
3536 int16_t a = src[0];
3537
3538
3539 dst[0] = 0;
3540
3541 dst[1] = 0;
3542
3543 dst[2] = 0;
3544
3545
3546 dst[3] = _mesa_snorm_to_unorm(a, 16, 8);
3547 }
3548
3549 static inline void
unpack_ubyte_l_snorm8(const void * void_src,GLubyte dst[4])3550 unpack_ubyte_l_snorm8(const void *void_src, GLubyte dst[4])
3551 {
3552 int8_t *src = (int8_t *)void_src;
3553 int8_t l = src[0];
3554
3555
3556
3557 dst[0] = _mesa_snorm_to_unorm(l, 8, 8);
3558
3559
3560 dst[1] = _mesa_snorm_to_unorm(l, 8, 8);
3561
3562
3563 dst[2] = _mesa_snorm_to_unorm(l, 8, 8);
3564
3565 dst[3] = 255;
3566 }
3567
3568 static inline void
unpack_ubyte_l_snorm16(const void * void_src,GLubyte dst[4])3569 unpack_ubyte_l_snorm16(const void *void_src, GLubyte dst[4])
3570 {
3571 int16_t *src = (int16_t *)void_src;
3572 int16_t l = src[0];
3573
3574
3575
3576 dst[0] = _mesa_snorm_to_unorm(l, 16, 8);
3577
3578
3579 dst[1] = _mesa_snorm_to_unorm(l, 16, 8);
3580
3581
3582 dst[2] = _mesa_snorm_to_unorm(l, 16, 8);
3583
3584 dst[3] = 255;
3585 }
3586
3587 static inline void
unpack_ubyte_i_snorm8(const void * void_src,GLubyte dst[4])3588 unpack_ubyte_i_snorm8(const void *void_src, GLubyte dst[4])
3589 {
3590 int8_t *src = (int8_t *)void_src;
3591 int8_t i = src[0];
3592
3593
3594
3595 dst[0] = _mesa_snorm_to_unorm(i, 8, 8);
3596
3597
3598 dst[1] = _mesa_snorm_to_unorm(i, 8, 8);
3599
3600
3601 dst[2] = _mesa_snorm_to_unorm(i, 8, 8);
3602
3603
3604 dst[3] = _mesa_snorm_to_unorm(i, 8, 8);
3605 }
3606
3607 static inline void
unpack_ubyte_i_snorm16(const void * void_src,GLubyte dst[4])3608 unpack_ubyte_i_snorm16(const void *void_src, GLubyte dst[4])
3609 {
3610 int16_t *src = (int16_t *)void_src;
3611 int16_t i = src[0];
3612
3613
3614
3615 dst[0] = _mesa_snorm_to_unorm(i, 16, 8);
3616
3617
3618 dst[1] = _mesa_snorm_to_unorm(i, 16, 8);
3619
3620
3621 dst[2] = _mesa_snorm_to_unorm(i, 16, 8);
3622
3623
3624 dst[3] = _mesa_snorm_to_unorm(i, 16, 8);
3625 }
3626
3627 static inline void
unpack_ubyte_r_snorm8(const void * void_src,GLubyte dst[4])3628 unpack_ubyte_r_snorm8(const void *void_src, GLubyte dst[4])
3629 {
3630 int8_t *src = (int8_t *)void_src;
3631 int8_t r = src[0];
3632
3633
3634
3635 dst[0] = _mesa_snorm_to_unorm(r, 8, 8);
3636
3637 dst[1] = 0;
3638
3639 dst[2] = 0;
3640
3641 dst[3] = 255;
3642 }
3643
3644 static inline void
unpack_ubyte_r_snorm16(const void * void_src,GLubyte dst[4])3645 unpack_ubyte_r_snorm16(const void *void_src, GLubyte dst[4])
3646 {
3647 int16_t *src = (int16_t *)void_src;
3648 int16_t r = src[0];
3649
3650
3651
3652 dst[0] = _mesa_snorm_to_unorm(r, 16, 8);
3653
3654 dst[1] = 0;
3655
3656 dst[2] = 0;
3657
3658 dst[3] = 255;
3659 }
3660
3661 static inline void
unpack_ubyte_la_snorm16(const void * void_src,GLubyte dst[4])3662 unpack_ubyte_la_snorm16(const void *void_src, GLubyte dst[4])
3663 {
3664 int16_t *src = (int16_t *)void_src;
3665 int16_t l = src[0];
3666 int16_t a = src[1];
3667
3668
3669
3670 dst[0] = _mesa_snorm_to_unorm(l, 16, 8);
3671
3672
3673 dst[1] = _mesa_snorm_to_unorm(l, 16, 8);
3674
3675
3676 dst[2] = _mesa_snorm_to_unorm(l, 16, 8);
3677
3678
3679 dst[3] = _mesa_snorm_to_unorm(a, 16, 8);
3680 }
3681
3682 static inline void
unpack_ubyte_rgb_snorm16(const void * void_src,GLubyte dst[4])3683 unpack_ubyte_rgb_snorm16(const void *void_src, GLubyte dst[4])
3684 {
3685 int16_t *src = (int16_t *)void_src;
3686 int16_t r = src[0];
3687 int16_t g = src[1];
3688 int16_t b = src[2];
3689
3690
3691
3692 dst[0] = _mesa_snorm_to_unorm(r, 16, 8);
3693
3694
3695 dst[1] = _mesa_snorm_to_unorm(g, 16, 8);
3696
3697
3698 dst[2] = _mesa_snorm_to_unorm(b, 16, 8);
3699
3700 dst[3] = 255;
3701 }
3702
3703 static inline void
unpack_ubyte_rgba_snorm16(const void * void_src,GLubyte dst[4])3704 unpack_ubyte_rgba_snorm16(const void *void_src, GLubyte dst[4])
3705 {
3706 int16_t *src = (int16_t *)void_src;
3707 int16_t r = src[0];
3708 int16_t g = src[1];
3709 int16_t b = src[2];
3710 int16_t a = src[3];
3711
3712
3713
3714 dst[0] = _mesa_snorm_to_unorm(r, 16, 8);
3715
3716
3717 dst[1] = _mesa_snorm_to_unorm(g, 16, 8);
3718
3719
3720 dst[2] = _mesa_snorm_to_unorm(b, 16, 8);
3721
3722
3723 dst[3] = _mesa_snorm_to_unorm(a, 16, 8);
3724 }
3725
3726 static inline void
unpack_ubyte_rgbx_snorm16(const void * void_src,GLubyte dst[4])3727 unpack_ubyte_rgbx_snorm16(const void *void_src, GLubyte dst[4])
3728 {
3729 int16_t *src = (int16_t *)void_src;
3730 int16_t r = src[0];
3731 int16_t g = src[1];
3732 int16_t b = src[2];
3733
3734
3735
3736 dst[0] = _mesa_snorm_to_unorm(r, 16, 8);
3737
3738
3739 dst[1] = _mesa_snorm_to_unorm(g, 16, 8);
3740
3741
3742 dst[2] = _mesa_snorm_to_unorm(b, 16, 8);
3743
3744 dst[3] = 255;
3745 }
3746
3747 static inline void
unpack_ubyte_a8b8g8r8_srgb(const void * void_src,GLubyte dst[4])3748 unpack_ubyte_a8b8g8r8_srgb(const void *void_src, GLubyte dst[4])
3749 {
3750 uint32_t *src = (uint32_t *)void_src;
3751 uint8_t a = UNPACK(*src, 0, 8);
3752 uint8_t b = UNPACK(*src, 8, 8);
3753 uint8_t g = UNPACK(*src, 16, 8);
3754 uint8_t r = UNPACK(*src, 24, 8);
3755
3756
3757
3758
3759 dst[0] = util_format_srgb_to_linear_8unorm(r);
3760
3761
3762
3763 dst[1] = util_format_srgb_to_linear_8unorm(g);
3764
3765
3766
3767 dst[2] = util_format_srgb_to_linear_8unorm(b);
3768
3769
3770 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
3771 }
3772
3773 static inline void
unpack_ubyte_b8g8r8a8_srgb(const void * void_src,GLubyte dst[4])3774 unpack_ubyte_b8g8r8a8_srgb(const void *void_src, GLubyte dst[4])
3775 {
3776 uint32_t *src = (uint32_t *)void_src;
3777 uint8_t b = UNPACK(*src, 0, 8);
3778 uint8_t g = UNPACK(*src, 8, 8);
3779 uint8_t r = UNPACK(*src, 16, 8);
3780 uint8_t a = UNPACK(*src, 24, 8);
3781
3782
3783
3784
3785 dst[0] = util_format_srgb_to_linear_8unorm(r);
3786
3787
3788
3789 dst[1] = util_format_srgb_to_linear_8unorm(g);
3790
3791
3792
3793 dst[2] = util_format_srgb_to_linear_8unorm(b);
3794
3795
3796 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
3797 }
3798
3799 static inline void
unpack_ubyte_a8r8g8b8_srgb(const void * void_src,GLubyte dst[4])3800 unpack_ubyte_a8r8g8b8_srgb(const void *void_src, GLubyte dst[4])
3801 {
3802 uint32_t *src = (uint32_t *)void_src;
3803 uint8_t a = UNPACK(*src, 0, 8);
3804 uint8_t r = UNPACK(*src, 8, 8);
3805 uint8_t g = UNPACK(*src, 16, 8);
3806 uint8_t b = UNPACK(*src, 24, 8);
3807
3808
3809
3810
3811 dst[0] = util_format_srgb_to_linear_8unorm(r);
3812
3813
3814
3815 dst[1] = util_format_srgb_to_linear_8unorm(g);
3816
3817
3818
3819 dst[2] = util_format_srgb_to_linear_8unorm(b);
3820
3821
3822 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
3823 }
3824
3825 static inline void
unpack_ubyte_b8g8r8x8_srgb(const void * void_src,GLubyte dst[4])3826 unpack_ubyte_b8g8r8x8_srgb(const void *void_src, GLubyte dst[4])
3827 {
3828 uint32_t *src = (uint32_t *)void_src;
3829 uint8_t b = UNPACK(*src, 0, 8);
3830 uint8_t g = UNPACK(*src, 8, 8);
3831 uint8_t r = UNPACK(*src, 16, 8);
3832
3833
3834
3835
3836 dst[0] = util_format_srgb_to_linear_8unorm(r);
3837
3838
3839
3840 dst[1] = util_format_srgb_to_linear_8unorm(g);
3841
3842
3843
3844 dst[2] = util_format_srgb_to_linear_8unorm(b);
3845
3846 dst[3] = 255;
3847 }
3848
3849 static inline void
unpack_ubyte_x8r8g8b8_srgb(const void * void_src,GLubyte dst[4])3850 unpack_ubyte_x8r8g8b8_srgb(const void *void_src, GLubyte dst[4])
3851 {
3852 uint32_t *src = (uint32_t *)void_src;
3853 uint8_t r = UNPACK(*src, 8, 8);
3854 uint8_t g = UNPACK(*src, 16, 8);
3855 uint8_t b = UNPACK(*src, 24, 8);
3856
3857
3858
3859
3860 dst[0] = util_format_srgb_to_linear_8unorm(r);
3861
3862
3863
3864 dst[1] = util_format_srgb_to_linear_8unorm(g);
3865
3866
3867
3868 dst[2] = util_format_srgb_to_linear_8unorm(b);
3869
3870 dst[3] = 255;
3871 }
3872
3873 static inline void
unpack_ubyte_r8g8b8a8_srgb(const void * void_src,GLubyte dst[4])3874 unpack_ubyte_r8g8b8a8_srgb(const void *void_src, GLubyte dst[4])
3875 {
3876 uint32_t *src = (uint32_t *)void_src;
3877 uint8_t r = UNPACK(*src, 0, 8);
3878 uint8_t g = UNPACK(*src, 8, 8);
3879 uint8_t b = UNPACK(*src, 16, 8);
3880 uint8_t a = UNPACK(*src, 24, 8);
3881
3882
3883
3884
3885 dst[0] = util_format_srgb_to_linear_8unorm(r);
3886
3887
3888
3889 dst[1] = util_format_srgb_to_linear_8unorm(g);
3890
3891
3892
3893 dst[2] = util_format_srgb_to_linear_8unorm(b);
3894
3895
3896 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
3897 }
3898
3899 static inline void
unpack_ubyte_r8g8b8x8_srgb(const void * void_src,GLubyte dst[4])3900 unpack_ubyte_r8g8b8x8_srgb(const void *void_src, GLubyte dst[4])
3901 {
3902 uint32_t *src = (uint32_t *)void_src;
3903 uint8_t r = UNPACK(*src, 0, 8);
3904 uint8_t g = UNPACK(*src, 8, 8);
3905 uint8_t b = UNPACK(*src, 16, 8);
3906
3907
3908
3909
3910 dst[0] = util_format_srgb_to_linear_8unorm(r);
3911
3912
3913
3914 dst[1] = util_format_srgb_to_linear_8unorm(g);
3915
3916
3917
3918 dst[2] = util_format_srgb_to_linear_8unorm(b);
3919
3920 dst[3] = 255;
3921 }
3922
3923 static inline void
unpack_ubyte_x8b8g8r8_srgb(const void * void_src,GLubyte dst[4])3924 unpack_ubyte_x8b8g8r8_srgb(const void *void_src, GLubyte dst[4])
3925 {
3926 uint32_t *src = (uint32_t *)void_src;
3927 uint8_t b = UNPACK(*src, 8, 8);
3928 uint8_t g = UNPACK(*src, 16, 8);
3929 uint8_t r = UNPACK(*src, 24, 8);
3930
3931
3932
3933
3934 dst[0] = util_format_srgb_to_linear_8unorm(r);
3935
3936
3937
3938 dst[1] = util_format_srgb_to_linear_8unorm(g);
3939
3940
3941
3942 dst[2] = util_format_srgb_to_linear_8unorm(b);
3943
3944 dst[3] = 255;
3945 }
3946
3947 static inline void
unpack_ubyte_l8a8_srgb(const void * void_src,GLubyte dst[4])3948 unpack_ubyte_l8a8_srgb(const void *void_src, GLubyte dst[4])
3949 {
3950 uint16_t *src = (uint16_t *)void_src;
3951 uint8_t l = UNPACK(*src, 0, 8);
3952 uint8_t a = UNPACK(*src, 8, 8);
3953
3954
3955
3956 dst[0] = _mesa_unorm_to_unorm(l, 8, 8);
3957
3958
3959 dst[1] = _mesa_unorm_to_unorm(l, 8, 8);
3960
3961
3962 dst[2] = _mesa_unorm_to_unorm(l, 8, 8);
3963
3964
3965 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
3966 }
3967
3968 static inline void
unpack_ubyte_a8l8_srgb(const void * void_src,GLubyte dst[4])3969 unpack_ubyte_a8l8_srgb(const void *void_src, GLubyte dst[4])
3970 {
3971 uint16_t *src = (uint16_t *)void_src;
3972 uint8_t a = UNPACK(*src, 0, 8);
3973 uint8_t l = UNPACK(*src, 8, 8);
3974
3975
3976
3977 dst[0] = _mesa_unorm_to_unorm(l, 8, 8);
3978
3979
3980 dst[1] = _mesa_unorm_to_unorm(l, 8, 8);
3981
3982
3983 dst[2] = _mesa_unorm_to_unorm(l, 8, 8);
3984
3985
3986 dst[3] = _mesa_unorm_to_unorm(a, 8, 8);
3987 }
3988
3989 static inline void
unpack_ubyte_l_srgb8(const void * void_src,GLubyte dst[4])3990 unpack_ubyte_l_srgb8(const void *void_src, GLubyte dst[4])
3991 {
3992 uint8_t *src = (uint8_t *)void_src;
3993 uint8_t l = src[0];
3994
3995
3996
3997 dst[0] = _mesa_unorm_to_unorm(l, 8, 8);
3998
3999
4000 dst[1] = _mesa_unorm_to_unorm(l, 8, 8);
4001
4002
4003 dst[2] = _mesa_unorm_to_unorm(l, 8, 8);
4004
4005 dst[3] = 255;
4006 }
4007
4008 static inline void
unpack_ubyte_bgr_srgb8(const void * void_src,GLubyte dst[4])4009 unpack_ubyte_bgr_srgb8(const void *void_src, GLubyte dst[4])
4010 {
4011 uint8_t *src = (uint8_t *)void_src;
4012 uint8_t b = src[0];
4013 uint8_t g = src[1];
4014 uint8_t r = src[2];
4015
4016
4017
4018
4019 dst[0] = util_format_srgb_to_linear_8unorm(r);
4020
4021
4022
4023 dst[1] = util_format_srgb_to_linear_8unorm(g);
4024
4025
4026
4027 dst[2] = util_format_srgb_to_linear_8unorm(b);
4028
4029 dst[3] = 255;
4030 }
4031
4032 /* integer packing functions */
4033
4034
4035 static inline void
unpack_int_a8b8g8r8_uint(const void * void_src,GLuint dst[4])4036 unpack_int_a8b8g8r8_uint(const void *void_src, GLuint dst[4])
4037 {
4038 uint32_t *src = (uint32_t *)void_src;
4039 uint8_t a = UNPACK(*src, 0, 8);
4040 uint8_t b = UNPACK(*src, 8, 8);
4041 uint8_t g = UNPACK(*src, 16, 8);
4042 uint8_t r = UNPACK(*src, 24, 8);
4043
4044
4045 dst[0] = r;
4046
4047 dst[1] = g;
4048
4049 dst[2] = b;
4050
4051 dst[3] = a;
4052 }
4053
4054 static inline void
unpack_int_a8r8g8b8_uint(const void * void_src,GLuint dst[4])4055 unpack_int_a8r8g8b8_uint(const void *void_src, GLuint dst[4])
4056 {
4057 uint32_t *src = (uint32_t *)void_src;
4058 uint8_t a = UNPACK(*src, 0, 8);
4059 uint8_t r = UNPACK(*src, 8, 8);
4060 uint8_t g = UNPACK(*src, 16, 8);
4061 uint8_t b = UNPACK(*src, 24, 8);
4062
4063
4064 dst[0] = r;
4065
4066 dst[1] = g;
4067
4068 dst[2] = b;
4069
4070 dst[3] = a;
4071 }
4072
4073 static inline void
unpack_int_r8g8b8a8_uint(const void * void_src,GLuint dst[4])4074 unpack_int_r8g8b8a8_uint(const void *void_src, GLuint dst[4])
4075 {
4076 uint32_t *src = (uint32_t *)void_src;
4077 uint8_t r = UNPACK(*src, 0, 8);
4078 uint8_t g = UNPACK(*src, 8, 8);
4079 uint8_t b = UNPACK(*src, 16, 8);
4080 uint8_t a = UNPACK(*src, 24, 8);
4081
4082
4083 dst[0] = r;
4084
4085 dst[1] = g;
4086
4087 dst[2] = b;
4088
4089 dst[3] = a;
4090 }
4091
4092 static inline void
unpack_int_b8g8r8a8_uint(const void * void_src,GLuint dst[4])4093 unpack_int_b8g8r8a8_uint(const void *void_src, GLuint dst[4])
4094 {
4095 uint32_t *src = (uint32_t *)void_src;
4096 uint8_t b = UNPACK(*src, 0, 8);
4097 uint8_t g = UNPACK(*src, 8, 8);
4098 uint8_t r = UNPACK(*src, 16, 8);
4099 uint8_t a = UNPACK(*src, 24, 8);
4100
4101
4102 dst[0] = r;
4103
4104 dst[1] = g;
4105
4106 dst[2] = b;
4107
4108 dst[3] = a;
4109 }
4110
4111 static inline void
unpack_int_b10g10r10a2_uint(const void * void_src,GLuint dst[4])4112 unpack_int_b10g10r10a2_uint(const void *void_src, GLuint dst[4])
4113 {
4114 uint32_t *src = (uint32_t *)void_src;
4115 uint16_t b = UNPACK(*src, 0, 10);
4116 uint16_t g = UNPACK(*src, 10, 10);
4117 uint16_t r = UNPACK(*src, 20, 10);
4118 uint8_t a = UNPACK(*src, 30, 2);
4119
4120
4121 dst[0] = r;
4122
4123 dst[1] = g;
4124
4125 dst[2] = b;
4126
4127 dst[3] = a;
4128 }
4129
4130 static inline void
unpack_int_r10g10b10a2_uint(const void * void_src,GLuint dst[4])4131 unpack_int_r10g10b10a2_uint(const void *void_src, GLuint dst[4])
4132 {
4133 uint32_t *src = (uint32_t *)void_src;
4134 uint16_t r = UNPACK(*src, 0, 10);
4135 uint16_t g = UNPACK(*src, 10, 10);
4136 uint16_t b = UNPACK(*src, 20, 10);
4137 uint8_t a = UNPACK(*src, 30, 2);
4138
4139
4140 dst[0] = r;
4141
4142 dst[1] = g;
4143
4144 dst[2] = b;
4145
4146 dst[3] = a;
4147 }
4148
4149 static inline void
unpack_int_a2b10g10r10_uint(const void * void_src,GLuint dst[4])4150 unpack_int_a2b10g10r10_uint(const void *void_src, GLuint dst[4])
4151 {
4152 uint32_t *src = (uint32_t *)void_src;
4153 uint8_t a = UNPACK(*src, 0, 2);
4154 uint16_t b = UNPACK(*src, 2, 10);
4155 uint16_t g = UNPACK(*src, 12, 10);
4156 uint16_t r = UNPACK(*src, 22, 10);
4157
4158
4159 dst[0] = r;
4160
4161 dst[1] = g;
4162
4163 dst[2] = b;
4164
4165 dst[3] = a;
4166 }
4167
4168 static inline void
unpack_int_a2r10g10b10_uint(const void * void_src,GLuint dst[4])4169 unpack_int_a2r10g10b10_uint(const void *void_src, GLuint dst[4])
4170 {
4171 uint32_t *src = (uint32_t *)void_src;
4172 uint8_t a = UNPACK(*src, 0, 2);
4173 uint16_t r = UNPACK(*src, 2, 10);
4174 uint16_t g = UNPACK(*src, 12, 10);
4175 uint16_t b = UNPACK(*src, 22, 10);
4176
4177
4178 dst[0] = r;
4179
4180 dst[1] = g;
4181
4182 dst[2] = b;
4183
4184 dst[3] = a;
4185 }
4186
4187 static inline void
unpack_int_b5g6r5_uint(const void * void_src,GLuint dst[4])4188 unpack_int_b5g6r5_uint(const void *void_src, GLuint dst[4])
4189 {
4190 uint16_t *src = (uint16_t *)void_src;
4191 uint8_t b = UNPACK(*src, 0, 5);
4192 uint8_t g = UNPACK(*src, 5, 6);
4193 uint8_t r = UNPACK(*src, 11, 5);
4194
4195
4196 dst[0] = r;
4197
4198 dst[1] = g;
4199
4200 dst[2] = b;
4201
4202 dst[3] = 1;
4203 }
4204
4205 static inline void
unpack_int_r5g6b5_uint(const void * void_src,GLuint dst[4])4206 unpack_int_r5g6b5_uint(const void *void_src, GLuint dst[4])
4207 {
4208 uint16_t *src = (uint16_t *)void_src;
4209 uint8_t r = UNPACK(*src, 0, 5);
4210 uint8_t g = UNPACK(*src, 5, 6);
4211 uint8_t b = UNPACK(*src, 11, 5);
4212
4213
4214 dst[0] = r;
4215
4216 dst[1] = g;
4217
4218 dst[2] = b;
4219
4220 dst[3] = 1;
4221 }
4222
4223 static inline void
unpack_int_b2g3r3_uint(const void * void_src,GLuint dst[4])4224 unpack_int_b2g3r3_uint(const void *void_src, GLuint dst[4])
4225 {
4226 uint8_t *src = (uint8_t *)void_src;
4227 uint8_t b = UNPACK(*src, 0, 2);
4228 uint8_t g = UNPACK(*src, 2, 3);
4229 uint8_t r = UNPACK(*src, 5, 3);
4230
4231
4232 dst[0] = r;
4233
4234 dst[1] = g;
4235
4236 dst[2] = b;
4237
4238 dst[3] = 1;
4239 }
4240
4241 static inline void
unpack_int_r3g3b2_uint(const void * void_src,GLuint dst[4])4242 unpack_int_r3g3b2_uint(const void *void_src, GLuint dst[4])
4243 {
4244 uint8_t *src = (uint8_t *)void_src;
4245 uint8_t r = UNPACK(*src, 0, 3);
4246 uint8_t g = UNPACK(*src, 3, 3);
4247 uint8_t b = UNPACK(*src, 6, 2);
4248
4249
4250 dst[0] = r;
4251
4252 dst[1] = g;
4253
4254 dst[2] = b;
4255
4256 dst[3] = 1;
4257 }
4258
4259 static inline void
unpack_int_a4b4g4r4_uint(const void * void_src,GLuint dst[4])4260 unpack_int_a4b4g4r4_uint(const void *void_src, GLuint dst[4])
4261 {
4262 uint16_t *src = (uint16_t *)void_src;
4263 uint8_t a = UNPACK(*src, 0, 4);
4264 uint8_t b = UNPACK(*src, 4, 4);
4265 uint8_t g = UNPACK(*src, 8, 4);
4266 uint8_t r = UNPACK(*src, 12, 4);
4267
4268
4269 dst[0] = r;
4270
4271 dst[1] = g;
4272
4273 dst[2] = b;
4274
4275 dst[3] = a;
4276 }
4277
4278 static inline void
unpack_int_r4g4b4a4_uint(const void * void_src,GLuint dst[4])4279 unpack_int_r4g4b4a4_uint(const void *void_src, GLuint dst[4])
4280 {
4281 uint16_t *src = (uint16_t *)void_src;
4282 uint8_t r = UNPACK(*src, 0, 4);
4283 uint8_t g = UNPACK(*src, 4, 4);
4284 uint8_t b = UNPACK(*src, 8, 4);
4285 uint8_t a = UNPACK(*src, 12, 4);
4286
4287
4288 dst[0] = r;
4289
4290 dst[1] = g;
4291
4292 dst[2] = b;
4293
4294 dst[3] = a;
4295 }
4296
4297 static inline void
unpack_int_b4g4r4a4_uint(const void * void_src,GLuint dst[4])4298 unpack_int_b4g4r4a4_uint(const void *void_src, GLuint dst[4])
4299 {
4300 uint16_t *src = (uint16_t *)void_src;
4301 uint8_t b = UNPACK(*src, 0, 4);
4302 uint8_t g = UNPACK(*src, 4, 4);
4303 uint8_t r = UNPACK(*src, 8, 4);
4304 uint8_t a = UNPACK(*src, 12, 4);
4305
4306
4307 dst[0] = r;
4308
4309 dst[1] = g;
4310
4311 dst[2] = b;
4312
4313 dst[3] = a;
4314 }
4315
4316 static inline void
unpack_int_a4r4g4b4_uint(const void * void_src,GLuint dst[4])4317 unpack_int_a4r4g4b4_uint(const void *void_src, GLuint dst[4])
4318 {
4319 uint16_t *src = (uint16_t *)void_src;
4320 uint8_t a = UNPACK(*src, 0, 4);
4321 uint8_t r = UNPACK(*src, 4, 4);
4322 uint8_t g = UNPACK(*src, 8, 4);
4323 uint8_t b = UNPACK(*src, 12, 4);
4324
4325
4326 dst[0] = r;
4327
4328 dst[1] = g;
4329
4330 dst[2] = b;
4331
4332 dst[3] = a;
4333 }
4334
4335 static inline void
unpack_int_a1b5g5r5_uint(const void * void_src,GLuint dst[4])4336 unpack_int_a1b5g5r5_uint(const void *void_src, GLuint dst[4])
4337 {
4338 uint16_t *src = (uint16_t *)void_src;
4339 uint8_t a = UNPACK(*src, 0, 1);
4340 uint8_t b = UNPACK(*src, 1, 5);
4341 uint8_t g = UNPACK(*src, 6, 5);
4342 uint8_t r = UNPACK(*src, 11, 5);
4343
4344
4345 dst[0] = r;
4346
4347 dst[1] = g;
4348
4349 dst[2] = b;
4350
4351 dst[3] = a;
4352 }
4353
4354 static inline void
unpack_int_b5g5r5a1_uint(const void * void_src,GLuint dst[4])4355 unpack_int_b5g5r5a1_uint(const void *void_src, GLuint dst[4])
4356 {
4357 uint16_t *src = (uint16_t *)void_src;
4358 uint8_t b = UNPACK(*src, 0, 5);
4359 uint8_t g = UNPACK(*src, 5, 5);
4360 uint8_t r = UNPACK(*src, 10, 5);
4361 uint8_t a = UNPACK(*src, 15, 1);
4362
4363
4364 dst[0] = r;
4365
4366 dst[1] = g;
4367
4368 dst[2] = b;
4369
4370 dst[3] = a;
4371 }
4372
4373 static inline void
unpack_int_a1r5g5b5_uint(const void * void_src,GLuint dst[4])4374 unpack_int_a1r5g5b5_uint(const void *void_src, GLuint dst[4])
4375 {
4376 uint16_t *src = (uint16_t *)void_src;
4377 uint8_t a = UNPACK(*src, 0, 1);
4378 uint8_t r = UNPACK(*src, 1, 5);
4379 uint8_t g = UNPACK(*src, 6, 5);
4380 uint8_t b = UNPACK(*src, 11, 5);
4381
4382
4383 dst[0] = r;
4384
4385 dst[1] = g;
4386
4387 dst[2] = b;
4388
4389 dst[3] = a;
4390 }
4391
4392 static inline void
unpack_int_r5g5b5a1_uint(const void * void_src,GLuint dst[4])4393 unpack_int_r5g5b5a1_uint(const void *void_src, GLuint dst[4])
4394 {
4395 uint16_t *src = (uint16_t *)void_src;
4396 uint8_t r = UNPACK(*src, 0, 5);
4397 uint8_t g = UNPACK(*src, 5, 5);
4398 uint8_t b = UNPACK(*src, 10, 5);
4399 uint8_t a = UNPACK(*src, 15, 1);
4400
4401
4402 dst[0] = r;
4403
4404 dst[1] = g;
4405
4406 dst[2] = b;
4407
4408 dst[3] = a;
4409 }
4410
4411 static inline void
unpack_int_a_uint8(const void * void_src,GLuint dst[4])4412 unpack_int_a_uint8(const void *void_src, GLuint dst[4])
4413 {
4414 uint8_t *src = (uint8_t *)void_src;
4415 uint8_t a = src[0];
4416
4417
4418 dst[0] = 0;
4419
4420 dst[1] = 0;
4421
4422 dst[2] = 0;
4423
4424 dst[3] = a;
4425 }
4426
4427 static inline void
unpack_int_a_uint16(const void * void_src,GLuint dst[4])4428 unpack_int_a_uint16(const void *void_src, GLuint dst[4])
4429 {
4430 uint16_t *src = (uint16_t *)void_src;
4431 uint16_t a = src[0];
4432
4433
4434 dst[0] = 0;
4435
4436 dst[1] = 0;
4437
4438 dst[2] = 0;
4439
4440 dst[3] = a;
4441 }
4442
4443 static inline void
unpack_int_a_uint32(const void * void_src,GLuint dst[4])4444 unpack_int_a_uint32(const void *void_src, GLuint dst[4])
4445 {
4446 uint32_t *src = (uint32_t *)void_src;
4447 uint32_t a = src[0];
4448
4449
4450 dst[0] = 0;
4451
4452 dst[1] = 0;
4453
4454 dst[2] = 0;
4455
4456 dst[3] = a;
4457 }
4458
4459 static inline void
unpack_int_a_sint8(const void * void_src,GLuint dst[4])4460 unpack_int_a_sint8(const void *void_src, GLuint dst[4])
4461 {
4462 int8_t *src = (int8_t *)void_src;
4463 int8_t a = src[0];
4464
4465
4466 dst[0] = 0;
4467
4468 dst[1] = 0;
4469
4470 dst[2] = 0;
4471
4472 dst[3] = a;
4473 }
4474
4475 static inline void
unpack_int_a_sint16(const void * void_src,GLuint dst[4])4476 unpack_int_a_sint16(const void *void_src, GLuint dst[4])
4477 {
4478 int16_t *src = (int16_t *)void_src;
4479 int16_t a = src[0];
4480
4481
4482 dst[0] = 0;
4483
4484 dst[1] = 0;
4485
4486 dst[2] = 0;
4487
4488 dst[3] = a;
4489 }
4490
4491 static inline void
unpack_int_a_sint32(const void * void_src,GLuint dst[4])4492 unpack_int_a_sint32(const void *void_src, GLuint dst[4])
4493 {
4494 int32_t *src = (int32_t *)void_src;
4495 int32_t a = src[0];
4496
4497
4498 dst[0] = 0;
4499
4500 dst[1] = 0;
4501
4502 dst[2] = 0;
4503
4504 dst[3] = a;
4505 }
4506
4507 static inline void
unpack_int_i_uint8(const void * void_src,GLuint dst[4])4508 unpack_int_i_uint8(const void *void_src, GLuint dst[4])
4509 {
4510 uint8_t *src = (uint8_t *)void_src;
4511 uint8_t i = src[0];
4512
4513
4514 dst[0] = i;
4515
4516 dst[1] = i;
4517
4518 dst[2] = i;
4519
4520 dst[3] = i;
4521 }
4522
4523 static inline void
unpack_int_i_uint16(const void * void_src,GLuint dst[4])4524 unpack_int_i_uint16(const void *void_src, GLuint dst[4])
4525 {
4526 uint16_t *src = (uint16_t *)void_src;
4527 uint16_t i = src[0];
4528
4529
4530 dst[0] = i;
4531
4532 dst[1] = i;
4533
4534 dst[2] = i;
4535
4536 dst[3] = i;
4537 }
4538
4539 static inline void
unpack_int_i_uint32(const void * void_src,GLuint dst[4])4540 unpack_int_i_uint32(const void *void_src, GLuint dst[4])
4541 {
4542 uint32_t *src = (uint32_t *)void_src;
4543 uint32_t i = src[0];
4544
4545
4546 dst[0] = i;
4547
4548 dst[1] = i;
4549
4550 dst[2] = i;
4551
4552 dst[3] = i;
4553 }
4554
4555 static inline void
unpack_int_i_sint8(const void * void_src,GLuint dst[4])4556 unpack_int_i_sint8(const void *void_src, GLuint dst[4])
4557 {
4558 int8_t *src = (int8_t *)void_src;
4559 int8_t i = src[0];
4560
4561
4562 dst[0] = i;
4563
4564 dst[1] = i;
4565
4566 dst[2] = i;
4567
4568 dst[3] = i;
4569 }
4570
4571 static inline void
unpack_int_i_sint16(const void * void_src,GLuint dst[4])4572 unpack_int_i_sint16(const void *void_src, GLuint dst[4])
4573 {
4574 int16_t *src = (int16_t *)void_src;
4575 int16_t i = src[0];
4576
4577
4578 dst[0] = i;
4579
4580 dst[1] = i;
4581
4582 dst[2] = i;
4583
4584 dst[3] = i;
4585 }
4586
4587 static inline void
unpack_int_i_sint32(const void * void_src,GLuint dst[4])4588 unpack_int_i_sint32(const void *void_src, GLuint dst[4])
4589 {
4590 int32_t *src = (int32_t *)void_src;
4591 int32_t i = src[0];
4592
4593
4594 dst[0] = i;
4595
4596 dst[1] = i;
4597
4598 dst[2] = i;
4599
4600 dst[3] = i;
4601 }
4602
4603 static inline void
unpack_int_l_uint8(const void * void_src,GLuint dst[4])4604 unpack_int_l_uint8(const void *void_src, GLuint dst[4])
4605 {
4606 uint8_t *src = (uint8_t *)void_src;
4607 uint8_t l = src[0];
4608
4609
4610 dst[0] = l;
4611
4612 dst[1] = l;
4613
4614 dst[2] = l;
4615
4616 dst[3] = 1;
4617 }
4618
4619 static inline void
unpack_int_l_uint16(const void * void_src,GLuint dst[4])4620 unpack_int_l_uint16(const void *void_src, GLuint dst[4])
4621 {
4622 uint16_t *src = (uint16_t *)void_src;
4623 uint16_t l = src[0];
4624
4625
4626 dst[0] = l;
4627
4628 dst[1] = l;
4629
4630 dst[2] = l;
4631
4632 dst[3] = 1;
4633 }
4634
4635 static inline void
unpack_int_l_uint32(const void * void_src,GLuint dst[4])4636 unpack_int_l_uint32(const void *void_src, GLuint dst[4])
4637 {
4638 uint32_t *src = (uint32_t *)void_src;
4639 uint32_t l = src[0];
4640
4641
4642 dst[0] = l;
4643
4644 dst[1] = l;
4645
4646 dst[2] = l;
4647
4648 dst[3] = 1;
4649 }
4650
4651 static inline void
unpack_int_l_sint8(const void * void_src,GLuint dst[4])4652 unpack_int_l_sint8(const void *void_src, GLuint dst[4])
4653 {
4654 int8_t *src = (int8_t *)void_src;
4655 int8_t l = src[0];
4656
4657
4658 dst[0] = l;
4659
4660 dst[1] = l;
4661
4662 dst[2] = l;
4663
4664 dst[3] = 1;
4665 }
4666
4667 static inline void
unpack_int_l_sint16(const void * void_src,GLuint dst[4])4668 unpack_int_l_sint16(const void *void_src, GLuint dst[4])
4669 {
4670 int16_t *src = (int16_t *)void_src;
4671 int16_t l = src[0];
4672
4673
4674 dst[0] = l;
4675
4676 dst[1] = l;
4677
4678 dst[2] = l;
4679
4680 dst[3] = 1;
4681 }
4682
4683 static inline void
unpack_int_l_sint32(const void * void_src,GLuint dst[4])4684 unpack_int_l_sint32(const void *void_src, GLuint dst[4])
4685 {
4686 int32_t *src = (int32_t *)void_src;
4687 int32_t l = src[0];
4688
4689
4690 dst[0] = l;
4691
4692 dst[1] = l;
4693
4694 dst[2] = l;
4695
4696 dst[3] = 1;
4697 }
4698
4699 static inline void
unpack_int_la_uint8(const void * void_src,GLuint dst[4])4700 unpack_int_la_uint8(const void *void_src, GLuint dst[4])
4701 {
4702 uint8_t *src = (uint8_t *)void_src;
4703 uint8_t l = src[0];
4704 uint8_t a = src[1];
4705
4706
4707 dst[0] = l;
4708
4709 dst[1] = l;
4710
4711 dst[2] = l;
4712
4713 dst[3] = a;
4714 }
4715
4716 static inline void
unpack_int_la_uint16(const void * void_src,GLuint dst[4])4717 unpack_int_la_uint16(const void *void_src, GLuint dst[4])
4718 {
4719 uint16_t *src = (uint16_t *)void_src;
4720 uint16_t l = src[0];
4721 uint16_t a = src[1];
4722
4723
4724 dst[0] = l;
4725
4726 dst[1] = l;
4727
4728 dst[2] = l;
4729
4730 dst[3] = a;
4731 }
4732
4733 static inline void
unpack_int_la_uint32(const void * void_src,GLuint dst[4])4734 unpack_int_la_uint32(const void *void_src, GLuint dst[4])
4735 {
4736 uint32_t *src = (uint32_t *)void_src;
4737 uint32_t l = src[0];
4738 uint32_t a = src[1];
4739
4740
4741 dst[0] = l;
4742
4743 dst[1] = l;
4744
4745 dst[2] = l;
4746
4747 dst[3] = a;
4748 }
4749
4750 static inline void
unpack_int_la_sint8(const void * void_src,GLuint dst[4])4751 unpack_int_la_sint8(const void *void_src, GLuint dst[4])
4752 {
4753 int8_t *src = (int8_t *)void_src;
4754 int8_t l = src[0];
4755 int8_t a = src[1];
4756
4757
4758 dst[0] = l;
4759
4760 dst[1] = l;
4761
4762 dst[2] = l;
4763
4764 dst[3] = a;
4765 }
4766
4767 static inline void
unpack_int_la_sint16(const void * void_src,GLuint dst[4])4768 unpack_int_la_sint16(const void *void_src, GLuint dst[4])
4769 {
4770 int16_t *src = (int16_t *)void_src;
4771 int16_t l = src[0];
4772 int16_t a = src[1];
4773
4774
4775 dst[0] = l;
4776
4777 dst[1] = l;
4778
4779 dst[2] = l;
4780
4781 dst[3] = a;
4782 }
4783
4784 static inline void
unpack_int_la_sint32(const void * void_src,GLuint dst[4])4785 unpack_int_la_sint32(const void *void_src, GLuint dst[4])
4786 {
4787 int32_t *src = (int32_t *)void_src;
4788 int32_t l = src[0];
4789 int32_t a = src[1];
4790
4791
4792 dst[0] = l;
4793
4794 dst[1] = l;
4795
4796 dst[2] = l;
4797
4798 dst[3] = a;
4799 }
4800
4801 static inline void
unpack_int_r_uint8(const void * void_src,GLuint dst[4])4802 unpack_int_r_uint8(const void *void_src, GLuint dst[4])
4803 {
4804 uint8_t *src = (uint8_t *)void_src;
4805 uint8_t r = src[0];
4806
4807
4808 dst[0] = r;
4809
4810 dst[1] = 0;
4811
4812 dst[2] = 0;
4813
4814 dst[3] = 1;
4815 }
4816
4817 static inline void
unpack_int_r_uint16(const void * void_src,GLuint dst[4])4818 unpack_int_r_uint16(const void *void_src, GLuint dst[4])
4819 {
4820 uint16_t *src = (uint16_t *)void_src;
4821 uint16_t r = src[0];
4822
4823
4824 dst[0] = r;
4825
4826 dst[1] = 0;
4827
4828 dst[2] = 0;
4829
4830 dst[3] = 1;
4831 }
4832
4833 static inline void
unpack_int_r_uint32(const void * void_src,GLuint dst[4])4834 unpack_int_r_uint32(const void *void_src, GLuint dst[4])
4835 {
4836 uint32_t *src = (uint32_t *)void_src;
4837 uint32_t r = src[0];
4838
4839
4840 dst[0] = r;
4841
4842 dst[1] = 0;
4843
4844 dst[2] = 0;
4845
4846 dst[3] = 1;
4847 }
4848
4849 static inline void
unpack_int_r_sint8(const void * void_src,GLuint dst[4])4850 unpack_int_r_sint8(const void *void_src, GLuint dst[4])
4851 {
4852 int8_t *src = (int8_t *)void_src;
4853 int8_t r = src[0];
4854
4855
4856 dst[0] = r;
4857
4858 dst[1] = 0;
4859
4860 dst[2] = 0;
4861
4862 dst[3] = 1;
4863 }
4864
4865 static inline void
unpack_int_r_sint16(const void * void_src,GLuint dst[4])4866 unpack_int_r_sint16(const void *void_src, GLuint dst[4])
4867 {
4868 int16_t *src = (int16_t *)void_src;
4869 int16_t r = src[0];
4870
4871
4872 dst[0] = r;
4873
4874 dst[1] = 0;
4875
4876 dst[2] = 0;
4877
4878 dst[3] = 1;
4879 }
4880
4881 static inline void
unpack_int_r_sint32(const void * void_src,GLuint dst[4])4882 unpack_int_r_sint32(const void *void_src, GLuint dst[4])
4883 {
4884 int32_t *src = (int32_t *)void_src;
4885 int32_t r = src[0];
4886
4887
4888 dst[0] = r;
4889
4890 dst[1] = 0;
4891
4892 dst[2] = 0;
4893
4894 dst[3] = 1;
4895 }
4896
4897 static inline void
unpack_int_rg_uint8(const void * void_src,GLuint dst[4])4898 unpack_int_rg_uint8(const void *void_src, GLuint dst[4])
4899 {
4900 uint8_t *src = (uint8_t *)void_src;
4901 uint8_t r = src[0];
4902 uint8_t g = src[1];
4903
4904
4905 dst[0] = r;
4906
4907 dst[1] = g;
4908
4909 dst[2] = 0;
4910
4911 dst[3] = 1;
4912 }
4913
4914 static inline void
unpack_int_rg_uint16(const void * void_src,GLuint dst[4])4915 unpack_int_rg_uint16(const void *void_src, GLuint dst[4])
4916 {
4917 uint16_t *src = (uint16_t *)void_src;
4918 uint16_t r = src[0];
4919 uint16_t g = src[1];
4920
4921
4922 dst[0] = r;
4923
4924 dst[1] = g;
4925
4926 dst[2] = 0;
4927
4928 dst[3] = 1;
4929 }
4930
4931 static inline void
unpack_int_rg_uint32(const void * void_src,GLuint dst[4])4932 unpack_int_rg_uint32(const void *void_src, GLuint dst[4])
4933 {
4934 uint32_t *src = (uint32_t *)void_src;
4935 uint32_t r = src[0];
4936 uint32_t g = src[1];
4937
4938
4939 dst[0] = r;
4940
4941 dst[1] = g;
4942
4943 dst[2] = 0;
4944
4945 dst[3] = 1;
4946 }
4947
4948 static inline void
unpack_int_rg_sint8(const void * void_src,GLuint dst[4])4949 unpack_int_rg_sint8(const void *void_src, GLuint dst[4])
4950 {
4951 int8_t *src = (int8_t *)void_src;
4952 int8_t r = src[0];
4953 int8_t g = src[1];
4954
4955
4956 dst[0] = r;
4957
4958 dst[1] = g;
4959
4960 dst[2] = 0;
4961
4962 dst[3] = 1;
4963 }
4964
4965 static inline void
unpack_int_rg_sint16(const void * void_src,GLuint dst[4])4966 unpack_int_rg_sint16(const void *void_src, GLuint dst[4])
4967 {
4968 int16_t *src = (int16_t *)void_src;
4969 int16_t r = src[0];
4970 int16_t g = src[1];
4971
4972
4973 dst[0] = r;
4974
4975 dst[1] = g;
4976
4977 dst[2] = 0;
4978
4979 dst[3] = 1;
4980 }
4981
4982 static inline void
unpack_int_rg_sint32(const void * void_src,GLuint dst[4])4983 unpack_int_rg_sint32(const void *void_src, GLuint dst[4])
4984 {
4985 int32_t *src = (int32_t *)void_src;
4986 int32_t r = src[0];
4987 int32_t g = src[1];
4988
4989
4990 dst[0] = r;
4991
4992 dst[1] = g;
4993
4994 dst[2] = 0;
4995
4996 dst[3] = 1;
4997 }
4998
4999 static inline void
unpack_int_rgb_uint8(const void * void_src,GLuint dst[4])5000 unpack_int_rgb_uint8(const void *void_src, GLuint dst[4])
5001 {
5002 uint8_t *src = (uint8_t *)void_src;
5003 uint8_t r = src[0];
5004 uint8_t g = src[1];
5005 uint8_t b = src[2];
5006
5007
5008 dst[0] = r;
5009
5010 dst[1] = g;
5011
5012 dst[2] = b;
5013
5014 dst[3] = 1;
5015 }
5016
5017 static inline void
unpack_int_rgb_uint16(const void * void_src,GLuint dst[4])5018 unpack_int_rgb_uint16(const void *void_src, GLuint dst[4])
5019 {
5020 uint16_t *src = (uint16_t *)void_src;
5021 uint16_t r = src[0];
5022 uint16_t g = src[1];
5023 uint16_t b = src[2];
5024
5025
5026 dst[0] = r;
5027
5028 dst[1] = g;
5029
5030 dst[2] = b;
5031
5032 dst[3] = 1;
5033 }
5034
5035 static inline void
unpack_int_rgb_uint32(const void * void_src,GLuint dst[4])5036 unpack_int_rgb_uint32(const void *void_src, GLuint dst[4])
5037 {
5038 uint32_t *src = (uint32_t *)void_src;
5039 uint32_t r = src[0];
5040 uint32_t g = src[1];
5041 uint32_t b = src[2];
5042
5043
5044 dst[0] = r;
5045
5046 dst[1] = g;
5047
5048 dst[2] = b;
5049
5050 dst[3] = 1;
5051 }
5052
5053 static inline void
unpack_int_rgb_sint8(const void * void_src,GLuint dst[4])5054 unpack_int_rgb_sint8(const void *void_src, GLuint dst[4])
5055 {
5056 int8_t *src = (int8_t *)void_src;
5057 int8_t r = src[0];
5058 int8_t g = src[1];
5059 int8_t b = src[2];
5060
5061
5062 dst[0] = r;
5063
5064 dst[1] = g;
5065
5066 dst[2] = b;
5067
5068 dst[3] = 1;
5069 }
5070
5071 static inline void
unpack_int_rgb_sint16(const void * void_src,GLuint dst[4])5072 unpack_int_rgb_sint16(const void *void_src, GLuint dst[4])
5073 {
5074 int16_t *src = (int16_t *)void_src;
5075 int16_t r = src[0];
5076 int16_t g = src[1];
5077 int16_t b = src[2];
5078
5079
5080 dst[0] = r;
5081
5082 dst[1] = g;
5083
5084 dst[2] = b;
5085
5086 dst[3] = 1;
5087 }
5088
5089 static inline void
unpack_int_rgb_sint32(const void * void_src,GLuint dst[4])5090 unpack_int_rgb_sint32(const void *void_src, GLuint dst[4])
5091 {
5092 int32_t *src = (int32_t *)void_src;
5093 int32_t r = src[0];
5094 int32_t g = src[1];
5095 int32_t b = src[2];
5096
5097
5098 dst[0] = r;
5099
5100 dst[1] = g;
5101
5102 dst[2] = b;
5103
5104 dst[3] = 1;
5105 }
5106
5107 static inline void
unpack_int_rgba_uint8(const void * void_src,GLuint dst[4])5108 unpack_int_rgba_uint8(const void *void_src, GLuint dst[4])
5109 {
5110 uint8_t *src = (uint8_t *)void_src;
5111 uint8_t r = src[0];
5112 uint8_t g = src[1];
5113 uint8_t b = src[2];
5114 uint8_t a = src[3];
5115
5116
5117 dst[0] = r;
5118
5119 dst[1] = g;
5120
5121 dst[2] = b;
5122
5123 dst[3] = a;
5124 }
5125
5126 static inline void
unpack_int_rgba_uint16(const void * void_src,GLuint dst[4])5127 unpack_int_rgba_uint16(const void *void_src, GLuint dst[4])
5128 {
5129 uint16_t *src = (uint16_t *)void_src;
5130 uint16_t r = src[0];
5131 uint16_t g = src[1];
5132 uint16_t b = src[2];
5133 uint16_t a = src[3];
5134
5135
5136 dst[0] = r;
5137
5138 dst[1] = g;
5139
5140 dst[2] = b;
5141
5142 dst[3] = a;
5143 }
5144
5145 static inline void
unpack_int_rgba_uint32(const void * void_src,GLuint dst[4])5146 unpack_int_rgba_uint32(const void *void_src, GLuint dst[4])
5147 {
5148 uint32_t *src = (uint32_t *)void_src;
5149 uint32_t r = src[0];
5150 uint32_t g = src[1];
5151 uint32_t b = src[2];
5152 uint32_t a = src[3];
5153
5154
5155 dst[0] = r;
5156
5157 dst[1] = g;
5158
5159 dst[2] = b;
5160
5161 dst[3] = a;
5162 }
5163
5164 static inline void
unpack_int_rgba_sint8(const void * void_src,GLuint dst[4])5165 unpack_int_rgba_sint8(const void *void_src, GLuint dst[4])
5166 {
5167 int8_t *src = (int8_t *)void_src;
5168 int8_t r = src[0];
5169 int8_t g = src[1];
5170 int8_t b = src[2];
5171 int8_t a = src[3];
5172
5173
5174 dst[0] = r;
5175
5176 dst[1] = g;
5177
5178 dst[2] = b;
5179
5180 dst[3] = a;
5181 }
5182
5183 static inline void
unpack_int_rgba_sint16(const void * void_src,GLuint dst[4])5184 unpack_int_rgba_sint16(const void *void_src, GLuint dst[4])
5185 {
5186 int16_t *src = (int16_t *)void_src;
5187 int16_t r = src[0];
5188 int16_t g = src[1];
5189 int16_t b = src[2];
5190 int16_t a = src[3];
5191
5192
5193 dst[0] = r;
5194
5195 dst[1] = g;
5196
5197 dst[2] = b;
5198
5199 dst[3] = a;
5200 }
5201
5202 static inline void
unpack_int_rgba_sint32(const void * void_src,GLuint dst[4])5203 unpack_int_rgba_sint32(const void *void_src, GLuint dst[4])
5204 {
5205 int32_t *src = (int32_t *)void_src;
5206 int32_t r = src[0];
5207 int32_t g = src[1];
5208 int32_t b = src[2];
5209 int32_t a = src[3];
5210
5211
5212 dst[0] = r;
5213
5214 dst[1] = g;
5215
5216 dst[2] = b;
5217
5218 dst[3] = a;
5219 }
5220
5221 static inline void
unpack_int_rgbx_uint8(const void * void_src,GLuint dst[4])5222 unpack_int_rgbx_uint8(const void *void_src, GLuint dst[4])
5223 {
5224 uint8_t *src = (uint8_t *)void_src;
5225 uint8_t r = src[0];
5226 uint8_t g = src[1];
5227 uint8_t b = src[2];
5228
5229
5230 dst[0] = r;
5231
5232 dst[1] = g;
5233
5234 dst[2] = b;
5235
5236 dst[3] = 1;
5237 }
5238
5239 static inline void
unpack_int_rgbx_uint16(const void * void_src,GLuint dst[4])5240 unpack_int_rgbx_uint16(const void *void_src, GLuint dst[4])
5241 {
5242 uint16_t *src = (uint16_t *)void_src;
5243 uint16_t r = src[0];
5244 uint16_t g = src[1];
5245 uint16_t b = src[2];
5246
5247
5248 dst[0] = r;
5249
5250 dst[1] = g;
5251
5252 dst[2] = b;
5253
5254 dst[3] = 1;
5255 }
5256
5257 static inline void
unpack_int_rgbx_uint32(const void * void_src,GLuint dst[4])5258 unpack_int_rgbx_uint32(const void *void_src, GLuint dst[4])
5259 {
5260 uint32_t *src = (uint32_t *)void_src;
5261 uint32_t r = src[0];
5262 uint32_t g = src[1];
5263 uint32_t b = src[2];
5264
5265
5266 dst[0] = r;
5267
5268 dst[1] = g;
5269
5270 dst[2] = b;
5271
5272 dst[3] = 1;
5273 }
5274
5275 static inline void
unpack_int_rgbx_sint8(const void * void_src,GLuint dst[4])5276 unpack_int_rgbx_sint8(const void *void_src, GLuint dst[4])
5277 {
5278 int8_t *src = (int8_t *)void_src;
5279 int8_t r = src[0];
5280 int8_t g = src[1];
5281 int8_t b = src[2];
5282
5283
5284 dst[0] = r;
5285
5286 dst[1] = g;
5287
5288 dst[2] = b;
5289
5290 dst[3] = 1;
5291 }
5292
5293 static inline void
unpack_int_rgbx_sint16(const void * void_src,GLuint dst[4])5294 unpack_int_rgbx_sint16(const void *void_src, GLuint dst[4])
5295 {
5296 int16_t *src = (int16_t *)void_src;
5297 int16_t r = src[0];
5298 int16_t g = src[1];
5299 int16_t b = src[2];
5300
5301
5302 dst[0] = r;
5303
5304 dst[1] = g;
5305
5306 dst[2] = b;
5307
5308 dst[3] = 1;
5309 }
5310
5311 static inline void
unpack_int_rgbx_sint32(const void * void_src,GLuint dst[4])5312 unpack_int_rgbx_sint32(const void *void_src, GLuint dst[4])
5313 {
5314 int32_t *src = (int32_t *)void_src;
5315 int32_t r = src[0];
5316 int32_t g = src[1];
5317 int32_t b = src[2];
5318
5319
5320 dst[0] = r;
5321
5322 dst[1] = g;
5323
5324 dst[2] = b;
5325
5326 dst[3] = 1;
5327 }
5328
5329
5330 void
_mesa_unpack_rgba_row(mesa_format format,GLuint n,const void * src,GLfloat dst[][4])5331 _mesa_unpack_rgba_row(mesa_format format, GLuint n,
5332 const void *src, GLfloat dst[][4])
5333 {
5334 GLubyte *s = (GLubyte *)src;
5335 GLuint i;
5336
5337 switch (format) {
5338 case MESA_FORMAT_A8B8G8R8_UNORM:
5339 for (i = 0; i < n; ++i) {
5340 unpack_float_a8b8g8r8_unorm(s, dst[i]);
5341 s += 4;
5342 }
5343 break;
5344 case MESA_FORMAT_X8B8G8R8_UNORM:
5345 for (i = 0; i < n; ++i) {
5346 unpack_float_x8b8g8r8_unorm(s, dst[i]);
5347 s += 4;
5348 }
5349 break;
5350 case MESA_FORMAT_R8G8B8A8_UNORM:
5351 for (i = 0; i < n; ++i) {
5352 unpack_float_r8g8b8a8_unorm(s, dst[i]);
5353 s += 4;
5354 }
5355 break;
5356 case MESA_FORMAT_R8G8B8X8_UNORM:
5357 for (i = 0; i < n; ++i) {
5358 unpack_float_r8g8b8x8_unorm(s, dst[i]);
5359 s += 4;
5360 }
5361 break;
5362 case MESA_FORMAT_B8G8R8A8_UNORM:
5363 for (i = 0; i < n; ++i) {
5364 unpack_float_b8g8r8a8_unorm(s, dst[i]);
5365 s += 4;
5366 }
5367 break;
5368 case MESA_FORMAT_B8G8R8X8_UNORM:
5369 for (i = 0; i < n; ++i) {
5370 unpack_float_b8g8r8x8_unorm(s, dst[i]);
5371 s += 4;
5372 }
5373 break;
5374 case MESA_FORMAT_A8R8G8B8_UNORM:
5375 for (i = 0; i < n; ++i) {
5376 unpack_float_a8r8g8b8_unorm(s, dst[i]);
5377 s += 4;
5378 }
5379 break;
5380 case MESA_FORMAT_X8R8G8B8_UNORM:
5381 for (i = 0; i < n; ++i) {
5382 unpack_float_x8r8g8b8_unorm(s, dst[i]);
5383 s += 4;
5384 }
5385 break;
5386 case MESA_FORMAT_L16A16_UNORM:
5387 for (i = 0; i < n; ++i) {
5388 unpack_float_l16a16_unorm(s, dst[i]);
5389 s += 4;
5390 }
5391 break;
5392 case MESA_FORMAT_A16L16_UNORM:
5393 for (i = 0; i < n; ++i) {
5394 unpack_float_a16l16_unorm(s, dst[i]);
5395 s += 4;
5396 }
5397 break;
5398 case MESA_FORMAT_B5G6R5_UNORM:
5399 for (i = 0; i < n; ++i) {
5400 unpack_float_b5g6r5_unorm(s, dst[i]);
5401 s += 2;
5402 }
5403 break;
5404 case MESA_FORMAT_R5G6B5_UNORM:
5405 for (i = 0; i < n; ++i) {
5406 unpack_float_r5g6b5_unorm(s, dst[i]);
5407 s += 2;
5408 }
5409 break;
5410 case MESA_FORMAT_B4G4R4A4_UNORM:
5411 for (i = 0; i < n; ++i) {
5412 unpack_float_b4g4r4a4_unorm(s, dst[i]);
5413 s += 2;
5414 }
5415 break;
5416 case MESA_FORMAT_B4G4R4X4_UNORM:
5417 for (i = 0; i < n; ++i) {
5418 unpack_float_b4g4r4x4_unorm(s, dst[i]);
5419 s += 2;
5420 }
5421 break;
5422 case MESA_FORMAT_A4R4G4B4_UNORM:
5423 for (i = 0; i < n; ++i) {
5424 unpack_float_a4r4g4b4_unorm(s, dst[i]);
5425 s += 2;
5426 }
5427 break;
5428 case MESA_FORMAT_A1B5G5R5_UNORM:
5429 for (i = 0; i < n; ++i) {
5430 unpack_float_a1b5g5r5_unorm(s, dst[i]);
5431 s += 2;
5432 }
5433 break;
5434 case MESA_FORMAT_X1B5G5R5_UNORM:
5435 for (i = 0; i < n; ++i) {
5436 unpack_float_x1b5g5r5_unorm(s, dst[i]);
5437 s += 2;
5438 }
5439 break;
5440 case MESA_FORMAT_B5G5R5A1_UNORM:
5441 for (i = 0; i < n; ++i) {
5442 unpack_float_b5g5r5a1_unorm(s, dst[i]);
5443 s += 2;
5444 }
5445 break;
5446 case MESA_FORMAT_B5G5R5X1_UNORM:
5447 for (i = 0; i < n; ++i) {
5448 unpack_float_b5g5r5x1_unorm(s, dst[i]);
5449 s += 2;
5450 }
5451 break;
5452 case MESA_FORMAT_A1R5G5B5_UNORM:
5453 for (i = 0; i < n; ++i) {
5454 unpack_float_a1r5g5b5_unorm(s, dst[i]);
5455 s += 2;
5456 }
5457 break;
5458 case MESA_FORMAT_L8A8_UNORM:
5459 for (i = 0; i < n; ++i) {
5460 unpack_float_l8a8_unorm(s, dst[i]);
5461 s += 2;
5462 }
5463 break;
5464 case MESA_FORMAT_A8L8_UNORM:
5465 for (i = 0; i < n; ++i) {
5466 unpack_float_a8l8_unorm(s, dst[i]);
5467 s += 2;
5468 }
5469 break;
5470 case MESA_FORMAT_R8G8_UNORM:
5471 for (i = 0; i < n; ++i) {
5472 unpack_float_r8g8_unorm(s, dst[i]);
5473 s += 2;
5474 }
5475 break;
5476 case MESA_FORMAT_G8R8_UNORM:
5477 for (i = 0; i < n; ++i) {
5478 unpack_float_g8r8_unorm(s, dst[i]);
5479 s += 2;
5480 }
5481 break;
5482 case MESA_FORMAT_L4A4_UNORM:
5483 for (i = 0; i < n; ++i) {
5484 unpack_float_l4a4_unorm(s, dst[i]);
5485 s += 1;
5486 }
5487 break;
5488 case MESA_FORMAT_B2G3R3_UNORM:
5489 for (i = 0; i < n; ++i) {
5490 unpack_float_b2g3r3_unorm(s, dst[i]);
5491 s += 1;
5492 }
5493 break;
5494 case MESA_FORMAT_R16G16_UNORM:
5495 for (i = 0; i < n; ++i) {
5496 unpack_float_r16g16_unorm(s, dst[i]);
5497 s += 4;
5498 }
5499 break;
5500 case MESA_FORMAT_G16R16_UNORM:
5501 for (i = 0; i < n; ++i) {
5502 unpack_float_g16r16_unorm(s, dst[i]);
5503 s += 4;
5504 }
5505 break;
5506 case MESA_FORMAT_B10G10R10A2_UNORM:
5507 for (i = 0; i < n; ++i) {
5508 unpack_float_b10g10r10a2_unorm(s, dst[i]);
5509 s += 4;
5510 }
5511 break;
5512 case MESA_FORMAT_B10G10R10X2_UNORM:
5513 for (i = 0; i < n; ++i) {
5514 unpack_float_b10g10r10x2_unorm(s, dst[i]);
5515 s += 4;
5516 }
5517 break;
5518 case MESA_FORMAT_R10G10B10A2_UNORM:
5519 for (i = 0; i < n; ++i) {
5520 unpack_float_r10g10b10a2_unorm(s, dst[i]);
5521 s += 4;
5522 }
5523 break;
5524 case MESA_FORMAT_R10G10B10X2_UNORM:
5525 for (i = 0; i < n; ++i) {
5526 unpack_float_r10g10b10x2_unorm(s, dst[i]);
5527 s += 4;
5528 }
5529 break;
5530 case MESA_FORMAT_R3G3B2_UNORM:
5531 for (i = 0; i < n; ++i) {
5532 unpack_float_r3g3b2_unorm(s, dst[i]);
5533 s += 1;
5534 }
5535 break;
5536 case MESA_FORMAT_A4B4G4R4_UNORM:
5537 for (i = 0; i < n; ++i) {
5538 unpack_float_a4b4g4r4_unorm(s, dst[i]);
5539 s += 2;
5540 }
5541 break;
5542 case MESA_FORMAT_R4G4B4A4_UNORM:
5543 for (i = 0; i < n; ++i) {
5544 unpack_float_r4g4b4a4_unorm(s, dst[i]);
5545 s += 2;
5546 }
5547 break;
5548 case MESA_FORMAT_R5G5B5A1_UNORM:
5549 for (i = 0; i < n; ++i) {
5550 unpack_float_r5g5b5a1_unorm(s, dst[i]);
5551 s += 2;
5552 }
5553 break;
5554 case MESA_FORMAT_A2B10G10R10_UNORM:
5555 for (i = 0; i < n; ++i) {
5556 unpack_float_a2b10g10r10_unorm(s, dst[i]);
5557 s += 4;
5558 }
5559 break;
5560 case MESA_FORMAT_A2R10G10B10_UNORM:
5561 for (i = 0; i < n; ++i) {
5562 unpack_float_a2r10g10b10_unorm(s, dst[i]);
5563 s += 4;
5564 }
5565 break;
5566 case MESA_FORMAT_A_UNORM8:
5567 for (i = 0; i < n; ++i) {
5568 unpack_float_a_unorm8(s, dst[i]);
5569 s += 1;
5570 }
5571 break;
5572 case MESA_FORMAT_A_UNORM16:
5573 for (i = 0; i < n; ++i) {
5574 unpack_float_a_unorm16(s, dst[i]);
5575 s += 2;
5576 }
5577 break;
5578 case MESA_FORMAT_L_UNORM8:
5579 for (i = 0; i < n; ++i) {
5580 unpack_float_l_unorm8(s, dst[i]);
5581 s += 1;
5582 }
5583 break;
5584 case MESA_FORMAT_L_UNORM16:
5585 for (i = 0; i < n; ++i) {
5586 unpack_float_l_unorm16(s, dst[i]);
5587 s += 2;
5588 }
5589 break;
5590 case MESA_FORMAT_I_UNORM8:
5591 for (i = 0; i < n; ++i) {
5592 unpack_float_i_unorm8(s, dst[i]);
5593 s += 1;
5594 }
5595 break;
5596 case MESA_FORMAT_I_UNORM16:
5597 for (i = 0; i < n; ++i) {
5598 unpack_float_i_unorm16(s, dst[i]);
5599 s += 2;
5600 }
5601 break;
5602 case MESA_FORMAT_R_UNORM8:
5603 for (i = 0; i < n; ++i) {
5604 unpack_float_r_unorm8(s, dst[i]);
5605 s += 1;
5606 }
5607 break;
5608 case MESA_FORMAT_R_UNORM16:
5609 for (i = 0; i < n; ++i) {
5610 unpack_float_r_unorm16(s, dst[i]);
5611 s += 2;
5612 }
5613 break;
5614 case MESA_FORMAT_BGR_UNORM8:
5615 for (i = 0; i < n; ++i) {
5616 unpack_float_bgr_unorm8(s, dst[i]);
5617 s += 3;
5618 }
5619 break;
5620 case MESA_FORMAT_RGB_UNORM8:
5621 for (i = 0; i < n; ++i) {
5622 unpack_float_rgb_unorm8(s, dst[i]);
5623 s += 3;
5624 }
5625 break;
5626 case MESA_FORMAT_RGBA_UNORM16:
5627 for (i = 0; i < n; ++i) {
5628 unpack_float_rgba_unorm16(s, dst[i]);
5629 s += 8;
5630 }
5631 break;
5632 case MESA_FORMAT_RGBX_UNORM16:
5633 for (i = 0; i < n; ++i) {
5634 unpack_float_rgbx_unorm16(s, dst[i]);
5635 s += 8;
5636 }
5637 break;
5638 case MESA_FORMAT_A8B8G8R8_SNORM:
5639 for (i = 0; i < n; ++i) {
5640 unpack_float_a8b8g8r8_snorm(s, dst[i]);
5641 s += 4;
5642 }
5643 break;
5644 case MESA_FORMAT_X8B8G8R8_SNORM:
5645 for (i = 0; i < n; ++i) {
5646 unpack_float_x8b8g8r8_snorm(s, dst[i]);
5647 s += 4;
5648 }
5649 break;
5650 case MESA_FORMAT_R8G8B8A8_SNORM:
5651 for (i = 0; i < n; ++i) {
5652 unpack_float_r8g8b8a8_snorm(s, dst[i]);
5653 s += 4;
5654 }
5655 break;
5656 case MESA_FORMAT_R8G8B8X8_SNORM:
5657 for (i = 0; i < n; ++i) {
5658 unpack_float_r8g8b8x8_snorm(s, dst[i]);
5659 s += 4;
5660 }
5661 break;
5662 case MESA_FORMAT_R16G16_SNORM:
5663 for (i = 0; i < n; ++i) {
5664 unpack_float_r16g16_snorm(s, dst[i]);
5665 s += 4;
5666 }
5667 break;
5668 case MESA_FORMAT_G16R16_SNORM:
5669 for (i = 0; i < n; ++i) {
5670 unpack_float_g16r16_snorm(s, dst[i]);
5671 s += 4;
5672 }
5673 break;
5674 case MESA_FORMAT_R8G8_SNORM:
5675 for (i = 0; i < n; ++i) {
5676 unpack_float_r8g8_snorm(s, dst[i]);
5677 s += 2;
5678 }
5679 break;
5680 case MESA_FORMAT_G8R8_SNORM:
5681 for (i = 0; i < n; ++i) {
5682 unpack_float_g8r8_snorm(s, dst[i]);
5683 s += 2;
5684 }
5685 break;
5686 case MESA_FORMAT_L8A8_SNORM:
5687 for (i = 0; i < n; ++i) {
5688 unpack_float_l8a8_snorm(s, dst[i]);
5689 s += 2;
5690 }
5691 break;
5692 case MESA_FORMAT_A8L8_SNORM:
5693 for (i = 0; i < n; ++i) {
5694 unpack_float_a8l8_snorm(s, dst[i]);
5695 s += 2;
5696 }
5697 break;
5698 case MESA_FORMAT_A_SNORM8:
5699 for (i = 0; i < n; ++i) {
5700 unpack_float_a_snorm8(s, dst[i]);
5701 s += 1;
5702 }
5703 break;
5704 case MESA_FORMAT_A_SNORM16:
5705 for (i = 0; i < n; ++i) {
5706 unpack_float_a_snorm16(s, dst[i]);
5707 s += 2;
5708 }
5709 break;
5710 case MESA_FORMAT_L_SNORM8:
5711 for (i = 0; i < n; ++i) {
5712 unpack_float_l_snorm8(s, dst[i]);
5713 s += 1;
5714 }
5715 break;
5716 case MESA_FORMAT_L_SNORM16:
5717 for (i = 0; i < n; ++i) {
5718 unpack_float_l_snorm16(s, dst[i]);
5719 s += 2;
5720 }
5721 break;
5722 case MESA_FORMAT_I_SNORM8:
5723 for (i = 0; i < n; ++i) {
5724 unpack_float_i_snorm8(s, dst[i]);
5725 s += 1;
5726 }
5727 break;
5728 case MESA_FORMAT_I_SNORM16:
5729 for (i = 0; i < n; ++i) {
5730 unpack_float_i_snorm16(s, dst[i]);
5731 s += 2;
5732 }
5733 break;
5734 case MESA_FORMAT_R_SNORM8:
5735 for (i = 0; i < n; ++i) {
5736 unpack_float_r_snorm8(s, dst[i]);
5737 s += 1;
5738 }
5739 break;
5740 case MESA_FORMAT_R_SNORM16:
5741 for (i = 0; i < n; ++i) {
5742 unpack_float_r_snorm16(s, dst[i]);
5743 s += 2;
5744 }
5745 break;
5746 case MESA_FORMAT_LA_SNORM16:
5747 for (i = 0; i < n; ++i) {
5748 unpack_float_la_snorm16(s, dst[i]);
5749 s += 4;
5750 }
5751 break;
5752 case MESA_FORMAT_RGB_SNORM16:
5753 for (i = 0; i < n; ++i) {
5754 unpack_float_rgb_snorm16(s, dst[i]);
5755 s += 6;
5756 }
5757 break;
5758 case MESA_FORMAT_RGBA_SNORM16:
5759 for (i = 0; i < n; ++i) {
5760 unpack_float_rgba_snorm16(s, dst[i]);
5761 s += 8;
5762 }
5763 break;
5764 case MESA_FORMAT_RGBX_SNORM16:
5765 for (i = 0; i < n; ++i) {
5766 unpack_float_rgbx_snorm16(s, dst[i]);
5767 s += 8;
5768 }
5769 break;
5770 case MESA_FORMAT_A8B8G8R8_SRGB:
5771 for (i = 0; i < n; ++i) {
5772 unpack_float_a8b8g8r8_srgb(s, dst[i]);
5773 s += 4;
5774 }
5775 break;
5776 case MESA_FORMAT_B8G8R8A8_SRGB:
5777 for (i = 0; i < n; ++i) {
5778 unpack_float_b8g8r8a8_srgb(s, dst[i]);
5779 s += 4;
5780 }
5781 break;
5782 case MESA_FORMAT_A8R8G8B8_SRGB:
5783 for (i = 0; i < n; ++i) {
5784 unpack_float_a8r8g8b8_srgb(s, dst[i]);
5785 s += 4;
5786 }
5787 break;
5788 case MESA_FORMAT_B8G8R8X8_SRGB:
5789 for (i = 0; i < n; ++i) {
5790 unpack_float_b8g8r8x8_srgb(s, dst[i]);
5791 s += 4;
5792 }
5793 break;
5794 case MESA_FORMAT_X8R8G8B8_SRGB:
5795 for (i = 0; i < n; ++i) {
5796 unpack_float_x8r8g8b8_srgb(s, dst[i]);
5797 s += 4;
5798 }
5799 break;
5800 case MESA_FORMAT_R8G8B8A8_SRGB:
5801 for (i = 0; i < n; ++i) {
5802 unpack_float_r8g8b8a8_srgb(s, dst[i]);
5803 s += 4;
5804 }
5805 break;
5806 case MESA_FORMAT_R8G8B8X8_SRGB:
5807 for (i = 0; i < n; ++i) {
5808 unpack_float_r8g8b8x8_srgb(s, dst[i]);
5809 s += 4;
5810 }
5811 break;
5812 case MESA_FORMAT_X8B8G8R8_SRGB:
5813 for (i = 0; i < n; ++i) {
5814 unpack_float_x8b8g8r8_srgb(s, dst[i]);
5815 s += 4;
5816 }
5817 break;
5818 case MESA_FORMAT_L8A8_SRGB:
5819 for (i = 0; i < n; ++i) {
5820 unpack_float_l8a8_srgb(s, dst[i]);
5821 s += 2;
5822 }
5823 break;
5824 case MESA_FORMAT_A8L8_SRGB:
5825 for (i = 0; i < n; ++i) {
5826 unpack_float_a8l8_srgb(s, dst[i]);
5827 s += 2;
5828 }
5829 break;
5830 case MESA_FORMAT_L_SRGB8:
5831 for (i = 0; i < n; ++i) {
5832 unpack_float_l_srgb8(s, dst[i]);
5833 s += 1;
5834 }
5835 break;
5836 case MESA_FORMAT_BGR_SRGB8:
5837 for (i = 0; i < n; ++i) {
5838 unpack_float_bgr_srgb8(s, dst[i]);
5839 s += 3;
5840 }
5841 break;
5842 case MESA_FORMAT_R9G9B9E5_FLOAT:
5843 for (i = 0; i < n; ++i) {
5844 unpack_float_r9g9b9e5_float(s, dst[i]);
5845 s += 4;
5846 }
5847 break;
5848 case MESA_FORMAT_R11G11B10_FLOAT:
5849 for (i = 0; i < n; ++i) {
5850 unpack_float_r11g11b10_float(s, dst[i]);
5851 s += 4;
5852 }
5853 break;
5854 case MESA_FORMAT_A_FLOAT16:
5855 for (i = 0; i < n; ++i) {
5856 unpack_float_a_float16(s, dst[i]);
5857 s += 2;
5858 }
5859 break;
5860 case MESA_FORMAT_A_FLOAT32:
5861 for (i = 0; i < n; ++i) {
5862 unpack_float_a_float32(s, dst[i]);
5863 s += 4;
5864 }
5865 break;
5866 case MESA_FORMAT_L_FLOAT16:
5867 for (i = 0; i < n; ++i) {
5868 unpack_float_l_float16(s, dst[i]);
5869 s += 2;
5870 }
5871 break;
5872 case MESA_FORMAT_L_FLOAT32:
5873 for (i = 0; i < n; ++i) {
5874 unpack_float_l_float32(s, dst[i]);
5875 s += 4;
5876 }
5877 break;
5878 case MESA_FORMAT_LA_FLOAT16:
5879 for (i = 0; i < n; ++i) {
5880 unpack_float_la_float16(s, dst[i]);
5881 s += 4;
5882 }
5883 break;
5884 case MESA_FORMAT_LA_FLOAT32:
5885 for (i = 0; i < n; ++i) {
5886 unpack_float_la_float32(s, dst[i]);
5887 s += 8;
5888 }
5889 break;
5890 case MESA_FORMAT_I_FLOAT16:
5891 for (i = 0; i < n; ++i) {
5892 unpack_float_i_float16(s, dst[i]);
5893 s += 2;
5894 }
5895 break;
5896 case MESA_FORMAT_I_FLOAT32:
5897 for (i = 0; i < n; ++i) {
5898 unpack_float_i_float32(s, dst[i]);
5899 s += 4;
5900 }
5901 break;
5902 case MESA_FORMAT_R_FLOAT16:
5903 for (i = 0; i < n; ++i) {
5904 unpack_float_r_float16(s, dst[i]);
5905 s += 2;
5906 }
5907 break;
5908 case MESA_FORMAT_R_FLOAT32:
5909 for (i = 0; i < n; ++i) {
5910 unpack_float_r_float32(s, dst[i]);
5911 s += 4;
5912 }
5913 break;
5914 case MESA_FORMAT_RG_FLOAT16:
5915 for (i = 0; i < n; ++i) {
5916 unpack_float_rg_float16(s, dst[i]);
5917 s += 4;
5918 }
5919 break;
5920 case MESA_FORMAT_RG_FLOAT32:
5921 for (i = 0; i < n; ++i) {
5922 unpack_float_rg_float32(s, dst[i]);
5923 s += 8;
5924 }
5925 break;
5926 case MESA_FORMAT_RGB_FLOAT16:
5927 for (i = 0; i < n; ++i) {
5928 unpack_float_rgb_float16(s, dst[i]);
5929 s += 6;
5930 }
5931 break;
5932 case MESA_FORMAT_RGB_FLOAT32:
5933 for (i = 0; i < n; ++i) {
5934 unpack_float_rgb_float32(s, dst[i]);
5935 s += 12;
5936 }
5937 break;
5938 case MESA_FORMAT_RGBA_FLOAT16:
5939 for (i = 0; i < n; ++i) {
5940 unpack_float_rgba_float16(s, dst[i]);
5941 s += 8;
5942 }
5943 break;
5944 case MESA_FORMAT_RGBA_FLOAT32:
5945 for (i = 0; i < n; ++i) {
5946 unpack_float_rgba_float32(s, dst[i]);
5947 s += 16;
5948 }
5949 break;
5950 case MESA_FORMAT_RGBX_FLOAT16:
5951 for (i = 0; i < n; ++i) {
5952 unpack_float_rgbx_float16(s, dst[i]);
5953 s += 8;
5954 }
5955 break;
5956 case MESA_FORMAT_RGBX_FLOAT32:
5957 for (i = 0; i < n; ++i) {
5958 unpack_float_rgbx_float32(s, dst[i]);
5959 s += 16;
5960 }
5961 break;
5962 case MESA_FORMAT_YCBCR:
5963 unpack_float_ycbcr(src, dst, n);
5964 break;
5965 case MESA_FORMAT_YCBCR_REV:
5966 unpack_float_ycbcr_rev(src, dst, n);
5967 break;
5968 default:
5969 _mesa_problem(NULL, "%s: bad format %s", __func__,
5970 _mesa_get_format_name(format));
5971 return;
5972 }
5973 }
5974
5975 void
_mesa_unpack_ubyte_rgba_row(mesa_format format,GLuint n,const void * src,GLubyte dst[][4])5976 _mesa_unpack_ubyte_rgba_row(mesa_format format, GLuint n,
5977 const void *src, GLubyte dst[][4])
5978 {
5979 GLubyte *s = (GLubyte *)src;
5980 GLuint i;
5981
5982 switch (format) {
5983
5984 case MESA_FORMAT_A8B8G8R8_UNORM:
5985 for (i = 0; i < n; ++i) {
5986 unpack_ubyte_a8b8g8r8_unorm(s, dst[i]);
5987 s += 4;
5988 }
5989 break;
5990
5991 case MESA_FORMAT_X8B8G8R8_UNORM:
5992 for (i = 0; i < n; ++i) {
5993 unpack_ubyte_x8b8g8r8_unorm(s, dst[i]);
5994 s += 4;
5995 }
5996 break;
5997
5998 case MESA_FORMAT_R8G8B8A8_UNORM:
5999 for (i = 0; i < n; ++i) {
6000 unpack_ubyte_r8g8b8a8_unorm(s, dst[i]);
6001 s += 4;
6002 }
6003 break;
6004
6005 case MESA_FORMAT_R8G8B8X8_UNORM:
6006 for (i = 0; i < n; ++i) {
6007 unpack_ubyte_r8g8b8x8_unorm(s, dst[i]);
6008 s += 4;
6009 }
6010 break;
6011
6012 case MESA_FORMAT_B8G8R8A8_UNORM:
6013 for (i = 0; i < n; ++i) {
6014 unpack_ubyte_b8g8r8a8_unorm(s, dst[i]);
6015 s += 4;
6016 }
6017 break;
6018
6019 case MESA_FORMAT_B8G8R8X8_UNORM:
6020 for (i = 0; i < n; ++i) {
6021 unpack_ubyte_b8g8r8x8_unorm(s, dst[i]);
6022 s += 4;
6023 }
6024 break;
6025
6026 case MESA_FORMAT_A8R8G8B8_UNORM:
6027 for (i = 0; i < n; ++i) {
6028 unpack_ubyte_a8r8g8b8_unorm(s, dst[i]);
6029 s += 4;
6030 }
6031 break;
6032
6033 case MESA_FORMAT_X8R8G8B8_UNORM:
6034 for (i = 0; i < n; ++i) {
6035 unpack_ubyte_x8r8g8b8_unorm(s, dst[i]);
6036 s += 4;
6037 }
6038 break;
6039
6040 case MESA_FORMAT_L16A16_UNORM:
6041 for (i = 0; i < n; ++i) {
6042 unpack_ubyte_l16a16_unorm(s, dst[i]);
6043 s += 4;
6044 }
6045 break;
6046
6047 case MESA_FORMAT_A16L16_UNORM:
6048 for (i = 0; i < n; ++i) {
6049 unpack_ubyte_a16l16_unorm(s, dst[i]);
6050 s += 4;
6051 }
6052 break;
6053
6054 case MESA_FORMAT_B5G6R5_UNORM:
6055 for (i = 0; i < n; ++i) {
6056 unpack_ubyte_b5g6r5_unorm(s, dst[i]);
6057 s += 2;
6058 }
6059 break;
6060
6061 case MESA_FORMAT_R5G6B5_UNORM:
6062 for (i = 0; i < n; ++i) {
6063 unpack_ubyte_r5g6b5_unorm(s, dst[i]);
6064 s += 2;
6065 }
6066 break;
6067
6068 case MESA_FORMAT_B4G4R4A4_UNORM:
6069 for (i = 0; i < n; ++i) {
6070 unpack_ubyte_b4g4r4a4_unorm(s, dst[i]);
6071 s += 2;
6072 }
6073 break;
6074
6075 case MESA_FORMAT_B4G4R4X4_UNORM:
6076 for (i = 0; i < n; ++i) {
6077 unpack_ubyte_b4g4r4x4_unorm(s, dst[i]);
6078 s += 2;
6079 }
6080 break;
6081
6082 case MESA_FORMAT_A4R4G4B4_UNORM:
6083 for (i = 0; i < n; ++i) {
6084 unpack_ubyte_a4r4g4b4_unorm(s, dst[i]);
6085 s += 2;
6086 }
6087 break;
6088
6089 case MESA_FORMAT_A1B5G5R5_UNORM:
6090 for (i = 0; i < n; ++i) {
6091 unpack_ubyte_a1b5g5r5_unorm(s, dst[i]);
6092 s += 2;
6093 }
6094 break;
6095
6096 case MESA_FORMAT_X1B5G5R5_UNORM:
6097 for (i = 0; i < n; ++i) {
6098 unpack_ubyte_x1b5g5r5_unorm(s, dst[i]);
6099 s += 2;
6100 }
6101 break;
6102
6103 case MESA_FORMAT_B5G5R5A1_UNORM:
6104 for (i = 0; i < n; ++i) {
6105 unpack_ubyte_b5g5r5a1_unorm(s, dst[i]);
6106 s += 2;
6107 }
6108 break;
6109
6110 case MESA_FORMAT_B5G5R5X1_UNORM:
6111 for (i = 0; i < n; ++i) {
6112 unpack_ubyte_b5g5r5x1_unorm(s, dst[i]);
6113 s += 2;
6114 }
6115 break;
6116
6117 case MESA_FORMAT_A1R5G5B5_UNORM:
6118 for (i = 0; i < n; ++i) {
6119 unpack_ubyte_a1r5g5b5_unorm(s, dst[i]);
6120 s += 2;
6121 }
6122 break;
6123
6124 case MESA_FORMAT_L8A8_UNORM:
6125 for (i = 0; i < n; ++i) {
6126 unpack_ubyte_l8a8_unorm(s, dst[i]);
6127 s += 2;
6128 }
6129 break;
6130
6131 case MESA_FORMAT_A8L8_UNORM:
6132 for (i = 0; i < n; ++i) {
6133 unpack_ubyte_a8l8_unorm(s, dst[i]);
6134 s += 2;
6135 }
6136 break;
6137
6138 case MESA_FORMAT_R8G8_UNORM:
6139 for (i = 0; i < n; ++i) {
6140 unpack_ubyte_r8g8_unorm(s, dst[i]);
6141 s += 2;
6142 }
6143 break;
6144
6145 case MESA_FORMAT_G8R8_UNORM:
6146 for (i = 0; i < n; ++i) {
6147 unpack_ubyte_g8r8_unorm(s, dst[i]);
6148 s += 2;
6149 }
6150 break;
6151
6152 case MESA_FORMAT_L4A4_UNORM:
6153 for (i = 0; i < n; ++i) {
6154 unpack_ubyte_l4a4_unorm(s, dst[i]);
6155 s += 1;
6156 }
6157 break;
6158
6159 case MESA_FORMAT_B2G3R3_UNORM:
6160 for (i = 0; i < n; ++i) {
6161 unpack_ubyte_b2g3r3_unorm(s, dst[i]);
6162 s += 1;
6163 }
6164 break;
6165
6166 case MESA_FORMAT_R16G16_UNORM:
6167 for (i = 0; i < n; ++i) {
6168 unpack_ubyte_r16g16_unorm(s, dst[i]);
6169 s += 4;
6170 }
6171 break;
6172
6173 case MESA_FORMAT_G16R16_UNORM:
6174 for (i = 0; i < n; ++i) {
6175 unpack_ubyte_g16r16_unorm(s, dst[i]);
6176 s += 4;
6177 }
6178 break;
6179
6180 case MESA_FORMAT_B10G10R10A2_UNORM:
6181 for (i = 0; i < n; ++i) {
6182 unpack_ubyte_b10g10r10a2_unorm(s, dst[i]);
6183 s += 4;
6184 }
6185 break;
6186
6187 case MESA_FORMAT_B10G10R10X2_UNORM:
6188 for (i = 0; i < n; ++i) {
6189 unpack_ubyte_b10g10r10x2_unorm(s, dst[i]);
6190 s += 4;
6191 }
6192 break;
6193
6194 case MESA_FORMAT_R10G10B10A2_UNORM:
6195 for (i = 0; i < n; ++i) {
6196 unpack_ubyte_r10g10b10a2_unorm(s, dst[i]);
6197 s += 4;
6198 }
6199 break;
6200
6201 case MESA_FORMAT_R10G10B10X2_UNORM:
6202 for (i = 0; i < n; ++i) {
6203 unpack_ubyte_r10g10b10x2_unorm(s, dst[i]);
6204 s += 4;
6205 }
6206 break;
6207
6208 case MESA_FORMAT_R3G3B2_UNORM:
6209 for (i = 0; i < n; ++i) {
6210 unpack_ubyte_r3g3b2_unorm(s, dst[i]);
6211 s += 1;
6212 }
6213 break;
6214
6215 case MESA_FORMAT_A4B4G4R4_UNORM:
6216 for (i = 0; i < n; ++i) {
6217 unpack_ubyte_a4b4g4r4_unorm(s, dst[i]);
6218 s += 2;
6219 }
6220 break;
6221
6222 case MESA_FORMAT_R4G4B4A4_UNORM:
6223 for (i = 0; i < n; ++i) {
6224 unpack_ubyte_r4g4b4a4_unorm(s, dst[i]);
6225 s += 2;
6226 }
6227 break;
6228
6229 case MESA_FORMAT_R5G5B5A1_UNORM:
6230 for (i = 0; i < n; ++i) {
6231 unpack_ubyte_r5g5b5a1_unorm(s, dst[i]);
6232 s += 2;
6233 }
6234 break;
6235
6236 case MESA_FORMAT_A2B10G10R10_UNORM:
6237 for (i = 0; i < n; ++i) {
6238 unpack_ubyte_a2b10g10r10_unorm(s, dst[i]);
6239 s += 4;
6240 }
6241 break;
6242
6243 case MESA_FORMAT_A2R10G10B10_UNORM:
6244 for (i = 0; i < n; ++i) {
6245 unpack_ubyte_a2r10g10b10_unorm(s, dst[i]);
6246 s += 4;
6247 }
6248 break;
6249
6250 case MESA_FORMAT_A_UNORM8:
6251 for (i = 0; i < n; ++i) {
6252 unpack_ubyte_a_unorm8(s, dst[i]);
6253 s += 1;
6254 }
6255 break;
6256
6257 case MESA_FORMAT_A_UNORM16:
6258 for (i = 0; i < n; ++i) {
6259 unpack_ubyte_a_unorm16(s, dst[i]);
6260 s += 2;
6261 }
6262 break;
6263
6264 case MESA_FORMAT_L_UNORM8:
6265 for (i = 0; i < n; ++i) {
6266 unpack_ubyte_l_unorm8(s, dst[i]);
6267 s += 1;
6268 }
6269 break;
6270
6271 case MESA_FORMAT_L_UNORM16:
6272 for (i = 0; i < n; ++i) {
6273 unpack_ubyte_l_unorm16(s, dst[i]);
6274 s += 2;
6275 }
6276 break;
6277
6278 case MESA_FORMAT_I_UNORM8:
6279 for (i = 0; i < n; ++i) {
6280 unpack_ubyte_i_unorm8(s, dst[i]);
6281 s += 1;
6282 }
6283 break;
6284
6285 case MESA_FORMAT_I_UNORM16:
6286 for (i = 0; i < n; ++i) {
6287 unpack_ubyte_i_unorm16(s, dst[i]);
6288 s += 2;
6289 }
6290 break;
6291
6292 case MESA_FORMAT_R_UNORM8:
6293 for (i = 0; i < n; ++i) {
6294 unpack_ubyte_r_unorm8(s, dst[i]);
6295 s += 1;
6296 }
6297 break;
6298
6299 case MESA_FORMAT_R_UNORM16:
6300 for (i = 0; i < n; ++i) {
6301 unpack_ubyte_r_unorm16(s, dst[i]);
6302 s += 2;
6303 }
6304 break;
6305
6306 case MESA_FORMAT_BGR_UNORM8:
6307 for (i = 0; i < n; ++i) {
6308 unpack_ubyte_bgr_unorm8(s, dst[i]);
6309 s += 3;
6310 }
6311 break;
6312
6313 case MESA_FORMAT_RGB_UNORM8:
6314 for (i = 0; i < n; ++i) {
6315 unpack_ubyte_rgb_unorm8(s, dst[i]);
6316 s += 3;
6317 }
6318 break;
6319
6320 case MESA_FORMAT_RGBA_UNORM16:
6321 for (i = 0; i < n; ++i) {
6322 unpack_ubyte_rgba_unorm16(s, dst[i]);
6323 s += 8;
6324 }
6325 break;
6326
6327 case MESA_FORMAT_RGBX_UNORM16:
6328 for (i = 0; i < n; ++i) {
6329 unpack_ubyte_rgbx_unorm16(s, dst[i]);
6330 s += 8;
6331 }
6332 break;
6333
6334 case MESA_FORMAT_A8B8G8R8_SNORM:
6335 for (i = 0; i < n; ++i) {
6336 unpack_ubyte_a8b8g8r8_snorm(s, dst[i]);
6337 s += 4;
6338 }
6339 break;
6340
6341 case MESA_FORMAT_X8B8G8R8_SNORM:
6342 for (i = 0; i < n; ++i) {
6343 unpack_ubyte_x8b8g8r8_snorm(s, dst[i]);
6344 s += 4;
6345 }
6346 break;
6347
6348 case MESA_FORMAT_R8G8B8A8_SNORM:
6349 for (i = 0; i < n; ++i) {
6350 unpack_ubyte_r8g8b8a8_snorm(s, dst[i]);
6351 s += 4;
6352 }
6353 break;
6354
6355 case MESA_FORMAT_R8G8B8X8_SNORM:
6356 for (i = 0; i < n; ++i) {
6357 unpack_ubyte_r8g8b8x8_snorm(s, dst[i]);
6358 s += 4;
6359 }
6360 break;
6361
6362 case MESA_FORMAT_R16G16_SNORM:
6363 for (i = 0; i < n; ++i) {
6364 unpack_ubyte_r16g16_snorm(s, dst[i]);
6365 s += 4;
6366 }
6367 break;
6368
6369 case MESA_FORMAT_G16R16_SNORM:
6370 for (i = 0; i < n; ++i) {
6371 unpack_ubyte_g16r16_snorm(s, dst[i]);
6372 s += 4;
6373 }
6374 break;
6375
6376 case MESA_FORMAT_R8G8_SNORM:
6377 for (i = 0; i < n; ++i) {
6378 unpack_ubyte_r8g8_snorm(s, dst[i]);
6379 s += 2;
6380 }
6381 break;
6382
6383 case MESA_FORMAT_G8R8_SNORM:
6384 for (i = 0; i < n; ++i) {
6385 unpack_ubyte_g8r8_snorm(s, dst[i]);
6386 s += 2;
6387 }
6388 break;
6389
6390 case MESA_FORMAT_L8A8_SNORM:
6391 for (i = 0; i < n; ++i) {
6392 unpack_ubyte_l8a8_snorm(s, dst[i]);
6393 s += 2;
6394 }
6395 break;
6396
6397 case MESA_FORMAT_A8L8_SNORM:
6398 for (i = 0; i < n; ++i) {
6399 unpack_ubyte_a8l8_snorm(s, dst[i]);
6400 s += 2;
6401 }
6402 break;
6403
6404 case MESA_FORMAT_A_SNORM8:
6405 for (i = 0; i < n; ++i) {
6406 unpack_ubyte_a_snorm8(s, dst[i]);
6407 s += 1;
6408 }
6409 break;
6410
6411 case MESA_FORMAT_A_SNORM16:
6412 for (i = 0; i < n; ++i) {
6413 unpack_ubyte_a_snorm16(s, dst[i]);
6414 s += 2;
6415 }
6416 break;
6417
6418 case MESA_FORMAT_L_SNORM8:
6419 for (i = 0; i < n; ++i) {
6420 unpack_ubyte_l_snorm8(s, dst[i]);
6421 s += 1;
6422 }
6423 break;
6424
6425 case MESA_FORMAT_L_SNORM16:
6426 for (i = 0; i < n; ++i) {
6427 unpack_ubyte_l_snorm16(s, dst[i]);
6428 s += 2;
6429 }
6430 break;
6431
6432 case MESA_FORMAT_I_SNORM8:
6433 for (i = 0; i < n; ++i) {
6434 unpack_ubyte_i_snorm8(s, dst[i]);
6435 s += 1;
6436 }
6437 break;
6438
6439 case MESA_FORMAT_I_SNORM16:
6440 for (i = 0; i < n; ++i) {
6441 unpack_ubyte_i_snorm16(s, dst[i]);
6442 s += 2;
6443 }
6444 break;
6445
6446 case MESA_FORMAT_R_SNORM8:
6447 for (i = 0; i < n; ++i) {
6448 unpack_ubyte_r_snorm8(s, dst[i]);
6449 s += 1;
6450 }
6451 break;
6452
6453 case MESA_FORMAT_R_SNORM16:
6454 for (i = 0; i < n; ++i) {
6455 unpack_ubyte_r_snorm16(s, dst[i]);
6456 s += 2;
6457 }
6458 break;
6459
6460 case MESA_FORMAT_LA_SNORM16:
6461 for (i = 0; i < n; ++i) {
6462 unpack_ubyte_la_snorm16(s, dst[i]);
6463 s += 4;
6464 }
6465 break;
6466
6467 case MESA_FORMAT_RGB_SNORM16:
6468 for (i = 0; i < n; ++i) {
6469 unpack_ubyte_rgb_snorm16(s, dst[i]);
6470 s += 6;
6471 }
6472 break;
6473
6474 case MESA_FORMAT_RGBA_SNORM16:
6475 for (i = 0; i < n; ++i) {
6476 unpack_ubyte_rgba_snorm16(s, dst[i]);
6477 s += 8;
6478 }
6479 break;
6480
6481 case MESA_FORMAT_RGBX_SNORM16:
6482 for (i = 0; i < n; ++i) {
6483 unpack_ubyte_rgbx_snorm16(s, dst[i]);
6484 s += 8;
6485 }
6486 break;
6487
6488 case MESA_FORMAT_A8B8G8R8_SRGB:
6489 for (i = 0; i < n; ++i) {
6490 unpack_ubyte_a8b8g8r8_srgb(s, dst[i]);
6491 s += 4;
6492 }
6493 break;
6494
6495 case MESA_FORMAT_B8G8R8A8_SRGB:
6496 for (i = 0; i < n; ++i) {
6497 unpack_ubyte_b8g8r8a8_srgb(s, dst[i]);
6498 s += 4;
6499 }
6500 break;
6501
6502 case MESA_FORMAT_A8R8G8B8_SRGB:
6503 for (i = 0; i < n; ++i) {
6504 unpack_ubyte_a8r8g8b8_srgb(s, dst[i]);
6505 s += 4;
6506 }
6507 break;
6508
6509 case MESA_FORMAT_B8G8R8X8_SRGB:
6510 for (i = 0; i < n; ++i) {
6511 unpack_ubyte_b8g8r8x8_srgb(s, dst[i]);
6512 s += 4;
6513 }
6514 break;
6515
6516 case MESA_FORMAT_X8R8G8B8_SRGB:
6517 for (i = 0; i < n; ++i) {
6518 unpack_ubyte_x8r8g8b8_srgb(s, dst[i]);
6519 s += 4;
6520 }
6521 break;
6522
6523 case MESA_FORMAT_R8G8B8A8_SRGB:
6524 for (i = 0; i < n; ++i) {
6525 unpack_ubyte_r8g8b8a8_srgb(s, dst[i]);
6526 s += 4;
6527 }
6528 break;
6529
6530 case MESA_FORMAT_R8G8B8X8_SRGB:
6531 for (i = 0; i < n; ++i) {
6532 unpack_ubyte_r8g8b8x8_srgb(s, dst[i]);
6533 s += 4;
6534 }
6535 break;
6536
6537 case MESA_FORMAT_X8B8G8R8_SRGB:
6538 for (i = 0; i < n; ++i) {
6539 unpack_ubyte_x8b8g8r8_srgb(s, dst[i]);
6540 s += 4;
6541 }
6542 break;
6543
6544 case MESA_FORMAT_L8A8_SRGB:
6545 for (i = 0; i < n; ++i) {
6546 unpack_ubyte_l8a8_srgb(s, dst[i]);
6547 s += 2;
6548 }
6549 break;
6550
6551 case MESA_FORMAT_A8L8_SRGB:
6552 for (i = 0; i < n; ++i) {
6553 unpack_ubyte_a8l8_srgb(s, dst[i]);
6554 s += 2;
6555 }
6556 break;
6557
6558 case MESA_FORMAT_L_SRGB8:
6559 for (i = 0; i < n; ++i) {
6560 unpack_ubyte_l_srgb8(s, dst[i]);
6561 s += 1;
6562 }
6563 break;
6564
6565 case MESA_FORMAT_BGR_SRGB8:
6566 for (i = 0; i < n; ++i) {
6567 unpack_ubyte_bgr_srgb8(s, dst[i]);
6568 s += 3;
6569 }
6570 break;
6571 default:
6572 /* get float values, convert to ubyte */
6573 {
6574 GLfloat *tmp = malloc(n * 4 * sizeof(GLfloat));
6575 if (tmp) {
6576 GLuint i;
6577 _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
6578 for (i = 0; i < n; i++) {
6579 dst[i][0] = _mesa_float_to_unorm(tmp[i*4+0], 8);
6580 dst[i][1] = _mesa_float_to_unorm(tmp[i*4+1], 8);
6581 dst[i][2] = _mesa_float_to_unorm(tmp[i*4+2], 8);
6582 dst[i][3] = _mesa_float_to_unorm(tmp[i*4+3], 8);
6583 }
6584 free(tmp);
6585 }
6586 }
6587 break;
6588 }
6589 }
6590
6591 void
_mesa_unpack_uint_rgba_row(mesa_format format,GLuint n,const void * src,GLuint dst[][4])6592 _mesa_unpack_uint_rgba_row(mesa_format format, GLuint n,
6593 const void *src, GLuint dst[][4])
6594 {
6595 GLubyte *s = (GLubyte *)src;
6596 GLuint i;
6597
6598 switch (format) {
6599
6600 case MESA_FORMAT_A8B8G8R8_UINT:
6601 for (i = 0; i < n; ++i) {
6602 unpack_int_a8b8g8r8_uint(s, dst[i]);
6603 s += 4;
6604 }
6605 break;
6606
6607 case MESA_FORMAT_A8R8G8B8_UINT:
6608 for (i = 0; i < n; ++i) {
6609 unpack_int_a8r8g8b8_uint(s, dst[i]);
6610 s += 4;
6611 }
6612 break;
6613
6614 case MESA_FORMAT_R8G8B8A8_UINT:
6615 for (i = 0; i < n; ++i) {
6616 unpack_int_r8g8b8a8_uint(s, dst[i]);
6617 s += 4;
6618 }
6619 break;
6620
6621 case MESA_FORMAT_B8G8R8A8_UINT:
6622 for (i = 0; i < n; ++i) {
6623 unpack_int_b8g8r8a8_uint(s, dst[i]);
6624 s += 4;
6625 }
6626 break;
6627
6628 case MESA_FORMAT_B10G10R10A2_UINT:
6629 for (i = 0; i < n; ++i) {
6630 unpack_int_b10g10r10a2_uint(s, dst[i]);
6631 s += 4;
6632 }
6633 break;
6634
6635 case MESA_FORMAT_R10G10B10A2_UINT:
6636 for (i = 0; i < n; ++i) {
6637 unpack_int_r10g10b10a2_uint(s, dst[i]);
6638 s += 4;
6639 }
6640 break;
6641
6642 case MESA_FORMAT_A2B10G10R10_UINT:
6643 for (i = 0; i < n; ++i) {
6644 unpack_int_a2b10g10r10_uint(s, dst[i]);
6645 s += 4;
6646 }
6647 break;
6648
6649 case MESA_FORMAT_A2R10G10B10_UINT:
6650 for (i = 0; i < n; ++i) {
6651 unpack_int_a2r10g10b10_uint(s, dst[i]);
6652 s += 4;
6653 }
6654 break;
6655
6656 case MESA_FORMAT_B5G6R5_UINT:
6657 for (i = 0; i < n; ++i) {
6658 unpack_int_b5g6r5_uint(s, dst[i]);
6659 s += 2;
6660 }
6661 break;
6662
6663 case MESA_FORMAT_R5G6B5_UINT:
6664 for (i = 0; i < n; ++i) {
6665 unpack_int_r5g6b5_uint(s, dst[i]);
6666 s += 2;
6667 }
6668 break;
6669
6670 case MESA_FORMAT_B2G3R3_UINT:
6671 for (i = 0; i < n; ++i) {
6672 unpack_int_b2g3r3_uint(s, dst[i]);
6673 s += 1;
6674 }
6675 break;
6676
6677 case MESA_FORMAT_R3G3B2_UINT:
6678 for (i = 0; i < n; ++i) {
6679 unpack_int_r3g3b2_uint(s, dst[i]);
6680 s += 1;
6681 }
6682 break;
6683
6684 case MESA_FORMAT_A4B4G4R4_UINT:
6685 for (i = 0; i < n; ++i) {
6686 unpack_int_a4b4g4r4_uint(s, dst[i]);
6687 s += 2;
6688 }
6689 break;
6690
6691 case MESA_FORMAT_R4G4B4A4_UINT:
6692 for (i = 0; i < n; ++i) {
6693 unpack_int_r4g4b4a4_uint(s, dst[i]);
6694 s += 2;
6695 }
6696 break;
6697
6698 case MESA_FORMAT_B4G4R4A4_UINT:
6699 for (i = 0; i < n; ++i) {
6700 unpack_int_b4g4r4a4_uint(s, dst[i]);
6701 s += 2;
6702 }
6703 break;
6704
6705 case MESA_FORMAT_A4R4G4B4_UINT:
6706 for (i = 0; i < n; ++i) {
6707 unpack_int_a4r4g4b4_uint(s, dst[i]);
6708 s += 2;
6709 }
6710 break;
6711
6712 case MESA_FORMAT_A1B5G5R5_UINT:
6713 for (i = 0; i < n; ++i) {
6714 unpack_int_a1b5g5r5_uint(s, dst[i]);
6715 s += 2;
6716 }
6717 break;
6718
6719 case MESA_FORMAT_B5G5R5A1_UINT:
6720 for (i = 0; i < n; ++i) {
6721 unpack_int_b5g5r5a1_uint(s, dst[i]);
6722 s += 2;
6723 }
6724 break;
6725
6726 case MESA_FORMAT_A1R5G5B5_UINT:
6727 for (i = 0; i < n; ++i) {
6728 unpack_int_a1r5g5b5_uint(s, dst[i]);
6729 s += 2;
6730 }
6731 break;
6732
6733 case MESA_FORMAT_R5G5B5A1_UINT:
6734 for (i = 0; i < n; ++i) {
6735 unpack_int_r5g5b5a1_uint(s, dst[i]);
6736 s += 2;
6737 }
6738 break;
6739
6740 case MESA_FORMAT_A_UINT8:
6741 for (i = 0; i < n; ++i) {
6742 unpack_int_a_uint8(s, dst[i]);
6743 s += 1;
6744 }
6745 break;
6746
6747 case MESA_FORMAT_A_UINT16:
6748 for (i = 0; i < n; ++i) {
6749 unpack_int_a_uint16(s, dst[i]);
6750 s += 2;
6751 }
6752 break;
6753
6754 case MESA_FORMAT_A_UINT32:
6755 for (i = 0; i < n; ++i) {
6756 unpack_int_a_uint32(s, dst[i]);
6757 s += 4;
6758 }
6759 break;
6760
6761 case MESA_FORMAT_A_SINT8:
6762 for (i = 0; i < n; ++i) {
6763 unpack_int_a_sint8(s, dst[i]);
6764 s += 1;
6765 }
6766 break;
6767
6768 case MESA_FORMAT_A_SINT16:
6769 for (i = 0; i < n; ++i) {
6770 unpack_int_a_sint16(s, dst[i]);
6771 s += 2;
6772 }
6773 break;
6774
6775 case MESA_FORMAT_A_SINT32:
6776 for (i = 0; i < n; ++i) {
6777 unpack_int_a_sint32(s, dst[i]);
6778 s += 4;
6779 }
6780 break;
6781
6782 case MESA_FORMAT_I_UINT8:
6783 for (i = 0; i < n; ++i) {
6784 unpack_int_i_uint8(s, dst[i]);
6785 s += 1;
6786 }
6787 break;
6788
6789 case MESA_FORMAT_I_UINT16:
6790 for (i = 0; i < n; ++i) {
6791 unpack_int_i_uint16(s, dst[i]);
6792 s += 2;
6793 }
6794 break;
6795
6796 case MESA_FORMAT_I_UINT32:
6797 for (i = 0; i < n; ++i) {
6798 unpack_int_i_uint32(s, dst[i]);
6799 s += 4;
6800 }
6801 break;
6802
6803 case MESA_FORMAT_I_SINT8:
6804 for (i = 0; i < n; ++i) {
6805 unpack_int_i_sint8(s, dst[i]);
6806 s += 1;
6807 }
6808 break;
6809
6810 case MESA_FORMAT_I_SINT16:
6811 for (i = 0; i < n; ++i) {
6812 unpack_int_i_sint16(s, dst[i]);
6813 s += 2;
6814 }
6815 break;
6816
6817 case MESA_FORMAT_I_SINT32:
6818 for (i = 0; i < n; ++i) {
6819 unpack_int_i_sint32(s, dst[i]);
6820 s += 4;
6821 }
6822 break;
6823
6824 case MESA_FORMAT_L_UINT8:
6825 for (i = 0; i < n; ++i) {
6826 unpack_int_l_uint8(s, dst[i]);
6827 s += 1;
6828 }
6829 break;
6830
6831 case MESA_FORMAT_L_UINT16:
6832 for (i = 0; i < n; ++i) {
6833 unpack_int_l_uint16(s, dst[i]);
6834 s += 2;
6835 }
6836 break;
6837
6838 case MESA_FORMAT_L_UINT32:
6839 for (i = 0; i < n; ++i) {
6840 unpack_int_l_uint32(s, dst[i]);
6841 s += 4;
6842 }
6843 break;
6844
6845 case MESA_FORMAT_L_SINT8:
6846 for (i = 0; i < n; ++i) {
6847 unpack_int_l_sint8(s, dst[i]);
6848 s += 1;
6849 }
6850 break;
6851
6852 case MESA_FORMAT_L_SINT16:
6853 for (i = 0; i < n; ++i) {
6854 unpack_int_l_sint16(s, dst[i]);
6855 s += 2;
6856 }
6857 break;
6858
6859 case MESA_FORMAT_L_SINT32:
6860 for (i = 0; i < n; ++i) {
6861 unpack_int_l_sint32(s, dst[i]);
6862 s += 4;
6863 }
6864 break;
6865
6866 case MESA_FORMAT_LA_UINT8:
6867 for (i = 0; i < n; ++i) {
6868 unpack_int_la_uint8(s, dst[i]);
6869 s += 2;
6870 }
6871 break;
6872
6873 case MESA_FORMAT_LA_UINT16:
6874 for (i = 0; i < n; ++i) {
6875 unpack_int_la_uint16(s, dst[i]);
6876 s += 4;
6877 }
6878 break;
6879
6880 case MESA_FORMAT_LA_UINT32:
6881 for (i = 0; i < n; ++i) {
6882 unpack_int_la_uint32(s, dst[i]);
6883 s += 8;
6884 }
6885 break;
6886
6887 case MESA_FORMAT_LA_SINT8:
6888 for (i = 0; i < n; ++i) {
6889 unpack_int_la_sint8(s, dst[i]);
6890 s += 2;
6891 }
6892 break;
6893
6894 case MESA_FORMAT_LA_SINT16:
6895 for (i = 0; i < n; ++i) {
6896 unpack_int_la_sint16(s, dst[i]);
6897 s += 4;
6898 }
6899 break;
6900
6901 case MESA_FORMAT_LA_SINT32:
6902 for (i = 0; i < n; ++i) {
6903 unpack_int_la_sint32(s, dst[i]);
6904 s += 8;
6905 }
6906 break;
6907
6908 case MESA_FORMAT_R_UINT8:
6909 for (i = 0; i < n; ++i) {
6910 unpack_int_r_uint8(s, dst[i]);
6911 s += 1;
6912 }
6913 break;
6914
6915 case MESA_FORMAT_R_UINT16:
6916 for (i = 0; i < n; ++i) {
6917 unpack_int_r_uint16(s, dst[i]);
6918 s += 2;
6919 }
6920 break;
6921
6922 case MESA_FORMAT_R_UINT32:
6923 for (i = 0; i < n; ++i) {
6924 unpack_int_r_uint32(s, dst[i]);
6925 s += 4;
6926 }
6927 break;
6928
6929 case MESA_FORMAT_R_SINT8:
6930 for (i = 0; i < n; ++i) {
6931 unpack_int_r_sint8(s, dst[i]);
6932 s += 1;
6933 }
6934 break;
6935
6936 case MESA_FORMAT_R_SINT16:
6937 for (i = 0; i < n; ++i) {
6938 unpack_int_r_sint16(s, dst[i]);
6939 s += 2;
6940 }
6941 break;
6942
6943 case MESA_FORMAT_R_SINT32:
6944 for (i = 0; i < n; ++i) {
6945 unpack_int_r_sint32(s, dst[i]);
6946 s += 4;
6947 }
6948 break;
6949
6950 case MESA_FORMAT_RG_UINT8:
6951 for (i = 0; i < n; ++i) {
6952 unpack_int_rg_uint8(s, dst[i]);
6953 s += 2;
6954 }
6955 break;
6956
6957 case MESA_FORMAT_RG_UINT16:
6958 for (i = 0; i < n; ++i) {
6959 unpack_int_rg_uint16(s, dst[i]);
6960 s += 4;
6961 }
6962 break;
6963
6964 case MESA_FORMAT_RG_UINT32:
6965 for (i = 0; i < n; ++i) {
6966 unpack_int_rg_uint32(s, dst[i]);
6967 s += 8;
6968 }
6969 break;
6970
6971 case MESA_FORMAT_RG_SINT8:
6972 for (i = 0; i < n; ++i) {
6973 unpack_int_rg_sint8(s, dst[i]);
6974 s += 2;
6975 }
6976 break;
6977
6978 case MESA_FORMAT_RG_SINT16:
6979 for (i = 0; i < n; ++i) {
6980 unpack_int_rg_sint16(s, dst[i]);
6981 s += 4;
6982 }
6983 break;
6984
6985 case MESA_FORMAT_RG_SINT32:
6986 for (i = 0; i < n; ++i) {
6987 unpack_int_rg_sint32(s, dst[i]);
6988 s += 8;
6989 }
6990 break;
6991
6992 case MESA_FORMAT_RGB_UINT8:
6993 for (i = 0; i < n; ++i) {
6994 unpack_int_rgb_uint8(s, dst[i]);
6995 s += 3;
6996 }
6997 break;
6998
6999 case MESA_FORMAT_RGB_UINT16:
7000 for (i = 0; i < n; ++i) {
7001 unpack_int_rgb_uint16(s, dst[i]);
7002 s += 6;
7003 }
7004 break;
7005
7006 case MESA_FORMAT_RGB_UINT32:
7007 for (i = 0; i < n; ++i) {
7008 unpack_int_rgb_uint32(s, dst[i]);
7009 s += 12;
7010 }
7011 break;
7012
7013 case MESA_FORMAT_RGB_SINT8:
7014 for (i = 0; i < n; ++i) {
7015 unpack_int_rgb_sint8(s, dst[i]);
7016 s += 3;
7017 }
7018 break;
7019
7020 case MESA_FORMAT_RGB_SINT16:
7021 for (i = 0; i < n; ++i) {
7022 unpack_int_rgb_sint16(s, dst[i]);
7023 s += 6;
7024 }
7025 break;
7026
7027 case MESA_FORMAT_RGB_SINT32:
7028 for (i = 0; i < n; ++i) {
7029 unpack_int_rgb_sint32(s, dst[i]);
7030 s += 12;
7031 }
7032 break;
7033
7034 case MESA_FORMAT_RGBA_UINT8:
7035 for (i = 0; i < n; ++i) {
7036 unpack_int_rgba_uint8(s, dst[i]);
7037 s += 4;
7038 }
7039 break;
7040
7041 case MESA_FORMAT_RGBA_UINT16:
7042 for (i = 0; i < n; ++i) {
7043 unpack_int_rgba_uint16(s, dst[i]);
7044 s += 8;
7045 }
7046 break;
7047
7048 case MESA_FORMAT_RGBA_UINT32:
7049 for (i = 0; i < n; ++i) {
7050 unpack_int_rgba_uint32(s, dst[i]);
7051 s += 16;
7052 }
7053 break;
7054
7055 case MESA_FORMAT_RGBA_SINT8:
7056 for (i = 0; i < n; ++i) {
7057 unpack_int_rgba_sint8(s, dst[i]);
7058 s += 4;
7059 }
7060 break;
7061
7062 case MESA_FORMAT_RGBA_SINT16:
7063 for (i = 0; i < n; ++i) {
7064 unpack_int_rgba_sint16(s, dst[i]);
7065 s += 8;
7066 }
7067 break;
7068
7069 case MESA_FORMAT_RGBA_SINT32:
7070 for (i = 0; i < n; ++i) {
7071 unpack_int_rgba_sint32(s, dst[i]);
7072 s += 16;
7073 }
7074 break;
7075
7076 case MESA_FORMAT_RGBX_UINT8:
7077 for (i = 0; i < n; ++i) {
7078 unpack_int_rgbx_uint8(s, dst[i]);
7079 s += 4;
7080 }
7081 break;
7082
7083 case MESA_FORMAT_RGBX_UINT16:
7084 for (i = 0; i < n; ++i) {
7085 unpack_int_rgbx_uint16(s, dst[i]);
7086 s += 8;
7087 }
7088 break;
7089
7090 case MESA_FORMAT_RGBX_UINT32:
7091 for (i = 0; i < n; ++i) {
7092 unpack_int_rgbx_uint32(s, dst[i]);
7093 s += 16;
7094 }
7095 break;
7096
7097 case MESA_FORMAT_RGBX_SINT8:
7098 for (i = 0; i < n; ++i) {
7099 unpack_int_rgbx_sint8(s, dst[i]);
7100 s += 4;
7101 }
7102 break;
7103
7104 case MESA_FORMAT_RGBX_SINT16:
7105 for (i = 0; i < n; ++i) {
7106 unpack_int_rgbx_sint16(s, dst[i]);
7107 s += 8;
7108 }
7109 break;
7110
7111 case MESA_FORMAT_RGBX_SINT32:
7112 for (i = 0; i < n; ++i) {
7113 unpack_int_rgbx_sint32(s, dst[i]);
7114 s += 16;
7115 }
7116 break;
7117 default:
7118 _mesa_problem(NULL, "%s: bad format %s", __func__,
7119 _mesa_get_format_name(format));
7120 return;
7121 }
7122 }
7123
7124 /**
7125 * Unpack a 2D rect of pixels returning float RGBA colors.
7126 * \param format the source image format
7127 * \param src start address of the source image
7128 * \param srcRowStride source image row stride in bytes
7129 * \param dst start address of the dest image
7130 * \param dstRowStride dest image row stride in bytes
7131 * \param x source image start X pos
7132 * \param y source image start Y pos
7133 * \param width width of rect region to convert
7134 * \param height height of rect region to convert
7135 */
7136 void
_mesa_unpack_rgba_block(mesa_format format,const void * src,GLint srcRowStride,GLfloat dst[][4],GLint dstRowStride,GLuint x,GLuint y,GLuint width,GLuint height)7137 _mesa_unpack_rgba_block(mesa_format format,
7138 const void *src, GLint srcRowStride,
7139 GLfloat dst[][4], GLint dstRowStride,
7140 GLuint x, GLuint y, GLuint width, GLuint height)
7141 {
7142 const GLuint srcPixStride = _mesa_get_format_bytes(format);
7143 const GLuint dstPixStride = 4 * sizeof(GLfloat);
7144 const GLubyte *srcRow;
7145 GLubyte *dstRow;
7146 GLuint i;
7147
7148 /* XXX needs to be fixed for compressed formats */
7149
7150 srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
7151 dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
7152
7153 for (i = 0; i < height; i++) {
7154 _mesa_unpack_rgba_row(format, width, srcRow, (GLfloat (*)[4]) dstRow);
7155
7156 dstRow += dstRowStride;
7157 srcRow += srcRowStride;
7158 }
7159 }
7160
7161 /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
7162 struct z32f_x24s8
7163 {
7164 float z;
7165 uint32_t x24s8;
7166 };
7167
7168 typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
7169
7170 static void
unpack_float_z_X8_UINT_Z24_UNORM(GLuint n,const void * src,GLfloat * dst)7171 unpack_float_z_X8_UINT_Z24_UNORM(GLuint n, const void *src, GLfloat *dst)
7172 {
7173 /* only return Z, not stencil data */
7174 const GLuint *s = ((const GLuint *) src);
7175 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
7176 GLuint i;
7177 for (i = 0; i < n; i++) {
7178 dst[i] = (GLfloat) ((s[i] >> 8) * scale);
7179 assert(dst[i] >= 0.0F);
7180 assert(dst[i] <= 1.0F);
7181 }
7182 }
7183
7184 static void
unpack_float_z_Z24_UNORM_X8_UINT(GLuint n,const void * src,GLfloat * dst)7185 unpack_float_z_Z24_UNORM_X8_UINT(GLuint n, const void *src, GLfloat *dst)
7186 {
7187 /* only return Z, not stencil data */
7188 const GLuint *s = ((const GLuint *) src);
7189 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
7190 GLuint i;
7191 for (i = 0; i < n; i++) {
7192 dst[i] = (GLfloat) ((s[i] & 0x00ffffff) * scale);
7193 assert(dst[i] >= 0.0F);
7194 assert(dst[i] <= 1.0F);
7195 }
7196 }
7197
7198 static void
unpack_float_Z_UNORM16(GLuint n,const void * src,GLfloat * dst)7199 unpack_float_Z_UNORM16(GLuint n, const void *src, GLfloat *dst)
7200 {
7201 const GLushort *s = ((const GLushort *) src);
7202 GLuint i;
7203 for (i = 0; i < n; i++) {
7204 dst[i] = s[i] * (1.0F / 65535.0F);
7205 }
7206 }
7207
7208 static void
unpack_float_Z_UNORM32(GLuint n,const void * src,GLfloat * dst)7209 unpack_float_Z_UNORM32(GLuint n, const void *src, GLfloat *dst)
7210 {
7211 const GLuint *s = ((const GLuint *) src);
7212 GLuint i;
7213 for (i = 0; i < n; i++) {
7214 dst[i] = s[i] * (1.0F / 0xffffffff);
7215 }
7216 }
7217
7218 static void
unpack_float_Z_FLOAT32(GLuint n,const void * src,GLfloat * dst)7219 unpack_float_Z_FLOAT32(GLuint n, const void *src, GLfloat *dst)
7220 {
7221 memcpy(dst, src, n * sizeof(float));
7222 }
7223
7224 static void
unpack_float_z_Z32X24S8(GLuint n,const void * src,GLfloat * dst)7225 unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
7226 {
7227 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
7228 GLuint i;
7229 for (i = 0; i < n; i++) {
7230 dst[i] = s[i].z;
7231 }
7232 }
7233
7234
7235
7236 /**
7237 * Unpack Z values.
7238 * The returned values will always be in the range [0.0, 1.0].
7239 */
7240 void
_mesa_unpack_float_z_row(mesa_format format,GLuint n,const void * src,GLfloat * dst)7241 _mesa_unpack_float_z_row(mesa_format format, GLuint n,
7242 const void *src, GLfloat *dst)
7243 {
7244 unpack_float_z_func unpack;
7245
7246 switch (format) {
7247 case MESA_FORMAT_S8_UINT_Z24_UNORM:
7248 case MESA_FORMAT_X8_UINT_Z24_UNORM:
7249 unpack = unpack_float_z_X8_UINT_Z24_UNORM;
7250 break;
7251 case MESA_FORMAT_Z24_UNORM_S8_UINT:
7252 case MESA_FORMAT_Z24_UNORM_X8_UINT:
7253 unpack = unpack_float_z_Z24_UNORM_X8_UINT;
7254 break;
7255 case MESA_FORMAT_Z_UNORM16:
7256 unpack = unpack_float_Z_UNORM16;
7257 break;
7258 case MESA_FORMAT_Z_UNORM32:
7259 unpack = unpack_float_Z_UNORM32;
7260 break;
7261 case MESA_FORMAT_Z_FLOAT32:
7262 unpack = unpack_float_Z_FLOAT32;
7263 break;
7264 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
7265 unpack = unpack_float_z_Z32X24S8;
7266 break;
7267 default:
7268 _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
7269 _mesa_get_format_name(format));
7270 return;
7271 }
7272
7273 unpack(n, src, dst);
7274 }
7275
7276
7277
7278 typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
7279
7280 static void
unpack_uint_z_X8_UINT_Z24_UNORM(const void * src,GLuint * dst,GLuint n)7281 unpack_uint_z_X8_UINT_Z24_UNORM(const void *src, GLuint *dst, GLuint n)
7282 {
7283 /* only return Z, not stencil data */
7284 const GLuint *s = ((const GLuint *) src);
7285 GLuint i;
7286 for (i = 0; i < n; i++) {
7287 dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
7288 }
7289 }
7290
7291 static void
unpack_uint_z_Z24_UNORM_X8_UINT(const void * src,GLuint * dst,GLuint n)7292 unpack_uint_z_Z24_UNORM_X8_UINT(const void *src, GLuint *dst, GLuint n)
7293 {
7294 /* only return Z, not stencil data */
7295 const GLuint *s = ((const GLuint *) src);
7296 GLuint i;
7297 for (i = 0; i < n; i++) {
7298 dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
7299 }
7300 }
7301
7302 static void
unpack_uint_Z_UNORM16(const void * src,GLuint * dst,GLuint n)7303 unpack_uint_Z_UNORM16(const void *src, GLuint *dst, GLuint n)
7304 {
7305 const GLushort *s = ((const GLushort *)src);
7306 GLuint i;
7307 for (i = 0; i < n; i++) {
7308 dst[i] = (s[i] << 16) | s[i];
7309 }
7310 }
7311
7312 static void
unpack_uint_Z_UNORM32(const void * src,GLuint * dst,GLuint n)7313 unpack_uint_Z_UNORM32(const void *src, GLuint *dst, GLuint n)
7314 {
7315 memcpy(dst, src, n * sizeof(GLuint));
7316 }
7317
7318 static void
unpack_uint_Z_FLOAT32(const void * src,GLuint * dst,GLuint n)7319 unpack_uint_Z_FLOAT32(const void *src, GLuint *dst, GLuint n)
7320 {
7321 const float *s = (const float *)src;
7322 GLuint i;
7323 for (i = 0; i < n; i++) {
7324 dst[i] = FLOAT_TO_UINT(CLAMP(s[i], 0.0F, 1.0F));
7325 }
7326 }
7327
7328 static void
unpack_uint_Z_FLOAT32_X24S8(const void * src,GLuint * dst,GLuint n)7329 unpack_uint_Z_FLOAT32_X24S8(const void *src, GLuint *dst, GLuint n)
7330 {
7331 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
7332 GLuint i;
7333
7334 for (i = 0; i < n; i++) {
7335 dst[i] = FLOAT_TO_UINT(CLAMP(s[i].z, 0.0F, 1.0F));
7336 }
7337 }
7338
7339
7340 /**
7341 * Unpack Z values.
7342 * The returned values will always be in the range [0, 0xffffffff].
7343 */
7344 void
_mesa_unpack_uint_z_row(mesa_format format,GLuint n,const void * src,GLuint * dst)7345 _mesa_unpack_uint_z_row(mesa_format format, GLuint n,
7346 const void *src, GLuint *dst)
7347 {
7348 unpack_uint_z_func unpack;
7349 const GLubyte *srcPtr = (GLubyte *) src;
7350
7351 switch (format) {
7352 case MESA_FORMAT_S8_UINT_Z24_UNORM:
7353 case MESA_FORMAT_X8_UINT_Z24_UNORM:
7354 unpack = unpack_uint_z_X8_UINT_Z24_UNORM;
7355 break;
7356 case MESA_FORMAT_Z24_UNORM_S8_UINT:
7357 case MESA_FORMAT_Z24_UNORM_X8_UINT:
7358 unpack = unpack_uint_z_Z24_UNORM_X8_UINT;
7359 break;
7360 case MESA_FORMAT_Z_UNORM16:
7361 unpack = unpack_uint_Z_UNORM16;
7362 break;
7363 case MESA_FORMAT_Z_UNORM32:
7364 unpack = unpack_uint_Z_UNORM32;
7365 break;
7366 case MESA_FORMAT_Z_FLOAT32:
7367 unpack = unpack_uint_Z_FLOAT32;
7368 break;
7369 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
7370 unpack = unpack_uint_Z_FLOAT32_X24S8;
7371 break;
7372 default:
7373 _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
7374 _mesa_get_format_name(format));
7375 return;
7376 }
7377
7378 unpack(srcPtr, dst, n);
7379 }
7380
7381
7382 static void
unpack_ubyte_s_S_UINT8(const void * src,GLubyte * dst,GLuint n)7383 unpack_ubyte_s_S_UINT8(const void *src, GLubyte *dst, GLuint n)
7384 {
7385 memcpy(dst, src, n);
7386 }
7387
7388 static void
unpack_ubyte_s_S8_UINT_Z24_UNORM(const void * src,GLubyte * dst,GLuint n)7389 unpack_ubyte_s_S8_UINT_Z24_UNORM(const void *src, GLubyte *dst, GLuint n)
7390 {
7391 GLuint i;
7392 const GLuint *src32 = src;
7393
7394 for (i = 0; i < n; i++)
7395 dst[i] = src32[i] & 0xff;
7396 }
7397
7398 static void
unpack_ubyte_s_Z24_UNORM_S8_UINT(const void * src,GLubyte * dst,GLuint n)7399 unpack_ubyte_s_Z24_UNORM_S8_UINT(const void *src, GLubyte *dst, GLuint n)
7400 {
7401 GLuint i;
7402 const GLuint *src32 = src;
7403
7404 for (i = 0; i < n; i++)
7405 dst[i] = src32[i] >> 24;
7406 }
7407
7408 static void
unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(const void * src,GLubyte * dst,GLuint n)7409 unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(const void *src, GLubyte *dst, GLuint n)
7410 {
7411 GLuint i;
7412 const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
7413
7414 for (i = 0; i < n; i++)
7415 dst[i] = s[i].x24s8 & 0xff;
7416 }
7417
7418 void
_mesa_unpack_ubyte_stencil_row(mesa_format format,GLuint n,const void * src,GLubyte * dst)7419 _mesa_unpack_ubyte_stencil_row(mesa_format format, GLuint n,
7420 const void *src, GLubyte *dst)
7421 {
7422 switch (format) {
7423 case MESA_FORMAT_S_UINT8:
7424 unpack_ubyte_s_S_UINT8(src, dst, n);
7425 break;
7426 case MESA_FORMAT_S8_UINT_Z24_UNORM:
7427 unpack_ubyte_s_S8_UINT_Z24_UNORM(src, dst, n);
7428 break;
7429 case MESA_FORMAT_Z24_UNORM_S8_UINT:
7430 unpack_ubyte_s_Z24_UNORM_S8_UINT(src, dst, n);
7431 break;
7432 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
7433 unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(src, dst, n);
7434 break;
7435 default:
7436 _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
7437 _mesa_get_format_name(format));
7438 return;
7439 }
7440 }
7441
7442 static void
unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(const GLuint * src,GLuint * dst,GLuint n)7443 unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(const GLuint *src, GLuint *dst, GLuint n)
7444 {
7445 GLuint i;
7446
7447 for (i = 0; i < n; i++) {
7448 GLuint val = src[i];
7449 dst[i] = val >> 24 | val << 8;
7450 }
7451 }
7452
7453 static void
unpack_uint_24_8_depth_stencil_Z32_S8X24(const GLuint * src,GLuint * dst,GLuint n)7454 unpack_uint_24_8_depth_stencil_Z32_S8X24(const GLuint *src,
7455 GLuint *dst, GLuint n)
7456 {
7457 GLuint i;
7458
7459 for (i = 0; i < n; i++) {
7460 /* 8 bytes per pixel (float + uint32) */
7461 GLfloat zf = ((GLfloat *) src)[i * 2 + 0];
7462 GLuint z24 = (GLuint) (zf * (GLfloat) 0xffffff);
7463 GLuint s = src[i * 2 + 1] & 0xff;
7464 dst[i] = (z24 << 8) | s;
7465 }
7466 }
7467
7468 static void
unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(const GLuint * src,GLuint * dst,GLuint n)7469 unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(const GLuint *src, GLuint *dst, GLuint n)
7470 {
7471 memcpy(dst, src, n * 4);
7472 }
7473
7474 /**
7475 * Unpack depth/stencil returning as GL_UNSIGNED_INT_24_8.
7476 * \param format the source data format
7477 */
7478 void
_mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format,GLuint n,const void * src,GLuint * dst)7479 _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
7480 const void *src, GLuint *dst)
7481 {
7482 switch (format) {
7483 case MESA_FORMAT_S8_UINT_Z24_UNORM:
7484 unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(src, dst, n);
7485 break;
7486 case MESA_FORMAT_Z24_UNORM_S8_UINT:
7487 unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(src, dst, n);
7488 break;
7489 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
7490 unpack_uint_24_8_depth_stencil_Z32_S8X24(src, dst, n);
7491 break;
7492 default:
7493 _mesa_problem(NULL,
7494 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
7495 _mesa_get_format_name(format));
7496 return;
7497 }
7498 }
7499
7500 static void
unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(const GLuint * src,GLuint * dst,GLuint n)7501 unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(const GLuint *src,
7502 GLuint *dst, GLuint n)
7503 {
7504 GLuint i;
7505 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
7506 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
7507
7508 for (i = 0; i < n; i++) {
7509 const GLuint z24 = src[i] & 0xffffff;
7510 d[i].z = z24 * scale;
7511 d[i].x24s8 = src[i] >> 24;
7512 assert(d[i].z >= 0.0f);
7513 assert(d[i].z <= 1.0f);
7514 }
7515 }
7516
7517 static void
unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(const GLuint * src,GLuint * dst,GLuint n)7518 unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(const GLuint *src,
7519 GLuint *dst, GLuint n)
7520 {
7521 memcpy(dst, src, n * sizeof(struct z32f_x24s8));
7522 }
7523
7524 static void
unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(const GLuint * src,GLuint * dst,GLuint n)7525 unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(const GLuint *src,
7526 GLuint *dst, GLuint n)
7527 {
7528 GLuint i;
7529 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
7530 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
7531
7532 for (i = 0; i < n; i++) {
7533 const GLuint z24 = src[i] >> 8;
7534 d[i].z = z24 * scale;
7535 d[i].x24s8 = src[i] & 0xff;
7536 assert(d[i].z >= 0.0f);
7537 assert(d[i].z <= 1.0f);
7538 }
7539 }
7540
7541 /**
7542 * Unpack depth/stencil returning as GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
7543 * \param format the source data format
7544 *
7545 * In GL_FLOAT_32_UNSIGNED_INT_24_8_REV lower 4 bytes contain float
7546 * component and higher 4 bytes contain packed 24-bit and 8-bit
7547 * components.
7548 *
7549 * 31 30 29 28 ... 4 3 2 1 0 31 30 29 ... 9 8 7 6 5 ... 2 1 0
7550 * +-------------------------+ +--------------------------------+
7551 * | Float Component | | Unused | 8 bit stencil |
7552 * +-------------------------+ +--------------------------------+
7553 * lower 4 bytes higher 4 bytes
7554 */
7555 void
_mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format,GLuint n,const void * src,GLuint * dst)7556 _mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
7557 const void *src, GLuint *dst)
7558 {
7559 switch (format) {
7560 case MESA_FORMAT_S8_UINT_Z24_UNORM:
7561 unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(src, dst, n);
7562 break;
7563 case MESA_FORMAT_Z24_UNORM_S8_UINT:
7564 unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(src, dst, n);
7565 break;
7566 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
7567 unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(src, dst, n);
7568 break;
7569 default:
7570 _mesa_problem(NULL,
7571 "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
7572 _mesa_get_format_name(format));
7573 return;
7574 }
7575 }
7576
7577 /**
7578 * Unpack depth/stencil
7579 * \param format the source data format
7580 * \param type the destination data type
7581 */
7582 void
_mesa_unpack_depth_stencil_row(mesa_format format,GLuint n,const void * src,GLenum type,GLuint * dst)7583 _mesa_unpack_depth_stencil_row(mesa_format format, GLuint n,
7584 const void *src, GLenum type,
7585 GLuint *dst)
7586 {
7587 assert(type == GL_UNSIGNED_INT_24_8 ||
7588 type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
7589
7590 switch (type) {
7591 case GL_UNSIGNED_INT_24_8:
7592 _mesa_unpack_uint_24_8_depth_stencil_row(format, n, src, dst);
7593 break;
7594 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
7595 _mesa_unpack_float_32_uint_24_8_depth_stencil_row(format, n, src, dst);
7596 break;
7597 default:
7598 _mesa_problem(NULL,
7599 "bad type 0x%x in _mesa_unpack_depth_stencil_row",
7600 type);
7601 return;
7602 }
7603 }
7604
7605