function parseKTX(url, arrayBuffer, loadKeyValueData) {
    if (loadKeyValueData === void 0) { loadKeyValueData = false; }
    var dataView = new DataView(arrayBuffer);
    if (!validate(url, dataView)) {
        return null;
    }
    var littleEndian = dataView.getUint32(KTX_FIELDS.ENDIANNESS, true) === ENDIANNESS;
    var glType = dataView.getUint32(KTX_FIELDS.GL_TYPE, littleEndian);
    // const glTypeSize = dataView.getUint32(KTX_FIELDS.GL_TYPE_SIZE, littleEndian);
    var glFormat = dataView.getUint32(KTX_FIELDS.GL_FORMAT, littleEndian);
    var glInternalFormat = dataView.getUint32(KTX_FIELDS.GL_INTERNAL_FORMAT, littleEndian);
    var pixelWidth = dataView.getUint32(KTX_FIELDS.PIXEL_WIDTH, littleEndian);
    var pixelHeight = dataView.getUint32(KTX_FIELDS.PIXEL_HEIGHT, littleEndian) || 1; // "pixelHeight = 0" -> "1"
    var pixelDepth = dataView.getUint32(KTX_FIELDS.PIXEL_DEPTH, littleEndian) || 1; // ^^
    var numberOfArrayElements = dataView.getUint32(KTX_FIELDS.NUMBER_OF_ARRAY_ELEMENTS, littleEndian) || 1; // ^^
    var numberOfFaces = dataView.getUint32(KTX_FIELDS.NUMBER_OF_FACES, littleEndian);
    var numberOfMipmapLevels = dataView.getUint32(KTX_FIELDS.NUMBER_OF_MIPMAP_LEVELS, littleEndian);
    var bytesOfKeyValueData = dataView.getUint32(KTX_FIELDS.BYTES_OF_KEY_VALUE_DATA, littleEndian);
    // Whether the platform architecture is little endian. If littleEndian !== platformLittleEndian, then the
    // file contents must be endian-converted!
    // TODO: Endianness conversion
    // const platformLittleEndian = new Uint8Array((new Uint32Array([ENDIANNESS])).buffer)[0] === 0x01;
    if (pixelHeight === 0 || pixelDepth !== 1) {
        throw new Error('Only 2D textures are supported');
    }
    if (numberOfFaces !== 1) {
        throw new Error('CubeTextures are not supported by KTXLoader yet!');
    }
    if (numberOfArrayElements !== 1) {
        // TODO: Support splitting array-textures into multiple BaseTextures
        throw new Error('WebGL does not support array textures');
    }
    // TODO: 8x4 blocks for 2bpp pvrtc
    var blockWidth = 4;
    var blockHeight = 4;
    var alignedWidth = (pixelWidth + 3) & ~3;
    var alignedHeight = (pixelHeight + 3) & ~3;
    var imageBuffers = new Array(numberOfArrayElements);
    var imagePixels = pixelWidth * pixelHeight;
    if (glType === 0) {
        // Align to 16 pixels (4x4 blocks)
        imagePixels = alignedWidth * alignedHeight;
    }
    var imagePixelByteSize;
    if (glType !== 0) {
        // Uncompressed texture format
        if (TYPES_TO_BYTES_PER_COMPONENT[glType]) {
            imagePixelByteSize = TYPES_TO_BYTES_PER_COMPONENT[glType] * FORMATS_TO_COMPONENTS[glFormat];
        }
        else {
            imagePixelByteSize = TYPES_TO_BYTES_PER_PIXEL[glType];
        }
    }
    else {
        imagePixelByteSize = INTERNAL_FORMAT_TO_BYTES_PER_PIXEL[glInternalFormat];
    }
    if (imagePixelByteSize === undefined) {
        throw new Error('Unable to resolve the pixel format stored in the *.ktx file!');
    }
    var kvData = loadKeyValueData
        ? parseKvData(dataView, bytesOfKeyValueData, littleEndian)
        : null;
    var imageByteSize = imagePixels * imagePixelByteSize;
    var mipByteSize = imageByteSize;
    var mipWidth = pixelWidth;
    var mipHeight = pixelHeight;
    var alignedMipWidth = alignedWidth;
    var alignedMipHeight = alignedHeight;
    var imageOffset = FILE_HEADER_SIZE + bytesOfKeyValueData;
    for (var mipmapLevel = 0; mipmapLevel < numberOfMipmapLevels; mipmapLevel++) {
        var imageSize = dataView.getUint32(imageOffset, littleEndian);
        var elementOffset = imageOffset + 4;
        for (var arrayElement = 0; arrayElement < numberOfArrayElements; arrayElement++) {
            // TODO: Maybe support 3D textures? :-)
            // for (let zSlice = 0; zSlice < pixelDepth; zSlice)
            var mips = imageBuffers[arrayElement];
            if (!mips) {
                mips = imageBuffers[arrayElement] = new Array(numberOfMipmapLevels);
            }
            mips[mipmapLevel] = {
                levelID: mipmapLevel,
                // don't align mipWidth when texture not compressed! (glType not zero)
                levelWidth: numberOfMipmapLevels > 1 || glType !== 0 ? mipWidth : alignedMipWidth,
                levelHeight: numberOfMipmapLevels > 1 || glType !== 0 ? mipHeight : alignedMipHeight,
                levelBuffer: new Uint8Array(arrayBuffer, elementOffset, mipByteSize)
            };
            elementOffset += mipByteSize;
        }
        // HINT: Aligns to 4-byte boundary after jumping imageSize (in lieu of mipPadding)
        imageOffset += imageSize + 4; // (+4 to jump the imageSize field itself)
        imageOffset = imageOffset % 4 !== 0 ? imageOffset + 4 - (imageOffset % 4) : imageOffset;
        // Calculate mipWidth, mipHeight for _next_ iteration
        mipWidth = (mipWidth >> 1) || 1;
        mipHeight = (mipHeight >> 1) || 1;
        alignedMipWidth = (mipWidth + blockWidth - 1) & ~(blockWidth - 1);
        alignedMipHeight = (mipHeight + blockHeight - 1) & ~(blockHeight - 1);
        // Each mipmap level is 4-times smaller?
        mipByteSize = alignedMipWidth * alignedMipHeight * imagePixelByteSize;
    }
    // We use the levelBuffers feature of CompressedTextureResource b/c texture data is image-major, not level-major.
    if (glType !== 0) {
        return {
            uncompressed: imageBuffers.map(function (levelBuffers) {
                var buffer = levelBuffers[0].levelBuffer;
                var convertToInt = false;
                if (glType === _pixi_constants__WEBPACK_IMPORTED_MODULE_4__.TYPES.FLOAT) {
                    buffer = new Float32Array(levelBuffers[0].levelBuffer.buffer, levelBuffers[0].levelBuffer.byteOffset, levelBuffers[0].levelBuffer.byteLength / 4);
                }
                else if (glType === _pixi_constants__WEBPACK_IMPORTED_MODULE_4__.TYPES.UNSIGNED_INT) {
                    convertToInt = true;
                    buffer = new Uint32Array(levelBuffers[0].levelBuffer.buffer, levelBuffers[0].levelBuffer.byteOffset, levelBuffers[0].levelBuffer.byteLength / 4);
                }
                else if (glType === _pixi_constants__WEBPACK_IMPORTED_MODULE_4__.TYPES.INT) {
                    convertToInt = true;
                    buffer = new Int32Array(levelBuffers[0].levelBuffer.buffer, levelBuffers[0].levelBuffer.byteOffset, levelBuffers[0].levelBuffer.byteLength / 4);
                }
                return {
                    resource: new _pixi_core__WEBPACK_IMPORTED_MODULE_0__.BufferResource(buffer, {
                        width: levelBuffers[0].levelWidth,
                        height: levelBuffers[0].levelHeight,
                    }),
                    type: glType,
                    format: convertToInt ? convertFormatToInteger(glFormat) : glFormat,
                };
            }),
            kvData: kvData
        };
    }
    return {
        compressed: imageBuffers.map(function (levelBuffers) { return new CompressedTextureResource(null, {
            format: glInternalFormat,
            width: pixelWidth,
            height: pixelHeight,
            levels: numberOfMipmapLevels,
            levelBuffers: levelBuffers,
        }); }),
        kvData: kvData
    };
}
Number of bytes per pixel in bit-field types in {@link PIXI.TYPES}
@ignore