lerc.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import { inflate } from 'pako';
  2. import Lerc from 'lerc';
  3. import BaseDecoder from './basedecoder.js';
  4. import { LercParameters, LercAddCompression } from '../globals.js';
  5. export default class LercDecoder extends BaseDecoder {
  6. constructor(fileDirectory) {
  7. super();
  8. this.planarConfiguration = typeof fileDirectory.PlanarConfiguration !== 'undefined' ? fileDirectory.PlanarConfiguration : 1;
  9. this.samplesPerPixel = typeof fileDirectory.SamplesPerPixel !== 'undefined' ? fileDirectory.SamplesPerPixel : 1;
  10. this.addCompression = fileDirectory.LercParameters[LercParameters.AddCompression];
  11. }
  12. decodeBlock(buffer) {
  13. switch (this.addCompression) {
  14. case LercAddCompression.None:
  15. break;
  16. case LercAddCompression.Deflate:
  17. buffer = inflate(new Uint8Array(buffer)).buffer; // eslint-disable-line no-param-reassign, prefer-destructuring
  18. break;
  19. default:
  20. throw new Error(`Unsupported LERC additional compression method identifier: ${this.addCompression}`);
  21. }
  22. const lercResult = Lerc.decode(buffer, { returnPixelInterleavedDims: this.planarConfiguration === 1 });
  23. const lercData = lercResult.pixels[0];
  24. return lercData.buffer;
  25. }
  26. }