@@ -81,13 +81,6 @@ add_format(
81
81
[:ImageMagick ],
82
82
[:MimeWriter , SAVE]
83
83
)
84
- add_format (
85
- format " TIFF" ,
86
- (UInt8[0x4d ,0x4d ,0x00 ,0x2a ], UInt8[0x4d ,0x4d ,0x00 ,0x2b ], UInt8[0x49 ,0x49 ,0x2a ,0x00 ],UInt8[0x49 ,0x49 ,0x2b ,0x00 ]),
87
- [" .tiff" , " .tif" ],
88
- [:QuartzImageIO , OSX],
89
- [:ImageMagick ]
90
- )
91
84
add_format (
92
85
format " JPEG" ,
93
86
UInt8[0xff ,0xd8 ,0xff ],
@@ -154,6 +147,25 @@ add_format(format"FLAC","fLaC",".flac",[:FLAC])
154
147
155
148
# ## Complex cases
156
149
150
+ # Handle OME-TIFFs, which are identical to normal TIFFs with the primary difference being the filename and embedded XML metadata
151
+ const tiff_magic = (UInt8[0x4d ,0x4d ,0x00 ,0x2a ], UInt8[0x4d ,0x4d ,0x00 ,0x2b ], UInt8[0x49 ,0x49 ,0x2a ,0x00 ],UInt8[0x49 ,0x49 ,0x2b ,0x00 ])
152
+ function detecttiff (io)
153
+ seekstart (io)
154
+ magic = read (io, UInt8, 4 )
155
+ # do any of the first 4 bytes match any of the 4 possible combinations of tiff magics
156
+ return any (map (x-> all (magic .== x), tiff_magic))
157
+ end
158
+ # OME-TIFF
159
+ detect_ometiff (io) = detecttiff (io) && (endswith (io. name, " .ome.tif>" ) || endswith (io. name, " .ome.tiff>" ))
160
+ add_format (format " OMETIFF" , detect_ometiff, [" .tif" , " .tiff" ], [:OMETIFF ])
161
+ # normal TIFF
162
+ detect_noometiff (io) = detecttiff (io) && ! (endswith (io. name, " .ome.tif>" ) || endswith (io. name, " .ome.tiff>" ))
163
+ add_format (format " TIFF" , detect_noometiff, [" .tiff" , " .tif" ], [:QuartzImageIO , OSX], [:ImageMagick ])
164
+
165
+ # custom skipmagic functions for function-based tiff magic detection
166
+ skipmagic (io, :: typeof (detect_ometiff)) = seek (io, 4 )
167
+ skipmagic (io, :: typeof (detect_noometiff)) = seek (io, 4 )
168
+
157
169
# AVI is a subtype of RIFF, as is WAV
158
170
function detectavi (io)
159
171
seekstart (io)
0 commit comments