UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

77 lines (76 loc) 6.01 kB
const t = 0, n = 2, p = 1, x = 2, nt = 0, ct = 9, gt = 15, yt = 16, dt = 22, Ot = 37, Ft = 43, $t = 76, se = 83, pe = 97, xe = 100, de = 103, Ae = 109; class Si { constructor() { this.vkFormat = 0, this.typeSize = 1, this.pixelWidth = 0, this.pixelHeight = 0, this.pixelDepth = 0, this.layerCount = 0, this.faceCount = 1, this.supercompressionScheme = 0, this.levels = [], this.dataFormatDescriptor = [{ vendorId: 0, descriptorType: 0, descriptorBlockSize: 0, versionNumber: 2, colorModel: 0, colorPrimaries: 1, transferFunction: 2, flags: 0, texelBlockDimension: [0, 0, 0, 0], bytesPlane: [0, 0, 0, 0, 0, 0, 0, 0], samples: [] }], this.keyValue = {}, this.globalData = null; } } class Ii { constructor(t2, e, n2, i) { this._dataView = new DataView(t2.buffer, t2.byteOffset + e, n2), this._littleEndian = i, this._offset = 0; } _nextUint8() { const t2 = this._dataView.getUint8(this._offset); return this._offset += 1, t2; } _nextUint16() { const t2 = this._dataView.getUint16(this._offset, this._littleEndian); return this._offset += 2, t2; } _nextUint32() { const t2 = this._dataView.getUint32(this._offset, this._littleEndian); return this._offset += 4, t2; } _nextUint64() { const t2 = this._dataView.getUint32(this._offset, this._littleEndian) + 2 ** 32 * this._dataView.getUint32(this._offset + 4, this._littleEndian); return this._offset += 8, t2; } _nextInt32() { const t2 = this._dataView.getInt32(this._offset, this._littleEndian); return this._offset += 4, t2; } _skip(t2) { return this._offset += t2, this; } _scan(t2, e = 0) { const n2 = this._offset; let i = 0; for (; this._dataView.getUint8(this._offset) !== e && i < t2; ) i++, this._offset++; return i < t2 && this._offset++, new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + n2, i); } } const Ti = [171, 75, 84, 88, 32, 50, 48, 187, 13, 10, 26, 10]; function Ei(t2) { return "undefined" != typeof TextDecoder ? new TextDecoder().decode(t2) : Buffer.from(t2).toString("utf8"); } function Pi(t2) { const e = new Uint8Array(t2.buffer, t2.byteOffset, Ti.length); if (e[0] !== Ti[0] || e[1] !== Ti[1] || e[2] !== Ti[2] || e[3] !== Ti[3] || e[4] !== Ti[4] || e[5] !== Ti[5] || e[6] !== Ti[6] || e[7] !== Ti[7] || e[8] !== Ti[8] || e[9] !== Ti[9] || e[10] !== Ti[10] || e[11] !== Ti[11]) throw new Error("Missing KTX 2.0 identifier."); const n2 = new Si(), i = 17 * Uint32Array.BYTES_PER_ELEMENT, s = new Ii(t2, Ti.length, i, true); n2.vkFormat = s._nextUint32(), n2.typeSize = s._nextUint32(), n2.pixelWidth = s._nextUint32(), n2.pixelHeight = s._nextUint32(), n2.pixelDepth = s._nextUint32(), n2.layerCount = s._nextUint32(), n2.faceCount = s._nextUint32(); const a = s._nextUint32(); n2.supercompressionScheme = s._nextUint32(); const r = s._nextUint32(), o = s._nextUint32(), l = s._nextUint32(), f = s._nextUint32(), U = s._nextUint64(), c = s._nextUint64(), h = new Ii(t2, Ti.length + i, 3 * a * 8, true); for (let e2 = 0; e2 < a; e2++) n2.levels.push({ levelData: new Uint8Array(t2.buffer, t2.byteOffset + h._nextUint64(), h._nextUint64()), uncompressedByteLength: h._nextUint64() }); const _ = new Ii(t2, r, o, true), p2 = { vendorId: _._skip(4)._nextUint16(), descriptorType: _._nextUint16(), versionNumber: _._nextUint16(), descriptorBlockSize: _._nextUint16(), colorModel: _._nextUint8(), colorPrimaries: _._nextUint8(), transferFunction: _._nextUint8(), flags: _._nextUint8(), texelBlockDimension: [_._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8()], bytesPlane: [_._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8()], samples: [] }, g = (p2.descriptorBlockSize / 4 - 6) / 4; for (let t3 = 0; t3 < g; t3++) { const e2 = { bitOffset: _._nextUint16(), bitLength: _._nextUint8(), channelType: _._nextUint8(), samplePosition: [_._nextUint8(), _._nextUint8(), _._nextUint8(), _._nextUint8()], sampleLower: -Infinity, sampleUpper: Infinity }; 64 & e2.channelType ? (e2.sampleLower = _._nextInt32(), e2.sampleUpper = _._nextInt32()) : (e2.sampleLower = _._nextUint32(), e2.sampleUpper = _._nextUint32()), p2.samples[t3] = e2; } n2.dataFormatDescriptor.length = 0, n2.dataFormatDescriptor.push(p2); const y = new Ii(t2, l, f, true); for (; y._offset < f; ) { const t3 = y._nextUint32(), e2 = y._scan(t3), i2 = Ei(e2), s2 = y._scan(t3 - e2.byteLength); n2.keyValue[i2] = i2.match(/^ktx/i) ? Ei(s2) : s2, y._offset % 4 && y._skip(4 - y._offset % 4); } if (c <= 0) return n2; const x2 = new Ii(t2, U, c, true), u = x2._nextUint16(), b = x2._nextUint16(), d = x2._nextUint32(), m = x2._nextUint32(), w = x2._nextUint32(), D = x2._nextUint32(), B = []; for (let t3 = 0; t3 < a; t3++) B.push({ imageFlags: x2._nextUint32(), rgbSliceByteOffset: x2._nextUint32(), rgbSliceByteLength: x2._nextUint32(), alphaSliceByteOffset: x2._nextUint32(), alphaSliceByteLength: x2._nextUint32() }); const L = U + x2._offset, A = L + d, k = A + m, v = k + w, S = new Uint8Array(t2.buffer, t2.byteOffset + L, d), I = new Uint8Array(t2.buffer, t2.byteOffset + A, m), O = new Uint8Array(t2.buffer, t2.byteOffset + k, w), T = new Uint8Array(t2.buffer, t2.byteOffset + v, D); return n2.globalData = { endpointCount: u, selectorCount: b, imageDescs: B, endpointsData: S, selectorsData: I, tablesData: O, extendedData: T }, n2; } export { p as KHR_DF_FLAG_ALPHA_PREMULTIPLIED, x as KHR_DF_TRANSFER_SRGB, t as KHR_SUPERCOMPRESSION_NONE, n as KHR_SUPERCOMPRESSION_ZSTD, Si as KTX2Container, pe as VK_FORMAT_R16G16B16A16_SFLOAT, se as VK_FORMAT_R16G16_SFLOAT, $t as VK_FORMAT_R16_SFLOAT, Ae as VK_FORMAT_R32G32B32A32_SFLOAT, de as VK_FORMAT_R32G32_SFLOAT, xe as VK_FORMAT_R32_SFLOAT, Ft as VK_FORMAT_R8G8B8A8_SRGB, Ot as VK_FORMAT_R8G8B8A8_UNORM, dt as VK_FORMAT_R8G8_SRGB, yt as VK_FORMAT_R8G8_UNORM, gt as VK_FORMAT_R8_SRGB, ct as VK_FORMAT_R8_UNORM, nt as VK_FORMAT_UNDEFINED, Pi as read };