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

Adds GIF format to ImageIO #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.6.6"

[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GIFImages = "7064036c-d33e-4a25-b247-cf6150d8ad81"
IndirectArrays = "9b13fd28-a010-5f03-acff-a1bbcff69959"
JpegTurbo = "b835a17e-a41a-41e7-81f0-2f016b05efe0"
LazyModules = "8cdb02fc-e678-4876-92c5-9defec4f444e"
Expand All @@ -18,6 +19,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
FileIO = "1.2"
GIFImages = "0.1"
ImageCore = "0.8.1, 0.9"
IndirectArrays = "0.5, 1"
JpegTurbo = "0.1"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ FileIO.jl integration for image files

| Format | Extensions | Provider | Implementation | Comment |
| ------- | ---------- | -------- | ---- | ----------- |
| GIF | `.gif` | [GIFImages.jl](https://github.com/JuliaIO/GIFImages.jl) | Julia wrapper of [giflib](https://sourceforge.net/projects/giflib/) | |
| JPEG | `.jpg`, `.jpeg` | [JpegTurbo.jl](https://github.com/johnnychen94/JpegTurbo.jl) | Julia wrapper of [libjpeg-turbo](https://github.com/libjpeg-turbo/libjpeg-turbo) | [Benchmark results against other backends](https://github.com/johnnychen94/JpegTurbo.jl/issues/15) |
| [OpenEXR](https://www.openexr.com/) | `.exr` | [OpenEXR.jl](https://github.com/twadleigh/OpenEXR.jl) | Julia wrapper of [OpenEXR](https://github.com/AcademySoftwareFoundation/openexr) | |
| Portable Bitmap formats | `.pbm`, `.pgm`, `.ppm` | [Netpbm.jl](https://github.com/JuliaIO/Netpbm.jl) | pure Julia | |
Expand Down
17 changes: 16 additions & 1 deletion src/ImageIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using LazyModules # @lazy macro is used to delay the package loading to its firs
@lazy import OpenEXR = "52e1d378-f018-4a11-a4be-720524705ac7"
@lazy import QOI = "4b34888f-f399-49d4-9bb3-47ed5cae4e65"
@lazy import JpegTurbo = "b835a17e-a41a-41e7-81f0-2f016b05efe0"
@lazy import GIFImages = "7064036c-d33e-4a25-b247-cf6150d8ad81"

# Enforce a type conversion to be backend independent (issue #25)
# Note: If the backend does not provide efficient `convert` implementation,
Expand All @@ -24,7 +25,8 @@ for FMT in (
:EXR,
:QOI,
:SIXEL,
:JPEG
:JPEG,
:GIF
)
@eval canonical_type(::DataFormat{$(Expr(:quote, FMT))}, ::AbstractArray{T, N}) where {T,N} =
Array{T,N}
Expand Down Expand Up @@ -186,6 +188,19 @@ function save(s::Stream{DataFormat{:JPEG}}, image::AbstractArray; kwargs...)
JpegTurbo.fileio_save(s, image; kwargs...)
end

# GIF
function load(f::File{DataFormat{:GIF}}; kwargs...)
data = GIFImages.fileio_load(f, kwargs...)
return enforce_canonical_type(f, data)
end
function load(s::Stream{DataFormat{:GIF}}; kwargs...)
data = GIFImages.fileio_load(s, kwargs...)
return enforce_canonical_type(s, data)
end
function save(f::File{DataFormat{:GIF}}, image::AbstractArray; kwargs...)
GIFImages.fileio_save(f, image; kwargs...)
end

## Function names labelled for FileIO. Makes FileIO lookup quicker
const fileio_save = save
const fileio_load = load
Expand Down
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,18 @@ Threads.nthreads() <= 1 && @info "Threads.nthreads() = $(Threads.nthreads()), mu
end
end
end

@testset "GIF" begin
for typ in [Gray{N0f8}, Gray{Float64}, RGB{N0f8}, RGB{Float64}]
@testset "$typ GIF" begin
img = repeat(typ.(0:0.1:0.9), inner=(10, 50))
f = File{format"GIF"}(joinpath(tmpdir, "test_fpath.gif"))
ImageIO.save(f, img)
img_saveload = ImageIO.load(f)
@test eltype(img_saveload) == n0f8(typ)
@test assess_psnr(img, eltype(img).(img_saveload)) > 51
@test typeof(img_saveload) == ImageIO.canonical_type(f, img_saveload)
end
end
end
end