Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 20.x
- run: npm ci
- run: npm run build
- run: npm test
Expand Down
107 changes: 12 additions & 95 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
"parse-headers": "^2.0.2",
"quick-lru": "^6.1.1",
"web-worker": "^1.2.0",
"xml-utils": "^1.0.2"
"xml-utils": "^1.0.2",
"zstddec": "^0.1.0"
},
"devDependencies": {
"@babel/core": "^7.8.7",
Expand All @@ -107,7 +108,6 @@
"express": "^4.17.1",
"finalhandler": "^1.1.2",
"fs-extra": "^7.0.1",
"isomorphic-fetch": "^2.2.1",
"jsdoc": "^3.6.4",
"jsdoc-plugin-intersection": "^1.0.4",
"jsdoc-plugin-typescript": "^2.0.6",
Expand Down
2 changes: 1 addition & 1 deletion scripts/serialize-workers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function build(input, { minify = true } = {}) {
import Worker from 'web-worker';
export function create() {
const source = ${JSON.stringify(code)};
return new Worker(typeof Blob === 'undefined'
return new Worker(typeof Buffer !== 'undefined'
? 'data:application/javascript;base64,' + Buffer.from(source, 'binary').toString('base64')
: URL.createObjectURL(new Blob([source], {type: 'application/javascript'})));
}
Expand Down
8 changes: 7 additions & 1 deletion src/compression/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ addDecoder(6, () => {
addDecoder(7, () => import('./jpeg.js').then((m) => m.default));
addDecoder([8, 32946], () => import('./deflate.js').then((m) => m.default));
addDecoder(32773, () => import('./packbits.js').then((m) => m.default));
addDecoder(34887, () => import('./lerc.js').then((m) => m.default));
addDecoder(34887, () => import('./lerc.js')
.then(async (m) => {
await m.zstd.init();
return m;
})
.then((m) => m.default),
);
addDecoder(50001, () => import('./webimage.js').then((m) => m.default));
6 changes: 6 additions & 0 deletions src/compression/lerc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { inflate } from 'pako';
import Lerc from 'lerc';
import { ZSTDDecoder } from 'zstddec';
import BaseDecoder from './basedecoder.js';
import { LercParameters, LercAddCompression } from '../globals.js';

export const zstd = new ZSTDDecoder();

export default class LercDecoder extends BaseDecoder {
constructor(fileDirectory) {
super();
Expand All @@ -20,6 +23,9 @@ export default class LercDecoder extends BaseDecoder {
case LercAddCompression.Deflate:
buffer = inflate(new Uint8Array(buffer)).buffer; // eslint-disable-line no-param-reassign, prefer-destructuring
break;
case LercAddCompression.Zstandard:
buffer = zstd.decode(new Uint8Array(buffer)).buffer; // eslint-disable-line no-param-reassign, prefer-destructuring
break;
default:
throw new Error(`Unsupported LERC additional compression method identifier: ${this.addCompression}`);
}
Expand Down
1 change: 1 addition & 0 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export const LercParameters = {
export const LercAddCompression = {
None: 0,
Deflate: 1,
Zstandard: 2,
};

export const geoKeyNames = {
Expand Down
2 changes: 2 additions & 0 deletions test/data/setup_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ gdal_translate -of GTiff -co BIGTIFF=YES stripped.tiff bigtiff.tiff
gdal_translate -of GTiff -co COMPRESS=LERC -co MAX_Z_ERROR=1000 stripped.tiff lerc.tiff
gdal_translate -of GTiff -co COMPRESS=LERC -co MAX_Z_ERROR=1000 -co INTERLEAVE=BAND stripped.tiff lerc_interleave.tiff
gdal_translate -of GTiff -co COMPRESS=LERC_DEFLATE -co MAX_Z_ERROR=1000 stripped.tiff lerc_deflate.tiff
gdal_translate -of GTiff -co COMPRESS=LERC_ZSTD -co MAX_Z_ERROR=1000 stripped.tiff lerc_zstd.tiff
gdal_translate -of GTiff -ot Float32 -co COMPRESS=LERC -co MAX_Z_ERROR=1000 stripped.tiff float32lerc.tiff
gdal_translate -of GTiff -ot Float32 -co COMPRESS=LERC -co MAX_Z_ERROR=1000 -co INTERLEAVE=BAND stripped.tiff float32lerc_interleave.tiff
gdal_translate -of GTiff -ot Float32 -co COMPRESS=LERC_DEFLATE -co MAX_Z_ERROR=1000 stripped.tiff float32lerc_deflate.tiff
gdal_translate -of GTiff -ot Float32 -co COMPRESS=LERC_ZSTD -co MAX_Z_ERROR=1000 stripped.tiff float32lerc_zstd.tiff

gdal_translate -of COG initial.tiff cog.tiff

Expand Down
11 changes: 10 additions & 1 deletion test/geotiff.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { expect } from 'chai';
import http from 'http';
import serveStatic from 'serve-static';
import finalhandler from 'finalhandler';
import 'isomorphic-fetch';
import AbortController from 'node-abort-controller';
import { dirname } from 'path';

Expand Down Expand Up @@ -243,6 +242,11 @@ describe('GeoTIFF', () => {
await performTiffTests(tiff, 539, 448, 15, Uint16Array);
});

it('should work on LERC Zstandard compressed tiffs', async () => {
const tiff = await GeoTIFF.fromSource(createSource('lerc_zstd.tiff'));
await performTiffTests(tiff, 539, 448, 15, Uint16Array);
});

it('should work on Float32 and LERC compressed tiffs', async () => {
const tiff = await GeoTIFF.fromSource(createSource('float32lerc.tiff'));
await performTiffTests(tiff, 539, 448, 15, Float32Array);
Expand All @@ -258,6 +262,11 @@ describe('GeoTIFF', () => {
await performTiffTests(tiff, 539, 448, 15, Float32Array);
});

it('should work on Float32 and LERC Zstandard compressed tiffs', async () => {
const tiff = await GeoTIFF.fromSource(createSource('float32lerc_zstd.tiff'));
await performTiffTests(tiff, 539, 448, 15, Float32Array);
});

it('should work with worker pool', async () => {
const testPool = new Pool();
const tiff = await GeoTIFF.fromSource(createSource('nasa_raster.tiff'));
Expand Down
1 change: 0 additions & 1 deletion test/source.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable global-require, no-unused-expressions */
import isNode from 'detect-node';
import 'isomorphic-fetch';
import { expect } from 'chai';

import { makeFetchSource } from '../src/source/remote.js';
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "ES5",
"lib": ["ES2020"],
"lib": ["ES2020", "DOM"],
"allowJs": true,
"declaration": true,
"declarationMap": true,
Expand Down