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