Skip to content

Commit

Permalink
Add OpenEXR (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
twadleigh authored Aug 19, 2021
1 parent 97ff5c0 commit a744bbd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.5.6"
[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Netpbm = "f09324ee-3d7c-5217-9330-fc30815ba969"
OpenEXR = "52e1d378-f018-4a11-a4be-720524705ac7"
PNGFiles = "f57f5aa1-a3ce-4bc8-8ab9-96f992907883"
TiffImages = "731e570b-9d59-4bfa-96dc-6df516fadf69"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Expand All @@ -14,6 +15,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
FileIO = "1.2"
ImageCore = "0.8.1, 0.9"
Netpbm = "1.0"
OpenEXR = "0.3"
PNGFiles = "0.3"
TiffImages = "0.3, 0.4"
julia = "1.3"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Currently provides:
- [PNGFiles.jl](https://github.com/JuliaIO/PNGFiles.jl) for Portable Network Graphics via libpng - ([Benchmark vs. ImageMagick & QuartzImageIO](https://github.com/JuliaIO/PNGFiles.jl/issues/1#issuecomment-586749654))
- [Netpbm.jl](https://github.com/JuliaIO/Netpbm.jl) for Portable Bitmap formats (in pure Julia)
- [TiffImages.jl](https://github.com/tlnagy/TiffImages.jl) for TIFFs (in pure Julia)
- [OpenEXR.jl](https://github.com/twadleigh/OpenEXR.jl) for OpenEXR files (wrapping the C API provided by the [OpenEXR](https://github.com/AcademySoftwareFoundation/openexr) library)


## Installation
Expand Down
13 changes: 13 additions & 0 deletions src/ImageIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using FileIO: File, DataFormat, Stream, stream, Formatted
const idNetpbm = Base.PkgId(UUID("f09324ee-3d7c-5217-9330-fc30815ba969"), "Netpbm")
const idPNGFiles = Base.PkgId(UUID("f57f5aa1-a3ce-4bc8-8ab9-96f992907883"), "PNGFiles")
const idTiffImages = Base.PkgId(UUID("731e570b-9d59-4bfa-96dc-6df516fadf69"), "TiffImages")
const idOpenEXR = Base.PkgId(UUID("52e1d378-f018-4a11-a4be-720524705ac7"), "OpenEXR")

# Enforce a type conversion to be backend independent (issue #25)
# Note: If the backend does not provide efficient `convert` implementation,
Expand All @@ -14,6 +15,7 @@ for FMT in (
:PBMBinary, :PGMBinary, :PPMBinary, :PBMText, :PGMText, :PPMText,
:TIFF,
:PNG,
:EXR,
)
@eval canonical_type(::DataFormat{$(Expr(:quote, FMT))}, ::AbstractArray{T, N}) where {T,N} =
Array{T,N}
Expand Down Expand Up @@ -119,6 +121,17 @@ function save(s::Stream{DataFormat{:TIFF}}, image::S; permute_horizontal=false,
end
end

## OpenEXR

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

function save(f::File{DataFormat{:EXR}}, args...; kwargs...)
Base.invokelatest(checked_import(idOpenEXR).save, f, args...; kwargs...)
end

## Function names labelled for FileIO. Makes FileIO lookup quicker
const fileio_save = save
const fileio_load = load
Expand Down
13 changes: 12 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Test
using ImageIO
using FileIO: File, DataFormat, Stream, @format_str
using ImageCore: N0f8, RGB, Gray
using ImageCore: N0f8, RGB, Gray, RGBA, GrayA

tmpdir = mktempdir()
Threads.nthreads() <= 1 && @info "Threads.nthreads() = $(Threads.nthreads()), multithread tests will be disabled"
Expand Down Expand Up @@ -110,4 +110,15 @@ Threads.nthreads() <= 1 && @info "Threads.nthreads() = $(Threads.nthreads()), mu
end
end
end

@testset "EXR" begin
for typ in [RGBA{Float16}, RGB{Float16}, GrayA{Float16}, Gray{Float16}]
img = rand(typ, 10, 10)
f = File{format"EXR"}(joinpath(tmpdir, "test_fpath.exr"))
ImageIO.save(f, img)
img_saveload = ImageIO.load(f)
@test img == img_saveload
@test typeof(img_saveload) == ImageIO.canonical_type(f, img_saveload)
end
end
end

0 comments on commit a744bbd

Please sign in to comment.