Skip to content

Commit

Permalink
Fix kwarg pass-through (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Aug 24, 2021
1 parent 16204e5 commit 392e58a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ImageIO"
uuid = "82e4d734-157c-48bb-816b-45c225c6df19"
authors = ["Ian Butterworth"]
version = "0.5.7"
version = "0.5.8"

[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Expand Down
16 changes: 8 additions & 8 deletions src/ImageIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@ function checked_import(pkgid)
end

function load(f::File{DataFormat{:PNG}}; kwargs...)
data = Base.invokelatest(checked_import(idPNGFiles).load, f.filename, kwargs...)
data = Base.invokelatest(checked_import(idPNGFiles).load, f.filename; kwargs...)
return enforece_canonical_type(f, data)
end
function load(s::Stream{DataFormat{:PNG}}; kwargs...)
data = Base.invokelatest(checked_import(idPNGFiles).load, stream(s), kwargs...)
data = Base.invokelatest(checked_import(idPNGFiles).load, stream(s); kwargs...)
return enforece_canonical_type(s, data)
end

function save(f::File{DataFormat{:PNG}}, image::S; kwargs...) where {T, S<:Union{AbstractMatrix, AbstractArray{T,3}}}
return Base.invokelatest(checked_import(idPNGFiles).save, f.filename, image, kwargs...)
return Base.invokelatest(checked_import(idPNGFiles).save, f.filename, image; kwargs...)
end

function save(s::Stream{DataFormat{:PNG}}, image::S; permute_horizontal=false, mapi=identity, kwargs...) where {T, S<:Union{AbstractMatrix, AbstractArray{T,3}}}
imgout = map(mapi, image)
if permute_horizontal
perm = ndims(imgout) == 2 ? (2, 1) : ndims(imgout) == 3 ? (2, 1, 3) : error("$(ndims(imgout)) dims array is not supported")
return Base.invokelatest(checked_import(idPNGFiles).save, stream(s), PermutedDimsArray(imgout, perm), kwargs...)
return Base.invokelatest(checked_import(idPNGFiles).save, stream(s), PermutedDimsArray(imgout, perm); kwargs...)
else
return Base.invokelatest(checked_import(idPNGFiles).save, stream(s), imgout, kwargs...)
return Base.invokelatest(checked_import(idPNGFiles).save, stream(s), imgout; kwargs...)
end
end

Expand Down Expand Up @@ -99,11 +99,11 @@ end
## TIFFs

function load(f::File{DataFormat{:TIFF}}; kwargs...)
data = Base.invokelatest(checked_import(idTiffImages).load, f.filename, kwargs...)
data = Base.invokelatest(checked_import(idTiffImages).load, f.filename; kwargs...)
return enforece_canonical_type(f, data)
end
function load(s::Stream{DataFormat{:TIFF}}; kwargs...)
data = Base.invokelatest(checked_import(idTiffImages).load, stream(s), kwargs...)
data = Base.invokelatest(checked_import(idTiffImages).load, stream(s); kwargs...)
return enforece_canonical_type(s, data)
end

Expand All @@ -124,7 +124,7 @@ end
## OpenEXR

function load(f::File{DataFormat{:EXR}}; kwargs...)
data = Base.invokelatest(checked_import(idOpenEXR).load, f, kwargs...)
data = Base.invokelatest(checked_import(idOpenEXR).load, f; kwargs...)
return enforece_canonical_type(f, data)
end

Expand Down
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Threads.nthreads() <= 1 && @info "Threads.nthreads() = $(Threads.nthreads()), mu
@test img == img_saveload
end
@test typeof(img_saveload) == ImageIO.canonical_type(f, img_saveload)
img_saveload = ImageIO.load(f; gamma=1.0)
if typ == UInt8
@test all(img .== reinterpret(UInt8, img_saveload))
else
@test img == img_saveload
end

open(io->ImageIO.save(Stream{format"PNG"}(io), img, permute_horizontal=false), joinpath(tmpdir, "test_io.png"), "w")
img_saveload = open(io->ImageIO.load(Stream{format"PNG"}(io)), joinpath(tmpdir, "test_io.png"))
Expand All @@ -39,6 +45,14 @@ Threads.nthreads() <= 1 && @info "Threads.nthreads() = $(Threads.nthreads()), mu
@test img == img_saveload
end
@test typeof(img_saveload) == ImageIO.canonical_type(f, img_saveload)

ImageIO.save(f, img; compression_level=1)
img_saveload = ImageIO.load(f)
if typ == UInt8
@test all(img .== reinterpret(UInt8, img_saveload))
else
@test img == img_saveload
end
end
end
end
Expand Down Expand Up @@ -102,6 +116,8 @@ Threads.nthreads() <= 1 && @info "Threads.nthreads() = $(Threads.nthreads()), mu
img_saveload = ImageIO.load(f)
@test img == img_saveload
@test typeof(img_saveload) == ImageIO.canonical_type(f, img_saveload)
img_saveload = ImageIO.load(f; mmap=true)
@test img == reshape(img_saveload, size(img))

open(io->ImageIO.save(Stream{format"TIFF"}(io), img), joinpath(tmpdir, "test_io.tiff"), "w")
img_saveload = open(io->ImageIO.load(Stream{format"TIFF"}(io)), joinpath(tmpdir, "test_io.tiff"))
Expand Down

2 comments on commit 392e58a

@timholy
Copy link
Member Author

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/43450

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.8 -m "<description of version>" 392e58a1ff7113a850a9dca7b457820681ccd780
git push origin v0.5.8

Please sign in to comment.