MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / createDFDPackedShifted

Function createDFDPackedShifted

external/dfdutils/createdfd.c:254–369  ·  view source on GitHub ↗

* @~English * @brief Create a Data Format Descriptor for a packed format. * * @param bigEndian Big-endian flag: Set to 1 for big-endian byte ordering and * 0 for little-endian byte ordering. * @param numChannels The number of color channels. * @param bits[] An array of length numChannels. * Each entry is the number of bits composing the channel, in *

Source from the content-addressed store, hash-verified

252 * for freeing the descriptor.
253 **/
254uint32_t *createDFDPackedShifted(int bigEndian, int numChannels,
255 int bits[], int shiftBits[], int channels[],
256 enum VkSuffix suffix)
257{
258 uint32_t *DFD = 0;
259 if (numChannels == 6) {
260 /* Special case E5B9G9R9 */
261 DFD = writeHeader(numChannels, 4, s_UFLOAT, i_COLOR);
262 writeSample(DFD, 0, 0,
263 9, 0,
264 1, 1, s_UNORM);
265 KHR_DFDSETSVAL((DFD+1), 0, SAMPLEUPPER, 8448);
266 writeSample(DFD, 1, 0 | KHR_DF_SAMPLE_DATATYPE_EXPONENT,
267 5, 27,
268 1, 1, s_UNORM);
269 KHR_DFDSETSVAL((DFD+1), 1, SAMPLELOWER, 15);
270 KHR_DFDSETSVAL((DFD+1), 1, SAMPLEUPPER, 31);
271 writeSample(DFD, 2, 1,
272 9, 9,
273 1, 1, s_UNORM);
274 KHR_DFDSETSVAL((DFD+1), 2, SAMPLEUPPER, 8448);
275 writeSample(DFD, 3, 1 | KHR_DF_SAMPLE_DATATYPE_EXPONENT,
276 5, 27,
277 1, 1, s_UNORM);
278 KHR_DFDSETSVAL((DFD+1), 3, SAMPLELOWER, 15);
279 KHR_DFDSETSVAL((DFD+1), 3, SAMPLEUPPER, 31);
280 writeSample(DFD, 4, 2,
281 9, 18,
282 1, 1, s_UNORM);
283 KHR_DFDSETSVAL((DFD+1), 4, SAMPLEUPPER, 8448);
284 writeSample(DFD, 5, 2 | KHR_DF_SAMPLE_DATATYPE_EXPONENT,
285 5, 27,
286 1, 1, s_UNORM);
287 KHR_DFDSETSVAL((DFD+1), 5, SAMPLELOWER, 15);
288 KHR_DFDSETSVAL((DFD+1), 5, SAMPLEUPPER, 31);
289 } else if (bigEndian) {
290 /* No packed format is larger than 32 bits. */
291 /* No packed channel crosses more than two bytes. */
292 int totalBits = 0;
293 int bitChannel[32];
294 int beChannelStart[4];
295 int channelCounter;
296 int bitOffset = 0;
297 int BEMask;
298 int numSamples = numChannels;
299 int sampleCounter;
300 for (channelCounter = 0; channelCounter < numChannels; ++channelCounter) {
301 beChannelStart[channelCounter] = totalBits;
302 totalBits += shiftBits[channelCounter] + bits[channelCounter];
303 }
304 BEMask = (totalBits - 1) & 0x18;
305 for (channelCounter = 0; channelCounter < numChannels; ++channelCounter) {
306 bitOffset += shiftBits[channelCounter];
307 bitChannel[bitOffset ^ BEMask] = channelCounter;
308 if (((bitOffset + bits[channelCounter] - 1) & ~7) != (bitOffset & ~7)) {
309 /* Continuation sample */
310 bitChannel[((bitOffset + bits[channelCounter] - 1) & ~7) ^ BEMask] = channelCounter;
311 numSamples++;

Callers 1

createDFDPackedFunction · 0.85

Calls 2

writeHeaderFunction · 0.85
writeSampleFunction · 0.85

Tested by

no test coverage detected