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

Write optimization via caching #33

Merged
merged 5 commits into from
Feb 24, 2021
Merged
Changes from 4 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
12 changes: 8 additions & 4 deletions src/types/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ using Base: @propagate_inbounds
struct DenseTaggedImage{T, N, O <: Unsigned,AA <: AbstractArray} <: AbstractDenseTIFF{T, N}
data::AA
ifds::Vector{IFD{O}}
pagecache::Matrix{UInt8}
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved

function DenseTaggedImage(data::AbstractArray{T, N}, ifds::Vector{IFD{O}}) where {T, N, O}
if N == 3
@assert size(data, 3) == length(ifds)
d1, d2, d3 = size(data)
@assert d3 == length(ifds)
elseif N == 2
d1, d2 = size(data)
@assert length(ifds) == 1
end
new{T, N, O, typeof(data)}(data, ifds)
pagecache = Matrix{UInt8}(undef, d2 * sizeof(T), d1)
new{T, N, O, typeof(data)}(data, ifds, pagecache)
end
end

Expand Down Expand Up @@ -90,8 +94,8 @@ function Base.write(io::Stream, img::DenseTaggedImage)

IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
for (idx, ifd) in enumerate(img.ifds)
data_pos = position(tf.io) # start of data

write(tf, reinterpret(UInt8, permutedims(view(img.data, :, :, idx), [2, 1]))) # write data
img.pagecache .= reinterpret(UInt8, PermutedDimsArray(view(img.data, :, :, idx), (2, 1)))
write(tf, img.pagecache) # write data
ifd_pos = position(tf.io)

# update record of previous IFD to point to this new IFD
Expand Down