isBasisUniversalKtx2 function

bool isBasisUniversalKtx2(
  1. Uint8List bytes
)

True when bytes is a KTX2 file whose vkFormat is undefined — a Basis Universal file, whose pixels are a transcode rather than a copy.

Asked before Ktx2Texture.parse by a caller deciding where to run it: a plain file's parse is a handful of reads and belongs on the calling isolate, a transcode is a pass over every block and does not.

Implementation

bool isBasisUniversalKtx2(Uint8List bytes) {
  if (!isKtx2File(bytes) ||
      bytes.lengthInBytes < kKtx2HeaderOffset + Ktx2HeaderField.vkFormat + 4) {
    return false;
  }
  return ByteData.view(
        bytes.buffer,
        bytes.offsetInBytes,
        bytes.lengthInBytes,
      ).getUint32(
        kKtx2HeaderOffset + Ktx2HeaderField.vkFormat,
        Endian.little,
      ) ==
      VkFormat.undefined;
}