Skip to content

Commit

Permalink
Merge pull request #235 from zakjan/lerc-update
Browse files Browse the repository at this point in the history
Update LERC
  • Loading branch information
constantinius committed Sep 6, 2021
2 parents a0153dc + 4cfc98f commit 1d80742
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@petamoriken/float16": "^1.0.7",
"content-type-parser": "^1.0.2",
"lerc": "^2.0.0",
"lerc": "^3.0.0",
"lru-cache": "^6.0.0",
"pako": "^1.0.11",
"parse-headers": "^2.0.2",
Expand Down
18 changes: 3 additions & 15 deletions src/compression/lerc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ export default class LercDecoder extends BaseDecoder {
this.addCompression = fileDirectory.LercParameters[LercParameters.AddCompression];
}

interleavePixels(bandInterleavedData) {
const pixelInterleavedData = new bandInterleavedData.constructor(bandInterleavedData.length);
const lengthPerSample = bandInterleavedData.length / this.samplesPerPixel;
for (let i = 0; i < lengthPerSample; i++) {
for (let j = 0; j < this.samplesPerPixel; j++) {
pixelInterleavedData[i * this.samplesPerPixel + j] = bandInterleavedData[i + j * lengthPerSample];
}
}
return pixelInterleavedData;
}

decodeBlock(buffer) {
switch (this.addCompression) {
case LercAddCompression.None:
Expand All @@ -35,9 +24,8 @@ export default class LercDecoder extends BaseDecoder {
throw new Error(`Unsupported LERC additional compression method identifier: ${this.addCompression}`);
}

const lercResult = Lerc.decode(buffer);
const lercData = lercResult.pixels[0]; // always band-interleaved
const decodedData = this.planarConfiguration === 1 ? this.interleavePixels(lercData) : lercData; // transform to pixel-interleaved if expected
return decodedData.buffer;
const lercResult = Lerc.decode(buffer, { returnPixelInterleavedDims: this.planarConfiguration === 1 });
const lercData = lercResult.pixels[0];
return lercData.buffer;
}
}

0 comments on commit 1d80742

Please sign in to comment.