diff --git a/src/types/lazy.jl b/src/types/lazy.jl index 23b1c2c..2da0196 100644 --- a/src/types/lazy.jl +++ b/src/types/lazy.jl @@ -39,6 +39,11 @@ mutable struct LazyBufferedTIFF{T <: ColorOrTuple, O <: Unsigned, AA <: Abstract """ An internal cache to fill reading from disk """ + working_cache::AA + + """ + An internal cache to fill with fully transformed data + """ cache::AA """ @@ -57,7 +62,7 @@ mutable struct LazyBufferedTIFF{T <: ColorOrTuple, O <: Unsigned, AA <: Abstract readonly::Bool function LazyBufferedTIFF(file::TiffFile{O}, ifds::Vector{IFD{O}}, dims, cache::AA, cache_index::Int, last_ifd_offset::O, readonly::Bool) where {O, AA <: AbstractArray} - new{eltype(cache), O, typeof(cache)}(file, ifds, dims, cache, cache_index, last_ifd_offset, readonly) + new{eltype(cache), O, typeof(cache)}(file, ifds, dims, cache, cache, cache_index, last_ifd_offset, readonly) end end @@ -124,9 +129,9 @@ function Base.getindex(A::LazyBufferedTIFF{T, O, AA}, i1::Int, i2::Int, i::Int) A.file.io = getstream(format"TIFF", open(path), path) end - read!(A.cache, A.file, ifd) + read!(A.working_cache, A.file, ifd) - A.cache = transform(A.cache, ifd) + A.cache = transform(A.working_cache, ifd) A.cache_index = i end diff --git a/test/runtests.jl b/test/runtests.jl index 7fcfae1..ddda950 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -222,8 +222,14 @@ end @testset "Tiled" begin uncompressed = get_example("shapes_uncompressed.tif") compressed_tiled = get_example("shapes_lzw_tiled.tif") - @test TiffImages.load(uncompressed) == TiffImages.load(compressed_tiled) - @test TiffImages.load(uncompressed)[:] == TiffImages.load(compressed_tiled; lazyio=true)[:] + compressed_tiled_multi = get_example("shapes_tiled_multi.tif") + uncompressed_loaded = TiffImages.load(uncompressed) + compressed_tiled_multi_loaded = TiffImages.load(compressed_tiled_multi; lazyio=true) + @test uncompressed_loaded == TiffImages.load(compressed_tiled) + @test uncompressed_loaded[:] == TiffImages.load(compressed_tiled; lazyio=true)[:] + @test compressed_tiled_multi_loaded[:,:,1] == uncompressed_loaded + @test compressed_tiled_multi_loaded[:,:,2] == uncompressed_loaded + @test compressed_tiled_multi_loaded[:,:,3] == uncompressed_loaded end @testset "Planar" begin