@@ -446,6 +446,78 @@ describe('ifdRequestTests', () => {
446
446
} ) ;
447
447
} ) ;
448
448
449
+ describe ( 'Empty tile tests' , ( ) => {
450
+ it ( 'should be able to read tiffs with empty tiles' , async ( ) => {
451
+ const tiff = await GeoTIFF . fromSource ( createSource ( 'empty_tiles.tiff' ) ) ;
452
+ const image = await tiff . getImage ( ) ;
453
+ expect ( image ) . to . be . ok ;
454
+ expect ( image . getWidth ( ) ) . to . equal ( 541 ) ;
455
+ expect ( image . getHeight ( ) ) . to . equal ( 449 ) ;
456
+ expect ( image . getSamplesPerPixel ( ) ) . to . equal ( 3 ) ;
457
+ } ) ;
458
+
459
+ it ( 'should be able to read tiffs with empty uint16 tiles' , async ( ) => {
460
+ const tiff = await GeoTIFF . fromSource ( createSource ( 'empty_tiles_16.tiff' ) ) ;
461
+ const image = await tiff . getImage ( ) ;
462
+ expect ( image ) . to . be . ok ;
463
+ expect ( image . getWidth ( ) ) . to . equal ( 541 ) ;
464
+ expect ( image . getHeight ( ) ) . to . equal ( 449 ) ;
465
+ expect ( image . getSamplesPerPixel ( ) ) . to . equal ( 3 ) ;
466
+ } ) ;
467
+
468
+ const options = { width : 541 , height : 449 , interleave : true , samples : [ 0 , 1 , 2 ] } ;
469
+ const readImage = async ( fname ) => {
470
+ const tiff = await GeoTIFF . fromSource ( createSource ( fname ) ) ;
471
+ const image = await tiff . getImage ( ) ;
472
+ return image . readRasters ( options ) ;
473
+ } ;
474
+
475
+ it ( 'should interpret empty tiles' , async ( ) => {
476
+ const comp = await readImage ( 'rgb.tiff' ) ;
477
+ const rgb = await readImage ( 'empty_tiles.tiff' ) ;
478
+ expect ( rgb ) . to . have . lengthOf ( comp . length ) ;
479
+ let maxDiff = 0 ;
480
+ for ( let i = 0 ; i < rgb . length ; ++ i ) {
481
+ maxDiff = Math . max ( maxDiff , Math . abs ( comp [ i ] - rgb [ i ] ) ) ;
482
+ }
483
+ expect ( maxDiff ) . to . equal ( 0 ) ;
484
+ } ) ;
485
+
486
+ it ( 'should interpret empty tiles with nodata' , async ( ) => {
487
+ const comp = await readImage ( 'rgb.tiff' ) ;
488
+ const rgb = await readImage ( 'empty_tiles_nodata.tiff' ) ;
489
+ expect ( rgb ) . to . have . lengthOf ( comp . length ) ;
490
+ let maxDiff = 0 ;
491
+ for ( let i = 0 ; i < rgb . length ; ++ i ) {
492
+ maxDiff = Math . max ( maxDiff , Math . abs ( comp [ i ] - rgb [ i ] ) ) ;
493
+ }
494
+ expect ( maxDiff ) . to . equal ( 0 ) ;
495
+ } ) ;
496
+
497
+ it ( 'should interpret empty uint16 tiles' , async ( ) => {
498
+ const comp = await readImage ( 'rgb.tiff' ) ;
499
+ const rgb = await readImage ( 'empty_tiles_16.tiff' ) ;
500
+ expect ( rgb ) . to . have . lengthOf ( comp . length ) ;
501
+ let maxDiff = 0 ;
502
+ for ( let i = 0 ; i < rgb . length ; ++ i ) {
503
+ maxDiff = Math . max ( maxDiff , Math . abs ( comp [ i ] - rgb [ i ] ) ) ;
504
+ }
505
+ expect ( maxDiff ) . to . equal ( 0 ) ;
506
+ } ) ;
507
+
508
+ it ( 'should interpret empty uint16 tiles and nodata==256' , async ( ) => {
509
+ const comp = await readImage ( 'rgb.tiff' ) ;
510
+ const rgb = await readImage ( 'empty_tiles_16_nodata256.tiff' ) ;
511
+ expect ( rgb ) . to . have . lengthOf ( comp . length ) ;
512
+ let maxDiff = 0 ;
513
+ for ( let i = 0 ; i < rgb . length ; ++ i ) {
514
+ const compSample = comp [ i ] === 0 ? 256 : comp [ i ] ;
515
+ maxDiff = Math . max ( maxDiff , Math . abs ( compSample - rgb [ i ] ) ) ;
516
+ }
517
+ expect ( maxDiff ) . to . equal ( 0 ) ;
518
+ } ) ;
519
+ } ) ;
520
+
449
521
describe ( 'RGB-tests' , ( ) => {
450
522
const options = { window : [ 250 , 250 , 300 , 300 ] , interleave : true } ;
451
523
const comparisonRaster = ( async ( ) => {
0 commit comments