UNPKG

cione-comp-lib

Version:

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

2 lines (1 loc) 1.11 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e=require("../Texture.js"),r=require("../Texture2D.js");function a(e){return e.charCodeAt(0)+(e.charCodeAt(1)<<8)+(e.charCodeAt(2)<<16)+(e.charCodeAt(3)<<24)}var t=a("DXT1"),i=a("DXT3"),u=a("DXT5"),l={parse:function(a,l){var n=new Int32Array(a,0,31);if(542327876!==n[0])return null;if(4&!n(20))return null;var s,o,f=n(21),h=n[4],d=n[3],T=512&n[28],_=131072&n[2];switch(f){case t:s=8,o=e.default.COMPRESSED_RGB_S3TC_DXT1_EXT;break;case i:s=16,o=e.default.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case u:s=16,o=e.default.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;default:return null}var m=n[1]+4,p=T?6:1,c=1;_&&(c=Math.max(1,n[7]));for(var v=[],S=0;S<p;S++){var x=h,C=d;v[S]=new r.default({width:x,height:C,format:o});for(var D=[],E=0;E<c;E++){var X=Math.max(4,x)/4*Math.max(4,C)/4*s,A=new Uint8Array(a,m,X);m+=X,x*=.5,C*=.5,D[E]=A}v[S].pixels=D[0],_&&(v[S].mipmaps=D)}if(!l)return v[0];l.width=v[0].width,l.height=v[0].height,l.format=v[0].format,l.pixels=v[0].pixels,l.mipmaps=v[0].mipmaps}};exports.default=l;