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

Update to ImageMagick 7 library that almost works. #234

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ImageMagick"
uuid = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
version = "1.3.1"
version = "1.4.0"

[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Expand All @@ -11,7 +11,7 @@ InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
[compat]
FileIO = "1"
ImageCore = "0.9, 0.10"
ImageMagick_jll = "= 6.9.11"
ImageMagick_jll = "= 7.1.1"
julia = "1.6"

[extras]
Expand Down
4 changes: 2 additions & 2 deletions src/ImageMagick.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ function _metadata(wand)
evendepth = ((depth+1)>>1)<<1
if depth <= 8
if cs == "Gray"
cdepth = getimagechanneldepth(wand, GrayChannel)
cdepth = getimagedepth(wand)
if n > 1
for k = 1:n # while it might seem that this should be 2:n, that doesn't work...
nextimage(wand)
cdepth = max(cdepth, getimagechanneldepth(wand, GrayChannel))
cdepth = max(cdepth, getimagedepth(wand))
end
resetiterator(wand)
end
Expand Down
55 changes: 50 additions & 5 deletions src/libmagickwand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,50 @@ const IMTypedict = Dict([(IMType[i], i) for i = 1:length(IMType)])
const CStoIMTypedict = Dict("Gray" => "GrayscaleType", "GrayA" => "GrayscaleMatteType", "AGray" => "GrayscaleMatteType", "RGB" => "TrueColorType", "ARGB" => "TrueColorMatteType", "RGBA" => "TrueColorMatteType", "CMYK" => "ColorSeparationType", "I"=>"GrayscaleType", "IA"=>"GrayscaleMatteType", "AI"=>"GrayscaleMatteType", "BGRA"=>"TrueColorMatteType", "ABGR"=>"TrueColorMatteType")

# Colorspace
const IMColorspace = ["RGB", "Gray", "Transparent", "OHTA", "Lab", "XYZ", "YCbCr", "YCC", "YIQ", "YPbPr", "YUV", "CMYK", "sRGB"]
# The colorspace order comes from the C struct definition
# https://github.com/ImageMagick/ImageMagick/blob/e96022d5f377f2a4c0780be9f60ed44535dc5488/MagickCore/colorspace.h#L67
# It starts at 0 with UndefinedColorspace, which is not used in the Julia interface
const IMColorspace = [
"CMY"
"CMYK"
"Gray"
"HCL"
"HCLp"
"HSB"
"HSI"
"HSL"
"HSV"
"HWB"
"Lab"
"LCH"
"LCHab"
"LCHuv"
"Log"
"LMS"
"Luv"
"OHTA"
"Rec601YCbCr"
"Rec709YCbCr"
"RGB"
"scRGB"
"sRGB"
"Transparent"
"xyY"
"XYZ"
"YCbCr"
"YCC"
"YDbDr"
"YIQ"
"YPbPr"
"YUV"
"LinearGRAY"
"Jzazbz"
"DisplayP3"
"Adobe98"
"ProPhoto"
"Oklab"
"Oklch"
]
const IMColordict = Dict([(IMColorspace[i], i) for i = 1:length(IMColorspace)])
for AC in vcat(subtypes(AlphaColor), subtypes(ColorAlpha))
Cstr = ColorTypes.colorant_string(color_type(AC))
Expand Down Expand Up @@ -281,7 +324,12 @@ function readimage(wand::MagickWand, stream::IO)
nothing
end

function readimage(wand::MagickWand, stream::Vector{UInt8})
if VERSION >= v"1.11"
StreamTypes = Union{Vector{UInt8}, Memory{UInt8}}
else
StreamTypes = Vector{UInt8}
end
function readimage(wand::MagickWand, stream::StreamTypes)
status = ccall((:MagickReadImageBlob, libwand), Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Cint), wand, stream, length(stream)*sizeof(eltype(stream)))
status == 0 && error(wand)
nothing
Expand Down Expand Up @@ -426,9 +474,6 @@ end
# get the pixel depth
getimagedepth(wand::MagickWand) = convert(Int, ccall((:MagickGetImageDepth, libwand), Csize_t, (Ptr{Cvoid},), wand))

# pixel depth for given channel type
getimagechanneldepth(wand::MagickWand, channelType::ChannelType) = convert(Int, ccall((:MagickGetImageChannelDepth, libwand), Csize_t, (Ptr{Cvoid}, UInt32), wand, channelType.value))

pixelsetcolor(wand::PixelWand, colorstr::String) = ccall((:PixelSetColor, libwand), Csize_t, (Ptr{Cvoid}, Ptr{UInt8}), wand, colorstr) == 0 && error(wand)

relinquishmemory(p) = ccall((:MagickRelinquishMemory, libwand), Ptr{UInt8}, (Ptr{UInt8},), p)
Expand Down
1 change: 1 addition & 0 deletions test/constructed_images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ mutable struct TestType end
ImageMagick.save(fn, a)
b = ImageMagick.load(fn)
@test eltype(b) == Gray{N0f8}
@test round.(b) == a # JPG is lossy
end

@testset "Gray png" begin
Expand Down
Loading