Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .dcm files #370

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/registry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Binary file added test/files/CT_JPEG70.dcm
Binary file not shown.
4 changes: 4 additions & 0 deletions test/loadsave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading