texture-compressor
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -19,3 +19,3 @@ "use strict"; | ||
const combinedFlags = [...flagMapping, ...toolFlags]; | ||
return new Promise((resolve) => { | ||
return new Promise((resolve, reject) => { | ||
if (args.verbose) { | ||
@@ -38,3 +38,3 @@ console.log(`Using flags: ${combinedFlags}`); | ||
if (code !== 0) { | ||
throw new Error(`Compression tool exited with error code ${code}`); | ||
reject(new Error(`Compression tool exited with error code ${code}`)); | ||
} | ||
@@ -41,0 +41,0 @@ else { |
{ | ||
"name": "texture-compressor", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "CLI tool for texture compression using ASTC, ETC, PVRTC and S3TC in a KTX container.", | ||
"main": "dist/cli/lib/index.js", | ||
"types": "dist/types/lib/index.d.ts", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "start": "tsc -w", |
@@ -10,21 +10,22 @@ /** | ||
THREE.KTXLoader = function() { | ||
this._parser = THREE.KTXLoader.parse; | ||
THREE.KTXLoader = function(manager) { | ||
THREE.CompressedTextureLoader.call(this, manager); | ||
}; | ||
THREE.KTXLoader.prototype = Object.create(THREE.CompressedTextureLoader.prototype); | ||
THREE.KTXLoader.prototype.constructor = THREE.KTXLoader; | ||
THREE.KTXLoader.prototype = Object.assign(Object.create(THREE.CompressedTextureLoader.prototype), { | ||
constructor: THREE.KTXLoader, | ||
THREE.KTXLoader.parse = function(buffer, loadMipmaps) { | ||
var ktx = new KhronosTextureContainer(buffer, 1); | ||
parse: function(buffer, loadMipmaps) { | ||
var ktx = new KhronosTextureContainer(buffer, 1); | ||
return { | ||
mipmaps: ktx.mipmaps(loadMipmaps), | ||
width: ktx.pixelWidth, | ||
height: ktx.pixelHeight, | ||
format: ktx.glInternalFormat, | ||
isCubemap: ktx.numberOfFaces === 6, | ||
mipmapCount: ktx.numberOfMipmapLevels, | ||
}; | ||
}; | ||
return { | ||
mipmaps: ktx.mipmaps(loadMipmaps), | ||
width: ktx.pixelWidth, | ||
height: ktx.pixelHeight, | ||
format: ktx.glInternalFormat, | ||
isCubemap: ktx.numberOfFaces === 6, | ||
mipmapCount: ktx.numberOfMipmapLevels, | ||
}; | ||
}, | ||
}); | ||
@@ -34,5 +35,10 @@ var KhronosTextureContainer = (function() { | ||
* @param {ArrayBuffer} arrayBuffer- contents of the KTX container file | ||
* @param {number} facesExpected- should be either 1 or 6, based whether a cube texture or not | ||
* @param {number} facesExpected- should be either 1 or 6, based whether a cube texture or or | ||
* @param {boolean} threeDExpected- provision for indicating that data should be a 3D texture, not implemented | ||
* @param {boolean} textureArrayExpected- provision for indicating that data should be a texture array, not implemented | ||
*/ | ||
function KhronosTextureContainer(arrayBuffer, facesExpected) { | ||
function KhronosTextureContainer( | ||
arrayBuffer, | ||
facesExpected /*, threeDExpected, textureArrayExpected */ | ||
) { | ||
this.arrayBuffer = arrayBuffer; | ||
@@ -62,20 +68,21 @@ | ||
// load the reset of the header in native 32 bit int | ||
var header = new Int32Array(this.arrayBuffer, 12, 13); | ||
// determine of the remaining header values are recorded in the opposite endianness & require conversion | ||
var oppositeEndianess = header[0] === 0x01020304; | ||
// read all the header elements in order they exist in the file, without modification (sans endainness) | ||
this.glType = oppositeEndianess ? this.switchEndainness(header[1]) : header[1]; // must be 0 for compressed textures | ||
this.glTypeSize = oppositeEndianess ? this.switchEndainness(header[2]) : header[2]; // must be 1 for compressed textures | ||
this.glFormat = oppositeEndianess ? this.switchEndainness(header[3]) : header[3]; // must be 0 for compressed textures | ||
this.glInternalFormat = oppositeEndianess ? this.switchEndainness(header[4]) : header[4]; // the value of arg passed to gl.compressedTexImage2D(,,x,,,,) | ||
this.glBaseInternalFormat = oppositeEndianess ? this.switchEndainness(header[5]) : header[5]; // specify GL_RGB, GL_RGBA, GL_ALPHA, etc (un-compressed only) | ||
this.pixelWidth = oppositeEndianess ? this.switchEndainness(header[6]) : header[6]; // level 0 value of arg passed to gl.compressedTexImage2D(,,,x,,,) | ||
this.pixelHeight = oppositeEndianess ? this.switchEndainness(header[7]) : header[7]; // level 0 value of arg passed to gl.compressedTexImage2D(,,,,x,,) | ||
this.pixelDepth = oppositeEndianess ? this.switchEndainness(header[8]) : header[8]; // level 0 value of arg passed to gl.compressedTexImage3D(,,,,,x,,) | ||
this.numberOfArrayElements = oppositeEndianess ? this.switchEndainness(header[9]) : header[9]; // used for texture arrays | ||
this.numberOfFaces = oppositeEndianess ? this.switchEndainness(header[10]) : header[10]; // used for cubemap textures, should either be 1 or 6 | ||
this.numberOfMipmapLevels = oppositeEndianess ? this.switchEndainness(header[11]) : header[11]; // number of levels; disregard possibility of 0 for compressed textures | ||
this.bytesOfKeyValueData = oppositeEndianess ? this.switchEndainness(header[12]) : header[12]; // the amount of space after the header for meta-data | ||
// load the reset of the header in native 32 bit uint | ||
var dataSize = Uint32Array.BYTES_PER_ELEMENT; | ||
var headerDataView = new DataView(this.arrayBuffer, 12, 13 * dataSize); | ||
var endianness = headerDataView.getUint32(0, true); | ||
var littleEndian = endianness === 0x04030201; | ||
this.glType = headerDataView.getUint32(1 * dataSize, littleEndian); // must be 0 for compressed textures | ||
this.glTypeSize = headerDataView.getUint32(2 * dataSize, littleEndian); // must be 1 for compressed textures | ||
this.glFormat = headerDataView.getUint32(3 * dataSize, littleEndian); // must be 0 for compressed textures | ||
this.glInternalFormat = headerDataView.getUint32(4 * dataSize, littleEndian); // the value of arg passed to gl.compressedTexImage2D(,,x,,,,) | ||
this.glBaseInternalFormat = headerDataView.getUint32(5 * dataSize, littleEndian); // specify GL_RGB, GL_RGBA, GL_ALPHA, etc (un-compressed only) | ||
this.pixelWidth = headerDataView.getUint32(6 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage2D(,,,x,,,) | ||
this.pixelHeight = headerDataView.getUint32(7 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage2D(,,,,x,,) | ||
this.pixelDepth = headerDataView.getUint32(8 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage3D(,,,,,x,,) | ||
this.numberOfArrayElements = headerDataView.getUint32(9 * dataSize, littleEndian); // used for texture arrays | ||
this.numberOfFaces = headerDataView.getUint32(10 * dataSize, littleEndian); // used for cubemap textures, should either be 1 or 6 | ||
this.numberOfMipmapLevels = headerDataView.getUint32(11 * dataSize, littleEndian); // number of levels; disregard possibility of 0 for compressed textures | ||
this.bytesOfKeyValueData = headerDataView.getUint32(12 * dataSize, littleEndian); // the amount of space after the header for meta-data | ||
// Make sure we have a compressed type. Not only reduces work, but probably better to let dev know they are not compressing. | ||
@@ -108,9 +115,2 @@ if (this.glType !== 0) { | ||
// not as fast hardware based, but will probably never need to use | ||
KhronosTextureContainer.prototype.switchEndainness = function(val) { | ||
return ( | ||
((val & 0xff) << 24) | ((val & 0xff00) << 8) | ((val >> 8) & 0xff00) | ((val >> 24) & 0xff) | ||
); | ||
}; | ||
// return mipmaps for THREE.js | ||
@@ -128,3 +128,3 @@ KhronosTextureContainer.prototype.mipmaps = function(loadMipmaps) { | ||
var imageSize = new Int32Array(this.arrayBuffer, dataOffset, 1)[0]; // size per face, since not supporting array cubemaps | ||
dataOffset += 4; //image data starts from next multiple of 4 offset. Each face refers to same imagesize field above. | ||
dataOffset += 4; // size of the image + 4 for the imageSize field | ||
@@ -136,3 +136,3 @@ for (var face = 0; face < this.numberOfFaces; face++) { | ||
dataOffset += imageSize; // add size of the image for the next face/mipmap | ||
dataOffset += imageSize; | ||
dataOffset += 3 - ((imageSize + 3) % 4); // add padding for odd sized image | ||
@@ -139,0 +139,0 @@ } |
@@ -28,3 +28,3 @@ // Native | ||
return new Promise( | ||
(resolve): void => { | ||
(resolve, reject): void => { | ||
if (args.verbose) { | ||
@@ -51,3 +51,3 @@ console.log(`Using flags: ${combinedFlags}`); | ||
if (code !== 0) { | ||
throw new Error(`Compression tool exited with error code ${code}`); | ||
reject(new Error(`Compression tool exited with error code ${code}`)); | ||
} else { | ||
@@ -54,0 +54,0 @@ resolve(); |
{ | ||
"name": "texture-compressor", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "CLI tool for texture compression using ASTC, ETC, PVRTC and S3TC in a KTX container.", | ||
"main": "dist/cli/lib/index.js", | ||
"types": "dist/types/lib/index.d.ts", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "start": "tsc -w", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33495452
77