Open manzt opened 5 months ago
Steps to reproduce:
mkdir geotiff-bug
cd geotiff-bug
npm init -y
npm install geotiff
touch index.js # add following code
// index.mjs
import * as GeoTIFF from "geotiff";
let tiff = await GeoTIFF.fromFile("../../Downloads/Xenium_FFPE_Human_Breast_Cancer_Rep1_he_image.ome.tif");
let img = await tiff.getImage();
let data = await img.readRasters({ window: [0, 0, 512, 512], interleave: true });
console.log(data);
node index.mjs
file:///Users/manzt/demos/tgo/node_modules/.pnpm/geotiff@2.1.3/node_modules/geotiff/dist-module/geotiffimage.js:337
throw Error('Unsupported data format/bitsPerSample');
^
Error: Unsupported data format/bitsPerSample
at GeoTIFFImage.getReaderForSample (file:///Users/manzt/demos/tgo/node_modules/.pnpm/geotiff@2.1.3/node_modules/geotiff/dist-module/geotiffimage.js:337:11)
at GeoTIFFImage._readRaster (file:///Users/manzt/demos/tgo/node_modules/.pnpm/geotiff@2.1.3/node_modules/geotiff/dist-module/geotiffimage.js:465:31)
at GeoTIFFImage.readRasters (file:///Users/manzt/demos/tgo/node_modules/.pnpm/geotiff@2.1.3/node_modules/geotiff/dist-module/geotiffimage.js:616:31)
at async file:///Users/manzt/demos/tgo/index.mjs:5:12
Node.js v20.10.0
It seems the intent this code in
getReaderForSample
is to always ensureformat
is defined. However, I ran into an edge case when loading an OME-TIFF where for some reasonSampleFormat
is defined but the format for specific sample index is missing, causingformat: undefined
, and throwing:A snapshot of this edge case from the debugger:
You can see
format: undefined
. This PR keeps the current behavior but falls back to format: 1 in the additional case whereSampleFormat
is defined but there is no entry for thesampleIndex
.Apologies for the screenshots. The changes are very minimal, I just want to make sure this is the intended behavior. It seems the intent of the code is to always have
format
defined, but this is an edge case where it is not.