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

Method validateHeader

tools/ktx/validate.cpp:395–543  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

393}
394
395void ValidationContext::validateHeader() {
396 static constexpr uint8_t ktx2_identifier_reference[12] = KTX2_IDENTIFIER_REF;
397
398 read(0, &header, sizeof(KTX_header2), "the header");
399 const auto vkFormat = VkFormat(header.vkFormat);
400 const auto supercompressionScheme = ktxSupercmpScheme(header.supercompressionScheme);
401
402 // Validate file identifier
403 if (std::memcmp(&header.identifier, ktx2_identifier_reference, 12) != 0)
404 fatal(FileError::NotKTX2);
405
406 // Validate vkFormat
407 if (isProhibitedFormat(vkFormat)) {
408 error(HeaderData::ProhibitedFormat, toString(vkFormat));
409
410 } else if (!isFormatValid(vkFormat)) {
411 if (vkFormat <= VK_FORMAT_MAX_STANDARD_ENUM)
412 error(HeaderData::InvalidFormat, toString(vkFormat));
413 if (VK_FORMAT_MAX_STANDARD_ENUM < vkFormat && vkFormat < 1000001000)
414 error(HeaderData::InvalidFormat, toString(vkFormat));
415 if (1000001000 <= vkFormat && !isFormatKnown(vkFormat))
416 warning(HeaderData::UnknownFormat, toString(vkFormat));
417 }
418
419 if (header.supercompressionScheme == KTX_SS_BASIS_LZ) {
420 if (header.vkFormat != VK_FORMAT_UNDEFINED)
421 error(HeaderData::VkFormatAndBasis, toString(vkFormat));
422 }
423
424 // Validate typeSize
425 if (header.vkFormat == VK_FORMAT_UNDEFINED) {
426 if (header.typeSize != 1)
427 error(HeaderData::TypeSizeNotOne, header.typeSize, toString(vkFormat));
428
429 } else if (isFormatBlockCompressed(vkFormat)) {
430 if (header.typeSize != 1)
431 error(HeaderData::TypeSizeNotOne, header.typeSize, toString(vkFormat));
432 }
433 // Additional checks are performed on typeSize after the DFD is parsed
434
435 // Validate image dimensions
436 if (header.pixelWidth == 0)
437 error(HeaderData::WidthZero);
438
439 if (isFormatBlockCompressed(vkFormat))
440 if (header.pixelHeight == 0)
441 error(HeaderData::BlockCompressedNoHeight, toString(vkFormat));
442 if (isSupercompressionBlockCompressed(supercompressionScheme))
443 if (header.pixelHeight == 0)
444 error(HeaderData::BlockCompressedNoHeight, toString(supercompressionScheme));
445 // Additional block-compressed formats (like UASTC) are detected after the DFD is parsed to validate pixelHeight
446
447 if (header.faceCount == 6)
448 if (header.pixelWidth != header.pixelHeight)
449 error(HeaderData::CubeHeightWidthMismatch, header.pixelWidth, header.pixelHeight);
450
451 if (header.pixelDepth != 0 && header.pixelHeight == 0)
452 error(HeaderData::DepthNoHeight, header.pixelDepth);

Callers

nothing calls this directly

Calls 15

fatalClass · 0.85
isProhibitedFormatFunction · 0.85
errorFunction · 0.85
isFormatValidFunction · 0.85
isFormatKnownFunction · 0.85
warningFunction · 0.85
isFormatBlockCompressedFunction · 0.85
isFormatDepthFunction · 0.85
isFormatStencilFunction · 0.85
toStringFunction · 0.70

Tested by

no test coverage detected