From 62ed7c1e10d59cb9116f5f73ba3c29c6d3e8e97f Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 24 Aug 2021 07:41:03 -0500 Subject: [PATCH] Fix kwarg pass-through --- Project.toml | 2 +- src/ImageIO.jl | 16 ++++++++-------- test/runtests.jl | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index 5e923d4..0fcce4f 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/ImageIO.jl b/src/ImageIO.jl index 60741f6..0740a5e 100644 --- a/src/ImageIO.jl +++ b/src/ImageIO.jl @@ -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 @@ -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 @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 2e7b4e3..94e009d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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")) @@ -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 @@ -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"))