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

Method compareImagesRaw

tools/ktx/command_compare.cpp:2290–2337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2288}
2289
2290void CommandCompare::compareImagesRaw(PrintDiff& diff, InputStreams& streams) {
2291 diff.setContext("Image Data\n\n");
2292
2293 const uint32_t numLevels[] = {
2294 std::max(1u, headers[0].levelCount),
2295 std::max(1u, headers[1].levelCount)
2296 };
2297 const uint32_t maxNumLevels = std::max(numLevels[0], numLevels[1]);
2298
2299 for (uint32_t level = 0; level < maxNumLevels; ++level) {
2300 const auto levelIndexEntryOffset = sizeof(KTX_header2) + level * sizeof(ktxLevelIndexEntry);
2301 std::optional<ktxLevelIndexEntry> levelIndexEntry[2];
2302 for (std::size_t i = 0; i < streams.size(); ++i)
2303 if (level < numLevels[i]) {
2304 ktxLevelIndexEntry entry;
2305 read(streams[i], levelIndexEntryOffset, &entry, sizeof(entry), "the level index");
2306 levelIndexEntry[i] = entry;
2307 }
2308
2309 bool mismatch = false;
2310
2311 // Missing levels are always considered a mismatch
2312 if (!levelIndexEntry[0].has_value() || !levelIndexEntry[1].has_value())
2313 mismatch = true;
2314
2315 // Mismatching level data sizes are always considered a mismatch
2316 if (!mismatch && levelIndexEntry[0]->byteLength != levelIndexEntry[1]->byteLength)
2317 mismatch = true;
2318
2319 if (!mismatch) {
2320 // If so far so good then load the level data and compare them
2321 std::unique_ptr<uint8_t[]> buffers[] = {
2322 std::make_unique<uint8_t[]>(levelIndexEntry[0]->byteLength),
2323 std::make_unique<uint8_t[]>(levelIndexEntry[1]->byteLength)
2324 };
2325
2326 for (std::size_t i = 0; i < streams.size(); ++i)
2327 read(streams[i], levelIndexEntry[i]->byteOffset, buffers[i].get(),
2328 levelIndexEntry[i]->byteLength, fmt::format("level {} data", level));
2329
2330 if (std::memcmp(buffers[0].get(), buffers[1].get(), levelIndexEntry[0]->byteLength) != 0)
2331 mismatch = true;
2332 }
2333
2334 if (mismatch)
2335 diff << DiffMismatch(fmt::format("Mismatch in level {} data", level), fmt::format("m={}", level));
2336 }
2337}
2338
2339void CommandCompare::compareImagesPerPixel(PrintDiff& diff, InputStreams& streams) {
2340 diff.setContext("Image Data\n\n");

Callers

nothing calls this directly

Calls 7

DiffMismatchClass · 0.85
setContextMethod · 0.80
maxFunction · 0.50
readFunction · 0.50
formatFunction · 0.50
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected