u_format.h revision a441feb757b1be4845ba378f0207dcdc5cc1a407
14ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor/**************************************************************************
24ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor *
34ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * Copyright 2009-2010 Vmware, Inc.
44ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * All Rights Reserved.
54ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor *
64ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * Permission is hereby granted, free of charge, to any person obtaining a
74ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * copy of this software and associated documentation files (the
84ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * "Software"), to deal in the Software without restriction, including
94ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * without limitation the rights to use, copy, modify, merge, publish,
104ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * distribute, sub license, and/or sell copies of the Software, and to
114ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * permit persons to whom the Software is furnished to do so, subject to
124ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * the following conditions:
134ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor *
144ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * The above copyright notice and this permission notice (including the
154ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * next paragraph) shall be included in all copies or substantial portions
164ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * of the Software.
178f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis *
1830a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1930a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20b9e1b75772db2c7db566c6034ba90a07f22e35ebDouglas Gregor * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
2230a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
234ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
254ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor *
264ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor **************************************************************************/
274ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
284ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
29c515978bd3a703aa733f846a0094ffa84d149074Argyrios Kyrtzidis#ifndef U_FORMAT_H
304ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor#define U_FORMAT_H
314ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
324ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
334ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor#include "pipe/p_format.h"
344ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor#include "util/u_debug.h"
354ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
364ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor#ifdef __cplusplus
374ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregorextern "C" {
384ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor#endif
394ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
404ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
414ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor/**
42bf7efa2742dc94363d3561d284c9d634fc5a780fDouglas Gregor * Describe how to pack/unpack pixels into/from the prescribed format.
43ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor *
44bf7efa2742dc94363d3561d284c9d634fc5a780fDouglas Gregor * XXX: This could be renamed to something like util_format_pack, or broke down
454ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * in flags inside util_format_block that said exactly what we want.
469e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler Carruth */
474ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregorenum util_format_layout {
484ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   /**
494ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    * Formats with util_format_block::width == util_format_block::height == 1
504ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    * that can be described as an ordinary data structure.
51e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis    */
52e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   UTIL_FORMAT_LAYOUT_PLAIN = 0,
53e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
549e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler Carruth   /**
559e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler Carruth    * Formats with sub-sampled channels.
564ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    *
575555bf78e0a76337f7149669723bf4f3f9ddbc1cArgyrios Kyrtzidis    * This is for formats like YV12 where there is less than one sample per
585555bf78e0a76337f7149669723bf4f3f9ddbc1cArgyrios Kyrtzidis    * pixel.
594ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    */
604ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_LAYOUT_SUBSAMPLED = 3,
614ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
624ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   /**
63809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett    * S3 Texture Compression formats.
64809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett    */
65ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   UTIL_FORMAT_LAYOUT_S3TC = 4,
66ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor
675555bf78e0a76337f7149669723bf4f3f9ddbc1cArgyrios Kyrtzidis   /**
685555bf78e0a76337f7149669723bf4f3f9ddbc1cArgyrios Kyrtzidis    * Red-Green Texture Compression formats.
695555bf78e0a76337f7149669723bf4f3f9ddbc1cArgyrios Kyrtzidis    */
70ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   UTIL_FORMAT_LAYOUT_RGTC = 5,
714ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
724ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   /**
734ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    * Everything else that doesn't fit in any of the above layouts.
744ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    */
754ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_LAYOUT_OTHER = 6
764ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor};
774ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
784ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
794ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregorstruct util_format_block
804ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor{
814ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   /** Block width in pixels */
824ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   unsigned width;
83e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
84e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   /** Block height in pixels */
85e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   unsigned height;
864ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
874ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   /** Block size in bits */
884ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   unsigned bits;
894ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor};
904ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
914ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
92aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbarenum util_format_type {
93e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   UTIL_FORMAT_TYPE_VOID = 0,
94e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   UTIL_FORMAT_TYPE_UNSIGNED = 1,
95e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   UTIL_FORMAT_TYPE_SIGNED = 2,
96e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   UTIL_FORMAT_TYPE_FIXED = 3,
97e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   UTIL_FORMAT_TYPE_FLOAT = 4
984ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor};
994ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
1004ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
1014ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregorenum util_format_swizzle {
1024ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_SWIZZLE_X = 0,
1034ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_SWIZZLE_Y = 1,
1044ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_SWIZZLE_Z = 2,
1054ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_SWIZZLE_W = 3,
1064ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_SWIZZLE_0 = 4,
1074ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_SWIZZLE_1 = 5,
1084ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_SWIZZLE_NONE = 6,
1094ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_SWIZZLE_MAX = 7  /**< Number of enums counter (must be last) */
1104ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor};
1114ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
1124ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
1134ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregorenum util_format_colorspace {
1144ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_COLORSPACE_RGB = 0,
1154ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_COLORSPACE_SRGB = 1,
1164ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_COLORSPACE_YUV = 2,
1174ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   UTIL_FORMAT_COLORSPACE_ZS = 3
1184ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor};
1194ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
1204ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
1214ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregorstruct util_format_channel_description
1224ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor{
1234ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   unsigned type:5;        /**< UTIL_FORMAT_TYPE_x */
1244ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   unsigned normalized:1;
1254ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   unsigned pure_integer:1;
1264ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   unsigned size:9;        /**< bits per channel */
1274ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor};
1284ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
1294ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
1304ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregorstruct util_format_description
1314ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor{
1324ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   enum pipe_format format;
1334ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
1344ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   const char *name;
1354ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
1364ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   /**
1374ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    * Short name, striped of the prefix, lower case.
1384ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    */
1394ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   const char *short_name;
1404ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
1414ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   /**
142de4e0a8e57e643bbe78ad37ad6023c45a8a9f7e2Argyrios Kyrtzidis    * Pixel block dimensions.
143de4e0a8e57e643bbe78ad37ad6023c45a8a9f7e2Argyrios Kyrtzidis    */
1444ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   struct util_format_block block;
1454ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
146572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor   enum util_format_layout layout;
1474ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
1484ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   /**
149de4e0a8e57e643bbe78ad37ad6023c45a8a9f7e2Argyrios Kyrtzidis    * The number of channels.
1504ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    */
1514ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   unsigned nr_channels:3;
152572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor
153572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor   /**
1544ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    * Whether all channels have the same number of (whole) bytes.
1554ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    */
1568f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis   unsigned is_array:1;
1578f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis
1588f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis   /**
1598f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * Whether the pixel format can be described as a bitfield structure.
1608f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    *
1618f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * In particular:
1628f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * - pixel depth must be 8, 16, or 32 bits;
1638f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * - all channels must be unsigned, signed, or void
1648f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    */
1658f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis   unsigned is_bitmask:1;
1668f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis
1678f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis   /**
1688f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * Whether channels have mixed types (ignoring UTIL_FORMAT_TYPE_VOID).
1698f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    */
1708f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis   unsigned is_mixed:1;
1718f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis
1728f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis   /**
1738f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * Input channel description.
1748f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    *
1758f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * Only valid for UTIL_FORMAT_LAYOUT_PLAIN formats.
1768f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    */
1778f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis   struct util_format_channel_description channel[4];
1788f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis
1798f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis   /**
1808f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * Output channel swizzle.
1818f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    *
1828f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * The order is either:
1838f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * - RGBA
1848f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * - YUV(A)
1858f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * - ZS
1868f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * depending on the colorspace.
1878f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    */
1888f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis   unsigned char swizzle[4];
1898f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis
1908f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis   /**
1918f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    * Colorspace transformation.
1928f7c540ac42370c40ebcdc4b69018c938faf94ecArgyrios Kyrtzidis    */
193ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   enum util_format_colorspace colorspace;
194ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor
195809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett   /**
196ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * Unpack pixel blocks to R8G8B8A8_UNORM.
197ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * Note: strides are in bytes.
198ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    *
199ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * Only defined for non-depth-stencil formats.
200ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    */
201809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett   void
202ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   (*unpack_rgba_8unorm)(uint8_t *dst, unsigned dst_stride,
203809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett                         const uint8_t *src, unsigned src_stride,
204ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor                         unsigned width, unsigned height);
205809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett
206ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   /**
207809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett    * Pack pixel blocks from R8G8B8A8_UNORM.
208ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * Note: strides are in bytes.
209ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    *
210ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * Only defined for non-depth-stencil formats.
211ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    */
212ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   void
213ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   (*pack_rgba_8unorm)(uint8_t *dst, unsigned dst_stride,
214686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                       const uint8_t *src, unsigned src_stride,
215ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor                       unsigned width, unsigned height);
216ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor
217ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   /**
218ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * Fetch a single pixel (i, j) from a block.
219ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    *
220ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * XXX: Only defined for a very few select formats.
221ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    */
222ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   void
223ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   (*fetch_rgba_8unorm)(uint8_t *dst,
224ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor                        const uint8_t *src,
2258dd927cf03e85b942f323eebb42e06c839887ebbArgyrios Kyrtzidis                        unsigned i, unsigned j);
2268dd927cf03e85b942f323eebb42e06c839887ebbArgyrios Kyrtzidis
2278dd927cf03e85b942f323eebb42e06c839887ebbArgyrios Kyrtzidis   /**
2288dd927cf03e85b942f323eebb42e06c839887ebbArgyrios Kyrtzidis    * Unpack pixel blocks to R32G32B32A32_FLOAT.
229ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * Note: strides are in bytes.
230ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    *
231ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * Only defined for non-depth-stencil formats.
232ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    */
2334ab829c2a229dc20ecb9f35e7337bbfa95bf4026Douglas Gregor   void
234686775deca8b8685eb90801495880e3abdd844c2Chris Lattner   (*unpack_rgba_float)(float *dst, unsigned dst_stride,
2358dd927cf03e85b942f323eebb42e06c839887ebbArgyrios Kyrtzidis                        const uint8_t *src, unsigned src_stride,
2368dd927cf03e85b942f323eebb42e06c839887ebbArgyrios Kyrtzidis                        unsigned width, unsigned height);
237ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor
238ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   /**
239ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * Pack pixel blocks from R32G32B32A32_FLOAT.
240ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * Note: strides are in bytes.
241ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    *
242686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    * Only defined for non-depth-stencil formats.
243ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    */
244ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   void
245ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   (*pack_rgba_float)(uint8_t *dst, unsigned dst_stride,
246ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor                      const float *src, unsigned src_stride,
2478dd927cf03e85b942f323eebb42e06c839887ebbArgyrios Kyrtzidis                      unsigned width, unsigned height);
2488dd927cf03e85b942f323eebb42e06c839887ebbArgyrios Kyrtzidis
2498dd927cf03e85b942f323eebb42e06c839887ebbArgyrios Kyrtzidis   /**
2508dd927cf03e85b942f323eebb42e06c839887ebbArgyrios Kyrtzidis    * Fetch a single pixel (i, j) from a block.
251ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    *
252ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * Only defined for non-depth-stencil formats.
253ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    */
254ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   void
255ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   (*fetch_rgba_float)(float *dst,
256ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor                       const uint8_t *src,
257ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor                       unsigned i, unsigned j);
258ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor
259ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor   /**
260ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor    * Unpack pixels to Z32_UNORM.
2616a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor    * Note: strides are in bytes.
2626a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor    *
2636a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor    * Only defined for depth formats.
2646a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor    */
2656a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor   void
2666a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor   (*unpack_z_32unorm)(uint32_t *dst, unsigned dst_stride,
2674ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor                       const uint8_t *src, unsigned src_stride,
268e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis                       unsigned width, unsigned height);
269e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
270e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   /**
271e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis    * Pack pixels from Z32_FLOAT.
272e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis    * Note: strides are in bytes.
273e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis    *
2742dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis    * Only defined for depth formats.
2751824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko    */
2762dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis   void
2772dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis   (*pack_z_32unorm)(uint8_t *dst, unsigned dst_stride,
278f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis                     const uint32_t *src, unsigned src_stride,
279f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis                     unsigned width, unsigned height);
2801824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko
281dc84cd5efdd3430efb22546b4ac656aa0540b210David Blaikie   /**
282dc84cd5efdd3430efb22546b4ac656aa0540b210David Blaikie    * Unpack pixels to Z32_FLOAT.
28366874fb18afbffb8b2ca05576851a64534be3352David Blaikie    * Note: strides are in bytes.
284f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis    *
2856a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor    * Only defined for depth formats.
2866a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor    */
2874ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   void
2884ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   (*unpack_z_float)(float *dst, unsigned dst_stride,
2899e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler Carruth                     const uint8_t *src, unsigned src_stride,
290b9e1b75772db2c7db566c6034ba90a07f22e35ebDouglas Gregor                     unsigned width, unsigned height);
2912dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
292dca8ee8b7bc86076916a3a80f553f7a4e98c14afDouglas Gregor   /**
2934ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    * Pack pixels from Z32_FLOAT.
2944ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    * Note: strides are in bytes.
2954ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    *
2964ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    * Only defined for depth formats.
2974ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor    */
2984ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   void
2994ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   (*pack_z_float)(uint8_t *dst, unsigned dst_stride,
3004c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor                   const float *src, unsigned src_stride,
3014c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor                   unsigned width, unsigned height);
3024c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
3034c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   /**
3044c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    * Unpack pixels to S8_USCALED.
3054c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    * Note: strides are in bytes.
306e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis    *
307651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    * Only defined for stencil formats.
308651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    */
309651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines   void
310e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   (*unpack_s_8uscaled)(uint8_t *dst, unsigned dst_stride,
311e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis                        const uint8_t *src, unsigned src_stride,
312e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis                        unsigned width, unsigned height);
313e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
314f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis   /**
315f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis    * Pack pixels from S8_USCALED.
316f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis    * Note: strides are in bytes.
317f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis    *
318f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis    * Only defined for stencil formats.
319f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis    */
320f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis   void
321f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis   (*pack_s_8uscaled)(uint8_t *dst, unsigned dst_stride,
322f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis                      const uint8_t *src, unsigned src_stride,
323f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis                      unsigned width, unsigned height);
324f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis
325f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis  /**
326f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis    * Unpack pixel blocks to R32G32B32A32_UINT.
327f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis    * Note: strides are in bytes.
328f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis    *
329e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis    * Only defined for INT formats.
330e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis    */
331b9e1b75772db2c7db566c6034ba90a07f22e35ebDouglas Gregor   void
3320b849d34b3a9574615e98e108db4e8099e9032e0Argyrios Kyrtzidis   (*unpack_rgba_uint)(unsigned *dst, unsigned dst_stride,
333b9e1b75772db2c7db566c6034ba90a07f22e35ebDouglas Gregor                       const uint8_t *src, unsigned src_stride,
3346a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor                       unsigned width, unsigned height);
3356a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor
336e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   void
337e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   (*pack_rgba_uint)(uint8_t *dst, unsigned dst_stride,
338e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis                     const unsigned *src, unsigned src_stride,
339e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis                     unsigned width, unsigned height);
340e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
341e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  /**
3426a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor    * Unpack pixel blocks to R32G32B32A32_SINT.
343e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis    * Note: strides are in bytes.
344e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis    *
345e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis    * Only defined for INT formats.
346e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis    */
347e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis   void
3482dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis   (*unpack_rgba_sint)(signed *dst, unsigned dst_stride,
3492dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis                       const uint8_t *src, unsigned src_stride,
3501824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko                       unsigned width, unsigned height);
3512dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
3522dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis   void
3532dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis   (*pack_rgba_sint)(uint8_t *dst, unsigned dst_stride,
3542dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis                     const int *src, unsigned src_stride,
3552dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis                     unsigned width, unsigned height);
356e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis};
357e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
358e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
359e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidisextern const struct util_format_description
360e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidisutil_format_description_table[];
361e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
362e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
3630b849d34b3a9574615e98e108db4e8099e9032e0Argyrios Kyrtzidisconst struct util_format_description *
3646a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregorutil_format_description(enum pipe_format format);
3654ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
3664c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
36737ed12720a35b7bfa1c4de73ad6f1c6c1c88ee17Argyrios Kyrtzidis/*
3686a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor * Format query functions.
3694ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor */
3704ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
3714ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregorstatic INLINE const char *
3724ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregorutil_format_name(enum pipe_format format)
3734ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor{
3744ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   const struct util_format_description *desc = util_format_description(format);
3754ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
37691d1bd6ede1d101a2e49719250c33154b39e0016Ted Kremenek   assert(desc);
37791d1bd6ede1d101a2e49719250c33154b39e0016Ted Kremenek   if (!desc) {
37891d1bd6ede1d101a2e49719250c33154b39e0016Ted Kremenek      return "PIPE_FORMAT_???";
3792dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis   }
3802dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
3814ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   return desc->name;
3824c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor}
3834c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
3844c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregorstatic INLINE const char *
3854c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregorutil_format_short_name(enum pipe_format format)
3864c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor{
3874c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   const struct util_format_description *desc = util_format_description(format);
3884c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
3894c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   assert(desc);
3904c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   if (!desc) {
3914c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor      return "???";
3924c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   }
3934c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
3944c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   return desc->short_name;
3954c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor}
3964c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
397f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis/**
3984c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor * Whether this format is plain, see UTIL_FORMAT_LAYOUT_PLAIN for more info.
3994c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor */
4004c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregorstatic INLINE boolean
4014c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregorutil_format_is_plain(enum pipe_format format)
4024c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor{
4034c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   const struct util_format_description *desc = util_format_description(format);
4044c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4054c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   if (!format) {
4066bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines      return FALSE;
4074c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   }
408f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis
4094c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   return desc->layout == UTIL_FORMAT_LAYOUT_PLAIN ? TRUE : FALSE;
4104c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor}
411e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
412f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidisstatic INLINE boolean
413f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidisutil_format_is_compressed(enum pipe_format format)
414f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis{
415f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis   const struct util_format_description *desc = util_format_description(format);
416f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis
417a3e9a969fd25022805a9e0ad827f3729286f6d58Argyrios Kyrtzidis   assert(desc);
4184c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   if (!desc) {
419e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis      return FALSE;
4204c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   }
4214c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4224c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   switch (desc->layout) {
4234c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   case UTIL_FORMAT_LAYOUT_S3TC:
4244c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   case UTIL_FORMAT_LAYOUT_RGTC:
4254c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor      /* XXX add other formats in the future */
4264c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor      return TRUE;
4274c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   default:
4284c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor      return FALSE;
4294c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   }
4304c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor}
4314c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4324c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregorstatic INLINE boolean
4334c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregorutil_format_is_s3tc(enum pipe_format format)
4344c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor{
4354c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   const struct util_format_description *desc = util_format_description(format);
4364c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4374c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   assert(desc);
4384c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   if (!desc) {
4394c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor      return FALSE;
4404c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   }
4414c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4424c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   return desc->layout == UTIL_FORMAT_LAYOUT_S3TC ? TRUE : FALSE;
4434c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor}
4444c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4454c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregorstatic INLINE boolean
4464c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregorutil_format_is_srgb(enum pipe_format format)
4474c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor{
4484c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   const struct util_format_description *desc = util_format_description(format);
44967029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregor   return desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB;
45067029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregor}
45167029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregor
45267029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregorstatic INLINE boolean
4538d366c0e347ab600ac09e2ba9b676d12017a448aFrancois Pichetutil_format_has_depth(const struct util_format_description *desc)
4548d366c0e347ab600ac09e2ba9b676d12017a448aFrancois Pichet{
4558d366c0e347ab600ac09e2ba9b676d12017a448aFrancois Pichet   return desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS &&
4568d366c0e347ab600ac09e2ba9b676d12017a448aFrancois Pichet          desc->swizzle[0] != UTIL_FORMAT_SWIZZLE_NONE;
45767029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregor}
45867029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregor
45967029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregorstatic INLINE boolean
46067029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregorutil_format_has_stencil(const struct util_format_description *desc)
46167029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregor{
46267029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregor   return desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS &&
4634c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor          desc->swizzle[1] != UTIL_FORMAT_SWIZZLE_NONE;
4644c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor}
46567029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregor
46667029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregorstatic INLINE boolean
46767029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregorutil_format_is_depth_or_stencil(enum pipe_format format)
46867029567f7d39d9356fbc505fffc2c1e21bf06ceDouglas Gregor{
4694c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   const struct util_format_description *desc = util_format_description(format);
4704c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4714c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   assert(desc);
4724c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   if (!desc) {
4734c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor      return FALSE;
4744c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   }
4754c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4764c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   return util_format_has_depth(desc) ||
4774c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor          util_format_has_stencil(desc);
4784c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor}
4794c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4804c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregorstatic INLINE boolean
4814c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregorutil_format_is_depth_and_stencil(enum pipe_format format)
4824c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor{
4834c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   const struct util_format_description *desc = util_format_description(format);
4844c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4854c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   assert(desc);
4864c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   if (!desc) {
4874c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor      return FALSE;
4884c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   }
4894c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4904c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor   return util_format_has_depth(desc) &&
4914c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor          util_format_has_stencil(desc);
4921a23f12e1e283384b76e768a83f01bfcbbd61ca0Douglas Gregor}
4931a23f12e1e283384b76e768a83f01bfcbbd61ca0Douglas Gregor
4941a23f12e1e283384b76e768a83f01bfcbbd61ca0Douglas Gregor
4951a23f12e1e283384b76e768a83f01bfcbbd61ca0Douglas Gregor/**
4961a23f12e1e283384b76e768a83f01bfcbbd61ca0Douglas Gregor * Give the RGBA colormask of the channels that can be represented in this
497f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis * format.
4984c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor *
4994c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor * That is, the channels whose values are preserved.
500b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis */
501b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidisstatic INLINE unsigned
502b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidisutil_format_colormask(const struct util_format_description *desc)
503b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis{
504b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis   unsigned colormask;
505b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis   unsigned chan;
506b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis
507b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis   switch (desc->colorspace) {
508b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis   case UTIL_FORMAT_COLORSPACE_RGB:
509b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis   case UTIL_FORMAT_COLORSPACE_SRGB:
510b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis   case UTIL_FORMAT_COLORSPACE_YUV:
511b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis      colormask = 0;
512b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis      for (chan = 0; chan < 4; ++chan) {
513b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis         if (desc->swizzle[chan] < 4) {
514b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis            colormask |= (1 << chan);
515b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis         }
516b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis      }
517b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis      return colormask;
518b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis   case UTIL_FORMAT_COLORSPACE_ZS:
519b6441ef9b7285bd1aa77b05b10f473f7a3f413e7Argyrios Kyrtzidis      return 0;
5200a480293f726508ad9aed0be39e8c9779e84f2f2Douglas Gregor   default:
521632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis      assert(0);
522632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis      return 0;
523632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis   }
524632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis}
525632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis
526632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis
527632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidisboolean
528632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidisutil_format_is_float(enum pipe_format format);
529632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis
530632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidis
531632dcc92f60ab7f806a89c5bca3a0951763a9219Argyrios Kyrtzidisboolean
5322dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidisutil_format_is_rgb_no_alpha(enum pipe_format format);
5331824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko
534f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis
535f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidisboolean
536f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidisutil_format_is_luminance(enum pipe_format format);
5372dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
5382dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
5391824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenkoboolean
5401824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenkoutil_format_is_luminance_alpha(enum pipe_format format);
541f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis
542f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis
543f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidisboolean
544809d1be9820039b4cf6efa48246a0d70ffa13394James Dennettutil_format_is_intensity(enum pipe_format format);
545f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis
546f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidisboolean
547f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidisutil_format_is_pure_integer(enum pipe_format format);
5484ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
549db81d38d9cd468a9eeffe8ab092be4d48e43888eArgyrios Kyrtzidisboolean
550c6c54521f95760a5eaf29b668d4bf41fe2af49d7Argyrios Kyrtzidisutil_format_is_pure_sint(enum pipe_format format);
5516a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor
5524c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregorboolean
553b57a624f22b1efa873e0abac78128b69fba3d486Sebastian Redlutil_format_is_pure_uint(enum pipe_format format);
55489d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor
55589d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor/**
55689d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor * Whether the src format can be blitted to destation format with a simple
55789d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor * memcpy.
55889d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor */
559b9e1b75772db2c7db566c6034ba90a07f22e35ebDouglas Gregorboolean
560b9e1b75772db2c7db566c6034ba90a07f22e35ebDouglas Gregorutil_is_format_compatible(const struct util_format_description *src_desc,
5611b058e8956ea29a7fb7649fdee2b80581dcbdf39Douglas Gregor                          const struct util_format_description *dst_desc);
562651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
563651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/**
564651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines * Whether the format is supported by Gallium for the given bindings.
565651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines * This covers S3TC textures and floating-point render targets.
566651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines */
5674c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregorboolean
568c6c54521f95760a5eaf29b668d4bf41fe2af49d7Argyrios Kyrtzidisutil_format_is_supported(enum pipe_format format, unsigned bind);
569651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
570651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/**
571651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines * Whether this format is a rgab8 variant.
572651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines *
573651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines * That is, any format that matches the
574651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines *
575651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines *   PIPE_FORMAT_?8?8?8?8_UNORM
576651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines */
577651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstatic INLINE boolean
578651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesutil_format_is_rgba8_variant(const struct util_format_description *desc)
579651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines{
580651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines   unsigned chan;
581651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
582651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines   if(desc->block.width != 1 ||
5835f5250b140544436eb3c2fbd9f43e14019ef01f2Argyrios Kyrtzidis      desc->block.height != 1 ||
584651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      desc->block.bits != 32)
585651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      return FALSE;
586651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
587651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines   for(chan = 0; chan < 4; ++chan) {
5885f5250b140544436eb3c2fbd9f43e14019ef01f2Argyrios Kyrtzidis      if(desc->channel[chan].type != UTIL_FORMAT_TYPE_UNSIGNED &&
5895f5250b140544436eb3c2fbd9f43e14019ef01f2Argyrios Kyrtzidis         desc->channel[chan].type != UTIL_FORMAT_TYPE_VOID)
5905f5250b140544436eb3c2fbd9f43e14019ef01f2Argyrios Kyrtzidis         return FALSE;
591e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis      if(desc->channel[chan].size != 8)
592f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis         return FALSE;
593f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis   }
594f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis
595f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis   return TRUE;
596f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis}
597f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis
598f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis
599f03b888a12ccff7d54ddd8a79a0141cf23adbf67Argyrios Kyrtzidis/**
600f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis * Return total bits needed for the pixel format per block.
601e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis */
602e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidisstatic INLINE uint
6034ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregorutil_format_get_blocksizebits(enum pipe_format format)
6044ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor{
6054ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   const struct util_format_description *desc = util_format_description(format);
6064ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
6074ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   assert(desc);
6084ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   if (!desc) {
6094ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor      return 0;
6104ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   }
6114ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
6124ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor   return desc->block.bits;
6134ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor}
6144ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor
6154ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor/**
6164ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor * Return bytes per block (not pixel) for the given format.
617 */
618static INLINE uint
619util_format_get_blocksize(enum pipe_format format)
620{
621   uint bits = util_format_get_blocksizebits(format);
622
623   assert(bits % 8 == 0);
624
625   return bits / 8;
626}
627
628static INLINE uint
629util_format_get_blockwidth(enum pipe_format format)
630{
631   const struct util_format_description *desc = util_format_description(format);
632
633   assert(desc);
634   if (!desc) {
635      return 1;
636   }
637
638   return desc->block.width;
639}
640
641static INLINE uint
642util_format_get_blockheight(enum pipe_format format)
643{
644   const struct util_format_description *desc = util_format_description(format);
645
646   assert(desc);
647   if (!desc) {
648      return 1;
649   }
650
651   return desc->block.height;
652}
653
654static INLINE unsigned
655util_format_get_nblocksx(enum pipe_format format,
656                         unsigned x)
657{
658   unsigned blockwidth = util_format_get_blockwidth(format);
659   return (x + blockwidth - 1) / blockwidth;
660}
661
662static INLINE unsigned
663util_format_get_nblocksy(enum pipe_format format,
664                         unsigned y)
665{
666   unsigned blockheight = util_format_get_blockheight(format);
667   return (y + blockheight - 1) / blockheight;
668}
669
670static INLINE unsigned
671util_format_get_nblocks(enum pipe_format format,
672                        unsigned width,
673                        unsigned height)
674{
675   return util_format_get_nblocksx(format, width) * util_format_get_nblocksy(format, height);
676}
677
678static INLINE size_t
679util_format_get_stride(enum pipe_format format,
680                       unsigned width)
681{
682   return util_format_get_nblocksx(format, width) * util_format_get_blocksize(format);
683}
684
685static INLINE size_t
686util_format_get_2d_size(enum pipe_format format,
687                        size_t stride,
688                        unsigned height)
689{
690   return util_format_get_nblocksy(format, height) * stride;
691}
692
693static INLINE uint
694util_format_get_component_bits(enum pipe_format format,
695                               enum util_format_colorspace colorspace,
696                               uint component)
697{
698   const struct util_format_description *desc = util_format_description(format);
699   enum util_format_colorspace desc_colorspace;
700
701   assert(format);
702   if (!format) {
703      return 0;
704   }
705
706   assert(component < 4);
707
708   /* Treat RGB and SRGB as equivalent. */
709   if (colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
710      colorspace = UTIL_FORMAT_COLORSPACE_RGB;
711   }
712   if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
713      desc_colorspace = UTIL_FORMAT_COLORSPACE_RGB;
714   } else {
715      desc_colorspace = desc->colorspace;
716   }
717
718   if (desc_colorspace != colorspace) {
719      return 0;
720   }
721
722   switch (desc->swizzle[component]) {
723   case UTIL_FORMAT_SWIZZLE_X:
724      return desc->channel[0].size;
725   case UTIL_FORMAT_SWIZZLE_Y:
726      return desc->channel[1].size;
727   case UTIL_FORMAT_SWIZZLE_Z:
728      return desc->channel[2].size;
729   case UTIL_FORMAT_SWIZZLE_W:
730      return desc->channel[3].size;
731   default:
732      return 0;
733   }
734}
735
736static INLINE boolean
737util_format_has_alpha(enum pipe_format format)
738{
739   const struct util_format_description *desc = util_format_description(format);
740
741   assert(format);
742   if (!format) {
743      return FALSE;
744   }
745
746   switch (desc->colorspace) {
747   case UTIL_FORMAT_COLORSPACE_RGB:
748   case UTIL_FORMAT_COLORSPACE_SRGB:
749      return desc->swizzle[3] != UTIL_FORMAT_SWIZZLE_1;
750   case UTIL_FORMAT_COLORSPACE_YUV:
751      return FALSE;
752   case UTIL_FORMAT_COLORSPACE_ZS:
753      return FALSE;
754   default:
755      assert(0);
756      return FALSE;
757   }
758}
759
760/**
761 * Given a linear RGB colorspace format, return the corresponding SRGB
762 * format, or PIPE_FORMAT_NONE if none.
763 */
764static INLINE enum pipe_format
765util_format_srgb(enum pipe_format format)
766{
767   switch (format) {
768   case PIPE_FORMAT_L8_UNORM:
769      return PIPE_FORMAT_L8_SRGB;
770   case PIPE_FORMAT_L8A8_UNORM:
771      return PIPE_FORMAT_L8A8_SRGB;
772   case PIPE_FORMAT_R8G8B8_UNORM:
773      return PIPE_FORMAT_R8G8B8_SRGB;
774   case PIPE_FORMAT_A8B8G8R8_UNORM:
775      return PIPE_FORMAT_A8B8G8R8_SRGB;
776   case PIPE_FORMAT_X8B8G8R8_UNORM:
777      return PIPE_FORMAT_X8B8G8R8_SRGB;
778   case PIPE_FORMAT_B8G8R8A8_UNORM:
779      return PIPE_FORMAT_B8G8R8A8_SRGB;
780   case PIPE_FORMAT_B8G8R8X8_UNORM:
781      return PIPE_FORMAT_B8G8R8X8_SRGB;
782   case PIPE_FORMAT_A8R8G8B8_UNORM:
783      return PIPE_FORMAT_A8R8G8B8_SRGB;
784   case PIPE_FORMAT_X8R8G8B8_UNORM:
785      return PIPE_FORMAT_X8R8G8B8_SRGB;
786   case PIPE_FORMAT_DXT1_RGB:
787      return PIPE_FORMAT_DXT1_SRGB;
788   case PIPE_FORMAT_DXT1_RGBA:
789      return PIPE_FORMAT_DXT1_SRGBA;
790   case PIPE_FORMAT_DXT3_RGBA:
791      return PIPE_FORMAT_DXT3_SRGBA;
792   case PIPE_FORMAT_DXT5_RGBA:
793      return PIPE_FORMAT_DXT5_SRGBA;
794   default:
795      return PIPE_FORMAT_NONE;
796   }
797}
798
799/**
800 * Given an sRGB format, return the corresponding linear colorspace format.
801 * For non sRGB formats, return the format unchanged.
802 */
803static INLINE enum pipe_format
804util_format_linear(enum pipe_format format)
805{
806   switch (format) {
807   case PIPE_FORMAT_L8_SRGB:
808      return PIPE_FORMAT_L8_UNORM;
809   case PIPE_FORMAT_L8A8_SRGB:
810      return PIPE_FORMAT_L8A8_UNORM;
811   case PIPE_FORMAT_R8G8B8_SRGB:
812      return PIPE_FORMAT_R8G8B8_UNORM;
813   case PIPE_FORMAT_A8B8G8R8_SRGB:
814      return PIPE_FORMAT_A8B8G8R8_UNORM;
815   case PIPE_FORMAT_X8B8G8R8_SRGB:
816      return PIPE_FORMAT_X8B8G8R8_UNORM;
817   case PIPE_FORMAT_B8G8R8A8_SRGB:
818      return PIPE_FORMAT_B8G8R8A8_UNORM;
819   case PIPE_FORMAT_B8G8R8X8_SRGB:
820      return PIPE_FORMAT_B8G8R8X8_UNORM;
821   case PIPE_FORMAT_A8R8G8B8_SRGB:
822      return PIPE_FORMAT_A8R8G8B8_UNORM;
823   case PIPE_FORMAT_X8R8G8B8_SRGB:
824      return PIPE_FORMAT_X8R8G8B8_UNORM;
825   case PIPE_FORMAT_DXT1_SRGB:
826      return PIPE_FORMAT_DXT1_RGB;
827   case PIPE_FORMAT_DXT1_SRGBA:
828      return PIPE_FORMAT_DXT1_RGBA;
829   case PIPE_FORMAT_DXT3_SRGBA:
830      return PIPE_FORMAT_DXT3_RGBA;
831   case PIPE_FORMAT_DXT5_SRGBA:
832      return PIPE_FORMAT_DXT5_RGBA;
833   default:
834      return format;
835   }
836}
837
838/**
839 * Return the number of components stored.
840 * Formats with block size != 1x1 will always have 1 component (the block).
841 */
842static INLINE unsigned
843util_format_get_nr_components(enum pipe_format format)
844{
845   const struct util_format_description *desc = util_format_description(format);
846   return desc->nr_channels;
847}
848
849/**
850 * Return the index of the first non-void channel
851 * -1 if no non-void channels
852 */
853static INLINE int
854util_format_get_first_non_void_channel(enum pipe_format format)
855{
856   const struct util_format_description *desc = util_format_description(format);
857   int i;
858
859   for (i = 0; i < 4; i++)
860      if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID)
861         break;
862
863   if (i == 4)
864       return -1;
865
866   return i;
867}
868
869/*
870 * Format access functions.
871 */
872
873void
874util_format_read_4f(enum pipe_format format,
875                    float *dst, unsigned dst_stride,
876                    const void *src, unsigned src_stride,
877                    unsigned x, unsigned y, unsigned w, unsigned h);
878
879void
880util_format_write_4f(enum pipe_format format,
881                     const float *src, unsigned src_stride,
882                     void *dst, unsigned dst_stride,
883                     unsigned x, unsigned y, unsigned w, unsigned h);
884
885void
886util_format_read_4ub(enum pipe_format format,
887                     uint8_t *dst, unsigned dst_stride,
888                     const void *src, unsigned src_stride,
889                     unsigned x, unsigned y, unsigned w, unsigned h);
890
891void
892util_format_write_4ub(enum pipe_format format,
893                      const uint8_t *src, unsigned src_stride,
894                      void *dst, unsigned dst_stride,
895                      unsigned x, unsigned y, unsigned w, unsigned h);
896
897void
898util_format_read_4ui(enum pipe_format format,
899                     unsigned *dst, unsigned dst_stride,
900                     const void *src, unsigned src_stride,
901                     unsigned x, unsigned y, unsigned w, unsigned h);
902
903void
904util_format_write_4ui(enum pipe_format format,
905                      const unsigned int *src, unsigned src_stride,
906                      void *dst, unsigned dst_stride,
907                      unsigned x, unsigned y, unsigned w, unsigned h);
908
909void
910util_format_read_4i(enum pipe_format format,
911                    int *dst, unsigned dst_stride,
912                    const void *src, unsigned src_stride,
913                    unsigned x, unsigned y, unsigned w, unsigned h);
914
915void
916util_format_write_4i(enum pipe_format format,
917                     const int *src, unsigned src_stride,
918                     void *dst, unsigned dst_stride,
919                     unsigned x, unsigned y, unsigned w, unsigned h);
920
921/*
922 * Generic format conversion;
923 */
924
925boolean
926util_format_fits_8unorm(const struct util_format_description *format_desc);
927
928void
929util_format_translate(enum pipe_format dst_format,
930                      void *dst, unsigned dst_stride,
931                      unsigned dst_x, unsigned dst_y,
932                      enum pipe_format src_format,
933                      const void *src, unsigned src_stride,
934                      unsigned src_x, unsigned src_y,
935                      unsigned width, unsigned height);
936
937/*
938 * Swizzle operations.
939 */
940
941/* Compose two sets of swizzles.
942 * If V is a 4D vector and the function parameters represent functions that
943 * swizzle vector components, this holds:
944 *     swz2(swz1(V)) = dst(V)
945 */
946void util_format_compose_swizzles(const unsigned char swz1[4],
947                                  const unsigned char swz2[4],
948                                  unsigned char dst[4]);
949
950void util_format_swizzle_4f(float *dst, const float *src,
951                            const unsigned char swz[4]);
952
953void util_format_unswizzle_4f(float *dst, const float *src,
954                              const unsigned char swz[4]);
955
956#ifdef __cplusplus
957} // extern "C" {
958#endif
959
960#endif /* ! U_FORMAT_H */
961