Skip to content

Commit

Permalink
Merge pull request #370 from JuliaGraphics/teh/precompile
Browse files Browse the repository at this point in the history
Add some precompiles
  • Loading branch information
timholy authored Dec 12, 2019
2 parents 1bc194e + eb734ea commit c9f4349
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Colors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ include("colormaps.jl")
include("display.jl")
include("colormatch.jl")

include("precompile.jl")
_precompile_()

end # module
29 changes: 29 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function _precompile_()
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
eltypes = (N0f8, N0f16, Float32, Float64) # eltypes of parametric colors
feltypes = (Float32, Float64) # floating-point eltypes
pctypes = (Gray, RGB, AGray, GrayA, ARGB, RGBA) # parametric colors
cctypes = (Gray24, AGray32, RGB24, ARGB32) # non-parametric colors
# conversions
## to RGB
for T in eltypes, F in feltypes, C in (HSV,LCHab,LCHuv,Lab,Luv,XYZ)
@assert precompile(Tuple{typeof(convert),Type{RGB{T}},C{F}})
end
## to XYZ
for T in feltypes, F in feltypes, C in (HSV,LCHab,LCHuv,Lab,Luv,XYZ,RGB)
@assert precompile(Tuple{typeof(convert),Type{XYZ{T}},C{F}})
end
for T in feltypes, F in (N0f8, N0f16)
@assert precompile(Tuple{typeof(convert),Type{XYZ{T}},RGB{F}})
end
# parse
@assert precompile(Tuple{typeof(parse),Type{ColorTypes.Colorant},String})
@assert precompile(Tuple{typeof(parse),Type{RGB{N0f8}},String})
@assert precompile(Tuple{typeof(parse),Type{RGBA{N0f8}},String})
# colordiff
for T in eltypes
@assert precompile(Tuple{typeof(colordiff),RGB{T},RGB{T}})
end
@assert precompile(Tuple{typeof(colormap),String})
@assert precompile(Tuple{typeof(distinguishable_colors),Int})
end
4 changes: 2 additions & 2 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ end

#Double quadratic Bezier curve
function Bezier(t::T, p0::T, p2::T, q0::T, q1::T, q2::T) where T<:Real
B(t,a,b,c)=a*(1.0-t)^2.0+2.0b*(1.0-t)*t+c*t^2.0
B(t,a,b,c)=a*(1.0-t)^2 + 2.0b*(1.0-t)*t + c*t^2
if t <= 0.5
return B(2.0t, p0, q0, q1)
else #t > 0.5
Expand All @@ -79,7 +79,7 @@ end

#Inverse double quadratic Bezier curve
function invBezier(t::T, p0::T, p2::T, q0::T, q1::T, q2::T) where T<:Real
invB(t,a,b,c)=(a-b+sqrt(b^2.0-a*c+(a-2.0b+c)*t))/(a-2.0b+c)
invB(t,a,b,c)=(a-b+sqrt(b^2-a*c+(a-2.0b+c)*t))/(a-2.0b+c)
if t < q1
return 0.5*invB(t,p0,q0,q1)
else #t >= q1
Expand Down

0 comments on commit c9f4349

Please sign in to comment.