format_pack.c revision b8e80941
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 "config.h"
42#include "errors.h"
43#include "format_pack.h"
44#include "format_utils.h"
45#include "macros.h"
46#include "util/format_rgb9e5.h"
47#include "util/format_r11g11b10f.h"
48#include "util/format_srgb.h"
49
50#define UNPACK(SRC, OFFSET, BITS) (((SRC) >> (OFFSET)) & MAX_UINT(BITS))
51#define PACK(SRC, OFFSET, BITS) (((SRC) & MAX_UINT(BITS)) << (OFFSET))
52
53
54
55/* ubyte packing functions */
56
57
58static inline void
59pack_ubyte_a8b8g8r8_unorm(const GLubyte src[4], void *dst)
60{
61
62
63      uint8_t a =
64            _mesa_unorm_to_unorm(src[3], 8, 8);
65
66
67      uint8_t b =
68            _mesa_unorm_to_unorm(src[2], 8, 8);
69
70
71      uint8_t g =
72            _mesa_unorm_to_unorm(src[1], 8, 8);
73
74
75      uint8_t r =
76            _mesa_unorm_to_unorm(src[0], 8, 8);
77
78      uint32_t d = 0;
79         d |= PACK(a, 0, 8);
80         d |= PACK(b, 8, 8);
81         d |= PACK(g, 16, 8);
82         d |= PACK(r, 24, 8);
83      (*(uint32_t *)dst) = d;
84}
85
86static inline void
87pack_ubyte_x8b8g8r8_unorm(const GLubyte src[4], void *dst)
88{
89
90
91
92      uint8_t b =
93            _mesa_unorm_to_unorm(src[2], 8, 8);
94
95
96      uint8_t g =
97            _mesa_unorm_to_unorm(src[1], 8, 8);
98
99
100      uint8_t r =
101            _mesa_unorm_to_unorm(src[0], 8, 8);
102
103      uint32_t d = 0;
104                     d |= PACK(b, 8, 8);
105         d |= PACK(g, 16, 8);
106         d |= PACK(r, 24, 8);
107      (*(uint32_t *)dst) = d;
108}
109
110static inline void
111pack_ubyte_r8g8b8a8_unorm(const GLubyte src[4], void *dst)
112{
113
114
115      uint8_t r =
116            _mesa_unorm_to_unorm(src[0], 8, 8);
117
118
119      uint8_t g =
120            _mesa_unorm_to_unorm(src[1], 8, 8);
121
122
123      uint8_t b =
124            _mesa_unorm_to_unorm(src[2], 8, 8);
125
126
127      uint8_t a =
128            _mesa_unorm_to_unorm(src[3], 8, 8);
129
130      uint32_t d = 0;
131         d |= PACK(r, 0, 8);
132         d |= PACK(g, 8, 8);
133         d |= PACK(b, 16, 8);
134         d |= PACK(a, 24, 8);
135      (*(uint32_t *)dst) = d;
136}
137
138static inline void
139pack_ubyte_r8g8b8x8_unorm(const GLubyte src[4], void *dst)
140{
141
142
143      uint8_t r =
144            _mesa_unorm_to_unorm(src[0], 8, 8);
145
146
147      uint8_t g =
148            _mesa_unorm_to_unorm(src[1], 8, 8);
149
150
151      uint8_t b =
152            _mesa_unorm_to_unorm(src[2], 8, 8);
153
154
155      uint32_t d = 0;
156         d |= PACK(r, 0, 8);
157         d |= PACK(g, 8, 8);
158         d |= PACK(b, 16, 8);
159                  (*(uint32_t *)dst) = d;
160}
161
162static inline void
163pack_ubyte_b8g8r8a8_unorm(const GLubyte src[4], void *dst)
164{
165
166
167      uint8_t b =
168            _mesa_unorm_to_unorm(src[2], 8, 8);
169
170
171      uint8_t g =
172            _mesa_unorm_to_unorm(src[1], 8, 8);
173
174
175      uint8_t r =
176            _mesa_unorm_to_unorm(src[0], 8, 8);
177
178
179      uint8_t a =
180            _mesa_unorm_to_unorm(src[3], 8, 8);
181
182      uint32_t d = 0;
183         d |= PACK(b, 0, 8);
184         d |= PACK(g, 8, 8);
185         d |= PACK(r, 16, 8);
186         d |= PACK(a, 24, 8);
187      (*(uint32_t *)dst) = d;
188}
189
190static inline void
191pack_ubyte_b8g8r8x8_unorm(const GLubyte src[4], void *dst)
192{
193
194
195      uint8_t b =
196            _mesa_unorm_to_unorm(src[2], 8, 8);
197
198
199      uint8_t g =
200            _mesa_unorm_to_unorm(src[1], 8, 8);
201
202
203      uint8_t r =
204            _mesa_unorm_to_unorm(src[0], 8, 8);
205
206
207      uint32_t d = 0;
208         d |= PACK(b, 0, 8);
209         d |= PACK(g, 8, 8);
210         d |= PACK(r, 16, 8);
211                  (*(uint32_t *)dst) = d;
212}
213
214static inline void
215pack_ubyte_a8r8g8b8_unorm(const GLubyte src[4], void *dst)
216{
217
218
219      uint8_t a =
220            _mesa_unorm_to_unorm(src[3], 8, 8);
221
222
223      uint8_t r =
224            _mesa_unorm_to_unorm(src[0], 8, 8);
225
226
227      uint8_t g =
228            _mesa_unorm_to_unorm(src[1], 8, 8);
229
230
231      uint8_t b =
232            _mesa_unorm_to_unorm(src[2], 8, 8);
233
234      uint32_t d = 0;
235         d |= PACK(a, 0, 8);
236         d |= PACK(r, 8, 8);
237         d |= PACK(g, 16, 8);
238         d |= PACK(b, 24, 8);
239      (*(uint32_t *)dst) = d;
240}
241
242static inline void
243pack_ubyte_x8r8g8b8_unorm(const GLubyte src[4], void *dst)
244{
245
246
247
248      uint8_t r =
249            _mesa_unorm_to_unorm(src[0], 8, 8);
250
251
252      uint8_t g =
253            _mesa_unorm_to_unorm(src[1], 8, 8);
254
255
256      uint8_t b =
257            _mesa_unorm_to_unorm(src[2], 8, 8);
258
259      uint32_t d = 0;
260                     d |= PACK(r, 8, 8);
261         d |= PACK(g, 16, 8);
262         d |= PACK(b, 24, 8);
263      (*(uint32_t *)dst) = d;
264}
265
266static inline void
267pack_ubyte_l16a16_unorm(const GLubyte src[4], void *dst)
268{
269
270
271      uint16_t l =
272            _mesa_unorm_to_unorm(src[0], 8, 16);
273
274
275      uint16_t a =
276            _mesa_unorm_to_unorm(src[3], 8, 16);
277
278      uint32_t d = 0;
279         d |= PACK(l, 0, 16);
280         d |= PACK(a, 16, 16);
281      (*(uint32_t *)dst) = d;
282}
283
284static inline void
285pack_ubyte_a16l16_unorm(const GLubyte src[4], void *dst)
286{
287
288
289      uint16_t a =
290            _mesa_unorm_to_unorm(src[3], 8, 16);
291
292
293      uint16_t l =
294            _mesa_unorm_to_unorm(src[0], 8, 16);
295
296      uint32_t d = 0;
297         d |= PACK(a, 0, 16);
298         d |= PACK(l, 16, 16);
299      (*(uint32_t *)dst) = d;
300}
301
302static inline void
303pack_ubyte_b5g6r5_unorm(const GLubyte src[4], void *dst)
304{
305
306
307      uint8_t b =
308            _mesa_unorm_to_unorm(src[2], 8, 5);
309
310
311      uint8_t g =
312            _mesa_unorm_to_unorm(src[1], 8, 6);
313
314
315      uint8_t r =
316            _mesa_unorm_to_unorm(src[0], 8, 5);
317
318      uint16_t d = 0;
319         d |= PACK(b, 0, 5);
320         d |= PACK(g, 5, 6);
321         d |= PACK(r, 11, 5);
322      (*(uint16_t *)dst) = d;
323}
324
325static inline void
326pack_ubyte_r5g6b5_unorm(const GLubyte src[4], void *dst)
327{
328
329
330      uint8_t r =
331            _mesa_unorm_to_unorm(src[0], 8, 5);
332
333
334      uint8_t g =
335            _mesa_unorm_to_unorm(src[1], 8, 6);
336
337
338      uint8_t b =
339            _mesa_unorm_to_unorm(src[2], 8, 5);
340
341      uint16_t d = 0;
342         d |= PACK(r, 0, 5);
343         d |= PACK(g, 5, 6);
344         d |= PACK(b, 11, 5);
345      (*(uint16_t *)dst) = d;
346}
347
348static inline void
349pack_ubyte_b4g4r4a4_unorm(const GLubyte src[4], void *dst)
350{
351
352
353      uint8_t b =
354            _mesa_unorm_to_unorm(src[2], 8, 4);
355
356
357      uint8_t g =
358            _mesa_unorm_to_unorm(src[1], 8, 4);
359
360
361      uint8_t r =
362            _mesa_unorm_to_unorm(src[0], 8, 4);
363
364
365      uint8_t a =
366            _mesa_unorm_to_unorm(src[3], 8, 4);
367
368      uint16_t d = 0;
369         d |= PACK(b, 0, 4);
370         d |= PACK(g, 4, 4);
371         d |= PACK(r, 8, 4);
372         d |= PACK(a, 12, 4);
373      (*(uint16_t *)dst) = d;
374}
375
376static inline void
377pack_ubyte_b4g4r4x4_unorm(const GLubyte src[4], void *dst)
378{
379
380
381      uint8_t b =
382            _mesa_unorm_to_unorm(src[2], 8, 4);
383
384
385      uint8_t g =
386            _mesa_unorm_to_unorm(src[1], 8, 4);
387
388
389      uint8_t r =
390            _mesa_unorm_to_unorm(src[0], 8, 4);
391
392
393      uint16_t d = 0;
394         d |= PACK(b, 0, 4);
395         d |= PACK(g, 4, 4);
396         d |= PACK(r, 8, 4);
397                  (*(uint16_t *)dst) = d;
398}
399
400static inline void
401pack_ubyte_a4r4g4b4_unorm(const GLubyte src[4], void *dst)
402{
403
404
405      uint8_t a =
406            _mesa_unorm_to_unorm(src[3], 8, 4);
407
408
409      uint8_t r =
410            _mesa_unorm_to_unorm(src[0], 8, 4);
411
412
413      uint8_t g =
414            _mesa_unorm_to_unorm(src[1], 8, 4);
415
416
417      uint8_t b =
418            _mesa_unorm_to_unorm(src[2], 8, 4);
419
420      uint16_t d = 0;
421         d |= PACK(a, 0, 4);
422         d |= PACK(r, 4, 4);
423         d |= PACK(g, 8, 4);
424         d |= PACK(b, 12, 4);
425      (*(uint16_t *)dst) = d;
426}
427
428static inline void
429pack_ubyte_a1b5g5r5_unorm(const GLubyte src[4], void *dst)
430{
431
432
433      uint8_t a =
434            _mesa_unorm_to_unorm(src[3], 8, 1);
435
436
437      uint8_t b =
438            _mesa_unorm_to_unorm(src[2], 8, 5);
439
440
441      uint8_t g =
442            _mesa_unorm_to_unorm(src[1], 8, 5);
443
444
445      uint8_t r =
446            _mesa_unorm_to_unorm(src[0], 8, 5);
447
448      uint16_t d = 0;
449         d |= PACK(a, 0, 1);
450         d |= PACK(b, 1, 5);
451         d |= PACK(g, 6, 5);
452         d |= PACK(r, 11, 5);
453      (*(uint16_t *)dst) = d;
454}
455
456static inline void
457pack_ubyte_x1b5g5r5_unorm(const GLubyte src[4], void *dst)
458{
459
460
461
462      uint8_t b =
463            _mesa_unorm_to_unorm(src[2], 8, 5);
464
465
466      uint8_t g =
467            _mesa_unorm_to_unorm(src[1], 8, 5);
468
469
470      uint8_t r =
471            _mesa_unorm_to_unorm(src[0], 8, 5);
472
473      uint16_t d = 0;
474                     d |= PACK(b, 1, 5);
475         d |= PACK(g, 6, 5);
476         d |= PACK(r, 11, 5);
477      (*(uint16_t *)dst) = d;
478}
479
480static inline void
481pack_ubyte_b5g5r5a1_unorm(const GLubyte src[4], void *dst)
482{
483
484
485      uint8_t b =
486            _mesa_unorm_to_unorm(src[2], 8, 5);
487
488
489      uint8_t g =
490            _mesa_unorm_to_unorm(src[1], 8, 5);
491
492
493      uint8_t r =
494            _mesa_unorm_to_unorm(src[0], 8, 5);
495
496
497      uint8_t a =
498            _mesa_unorm_to_unorm(src[3], 8, 1);
499
500      uint16_t d = 0;
501         d |= PACK(b, 0, 5);
502         d |= PACK(g, 5, 5);
503         d |= PACK(r, 10, 5);
504         d |= PACK(a, 15, 1);
505      (*(uint16_t *)dst) = d;
506}
507
508static inline void
509pack_ubyte_b5g5r5x1_unorm(const GLubyte src[4], void *dst)
510{
511
512
513      uint8_t b =
514            _mesa_unorm_to_unorm(src[2], 8, 5);
515
516
517      uint8_t g =
518            _mesa_unorm_to_unorm(src[1], 8, 5);
519
520
521      uint8_t r =
522            _mesa_unorm_to_unorm(src[0], 8, 5);
523
524
525      uint16_t d = 0;
526         d |= PACK(b, 0, 5);
527         d |= PACK(g, 5, 5);
528         d |= PACK(r, 10, 5);
529                  (*(uint16_t *)dst) = d;
530}
531
532static inline void
533pack_ubyte_a1r5g5b5_unorm(const GLubyte src[4], void *dst)
534{
535
536
537      uint8_t a =
538            _mesa_unorm_to_unorm(src[3], 8, 1);
539
540
541      uint8_t r =
542            _mesa_unorm_to_unorm(src[0], 8, 5);
543
544
545      uint8_t g =
546            _mesa_unorm_to_unorm(src[1], 8, 5);
547
548
549      uint8_t b =
550            _mesa_unorm_to_unorm(src[2], 8, 5);
551
552      uint16_t d = 0;
553         d |= PACK(a, 0, 1);
554         d |= PACK(r, 1, 5);
555         d |= PACK(g, 6, 5);
556         d |= PACK(b, 11, 5);
557      (*(uint16_t *)dst) = d;
558}
559
560static inline void
561pack_ubyte_l8a8_unorm(const GLubyte src[4], void *dst)
562{
563
564
565      uint8_t l =
566            _mesa_unorm_to_unorm(src[0], 8, 8);
567
568
569      uint8_t a =
570            _mesa_unorm_to_unorm(src[3], 8, 8);
571
572      uint16_t d = 0;
573         d |= PACK(l, 0, 8);
574         d |= PACK(a, 8, 8);
575      (*(uint16_t *)dst) = d;
576}
577
578static inline void
579pack_ubyte_a8l8_unorm(const GLubyte src[4], void *dst)
580{
581
582
583      uint8_t a =
584            _mesa_unorm_to_unorm(src[3], 8, 8);
585
586
587      uint8_t l =
588            _mesa_unorm_to_unorm(src[0], 8, 8);
589
590      uint16_t d = 0;
591         d |= PACK(a, 0, 8);
592         d |= PACK(l, 8, 8);
593      (*(uint16_t *)dst) = d;
594}
595
596static inline void
597pack_ubyte_r8g8_unorm(const GLubyte src[4], void *dst)
598{
599
600
601      uint8_t r =
602            _mesa_unorm_to_unorm(src[0], 8, 8);
603
604
605      uint8_t g =
606            _mesa_unorm_to_unorm(src[1], 8, 8);
607
608      uint16_t d = 0;
609         d |= PACK(r, 0, 8);
610         d |= PACK(g, 8, 8);
611      (*(uint16_t *)dst) = d;
612}
613
614static inline void
615pack_ubyte_g8r8_unorm(const GLubyte src[4], void *dst)
616{
617
618
619      uint8_t g =
620            _mesa_unorm_to_unorm(src[1], 8, 8);
621
622
623      uint8_t r =
624            _mesa_unorm_to_unorm(src[0], 8, 8);
625
626      uint16_t d = 0;
627         d |= PACK(g, 0, 8);
628         d |= PACK(r, 8, 8);
629      (*(uint16_t *)dst) = d;
630}
631
632static inline void
633pack_ubyte_l4a4_unorm(const GLubyte src[4], void *dst)
634{
635
636
637      uint8_t l =
638            _mesa_unorm_to_unorm(src[0], 8, 4);
639
640
641      uint8_t a =
642            _mesa_unorm_to_unorm(src[3], 8, 4);
643
644      uint8_t d = 0;
645         d |= PACK(l, 0, 4);
646         d |= PACK(a, 4, 4);
647      (*(uint8_t *)dst) = d;
648}
649
650static inline void
651pack_ubyte_b2g3r3_unorm(const GLubyte src[4], void *dst)
652{
653
654
655      uint8_t b =
656            _mesa_unorm_to_unorm(src[2], 8, 2);
657
658
659      uint8_t g =
660            _mesa_unorm_to_unorm(src[1], 8, 3);
661
662
663      uint8_t r =
664            _mesa_unorm_to_unorm(src[0], 8, 3);
665
666      uint8_t d = 0;
667         d |= PACK(b, 0, 2);
668         d |= PACK(g, 2, 3);
669         d |= PACK(r, 5, 3);
670      (*(uint8_t *)dst) = d;
671}
672
673static inline void
674pack_ubyte_r16g16_unorm(const GLubyte src[4], void *dst)
675{
676
677
678      uint16_t r =
679            _mesa_unorm_to_unorm(src[0], 8, 16);
680
681
682      uint16_t g =
683            _mesa_unorm_to_unorm(src[1], 8, 16);
684
685      uint32_t d = 0;
686         d |= PACK(r, 0, 16);
687         d |= PACK(g, 16, 16);
688      (*(uint32_t *)dst) = d;
689}
690
691static inline void
692pack_ubyte_g16r16_unorm(const GLubyte src[4], void *dst)
693{
694
695
696      uint16_t g =
697            _mesa_unorm_to_unorm(src[1], 8, 16);
698
699
700      uint16_t r =
701            _mesa_unorm_to_unorm(src[0], 8, 16);
702
703      uint32_t d = 0;
704         d |= PACK(g, 0, 16);
705         d |= PACK(r, 16, 16);
706      (*(uint32_t *)dst) = d;
707}
708
709static inline void
710pack_ubyte_b10g10r10a2_unorm(const GLubyte src[4], void *dst)
711{
712
713
714      uint16_t b =
715            _mesa_unorm_to_unorm(src[2], 8, 10);
716
717
718      uint16_t g =
719            _mesa_unorm_to_unorm(src[1], 8, 10);
720
721
722      uint16_t r =
723            _mesa_unorm_to_unorm(src[0], 8, 10);
724
725
726      uint8_t a =
727            _mesa_unorm_to_unorm(src[3], 8, 2);
728
729      uint32_t d = 0;
730         d |= PACK(b, 0, 10);
731         d |= PACK(g, 10, 10);
732         d |= PACK(r, 20, 10);
733         d |= PACK(a, 30, 2);
734      (*(uint32_t *)dst) = d;
735}
736
737static inline void
738pack_ubyte_b10g10r10x2_unorm(const GLubyte src[4], void *dst)
739{
740
741
742      uint16_t b =
743            _mesa_unorm_to_unorm(src[2], 8, 10);
744
745
746      uint16_t g =
747            _mesa_unorm_to_unorm(src[1], 8, 10);
748
749
750      uint16_t r =
751            _mesa_unorm_to_unorm(src[0], 8, 10);
752
753
754      uint32_t d = 0;
755         d |= PACK(b, 0, 10);
756         d |= PACK(g, 10, 10);
757         d |= PACK(r, 20, 10);
758                  (*(uint32_t *)dst) = d;
759}
760
761static inline void
762pack_ubyte_r10g10b10a2_unorm(const GLubyte src[4], void *dst)
763{
764
765
766      uint16_t r =
767            _mesa_unorm_to_unorm(src[0], 8, 10);
768
769
770      uint16_t g =
771            _mesa_unorm_to_unorm(src[1], 8, 10);
772
773
774      uint16_t b =
775            _mesa_unorm_to_unorm(src[2], 8, 10);
776
777
778      uint8_t a =
779            _mesa_unorm_to_unorm(src[3], 8, 2);
780
781      uint32_t d = 0;
782         d |= PACK(r, 0, 10);
783         d |= PACK(g, 10, 10);
784         d |= PACK(b, 20, 10);
785         d |= PACK(a, 30, 2);
786      (*(uint32_t *)dst) = d;
787}
788
789static inline void
790pack_ubyte_r10g10b10x2_unorm(const GLubyte src[4], void *dst)
791{
792
793
794      uint16_t r =
795            _mesa_unorm_to_unorm(src[0], 8, 10);
796
797
798      uint16_t g =
799            _mesa_unorm_to_unorm(src[1], 8, 10);
800
801
802      uint16_t b =
803            _mesa_unorm_to_unorm(src[2], 8, 10);
804
805
806      uint32_t d = 0;
807         d |= PACK(r, 0, 10);
808         d |= PACK(g, 10, 10);
809         d |= PACK(b, 20, 10);
810                  (*(uint32_t *)dst) = d;
811}
812
813static inline void
814pack_ubyte_r3g3b2_unorm(const GLubyte src[4], void *dst)
815{
816
817
818      uint8_t r =
819            _mesa_unorm_to_unorm(src[0], 8, 3);
820
821
822      uint8_t g =
823            _mesa_unorm_to_unorm(src[1], 8, 3);
824
825
826      uint8_t b =
827            _mesa_unorm_to_unorm(src[2], 8, 2);
828
829      uint8_t d = 0;
830         d |= PACK(r, 0, 3);
831         d |= PACK(g, 3, 3);
832         d |= PACK(b, 6, 2);
833      (*(uint8_t *)dst) = d;
834}
835
836static inline void
837pack_ubyte_a4b4g4r4_unorm(const GLubyte src[4], void *dst)
838{
839
840
841      uint8_t a =
842            _mesa_unorm_to_unorm(src[3], 8, 4);
843
844
845      uint8_t b =
846            _mesa_unorm_to_unorm(src[2], 8, 4);
847
848
849      uint8_t g =
850            _mesa_unorm_to_unorm(src[1], 8, 4);
851
852
853      uint8_t r =
854            _mesa_unorm_to_unorm(src[0], 8, 4);
855
856      uint16_t d = 0;
857         d |= PACK(a, 0, 4);
858         d |= PACK(b, 4, 4);
859         d |= PACK(g, 8, 4);
860         d |= PACK(r, 12, 4);
861      (*(uint16_t *)dst) = d;
862}
863
864static inline void
865pack_ubyte_r4g4b4a4_unorm(const GLubyte src[4], void *dst)
866{
867
868
869      uint8_t r =
870            _mesa_unorm_to_unorm(src[0], 8, 4);
871
872
873      uint8_t g =
874            _mesa_unorm_to_unorm(src[1], 8, 4);
875
876
877      uint8_t b =
878            _mesa_unorm_to_unorm(src[2], 8, 4);
879
880
881      uint8_t a =
882            _mesa_unorm_to_unorm(src[3], 8, 4);
883
884      uint16_t d = 0;
885         d |= PACK(r, 0, 4);
886         d |= PACK(g, 4, 4);
887         d |= PACK(b, 8, 4);
888         d |= PACK(a, 12, 4);
889      (*(uint16_t *)dst) = d;
890}
891
892static inline void
893pack_ubyte_r5g5b5a1_unorm(const GLubyte src[4], void *dst)
894{
895
896
897      uint8_t r =
898            _mesa_unorm_to_unorm(src[0], 8, 5);
899
900
901      uint8_t g =
902            _mesa_unorm_to_unorm(src[1], 8, 5);
903
904
905      uint8_t b =
906            _mesa_unorm_to_unorm(src[2], 8, 5);
907
908
909      uint8_t a =
910            _mesa_unorm_to_unorm(src[3], 8, 1);
911
912      uint16_t d = 0;
913         d |= PACK(r, 0, 5);
914         d |= PACK(g, 5, 5);
915         d |= PACK(b, 10, 5);
916         d |= PACK(a, 15, 1);
917      (*(uint16_t *)dst) = d;
918}
919
920static inline void
921pack_ubyte_a2b10g10r10_unorm(const GLubyte src[4], void *dst)
922{
923
924
925      uint8_t a =
926            _mesa_unorm_to_unorm(src[3], 8, 2);
927
928
929      uint16_t b =
930            _mesa_unorm_to_unorm(src[2], 8, 10);
931
932
933      uint16_t g =
934            _mesa_unorm_to_unorm(src[1], 8, 10);
935
936
937      uint16_t r =
938            _mesa_unorm_to_unorm(src[0], 8, 10);
939
940      uint32_t d = 0;
941         d |= PACK(a, 0, 2);
942         d |= PACK(b, 2, 10);
943         d |= PACK(g, 12, 10);
944         d |= PACK(r, 22, 10);
945      (*(uint32_t *)dst) = d;
946}
947
948static inline void
949pack_ubyte_a2r10g10b10_unorm(const GLubyte src[4], void *dst)
950{
951
952
953      uint8_t a =
954            _mesa_unorm_to_unorm(src[3], 8, 2);
955
956
957      uint16_t r =
958            _mesa_unorm_to_unorm(src[0], 8, 10);
959
960
961      uint16_t g =
962            _mesa_unorm_to_unorm(src[1], 8, 10);
963
964
965      uint16_t b =
966            _mesa_unorm_to_unorm(src[2], 8, 10);
967
968      uint32_t d = 0;
969         d |= PACK(a, 0, 2);
970         d |= PACK(r, 2, 10);
971         d |= PACK(g, 12, 10);
972         d |= PACK(b, 22, 10);
973      (*(uint32_t *)dst) = d;
974}
975
976static inline void
977pack_ubyte_a_unorm8(const GLubyte src[4], void *dst)
978{
979
980
981      uint8_t a =
982            _mesa_unorm_to_unorm(src[3], 8, 8);
983
984      uint8_t *d = (uint8_t *)dst;
985         d[0] = a;
986}
987
988static inline void
989pack_ubyte_a_unorm16(const GLubyte src[4], void *dst)
990{
991
992
993      uint16_t a =
994            _mesa_unorm_to_unorm(src[3], 8, 16);
995
996      uint16_t *d = (uint16_t *)dst;
997         d[0] = a;
998}
999
1000static inline void
1001pack_ubyte_l_unorm8(const GLubyte src[4], void *dst)
1002{
1003
1004
1005      uint8_t l =
1006            _mesa_unorm_to_unorm(src[0], 8, 8);
1007
1008      uint8_t *d = (uint8_t *)dst;
1009         d[0] = l;
1010}
1011
1012static inline void
1013pack_ubyte_l_unorm16(const GLubyte src[4], void *dst)
1014{
1015
1016
1017      uint16_t l =
1018            _mesa_unorm_to_unorm(src[0], 8, 16);
1019
1020      uint16_t *d = (uint16_t *)dst;
1021         d[0] = l;
1022}
1023
1024static inline void
1025pack_ubyte_i_unorm8(const GLubyte src[4], void *dst)
1026{
1027
1028
1029      uint8_t i =
1030            _mesa_unorm_to_unorm(src[0], 8, 8);
1031
1032      uint8_t *d = (uint8_t *)dst;
1033         d[0] = i;
1034}
1035
1036static inline void
1037pack_ubyte_i_unorm16(const GLubyte src[4], void *dst)
1038{
1039
1040
1041      uint16_t i =
1042            _mesa_unorm_to_unorm(src[0], 8, 16);
1043
1044      uint16_t *d = (uint16_t *)dst;
1045         d[0] = i;
1046}
1047
1048static inline void
1049pack_ubyte_r_unorm8(const GLubyte src[4], void *dst)
1050{
1051
1052
1053      uint8_t r =
1054            _mesa_unorm_to_unorm(src[0], 8, 8);
1055
1056      uint8_t *d = (uint8_t *)dst;
1057         d[0] = r;
1058}
1059
1060static inline void
1061pack_ubyte_r_unorm16(const GLubyte src[4], void *dst)
1062{
1063
1064
1065      uint16_t r =
1066            _mesa_unorm_to_unorm(src[0], 8, 16);
1067
1068      uint16_t *d = (uint16_t *)dst;
1069         d[0] = r;
1070}
1071
1072static inline void
1073pack_ubyte_bgr_unorm8(const GLubyte src[4], void *dst)
1074{
1075
1076
1077      uint8_t b =
1078            _mesa_unorm_to_unorm(src[2], 8, 8);
1079
1080
1081      uint8_t g =
1082            _mesa_unorm_to_unorm(src[1], 8, 8);
1083
1084
1085      uint8_t r =
1086            _mesa_unorm_to_unorm(src[0], 8, 8);
1087
1088      uint8_t *d = (uint8_t *)dst;
1089         d[0] = b;
1090         d[1] = g;
1091         d[2] = r;
1092}
1093
1094static inline void
1095pack_ubyte_rgb_unorm8(const GLubyte src[4], void *dst)
1096{
1097
1098
1099      uint8_t r =
1100            _mesa_unorm_to_unorm(src[0], 8, 8);
1101
1102
1103      uint8_t g =
1104            _mesa_unorm_to_unorm(src[1], 8, 8);
1105
1106
1107      uint8_t b =
1108            _mesa_unorm_to_unorm(src[2], 8, 8);
1109
1110      uint8_t *d = (uint8_t *)dst;
1111         d[0] = r;
1112         d[1] = g;
1113         d[2] = b;
1114}
1115
1116static inline void
1117pack_ubyte_rgba_unorm16(const GLubyte src[4], void *dst)
1118{
1119
1120
1121      uint16_t r =
1122            _mesa_unorm_to_unorm(src[0], 8, 16);
1123
1124
1125      uint16_t g =
1126            _mesa_unorm_to_unorm(src[1], 8, 16);
1127
1128
1129      uint16_t b =
1130            _mesa_unorm_to_unorm(src[2], 8, 16);
1131
1132
1133      uint16_t a =
1134            _mesa_unorm_to_unorm(src[3], 8, 16);
1135
1136      uint16_t *d = (uint16_t *)dst;
1137         d[0] = r;
1138         d[1] = g;
1139         d[2] = b;
1140         d[3] = a;
1141}
1142
1143static inline void
1144pack_ubyte_rgbx_unorm16(const GLubyte src[4], void *dst)
1145{
1146
1147
1148      uint16_t r =
1149            _mesa_unorm_to_unorm(src[0], 8, 16);
1150
1151
1152      uint16_t g =
1153            _mesa_unorm_to_unorm(src[1], 8, 16);
1154
1155
1156      uint16_t b =
1157            _mesa_unorm_to_unorm(src[2], 8, 16);
1158
1159
1160      uint16_t *d = (uint16_t *)dst;
1161         d[0] = r;
1162         d[1] = g;
1163         d[2] = b;
1164            }
1165
1166static inline void
1167pack_ubyte_a8b8g8r8_snorm(const GLubyte src[4], void *dst)
1168{
1169
1170
1171      int8_t a =
1172         _mesa_unorm_to_snorm(src[3], 8, 8);
1173
1174
1175      int8_t b =
1176         _mesa_unorm_to_snorm(src[2], 8, 8);
1177
1178
1179      int8_t g =
1180         _mesa_unorm_to_snorm(src[1], 8, 8);
1181
1182
1183      int8_t r =
1184         _mesa_unorm_to_snorm(src[0], 8, 8);
1185
1186      uint32_t d = 0;
1187         d |= PACK(a, 0, 8);
1188         d |= PACK(b, 8, 8);
1189         d |= PACK(g, 16, 8);
1190         d |= PACK(r, 24, 8);
1191      (*(uint32_t *)dst) = d;
1192}
1193
1194static inline void
1195pack_ubyte_x8b8g8r8_snorm(const GLubyte src[4], void *dst)
1196{
1197
1198
1199
1200      int8_t b =
1201         _mesa_unorm_to_snorm(src[2], 8, 8);
1202
1203
1204      int8_t g =
1205         _mesa_unorm_to_snorm(src[1], 8, 8);
1206
1207
1208      int8_t r =
1209         _mesa_unorm_to_snorm(src[0], 8, 8);
1210
1211      uint32_t d = 0;
1212                     d |= PACK(b, 8, 8);
1213         d |= PACK(g, 16, 8);
1214         d |= PACK(r, 24, 8);
1215      (*(uint32_t *)dst) = d;
1216}
1217
1218static inline void
1219pack_ubyte_r8g8b8a8_snorm(const GLubyte src[4], void *dst)
1220{
1221
1222
1223      int8_t r =
1224         _mesa_unorm_to_snorm(src[0], 8, 8);
1225
1226
1227      int8_t g =
1228         _mesa_unorm_to_snorm(src[1], 8, 8);
1229
1230
1231      int8_t b =
1232         _mesa_unorm_to_snorm(src[2], 8, 8);
1233
1234
1235      int8_t a =
1236         _mesa_unorm_to_snorm(src[3], 8, 8);
1237
1238      uint32_t d = 0;
1239         d |= PACK(r, 0, 8);
1240         d |= PACK(g, 8, 8);
1241         d |= PACK(b, 16, 8);
1242         d |= PACK(a, 24, 8);
1243      (*(uint32_t *)dst) = d;
1244}
1245
1246static inline void
1247pack_ubyte_r8g8b8x8_snorm(const GLubyte src[4], void *dst)
1248{
1249
1250
1251      int8_t r =
1252         _mesa_unorm_to_snorm(src[0], 8, 8);
1253
1254
1255      int8_t g =
1256         _mesa_unorm_to_snorm(src[1], 8, 8);
1257
1258
1259      int8_t b =
1260         _mesa_unorm_to_snorm(src[2], 8, 8);
1261
1262
1263      uint32_t d = 0;
1264         d |= PACK(r, 0, 8);
1265         d |= PACK(g, 8, 8);
1266         d |= PACK(b, 16, 8);
1267                  (*(uint32_t *)dst) = d;
1268}
1269
1270static inline void
1271pack_ubyte_r16g16_snorm(const GLubyte src[4], void *dst)
1272{
1273
1274
1275      int16_t r =
1276         _mesa_unorm_to_snorm(src[0], 8, 16);
1277
1278
1279      int16_t g =
1280         _mesa_unorm_to_snorm(src[1], 8, 16);
1281
1282      uint32_t d = 0;
1283         d |= PACK(r, 0, 16);
1284         d |= PACK(g, 16, 16);
1285      (*(uint32_t *)dst) = d;
1286}
1287
1288static inline void
1289pack_ubyte_g16r16_snorm(const GLubyte src[4], void *dst)
1290{
1291
1292
1293      int16_t g =
1294         _mesa_unorm_to_snorm(src[1], 8, 16);
1295
1296
1297      int16_t r =
1298         _mesa_unorm_to_snorm(src[0], 8, 16);
1299
1300      uint32_t d = 0;
1301         d |= PACK(g, 0, 16);
1302         d |= PACK(r, 16, 16);
1303      (*(uint32_t *)dst) = d;
1304}
1305
1306static inline void
1307pack_ubyte_r8g8_snorm(const GLubyte src[4], void *dst)
1308{
1309
1310
1311      int8_t r =
1312         _mesa_unorm_to_snorm(src[0], 8, 8);
1313
1314
1315      int8_t g =
1316         _mesa_unorm_to_snorm(src[1], 8, 8);
1317
1318      uint16_t d = 0;
1319         d |= PACK(r, 0, 8);
1320         d |= PACK(g, 8, 8);
1321      (*(uint16_t *)dst) = d;
1322}
1323
1324static inline void
1325pack_ubyte_g8r8_snorm(const GLubyte src[4], void *dst)
1326{
1327
1328
1329      int8_t g =
1330         _mesa_unorm_to_snorm(src[1], 8, 8);
1331
1332
1333      int8_t r =
1334         _mesa_unorm_to_snorm(src[0], 8, 8);
1335
1336      uint16_t d = 0;
1337         d |= PACK(g, 0, 8);
1338         d |= PACK(r, 8, 8);
1339      (*(uint16_t *)dst) = d;
1340}
1341
1342static inline void
1343pack_ubyte_l8a8_snorm(const GLubyte src[4], void *dst)
1344{
1345
1346
1347      int8_t l =
1348         _mesa_unorm_to_snorm(src[0], 8, 8);
1349
1350
1351      int8_t a =
1352         _mesa_unorm_to_snorm(src[3], 8, 8);
1353
1354      uint16_t d = 0;
1355         d |= PACK(l, 0, 8);
1356         d |= PACK(a, 8, 8);
1357      (*(uint16_t *)dst) = d;
1358}
1359
1360static inline void
1361pack_ubyte_a8l8_snorm(const GLubyte src[4], void *dst)
1362{
1363
1364
1365      int8_t a =
1366         _mesa_unorm_to_snorm(src[3], 8, 8);
1367
1368
1369      int8_t l =
1370         _mesa_unorm_to_snorm(src[0], 8, 8);
1371
1372      uint16_t d = 0;
1373         d |= PACK(a, 0, 8);
1374         d |= PACK(l, 8, 8);
1375      (*(uint16_t *)dst) = d;
1376}
1377
1378static inline void
1379pack_ubyte_a_snorm8(const GLubyte src[4], void *dst)
1380{
1381
1382
1383      int8_t a =
1384         _mesa_unorm_to_snorm(src[3], 8, 8);
1385
1386      int8_t *d = (int8_t *)dst;
1387         d[0] = a;
1388}
1389
1390static inline void
1391pack_ubyte_a_snorm16(const GLubyte src[4], void *dst)
1392{
1393
1394
1395      int16_t a =
1396         _mesa_unorm_to_snorm(src[3], 8, 16);
1397
1398      int16_t *d = (int16_t *)dst;
1399         d[0] = a;
1400}
1401
1402static inline void
1403pack_ubyte_l_snorm8(const GLubyte src[4], void *dst)
1404{
1405
1406
1407      int8_t l =
1408         _mesa_unorm_to_snorm(src[0], 8, 8);
1409
1410      int8_t *d = (int8_t *)dst;
1411         d[0] = l;
1412}
1413
1414static inline void
1415pack_ubyte_l_snorm16(const GLubyte src[4], void *dst)
1416{
1417
1418
1419      int16_t l =
1420         _mesa_unorm_to_snorm(src[0], 8, 16);
1421
1422      int16_t *d = (int16_t *)dst;
1423         d[0] = l;
1424}
1425
1426static inline void
1427pack_ubyte_i_snorm8(const GLubyte src[4], void *dst)
1428{
1429
1430
1431      int8_t i =
1432         _mesa_unorm_to_snorm(src[0], 8, 8);
1433
1434      int8_t *d = (int8_t *)dst;
1435         d[0] = i;
1436}
1437
1438static inline void
1439pack_ubyte_i_snorm16(const GLubyte src[4], void *dst)
1440{
1441
1442
1443      int16_t i =
1444         _mesa_unorm_to_snorm(src[0], 8, 16);
1445
1446      int16_t *d = (int16_t *)dst;
1447         d[0] = i;
1448}
1449
1450static inline void
1451pack_ubyte_r_snorm8(const GLubyte src[4], void *dst)
1452{
1453
1454
1455      int8_t r =
1456         _mesa_unorm_to_snorm(src[0], 8, 8);
1457
1458      int8_t *d = (int8_t *)dst;
1459         d[0] = r;
1460}
1461
1462static inline void
1463pack_ubyte_r_snorm16(const GLubyte src[4], void *dst)
1464{
1465
1466
1467      int16_t r =
1468         _mesa_unorm_to_snorm(src[0], 8, 16);
1469
1470      int16_t *d = (int16_t *)dst;
1471         d[0] = r;
1472}
1473
1474static inline void
1475pack_ubyte_la_snorm16(const GLubyte src[4], void *dst)
1476{
1477
1478
1479      int16_t l =
1480         _mesa_unorm_to_snorm(src[0], 8, 16);
1481
1482
1483      int16_t a =
1484         _mesa_unorm_to_snorm(src[3], 8, 16);
1485
1486      int16_t *d = (int16_t *)dst;
1487         d[0] = l;
1488         d[1] = a;
1489}
1490
1491static inline void
1492pack_ubyte_rgb_snorm16(const GLubyte src[4], void *dst)
1493{
1494
1495
1496      int16_t r =
1497         _mesa_unorm_to_snorm(src[0], 8, 16);
1498
1499
1500      int16_t g =
1501         _mesa_unorm_to_snorm(src[1], 8, 16);
1502
1503
1504      int16_t b =
1505         _mesa_unorm_to_snorm(src[2], 8, 16);
1506
1507      int16_t *d = (int16_t *)dst;
1508         d[0] = r;
1509         d[1] = g;
1510         d[2] = b;
1511}
1512
1513static inline void
1514pack_ubyte_rgba_snorm16(const GLubyte src[4], void *dst)
1515{
1516
1517
1518      int16_t r =
1519         _mesa_unorm_to_snorm(src[0], 8, 16);
1520
1521
1522      int16_t g =
1523         _mesa_unorm_to_snorm(src[1], 8, 16);
1524
1525
1526      int16_t b =
1527         _mesa_unorm_to_snorm(src[2], 8, 16);
1528
1529
1530      int16_t a =
1531         _mesa_unorm_to_snorm(src[3], 8, 16);
1532
1533      int16_t *d = (int16_t *)dst;
1534         d[0] = r;
1535         d[1] = g;
1536         d[2] = b;
1537         d[3] = a;
1538}
1539
1540static inline void
1541pack_ubyte_rgbx_snorm16(const GLubyte src[4], void *dst)
1542{
1543
1544
1545      int16_t r =
1546         _mesa_unorm_to_snorm(src[0], 8, 16);
1547
1548
1549      int16_t g =
1550         _mesa_unorm_to_snorm(src[1], 8, 16);
1551
1552
1553      int16_t b =
1554         _mesa_unorm_to_snorm(src[2], 8, 16);
1555
1556
1557      int16_t *d = (int16_t *)dst;
1558         d[0] = r;
1559         d[1] = g;
1560         d[2] = b;
1561            }
1562
1563static inline void
1564pack_ubyte_a8b8g8r8_srgb(const GLubyte src[4], void *dst)
1565{
1566
1567
1568      uint8_t a =
1569            _mesa_unorm_to_unorm(src[3], 8, 8);
1570
1571
1572      uint8_t b =
1573
1574            util_format_linear_to_srgb_8unorm(src[2]);
1575
1576
1577      uint8_t g =
1578
1579            util_format_linear_to_srgb_8unorm(src[1]);
1580
1581
1582      uint8_t r =
1583
1584            util_format_linear_to_srgb_8unorm(src[0]);
1585
1586      uint32_t d = 0;
1587         d |= PACK(a, 0, 8);
1588         d |= PACK(b, 8, 8);
1589         d |= PACK(g, 16, 8);
1590         d |= PACK(r, 24, 8);
1591      (*(uint32_t *)dst) = d;
1592}
1593
1594static inline void
1595pack_ubyte_b8g8r8a8_srgb(const GLubyte src[4], void *dst)
1596{
1597
1598
1599      uint8_t b =
1600
1601            util_format_linear_to_srgb_8unorm(src[2]);
1602
1603
1604      uint8_t g =
1605
1606            util_format_linear_to_srgb_8unorm(src[1]);
1607
1608
1609      uint8_t r =
1610
1611            util_format_linear_to_srgb_8unorm(src[0]);
1612
1613
1614      uint8_t a =
1615            _mesa_unorm_to_unorm(src[3], 8, 8);
1616
1617      uint32_t d = 0;
1618         d |= PACK(b, 0, 8);
1619         d |= PACK(g, 8, 8);
1620         d |= PACK(r, 16, 8);
1621         d |= PACK(a, 24, 8);
1622      (*(uint32_t *)dst) = d;
1623}
1624
1625static inline void
1626pack_ubyte_a8r8g8b8_srgb(const GLubyte src[4], void *dst)
1627{
1628
1629
1630      uint8_t a =
1631            _mesa_unorm_to_unorm(src[3], 8, 8);
1632
1633
1634      uint8_t r =
1635
1636            util_format_linear_to_srgb_8unorm(src[0]);
1637
1638
1639      uint8_t g =
1640
1641            util_format_linear_to_srgb_8unorm(src[1]);
1642
1643
1644      uint8_t b =
1645
1646            util_format_linear_to_srgb_8unorm(src[2]);
1647
1648      uint32_t d = 0;
1649         d |= PACK(a, 0, 8);
1650         d |= PACK(r, 8, 8);
1651         d |= PACK(g, 16, 8);
1652         d |= PACK(b, 24, 8);
1653      (*(uint32_t *)dst) = d;
1654}
1655
1656static inline void
1657pack_ubyte_b8g8r8x8_srgb(const GLubyte src[4], void *dst)
1658{
1659
1660
1661      uint8_t b =
1662
1663            util_format_linear_to_srgb_8unorm(src[2]);
1664
1665
1666      uint8_t g =
1667
1668            util_format_linear_to_srgb_8unorm(src[1]);
1669
1670
1671      uint8_t r =
1672
1673            util_format_linear_to_srgb_8unorm(src[0]);
1674
1675
1676      uint32_t d = 0;
1677         d |= PACK(b, 0, 8);
1678         d |= PACK(g, 8, 8);
1679         d |= PACK(r, 16, 8);
1680                  (*(uint32_t *)dst) = d;
1681}
1682
1683static inline void
1684pack_ubyte_x8r8g8b8_srgb(const GLubyte src[4], void *dst)
1685{
1686
1687
1688
1689      uint8_t r =
1690
1691            util_format_linear_to_srgb_8unorm(src[0]);
1692
1693
1694      uint8_t g =
1695
1696            util_format_linear_to_srgb_8unorm(src[1]);
1697
1698
1699      uint8_t b =
1700
1701            util_format_linear_to_srgb_8unorm(src[2]);
1702
1703      uint32_t d = 0;
1704                     d |= PACK(r, 8, 8);
1705         d |= PACK(g, 16, 8);
1706         d |= PACK(b, 24, 8);
1707      (*(uint32_t *)dst) = d;
1708}
1709
1710static inline void
1711pack_ubyte_r8g8b8a8_srgb(const GLubyte src[4], void *dst)
1712{
1713
1714
1715      uint8_t r =
1716
1717            util_format_linear_to_srgb_8unorm(src[0]);
1718
1719
1720      uint8_t g =
1721
1722            util_format_linear_to_srgb_8unorm(src[1]);
1723
1724
1725      uint8_t b =
1726
1727            util_format_linear_to_srgb_8unorm(src[2]);
1728
1729
1730      uint8_t a =
1731            _mesa_unorm_to_unorm(src[3], 8, 8);
1732
1733      uint32_t d = 0;
1734         d |= PACK(r, 0, 8);
1735         d |= PACK(g, 8, 8);
1736         d |= PACK(b, 16, 8);
1737         d |= PACK(a, 24, 8);
1738      (*(uint32_t *)dst) = d;
1739}
1740
1741static inline void
1742pack_ubyte_r8g8b8x8_srgb(const GLubyte src[4], void *dst)
1743{
1744
1745
1746      uint8_t r =
1747
1748            util_format_linear_to_srgb_8unorm(src[0]);
1749
1750
1751      uint8_t g =
1752
1753            util_format_linear_to_srgb_8unorm(src[1]);
1754
1755
1756      uint8_t b =
1757
1758            util_format_linear_to_srgb_8unorm(src[2]);
1759
1760
1761      uint32_t d = 0;
1762         d |= PACK(r, 0, 8);
1763         d |= PACK(g, 8, 8);
1764         d |= PACK(b, 16, 8);
1765                  (*(uint32_t *)dst) = d;
1766}
1767
1768static inline void
1769pack_ubyte_x8b8g8r8_srgb(const GLubyte src[4], void *dst)
1770{
1771
1772
1773
1774      uint8_t b =
1775
1776            util_format_linear_to_srgb_8unorm(src[2]);
1777
1778
1779      uint8_t g =
1780
1781            util_format_linear_to_srgb_8unorm(src[1]);
1782
1783
1784      uint8_t r =
1785
1786            util_format_linear_to_srgb_8unorm(src[0]);
1787
1788      uint32_t d = 0;
1789                     d |= PACK(b, 8, 8);
1790         d |= PACK(g, 16, 8);
1791         d |= PACK(r, 24, 8);
1792      (*(uint32_t *)dst) = d;
1793}
1794
1795static inline void
1796pack_ubyte_l8a8_srgb(const GLubyte src[4], void *dst)
1797{
1798
1799
1800      uint8_t l =
1801            _mesa_unorm_to_unorm(src[0], 8, 8);
1802
1803
1804      uint8_t a =
1805            _mesa_unorm_to_unorm(src[3], 8, 8);
1806
1807      uint16_t d = 0;
1808         d |= PACK(l, 0, 8);
1809         d |= PACK(a, 8, 8);
1810      (*(uint16_t *)dst) = d;
1811}
1812
1813static inline void
1814pack_ubyte_a8l8_srgb(const GLubyte src[4], void *dst)
1815{
1816
1817
1818      uint8_t a =
1819            _mesa_unorm_to_unorm(src[3], 8, 8);
1820
1821
1822      uint8_t l =
1823            _mesa_unorm_to_unorm(src[0], 8, 8);
1824
1825      uint16_t d = 0;
1826         d |= PACK(a, 0, 8);
1827         d |= PACK(l, 8, 8);
1828      (*(uint16_t *)dst) = d;
1829}
1830
1831static inline void
1832pack_ubyte_r_srgb8(const GLubyte src[4], void *dst)
1833{
1834
1835
1836      uint8_t r =
1837
1838            util_format_linear_to_srgb_8unorm(src[0]);
1839
1840      uint8_t *d = (uint8_t *)dst;
1841         d[0] = r;
1842}
1843
1844static inline void
1845pack_ubyte_l_srgb8(const GLubyte src[4], void *dst)
1846{
1847
1848
1849      uint8_t l =
1850            _mesa_unorm_to_unorm(src[0], 8, 8);
1851
1852      uint8_t *d = (uint8_t *)dst;
1853         d[0] = l;
1854}
1855
1856static inline void
1857pack_ubyte_bgr_srgb8(const GLubyte src[4], void *dst)
1858{
1859
1860
1861      uint8_t b =
1862
1863            util_format_linear_to_srgb_8unorm(src[2]);
1864
1865
1866      uint8_t g =
1867
1868            util_format_linear_to_srgb_8unorm(src[1]);
1869
1870
1871      uint8_t r =
1872
1873            util_format_linear_to_srgb_8unorm(src[0]);
1874
1875      uint8_t *d = (uint8_t *)dst;
1876         d[0] = b;
1877         d[1] = g;
1878         d[2] = r;
1879}
1880
1881static inline void
1882pack_ubyte_a_float16(const GLubyte src[4], void *dst)
1883{
1884
1885
1886      uint16_t a =
1887            _mesa_unorm_to_half(src[3], 8);
1888
1889      uint16_t *d = (uint16_t *)dst;
1890         d[0] = a;
1891}
1892
1893static inline void
1894pack_ubyte_a_float32(const GLubyte src[4], void *dst)
1895{
1896
1897
1898      float a =
1899            _mesa_unorm_to_float(src[3], 8);
1900
1901      float *d = (float *)dst;
1902         d[0] = a;
1903}
1904
1905static inline void
1906pack_ubyte_l_float16(const GLubyte src[4], void *dst)
1907{
1908
1909
1910      uint16_t l =
1911            _mesa_unorm_to_half(src[0], 8);
1912
1913      uint16_t *d = (uint16_t *)dst;
1914         d[0] = l;
1915}
1916
1917static inline void
1918pack_ubyte_l_float32(const GLubyte src[4], void *dst)
1919{
1920
1921
1922      float l =
1923            _mesa_unorm_to_float(src[0], 8);
1924
1925      float *d = (float *)dst;
1926         d[0] = l;
1927}
1928
1929static inline void
1930pack_ubyte_la_float16(const GLubyte src[4], void *dst)
1931{
1932
1933
1934      uint16_t l =
1935            _mesa_unorm_to_half(src[0], 8);
1936
1937
1938      uint16_t a =
1939            _mesa_unorm_to_half(src[3], 8);
1940
1941      uint16_t *d = (uint16_t *)dst;
1942         d[0] = l;
1943         d[1] = a;
1944}
1945
1946static inline void
1947pack_ubyte_la_float32(const GLubyte src[4], void *dst)
1948{
1949
1950
1951      float l =
1952            _mesa_unorm_to_float(src[0], 8);
1953
1954
1955      float a =
1956            _mesa_unorm_to_float(src[3], 8);
1957
1958      float *d = (float *)dst;
1959         d[0] = l;
1960         d[1] = a;
1961}
1962
1963static inline void
1964pack_ubyte_i_float16(const GLubyte src[4], void *dst)
1965{
1966
1967
1968      uint16_t i =
1969            _mesa_unorm_to_half(src[0], 8);
1970
1971      uint16_t *d = (uint16_t *)dst;
1972         d[0] = i;
1973}
1974
1975static inline void
1976pack_ubyte_i_float32(const GLubyte src[4], void *dst)
1977{
1978
1979
1980      float i =
1981            _mesa_unorm_to_float(src[0], 8);
1982
1983      float *d = (float *)dst;
1984         d[0] = i;
1985}
1986
1987static inline void
1988pack_ubyte_r_float16(const GLubyte src[4], void *dst)
1989{
1990
1991
1992      uint16_t r =
1993            _mesa_unorm_to_half(src[0], 8);
1994
1995      uint16_t *d = (uint16_t *)dst;
1996         d[0] = r;
1997}
1998
1999static inline void
2000pack_ubyte_r_float32(const GLubyte src[4], void *dst)
2001{
2002
2003
2004      float r =
2005            _mesa_unorm_to_float(src[0], 8);
2006
2007      float *d = (float *)dst;
2008         d[0] = r;
2009}
2010
2011static inline void
2012pack_ubyte_rg_float16(const GLubyte src[4], void *dst)
2013{
2014
2015
2016      uint16_t r =
2017            _mesa_unorm_to_half(src[0], 8);
2018
2019
2020      uint16_t g =
2021            _mesa_unorm_to_half(src[1], 8);
2022
2023      uint16_t *d = (uint16_t *)dst;
2024         d[0] = r;
2025         d[1] = g;
2026}
2027
2028static inline void
2029pack_ubyte_rg_float32(const GLubyte src[4], void *dst)
2030{
2031
2032
2033      float r =
2034            _mesa_unorm_to_float(src[0], 8);
2035
2036
2037      float g =
2038            _mesa_unorm_to_float(src[1], 8);
2039
2040      float *d = (float *)dst;
2041         d[0] = r;
2042         d[1] = g;
2043}
2044
2045static inline void
2046pack_ubyte_rgb_float16(const GLubyte src[4], void *dst)
2047{
2048
2049
2050      uint16_t r =
2051            _mesa_unorm_to_half(src[0], 8);
2052
2053
2054      uint16_t g =
2055            _mesa_unorm_to_half(src[1], 8);
2056
2057
2058      uint16_t b =
2059            _mesa_unorm_to_half(src[2], 8);
2060
2061      uint16_t *d = (uint16_t *)dst;
2062         d[0] = r;
2063         d[1] = g;
2064         d[2] = b;
2065}
2066
2067static inline void
2068pack_ubyte_rgb_float32(const GLubyte src[4], void *dst)
2069{
2070
2071
2072      float r =
2073            _mesa_unorm_to_float(src[0], 8);
2074
2075
2076      float g =
2077            _mesa_unorm_to_float(src[1], 8);
2078
2079
2080      float b =
2081            _mesa_unorm_to_float(src[2], 8);
2082
2083      float *d = (float *)dst;
2084         d[0] = r;
2085         d[1] = g;
2086         d[2] = b;
2087}
2088
2089static inline void
2090pack_ubyte_rgba_float16(const GLubyte src[4], void *dst)
2091{
2092
2093
2094      uint16_t r =
2095            _mesa_unorm_to_half(src[0], 8);
2096
2097
2098      uint16_t g =
2099            _mesa_unorm_to_half(src[1], 8);
2100
2101
2102      uint16_t b =
2103            _mesa_unorm_to_half(src[2], 8);
2104
2105
2106      uint16_t a =
2107            _mesa_unorm_to_half(src[3], 8);
2108
2109      uint16_t *d = (uint16_t *)dst;
2110         d[0] = r;
2111         d[1] = g;
2112         d[2] = b;
2113         d[3] = a;
2114}
2115
2116static inline void
2117pack_ubyte_rgba_float32(const GLubyte src[4], void *dst)
2118{
2119
2120
2121      float r =
2122            _mesa_unorm_to_float(src[0], 8);
2123
2124
2125      float g =
2126            _mesa_unorm_to_float(src[1], 8);
2127
2128
2129      float b =
2130            _mesa_unorm_to_float(src[2], 8);
2131
2132
2133      float a =
2134            _mesa_unorm_to_float(src[3], 8);
2135
2136      float *d = (float *)dst;
2137         d[0] = r;
2138         d[1] = g;
2139         d[2] = b;
2140         d[3] = a;
2141}
2142
2143static inline void
2144pack_ubyte_rgbx_float16(const GLubyte src[4], void *dst)
2145{
2146
2147
2148      uint16_t r =
2149            _mesa_unorm_to_half(src[0], 8);
2150
2151
2152      uint16_t g =
2153            _mesa_unorm_to_half(src[1], 8);
2154
2155
2156      uint16_t b =
2157            _mesa_unorm_to_half(src[2], 8);
2158
2159
2160      uint16_t *d = (uint16_t *)dst;
2161         d[0] = r;
2162         d[1] = g;
2163         d[2] = b;
2164            }
2165
2166static inline void
2167pack_ubyte_rgbx_float32(const GLubyte src[4], void *dst)
2168{
2169
2170
2171      float r =
2172            _mesa_unorm_to_float(src[0], 8);
2173
2174
2175      float g =
2176            _mesa_unorm_to_float(src[1], 8);
2177
2178
2179      float b =
2180            _mesa_unorm_to_float(src[2], 8);
2181
2182
2183      float *d = (float *)dst;
2184         d[0] = r;
2185         d[1] = g;
2186         d[2] = b;
2187            }
2188
2189static inline void
2190pack_ubyte_a8b8g8r8_uint(const GLubyte src[4], void *dst)
2191{
2192
2193
2194      uint8_t a =
2195              _mesa_unsigned_to_unsigned(src[3], 8);
2196
2197
2198      uint8_t b =
2199              _mesa_unsigned_to_unsigned(src[2], 8);
2200
2201
2202      uint8_t g =
2203              _mesa_unsigned_to_unsigned(src[1], 8);
2204
2205
2206      uint8_t r =
2207              _mesa_unsigned_to_unsigned(src[0], 8);
2208
2209      uint32_t d = 0;
2210         d |= PACK(a, 0, 8);
2211         d |= PACK(b, 8, 8);
2212         d |= PACK(g, 16, 8);
2213         d |= PACK(r, 24, 8);
2214      (*(uint32_t *)dst) = d;
2215}
2216
2217static inline void
2218pack_ubyte_a8r8g8b8_uint(const GLubyte src[4], void *dst)
2219{
2220
2221
2222      uint8_t a =
2223              _mesa_unsigned_to_unsigned(src[3], 8);
2224
2225
2226      uint8_t r =
2227              _mesa_unsigned_to_unsigned(src[0], 8);
2228
2229
2230      uint8_t g =
2231              _mesa_unsigned_to_unsigned(src[1], 8);
2232
2233
2234      uint8_t b =
2235              _mesa_unsigned_to_unsigned(src[2], 8);
2236
2237      uint32_t d = 0;
2238         d |= PACK(a, 0, 8);
2239         d |= PACK(r, 8, 8);
2240         d |= PACK(g, 16, 8);
2241         d |= PACK(b, 24, 8);
2242      (*(uint32_t *)dst) = d;
2243}
2244
2245static inline void
2246pack_ubyte_r8g8b8a8_uint(const GLubyte src[4], void *dst)
2247{
2248
2249
2250      uint8_t r =
2251              _mesa_unsigned_to_unsigned(src[0], 8);
2252
2253
2254      uint8_t g =
2255              _mesa_unsigned_to_unsigned(src[1], 8);
2256
2257
2258      uint8_t b =
2259              _mesa_unsigned_to_unsigned(src[2], 8);
2260
2261
2262      uint8_t a =
2263              _mesa_unsigned_to_unsigned(src[3], 8);
2264
2265      uint32_t d = 0;
2266         d |= PACK(r, 0, 8);
2267         d |= PACK(g, 8, 8);
2268         d |= PACK(b, 16, 8);
2269         d |= PACK(a, 24, 8);
2270      (*(uint32_t *)dst) = d;
2271}
2272
2273static inline void
2274pack_ubyte_b8g8r8a8_uint(const GLubyte src[4], void *dst)
2275{
2276
2277
2278      uint8_t b =
2279              _mesa_unsigned_to_unsigned(src[2], 8);
2280
2281
2282      uint8_t g =
2283              _mesa_unsigned_to_unsigned(src[1], 8);
2284
2285
2286      uint8_t r =
2287              _mesa_unsigned_to_unsigned(src[0], 8);
2288
2289
2290      uint8_t a =
2291              _mesa_unsigned_to_unsigned(src[3], 8);
2292
2293      uint32_t d = 0;
2294         d |= PACK(b, 0, 8);
2295         d |= PACK(g, 8, 8);
2296         d |= PACK(r, 16, 8);
2297         d |= PACK(a, 24, 8);
2298      (*(uint32_t *)dst) = d;
2299}
2300
2301static inline void
2302pack_ubyte_b10g10r10a2_uint(const GLubyte src[4], void *dst)
2303{
2304
2305
2306      uint16_t b =
2307              _mesa_unsigned_to_unsigned(src[2], 10);
2308
2309
2310      uint16_t g =
2311              _mesa_unsigned_to_unsigned(src[1], 10);
2312
2313
2314      uint16_t r =
2315              _mesa_unsigned_to_unsigned(src[0], 10);
2316
2317
2318      uint8_t a =
2319              _mesa_unsigned_to_unsigned(src[3], 2);
2320
2321      uint32_t d = 0;
2322         d |= PACK(b, 0, 10);
2323         d |= PACK(g, 10, 10);
2324         d |= PACK(r, 20, 10);
2325         d |= PACK(a, 30, 2);
2326      (*(uint32_t *)dst) = d;
2327}
2328
2329static inline void
2330pack_ubyte_r10g10b10a2_uint(const GLubyte src[4], void *dst)
2331{
2332
2333
2334      uint16_t r =
2335              _mesa_unsigned_to_unsigned(src[0], 10);
2336
2337
2338      uint16_t g =
2339              _mesa_unsigned_to_unsigned(src[1], 10);
2340
2341
2342      uint16_t b =
2343              _mesa_unsigned_to_unsigned(src[2], 10);
2344
2345
2346      uint8_t a =
2347              _mesa_unsigned_to_unsigned(src[3], 2);
2348
2349      uint32_t d = 0;
2350         d |= PACK(r, 0, 10);
2351         d |= PACK(g, 10, 10);
2352         d |= PACK(b, 20, 10);
2353         d |= PACK(a, 30, 2);
2354      (*(uint32_t *)dst) = d;
2355}
2356
2357static inline void
2358pack_ubyte_a2b10g10r10_uint(const GLubyte src[4], void *dst)
2359{
2360
2361
2362      uint8_t a =
2363              _mesa_unsigned_to_unsigned(src[3], 2);
2364
2365
2366      uint16_t b =
2367              _mesa_unsigned_to_unsigned(src[2], 10);
2368
2369
2370      uint16_t g =
2371              _mesa_unsigned_to_unsigned(src[1], 10);
2372
2373
2374      uint16_t r =
2375              _mesa_unsigned_to_unsigned(src[0], 10);
2376
2377      uint32_t d = 0;
2378         d |= PACK(a, 0, 2);
2379         d |= PACK(b, 2, 10);
2380         d |= PACK(g, 12, 10);
2381         d |= PACK(r, 22, 10);
2382      (*(uint32_t *)dst) = d;
2383}
2384
2385static inline void
2386pack_ubyte_a2r10g10b10_uint(const GLubyte src[4], void *dst)
2387{
2388
2389
2390      uint8_t a =
2391              _mesa_unsigned_to_unsigned(src[3], 2);
2392
2393
2394      uint16_t r =
2395              _mesa_unsigned_to_unsigned(src[0], 10);
2396
2397
2398      uint16_t g =
2399              _mesa_unsigned_to_unsigned(src[1], 10);
2400
2401
2402      uint16_t b =
2403              _mesa_unsigned_to_unsigned(src[2], 10);
2404
2405      uint32_t d = 0;
2406         d |= PACK(a, 0, 2);
2407         d |= PACK(r, 2, 10);
2408         d |= PACK(g, 12, 10);
2409         d |= PACK(b, 22, 10);
2410      (*(uint32_t *)dst) = d;
2411}
2412
2413static inline void
2414pack_ubyte_b5g6r5_uint(const GLubyte src[4], void *dst)
2415{
2416
2417
2418      uint8_t b =
2419              _mesa_unsigned_to_unsigned(src[2], 5);
2420
2421
2422      uint8_t g =
2423              _mesa_unsigned_to_unsigned(src[1], 6);
2424
2425
2426      uint8_t r =
2427              _mesa_unsigned_to_unsigned(src[0], 5);
2428
2429      uint16_t d = 0;
2430         d |= PACK(b, 0, 5);
2431         d |= PACK(g, 5, 6);
2432         d |= PACK(r, 11, 5);
2433      (*(uint16_t *)dst) = d;
2434}
2435
2436static inline void
2437pack_ubyte_r5g6b5_uint(const GLubyte src[4], void *dst)
2438{
2439
2440
2441      uint8_t r =
2442              _mesa_unsigned_to_unsigned(src[0], 5);
2443
2444
2445      uint8_t g =
2446              _mesa_unsigned_to_unsigned(src[1], 6);
2447
2448
2449      uint8_t b =
2450              _mesa_unsigned_to_unsigned(src[2], 5);
2451
2452      uint16_t d = 0;
2453         d |= PACK(r, 0, 5);
2454         d |= PACK(g, 5, 6);
2455         d |= PACK(b, 11, 5);
2456      (*(uint16_t *)dst) = d;
2457}
2458
2459static inline void
2460pack_ubyte_b2g3r3_uint(const GLubyte src[4], void *dst)
2461{
2462
2463
2464      uint8_t b =
2465              _mesa_unsigned_to_unsigned(src[2], 2);
2466
2467
2468      uint8_t g =
2469              _mesa_unsigned_to_unsigned(src[1], 3);
2470
2471
2472      uint8_t r =
2473              _mesa_unsigned_to_unsigned(src[0], 3);
2474
2475      uint8_t d = 0;
2476         d |= PACK(b, 0, 2);
2477         d |= PACK(g, 2, 3);
2478         d |= PACK(r, 5, 3);
2479      (*(uint8_t *)dst) = d;
2480}
2481
2482static inline void
2483pack_ubyte_r3g3b2_uint(const GLubyte src[4], void *dst)
2484{
2485
2486
2487      uint8_t r =
2488              _mesa_unsigned_to_unsigned(src[0], 3);
2489
2490
2491      uint8_t g =
2492              _mesa_unsigned_to_unsigned(src[1], 3);
2493
2494
2495      uint8_t b =
2496              _mesa_unsigned_to_unsigned(src[2], 2);
2497
2498      uint8_t d = 0;
2499         d |= PACK(r, 0, 3);
2500         d |= PACK(g, 3, 3);
2501         d |= PACK(b, 6, 2);
2502      (*(uint8_t *)dst) = d;
2503}
2504
2505static inline void
2506pack_ubyte_a4b4g4r4_uint(const GLubyte src[4], void *dst)
2507{
2508
2509
2510      uint8_t a =
2511              _mesa_unsigned_to_unsigned(src[3], 4);
2512
2513
2514      uint8_t b =
2515              _mesa_unsigned_to_unsigned(src[2], 4);
2516
2517
2518      uint8_t g =
2519              _mesa_unsigned_to_unsigned(src[1], 4);
2520
2521
2522      uint8_t r =
2523              _mesa_unsigned_to_unsigned(src[0], 4);
2524
2525      uint16_t d = 0;
2526         d |= PACK(a, 0, 4);
2527         d |= PACK(b, 4, 4);
2528         d |= PACK(g, 8, 4);
2529         d |= PACK(r, 12, 4);
2530      (*(uint16_t *)dst) = d;
2531}
2532
2533static inline void
2534pack_ubyte_r4g4b4a4_uint(const GLubyte src[4], void *dst)
2535{
2536
2537
2538      uint8_t r =
2539              _mesa_unsigned_to_unsigned(src[0], 4);
2540
2541
2542      uint8_t g =
2543              _mesa_unsigned_to_unsigned(src[1], 4);
2544
2545
2546      uint8_t b =
2547              _mesa_unsigned_to_unsigned(src[2], 4);
2548
2549
2550      uint8_t a =
2551              _mesa_unsigned_to_unsigned(src[3], 4);
2552
2553      uint16_t d = 0;
2554         d |= PACK(r, 0, 4);
2555         d |= PACK(g, 4, 4);
2556         d |= PACK(b, 8, 4);
2557         d |= PACK(a, 12, 4);
2558      (*(uint16_t *)dst) = d;
2559}
2560
2561static inline void
2562pack_ubyte_b4g4r4a4_uint(const GLubyte src[4], void *dst)
2563{
2564
2565
2566      uint8_t b =
2567              _mesa_unsigned_to_unsigned(src[2], 4);
2568
2569
2570      uint8_t g =
2571              _mesa_unsigned_to_unsigned(src[1], 4);
2572
2573
2574      uint8_t r =
2575              _mesa_unsigned_to_unsigned(src[0], 4);
2576
2577
2578      uint8_t a =
2579              _mesa_unsigned_to_unsigned(src[3], 4);
2580
2581      uint16_t d = 0;
2582         d |= PACK(b, 0, 4);
2583         d |= PACK(g, 4, 4);
2584         d |= PACK(r, 8, 4);
2585         d |= PACK(a, 12, 4);
2586      (*(uint16_t *)dst) = d;
2587}
2588
2589static inline void
2590pack_ubyte_a4r4g4b4_uint(const GLubyte src[4], void *dst)
2591{
2592
2593
2594      uint8_t a =
2595              _mesa_unsigned_to_unsigned(src[3], 4);
2596
2597
2598      uint8_t r =
2599              _mesa_unsigned_to_unsigned(src[0], 4);
2600
2601
2602      uint8_t g =
2603              _mesa_unsigned_to_unsigned(src[1], 4);
2604
2605
2606      uint8_t b =
2607              _mesa_unsigned_to_unsigned(src[2], 4);
2608
2609      uint16_t d = 0;
2610         d |= PACK(a, 0, 4);
2611         d |= PACK(r, 4, 4);
2612         d |= PACK(g, 8, 4);
2613         d |= PACK(b, 12, 4);
2614      (*(uint16_t *)dst) = d;
2615}
2616
2617static inline void
2618pack_ubyte_a1b5g5r5_uint(const GLubyte src[4], void *dst)
2619{
2620
2621
2622      uint8_t a =
2623              _mesa_unsigned_to_unsigned(src[3], 1);
2624
2625
2626      uint8_t b =
2627              _mesa_unsigned_to_unsigned(src[2], 5);
2628
2629
2630      uint8_t g =
2631              _mesa_unsigned_to_unsigned(src[1], 5);
2632
2633
2634      uint8_t r =
2635              _mesa_unsigned_to_unsigned(src[0], 5);
2636
2637      uint16_t d = 0;
2638         d |= PACK(a, 0, 1);
2639         d |= PACK(b, 1, 5);
2640         d |= PACK(g, 6, 5);
2641         d |= PACK(r, 11, 5);
2642      (*(uint16_t *)dst) = d;
2643}
2644
2645static inline void
2646pack_ubyte_b5g5r5a1_uint(const GLubyte src[4], void *dst)
2647{
2648
2649
2650      uint8_t b =
2651              _mesa_unsigned_to_unsigned(src[2], 5);
2652
2653
2654      uint8_t g =
2655              _mesa_unsigned_to_unsigned(src[1], 5);
2656
2657
2658      uint8_t r =
2659              _mesa_unsigned_to_unsigned(src[0], 5);
2660
2661
2662      uint8_t a =
2663              _mesa_unsigned_to_unsigned(src[3], 1);
2664
2665      uint16_t d = 0;
2666         d |= PACK(b, 0, 5);
2667         d |= PACK(g, 5, 5);
2668         d |= PACK(r, 10, 5);
2669         d |= PACK(a, 15, 1);
2670      (*(uint16_t *)dst) = d;
2671}
2672
2673static inline void
2674pack_ubyte_a1r5g5b5_uint(const GLubyte src[4], void *dst)
2675{
2676
2677
2678      uint8_t a =
2679              _mesa_unsigned_to_unsigned(src[3], 1);
2680
2681
2682      uint8_t r =
2683              _mesa_unsigned_to_unsigned(src[0], 5);
2684
2685
2686      uint8_t g =
2687              _mesa_unsigned_to_unsigned(src[1], 5);
2688
2689
2690      uint8_t b =
2691              _mesa_unsigned_to_unsigned(src[2], 5);
2692
2693      uint16_t d = 0;
2694         d |= PACK(a, 0, 1);
2695         d |= PACK(r, 1, 5);
2696         d |= PACK(g, 6, 5);
2697         d |= PACK(b, 11, 5);
2698      (*(uint16_t *)dst) = d;
2699}
2700
2701static inline void
2702pack_ubyte_r5g5b5a1_uint(const GLubyte src[4], void *dst)
2703{
2704
2705
2706      uint8_t r =
2707              _mesa_unsigned_to_unsigned(src[0], 5);
2708
2709
2710      uint8_t g =
2711              _mesa_unsigned_to_unsigned(src[1], 5);
2712
2713
2714      uint8_t b =
2715              _mesa_unsigned_to_unsigned(src[2], 5);
2716
2717
2718      uint8_t a =
2719              _mesa_unsigned_to_unsigned(src[3], 1);
2720
2721      uint16_t d = 0;
2722         d |= PACK(r, 0, 5);
2723         d |= PACK(g, 5, 5);
2724         d |= PACK(b, 10, 5);
2725         d |= PACK(a, 15, 1);
2726      (*(uint16_t *)dst) = d;
2727}
2728
2729static inline void
2730pack_ubyte_a_uint8(const GLubyte src[4], void *dst)
2731{
2732
2733
2734      uint8_t a =
2735              _mesa_unsigned_to_unsigned(src[3], 8);
2736
2737      uint8_t *d = (uint8_t *)dst;
2738         d[0] = a;
2739}
2740
2741static inline void
2742pack_ubyte_a_uint16(const GLubyte src[4], void *dst)
2743{
2744
2745
2746      uint16_t a =
2747              _mesa_unsigned_to_unsigned(src[3], 16);
2748
2749      uint16_t *d = (uint16_t *)dst;
2750         d[0] = a;
2751}
2752
2753static inline void
2754pack_ubyte_a_uint32(const GLubyte src[4], void *dst)
2755{
2756
2757
2758      uint32_t a =
2759              _mesa_unsigned_to_unsigned(src[3], 32);
2760
2761      uint32_t *d = (uint32_t *)dst;
2762         d[0] = a;
2763}
2764
2765static inline void
2766pack_ubyte_a_sint8(const GLubyte src[4], void *dst)
2767{
2768
2769
2770      int8_t a =
2771              _mesa_unsigned_to_signed(src[3], 8);
2772
2773      int8_t *d = (int8_t *)dst;
2774         d[0] = a;
2775}
2776
2777static inline void
2778pack_ubyte_a_sint16(const GLubyte src[4], void *dst)
2779{
2780
2781
2782      int16_t a =
2783              _mesa_unsigned_to_signed(src[3], 16);
2784
2785      int16_t *d = (int16_t *)dst;
2786         d[0] = a;
2787}
2788
2789static inline void
2790pack_ubyte_a_sint32(const GLubyte src[4], void *dst)
2791{
2792
2793
2794      int32_t a =
2795              _mesa_unsigned_to_signed(src[3], 32);
2796
2797      int32_t *d = (int32_t *)dst;
2798         d[0] = a;
2799}
2800
2801static inline void
2802pack_ubyte_i_uint8(const GLubyte src[4], void *dst)
2803{
2804
2805
2806      uint8_t i =
2807              _mesa_unsigned_to_unsigned(src[0], 8);
2808
2809      uint8_t *d = (uint8_t *)dst;
2810         d[0] = i;
2811}
2812
2813static inline void
2814pack_ubyte_i_uint16(const GLubyte src[4], void *dst)
2815{
2816
2817
2818      uint16_t i =
2819              _mesa_unsigned_to_unsigned(src[0], 16);
2820
2821      uint16_t *d = (uint16_t *)dst;
2822         d[0] = i;
2823}
2824
2825static inline void
2826pack_ubyte_i_uint32(const GLubyte src[4], void *dst)
2827{
2828
2829
2830      uint32_t i =
2831              _mesa_unsigned_to_unsigned(src[0], 32);
2832
2833      uint32_t *d = (uint32_t *)dst;
2834         d[0] = i;
2835}
2836
2837static inline void
2838pack_ubyte_i_sint8(const GLubyte src[4], void *dst)
2839{
2840
2841
2842      int8_t i =
2843              _mesa_unsigned_to_signed(src[0], 8);
2844
2845      int8_t *d = (int8_t *)dst;
2846         d[0] = i;
2847}
2848
2849static inline void
2850pack_ubyte_i_sint16(const GLubyte src[4], void *dst)
2851{
2852
2853
2854      int16_t i =
2855              _mesa_unsigned_to_signed(src[0], 16);
2856
2857      int16_t *d = (int16_t *)dst;
2858         d[0] = i;
2859}
2860
2861static inline void
2862pack_ubyte_i_sint32(const GLubyte src[4], void *dst)
2863{
2864
2865
2866      int32_t i =
2867              _mesa_unsigned_to_signed(src[0], 32);
2868
2869      int32_t *d = (int32_t *)dst;
2870         d[0] = i;
2871}
2872
2873static inline void
2874pack_ubyte_l_uint8(const GLubyte src[4], void *dst)
2875{
2876
2877
2878      uint8_t l =
2879              _mesa_unsigned_to_unsigned(src[0], 8);
2880
2881      uint8_t *d = (uint8_t *)dst;
2882         d[0] = l;
2883}
2884
2885static inline void
2886pack_ubyte_l_uint16(const GLubyte src[4], void *dst)
2887{
2888
2889
2890      uint16_t l =
2891              _mesa_unsigned_to_unsigned(src[0], 16);
2892
2893      uint16_t *d = (uint16_t *)dst;
2894         d[0] = l;
2895}
2896
2897static inline void
2898pack_ubyte_l_uint32(const GLubyte src[4], void *dst)
2899{
2900
2901
2902      uint32_t l =
2903              _mesa_unsigned_to_unsigned(src[0], 32);
2904
2905      uint32_t *d = (uint32_t *)dst;
2906         d[0] = l;
2907}
2908
2909static inline void
2910pack_ubyte_l_sint8(const GLubyte src[4], void *dst)
2911{
2912
2913
2914      int8_t l =
2915              _mesa_unsigned_to_signed(src[0], 8);
2916
2917      int8_t *d = (int8_t *)dst;
2918         d[0] = l;
2919}
2920
2921static inline void
2922pack_ubyte_l_sint16(const GLubyte src[4], void *dst)
2923{
2924
2925
2926      int16_t l =
2927              _mesa_unsigned_to_signed(src[0], 16);
2928
2929      int16_t *d = (int16_t *)dst;
2930         d[0] = l;
2931}
2932
2933static inline void
2934pack_ubyte_l_sint32(const GLubyte src[4], void *dst)
2935{
2936
2937
2938      int32_t l =
2939              _mesa_unsigned_to_signed(src[0], 32);
2940
2941      int32_t *d = (int32_t *)dst;
2942         d[0] = l;
2943}
2944
2945static inline void
2946pack_ubyte_la_uint8(const GLubyte src[4], void *dst)
2947{
2948
2949
2950      uint8_t l =
2951              _mesa_unsigned_to_unsigned(src[0], 8);
2952
2953
2954      uint8_t a =
2955              _mesa_unsigned_to_unsigned(src[3], 8);
2956
2957      uint8_t *d = (uint8_t *)dst;
2958         d[0] = l;
2959         d[1] = a;
2960}
2961
2962static inline void
2963pack_ubyte_la_uint16(const GLubyte src[4], void *dst)
2964{
2965
2966
2967      uint16_t l =
2968              _mesa_unsigned_to_unsigned(src[0], 16);
2969
2970
2971      uint16_t a =
2972              _mesa_unsigned_to_unsigned(src[3], 16);
2973
2974      uint16_t *d = (uint16_t *)dst;
2975         d[0] = l;
2976         d[1] = a;
2977}
2978
2979static inline void
2980pack_ubyte_la_uint32(const GLubyte src[4], void *dst)
2981{
2982
2983
2984      uint32_t l =
2985              _mesa_unsigned_to_unsigned(src[0], 32);
2986
2987
2988      uint32_t a =
2989              _mesa_unsigned_to_unsigned(src[3], 32);
2990
2991      uint32_t *d = (uint32_t *)dst;
2992         d[0] = l;
2993         d[1] = a;
2994}
2995
2996static inline void
2997pack_ubyte_la_sint8(const GLubyte src[4], void *dst)
2998{
2999
3000
3001      int8_t l =
3002              _mesa_unsigned_to_signed(src[0], 8);
3003
3004
3005      int8_t a =
3006              _mesa_unsigned_to_signed(src[3], 8);
3007
3008      int8_t *d = (int8_t *)dst;
3009         d[0] = l;
3010         d[1] = a;
3011}
3012
3013static inline void
3014pack_ubyte_la_sint16(const GLubyte src[4], void *dst)
3015{
3016
3017
3018      int16_t l =
3019              _mesa_unsigned_to_signed(src[0], 16);
3020
3021
3022      int16_t a =
3023              _mesa_unsigned_to_signed(src[3], 16);
3024
3025      int16_t *d = (int16_t *)dst;
3026         d[0] = l;
3027         d[1] = a;
3028}
3029
3030static inline void
3031pack_ubyte_la_sint32(const GLubyte src[4], void *dst)
3032{
3033
3034
3035      int32_t l =
3036              _mesa_unsigned_to_signed(src[0], 32);
3037
3038
3039      int32_t a =
3040              _mesa_unsigned_to_signed(src[3], 32);
3041
3042      int32_t *d = (int32_t *)dst;
3043         d[0] = l;
3044         d[1] = a;
3045}
3046
3047static inline void
3048pack_ubyte_r_uint8(const GLubyte src[4], void *dst)
3049{
3050
3051
3052      uint8_t r =
3053              _mesa_unsigned_to_unsigned(src[0], 8);
3054
3055      uint8_t *d = (uint8_t *)dst;
3056         d[0] = r;
3057}
3058
3059static inline void
3060pack_ubyte_r_uint16(const GLubyte src[4], void *dst)
3061{
3062
3063
3064      uint16_t r =
3065              _mesa_unsigned_to_unsigned(src[0], 16);
3066
3067      uint16_t *d = (uint16_t *)dst;
3068         d[0] = r;
3069}
3070
3071static inline void
3072pack_ubyte_r_uint32(const GLubyte src[4], void *dst)
3073{
3074
3075
3076      uint32_t r =
3077              _mesa_unsigned_to_unsigned(src[0], 32);
3078
3079      uint32_t *d = (uint32_t *)dst;
3080         d[0] = r;
3081}
3082
3083static inline void
3084pack_ubyte_r_sint8(const GLubyte src[4], void *dst)
3085{
3086
3087
3088      int8_t r =
3089              _mesa_unsigned_to_signed(src[0], 8);
3090
3091      int8_t *d = (int8_t *)dst;
3092         d[0] = r;
3093}
3094
3095static inline void
3096pack_ubyte_r_sint16(const GLubyte src[4], void *dst)
3097{
3098
3099
3100      int16_t r =
3101              _mesa_unsigned_to_signed(src[0], 16);
3102
3103      int16_t *d = (int16_t *)dst;
3104         d[0] = r;
3105}
3106
3107static inline void
3108pack_ubyte_r_sint32(const GLubyte src[4], void *dst)
3109{
3110
3111
3112      int32_t r =
3113              _mesa_unsigned_to_signed(src[0], 32);
3114
3115      int32_t *d = (int32_t *)dst;
3116         d[0] = r;
3117}
3118
3119static inline void
3120pack_ubyte_rg_uint8(const GLubyte src[4], void *dst)
3121{
3122
3123
3124      uint8_t r =
3125              _mesa_unsigned_to_unsigned(src[0], 8);
3126
3127
3128      uint8_t g =
3129              _mesa_unsigned_to_unsigned(src[1], 8);
3130
3131      uint8_t *d = (uint8_t *)dst;
3132         d[0] = r;
3133         d[1] = g;
3134}
3135
3136static inline void
3137pack_ubyte_rg_uint16(const GLubyte src[4], void *dst)
3138{
3139
3140
3141      uint16_t r =
3142              _mesa_unsigned_to_unsigned(src[0], 16);
3143
3144
3145      uint16_t g =
3146              _mesa_unsigned_to_unsigned(src[1], 16);
3147
3148      uint16_t *d = (uint16_t *)dst;
3149         d[0] = r;
3150         d[1] = g;
3151}
3152
3153static inline void
3154pack_ubyte_rg_uint32(const GLubyte src[4], void *dst)
3155{
3156
3157
3158      uint32_t r =
3159              _mesa_unsigned_to_unsigned(src[0], 32);
3160
3161
3162      uint32_t g =
3163              _mesa_unsigned_to_unsigned(src[1], 32);
3164
3165      uint32_t *d = (uint32_t *)dst;
3166         d[0] = r;
3167         d[1] = g;
3168}
3169
3170static inline void
3171pack_ubyte_rg_sint8(const GLubyte src[4], void *dst)
3172{
3173
3174
3175      int8_t r =
3176              _mesa_unsigned_to_signed(src[0], 8);
3177
3178
3179      int8_t g =
3180              _mesa_unsigned_to_signed(src[1], 8);
3181
3182      int8_t *d = (int8_t *)dst;
3183         d[0] = r;
3184         d[1] = g;
3185}
3186
3187static inline void
3188pack_ubyte_rg_sint16(const GLubyte src[4], void *dst)
3189{
3190
3191
3192      int16_t r =
3193              _mesa_unsigned_to_signed(src[0], 16);
3194
3195
3196      int16_t g =
3197              _mesa_unsigned_to_signed(src[1], 16);
3198
3199      int16_t *d = (int16_t *)dst;
3200         d[0] = r;
3201         d[1] = g;
3202}
3203
3204static inline void
3205pack_ubyte_rg_sint32(const GLubyte src[4], void *dst)
3206{
3207
3208
3209      int32_t r =
3210              _mesa_unsigned_to_signed(src[0], 32);
3211
3212
3213      int32_t g =
3214              _mesa_unsigned_to_signed(src[1], 32);
3215
3216      int32_t *d = (int32_t *)dst;
3217         d[0] = r;
3218         d[1] = g;
3219}
3220
3221static inline void
3222pack_ubyte_rgb_uint8(const GLubyte src[4], void *dst)
3223{
3224
3225
3226      uint8_t r =
3227              _mesa_unsigned_to_unsigned(src[0], 8);
3228
3229
3230      uint8_t g =
3231              _mesa_unsigned_to_unsigned(src[1], 8);
3232
3233
3234      uint8_t b =
3235              _mesa_unsigned_to_unsigned(src[2], 8);
3236
3237      uint8_t *d = (uint8_t *)dst;
3238         d[0] = r;
3239         d[1] = g;
3240         d[2] = b;
3241}
3242
3243static inline void
3244pack_ubyte_rgb_uint16(const GLubyte src[4], void *dst)
3245{
3246
3247
3248      uint16_t r =
3249              _mesa_unsigned_to_unsigned(src[0], 16);
3250
3251
3252      uint16_t g =
3253              _mesa_unsigned_to_unsigned(src[1], 16);
3254
3255
3256      uint16_t b =
3257              _mesa_unsigned_to_unsigned(src[2], 16);
3258
3259      uint16_t *d = (uint16_t *)dst;
3260         d[0] = r;
3261         d[1] = g;
3262         d[2] = b;
3263}
3264
3265static inline void
3266pack_ubyte_rgb_uint32(const GLubyte src[4], void *dst)
3267{
3268
3269
3270      uint32_t r =
3271              _mesa_unsigned_to_unsigned(src[0], 32);
3272
3273
3274      uint32_t g =
3275              _mesa_unsigned_to_unsigned(src[1], 32);
3276
3277
3278      uint32_t b =
3279              _mesa_unsigned_to_unsigned(src[2], 32);
3280
3281      uint32_t *d = (uint32_t *)dst;
3282         d[0] = r;
3283         d[1] = g;
3284         d[2] = b;
3285}
3286
3287static inline void
3288pack_ubyte_rgb_sint8(const GLubyte src[4], void *dst)
3289{
3290
3291
3292      int8_t r =
3293              _mesa_unsigned_to_signed(src[0], 8);
3294
3295
3296      int8_t g =
3297              _mesa_unsigned_to_signed(src[1], 8);
3298
3299
3300      int8_t b =
3301              _mesa_unsigned_to_signed(src[2], 8);
3302
3303      int8_t *d = (int8_t *)dst;
3304         d[0] = r;
3305         d[1] = g;
3306         d[2] = b;
3307}
3308
3309static inline void
3310pack_ubyte_rgb_sint16(const GLubyte src[4], void *dst)
3311{
3312
3313
3314      int16_t r =
3315              _mesa_unsigned_to_signed(src[0], 16);
3316
3317
3318      int16_t g =
3319              _mesa_unsigned_to_signed(src[1], 16);
3320
3321
3322      int16_t b =
3323              _mesa_unsigned_to_signed(src[2], 16);
3324
3325      int16_t *d = (int16_t *)dst;
3326         d[0] = r;
3327         d[1] = g;
3328         d[2] = b;
3329}
3330
3331static inline void
3332pack_ubyte_rgb_sint32(const GLubyte src[4], void *dst)
3333{
3334
3335
3336      int32_t r =
3337              _mesa_unsigned_to_signed(src[0], 32);
3338
3339
3340      int32_t g =
3341              _mesa_unsigned_to_signed(src[1], 32);
3342
3343
3344      int32_t b =
3345              _mesa_unsigned_to_signed(src[2], 32);
3346
3347      int32_t *d = (int32_t *)dst;
3348         d[0] = r;
3349         d[1] = g;
3350         d[2] = b;
3351}
3352
3353static inline void
3354pack_ubyte_rgba_uint8(const GLubyte src[4], void *dst)
3355{
3356
3357
3358      uint8_t r =
3359              _mesa_unsigned_to_unsigned(src[0], 8);
3360
3361
3362      uint8_t g =
3363              _mesa_unsigned_to_unsigned(src[1], 8);
3364
3365
3366      uint8_t b =
3367              _mesa_unsigned_to_unsigned(src[2], 8);
3368
3369
3370      uint8_t a =
3371              _mesa_unsigned_to_unsigned(src[3], 8);
3372
3373      uint8_t *d = (uint8_t *)dst;
3374         d[0] = r;
3375         d[1] = g;
3376         d[2] = b;
3377         d[3] = a;
3378}
3379
3380static inline void
3381pack_ubyte_rgba_uint16(const GLubyte src[4], void *dst)
3382{
3383
3384
3385      uint16_t r =
3386              _mesa_unsigned_to_unsigned(src[0], 16);
3387
3388
3389      uint16_t g =
3390              _mesa_unsigned_to_unsigned(src[1], 16);
3391
3392
3393      uint16_t b =
3394              _mesa_unsigned_to_unsigned(src[2], 16);
3395
3396
3397      uint16_t a =
3398              _mesa_unsigned_to_unsigned(src[3], 16);
3399
3400      uint16_t *d = (uint16_t *)dst;
3401         d[0] = r;
3402         d[1] = g;
3403         d[2] = b;
3404         d[3] = a;
3405}
3406
3407static inline void
3408pack_ubyte_rgba_uint32(const GLubyte src[4], void *dst)
3409{
3410
3411
3412      uint32_t r =
3413              _mesa_unsigned_to_unsigned(src[0], 32);
3414
3415
3416      uint32_t g =
3417              _mesa_unsigned_to_unsigned(src[1], 32);
3418
3419
3420      uint32_t b =
3421              _mesa_unsigned_to_unsigned(src[2], 32);
3422
3423
3424      uint32_t a =
3425              _mesa_unsigned_to_unsigned(src[3], 32);
3426
3427      uint32_t *d = (uint32_t *)dst;
3428         d[0] = r;
3429         d[1] = g;
3430         d[2] = b;
3431         d[3] = a;
3432}
3433
3434static inline void
3435pack_ubyte_rgba_sint8(const GLubyte src[4], void *dst)
3436{
3437
3438
3439      int8_t r =
3440              _mesa_unsigned_to_signed(src[0], 8);
3441
3442
3443      int8_t g =
3444              _mesa_unsigned_to_signed(src[1], 8);
3445
3446
3447      int8_t b =
3448              _mesa_unsigned_to_signed(src[2], 8);
3449
3450
3451      int8_t a =
3452              _mesa_unsigned_to_signed(src[3], 8);
3453
3454      int8_t *d = (int8_t *)dst;
3455         d[0] = r;
3456         d[1] = g;
3457         d[2] = b;
3458         d[3] = a;
3459}
3460
3461static inline void
3462pack_ubyte_rgba_sint16(const GLubyte src[4], void *dst)
3463{
3464
3465
3466      int16_t r =
3467              _mesa_unsigned_to_signed(src[0], 16);
3468
3469
3470      int16_t g =
3471              _mesa_unsigned_to_signed(src[1], 16);
3472
3473
3474      int16_t b =
3475              _mesa_unsigned_to_signed(src[2], 16);
3476
3477
3478      int16_t a =
3479              _mesa_unsigned_to_signed(src[3], 16);
3480
3481      int16_t *d = (int16_t *)dst;
3482         d[0] = r;
3483         d[1] = g;
3484         d[2] = b;
3485         d[3] = a;
3486}
3487
3488static inline void
3489pack_ubyte_rgba_sint32(const GLubyte src[4], void *dst)
3490{
3491
3492
3493      int32_t r =
3494              _mesa_unsigned_to_signed(src[0], 32);
3495
3496
3497      int32_t g =
3498              _mesa_unsigned_to_signed(src[1], 32);
3499
3500
3501      int32_t b =
3502              _mesa_unsigned_to_signed(src[2], 32);
3503
3504
3505      int32_t a =
3506              _mesa_unsigned_to_signed(src[3], 32);
3507
3508      int32_t *d = (int32_t *)dst;
3509         d[0] = r;
3510         d[1] = g;
3511         d[2] = b;
3512         d[3] = a;
3513}
3514
3515static inline void
3516pack_ubyte_rgbx_uint8(const GLubyte src[4], void *dst)
3517{
3518
3519
3520      uint8_t r =
3521              _mesa_unsigned_to_unsigned(src[0], 8);
3522
3523
3524      uint8_t g =
3525              _mesa_unsigned_to_unsigned(src[1], 8);
3526
3527
3528      uint8_t b =
3529              _mesa_unsigned_to_unsigned(src[2], 8);
3530
3531
3532      uint8_t *d = (uint8_t *)dst;
3533         d[0] = r;
3534         d[1] = g;
3535         d[2] = b;
3536            }
3537
3538static inline void
3539pack_ubyte_rgbx_uint16(const GLubyte src[4], void *dst)
3540{
3541
3542
3543      uint16_t r =
3544              _mesa_unsigned_to_unsigned(src[0], 16);
3545
3546
3547      uint16_t g =
3548              _mesa_unsigned_to_unsigned(src[1], 16);
3549
3550
3551      uint16_t b =
3552              _mesa_unsigned_to_unsigned(src[2], 16);
3553
3554
3555      uint16_t *d = (uint16_t *)dst;
3556         d[0] = r;
3557         d[1] = g;
3558         d[2] = b;
3559            }
3560
3561static inline void
3562pack_ubyte_rgbx_uint32(const GLubyte src[4], void *dst)
3563{
3564
3565
3566      uint32_t r =
3567              _mesa_unsigned_to_unsigned(src[0], 32);
3568
3569
3570      uint32_t g =
3571              _mesa_unsigned_to_unsigned(src[1], 32);
3572
3573
3574      uint32_t b =
3575              _mesa_unsigned_to_unsigned(src[2], 32);
3576
3577
3578      uint32_t *d = (uint32_t *)dst;
3579         d[0] = r;
3580         d[1] = g;
3581         d[2] = b;
3582            }
3583
3584static inline void
3585pack_ubyte_rgbx_sint8(const GLubyte src[4], void *dst)
3586{
3587
3588
3589      int8_t r =
3590              _mesa_unsigned_to_signed(src[0], 8);
3591
3592
3593      int8_t g =
3594              _mesa_unsigned_to_signed(src[1], 8);
3595
3596
3597      int8_t b =
3598              _mesa_unsigned_to_signed(src[2], 8);
3599
3600
3601      int8_t *d = (int8_t *)dst;
3602         d[0] = r;
3603         d[1] = g;
3604         d[2] = b;
3605            }
3606
3607static inline void
3608pack_ubyte_rgbx_sint16(const GLubyte src[4], void *dst)
3609{
3610
3611
3612      int16_t r =
3613              _mesa_unsigned_to_signed(src[0], 16);
3614
3615
3616      int16_t g =
3617              _mesa_unsigned_to_signed(src[1], 16);
3618
3619
3620      int16_t b =
3621              _mesa_unsigned_to_signed(src[2], 16);
3622
3623
3624      int16_t *d = (int16_t *)dst;
3625         d[0] = r;
3626         d[1] = g;
3627         d[2] = b;
3628            }
3629
3630static inline void
3631pack_ubyte_rgbx_sint32(const GLubyte src[4], void *dst)
3632{
3633
3634
3635      int32_t r =
3636              _mesa_unsigned_to_signed(src[0], 32);
3637
3638
3639      int32_t g =
3640              _mesa_unsigned_to_signed(src[1], 32);
3641
3642
3643      int32_t b =
3644              _mesa_unsigned_to_signed(src[2], 32);
3645
3646
3647      int32_t *d = (int32_t *)dst;
3648         d[0] = r;
3649         d[1] = g;
3650         d[2] = b;
3651            }
3652
3653static inline void
3654pack_ubyte_r9g9b9e5_float(const GLubyte src[4], void *dst)
3655{
3656   GLuint *d = (GLuint *) dst;
3657   GLfloat rgb[3];
3658   rgb[0] = _mesa_unorm_to_float(src[RCOMP], 8);
3659   rgb[1] = _mesa_unorm_to_float(src[GCOMP], 8);
3660   rgb[2] = _mesa_unorm_to_float(src[BCOMP], 8);
3661   *d = float3_to_rgb9e5(rgb);
3662}
3663
3664static inline void
3665pack_ubyte_r11g11b10_float(const GLubyte src[4], void *dst)
3666{
3667   GLuint *d = (GLuint *) dst;
3668   GLfloat rgb[3];
3669   rgb[0] = _mesa_unorm_to_float(src[RCOMP], 8);
3670   rgb[1] = _mesa_unorm_to_float(src[GCOMP], 8);
3671   rgb[2] = _mesa_unorm_to_float(src[BCOMP], 8);
3672   *d = float3_to_r11g11b10f(rgb);
3673}
3674
3675/* uint packing functions */
3676
3677
3678static inline void
3679pack_uint_a8b8g8r8_uint(const GLuint src[4], void *dst)
3680{
3681
3682
3683      uint8_t a =
3684         _mesa_unsigned_to_unsigned(src[3], 8);
3685
3686
3687      uint8_t b =
3688         _mesa_unsigned_to_unsigned(src[2], 8);
3689
3690
3691      uint8_t g =
3692         _mesa_unsigned_to_unsigned(src[1], 8);
3693
3694
3695      uint8_t r =
3696         _mesa_unsigned_to_unsigned(src[0], 8);
3697
3698      uint32_t d = 0;
3699         d |= PACK(a, 0, 8);
3700         d |= PACK(b, 8, 8);
3701         d |= PACK(g, 16, 8);
3702         d |= PACK(r, 24, 8);
3703      (*(uint32_t *)dst) = d;
3704}
3705
3706static inline void
3707pack_uint_a8r8g8b8_uint(const GLuint src[4], void *dst)
3708{
3709
3710
3711      uint8_t a =
3712         _mesa_unsigned_to_unsigned(src[3], 8);
3713
3714
3715      uint8_t r =
3716         _mesa_unsigned_to_unsigned(src[0], 8);
3717
3718
3719      uint8_t g =
3720         _mesa_unsigned_to_unsigned(src[1], 8);
3721
3722
3723      uint8_t b =
3724         _mesa_unsigned_to_unsigned(src[2], 8);
3725
3726      uint32_t d = 0;
3727         d |= PACK(a, 0, 8);
3728         d |= PACK(r, 8, 8);
3729         d |= PACK(g, 16, 8);
3730         d |= PACK(b, 24, 8);
3731      (*(uint32_t *)dst) = d;
3732}
3733
3734static inline void
3735pack_uint_r8g8b8a8_uint(const GLuint src[4], void *dst)
3736{
3737
3738
3739      uint8_t r =
3740         _mesa_unsigned_to_unsigned(src[0], 8);
3741
3742
3743      uint8_t g =
3744         _mesa_unsigned_to_unsigned(src[1], 8);
3745
3746
3747      uint8_t b =
3748         _mesa_unsigned_to_unsigned(src[2], 8);
3749
3750
3751      uint8_t a =
3752         _mesa_unsigned_to_unsigned(src[3], 8);
3753
3754      uint32_t d = 0;
3755         d |= PACK(r, 0, 8);
3756         d |= PACK(g, 8, 8);
3757         d |= PACK(b, 16, 8);
3758         d |= PACK(a, 24, 8);
3759      (*(uint32_t *)dst) = d;
3760}
3761
3762static inline void
3763pack_uint_b8g8r8a8_uint(const GLuint src[4], void *dst)
3764{
3765
3766
3767      uint8_t b =
3768         _mesa_unsigned_to_unsigned(src[2], 8);
3769
3770
3771      uint8_t g =
3772         _mesa_unsigned_to_unsigned(src[1], 8);
3773
3774
3775      uint8_t r =
3776         _mesa_unsigned_to_unsigned(src[0], 8);
3777
3778
3779      uint8_t a =
3780         _mesa_unsigned_to_unsigned(src[3], 8);
3781
3782      uint32_t d = 0;
3783         d |= PACK(b, 0, 8);
3784         d |= PACK(g, 8, 8);
3785         d |= PACK(r, 16, 8);
3786         d |= PACK(a, 24, 8);
3787      (*(uint32_t *)dst) = d;
3788}
3789
3790static inline void
3791pack_uint_b10g10r10a2_uint(const GLuint src[4], void *dst)
3792{
3793
3794
3795      uint16_t b =
3796         _mesa_unsigned_to_unsigned(src[2], 10);
3797
3798
3799      uint16_t g =
3800         _mesa_unsigned_to_unsigned(src[1], 10);
3801
3802
3803      uint16_t r =
3804         _mesa_unsigned_to_unsigned(src[0], 10);
3805
3806
3807      uint8_t a =
3808         _mesa_unsigned_to_unsigned(src[3], 2);
3809
3810      uint32_t d = 0;
3811         d |= PACK(b, 0, 10);
3812         d |= PACK(g, 10, 10);
3813         d |= PACK(r, 20, 10);
3814         d |= PACK(a, 30, 2);
3815      (*(uint32_t *)dst) = d;
3816}
3817
3818static inline void
3819pack_uint_r10g10b10a2_uint(const GLuint src[4], void *dst)
3820{
3821
3822
3823      uint16_t r =
3824         _mesa_unsigned_to_unsigned(src[0], 10);
3825
3826
3827      uint16_t g =
3828         _mesa_unsigned_to_unsigned(src[1], 10);
3829
3830
3831      uint16_t b =
3832         _mesa_unsigned_to_unsigned(src[2], 10);
3833
3834
3835      uint8_t a =
3836         _mesa_unsigned_to_unsigned(src[3], 2);
3837
3838      uint32_t d = 0;
3839         d |= PACK(r, 0, 10);
3840         d |= PACK(g, 10, 10);
3841         d |= PACK(b, 20, 10);
3842         d |= PACK(a, 30, 2);
3843      (*(uint32_t *)dst) = d;
3844}
3845
3846static inline void
3847pack_uint_a2b10g10r10_uint(const GLuint src[4], void *dst)
3848{
3849
3850
3851      uint8_t a =
3852         _mesa_unsigned_to_unsigned(src[3], 2);
3853
3854
3855      uint16_t b =
3856         _mesa_unsigned_to_unsigned(src[2], 10);
3857
3858
3859      uint16_t g =
3860         _mesa_unsigned_to_unsigned(src[1], 10);
3861
3862
3863      uint16_t r =
3864         _mesa_unsigned_to_unsigned(src[0], 10);
3865
3866      uint32_t d = 0;
3867         d |= PACK(a, 0, 2);
3868         d |= PACK(b, 2, 10);
3869         d |= PACK(g, 12, 10);
3870         d |= PACK(r, 22, 10);
3871      (*(uint32_t *)dst) = d;
3872}
3873
3874static inline void
3875pack_uint_a2r10g10b10_uint(const GLuint src[4], void *dst)
3876{
3877
3878
3879      uint8_t a =
3880         _mesa_unsigned_to_unsigned(src[3], 2);
3881
3882
3883      uint16_t r =
3884         _mesa_unsigned_to_unsigned(src[0], 10);
3885
3886
3887      uint16_t g =
3888         _mesa_unsigned_to_unsigned(src[1], 10);
3889
3890
3891      uint16_t b =
3892         _mesa_unsigned_to_unsigned(src[2], 10);
3893
3894      uint32_t d = 0;
3895         d |= PACK(a, 0, 2);
3896         d |= PACK(r, 2, 10);
3897         d |= PACK(g, 12, 10);
3898         d |= PACK(b, 22, 10);
3899      (*(uint32_t *)dst) = d;
3900}
3901
3902static inline void
3903pack_uint_b5g6r5_uint(const GLuint src[4], void *dst)
3904{
3905
3906
3907      uint8_t b =
3908         _mesa_unsigned_to_unsigned(src[2], 5);
3909
3910
3911      uint8_t g =
3912         _mesa_unsigned_to_unsigned(src[1], 6);
3913
3914
3915      uint8_t r =
3916         _mesa_unsigned_to_unsigned(src[0], 5);
3917
3918      uint16_t d = 0;
3919         d |= PACK(b, 0, 5);
3920         d |= PACK(g, 5, 6);
3921         d |= PACK(r, 11, 5);
3922      (*(uint16_t *)dst) = d;
3923}
3924
3925static inline void
3926pack_uint_r5g6b5_uint(const GLuint src[4], void *dst)
3927{
3928
3929
3930      uint8_t r =
3931         _mesa_unsigned_to_unsigned(src[0], 5);
3932
3933
3934      uint8_t g =
3935         _mesa_unsigned_to_unsigned(src[1], 6);
3936
3937
3938      uint8_t b =
3939         _mesa_unsigned_to_unsigned(src[2], 5);
3940
3941      uint16_t d = 0;
3942         d |= PACK(r, 0, 5);
3943         d |= PACK(g, 5, 6);
3944         d |= PACK(b, 11, 5);
3945      (*(uint16_t *)dst) = d;
3946}
3947
3948static inline void
3949pack_uint_b2g3r3_uint(const GLuint src[4], void *dst)
3950{
3951
3952
3953      uint8_t b =
3954         _mesa_unsigned_to_unsigned(src[2], 2);
3955
3956
3957      uint8_t g =
3958         _mesa_unsigned_to_unsigned(src[1], 3);
3959
3960
3961      uint8_t r =
3962         _mesa_unsigned_to_unsigned(src[0], 3);
3963
3964      uint8_t d = 0;
3965         d |= PACK(b, 0, 2);
3966         d |= PACK(g, 2, 3);
3967         d |= PACK(r, 5, 3);
3968      (*(uint8_t *)dst) = d;
3969}
3970
3971static inline void
3972pack_uint_r3g3b2_uint(const GLuint src[4], void *dst)
3973{
3974
3975
3976      uint8_t r =
3977         _mesa_unsigned_to_unsigned(src[0], 3);
3978
3979
3980      uint8_t g =
3981         _mesa_unsigned_to_unsigned(src[1], 3);
3982
3983
3984      uint8_t b =
3985         _mesa_unsigned_to_unsigned(src[2], 2);
3986
3987      uint8_t d = 0;
3988         d |= PACK(r, 0, 3);
3989         d |= PACK(g, 3, 3);
3990         d |= PACK(b, 6, 2);
3991      (*(uint8_t *)dst) = d;
3992}
3993
3994static inline void
3995pack_uint_a4b4g4r4_uint(const GLuint src[4], void *dst)
3996{
3997
3998
3999      uint8_t a =
4000         _mesa_unsigned_to_unsigned(src[3], 4);
4001
4002
4003      uint8_t b =
4004         _mesa_unsigned_to_unsigned(src[2], 4);
4005
4006
4007      uint8_t g =
4008         _mesa_unsigned_to_unsigned(src[1], 4);
4009
4010
4011      uint8_t r =
4012         _mesa_unsigned_to_unsigned(src[0], 4);
4013
4014      uint16_t d = 0;
4015         d |= PACK(a, 0, 4);
4016         d |= PACK(b, 4, 4);
4017         d |= PACK(g, 8, 4);
4018         d |= PACK(r, 12, 4);
4019      (*(uint16_t *)dst) = d;
4020}
4021
4022static inline void
4023pack_uint_r4g4b4a4_uint(const GLuint src[4], void *dst)
4024{
4025
4026
4027      uint8_t r =
4028         _mesa_unsigned_to_unsigned(src[0], 4);
4029
4030
4031      uint8_t g =
4032         _mesa_unsigned_to_unsigned(src[1], 4);
4033
4034
4035      uint8_t b =
4036         _mesa_unsigned_to_unsigned(src[2], 4);
4037
4038
4039      uint8_t a =
4040         _mesa_unsigned_to_unsigned(src[3], 4);
4041
4042      uint16_t d = 0;
4043         d |= PACK(r, 0, 4);
4044         d |= PACK(g, 4, 4);
4045         d |= PACK(b, 8, 4);
4046         d |= PACK(a, 12, 4);
4047      (*(uint16_t *)dst) = d;
4048}
4049
4050static inline void
4051pack_uint_b4g4r4a4_uint(const GLuint src[4], void *dst)
4052{
4053
4054
4055      uint8_t b =
4056         _mesa_unsigned_to_unsigned(src[2], 4);
4057
4058
4059      uint8_t g =
4060         _mesa_unsigned_to_unsigned(src[1], 4);
4061
4062
4063      uint8_t r =
4064         _mesa_unsigned_to_unsigned(src[0], 4);
4065
4066
4067      uint8_t a =
4068         _mesa_unsigned_to_unsigned(src[3], 4);
4069
4070      uint16_t d = 0;
4071         d |= PACK(b, 0, 4);
4072         d |= PACK(g, 4, 4);
4073         d |= PACK(r, 8, 4);
4074         d |= PACK(a, 12, 4);
4075      (*(uint16_t *)dst) = d;
4076}
4077
4078static inline void
4079pack_uint_a4r4g4b4_uint(const GLuint src[4], void *dst)
4080{
4081
4082
4083      uint8_t a =
4084         _mesa_unsigned_to_unsigned(src[3], 4);
4085
4086
4087      uint8_t r =
4088         _mesa_unsigned_to_unsigned(src[0], 4);
4089
4090
4091      uint8_t g =
4092         _mesa_unsigned_to_unsigned(src[1], 4);
4093
4094
4095      uint8_t b =
4096         _mesa_unsigned_to_unsigned(src[2], 4);
4097
4098      uint16_t d = 0;
4099         d |= PACK(a, 0, 4);
4100         d |= PACK(r, 4, 4);
4101         d |= PACK(g, 8, 4);
4102         d |= PACK(b, 12, 4);
4103      (*(uint16_t *)dst) = d;
4104}
4105
4106static inline void
4107pack_uint_a1b5g5r5_uint(const GLuint src[4], void *dst)
4108{
4109
4110
4111      uint8_t a =
4112         _mesa_unsigned_to_unsigned(src[3], 1);
4113
4114
4115      uint8_t b =
4116         _mesa_unsigned_to_unsigned(src[2], 5);
4117
4118
4119      uint8_t g =
4120         _mesa_unsigned_to_unsigned(src[1], 5);
4121
4122
4123      uint8_t r =
4124         _mesa_unsigned_to_unsigned(src[0], 5);
4125
4126      uint16_t d = 0;
4127         d |= PACK(a, 0, 1);
4128         d |= PACK(b, 1, 5);
4129         d |= PACK(g, 6, 5);
4130         d |= PACK(r, 11, 5);
4131      (*(uint16_t *)dst) = d;
4132}
4133
4134static inline void
4135pack_uint_b5g5r5a1_uint(const GLuint src[4], void *dst)
4136{
4137
4138
4139      uint8_t b =
4140         _mesa_unsigned_to_unsigned(src[2], 5);
4141
4142
4143      uint8_t g =
4144         _mesa_unsigned_to_unsigned(src[1], 5);
4145
4146
4147      uint8_t r =
4148         _mesa_unsigned_to_unsigned(src[0], 5);
4149
4150
4151      uint8_t a =
4152         _mesa_unsigned_to_unsigned(src[3], 1);
4153
4154      uint16_t d = 0;
4155         d |= PACK(b, 0, 5);
4156         d |= PACK(g, 5, 5);
4157         d |= PACK(r, 10, 5);
4158         d |= PACK(a, 15, 1);
4159      (*(uint16_t *)dst) = d;
4160}
4161
4162static inline void
4163pack_uint_a1r5g5b5_uint(const GLuint src[4], void *dst)
4164{
4165
4166
4167      uint8_t a =
4168         _mesa_unsigned_to_unsigned(src[3], 1);
4169
4170
4171      uint8_t r =
4172         _mesa_unsigned_to_unsigned(src[0], 5);
4173
4174
4175      uint8_t g =
4176         _mesa_unsigned_to_unsigned(src[1], 5);
4177
4178
4179      uint8_t b =
4180         _mesa_unsigned_to_unsigned(src[2], 5);
4181
4182      uint16_t d = 0;
4183         d |= PACK(a, 0, 1);
4184         d |= PACK(r, 1, 5);
4185         d |= PACK(g, 6, 5);
4186         d |= PACK(b, 11, 5);
4187      (*(uint16_t *)dst) = d;
4188}
4189
4190static inline void
4191pack_uint_r5g5b5a1_uint(const GLuint src[4], void *dst)
4192{
4193
4194
4195      uint8_t r =
4196         _mesa_unsigned_to_unsigned(src[0], 5);
4197
4198
4199      uint8_t g =
4200         _mesa_unsigned_to_unsigned(src[1], 5);
4201
4202
4203      uint8_t b =
4204         _mesa_unsigned_to_unsigned(src[2], 5);
4205
4206
4207      uint8_t a =
4208         _mesa_unsigned_to_unsigned(src[3], 1);
4209
4210      uint16_t d = 0;
4211         d |= PACK(r, 0, 5);
4212         d |= PACK(g, 5, 5);
4213         d |= PACK(b, 10, 5);
4214         d |= PACK(a, 15, 1);
4215      (*(uint16_t *)dst) = d;
4216}
4217
4218static inline void
4219pack_uint_a_uint8(const GLuint src[4], void *dst)
4220{
4221
4222
4223      uint8_t a =
4224         _mesa_unsigned_to_unsigned(src[3], 8);
4225
4226      uint8_t *d = (uint8_t *)dst;
4227         d[0] = a;
4228}
4229
4230static inline void
4231pack_uint_a_uint16(const GLuint src[4], void *dst)
4232{
4233
4234
4235      uint16_t a =
4236         _mesa_unsigned_to_unsigned(src[3], 16);
4237
4238      uint16_t *d = (uint16_t *)dst;
4239         d[0] = a;
4240}
4241
4242static inline void
4243pack_uint_a_uint32(const GLuint src[4], void *dst)
4244{
4245
4246
4247      uint32_t a =
4248         _mesa_unsigned_to_unsigned(src[3], 32);
4249
4250      uint32_t *d = (uint32_t *)dst;
4251         d[0] = a;
4252}
4253
4254static inline void
4255pack_uint_a_sint8(const GLuint src[4], void *dst)
4256{
4257
4258
4259      int8_t a =
4260         _mesa_signed_to_signed(src[3], 8);
4261
4262      int8_t *d = (int8_t *)dst;
4263         d[0] = a;
4264}
4265
4266static inline void
4267pack_uint_a_sint16(const GLuint src[4], void *dst)
4268{
4269
4270
4271      int16_t a =
4272         _mesa_signed_to_signed(src[3], 16);
4273
4274      int16_t *d = (int16_t *)dst;
4275         d[0] = a;
4276}
4277
4278static inline void
4279pack_uint_a_sint32(const GLuint src[4], void *dst)
4280{
4281
4282
4283      int32_t a =
4284         _mesa_signed_to_signed(src[3], 32);
4285
4286      int32_t *d = (int32_t *)dst;
4287         d[0] = a;
4288}
4289
4290static inline void
4291pack_uint_i_uint8(const GLuint src[4], void *dst)
4292{
4293
4294
4295      uint8_t i =
4296         _mesa_unsigned_to_unsigned(src[0], 8);
4297
4298      uint8_t *d = (uint8_t *)dst;
4299         d[0] = i;
4300}
4301
4302static inline void
4303pack_uint_i_uint16(const GLuint src[4], void *dst)
4304{
4305
4306
4307      uint16_t i =
4308         _mesa_unsigned_to_unsigned(src[0], 16);
4309
4310      uint16_t *d = (uint16_t *)dst;
4311         d[0] = i;
4312}
4313
4314static inline void
4315pack_uint_i_uint32(const GLuint src[4], void *dst)
4316{
4317
4318
4319      uint32_t i =
4320         _mesa_unsigned_to_unsigned(src[0], 32);
4321
4322      uint32_t *d = (uint32_t *)dst;
4323         d[0] = i;
4324}
4325
4326static inline void
4327pack_uint_i_sint8(const GLuint src[4], void *dst)
4328{
4329
4330
4331      int8_t i =
4332         _mesa_signed_to_signed(src[0], 8);
4333
4334      int8_t *d = (int8_t *)dst;
4335         d[0] = i;
4336}
4337
4338static inline void
4339pack_uint_i_sint16(const GLuint src[4], void *dst)
4340{
4341
4342
4343      int16_t i =
4344         _mesa_signed_to_signed(src[0], 16);
4345
4346      int16_t *d = (int16_t *)dst;
4347         d[0] = i;
4348}
4349
4350static inline void
4351pack_uint_i_sint32(const GLuint src[4], void *dst)
4352{
4353
4354
4355      int32_t i =
4356         _mesa_signed_to_signed(src[0], 32);
4357
4358      int32_t *d = (int32_t *)dst;
4359         d[0] = i;
4360}
4361
4362static inline void
4363pack_uint_l_uint8(const GLuint src[4], void *dst)
4364{
4365
4366
4367      uint8_t l =
4368         _mesa_unsigned_to_unsigned(src[0], 8);
4369
4370      uint8_t *d = (uint8_t *)dst;
4371         d[0] = l;
4372}
4373
4374static inline void
4375pack_uint_l_uint16(const GLuint src[4], void *dst)
4376{
4377
4378
4379      uint16_t l =
4380         _mesa_unsigned_to_unsigned(src[0], 16);
4381
4382      uint16_t *d = (uint16_t *)dst;
4383         d[0] = l;
4384}
4385
4386static inline void
4387pack_uint_l_uint32(const GLuint src[4], void *dst)
4388{
4389
4390
4391      uint32_t l =
4392         _mesa_unsigned_to_unsigned(src[0], 32);
4393
4394      uint32_t *d = (uint32_t *)dst;
4395         d[0] = l;
4396}
4397
4398static inline void
4399pack_uint_l_sint8(const GLuint src[4], void *dst)
4400{
4401
4402
4403      int8_t l =
4404         _mesa_signed_to_signed(src[0], 8);
4405
4406      int8_t *d = (int8_t *)dst;
4407         d[0] = l;
4408}
4409
4410static inline void
4411pack_uint_l_sint16(const GLuint src[4], void *dst)
4412{
4413
4414
4415      int16_t l =
4416         _mesa_signed_to_signed(src[0], 16);
4417
4418      int16_t *d = (int16_t *)dst;
4419         d[0] = l;
4420}
4421
4422static inline void
4423pack_uint_l_sint32(const GLuint src[4], void *dst)
4424{
4425
4426
4427      int32_t l =
4428         _mesa_signed_to_signed(src[0], 32);
4429
4430      int32_t *d = (int32_t *)dst;
4431         d[0] = l;
4432}
4433
4434static inline void
4435pack_uint_la_uint8(const GLuint src[4], void *dst)
4436{
4437
4438
4439      uint8_t l =
4440         _mesa_unsigned_to_unsigned(src[0], 8);
4441
4442
4443      uint8_t a =
4444         _mesa_unsigned_to_unsigned(src[3], 8);
4445
4446      uint8_t *d = (uint8_t *)dst;
4447         d[0] = l;
4448         d[1] = a;
4449}
4450
4451static inline void
4452pack_uint_la_uint16(const GLuint src[4], void *dst)
4453{
4454
4455
4456      uint16_t l =
4457         _mesa_unsigned_to_unsigned(src[0], 16);
4458
4459
4460      uint16_t a =
4461         _mesa_unsigned_to_unsigned(src[3], 16);
4462
4463      uint16_t *d = (uint16_t *)dst;
4464         d[0] = l;
4465         d[1] = a;
4466}
4467
4468static inline void
4469pack_uint_la_uint32(const GLuint src[4], void *dst)
4470{
4471
4472
4473      uint32_t l =
4474         _mesa_unsigned_to_unsigned(src[0], 32);
4475
4476
4477      uint32_t a =
4478         _mesa_unsigned_to_unsigned(src[3], 32);
4479
4480      uint32_t *d = (uint32_t *)dst;
4481         d[0] = l;
4482         d[1] = a;
4483}
4484
4485static inline void
4486pack_uint_la_sint8(const GLuint src[4], void *dst)
4487{
4488
4489
4490      int8_t l =
4491         _mesa_signed_to_signed(src[0], 8);
4492
4493
4494      int8_t a =
4495         _mesa_signed_to_signed(src[3], 8);
4496
4497      int8_t *d = (int8_t *)dst;
4498         d[0] = l;
4499         d[1] = a;
4500}
4501
4502static inline void
4503pack_uint_la_sint16(const GLuint src[4], void *dst)
4504{
4505
4506
4507      int16_t l =
4508         _mesa_signed_to_signed(src[0], 16);
4509
4510
4511      int16_t a =
4512         _mesa_signed_to_signed(src[3], 16);
4513
4514      int16_t *d = (int16_t *)dst;
4515         d[0] = l;
4516         d[1] = a;
4517}
4518
4519static inline void
4520pack_uint_la_sint32(const GLuint src[4], void *dst)
4521{
4522
4523
4524      int32_t l =
4525         _mesa_signed_to_signed(src[0], 32);
4526
4527
4528      int32_t a =
4529         _mesa_signed_to_signed(src[3], 32);
4530
4531      int32_t *d = (int32_t *)dst;
4532         d[0] = l;
4533         d[1] = a;
4534}
4535
4536static inline void
4537pack_uint_r_uint8(const GLuint src[4], void *dst)
4538{
4539
4540
4541      uint8_t r =
4542         _mesa_unsigned_to_unsigned(src[0], 8);
4543
4544      uint8_t *d = (uint8_t *)dst;
4545         d[0] = r;
4546}
4547
4548static inline void
4549pack_uint_r_uint16(const GLuint src[4], void *dst)
4550{
4551
4552
4553      uint16_t r =
4554         _mesa_unsigned_to_unsigned(src[0], 16);
4555
4556      uint16_t *d = (uint16_t *)dst;
4557         d[0] = r;
4558}
4559
4560static inline void
4561pack_uint_r_uint32(const GLuint src[4], void *dst)
4562{
4563
4564
4565      uint32_t r =
4566         _mesa_unsigned_to_unsigned(src[0], 32);
4567
4568      uint32_t *d = (uint32_t *)dst;
4569         d[0] = r;
4570}
4571
4572static inline void
4573pack_uint_r_sint8(const GLuint src[4], void *dst)
4574{
4575
4576
4577      int8_t r =
4578         _mesa_signed_to_signed(src[0], 8);
4579
4580      int8_t *d = (int8_t *)dst;
4581         d[0] = r;
4582}
4583
4584static inline void
4585pack_uint_r_sint16(const GLuint src[4], void *dst)
4586{
4587
4588
4589      int16_t r =
4590         _mesa_signed_to_signed(src[0], 16);
4591
4592      int16_t *d = (int16_t *)dst;
4593         d[0] = r;
4594}
4595
4596static inline void
4597pack_uint_r_sint32(const GLuint src[4], void *dst)
4598{
4599
4600
4601      int32_t r =
4602         _mesa_signed_to_signed(src[0], 32);
4603
4604      int32_t *d = (int32_t *)dst;
4605         d[0] = r;
4606}
4607
4608static inline void
4609pack_uint_rg_uint8(const GLuint src[4], void *dst)
4610{
4611
4612
4613      uint8_t r =
4614         _mesa_unsigned_to_unsigned(src[0], 8);
4615
4616
4617      uint8_t g =
4618         _mesa_unsigned_to_unsigned(src[1], 8);
4619
4620      uint8_t *d = (uint8_t *)dst;
4621         d[0] = r;
4622         d[1] = g;
4623}
4624
4625static inline void
4626pack_uint_rg_uint16(const GLuint src[4], void *dst)
4627{
4628
4629
4630      uint16_t r =
4631         _mesa_unsigned_to_unsigned(src[0], 16);
4632
4633
4634      uint16_t g =
4635         _mesa_unsigned_to_unsigned(src[1], 16);
4636
4637      uint16_t *d = (uint16_t *)dst;
4638         d[0] = r;
4639         d[1] = g;
4640}
4641
4642static inline void
4643pack_uint_rg_uint32(const GLuint src[4], void *dst)
4644{
4645
4646
4647      uint32_t r =
4648         _mesa_unsigned_to_unsigned(src[0], 32);
4649
4650
4651      uint32_t g =
4652         _mesa_unsigned_to_unsigned(src[1], 32);
4653
4654      uint32_t *d = (uint32_t *)dst;
4655         d[0] = r;
4656         d[1] = g;
4657}
4658
4659static inline void
4660pack_uint_rg_sint8(const GLuint src[4], void *dst)
4661{
4662
4663
4664      int8_t r =
4665         _mesa_signed_to_signed(src[0], 8);
4666
4667
4668      int8_t g =
4669         _mesa_signed_to_signed(src[1], 8);
4670
4671      int8_t *d = (int8_t *)dst;
4672         d[0] = r;
4673         d[1] = g;
4674}
4675
4676static inline void
4677pack_uint_rg_sint16(const GLuint src[4], void *dst)
4678{
4679
4680
4681      int16_t r =
4682         _mesa_signed_to_signed(src[0], 16);
4683
4684
4685      int16_t g =
4686         _mesa_signed_to_signed(src[1], 16);
4687
4688      int16_t *d = (int16_t *)dst;
4689         d[0] = r;
4690         d[1] = g;
4691}
4692
4693static inline void
4694pack_uint_rg_sint32(const GLuint src[4], void *dst)
4695{
4696
4697
4698      int32_t r =
4699         _mesa_signed_to_signed(src[0], 32);
4700
4701
4702      int32_t g =
4703         _mesa_signed_to_signed(src[1], 32);
4704
4705      int32_t *d = (int32_t *)dst;
4706         d[0] = r;
4707         d[1] = g;
4708}
4709
4710static inline void
4711pack_uint_rgb_uint8(const GLuint src[4], void *dst)
4712{
4713
4714
4715      uint8_t r =
4716         _mesa_unsigned_to_unsigned(src[0], 8);
4717
4718
4719      uint8_t g =
4720         _mesa_unsigned_to_unsigned(src[1], 8);
4721
4722
4723      uint8_t b =
4724         _mesa_unsigned_to_unsigned(src[2], 8);
4725
4726      uint8_t *d = (uint8_t *)dst;
4727         d[0] = r;
4728         d[1] = g;
4729         d[2] = b;
4730}
4731
4732static inline void
4733pack_uint_rgb_uint16(const GLuint src[4], void *dst)
4734{
4735
4736
4737      uint16_t r =
4738         _mesa_unsigned_to_unsigned(src[0], 16);
4739
4740
4741      uint16_t g =
4742         _mesa_unsigned_to_unsigned(src[1], 16);
4743
4744
4745      uint16_t b =
4746         _mesa_unsigned_to_unsigned(src[2], 16);
4747
4748      uint16_t *d = (uint16_t *)dst;
4749         d[0] = r;
4750         d[1] = g;
4751         d[2] = b;
4752}
4753
4754static inline void
4755pack_uint_rgb_uint32(const GLuint src[4], void *dst)
4756{
4757
4758
4759      uint32_t r =
4760         _mesa_unsigned_to_unsigned(src[0], 32);
4761
4762
4763      uint32_t g =
4764         _mesa_unsigned_to_unsigned(src[1], 32);
4765
4766
4767      uint32_t b =
4768         _mesa_unsigned_to_unsigned(src[2], 32);
4769
4770      uint32_t *d = (uint32_t *)dst;
4771         d[0] = r;
4772         d[1] = g;
4773         d[2] = b;
4774}
4775
4776static inline void
4777pack_uint_rgb_sint8(const GLuint src[4], void *dst)
4778{
4779
4780
4781      int8_t r =
4782         _mesa_signed_to_signed(src[0], 8);
4783
4784
4785      int8_t g =
4786         _mesa_signed_to_signed(src[1], 8);
4787
4788
4789      int8_t b =
4790         _mesa_signed_to_signed(src[2], 8);
4791
4792      int8_t *d = (int8_t *)dst;
4793         d[0] = r;
4794         d[1] = g;
4795         d[2] = b;
4796}
4797
4798static inline void
4799pack_uint_rgb_sint16(const GLuint src[4], void *dst)
4800{
4801
4802
4803      int16_t r =
4804         _mesa_signed_to_signed(src[0], 16);
4805
4806
4807      int16_t g =
4808         _mesa_signed_to_signed(src[1], 16);
4809
4810
4811      int16_t b =
4812         _mesa_signed_to_signed(src[2], 16);
4813
4814      int16_t *d = (int16_t *)dst;
4815         d[0] = r;
4816         d[1] = g;
4817         d[2] = b;
4818}
4819
4820static inline void
4821pack_uint_rgb_sint32(const GLuint src[4], void *dst)
4822{
4823
4824
4825      int32_t r =
4826         _mesa_signed_to_signed(src[0], 32);
4827
4828
4829      int32_t g =
4830         _mesa_signed_to_signed(src[1], 32);
4831
4832
4833      int32_t b =
4834         _mesa_signed_to_signed(src[2], 32);
4835
4836      int32_t *d = (int32_t *)dst;
4837         d[0] = r;
4838         d[1] = g;
4839         d[2] = b;
4840}
4841
4842static inline void
4843pack_uint_rgba_uint8(const GLuint src[4], void *dst)
4844{
4845
4846
4847      uint8_t r =
4848         _mesa_unsigned_to_unsigned(src[0], 8);
4849
4850
4851      uint8_t g =
4852         _mesa_unsigned_to_unsigned(src[1], 8);
4853
4854
4855      uint8_t b =
4856         _mesa_unsigned_to_unsigned(src[2], 8);
4857
4858
4859      uint8_t a =
4860         _mesa_unsigned_to_unsigned(src[3], 8);
4861
4862      uint8_t *d = (uint8_t *)dst;
4863         d[0] = r;
4864         d[1] = g;
4865         d[2] = b;
4866         d[3] = a;
4867}
4868
4869static inline void
4870pack_uint_rgba_uint16(const GLuint src[4], void *dst)
4871{
4872
4873
4874      uint16_t r =
4875         _mesa_unsigned_to_unsigned(src[0], 16);
4876
4877
4878      uint16_t g =
4879         _mesa_unsigned_to_unsigned(src[1], 16);
4880
4881
4882      uint16_t b =
4883         _mesa_unsigned_to_unsigned(src[2], 16);
4884
4885
4886      uint16_t a =
4887         _mesa_unsigned_to_unsigned(src[3], 16);
4888
4889      uint16_t *d = (uint16_t *)dst;
4890         d[0] = r;
4891         d[1] = g;
4892         d[2] = b;
4893         d[3] = a;
4894}
4895
4896static inline void
4897pack_uint_rgba_uint32(const GLuint src[4], void *dst)
4898{
4899
4900
4901      uint32_t r =
4902         _mesa_unsigned_to_unsigned(src[0], 32);
4903
4904
4905      uint32_t g =
4906         _mesa_unsigned_to_unsigned(src[1], 32);
4907
4908
4909      uint32_t b =
4910         _mesa_unsigned_to_unsigned(src[2], 32);
4911
4912
4913      uint32_t a =
4914         _mesa_unsigned_to_unsigned(src[3], 32);
4915
4916      uint32_t *d = (uint32_t *)dst;
4917         d[0] = r;
4918         d[1] = g;
4919         d[2] = b;
4920         d[3] = a;
4921}
4922
4923static inline void
4924pack_uint_rgba_sint8(const GLuint src[4], void *dst)
4925{
4926
4927
4928      int8_t r =
4929         _mesa_signed_to_signed(src[0], 8);
4930
4931
4932      int8_t g =
4933         _mesa_signed_to_signed(src[1], 8);
4934
4935
4936      int8_t b =
4937         _mesa_signed_to_signed(src[2], 8);
4938
4939
4940      int8_t a =
4941         _mesa_signed_to_signed(src[3], 8);
4942
4943      int8_t *d = (int8_t *)dst;
4944         d[0] = r;
4945         d[1] = g;
4946         d[2] = b;
4947         d[3] = a;
4948}
4949
4950static inline void
4951pack_uint_rgba_sint16(const GLuint src[4], void *dst)
4952{
4953
4954
4955      int16_t r =
4956         _mesa_signed_to_signed(src[0], 16);
4957
4958
4959      int16_t g =
4960         _mesa_signed_to_signed(src[1], 16);
4961
4962
4963      int16_t b =
4964         _mesa_signed_to_signed(src[2], 16);
4965
4966
4967      int16_t a =
4968         _mesa_signed_to_signed(src[3], 16);
4969
4970      int16_t *d = (int16_t *)dst;
4971         d[0] = r;
4972         d[1] = g;
4973         d[2] = b;
4974         d[3] = a;
4975}
4976
4977static inline void
4978pack_uint_rgba_sint32(const GLuint src[4], void *dst)
4979{
4980
4981
4982      int32_t r =
4983         _mesa_signed_to_signed(src[0], 32);
4984
4985
4986      int32_t g =
4987         _mesa_signed_to_signed(src[1], 32);
4988
4989
4990      int32_t b =
4991         _mesa_signed_to_signed(src[2], 32);
4992
4993
4994      int32_t a =
4995         _mesa_signed_to_signed(src[3], 32);
4996
4997      int32_t *d = (int32_t *)dst;
4998         d[0] = r;
4999         d[1] = g;
5000         d[2] = b;
5001         d[3] = a;
5002}
5003
5004static inline void
5005pack_uint_rgbx_uint8(const GLuint src[4], void *dst)
5006{
5007
5008
5009      uint8_t r =
5010         _mesa_unsigned_to_unsigned(src[0], 8);
5011
5012
5013      uint8_t g =
5014         _mesa_unsigned_to_unsigned(src[1], 8);
5015
5016
5017      uint8_t b =
5018         _mesa_unsigned_to_unsigned(src[2], 8);
5019
5020
5021      uint8_t *d = (uint8_t *)dst;
5022         d[0] = r;
5023         d[1] = g;
5024         d[2] = b;
5025            }
5026
5027static inline void
5028pack_uint_rgbx_uint16(const GLuint src[4], void *dst)
5029{
5030
5031
5032      uint16_t r =
5033         _mesa_unsigned_to_unsigned(src[0], 16);
5034
5035
5036      uint16_t g =
5037         _mesa_unsigned_to_unsigned(src[1], 16);
5038
5039
5040      uint16_t b =
5041         _mesa_unsigned_to_unsigned(src[2], 16);
5042
5043
5044      uint16_t *d = (uint16_t *)dst;
5045         d[0] = r;
5046         d[1] = g;
5047         d[2] = b;
5048            }
5049
5050static inline void
5051pack_uint_rgbx_uint32(const GLuint src[4], void *dst)
5052{
5053
5054
5055      uint32_t r =
5056         _mesa_unsigned_to_unsigned(src[0], 32);
5057
5058
5059      uint32_t g =
5060         _mesa_unsigned_to_unsigned(src[1], 32);
5061
5062
5063      uint32_t b =
5064         _mesa_unsigned_to_unsigned(src[2], 32);
5065
5066
5067      uint32_t *d = (uint32_t *)dst;
5068         d[0] = r;
5069         d[1] = g;
5070         d[2] = b;
5071            }
5072
5073static inline void
5074pack_uint_rgbx_sint8(const GLuint src[4], void *dst)
5075{
5076
5077
5078      int8_t r =
5079         _mesa_signed_to_signed(src[0], 8);
5080
5081
5082      int8_t g =
5083         _mesa_signed_to_signed(src[1], 8);
5084
5085
5086      int8_t b =
5087         _mesa_signed_to_signed(src[2], 8);
5088
5089
5090      int8_t *d = (int8_t *)dst;
5091         d[0] = r;
5092         d[1] = g;
5093         d[2] = b;
5094            }
5095
5096static inline void
5097pack_uint_rgbx_sint16(const GLuint src[4], void *dst)
5098{
5099
5100
5101      int16_t r =
5102         _mesa_signed_to_signed(src[0], 16);
5103
5104
5105      int16_t g =
5106         _mesa_signed_to_signed(src[1], 16);
5107
5108
5109      int16_t b =
5110         _mesa_signed_to_signed(src[2], 16);
5111
5112
5113      int16_t *d = (int16_t *)dst;
5114         d[0] = r;
5115         d[1] = g;
5116         d[2] = b;
5117            }
5118
5119static inline void
5120pack_uint_rgbx_sint32(const GLuint src[4], void *dst)
5121{
5122
5123
5124      int32_t r =
5125         _mesa_signed_to_signed(src[0], 32);
5126
5127
5128      int32_t g =
5129         _mesa_signed_to_signed(src[1], 32);
5130
5131
5132      int32_t b =
5133         _mesa_signed_to_signed(src[2], 32);
5134
5135
5136      int32_t *d = (int32_t *)dst;
5137         d[0] = r;
5138         d[1] = g;
5139         d[2] = b;
5140            }
5141
5142/* float packing functions */
5143
5144
5145static inline void
5146pack_float_a8b8g8r8_unorm(const GLfloat src[4], void *dst)
5147{
5148
5149
5150      uint8_t a =
5151            _mesa_float_to_unorm(src[3], 8);
5152
5153
5154      uint8_t b =
5155            _mesa_float_to_unorm(src[2], 8);
5156
5157
5158      uint8_t g =
5159            _mesa_float_to_unorm(src[1], 8);
5160
5161
5162      uint8_t r =
5163            _mesa_float_to_unorm(src[0], 8);
5164
5165      uint32_t d = 0;
5166         d |= PACK(a, 0, 8);
5167         d |= PACK(b, 8, 8);
5168         d |= PACK(g, 16, 8);
5169         d |= PACK(r, 24, 8);
5170      (*(uint32_t *)dst) = d;
5171}
5172
5173static inline void
5174pack_float_x8b8g8r8_unorm(const GLfloat src[4], void *dst)
5175{
5176
5177
5178
5179      uint8_t b =
5180            _mesa_float_to_unorm(src[2], 8);
5181
5182
5183      uint8_t g =
5184            _mesa_float_to_unorm(src[1], 8);
5185
5186
5187      uint8_t r =
5188            _mesa_float_to_unorm(src[0], 8);
5189
5190      uint32_t d = 0;
5191                     d |= PACK(b, 8, 8);
5192         d |= PACK(g, 16, 8);
5193         d |= PACK(r, 24, 8);
5194      (*(uint32_t *)dst) = d;
5195}
5196
5197static inline void
5198pack_float_r8g8b8a8_unorm(const GLfloat src[4], void *dst)
5199{
5200
5201
5202      uint8_t r =
5203            _mesa_float_to_unorm(src[0], 8);
5204
5205
5206      uint8_t g =
5207            _mesa_float_to_unorm(src[1], 8);
5208
5209
5210      uint8_t b =
5211            _mesa_float_to_unorm(src[2], 8);
5212
5213
5214      uint8_t a =
5215            _mesa_float_to_unorm(src[3], 8);
5216
5217      uint32_t d = 0;
5218         d |= PACK(r, 0, 8);
5219         d |= PACK(g, 8, 8);
5220         d |= PACK(b, 16, 8);
5221         d |= PACK(a, 24, 8);
5222      (*(uint32_t *)dst) = d;
5223}
5224
5225static inline void
5226pack_float_r8g8b8x8_unorm(const GLfloat src[4], void *dst)
5227{
5228
5229
5230      uint8_t r =
5231            _mesa_float_to_unorm(src[0], 8);
5232
5233
5234      uint8_t g =
5235            _mesa_float_to_unorm(src[1], 8);
5236
5237
5238      uint8_t b =
5239            _mesa_float_to_unorm(src[2], 8);
5240
5241
5242      uint32_t d = 0;
5243         d |= PACK(r, 0, 8);
5244         d |= PACK(g, 8, 8);
5245         d |= PACK(b, 16, 8);
5246                  (*(uint32_t *)dst) = d;
5247}
5248
5249static inline void
5250pack_float_b8g8r8a8_unorm(const GLfloat src[4], void *dst)
5251{
5252
5253
5254      uint8_t b =
5255            _mesa_float_to_unorm(src[2], 8);
5256
5257
5258      uint8_t g =
5259            _mesa_float_to_unorm(src[1], 8);
5260
5261
5262      uint8_t r =
5263            _mesa_float_to_unorm(src[0], 8);
5264
5265
5266      uint8_t a =
5267            _mesa_float_to_unorm(src[3], 8);
5268
5269      uint32_t d = 0;
5270         d |= PACK(b, 0, 8);
5271         d |= PACK(g, 8, 8);
5272         d |= PACK(r, 16, 8);
5273         d |= PACK(a, 24, 8);
5274      (*(uint32_t *)dst) = d;
5275}
5276
5277static inline void
5278pack_float_b8g8r8x8_unorm(const GLfloat src[4], void *dst)
5279{
5280
5281
5282      uint8_t b =
5283            _mesa_float_to_unorm(src[2], 8);
5284
5285
5286      uint8_t g =
5287            _mesa_float_to_unorm(src[1], 8);
5288
5289
5290      uint8_t r =
5291            _mesa_float_to_unorm(src[0], 8);
5292
5293
5294      uint32_t d = 0;
5295         d |= PACK(b, 0, 8);
5296         d |= PACK(g, 8, 8);
5297         d |= PACK(r, 16, 8);
5298                  (*(uint32_t *)dst) = d;
5299}
5300
5301static inline void
5302pack_float_a8r8g8b8_unorm(const GLfloat src[4], void *dst)
5303{
5304
5305
5306      uint8_t a =
5307            _mesa_float_to_unorm(src[3], 8);
5308
5309
5310      uint8_t r =
5311            _mesa_float_to_unorm(src[0], 8);
5312
5313
5314      uint8_t g =
5315            _mesa_float_to_unorm(src[1], 8);
5316
5317
5318      uint8_t b =
5319            _mesa_float_to_unorm(src[2], 8);
5320
5321      uint32_t d = 0;
5322         d |= PACK(a, 0, 8);
5323         d |= PACK(r, 8, 8);
5324         d |= PACK(g, 16, 8);
5325         d |= PACK(b, 24, 8);
5326      (*(uint32_t *)dst) = d;
5327}
5328
5329static inline void
5330pack_float_x8r8g8b8_unorm(const GLfloat src[4], void *dst)
5331{
5332
5333
5334
5335      uint8_t r =
5336            _mesa_float_to_unorm(src[0], 8);
5337
5338
5339      uint8_t g =
5340            _mesa_float_to_unorm(src[1], 8);
5341
5342
5343      uint8_t b =
5344            _mesa_float_to_unorm(src[2], 8);
5345
5346      uint32_t d = 0;
5347                     d |= PACK(r, 8, 8);
5348         d |= PACK(g, 16, 8);
5349         d |= PACK(b, 24, 8);
5350      (*(uint32_t *)dst) = d;
5351}
5352
5353static inline void
5354pack_float_l16a16_unorm(const GLfloat src[4], void *dst)
5355{
5356
5357
5358      uint16_t l =
5359            _mesa_float_to_unorm(src[0], 16);
5360
5361
5362      uint16_t a =
5363            _mesa_float_to_unorm(src[3], 16);
5364
5365      uint32_t d = 0;
5366         d |= PACK(l, 0, 16);
5367         d |= PACK(a, 16, 16);
5368      (*(uint32_t *)dst) = d;
5369}
5370
5371static inline void
5372pack_float_a16l16_unorm(const GLfloat src[4], void *dst)
5373{
5374
5375
5376      uint16_t a =
5377            _mesa_float_to_unorm(src[3], 16);
5378
5379
5380      uint16_t l =
5381            _mesa_float_to_unorm(src[0], 16);
5382
5383      uint32_t d = 0;
5384         d |= PACK(a, 0, 16);
5385         d |= PACK(l, 16, 16);
5386      (*(uint32_t *)dst) = d;
5387}
5388
5389static inline void
5390pack_float_b5g6r5_unorm(const GLfloat src[4], void *dst)
5391{
5392
5393
5394      uint8_t b =
5395            _mesa_float_to_unorm(src[2], 5);
5396
5397
5398      uint8_t g =
5399            _mesa_float_to_unorm(src[1], 6);
5400
5401
5402      uint8_t r =
5403            _mesa_float_to_unorm(src[0], 5);
5404
5405      uint16_t d = 0;
5406         d |= PACK(b, 0, 5);
5407         d |= PACK(g, 5, 6);
5408         d |= PACK(r, 11, 5);
5409      (*(uint16_t *)dst) = d;
5410}
5411
5412static inline void
5413pack_float_r5g6b5_unorm(const GLfloat src[4], void *dst)
5414{
5415
5416
5417      uint8_t r =
5418            _mesa_float_to_unorm(src[0], 5);
5419
5420
5421      uint8_t g =
5422            _mesa_float_to_unorm(src[1], 6);
5423
5424
5425      uint8_t b =
5426            _mesa_float_to_unorm(src[2], 5);
5427
5428      uint16_t d = 0;
5429         d |= PACK(r, 0, 5);
5430         d |= PACK(g, 5, 6);
5431         d |= PACK(b, 11, 5);
5432      (*(uint16_t *)dst) = d;
5433}
5434
5435static inline void
5436pack_float_b4g4r4a4_unorm(const GLfloat src[4], void *dst)
5437{
5438
5439
5440      uint8_t b =
5441            _mesa_float_to_unorm(src[2], 4);
5442
5443
5444      uint8_t g =
5445            _mesa_float_to_unorm(src[1], 4);
5446
5447
5448      uint8_t r =
5449            _mesa_float_to_unorm(src[0], 4);
5450
5451
5452      uint8_t a =
5453            _mesa_float_to_unorm(src[3], 4);
5454
5455      uint16_t d = 0;
5456         d |= PACK(b, 0, 4);
5457         d |= PACK(g, 4, 4);
5458         d |= PACK(r, 8, 4);
5459         d |= PACK(a, 12, 4);
5460      (*(uint16_t *)dst) = d;
5461}
5462
5463static inline void
5464pack_float_b4g4r4x4_unorm(const GLfloat src[4], void *dst)
5465{
5466
5467
5468      uint8_t b =
5469            _mesa_float_to_unorm(src[2], 4);
5470
5471
5472      uint8_t g =
5473            _mesa_float_to_unorm(src[1], 4);
5474
5475
5476      uint8_t r =
5477            _mesa_float_to_unorm(src[0], 4);
5478
5479
5480      uint16_t d = 0;
5481         d |= PACK(b, 0, 4);
5482         d |= PACK(g, 4, 4);
5483         d |= PACK(r, 8, 4);
5484                  (*(uint16_t *)dst) = d;
5485}
5486
5487static inline void
5488pack_float_a4r4g4b4_unorm(const GLfloat src[4], void *dst)
5489{
5490
5491
5492      uint8_t a =
5493            _mesa_float_to_unorm(src[3], 4);
5494
5495
5496      uint8_t r =
5497            _mesa_float_to_unorm(src[0], 4);
5498
5499
5500      uint8_t g =
5501            _mesa_float_to_unorm(src[1], 4);
5502
5503
5504      uint8_t b =
5505            _mesa_float_to_unorm(src[2], 4);
5506
5507      uint16_t d = 0;
5508         d |= PACK(a, 0, 4);
5509         d |= PACK(r, 4, 4);
5510         d |= PACK(g, 8, 4);
5511         d |= PACK(b, 12, 4);
5512      (*(uint16_t *)dst) = d;
5513}
5514
5515static inline void
5516pack_float_a1b5g5r5_unorm(const GLfloat src[4], void *dst)
5517{
5518
5519
5520      uint8_t a =
5521            _mesa_float_to_unorm(src[3], 1);
5522
5523
5524      uint8_t b =
5525            _mesa_float_to_unorm(src[2], 5);
5526
5527
5528      uint8_t g =
5529            _mesa_float_to_unorm(src[1], 5);
5530
5531
5532      uint8_t r =
5533            _mesa_float_to_unorm(src[0], 5);
5534
5535      uint16_t d = 0;
5536         d |= PACK(a, 0, 1);
5537         d |= PACK(b, 1, 5);
5538         d |= PACK(g, 6, 5);
5539         d |= PACK(r, 11, 5);
5540      (*(uint16_t *)dst) = d;
5541}
5542
5543static inline void
5544pack_float_x1b5g5r5_unorm(const GLfloat src[4], void *dst)
5545{
5546
5547
5548
5549      uint8_t b =
5550            _mesa_float_to_unorm(src[2], 5);
5551
5552
5553      uint8_t g =
5554            _mesa_float_to_unorm(src[1], 5);
5555
5556
5557      uint8_t r =
5558            _mesa_float_to_unorm(src[0], 5);
5559
5560      uint16_t d = 0;
5561                     d |= PACK(b, 1, 5);
5562         d |= PACK(g, 6, 5);
5563         d |= PACK(r, 11, 5);
5564      (*(uint16_t *)dst) = d;
5565}
5566
5567static inline void
5568pack_float_b5g5r5a1_unorm(const GLfloat src[4], void *dst)
5569{
5570
5571
5572      uint8_t b =
5573            _mesa_float_to_unorm(src[2], 5);
5574
5575
5576      uint8_t g =
5577            _mesa_float_to_unorm(src[1], 5);
5578
5579
5580      uint8_t r =
5581            _mesa_float_to_unorm(src[0], 5);
5582
5583
5584      uint8_t a =
5585            _mesa_float_to_unorm(src[3], 1);
5586
5587      uint16_t d = 0;
5588         d |= PACK(b, 0, 5);
5589         d |= PACK(g, 5, 5);
5590         d |= PACK(r, 10, 5);
5591         d |= PACK(a, 15, 1);
5592      (*(uint16_t *)dst) = d;
5593}
5594
5595static inline void
5596pack_float_b5g5r5x1_unorm(const GLfloat src[4], void *dst)
5597{
5598
5599
5600      uint8_t b =
5601            _mesa_float_to_unorm(src[2], 5);
5602
5603
5604      uint8_t g =
5605            _mesa_float_to_unorm(src[1], 5);
5606
5607
5608      uint8_t r =
5609            _mesa_float_to_unorm(src[0], 5);
5610
5611
5612      uint16_t d = 0;
5613         d |= PACK(b, 0, 5);
5614         d |= PACK(g, 5, 5);
5615         d |= PACK(r, 10, 5);
5616                  (*(uint16_t *)dst) = d;
5617}
5618
5619static inline void
5620pack_float_a1r5g5b5_unorm(const GLfloat src[4], void *dst)
5621{
5622
5623
5624      uint8_t a =
5625            _mesa_float_to_unorm(src[3], 1);
5626
5627
5628      uint8_t r =
5629            _mesa_float_to_unorm(src[0], 5);
5630
5631
5632      uint8_t g =
5633            _mesa_float_to_unorm(src[1], 5);
5634
5635
5636      uint8_t b =
5637            _mesa_float_to_unorm(src[2], 5);
5638
5639      uint16_t d = 0;
5640         d |= PACK(a, 0, 1);
5641         d |= PACK(r, 1, 5);
5642         d |= PACK(g, 6, 5);
5643         d |= PACK(b, 11, 5);
5644      (*(uint16_t *)dst) = d;
5645}
5646
5647static inline void
5648pack_float_l8a8_unorm(const GLfloat src[4], void *dst)
5649{
5650
5651
5652      uint8_t l =
5653            _mesa_float_to_unorm(src[0], 8);
5654
5655
5656      uint8_t a =
5657            _mesa_float_to_unorm(src[3], 8);
5658
5659      uint16_t d = 0;
5660         d |= PACK(l, 0, 8);
5661         d |= PACK(a, 8, 8);
5662      (*(uint16_t *)dst) = d;
5663}
5664
5665static inline void
5666pack_float_a8l8_unorm(const GLfloat src[4], void *dst)
5667{
5668
5669
5670      uint8_t a =
5671            _mesa_float_to_unorm(src[3], 8);
5672
5673
5674      uint8_t l =
5675            _mesa_float_to_unorm(src[0], 8);
5676
5677      uint16_t d = 0;
5678         d |= PACK(a, 0, 8);
5679         d |= PACK(l, 8, 8);
5680      (*(uint16_t *)dst) = d;
5681}
5682
5683static inline void
5684pack_float_r8g8_unorm(const GLfloat src[4], void *dst)
5685{
5686
5687
5688      uint8_t r =
5689            _mesa_float_to_unorm(src[0], 8);
5690
5691
5692      uint8_t g =
5693            _mesa_float_to_unorm(src[1], 8);
5694
5695      uint16_t d = 0;
5696         d |= PACK(r, 0, 8);
5697         d |= PACK(g, 8, 8);
5698      (*(uint16_t *)dst) = d;
5699}
5700
5701static inline void
5702pack_float_g8r8_unorm(const GLfloat src[4], void *dst)
5703{
5704
5705
5706      uint8_t g =
5707            _mesa_float_to_unorm(src[1], 8);
5708
5709
5710      uint8_t r =
5711            _mesa_float_to_unorm(src[0], 8);
5712
5713      uint16_t d = 0;
5714         d |= PACK(g, 0, 8);
5715         d |= PACK(r, 8, 8);
5716      (*(uint16_t *)dst) = d;
5717}
5718
5719static inline void
5720pack_float_l4a4_unorm(const GLfloat src[4], void *dst)
5721{
5722
5723
5724      uint8_t l =
5725            _mesa_float_to_unorm(src[0], 4);
5726
5727
5728      uint8_t a =
5729            _mesa_float_to_unorm(src[3], 4);
5730
5731      uint8_t d = 0;
5732         d |= PACK(l, 0, 4);
5733         d |= PACK(a, 4, 4);
5734      (*(uint8_t *)dst) = d;
5735}
5736
5737static inline void
5738pack_float_b2g3r3_unorm(const GLfloat src[4], void *dst)
5739{
5740
5741
5742      uint8_t b =
5743            _mesa_float_to_unorm(src[2], 2);
5744
5745
5746      uint8_t g =
5747            _mesa_float_to_unorm(src[1], 3);
5748
5749
5750      uint8_t r =
5751            _mesa_float_to_unorm(src[0], 3);
5752
5753      uint8_t d = 0;
5754         d |= PACK(b, 0, 2);
5755         d |= PACK(g, 2, 3);
5756         d |= PACK(r, 5, 3);
5757      (*(uint8_t *)dst) = d;
5758}
5759
5760static inline void
5761pack_float_r16g16_unorm(const GLfloat src[4], void *dst)
5762{
5763
5764
5765      uint16_t r =
5766            _mesa_float_to_unorm(src[0], 16);
5767
5768
5769      uint16_t g =
5770            _mesa_float_to_unorm(src[1], 16);
5771
5772      uint32_t d = 0;
5773         d |= PACK(r, 0, 16);
5774         d |= PACK(g, 16, 16);
5775      (*(uint32_t *)dst) = d;
5776}
5777
5778static inline void
5779pack_float_g16r16_unorm(const GLfloat src[4], void *dst)
5780{
5781
5782
5783      uint16_t g =
5784            _mesa_float_to_unorm(src[1], 16);
5785
5786
5787      uint16_t r =
5788            _mesa_float_to_unorm(src[0], 16);
5789
5790      uint32_t d = 0;
5791         d |= PACK(g, 0, 16);
5792         d |= PACK(r, 16, 16);
5793      (*(uint32_t *)dst) = d;
5794}
5795
5796static inline void
5797pack_float_b10g10r10a2_unorm(const GLfloat src[4], void *dst)
5798{
5799
5800
5801      uint16_t b =
5802            _mesa_float_to_unorm(src[2], 10);
5803
5804
5805      uint16_t g =
5806            _mesa_float_to_unorm(src[1], 10);
5807
5808
5809      uint16_t r =
5810            _mesa_float_to_unorm(src[0], 10);
5811
5812
5813      uint8_t a =
5814            _mesa_float_to_unorm(src[3], 2);
5815
5816      uint32_t d = 0;
5817         d |= PACK(b, 0, 10);
5818         d |= PACK(g, 10, 10);
5819         d |= PACK(r, 20, 10);
5820         d |= PACK(a, 30, 2);
5821      (*(uint32_t *)dst) = d;
5822}
5823
5824static inline void
5825pack_float_b10g10r10x2_unorm(const GLfloat src[4], void *dst)
5826{
5827
5828
5829      uint16_t b =
5830            _mesa_float_to_unorm(src[2], 10);
5831
5832
5833      uint16_t g =
5834            _mesa_float_to_unorm(src[1], 10);
5835
5836
5837      uint16_t r =
5838            _mesa_float_to_unorm(src[0], 10);
5839
5840
5841      uint32_t d = 0;
5842         d |= PACK(b, 0, 10);
5843         d |= PACK(g, 10, 10);
5844         d |= PACK(r, 20, 10);
5845                  (*(uint32_t *)dst) = d;
5846}
5847
5848static inline void
5849pack_float_r10g10b10a2_unorm(const GLfloat src[4], void *dst)
5850{
5851
5852
5853      uint16_t r =
5854            _mesa_float_to_unorm(src[0], 10);
5855
5856
5857      uint16_t g =
5858            _mesa_float_to_unorm(src[1], 10);
5859
5860
5861      uint16_t b =
5862            _mesa_float_to_unorm(src[2], 10);
5863
5864
5865      uint8_t a =
5866            _mesa_float_to_unorm(src[3], 2);
5867
5868      uint32_t d = 0;
5869         d |= PACK(r, 0, 10);
5870         d |= PACK(g, 10, 10);
5871         d |= PACK(b, 20, 10);
5872         d |= PACK(a, 30, 2);
5873      (*(uint32_t *)dst) = d;
5874}
5875
5876static inline void
5877pack_float_r10g10b10x2_unorm(const GLfloat src[4], void *dst)
5878{
5879
5880
5881      uint16_t r =
5882            _mesa_float_to_unorm(src[0], 10);
5883
5884
5885      uint16_t g =
5886            _mesa_float_to_unorm(src[1], 10);
5887
5888
5889      uint16_t b =
5890            _mesa_float_to_unorm(src[2], 10);
5891
5892
5893      uint32_t d = 0;
5894         d |= PACK(r, 0, 10);
5895         d |= PACK(g, 10, 10);
5896         d |= PACK(b, 20, 10);
5897                  (*(uint32_t *)dst) = d;
5898}
5899
5900static inline void
5901pack_float_r3g3b2_unorm(const GLfloat src[4], void *dst)
5902{
5903
5904
5905      uint8_t r =
5906            _mesa_float_to_unorm(src[0], 3);
5907
5908
5909      uint8_t g =
5910            _mesa_float_to_unorm(src[1], 3);
5911
5912
5913      uint8_t b =
5914            _mesa_float_to_unorm(src[2], 2);
5915
5916      uint8_t d = 0;
5917         d |= PACK(r, 0, 3);
5918         d |= PACK(g, 3, 3);
5919         d |= PACK(b, 6, 2);
5920      (*(uint8_t *)dst) = d;
5921}
5922
5923static inline void
5924pack_float_a4b4g4r4_unorm(const GLfloat src[4], void *dst)
5925{
5926
5927
5928      uint8_t a =
5929            _mesa_float_to_unorm(src[3], 4);
5930
5931
5932      uint8_t b =
5933            _mesa_float_to_unorm(src[2], 4);
5934
5935
5936      uint8_t g =
5937            _mesa_float_to_unorm(src[1], 4);
5938
5939
5940      uint8_t r =
5941            _mesa_float_to_unorm(src[0], 4);
5942
5943      uint16_t d = 0;
5944         d |= PACK(a, 0, 4);
5945         d |= PACK(b, 4, 4);
5946         d |= PACK(g, 8, 4);
5947         d |= PACK(r, 12, 4);
5948      (*(uint16_t *)dst) = d;
5949}
5950
5951static inline void
5952pack_float_r4g4b4a4_unorm(const GLfloat src[4], void *dst)
5953{
5954
5955
5956      uint8_t r =
5957            _mesa_float_to_unorm(src[0], 4);
5958
5959
5960      uint8_t g =
5961            _mesa_float_to_unorm(src[1], 4);
5962
5963
5964      uint8_t b =
5965            _mesa_float_to_unorm(src[2], 4);
5966
5967
5968      uint8_t a =
5969            _mesa_float_to_unorm(src[3], 4);
5970
5971      uint16_t d = 0;
5972         d |= PACK(r, 0, 4);
5973         d |= PACK(g, 4, 4);
5974         d |= PACK(b, 8, 4);
5975         d |= PACK(a, 12, 4);
5976      (*(uint16_t *)dst) = d;
5977}
5978
5979static inline void
5980pack_float_r5g5b5a1_unorm(const GLfloat src[4], void *dst)
5981{
5982
5983
5984      uint8_t r =
5985            _mesa_float_to_unorm(src[0], 5);
5986
5987
5988      uint8_t g =
5989            _mesa_float_to_unorm(src[1], 5);
5990
5991
5992      uint8_t b =
5993            _mesa_float_to_unorm(src[2], 5);
5994
5995
5996      uint8_t a =
5997            _mesa_float_to_unorm(src[3], 1);
5998
5999      uint16_t d = 0;
6000         d |= PACK(r, 0, 5);
6001         d |= PACK(g, 5, 5);
6002         d |= PACK(b, 10, 5);
6003         d |= PACK(a, 15, 1);
6004      (*(uint16_t *)dst) = d;
6005}
6006
6007static inline void
6008pack_float_a2b10g10r10_unorm(const GLfloat src[4], void *dst)
6009{
6010
6011
6012      uint8_t a =
6013            _mesa_float_to_unorm(src[3], 2);
6014
6015
6016      uint16_t b =
6017            _mesa_float_to_unorm(src[2], 10);
6018
6019
6020      uint16_t g =
6021            _mesa_float_to_unorm(src[1], 10);
6022
6023
6024      uint16_t r =
6025            _mesa_float_to_unorm(src[0], 10);
6026
6027      uint32_t d = 0;
6028         d |= PACK(a, 0, 2);
6029         d |= PACK(b, 2, 10);
6030         d |= PACK(g, 12, 10);
6031         d |= PACK(r, 22, 10);
6032      (*(uint32_t *)dst) = d;
6033}
6034
6035static inline void
6036pack_float_a2r10g10b10_unorm(const GLfloat src[4], void *dst)
6037{
6038
6039
6040      uint8_t a =
6041            _mesa_float_to_unorm(src[3], 2);
6042
6043
6044      uint16_t r =
6045            _mesa_float_to_unorm(src[0], 10);
6046
6047
6048      uint16_t g =
6049            _mesa_float_to_unorm(src[1], 10);
6050
6051
6052      uint16_t b =
6053            _mesa_float_to_unorm(src[2], 10);
6054
6055      uint32_t d = 0;
6056         d |= PACK(a, 0, 2);
6057         d |= PACK(r, 2, 10);
6058         d |= PACK(g, 12, 10);
6059         d |= PACK(b, 22, 10);
6060      (*(uint32_t *)dst) = d;
6061}
6062
6063static inline void
6064pack_float_a_unorm8(const GLfloat src[4], void *dst)
6065{
6066
6067
6068      uint8_t a =
6069            _mesa_float_to_unorm(src[3], 8);
6070
6071      uint8_t *d = (uint8_t *)dst;
6072         d[0] = a;
6073}
6074
6075static inline void
6076pack_float_a_unorm16(const GLfloat src[4], void *dst)
6077{
6078
6079
6080      uint16_t a =
6081            _mesa_float_to_unorm(src[3], 16);
6082
6083      uint16_t *d = (uint16_t *)dst;
6084         d[0] = a;
6085}
6086
6087static inline void
6088pack_float_l_unorm8(const GLfloat src[4], void *dst)
6089{
6090
6091
6092      uint8_t l =
6093            _mesa_float_to_unorm(src[0], 8);
6094
6095      uint8_t *d = (uint8_t *)dst;
6096         d[0] = l;
6097}
6098
6099static inline void
6100pack_float_l_unorm16(const GLfloat src[4], void *dst)
6101{
6102
6103
6104      uint16_t l =
6105            _mesa_float_to_unorm(src[0], 16);
6106
6107      uint16_t *d = (uint16_t *)dst;
6108         d[0] = l;
6109}
6110
6111static inline void
6112pack_float_i_unorm8(const GLfloat src[4], void *dst)
6113{
6114
6115
6116      uint8_t i =
6117            _mesa_float_to_unorm(src[0], 8);
6118
6119      uint8_t *d = (uint8_t *)dst;
6120         d[0] = i;
6121}
6122
6123static inline void
6124pack_float_i_unorm16(const GLfloat src[4], void *dst)
6125{
6126
6127
6128      uint16_t i =
6129            _mesa_float_to_unorm(src[0], 16);
6130
6131      uint16_t *d = (uint16_t *)dst;
6132         d[0] = i;
6133}
6134
6135static inline void
6136pack_float_r_unorm8(const GLfloat src[4], void *dst)
6137{
6138
6139
6140      uint8_t r =
6141            _mesa_float_to_unorm(src[0], 8);
6142
6143      uint8_t *d = (uint8_t *)dst;
6144         d[0] = r;
6145}
6146
6147static inline void
6148pack_float_r_unorm16(const GLfloat src[4], void *dst)
6149{
6150
6151
6152      uint16_t r =
6153            _mesa_float_to_unorm(src[0], 16);
6154
6155      uint16_t *d = (uint16_t *)dst;
6156         d[0] = r;
6157}
6158
6159static inline void
6160pack_float_bgr_unorm8(const GLfloat src[4], void *dst)
6161{
6162
6163
6164      uint8_t b =
6165            _mesa_float_to_unorm(src[2], 8);
6166
6167
6168      uint8_t g =
6169            _mesa_float_to_unorm(src[1], 8);
6170
6171
6172      uint8_t r =
6173            _mesa_float_to_unorm(src[0], 8);
6174
6175      uint8_t *d = (uint8_t *)dst;
6176         d[0] = b;
6177         d[1] = g;
6178         d[2] = r;
6179}
6180
6181static inline void
6182pack_float_rgb_unorm8(const GLfloat src[4], void *dst)
6183{
6184
6185
6186      uint8_t r =
6187            _mesa_float_to_unorm(src[0], 8);
6188
6189
6190      uint8_t g =
6191            _mesa_float_to_unorm(src[1], 8);
6192
6193
6194      uint8_t b =
6195            _mesa_float_to_unorm(src[2], 8);
6196
6197      uint8_t *d = (uint8_t *)dst;
6198         d[0] = r;
6199         d[1] = g;
6200         d[2] = b;
6201}
6202
6203static inline void
6204pack_float_rgba_unorm16(const GLfloat src[4], void *dst)
6205{
6206
6207
6208      uint16_t r =
6209            _mesa_float_to_unorm(src[0], 16);
6210
6211
6212      uint16_t g =
6213            _mesa_float_to_unorm(src[1], 16);
6214
6215
6216      uint16_t b =
6217            _mesa_float_to_unorm(src[2], 16);
6218
6219
6220      uint16_t a =
6221            _mesa_float_to_unorm(src[3], 16);
6222
6223      uint16_t *d = (uint16_t *)dst;
6224         d[0] = r;
6225         d[1] = g;
6226         d[2] = b;
6227         d[3] = a;
6228}
6229
6230static inline void
6231pack_float_rgbx_unorm16(const GLfloat src[4], void *dst)
6232{
6233
6234
6235      uint16_t r =
6236            _mesa_float_to_unorm(src[0], 16);
6237
6238
6239      uint16_t g =
6240            _mesa_float_to_unorm(src[1], 16);
6241
6242
6243      uint16_t b =
6244            _mesa_float_to_unorm(src[2], 16);
6245
6246
6247      uint16_t *d = (uint16_t *)dst;
6248         d[0] = r;
6249         d[1] = g;
6250         d[2] = b;
6251            }
6252
6253static inline void
6254pack_float_a8b8g8r8_snorm(const GLfloat src[4], void *dst)
6255{
6256
6257
6258      int8_t a =
6259         _mesa_float_to_snorm(src[3], 8);
6260
6261
6262      int8_t b =
6263         _mesa_float_to_snorm(src[2], 8);
6264
6265
6266      int8_t g =
6267         _mesa_float_to_snorm(src[1], 8);
6268
6269
6270      int8_t r =
6271         _mesa_float_to_snorm(src[0], 8);
6272
6273      uint32_t d = 0;
6274         d |= PACK(a, 0, 8);
6275         d |= PACK(b, 8, 8);
6276         d |= PACK(g, 16, 8);
6277         d |= PACK(r, 24, 8);
6278      (*(uint32_t *)dst) = d;
6279}
6280
6281static inline void
6282pack_float_x8b8g8r8_snorm(const GLfloat src[4], void *dst)
6283{
6284
6285
6286
6287      int8_t b =
6288         _mesa_float_to_snorm(src[2], 8);
6289
6290
6291      int8_t g =
6292         _mesa_float_to_snorm(src[1], 8);
6293
6294
6295      int8_t r =
6296         _mesa_float_to_snorm(src[0], 8);
6297
6298      uint32_t d = 0;
6299                     d |= PACK(b, 8, 8);
6300         d |= PACK(g, 16, 8);
6301         d |= PACK(r, 24, 8);
6302      (*(uint32_t *)dst) = d;
6303}
6304
6305static inline void
6306pack_float_r8g8b8a8_snorm(const GLfloat src[4], void *dst)
6307{
6308
6309
6310      int8_t r =
6311         _mesa_float_to_snorm(src[0], 8);
6312
6313
6314      int8_t g =
6315         _mesa_float_to_snorm(src[1], 8);
6316
6317
6318      int8_t b =
6319         _mesa_float_to_snorm(src[2], 8);
6320
6321
6322      int8_t a =
6323         _mesa_float_to_snorm(src[3], 8);
6324
6325      uint32_t d = 0;
6326         d |= PACK(r, 0, 8);
6327         d |= PACK(g, 8, 8);
6328         d |= PACK(b, 16, 8);
6329         d |= PACK(a, 24, 8);
6330      (*(uint32_t *)dst) = d;
6331}
6332
6333static inline void
6334pack_float_r8g8b8x8_snorm(const GLfloat src[4], void *dst)
6335{
6336
6337
6338      int8_t r =
6339         _mesa_float_to_snorm(src[0], 8);
6340
6341
6342      int8_t g =
6343         _mesa_float_to_snorm(src[1], 8);
6344
6345
6346      int8_t b =
6347         _mesa_float_to_snorm(src[2], 8);
6348
6349
6350      uint32_t d = 0;
6351         d |= PACK(r, 0, 8);
6352         d |= PACK(g, 8, 8);
6353         d |= PACK(b, 16, 8);
6354                  (*(uint32_t *)dst) = d;
6355}
6356
6357static inline void
6358pack_float_r16g16_snorm(const GLfloat src[4], void *dst)
6359{
6360
6361
6362      int16_t r =
6363         _mesa_float_to_snorm(src[0], 16);
6364
6365
6366      int16_t g =
6367         _mesa_float_to_snorm(src[1], 16);
6368
6369      uint32_t d = 0;
6370         d |= PACK(r, 0, 16);
6371         d |= PACK(g, 16, 16);
6372      (*(uint32_t *)dst) = d;
6373}
6374
6375static inline void
6376pack_float_g16r16_snorm(const GLfloat src[4], void *dst)
6377{
6378
6379
6380      int16_t g =
6381         _mesa_float_to_snorm(src[1], 16);
6382
6383
6384      int16_t r =
6385         _mesa_float_to_snorm(src[0], 16);
6386
6387      uint32_t d = 0;
6388         d |= PACK(g, 0, 16);
6389         d |= PACK(r, 16, 16);
6390      (*(uint32_t *)dst) = d;
6391}
6392
6393static inline void
6394pack_float_r8g8_snorm(const GLfloat src[4], void *dst)
6395{
6396
6397
6398      int8_t r =
6399         _mesa_float_to_snorm(src[0], 8);
6400
6401
6402      int8_t g =
6403         _mesa_float_to_snorm(src[1], 8);
6404
6405      uint16_t d = 0;
6406         d |= PACK(r, 0, 8);
6407         d |= PACK(g, 8, 8);
6408      (*(uint16_t *)dst) = d;
6409}
6410
6411static inline void
6412pack_float_g8r8_snorm(const GLfloat src[4], void *dst)
6413{
6414
6415
6416      int8_t g =
6417         _mesa_float_to_snorm(src[1], 8);
6418
6419
6420      int8_t r =
6421         _mesa_float_to_snorm(src[0], 8);
6422
6423      uint16_t d = 0;
6424         d |= PACK(g, 0, 8);
6425         d |= PACK(r, 8, 8);
6426      (*(uint16_t *)dst) = d;
6427}
6428
6429static inline void
6430pack_float_l8a8_snorm(const GLfloat src[4], void *dst)
6431{
6432
6433
6434      int8_t l =
6435         _mesa_float_to_snorm(src[0], 8);
6436
6437
6438      int8_t a =
6439         _mesa_float_to_snorm(src[3], 8);
6440
6441      uint16_t d = 0;
6442         d |= PACK(l, 0, 8);
6443         d |= PACK(a, 8, 8);
6444      (*(uint16_t *)dst) = d;
6445}
6446
6447static inline void
6448pack_float_a8l8_snorm(const GLfloat src[4], void *dst)
6449{
6450
6451
6452      int8_t a =
6453         _mesa_float_to_snorm(src[3], 8);
6454
6455
6456      int8_t l =
6457         _mesa_float_to_snorm(src[0], 8);
6458
6459      uint16_t d = 0;
6460         d |= PACK(a, 0, 8);
6461         d |= PACK(l, 8, 8);
6462      (*(uint16_t *)dst) = d;
6463}
6464
6465static inline void
6466pack_float_a_snorm8(const GLfloat src[4], void *dst)
6467{
6468
6469
6470      int8_t a =
6471         _mesa_float_to_snorm(src[3], 8);
6472
6473      int8_t *d = (int8_t *)dst;
6474         d[0] = a;
6475}
6476
6477static inline void
6478pack_float_a_snorm16(const GLfloat src[4], void *dst)
6479{
6480
6481
6482      int16_t a =
6483         _mesa_float_to_snorm(src[3], 16);
6484
6485      int16_t *d = (int16_t *)dst;
6486         d[0] = a;
6487}
6488
6489static inline void
6490pack_float_l_snorm8(const GLfloat src[4], void *dst)
6491{
6492
6493
6494      int8_t l =
6495         _mesa_float_to_snorm(src[0], 8);
6496
6497      int8_t *d = (int8_t *)dst;
6498         d[0] = l;
6499}
6500
6501static inline void
6502pack_float_l_snorm16(const GLfloat src[4], void *dst)
6503{
6504
6505
6506      int16_t l =
6507         _mesa_float_to_snorm(src[0], 16);
6508
6509      int16_t *d = (int16_t *)dst;
6510         d[0] = l;
6511}
6512
6513static inline void
6514pack_float_i_snorm8(const GLfloat src[4], void *dst)
6515{
6516
6517
6518      int8_t i =
6519         _mesa_float_to_snorm(src[0], 8);
6520
6521      int8_t *d = (int8_t *)dst;
6522         d[0] = i;
6523}
6524
6525static inline void
6526pack_float_i_snorm16(const GLfloat src[4], void *dst)
6527{
6528
6529
6530      int16_t i =
6531         _mesa_float_to_snorm(src[0], 16);
6532
6533      int16_t *d = (int16_t *)dst;
6534         d[0] = i;
6535}
6536
6537static inline void
6538pack_float_r_snorm8(const GLfloat src[4], void *dst)
6539{
6540
6541
6542      int8_t r =
6543         _mesa_float_to_snorm(src[0], 8);
6544
6545      int8_t *d = (int8_t *)dst;
6546         d[0] = r;
6547}
6548
6549static inline void
6550pack_float_r_snorm16(const GLfloat src[4], void *dst)
6551{
6552
6553
6554      int16_t r =
6555         _mesa_float_to_snorm(src[0], 16);
6556
6557      int16_t *d = (int16_t *)dst;
6558         d[0] = r;
6559}
6560
6561static inline void
6562pack_float_la_snorm16(const GLfloat src[4], void *dst)
6563{
6564
6565
6566      int16_t l =
6567         _mesa_float_to_snorm(src[0], 16);
6568
6569
6570      int16_t a =
6571         _mesa_float_to_snorm(src[3], 16);
6572
6573      int16_t *d = (int16_t *)dst;
6574         d[0] = l;
6575         d[1] = a;
6576}
6577
6578static inline void
6579pack_float_rgb_snorm16(const GLfloat src[4], void *dst)
6580{
6581
6582
6583      int16_t r =
6584         _mesa_float_to_snorm(src[0], 16);
6585
6586
6587      int16_t g =
6588         _mesa_float_to_snorm(src[1], 16);
6589
6590
6591      int16_t b =
6592         _mesa_float_to_snorm(src[2], 16);
6593
6594      int16_t *d = (int16_t *)dst;
6595         d[0] = r;
6596         d[1] = g;
6597         d[2] = b;
6598}
6599
6600static inline void
6601pack_float_rgba_snorm16(const GLfloat src[4], void *dst)
6602{
6603
6604
6605      int16_t r =
6606         _mesa_float_to_snorm(src[0], 16);
6607
6608
6609      int16_t g =
6610         _mesa_float_to_snorm(src[1], 16);
6611
6612
6613      int16_t b =
6614         _mesa_float_to_snorm(src[2], 16);
6615
6616
6617      int16_t a =
6618         _mesa_float_to_snorm(src[3], 16);
6619
6620      int16_t *d = (int16_t *)dst;
6621         d[0] = r;
6622         d[1] = g;
6623         d[2] = b;
6624         d[3] = a;
6625}
6626
6627static inline void
6628pack_float_rgbx_snorm16(const GLfloat src[4], void *dst)
6629{
6630
6631
6632      int16_t r =
6633         _mesa_float_to_snorm(src[0], 16);
6634
6635
6636      int16_t g =
6637         _mesa_float_to_snorm(src[1], 16);
6638
6639
6640      int16_t b =
6641         _mesa_float_to_snorm(src[2], 16);
6642
6643
6644      int16_t *d = (int16_t *)dst;
6645         d[0] = r;
6646         d[1] = g;
6647         d[2] = b;
6648            }
6649
6650static inline void
6651pack_float_a8b8g8r8_srgb(const GLfloat src[4], void *dst)
6652{
6653
6654
6655      uint8_t a =
6656            _mesa_float_to_unorm(src[3], 8);
6657
6658
6659      uint8_t b =
6660
6661            util_format_linear_float_to_srgb_8unorm(src[2]);
6662
6663
6664      uint8_t g =
6665
6666            util_format_linear_float_to_srgb_8unorm(src[1]);
6667
6668
6669      uint8_t r =
6670
6671            util_format_linear_float_to_srgb_8unorm(src[0]);
6672
6673      uint32_t d = 0;
6674         d |= PACK(a, 0, 8);
6675         d |= PACK(b, 8, 8);
6676         d |= PACK(g, 16, 8);
6677         d |= PACK(r, 24, 8);
6678      (*(uint32_t *)dst) = d;
6679}
6680
6681static inline void
6682pack_float_b8g8r8a8_srgb(const GLfloat src[4], void *dst)
6683{
6684
6685
6686      uint8_t b =
6687
6688            util_format_linear_float_to_srgb_8unorm(src[2]);
6689
6690
6691      uint8_t g =
6692
6693            util_format_linear_float_to_srgb_8unorm(src[1]);
6694
6695
6696      uint8_t r =
6697
6698            util_format_linear_float_to_srgb_8unorm(src[0]);
6699
6700
6701      uint8_t a =
6702            _mesa_float_to_unorm(src[3], 8);
6703
6704      uint32_t d = 0;
6705         d |= PACK(b, 0, 8);
6706         d |= PACK(g, 8, 8);
6707         d |= PACK(r, 16, 8);
6708         d |= PACK(a, 24, 8);
6709      (*(uint32_t *)dst) = d;
6710}
6711
6712static inline void
6713pack_float_a8r8g8b8_srgb(const GLfloat src[4], void *dst)
6714{
6715
6716
6717      uint8_t a =
6718            _mesa_float_to_unorm(src[3], 8);
6719
6720
6721      uint8_t r =
6722
6723            util_format_linear_float_to_srgb_8unorm(src[0]);
6724
6725
6726      uint8_t g =
6727
6728            util_format_linear_float_to_srgb_8unorm(src[1]);
6729
6730
6731      uint8_t b =
6732
6733            util_format_linear_float_to_srgb_8unorm(src[2]);
6734
6735      uint32_t d = 0;
6736         d |= PACK(a, 0, 8);
6737         d |= PACK(r, 8, 8);
6738         d |= PACK(g, 16, 8);
6739         d |= PACK(b, 24, 8);
6740      (*(uint32_t *)dst) = d;
6741}
6742
6743static inline void
6744pack_float_b8g8r8x8_srgb(const GLfloat src[4], void *dst)
6745{
6746
6747
6748      uint8_t b =
6749
6750            util_format_linear_float_to_srgb_8unorm(src[2]);
6751
6752
6753      uint8_t g =
6754
6755            util_format_linear_float_to_srgb_8unorm(src[1]);
6756
6757
6758      uint8_t r =
6759
6760            util_format_linear_float_to_srgb_8unorm(src[0]);
6761
6762
6763      uint32_t d = 0;
6764         d |= PACK(b, 0, 8);
6765         d |= PACK(g, 8, 8);
6766         d |= PACK(r, 16, 8);
6767                  (*(uint32_t *)dst) = d;
6768}
6769
6770static inline void
6771pack_float_x8r8g8b8_srgb(const GLfloat src[4], void *dst)
6772{
6773
6774
6775
6776      uint8_t r =
6777
6778            util_format_linear_float_to_srgb_8unorm(src[0]);
6779
6780
6781      uint8_t g =
6782
6783            util_format_linear_float_to_srgb_8unorm(src[1]);
6784
6785
6786      uint8_t b =
6787
6788            util_format_linear_float_to_srgb_8unorm(src[2]);
6789
6790      uint32_t d = 0;
6791                     d |= PACK(r, 8, 8);
6792         d |= PACK(g, 16, 8);
6793         d |= PACK(b, 24, 8);
6794      (*(uint32_t *)dst) = d;
6795}
6796
6797static inline void
6798pack_float_r8g8b8a8_srgb(const GLfloat src[4], void *dst)
6799{
6800
6801
6802      uint8_t r =
6803
6804            util_format_linear_float_to_srgb_8unorm(src[0]);
6805
6806
6807      uint8_t g =
6808
6809            util_format_linear_float_to_srgb_8unorm(src[1]);
6810
6811
6812      uint8_t b =
6813
6814            util_format_linear_float_to_srgb_8unorm(src[2]);
6815
6816
6817      uint8_t a =
6818            _mesa_float_to_unorm(src[3], 8);
6819
6820      uint32_t d = 0;
6821         d |= PACK(r, 0, 8);
6822         d |= PACK(g, 8, 8);
6823         d |= PACK(b, 16, 8);
6824         d |= PACK(a, 24, 8);
6825      (*(uint32_t *)dst) = d;
6826}
6827
6828static inline void
6829pack_float_r8g8b8x8_srgb(const GLfloat src[4], void *dst)
6830{
6831
6832
6833      uint8_t r =
6834
6835            util_format_linear_float_to_srgb_8unorm(src[0]);
6836
6837
6838      uint8_t g =
6839
6840            util_format_linear_float_to_srgb_8unorm(src[1]);
6841
6842
6843      uint8_t b =
6844
6845            util_format_linear_float_to_srgb_8unorm(src[2]);
6846
6847
6848      uint32_t d = 0;
6849         d |= PACK(r, 0, 8);
6850         d |= PACK(g, 8, 8);
6851         d |= PACK(b, 16, 8);
6852                  (*(uint32_t *)dst) = d;
6853}
6854
6855static inline void
6856pack_float_x8b8g8r8_srgb(const GLfloat src[4], void *dst)
6857{
6858
6859
6860
6861      uint8_t b =
6862
6863            util_format_linear_float_to_srgb_8unorm(src[2]);
6864
6865
6866      uint8_t g =
6867
6868            util_format_linear_float_to_srgb_8unorm(src[1]);
6869
6870
6871      uint8_t r =
6872
6873            util_format_linear_float_to_srgb_8unorm(src[0]);
6874
6875      uint32_t d = 0;
6876                     d |= PACK(b, 8, 8);
6877         d |= PACK(g, 16, 8);
6878         d |= PACK(r, 24, 8);
6879      (*(uint32_t *)dst) = d;
6880}
6881
6882static inline void
6883pack_float_l8a8_srgb(const GLfloat src[4], void *dst)
6884{
6885
6886
6887      uint8_t l =
6888            _mesa_float_to_unorm(src[0], 8);
6889
6890
6891      uint8_t a =
6892            _mesa_float_to_unorm(src[3], 8);
6893
6894      uint16_t d = 0;
6895         d |= PACK(l, 0, 8);
6896         d |= PACK(a, 8, 8);
6897      (*(uint16_t *)dst) = d;
6898}
6899
6900static inline void
6901pack_float_a8l8_srgb(const GLfloat src[4], void *dst)
6902{
6903
6904
6905      uint8_t a =
6906            _mesa_float_to_unorm(src[3], 8);
6907
6908
6909      uint8_t l =
6910            _mesa_float_to_unorm(src[0], 8);
6911
6912      uint16_t d = 0;
6913         d |= PACK(a, 0, 8);
6914         d |= PACK(l, 8, 8);
6915      (*(uint16_t *)dst) = d;
6916}
6917
6918static inline void
6919pack_float_r_srgb8(const GLfloat src[4], void *dst)
6920{
6921
6922
6923      uint8_t r =
6924
6925            util_format_linear_float_to_srgb_8unorm(src[0]);
6926
6927      uint8_t *d = (uint8_t *)dst;
6928         d[0] = r;
6929}
6930
6931static inline void
6932pack_float_l_srgb8(const GLfloat src[4], void *dst)
6933{
6934
6935
6936      uint8_t l =
6937            _mesa_float_to_unorm(src[0], 8);
6938
6939      uint8_t *d = (uint8_t *)dst;
6940         d[0] = l;
6941}
6942
6943static inline void
6944pack_float_bgr_srgb8(const GLfloat src[4], void *dst)
6945{
6946
6947
6948      uint8_t b =
6949
6950            util_format_linear_float_to_srgb_8unorm(src[2]);
6951
6952
6953      uint8_t g =
6954
6955            util_format_linear_float_to_srgb_8unorm(src[1]);
6956
6957
6958      uint8_t r =
6959
6960            util_format_linear_float_to_srgb_8unorm(src[0]);
6961
6962      uint8_t *d = (uint8_t *)dst;
6963         d[0] = b;
6964         d[1] = g;
6965         d[2] = r;
6966}
6967
6968static inline void
6969pack_float_a_float16(const GLfloat src[4], void *dst)
6970{
6971
6972
6973      uint16_t a =
6974            _mesa_float_to_half(src[3]);
6975
6976      uint16_t *d = (uint16_t *)dst;
6977         d[0] = a;
6978}
6979
6980static inline void
6981pack_float_a_float32(const GLfloat src[4], void *dst)
6982{
6983
6984
6985      float a =
6986            src[3];
6987
6988      float *d = (float *)dst;
6989         d[0] = a;
6990}
6991
6992static inline void
6993pack_float_l_float16(const GLfloat src[4], void *dst)
6994{
6995
6996
6997      uint16_t l =
6998            _mesa_float_to_half(src[0]);
6999
7000      uint16_t *d = (uint16_t *)dst;
7001         d[0] = l;
7002}
7003
7004static inline void
7005pack_float_l_float32(const GLfloat src[4], void *dst)
7006{
7007
7008
7009      float l =
7010            src[0];
7011
7012      float *d = (float *)dst;
7013         d[0] = l;
7014}
7015
7016static inline void
7017pack_float_la_float16(const GLfloat src[4], void *dst)
7018{
7019
7020
7021      uint16_t l =
7022            _mesa_float_to_half(src[0]);
7023
7024
7025      uint16_t a =
7026            _mesa_float_to_half(src[3]);
7027
7028      uint16_t *d = (uint16_t *)dst;
7029         d[0] = l;
7030         d[1] = a;
7031}
7032
7033static inline void
7034pack_float_la_float32(const GLfloat src[4], void *dst)
7035{
7036
7037
7038      float l =
7039            src[0];
7040
7041
7042      float a =
7043            src[3];
7044
7045      float *d = (float *)dst;
7046         d[0] = l;
7047         d[1] = a;
7048}
7049
7050static inline void
7051pack_float_i_float16(const GLfloat src[4], void *dst)
7052{
7053
7054
7055      uint16_t i =
7056            _mesa_float_to_half(src[0]);
7057
7058      uint16_t *d = (uint16_t *)dst;
7059         d[0] = i;
7060}
7061
7062static inline void
7063pack_float_i_float32(const GLfloat src[4], void *dst)
7064{
7065
7066
7067      float i =
7068            src[0];
7069
7070      float *d = (float *)dst;
7071         d[0] = i;
7072}
7073
7074static inline void
7075pack_float_r_float16(const GLfloat src[4], void *dst)
7076{
7077
7078
7079      uint16_t r =
7080            _mesa_float_to_half(src[0]);
7081
7082      uint16_t *d = (uint16_t *)dst;
7083         d[0] = r;
7084}
7085
7086static inline void
7087pack_float_r_float32(const GLfloat src[4], void *dst)
7088{
7089
7090
7091      float r =
7092            src[0];
7093
7094      float *d = (float *)dst;
7095         d[0] = r;
7096}
7097
7098static inline void
7099pack_float_rg_float16(const GLfloat src[4], void *dst)
7100{
7101
7102
7103      uint16_t r =
7104            _mesa_float_to_half(src[0]);
7105
7106
7107      uint16_t g =
7108            _mesa_float_to_half(src[1]);
7109
7110      uint16_t *d = (uint16_t *)dst;
7111         d[0] = r;
7112         d[1] = g;
7113}
7114
7115static inline void
7116pack_float_rg_float32(const GLfloat src[4], void *dst)
7117{
7118
7119
7120      float r =
7121            src[0];
7122
7123
7124      float g =
7125            src[1];
7126
7127      float *d = (float *)dst;
7128         d[0] = r;
7129         d[1] = g;
7130}
7131
7132static inline void
7133pack_float_rgb_float16(const GLfloat src[4], void *dst)
7134{
7135
7136
7137      uint16_t r =
7138            _mesa_float_to_half(src[0]);
7139
7140
7141      uint16_t g =
7142            _mesa_float_to_half(src[1]);
7143
7144
7145      uint16_t b =
7146            _mesa_float_to_half(src[2]);
7147
7148      uint16_t *d = (uint16_t *)dst;
7149         d[0] = r;
7150         d[1] = g;
7151         d[2] = b;
7152}
7153
7154static inline void
7155pack_float_rgb_float32(const GLfloat src[4], void *dst)
7156{
7157
7158
7159      float r =
7160            src[0];
7161
7162
7163      float g =
7164            src[1];
7165
7166
7167      float b =
7168            src[2];
7169
7170      float *d = (float *)dst;
7171         d[0] = r;
7172         d[1] = g;
7173         d[2] = b;
7174}
7175
7176static inline void
7177pack_float_rgba_float16(const GLfloat src[4], void *dst)
7178{
7179
7180
7181      uint16_t r =
7182            _mesa_float_to_half(src[0]);
7183
7184
7185      uint16_t g =
7186            _mesa_float_to_half(src[1]);
7187
7188
7189      uint16_t b =
7190            _mesa_float_to_half(src[2]);
7191
7192
7193      uint16_t a =
7194            _mesa_float_to_half(src[3]);
7195
7196      uint16_t *d = (uint16_t *)dst;
7197         d[0] = r;
7198         d[1] = g;
7199         d[2] = b;
7200         d[3] = a;
7201}
7202
7203static inline void
7204pack_float_rgba_float32(const GLfloat src[4], void *dst)
7205{
7206
7207
7208      float r =
7209            src[0];
7210
7211
7212      float g =
7213            src[1];
7214
7215
7216      float b =
7217            src[2];
7218
7219
7220      float a =
7221            src[3];
7222
7223      float *d = (float *)dst;
7224         d[0] = r;
7225         d[1] = g;
7226         d[2] = b;
7227         d[3] = a;
7228}
7229
7230static inline void
7231pack_float_rgbx_float16(const GLfloat src[4], void *dst)
7232{
7233
7234
7235      uint16_t r =
7236            _mesa_float_to_half(src[0]);
7237
7238
7239      uint16_t g =
7240            _mesa_float_to_half(src[1]);
7241
7242
7243      uint16_t b =
7244            _mesa_float_to_half(src[2]);
7245
7246
7247      uint16_t *d = (uint16_t *)dst;
7248         d[0] = r;
7249         d[1] = g;
7250         d[2] = b;
7251            }
7252
7253static inline void
7254pack_float_rgbx_float32(const GLfloat src[4], void *dst)
7255{
7256
7257
7258      float r =
7259            src[0];
7260
7261
7262      float g =
7263            src[1];
7264
7265
7266      float b =
7267            src[2];
7268
7269
7270      float *d = (float *)dst;
7271         d[0] = r;
7272         d[1] = g;
7273         d[2] = b;
7274            }
7275
7276static inline void
7277pack_float_r9g9b9e5_float(const GLfloat src[4], void *dst)
7278{
7279   GLuint *d = (GLuint *) dst;
7280   *d = float3_to_rgb9e5(src);
7281}
7282
7283static inline void
7284pack_float_r11g11b10_float(const GLfloat src[4], void *dst)
7285{
7286   GLuint *d = (GLuint *) dst;
7287   *d = float3_to_r11g11b10f(src);
7288}
7289
7290/**
7291 * Return a function that can pack a GLubyte rgba[4] color.
7292 */
7293gl_pack_ubyte_rgba_func
7294_mesa_get_pack_ubyte_rgba_function(mesa_format format)
7295{
7296   switch (format) {
7297
7298   case MESA_FORMAT_A8B8G8R8_UNORM:
7299      return pack_ubyte_a8b8g8r8_unorm;
7300
7301   case MESA_FORMAT_X8B8G8R8_UNORM:
7302      return pack_ubyte_x8b8g8r8_unorm;
7303
7304   case MESA_FORMAT_R8G8B8A8_UNORM:
7305      return pack_ubyte_r8g8b8a8_unorm;
7306
7307   case MESA_FORMAT_R8G8B8X8_UNORM:
7308      return pack_ubyte_r8g8b8x8_unorm;
7309
7310   case MESA_FORMAT_B8G8R8A8_UNORM:
7311      return pack_ubyte_b8g8r8a8_unorm;
7312
7313   case MESA_FORMAT_B8G8R8X8_UNORM:
7314      return pack_ubyte_b8g8r8x8_unorm;
7315
7316   case MESA_FORMAT_A8R8G8B8_UNORM:
7317      return pack_ubyte_a8r8g8b8_unorm;
7318
7319   case MESA_FORMAT_X8R8G8B8_UNORM:
7320      return pack_ubyte_x8r8g8b8_unorm;
7321
7322   case MESA_FORMAT_L16A16_UNORM:
7323      return pack_ubyte_l16a16_unorm;
7324
7325   case MESA_FORMAT_A16L16_UNORM:
7326      return pack_ubyte_a16l16_unorm;
7327
7328   case MESA_FORMAT_B5G6R5_UNORM:
7329      return pack_ubyte_b5g6r5_unorm;
7330
7331   case MESA_FORMAT_R5G6B5_UNORM:
7332      return pack_ubyte_r5g6b5_unorm;
7333
7334   case MESA_FORMAT_B4G4R4A4_UNORM:
7335      return pack_ubyte_b4g4r4a4_unorm;
7336
7337   case MESA_FORMAT_B4G4R4X4_UNORM:
7338      return pack_ubyte_b4g4r4x4_unorm;
7339
7340   case MESA_FORMAT_A4R4G4B4_UNORM:
7341      return pack_ubyte_a4r4g4b4_unorm;
7342
7343   case MESA_FORMAT_A1B5G5R5_UNORM:
7344      return pack_ubyte_a1b5g5r5_unorm;
7345
7346   case MESA_FORMAT_X1B5G5R5_UNORM:
7347      return pack_ubyte_x1b5g5r5_unorm;
7348
7349   case MESA_FORMAT_B5G5R5A1_UNORM:
7350      return pack_ubyte_b5g5r5a1_unorm;
7351
7352   case MESA_FORMAT_B5G5R5X1_UNORM:
7353      return pack_ubyte_b5g5r5x1_unorm;
7354
7355   case MESA_FORMAT_A1R5G5B5_UNORM:
7356      return pack_ubyte_a1r5g5b5_unorm;
7357
7358   case MESA_FORMAT_L8A8_UNORM:
7359      return pack_ubyte_l8a8_unorm;
7360
7361   case MESA_FORMAT_A8L8_UNORM:
7362      return pack_ubyte_a8l8_unorm;
7363
7364   case MESA_FORMAT_R8G8_UNORM:
7365      return pack_ubyte_r8g8_unorm;
7366
7367   case MESA_FORMAT_G8R8_UNORM:
7368      return pack_ubyte_g8r8_unorm;
7369
7370   case MESA_FORMAT_L4A4_UNORM:
7371      return pack_ubyte_l4a4_unorm;
7372
7373   case MESA_FORMAT_B2G3R3_UNORM:
7374      return pack_ubyte_b2g3r3_unorm;
7375
7376   case MESA_FORMAT_R16G16_UNORM:
7377      return pack_ubyte_r16g16_unorm;
7378
7379   case MESA_FORMAT_G16R16_UNORM:
7380      return pack_ubyte_g16r16_unorm;
7381
7382   case MESA_FORMAT_B10G10R10A2_UNORM:
7383      return pack_ubyte_b10g10r10a2_unorm;
7384
7385   case MESA_FORMAT_B10G10R10X2_UNORM:
7386      return pack_ubyte_b10g10r10x2_unorm;
7387
7388   case MESA_FORMAT_R10G10B10A2_UNORM:
7389      return pack_ubyte_r10g10b10a2_unorm;
7390
7391   case MESA_FORMAT_R10G10B10X2_UNORM:
7392      return pack_ubyte_r10g10b10x2_unorm;
7393
7394   case MESA_FORMAT_R3G3B2_UNORM:
7395      return pack_ubyte_r3g3b2_unorm;
7396
7397   case MESA_FORMAT_A4B4G4R4_UNORM:
7398      return pack_ubyte_a4b4g4r4_unorm;
7399
7400   case MESA_FORMAT_R4G4B4A4_UNORM:
7401      return pack_ubyte_r4g4b4a4_unorm;
7402
7403   case MESA_FORMAT_R5G5B5A1_UNORM:
7404      return pack_ubyte_r5g5b5a1_unorm;
7405
7406   case MESA_FORMAT_A2B10G10R10_UNORM:
7407      return pack_ubyte_a2b10g10r10_unorm;
7408
7409   case MESA_FORMAT_A2R10G10B10_UNORM:
7410      return pack_ubyte_a2r10g10b10_unorm;
7411
7412   case MESA_FORMAT_A_UNORM8:
7413      return pack_ubyte_a_unorm8;
7414
7415   case MESA_FORMAT_A_UNORM16:
7416      return pack_ubyte_a_unorm16;
7417
7418   case MESA_FORMAT_L_UNORM8:
7419      return pack_ubyte_l_unorm8;
7420
7421   case MESA_FORMAT_L_UNORM16:
7422      return pack_ubyte_l_unorm16;
7423
7424   case MESA_FORMAT_I_UNORM8:
7425      return pack_ubyte_i_unorm8;
7426
7427   case MESA_FORMAT_I_UNORM16:
7428      return pack_ubyte_i_unorm16;
7429
7430   case MESA_FORMAT_R_UNORM8:
7431      return pack_ubyte_r_unorm8;
7432
7433   case MESA_FORMAT_R_UNORM16:
7434      return pack_ubyte_r_unorm16;
7435
7436   case MESA_FORMAT_BGR_UNORM8:
7437      return pack_ubyte_bgr_unorm8;
7438
7439   case MESA_FORMAT_RGB_UNORM8:
7440      return pack_ubyte_rgb_unorm8;
7441
7442   case MESA_FORMAT_RGBA_UNORM16:
7443      return pack_ubyte_rgba_unorm16;
7444
7445   case MESA_FORMAT_RGBX_UNORM16:
7446      return pack_ubyte_rgbx_unorm16;
7447
7448   case MESA_FORMAT_A8B8G8R8_SNORM:
7449      return pack_ubyte_a8b8g8r8_snorm;
7450
7451   case MESA_FORMAT_X8B8G8R8_SNORM:
7452      return pack_ubyte_x8b8g8r8_snorm;
7453
7454   case MESA_FORMAT_R8G8B8A8_SNORM:
7455      return pack_ubyte_r8g8b8a8_snorm;
7456
7457   case MESA_FORMAT_R8G8B8X8_SNORM:
7458      return pack_ubyte_r8g8b8x8_snorm;
7459
7460   case MESA_FORMAT_R16G16_SNORM:
7461      return pack_ubyte_r16g16_snorm;
7462
7463   case MESA_FORMAT_G16R16_SNORM:
7464      return pack_ubyte_g16r16_snorm;
7465
7466   case MESA_FORMAT_R8G8_SNORM:
7467      return pack_ubyte_r8g8_snorm;
7468
7469   case MESA_FORMAT_G8R8_SNORM:
7470      return pack_ubyte_g8r8_snorm;
7471
7472   case MESA_FORMAT_L8A8_SNORM:
7473      return pack_ubyte_l8a8_snorm;
7474
7475   case MESA_FORMAT_A8L8_SNORM:
7476      return pack_ubyte_a8l8_snorm;
7477
7478   case MESA_FORMAT_A_SNORM8:
7479      return pack_ubyte_a_snorm8;
7480
7481   case MESA_FORMAT_A_SNORM16:
7482      return pack_ubyte_a_snorm16;
7483
7484   case MESA_FORMAT_L_SNORM8:
7485      return pack_ubyte_l_snorm8;
7486
7487   case MESA_FORMAT_L_SNORM16:
7488      return pack_ubyte_l_snorm16;
7489
7490   case MESA_FORMAT_I_SNORM8:
7491      return pack_ubyte_i_snorm8;
7492
7493   case MESA_FORMAT_I_SNORM16:
7494      return pack_ubyte_i_snorm16;
7495
7496   case MESA_FORMAT_R_SNORM8:
7497      return pack_ubyte_r_snorm8;
7498
7499   case MESA_FORMAT_R_SNORM16:
7500      return pack_ubyte_r_snorm16;
7501
7502   case MESA_FORMAT_LA_SNORM16:
7503      return pack_ubyte_la_snorm16;
7504
7505   case MESA_FORMAT_RGB_SNORM16:
7506      return pack_ubyte_rgb_snorm16;
7507
7508   case MESA_FORMAT_RGBA_SNORM16:
7509      return pack_ubyte_rgba_snorm16;
7510
7511   case MESA_FORMAT_RGBX_SNORM16:
7512      return pack_ubyte_rgbx_snorm16;
7513
7514   case MESA_FORMAT_A8B8G8R8_SRGB:
7515      return pack_ubyte_a8b8g8r8_srgb;
7516
7517   case MESA_FORMAT_B8G8R8A8_SRGB:
7518      return pack_ubyte_b8g8r8a8_srgb;
7519
7520   case MESA_FORMAT_A8R8G8B8_SRGB:
7521      return pack_ubyte_a8r8g8b8_srgb;
7522
7523   case MESA_FORMAT_B8G8R8X8_SRGB:
7524      return pack_ubyte_b8g8r8x8_srgb;
7525
7526   case MESA_FORMAT_X8R8G8B8_SRGB:
7527      return pack_ubyte_x8r8g8b8_srgb;
7528
7529   case MESA_FORMAT_R8G8B8A8_SRGB:
7530      return pack_ubyte_r8g8b8a8_srgb;
7531
7532   case MESA_FORMAT_R8G8B8X8_SRGB:
7533      return pack_ubyte_r8g8b8x8_srgb;
7534
7535   case MESA_FORMAT_X8B8G8R8_SRGB:
7536      return pack_ubyte_x8b8g8r8_srgb;
7537
7538   case MESA_FORMAT_L8A8_SRGB:
7539      return pack_ubyte_l8a8_srgb;
7540
7541   case MESA_FORMAT_A8L8_SRGB:
7542      return pack_ubyte_a8l8_srgb;
7543
7544   case MESA_FORMAT_R_SRGB8:
7545      return pack_ubyte_r_srgb8;
7546
7547   case MESA_FORMAT_L_SRGB8:
7548      return pack_ubyte_l_srgb8;
7549
7550   case MESA_FORMAT_BGR_SRGB8:
7551      return pack_ubyte_bgr_srgb8;
7552
7553   case MESA_FORMAT_R9G9B9E5_FLOAT:
7554      return pack_ubyte_r9g9b9e5_float;
7555
7556   case MESA_FORMAT_R11G11B10_FLOAT:
7557      return pack_ubyte_r11g11b10_float;
7558
7559   case MESA_FORMAT_A_FLOAT16:
7560      return pack_ubyte_a_float16;
7561
7562   case MESA_FORMAT_A_FLOAT32:
7563      return pack_ubyte_a_float32;
7564
7565   case MESA_FORMAT_L_FLOAT16:
7566      return pack_ubyte_l_float16;
7567
7568   case MESA_FORMAT_L_FLOAT32:
7569      return pack_ubyte_l_float32;
7570
7571   case MESA_FORMAT_LA_FLOAT16:
7572      return pack_ubyte_la_float16;
7573
7574   case MESA_FORMAT_LA_FLOAT32:
7575      return pack_ubyte_la_float32;
7576
7577   case MESA_FORMAT_I_FLOAT16:
7578      return pack_ubyte_i_float16;
7579
7580   case MESA_FORMAT_I_FLOAT32:
7581      return pack_ubyte_i_float32;
7582
7583   case MESA_FORMAT_R_FLOAT16:
7584      return pack_ubyte_r_float16;
7585
7586   case MESA_FORMAT_R_FLOAT32:
7587      return pack_ubyte_r_float32;
7588
7589   case MESA_FORMAT_RG_FLOAT16:
7590      return pack_ubyte_rg_float16;
7591
7592   case MESA_FORMAT_RG_FLOAT32:
7593      return pack_ubyte_rg_float32;
7594
7595   case MESA_FORMAT_RGB_FLOAT16:
7596      return pack_ubyte_rgb_float16;
7597
7598   case MESA_FORMAT_RGB_FLOAT32:
7599      return pack_ubyte_rgb_float32;
7600
7601   case MESA_FORMAT_RGBA_FLOAT16:
7602      return pack_ubyte_rgba_float16;
7603
7604   case MESA_FORMAT_RGBA_FLOAT32:
7605      return pack_ubyte_rgba_float32;
7606
7607   case MESA_FORMAT_RGBX_FLOAT16:
7608      return pack_ubyte_rgbx_float16;
7609
7610   case MESA_FORMAT_RGBX_FLOAT32:
7611      return pack_ubyte_rgbx_float32;
7612
7613   case MESA_FORMAT_A8B8G8R8_UINT:
7614      return pack_ubyte_a8b8g8r8_uint;
7615
7616   case MESA_FORMAT_A8R8G8B8_UINT:
7617      return pack_ubyte_a8r8g8b8_uint;
7618
7619   case MESA_FORMAT_R8G8B8A8_UINT:
7620      return pack_ubyte_r8g8b8a8_uint;
7621
7622   case MESA_FORMAT_B8G8R8A8_UINT:
7623      return pack_ubyte_b8g8r8a8_uint;
7624
7625   case MESA_FORMAT_B10G10R10A2_UINT:
7626      return pack_ubyte_b10g10r10a2_uint;
7627
7628   case MESA_FORMAT_R10G10B10A2_UINT:
7629      return pack_ubyte_r10g10b10a2_uint;
7630
7631   case MESA_FORMAT_A2B10G10R10_UINT:
7632      return pack_ubyte_a2b10g10r10_uint;
7633
7634   case MESA_FORMAT_A2R10G10B10_UINT:
7635      return pack_ubyte_a2r10g10b10_uint;
7636
7637   case MESA_FORMAT_B5G6R5_UINT:
7638      return pack_ubyte_b5g6r5_uint;
7639
7640   case MESA_FORMAT_R5G6B5_UINT:
7641      return pack_ubyte_r5g6b5_uint;
7642
7643   case MESA_FORMAT_B2G3R3_UINT:
7644      return pack_ubyte_b2g3r3_uint;
7645
7646   case MESA_FORMAT_R3G3B2_UINT:
7647      return pack_ubyte_r3g3b2_uint;
7648
7649   case MESA_FORMAT_A4B4G4R4_UINT:
7650      return pack_ubyte_a4b4g4r4_uint;
7651
7652   case MESA_FORMAT_R4G4B4A4_UINT:
7653      return pack_ubyte_r4g4b4a4_uint;
7654
7655   case MESA_FORMAT_B4G4R4A4_UINT:
7656      return pack_ubyte_b4g4r4a4_uint;
7657
7658   case MESA_FORMAT_A4R4G4B4_UINT:
7659      return pack_ubyte_a4r4g4b4_uint;
7660
7661   case MESA_FORMAT_A1B5G5R5_UINT:
7662      return pack_ubyte_a1b5g5r5_uint;
7663
7664   case MESA_FORMAT_B5G5R5A1_UINT:
7665      return pack_ubyte_b5g5r5a1_uint;
7666
7667   case MESA_FORMAT_A1R5G5B5_UINT:
7668      return pack_ubyte_a1r5g5b5_uint;
7669
7670   case MESA_FORMAT_R5G5B5A1_UINT:
7671      return pack_ubyte_r5g5b5a1_uint;
7672
7673   case MESA_FORMAT_A_UINT8:
7674      return pack_ubyte_a_uint8;
7675
7676   case MESA_FORMAT_A_UINT16:
7677      return pack_ubyte_a_uint16;
7678
7679   case MESA_FORMAT_A_UINT32:
7680      return pack_ubyte_a_uint32;
7681
7682   case MESA_FORMAT_A_SINT8:
7683      return pack_ubyte_a_sint8;
7684
7685   case MESA_FORMAT_A_SINT16:
7686      return pack_ubyte_a_sint16;
7687
7688   case MESA_FORMAT_A_SINT32:
7689      return pack_ubyte_a_sint32;
7690
7691   case MESA_FORMAT_I_UINT8:
7692      return pack_ubyte_i_uint8;
7693
7694   case MESA_FORMAT_I_UINT16:
7695      return pack_ubyte_i_uint16;
7696
7697   case MESA_FORMAT_I_UINT32:
7698      return pack_ubyte_i_uint32;
7699
7700   case MESA_FORMAT_I_SINT8:
7701      return pack_ubyte_i_sint8;
7702
7703   case MESA_FORMAT_I_SINT16:
7704      return pack_ubyte_i_sint16;
7705
7706   case MESA_FORMAT_I_SINT32:
7707      return pack_ubyte_i_sint32;
7708
7709   case MESA_FORMAT_L_UINT8:
7710      return pack_ubyte_l_uint8;
7711
7712   case MESA_FORMAT_L_UINT16:
7713      return pack_ubyte_l_uint16;
7714
7715   case MESA_FORMAT_L_UINT32:
7716      return pack_ubyte_l_uint32;
7717
7718   case MESA_FORMAT_L_SINT8:
7719      return pack_ubyte_l_sint8;
7720
7721   case MESA_FORMAT_L_SINT16:
7722      return pack_ubyte_l_sint16;
7723
7724   case MESA_FORMAT_L_SINT32:
7725      return pack_ubyte_l_sint32;
7726
7727   case MESA_FORMAT_LA_UINT8:
7728      return pack_ubyte_la_uint8;
7729
7730   case MESA_FORMAT_LA_UINT16:
7731      return pack_ubyte_la_uint16;
7732
7733   case MESA_FORMAT_LA_UINT32:
7734      return pack_ubyte_la_uint32;
7735
7736   case MESA_FORMAT_LA_SINT8:
7737      return pack_ubyte_la_sint8;
7738
7739   case MESA_FORMAT_LA_SINT16:
7740      return pack_ubyte_la_sint16;
7741
7742   case MESA_FORMAT_LA_SINT32:
7743      return pack_ubyte_la_sint32;
7744
7745   case MESA_FORMAT_R_UINT8:
7746      return pack_ubyte_r_uint8;
7747
7748   case MESA_FORMAT_R_UINT16:
7749      return pack_ubyte_r_uint16;
7750
7751   case MESA_FORMAT_R_UINT32:
7752      return pack_ubyte_r_uint32;
7753
7754   case MESA_FORMAT_R_SINT8:
7755      return pack_ubyte_r_sint8;
7756
7757   case MESA_FORMAT_R_SINT16:
7758      return pack_ubyte_r_sint16;
7759
7760   case MESA_FORMAT_R_SINT32:
7761      return pack_ubyte_r_sint32;
7762
7763   case MESA_FORMAT_RG_UINT8:
7764      return pack_ubyte_rg_uint8;
7765
7766   case MESA_FORMAT_RG_UINT16:
7767      return pack_ubyte_rg_uint16;
7768
7769   case MESA_FORMAT_RG_UINT32:
7770      return pack_ubyte_rg_uint32;
7771
7772   case MESA_FORMAT_RG_SINT8:
7773      return pack_ubyte_rg_sint8;
7774
7775   case MESA_FORMAT_RG_SINT16:
7776      return pack_ubyte_rg_sint16;
7777
7778   case MESA_FORMAT_RG_SINT32:
7779      return pack_ubyte_rg_sint32;
7780
7781   case MESA_FORMAT_RGB_UINT8:
7782      return pack_ubyte_rgb_uint8;
7783
7784   case MESA_FORMAT_RGB_UINT16:
7785      return pack_ubyte_rgb_uint16;
7786
7787   case MESA_FORMAT_RGB_UINT32:
7788      return pack_ubyte_rgb_uint32;
7789
7790   case MESA_FORMAT_RGB_SINT8:
7791      return pack_ubyte_rgb_sint8;
7792
7793   case MESA_FORMAT_RGB_SINT16:
7794      return pack_ubyte_rgb_sint16;
7795
7796   case MESA_FORMAT_RGB_SINT32:
7797      return pack_ubyte_rgb_sint32;
7798
7799   case MESA_FORMAT_RGBA_UINT8:
7800      return pack_ubyte_rgba_uint8;
7801
7802   case MESA_FORMAT_RGBA_UINT16:
7803      return pack_ubyte_rgba_uint16;
7804
7805   case MESA_FORMAT_RGBA_UINT32:
7806      return pack_ubyte_rgba_uint32;
7807
7808   case MESA_FORMAT_RGBA_SINT8:
7809      return pack_ubyte_rgba_sint8;
7810
7811   case MESA_FORMAT_RGBA_SINT16:
7812      return pack_ubyte_rgba_sint16;
7813
7814   case MESA_FORMAT_RGBA_SINT32:
7815      return pack_ubyte_rgba_sint32;
7816
7817   case MESA_FORMAT_RGBX_UINT8:
7818      return pack_ubyte_rgbx_uint8;
7819
7820   case MESA_FORMAT_RGBX_UINT16:
7821      return pack_ubyte_rgbx_uint16;
7822
7823   case MESA_FORMAT_RGBX_UINT32:
7824      return pack_ubyte_rgbx_uint32;
7825
7826   case MESA_FORMAT_RGBX_SINT8:
7827      return pack_ubyte_rgbx_sint8;
7828
7829   case MESA_FORMAT_RGBX_SINT16:
7830      return pack_ubyte_rgbx_sint16;
7831
7832   case MESA_FORMAT_RGBX_SINT32:
7833      return pack_ubyte_rgbx_sint32;
7834                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           default:
7835      return NULL;
7836   }
7837}
7838
7839/**
7840 * Return a function that can pack a GLfloat rgba[4] color.
7841 */
7842gl_pack_float_rgba_func
7843_mesa_get_pack_float_rgba_function(mesa_format format)
7844{
7845   switch (format) {
7846
7847   case MESA_FORMAT_A8B8G8R8_UNORM:
7848      return pack_float_a8b8g8r8_unorm;
7849
7850   case MESA_FORMAT_X8B8G8R8_UNORM:
7851      return pack_float_x8b8g8r8_unorm;
7852
7853   case MESA_FORMAT_R8G8B8A8_UNORM:
7854      return pack_float_r8g8b8a8_unorm;
7855
7856   case MESA_FORMAT_R8G8B8X8_UNORM:
7857      return pack_float_r8g8b8x8_unorm;
7858
7859   case MESA_FORMAT_B8G8R8A8_UNORM:
7860      return pack_float_b8g8r8a8_unorm;
7861
7862   case MESA_FORMAT_B8G8R8X8_UNORM:
7863      return pack_float_b8g8r8x8_unorm;
7864
7865   case MESA_FORMAT_A8R8G8B8_UNORM:
7866      return pack_float_a8r8g8b8_unorm;
7867
7868   case MESA_FORMAT_X8R8G8B8_UNORM:
7869      return pack_float_x8r8g8b8_unorm;
7870
7871   case MESA_FORMAT_L16A16_UNORM:
7872      return pack_float_l16a16_unorm;
7873
7874   case MESA_FORMAT_A16L16_UNORM:
7875      return pack_float_a16l16_unorm;
7876
7877   case MESA_FORMAT_B5G6R5_UNORM:
7878      return pack_float_b5g6r5_unorm;
7879
7880   case MESA_FORMAT_R5G6B5_UNORM:
7881      return pack_float_r5g6b5_unorm;
7882
7883   case MESA_FORMAT_B4G4R4A4_UNORM:
7884      return pack_float_b4g4r4a4_unorm;
7885
7886   case MESA_FORMAT_B4G4R4X4_UNORM:
7887      return pack_float_b4g4r4x4_unorm;
7888
7889   case MESA_FORMAT_A4R4G4B4_UNORM:
7890      return pack_float_a4r4g4b4_unorm;
7891
7892   case MESA_FORMAT_A1B5G5R5_UNORM:
7893      return pack_float_a1b5g5r5_unorm;
7894
7895   case MESA_FORMAT_X1B5G5R5_UNORM:
7896      return pack_float_x1b5g5r5_unorm;
7897
7898   case MESA_FORMAT_B5G5R5A1_UNORM:
7899      return pack_float_b5g5r5a1_unorm;
7900
7901   case MESA_FORMAT_B5G5R5X1_UNORM:
7902      return pack_float_b5g5r5x1_unorm;
7903
7904   case MESA_FORMAT_A1R5G5B5_UNORM:
7905      return pack_float_a1r5g5b5_unorm;
7906
7907   case MESA_FORMAT_L8A8_UNORM:
7908      return pack_float_l8a8_unorm;
7909
7910   case MESA_FORMAT_A8L8_UNORM:
7911      return pack_float_a8l8_unorm;
7912
7913   case MESA_FORMAT_R8G8_UNORM:
7914      return pack_float_r8g8_unorm;
7915
7916   case MESA_FORMAT_G8R8_UNORM:
7917      return pack_float_g8r8_unorm;
7918
7919   case MESA_FORMAT_L4A4_UNORM:
7920      return pack_float_l4a4_unorm;
7921
7922   case MESA_FORMAT_B2G3R3_UNORM:
7923      return pack_float_b2g3r3_unorm;
7924
7925   case MESA_FORMAT_R16G16_UNORM:
7926      return pack_float_r16g16_unorm;
7927
7928   case MESA_FORMAT_G16R16_UNORM:
7929      return pack_float_g16r16_unorm;
7930
7931   case MESA_FORMAT_B10G10R10A2_UNORM:
7932      return pack_float_b10g10r10a2_unorm;
7933
7934   case MESA_FORMAT_B10G10R10X2_UNORM:
7935      return pack_float_b10g10r10x2_unorm;
7936
7937   case MESA_FORMAT_R10G10B10A2_UNORM:
7938      return pack_float_r10g10b10a2_unorm;
7939
7940   case MESA_FORMAT_R10G10B10X2_UNORM:
7941      return pack_float_r10g10b10x2_unorm;
7942
7943   case MESA_FORMAT_R3G3B2_UNORM:
7944      return pack_float_r3g3b2_unorm;
7945
7946   case MESA_FORMAT_A4B4G4R4_UNORM:
7947      return pack_float_a4b4g4r4_unorm;
7948
7949   case MESA_FORMAT_R4G4B4A4_UNORM:
7950      return pack_float_r4g4b4a4_unorm;
7951
7952   case MESA_FORMAT_R5G5B5A1_UNORM:
7953      return pack_float_r5g5b5a1_unorm;
7954
7955   case MESA_FORMAT_A2B10G10R10_UNORM:
7956      return pack_float_a2b10g10r10_unorm;
7957
7958   case MESA_FORMAT_A2R10G10B10_UNORM:
7959      return pack_float_a2r10g10b10_unorm;
7960
7961   case MESA_FORMAT_A_UNORM8:
7962      return pack_float_a_unorm8;
7963
7964   case MESA_FORMAT_A_UNORM16:
7965      return pack_float_a_unorm16;
7966
7967   case MESA_FORMAT_L_UNORM8:
7968      return pack_float_l_unorm8;
7969
7970   case MESA_FORMAT_L_UNORM16:
7971      return pack_float_l_unorm16;
7972
7973   case MESA_FORMAT_I_UNORM8:
7974      return pack_float_i_unorm8;
7975
7976   case MESA_FORMAT_I_UNORM16:
7977      return pack_float_i_unorm16;
7978
7979   case MESA_FORMAT_R_UNORM8:
7980      return pack_float_r_unorm8;
7981
7982   case MESA_FORMAT_R_UNORM16:
7983      return pack_float_r_unorm16;
7984
7985   case MESA_FORMAT_BGR_UNORM8:
7986      return pack_float_bgr_unorm8;
7987
7988   case MESA_FORMAT_RGB_UNORM8:
7989      return pack_float_rgb_unorm8;
7990
7991   case MESA_FORMAT_RGBA_UNORM16:
7992      return pack_float_rgba_unorm16;
7993
7994   case MESA_FORMAT_RGBX_UNORM16:
7995      return pack_float_rgbx_unorm16;
7996
7997   case MESA_FORMAT_A8B8G8R8_SNORM:
7998      return pack_float_a8b8g8r8_snorm;
7999
8000   case MESA_FORMAT_X8B8G8R8_SNORM:
8001      return pack_float_x8b8g8r8_snorm;
8002
8003   case MESA_FORMAT_R8G8B8A8_SNORM:
8004      return pack_float_r8g8b8a8_snorm;
8005
8006   case MESA_FORMAT_R8G8B8X8_SNORM:
8007      return pack_float_r8g8b8x8_snorm;
8008
8009   case MESA_FORMAT_R16G16_SNORM:
8010      return pack_float_r16g16_snorm;
8011
8012   case MESA_FORMAT_G16R16_SNORM:
8013      return pack_float_g16r16_snorm;
8014
8015   case MESA_FORMAT_R8G8_SNORM:
8016      return pack_float_r8g8_snorm;
8017
8018   case MESA_FORMAT_G8R8_SNORM:
8019      return pack_float_g8r8_snorm;
8020
8021   case MESA_FORMAT_L8A8_SNORM:
8022      return pack_float_l8a8_snorm;
8023
8024   case MESA_FORMAT_A8L8_SNORM:
8025      return pack_float_a8l8_snorm;
8026
8027   case MESA_FORMAT_A_SNORM8:
8028      return pack_float_a_snorm8;
8029
8030   case MESA_FORMAT_A_SNORM16:
8031      return pack_float_a_snorm16;
8032
8033   case MESA_FORMAT_L_SNORM8:
8034      return pack_float_l_snorm8;
8035
8036   case MESA_FORMAT_L_SNORM16:
8037      return pack_float_l_snorm16;
8038
8039   case MESA_FORMAT_I_SNORM8:
8040      return pack_float_i_snorm8;
8041
8042   case MESA_FORMAT_I_SNORM16:
8043      return pack_float_i_snorm16;
8044
8045   case MESA_FORMAT_R_SNORM8:
8046      return pack_float_r_snorm8;
8047
8048   case MESA_FORMAT_R_SNORM16:
8049      return pack_float_r_snorm16;
8050
8051   case MESA_FORMAT_LA_SNORM16:
8052      return pack_float_la_snorm16;
8053
8054   case MESA_FORMAT_RGB_SNORM16:
8055      return pack_float_rgb_snorm16;
8056
8057   case MESA_FORMAT_RGBA_SNORM16:
8058      return pack_float_rgba_snorm16;
8059
8060   case MESA_FORMAT_RGBX_SNORM16:
8061      return pack_float_rgbx_snorm16;
8062
8063   case MESA_FORMAT_A8B8G8R8_SRGB:
8064      return pack_float_a8b8g8r8_srgb;
8065
8066   case MESA_FORMAT_B8G8R8A8_SRGB:
8067      return pack_float_b8g8r8a8_srgb;
8068
8069   case MESA_FORMAT_A8R8G8B8_SRGB:
8070      return pack_float_a8r8g8b8_srgb;
8071
8072   case MESA_FORMAT_B8G8R8X8_SRGB:
8073      return pack_float_b8g8r8x8_srgb;
8074
8075   case MESA_FORMAT_X8R8G8B8_SRGB:
8076      return pack_float_x8r8g8b8_srgb;
8077
8078   case MESA_FORMAT_R8G8B8A8_SRGB:
8079      return pack_float_r8g8b8a8_srgb;
8080
8081   case MESA_FORMAT_R8G8B8X8_SRGB:
8082      return pack_float_r8g8b8x8_srgb;
8083
8084   case MESA_FORMAT_X8B8G8R8_SRGB:
8085      return pack_float_x8b8g8r8_srgb;
8086
8087   case MESA_FORMAT_L8A8_SRGB:
8088      return pack_float_l8a8_srgb;
8089
8090   case MESA_FORMAT_A8L8_SRGB:
8091      return pack_float_a8l8_srgb;
8092
8093   case MESA_FORMAT_R_SRGB8:
8094      return pack_float_r_srgb8;
8095
8096   case MESA_FORMAT_L_SRGB8:
8097      return pack_float_l_srgb8;
8098
8099   case MESA_FORMAT_BGR_SRGB8:
8100      return pack_float_bgr_srgb8;
8101
8102   case MESA_FORMAT_R9G9B9E5_FLOAT:
8103      return pack_float_r9g9b9e5_float;
8104
8105   case MESA_FORMAT_R11G11B10_FLOAT:
8106      return pack_float_r11g11b10_float;
8107
8108   case MESA_FORMAT_A_FLOAT16:
8109      return pack_float_a_float16;
8110
8111   case MESA_FORMAT_A_FLOAT32:
8112      return pack_float_a_float32;
8113
8114   case MESA_FORMAT_L_FLOAT16:
8115      return pack_float_l_float16;
8116
8117   case MESA_FORMAT_L_FLOAT32:
8118      return pack_float_l_float32;
8119
8120   case MESA_FORMAT_LA_FLOAT16:
8121      return pack_float_la_float16;
8122
8123   case MESA_FORMAT_LA_FLOAT32:
8124      return pack_float_la_float32;
8125
8126   case MESA_FORMAT_I_FLOAT16:
8127      return pack_float_i_float16;
8128
8129   case MESA_FORMAT_I_FLOAT32:
8130      return pack_float_i_float32;
8131
8132   case MESA_FORMAT_R_FLOAT16:
8133      return pack_float_r_float16;
8134
8135   case MESA_FORMAT_R_FLOAT32:
8136      return pack_float_r_float32;
8137
8138   case MESA_FORMAT_RG_FLOAT16:
8139      return pack_float_rg_float16;
8140
8141   case MESA_FORMAT_RG_FLOAT32:
8142      return pack_float_rg_float32;
8143
8144   case MESA_FORMAT_RGB_FLOAT16:
8145      return pack_float_rgb_float16;
8146
8147   case MESA_FORMAT_RGB_FLOAT32:
8148      return pack_float_rgb_float32;
8149
8150   case MESA_FORMAT_RGBA_FLOAT16:
8151      return pack_float_rgba_float16;
8152
8153   case MESA_FORMAT_RGBA_FLOAT32:
8154      return pack_float_rgba_float32;
8155
8156   case MESA_FORMAT_RGBX_FLOAT16:
8157      return pack_float_rgbx_float16;
8158
8159   case MESA_FORMAT_RGBX_FLOAT32:
8160      return pack_float_rgbx_float32;
8161                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       default:
8162      return NULL;
8163   }
8164}
8165
8166/**
8167 * Pack a row of GLubyte rgba[4] values to the destination.
8168 */
8169void
8170_mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n,
8171                          const GLubyte src[][4], void *dst)
8172{
8173   GLuint i;
8174   GLubyte *d = dst;
8175
8176   switch (format) {
8177
8178   case MESA_FORMAT_A8B8G8R8_UNORM:
8179      for (i = 0; i < n; ++i) {
8180         pack_ubyte_a8b8g8r8_unorm(src[i], d);
8181         d += 4;
8182      }
8183      break;
8184
8185   case MESA_FORMAT_X8B8G8R8_UNORM:
8186      for (i = 0; i < n; ++i) {
8187         pack_ubyte_x8b8g8r8_unorm(src[i], d);
8188         d += 4;
8189      }
8190      break;
8191
8192   case MESA_FORMAT_R8G8B8A8_UNORM:
8193      for (i = 0; i < n; ++i) {
8194         pack_ubyte_r8g8b8a8_unorm(src[i], d);
8195         d += 4;
8196      }
8197      break;
8198
8199   case MESA_FORMAT_R8G8B8X8_UNORM:
8200      for (i = 0; i < n; ++i) {
8201         pack_ubyte_r8g8b8x8_unorm(src[i], d);
8202         d += 4;
8203      }
8204      break;
8205
8206   case MESA_FORMAT_B8G8R8A8_UNORM:
8207      for (i = 0; i < n; ++i) {
8208         pack_ubyte_b8g8r8a8_unorm(src[i], d);
8209         d += 4;
8210      }
8211      break;
8212
8213   case MESA_FORMAT_B8G8R8X8_UNORM:
8214      for (i = 0; i < n; ++i) {
8215         pack_ubyte_b8g8r8x8_unorm(src[i], d);
8216         d += 4;
8217      }
8218      break;
8219
8220   case MESA_FORMAT_A8R8G8B8_UNORM:
8221      for (i = 0; i < n; ++i) {
8222         pack_ubyte_a8r8g8b8_unorm(src[i], d);
8223         d += 4;
8224      }
8225      break;
8226
8227   case MESA_FORMAT_X8R8G8B8_UNORM:
8228      for (i = 0; i < n; ++i) {
8229         pack_ubyte_x8r8g8b8_unorm(src[i], d);
8230         d += 4;
8231      }
8232      break;
8233
8234   case MESA_FORMAT_L16A16_UNORM:
8235      for (i = 0; i < n; ++i) {
8236         pack_ubyte_l16a16_unorm(src[i], d);
8237         d += 4;
8238      }
8239      break;
8240
8241   case MESA_FORMAT_A16L16_UNORM:
8242      for (i = 0; i < n; ++i) {
8243         pack_ubyte_a16l16_unorm(src[i], d);
8244         d += 4;
8245      }
8246      break;
8247
8248   case MESA_FORMAT_B5G6R5_UNORM:
8249      for (i = 0; i < n; ++i) {
8250         pack_ubyte_b5g6r5_unorm(src[i], d);
8251         d += 2;
8252      }
8253      break;
8254
8255   case MESA_FORMAT_R5G6B5_UNORM:
8256      for (i = 0; i < n; ++i) {
8257         pack_ubyte_r5g6b5_unorm(src[i], d);
8258         d += 2;
8259      }
8260      break;
8261
8262   case MESA_FORMAT_B4G4R4A4_UNORM:
8263      for (i = 0; i < n; ++i) {
8264         pack_ubyte_b4g4r4a4_unorm(src[i], d);
8265         d += 2;
8266      }
8267      break;
8268
8269   case MESA_FORMAT_B4G4R4X4_UNORM:
8270      for (i = 0; i < n; ++i) {
8271         pack_ubyte_b4g4r4x4_unorm(src[i], d);
8272         d += 2;
8273      }
8274      break;
8275
8276   case MESA_FORMAT_A4R4G4B4_UNORM:
8277      for (i = 0; i < n; ++i) {
8278         pack_ubyte_a4r4g4b4_unorm(src[i], d);
8279         d += 2;
8280      }
8281      break;
8282
8283   case MESA_FORMAT_A1B5G5R5_UNORM:
8284      for (i = 0; i < n; ++i) {
8285         pack_ubyte_a1b5g5r5_unorm(src[i], d);
8286         d += 2;
8287      }
8288      break;
8289
8290   case MESA_FORMAT_X1B5G5R5_UNORM:
8291      for (i = 0; i < n; ++i) {
8292         pack_ubyte_x1b5g5r5_unorm(src[i], d);
8293         d += 2;
8294      }
8295      break;
8296
8297   case MESA_FORMAT_B5G5R5A1_UNORM:
8298      for (i = 0; i < n; ++i) {
8299         pack_ubyte_b5g5r5a1_unorm(src[i], d);
8300         d += 2;
8301      }
8302      break;
8303
8304   case MESA_FORMAT_B5G5R5X1_UNORM:
8305      for (i = 0; i < n; ++i) {
8306         pack_ubyte_b5g5r5x1_unorm(src[i], d);
8307         d += 2;
8308      }
8309      break;
8310
8311   case MESA_FORMAT_A1R5G5B5_UNORM:
8312      for (i = 0; i < n; ++i) {
8313         pack_ubyte_a1r5g5b5_unorm(src[i], d);
8314         d += 2;
8315      }
8316      break;
8317
8318   case MESA_FORMAT_L8A8_UNORM:
8319      for (i = 0; i < n; ++i) {
8320         pack_ubyte_l8a8_unorm(src[i], d);
8321         d += 2;
8322      }
8323      break;
8324
8325   case MESA_FORMAT_A8L8_UNORM:
8326      for (i = 0; i < n; ++i) {
8327         pack_ubyte_a8l8_unorm(src[i], d);
8328         d += 2;
8329      }
8330      break;
8331
8332   case MESA_FORMAT_R8G8_UNORM:
8333      for (i = 0; i < n; ++i) {
8334         pack_ubyte_r8g8_unorm(src[i], d);
8335         d += 2;
8336      }
8337      break;
8338
8339   case MESA_FORMAT_G8R8_UNORM:
8340      for (i = 0; i < n; ++i) {
8341         pack_ubyte_g8r8_unorm(src[i], d);
8342         d += 2;
8343      }
8344      break;
8345
8346   case MESA_FORMAT_L4A4_UNORM:
8347      for (i = 0; i < n; ++i) {
8348         pack_ubyte_l4a4_unorm(src[i], d);
8349         d += 1;
8350      }
8351      break;
8352
8353   case MESA_FORMAT_B2G3R3_UNORM:
8354      for (i = 0; i < n; ++i) {
8355         pack_ubyte_b2g3r3_unorm(src[i], d);
8356         d += 1;
8357      }
8358      break;
8359
8360   case MESA_FORMAT_R16G16_UNORM:
8361      for (i = 0; i < n; ++i) {
8362         pack_ubyte_r16g16_unorm(src[i], d);
8363         d += 4;
8364      }
8365      break;
8366
8367   case MESA_FORMAT_G16R16_UNORM:
8368      for (i = 0; i < n; ++i) {
8369         pack_ubyte_g16r16_unorm(src[i], d);
8370         d += 4;
8371      }
8372      break;
8373
8374   case MESA_FORMAT_B10G10R10A2_UNORM:
8375      for (i = 0; i < n; ++i) {
8376         pack_ubyte_b10g10r10a2_unorm(src[i], d);
8377         d += 4;
8378      }
8379      break;
8380
8381   case MESA_FORMAT_B10G10R10X2_UNORM:
8382      for (i = 0; i < n; ++i) {
8383         pack_ubyte_b10g10r10x2_unorm(src[i], d);
8384         d += 4;
8385      }
8386      break;
8387
8388   case MESA_FORMAT_R10G10B10A2_UNORM:
8389      for (i = 0; i < n; ++i) {
8390         pack_ubyte_r10g10b10a2_unorm(src[i], d);
8391         d += 4;
8392      }
8393      break;
8394
8395   case MESA_FORMAT_R10G10B10X2_UNORM:
8396      for (i = 0; i < n; ++i) {
8397         pack_ubyte_r10g10b10x2_unorm(src[i], d);
8398         d += 4;
8399      }
8400      break;
8401
8402   case MESA_FORMAT_R3G3B2_UNORM:
8403      for (i = 0; i < n; ++i) {
8404         pack_ubyte_r3g3b2_unorm(src[i], d);
8405         d += 1;
8406      }
8407      break;
8408
8409   case MESA_FORMAT_A4B4G4R4_UNORM:
8410      for (i = 0; i < n; ++i) {
8411         pack_ubyte_a4b4g4r4_unorm(src[i], d);
8412         d += 2;
8413      }
8414      break;
8415
8416   case MESA_FORMAT_R4G4B4A4_UNORM:
8417      for (i = 0; i < n; ++i) {
8418         pack_ubyte_r4g4b4a4_unorm(src[i], d);
8419         d += 2;
8420      }
8421      break;
8422
8423   case MESA_FORMAT_R5G5B5A1_UNORM:
8424      for (i = 0; i < n; ++i) {
8425         pack_ubyte_r5g5b5a1_unorm(src[i], d);
8426         d += 2;
8427      }
8428      break;
8429
8430   case MESA_FORMAT_A2B10G10R10_UNORM:
8431      for (i = 0; i < n; ++i) {
8432         pack_ubyte_a2b10g10r10_unorm(src[i], d);
8433         d += 4;
8434      }
8435      break;
8436
8437   case MESA_FORMAT_A2R10G10B10_UNORM:
8438      for (i = 0; i < n; ++i) {
8439         pack_ubyte_a2r10g10b10_unorm(src[i], d);
8440         d += 4;
8441      }
8442      break;
8443
8444   case MESA_FORMAT_A_UNORM8:
8445      for (i = 0; i < n; ++i) {
8446         pack_ubyte_a_unorm8(src[i], d);
8447         d += 1;
8448      }
8449      break;
8450
8451   case MESA_FORMAT_A_UNORM16:
8452      for (i = 0; i < n; ++i) {
8453         pack_ubyte_a_unorm16(src[i], d);
8454         d += 2;
8455      }
8456      break;
8457
8458   case MESA_FORMAT_L_UNORM8:
8459      for (i = 0; i < n; ++i) {
8460         pack_ubyte_l_unorm8(src[i], d);
8461         d += 1;
8462      }
8463      break;
8464
8465   case MESA_FORMAT_L_UNORM16:
8466      for (i = 0; i < n; ++i) {
8467         pack_ubyte_l_unorm16(src[i], d);
8468         d += 2;
8469      }
8470      break;
8471
8472   case MESA_FORMAT_I_UNORM8:
8473      for (i = 0; i < n; ++i) {
8474         pack_ubyte_i_unorm8(src[i], d);
8475         d += 1;
8476      }
8477      break;
8478
8479   case MESA_FORMAT_I_UNORM16:
8480      for (i = 0; i < n; ++i) {
8481         pack_ubyte_i_unorm16(src[i], d);
8482         d += 2;
8483      }
8484      break;
8485
8486   case MESA_FORMAT_R_UNORM8:
8487      for (i = 0; i < n; ++i) {
8488         pack_ubyte_r_unorm8(src[i], d);
8489         d += 1;
8490      }
8491      break;
8492
8493   case MESA_FORMAT_R_UNORM16:
8494      for (i = 0; i < n; ++i) {
8495         pack_ubyte_r_unorm16(src[i], d);
8496         d += 2;
8497      }
8498      break;
8499
8500   case MESA_FORMAT_BGR_UNORM8:
8501      for (i = 0; i < n; ++i) {
8502         pack_ubyte_bgr_unorm8(src[i], d);
8503         d += 3;
8504      }
8505      break;
8506
8507   case MESA_FORMAT_RGB_UNORM8:
8508      for (i = 0; i < n; ++i) {
8509         pack_ubyte_rgb_unorm8(src[i], d);
8510         d += 3;
8511      }
8512      break;
8513
8514   case MESA_FORMAT_RGBA_UNORM16:
8515      for (i = 0; i < n; ++i) {
8516         pack_ubyte_rgba_unorm16(src[i], d);
8517         d += 8;
8518      }
8519      break;
8520
8521   case MESA_FORMAT_RGBX_UNORM16:
8522      for (i = 0; i < n; ++i) {
8523         pack_ubyte_rgbx_unorm16(src[i], d);
8524         d += 8;
8525      }
8526      break;
8527
8528   case MESA_FORMAT_A8B8G8R8_SNORM:
8529      for (i = 0; i < n; ++i) {
8530         pack_ubyte_a8b8g8r8_snorm(src[i], d);
8531         d += 4;
8532      }
8533      break;
8534
8535   case MESA_FORMAT_X8B8G8R8_SNORM:
8536      for (i = 0; i < n; ++i) {
8537         pack_ubyte_x8b8g8r8_snorm(src[i], d);
8538         d += 4;
8539      }
8540      break;
8541
8542   case MESA_FORMAT_R8G8B8A8_SNORM:
8543      for (i = 0; i < n; ++i) {
8544         pack_ubyte_r8g8b8a8_snorm(src[i], d);
8545         d += 4;
8546      }
8547      break;
8548
8549   case MESA_FORMAT_R8G8B8X8_SNORM:
8550      for (i = 0; i < n; ++i) {
8551         pack_ubyte_r8g8b8x8_snorm(src[i], d);
8552         d += 4;
8553      }
8554      break;
8555
8556   case MESA_FORMAT_R16G16_SNORM:
8557      for (i = 0; i < n; ++i) {
8558         pack_ubyte_r16g16_snorm(src[i], d);
8559         d += 4;
8560      }
8561      break;
8562
8563   case MESA_FORMAT_G16R16_SNORM:
8564      for (i = 0; i < n; ++i) {
8565         pack_ubyte_g16r16_snorm(src[i], d);
8566         d += 4;
8567      }
8568      break;
8569
8570   case MESA_FORMAT_R8G8_SNORM:
8571      for (i = 0; i < n; ++i) {
8572         pack_ubyte_r8g8_snorm(src[i], d);
8573         d += 2;
8574      }
8575      break;
8576
8577   case MESA_FORMAT_G8R8_SNORM:
8578      for (i = 0; i < n; ++i) {
8579         pack_ubyte_g8r8_snorm(src[i], d);
8580         d += 2;
8581      }
8582      break;
8583
8584   case MESA_FORMAT_L8A8_SNORM:
8585      for (i = 0; i < n; ++i) {
8586         pack_ubyte_l8a8_snorm(src[i], d);
8587         d += 2;
8588      }
8589      break;
8590
8591   case MESA_FORMAT_A8L8_SNORM:
8592      for (i = 0; i < n; ++i) {
8593         pack_ubyte_a8l8_snorm(src[i], d);
8594         d += 2;
8595      }
8596      break;
8597
8598   case MESA_FORMAT_A_SNORM8:
8599      for (i = 0; i < n; ++i) {
8600         pack_ubyte_a_snorm8(src[i], d);
8601         d += 1;
8602      }
8603      break;
8604
8605   case MESA_FORMAT_A_SNORM16:
8606      for (i = 0; i < n; ++i) {
8607         pack_ubyte_a_snorm16(src[i], d);
8608         d += 2;
8609      }
8610      break;
8611
8612   case MESA_FORMAT_L_SNORM8:
8613      for (i = 0; i < n; ++i) {
8614         pack_ubyte_l_snorm8(src[i], d);
8615         d += 1;
8616      }
8617      break;
8618
8619   case MESA_FORMAT_L_SNORM16:
8620      for (i = 0; i < n; ++i) {
8621         pack_ubyte_l_snorm16(src[i], d);
8622         d += 2;
8623      }
8624      break;
8625
8626   case MESA_FORMAT_I_SNORM8:
8627      for (i = 0; i < n; ++i) {
8628         pack_ubyte_i_snorm8(src[i], d);
8629         d += 1;
8630      }
8631      break;
8632
8633   case MESA_FORMAT_I_SNORM16:
8634      for (i = 0; i < n; ++i) {
8635         pack_ubyte_i_snorm16(src[i], d);
8636         d += 2;
8637      }
8638      break;
8639
8640   case MESA_FORMAT_R_SNORM8:
8641      for (i = 0; i < n; ++i) {
8642         pack_ubyte_r_snorm8(src[i], d);
8643         d += 1;
8644      }
8645      break;
8646
8647   case MESA_FORMAT_R_SNORM16:
8648      for (i = 0; i < n; ++i) {
8649         pack_ubyte_r_snorm16(src[i], d);
8650         d += 2;
8651      }
8652      break;
8653
8654   case MESA_FORMAT_LA_SNORM16:
8655      for (i = 0; i < n; ++i) {
8656         pack_ubyte_la_snorm16(src[i], d);
8657         d += 4;
8658      }
8659      break;
8660
8661   case MESA_FORMAT_RGB_SNORM16:
8662      for (i = 0; i < n; ++i) {
8663         pack_ubyte_rgb_snorm16(src[i], d);
8664         d += 6;
8665      }
8666      break;
8667
8668   case MESA_FORMAT_RGBA_SNORM16:
8669      for (i = 0; i < n; ++i) {
8670         pack_ubyte_rgba_snorm16(src[i], d);
8671         d += 8;
8672      }
8673      break;
8674
8675   case MESA_FORMAT_RGBX_SNORM16:
8676      for (i = 0; i < n; ++i) {
8677         pack_ubyte_rgbx_snorm16(src[i], d);
8678         d += 8;
8679      }
8680      break;
8681
8682   case MESA_FORMAT_A8B8G8R8_SRGB:
8683      for (i = 0; i < n; ++i) {
8684         pack_ubyte_a8b8g8r8_srgb(src[i], d);
8685         d += 4;
8686      }
8687      break;
8688
8689   case MESA_FORMAT_B8G8R8A8_SRGB:
8690      for (i = 0; i < n; ++i) {
8691         pack_ubyte_b8g8r8a8_srgb(src[i], d);
8692         d += 4;
8693      }
8694      break;
8695
8696   case MESA_FORMAT_A8R8G8B8_SRGB:
8697      for (i = 0; i < n; ++i) {
8698         pack_ubyte_a8r8g8b8_srgb(src[i], d);
8699         d += 4;
8700      }
8701      break;
8702
8703   case MESA_FORMAT_B8G8R8X8_SRGB:
8704      for (i = 0; i < n; ++i) {
8705         pack_ubyte_b8g8r8x8_srgb(src[i], d);
8706         d += 4;
8707      }
8708      break;
8709
8710   case MESA_FORMAT_X8R8G8B8_SRGB:
8711      for (i = 0; i < n; ++i) {
8712         pack_ubyte_x8r8g8b8_srgb(src[i], d);
8713         d += 4;
8714      }
8715      break;
8716
8717   case MESA_FORMAT_R8G8B8A8_SRGB:
8718      for (i = 0; i < n; ++i) {
8719         pack_ubyte_r8g8b8a8_srgb(src[i], d);
8720         d += 4;
8721      }
8722      break;
8723
8724   case MESA_FORMAT_R8G8B8X8_SRGB:
8725      for (i = 0; i < n; ++i) {
8726         pack_ubyte_r8g8b8x8_srgb(src[i], d);
8727         d += 4;
8728      }
8729      break;
8730
8731   case MESA_FORMAT_X8B8G8R8_SRGB:
8732      for (i = 0; i < n; ++i) {
8733         pack_ubyte_x8b8g8r8_srgb(src[i], d);
8734         d += 4;
8735      }
8736      break;
8737
8738   case MESA_FORMAT_L8A8_SRGB:
8739      for (i = 0; i < n; ++i) {
8740         pack_ubyte_l8a8_srgb(src[i], d);
8741         d += 2;
8742      }
8743      break;
8744
8745   case MESA_FORMAT_A8L8_SRGB:
8746      for (i = 0; i < n; ++i) {
8747         pack_ubyte_a8l8_srgb(src[i], d);
8748         d += 2;
8749      }
8750      break;
8751
8752   case MESA_FORMAT_R_SRGB8:
8753      for (i = 0; i < n; ++i) {
8754         pack_ubyte_r_srgb8(src[i], d);
8755         d += 1;
8756      }
8757      break;
8758
8759   case MESA_FORMAT_L_SRGB8:
8760      for (i = 0; i < n; ++i) {
8761         pack_ubyte_l_srgb8(src[i], d);
8762         d += 1;
8763      }
8764      break;
8765
8766   case MESA_FORMAT_BGR_SRGB8:
8767      for (i = 0; i < n; ++i) {
8768         pack_ubyte_bgr_srgb8(src[i], d);
8769         d += 3;
8770      }
8771      break;
8772
8773   case MESA_FORMAT_R9G9B9E5_FLOAT:
8774      for (i = 0; i < n; ++i) {
8775         pack_ubyte_r9g9b9e5_float(src[i], d);
8776         d += 4;
8777      }
8778      break;
8779
8780   case MESA_FORMAT_R11G11B10_FLOAT:
8781      for (i = 0; i < n; ++i) {
8782         pack_ubyte_r11g11b10_float(src[i], d);
8783         d += 4;
8784      }
8785      break;
8786
8787   case MESA_FORMAT_A_FLOAT16:
8788      for (i = 0; i < n; ++i) {
8789         pack_ubyte_a_float16(src[i], d);
8790         d += 2;
8791      }
8792      break;
8793
8794   case MESA_FORMAT_A_FLOAT32:
8795      for (i = 0; i < n; ++i) {
8796         pack_ubyte_a_float32(src[i], d);
8797         d += 4;
8798      }
8799      break;
8800
8801   case MESA_FORMAT_L_FLOAT16:
8802      for (i = 0; i < n; ++i) {
8803         pack_ubyte_l_float16(src[i], d);
8804         d += 2;
8805      }
8806      break;
8807
8808   case MESA_FORMAT_L_FLOAT32:
8809      for (i = 0; i < n; ++i) {
8810         pack_ubyte_l_float32(src[i], d);
8811         d += 4;
8812      }
8813      break;
8814
8815   case MESA_FORMAT_LA_FLOAT16:
8816      for (i = 0; i < n; ++i) {
8817         pack_ubyte_la_float16(src[i], d);
8818         d += 4;
8819      }
8820      break;
8821
8822   case MESA_FORMAT_LA_FLOAT32:
8823      for (i = 0; i < n; ++i) {
8824         pack_ubyte_la_float32(src[i], d);
8825         d += 8;
8826      }
8827      break;
8828
8829   case MESA_FORMAT_I_FLOAT16:
8830      for (i = 0; i < n; ++i) {
8831         pack_ubyte_i_float16(src[i], d);
8832         d += 2;
8833      }
8834      break;
8835
8836   case MESA_FORMAT_I_FLOAT32:
8837      for (i = 0; i < n; ++i) {
8838         pack_ubyte_i_float32(src[i], d);
8839         d += 4;
8840      }
8841      break;
8842
8843   case MESA_FORMAT_R_FLOAT16:
8844      for (i = 0; i < n; ++i) {
8845         pack_ubyte_r_float16(src[i], d);
8846         d += 2;
8847      }
8848      break;
8849
8850   case MESA_FORMAT_R_FLOAT32:
8851      for (i = 0; i < n; ++i) {
8852         pack_ubyte_r_float32(src[i], d);
8853         d += 4;
8854      }
8855      break;
8856
8857   case MESA_FORMAT_RG_FLOAT16:
8858      for (i = 0; i < n; ++i) {
8859         pack_ubyte_rg_float16(src[i], d);
8860         d += 4;
8861      }
8862      break;
8863
8864   case MESA_FORMAT_RG_FLOAT32:
8865      for (i = 0; i < n; ++i) {
8866         pack_ubyte_rg_float32(src[i], d);
8867         d += 8;
8868      }
8869      break;
8870
8871   case MESA_FORMAT_RGB_FLOAT16:
8872      for (i = 0; i < n; ++i) {
8873         pack_ubyte_rgb_float16(src[i], d);
8874         d += 6;
8875      }
8876      break;
8877
8878   case MESA_FORMAT_RGB_FLOAT32:
8879      for (i = 0; i < n; ++i) {
8880         pack_ubyte_rgb_float32(src[i], d);
8881         d += 12;
8882      }
8883      break;
8884
8885   case MESA_FORMAT_RGBA_FLOAT16:
8886      for (i = 0; i < n; ++i) {
8887         pack_ubyte_rgba_float16(src[i], d);
8888         d += 8;
8889      }
8890      break;
8891
8892   case MESA_FORMAT_RGBA_FLOAT32:
8893      for (i = 0; i < n; ++i) {
8894         pack_ubyte_rgba_float32(src[i], d);
8895         d += 16;
8896      }
8897      break;
8898
8899   case MESA_FORMAT_RGBX_FLOAT16:
8900      for (i = 0; i < n; ++i) {
8901         pack_ubyte_rgbx_float16(src[i], d);
8902         d += 8;
8903      }
8904      break;
8905
8906   case MESA_FORMAT_RGBX_FLOAT32:
8907      for (i = 0; i < n; ++i) {
8908         pack_ubyte_rgbx_float32(src[i], d);
8909         d += 16;
8910      }
8911      break;
8912
8913   case MESA_FORMAT_A8B8G8R8_UINT:
8914      for (i = 0; i < n; ++i) {
8915         pack_ubyte_a8b8g8r8_uint(src[i], d);
8916         d += 4;
8917      }
8918      break;
8919
8920   case MESA_FORMAT_A8R8G8B8_UINT:
8921      for (i = 0; i < n; ++i) {
8922         pack_ubyte_a8r8g8b8_uint(src[i], d);
8923         d += 4;
8924      }
8925      break;
8926
8927   case MESA_FORMAT_R8G8B8A8_UINT:
8928      for (i = 0; i < n; ++i) {
8929         pack_ubyte_r8g8b8a8_uint(src[i], d);
8930         d += 4;
8931      }
8932      break;
8933
8934   case MESA_FORMAT_B8G8R8A8_UINT:
8935      for (i = 0; i < n; ++i) {
8936         pack_ubyte_b8g8r8a8_uint(src[i], d);
8937         d += 4;
8938      }
8939      break;
8940
8941   case MESA_FORMAT_B10G10R10A2_UINT:
8942      for (i = 0; i < n; ++i) {
8943         pack_ubyte_b10g10r10a2_uint(src[i], d);
8944         d += 4;
8945      }
8946      break;
8947
8948   case MESA_FORMAT_R10G10B10A2_UINT:
8949      for (i = 0; i < n; ++i) {
8950         pack_ubyte_r10g10b10a2_uint(src[i], d);
8951         d += 4;
8952      }
8953      break;
8954
8955   case MESA_FORMAT_A2B10G10R10_UINT:
8956      for (i = 0; i < n; ++i) {
8957         pack_ubyte_a2b10g10r10_uint(src[i], d);
8958         d += 4;
8959      }
8960      break;
8961
8962   case MESA_FORMAT_A2R10G10B10_UINT:
8963      for (i = 0; i < n; ++i) {
8964         pack_ubyte_a2r10g10b10_uint(src[i], d);
8965         d += 4;
8966      }
8967      break;
8968
8969   case MESA_FORMAT_B5G6R5_UINT:
8970      for (i = 0; i < n; ++i) {
8971         pack_ubyte_b5g6r5_uint(src[i], d);
8972         d += 2;
8973      }
8974      break;
8975
8976   case MESA_FORMAT_R5G6B5_UINT:
8977      for (i = 0; i < n; ++i) {
8978         pack_ubyte_r5g6b5_uint(src[i], d);
8979         d += 2;
8980      }
8981      break;
8982
8983   case MESA_FORMAT_B2G3R3_UINT:
8984      for (i = 0; i < n; ++i) {
8985         pack_ubyte_b2g3r3_uint(src[i], d);
8986         d += 1;
8987      }
8988      break;
8989
8990   case MESA_FORMAT_R3G3B2_UINT:
8991      for (i = 0; i < n; ++i) {
8992         pack_ubyte_r3g3b2_uint(src[i], d);
8993         d += 1;
8994      }
8995      break;
8996
8997   case MESA_FORMAT_A4B4G4R4_UINT:
8998      for (i = 0; i < n; ++i) {
8999         pack_ubyte_a4b4g4r4_uint(src[i], d);
9000         d += 2;
9001      }
9002      break;
9003
9004   case MESA_FORMAT_R4G4B4A4_UINT:
9005      for (i = 0; i < n; ++i) {
9006         pack_ubyte_r4g4b4a4_uint(src[i], d);
9007         d += 2;
9008      }
9009      break;
9010
9011   case MESA_FORMAT_B4G4R4A4_UINT:
9012      for (i = 0; i < n; ++i) {
9013         pack_ubyte_b4g4r4a4_uint(src[i], d);
9014         d += 2;
9015      }
9016      break;
9017
9018   case MESA_FORMAT_A4R4G4B4_UINT:
9019      for (i = 0; i < n; ++i) {
9020         pack_ubyte_a4r4g4b4_uint(src[i], d);
9021         d += 2;
9022      }
9023      break;
9024
9025   case MESA_FORMAT_A1B5G5R5_UINT:
9026      for (i = 0; i < n; ++i) {
9027         pack_ubyte_a1b5g5r5_uint(src[i], d);
9028         d += 2;
9029      }
9030      break;
9031
9032   case MESA_FORMAT_B5G5R5A1_UINT:
9033      for (i = 0; i < n; ++i) {
9034         pack_ubyte_b5g5r5a1_uint(src[i], d);
9035         d += 2;
9036      }
9037      break;
9038
9039   case MESA_FORMAT_A1R5G5B5_UINT:
9040      for (i = 0; i < n; ++i) {
9041         pack_ubyte_a1r5g5b5_uint(src[i], d);
9042         d += 2;
9043      }
9044      break;
9045
9046   case MESA_FORMAT_R5G5B5A1_UINT:
9047      for (i = 0; i < n; ++i) {
9048         pack_ubyte_r5g5b5a1_uint(src[i], d);
9049         d += 2;
9050      }
9051      break;
9052
9053   case MESA_FORMAT_A_UINT8:
9054      for (i = 0; i < n; ++i) {
9055         pack_ubyte_a_uint8(src[i], d);
9056         d += 1;
9057      }
9058      break;
9059
9060   case MESA_FORMAT_A_UINT16:
9061      for (i = 0; i < n; ++i) {
9062         pack_ubyte_a_uint16(src[i], d);
9063         d += 2;
9064      }
9065      break;
9066
9067   case MESA_FORMAT_A_UINT32:
9068      for (i = 0; i < n; ++i) {
9069         pack_ubyte_a_uint32(src[i], d);
9070         d += 4;
9071      }
9072      break;
9073
9074   case MESA_FORMAT_A_SINT8:
9075      for (i = 0; i < n; ++i) {
9076         pack_ubyte_a_sint8(src[i], d);
9077         d += 1;
9078      }
9079      break;
9080
9081   case MESA_FORMAT_A_SINT16:
9082      for (i = 0; i < n; ++i) {
9083         pack_ubyte_a_sint16(src[i], d);
9084         d += 2;
9085      }
9086      break;
9087
9088   case MESA_FORMAT_A_SINT32:
9089      for (i = 0; i < n; ++i) {
9090         pack_ubyte_a_sint32(src[i], d);
9091         d += 4;
9092      }
9093      break;
9094
9095   case MESA_FORMAT_I_UINT8:
9096      for (i = 0; i < n; ++i) {
9097         pack_ubyte_i_uint8(src[i], d);
9098         d += 1;
9099      }
9100      break;
9101
9102   case MESA_FORMAT_I_UINT16:
9103      for (i = 0; i < n; ++i) {
9104         pack_ubyte_i_uint16(src[i], d);
9105         d += 2;
9106      }
9107      break;
9108
9109   case MESA_FORMAT_I_UINT32:
9110      for (i = 0; i < n; ++i) {
9111         pack_ubyte_i_uint32(src[i], d);
9112         d += 4;
9113      }
9114      break;
9115
9116   case MESA_FORMAT_I_SINT8:
9117      for (i = 0; i < n; ++i) {
9118         pack_ubyte_i_sint8(src[i], d);
9119         d += 1;
9120      }
9121      break;
9122
9123   case MESA_FORMAT_I_SINT16:
9124      for (i = 0; i < n; ++i) {
9125         pack_ubyte_i_sint16(src[i], d);
9126         d += 2;
9127      }
9128      break;
9129
9130   case MESA_FORMAT_I_SINT32:
9131      for (i = 0; i < n; ++i) {
9132         pack_ubyte_i_sint32(src[i], d);
9133         d += 4;
9134      }
9135      break;
9136
9137   case MESA_FORMAT_L_UINT8:
9138      for (i = 0; i < n; ++i) {
9139         pack_ubyte_l_uint8(src[i], d);
9140         d += 1;
9141      }
9142      break;
9143
9144   case MESA_FORMAT_L_UINT16:
9145      for (i = 0; i < n; ++i) {
9146         pack_ubyte_l_uint16(src[i], d);
9147         d += 2;
9148      }
9149      break;
9150
9151   case MESA_FORMAT_L_UINT32:
9152      for (i = 0; i < n; ++i) {
9153         pack_ubyte_l_uint32(src[i], d);
9154         d += 4;
9155      }
9156      break;
9157
9158   case MESA_FORMAT_L_SINT8:
9159      for (i = 0; i < n; ++i) {
9160         pack_ubyte_l_sint8(src[i], d);
9161         d += 1;
9162      }
9163      break;
9164
9165   case MESA_FORMAT_L_SINT16:
9166      for (i = 0; i < n; ++i) {
9167         pack_ubyte_l_sint16(src[i], d);
9168         d += 2;
9169      }
9170      break;
9171
9172   case MESA_FORMAT_L_SINT32:
9173      for (i = 0; i < n; ++i) {
9174         pack_ubyte_l_sint32(src[i], d);
9175         d += 4;
9176      }
9177      break;
9178
9179   case MESA_FORMAT_LA_UINT8:
9180      for (i = 0; i < n; ++i) {
9181         pack_ubyte_la_uint8(src[i], d);
9182         d += 2;
9183      }
9184      break;
9185
9186   case MESA_FORMAT_LA_UINT16:
9187      for (i = 0; i < n; ++i) {
9188         pack_ubyte_la_uint16(src[i], d);
9189         d += 4;
9190      }
9191      break;
9192
9193   case MESA_FORMAT_LA_UINT32:
9194      for (i = 0; i < n; ++i) {
9195         pack_ubyte_la_uint32(src[i], d);
9196         d += 8;
9197      }
9198      break;
9199
9200   case MESA_FORMAT_LA_SINT8:
9201      for (i = 0; i < n; ++i) {
9202         pack_ubyte_la_sint8(src[i], d);
9203         d += 2;
9204      }
9205      break;
9206
9207   case MESA_FORMAT_LA_SINT16:
9208      for (i = 0; i < n; ++i) {
9209         pack_ubyte_la_sint16(src[i], d);
9210         d += 4;
9211      }
9212      break;
9213
9214   case MESA_FORMAT_LA_SINT32:
9215      for (i = 0; i < n; ++i) {
9216         pack_ubyte_la_sint32(src[i], d);
9217         d += 8;
9218      }
9219      break;
9220
9221   case MESA_FORMAT_R_UINT8:
9222      for (i = 0; i < n; ++i) {
9223         pack_ubyte_r_uint8(src[i], d);
9224         d += 1;
9225      }
9226      break;
9227
9228   case MESA_FORMAT_R_UINT16:
9229      for (i = 0; i < n; ++i) {
9230         pack_ubyte_r_uint16(src[i], d);
9231         d += 2;
9232      }
9233      break;
9234
9235   case MESA_FORMAT_R_UINT32:
9236      for (i = 0; i < n; ++i) {
9237         pack_ubyte_r_uint32(src[i], d);
9238         d += 4;
9239      }
9240      break;
9241
9242   case MESA_FORMAT_R_SINT8:
9243      for (i = 0; i < n; ++i) {
9244         pack_ubyte_r_sint8(src[i], d);
9245         d += 1;
9246      }
9247      break;
9248
9249   case MESA_FORMAT_R_SINT16:
9250      for (i = 0; i < n; ++i) {
9251         pack_ubyte_r_sint16(src[i], d);
9252         d += 2;
9253      }
9254      break;
9255
9256   case MESA_FORMAT_R_SINT32:
9257      for (i = 0; i < n; ++i) {
9258         pack_ubyte_r_sint32(src[i], d);
9259         d += 4;
9260      }
9261      break;
9262
9263   case MESA_FORMAT_RG_UINT8:
9264      for (i = 0; i < n; ++i) {
9265         pack_ubyte_rg_uint8(src[i], d);
9266         d += 2;
9267      }
9268      break;
9269
9270   case MESA_FORMAT_RG_UINT16:
9271      for (i = 0; i < n; ++i) {
9272         pack_ubyte_rg_uint16(src[i], d);
9273         d += 4;
9274      }
9275      break;
9276
9277   case MESA_FORMAT_RG_UINT32:
9278      for (i = 0; i < n; ++i) {
9279         pack_ubyte_rg_uint32(src[i], d);
9280         d += 8;
9281      }
9282      break;
9283
9284   case MESA_FORMAT_RG_SINT8:
9285      for (i = 0; i < n; ++i) {
9286         pack_ubyte_rg_sint8(src[i], d);
9287         d += 2;
9288      }
9289      break;
9290
9291   case MESA_FORMAT_RG_SINT16:
9292      for (i = 0; i < n; ++i) {
9293         pack_ubyte_rg_sint16(src[i], d);
9294         d += 4;
9295      }
9296      break;
9297
9298   case MESA_FORMAT_RG_SINT32:
9299      for (i = 0; i < n; ++i) {
9300         pack_ubyte_rg_sint32(src[i], d);
9301         d += 8;
9302      }
9303      break;
9304
9305   case MESA_FORMAT_RGB_UINT8:
9306      for (i = 0; i < n; ++i) {
9307         pack_ubyte_rgb_uint8(src[i], d);
9308         d += 3;
9309      }
9310      break;
9311
9312   case MESA_FORMAT_RGB_UINT16:
9313      for (i = 0; i < n; ++i) {
9314         pack_ubyte_rgb_uint16(src[i], d);
9315         d += 6;
9316      }
9317      break;
9318
9319   case MESA_FORMAT_RGB_UINT32:
9320      for (i = 0; i < n; ++i) {
9321         pack_ubyte_rgb_uint32(src[i], d);
9322         d += 12;
9323      }
9324      break;
9325
9326   case MESA_FORMAT_RGB_SINT8:
9327      for (i = 0; i < n; ++i) {
9328         pack_ubyte_rgb_sint8(src[i], d);
9329         d += 3;
9330      }
9331      break;
9332
9333   case MESA_FORMAT_RGB_SINT16:
9334      for (i = 0; i < n; ++i) {
9335         pack_ubyte_rgb_sint16(src[i], d);
9336         d += 6;
9337      }
9338      break;
9339
9340   case MESA_FORMAT_RGB_SINT32:
9341      for (i = 0; i < n; ++i) {
9342         pack_ubyte_rgb_sint32(src[i], d);
9343         d += 12;
9344      }
9345      break;
9346
9347   case MESA_FORMAT_RGBA_UINT8:
9348      for (i = 0; i < n; ++i) {
9349         pack_ubyte_rgba_uint8(src[i], d);
9350         d += 4;
9351      }
9352      break;
9353
9354   case MESA_FORMAT_RGBA_UINT16:
9355      for (i = 0; i < n; ++i) {
9356         pack_ubyte_rgba_uint16(src[i], d);
9357         d += 8;
9358      }
9359      break;
9360
9361   case MESA_FORMAT_RGBA_UINT32:
9362      for (i = 0; i < n; ++i) {
9363         pack_ubyte_rgba_uint32(src[i], d);
9364         d += 16;
9365      }
9366      break;
9367
9368   case MESA_FORMAT_RGBA_SINT8:
9369      for (i = 0; i < n; ++i) {
9370         pack_ubyte_rgba_sint8(src[i], d);
9371         d += 4;
9372      }
9373      break;
9374
9375   case MESA_FORMAT_RGBA_SINT16:
9376      for (i = 0; i < n; ++i) {
9377         pack_ubyte_rgba_sint16(src[i], d);
9378         d += 8;
9379      }
9380      break;
9381
9382   case MESA_FORMAT_RGBA_SINT32:
9383      for (i = 0; i < n; ++i) {
9384         pack_ubyte_rgba_sint32(src[i], d);
9385         d += 16;
9386      }
9387      break;
9388
9389   case MESA_FORMAT_RGBX_UINT8:
9390      for (i = 0; i < n; ++i) {
9391         pack_ubyte_rgbx_uint8(src[i], d);
9392         d += 4;
9393      }
9394      break;
9395
9396   case MESA_FORMAT_RGBX_UINT16:
9397      for (i = 0; i < n; ++i) {
9398         pack_ubyte_rgbx_uint16(src[i], d);
9399         d += 8;
9400      }
9401      break;
9402
9403   case MESA_FORMAT_RGBX_UINT32:
9404      for (i = 0; i < n; ++i) {
9405         pack_ubyte_rgbx_uint32(src[i], d);
9406         d += 16;
9407      }
9408      break;
9409
9410   case MESA_FORMAT_RGBX_SINT8:
9411      for (i = 0; i < n; ++i) {
9412         pack_ubyte_rgbx_sint8(src[i], d);
9413         d += 4;
9414      }
9415      break;
9416
9417   case MESA_FORMAT_RGBX_SINT16:
9418      for (i = 0; i < n; ++i) {
9419         pack_ubyte_rgbx_sint16(src[i], d);
9420         d += 8;
9421      }
9422      break;
9423
9424   case MESA_FORMAT_RGBX_SINT32:
9425      for (i = 0; i < n; ++i) {
9426         pack_ubyte_rgbx_sint32(src[i], d);
9427         d += 16;
9428      }
9429      break;
9430                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           default:
9431      assert(!"Invalid format");
9432   }
9433}
9434
9435/**
9436 * Pack a row of GLuint rgba[4] values to the destination.
9437 */
9438void
9439_mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
9440                          const GLuint src[][4], void *dst)
9441{
9442   GLuint i;
9443   GLubyte *d = dst;
9444
9445   switch (format) {
9446
9447   case MESA_FORMAT_A8B8G8R8_UINT:
9448      for (i = 0; i < n; ++i) {
9449         pack_uint_a8b8g8r8_uint(src[i], d);
9450         d += 4;
9451      }
9452      break;
9453
9454   case MESA_FORMAT_A8R8G8B8_UINT:
9455      for (i = 0; i < n; ++i) {
9456         pack_uint_a8r8g8b8_uint(src[i], d);
9457         d += 4;
9458      }
9459      break;
9460
9461   case MESA_FORMAT_R8G8B8A8_UINT:
9462      for (i = 0; i < n; ++i) {
9463         pack_uint_r8g8b8a8_uint(src[i], d);
9464         d += 4;
9465      }
9466      break;
9467
9468   case MESA_FORMAT_B8G8R8A8_UINT:
9469      for (i = 0; i < n; ++i) {
9470         pack_uint_b8g8r8a8_uint(src[i], d);
9471         d += 4;
9472      }
9473      break;
9474
9475   case MESA_FORMAT_B10G10R10A2_UINT:
9476      for (i = 0; i < n; ++i) {
9477         pack_uint_b10g10r10a2_uint(src[i], d);
9478         d += 4;
9479      }
9480      break;
9481
9482   case MESA_FORMAT_R10G10B10A2_UINT:
9483      for (i = 0; i < n; ++i) {
9484         pack_uint_r10g10b10a2_uint(src[i], d);
9485         d += 4;
9486      }
9487      break;
9488
9489   case MESA_FORMAT_A2B10G10R10_UINT:
9490      for (i = 0; i < n; ++i) {
9491         pack_uint_a2b10g10r10_uint(src[i], d);
9492         d += 4;
9493      }
9494      break;
9495
9496   case MESA_FORMAT_A2R10G10B10_UINT:
9497      for (i = 0; i < n; ++i) {
9498         pack_uint_a2r10g10b10_uint(src[i], d);
9499         d += 4;
9500      }
9501      break;
9502
9503   case MESA_FORMAT_B5G6R5_UINT:
9504      for (i = 0; i < n; ++i) {
9505         pack_uint_b5g6r5_uint(src[i], d);
9506         d += 2;
9507      }
9508      break;
9509
9510   case MESA_FORMAT_R5G6B5_UINT:
9511      for (i = 0; i < n; ++i) {
9512         pack_uint_r5g6b5_uint(src[i], d);
9513         d += 2;
9514      }
9515      break;
9516
9517   case MESA_FORMAT_B2G3R3_UINT:
9518      for (i = 0; i < n; ++i) {
9519         pack_uint_b2g3r3_uint(src[i], d);
9520         d += 1;
9521      }
9522      break;
9523
9524   case MESA_FORMAT_R3G3B2_UINT:
9525      for (i = 0; i < n; ++i) {
9526         pack_uint_r3g3b2_uint(src[i], d);
9527         d += 1;
9528      }
9529      break;
9530
9531   case MESA_FORMAT_A4B4G4R4_UINT:
9532      for (i = 0; i < n; ++i) {
9533         pack_uint_a4b4g4r4_uint(src[i], d);
9534         d += 2;
9535      }
9536      break;
9537
9538   case MESA_FORMAT_R4G4B4A4_UINT:
9539      for (i = 0; i < n; ++i) {
9540         pack_uint_r4g4b4a4_uint(src[i], d);
9541         d += 2;
9542      }
9543      break;
9544
9545   case MESA_FORMAT_B4G4R4A4_UINT:
9546      for (i = 0; i < n; ++i) {
9547         pack_uint_b4g4r4a4_uint(src[i], d);
9548         d += 2;
9549      }
9550      break;
9551
9552   case MESA_FORMAT_A4R4G4B4_UINT:
9553      for (i = 0; i < n; ++i) {
9554         pack_uint_a4r4g4b4_uint(src[i], d);
9555         d += 2;
9556      }
9557      break;
9558
9559   case MESA_FORMAT_A1B5G5R5_UINT:
9560      for (i = 0; i < n; ++i) {
9561         pack_uint_a1b5g5r5_uint(src[i], d);
9562         d += 2;
9563      }
9564      break;
9565
9566   case MESA_FORMAT_B5G5R5A1_UINT:
9567      for (i = 0; i < n; ++i) {
9568         pack_uint_b5g5r5a1_uint(src[i], d);
9569         d += 2;
9570      }
9571      break;
9572
9573   case MESA_FORMAT_A1R5G5B5_UINT:
9574      for (i = 0; i < n; ++i) {
9575         pack_uint_a1r5g5b5_uint(src[i], d);
9576         d += 2;
9577      }
9578      break;
9579
9580   case MESA_FORMAT_R5G5B5A1_UINT:
9581      for (i = 0; i < n; ++i) {
9582         pack_uint_r5g5b5a1_uint(src[i], d);
9583         d += 2;
9584      }
9585      break;
9586
9587   case MESA_FORMAT_A_UINT8:
9588      for (i = 0; i < n; ++i) {
9589         pack_uint_a_uint8(src[i], d);
9590         d += 1;
9591      }
9592      break;
9593
9594   case MESA_FORMAT_A_UINT16:
9595      for (i = 0; i < n; ++i) {
9596         pack_uint_a_uint16(src[i], d);
9597         d += 2;
9598      }
9599      break;
9600
9601   case MESA_FORMAT_A_UINT32:
9602      for (i = 0; i < n; ++i) {
9603         pack_uint_a_uint32(src[i], d);
9604         d += 4;
9605      }
9606      break;
9607
9608   case MESA_FORMAT_A_SINT8:
9609      for (i = 0; i < n; ++i) {
9610         pack_uint_a_sint8(src[i], d);
9611         d += 1;
9612      }
9613      break;
9614
9615   case MESA_FORMAT_A_SINT16:
9616      for (i = 0; i < n; ++i) {
9617         pack_uint_a_sint16(src[i], d);
9618         d += 2;
9619      }
9620      break;
9621
9622   case MESA_FORMAT_A_SINT32:
9623      for (i = 0; i < n; ++i) {
9624         pack_uint_a_sint32(src[i], d);
9625         d += 4;
9626      }
9627      break;
9628
9629   case MESA_FORMAT_I_UINT8:
9630      for (i = 0; i < n; ++i) {
9631         pack_uint_i_uint8(src[i], d);
9632         d += 1;
9633      }
9634      break;
9635
9636   case MESA_FORMAT_I_UINT16:
9637      for (i = 0; i < n; ++i) {
9638         pack_uint_i_uint16(src[i], d);
9639         d += 2;
9640      }
9641      break;
9642
9643   case MESA_FORMAT_I_UINT32:
9644      for (i = 0; i < n; ++i) {
9645         pack_uint_i_uint32(src[i], d);
9646         d += 4;
9647      }
9648      break;
9649
9650   case MESA_FORMAT_I_SINT8:
9651      for (i = 0; i < n; ++i) {
9652         pack_uint_i_sint8(src[i], d);
9653         d += 1;
9654      }
9655      break;
9656
9657   case MESA_FORMAT_I_SINT16:
9658      for (i = 0; i < n; ++i) {
9659         pack_uint_i_sint16(src[i], d);
9660         d += 2;
9661      }
9662      break;
9663
9664   case MESA_FORMAT_I_SINT32:
9665      for (i = 0; i < n; ++i) {
9666         pack_uint_i_sint32(src[i], d);
9667         d += 4;
9668      }
9669      break;
9670
9671   case MESA_FORMAT_L_UINT8:
9672      for (i = 0; i < n; ++i) {
9673         pack_uint_l_uint8(src[i], d);
9674         d += 1;
9675      }
9676      break;
9677
9678   case MESA_FORMAT_L_UINT16:
9679      for (i = 0; i < n; ++i) {
9680         pack_uint_l_uint16(src[i], d);
9681         d += 2;
9682      }
9683      break;
9684
9685   case MESA_FORMAT_L_UINT32:
9686      for (i = 0; i < n; ++i) {
9687         pack_uint_l_uint32(src[i], d);
9688         d += 4;
9689      }
9690      break;
9691
9692   case MESA_FORMAT_L_SINT8:
9693      for (i = 0; i < n; ++i) {
9694         pack_uint_l_sint8(src[i], d);
9695         d += 1;
9696      }
9697      break;
9698
9699   case MESA_FORMAT_L_SINT16:
9700      for (i = 0; i < n; ++i) {
9701         pack_uint_l_sint16(src[i], d);
9702         d += 2;
9703      }
9704      break;
9705
9706   case MESA_FORMAT_L_SINT32:
9707      for (i = 0; i < n; ++i) {
9708         pack_uint_l_sint32(src[i], d);
9709         d += 4;
9710      }
9711      break;
9712
9713   case MESA_FORMAT_LA_UINT8:
9714      for (i = 0; i < n; ++i) {
9715         pack_uint_la_uint8(src[i], d);
9716         d += 2;
9717      }
9718      break;
9719
9720   case MESA_FORMAT_LA_UINT16:
9721      for (i = 0; i < n; ++i) {
9722         pack_uint_la_uint16(src[i], d);
9723         d += 4;
9724      }
9725      break;
9726
9727   case MESA_FORMAT_LA_UINT32:
9728      for (i = 0; i < n; ++i) {
9729         pack_uint_la_uint32(src[i], d);
9730         d += 8;
9731      }
9732      break;
9733
9734   case MESA_FORMAT_LA_SINT8:
9735      for (i = 0; i < n; ++i) {
9736         pack_uint_la_sint8(src[i], d);
9737         d += 2;
9738      }
9739      break;
9740
9741   case MESA_FORMAT_LA_SINT16:
9742      for (i = 0; i < n; ++i) {
9743         pack_uint_la_sint16(src[i], d);
9744         d += 4;
9745      }
9746      break;
9747
9748   case MESA_FORMAT_LA_SINT32:
9749      for (i = 0; i < n; ++i) {
9750         pack_uint_la_sint32(src[i], d);
9751         d += 8;
9752      }
9753      break;
9754
9755   case MESA_FORMAT_R_UINT8:
9756      for (i = 0; i < n; ++i) {
9757         pack_uint_r_uint8(src[i], d);
9758         d += 1;
9759      }
9760      break;
9761
9762   case MESA_FORMAT_R_UINT16:
9763      for (i = 0; i < n; ++i) {
9764         pack_uint_r_uint16(src[i], d);
9765         d += 2;
9766      }
9767      break;
9768
9769   case MESA_FORMAT_R_UINT32:
9770      for (i = 0; i < n; ++i) {
9771         pack_uint_r_uint32(src[i], d);
9772         d += 4;
9773      }
9774      break;
9775
9776   case MESA_FORMAT_R_SINT8:
9777      for (i = 0; i < n; ++i) {
9778         pack_uint_r_sint8(src[i], d);
9779         d += 1;
9780      }
9781      break;
9782
9783   case MESA_FORMAT_R_SINT16:
9784      for (i = 0; i < n; ++i) {
9785         pack_uint_r_sint16(src[i], d);
9786         d += 2;
9787      }
9788      break;
9789
9790   case MESA_FORMAT_R_SINT32:
9791      for (i = 0; i < n; ++i) {
9792         pack_uint_r_sint32(src[i], d);
9793         d += 4;
9794      }
9795      break;
9796
9797   case MESA_FORMAT_RG_UINT8:
9798      for (i = 0; i < n; ++i) {
9799         pack_uint_rg_uint8(src[i], d);
9800         d += 2;
9801      }
9802      break;
9803
9804   case MESA_FORMAT_RG_UINT16:
9805      for (i = 0; i < n; ++i) {
9806         pack_uint_rg_uint16(src[i], d);
9807         d += 4;
9808      }
9809      break;
9810
9811   case MESA_FORMAT_RG_UINT32:
9812      for (i = 0; i < n; ++i) {
9813         pack_uint_rg_uint32(src[i], d);
9814         d += 8;
9815      }
9816      break;
9817
9818   case MESA_FORMAT_RG_SINT8:
9819      for (i = 0; i < n; ++i) {
9820         pack_uint_rg_sint8(src[i], d);
9821         d += 2;
9822      }
9823      break;
9824
9825   case MESA_FORMAT_RG_SINT16:
9826      for (i = 0; i < n; ++i) {
9827         pack_uint_rg_sint16(src[i], d);
9828         d += 4;
9829      }
9830      break;
9831
9832   case MESA_FORMAT_RG_SINT32:
9833      for (i = 0; i < n; ++i) {
9834         pack_uint_rg_sint32(src[i], d);
9835         d += 8;
9836      }
9837      break;
9838
9839   case MESA_FORMAT_RGB_UINT8:
9840      for (i = 0; i < n; ++i) {
9841         pack_uint_rgb_uint8(src[i], d);
9842         d += 3;
9843      }
9844      break;
9845
9846   case MESA_FORMAT_RGB_UINT16:
9847      for (i = 0; i < n; ++i) {
9848         pack_uint_rgb_uint16(src[i], d);
9849         d += 6;
9850      }
9851      break;
9852
9853   case MESA_FORMAT_RGB_UINT32:
9854      for (i = 0; i < n; ++i) {
9855         pack_uint_rgb_uint32(src[i], d);
9856         d += 12;
9857      }
9858      break;
9859
9860   case MESA_FORMAT_RGB_SINT8:
9861      for (i = 0; i < n; ++i) {
9862         pack_uint_rgb_sint8(src[i], d);
9863         d += 3;
9864      }
9865      break;
9866
9867   case MESA_FORMAT_RGB_SINT16:
9868      for (i = 0; i < n; ++i) {
9869         pack_uint_rgb_sint16(src[i], d);
9870         d += 6;
9871      }
9872      break;
9873
9874   case MESA_FORMAT_RGB_SINT32:
9875      for (i = 0; i < n; ++i) {
9876         pack_uint_rgb_sint32(src[i], d);
9877         d += 12;
9878      }
9879      break;
9880
9881   case MESA_FORMAT_RGBA_UINT8:
9882      for (i = 0; i < n; ++i) {
9883         pack_uint_rgba_uint8(src[i], d);
9884         d += 4;
9885      }
9886      break;
9887
9888   case MESA_FORMAT_RGBA_UINT16:
9889      for (i = 0; i < n; ++i) {
9890         pack_uint_rgba_uint16(src[i], d);
9891         d += 8;
9892      }
9893      break;
9894
9895   case MESA_FORMAT_RGBA_UINT32:
9896      for (i = 0; i < n; ++i) {
9897         pack_uint_rgba_uint32(src[i], d);
9898         d += 16;
9899      }
9900      break;
9901
9902   case MESA_FORMAT_RGBA_SINT8:
9903      for (i = 0; i < n; ++i) {
9904         pack_uint_rgba_sint8(src[i], d);
9905         d += 4;
9906      }
9907      break;
9908
9909   case MESA_FORMAT_RGBA_SINT16:
9910      for (i = 0; i < n; ++i) {
9911         pack_uint_rgba_sint16(src[i], d);
9912         d += 8;
9913      }
9914      break;
9915
9916   case MESA_FORMAT_RGBA_SINT32:
9917      for (i = 0; i < n; ++i) {
9918         pack_uint_rgba_sint32(src[i], d);
9919         d += 16;
9920      }
9921      break;
9922
9923   case MESA_FORMAT_RGBX_UINT8:
9924      for (i = 0; i < n; ++i) {
9925         pack_uint_rgbx_uint8(src[i], d);
9926         d += 4;
9927      }
9928      break;
9929
9930   case MESA_FORMAT_RGBX_UINT16:
9931      for (i = 0; i < n; ++i) {
9932         pack_uint_rgbx_uint16(src[i], d);
9933         d += 8;
9934      }
9935      break;
9936
9937   case MESA_FORMAT_RGBX_UINT32:
9938      for (i = 0; i < n; ++i) {
9939         pack_uint_rgbx_uint32(src[i], d);
9940         d += 16;
9941      }
9942      break;
9943
9944   case MESA_FORMAT_RGBX_SINT8:
9945      for (i = 0; i < n; ++i) {
9946         pack_uint_rgbx_sint8(src[i], d);
9947         d += 4;
9948      }
9949      break;
9950
9951   case MESA_FORMAT_RGBX_SINT16:
9952      for (i = 0; i < n; ++i) {
9953         pack_uint_rgbx_sint16(src[i], d);
9954         d += 8;
9955      }
9956      break;
9957
9958   case MESA_FORMAT_RGBX_SINT32:
9959      for (i = 0; i < n; ++i) {
9960         pack_uint_rgbx_sint32(src[i], d);
9961         d += 16;
9962      }
9963      break;
9964                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           default:
9965      assert(!"Invalid format");
9966   }
9967}
9968
9969/**
9970 * Pack a row of GLfloat rgba[4] values to the destination.
9971 */
9972void
9973_mesa_pack_float_rgba_row(mesa_format format, GLuint n,
9974                          const GLfloat src[][4], void *dst)
9975{
9976   GLuint i;
9977   GLubyte *d = dst;
9978
9979   switch (format) {
9980
9981   case MESA_FORMAT_A8B8G8R8_UNORM:
9982      for (i = 0; i < n; ++i) {
9983         pack_float_a8b8g8r8_unorm(src[i], d);
9984         d += 4;
9985      }
9986      break;
9987
9988   case MESA_FORMAT_X8B8G8R8_UNORM:
9989      for (i = 0; i < n; ++i) {
9990         pack_float_x8b8g8r8_unorm(src[i], d);
9991         d += 4;
9992      }
9993      break;
9994
9995   case MESA_FORMAT_R8G8B8A8_UNORM:
9996      for (i = 0; i < n; ++i) {
9997         pack_float_r8g8b8a8_unorm(src[i], d);
9998         d += 4;
9999      }
10000      break;
10001
10002   case MESA_FORMAT_R8G8B8X8_UNORM:
10003      for (i = 0; i < n; ++i) {
10004         pack_float_r8g8b8x8_unorm(src[i], d);
10005         d += 4;
10006      }
10007      break;
10008
10009   case MESA_FORMAT_B8G8R8A8_UNORM:
10010      for (i = 0; i < n; ++i) {
10011         pack_float_b8g8r8a8_unorm(src[i], d);
10012         d += 4;
10013      }
10014      break;
10015
10016   case MESA_FORMAT_B8G8R8X8_UNORM:
10017      for (i = 0; i < n; ++i) {
10018         pack_float_b8g8r8x8_unorm(src[i], d);
10019         d += 4;
10020      }
10021      break;
10022
10023   case MESA_FORMAT_A8R8G8B8_UNORM:
10024      for (i = 0; i < n; ++i) {
10025         pack_float_a8r8g8b8_unorm(src[i], d);
10026         d += 4;
10027      }
10028      break;
10029
10030   case MESA_FORMAT_X8R8G8B8_UNORM:
10031      for (i = 0; i < n; ++i) {
10032         pack_float_x8r8g8b8_unorm(src[i], d);
10033         d += 4;
10034      }
10035      break;
10036
10037   case MESA_FORMAT_L16A16_UNORM:
10038      for (i = 0; i < n; ++i) {
10039         pack_float_l16a16_unorm(src[i], d);
10040         d += 4;
10041      }
10042      break;
10043
10044   case MESA_FORMAT_A16L16_UNORM:
10045      for (i = 0; i < n; ++i) {
10046         pack_float_a16l16_unorm(src[i], d);
10047         d += 4;
10048      }
10049      break;
10050
10051   case MESA_FORMAT_B5G6R5_UNORM:
10052      for (i = 0; i < n; ++i) {
10053         pack_float_b5g6r5_unorm(src[i], d);
10054         d += 2;
10055      }
10056      break;
10057
10058   case MESA_FORMAT_R5G6B5_UNORM:
10059      for (i = 0; i < n; ++i) {
10060         pack_float_r5g6b5_unorm(src[i], d);
10061         d += 2;
10062      }
10063      break;
10064
10065   case MESA_FORMAT_B4G4R4A4_UNORM:
10066      for (i = 0; i < n; ++i) {
10067         pack_float_b4g4r4a4_unorm(src[i], d);
10068         d += 2;
10069      }
10070      break;
10071
10072   case MESA_FORMAT_B4G4R4X4_UNORM:
10073      for (i = 0; i < n; ++i) {
10074         pack_float_b4g4r4x4_unorm(src[i], d);
10075         d += 2;
10076      }
10077      break;
10078
10079   case MESA_FORMAT_A4R4G4B4_UNORM:
10080      for (i = 0; i < n; ++i) {
10081         pack_float_a4r4g4b4_unorm(src[i], d);
10082         d += 2;
10083      }
10084      break;
10085
10086   case MESA_FORMAT_A1B5G5R5_UNORM:
10087      for (i = 0; i < n; ++i) {
10088         pack_float_a1b5g5r5_unorm(src[i], d);
10089         d += 2;
10090      }
10091      break;
10092
10093   case MESA_FORMAT_X1B5G5R5_UNORM:
10094      for (i = 0; i < n; ++i) {
10095         pack_float_x1b5g5r5_unorm(src[i], d);
10096         d += 2;
10097      }
10098      break;
10099
10100   case MESA_FORMAT_B5G5R5A1_UNORM:
10101      for (i = 0; i < n; ++i) {
10102         pack_float_b5g5r5a1_unorm(src[i], d);
10103         d += 2;
10104      }
10105      break;
10106
10107   case MESA_FORMAT_B5G5R5X1_UNORM:
10108      for (i = 0; i < n; ++i) {
10109         pack_float_b5g5r5x1_unorm(src[i], d);
10110         d += 2;
10111      }
10112      break;
10113
10114   case MESA_FORMAT_A1R5G5B5_UNORM:
10115      for (i = 0; i < n; ++i) {
10116         pack_float_a1r5g5b5_unorm(src[i], d);
10117         d += 2;
10118      }
10119      break;
10120
10121   case MESA_FORMAT_L8A8_UNORM:
10122      for (i = 0; i < n; ++i) {
10123         pack_float_l8a8_unorm(src[i], d);
10124         d += 2;
10125      }
10126      break;
10127
10128   case MESA_FORMAT_A8L8_UNORM:
10129      for (i = 0; i < n; ++i) {
10130         pack_float_a8l8_unorm(src[i], d);
10131         d += 2;
10132      }
10133      break;
10134
10135   case MESA_FORMAT_R8G8_UNORM:
10136      for (i = 0; i < n; ++i) {
10137         pack_float_r8g8_unorm(src[i], d);
10138         d += 2;
10139      }
10140      break;
10141
10142   case MESA_FORMAT_G8R8_UNORM:
10143      for (i = 0; i < n; ++i) {
10144         pack_float_g8r8_unorm(src[i], d);
10145         d += 2;
10146      }
10147      break;
10148
10149   case MESA_FORMAT_L4A4_UNORM:
10150      for (i = 0; i < n; ++i) {
10151         pack_float_l4a4_unorm(src[i], d);
10152         d += 1;
10153      }
10154      break;
10155
10156   case MESA_FORMAT_B2G3R3_UNORM:
10157      for (i = 0; i < n; ++i) {
10158         pack_float_b2g3r3_unorm(src[i], d);
10159         d += 1;
10160      }
10161      break;
10162
10163   case MESA_FORMAT_R16G16_UNORM:
10164      for (i = 0; i < n; ++i) {
10165         pack_float_r16g16_unorm(src[i], d);
10166         d += 4;
10167      }
10168      break;
10169
10170   case MESA_FORMAT_G16R16_UNORM:
10171      for (i = 0; i < n; ++i) {
10172         pack_float_g16r16_unorm(src[i], d);
10173         d += 4;
10174      }
10175      break;
10176
10177   case MESA_FORMAT_B10G10R10A2_UNORM:
10178      for (i = 0; i < n; ++i) {
10179         pack_float_b10g10r10a2_unorm(src[i], d);
10180         d += 4;
10181      }
10182      break;
10183
10184   case MESA_FORMAT_B10G10R10X2_UNORM:
10185      for (i = 0; i < n; ++i) {
10186         pack_float_b10g10r10x2_unorm(src[i], d);
10187         d += 4;
10188      }
10189      break;
10190
10191   case MESA_FORMAT_R10G10B10A2_UNORM:
10192      for (i = 0; i < n; ++i) {
10193         pack_float_r10g10b10a2_unorm(src[i], d);
10194         d += 4;
10195      }
10196      break;
10197
10198   case MESA_FORMAT_R10G10B10X2_UNORM:
10199      for (i = 0; i < n; ++i) {
10200         pack_float_r10g10b10x2_unorm(src[i], d);
10201         d += 4;
10202      }
10203      break;
10204
10205   case MESA_FORMAT_R3G3B2_UNORM:
10206      for (i = 0; i < n; ++i) {
10207         pack_float_r3g3b2_unorm(src[i], d);
10208         d += 1;
10209      }
10210      break;
10211
10212   case MESA_FORMAT_A4B4G4R4_UNORM:
10213      for (i = 0; i < n; ++i) {
10214         pack_float_a4b4g4r4_unorm(src[i], d);
10215         d += 2;
10216      }
10217      break;
10218
10219   case MESA_FORMAT_R4G4B4A4_UNORM:
10220      for (i = 0; i < n; ++i) {
10221         pack_float_r4g4b4a4_unorm(src[i], d);
10222         d += 2;
10223      }
10224      break;
10225
10226   case MESA_FORMAT_R5G5B5A1_UNORM:
10227      for (i = 0; i < n; ++i) {
10228         pack_float_r5g5b5a1_unorm(src[i], d);
10229         d += 2;
10230      }
10231      break;
10232
10233   case MESA_FORMAT_A2B10G10R10_UNORM:
10234      for (i = 0; i < n; ++i) {
10235         pack_float_a2b10g10r10_unorm(src[i], d);
10236         d += 4;
10237      }
10238      break;
10239
10240   case MESA_FORMAT_A2R10G10B10_UNORM:
10241      for (i = 0; i < n; ++i) {
10242         pack_float_a2r10g10b10_unorm(src[i], d);
10243         d += 4;
10244      }
10245      break;
10246
10247   case MESA_FORMAT_A_UNORM8:
10248      for (i = 0; i < n; ++i) {
10249         pack_float_a_unorm8(src[i], d);
10250         d += 1;
10251      }
10252      break;
10253
10254   case MESA_FORMAT_A_UNORM16:
10255      for (i = 0; i < n; ++i) {
10256         pack_float_a_unorm16(src[i], d);
10257         d += 2;
10258      }
10259      break;
10260
10261   case MESA_FORMAT_L_UNORM8:
10262      for (i = 0; i < n; ++i) {
10263         pack_float_l_unorm8(src[i], d);
10264         d += 1;
10265      }
10266      break;
10267
10268   case MESA_FORMAT_L_UNORM16:
10269      for (i = 0; i < n; ++i) {
10270         pack_float_l_unorm16(src[i], d);
10271         d += 2;
10272      }
10273      break;
10274
10275   case MESA_FORMAT_I_UNORM8:
10276      for (i = 0; i < n; ++i) {
10277         pack_float_i_unorm8(src[i], d);
10278         d += 1;
10279      }
10280      break;
10281
10282   case MESA_FORMAT_I_UNORM16:
10283      for (i = 0; i < n; ++i) {
10284         pack_float_i_unorm16(src[i], d);
10285         d += 2;
10286      }
10287      break;
10288
10289   case MESA_FORMAT_R_UNORM8:
10290      for (i = 0; i < n; ++i) {
10291         pack_float_r_unorm8(src[i], d);
10292         d += 1;
10293      }
10294      break;
10295
10296   case MESA_FORMAT_R_UNORM16:
10297      for (i = 0; i < n; ++i) {
10298         pack_float_r_unorm16(src[i], d);
10299         d += 2;
10300      }
10301      break;
10302
10303   case MESA_FORMAT_BGR_UNORM8:
10304      for (i = 0; i < n; ++i) {
10305         pack_float_bgr_unorm8(src[i], d);
10306         d += 3;
10307      }
10308      break;
10309
10310   case MESA_FORMAT_RGB_UNORM8:
10311      for (i = 0; i < n; ++i) {
10312         pack_float_rgb_unorm8(src[i], d);
10313         d += 3;
10314      }
10315      break;
10316
10317   case MESA_FORMAT_RGBA_UNORM16:
10318      for (i = 0; i < n; ++i) {
10319         pack_float_rgba_unorm16(src[i], d);
10320         d += 8;
10321      }
10322      break;
10323
10324   case MESA_FORMAT_RGBX_UNORM16:
10325      for (i = 0; i < n; ++i) {
10326         pack_float_rgbx_unorm16(src[i], d);
10327         d += 8;
10328      }
10329      break;
10330
10331   case MESA_FORMAT_A8B8G8R8_SNORM:
10332      for (i = 0; i < n; ++i) {
10333         pack_float_a8b8g8r8_snorm(src[i], d);
10334         d += 4;
10335      }
10336      break;
10337
10338   case MESA_FORMAT_X8B8G8R8_SNORM:
10339      for (i = 0; i < n; ++i) {
10340         pack_float_x8b8g8r8_snorm(src[i], d);
10341         d += 4;
10342      }
10343      break;
10344
10345   case MESA_FORMAT_R8G8B8A8_SNORM:
10346      for (i = 0; i < n; ++i) {
10347         pack_float_r8g8b8a8_snorm(src[i], d);
10348         d += 4;
10349      }
10350      break;
10351
10352   case MESA_FORMAT_R8G8B8X8_SNORM:
10353      for (i = 0; i < n; ++i) {
10354         pack_float_r8g8b8x8_snorm(src[i], d);
10355         d += 4;
10356      }
10357      break;
10358
10359   case MESA_FORMAT_R16G16_SNORM:
10360      for (i = 0; i < n; ++i) {
10361         pack_float_r16g16_snorm(src[i], d);
10362         d += 4;
10363      }
10364      break;
10365
10366   case MESA_FORMAT_G16R16_SNORM:
10367      for (i = 0; i < n; ++i) {
10368         pack_float_g16r16_snorm(src[i], d);
10369         d += 4;
10370      }
10371      break;
10372
10373   case MESA_FORMAT_R8G8_SNORM:
10374      for (i = 0; i < n; ++i) {
10375         pack_float_r8g8_snorm(src[i], d);
10376         d += 2;
10377      }
10378      break;
10379
10380   case MESA_FORMAT_G8R8_SNORM:
10381      for (i = 0; i < n; ++i) {
10382         pack_float_g8r8_snorm(src[i], d);
10383         d += 2;
10384      }
10385      break;
10386
10387   case MESA_FORMAT_L8A8_SNORM:
10388      for (i = 0; i < n; ++i) {
10389         pack_float_l8a8_snorm(src[i], d);
10390         d += 2;
10391      }
10392      break;
10393
10394   case MESA_FORMAT_A8L8_SNORM:
10395      for (i = 0; i < n; ++i) {
10396         pack_float_a8l8_snorm(src[i], d);
10397         d += 2;
10398      }
10399      break;
10400
10401   case MESA_FORMAT_A_SNORM8:
10402      for (i = 0; i < n; ++i) {
10403         pack_float_a_snorm8(src[i], d);
10404         d += 1;
10405      }
10406      break;
10407
10408   case MESA_FORMAT_A_SNORM16:
10409      for (i = 0; i < n; ++i) {
10410         pack_float_a_snorm16(src[i], d);
10411         d += 2;
10412      }
10413      break;
10414
10415   case MESA_FORMAT_L_SNORM8:
10416      for (i = 0; i < n; ++i) {
10417         pack_float_l_snorm8(src[i], d);
10418         d += 1;
10419      }
10420      break;
10421
10422   case MESA_FORMAT_L_SNORM16:
10423      for (i = 0; i < n; ++i) {
10424         pack_float_l_snorm16(src[i], d);
10425         d += 2;
10426      }
10427      break;
10428
10429   case MESA_FORMAT_I_SNORM8:
10430      for (i = 0; i < n; ++i) {
10431         pack_float_i_snorm8(src[i], d);
10432         d += 1;
10433      }
10434      break;
10435
10436   case MESA_FORMAT_I_SNORM16:
10437      for (i = 0; i < n; ++i) {
10438         pack_float_i_snorm16(src[i], d);
10439         d += 2;
10440      }
10441      break;
10442
10443   case MESA_FORMAT_R_SNORM8:
10444      for (i = 0; i < n; ++i) {
10445         pack_float_r_snorm8(src[i], d);
10446         d += 1;
10447      }
10448      break;
10449
10450   case MESA_FORMAT_R_SNORM16:
10451      for (i = 0; i < n; ++i) {
10452         pack_float_r_snorm16(src[i], d);
10453         d += 2;
10454      }
10455      break;
10456
10457   case MESA_FORMAT_LA_SNORM16:
10458      for (i = 0; i < n; ++i) {
10459         pack_float_la_snorm16(src[i], d);
10460         d += 4;
10461      }
10462      break;
10463
10464   case MESA_FORMAT_RGB_SNORM16:
10465      for (i = 0; i < n; ++i) {
10466         pack_float_rgb_snorm16(src[i], d);
10467         d += 6;
10468      }
10469      break;
10470
10471   case MESA_FORMAT_RGBA_SNORM16:
10472      for (i = 0; i < n; ++i) {
10473         pack_float_rgba_snorm16(src[i], d);
10474         d += 8;
10475      }
10476      break;
10477
10478   case MESA_FORMAT_RGBX_SNORM16:
10479      for (i = 0; i < n; ++i) {
10480         pack_float_rgbx_snorm16(src[i], d);
10481         d += 8;
10482      }
10483      break;
10484
10485   case MESA_FORMAT_A8B8G8R8_SRGB:
10486      for (i = 0; i < n; ++i) {
10487         pack_float_a8b8g8r8_srgb(src[i], d);
10488         d += 4;
10489      }
10490      break;
10491
10492   case MESA_FORMAT_B8G8R8A8_SRGB:
10493      for (i = 0; i < n; ++i) {
10494         pack_float_b8g8r8a8_srgb(src[i], d);
10495         d += 4;
10496      }
10497      break;
10498
10499   case MESA_FORMAT_A8R8G8B8_SRGB:
10500      for (i = 0; i < n; ++i) {
10501         pack_float_a8r8g8b8_srgb(src[i], d);
10502         d += 4;
10503      }
10504      break;
10505
10506   case MESA_FORMAT_B8G8R8X8_SRGB:
10507      for (i = 0; i < n; ++i) {
10508         pack_float_b8g8r8x8_srgb(src[i], d);
10509         d += 4;
10510      }
10511      break;
10512
10513   case MESA_FORMAT_X8R8G8B8_SRGB:
10514      for (i = 0; i < n; ++i) {
10515         pack_float_x8r8g8b8_srgb(src[i], d);
10516         d += 4;
10517      }
10518      break;
10519
10520   case MESA_FORMAT_R8G8B8A8_SRGB:
10521      for (i = 0; i < n; ++i) {
10522         pack_float_r8g8b8a8_srgb(src[i], d);
10523         d += 4;
10524      }
10525      break;
10526
10527   case MESA_FORMAT_R8G8B8X8_SRGB:
10528      for (i = 0; i < n; ++i) {
10529         pack_float_r8g8b8x8_srgb(src[i], d);
10530         d += 4;
10531      }
10532      break;
10533
10534   case MESA_FORMAT_X8B8G8R8_SRGB:
10535      for (i = 0; i < n; ++i) {
10536         pack_float_x8b8g8r8_srgb(src[i], d);
10537         d += 4;
10538      }
10539      break;
10540
10541   case MESA_FORMAT_L8A8_SRGB:
10542      for (i = 0; i < n; ++i) {
10543         pack_float_l8a8_srgb(src[i], d);
10544         d += 2;
10545      }
10546      break;
10547
10548   case MESA_FORMAT_A8L8_SRGB:
10549      for (i = 0; i < n; ++i) {
10550         pack_float_a8l8_srgb(src[i], d);
10551         d += 2;
10552      }
10553      break;
10554
10555   case MESA_FORMAT_R_SRGB8:
10556      for (i = 0; i < n; ++i) {
10557         pack_float_r_srgb8(src[i], d);
10558         d += 1;
10559      }
10560      break;
10561
10562   case MESA_FORMAT_L_SRGB8:
10563      for (i = 0; i < n; ++i) {
10564         pack_float_l_srgb8(src[i], d);
10565         d += 1;
10566      }
10567      break;
10568
10569   case MESA_FORMAT_BGR_SRGB8:
10570      for (i = 0; i < n; ++i) {
10571         pack_float_bgr_srgb8(src[i], d);
10572         d += 3;
10573      }
10574      break;
10575
10576   case MESA_FORMAT_R9G9B9E5_FLOAT:
10577      for (i = 0; i < n; ++i) {
10578         pack_float_r9g9b9e5_float(src[i], d);
10579         d += 4;
10580      }
10581      break;
10582
10583   case MESA_FORMAT_R11G11B10_FLOAT:
10584      for (i = 0; i < n; ++i) {
10585         pack_float_r11g11b10_float(src[i], d);
10586         d += 4;
10587      }
10588      break;
10589
10590   case MESA_FORMAT_A_FLOAT16:
10591      for (i = 0; i < n; ++i) {
10592         pack_float_a_float16(src[i], d);
10593         d += 2;
10594      }
10595      break;
10596
10597   case MESA_FORMAT_A_FLOAT32:
10598      for (i = 0; i < n; ++i) {
10599         pack_float_a_float32(src[i], d);
10600         d += 4;
10601      }
10602      break;
10603
10604   case MESA_FORMAT_L_FLOAT16:
10605      for (i = 0; i < n; ++i) {
10606         pack_float_l_float16(src[i], d);
10607         d += 2;
10608      }
10609      break;
10610
10611   case MESA_FORMAT_L_FLOAT32:
10612      for (i = 0; i < n; ++i) {
10613         pack_float_l_float32(src[i], d);
10614         d += 4;
10615      }
10616      break;
10617
10618   case MESA_FORMAT_LA_FLOAT16:
10619      for (i = 0; i < n; ++i) {
10620         pack_float_la_float16(src[i], d);
10621         d += 4;
10622      }
10623      break;
10624
10625   case MESA_FORMAT_LA_FLOAT32:
10626      for (i = 0; i < n; ++i) {
10627         pack_float_la_float32(src[i], d);
10628         d += 8;
10629      }
10630      break;
10631
10632   case MESA_FORMAT_I_FLOAT16:
10633      for (i = 0; i < n; ++i) {
10634         pack_float_i_float16(src[i], d);
10635         d += 2;
10636      }
10637      break;
10638
10639   case MESA_FORMAT_I_FLOAT32:
10640      for (i = 0; i < n; ++i) {
10641         pack_float_i_float32(src[i], d);
10642         d += 4;
10643      }
10644      break;
10645
10646   case MESA_FORMAT_R_FLOAT16:
10647      for (i = 0; i < n; ++i) {
10648         pack_float_r_float16(src[i], d);
10649         d += 2;
10650      }
10651      break;
10652
10653   case MESA_FORMAT_R_FLOAT32:
10654      for (i = 0; i < n; ++i) {
10655         pack_float_r_float32(src[i], d);
10656         d += 4;
10657      }
10658      break;
10659
10660   case MESA_FORMAT_RG_FLOAT16:
10661      for (i = 0; i < n; ++i) {
10662         pack_float_rg_float16(src[i], d);
10663         d += 4;
10664      }
10665      break;
10666
10667   case MESA_FORMAT_RG_FLOAT32:
10668      for (i = 0; i < n; ++i) {
10669         pack_float_rg_float32(src[i], d);
10670         d += 8;
10671      }
10672      break;
10673
10674   case MESA_FORMAT_RGB_FLOAT16:
10675      for (i = 0; i < n; ++i) {
10676         pack_float_rgb_float16(src[i], d);
10677         d += 6;
10678      }
10679      break;
10680
10681   case MESA_FORMAT_RGB_FLOAT32:
10682      for (i = 0; i < n; ++i) {
10683         pack_float_rgb_float32(src[i], d);
10684         d += 12;
10685      }
10686      break;
10687
10688   case MESA_FORMAT_RGBA_FLOAT16:
10689      for (i = 0; i < n; ++i) {
10690         pack_float_rgba_float16(src[i], d);
10691         d += 8;
10692      }
10693      break;
10694
10695   case MESA_FORMAT_RGBA_FLOAT32:
10696      for (i = 0; i < n; ++i) {
10697         pack_float_rgba_float32(src[i], d);
10698         d += 16;
10699      }
10700      break;
10701
10702   case MESA_FORMAT_RGBX_FLOAT16:
10703      for (i = 0; i < n; ++i) {
10704         pack_float_rgbx_float16(src[i], d);
10705         d += 8;
10706      }
10707      break;
10708
10709   case MESA_FORMAT_RGBX_FLOAT32:
10710      for (i = 0; i < n; ++i) {
10711         pack_float_rgbx_float32(src[i], d);
10712         d += 16;
10713      }
10714      break;
10715                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       default:
10716      assert(!"Invalid format");
10717   }
10718}
10719
10720/**
10721 * Pack a 2D image of ubyte RGBA pixels in the given format.
10722 * \param srcRowStride  source image row stride in bytes
10723 * \param dstRowStride  destination image row stride in bytes
10724 */
10725void
10726_mesa_pack_ubyte_rgba_rect(mesa_format format, GLuint width, GLuint height,
10727                           const GLubyte *src, GLint srcRowStride,
10728                           void *dst, GLint dstRowStride)
10729{
10730   GLubyte *dstUB = dst;
10731   GLuint i;
10732
10733   if (srcRowStride == width * 4 * sizeof(GLubyte) &&
10734       dstRowStride == _mesa_format_row_stride(format, width)) {
10735      /* do whole image at once */
10736      _mesa_pack_ubyte_rgba_row(format, width * height,
10737                                (const GLubyte (*)[4]) src, dst);
10738   }
10739   else {
10740      /* row by row */
10741      for (i = 0; i < height; i++) {
10742         _mesa_pack_ubyte_rgba_row(format, width,
10743                                   (const GLubyte (*)[4]) src, dstUB);
10744         src += srcRowStride;
10745         dstUB += dstRowStride;
10746      }
10747   }
10748}
10749
10750
10751/** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
10752struct z32f_x24s8
10753{
10754   float z;
10755   uint32_t x24s8;
10756};
10757
10758
10759/**
10760 ** Pack float Z pixels
10761 **/
10762
10763static void
10764pack_float_S8_UINT_Z24_UNORM(const GLfloat *src, void *dst)
10765{
10766   /* don't disturb the stencil values */
10767   GLuint *d = ((GLuint *) dst);
10768   const GLdouble scale = (GLdouble) 0xffffff;
10769   GLuint s = *d & 0xff;
10770   GLuint z = (GLuint) (*src * scale);
10771   assert(z <= 0xffffff);
10772   *d = (z << 8) | s;
10773}
10774
10775static void
10776pack_float_Z24_UNORM_S8_UINT(const GLfloat *src, void *dst)
10777{
10778   /* don't disturb the stencil values */
10779   GLuint *d = ((GLuint *) dst);
10780   const GLdouble scale = (GLdouble) 0xffffff;
10781   GLuint s = *d & 0xff000000;
10782   GLuint z = (GLuint) (*src * scale);
10783   assert(z <= 0xffffff);
10784   *d = s | z;
10785}
10786
10787static void
10788pack_float_Z_UNORM16(const GLfloat *src, void *dst)
10789{
10790   GLushort *d = ((GLushort *) dst);
10791   const GLfloat scale = (GLfloat) 0xffff;
10792   *d = (GLushort) (*src * scale);
10793}
10794
10795static void
10796pack_float_Z_UNORM32(const GLfloat *src, void *dst)
10797{
10798   GLuint *d = ((GLuint *) dst);
10799   const GLdouble scale = (GLdouble) 0xffffffff;
10800   *d = (GLuint) (*src * scale);
10801}
10802
10803/**
10804 ** Pack float to Z_FLOAT32 or Z_FLOAT32_X24S8.
10805 **/
10806
10807static void
10808pack_float_Z_FLOAT32(const GLfloat *src, void *dst)
10809{
10810   GLfloat *d = (GLfloat *) dst;
10811   *d = *src;
10812}
10813
10814gl_pack_float_z_func
10815_mesa_get_pack_float_z_func(mesa_format format)
10816{
10817   switch (format) {
10818   case MESA_FORMAT_S8_UINT_Z24_UNORM:
10819   case MESA_FORMAT_X8_UINT_Z24_UNORM:
10820      return pack_float_S8_UINT_Z24_UNORM;
10821   case MESA_FORMAT_Z24_UNORM_S8_UINT:
10822   case MESA_FORMAT_Z24_UNORM_X8_UINT:
10823      return pack_float_Z24_UNORM_S8_UINT;
10824   case MESA_FORMAT_Z_UNORM16:
10825      return pack_float_Z_UNORM16;
10826   case MESA_FORMAT_Z_UNORM32:
10827      return pack_float_Z_UNORM32;
10828   case MESA_FORMAT_Z_FLOAT32:
10829   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
10830      return pack_float_Z_FLOAT32;
10831   default:
10832      _mesa_problem(NULL,
10833                    "unexpected format in _mesa_get_pack_float_z_func()");
10834      return NULL;
10835   }
10836}
10837
10838
10839
10840/**
10841 ** Pack uint Z pixels.  The incoming src value is always in
10842 ** the range [0, 2^32-1].
10843 **/
10844
10845static void
10846pack_uint_S8_UINT_Z24_UNORM(const GLuint *src, void *dst)
10847{
10848   /* don't disturb the stencil values */
10849   GLuint *d = ((GLuint *) dst);
10850   GLuint s = *d & 0xff;
10851   GLuint z = *src & 0xffffff00;
10852   *d = z | s;
10853}
10854
10855static void
10856pack_uint_Z24_UNORM_S8_UINT(const GLuint *src, void *dst)
10857{
10858   /* don't disturb the stencil values */
10859   GLuint *d = ((GLuint *) dst);
10860   GLuint s = *d & 0xff000000;
10861   GLuint z = *src >> 8;
10862   *d = s | z;
10863}
10864
10865static void
10866pack_uint_Z_UNORM16(const GLuint *src, void *dst)
10867{
10868   GLushort *d = ((GLushort *) dst);
10869   *d = *src >> 16;
10870}
10871
10872static void
10873pack_uint_Z_UNORM32(const GLuint *src, void *dst)
10874{
10875   GLuint *d = ((GLuint *) dst);
10876   *d = *src;
10877}
10878
10879/**
10880 ** Pack uint to Z_FLOAT32 or Z_FLOAT32_X24S8.
10881 **/
10882
10883static void
10884pack_uint_Z_FLOAT32(const GLuint *src, void *dst)
10885{
10886   GLfloat *d = ((GLfloat *) dst);
10887   const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
10888   *d = (GLfloat) (*src * scale);
10889   assert(*d >= 0.0f);
10890   assert(*d <= 1.0f);
10891}
10892
10893gl_pack_uint_z_func
10894_mesa_get_pack_uint_z_func(mesa_format format)
10895{
10896   switch (format) {
10897   case MESA_FORMAT_S8_UINT_Z24_UNORM:
10898   case MESA_FORMAT_X8_UINT_Z24_UNORM:
10899      return pack_uint_S8_UINT_Z24_UNORM;
10900   case MESA_FORMAT_Z24_UNORM_S8_UINT:
10901   case MESA_FORMAT_Z24_UNORM_X8_UINT:
10902      return pack_uint_Z24_UNORM_S8_UINT;
10903   case MESA_FORMAT_Z_UNORM16:
10904      return pack_uint_Z_UNORM16;
10905   case MESA_FORMAT_Z_UNORM32:
10906      return pack_uint_Z_UNORM32;
10907   case MESA_FORMAT_Z_FLOAT32:
10908   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
10909      return pack_uint_Z_FLOAT32;
10910   default:
10911      _mesa_problem(NULL, "unexpected format in _mesa_get_pack_uint_z_func()");
10912      return NULL;
10913   }
10914}
10915
10916
10917/**
10918 ** Pack ubyte stencil pixels
10919 **/
10920
10921static void
10922pack_ubyte_stencil_Z24_S8(const GLubyte *src, void *dst)
10923{
10924   /* don't disturb the Z values */
10925   GLuint *d = ((GLuint *) dst);
10926   GLuint s = *src;
10927   GLuint z = *d & 0xffffff00;
10928   *d = z | s;
10929}
10930
10931static void
10932pack_ubyte_stencil_S8_Z24(const GLubyte *src, void *dst)
10933{
10934   /* don't disturb the Z values */
10935   GLuint *d = ((GLuint *) dst);
10936   GLuint s = *src << 24;
10937   GLuint z = *d & 0xffffff;
10938   *d = s | z;
10939}
10940
10941static void
10942pack_ubyte_stencil_S8(const GLubyte *src, void *dst)
10943{
10944   GLubyte *d = (GLubyte *) dst;
10945   *d = *src;
10946}
10947
10948static void
10949pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte *src, void *dst)
10950{
10951   GLfloat *d = ((GLfloat *) dst);
10952   d[1] = *src;
10953}
10954
10955
10956gl_pack_ubyte_stencil_func
10957_mesa_get_pack_ubyte_stencil_func(mesa_format format)
10958{
10959   switch (format) {
10960   case MESA_FORMAT_S8_UINT_Z24_UNORM:
10961      return pack_ubyte_stencil_Z24_S8;
10962   case MESA_FORMAT_Z24_UNORM_S8_UINT:
10963      return pack_ubyte_stencil_S8_Z24;
10964   case MESA_FORMAT_S_UINT8:
10965      return pack_ubyte_stencil_S8;
10966   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
10967      return pack_ubyte_stencil_Z32_FLOAT_X24S8;
10968   default:
10969      _mesa_problem(NULL,
10970                    "unexpected format in _mesa_pack_ubyte_stencil_func()");
10971      return NULL;
10972   }
10973}
10974
10975
10976
10977void
10978_mesa_pack_float_z_row(mesa_format format, GLuint n,
10979                       const GLfloat *src, void *dst)
10980{
10981   switch (format) {
10982   case MESA_FORMAT_S8_UINT_Z24_UNORM:
10983   case MESA_FORMAT_X8_UINT_Z24_UNORM:
10984      {
10985         /* don't disturb the stencil values */
10986         GLuint *d = ((GLuint *) dst);
10987         const GLdouble scale = (GLdouble) 0xffffff;
10988         GLuint i;
10989         for (i = 0; i < n; i++) {
10990            GLuint s = d[i] & 0xff;
10991            GLuint z = (GLuint) (src[i] * scale);
10992            assert(z <= 0xffffff);
10993            d[i] = (z << 8) | s;
10994         }
10995      }
10996      break;
10997   case MESA_FORMAT_Z24_UNORM_S8_UINT:
10998   case MESA_FORMAT_Z24_UNORM_X8_UINT:
10999      {
11000         /* don't disturb the stencil values */
11001         GLuint *d = ((GLuint *) dst);
11002         const GLdouble scale = (GLdouble) 0xffffff;
11003         GLuint i;
11004         for (i = 0; i < n; i++) {
11005            GLuint s = d[i] & 0xff000000;
11006            GLuint z = (GLuint) (src[i] * scale);
11007            assert(z <= 0xffffff);
11008            d[i] = s | z;
11009         }
11010      }
11011      break;
11012   case MESA_FORMAT_Z_UNORM16:
11013      {
11014         GLushort *d = ((GLushort *) dst);
11015         const GLfloat scale = (GLfloat) 0xffff;
11016         GLuint i;
11017         for (i = 0; i < n; i++) {
11018            d[i] = (GLushort) (src[i] * scale);
11019         }
11020      }
11021      break;
11022   case MESA_FORMAT_Z_UNORM32:
11023      {
11024         GLuint *d = ((GLuint *) dst);
11025         const GLdouble scale = (GLdouble) 0xffffffff;
11026         GLuint i;
11027         for (i = 0; i < n; i++) {
11028            d[i] = (GLuint) (src[i] * scale);
11029         }
11030      }
11031      break;
11032   case MESA_FORMAT_Z_FLOAT32:
11033      memcpy(dst, src, n * sizeof(GLfloat));
11034      break;
11035   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
11036      {
11037         struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
11038         GLuint i;
11039         for (i = 0; i < n; i++) {
11040            d[i].z = src[i];
11041         }
11042      }
11043      break;
11044   default:
11045      _mesa_problem(NULL, "unexpected format in _mesa_pack_float_z_row()");
11046   }
11047}
11048
11049
11050/**
11051 * The incoming Z values are always in the range [0, 0xffffffff].
11052 */
11053void
11054_mesa_pack_uint_z_row(mesa_format format, GLuint n,
11055                      const GLuint *src, void *dst)
11056{
11057   switch (format) {
11058   case MESA_FORMAT_S8_UINT_Z24_UNORM:
11059   case MESA_FORMAT_X8_UINT_Z24_UNORM:
11060      {
11061         /* don't disturb the stencil values */
11062         GLuint *d = ((GLuint *) dst);
11063         GLuint i;
11064         for (i = 0; i < n; i++) {
11065            GLuint s = d[i] & 0xff;
11066            GLuint z = src[i] & 0xffffff00;
11067            d[i] = z | s;
11068         }
11069      }
11070      break;
11071   case MESA_FORMAT_Z24_UNORM_S8_UINT:
11072   case MESA_FORMAT_Z24_UNORM_X8_UINT:
11073      {
11074         /* don't disturb the stencil values */
11075         GLuint *d = ((GLuint *) dst);
11076         GLuint i;
11077         for (i = 0; i < n; i++) {
11078            GLuint s = d[i] & 0xff000000;
11079            GLuint z = src[i] >> 8;
11080            d[i] = s | z;
11081         }
11082      }
11083      break;
11084   case MESA_FORMAT_Z_UNORM16:
11085      {
11086         GLushort *d = ((GLushort *) dst);
11087         GLuint i;
11088         for (i = 0; i < n; i++) {
11089            d[i] = src[i] >> 16;
11090         }
11091      }
11092      break;
11093   case MESA_FORMAT_Z_UNORM32:
11094      memcpy(dst, src, n * sizeof(GLfloat));
11095      break;
11096   case MESA_FORMAT_Z_FLOAT32:
11097      {
11098         GLuint *d = ((GLuint *) dst);
11099         const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
11100         GLuint i;
11101         for (i = 0; i < n; i++) {
11102            d[i] = (GLuint) (src[i] * scale);
11103            assert(d[i] >= 0.0f);
11104            assert(d[i] <= 1.0f);
11105         }
11106      }
11107      break;
11108   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
11109      {
11110         struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
11111         const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
11112         GLuint i;
11113         for (i = 0; i < n; i++) {
11114            d[i].z = (GLfloat) (src[i] * scale);
11115            assert(d[i].z >= 0.0f);
11116            assert(d[i].z <= 1.0f);
11117         }
11118      }
11119      break;
11120   default:
11121      _mesa_problem(NULL, "unexpected format in _mesa_pack_uint_z_row()");
11122   }
11123}
11124
11125
11126void
11127_mesa_pack_ubyte_stencil_row(mesa_format format, GLuint n,
11128                             const GLubyte *src, void *dst)
11129{
11130   switch (format) {
11131   case MESA_FORMAT_S8_UINT_Z24_UNORM:
11132      {
11133         /* don't disturb the Z values */
11134         GLuint *d = ((GLuint *) dst);
11135         GLuint i;
11136         for (i = 0; i < n; i++) {
11137            GLuint s = src[i];
11138            GLuint z = d[i] & 0xffffff00;
11139            d[i] = z | s;
11140         }
11141      }
11142      break;
11143   case MESA_FORMAT_Z24_UNORM_S8_UINT:
11144      {
11145         /* don't disturb the Z values */
11146         GLuint *d = ((GLuint *) dst);
11147         GLuint i;
11148         for (i = 0; i < n; i++) {
11149            GLuint s = src[i] << 24;
11150            GLuint z = d[i] & 0xffffff;
11151            d[i] = s | z;
11152         }
11153      }
11154      break;
11155   case MESA_FORMAT_S_UINT8:
11156      memcpy(dst, src, n * sizeof(GLubyte));
11157      break;
11158   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
11159      {
11160         struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
11161         GLuint i;
11162         for (i = 0; i < n; i++) {
11163            d[i].x24s8 = src[i];
11164         }
11165      }
11166      break;
11167   default:
11168      _mesa_problem(NULL, "unexpected format in _mesa_pack_ubyte_stencil_row()");
11169   }
11170}
11171
11172
11173/**
11174 * Incoming Z/stencil values are always in uint_24_8 format.
11175 */
11176void
11177_mesa_pack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
11178                                       const GLuint *src, void *dst)
11179{
11180   switch (format) {
11181   case MESA_FORMAT_S8_UINT_Z24_UNORM:
11182      memcpy(dst, src, n * sizeof(GLuint));
11183      break;
11184   case MESA_FORMAT_Z24_UNORM_S8_UINT:
11185      {
11186         GLuint *d = ((GLuint *) dst);
11187         GLuint i;
11188         for (i = 0; i < n; i++) {
11189            GLuint s = src[i] << 24;
11190            GLuint z = src[i] >> 8;
11191            d[i] = s | z;
11192         }
11193      }
11194      break;
11195   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
11196      {
11197         const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
11198         struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
11199         GLuint i;
11200         for (i = 0; i < n; i++) {
11201            GLfloat z = (GLfloat) ((src[i] >> 8) * scale);
11202            d[i].z = z;
11203            d[i].x24s8 = src[i];
11204         }
11205      }
11206      break;
11207   default:
11208      _mesa_problem(NULL, "bad format %s in _mesa_pack_ubyte_s_row",
11209                    _mesa_get_format_name(format));
11210      return;
11211   }
11212}
11213
11214
11215
11216/**
11217 * Convert a boolean color mask to a packed color where each channel of
11218 * the packed value at dst will be 0 or ~0 depending on the colorMask.
11219 */
11220void
11221_mesa_pack_colormask(mesa_format format, const GLubyte colorMask[4], void *dst)
11222{
11223   GLfloat maskColor[4];
11224
11225   switch (_mesa_get_format_datatype(format)) {
11226   case GL_UNSIGNED_NORMALIZED:
11227      /* simple: 1.0 will convert to ~0 in the right bit positions */
11228      maskColor[0] = colorMask[0] ? 1.0f : 0.0f;
11229      maskColor[1] = colorMask[1] ? 1.0f : 0.0f;
11230      maskColor[2] = colorMask[2] ? 1.0f : 0.0f;
11231      maskColor[3] = colorMask[3] ? 1.0f : 0.0f;
11232      _mesa_pack_float_rgba_row(format, 1,
11233                                (const GLfloat (*)[4]) maskColor, dst);
11234      break;
11235   case GL_SIGNED_NORMALIZED:
11236   case GL_FLOAT:
11237      /* These formats are harder because it's hard to know the floating
11238       * point values that will convert to ~0 for each color channel's bits.
11239       * This solution just generates a non-zero value for each color channel
11240       * then fixes up the non-zero values to be ~0.
11241       * Note: we'll need to add special case code if we ever have to deal
11242       * with formats with unequal color channel sizes, like R11_G11_B10.
11243       * We issue a warning below for channel sizes other than 8,16,32.
11244       */
11245      {
11246         GLuint bits = _mesa_get_format_max_bits(format); /* bits per chan */
11247         GLuint bytes = _mesa_get_format_bytes(format);
11248         GLuint i;
11249
11250         /* this should put non-zero values into the channels of dst */
11251         maskColor[0] = colorMask[0] ? -1.0f : 0.0f;
11252         maskColor[1] = colorMask[1] ? -1.0f : 0.0f;
11253         maskColor[2] = colorMask[2] ? -1.0f : 0.0f;
11254         maskColor[3] = colorMask[3] ? -1.0f : 0.0f;
11255         _mesa_pack_float_rgba_row(format, 1,
11256                                   (const GLfloat (*)[4]) maskColor, dst);
11257
11258         /* fix-up the dst channels by converting non-zero values to ~0 */
11259         if (bits == 8) {
11260            GLubyte *d = (GLubyte *) dst;
11261            for (i = 0; i < bytes; i++) {
11262               d[i] = d[i] ? 0xff : 0x0;
11263            }
11264         }
11265         else if (bits == 16) {
11266            GLushort *d = (GLushort *) dst;
11267            for (i = 0; i < bytes / 2; i++) {
11268               d[i] = d[i] ? 0xffff : 0x0;
11269            }
11270         }
11271         else if (bits == 32) {
11272            GLuint *d = (GLuint *) dst;
11273            for (i = 0; i < bytes / 4; i++) {
11274               d[i] = d[i] ? 0xffffffffU : 0x0;
11275            }
11276         }
11277         else {
11278            _mesa_problem(NULL, "unexpected size in _mesa_pack_colormask()");
11279            return;
11280         }
11281      }
11282      break;
11283   default:
11284      _mesa_problem(NULL, "unexpected format data type in gen_color_mask()");
11285      return;
11286   }
11287}
11288
11289