geotiffjs / geotiff.js

geotiff.js is a small library to parse TIFF files for visualization or analysis. It is written in pure JavaScript, and is usable in both the browser and node.js applications.
https://geotiffjs.github.io/
MIT License
859 stars 179 forks source link

_readRaster on pixel-interleaved file uses memory proportional to square of band count #376

Closed jcphill closed 1 year ago

jcphill commented 1 year ago

The following code in _readRaster() launches a separate getTileOrStrip() for each band ("sample") requested, which is fine for band-interleaved files, but for pixel-interleaved files the size of each load is multiplied by the number of bands present so that the total amount of data loaded is proportional to the number of bands present times the number of bands requested. This is not only redundant, but because the work is launched asynchronously it is also possible for all of the data to be in flight at the same time resulting in memory allocation failures. https://github.com/geotiffjs/geotiff.js/blob/f15d7709efd5e519dc2834386305218208cecd9c/src/geotiffimage.js#L471-L479

Line 477 also looks like it should call getSampleByteSize() on sample instead of sampleIndex.