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

Function printDFD

external/dfdutils/printdfd.c:722–847  ·  view source on GitHub ↗

* @~English * @brief Print a human-readable interpretation of a data format descriptor. * * @param DFD Pointer to a data format descriptor. * @param dataSize The maximum size that can be considered as part of the DFD. **/

Source from the content-addressed store, hash-verified

720 * @param dataSize The maximum size that can be considered as part of the DFD.
721 **/
722void printDFD(uint32_t *DFD, uint32_t dataSize)
723{
724#define PRINT_ENUM(VALUE, TO_STRING_FN) { \
725 int value = VALUE; \
726 const char* str = TO_STRING_FN(value); \
727 if (str) \
728 printf("%s", str); \
729 else \
730 printf("%u", value); \
731 }
732
733 const uint32_t sizeof_dfdTotalSize = sizeof(uint32_t);
734 const uint32_t sizeof_DFDBHeader = sizeof(uint32_t) * 2;
735 const uint32_t sizeof_BDFD = sizeof(uint32_t) * KHR_DF_WORD_SAMPLESTART;
736 const uint32_t sizeof_BDFDSample = sizeof(uint32_t) * KHR_DF_WORD_SAMPLEWORDS;
737
738 uint32_t dfdTotalSize = dataSize >= sizeof_dfdTotalSize ? DFD[0] : 0;
739 uint32_t remainingSize = dfdTotalSize < dataSize ? dfdTotalSize : dataSize;
740 if (remainingSize < sizeof_dfdTotalSize)
741 return; // Invalid DFD: dfdTotalSize must be present
742
743 uint32_t* block = DFD + 1;
744 remainingSize -= sizeof_dfdTotalSize;
745
746 printf("DFD total bytes: %u\n", dfdTotalSize);
747
748 for (int i = 0; i < MAX_NUM_DFD_BLOCKS; ++i) { // At most only iterate MAX_NUM_DFD_BLOCKS block
749 if (remainingSize < sizeof_DFDBHeader)
750 break; // Invalid DFD: Missing or partial block header
751
752 const khr_df_vendorid_e vendorID = KHR_DFDVAL(block, VENDORID);
753 const khr_df_khr_descriptortype_e descriptorType = KHR_DFDVAL(block, DESCRIPTORTYPE);
754 const khr_df_versionnumber_e versionNumber = KHR_DFDVAL(block, VERSIONNUMBER);
755 const uint32_t blockSize = KHR_DFDVAL(block, DESCRIPTORBLOCKSIZE);
756
757 printf("Vendor ID: ");
758 PRINT_ENUM(vendorID, dfdToStringVendorID);
759 printf("\nDescriptor type: ");
760 PRINT_ENUM(descriptorType, dfdToStringDescriptorType);
761 printf("\nVersion: ");
762 PRINT_ENUM(versionNumber, dfdToStringVersionNumber);
763 printf("\nDescriptor block size: %u", blockSize);
764 printf("\n");
765
766 if (vendorID == KHR_DF_VENDORID_KHRONOS && descriptorType == KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT) {
767 if (remainingSize < sizeof_BDFD)
768 break; // Invalid DFD: Missing or partial basic DFD block
769
770 const int model = KHR_DFDVAL(block, MODEL);
771
772 khr_df_flags_e flags = KHR_DFDVAL(block, FLAGS);
773 printf("Flags: 0x%X (", flags);
774 printFlagBits(flags, dfdToStringFlagsBit);
775 printf(")\nTransfer: ");
776 PRINT_ENUM(KHR_DFDVAL(block, TRANSFER), dfdToStringTransferFunction);
777 printf("\nPrimaries: ");
778 PRINT_ENUM(KHR_DFDVAL(block, PRIMARIES), dfdToStringColorPrimaries);
779 printf("\nModel: ");

Callers 3

printKTX2Info2Function · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 3

printfFunction · 0.85
printFlagBitsFunction · 0.85
dfdToStringChannelIdFunction · 0.85

Tested by 2

mainFunction · 0.68
mainFunction · 0.68