Skip to content

Commit 046a170

Browse files
committed
More round-trip tests. All pass.
1 parent 423c311 commit 046a170

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

test/runtests.jl

+46-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
using Test, OpenEXR, FileIO, Colors, FixedPointNumbers
22

3+
# helpers for testing channelwise bit-depth truncation
4+
function channelwise_max_diff(a::RGBA, b::RGBA)
5+
max(abs(a.r - b.r), abs(a.g - b.g), abs(a.b - b.b), abs(a.alpha - b.alpha))
6+
end
7+
8+
function channelwise_max_diff(a::RGB, b::RGB)
9+
max(abs(a.r - b.r), abs(a.g - b.g), abs(a.b - b.b))
10+
end
11+
12+
function channelwise_max_diff(a::GrayA, b::GrayA)
13+
max(abs(a.val - b.val), abs(a.alpha - b.alpha))
14+
end
15+
16+
function channelwise_max_diff(a::Gray, b::Gray)
17+
abs(a.val - b.val)
18+
end
19+
320
@testset "RoundTrip" begin
421

522
@testset "Identical" begin
@@ -31,7 +48,7 @@ using Test, OpenEXR, FileIO, Colors, FixedPointNumbers
3148
loaded_img = OpenEXR.load(fn)
3249
@test typeof(loaded_img) === Array{load_type,2}
3350
converted_img = (c -> convert(save_type, c)).(loaded_img)
34-
@test converted_img == loaded_img
51+
@test converted_img == img
3552
finally
3653
rm(fn.filename)
3754
end
@@ -41,7 +58,6 @@ using Test, OpenEXR, FileIO, Colors, FixedPointNumbers
4158
@testset "Lossy with type conversion" begin
4259

4360
@testset "Bit depth truncation" begin
44-
4561
for (save_type, load_type) in (
4662
(RGBA{Float32}, RGBA{Float16}),
4763
(RGB{Float32}, RGB{Float16}),
@@ -53,9 +69,35 @@ using Test, OpenEXR, FileIO, Colors, FixedPointNumbers
5369
OpenEXR.save(fn, img)
5470
try
5571
loaded_img = OpenEXR.load(fn)
72+
73+
# return type is as expected
5674
@test typeof(loaded_img) === Array{load_type,2}
57-
diffs = map(colordiff, color.(img), color.(loaded_img))
58-
@test diffs zeros(size(diffs)) rtol = 1e-10
75+
76+
# differences are bounded channelwise
77+
diffs = map(channelwise_max_diff, img, loaded_img)
78+
@test maximum(diffs) <= 2.5e-4
79+
finally
80+
rm(fn.filename)
81+
end
82+
end
83+
end
84+
85+
@testset "Colorspace conversion" begin
86+
for save_type in
87+
(HSV{Float16}, HSL{Float16}, Lab{Float16}, LCHab{Float16}, YIQ{Float16})
88+
img = rand(save_type, 256, 512)
89+
fn = File{DataFormat{:EXR}}(tempname())
90+
OpenEXR.save(fn, img)
91+
try
92+
loaded_img = OpenEXR.load(fn)
93+
94+
# return type is as expected
95+
@test typeof(loaded_img) === Array{RGB{Float16},2}
96+
97+
# differences are bounded channelwise
98+
converted_img = (c -> convert(RGB{Float16}, c)).(img)
99+
diffs = map(channelwise_max_diff, converted_img, loaded_img)
100+
@test maximum(diffs) <= 2.5e-4
59101
finally
60102
rm(fn.filename)
61103
end

0 commit comments

Comments
 (0)