hjlld
June 25, 2019, 3:11am
1
src
should be Uint8Array
* From https://github.com/BinomialLLC/basis_universal/blob/master/webgl/texture/dxt-to-rgb565.js
* An unoptimized version of dxtToRgb565. Also, the floating
* point math used to compute the colors actually results in
* slightly different colors compared to hardware DXT decoders.
* @param src dxt src pixels
* @param srcByteOffset offset for the start of src
* @param width aligned width of the image
* @param height aligned height of the image
* @return the converted pixels
*/
function ConvertDxtToRgb565(src: Uint16Array, srcByteOffset: number, width: number, height: number): Uint16Array {
var c = new Uint16Array(4);
var dst = new Uint16Array(width * height);
var blockWidth = width / 4;
var blockHeight = height / 4;
for (var blockY = 0; blockY < blockHeight; blockY++) {
for (var blockX = 0; blockX < blockWidth; blockX++) {
var i = srcByteOffset + 8 * (blockY * blockWidth + blockX);
c[0] = src[i] | (src[i + 1] << 8);
c[1] = src[i + 2] | (src[i + 3] << 8);
dxtToRgb565 return a Uint16Array
, here should return a new Uint16Array
variable
function TranscodeLevel(loadedFile: any, imageIndex: number, levelIndex: number, format: number, convertToRgb565: boolean) {
var dstSize = loadedFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, format);
var dst = new Uint8Array(dstSize);
if (!loadedFile.transcodeImage(dst, imageIndex, levelIndex, format, 1, 0)) {
return null;
}
// If no supported format is found, load as dxt and convert to rgb565
if (convertToRgb565) {
var alignedWidth = (loadedFile.getImageWidth(imageIndex, levelIndex) + 3) & ~3;
var alignedHeight = (loadedFile.getImageHeight(imageIndex, levelIndex) + 3) & ~3;
dst = ConvertDxtToRgb565(dst, 0, alignedWidth, alignedHeight);
}
return dst;
}
/**
* From https://github.com/BinomialLLC/basis_universal/blob/master/webgl/texture/dxt-to-rgb565.js
* An unoptimized version of dxtToRgb565. Also, the floating
* point math used to compute the colors actually results in
* slightly different colors compared to hardware DXT decoders.
* @param src dxt src pixels
BTW, this dtx to rgb565 function has an optimized version , why not use it?
Hey @hjlld
Sure, I can change that.
How did you find this issue as it seems like this typing change shouldn’t have any effect on the code. When I swap in the optimized version the result is corrupted, I think this has to do with the FIXME comment in their src.
1 Like
hjlld
June 26, 2019, 11:53am
4
My project is deeply combinated with BJS, so when i add basis support vs code remind me a type check error.
2 Likes