SourceTermAnalysisSystem_vue/node_modules/lerc/LercDecode.min.js

3 lines
38 KiB
JavaScript
Raw Normal View History

2026-05-15 10:22:44 +08:00
/* Copyright 2015-2018 Esri. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 @preserve */
(function(){var LercDecode=function(){var CntZImage={};CntZImage.defaultNoDataValue=-3.4027999387901484e38;CntZImage.decode=function(input,options){options=options||{};var skipMask=options.encodedMaskData||options.encodedMaskData===null;var parsedData=parse(input,options.inputOffset||0,skipMask);var noDataValue=options.noDataValue!==null?options.noDataValue:CntZImage.defaultNoDataValue;var uncompressedData=uncompressPixelValues(parsedData,options.pixelType||Float32Array,options.encodedMaskData,noDataValue,options.returnMask);var result={width:parsedData.width,height:parsedData.height,pixelData:uncompressedData.resultPixels,minValue:uncompressedData.minValue,maxValue:parsedData.pixels.maxValue,noDataValue:noDataValue};if(uncompressedData.resultMask){result.maskData=uncompressedData.resultMask}if(options.returnEncodedMask&&parsedData.mask){result.encodedMaskData=parsedData.mask.bitset?parsedData.mask.bitset:null}if(options.returnFileInfo){result.fileInfo=formatFileInfo(parsedData);if(options.computeUsedBitDepths){result.fileInfo.bitDepths=computeUsedBitDepths(parsedData)}}return result};var uncompressPixelValues=function(data,TypedArrayClass,maskBitset,noDataValue,storeDecodedMask){var blockIdx=0;var numX=data.pixels.numBlocksX;var numY=data.pixels.numBlocksY;var blockWidth=Math.floor(data.width/numX);var blockHeight=Math.floor(data.height/numY);var scale=2*data.maxZError;var minValue=Number.MAX_VALUE,currentValue;maskBitset=maskBitset||(data.mask?data.mask.bitset:null);var resultPixels,resultMask;resultPixels=new TypedArrayClass(data.width*data.height);if(storeDecodedMask&&maskBitset){resultMask=new Uint8Array(data.width*data.height)}var blockDataBuffer=new Float32Array(blockWidth*blockHeight);var xx,yy;for(var y=0;y<=numY;y++){var thisBlockHeight=y!==numY?blockHeight:data.height%numY;if(thisBlockHeight===0){continue}for(var x=0;x<=numX;x++){var thisBlockWidth=x!==numX?blockWidth:data.width%numX;if(thisBlockWidth===0){continue}var outPtr=y*data.width*blockHeight+x*blockWidth;var outStride=data.width-thisBlockWidth;var block=data.pixels.blocks[blockIdx];var blockData,blockPtr,constValue;if(block.encoding<2){if(block.encoding===0){blockData=block.rawData}else{unstuff(block.stuffedData,block.bitsPerPixel,block.numValidPixels,block.offset,scale,blockDataBuffer,data.pixels.maxValue);blockData=blockDataBuffer}blockPtr=0}else if(block.encoding===2){constValue=0}else{constValue=block.offset}var maskByte;if(maskBitset){for(yy=0;yy<thisBlockHeight;yy++){if(outPtr&7){maskByte=maskBitset[outPtr>>3];maskByte<<=outPtr&7}for(xx=0;xx<thisBlockWidth;xx++){if(!(outPtr&7)){maskByte=maskBitset[outPtr>>3]}if(maskByte&128){if(resultMask){resultMask[outPtr]=1}currentValue=block.encoding<2?blockData[blockPtr++]:constValue;minValue=minValue>currentValue?currentValue:minValue;resultPixels[outPtr++]=currentValue}else{if(resultMask){resultMask[outPtr]=0}resultPixels[outPtr++]=noDataValue}maskByte<<=1}outPtr+=outStride}}else{if(block.encoding<2){for(yy=0;yy<thisBlockHeight;yy++){for(xx=0;xx<thisBlockWidth;xx++){currentValue=blockData[blockPtr++];minValue=minValue>currentValue?currentValue:minValue;resultPixels[outPtr++]=currentValue}outPtr+=outStride}}else{minValue=minValue>constValue?constValue:minValue;for(yy=0;yy<thisBlockHeight;yy++){for(xx=0;xx<thisBlockWidth;xx++){resultPixels[outPtr++]=constValue}outPtr+=outStride}}}if(block.encoding===1&&blockPtr!==block.numValidPixels){throw"Block and Mask do not match"}blockIdx++}}return{resultPixels:resultPixels,resultMask:resultMask,minValue:minValue}};var formatFileInfo=function(data){return{fileIdentifierString:data.fileIdentifierString,fileVersion:data.fileVersion,imageType:data.imageType,height:data.height,width:data.width,maxZError:data.maxZError,eofOffset:data.eofOffset,mask:data.mask?{numBlocksX:data.mask.numBlocksX,numBlocksY:data.mask.numBlocksY,numBytes:data.mask.numBytes,maxValue:data.mask.maxValue}:null,pixels:{numBlocksX:data.pixels.numBlocksX,numBlocksY:data.pixels.numBlocksY,numBytes:data.pixels.numBytes,maxValue:data.pixels.maxValue,noDataValue:data.noDataValue}}};var computeUsedBitDepths
isValid=val>=-32768&&val<=32767;break;case 3:isValid=val>=0&&val<=65536;break;case 4:isValid=val>=-2147483648&&val<=2147483647;break;case 5:isValid=val>=0&&val<=4294967296;break;case 6:isValid=val>=-3.4027999387901484e38&&val<=3.4027999387901484e38;break;case 7:isValid=val>=5e-324&&val<=1.7976931348623157e308;break;default:isValid=false}return isValid},getDataTypeSize:function(t){var s=0;switch(t){case 0:case 1:s=1;break;case 2:case 3:s=2;break;case 4:case 5:case 6:s=4;break;case 7:s=8;break;default:s=t}return s},getDataTypeUsed:function(dt,tc){var t=dt;switch(dt){case 2:case 4:t=dt-tc;break;case 3:case 5:t=dt-2*tc;break;case 6:if(0===tc){t=dt}else if(1===tc){t=2}else{t=1}break;case 7:if(0===tc){t=dt}else{t=dt-2*tc+1}break;default:t=dt;break}return t},getOnePixel:function(block,blockPtr,offsetType,view){var temp=0;switch(offsetType){case 0:temp=view.getInt8(blockPtr);break;case 1:temp=view.getUint8(blockPtr);break;case 2:temp=view.getInt16(blockPtr,true);break;case 3:temp=view.getUint16(blockPtr,true);break;case 4:temp=view.getInt32(blockPtr,true);break;case 5:temp=view.getUInt32(blockPtr,true);break;case 6:temp=view.getFloat32(blockPtr,true);break;case 7:temp=view.getFloat64(blockPtr,true);break;default:throw"the decoder does not understand this pixel type"}return temp}};var TreeNode=function(val,left,right){this.val=val;this.left=left;this.right=right};var Lerc2Decode={decode:function(input,options){options=options||{};var noDataValue=options.noDataValue;var i=0,data={};data.ptr=options.inputOffset||0;data.pixels={};if(!Lerc2Helpers.readHeaderInfo(input,data)){return}var headerInfo=data.headerInfo;var fileVersion=headerInfo.fileVersion;var OutPixelTypeArray=Lerc2Helpers.getDataTypeArray(headerInfo.imageType);Lerc2Helpers.readMask(input,data);if(headerInfo.numValidPixel!==headerInfo.width*headerInfo.height&&!data.pixels.resultMask){data.pixels.resultMask=options.maskData}var numPixels=headerInfo.width*headerInfo.height;data.pixels.resultPixels=new OutPixelTypeArray(numPixels*headerInfo.numDims);data.counter={onesweep:0,uncompressed:0,lut:0,bitstuffer:0,constant:0,constantoffset:0};if(headerInfo.numValidPixel!==0){if(headerInfo.zMax===headerInfo.zMin){Lerc2Helpers.constructConstantSurface(data)}else if(fileVersion>=4&&Lerc2Helpers.checkMinMaxRanges(input,data)){Lerc2Helpers.constructConstantSurface(data)}else{var view=new DataView(input,data.ptr,2);var bReadDataOneSweep=view.getUint8(0);data.ptr++;if(bReadDataOneSweep){Lerc2Helpers.readDataOneSweep(input,data,OutPixelTypeArray)}else{if(fileVersion>1&&headerInfo.imageType<=1&&Math.abs(headerInfo.maxZError-.5)<1e-5){var flagHuffman=view.getUint8(1);data.ptr++;data.encodeMode=flagHuffman;if(flagHuffman>2||fileVersion<4&&flagHuffman>1){throw"Invalid Huffman flag "+flagHuffman}if(flagHuffman){Lerc2Helpers.readHuffman(input,data,OutPixelTypeArray)}else{Lerc2Helpers.readTiles(input,data,OutPixelTypeArray)}}else{Lerc2Helpers.readTiles(input,data,OutPixelTypeArray)}}}}data.eofOffset=data.ptr;var diff;if(options.inputOffset){diff=data.headerInfo.blobSize+options.inputOffset-data.ptr;if(Math.abs(diff)>=1){data.eofOffset=options.inputOffset+data.headerInfo.blobSize}}else{diff=data.headerInfo.blobSize-data.ptr;if(Math.abs(diff)>=1){data.eofOffset=data.headerInfo.blobSize}}var result={width:headerInfo.width,height:headerInfo.height,pixelData:data.pixels.resultPixels,minValue:headerInfo.zMin,maxValue:headerInfo.zMax,validPixelCount:headerInfo.numValidPixel,dimCount:headerInfo.numDims,dimStats:{minValues:headerInfo.minValues,maxValues:headerInfo.maxValues},maskData:data.pixels.resultMask};if(data.pixels.resultMask&&Lerc2Helpers.isValidPixelValue(headerInfo.imageType,noDataValue)){var mask=data.pixels.resultMask;for(i=0;i<numPixels;i++){if(!mask[i]){result.pixelData[i]=noDataValue}}result.noDataValue=noDataValue}data.noDataValue=noDataValue;if(options.returnFileInfo){result.fileInfo=Lerc2Helpers.formatFileInfo(data)}return result},getBandCount:function(input){var count=0;var i=0;var temp={};temp.ptr=0;temp.pixels={};while(i<input.byteLength-58){Lerc2Helpers.readHeaderInfo(input,temp);i+