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

Method compareDFD

tools/ktx/command_compare.cpp:1531–1676  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1529}
1530
1531void CommandCompare::compareDFD(PrintDiff& diff, InputStreams& streams) {
1532 if (options.ignoreDFD == IgnoreDFD::all) return;
1533
1534 diff.setContext("Data Format Descriptor\n\n");
1535
1536 std::unique_ptr<uint8_t[]> buffers[] = {
1537 std::make_unique<uint8_t[]>(headers[0].dataFormatDescriptor.byteLength),
1538 std::make_unique<uint8_t[]>(headers[1].dataFormatDescriptor.byteLength)
1539 };
1540
1541 for (std::size_t i = 0; i < streams.size(); ++i)
1542 read(streams[i], headers[i].dataFormatDescriptor.byteOffset, buffers[i].get(),
1543 headers[i].dataFormatDescriptor.byteLength, "the DFD blocks");
1544
1545 const uint8_t* ptrDFD[] = { buffers[0].get(), buffers[1].get() };
1546 const uint8_t* ptrDFDEnd[] = {
1547 ptrDFD[0] + headers[0].dataFormatDescriptor.byteLength,
1548 ptrDFD[1] + headers[1].dataFormatDescriptor.byteLength,
1549 };
1550 const uint8_t* ptrDFDIt[] = { ptrDFD[0], ptrDFD[1] };
1551
1552 uint32_t dfdTotalSize[2];
1553 for (std::size_t i = 0; i < streams.size(); ++i) {
1554 std::memcpy(&dfdTotalSize[i], ptrDFDIt[i], sizeof(uint32_t));
1555 ptrDFDIt[i] += sizeof(uint32_t);
1556 }
1557
1558 if (options.ignoreDFD != IgnoreDFD::all_except_color_space)
1559 if (dfdTotalSize[0] != dfdTotalSize[1])
1560 diff << Diff("DFD total bytes", "/dataFormatDescriptor/totalSize", dfdTotalSize[0], dfdTotalSize[1]);
1561
1562 uint32_t blockIndex = 0;
1563 while ((ptrDFDIt[0] < ptrDFDEnd[0]) || (ptrDFDIt[1] < ptrDFDEnd[1])) {
1564 const std::size_t remainingDFDBytes[] = {
1565 static_cast<std::size_t>(ptrDFDEnd[0] - ptrDFDIt[0]),
1566 static_cast<std::size_t>(ptrDFDEnd[1] - ptrDFDIt[1]),
1567 };
1568
1569 std::optional<DFDHeader> blockHeaders[2] = {};
1570 if (remainingDFDBytes[0] < sizeof(DFDHeader) && remainingDFDBytes[1] < sizeof(DFDHeader))
1571 break;
1572
1573 for (std::size_t i = 0; i < streams.size(); ++i)
1574 if (remainingDFDBytes[i] >= sizeof(DFDHeader)) {
1575 DFDHeader blockHeader;
1576 std::memcpy(&blockHeader, ptrDFDIt[i], sizeof(blockHeader));
1577 blockHeaders[i] = blockHeader;
1578 }
1579
1580 bool dfdKnown[2] = { false, false };
1581 bool dfdBasic[2] = { false, false };
1582 for (std::size_t i = 0; i < streams.size(); ++i) {
1583 if (blockHeaders[i].has_value() &&
1584 blockHeaders[i]->vendorId == KHR_DF_VENDORID_KHRONOS &&
1585 blockHeaders[i]->descriptorType == KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT) {
1586 dfdKnown[i] = dfdBasic[i] = true;
1587 }
1588 }

Callers

nothing calls this directly

Calls 14

DiffClass · 0.85
dfdToStringVendorIDFunction · 0.85
dfdToStringVersionNumberFunction · 0.85
assertFunction · 0.85
DiffRawBytesClass · 0.85
setContextMethod · 0.80
readFunction · 0.50
formatFunction · 0.50
minFunction · 0.50
maxFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected