Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/libktx/external/dfdutils/dfd.h
9912 views
1
/* -*- tab-width: 4; -*- */
2
/* vi: set sw=2 ts=4 expandtab: */
3
4
/* Copyright 2019-2020 The Khronos Group Inc.
5
* SPDX-License-Identifier: Apache-2.0
6
*/
7
8
/**
9
* @file
10
* @~English
11
* @brief Header file defining the data format descriptor utilities API.
12
*/
13
14
/*
15
* Author: Andrew Garrard
16
*/
17
18
#ifndef _DFD_H_
19
#define _DFD_H_
20
21
#include <KHR/khr_df.h>
22
#include <stdbool.h>
23
24
#ifdef __cplusplus
25
extern "C" {
26
#endif
27
28
/** Qualifier suffix to the format, in Vulkan terms. */
29
enum VkSuffix {
30
s_UNORM, /*!< Unsigned normalized format. */
31
s_SNORM, /*!< Signed normalized format. */
32
s_USCALED, /*!< Unsigned scaled format. */
33
s_SSCALED, /*!< Signed scaled format. */
34
s_UINT, /*!< Unsigned integer format. */
35
s_SINT, /*!< Signed integer format. */
36
s_SFLOAT, /*!< Signed float format. */
37
s_UFLOAT, /*!< Unsigned float format. */
38
s_SRGB, /*!< sRGB normalized format. */
39
s_SFIXED5 /*!< 2's complement fixed-point; 5 fractional bits. */
40
};
41
42
/** Compression scheme, in Vulkan terms. */
43
enum VkCompScheme {
44
c_BC1_RGB, /*!< BC1, aka DXT1, no alpha. */
45
c_BC1_RGBA, /*!< BC1, aka DXT1, punch-through alpha. */
46
c_BC2, /*!< BC2, aka DXT2 and DXT3. */
47
c_BC3, /*!< BC3, aka DXT4 and DXT5. */
48
c_BC4, /*!< BC4. */
49
c_BC5, /*!< BC5. */
50
c_BC6H, /*!< BC6h HDR format. */
51
c_BC7, /*!< BC7. */
52
c_ETC2_R8G8B8, /*!< ETC2 no alpha. */
53
c_ETC2_R8G8B8A1, /*!< ETC2 punch-through alpha. */
54
c_ETC2_R8G8B8A8, /*!< ETC2 independent alpha. */
55
c_EAC_R11, /*!< R11 ETC2 single-channel. */
56
c_EAC_R11G11, /*!< R11G11 ETC2 dual-channel. */
57
c_ASTC, /*!< ASTC. */
58
c_ETC1S, /*!< ETC1S. */
59
c_PVRTC, /*!< PVRTC(1). */
60
c_PVRTC2 /*!< PVRTC2. */
61
};
62
63
typedef unsigned int uint32_t;
64
65
#if !defined(LIBKTX)
66
#include <vulkan/vulkan_core.h>
67
#else
68
#include "../../lib/vkformat_enum.h"
69
#endif
70
71
uint32_t* vk2dfd(enum VkFormat format);
72
enum VkFormat dfd2vk(uint32_t* dfd);
73
74
/* Create a Data Format Descriptor for an unpacked format. */
75
uint32_t *createDFDUnpacked(int bigEndian, int numChannels, int bytes,
76
int redBlueSwap, enum VkSuffix suffix);
77
78
/* Create a Data Format Descriptor for a packed padded format. */
79
uint32_t *createDFDPackedShifted(int bigEndian, int numChannels,
80
int bits[], int shiftBits[],
81
int channels[], enum VkSuffix suffix);
82
83
/* Create a Data Format Descriptor for a packed format. */
84
uint32_t *createDFDPacked(int bigEndian, int numChannels,
85
int bits[], int channels[],
86
enum VkSuffix suffix);
87
88
/* Create a Data Format Descriptor for a 4:2:2 format. */
89
uint32_t *createDFD422(int bigEndian, int numChannels,
90
int bits[], int shiftBits[], int channels[],
91
int position_xs[], int position_ys[],
92
enum VkSuffix suffix);
93
94
/* Create a Data Format Descriptor for a compressed format. */
95
uint32_t *createDFDCompressed(enum VkCompScheme compScheme,
96
int bwidth, int bheight, int bdepth,
97
enum VkSuffix suffix);
98
99
/* Create a Data Format Descriptor for a depth/stencil format. */
100
uint32_t *createDFDDepthStencil(int depthBits,
101
int stencilBits,
102
int sizeBytes);
103
104
/* Create a Data Format Descriptor for an alpha-only format */
105
uint32_t *createDFDAlpha(int bigEndian, int bytes,
106
enum VkSuffix suffix);
107
108
/** @brief Result of interpreting the data format descriptor. */
109
enum InterpretDFDResult {
110
i_LITTLE_ENDIAN_FORMAT_BIT = 0, /*!< Confirmed little-endian (default for 8bpc). */
111
i_BIG_ENDIAN_FORMAT_BIT = 1u << 0u, /*!< Confirmed big-endian. */
112
i_PACKED_FORMAT_BIT = 1u << 1u, /*!< Packed format. */
113
i_SRGB_FORMAT_BIT = 1u << 2u, /*!< sRGB transfer function. */
114
i_NORMALIZED_FORMAT_BIT = 1u << 3u, /*!< Normalized (UNORM or SNORM). */
115
i_SIGNED_FORMAT_BIT = 1u << 4u, /*!< Format is signed. */
116
i_FIXED_FORMAT_BIT = 1u << 5u, /*!< Format is a fixed-point representation. */
117
i_FLOAT_FORMAT_BIT = 1u << 6u, /*!< Format is floating point. */
118
i_COMPRESSED_FORMAT_BIT = 1u << 7u, /*!< Format is block compressed (422). */
119
i_YUVSDA_FORMAT_BIT = 1u << 8u, /*!< Color model is YUVSDA. */
120
i_UNSUPPORTED_ERROR_BIT = 1u << 9u, /*!< Format not successfully interpreted. */
121
/** "NONTRIVIAL_ENDIANNESS" means not big-endian, not little-endian
122
* (a channel has bits that are not consecutive in either order). **/
123
i_UNSUPPORTED_NONTRIVIAL_ENDIANNESS = i_UNSUPPORTED_ERROR_BIT,
124
/** "MULTIPLE_SAMPLE_LOCATIONS" is an error because only single-sample
125
* texel blocks (with coordinates 0,0,0,0 for all samples) are supported. **/
126
i_UNSUPPORTED_MULTIPLE_SAMPLE_LOCATIONS = i_UNSUPPORTED_ERROR_BIT + 1,
127
/** "MULTIPLE_PLANES" is an error because only contiguous data is supported. */
128
i_UNSUPPORTED_MULTIPLE_PLANES = i_UNSUPPORTED_ERROR_BIT + 2,
129
/** Only channels R, G, B and A are supported. */
130
i_UNSUPPORTED_CHANNEL_TYPES = i_UNSUPPORTED_ERROR_BIT + 3,
131
/** Only channels with the same flags are supported
132
* (e.g. we don't support float red with integer green). */
133
i_UNSUPPORTED_MIXED_CHANNELS = i_UNSUPPORTED_ERROR_BIT + 4,
134
/** Only 2x1 block is supported for YUVSDA model. */
135
i_UNSUPPORTED_BLOCK_DIMENSIONS = i_UNSUPPORTED_ERROR_BIT + 5,
136
};
137
138
/** @brief Interpretation of a channel from the data format descriptor. */
139
typedef struct _InterpretedDFDChannel {
140
uint32_t offset; /*!< Offset in bits for packed, bytes for unpacked. */
141
uint32_t size; /*!< Size in bits for packed, bytes for unpacked. */
142
} InterpretedDFDChannel;
143
144
/* Interpret a Data Format Descriptor. */
145
enum InterpretDFDResult interpretDFD(const uint32_t *DFD,
146
InterpretedDFDChannel *R,
147
InterpretedDFDChannel *G,
148
InterpretedDFDChannel *B,
149
InterpretedDFDChannel *A,
150
uint32_t *wordBytes);
151
152
/* Returns the string representation.
153
* If there is no direct match or the value is invalid returns NULL */
154
const char* dfdToStringVendorID(khr_df_vendorid_e value);
155
156
/* Returns the string representation.
157
* If there is no direct match or the value is invalid returns NULL */
158
const char* dfdToStringDescriptorType(khr_df_khr_descriptortype_e value);
159
160
/* Returns the string representation.
161
* If there is no direct match or the value is invalid returns NULL */
162
const char* dfdToStringVersionNumber(khr_df_versionnumber_e value);
163
164
/* Returns the string representation of a bit in a khr_df_flags_e.
165
* If there is no direct match or the value is invalid returns NULL */
166
const char* dfdToStringFlagsBit(uint32_t bit_index, bool bit_value);
167
168
/* Returns the string representation.
169
* If there is no direct match or the value is invalid returns NULL */
170
const char* dfdToStringTransferFunction(khr_df_transfer_e value);
171
172
/* Returns the string representation.
173
* If there is no direct match or the value is invalid returns NULL */
174
const char* dfdToStringColorPrimaries(khr_df_primaries_e value);
175
176
/* Returns the string representation.
177
* If there is no direct match or the value is invalid returns NULL */
178
const char* dfdToStringColorModel(khr_df_model_e value);
179
180
/* Returns the string representation of a bit in a khr_df_sample_datatype_qualifiers_e.
181
* If there is no direct match or the value is invalid returns NULL */
182
const char* dfdToStringSampleDatatypeQualifiersBit(uint32_t bit_index, bool bit_value);
183
184
/* Returns the string representation.
185
* If there is no direct match or the value is invalid returns NULL */
186
const char* dfdToStringChannelId(khr_df_model_e model, khr_df_model_channels_e value);
187
188
/* Print a human-readable interpretation of a data format descriptor. */
189
void printDFD(uint32_t *DFD, uint32_t dataSize);
190
191
/* Print a JSON interpretation of a data format descriptor. */
192
void printDFDJSON(uint32_t *DFD, uint32_t dataSize, uint32_t base_indent, uint32_t indent_width, bool minified);
193
194
/* Get the number of components & component size from a DFD for an
195
* unpacked format.
196
*/
197
void getDFDComponentInfoUnpacked(const uint32_t* DFD, uint32_t* numComponents,
198
uint32_t* componentByteLength);
199
200
/* Return the number of components described by a DFD. */
201
uint32_t getDFDNumComponents(const uint32_t* DFD);
202
203
/* Reconstruct and update the bytesPlane[0-4] fields of an unsized DFD to what
204
* they were before supercompression.
205
*/
206
void reconstructDFDBytesPlanesFromSamples(uint32_t* DFD);
207
/* Deprecated. For backward compatibility. */
208
uint32_t reconstructDFDBytesPlane0FromSamples(const uint32_t* DFD);
209
/* Deprecated. For backward compatibility. */
210
void recreateBytesPlane0FromSampleInfo(const uint32_t* DFD,
211
uint32_t* bytesPlane0);
212
213
/** @brief Colourspace primaries information.
214
*
215
* Structure to store the 1931 CIE x,y chromaticities of the red, green, and blue
216
* display primaries and the reference white point of a colourspace.
217
*/
218
typedef struct _Primaries {
219
float Rx; /*!< Red x. */
220
float Ry; /*!< Red y. */
221
float Gx; /*!< Green x. */
222
float Gy; /*!< Green y. */
223
float Bx; /*!< Blue x. */
224
float By; /*!< Blue y. */
225
float Wx; /*!< White x. */
226
float Wy; /*!< White y. */
227
} Primaries;
228
229
khr_df_primaries_e findMapping(const Primaries *p, float latitude);
230
bool getPrimaries(khr_df_primaries_e primaries, Primaries *p);
231
232
#ifdef __cplusplus
233
}
234
#endif
235
236
#endif /* _DFD_H_ */
237
238