diff --git a/package-lock.json b/package-lock.json index a536dbc4..78a426ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,11 +9,12 @@ "version": "2.1.4-beta.0", "license": "MIT", "dependencies": { - "@petamoriken/float16": "^3.4.7", "lerc": "^3.0.0", "pako": "^2.0.4", "parse-headers": "^2.0.2", "quick-lru": "^6.1.1", + "web-worker": "^1.5.0", + "xml-utils": "^1.10.2", "zstddec": "^0.2.0-alpha.3" }, "devDependencies": { @@ -1729,11 +1730,6 @@ "integrity": "sha512-wdppn25U8z/2yiaT6YGquE6X8sSv7hNMWSXYSSU1jGv/yd6XqjXgTDJ8KP4NgjTXfJ3GbRjeeb8RTV7a/VpM+w==", "dev": true }, - "node_modules/@petamoriken/float16": { - "version": "3.4.7", - "resolved": "https://registry.npmjs.org/@petamoriken/float16/-/float16-3.4.7.tgz", - "integrity": "sha512-Mir0MAKxg5v6BUIg9SI5VAyrIa/3uptf7aPyvPhHNh0RMYMevrWbaLrsVSZ1f92C39hWd8v7GrjvvOT+WG5VUQ==" - }, "node_modules/@rollup/plugin-babel": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.3.0.tgz", @@ -8939,11 +8935,6 @@ "integrity": "sha512-wdppn25U8z/2yiaT6YGquE6X8sSv7hNMWSXYSSU1jGv/yd6XqjXgTDJ8KP4NgjTXfJ3GbRjeeb8RTV7a/VpM+w==", "dev": true }, - "@petamoriken/float16": { - "version": "3.4.7", - "resolved": "https://registry.npmjs.org/@petamoriken/float16/-/float16-3.4.7.tgz", - "integrity": "sha512-Mir0MAKxg5v6BUIg9SI5VAyrIa/3uptf7aPyvPhHNh0RMYMevrWbaLrsVSZ1f92C39hWd8v7GrjvvOT+WG5VUQ==" - }, "@rollup/plugin-babel": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.3.0.tgz", diff --git a/package.json b/package.json index 30eeec2a..d727c959 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,6 @@ "node": ">=10.19" }, "dependencies": { - "@petamoriken/float16": "^3.4.7", "lerc": "^3.0.0", "pako": "^2.0.4", "parse-headers": "^2.0.2", diff --git a/src/dataview64.js b/src/dataview64.js index 260d60b4..24bdaae0 100644 --- a/src/dataview64.js +++ b/src/dataview64.js @@ -1,5 +1,3 @@ -import { getFloat16 } from '@petamoriken/float16'; - export default class DataView64 { constructor(arrayBuffer) { this._dataView = new DataView(arrayBuffer); @@ -84,7 +82,7 @@ export default class DataView64 { } getFloat16(offset, littleEndian) { - return getFloat16(this._dataView, offset, littleEndian); + return this._dataView.getFloat16(offset, littleEndian); } getFloat32(offset, littleEndian) { diff --git a/src/geotiffimage.js b/src/geotiffimage.js index 3b7df8e7..847a15d9 100644 --- a/src/geotiffimage.js +++ b/src/geotiffimage.js @@ -1,5 +1,4 @@ /** @module geotiffimage */ -import { getFloat16 } from '@petamoriken/float16'; import getAttribute from 'xml-utils/get-attribute'; // eslint-disable-line import/extensions import findTagsByName from 'xml-utils/find-tags-by-name'; // eslint-disable-line import/extensions @@ -65,6 +64,10 @@ function arrayForType(format, bitsPerSample, size) { case 3: // floating point data switch (bitsPerSample) { case 16: + // Float16Array is supported since eslint 9.29.0, see https://eslint.org/blog/2025/06/eslint-v9.29.0-released/ + // but eslint can't be updated to 9.x.x, because eslint-config-airbnb-base supports up to eslint 8.x.x only + // eslint-disable-next-line no-undef + return new Float16Array(size); case 32: return new Float32Array(size); case 64: @@ -155,16 +158,6 @@ function normalizeArray(inBuffer, format, planarConfiguration, samplesPerPixel, // bitOffset = bitOffset + pixelBitSkip - bitsPerSample; } } - } else if (format === 3) { // floating point - // Float16 is handled elsewhere - // normalize 16/24 bit floats to 32 bit floats in the array - // console.time(); - // if (bitsPerSample === 16) { - // for (let byte = 0, outIndex = 0; byte < inBuffer.byteLength; byte += 2, ++outIndex) { - // outArray[outIndex] = getFloat16(view, byte); - // } - // } - // console.timeEnd() } return outArray.buffer; @@ -320,9 +313,7 @@ class GeoTIFFImage { case 3: switch (bitsPerSample) { case 16: - return function (offset, littleEndian) { - return getFloat16(this, offset, littleEndian); - }; + return DataView.prototype.getFloat16; case 32: return DataView.prototype.getFloat32; case 64: diff --git a/test/data/.gitignore b/test/data/.gitignore index 5fd66ea8..5a50ffb4 100644 --- a/test/data/.gitignore +++ b/test/data/.gitignore @@ -1,4 +1,5 @@ *zip* *tif* +*cog* *html *xml diff --git a/test/data/setup_data.sh b/test/data/setup_data.sh index 6f479f63..5ee13115 100755 --- a/test/data/setup_data.sh +++ b/test/data/setup_data.sh @@ -1,4 +1,8 @@ set -e + +# uncomment to create test data in Docker, GDAL on MacOS installed via Homebrew doesn't have LERC +# alias gdal_translate="docker run -v .:/data -w /data ghcr.io/osgeo/gdal:alpine-small-latest gdal_translate" + wget https://github.com/EOxServer/autotest/raw/f8d9f4bde6686abbda09c711d4bf5239f5378aa9/autotest/data/meris/MER_FRS_1P_reduced/ENVISAT-MER_FRS_1PNPDE20060816_090929_000001972050_00222_23322_0058_uint16_reduced_compressed.tif -O initial.tiff wget https://github.com/EOxServer/autotest/raw/f8d9f4bde6686abbda09c711d4bf5239f5378aa9/autotest/data/meris/mosaic_MER_FRS_1P_RGB_reduced/mosaic_ENVISAT-MER_FRS_1PNPDE20060816_090929_000001972050_00222_23322_0058_RGB_reduced.tif -O rgb.tiff wget https://raw.githubusercontent.com/hubmapconsortium/portal-containers/master/containers/ome-tiff-offsets/test-input/multi-channel.ome.tif -O multi-channel.ome.tif @@ -7,6 +11,7 @@ gdal_translate -of GTiff initial.tiff stripped.tiff gdal_translate -of GTiff -co TILED=YES -co BLOCKXSIZE=32 -co BLOCKYSIZE=32 stripped.tiff tiled.tiff gdal_translate -of GTiff -ot Int32 stripped.tiff int32.tiff gdal_translate -of GTiff -ot UInt32 stripped.tiff uint32.tiff +gdal_translate -of GTiff -ot Float32 -co NBITS=16 stripped.tiff float16.tiff gdal_translate -of GTiff -ot Float32 stripped.tiff float32.tiff gdal_translate -of GTiff -ot Float64 stripped.tiff float64.tiff gdal_translate -of GTiff -co COMPRESS=LZW stripped.tiff lzw.tiff diff --git a/test/geotiff.spec.js b/test/geotiff.spec.js index 327462d8..62b67ba7 100644 --- a/test/geotiff.spec.js +++ b/test/geotiff.spec.js @@ -247,6 +247,14 @@ describe('GeoTIFF', () => { await performTiffTests(tiff, 539, 448, 15, Uint32Array); }); + it('should work on Float16 tiffs', async () => { + const tiff = await GeoTIFF.fromSource(createSource('float16.tiff')); + // Float16Array is supported since eslint 9.29.0, see https://eslint.org/blog/2025/06/eslint-v9.29.0-released/ + // but eslint can't be updated to 9.x.x, because eslint-config-airbnb-base supports up to eslint 8.x.x only + // eslint-disable-next-line no-undef + await performTiffTests(tiff, 539, 448, 15, Float16Array); + }); + it('should work on Float32 tiffs', async () => { const tiff = await GeoTIFF.fromSource(createSource('float32.tiff')); await performTiffTests(tiff, 539, 448, 15, Float32Array);