| 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 Utilities for printing data format descriptors. |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * Author: Andrew Garrard |
| 16 | */ |
| 17 | |
| 18 | #include <stdio.h> |
| 19 | #include <KHR/khr_df.h> |
| 20 | #include "dfd.h" |
| 21 | |
| 22 | /** |
| 23 | * @~English |
| 24 | * @brief Print a human-readable interpretation of a data format descriptor. |
| 25 | * |
| 26 | * @param DFD Pointer to a data format descriptor. |
| 27 | **/ |
| 28 | void printDFD(uint32_t *DFD) |
| 29 | { |
| 30 | uint32_t *BDB = DFD+1; |
| 31 | int samples = (KHR_DFDVAL(BDB, DESCRIPTORBLOCKSIZE) - 4 * KHR_DF_WORD_SAMPLESTART) / (4 * KHR_DF_WORD_SAMPLEWORDS); |
| 32 | int sample; |
| 33 | int model = KHR_DFDVAL(BDB, MODEL); |
| 34 | printf("DFD total bytes: %d\n" , DFD[0]); |
| 35 | printf("BDB descriptor type 0x%04x vendor id = 0x%05x\n" , |
| 36 | KHR_DFDVAL(BDB, DESCRIPTORTYPE), |
| 37 | KHR_DFDVAL(BDB, VENDORID)); |
| 38 | printf("Descriptor block size %d (%d samples) versionNumber = 0x%04x\n" , |
| 39 | KHR_DFDVAL(BDB, DESCRIPTORBLOCKSIZE), |
| 40 | samples, |
| 41 | KHR_DFDVAL(BDB, VERSIONNUMBER)); |
| 42 | printf("Flags 0x%02x Xfer %02d Primaries %02d Model %03d\n" , |
| 43 | KHR_DFDVAL(BDB, FLAGS), |
| 44 | KHR_DFDVAL(BDB, TRANSFER), |
| 45 | KHR_DFDVAL(BDB, PRIMARIES), |
| 46 | model); |
| 47 | printf("Dimensions: %d,%d,%d,%d\n" , |
| 48 | KHR_DFDVAL(BDB, TEXELBLOCKDIMENSION0) + 1, |
| 49 | KHR_DFDVAL(BDB, TEXELBLOCKDIMENSION1) + 1, |
| 50 | KHR_DFDVAL(BDB, TEXELBLOCKDIMENSION2) + 1, |
| 51 | KHR_DFDVAL(BDB, TEXELBLOCKDIMENSION3) + 1); |
| 52 | printf("Plane bytes: %d,%d,%d,%d,%d,%d,%d,%d\n" , |
| 53 | KHR_DFDVAL(BDB, BYTESPLANE0), |
| 54 | KHR_DFDVAL(BDB, BYTESPLANE1), |
| 55 | KHR_DFDVAL(BDB, BYTESPLANE2), |
| 56 | KHR_DFDVAL(BDB, BYTESPLANE3), |
| 57 | KHR_DFDVAL(BDB, BYTESPLANE4), |
| 58 | KHR_DFDVAL(BDB, BYTESPLANE5), |
| 59 | KHR_DFDVAL(BDB, BYTESPLANE6), |
| 60 | KHR_DFDVAL(BDB, BYTESPLANE7)); |
| 61 | for (sample = 0; sample < samples; ++sample) { |
| 62 | int channelId = KHR_DFDSVAL(BDB, sample, CHANNELID); |
| 63 | printf(" Sample %d\n" , sample); |
| 64 | printf("Qualifiers %x" , KHR_DFDSVAL(BDB, sample, QUALIFIERS) >> 4); |
| 65 | printf(" Channel 0x%x" , channelId); |
| 66 | if (model == KHR_DF_MODEL_UASTC) { |
| 67 | printf(" (%s)" , |
| 68 | channelId == KHR_DF_CHANNEL_UASTC_RRRG ? "RRRG" |
| 69 | : channelId == KHR_DF_CHANNEL_UASTC_RGBA ? "RGBA" |
| 70 | : channelId == KHR_DF_CHANNEL_UASTC_RRR ? "RRR" |
| 71 | : channelId == KHR_DF_CHANNEL_UASTC_RGB ? "RGB" |
| 72 | : channelId == KHR_DF_CHANNEL_UASTC_RG ? "RG" |
| 73 | : "unknown" ); |
| 74 | } else if (model == KHR_DF_MODEL_ETC1S) { |
| 75 | printf(" (%s)" , |
| 76 | channelId == KHR_DF_CHANNEL_ETC1S_AAA ? "AAA" |
| 77 | : channelId == KHR_DF_CHANNEL_ETC1S_GGG ? "GGG" |
| 78 | : channelId == KHR_DF_CHANNEL_ETC1S_RRR ? "RRR" |
| 79 | : channelId == KHR_DF_CHANNEL_ETC1S_RGB ? "RGB" |
| 80 | : "unknown" ); |
| 81 | } else { |
| 82 | printf(" (%c)" , |
| 83 | "RGB3456789abcdeA" [channelId]); |
| 84 | } |
| 85 | printf(" Length %d bits Offset %d\n" , |
| 86 | KHR_DFDSVAL(BDB, sample, BITLENGTH) + 1, |
| 87 | KHR_DFDSVAL(BDB, sample, BITOFFSET)); |
| 88 | printf("Position: %d,%d,%d,%d\n" , |
| 89 | KHR_DFDSVAL(BDB, sample, SAMPLEPOSITION0), |
| 90 | KHR_DFDSVAL(BDB, sample, SAMPLEPOSITION1), |
| 91 | KHR_DFDSVAL(BDB, sample, SAMPLEPOSITION2), |
| 92 | KHR_DFDSVAL(BDB, sample, SAMPLEPOSITION3)); |
| 93 | printf("Lower 0x%08x\nUpper 0x%08x\n" , |
| 94 | KHR_DFDSVAL(BDB, sample, SAMPLELOWER), |
| 95 | KHR_DFDSVAL(BDB, sample, SAMPLEUPPER)); |
| 96 | } |
| 97 | } |
| 98 | |