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