Skip to content

Commit 251aa1b

Browse files
authored
Merge pull request #73 from tlnagy/tn/rework-file-ifd-offset-tracking
rework per-file IFD offset tracking, fixes #72
2 parents ddec999 + 53c9d12 commit 251aa1b

File tree

5 files changed

+8717
-10
lines changed

5 files changed

+8717
-10
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "OMETIFF"
22
uuid = "2d0ec36b-e807-5756-994b-45af29551fcf"
33
authors = ["Tamas Nagy <[email protected]>"]
4-
version = "0.3.7"
4+
version = "0.3.8"
55

66
[deps]
77
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"

src/loader.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function load(io::Stream{format"OMETIFF"}; dropunused=true, inmemory=true)
6565

6666
ifd_indices = OrderedDict{Int, NTuple{4, Int}}()
6767
ifd_files = OrderedDict{Int, Tuple{String, String}}()
68-
obs_filepaths = Set{String}()
68+
obs_filepaths = Dict{String, Int}()
6969
for (idx, container) in enumerate(containers)
7070
OMETIFF.ifdindex!(ifd_indices, ifd_files, obs_filepaths, container, dimlist[idx], orig_file, idx)
7171
end

src/parsing.jl

+9-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ these IFDs are located in) inside the TIFF image.
3131
dimensions
3232
- `ifd_files::OrderedDict{Int, Tuple{String, String}}`: A mapping from IFD
3333
number to the filepath and UUID of the file it's located in
34-
- `obs_filepaths::Set{String}`: A list of observed filepaths
34+
- `obs_filepaths::Dict{String, Int}`: A list of observed filepaths mapped to the offset of their IFDs
3535
- `image::EzXML.Node`: The OMEXML rooted at the current position
3636
- `dims::NamedTuple`: Sizes of each dimension with the names as keys
3737
- `tifffile::TiffFile`: A pointer to the root file
@@ -42,7 +42,7 @@ The first two parameters should be then pumped through
4242
"""
4343
function ifdindex!(ifd_index::OrderedDict{Int, NTuple{4, Int}},
4444
ifd_files::OrderedDict{Int, Tuple{String, String}},
45-
obs_filepaths::Set{String},
45+
obs_filepaths::Dict{String, Int},
4646
image::EzXML.Node,
4747
dims::NamedTuple,
4848
tifffile::TiffFile,
@@ -53,7 +53,7 @@ function ifdindex!(ifd_index::OrderedDict{Int, NTuple{4, Int}},
5353
ifd = 1
5454
# this is an offset value since multiple ifds can share the same index if
5555
# they are split across files, IFD1 (File1), IFD1 (File2), etc
56-
file_ifd_offset = 1
56+
prev_ifd = 0
5757
for tiffdata in tiffdatas
5858
try # if this tiffdata specifies the corresponding IFD
5959
ifd = parse(Int, tiffdata["IFD"]) + 1
@@ -79,11 +79,12 @@ function ifdindex!(ifd_index::OrderedDict{Int, NTuple{4, Int}},
7979
filepath = joinpath(dirname(tifffile.filepath), internal_filename)
8080

8181
# if this file isn't one we've observed before, increment the offset
82-
if !in(filepath, obs_filepaths)
83-
ifd = file_ifd_offset
84-
file_ifd_offset += 1
85-
push!(obs_filepaths, filepath)
82+
if !in(filepath, keys(obs_filepaths))
83+
obs_filepaths[filepath] = prev_ifd
8684
end
85+
86+
ifd += obs_filepaths[filepath]
87+
8788
ifd_files[ifd] = (uuid, filepath)
8889
end
8990

@@ -112,6 +113,7 @@ function ifdindex!(ifd_index::OrderedDict{Int, NTuple{4, Int}},
112113
# all the indices that are not specified, we assume the first index
113114
ifd_index[ifd] = Tuple(pos > 0 ? pos : 1 for pos in indices)
114115
end
116+
prev_ifd = ifd
115117
end
116118
end
117119

0 commit comments

Comments
 (0)