Skip to content

Commit

Permalink
add support for loading OME-TIFFs (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlnagy authored and timholy committed Aug 22, 2017
1 parent bf7756c commit bf2c3b3
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/registry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ add_format(
[:ImageMagick],
[:MimeWriter, SAVE]
)
add_format(
format"TIFF",
(UInt8[0x4d,0x4d,0x00,0x2a], UInt8[0x4d,0x4d,0x00,0x2b], UInt8[0x49,0x49,0x2a,0x00],UInt8[0x49,0x49,0x2b,0x00]),
[".tiff", ".tif"],
[:QuartzImageIO, OSX],
[:ImageMagick]
)
add_format(
format"JPEG",
UInt8[0xff,0xd8,0xff],
Expand Down Expand Up @@ -154,6 +147,25 @@ add_format(format"FLAC","fLaC",".flac",[:FLAC])

### Complex cases

# Handle OME-TIFFs, which are identical to normal TIFFs with the primary difference being the filename and embedded XML metadata
const tiff_magic = (UInt8[0x4d,0x4d,0x00,0x2a], UInt8[0x4d,0x4d,0x00,0x2b], UInt8[0x49,0x49,0x2a,0x00],UInt8[0x49,0x49,0x2b,0x00])
function detecttiff(io)
seekstart(io)
magic = read(io, UInt8, 4)
# do any of the first 4 bytes match any of the 4 possible combinations of tiff magics
return any(map(x->all(magic .== x), tiff_magic))
end
# OME-TIFF
detect_ometiff(io) = detecttiff(io) && (endswith(io.name, ".ome.tif>") || endswith(io.name, ".ome.tiff>"))
add_format(format"OMETIFF", detect_ometiff, [".tif", ".tiff"], [:OMETIFF])
# normal TIFF
detect_noometiff(io) = detecttiff(io) && !(endswith(io.name, ".ome.tif>") || endswith(io.name, ".ome.tiff>"))
add_format(format"TIFF", detect_noometiff, [".tiff", ".tif"], [:QuartzImageIO, OSX], [:ImageMagick])

# custom skipmagic functions for function-based tiff magic detection
skipmagic(io, ::typeof(detect_ometiff)) = seek(io, 4)
skipmagic(io, ::typeof(detect_noometiff)) = seek(io, 4)

# AVI is a subtype of RIFF, as is WAV
function detectavi(io)
seekstart(io)
Expand Down

0 comments on commit bf2c3b3

Please sign in to comment.