Skip to content
Open
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
13 changes: 2 additions & 11 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 1 addition & 3 deletions src/dataview64.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { getFloat16 } from '@petamoriken/float16';

export default class DataView64 {
constructor(arrayBuffer) {
this._dataView = new DataView(arrayBuffer);
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 5 additions & 14 deletions src/geotiffimage.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions test/data/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*zip*
*tif*
*cog*
*html
*xml
5 changes: 5 additions & 0 deletions test/data/setup_data.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/geotiff.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading