Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fallback to format=1 if not format for sample index #420

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

manzt
Copy link
Contributor

@manzt manzt commented Feb 20, 2024

It seems the intent this code in getReaderForSample is to always ensure format is defined. However, I ran into an edge case when loading an OME-TIFF where for some reason SampleFormat is defined but the format for specific sample index is missing, causing format: undefined, and throwing:

Error: Unsupported data format/bitsPerSample

A snapshot of this edge case from the debugger:

image

You can see format: undefined. This PR keeps the current behavior but falls back to format: 1 in the additional case where SampleFormat is defined but there is no entry for the sampleIndex.

image

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.

@manzt
Copy link
Contributor Author

manzt commented Feb 20, 2024

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/[email protected]/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/[email protected]/node_modules/geotiff/dist-module/geotiffimage.js:337:11)
    at GeoTIFFImage._readRaster (file:///Users/manzt/demos/tgo/node_modules/.pnpm/[email protected]/node_modules/geotiff/dist-module/geotiffimage.js:465:31)
    at GeoTIFFImage.readRasters (file:///Users/manzt/demos/tgo/node_modules/.pnpm/[email protected]/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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant