7b0e3ee1bc48b81af013974d36dbd48325815d02
[mesa.git] / src / gallium / auxiliary / util / u_format.h
1 /**************************************************************************
2 *
3 * Copyright 2009-2010 Vmware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #ifndef U_FORMAT_H
30 #define U_FORMAT_H
31
32
33 #include "pipe/p_format.h"
34 #include "pipe/p_defines.h"
35 #include "util/u_debug.h"
36
37 union pipe_color_union;
38
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44
45 /**
46 * Describe how to pack/unpack pixels into/from the prescribed format.
47 *
48 * XXX: This could be renamed to something like util_format_pack, or broke down
49 * in flags inside util_format_block that said exactly what we want.
50 */
51 enum util_format_layout {
52 /**
53 * Formats with util_format_block::width == util_format_block::height == 1
54 * that can be described as an ordinary data structure.
55 */
56 UTIL_FORMAT_LAYOUT_PLAIN = 0,
57
58 /**
59 * Formats with sub-sampled channels.
60 *
61 * This is for formats like YVYU where there is less than one sample per
62 * pixel.
63 */
64 UTIL_FORMAT_LAYOUT_SUBSAMPLED = 3,
65
66 /**
67 * S3 Texture Compression formats.
68 */
69 UTIL_FORMAT_LAYOUT_S3TC = 4,
70
71 /**
72 * Red-Green Texture Compression formats.
73 */
74 UTIL_FORMAT_LAYOUT_RGTC = 5,
75
76 /**
77 * Ericsson Texture Compression
78 */
79 UTIL_FORMAT_LAYOUT_ETC = 6,
80
81 /**
82 * BC6/7 Texture Compression
83 */
84 UTIL_FORMAT_LAYOUT_BPTC = 7,
85
86 UTIL_FORMAT_LAYOUT_ASTC = 8,
87
88 UTIL_FORMAT_LAYOUT_ATC = 9,
89
90 /**
91 * Everything else that doesn't fit in any of the above layouts.
92 */
93 UTIL_FORMAT_LAYOUT_OTHER = 10
94 };
95
96
97 struct util_format_block
98 {
99 /** Block width in pixels */
100 unsigned width;
101
102 /** Block height in pixels */
103 unsigned height;
104
105 /** Block depth in pixels */
106 unsigned depth;
107
108 /** Block size in bits */
109 unsigned bits;
110 };
111
112
113 enum util_format_type {
114 UTIL_FORMAT_TYPE_VOID = 0,
115 UTIL_FORMAT_TYPE_UNSIGNED = 1,
116 UTIL_FORMAT_TYPE_SIGNED = 2,
117 UTIL_FORMAT_TYPE_FIXED = 3,
118 UTIL_FORMAT_TYPE_FLOAT = 4
119 };
120
121
122 enum util_format_colorspace {
123 UTIL_FORMAT_COLORSPACE_RGB = 0,
124 UTIL_FORMAT_COLORSPACE_SRGB = 1,
125 UTIL_FORMAT_COLORSPACE_YUV = 2,
126 UTIL_FORMAT_COLORSPACE_ZS = 3
127 };
128
129
130 struct util_format_channel_description
131 {
132 unsigned type:5; /**< UTIL_FORMAT_TYPE_x */
133 unsigned normalized:1;
134 unsigned pure_integer:1;
135 unsigned size:9; /**< bits per channel */
136 unsigned shift:16; /** number of bits from lsb */
137 };
138
139
140 struct util_format_description
141 {
142 enum pipe_format format;
143
144 const char *name;
145
146 /**
147 * Short name, striped of the prefix, lower case.
148 */
149 const char *short_name;
150
151 /**
152 * Pixel block dimensions.
153 */
154 struct util_format_block block;
155
156 enum util_format_layout layout;
157
158 /**
159 * The number of channels.
160 */
161 unsigned nr_channels:3;
162
163 /**
164 * Whether all channels have the same number of (whole) bytes and type.
165 */
166 unsigned is_array:1;
167
168 /**
169 * Whether the pixel format can be described as a bitfield structure.
170 *
171 * In particular:
172 * - pixel depth must be 8, 16, or 32 bits;
173 * - all channels must be unsigned, signed, or void
174 */
175 unsigned is_bitmask:1;
176
177 /**
178 * Whether channels have mixed types (ignoring UTIL_FORMAT_TYPE_VOID).
179 */
180 unsigned is_mixed:1;
181
182 /**
183 * Whether the format contains UNORM channels
184 */
185 unsigned is_unorm:1;
186
187 /**
188 * Whether the format contains SNORM channels
189 */
190 unsigned is_snorm:1;
191
192 /**
193 * Input channel description, in the order XYZW.
194 *
195 * Only valid for UTIL_FORMAT_LAYOUT_PLAIN formats.
196 *
197 * If each channel is accessed as an individual N-byte value, X is always
198 * at the lowest address in memory, Y is always next, and so on. For all
199 * currently-defined formats, the N-byte value has native endianness.
200 *
201 * If instead a group of channels is accessed as a single N-byte value,
202 * the order of the channels within that value depends on endianness.
203 * For big-endian targets, X is the most significant subvalue,
204 * otherwise it is the least significant one.
205 *
206 * For example, if X is 8 bits and Y is 24 bits, the memory order is:
207 *
208 * 0 1 2 3
209 * little-endian: X Yl Ym Yu (l = lower, m = middle, u = upper)
210 * big-endian: X Yu Ym Yl
211 *
212 * If X is 5 bits, Y is 5 bits, Z is 5 bits and W is 1 bit, the layout is:
213 *
214 * 0 1
215 * msb lsb msb lsb
216 * little-endian: YYYXXXXX WZZZZZYY
217 * big-endian: XXXXXYYY YYZZZZZW
218 */
219 struct util_format_channel_description channel[4];
220
221 /**
222 * Output channel swizzle.
223 *
224 * The order is either:
225 * - RGBA
226 * - YUV(A)
227 * - ZS
228 * depending on the colorspace.
229 */
230 unsigned char swizzle[4];
231
232 /**
233 * Colorspace transformation.
234 */
235 enum util_format_colorspace colorspace;
236
237 /**
238 * Unpack pixel blocks to R8G8B8A8_UNORM.
239 * Note: strides are in bytes.
240 *
241 * Only defined for non-depth-stencil formats.
242 */
243 void
244 (*unpack_rgba_8unorm)(uint8_t *dst, unsigned dst_stride,
245 const uint8_t *src, unsigned src_stride,
246 unsigned width, unsigned height);
247
248 /**
249 * Pack pixel blocks from R8G8B8A8_UNORM.
250 * Note: strides are in bytes.
251 *
252 * Only defined for non-depth-stencil formats.
253 */
254 void
255 (*pack_rgba_8unorm)(uint8_t *dst, unsigned dst_stride,
256 const uint8_t *src, unsigned src_stride,
257 unsigned width, unsigned height);
258
259 /**
260 * Fetch a single pixel (i, j) from a block.
261 *
262 * XXX: Only defined for a very few select formats.
263 */
264 void
265 (*fetch_rgba_8unorm)(uint8_t *dst,
266 const uint8_t *src,
267 unsigned i, unsigned j);
268
269 /**
270 * Unpack pixel blocks to R32G32B32A32_FLOAT.
271 * Note: strides are in bytes.
272 *
273 * Only defined for non-depth-stencil formats.
274 */
275 void
276 (*unpack_rgba_float)(float *dst, unsigned dst_stride,
277 const uint8_t *src, unsigned src_stride,
278 unsigned width, unsigned height);
279
280 /**
281 * Pack pixel blocks from R32G32B32A32_FLOAT.
282 * Note: strides are in bytes.
283 *
284 * Only defined for non-depth-stencil formats.
285 */
286 void
287 (*pack_rgba_float)(uint8_t *dst, unsigned dst_stride,
288 const float *src, unsigned src_stride,
289 unsigned width, unsigned height);
290
291 /**
292 * Fetch a single pixel (i, j) from a block.
293 *
294 * Only defined for non-depth-stencil and non-integer formats.
295 */
296 void
297 (*fetch_rgba_float)(float *dst,
298 const uint8_t *src,
299 unsigned i, unsigned j);
300
301 /**
302 * Unpack pixels to Z32_UNORM.
303 * Note: strides are in bytes.
304 *
305 * Only defined for depth formats.
306 */
307 void
308 (*unpack_z_32unorm)(uint32_t *dst, unsigned dst_stride,
309 const uint8_t *src, unsigned src_stride,
310 unsigned width, unsigned height);
311
312 /**
313 * Pack pixels from Z32_FLOAT.
314 * Note: strides are in bytes.
315 *
316 * Only defined for depth formats.
317 */
318 void
319 (*pack_z_32unorm)(uint8_t *dst, unsigned dst_stride,
320 const uint32_t *src, unsigned src_stride,
321 unsigned width, unsigned height);
322
323 /**
324 * Unpack pixels to Z32_FLOAT.
325 * Note: strides are in bytes.
326 *
327 * Only defined for depth formats.
328 */
329 void
330 (*unpack_z_float)(float *dst, unsigned dst_stride,
331 const uint8_t *src, unsigned src_stride,
332 unsigned width, unsigned height);
333
334 /**
335 * Pack pixels from Z32_FLOAT.
336 * Note: strides are in bytes.
337 *
338 * Only defined for depth formats.
339 */
340 void
341 (*pack_z_float)(uint8_t *dst, unsigned dst_stride,
342 const float *src, unsigned src_stride,
343 unsigned width, unsigned height);
344
345 /**
346 * Unpack pixels to S8_UINT.
347 * Note: strides are in bytes.
348 *
349 * Only defined for stencil formats.
350 */
351 void
352 (*unpack_s_8uint)(uint8_t *dst, unsigned dst_stride,
353 const uint8_t *src, unsigned src_stride,
354 unsigned width, unsigned height);
355
356 /**
357 * Pack pixels from S8_UINT.
358 * Note: strides are in bytes.
359 *
360 * Only defined for stencil formats.
361 */
362 void
363 (*pack_s_8uint)(uint8_t *dst, unsigned dst_stride,
364 const uint8_t *src, unsigned src_stride,
365 unsigned width, unsigned height);
366
367 /**
368 * Unpack pixel blocks to R32G32B32A32_UINT.
369 * Note: strides are in bytes.
370 *
371 * Only defined for INT formats.
372 */
373 void
374 (*unpack_rgba_uint)(uint32_t *dst, unsigned dst_stride,
375 const uint8_t *src, unsigned src_stride,
376 unsigned width, unsigned height);
377
378 void
379 (*pack_rgba_uint)(uint8_t *dst, unsigned dst_stride,
380 const uint32_t *src, unsigned src_stride,
381 unsigned width, unsigned height);
382
383 /**
384 * Unpack pixel blocks to R32G32B32A32_SINT.
385 * Note: strides are in bytes.
386 *
387 * Only defined for INT formats.
388 */
389 void
390 (*unpack_rgba_sint)(int32_t *dst, unsigned dst_stride,
391 const uint8_t *src, unsigned src_stride,
392 unsigned width, unsigned height);
393
394 void
395 (*pack_rgba_sint)(uint8_t *dst, unsigned dst_stride,
396 const int32_t *src, unsigned src_stride,
397 unsigned width, unsigned height);
398
399 /**
400 * Fetch a single pixel (i, j) from a block.
401 *
402 * Only defined for unsigned (pure) integer formats.
403 */
404 void
405 (*fetch_rgba_uint)(uint32_t *dst,
406 const uint8_t *src,
407 unsigned i, unsigned j);
408
409 /**
410 * Fetch a single pixel (i, j) from a block.
411 *
412 * Only defined for signed (pure) integer formats.
413 */
414 void
415 (*fetch_rgba_sint)(int32_t *dst,
416 const uint8_t *src,
417 unsigned i, unsigned j);
418 };
419
420
421 extern const struct util_format_description
422 util_format_description_table[];
423
424
425 const struct util_format_description *
426 util_format_description(enum pipe_format format);
427
428
429 /*
430 * Format query functions.
431 */
432
433 static inline const char *
434 util_format_name(enum pipe_format format)
435 {
436 const struct util_format_description *desc = util_format_description(format);
437
438 assert(desc);
439 if (!desc) {
440 return "PIPE_FORMAT_???";
441 }
442
443 return desc->name;
444 }
445
446 static inline const char *
447 util_format_short_name(enum pipe_format format)
448 {
449 const struct util_format_description *desc = util_format_description(format);
450
451 assert(desc);
452 if (!desc) {
453 return "???";
454 }
455
456 return desc->short_name;
457 }
458
459 /**
460 * Whether this format is plain, see UTIL_FORMAT_LAYOUT_PLAIN for more info.
461 */
462 static inline boolean
463 util_format_is_plain(enum pipe_format format)
464 {
465 const struct util_format_description *desc = util_format_description(format);
466
467 if (!format) {
468 return FALSE;
469 }
470
471 return desc->layout == UTIL_FORMAT_LAYOUT_PLAIN ? TRUE : FALSE;
472 }
473
474 static inline boolean
475 util_format_is_compressed(enum pipe_format format)
476 {
477 const struct util_format_description *desc = util_format_description(format);
478
479 assert(desc);
480 if (!desc) {
481 return FALSE;
482 }
483
484 switch (desc->layout) {
485 case UTIL_FORMAT_LAYOUT_S3TC:
486 case UTIL_FORMAT_LAYOUT_RGTC:
487 case UTIL_FORMAT_LAYOUT_ETC:
488 case UTIL_FORMAT_LAYOUT_BPTC:
489 case UTIL_FORMAT_LAYOUT_ASTC:
490 case UTIL_FORMAT_LAYOUT_ATC:
491 /* XXX add other formats in the future */
492 return TRUE;
493 default:
494 return FALSE;
495 }
496 }
497
498 static inline boolean
499 util_format_is_s3tc(enum pipe_format format)
500 {
501 const struct util_format_description *desc = util_format_description(format);
502
503 assert(desc);
504 if (!desc) {
505 return FALSE;
506 }
507
508 return desc->layout == UTIL_FORMAT_LAYOUT_S3TC ? TRUE : FALSE;
509 }
510
511 static inline boolean
512 util_format_is_etc(enum pipe_format format)
513 {
514 const struct util_format_description *desc = util_format_description(format);
515
516 assert(desc);
517 if (!desc) {
518 return FALSE;
519 }
520
521 return desc->layout == UTIL_FORMAT_LAYOUT_ETC ? TRUE : FALSE;
522 }
523
524 static inline boolean
525 util_format_is_srgb(enum pipe_format format)
526 {
527 const struct util_format_description *desc = util_format_description(format);
528 return desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB;
529 }
530
531 static inline boolean
532 util_format_has_depth(const struct util_format_description *desc)
533 {
534 return desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS &&
535 desc->swizzle[0] != PIPE_SWIZZLE_NONE;
536 }
537
538 static inline boolean
539 util_format_has_stencil(const struct util_format_description *desc)
540 {
541 return desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS &&
542 desc->swizzle[1] != PIPE_SWIZZLE_NONE;
543 }
544
545 static inline boolean
546 util_format_is_depth_or_stencil(enum pipe_format format)
547 {
548 const struct util_format_description *desc = util_format_description(format);
549
550 assert(desc);
551 if (!desc) {
552 return FALSE;
553 }
554
555 return util_format_has_depth(desc) ||
556 util_format_has_stencil(desc);
557 }
558
559 static inline boolean
560 util_format_is_depth_and_stencil(enum pipe_format format)
561 {
562 const struct util_format_description *desc = util_format_description(format);
563
564 assert(desc);
565 if (!desc) {
566 return FALSE;
567 }
568
569 return util_format_has_depth(desc) &&
570 util_format_has_stencil(desc);
571 }
572
573 /**
574 * For depth-stencil formats, return the equivalent depth-only format.
575 */
576 static inline enum pipe_format
577 util_format_get_depth_only(enum pipe_format format)
578 {
579 switch (format) {
580 case PIPE_FORMAT_Z24_UNORM_S8_UINT:
581 return PIPE_FORMAT_Z24X8_UNORM;
582
583 case PIPE_FORMAT_S8_UINT_Z24_UNORM:
584 return PIPE_FORMAT_X8Z24_UNORM;
585
586 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
587 return PIPE_FORMAT_Z32_FLOAT;
588
589 default:
590 return format;
591 }
592 }
593
594 static inline boolean
595 util_format_is_yuv(enum pipe_format format)
596 {
597 const struct util_format_description *desc = util_format_description(format);
598
599 assert(desc);
600 if (!desc) {
601 return FALSE;
602 }
603
604 return desc->colorspace == UTIL_FORMAT_COLORSPACE_YUV;
605 }
606
607 /**
608 * Calculates the depth format type based upon the incoming format description.
609 */
610 static inline unsigned
611 util_get_depth_format_type(const struct util_format_description *desc)
612 {
613 unsigned depth_channel = desc->swizzle[0];
614 if (desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS &&
615 depth_channel != PIPE_SWIZZLE_NONE) {
616 return desc->channel[depth_channel].type;
617 } else {
618 return UTIL_FORMAT_TYPE_VOID;
619 }
620 }
621
622
623 /**
624 * Calculates the MRD for the depth format. MRD is used in depth bias
625 * for UNORM and unbound depth buffers. When the depth buffer is floating
626 * point, the depth bias calculation does not use the MRD. However, the
627 * default MRD will be 1.0 / ((1 << 24) - 1).
628 */
629 double
630 util_get_depth_format_mrd(const struct util_format_description *desc);
631
632
633 /**
634 * Return whether this is an RGBA, Z, S, or combined ZS format.
635 * Useful for initializing pipe_blit_info::mask.
636 */
637 static inline unsigned
638 util_format_get_mask(enum pipe_format format)
639 {
640 const struct util_format_description *desc =
641 util_format_description(format);
642
643 if (!desc)
644 return 0;
645
646 if (util_format_has_depth(desc)) {
647 if (util_format_has_stencil(desc)) {
648 return PIPE_MASK_ZS;
649 } else {
650 return PIPE_MASK_Z;
651 }
652 } else {
653 if (util_format_has_stencil(desc)) {
654 return PIPE_MASK_S;
655 } else {
656 return PIPE_MASK_RGBA;
657 }
658 }
659 }
660
661 /**
662 * Give the RGBA colormask of the channels that can be represented in this
663 * format.
664 *
665 * That is, the channels whose values are preserved.
666 */
667 static inline unsigned
668 util_format_colormask(const struct util_format_description *desc)
669 {
670 unsigned colormask;
671 unsigned chan;
672
673 switch (desc->colorspace) {
674 case UTIL_FORMAT_COLORSPACE_RGB:
675 case UTIL_FORMAT_COLORSPACE_SRGB:
676 case UTIL_FORMAT_COLORSPACE_YUV:
677 colormask = 0;
678 for (chan = 0; chan < 4; ++chan) {
679 if (desc->swizzle[chan] < 4) {
680 colormask |= (1 << chan);
681 }
682 }
683 return colormask;
684 case UTIL_FORMAT_COLORSPACE_ZS:
685 return 0;
686 default:
687 assert(0);
688 return 0;
689 }
690 }
691
692
693 /**
694 * Checks if color mask covers every channel for the specified format
695 *
696 * @param desc a format description to check colormask with
697 * @param colormask a bit mask for channels, matches format of PIPE_MASK_RGBA
698 */
699 static inline boolean
700 util_format_colormask_full(const struct util_format_description *desc, unsigned colormask)
701 {
702 return (~colormask & util_format_colormask(desc)) == 0;
703 }
704
705
706 boolean
707 util_format_is_float(enum pipe_format format);
708
709
710 boolean
711 util_format_has_alpha(enum pipe_format format);
712
713
714 boolean
715 util_format_is_luminance(enum pipe_format format);
716
717 boolean
718 util_format_is_alpha(enum pipe_format format);
719
720 boolean
721 util_format_is_luminance_alpha(enum pipe_format format);
722
723
724 boolean
725 util_format_is_intensity(enum pipe_format format);
726
727 boolean
728 util_format_is_subsampled_422(enum pipe_format format);
729
730 boolean
731 util_format_is_pure_integer(enum pipe_format format);
732
733 boolean
734 util_format_is_pure_sint(enum pipe_format format);
735
736 boolean
737 util_format_is_pure_uint(enum pipe_format format);
738
739 boolean
740 util_format_is_snorm(enum pipe_format format);
741
742 boolean
743 util_format_is_unorm(enum pipe_format format);
744
745 boolean
746 util_format_is_snorm8(enum pipe_format format);
747
748 /**
749 * Check if the src format can be blitted to the destination format with
750 * a simple memcpy. For example, blitting from RGBA to RGBx is OK, but not
751 * the reverse.
752 */
753 boolean
754 util_is_format_compatible(const struct util_format_description *src_desc,
755 const struct util_format_description *dst_desc);
756
757 /**
758 * Whether this format is a rgab8 variant.
759 *
760 * That is, any format that matches the
761 *
762 * PIPE_FORMAT_?8?8?8?8_UNORM
763 */
764 static inline boolean
765 util_format_is_rgba8_variant(const struct util_format_description *desc)
766 {
767 unsigned chan;
768
769 if(desc->block.width != 1 ||
770 desc->block.height != 1 ||
771 desc->block.bits != 32)
772 return FALSE;
773
774 for(chan = 0; chan < 4; ++chan) {
775 if(desc->channel[chan].type != UTIL_FORMAT_TYPE_UNSIGNED &&
776 desc->channel[chan].type != UTIL_FORMAT_TYPE_VOID)
777 return FALSE;
778 if(desc->channel[chan].type == UTIL_FORMAT_TYPE_UNSIGNED &&
779 !desc->channel[chan].normalized)
780 return FALSE;
781 if(desc->channel[chan].size != 8)
782 return FALSE;
783 }
784
785 return TRUE;
786 }
787
788 /**
789 * Return total bits needed for the pixel format per block.
790 */
791 static inline uint
792 util_format_get_blocksizebits(enum pipe_format format)
793 {
794 const struct util_format_description *desc = util_format_description(format);
795
796 assert(desc);
797 if (!desc) {
798 return 0;
799 }
800
801 return desc->block.bits;
802 }
803
804 /**
805 * Return bytes per block (not pixel) for the given format.
806 */
807 static inline uint
808 util_format_get_blocksize(enum pipe_format format)
809 {
810 uint bits = util_format_get_blocksizebits(format);
811 uint bytes = bits / 8;
812
813 assert(bits % 8 == 0);
814 assert(bytes > 0);
815 if (bytes == 0) {
816 bytes = 1;
817 }
818
819 return bytes;
820 }
821
822 static inline uint
823 util_format_get_blockwidth(enum pipe_format format)
824 {
825 const struct util_format_description *desc = util_format_description(format);
826
827 assert(desc);
828 if (!desc) {
829 return 1;
830 }
831
832 return desc->block.width;
833 }
834
835 static inline uint
836 util_format_get_blockheight(enum pipe_format format)
837 {
838 const struct util_format_description *desc = util_format_description(format);
839
840 assert(desc);
841 if (!desc) {
842 return 1;
843 }
844
845 return desc->block.height;
846 }
847
848 static inline uint
849 util_format_get_blockdepth(enum pipe_format format)
850 {
851 const struct util_format_description *desc = util_format_description(format);
852
853 assert(desc);
854 if (!desc) {
855 return 1;
856 }
857
858 return desc->block.depth;
859 }
860
861 static inline unsigned
862 util_format_get_nblocksx(enum pipe_format format,
863 unsigned x)
864 {
865 unsigned blockwidth = util_format_get_blockwidth(format);
866 return (x + blockwidth - 1) / blockwidth;
867 }
868
869 static inline unsigned
870 util_format_get_nblocksy(enum pipe_format format,
871 unsigned y)
872 {
873 unsigned blockheight = util_format_get_blockheight(format);
874 return (y + blockheight - 1) / blockheight;
875 }
876
877 static inline unsigned
878 util_format_get_nblocksz(enum pipe_format format,
879 unsigned z)
880 {
881 unsigned blockdepth = util_format_get_blockdepth(format);
882 return (z + blockdepth - 1) / blockdepth;
883 }
884
885 static inline unsigned
886 util_format_get_nblocks(enum pipe_format format,
887 unsigned width,
888 unsigned height)
889 {
890 assert(util_format_get_blockdepth(format) == 1);
891 return util_format_get_nblocksx(format, width) * util_format_get_nblocksy(format, height);
892 }
893
894 static inline size_t
895 util_format_get_stride(enum pipe_format format,
896 unsigned width)
897 {
898 return (size_t)util_format_get_nblocksx(format, width) * util_format_get_blocksize(format);
899 }
900
901 static inline size_t
902 util_format_get_2d_size(enum pipe_format format,
903 size_t stride,
904 unsigned height)
905 {
906 return util_format_get_nblocksy(format, height) * stride;
907 }
908
909 static inline uint
910 util_format_get_component_bits(enum pipe_format format,
911 enum util_format_colorspace colorspace,
912 uint component)
913 {
914 const struct util_format_description *desc = util_format_description(format);
915 enum util_format_colorspace desc_colorspace;
916
917 assert(format);
918 if (!format) {
919 return 0;
920 }
921
922 assert(component < 4);
923
924 /* Treat RGB and SRGB as equivalent. */
925 if (colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
926 colorspace = UTIL_FORMAT_COLORSPACE_RGB;
927 }
928 if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
929 desc_colorspace = UTIL_FORMAT_COLORSPACE_RGB;
930 } else {
931 desc_colorspace = desc->colorspace;
932 }
933
934 if (desc_colorspace != colorspace) {
935 return 0;
936 }
937
938 switch (desc->swizzle[component]) {
939 case PIPE_SWIZZLE_X:
940 return desc->channel[0].size;
941 case PIPE_SWIZZLE_Y:
942 return desc->channel[1].size;
943 case PIPE_SWIZZLE_Z:
944 return desc->channel[2].size;
945 case PIPE_SWIZZLE_W:
946 return desc->channel[3].size;
947 default:
948 return 0;
949 }
950 }
951
952 /**
953 * Given a linear RGB colorspace format, return the corresponding SRGB
954 * format, or PIPE_FORMAT_NONE if none.
955 */
956 static inline enum pipe_format
957 util_format_srgb(enum pipe_format format)
958 {
959 if (util_format_is_srgb(format))
960 return format;
961
962 switch (format) {
963 case PIPE_FORMAT_L8_UNORM:
964 return PIPE_FORMAT_L8_SRGB;
965 case PIPE_FORMAT_R8_UNORM:
966 return PIPE_FORMAT_R8_SRGB;
967 case PIPE_FORMAT_L8A8_UNORM:
968 return PIPE_FORMAT_L8A8_SRGB;
969 case PIPE_FORMAT_R8G8B8_UNORM:
970 return PIPE_FORMAT_R8G8B8_SRGB;
971 case PIPE_FORMAT_A8B8G8R8_UNORM:
972 return PIPE_FORMAT_A8B8G8R8_SRGB;
973 case PIPE_FORMAT_X8B8G8R8_UNORM:
974 return PIPE_FORMAT_X8B8G8R8_SRGB;
975 case PIPE_FORMAT_B8G8R8A8_UNORM:
976 return PIPE_FORMAT_B8G8R8A8_SRGB;
977 case PIPE_FORMAT_B8G8R8X8_UNORM:
978 return PIPE_FORMAT_B8G8R8X8_SRGB;
979 case PIPE_FORMAT_A8R8G8B8_UNORM:
980 return PIPE_FORMAT_A8R8G8B8_SRGB;
981 case PIPE_FORMAT_X8R8G8B8_UNORM:
982 return PIPE_FORMAT_X8R8G8B8_SRGB;
983 case PIPE_FORMAT_R8G8B8A8_UNORM:
984 return PIPE_FORMAT_R8G8B8A8_SRGB;
985 case PIPE_FORMAT_R8G8B8X8_UNORM:
986 return PIPE_FORMAT_R8G8B8X8_SRGB;
987 case PIPE_FORMAT_DXT1_RGB:
988 return PIPE_FORMAT_DXT1_SRGB;
989 case PIPE_FORMAT_DXT1_RGBA:
990 return PIPE_FORMAT_DXT1_SRGBA;
991 case PIPE_FORMAT_DXT3_RGBA:
992 return PIPE_FORMAT_DXT3_SRGBA;
993 case PIPE_FORMAT_DXT5_RGBA:
994 return PIPE_FORMAT_DXT5_SRGBA;
995 case PIPE_FORMAT_B5G6R5_UNORM:
996 return PIPE_FORMAT_B5G6R5_SRGB;
997 case PIPE_FORMAT_BPTC_RGBA_UNORM:
998 return PIPE_FORMAT_BPTC_SRGBA;
999 case PIPE_FORMAT_ETC2_RGB8:
1000 return PIPE_FORMAT_ETC2_SRGB8;
1001 case PIPE_FORMAT_ETC2_RGB8A1:
1002 return PIPE_FORMAT_ETC2_SRGB8A1;
1003 case PIPE_FORMAT_ETC2_RGBA8:
1004 return PIPE_FORMAT_ETC2_SRGBA8;
1005 case PIPE_FORMAT_ASTC_4x4:
1006 return PIPE_FORMAT_ASTC_4x4_SRGB;
1007 case PIPE_FORMAT_ASTC_5x4:
1008 return PIPE_FORMAT_ASTC_5x4_SRGB;
1009 case PIPE_FORMAT_ASTC_5x5:
1010 return PIPE_FORMAT_ASTC_5x5_SRGB;
1011 case PIPE_FORMAT_ASTC_6x5:
1012 return PIPE_FORMAT_ASTC_6x5_SRGB;
1013 case PIPE_FORMAT_ASTC_6x6:
1014 return PIPE_FORMAT_ASTC_6x6_SRGB;
1015 case PIPE_FORMAT_ASTC_8x5:
1016 return PIPE_FORMAT_ASTC_8x5_SRGB;
1017 case PIPE_FORMAT_ASTC_8x6:
1018 return PIPE_FORMAT_ASTC_8x6_SRGB;
1019 case PIPE_FORMAT_ASTC_8x8:
1020 return PIPE_FORMAT_ASTC_8x8_SRGB;
1021 case PIPE_FORMAT_ASTC_10x5:
1022 return PIPE_FORMAT_ASTC_10x5_SRGB;
1023 case PIPE_FORMAT_ASTC_10x6:
1024 return PIPE_FORMAT_ASTC_10x6_SRGB;
1025 case PIPE_FORMAT_ASTC_10x8:
1026 return PIPE_FORMAT_ASTC_10x8_SRGB;
1027 case PIPE_FORMAT_ASTC_10x10:
1028 return PIPE_FORMAT_ASTC_10x10_SRGB;
1029 case PIPE_FORMAT_ASTC_12x10:
1030 return PIPE_FORMAT_ASTC_12x10_SRGB;
1031 case PIPE_FORMAT_ASTC_12x12:
1032 return PIPE_FORMAT_ASTC_12x12_SRGB;
1033
1034 default:
1035 return PIPE_FORMAT_NONE;
1036 }
1037 }
1038
1039 /**
1040 * Given an sRGB format, return the corresponding linear colorspace format.
1041 * For non sRGB formats, return the format unchanged.
1042 */
1043 static inline enum pipe_format
1044 util_format_linear(enum pipe_format format)
1045 {
1046 switch (format) {
1047 case PIPE_FORMAT_L8_SRGB:
1048 return PIPE_FORMAT_L8_UNORM;
1049 case PIPE_FORMAT_R8_SRGB:
1050 return PIPE_FORMAT_R8_UNORM;
1051 case PIPE_FORMAT_L8A8_SRGB:
1052 return PIPE_FORMAT_L8A8_UNORM;
1053 case PIPE_FORMAT_R8G8B8_SRGB:
1054 return PIPE_FORMAT_R8G8B8_UNORM;
1055 case PIPE_FORMAT_A8B8G8R8_SRGB:
1056 return PIPE_FORMAT_A8B8G8R8_UNORM;
1057 case PIPE_FORMAT_X8B8G8R8_SRGB:
1058 return PIPE_FORMAT_X8B8G8R8_UNORM;
1059 case PIPE_FORMAT_B8G8R8A8_SRGB:
1060 return PIPE_FORMAT_B8G8R8A8_UNORM;
1061 case PIPE_FORMAT_B8G8R8X8_SRGB:
1062 return PIPE_FORMAT_B8G8R8X8_UNORM;
1063 case PIPE_FORMAT_A8R8G8B8_SRGB:
1064 return PIPE_FORMAT_A8R8G8B8_UNORM;
1065 case PIPE_FORMAT_X8R8G8B8_SRGB:
1066 return PIPE_FORMAT_X8R8G8B8_UNORM;
1067 case PIPE_FORMAT_R8G8B8A8_SRGB:
1068 return PIPE_FORMAT_R8G8B8A8_UNORM;
1069 case PIPE_FORMAT_R8G8B8X8_SRGB:
1070 return PIPE_FORMAT_R8G8B8X8_UNORM;
1071 case PIPE_FORMAT_DXT1_SRGB:
1072 return PIPE_FORMAT_DXT1_RGB;
1073 case PIPE_FORMAT_DXT1_SRGBA:
1074 return PIPE_FORMAT_DXT1_RGBA;
1075 case PIPE_FORMAT_DXT3_SRGBA:
1076 return PIPE_FORMAT_DXT3_RGBA;
1077 case PIPE_FORMAT_DXT5_SRGBA:
1078 return PIPE_FORMAT_DXT5_RGBA;
1079 case PIPE_FORMAT_B5G6R5_SRGB:
1080 return PIPE_FORMAT_B5G6R5_UNORM;
1081 case PIPE_FORMAT_BPTC_SRGBA:
1082 return PIPE_FORMAT_BPTC_RGBA_UNORM;
1083 case PIPE_FORMAT_ETC2_SRGB8:
1084 return PIPE_FORMAT_ETC2_RGB8;
1085 case PIPE_FORMAT_ETC2_SRGB8A1:
1086 return PIPE_FORMAT_ETC2_RGB8A1;
1087 case PIPE_FORMAT_ETC2_SRGBA8:
1088 return PIPE_FORMAT_ETC2_RGBA8;
1089 case PIPE_FORMAT_ASTC_4x4_SRGB:
1090 return PIPE_FORMAT_ASTC_4x4;
1091 case PIPE_FORMAT_ASTC_5x4_SRGB:
1092 return PIPE_FORMAT_ASTC_5x4;
1093 case PIPE_FORMAT_ASTC_5x5_SRGB:
1094 return PIPE_FORMAT_ASTC_5x5;
1095 case PIPE_FORMAT_ASTC_6x5_SRGB:
1096 return PIPE_FORMAT_ASTC_6x5;
1097 case PIPE_FORMAT_ASTC_6x6_SRGB:
1098 return PIPE_FORMAT_ASTC_6x6;
1099 case PIPE_FORMAT_ASTC_8x5_SRGB:
1100 return PIPE_FORMAT_ASTC_8x5;
1101 case PIPE_FORMAT_ASTC_8x6_SRGB:
1102 return PIPE_FORMAT_ASTC_8x6;
1103 case PIPE_FORMAT_ASTC_8x8_SRGB:
1104 return PIPE_FORMAT_ASTC_8x8;
1105 case PIPE_FORMAT_ASTC_10x5_SRGB:
1106 return PIPE_FORMAT_ASTC_10x5;
1107 case PIPE_FORMAT_ASTC_10x6_SRGB:
1108 return PIPE_FORMAT_ASTC_10x6;
1109 case PIPE_FORMAT_ASTC_10x8_SRGB:
1110 return PIPE_FORMAT_ASTC_10x8;
1111 case PIPE_FORMAT_ASTC_10x10_SRGB:
1112 return PIPE_FORMAT_ASTC_10x10;
1113 case PIPE_FORMAT_ASTC_12x10_SRGB:
1114 return PIPE_FORMAT_ASTC_12x10;
1115 case PIPE_FORMAT_ASTC_12x12_SRGB:
1116 return PIPE_FORMAT_ASTC_12x12;
1117 default:
1118 return format;
1119 }
1120 }
1121
1122 /**
1123 * Given a depth-stencil format, return the corresponding stencil-only format.
1124 * For stencil-only formats, return the format unchanged.
1125 */
1126 static inline enum pipe_format
1127 util_format_stencil_only(enum pipe_format format)
1128 {
1129 switch (format) {
1130 /* mask out the depth component */
1131 case PIPE_FORMAT_Z24_UNORM_S8_UINT:
1132 return PIPE_FORMAT_X24S8_UINT;
1133 case PIPE_FORMAT_S8_UINT_Z24_UNORM:
1134 return PIPE_FORMAT_S8X24_UINT;
1135 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
1136 return PIPE_FORMAT_X32_S8X24_UINT;
1137
1138 /* stencil only formats */
1139 case PIPE_FORMAT_X24S8_UINT:
1140 case PIPE_FORMAT_S8X24_UINT:
1141 case PIPE_FORMAT_X32_S8X24_UINT:
1142 case PIPE_FORMAT_S8_UINT:
1143 return format;
1144
1145 default:
1146 assert(0);
1147 return PIPE_FORMAT_NONE;
1148 }
1149 }
1150
1151 /**
1152 * Converts PIPE_FORMAT_*I* to PIPE_FORMAT_*R*.
1153 * This is identity for non-intensity formats.
1154 */
1155 static inline enum pipe_format
1156 util_format_intensity_to_red(enum pipe_format format)
1157 {
1158 switch (format) {
1159 case PIPE_FORMAT_I8_UNORM:
1160 return PIPE_FORMAT_R8_UNORM;
1161 case PIPE_FORMAT_I8_SNORM:
1162 return PIPE_FORMAT_R8_SNORM;
1163 case PIPE_FORMAT_I16_UNORM:
1164 return PIPE_FORMAT_R16_UNORM;
1165 case PIPE_FORMAT_I16_SNORM:
1166 return PIPE_FORMAT_R16_SNORM;
1167 case PIPE_FORMAT_I16_FLOAT:
1168 return PIPE_FORMAT_R16_FLOAT;
1169 case PIPE_FORMAT_I32_FLOAT:
1170 return PIPE_FORMAT_R32_FLOAT;
1171 case PIPE_FORMAT_I8_UINT:
1172 return PIPE_FORMAT_R8_UINT;
1173 case PIPE_FORMAT_I8_SINT:
1174 return PIPE_FORMAT_R8_SINT;
1175 case PIPE_FORMAT_I16_UINT:
1176 return PIPE_FORMAT_R16_UINT;
1177 case PIPE_FORMAT_I16_SINT:
1178 return PIPE_FORMAT_R16_SINT;
1179 case PIPE_FORMAT_I32_UINT:
1180 return PIPE_FORMAT_R32_UINT;
1181 case PIPE_FORMAT_I32_SINT:
1182 return PIPE_FORMAT_R32_SINT;
1183 default:
1184 assert(!util_format_is_intensity(format));
1185 return format;
1186 }
1187 }
1188
1189 /**
1190 * Converts PIPE_FORMAT_*L* to PIPE_FORMAT_*R*.
1191 * This is identity for non-luminance formats.
1192 */
1193 static inline enum pipe_format
1194 util_format_luminance_to_red(enum pipe_format format)
1195 {
1196 switch (format) {
1197 case PIPE_FORMAT_L8_UNORM:
1198 return PIPE_FORMAT_R8_UNORM;
1199 case PIPE_FORMAT_L8_SNORM:
1200 return PIPE_FORMAT_R8_SNORM;
1201 case PIPE_FORMAT_L16_UNORM:
1202 return PIPE_FORMAT_R16_UNORM;
1203 case PIPE_FORMAT_L16_SNORM:
1204 return PIPE_FORMAT_R16_SNORM;
1205 case PIPE_FORMAT_L16_FLOAT:
1206 return PIPE_FORMAT_R16_FLOAT;
1207 case PIPE_FORMAT_L32_FLOAT:
1208 return PIPE_FORMAT_R32_FLOAT;
1209 case PIPE_FORMAT_L8_UINT:
1210 return PIPE_FORMAT_R8_UINT;
1211 case PIPE_FORMAT_L8_SINT:
1212 return PIPE_FORMAT_R8_SINT;
1213 case PIPE_FORMAT_L16_UINT:
1214 return PIPE_FORMAT_R16_UINT;
1215 case PIPE_FORMAT_L16_SINT:
1216 return PIPE_FORMAT_R16_SINT;
1217 case PIPE_FORMAT_L32_UINT:
1218 return PIPE_FORMAT_R32_UINT;
1219 case PIPE_FORMAT_L32_SINT:
1220 return PIPE_FORMAT_R32_SINT;
1221
1222 case PIPE_FORMAT_LATC1_UNORM:
1223 return PIPE_FORMAT_RGTC1_UNORM;
1224 case PIPE_FORMAT_LATC1_SNORM:
1225 return PIPE_FORMAT_RGTC1_SNORM;
1226
1227 case PIPE_FORMAT_L4A4_UNORM:
1228 return PIPE_FORMAT_R4A4_UNORM;
1229
1230 case PIPE_FORMAT_L8A8_UNORM:
1231 return PIPE_FORMAT_R8A8_UNORM;
1232 case PIPE_FORMAT_L8A8_SNORM:
1233 return PIPE_FORMAT_R8A8_SNORM;
1234 case PIPE_FORMAT_L16A16_UNORM:
1235 return PIPE_FORMAT_R16A16_UNORM;
1236 case PIPE_FORMAT_L16A16_SNORM:
1237 return PIPE_FORMAT_R16A16_SNORM;
1238 case PIPE_FORMAT_L16A16_FLOAT:
1239 return PIPE_FORMAT_R16A16_FLOAT;
1240 case PIPE_FORMAT_L32A32_FLOAT:
1241 return PIPE_FORMAT_R32A32_FLOAT;
1242 case PIPE_FORMAT_L8A8_UINT:
1243 return PIPE_FORMAT_R8A8_UINT;
1244 case PIPE_FORMAT_L8A8_SINT:
1245 return PIPE_FORMAT_R8A8_SINT;
1246 case PIPE_FORMAT_L16A16_UINT:
1247 return PIPE_FORMAT_R16A16_UINT;
1248 case PIPE_FORMAT_L16A16_SINT:
1249 return PIPE_FORMAT_R16A16_SINT;
1250 case PIPE_FORMAT_L32A32_UINT:
1251 return PIPE_FORMAT_R32A32_UINT;
1252 case PIPE_FORMAT_L32A32_SINT:
1253 return PIPE_FORMAT_R32A32_SINT;
1254
1255 /* We don't have compressed red-alpha variants for these. */
1256 case PIPE_FORMAT_LATC2_UNORM:
1257 case PIPE_FORMAT_LATC2_SNORM:
1258 return PIPE_FORMAT_NONE;
1259
1260 default:
1261 assert(!util_format_is_luminance(format) &&
1262 !util_format_is_luminance_alpha(format));
1263 return format;
1264 }
1265 }
1266
1267 /**
1268 * Return the number of components stored.
1269 * Formats with block size != 1x1 will always have 1 component (the block).
1270 */
1271 static inline unsigned
1272 util_format_get_nr_components(enum pipe_format format)
1273 {
1274 const struct util_format_description *desc = util_format_description(format);
1275 return desc->nr_channels;
1276 }
1277
1278 /**
1279 * Return the index of the first non-void channel
1280 * -1 if no non-void channels
1281 */
1282 static inline int
1283 util_format_get_first_non_void_channel(enum pipe_format format)
1284 {
1285 const struct util_format_description *desc = util_format_description(format);
1286 int i;
1287
1288 for (i = 0; i < 4; i++)
1289 if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID)
1290 break;
1291
1292 if (i == 4)
1293 return -1;
1294
1295 return i;
1296 }
1297
1298 /**
1299 * Whether this format is any 8-bit UNORM variant. Looser than
1300 * util_is_rgba8_variant (also includes alpha textures, for instance).
1301 */
1302
1303 static inline bool
1304 util_format_is_unorm8(const struct util_format_description *desc)
1305 {
1306 int c = util_format_get_first_non_void_channel(desc->format);
1307
1308 if (c == -1)
1309 return false;
1310
1311 return desc->is_unorm && desc->is_array && desc->channel[c].size == 8;
1312 }
1313
1314 /*
1315 * Format access functions.
1316 */
1317
1318 void
1319 util_format_read_4f(enum pipe_format format,
1320 float *dst, unsigned dst_stride,
1321 const void *src, unsigned src_stride,
1322 unsigned x, unsigned y, unsigned w, unsigned h);
1323
1324 void
1325 util_format_write_4f(enum pipe_format format,
1326 const float *src, unsigned src_stride,
1327 void *dst, unsigned dst_stride,
1328 unsigned x, unsigned y, unsigned w, unsigned h);
1329
1330 void
1331 util_format_read_4ub(enum pipe_format format,
1332 uint8_t *dst, unsigned dst_stride,
1333 const void *src, unsigned src_stride,
1334 unsigned x, unsigned y, unsigned w, unsigned h);
1335
1336 void
1337 util_format_write_4ub(enum pipe_format format,
1338 const uint8_t *src, unsigned src_stride,
1339 void *dst, unsigned dst_stride,
1340 unsigned x, unsigned y, unsigned w, unsigned h);
1341
1342 void
1343 util_format_read_4ui(enum pipe_format format,
1344 unsigned *dst, unsigned dst_stride,
1345 const void *src, unsigned src_stride,
1346 unsigned x, unsigned y, unsigned w, unsigned h);
1347
1348 void
1349 util_format_write_4ui(enum pipe_format format,
1350 const unsigned int *src, unsigned src_stride,
1351 void *dst, unsigned dst_stride,
1352 unsigned x, unsigned y, unsigned w, unsigned h);
1353
1354 void
1355 util_format_read_4i(enum pipe_format format,
1356 int *dst, unsigned dst_stride,
1357 const void *src, unsigned src_stride,
1358 unsigned x, unsigned y, unsigned w, unsigned h);
1359
1360 void
1361 util_format_write_4i(enum pipe_format format,
1362 const int *src, unsigned src_stride,
1363 void *dst, unsigned dst_stride,
1364 unsigned x, unsigned y, unsigned w, unsigned h);
1365
1366 /*
1367 * Generic format conversion;
1368 */
1369
1370 boolean
1371 util_format_fits_8unorm(const struct util_format_description *format_desc);
1372
1373 boolean
1374 util_format_translate(enum pipe_format dst_format,
1375 void *dst, unsigned dst_stride,
1376 unsigned dst_x, unsigned dst_y,
1377 enum pipe_format src_format,
1378 const void *src, unsigned src_stride,
1379 unsigned src_x, unsigned src_y,
1380 unsigned width, unsigned height);
1381
1382 boolean
1383 util_format_translate_3d(enum pipe_format dst_format,
1384 void *dst, unsigned dst_stride,
1385 unsigned dst_slice_stride,
1386 unsigned dst_x, unsigned dst_y,
1387 unsigned dst_z,
1388 enum pipe_format src_format,
1389 const void *src, unsigned src_stride,
1390 unsigned src_slice_stride,
1391 unsigned src_x, unsigned src_y,
1392 unsigned src_z, unsigned width,
1393 unsigned height, unsigned depth);
1394
1395 /*
1396 * Swizzle operations.
1397 */
1398
1399 /* Compose two sets of swizzles.
1400 * If V is a 4D vector and the function parameters represent functions that
1401 * swizzle vector components, this holds:
1402 * swz2(swz1(V)) = dst(V)
1403 */
1404 void util_format_compose_swizzles(const unsigned char swz1[4],
1405 const unsigned char swz2[4],
1406 unsigned char dst[4]);
1407
1408 /* Apply the swizzle provided in \param swz (which is one of PIPE_SWIZZLE_x)
1409 * to \param src and store the result in \param dst.
1410 * \param is_integer determines the value written for PIPE_SWIZZLE_1.
1411 */
1412 void util_format_apply_color_swizzle(union pipe_color_union *dst,
1413 const union pipe_color_union *src,
1414 const unsigned char swz[4],
1415 const boolean is_integer);
1416
1417 void pipe_swizzle_4f(float *dst, const float *src,
1418 const unsigned char swz[4]);
1419
1420 void util_format_unswizzle_4f(float *dst, const float *src,
1421 const unsigned char swz[4]);
1422
1423 enum pipe_format
1424 util_format_snorm8_to_sint8(enum pipe_format format);
1425
1426 #ifdef __cplusplus
1427 } // extern "C" {
1428 #endif
1429
1430 #endif /* ! U_FORMAT_H */