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

switch to Extensions #12

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*.jl.*.cov
*.jl.cov
*.jl.mem
/Manifest.toml
/docs/Manifest.toml
Manifest.toml
/docs/build/
16 changes: 8 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[weakdeps]
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"

[extensions]
ImageCoreExt = "ImageCore"
StructArraysExt = "StructArrays"

[compat]
ColorTypes = "0.11.2"
ColorVectorSpace = "0.9"
Expand All @@ -22,11 +30,3 @@ FixedPointNumbers = "0.8"
Reexport = "1"
Requires = "1"
julia = "1.6"

[extras]
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["ImageCore", "StructArrays", "Test"]
17 changes: 17 additions & 0 deletions src/imagecore.jl → ext/ImageCoreExt.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
module ImageCoreExt

@static if isdefined(Base, :get_extension)
using ImageCore
else
using ..ImageCore
end

using MultiChannelColors: ColorMixture

# clamp01 is designed to work on RGB colors (a major usage is for display), so convert first
ImageCore.clamp01(c::ColorMixture{T}) where T = convert(RGB{T}, ImageCore.clamp01(convert(RGB{floattype(T)}, c)))
ImageCore.clamp01nan(c::ColorMixture{T}) where T = convert(RGB{T}, ImageCore.clamp01nan(convert(RGB{floattype(T)}, c)))

function __init__()
@debug "ImageCoreExt loaded"
return nothing
end

end
16 changes: 16 additions & 0 deletions src/structarrays.jl → ext/StructArraysExt.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
module StructArraysExt

@static if isdefined(Base, :get_extension)
using StructArrays
else
using ..StructArrays
end
using MultiChannelColors: ColorMixture

channelname(N::Int, i::Int) = Symbol("channel" * lpad(string(i), ndigits(N), '0'))

function StructArrays.staticschema(::Type{ColorMixture{T,N,Cs}}) where {T, N, Cs}
Expand Down Expand Up @@ -29,3 +38,10 @@ end
function StructArrays.createinstance(::Type{ColorMixture{T,N,Cs}}, args...) where {T, N, Cs}
return ColorMixture{T,N,Cs}(args)
end

function __init__()
@debug "StructArraysExt loaded"
return nothing
end

end
11 changes: 8 additions & 3 deletions src/MultiChannelColors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ using Reexport
@reexport using ColorTypes
using Colors
using ColorVectorSpace
using Requires

using ColorVectorSpace: _mapc, _mul, _div, rettype, acctype

Expand All @@ -24,9 +23,15 @@ include("fluorophores.jl")
include("utils.jl")
include("operations.jl")

@static if !isdefined(Base, :get_extension)
using Requires
end

function __init__()
@require StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" include("structarrays.jl")
@require ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" include("imagecore.jl")
@static if !isdefined(Base, :get_extension)
@require StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" include("../ext/StructArraysExt.jl")
@require ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" include("../ext/ImageCoreExt.jl")
end
end

end
5 changes: 5 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[deps]
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ using ImageCore
@test c2 == c0

f_infer16(i1, i2) = ColorMixture{N0f16}((fluorophore_rgb"EGFP", fluorophore_rgb"tdTomato"), (i1, i2))
@test_broken @inferred f_infer16(1, 0)
if Base.VERSION >= v"1.10.0-9ded051e9f8"
@test_nowarn @inferred f_infer16(1, 0)
else
@test_broken @inferred f_infer16(1, 0)
end

# Inferrability from a template
ctmpl = ColorMixture(channels)
Expand Down