Skip to content

Commit 6bbb8f4

Browse files
alysttimholy
authored andcommitted
Fix "tmp not defined" in exportimagepixels!() (#176)
1 parent 3a9ea3c commit 6bbb8f4

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/libmagickwand.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,12 @@ bitdepth(buffer::AbstractArray{C}) where {C<:Colorant} = 8*sizeof(eltype(C))
209209
bitdepth(buffer::AbstractArray{T}) where {T} = 8*sizeof(T)
210210

211211
# colorspace is included for consistency with constituteimage, but it is not used
212-
function exportimagepixels!(@nospecialize(buffer::AbstractArray{<:Union{Unsigned,Bool}}), wand::MagickWand, colorspace::String, channelorder::String; x = 0, y = 0)
212+
function exportimagepixels!(@nospecialize(buffer::AbstractArray{<:Union{Unsigned,Bool}}), wand::MagickWand, colorspace::String, channelorder::String; x = 0, y = 0)
213213
T = eltype(buffer)
214214
cols, rows, nimages = getsize(buffer, channelorder)
215215
ncolors = colorsize(buffer, channelorder)
216216
if isa(buffer, Array)
217+
tmp = nothing
217218
p = pointer(buffer)
218219
else
219220
tmp = similar(buffer)
@@ -225,7 +226,7 @@ function exportimagepixels!(@nospecialize(buffer::AbstractArray{<:Union{Unsigned
225226
status == 0 && error(wand)
226227
p += sizeof(T)*cols*rows*ncolors
227228
end
228-
isa(buffer, Array) || buffer .= tmp
229+
isa(buffer, Array) || (buffer .= tmp)
229230
buffer
230231
end
231232

test/constructed_images.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,30 @@ mutable struct TestType end
301301
B = ImageMagick.load(fn, true)
302302
@test transpose(A)==B
303303
end
304+
305+
@testset "exportimagepixels!()" begin
306+
# test the direct use of exportimagepixels!()
307+
Ar = [0x10 0xff 0x80; 0x00 0x00 0x20]
308+
A = Gray.(N0f8.(Ar, 0))
309+
fn = joinpath(workdir, "2d.tif")
310+
ImageMagick.save(fn, A, false)
311+
312+
wand = MagickWand()
313+
readimage(wand, fn)
314+
@test ImageMagick.getnumberimages(wand) == 1
315+
ImageMagick.resetiterator(wand)
316+
sz, T, cs, channelorder = ImageMagick._metadata(wand)
317+
@test sz == size(Ar)
318+
@test T == Gray{N0f8}
319+
# test using the array
320+
buf = Array{UInt8}(undef, sz)
321+
exportimagepixels!(buf, wand, cs, channelorder)
322+
@test buf == Ar
323+
324+
# test using the subarray
325+
buf2 = similar(buf, ntuple(i -> i <= length(sz) ? sz[i] + 1 : 2, length(sz) + 1))
326+
buf2view = view(buf2, 1:sz[1], 1:sz[2], 2)
327+
exportimagepixels!(buf2view, wand, cs, channelorder)
328+
@test buf2view == Ar
329+
end
304330
end

0 commit comments

Comments
 (0)