From 891c98d1c17be17ce1cdfe4b17ffab13c2d814e9 Mon Sep 17 00:00:00 2001 From: Alexey Stukalov Date: Sun, 12 Jan 2020 17:29:22 +0100 Subject: [PATCH 1/2] fix syntax that leads to "tmp not defined" error || has higher priority than .= - actually define tmp always - add tests for the direct use of exportimagepixels!() --- src/libmagickwand.jl | 3 ++- test/constructed_images.jl | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/libmagickwand.jl b/src/libmagickwand.jl index c91fb9b..8ff7fa8 100644 --- a/src/libmagickwand.jl +++ b/src/libmagickwand.jl @@ -214,6 +214,7 @@ function exportimagepixels!(@nospecialize(buffer::AbstractArray{<:Union{Unsigned cols, rows, nimages = getsize(buffer, channelorder) ncolors = colorsize(buffer, channelorder) if isa(buffer, Array) + tmp = nothing p = pointer(buffer) else tmp = similar(buffer) @@ -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 diff --git a/test/constructed_images.jl b/test/constructed_images.jl index 8406608..bb1eb0c 100755 --- a/test/constructed_images.jl +++ b/test/constructed_images.jl @@ -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 From d2a9db3657e33b954dc92fb7ed309ce0d551d388 Mon Sep 17 00:00:00 2001 From: Alexey Stukalov Date: Mon, 13 Jan 2020 10:42:49 +0100 Subject: [PATCH 2/2] fix whitespace --- src/libmagickwand.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libmagickwand.jl b/src/libmagickwand.jl index 8ff7fa8..7144827 100644 --- a/src/libmagickwand.jl +++ b/src/libmagickwand.jl @@ -209,7 +209,7 @@ 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)