@@ -57,7 +57,7 @@ class UnrecognizedFile(Exception):
5757
5858
5959class TiffFile (file ):
60- def __init__ (self , path , ndpi = False ):
60+ def __init__ (self , path ):
6161 file .__init__ (self , path , 'r+b' )
6262
6363 # Check header, decide endianness
@@ -74,7 +74,7 @@ def __init__(self, path, ndpi=False):
7474 self ._ndpi = False
7575 version = self .read_fmt ('H' )
7676 if version == 42 :
77- self . _ndpi = ndpi
77+ pass
7878 elif version == 43 :
7979 self ._bigtiff = True
8080 magic2 , reserved = self .read_fmt ('HH' )
@@ -93,6 +93,14 @@ def __init__(self, path, ndpi=False):
9393 self .seek (directory_offset )
9494 directory = TiffDirectory (self , len (self .directories ),
9595 in_pointer_offset )
96+ if not self .directories and not self ._bigtiff :
97+ # Check for NDPI. Because we don't know we have an NDPI file
98+ # until after reading the first directory, we will choke if
99+ # the first directory is beyond 4 GB.
100+ if NDPI_MAGIC in directory .entries :
101+ if DEBUG :
102+ print 'Enabling NDPI mode.'
103+ self ._ndpi = True
96104 self .directories .append (directory )
97105 if not self .directories :
98106 raise IOError ('No directories' )
@@ -246,7 +254,7 @@ def do_aperio_svs(filename):
246254
247255
248256def do_hamamatsu_ndpi (filename ):
249- with TiffFile (filename , ndpi = True ) as fh :
257+ with TiffFile (filename ) as fh :
250258 # Check for NDPI file
251259 if NDPI_MAGIC not in fh .directories [0 ].entries :
252260 raise UnrecognizedFile
@@ -262,8 +270,8 @@ def do_hamamatsu_ndpi(filename):
262270
263271
264272format_handlers = [
265- do_hamamatsu_ndpi ,
266273 do_aperio_svs ,
274+ do_hamamatsu_ndpi ,
267275]
268276
269277
0 commit comments