u_format.h revision be7407b75b12c70e1925c10117937ae2b9e6711f
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 "util/u_debug.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40
41/**
42 * Describe how to pack/unpack pixels into/from the prescribed format.
43 *
44 * XXX: This could be renamed to something like util_format_pack, or broke down
45 * in flags inside util_format_block that said exactly what we want.
46 */
47enum util_format_layout {
48   /**
49    * Formats with util_format_block::width == util_format_block::height == 1
50    * that can be described as an ordinary data structure.
51    */
52   UTIL_FORMAT_LAYOUT_PLAIN = 0,
53
54   /**
55    * Formats with sub-sampled channels.
56    *
57    * This is for formats like YV12 where there is less than one sample per
58    * pixel.
59    */
60   UTIL_FORMAT_LAYOUT_SUBSAMPLED = 3,
61
62   /**
63    * S3 Texture Compression formats.
64    */
65   UTIL_FORMAT_LAYOUT_S3TC = 4,
66
67   /**
68    * Red-Green Texture Compression formats.
69    */
70   UTIL_FORMAT_LAYOUT_RGTC = 5,
71
72   /**
73    * Everything else that doesn't fit in any of the above layouts.
74    */
75   UTIL_FORMAT_LAYOUT_OTHER = 6
76};
77
78
79struct util_format_block
80{
81   /** Block width in pixels */
82   unsigned width;
83
84   /** Block height in pixels */
85   unsigned height;
86
87   /** Block size in bits */
88   unsigned bits;
89};
90
91
92enum util_format_type {
93   UTIL_FORMAT_TYPE_VOID = 0,
94   UTIL_FORMAT_TYPE_UNSIGNED = 1,
95   UTIL_FORMAT_TYPE_SIGNED = 2,
96   UTIL_FORMAT_TYPE_FIXED = 3,
97   UTIL_FORMAT_TYPE_FLOAT = 4
98};
99
100
101enum util_format_swizzle {
102   UTIL_FORMAT_SWIZZLE_X = 0,
103   UTIL_FORMAT_SWIZZLE_Y = 1,
104   UTIL_FORMAT_SWIZZLE_Z = 2,
105   UTIL_FORMAT_SWIZZLE_W = 3,
106   UTIL_FORMAT_SWIZZLE_0 = 4,
107   UTIL_FORMAT_SWIZZLE_1 = 5,
108   UTIL_FORMAT_SWIZZLE_NONE = 6
109};
110
111
112enum util_format_colorspace {
113   UTIL_FORMAT_COLORSPACE_RGB = 0,
114   UTIL_FORMAT_COLORSPACE_SRGB = 1,
115   UTIL_FORMAT_COLORSPACE_YUV = 2,
116   UTIL_FORMAT_COLORSPACE_ZS = 3
117};
118
119
120struct util_format_channel_description
121{
122   unsigned type:6;
123   unsigned normalized:1;
124   unsigned size:9;
125};
126
127
128struct util_format_description
129{
130   enum pipe_format format;
131
132   const char *name;
133
134   /**
135    * Short name, striped of the prefix, lower case.
136    */
137   const char *short_name;
138
139   /**
140    * Pixel block dimensions.
141    */
142   struct util_format_block block;
143
144   enum util_format_layout layout;
145
146   /**
147    * The number of channels.
148    */
149   unsigned nr_channels:3;
150
151   /**
152    * Whether all channels have the same number of (whole) bytes.
153    */
154   unsigned is_array:1;
155
156   /**
157    * Whether the pixel format can be described as a bitfield structure.
158    *
159    * In particular:
160    * - pixel depth must be 8, 16, or 32 bits;
161    * - all channels must be unsigned, signed, or void
162    */
163   unsigned is_bitmask:1;
164
165   /**
166    * Whether channels have mixed types (ignoring UTIL_FORMAT_TYPE_VOID).
167    */
168   unsigned is_mixed:1;
169
170   /**
171    * Input channel description.
172    *
173    * Only valid for UTIL_FORMAT_LAYOUT_PLAIN formats.
174    */
175   struct util_format_channel_description channel[4];
176
177   /**
178    * Output channel swizzle.
179    *
180    * The order is either:
181    * - RGBA
182    * - YUV(A)
183    * - ZS
184    * depending on the colorspace.
185    */
186   unsigned char swizzle[4];
187
188   /**
189    * Colorspace transformation.
190    */
191   enum util_format_colorspace colorspace;
192
193   /**
194    * Unpack pixel blocks to R8G8B8A8_UNORM.
195    * Note: strides are in bytes.
196    *
197    * Only defined for non-depth-stencil formats.
198    */
199   void
200   (*unpack_rgba_8unorm)(uint8_t *dst, unsigned dst_stride,
201                         const uint8_t *src, unsigned src_stride,
202                         unsigned width, unsigned height);
203
204   /**
205    * Pack pixel blocks from R8G8B8A8_UNORM.
206    * Note: strides are in bytes.
207    *
208    * Only defined for non-depth-stencil formats.
209    */
210   void
211   (*pack_rgba_8unorm)(uint8_t *dst, unsigned dst_stride,
212                       const uint8_t *src, unsigned src_stride,
213                       unsigned width, unsigned height);
214
215   /**
216    * Fetch a single pixel (i, j) from a block.
217    *
218    * XXX: Only defined for a very few select formats.
219    */
220   void
221   (*fetch_rgba_8unorm)(uint8_t *dst,
222                        const uint8_t *src,
223                        unsigned i, unsigned j);
224
225   /**
226    * Unpack pixel blocks to R32G32B32A32_FLOAT.
227    * Note: strides are in bytes.
228    *
229    * Only defined for non-depth-stencil formats.
230    */
231   void
232   (*unpack_rgba_float)(float *dst, unsigned dst_stride,
233                        const uint8_t *src, unsigned src_stride,
234                        unsigned width, unsigned height);
235
236   /**
237    * Pack pixel blocks from R32G32B32A32_FLOAT.
238    * Note: strides are in bytes.
239    *
240    * Only defined for non-depth-stencil formats.
241    */
242   void
243   (*pack_rgba_float)(uint8_t *dst, unsigned dst_stride,
244                      const float *src, unsigned src_stride,
245                      unsigned width, unsigned height);
246
247   /**
248    * Fetch a single pixel (i, j) from a block.
249    *
250    * Only defined for non-depth-stencil formats.
251    */
252   void
253   (*fetch_rgba_float)(float *dst,
254                       const uint8_t *src,
255                       unsigned i, unsigned j);
256
257   /**
258    * Unpack pixels to Z32_UNORM.
259    * Note: strides are in bytes.
260    *
261    * Only defined for depth formats.
262    */
263   void
264   (*unpack_z_32unorm)(uint32_t *dst, unsigned dst_stride,
265                       const uint8_t *src, unsigned src_stride,
266                       unsigned width, unsigned height);
267
268   /**
269    * Pack pixels from Z32_FLOAT.
270    * Note: strides are in bytes.
271    *
272    * Only defined for depth formats.
273    */
274   void
275   (*pack_z_32unorm)(uint8_t *dst, unsigned dst_stride,
276                     const uint32_t *src, unsigned src_stride,
277                     unsigned width, unsigned height);
278
279   /**
280    * Unpack pixels to Z32_FLOAT.
281    * Note: strides are in bytes.
282    *
283    * Only defined for depth formats.
284    */
285   void
286   (*unpack_z_float)(float *dst, unsigned dst_stride,
287                     const uint8_t *src, unsigned src_stride,
288                     unsigned width, unsigned height);
289
290   /**
291    * Pack pixels from Z32_FLOAT.
292    * Note: strides are in bytes.
293    *
294    * Only defined for depth formats.
295    */
296   void
297   (*pack_z_float)(uint8_t *dst, unsigned dst_stride,
298                   const float *src, unsigned src_stride,
299                   unsigned width, unsigned height);
300
301   /**
302    * Unpack pixels to S8_USCALED.
303    * Note: strides are in bytes.
304    *
305    * Only defined for stencil formats.
306    */
307   void
308   (*unpack_s_8uscaled)(uint8_t *dst, unsigned dst_stride,
309                        const uint8_t *src, unsigned src_stride,
310                        unsigned width, unsigned height);
311
312   /**
313    * Pack pixels from S8_USCALED.
314    * Note: strides are in bytes.
315    *
316    * Only defined for stencil formats.
317    */
318   void
319   (*pack_s_8uscaled)(uint8_t *dst, unsigned dst_stride,
320                      const uint8_t *src, unsigned src_stride,
321                      unsigned width, unsigned height);
322
323};
324
325
326extern const struct util_format_description
327util_format_description_table[];
328
329
330const struct util_format_description *
331util_format_description(enum pipe_format format);
332
333
334/*
335 * Format query functions.
336 */
337
338static INLINE const char *
339util_format_name(enum pipe_format format)
340{
341   const struct util_format_description *desc = util_format_description(format);
342
343   assert(desc);
344   if (!desc) {
345      return "PIPE_FORMAT_???";
346   }
347
348   return desc->name;
349}
350
351static INLINE const char *
352util_format_short_name(enum pipe_format format)
353{
354   const struct util_format_description *desc = util_format_description(format);
355
356   assert(desc);
357   if (!desc) {
358      return "???";
359   }
360
361   return desc->short_name;
362}
363
364/**
365 * Whether this format is plain, see UTIL_FORMAT_LAYOUT_PLAIN for more info.
366 */
367static INLINE boolean
368util_format_is_plain(enum pipe_format format)
369{
370   const struct util_format_description *desc = util_format_description(format);
371
372   if (!format) {
373      return FALSE;
374   }
375
376   return desc->layout == UTIL_FORMAT_LAYOUT_PLAIN ? TRUE : FALSE;
377}
378
379static INLINE boolean
380util_format_is_compressed(enum pipe_format format)
381{
382   const struct util_format_description *desc = util_format_description(format);
383
384   assert(desc);
385   if (!desc) {
386      return FALSE;
387   }
388
389   switch (desc->layout) {
390   case UTIL_FORMAT_LAYOUT_S3TC:
391   case UTIL_FORMAT_LAYOUT_RGTC:
392      /* XXX add other formats in the future */
393      return TRUE;
394   default:
395      return FALSE;
396   }
397}
398
399static INLINE boolean
400util_format_is_s3tc(enum pipe_format format)
401{
402   const struct util_format_description *desc = util_format_description(format);
403
404   assert(desc);
405   if (!desc) {
406      return FALSE;
407   }
408
409   return desc->layout == UTIL_FORMAT_LAYOUT_S3TC ? TRUE : FALSE;
410}
411
412static INLINE boolean
413util_format_is_depth_or_stencil(enum pipe_format format)
414{
415   const struct util_format_description *desc = util_format_description(format);
416
417   assert(desc);
418   if (!desc) {
419      return FALSE;
420   }
421
422   return desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS ? TRUE : FALSE;
423}
424
425static INLINE boolean
426util_format_is_depth_and_stencil(enum pipe_format format)
427{
428   const struct util_format_description *desc = util_format_description(format);
429
430   assert(desc);
431   if (!desc) {
432      return FALSE;
433   }
434
435   if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) {
436      return FALSE;
437   }
438
439   return (desc->swizzle[0] != UTIL_FORMAT_SWIZZLE_NONE &&
440           desc->swizzle[1] != UTIL_FORMAT_SWIZZLE_NONE) ? TRUE : FALSE;
441}
442
443
444/**
445 * Give the RGBA colormask of the channels that can be represented in this
446 * format.
447 *
448 * That is, the channels whose values are preserved.
449 */
450static INLINE unsigned
451util_format_colormask(const struct util_format_description *desc)
452{
453   unsigned colormask;
454   unsigned chan;
455
456   switch (desc->colorspace) {
457   case UTIL_FORMAT_COLORSPACE_RGB:
458   case UTIL_FORMAT_COLORSPACE_SRGB:
459   case UTIL_FORMAT_COLORSPACE_YUV:
460      colormask = 0;
461      for (chan = 0; chan < 4; ++chan) {
462         if (desc->swizzle[chan] < 4) {
463            colormask |= (1 << chan);
464         }
465      }
466      return colormask;
467   case UTIL_FORMAT_COLORSPACE_ZS:
468      return 0;
469   default:
470      assert(0);
471      return 0;
472   }
473}
474
475
476boolean
477util_format_is_float(enum pipe_format format);
478
479
480/**
481 * Whether the src format can be blitted to destation format with a simple
482 * memcpy.
483 */
484boolean
485util_is_format_compatible(const struct util_format_description *src_desc,
486                          const struct util_format_description *dst_desc);
487
488/**
489 * Whether the format is supported by Gallium for the given bindings.
490 * This covers S3TC textures and floating-point render targets.
491 */
492boolean
493util_format_is_supported(enum pipe_format format, unsigned bind);
494
495/**
496 * Whether this format is a rgab8 variant.
497 *
498 * That is, any format that matches the
499 *
500 *   PIPE_FORMAT_?8?8?8?8_UNORM
501 */
502static INLINE boolean
503util_format_is_rgba8_variant(const struct util_format_description *desc)
504{
505   unsigned chan;
506
507   if(desc->block.width != 1 ||
508      desc->block.height != 1 ||
509      desc->block.bits != 32)
510      return FALSE;
511
512   for(chan = 0; chan < 4; ++chan) {
513      if(desc->channel[chan].type != UTIL_FORMAT_TYPE_UNSIGNED &&
514         desc->channel[chan].type != UTIL_FORMAT_TYPE_VOID)
515         return FALSE;
516      if(desc->channel[chan].size != 8)
517         return FALSE;
518   }
519
520   return TRUE;
521}
522
523
524/**
525 * Return total bits needed for the pixel format per block.
526 */
527static INLINE uint
528util_format_get_blocksizebits(enum pipe_format format)
529{
530   const struct util_format_description *desc = util_format_description(format);
531
532   assert(desc);
533   if (!desc) {
534      return 0;
535   }
536
537   return desc->block.bits;
538}
539
540/**
541 * Return bytes per block (not pixel) for the given format.
542 */
543static INLINE uint
544util_format_get_blocksize(enum pipe_format format)
545{
546   uint bits = util_format_get_blocksizebits(format);
547
548   assert(bits % 8 == 0);
549
550   return bits / 8;
551}
552
553static INLINE uint
554util_format_get_blockwidth(enum pipe_format format)
555{
556   const struct util_format_description *desc = util_format_description(format);
557
558   assert(desc);
559   if (!desc) {
560      return 1;
561   }
562
563   return desc->block.width;
564}
565
566static INLINE uint
567util_format_get_blockheight(enum pipe_format format)
568{
569   const struct util_format_description *desc = util_format_description(format);
570
571   assert(desc);
572   if (!desc) {
573      return 1;
574   }
575
576   return desc->block.height;
577}
578
579static INLINE unsigned
580util_format_get_nblocksx(enum pipe_format format,
581                         unsigned x)
582{
583   unsigned blockwidth = util_format_get_blockwidth(format);
584   return (x + blockwidth - 1) / blockwidth;
585}
586
587static INLINE unsigned
588util_format_get_nblocksy(enum pipe_format format,
589                         unsigned y)
590{
591   unsigned blockheight = util_format_get_blockheight(format);
592   return (y + blockheight - 1) / blockheight;
593}
594
595static INLINE unsigned
596util_format_get_nblocks(enum pipe_format format,
597                        unsigned width,
598                        unsigned height)
599{
600   return util_format_get_nblocksx(format, width) * util_format_get_nblocksy(format, height);
601}
602
603static INLINE size_t
604util_format_get_stride(enum pipe_format format,
605                       unsigned width)
606{
607   return util_format_get_nblocksx(format, width) * util_format_get_blocksize(format);
608}
609
610static INLINE size_t
611util_format_get_2d_size(enum pipe_format format,
612                        size_t stride,
613                        unsigned height)
614{
615   return util_format_get_nblocksy(format, height) * stride;
616}
617
618static INLINE uint
619util_format_get_component_bits(enum pipe_format format,
620                               enum util_format_colorspace colorspace,
621                               uint component)
622{
623   const struct util_format_description *desc = util_format_description(format);
624   enum util_format_colorspace desc_colorspace;
625
626   assert(format);
627   if (!format) {
628      return 0;
629   }
630
631   assert(component < 4);
632
633   /* Treat RGB and SRGB as equivalent. */
634   if (colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
635      colorspace = UTIL_FORMAT_COLORSPACE_RGB;
636   }
637   if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
638      desc_colorspace = UTIL_FORMAT_COLORSPACE_RGB;
639   } else {
640      desc_colorspace = desc->colorspace;
641   }
642
643   if (desc_colorspace != colorspace) {
644      return 0;
645   }
646
647   switch (desc->swizzle[component]) {
648   case UTIL_FORMAT_SWIZZLE_X:
649      return desc->channel[0].size;
650   case UTIL_FORMAT_SWIZZLE_Y:
651      return desc->channel[1].size;
652   case UTIL_FORMAT_SWIZZLE_Z:
653      return desc->channel[2].size;
654   case UTIL_FORMAT_SWIZZLE_W:
655      return desc->channel[3].size;
656   default:
657      return 0;
658   }
659}
660
661static INLINE boolean
662util_format_has_alpha(enum pipe_format format)
663{
664   const struct util_format_description *desc = util_format_description(format);
665
666   assert(format);
667   if (!format) {
668      return FALSE;
669   }
670
671   switch (desc->colorspace) {
672   case UTIL_FORMAT_COLORSPACE_RGB:
673   case UTIL_FORMAT_COLORSPACE_SRGB:
674      return desc->swizzle[3] != UTIL_FORMAT_SWIZZLE_1;
675   case UTIL_FORMAT_COLORSPACE_YUV:
676      return FALSE;
677   case UTIL_FORMAT_COLORSPACE_ZS:
678      return FALSE;
679   default:
680      assert(0);
681      return FALSE;
682   }
683}
684
685/**
686 * Given a linear RGB colorspace format, return the corresponding SRGB
687 * format, or PIPE_FORMAT_NONE if none.
688 */
689static INLINE enum pipe_format
690util_format_srgb(enum pipe_format format)
691{
692   switch (format) {
693   case PIPE_FORMAT_L8_UNORM:
694      return PIPE_FORMAT_L8_SRGB;
695   case PIPE_FORMAT_L8A8_UNORM:
696      return PIPE_FORMAT_L8A8_SRGB;
697   case PIPE_FORMAT_R8G8B8_UNORM:
698      return PIPE_FORMAT_R8G8B8_SRGB;
699   case PIPE_FORMAT_A8B8G8R8_UNORM:
700      return PIPE_FORMAT_A8B8G8R8_SRGB;
701   case PIPE_FORMAT_X8B8G8R8_UNORM:
702      return PIPE_FORMAT_X8B8G8R8_SRGB;
703   case PIPE_FORMAT_B8G8R8A8_UNORM:
704      return PIPE_FORMAT_B8G8R8A8_SRGB;
705   case PIPE_FORMAT_B8G8R8X8_UNORM:
706      return PIPE_FORMAT_B8G8R8X8_SRGB;
707   case PIPE_FORMAT_A8R8G8B8_UNORM:
708      return PIPE_FORMAT_A8R8G8B8_SRGB;
709   case PIPE_FORMAT_X8R8G8B8_UNORM:
710      return PIPE_FORMAT_X8R8G8B8_SRGB;
711   case PIPE_FORMAT_DXT1_RGB:
712      return PIPE_FORMAT_DXT1_SRGB;
713   case PIPE_FORMAT_DXT1_RGBA:
714      return PIPE_FORMAT_DXT1_SRGBA;
715   case PIPE_FORMAT_DXT3_RGBA:
716      return PIPE_FORMAT_DXT3_SRGBA;
717   case PIPE_FORMAT_DXT5_RGBA:
718      return PIPE_FORMAT_DXT5_SRGBA;
719   default:
720      return PIPE_FORMAT_NONE;
721   }
722}
723
724/**
725 * Given an sRGB format, return the corresponding linear colorspace format.
726 * For non sRGB formats, return the format unchanged.
727 */
728static INLINE enum pipe_format
729util_format_linear(enum pipe_format format)
730{
731   switch (format) {
732   case PIPE_FORMAT_L8_SRGB:
733      return PIPE_FORMAT_L8_UNORM;
734   case PIPE_FORMAT_L8A8_SRGB:
735      return PIPE_FORMAT_L8A8_UNORM;
736   case PIPE_FORMAT_R8G8B8_SRGB:
737      return PIPE_FORMAT_R8G8B8_UNORM;
738   case PIPE_FORMAT_A8B8G8R8_SRGB:
739      return PIPE_FORMAT_A8B8G8R8_UNORM;
740   case PIPE_FORMAT_X8B8G8R8_SRGB:
741      return PIPE_FORMAT_X8B8G8R8_UNORM;
742   case PIPE_FORMAT_B8G8R8A8_SRGB:
743      return PIPE_FORMAT_B8G8R8A8_UNORM;
744   case PIPE_FORMAT_B8G8R8X8_SRGB:
745      return PIPE_FORMAT_B8G8R8X8_UNORM;
746   case PIPE_FORMAT_A8R8G8B8_SRGB:
747      return PIPE_FORMAT_A8R8G8B8_UNORM;
748   case PIPE_FORMAT_X8R8G8B8_SRGB:
749      return PIPE_FORMAT_X8R8G8B8_UNORM;
750   case PIPE_FORMAT_DXT1_SRGB:
751      return PIPE_FORMAT_DXT1_RGB;
752   case PIPE_FORMAT_DXT1_SRGBA:
753      return PIPE_FORMAT_DXT1_RGBA;
754   case PIPE_FORMAT_DXT3_SRGBA:
755      return PIPE_FORMAT_DXT3_RGBA;
756   case PIPE_FORMAT_DXT5_SRGBA:
757      return PIPE_FORMAT_DXT5_RGBA;
758   default:
759      return format;
760   }
761}
762
763/**
764 * Return the number of components stored.
765 * Formats with block size != 1x1 will always have 1 component (the block).
766 */
767static INLINE unsigned
768util_format_get_nr_components(enum pipe_format format)
769{
770   const struct util_format_description *desc = util_format_description(format);
771   return desc->nr_channels;
772}
773
774/*
775 * Format access functions.
776 */
777
778void
779util_format_read_4f(enum pipe_format format,
780                    float *dst, unsigned dst_stride,
781                    const void *src, unsigned src_stride,
782                    unsigned x, unsigned y, unsigned w, unsigned h);
783
784void
785util_format_write_4f(enum pipe_format format,
786                     const float *src, unsigned src_stride,
787                     void *dst, unsigned dst_stride,
788                     unsigned x, unsigned y, unsigned w, unsigned h);
789
790void
791util_format_read_4ub(enum pipe_format format,
792                     uint8_t *dst, unsigned dst_stride,
793                     const void *src, unsigned src_stride,
794                     unsigned x, unsigned y, unsigned w, unsigned h);
795
796void
797util_format_write_4ub(enum pipe_format format,
798                      const uint8_t *src, unsigned src_stride,
799                      void *dst, unsigned dst_stride,
800                      unsigned x, unsigned y, unsigned w, unsigned h);
801
802/*
803 * Generic format conversion;
804 */
805
806boolean
807util_format_fits_8unorm(const struct util_format_description *format_desc);
808
809void
810util_format_translate(enum pipe_format dst_format,
811                      void *dst, unsigned dst_stride,
812                      unsigned dst_x, unsigned dst_y,
813                      enum pipe_format src_format,
814                      const void *src, unsigned src_stride,
815                      unsigned src_x, unsigned src_y,
816                      unsigned width, unsigned height);
817
818/*
819 * Swizzle operations.
820 */
821
822/* Compose two sets of swizzles.
823 * If V is a 4D vector and the function parameters represent functions that
824 * swizzle vector components, this holds:
825 *     swz2(swz1(V)) = dst(V)
826 */
827void util_format_compose_swizzles(const unsigned char swz1[4],
828                                  const unsigned char swz2[4],
829                                  unsigned char dst[4]);
830
831void util_format_swizzle_4f(float *dst, const float *src,
832                            const unsigned char swz[4]);
833
834void util_format_unswizzle_4f(float *dst, const float *src,
835                              const unsigned char swz[4]);
836
837#ifdef __cplusplus
838} // extern "C" {
839#endif
840
841#endif /* ! U_FORMAT_H */
842