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

Fix "tmp not defined" in exportimagepixels!() #176

Merged
merged 2 commits into from
Jan 13, 2020
Merged
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
5 changes: 3 additions & 2 deletions src/libmagickwand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,12 @@ bitdepth(buffer::AbstractArray{C}) where {C<:Colorant} = 8*sizeof(eltype(C))
bitdepth(buffer::AbstractArray{T}) where {T} = 8*sizeof(T)

# colorspace is included for consistency with constituteimage, but it is not used
function exportimagepixels!(@nospecialize(buffer::AbstractArray{<:Union{Unsigned,Bool}}), wand::MagickWand, colorspace::String, channelorder::String; x = 0, y = 0)
function exportimagepixels!(@nospecialize(buffer::AbstractArray{<:Union{Unsigned,Bool}}), wand::MagickWand, colorspace::String, channelorder::String; x = 0, y = 0)
T = eltype(buffer)
cols, rows, nimages = getsize(buffer, channelorder)
ncolors = colorsize(buffer, channelorder)
if isa(buffer, Array)
tmp = nothing
p = pointer(buffer)
else
tmp = similar(buffer)
Expand All @@ -225,7 +226,7 @@ function exportimagepixels!(@nospecialize(buffer::AbstractArray{<:Union{Unsigned
status == 0 && error(wand)
p += sizeof(T)*cols*rows*ncolors
end
isa(buffer, Array) || buffer .= tmp
isa(buffer, Array) || (buffer .= tmp)
buffer
end

Expand Down
26 changes: 26 additions & 0 deletions test/constructed_images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,30 @@ mutable struct TestType end
B = ImageMagick.load(fn, true)
@test transpose(A)==B
end

@testset "exportimagepixels!()" begin
# test the direct use of exportimagepixels!()
Ar = [0x10 0xff 0x80; 0x00 0x00 0x20]
A = Gray.(N0f8.(Ar, 0))
fn = joinpath(workdir, "2d.tif")
ImageMagick.save(fn, A, false)

wand = MagickWand()
readimage(wand, fn)
@test ImageMagick.getnumberimages(wand) == 1
ImageMagick.resetiterator(wand)
sz, T, cs, channelorder = ImageMagick._metadata(wand)
@test sz == size(Ar)
@test T == Gray{N0f8}
# test using the array
buf = Array{UInt8}(undef, sz)
exportimagepixels!(buf, wand, cs, channelorder)
@test buf == Ar

# test using the subarray
buf2 = similar(buf, ntuple(i -> i <= length(sz) ? sz[i] + 1 : 2, length(sz) + 1))
buf2view = view(buf2, 1:sz[1], 1:sz[2], 2)
exportimagepixels!(buf2view, wand, cs, channelorder)
@test buf2view == Ar
end
end