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

Fix kwarg pass-through #38

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
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