Home | History | Annotate | Download | only in main
      1 /*
      2  * Mesa 3-D graphics library
      3  *
      4  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
      5  * Copyright (c) 2008-2009  VMware, Inc.
      6  *
      7  * Permission is hereby granted, free of charge, to any person obtaining a
      8  * copy of this software and associated documentation files (the "Software"),
      9  * to deal in the Software without restriction, including without limitation
     10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     11  * and/or sell copies of the Software, and to permit persons to whom the
     12  * Software is furnished to do so, subject to the following conditions:
     13  *
     14  * The above copyright notice and this permission notice shall be included
     15  * in all copies or substantial portions of the Software.
     16  *
     17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
     21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     23  * OTHER DEALINGS IN THE SOFTWARE.
     24  */
     25 
     26 /*
     27  * Authors:
     28  *   Brian Paul
     29  */
     30 
     31 
     32 #ifndef FORMATS_H
     33 #define FORMATS_H
     34 
     35 
     36 #include <GL/gl.h>
     37 #include <stdbool.h>
     38 #include <stdint.h>
     39 #include "compiler.h"
     40 
     41 #ifdef __cplusplus
     42 extern "C" {
     43 #endif
     44 
     45 
     46 /**
     47  * OpenGL doesn't have GL_UNSIGNED_BYTE_4_4, so we must define our own type
     48  * for GL_LUMINANCE4_ALPHA4.
     49  */
     50 #define MESA_UNSIGNED_BYTE_4_4 (GL_UNSIGNED_BYTE<<1)
     51 
     52 
     53 /**
     54  * Max number of bytes for any non-compressed pixel format below, or for
     55  * intermediate pixel storage in Mesa.  This should never be less than
     56  * 16.  Maybe 32 someday?
     57  */
     58 #define MAX_PIXEL_BYTES 16
     59 
     60 /**
     61  * Specifies the layout of a pixel format.  See the MESA_FORMAT
     62  * documentation below.
     63  */
     64 enum mesa_format_layout {
     65    MESA_FORMAT_LAYOUT_ARRAY,
     66    MESA_FORMAT_LAYOUT_PACKED,
     67    MESA_FORMAT_LAYOUT_S3TC,
     68    MESA_FORMAT_LAYOUT_RGTC,
     69    MESA_FORMAT_LAYOUT_LATC,
     70    MESA_FORMAT_LAYOUT_FXT1,
     71    MESA_FORMAT_LAYOUT_ETC1,
     72    MESA_FORMAT_LAYOUT_ETC2,
     73    MESA_FORMAT_LAYOUT_BPTC,
     74    MESA_FORMAT_LAYOUT_ASTC,
     75    MESA_FORMAT_LAYOUT_OTHER,
     76 };
     77 
     78 /**
     79  * An enum representing different possible swizzling values.  This is used
     80  * to interpret the output of _mesa_get_format_swizzle
     81  */
     82 enum {
     83    MESA_FORMAT_SWIZZLE_X = 0,
     84    MESA_FORMAT_SWIZZLE_Y = 1,
     85    MESA_FORMAT_SWIZZLE_Z = 2,
     86    MESA_FORMAT_SWIZZLE_W = 3,
     87    MESA_FORMAT_SWIZZLE_ZERO = 4,
     88    MESA_FORMAT_SWIZZLE_ONE = 5,
     89    MESA_FORMAT_SWIZZLE_NONE = 6,
     90 };
     91 
     92 /**
     93  * An uint32_t that encodes the information necessary to represent an
     94  * array format
     95  */
     96 typedef uint32_t mesa_array_format;
     97 
     98 /**
     99  * Encoding for valid array format data types
    100  */
    101 enum mesa_array_format_datatype {
    102    MESA_ARRAY_FORMAT_TYPE_UBYTE = 0x0,
    103    MESA_ARRAY_FORMAT_TYPE_USHORT = 0x1,
    104    MESA_ARRAY_FORMAT_TYPE_UINT = 0x2,
    105    MESA_ARRAY_FORMAT_TYPE_BYTE = 0x4,
    106    MESA_ARRAY_FORMAT_TYPE_SHORT = 0x5,
    107    MESA_ARRAY_FORMAT_TYPE_INT = 0x6,
    108    MESA_ARRAY_FORMAT_TYPE_HALF = 0xd,
    109    MESA_ARRAY_FORMAT_TYPE_FLOAT = 0xe,
    110 };
    111 
    112 /**
    113  * An enum useful to encode/decode information stored in a mesa_array_format
    114  */
    115 enum {
    116    MESA_ARRAY_FORMAT_TYPE_IS_SIGNED = 0x4,
    117    MESA_ARRAY_FORMAT_TYPE_IS_FLOAT = 0x8,
    118    MESA_ARRAY_FORMAT_TYPE_NORMALIZED = 0x10,
    119    MESA_ARRAY_FORMAT_DATATYPE_MASK = 0xf,
    120    MESA_ARRAY_FORMAT_TYPE_MASK = 0x1f,
    121    MESA_ARRAY_FORMAT_TYPE_SIZE_MASK = 0x3,
    122    MESA_ARRAY_FORMAT_NUM_CHANS_MASK = 0xe0,
    123    MESA_ARRAY_FORMAT_SWIZZLE_X_MASK = 0x00700,
    124    MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK = 0x03800,
    125    MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK = 0x1c000,
    126    MESA_ARRAY_FORMAT_SWIZZLE_W_MASK = 0xe0000,
    127    MESA_ARRAY_FORMAT_BIT = 0x80000000
    128 };
    129 
    130 #define MESA_ARRAY_FORMAT(SIZE, SIGNED, IS_FLOAT, NORM, NUM_CHANS, \
    131       SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W) (                \
    132    (((SIZE >> 1)      ) & MESA_ARRAY_FORMAT_TYPE_SIZE_MASK) |      \
    133    (((SIGNED)    << 2 ) & MESA_ARRAY_FORMAT_TYPE_IS_SIGNED) |      \
    134    (((IS_FLOAT)  << 3 ) & MESA_ARRAY_FORMAT_TYPE_IS_FLOAT) |       \
    135    (((NORM)      << 4 ) & MESA_ARRAY_FORMAT_TYPE_NORMALIZED) |     \
    136    (((NUM_CHANS) << 5 ) & MESA_ARRAY_FORMAT_NUM_CHANS_MASK) |      \
    137    (((SWIZZLE_X) << 8 ) & MESA_ARRAY_FORMAT_SWIZZLE_X_MASK) |      \
    138    (((SWIZZLE_Y) << 11) & MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK) |      \
    139    (((SWIZZLE_Z) << 14) & MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK) |      \
    140    (((SWIZZLE_W) << 17) & MESA_ARRAY_FORMAT_SWIZZLE_W_MASK) |      \
    141    MESA_ARRAY_FORMAT_BIT)
    142 
    143 /**
    144  * Various helpers to access the data encoded in a mesa_array_format
    145  */
    146 static inline bool
    147 _mesa_array_format_is_signed(mesa_array_format f)
    148 {
    149    return (f & MESA_ARRAY_FORMAT_TYPE_IS_SIGNED) != 0;
    150 }
    151 
    152 static inline bool
    153 _mesa_array_format_is_float(mesa_array_format f)
    154 {
    155    return (f & MESA_ARRAY_FORMAT_TYPE_IS_FLOAT) != 0;
    156 }
    157 
    158 static inline bool
    159 _mesa_array_format_is_normalized(mesa_array_format f)
    160 {
    161    return (f & MESA_ARRAY_FORMAT_TYPE_NORMALIZED) !=0;
    162 }
    163 
    164 static inline enum mesa_array_format_datatype
    165 _mesa_array_format_get_datatype(mesa_array_format f)
    166 {
    167    return (enum mesa_array_format_datatype)
    168             (f & MESA_ARRAY_FORMAT_DATATYPE_MASK);
    169 }
    170 
    171 static inline int
    172 _mesa_array_format_datatype_get_size(enum mesa_array_format_datatype type)
    173 {
    174    return 1 << (type & MESA_ARRAY_FORMAT_TYPE_SIZE_MASK);
    175 }
    176 
    177 static inline int
    178 _mesa_array_format_get_type_size(mesa_array_format f)
    179 {
    180    return 1 << (f & MESA_ARRAY_FORMAT_TYPE_SIZE_MASK);
    181 }
    182 
    183 static inline int
    184 _mesa_array_format_get_num_channels(mesa_array_format f)
    185 {
    186    return (f & MESA_ARRAY_FORMAT_NUM_CHANS_MASK) >> 5;
    187 }
    188 
    189 static inline void
    190 _mesa_array_format_get_swizzle(mesa_array_format f, uint8_t *swizzle)
    191 {
    192    swizzle[0] = (f & MESA_ARRAY_FORMAT_SWIZZLE_X_MASK) >> 8;
    193    swizzle[1] = (f & MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK) >> 11;
    194    swizzle[2] = (f & MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK) >> 14;
    195    swizzle[3] = (f & MESA_ARRAY_FORMAT_SWIZZLE_W_MASK) >> 17;
    196 }
    197 
    198 static inline void
    199 _mesa_array_format_set_swizzle(mesa_array_format *f,
    200                                int32_t x, int32_t y, int32_t z, int32_t w)
    201 {
    202    *f &= ~(MESA_ARRAY_FORMAT_SWIZZLE_X_MASK |
    203            MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK |
    204            MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK |
    205            MESA_ARRAY_FORMAT_SWIZZLE_W_MASK);
    206 
    207    *f |= ((x << 8 ) & MESA_ARRAY_FORMAT_SWIZZLE_X_MASK) |
    208          ((y << 11) & MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK) |
    209          ((z << 14) & MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK) |
    210          ((w << 17) & MESA_ARRAY_FORMAT_SWIZZLE_W_MASK);
    211 }
    212 
    213 /**
    214  * A helper to know if the format stored in a uint32_t is a mesa_format
    215  * or a mesa_array_format
    216  */
    217 static inline bool
    218 _mesa_format_is_mesa_array_format(uint32_t f)
    219 {
    220    return (f & MESA_ARRAY_FORMAT_BIT) != 0;
    221 }
    222 
    223 /**
    224  * Mesa texture/renderbuffer image formats.
    225  */
    226 typedef enum
    227 {
    228    MESA_FORMAT_NONE = 0,
    229 
    230    /**
    231     * \name Basic hardware formats
    232     *
    233     * The mesa format name specification is as follows:
    234     *
    235     *  There shall be 3 naming format base types: those for component array
    236     *  formats (type A); those for compressed formats (type C); and those for
    237     *  packed component formats (type P). With type A formats, color component
    238     *  order does not change with endianess. Each format name shall begin with
    239     *  MESA_FORMAT_, followed by a component label (from the Component Label
    240     *  list below) for each component in the order that the component(s) occur
    241     *  in the format, except for non-linear color formats where the first
    242     *  letter shall be 'S'. For type P formats, each component label is
    243     *  followed by the number of bits that represent it in the fundamental
    244     *  data type used by the format.
    245     *
    246     *  Following the listing of the component labels shall be an underscore; a
    247     *  compression type followed by an underscore for Type C formats only; a
    248     *  storage type from the list below; and a bit with for type A formats,
    249     *  which is the bit width for each array element.
    250     *
    251     *
    252     *  ----------    Format Base Type A: Array ----------
    253     *  MESA_FORMAT_[component list]_[storage type][array element bit width]
    254     *
    255     *  examples:
    256     *  MESA_FORMAT_A_SNORM8     - uchar[i] = A
    257     *  MESA_FORMAT_RGBA_16 - ushort[i * 4 + 0] = R, ushort[i * 4 + 1] = G,
    258     *                             ushort[i * 4 + 2] = B, ushort[i * 4 + 3] = A
    259     *  MESA_FORMAT_Z_UNORM32    - float[i] = Z
    260     *
    261     *
    262     *
    263     *  ----------    Format Base Type C: Compressed ----------
    264     *  MESA_FORMAT_[component list*][_*][compression type][storage type*]
    265     *  * where required
    266     *
    267     *  examples:
    268     *  MESA_FORMAT_RGB_ETC1
    269     *  MESA_FORMAT_RGBA_ETC2
    270     *  MESA_FORMAT_LATC1_UNORM
    271     *  MESA_FORMAT_RGBA_FXT1
    272     *
    273     *
    274     *
    275     *  ----------    Format Base Type P: Packed  ----------
    276     *  MESA_FORMAT_[[component list,bit width][storage type*][_]][_][storage type**]
    277     *   * when type differs between component
    278     *   ** when type applies to all components
    279     *
    280     *  examples:                   msb <------ TEXEL BITS -----------> lsb
    281     *  MESA_FORMAT_A8B8G8R8_UNORM, RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA
    282     *  MESA_FORMAT_R5G6B5_UNORM                        BBBB BGGG GGGR RRRR
    283     *  MESA_FORMAT_B4G4R4X4_UNORM                      XXXX RRRR GGGG BBBB
    284     *  MESA_FORMAT_Z32_FLOAT_S8X24_UINT
    285     *  MESA_FORMAT_R10G10B10A2_UINT
    286     *  MESA_FORMAT_R9G9B9E5_FLOAT
    287     *
    288     *
    289     *
    290     *  ----------    Component Labels: ----------
    291     *  A - Alpha
    292     *  B - Blue
    293     *  DU - Delta U
    294     *  DV - Delta V
    295     *  E - Shared Exponent
    296     *  G - Green
    297     *  I - Intensity
    298     *  L - Luminance
    299     *  R - Red
    300     *  S - Stencil (when not followed by RGB or RGBA)
    301     *  U - Chrominance
    302     *  V - Chrominance
    303     *  Y - Luma
    304     *  X - Packing bits
    305     *  Z - Depth
    306     *
    307     *
    308     *
    309     *  ----------    Type C Compression Types: ----------
    310     *  DXT1 - Color component labels shall be given
    311     *  DXT3 - Color component labels shall be given
    312     *  DXT5 - Color component labels shall be given
    313     *  ETC1 - No other information required
    314     *  ETC2 - No other information required
    315     *  FXT1 - Color component labels shall be given
    316     *  FXT3 - Color component labels shall be given
    317     *  LATC1 - Fundamental data type shall be given
    318     *  LATC2 - Fundamental data type shall be given
    319     *  RGTC1 - Color component labels and data type shall be given
    320     *  RGTC2 - Color component labels and data type shall be given
    321     *
    322     *
    323     *
    324     *  ----------    Storage Types: ----------
    325     *  FLOAT
    326     *  SINT
    327     *  UINT
    328     *  SNORM
    329     *  UNORM
    330     *  SRGB - RGB components, or L are UNORMs in sRGB color space.
    331     *         Alpha, if present is linear.
    332     *
    333     */
    334 
    335    /* Packed unorm formats */    /* msb <------ TEXEL BITS -----------> lsb */
    336                                  /* ---- ---- ---- ---- ---- ---- ---- ---- */
    337    MESA_FORMAT_A8B8G8R8_UNORM,   /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
    338    MESA_FORMAT_X8B8G8R8_UNORM,   /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */
    339    MESA_FORMAT_R8G8B8A8_UNORM,   /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
    340    MESA_FORMAT_R8G8B8X8_UNORM,   /* xxxx xxxx BBBB BBBB GGGG GGGG RRRR RRRR */
    341    MESA_FORMAT_B8G8R8A8_UNORM,   /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */
    342    MESA_FORMAT_B8G8R8X8_UNORM,   /* xxxx xxxx RRRR RRRR GGGG GGGG BBBB BBBB */
    343    MESA_FORMAT_A8R8G8B8_UNORM,   /* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */
    344    MESA_FORMAT_X8R8G8B8_UNORM,   /* BBBB BBBB GGGG GGGG RRRR RRRR xxxx xxxx */
    345    MESA_FORMAT_L16A16_UNORM,     /* AAAA AAAA AAAA AAAA LLLL LLLL LLLL LLLL */
    346    MESA_FORMAT_A16L16_UNORM,     /* LLLL LLLL LLLL LLLL AAAA AAAA AAAA AAAA */
    347    MESA_FORMAT_B5G6R5_UNORM,                         /* RRRR RGGG GGGB BBBB */
    348    MESA_FORMAT_R5G6B5_UNORM,                         /* BBBB BGGG GGGR RRRR */
    349    MESA_FORMAT_B4G4R4A4_UNORM,                       /* AAAA RRRR GGGG BBBB */
    350    MESA_FORMAT_B4G4R4X4_UNORM,                       /* xxxx RRRR GGGG BBBB */
    351    MESA_FORMAT_A4R4G4B4_UNORM,                       /* BBBB GGGG RRRR AAAA */
    352    MESA_FORMAT_A1B5G5R5_UNORM,                       /* RRRR RGGG GGBB BBBA */
    353    MESA_FORMAT_B5G5R5A1_UNORM,                       /* ARRR RRGG GGGB BBBB */
    354    MESA_FORMAT_B5G5R5X1_UNORM,                       /* xRRR RRGG GGGB BBBB */
    355    MESA_FORMAT_A1R5G5B5_UNORM,                       /* BBBB BGGG GGRR RRRA */
    356    MESA_FORMAT_L8A8_UNORM,                           /* AAAA AAAA LLLL LLLL */
    357    MESA_FORMAT_A8L8_UNORM,                           /* LLLL LLLL AAAA AAAA */
    358    MESA_FORMAT_R8G8_UNORM,                           /* GGGG GGGG RRRR RRRR */
    359    MESA_FORMAT_G8R8_UNORM,                           /* RRRR RRRR GGGG GGGG */
    360    MESA_FORMAT_L4A4_UNORM,                                     /* AAAA LLLL */
    361    MESA_FORMAT_B2G3R3_UNORM,                                   /* RRRG GGBB */
    362 
    363    MESA_FORMAT_R16G16_UNORM,     /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
    364    MESA_FORMAT_G16R16_UNORM,     /* RRRR RRRR RRRR RRRR GGGG GGGG GGGG GGGG */
    365    MESA_FORMAT_B10G10R10A2_UNORM,/* AARR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */
    366    MESA_FORMAT_B10G10R10X2_UNORM,/* xxRR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */
    367    MESA_FORMAT_R10G10B10A2_UNORM,/* AABB BBBB BBBB GGGG GGGG GGRR RRRR RRRR */
    368    MESA_FORMAT_R10G10B10X2_UNORM,/* xxBB BBBB BBBB GGGG GGGG GGRR RRRR RRRR */
    369 
    370    MESA_FORMAT_S8_UINT_Z24_UNORM,/* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ SSSS SSSS */
    371    MESA_FORMAT_X8_UINT_Z24_UNORM,/* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ xxxx xxxx */
    372    MESA_FORMAT_Z24_UNORM_S8_UINT,/* SSSS SSSS ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
    373    MESA_FORMAT_Z24_UNORM_X8_UINT,/* xxxx xxxx ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
    374 
    375    /* Other formats */
    376    MESA_FORMAT_R3G3B2_UNORM,                                   /* BBGG GRRR */
    377    MESA_FORMAT_A4B4G4R4_UNORM,                       /* RRRR GGGG BBBB AAAA */
    378    MESA_FORMAT_R4G4B4A4_UNORM,                       /* AAAA BBBB GGGG RRRR */
    379    MESA_FORMAT_R5G5B5A1_UNORM,                       /* ABBB BBGG GGGR RRRR */
    380    MESA_FORMAT_A2B10G10R10_UNORM,/* RRRR RRRR RRGG GGGG GGGG BBBB BBBB BBAA */
    381    MESA_FORMAT_A2R10G10B10_UNORM,/* BBBB BBBB BBGG GGGG GGGG RRRR RRRR RRAA */
    382 
    383    MESA_FORMAT_YCBCR,            /*                     YYYY YYYY UorV UorV */
    384    MESA_FORMAT_YCBCR_REV,        /*                     UorV UorV YYYY YYYY */
    385 
    386    /* Array unorm formats */
    387    MESA_FORMAT_A_UNORM8,      /* ubyte[i] = A */
    388    MESA_FORMAT_A_UNORM16,     /* ushort[i] = A */
    389    MESA_FORMAT_L_UNORM8,      /* ubyte[i] = L */
    390    MESA_FORMAT_L_UNORM16,     /* ushort[i] = L */
    391    MESA_FORMAT_I_UNORM8,      /* ubyte[i] = I */
    392    MESA_FORMAT_I_UNORM16,     /* ushort[i] = I */
    393    MESA_FORMAT_R_UNORM8,      /* ubyte[i] = R */
    394    MESA_FORMAT_R_UNORM16,     /* ushort[i] = R */
    395    MESA_FORMAT_BGR_UNORM8,    /* ubyte[i*3] = B, [i*3+1] = G, [i*3+2] = R */
    396    MESA_FORMAT_RGB_UNORM8,    /* ubyte[i*3] = R, [i*3+1] = G, [i*3+2] = B */
    397    MESA_FORMAT_RGBA_UNORM16,  /* ushort[i] = R, [1] = G, [2] = B, [3] = A */
    398    MESA_FORMAT_RGBX_UNORM16,
    399 
    400    MESA_FORMAT_Z_UNORM16,     /* ushort[i] = Z */
    401    MESA_FORMAT_Z_UNORM32,     /* uint[i] = Z */
    402    MESA_FORMAT_S_UINT8,       /* ubyte[i] = S */
    403 
    404    /* Packed signed/normalized formats */
    405                                  /* msb <------ TEXEL BITS -----------> lsb */
    406                                  /* ---- ---- ---- ---- ---- ---- ---- ---- */
    407    MESA_FORMAT_A8B8G8R8_SNORM,   /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
    408    MESA_FORMAT_X8B8G8R8_SNORM,   /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */
    409    MESA_FORMAT_R8G8B8A8_SNORM,   /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
    410    MESA_FORMAT_R8G8B8X8_SNORM,   /* xxxx xxxx BBBB BBBB GGGG GGGG RRRR RRRR */
    411    MESA_FORMAT_R16G16_SNORM,     /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
    412    MESA_FORMAT_G16R16_SNORM,     /* RRRR RRRR RRRR RRRR GGGG GGGG GGGG GGGG */
    413    MESA_FORMAT_R8G8_SNORM,       /*                     GGGG GGGG RRRR RRRR */
    414    MESA_FORMAT_G8R8_SNORM,       /*                     RRRR RRRR GGGG GGGG */
    415    MESA_FORMAT_L8A8_SNORM,       /*                     AAAA AAAA LLLL LLLL */
    416    MESA_FORMAT_A8L8_SNORM,       /*                     LLLL LLLL AAAA AAAA */
    417 
    418    /* Array signed/normalized formats */
    419    MESA_FORMAT_A_SNORM8,      /* byte[i] = A */
    420    MESA_FORMAT_A_SNORM16,     /* short[i] = A */
    421    MESA_FORMAT_L_SNORM8,      /* byte[i] = L */
    422    MESA_FORMAT_L_SNORM16,     /* short[i] = L */
    423    MESA_FORMAT_I_SNORM8,      /* byte[i] = I */
    424    MESA_FORMAT_I_SNORM16,     /* short[i] = I */
    425    MESA_FORMAT_R_SNORM8,      /* byte[i] = R */
    426    MESA_FORMAT_R_SNORM16,     /* short[i] = R */
    427    MESA_FORMAT_LA_SNORM16,    /* short[i * 2] = L, [i * 2 + 1] = A */
    428    MESA_FORMAT_RGB_SNORM16,   /* short[i*3] = R, [i*3+1] = G, [i*3+2] = B */
    429    MESA_FORMAT_RGBA_SNORM16,  /* ... */
    430    MESA_FORMAT_RGBX_SNORM16,  /* ... */
    431 
    432    /* Packed sRGB formats */
    433    MESA_FORMAT_A8B8G8R8_SRGB,    /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
    434    MESA_FORMAT_B8G8R8A8_SRGB,    /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */
    435    MESA_FORMAT_A8R8G8B8_SRGB,    /* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */
    436    MESA_FORMAT_B8G8R8X8_SRGB,    /* xxxx xxxx RRRR RRRR GGGG GGGG BBBB BBBB */
    437    MESA_FORMAT_X8R8G8B8_SRGB,    /* BBBB BBBB GGGG GGGG RRRR RRRR xxxx xxxx */
    438    MESA_FORMAT_R8G8B8A8_SRGB,    /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
    439    MESA_FORMAT_R8G8B8X8_SRGB,    /* xxxx xxxx BBBB BBBB GGGG GGGG RRRR RRRR */
    440    MESA_FORMAT_X8B8G8R8_SRGB,    /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */
    441    MESA_FORMAT_L8A8_SRGB,                            /* AAAA AAAA LLLL LLLL */
    442    MESA_FORMAT_A8L8_SRGB,                            /* LLLL LLLL AAAA AAAA */
    443 
    444    /* Array sRGB formats */
    445    MESA_FORMAT_L_SRGB8,       /* ubyte[i] = L */
    446    MESA_FORMAT_BGR_SRGB8,     /* ubyte[i*3] = B, [i*3+1] = G, [i*3+2] = R */
    447 
    448    /* Packed float formats */
    449    MESA_FORMAT_R9G9B9E5_FLOAT,
    450    MESA_FORMAT_R11G11B10_FLOAT,   /* BBBB BBBB BBGG GGGG GGGG GRRR RRRR RRRR */
    451    MESA_FORMAT_Z32_FLOAT_S8X24_UINT, /* (float, x24s8) */
    452 
    453    /* Array float formats */
    454    MESA_FORMAT_A_FLOAT16,
    455    MESA_FORMAT_A_FLOAT32,
    456    MESA_FORMAT_L_FLOAT16,
    457    MESA_FORMAT_L_FLOAT32,
    458    MESA_FORMAT_LA_FLOAT16,
    459    MESA_FORMAT_LA_FLOAT32,
    460    MESA_FORMAT_I_FLOAT16,
    461    MESA_FORMAT_I_FLOAT32,
    462    MESA_FORMAT_R_FLOAT16,
    463    MESA_FORMAT_R_FLOAT32,
    464    MESA_FORMAT_RG_FLOAT16,
    465    MESA_FORMAT_RG_FLOAT32,
    466    MESA_FORMAT_RGB_FLOAT16,
    467    MESA_FORMAT_RGB_FLOAT32,
    468    MESA_FORMAT_RGBA_FLOAT16,
    469    MESA_FORMAT_RGBA_FLOAT32,  /* float[0] = R, [1] = G, [2] = B, [3] = A */
    470    MESA_FORMAT_RGBX_FLOAT16,
    471    MESA_FORMAT_RGBX_FLOAT32,
    472    MESA_FORMAT_Z_FLOAT32,
    473 
    474    /* Packed signed/unsigned non-normalized integer formats */
    475 
    476    MESA_FORMAT_A8B8G8R8_UINT,    /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
    477    MESA_FORMAT_A8R8G8B8_UINT,    /* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */
    478    MESA_FORMAT_R8G8B8A8_UINT,    /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
    479    MESA_FORMAT_B8G8R8A8_UINT,    /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */
    480    MESA_FORMAT_B10G10R10A2_UINT, /* AARR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */
    481    MESA_FORMAT_R10G10B10A2_UINT, /* AABB BBBB BBBB GGGG GGGG GGRR RRRR RRRR */
    482    MESA_FORMAT_A2B10G10R10_UINT, /* RRRR RRRR RRGG GGGG GGGG BBBB BBBB BBAA */
    483    MESA_FORMAT_A2R10G10B10_UINT, /* BBBB BBBB BBGG GGGG GGGG RRRR RRRR RRAA */
    484    MESA_FORMAT_B5G6R5_UINT,                          /* RRRR RGGG GGGB BBBB */
    485    MESA_FORMAT_R5G6B5_UINT,                          /* BBBB BGGG GGGR RRRR */
    486    MESA_FORMAT_B2G3R3_UINT,                                    /* RRRG GGBB */
    487    MESA_FORMAT_R3G3B2_UINT,                                    /* BBGG GRRR */
    488    MESA_FORMAT_A4B4G4R4_UINT,                        /* RRRR GGGG BBBB AAAA */
    489    MESA_FORMAT_R4G4B4A4_UINT,                        /* AAAA BBBB GGGG RRRR */
    490    MESA_FORMAT_B4G4R4A4_UINT,                        /* AAAA RRRR GGGG BBBB */
    491    MESA_FORMAT_A4R4G4B4_UINT,                        /* BBBB GGGG RRRR AAAA */
    492    MESA_FORMAT_A1B5G5R5_UINT,                        /* RRRR RGGG GGBB BBBA */
    493    MESA_FORMAT_B5G5R5A1_UINT,                        /* ARRR RRGG GGGB BBBB */
    494    MESA_FORMAT_A1R5G5B5_UINT,                        /* BBBB BGGG GGRR RRRA */
    495    MESA_FORMAT_R5G5B5A1_UINT,                        /* ABBB BBGG GGGR RRRR */
    496 
    497    /* Array signed/unsigned non-normalized integer formats */
    498    MESA_FORMAT_A_UINT8,
    499    MESA_FORMAT_A_UINT16,
    500    MESA_FORMAT_A_UINT32,
    501    MESA_FORMAT_A_SINT8,
    502    MESA_FORMAT_A_SINT16,
    503    MESA_FORMAT_A_SINT32,
    504 
    505    MESA_FORMAT_I_UINT8,
    506    MESA_FORMAT_I_UINT16,
    507    MESA_FORMAT_I_UINT32,
    508    MESA_FORMAT_I_SINT8,
    509    MESA_FORMAT_I_SINT16,
    510    MESA_FORMAT_I_SINT32,
    511 
    512    MESA_FORMAT_L_UINT8,
    513    MESA_FORMAT_L_UINT16,
    514    MESA_FORMAT_L_UINT32,
    515    MESA_FORMAT_L_SINT8,
    516    MESA_FORMAT_L_SINT16,
    517    MESA_FORMAT_L_SINT32,
    518 
    519    MESA_FORMAT_LA_UINT8,
    520    MESA_FORMAT_LA_UINT16,
    521    MESA_FORMAT_LA_UINT32,
    522    MESA_FORMAT_LA_SINT8,
    523    MESA_FORMAT_LA_SINT16,
    524    MESA_FORMAT_LA_SINT32,
    525 
    526    MESA_FORMAT_R_UINT8,
    527    MESA_FORMAT_R_UINT16,
    528    MESA_FORMAT_R_UINT32,
    529    MESA_FORMAT_R_SINT8,
    530    MESA_FORMAT_R_SINT16,
    531    MESA_FORMAT_R_SINT32,
    532 
    533    MESA_FORMAT_RG_UINT8,
    534    MESA_FORMAT_RG_UINT16,
    535    MESA_FORMAT_RG_UINT32,
    536    MESA_FORMAT_RG_SINT8,
    537    MESA_FORMAT_RG_SINT16,
    538    MESA_FORMAT_RG_SINT32,
    539 
    540    MESA_FORMAT_RGB_UINT8,
    541    MESA_FORMAT_RGB_UINT16,
    542    MESA_FORMAT_RGB_UINT32,
    543    MESA_FORMAT_RGB_SINT8,
    544    MESA_FORMAT_RGB_SINT16,
    545    MESA_FORMAT_RGB_SINT32,
    546 
    547    MESA_FORMAT_RGBA_UINT8,
    548    MESA_FORMAT_RGBA_UINT16,
    549    MESA_FORMAT_RGBA_UINT32,
    550    MESA_FORMAT_RGBA_SINT8,
    551    MESA_FORMAT_RGBA_SINT16,
    552    MESA_FORMAT_RGBA_SINT32,
    553 
    554    MESA_FORMAT_RGBX_UINT8,
    555    MESA_FORMAT_RGBX_UINT16,
    556    MESA_FORMAT_RGBX_UINT32,
    557    MESA_FORMAT_RGBX_SINT8,
    558    MESA_FORMAT_RGBX_SINT16,
    559    MESA_FORMAT_RGBX_SINT32,
    560 
    561    /* DXT compressed formats */
    562    MESA_FORMAT_RGB_DXT1,
    563    MESA_FORMAT_RGBA_DXT1,
    564    MESA_FORMAT_RGBA_DXT3,
    565    MESA_FORMAT_RGBA_DXT5,
    566 
    567    /* DXT sRGB compressed formats */
    568    MESA_FORMAT_SRGB_DXT1,
    569    MESA_FORMAT_SRGBA_DXT1,
    570    MESA_FORMAT_SRGBA_DXT3,
    571    MESA_FORMAT_SRGBA_DXT5,
    572 
    573    /* FXT1 compressed formats */
    574    MESA_FORMAT_RGB_FXT1,
    575    MESA_FORMAT_RGBA_FXT1,
    576 
    577    /* RGTC compressed formats */
    578    MESA_FORMAT_R_RGTC1_UNORM,
    579    MESA_FORMAT_R_RGTC1_SNORM,
    580    MESA_FORMAT_RG_RGTC2_UNORM,
    581    MESA_FORMAT_RG_RGTC2_SNORM,
    582 
    583    /* LATC1/2 compressed formats */
    584    MESA_FORMAT_L_LATC1_UNORM,
    585    MESA_FORMAT_L_LATC1_SNORM,
    586    MESA_FORMAT_LA_LATC2_UNORM,
    587    MESA_FORMAT_LA_LATC2_SNORM,
    588 
    589    /* ETC1/2 compressed formats */
    590    MESA_FORMAT_ETC1_RGB8,
    591    MESA_FORMAT_ETC2_RGB8,
    592    MESA_FORMAT_ETC2_SRGB8,
    593    MESA_FORMAT_ETC2_RGBA8_EAC,
    594    MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC,
    595    MESA_FORMAT_ETC2_R11_EAC,
    596    MESA_FORMAT_ETC2_RG11_EAC,
    597    MESA_FORMAT_ETC2_SIGNED_R11_EAC,
    598    MESA_FORMAT_ETC2_SIGNED_RG11_EAC,
    599    MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1,
    600    MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1,
    601 
    602    /* BPTC compressed formats */
    603    MESA_FORMAT_BPTC_RGBA_UNORM,
    604    MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM,
    605    MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT,
    606    MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT,
    607 
    608    /* ASTC compressed formats */
    609    MESA_FORMAT_RGBA_ASTC_4x4,
    610    MESA_FORMAT_RGBA_ASTC_5x4,
    611    MESA_FORMAT_RGBA_ASTC_5x5,
    612    MESA_FORMAT_RGBA_ASTC_6x5,
    613    MESA_FORMAT_RGBA_ASTC_6x6,
    614    MESA_FORMAT_RGBA_ASTC_8x5,
    615    MESA_FORMAT_RGBA_ASTC_8x6,
    616    MESA_FORMAT_RGBA_ASTC_8x8,
    617    MESA_FORMAT_RGBA_ASTC_10x5,
    618    MESA_FORMAT_RGBA_ASTC_10x6,
    619    MESA_FORMAT_RGBA_ASTC_10x8,
    620    MESA_FORMAT_RGBA_ASTC_10x10,
    621    MESA_FORMAT_RGBA_ASTC_12x10,
    622    MESA_FORMAT_RGBA_ASTC_12x12,
    623 
    624    MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4,
    625    MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4,
    626    MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5,
    627    MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5,
    628    MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6,
    629    MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5,
    630    MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6,
    631    MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8,
    632    MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5,
    633    MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6,
    634    MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8,
    635    MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10,
    636    MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10,
    637    MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12,
    638 
    639    MESA_FORMAT_RGBA_ASTC_3x3x3,
    640    MESA_FORMAT_RGBA_ASTC_4x3x3,
    641    MESA_FORMAT_RGBA_ASTC_4x4x3,
    642    MESA_FORMAT_RGBA_ASTC_4x4x4,
    643    MESA_FORMAT_RGBA_ASTC_5x4x4,
    644    MESA_FORMAT_RGBA_ASTC_5x5x4,
    645    MESA_FORMAT_RGBA_ASTC_5x5x5,
    646    MESA_FORMAT_RGBA_ASTC_6x5x5,
    647    MESA_FORMAT_RGBA_ASTC_6x6x5,
    648    MESA_FORMAT_RGBA_ASTC_6x6x6,
    649    MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3,
    650    MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3,
    651    MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3,
    652    MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4,
    653    MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4,
    654    MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4,
    655    MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5,
    656    MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5,
    657    MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5,
    658    MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6,
    659    MESA_FORMAT_COUNT
    660 } mesa_format;
    661 
    662 
    663 extern const char *
    664 _mesa_get_format_name(mesa_format format);
    665 
    666 extern GLint
    667 _mesa_get_format_bytes(mesa_format format);
    668 
    669 extern GLint
    670 _mesa_get_format_bits(mesa_format format, GLenum pname);
    671 
    672 extern GLuint
    673 _mesa_get_format_max_bits(mesa_format format);
    674 
    675 extern enum mesa_format_layout
    676 _mesa_get_format_layout(mesa_format format);
    677 
    678 extern GLenum
    679 _mesa_get_format_datatype(mesa_format format);
    680 
    681 extern GLenum
    682 _mesa_get_format_base_format(uint32_t format);
    683 
    684 extern void
    685 _mesa_get_format_block_size(mesa_format format, GLuint *bw, GLuint *bh);
    686 
    687 extern void
    688 _mesa_get_format_block_size_3d(mesa_format format, GLuint *bw,
    689                                GLuint *bh, GLuint *bd);
    690 
    691 extern mesa_array_format
    692 _mesa_array_format_flip_channels(mesa_array_format format);
    693 
    694 extern void
    695 _mesa_get_format_swizzle(mesa_format format, uint8_t swizzle_out[4]);
    696 
    697 extern uint32_t
    698 _mesa_format_to_array_format(mesa_format format);
    699 
    700 extern mesa_format
    701 _mesa_format_from_array_format(uint32_t array_format);
    702 
    703 extern GLboolean
    704 _mesa_is_format_compressed(mesa_format format);
    705 
    706 extern GLboolean
    707 _mesa_is_format_packed_depth_stencil(mesa_format format);
    708 
    709 extern GLboolean
    710 _mesa_is_format_integer_color(mesa_format format);
    711 
    712 extern GLboolean
    713 _mesa_is_format_unsigned(mesa_format format);
    714 
    715 extern GLboolean
    716 _mesa_is_format_signed(mesa_format format);
    717 
    718 extern GLboolean
    719 _mesa_is_format_integer(mesa_format format);
    720 
    721 extern bool
    722 _mesa_is_format_etc2(mesa_format format);
    723 
    724 GLenum
    725 _mesa_is_format_color_format(mesa_format format);
    726 
    727 extern GLenum
    728 _mesa_get_format_color_encoding(mesa_format format);
    729 
    730 extern GLuint
    731 _mesa_format_image_size(mesa_format format, GLsizei width,
    732                         GLsizei height, GLsizei depth);
    733 
    734 extern uint64_t
    735 _mesa_format_image_size64(mesa_format format, GLsizei width,
    736                           GLsizei height, GLsizei depth);
    737 
    738 extern GLint
    739 _mesa_format_row_stride(mesa_format format, GLsizei width);
    740 
    741 extern void
    742 _mesa_uncompressed_format_to_type_and_comps(mesa_format format,
    743                                GLenum *datatype, GLuint *comps);
    744 
    745 extern void
    746 _mesa_test_formats(void);
    747 
    748 extern mesa_format
    749 _mesa_get_srgb_format_linear(mesa_format format);
    750 
    751 extern mesa_format
    752 _mesa_get_uncompressed_format(mesa_format format);
    753 
    754 extern GLuint
    755 _mesa_format_num_components(mesa_format format);
    756 
    757 extern bool
    758 _mesa_format_has_color_component(mesa_format format, int component);
    759 
    760 GLboolean
    761 _mesa_format_matches_format_and_type(mesa_format mesa_format,
    762 				     GLenum format, GLenum type,
    763 				     GLboolean swapBytes, GLenum *error);
    764 
    765 #ifdef __cplusplus
    766 }
    767 #endif
    768 
    769 #endif /* FORMATS_H */
    770