Skip to content

Commit

Permalink
modularize load code for OMETIFF accessibility (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlnagy authored Oct 21, 2021
1 parent bbd032d commit a1f00c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TiffImages"
uuid = "731e570b-9d59-4bfa-96dc-6df516fadf69"
authors = ["Tamas Nagy <[email protected]>"]
version = "0.5.0"
version = "0.5.1"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand Down
23 changes: 16 additions & 7 deletions src/load.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,32 @@ function load(tf::TiffFile; verbose=true, mmap = false)
loaded = load(tf, ifds, nplanes; verbose=verbose)
end
end
data = fixcolors(loaded, first(ifds))

close(tf.io)
return DenseTaggedImage(data, ifds)
end

"""
fixcolors(loaded, ifd)
Wrap the raw eltype of an image with color if needed, e.g. for space efficient
on-disk representations like palette-colored images and bitarrays. Otherwise,
just return the passed image.
"""
function fixcolors(loaded, ifd)
if eltype(loaded) <: Palette
ifd = ifds[1]
raw = rawtype(ifd)
loadedr = reinterpret(raw, loaded)
maxdepth = 2^(Int(ifd[BITSPERSAMPLE].data))-1
colors = ifd[COLORMAP].data
color_map = vec(reinterpret(RGB{N0f16}, reshape(colors, :, 3)'))
data = IndirectArray(loadedr, OffsetArray(color_map, 0:maxdepth))
return IndirectArray(loadedr, OffsetArray(color_map, 0:maxdepth))
elseif eltype(loaded) <: Bool
data = Gray.(loaded)
return Gray.(loaded)
else
data = loaded
return loaded
end

close(tf.io)
return DenseTaggedImage(data, ifds)
end

function load(tf::TiffFile, ifds::AbstractVector{<:IFD}, ::Nothing; verbose = true)
Expand Down

2 comments on commit a1f00c1

@tlnagy
Copy link
Owner Author

@tlnagy tlnagy commented on a1f00c1 Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/47144

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.1 -m "<description of version>" a1f00c1eb0b2be35594e364470278cbfc6a31b7e
git push origin v0.5.1

Please sign in to comment.