diff --git a/src/registry.jl b/src/registry.jl index 7628c8b..1e1bf1c 100644 --- a/src/registry.jl +++ b/src/registry.jl @@ -392,6 +392,16 @@ add_format(format"OMETIFF", detect_ometiff, [".tif", ".tiff"], [:OMETIFF => UUID skipmagic(io, ::typeof(detect_ometiff)) = seek(io, 4) skipmagic(io, ::typeof(detect_noometiff)) = seek(io, 4) +# DICOM: DICOM files should begin with a 128-bytes (which are ignored) followed by the string DICM +const dicommagic = UInt8['D', 'I', 'C', 'M'] +function detectdicom(io) + len = getlength(io) + len < 132 && return false + magic = Vector{UInt8}(read(io, 132)[end-3:end]) + magic == dicommagic +end +add_format(format"DCM", detectdicom, [".dcm"], [:ImageMagick => UUID("6218d12a-5da1-5696-b52f-db25d2ecc6d1")]) + # HDF5: the complication is that the magic bytes may start at # 0, 512, 1024, 2048, or any multiple of 2 thereafter const h5magic = [0x89,0x48,0x44,0x46,0x0d,0x0a,0x1a,0x0a] diff --git a/test/files/CT_JPEG70.dcm b/test/files/CT_JPEG70.dcm new file mode 100644 index 0000000..995b949 Binary files /dev/null and b/test/files/CT_JPEG70.dcm differ diff --git a/test/loadsave.jl b/test/loadsave.jl index 7abafb5..85283db 100644 --- a/test/loadsave.jl +++ b/test/loadsave.jl @@ -14,6 +14,7 @@ module TestLoadSave2 import FileIO: File, @format_str fileio_load(file::File{format"HDF5"}) = "HDF5" fileio_load(file::File{format"BIB"}) = "BIB" + fileio_load(file::File{format"DCM"}) = "DCM" end @testset "FakeIO" begin @@ -34,6 +35,7 @@ end add_loader(format"JLD", TestLoadSave) add_loader(format"GZIP", TestLoadSave) add_loader(format"BIB", TestLoadSave2) + add_loader(format"DCM", TestLoadSave2) @test load(joinpath(fp,"file1.pbm")) == "PBMText" @test load(joinpath(fp,"file2.pbm")) == "PBMBinary" @@ -53,6 +55,8 @@ end @test load(joinpath(fp,"file.csv.gz")) == "GZIP" # Bibliography file saved with .bib extension @test load(joinpath(fp,"file.bib")) == "BIB" + # DICOM file saved with .dcm extension + @test load(joinpath(fp,"CT_JPEG70.dcm")) == "DCM" @test_throws Exception load("missing.fmt") end finally diff --git a/test/query.jl b/test/query.jl index 4024af0..1c23105 100644 --- a/test/query.jl +++ b/test/query.jl @@ -516,6 +516,11 @@ let file_dir = joinpath(@__DIR__, "files"), file_path = Path(file_dir) q = query(joinpath(file_dir, "file.bib")) @test typeof(q) <: File{format"BIB"} end + + @testset "DICOM detection" begin + q = query(joinpath(file_dir, "CT_JPEG70.dcm")) + @test typeof(q) <: File{format"DCM"} + end end @testset "Query from IOBuffer" begin