Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 2 additions & 20 deletions src/ImageMagick.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,7 @@ import Compat.String
using FixedPointNumbers, ColorTypes, Images, ColorVectorSpace
using FileIO: DataFormat, @format_str, Stream, File, filename, stream

export MagickWand
export constituteimage
export exportimagepixels!
export getblob
export getimagealphachannel
export getimagecolorspace
export getimagedepth
export getnumberimages
export importimagepixels
export readblob
export readimage
export resetiterator
export setimagecolorspace
export setimagecompression
export setimagecompressionquality
export setimageformat
export writeimage
export image2wand

include("libmagickwand.jl")
Expand Down Expand Up @@ -71,8 +55,6 @@ load{T <: DataFormat}(imgstream::Stream{T}, args...; key_args...) = load_(stream
load(imgstream::IO, args...; key_args...) = load_(imgstream, args...; key_args...)
save{T <: DataFormat}(imgstream::Stream{T}, args...; key_args...) = save_(imgstream, args...; key_args...)

const ufixedtype = Dict(10=>UFixed10, 12=>UFixed12, 14=>UFixed14, 16=>UFixed16)

readblob(data::Vector{UInt8}) = load_(data)

function load_(file::Union{AbstractString,IO,Vector{UInt8}}; ImageType=Image, extraprop="", extrapropertynames=false)
Expand All @@ -98,11 +80,11 @@ function load_(file::Union{AbstractString,IO,Vector{UInt8}}; ImageType=Image, ex
cs = "Gray"
end

depth = getimagechanneldepth(wand, DefaultChannels)
depth = getimagedepth(wand)
if depth <= 8
T = UFixed8 # always use 8-bit for 8-bit and less
else
T = ufixedtype[2*((depth+1)>>1)] # always use an even # of bits (see issue 242#issuecomment-68845157)
T = UFixed{UInt16,((depth+1)>>1)<<1} # always use an even # of bits (see issue 242#issuecomment-68845157)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If ImageMagick ever supports images with more than 16 bits (does it now?), getting rid of the dictionary will make this harder to support. Any particular reason for hardcoding it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supporting >16-bit depths would be easier i think by changing the existing else clause to an elseif depth <= 16 and then adding logic for UFixed{UInt32,..} in a subsequent else clause. i figured we'd do that when the time came, but we could add that now if you want. i don't know whether ImageMagick currently supports it or not.

moreover, the dict uses notation that will be deprecated by JuliaMath/FixedPointNumbers.jl#51.

end

channelorder = cs
Expand Down
10 changes: 5 additions & 5 deletions src/libmagickwand.jl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export MagickWand,
getimagecolorspace,
getimagedepth,
getnumberimages,
importimagepixels,
#importimagepixels,
readimage,
resetiterator,
setimagecolorspace,
Expand Down Expand Up @@ -147,13 +147,13 @@ destroypixelwand(wand::PixelWand) = ccall((:DestroyPixelWand, libwand), Ptr{Void
const IMExceptionType = Array(Cint, 1)
function error(wand::MagickWand)
pMsg = ccall((:MagickGetException, libwand), Ptr{UInt8}, (Ptr{Void}, Ptr{Cint}), wand.ptr, IMExceptionType)
msg = bytestring(pMsg)
msg = unsafe_string(pMsg)
relinquishmemory(pMsg)
error(msg)
end
function error(wand::PixelWand)
pMsg = ccall((:PixelGetException, libwand), Ptr{UInt8}, (Ptr{Void}, Ptr{Cint}), wand.ptr, IMExceptionType)
msg = bytestring(pMsg)
msg = unsafe_string(pMsg)
relinquishmemory(pMsg)
error(msg)
end
Expand Down Expand Up @@ -374,13 +374,13 @@ function queryoptions(pattern::AbstractString)
pops = ccall((:MagickQueryConfigureOptions, libwand), Ptr{Ptr{UInt8}}, (Ptr{UInt8}, Ptr{Cint}), pattern, nops)
ret = Array(Compat.ASCIIString, nops[1])
for i = 1:nops[1]
ret[i] = bytestring(unsafe_load(pops, i))
ret[i] = unsafe_string(unsafe_load(pops, i))
end
ret
end

# queries the value of a particular option
function queryoption(option::AbstractString)
p = ccall((:MagickQueryConfigureOption, libwand), Ptr{UInt8}, (Ptr{UInt8},), option)
bytestring(p)
unsafe_string(p)
end
11 changes: 11 additions & 0 deletions test/constructed_images.jl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ facts("IO") do
@fact A --> B
end

context("16-bit TIFF (issue #49)") do
Ar = rand(0x0000:0xffff, 2, 2, 4)
Ar[1] = 0xffff
A = Image(map(x->Gray(UFixed16(x,0)), Ar); colorspace="Gray", spatialorder=["x", "y"], timedim=3) # grayim does not use timedim, but load does...
fn = joinpath(workdir, "3d16.tif")
ImageMagick.save(fn, A)
B = ImageMagick.load(fn)

@fact A --> B
end

context("Clamping (issue #256)") do
Ar = rand(2,2)
Ar[1] = 1
Expand Down