formats.h 26.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * Mesa 3-D graphics library
 *
 * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
 * Copyright (c) 2008-2009  VMware, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20
21
22
23
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
24
25
26
27
28
29
30
31
32
33
34
35
 */

/*
 * Authors:
 *   Brian Paul
 */


#ifndef FORMATS_H
#define FORMATS_H


Vinson Lee's avatar
Vinson Lee committed
36
#include <GL/gl.h>
37
#include <stdbool.h>
38
#include <stdint.h>
39
#include "compiler.h"
40
41
42
43
44
45

#ifdef __cplusplus
extern "C" {
#endif


46
47
48
49
/**
 * OpenGL doesn't have GL_UNSIGNED_BYTE_4_4, so we must define our own type
 * for GL_LUMINANCE4_ALPHA4.
 */
50
#define MESA_UNSIGNED_BYTE_4_4 (GL_UNSIGNED_BYTE<<1)
51
52


Brian Paul's avatar
Brian Paul committed
53
54
55
56
57
58
59
/**
 * Max number of bytes for any non-compressed pixel format below, or for
 * intermediate pixel storage in Mesa.  This should never be less than
 * 16.  Maybe 32 someday?
 */
#define MAX_PIXEL_BYTES 16

60
61
62
63
64
65
66
/**
 * Specifies the layout of a pixel format.  See the MESA_FORMAT
 * documentation below.
 */
enum mesa_format_layout {
   MESA_FORMAT_LAYOUT_ARRAY,
   MESA_FORMAT_LAYOUT_PACKED,
67
68
   MESA_FORMAT_LAYOUT_S3TC,
   MESA_FORMAT_LAYOUT_RGTC,
69
   MESA_FORMAT_LAYOUT_LATC,
70
71
72
73
   MESA_FORMAT_LAYOUT_FXT1,
   MESA_FORMAT_LAYOUT_ETC1,
   MESA_FORMAT_LAYOUT_ETC2,
   MESA_FORMAT_LAYOUT_BPTC,
74
   MESA_FORMAT_LAYOUT_ASTC,
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
   MESA_FORMAT_LAYOUT_OTHER,
};

/**
 * An enum representing different possible swizzling values.  This is used
 * to interpret the output of _mesa_get_format_swizzle
 */
enum {
   MESA_FORMAT_SWIZZLE_X = 0,
   MESA_FORMAT_SWIZZLE_Y = 1,
   MESA_FORMAT_SWIZZLE_Z = 2,
   MESA_FORMAT_SWIZZLE_W = 3,
   MESA_FORMAT_SWIZZLE_ZERO = 4,
   MESA_FORMAT_SWIZZLE_ONE = 5,
   MESA_FORMAT_SWIZZLE_NONE = 6,
};
Brian Paul's avatar
Brian Paul committed
91

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/**
 * An uint32_t that encodes the information necessary to represent an
 * array format
 */
typedef uint32_t mesa_array_format;

/**
 * Encoding for valid array format data types
 */
enum mesa_array_format_datatype {
   MESA_ARRAY_FORMAT_TYPE_UBYTE = 0x0,
   MESA_ARRAY_FORMAT_TYPE_USHORT = 0x1,
   MESA_ARRAY_FORMAT_TYPE_UINT = 0x2,
   MESA_ARRAY_FORMAT_TYPE_BYTE = 0x4,
   MESA_ARRAY_FORMAT_TYPE_SHORT = 0x5,
   MESA_ARRAY_FORMAT_TYPE_INT = 0x6,
   MESA_ARRAY_FORMAT_TYPE_HALF = 0xd,
   MESA_ARRAY_FORMAT_TYPE_FLOAT = 0xe,
};

/**
 * An enum useful to encode/decode information stored in a mesa_array_format
 */
enum {
   MESA_ARRAY_FORMAT_TYPE_IS_SIGNED = 0x4,
   MESA_ARRAY_FORMAT_TYPE_IS_FLOAT = 0x8,
   MESA_ARRAY_FORMAT_TYPE_NORMALIZED = 0x10,
   MESA_ARRAY_FORMAT_DATATYPE_MASK = 0xf,
   MESA_ARRAY_FORMAT_TYPE_MASK = 0x1f,
   MESA_ARRAY_FORMAT_TYPE_SIZE_MASK = 0x3,
   MESA_ARRAY_FORMAT_NUM_CHANS_MASK = 0xe0,
   MESA_ARRAY_FORMAT_SWIZZLE_X_MASK = 0x00700,
   MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK = 0x03800,
   MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK = 0x1c000,
   MESA_ARRAY_FORMAT_SWIZZLE_W_MASK = 0xe0000,
   MESA_ARRAY_FORMAT_BIT = 0x80000000
};

#define MESA_ARRAY_FORMAT(SIZE, SIGNED, IS_FLOAT, NORM, NUM_CHANS, \
      SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W) (                \
   (((SIZE >> 1)      ) & MESA_ARRAY_FORMAT_TYPE_SIZE_MASK) |      \
   (((SIGNED)    << 2 ) & MESA_ARRAY_FORMAT_TYPE_IS_SIGNED) |      \
   (((IS_FLOAT)  << 3 ) & MESA_ARRAY_FORMAT_TYPE_IS_FLOAT) |       \
   (((NORM)      << 4 ) & MESA_ARRAY_FORMAT_TYPE_NORMALIZED) |     \
   (((NUM_CHANS) << 5 ) & MESA_ARRAY_FORMAT_NUM_CHANS_MASK) |      \
   (((SWIZZLE_X) << 8 ) & MESA_ARRAY_FORMAT_SWIZZLE_X_MASK) |      \
   (((SWIZZLE_Y) << 11) & MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK) |      \
   (((SWIZZLE_Z) << 14) & MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK) |      \
   (((SWIZZLE_W) << 17) & MESA_ARRAY_FORMAT_SWIZZLE_W_MASK) |      \
   MESA_ARRAY_FORMAT_BIT)

/**
 * Various helpers to access the data encoded in a mesa_array_format
 */
static inline bool
_mesa_array_format_is_signed(mesa_array_format f)
{
   return (f & MESA_ARRAY_FORMAT_TYPE_IS_SIGNED) != 0;
}

static inline bool
_mesa_array_format_is_float(mesa_array_format f)
{
   return (f & MESA_ARRAY_FORMAT_TYPE_IS_FLOAT) != 0;
}

static inline bool
_mesa_array_format_is_normalized(mesa_array_format f)
{
   return (f & MESA_ARRAY_FORMAT_TYPE_NORMALIZED) !=0;
}

static inline enum mesa_array_format_datatype
_mesa_array_format_get_datatype(mesa_array_format f)
{
   return (enum mesa_array_format_datatype)
            (f & MESA_ARRAY_FORMAT_DATATYPE_MASK);
}

static inline int
_mesa_array_format_datatype_get_size(enum mesa_array_format_datatype type)
{
   return 1 << (type & MESA_ARRAY_FORMAT_TYPE_SIZE_MASK);
}

static inline int
_mesa_array_format_get_type_size(mesa_array_format f)
{
   return 1 << (f & MESA_ARRAY_FORMAT_TYPE_SIZE_MASK);
}

static inline int
_mesa_array_format_get_num_channels(mesa_array_format f)
{
   return (f & MESA_ARRAY_FORMAT_NUM_CHANS_MASK) >> 5;
}

static inline void
_mesa_array_format_get_swizzle(mesa_array_format f, uint8_t *swizzle)
{
   swizzle[0] = (f & MESA_ARRAY_FORMAT_SWIZZLE_X_MASK) >> 8;
   swizzle[1] = (f & MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK) >> 11;
   swizzle[2] = (f & MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK) >> 14;
   swizzle[3] = (f & MESA_ARRAY_FORMAT_SWIZZLE_W_MASK) >> 17;
}

static inline void
_mesa_array_format_set_swizzle(mesa_array_format *f,
                               int32_t x, int32_t y, int32_t z, int32_t w)
{
202
203
204
205
206
   *f &= ~(MESA_ARRAY_FORMAT_SWIZZLE_X_MASK |
           MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK |
           MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK |
           MESA_ARRAY_FORMAT_SWIZZLE_W_MASK);

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
   *f |= ((x << 8 ) & MESA_ARRAY_FORMAT_SWIZZLE_X_MASK) |
         ((y << 11) & MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK) |
         ((z << 14) & MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK) |
         ((w << 17) & MESA_ARRAY_FORMAT_SWIZZLE_W_MASK);
}

/**
 * A helper to know if the format stored in a uint32_t is a mesa_format
 * or a mesa_array_format
 */
static inline bool
_mesa_format_is_mesa_array_format(uint32_t f)
{
   return (f & MESA_ARRAY_FORMAT_BIT) != 0;
}

223
224
225
226
227
/**
 * Mesa texture/renderbuffer image formats.
 */
typedef enum
{
Brian Paul's avatar
Brian Paul committed
228
   MESA_FORMAT_NONE = 0,
229

230
   /**
231
    * \name Basic hardware formats
232
233
234
235
    *
    * The mesa format name specification is as follows:
    *
    *  There shall be 3 naming format base types: those for component array
236
237
238
239
240
241
242
243
244
245
246
247
248
249
    *  formats (type A); those for compressed formats (type C); and those for
    *  packed component formats (type P). With type A formats, color component
    *  order does not change with endianess. Each format name shall begin with
    *  MESA_FORMAT_, followed by a component label (from the Component Label
    *  list below) for each component in the order that the component(s) occur
    *  in the format, except for non-linear color formats where the first
    *  letter shall be 'S'. For type P formats, each component label is
    *  followed by the number of bits that represent it in the fundamental
    *  data type used by the format.
    *
    *  Following the listing of the component labels shall be an underscore; a
    *  compression type followed by an underscore for Type C formats only; a
    *  storage type from the list below; and a bit with for type A formats,
    *  which is the bit width for each array element.
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
    *
    *
    *  ----------    Format Base Type A: Array ----------
    *  MESA_FORMAT_[component list]_[storage type][array element bit width]
    *
    *  examples:
    *  MESA_FORMAT_A_SNORM8     - uchar[i] = A
    *  MESA_FORMAT_RGBA_16 - ushort[i * 4 + 0] = R, ushort[i * 4 + 1] = G,
    *                             ushort[i * 4 + 2] = B, ushort[i * 4 + 3] = A
    *  MESA_FORMAT_Z_UNORM32    - float[i] = Z
    *
    *
    *
    *  ----------    Format Base Type C: Compressed ----------
    *  MESA_FORMAT_[component list*][_*][compression type][storage type*]
    *  * where required
    *
    *  examples:
    *  MESA_FORMAT_RGB_ETC1
    *  MESA_FORMAT_RGBA_ETC2
    *  MESA_FORMAT_LATC1_UNORM
    *  MESA_FORMAT_RGBA_FXT1
    *
    *
    *
    *  ----------    Format Base Type P: Packed  ----------
    *  MESA_FORMAT_[[component list,bit width][storage type*][_]][_][storage type**]
    *   * when type differs between component
    *   ** when type applies to all components
    *
    *  examples:                   msb <------ TEXEL BITS -----------> lsb
281
282
283
    *  MESA_FORMAT_A8B8G8R8_UNORM, RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA
    *  MESA_FORMAT_R5G6B5_UNORM                        BBBB BGGG GGGR RRRR
    *  MESA_FORMAT_B4G4R4X4_UNORM                      XXXX RRRR GGGG BBBB
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
    *  MESA_FORMAT_Z32_FLOAT_S8X24_UINT
    *  MESA_FORMAT_R10G10B10A2_UINT
    *  MESA_FORMAT_R9G9B9E5_FLOAT
    *
    *
    *
    *  ----------    Component Labels: ----------
    *  A - Alpha
    *  B - Blue
    *  DU - Delta U
    *  DV - Delta V
    *  E - Shared Exponent
    *  G - Green
    *  I - Intensity
    *  L - Luminance
    *  R - Red
    *  S - Stencil (when not followed by RGB or RGBA)
    *  U - Chrominance
    *  V - Chrominance
    *  Y - Luma
    *  X - Packing bits
    *  Z - Depth
    *
    *
    *
    *  ----------    Type C Compression Types: ----------
    *  DXT1 - Color component labels shall be given
    *  DXT3 - Color component labels shall be given
    *  DXT5 - Color component labels shall be given
    *  ETC1 - No other information required
    *  ETC2 - No other information required
    *  FXT1 - Color component labels shall be given
    *  FXT3 - Color component labels shall be given
    *  LATC1 - Fundamental data type shall be given
    *  LATC2 - Fundamental data type shall be given
    *  RGTC1 - Color component labels and data type shall be given
    *  RGTC2 - Color component labels and data type shall be given
    *
    *
    *
    *  ----------    Storage Types: ----------
    *  FLOAT
    *  SINT
    *  UINT
    *  SNORM
    *  UNORM
330
331
    *  SRGB - RGB components, or L are UNORMs in sRGB color space.
    *         Alpha, if present is linear.
332
    *
333
    */
334

Brian Paul's avatar
Brian Paul committed
335
   /* Packed unorm formats */    /* msb <------ TEXEL BITS -----------> lsb */
336
                                 /* ---- ---- ---- ---- ---- ---- ---- ---- */
337
338
   MESA_FORMAT_A8B8G8R8_UNORM,   /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
   MESA_FORMAT_X8B8G8R8_UNORM,   /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */
Brian Paul's avatar
Brian Paul committed
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 */
Brian Paul's avatar
Brian Paul committed
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 */
Brian Paul's avatar
Brian Paul committed
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 */
Brian Paul's avatar
Brian Paul committed
345
346
   MESA_FORMAT_L16A16_UNORM,     /* AAAA AAAA AAAA AAAA LLLL LLLL LLLL LLLL */
   MESA_FORMAT_A16L16_UNORM,     /* LLLL LLLL LLLL LLLL AAAA AAAA AAAA AAAA */
347
348
349
   MESA_FORMAT_B5G6R5_UNORM,                         /* RRRR RGGG GGGB BBBB */
   MESA_FORMAT_R5G6B5_UNORM,                         /* BBBB BGGG GGGR RRRR */
   MESA_FORMAT_B4G4R4A4_UNORM,                       /* AAAA RRRR GGGG BBBB */
Brian Paul's avatar
Brian Paul committed
350
   MESA_FORMAT_B4G4R4X4_UNORM,                       /* xxxx RRRR GGGG BBBB */
351
352
353
   MESA_FORMAT_A4R4G4B4_UNORM,                       /* BBBB GGGG RRRR AAAA */
   MESA_FORMAT_A1B5G5R5_UNORM,                       /* RRRR RGGG GGBB BBBA */
   MESA_FORMAT_B5G5R5A1_UNORM,                       /* ARRR RRGG GGGB BBBB */
Brian Paul's avatar
Brian Paul committed
354
   MESA_FORMAT_B5G5R5X1_UNORM,                       /* xRRR RRGG GGGB BBBB */
355
356
357
358
359
   MESA_FORMAT_A1R5G5B5_UNORM,                       /* BBBB BGGG GGRR RRRA */
   MESA_FORMAT_L8A8_UNORM,                           /* AAAA AAAA LLLL LLLL */
   MESA_FORMAT_A8L8_UNORM,                           /* LLLL LLLL AAAA AAAA */
   MESA_FORMAT_R8G8_UNORM,                           /* GGGG GGGG RRRR RRRR */
   MESA_FORMAT_G8R8_UNORM,                           /* RRRR RRRR GGGG GGGG */
Brian Paul's avatar
Brian Paul committed
360
361
   MESA_FORMAT_L4A4_UNORM,                                     /* AAAA LLLL */
   MESA_FORMAT_B2G3R3_UNORM,                                   /* RRRG GGBB */
362

363
364
365
   MESA_FORMAT_R16G16_UNORM,     /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
   MESA_FORMAT_G16R16_UNORM,     /* RRRR RRRR RRRR RRRR GGGG GGGG GGGG GGGG */
   MESA_FORMAT_B10G10R10A2_UNORM,/* AARR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */
Brian Paul's avatar
Brian Paul committed
366
367
   MESA_FORMAT_B10G10R10X2_UNORM,/* xxRR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */
   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 */
Brian Paul's avatar
Brian Paul committed
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 */
Brian Paul's avatar
Brian Paul committed
373
   MESA_FORMAT_Z24_UNORM_X8_UINT,/* xxxx xxxx ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
374

375
376
377
378
379
380
381
382
   /* Other formats */
   MESA_FORMAT_R3G3B2_UNORM,                                   /* BBGG GRRR */
   MESA_FORMAT_A4B4G4R4_UNORM,                       /* RRRR GGGG BBBB AAAA */
   MESA_FORMAT_R4G4B4A4_UNORM,                       /* AAAA BBBB GGGG RRRR */
   MESA_FORMAT_R5G5B5A1_UNORM,                       /* ABBB BBGG GGGR RRRR */
   MESA_FORMAT_A2B10G10R10_UNORM,/* RRRR RRRR RRGG GGGG GGGG BBBB BBBB BBAA */
   MESA_FORMAT_A2R10G10B10_UNORM,/* BBBB BBBB BBGG GGGG GGGG RRRR RRRR RRAA */

Brian Paul's avatar
Brian Paul committed
383
384
   MESA_FORMAT_YCBCR,            /*                     YYYY YYYY UorV UorV */
   MESA_FORMAT_YCBCR_REV,        /*                     UorV UorV YYYY YYYY */
385

Brian Paul's avatar
Brian Paul committed
386
387
388
389
390
391
392
393
394
395
396
397
398
   /* Array unorm formats */
   MESA_FORMAT_A_UNORM8,      /* ubyte[i] = A */
   MESA_FORMAT_A_UNORM16,     /* ushort[i] = A */
   MESA_FORMAT_L_UNORM8,      /* ubyte[i] = L */
   MESA_FORMAT_L_UNORM16,     /* ushort[i] = L */
   MESA_FORMAT_I_UNORM8,      /* ubyte[i] = I */
   MESA_FORMAT_I_UNORM16,     /* ushort[i] = I */
   MESA_FORMAT_R_UNORM8,      /* ubyte[i] = R */
   MESA_FORMAT_R_UNORM16,     /* ushort[i] = R */
   MESA_FORMAT_BGR_UNORM8,    /* ubyte[i*3] = B, [i*3+1] = G, [i*3+2] = R */
   MESA_FORMAT_RGB_UNORM8,    /* ubyte[i*3] = R, [i*3+1] = G, [i*3+2] = B */
   MESA_FORMAT_RGBA_UNORM16,  /* ushort[i] = R, [1] = G, [2] = B, [3] = A */
   MESA_FORMAT_RGBX_UNORM16,  
399

Brian Paul's avatar
Brian Paul committed
400
   MESA_FORMAT_Z_UNORM16,     /* ushort[i] = Z */
401
   MESA_FORMAT_Z_UNORM32,     /* uint[i] = Z */
Brian Paul's avatar
Brian Paul committed
402
   MESA_FORMAT_S_UINT8,       /* ubyte[i] = S */
403

Brian Paul's avatar
Brian Paul committed
404
405
406
407
408
409
410
411
412
413
414
415
   /* Packed signed/normalized formats */
                                 /* msb <------ TEXEL BITS -----------> lsb */
                                 /* ---- ---- ---- ---- ---- ---- ---- ---- */
   MESA_FORMAT_A8B8G8R8_SNORM,   /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
   MESA_FORMAT_X8B8G8R8_SNORM,   /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */
   MESA_FORMAT_R8G8B8A8_SNORM,   /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
   MESA_FORMAT_R8G8B8X8_SNORM,   /* xxxx xxxx BBBB BBBB GGGG GGGG RRRR RRRR */
   MESA_FORMAT_R16G16_SNORM,     /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
   MESA_FORMAT_G16R16_SNORM,     /* RRRR RRRR RRRR RRRR GGGG GGGG GGGG GGGG */
   MESA_FORMAT_R8G8_SNORM,       /*                     GGGG GGGG RRRR RRRR */
   MESA_FORMAT_G8R8_SNORM,       /*                     RRRR RRRR GGGG GGGG */
   MESA_FORMAT_L8A8_SNORM,       /*                     AAAA AAAA LLLL LLLL */
416
   MESA_FORMAT_A8L8_SNORM,       /*                     LLLL LLLL AAAA AAAA */
Brian Paul's avatar
Brian Paul committed
417
418
419
420
421
422
423
424
425
426
427
428
429
430

   /* Array signed/normalized formats */
   MESA_FORMAT_A_SNORM8,      /* byte[i] = A */
   MESA_FORMAT_A_SNORM16,     /* short[i] = A */
   MESA_FORMAT_L_SNORM8,      /* byte[i] = L */
   MESA_FORMAT_L_SNORM16,     /* short[i] = L */
   MESA_FORMAT_I_SNORM8,      /* byte[i] = I */
   MESA_FORMAT_I_SNORM16,     /* short[i] = I */
   MESA_FORMAT_R_SNORM8,      /* byte[i] = R */
   MESA_FORMAT_R_SNORM16,     /* short[i] = R */
   MESA_FORMAT_LA_SNORM16,    /* short[i * 2] = L, [i * 2 + 1] = A */
   MESA_FORMAT_RGB_SNORM16,   /* short[i*3] = R, [i*3+1] = G, [i*3+2] = B */
   MESA_FORMAT_RGBA_SNORM16,  /* ... */
   MESA_FORMAT_RGBX_SNORM16,  /* ... */
431

Brian Paul's avatar
Brian Paul committed
432
   /* Packed sRGB formats */
433
434
   MESA_FORMAT_A8B8G8R8_SRGB,    /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
   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 */
Brian Paul's avatar
Brian Paul committed
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 */
Brian Paul's avatar
Brian Paul committed
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

Brian Paul's avatar
Brian Paul committed
444
445
446
   /* Array sRGB formats */
   MESA_FORMAT_L_SRGB8,       /* ubyte[i] = L */
   MESA_FORMAT_BGR_SRGB8,     /* ubyte[i*3] = B, [i*3+1] = G, [i*3+2] = R */
447

Brian Paul's avatar
Brian Paul committed
448
449
450
451
   /* Packed float formats */
   MESA_FORMAT_R9G9B9E5_FLOAT,
   MESA_FORMAT_R11G11B10_FLOAT,   /* BBBB BBBB BBGG GGGG GGGG GRRR RRRR RRRR */
   MESA_FORMAT_Z32_FLOAT_S8X24_UINT, /* (float, x24s8) */
452

Brian Paul's avatar
Brian Paul committed
453
   /* Array float formats */
454
   MESA_FORMAT_A_FLOAT16,
Brian Paul's avatar
Brian Paul committed
455
   MESA_FORMAT_A_FLOAT32,
456
   MESA_FORMAT_L_FLOAT16,
Brian Paul's avatar
Brian Paul committed
457
   MESA_FORMAT_L_FLOAT32,
458
   MESA_FORMAT_LA_FLOAT16,
Brian Paul's avatar
Brian Paul committed
459
   MESA_FORMAT_LA_FLOAT32,
460
   MESA_FORMAT_I_FLOAT16,
Brian Paul's avatar
Brian Paul committed
461
   MESA_FORMAT_I_FLOAT32,
462
   MESA_FORMAT_R_FLOAT16,
Brian Paul's avatar
Brian Paul committed
463
   MESA_FORMAT_R_FLOAT32,
464
   MESA_FORMAT_RG_FLOAT16,
Brian Paul's avatar
Brian Paul committed
465
466
467
468
469
470
471
472
   MESA_FORMAT_RG_FLOAT32,
   MESA_FORMAT_RGB_FLOAT16,
   MESA_FORMAT_RGB_FLOAT32,
   MESA_FORMAT_RGBA_FLOAT16,
   MESA_FORMAT_RGBA_FLOAT32,  /* float[0] = R, [1] = G, [2] = B, [3] = A */
   MESA_FORMAT_RGBX_FLOAT16,
   MESA_FORMAT_RGBX_FLOAT32,
   MESA_FORMAT_Z_FLOAT32,
473

Brian Paul's avatar
Brian Paul committed
474
   /* Packed signed/unsigned non-normalized integer formats */
475
476
477
478
479

   MESA_FORMAT_A8B8G8R8_UINT,    /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
   MESA_FORMAT_A8R8G8B8_UINT,    /* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */
   MESA_FORMAT_R8G8B8A8_UINT,    /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
   MESA_FORMAT_B8G8R8A8_UINT,    /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */
Brian Paul's avatar
Brian Paul committed
480
481
   MESA_FORMAT_B10G10R10A2_UINT, /* AARR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */
   MESA_FORMAT_R10G10B10A2_UINT, /* AABB BBBB BBBB GGGG GGGG GGRR RRRR RRRR */
482
483
   MESA_FORMAT_A2B10G10R10_UINT, /* RRRR RRRR RRGG GGGG GGGG BBBB BBBB BBAA */
   MESA_FORMAT_A2R10G10B10_UINT, /* BBBB BBBB BBGG GGGG GGGG RRRR RRRR RRAA */
484
485
486
487
488
489
490
491
492
493
494
495
   MESA_FORMAT_B5G6R5_UINT,                          /* RRRR RGGG GGGB BBBB */
   MESA_FORMAT_R5G6B5_UINT,                          /* BBBB BGGG GGGR RRRR */
   MESA_FORMAT_B2G3R3_UINT,                                    /* RRRG GGBB */
   MESA_FORMAT_R3G3B2_UINT,                                    /* BBGG GRRR */
   MESA_FORMAT_A4B4G4R4_UINT,                        /* RRRR GGGG BBBB AAAA */
   MESA_FORMAT_R4G4B4A4_UINT,                        /* AAAA BBBB GGGG RRRR */
   MESA_FORMAT_B4G4R4A4_UINT,                        /* AAAA RRRR GGGG BBBB */
   MESA_FORMAT_A4R4G4B4_UINT,                        /* BBBB GGGG RRRR AAAA */
   MESA_FORMAT_A1B5G5R5_UINT,                        /* RRRR RGGG GGBB BBBA */
   MESA_FORMAT_B5G5R5A1_UINT,                        /* ARRR RRGG GGGB BBBB */
   MESA_FORMAT_A1R5G5B5_UINT,                        /* BBBB BGGG GGRR RRRA */
   MESA_FORMAT_R5G5B5A1_UINT,                        /* ABBB BBGG GGGR RRRR */
496

Brian Paul's avatar
Brian Paul committed
497
   /* Array signed/unsigned non-normalized integer formats */
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
   MESA_FORMAT_A_UINT8,
   MESA_FORMAT_A_UINT16,
   MESA_FORMAT_A_UINT32,
   MESA_FORMAT_A_SINT8,
   MESA_FORMAT_A_SINT16,
   MESA_FORMAT_A_SINT32,

   MESA_FORMAT_I_UINT8,
   MESA_FORMAT_I_UINT16,
   MESA_FORMAT_I_UINT32,
   MESA_FORMAT_I_SINT8,
   MESA_FORMAT_I_SINT16,
   MESA_FORMAT_I_SINT32,

   MESA_FORMAT_L_UINT8,
   MESA_FORMAT_L_UINT16,
   MESA_FORMAT_L_UINT32,
   MESA_FORMAT_L_SINT8,
   MESA_FORMAT_L_SINT16,
   MESA_FORMAT_L_SINT32,
Brian Paul's avatar
Brian Paul committed
518

519
520
521
522
523
524
   MESA_FORMAT_LA_UINT8,
   MESA_FORMAT_LA_UINT16,
   MESA_FORMAT_LA_UINT32,
   MESA_FORMAT_LA_SINT8,
   MESA_FORMAT_LA_SINT16,
   MESA_FORMAT_LA_SINT32,
525

Brian Paul's avatar
Brian Paul committed
526
527
528
   MESA_FORMAT_R_UINT8,
   MESA_FORMAT_R_UINT16,
   MESA_FORMAT_R_UINT32,
529
530
531
   MESA_FORMAT_R_SINT8,
   MESA_FORMAT_R_SINT16,
   MESA_FORMAT_R_SINT32,
532

533
534
535
   MESA_FORMAT_RG_UINT8,
   MESA_FORMAT_RG_UINT16,
   MESA_FORMAT_RG_UINT32,
Brian Paul's avatar
Brian Paul committed
536
537
538
539
540
541
   MESA_FORMAT_RG_SINT8,
   MESA_FORMAT_RG_SINT16,
   MESA_FORMAT_RG_SINT32,

   MESA_FORMAT_RGB_UINT8,
   MESA_FORMAT_RGB_UINT16,
542
   MESA_FORMAT_RGB_UINT32,
Brian Paul's avatar
Brian Paul committed
543
544
545
   MESA_FORMAT_RGB_SINT8,
   MESA_FORMAT_RGB_SINT16,
   MESA_FORMAT_RGB_SINT32,
546

Brian Paul's avatar
Brian Paul committed
547
548
549
550
551
552
   MESA_FORMAT_RGBA_UINT8,
   MESA_FORMAT_RGBA_UINT16,
   MESA_FORMAT_RGBA_UINT32,
   MESA_FORMAT_RGBA_SINT8,
   MESA_FORMAT_RGBA_SINT16,
   MESA_FORMAT_RGBA_SINT32,
553

Brian Paul's avatar
Brian Paul committed
554
555
556
557
558
559
   MESA_FORMAT_RGBX_UINT8,
   MESA_FORMAT_RGBX_UINT16,
   MESA_FORMAT_RGBX_UINT32,
   MESA_FORMAT_RGBX_SINT8,
   MESA_FORMAT_RGBX_SINT16,
   MESA_FORMAT_RGBX_SINT32,
560

Brian Paul's avatar
Brian Paul committed
561
562
563
564
565
   /* DXT compressed formats */
   MESA_FORMAT_RGB_DXT1,
   MESA_FORMAT_RGBA_DXT1,
   MESA_FORMAT_RGBA_DXT3,
   MESA_FORMAT_RGBA_DXT5,
566

Brian Paul's avatar
Brian Paul committed
567
568
569
570
571
   /* DXT sRGB compressed formats */
   MESA_FORMAT_SRGB_DXT1,
   MESA_FORMAT_SRGBA_DXT1,
   MESA_FORMAT_SRGBA_DXT3,
   MESA_FORMAT_SRGBA_DXT5,
572

Brian Paul's avatar
Brian Paul committed
573
574
575
   /* FXT1 compressed formats */
   MESA_FORMAT_RGB_FXT1,
   MESA_FORMAT_RGBA_FXT1,
576

Brian Paul's avatar
Brian Paul committed
577
   /* RGTC compressed formats */
578
579
580
581
   MESA_FORMAT_R_RGTC1_UNORM,
   MESA_FORMAT_R_RGTC1_SNORM,
   MESA_FORMAT_RG_RGTC2_UNORM,
   MESA_FORMAT_RG_RGTC2_SNORM,
582

Brian Paul's avatar
Brian Paul committed
583
   /* LATC1/2 compressed formats */
584
585
586
587
   MESA_FORMAT_L_LATC1_UNORM,
   MESA_FORMAT_L_LATC1_SNORM,
   MESA_FORMAT_LA_LATC2_UNORM,
   MESA_FORMAT_LA_LATC2_SNORM,
588

Brian Paul's avatar
Brian Paul committed
589
   /* ETC1/2 compressed formats */
590
   MESA_FORMAT_ETC1_RGB8,
591
592
593
594
595
596
597
598
599
600
   MESA_FORMAT_ETC2_RGB8,
   MESA_FORMAT_ETC2_SRGB8,
   MESA_FORMAT_ETC2_RGBA8_EAC,
   MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC,
   MESA_FORMAT_ETC2_R11_EAC,
   MESA_FORMAT_ETC2_RG11_EAC,
   MESA_FORMAT_ETC2_SIGNED_R11_EAC,
   MESA_FORMAT_ETC2_SIGNED_RG11_EAC,
   MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1,
   MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1,
601

602
603
604
605
606
607
   /* BPTC compressed formats */
   MESA_FORMAT_BPTC_RGBA_UNORM,
   MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM,
   MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT,
   MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT,

608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
   /* ASTC compressed formats */
   MESA_FORMAT_RGBA_ASTC_4x4,
   MESA_FORMAT_RGBA_ASTC_5x4,
   MESA_FORMAT_RGBA_ASTC_5x5,
   MESA_FORMAT_RGBA_ASTC_6x5,
   MESA_FORMAT_RGBA_ASTC_6x6,
   MESA_FORMAT_RGBA_ASTC_8x5,
   MESA_FORMAT_RGBA_ASTC_8x6,
   MESA_FORMAT_RGBA_ASTC_8x8,
   MESA_FORMAT_RGBA_ASTC_10x5,
   MESA_FORMAT_RGBA_ASTC_10x6,
   MESA_FORMAT_RGBA_ASTC_10x8,
   MESA_FORMAT_RGBA_ASTC_10x10,
   MESA_FORMAT_RGBA_ASTC_12x10,
   MESA_FORMAT_RGBA_ASTC_12x12,

   MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12,
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658

   MESA_FORMAT_RGBA_ASTC_3x3x3,
   MESA_FORMAT_RGBA_ASTC_4x3x3,
   MESA_FORMAT_RGBA_ASTC_4x4x3,
   MESA_FORMAT_RGBA_ASTC_4x4x4,
   MESA_FORMAT_RGBA_ASTC_5x4x4,
   MESA_FORMAT_RGBA_ASTC_5x5x4,
   MESA_FORMAT_RGBA_ASTC_5x5x5,
   MESA_FORMAT_RGBA_ASTC_6x5x5,
   MESA_FORMAT_RGBA_ASTC_6x6x5,
   MESA_FORMAT_RGBA_ASTC_6x6x6,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5,
   MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5,
   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

Brian Paul's avatar
Brian Paul committed
669
extern GLint
670
_mesa_get_format_bits(mesa_format format, GLenum pname);
Brian Paul's avatar
Brian Paul committed
671

672
extern GLuint
673
_mesa_get_format_max_bits(mesa_format format);
674

675
676
677
extern enum mesa_format_layout
_mesa_get_format_layout(mesa_format format);

Brian Paul's avatar
Brian Paul committed
678
extern GLenum
679
_mesa_get_format_datatype(mesa_format format);
Brian Paul's avatar
Brian Paul committed
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
688
689
690
extern void
_mesa_get_format_block_size_3d(mesa_format format, GLuint *bw,
                               GLuint *bh, GLuint *bd);

691
692
693
extern mesa_array_format
_mesa_array_format_flip_channels(mesa_array_format format);

694
695
696
extern void
_mesa_get_format_swizzle(mesa_format format, uint8_t swizzle_out[4]);

697
698
699
700
701
702
extern uint32_t
_mesa_format_to_array_format(mesa_format format);

extern mesa_format
_mesa_format_from_array_format(uint32_t array_format);

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
719
720
extern GLboolean
_mesa_is_format_integer(mesa_format format);

721
722
723
extern bool
_mesa_is_format_etc2(mesa_format format);

724
725
726
GLenum
_mesa_is_format_color_format(mesa_format format);

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
733
                        GLsizei height, GLsizei depth);

734
extern uint64_t
735
_mesa_format_image_size64(mesa_format format, GLsizei width,
736
737
                          GLsizei height, GLsizei depth);

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
746
747
extern void
_mesa_test_formats(void);

748
749
extern mesa_format
_mesa_get_srgb_format_linear(mesa_format format);
750

751
752
extern mesa_format
_mesa_get_uncompressed_format(mesa_format format);
753
754

extern GLuint
755
_mesa_format_num_components(mesa_format format);
756

757
758
759
extern bool
_mesa_format_has_color_component(mesa_format format, int component);

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
766
767
768
#ifdef __cplusplus
}
#endif

769
#endif /* FORMATS_H */