Skip to content

Commit 8914b46

Browse files
authored
Get bit depth from all images in stack (#179)
1 parent 948924c commit 8914b46

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/ImageMagick.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,17 @@ function _metadata(wand)
8181
evendepth = ((depth+1)>>1)<<1
8282
if depth <= 8
8383
if cs == "Gray"
84-
T = getimagechanneldepth(wand, GrayChannel) == 1 ? Bool : N0f8
84+
cdepth = getimagechanneldepth(wand, GrayChannel)
85+
if n > 1
86+
for k = 1:n # while it might seem that this should be 2:n, that doesn't work...
87+
nextimage(wand)
88+
cdepth = max(cdepth, getimagechanneldepth(wand, GrayChannel))
89+
end
90+
resetiterator(wand)
91+
end
92+
T = cdepth == 1 ? Bool : N0f8
8593
else
86-
T = Normed{UInt8,8} # otherwise use 8 fractional bits
94+
T = N0f8 # otherwise use 8 fractional bits
8795
end
8896
elseif depth <= 16
8997
T = Normed{UInt16,evendepth}

test/constructed_images.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using ImageMagick, IndirectArrays, FileIO, OffsetArrays
1+
using ImageMagick, IndirectArrays, FileIO, OffsetArrays, ImageMetadata, ImageTransformations
22
using ImageShow # for show(io, ::MIME, img) & ImageMeta
33
using Test
4-
using ImageCore
4+
using ImageCore, ColorVectorSpace
55
using Random, Base.CoreLogging
66

77
mutable struct TestType end
@@ -139,7 +139,8 @@ mutable struct TestType end
139139
@test D == c
140140
end
141141

142-
@testset "3D TIFF (issue #307)" begin
142+
@testset "3D TIFF" begin
143+
# issue #307
143144
Ar = rand(0x00:0xff, 2, 2, 4)
144145
Ar[1] = 0xff
145146
A = map(x->Gray(N0f8(x,0)), Ar)
@@ -150,6 +151,13 @@ mutable struct TestType end
150151
@test A == B
151152

152153
@test ImageMagick.metadata(fn) == ((2,2,4), Gray{N0f8})
154+
155+
# ensure proper colordepth if first image is black
156+
A = cat(N0f8[0 0; 0 0], N0f8[0 0.2; 0.4 0.8]; dims=3)
157+
fn = joinpath(workdir, "3dblack.tif")
158+
ImageMagick.save(fn, A)
159+
B = ImageMagick.load(fn)
160+
@test A == B
153161
end
154162

155163
@testset "16-bit TIFF (issue #49)" begin

0 commit comments

Comments
 (0)