1
1
/** @module geotiffimage */
2
- import { getFloat16 } from '@petamoriken/float16' ;
2
+ import { getFloat16 } from '@petamoriken/float16' ;
3
3
import getAttribute from 'xml-utils/get-attribute.js' ;
4
4
import findTagsByName from 'xml-utils/find-tags-by-name.js' ;
5
5
6
- import { photometricInterpretations , ExtraSamplesValues } from './globals.js' ;
7
- import { fromWhiteIsZero , fromBlackIsZero , fromPalette , fromCMYK , fromYCbCr , fromCIELab } from './rgb.js' ;
8
- import { getDecoder } from './compression/index.js' ;
9
- import { resample , resampleInterleaved } from './resample.js' ;
6
+ import { photometricInterpretations , ExtraSamplesValues } from './globals.js' ;
7
+ import { fromWhiteIsZero , fromBlackIsZero , fromPalette , fromCMYK , fromYCbCr , fromCIELab } from './rgb.js' ;
8
+ import { getDecoder } from './compression/index.js' ;
9
+ import { resample , resampleInterleaved } from './resample.js' ;
10
10
11
11
/**
12
12
* @typedef {Object } ReadRasterOptions
@@ -295,8 +295,8 @@ class GeoTIFFImage {
295
295
}
296
296
297
297
getReaderForSample ( sampleIndex ) {
298
- const format = this . fileDirectory . SampleFormat
299
- ? this . fileDirectory . SampleFormat [ sampleIndex ] : 1 ;
298
+ const format = this . getSampleFormat ( sampleIndex ) ;
299
+
300
300
const bitsPerSample = this . fileDirectory . BitsPerSample [ sampleIndex ] ;
301
301
switch ( format ) {
302
302
case 1 : // unsigned integer data
@@ -339,7 +339,8 @@ class GeoTIFFImage {
339
339
340
340
getSampleFormat ( sampleIndex = 0 ) {
341
341
return this . fileDirectory . SampleFormat
342
- ? this . fileDirectory . SampleFormat [ sampleIndex ] : 1 ;
342
+ ? ( this . fileDirectory . SampleFormat [ sampleIndex ] ?? Math . max . apply ( null , this . fileDirectory . SampleFormat ) )
343
+ : 1 ;
343
344
}
344
345
345
346
getBitsPerSample ( sampleIndex = 0 ) {
@@ -366,7 +367,7 @@ class GeoTIFFImage {
366
367
const numTilesPerRow = Math . ceil ( this . getWidth ( ) / this . getTileWidth ( ) ) ;
367
368
const numTilesPerCol = Math . ceil ( this . getHeight ( ) / this . getTileHeight ( ) ) ;
368
369
let index ;
369
- const { tiles } = this ;
370
+ const { tiles} = this ;
370
371
if ( this . planarConfiguration === 1 ) {
371
372
index = ( y * numTilesPerRow ) + x ;
372
373
} else if ( this . planarConfiguration === 2 ) {
@@ -382,11 +383,11 @@ class GeoTIFFImage {
382
383
offset = this . fileDirectory . StripOffsets [ index ] ;
383
384
byteCount = this . fileDirectory . StripByteCounts [ index ] ;
384
385
}
385
- const slice = ( await this . source . fetch ( [ { offset, length : byteCount } ] , signal ) ) [ 0 ] ;
386
+ const slice = ( await this . source . fetch ( [ { offset, length : byteCount } ] , signal ) ) [ 0 ] ;
386
387
387
388
let request ;
388
389
if ( tiles === null || ! tiles [ index ] ) {
389
- // resolve each request by potentially applying array normalization
390
+ // resolve each request by potentially applying array normalization
390
391
request = ( async ( ) => {
391
392
let data = await poolOrDecoder . decode ( this . fileDirectory , slice ) ;
392
393
const sampleFormat = this . getSampleFormat ( ) ;
@@ -415,7 +416,7 @@ class GeoTIFFImage {
415
416
}
416
417
417
418
// cache the tile request
418
- return { x, y, sample, data : await request } ;
419
+ return { x, y, sample, data : await request } ;
419
420
}
420
421
421
422
/**
@@ -434,7 +435,7 @@ class GeoTIFFImage {
434
435
* @returns {Promise<ReadRasterResult> }
435
436
*/
436
437
async _readRaster ( imageWindow , samples , valueArrays , interleave , poolOrDecoder , width ,
437
- height , resampleMethod , signal ) {
438
+ height , resampleMethod , signal ) {
438
439
const tileWidth = this . getTileWidth ( ) ;
439
440
const tileHeight = this . getTileHeight ( ) ;
440
441
const imageWidth = this . getWidth ( ) ;
@@ -466,7 +467,7 @@ class GeoTIFFImage {
466
467
}
467
468
468
469
const promises = [ ] ;
469
- const { littleEndian } = this ;
470
+ const { littleEndian} = this ;
470
471
471
472
for ( let yTile = minYTile ; yTile < maxYTile ; ++ yTile ) {
472
473
for ( let xTile = minXTile ; xTile < maxXTile ; ++ xTile ) {
@@ -517,7 +518,7 @@ class GeoTIFFImage {
517
518
await Promise . all ( promises ) ;
518
519
519
520
if ( ( width && ( imageWindow [ 2 ] - imageWindow [ 0 ] ) !== width )
520
- || ( height && ( imageWindow [ 3 ] - imageWindow [ 1 ] ) !== height ) ) {
521
+ || ( height && ( imageWindow [ 3 ] - imageWindow [ 1 ] ) !== height ) ) {
521
522
let resampled ;
522
523
if ( interleave ) {
523
524
resampled = resampleInterleaved (
@@ -558,9 +559,9 @@ class GeoTIFFImage {
558
559
* @returns {Promise<ReadRasterResult> } the decoded arrays as a promise
559
560
*/
560
561
async readRasters ( {
561
- window : wnd , samples = [ ] , interleave, pool = null ,
562
- width, height, resampleMethod, fillValue, signal,
563
- } = { } ) {
562
+ window : wnd , samples = [ ] , interleave, pool = null ,
563
+ width, height, resampleMethod, fillValue, signal,
564
+ } = { } ) {
564
565
const imageWindow = wnd || [ 0 , 0 , this . getWidth ( ) , this . getHeight ( ) ] ;
565
566
566
567
// check parameters
@@ -638,8 +639,10 @@ class GeoTIFFImage {
638
639
* to be aborted
639
640
* @returns {Promise<ReadRasterResult> } the RGB array as a Promise
640
641
*/
641
- async readRGB ( { window, interleave = true , pool = null , width, height,
642
- resampleMethod, enableAlpha = false , signal } = { } ) {
642
+ async readRGB ( {
643
+ window, interleave = true , pool = null , width, height,
644
+ resampleMethod, enableAlpha = false , signal
645
+ } = { } ) {
643
646
const imageWindow = window || [ 0 , 0 , this . getWidth ( ) , this . getHeight ( ) ] ;
644
647
645
648
// check parameters
@@ -697,7 +700,7 @@ class GeoTIFFImage {
697
700
resampleMethod,
698
701
signal,
699
702
} ;
700
- const { fileDirectory } = this ;
703
+ const { fileDirectory} = this ;
701
704
const raster = await this . readRasters ( subOptions ) ;
702
705
703
706
const max = 2 ** this . fileDirectory . BitsPerSample [ 0 ] ;
0 commit comments