Skip to content

Commit

Permalink
refactor getindex() for LazyBufferedTIFF
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstphrbrns committed Jun 1, 2024
1 parent c164410 commit 5633714
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/types/lazy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,21 @@ offset(::LazyBufferedTIFF{T, O, AA}) where {T, O, AA} = O
function Base.getindex(A::LazyBufferedTIFF{T, O, AA}, i1::Int, i2::Int, i::Int) where {T, O, AA}
(size(A) == (0, 0, 0)) && error("This image has not been initialized, please `push!` data into it first")
# check the loaded cache is already the correct slice
if A.cache_index == i
return A.cache[i1, i2]
end

ifd = ifds(A)[i]
if A.cache_index != i
ifd = ifds(A)[i]

# if the file isn't open, lets open a handle and update it
if !isopen(A.file.io)
path = A.file.filepath
A.file.io = getstream(format"TIFF", open(path), path)
end
# if the file isn't open, lets open a handle and update it
if !isopen(A.file.io)
path = A.file.filepath
A.file.io = getstream(format"TIFF", open(path), path)
end

read!(A.cache, A.file, ifd)
read!(A.cache, A.file, ifd)

A.cache = Matrix(transform(A.cache, ifd))
A.cache = transform(A.cache, ifd)

A.cache_index = i
A.cache_index = i
end

return A.cache[i1, i2]
end
Expand Down

0 comments on commit 5633714

Please sign in to comment.