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