diff --git a/REQUIRE b/REQUIRE index 0bb86827..35912a83 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,5 +1,4 @@ -julia 0.3 -ColorTypes -FixedPointNumbers -Compat 0.2 +julia 0.4 +ColorTypes 0.2 +FixedPointNumbers 0.1 Reexport diff --git a/src/Colors.jl b/src/Colors.jl index ebf62351..4584e1ed 100644 --- a/src/Colors.jl +++ b/src/Colors.jl @@ -1,8 +1,8 @@ -VERSION >= v"0.4.0-dev+6521" && __precompile__() +__precompile__() module Colors -using FixedPointNumbers, ColorTypes, Reexport, Compat +using FixedPointNumbers, ColorTypes, Reexport @reexport using ColorTypes typealias AbstractGray{T} Color{T,1} @@ -11,10 +11,6 @@ typealias Color3{T} Color{T,3} import Base: ==, +, -, *, / import Base: convert, eltype, hex, isless, linspace, show, typemin, typemax, writemime -if VERSION < v"0.4.0-dev" - using Docile -end - # Additional exports, not exported by ColorTypes export weighted_color_mean, hex, @colorant_str, diff --git a/src/algorithms.jl b/src/algorithms.jl index b9c7220b..2946f539 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -1,6 +1,6 @@ # Arithmetic #XYZ and LMS are linear vector spaces -@compat typealias Linear3 Union{XYZ, LMS} +typealias Linear3 Union{XYZ, LMS} +{C<:Linear3}(a::C, b::C) = C(comp1(a)+comp1(b), comp2(a)+comp2(b), comp3(a)+comp3(b)) -{C<:Linear3}(a::C, b::C) = C(comp1(a)-comp1(b), comp2(a)-comp2(b), comp3(a)-comp3(b)) -(a::Linear3) = typeof(a)(-comp1(a), -comp2(a), -comp3(a)) @@ -13,7 +13,7 @@ # Chromatic Adaptation / Whitebalancing # ------------------------------------- -@doc """ +""" whitebalance(c, src_white, ref_white) Whitebalance a color. @@ -31,7 +31,7 @@ Args: Returns: A whitebalanced color. -""" -> +""" function whitebalance{T <: Color}(c::T, src_white::Color, ref_white::Color) c_lms = convert(LMS, c) src_wp = convert(LMS, src_white) @@ -75,7 +75,7 @@ function brettel_abc(neutral::LMS, anchor::LMS) end -@doc """ +""" protanopic(c) protanopic(c, p) @@ -83,7 +83,7 @@ Convert a color to simulate protanopic color deficiency (lack of the long-wavelength photopigment). `c` is the input color; the optional argument `p` is the fraction of photopigment loss, in the range 0 (no loss) to 1 (complete loss). -""" -> +""" function protanopic{T <: Color}(q::T, p, neutral::LMS) q = convert(LMS, q) anchor_wavelen = q.s / q.m < neutral.s / neutral.m ? 575 : 475 @@ -98,13 +98,13 @@ function protanopic{T <: Color}(q::T, p, neutral::LMS) end -@doc """ +""" deuteranopic(c) deuteranopic(c, p) Convert a color to simulate deuteranopic color deficiency (lack of the middle-wavelength photopigment). See the description of `protanopic` for detail about the arguments. -""" -> +""" function deuteranopic{T <: Color}(q::T, p, neutral::LMS) q = convert(LMS, q) anchor_wavelen = q.s / q.l < neutral.s / neutral.l ? 575 : 475 @@ -119,14 +119,14 @@ function deuteranopic{T <: Color}(q::T, p, neutral::LMS) end -@doc """ +""" tritanopic(c) tritanopic(c, p) Convert a color to simulate tritanopic color deficiency (lack of the short-wavelength photogiment). See `protanopic` for more detail about the arguments. -""" -> +""" function tritanopic{T <: Color}(q::T, p, neutral::LMS) q = convert(LMS, q) anchor_wavelen = q.m / q.l < neutral.m / neutral.l ? 660 : 485 @@ -156,14 +156,14 @@ tritanopic(c::Color) = tritanopic(c, 1.0) # MSC - Most Saturated Colorant for given hue h # --------------------- -@doc """ +""" MSC(h) MSC(h, l) Calculates the most saturated color for any given hue `h` by finding the corresponding corner in LCHuv space. Optionally, the lightness `l` may also be specified. -""" -> +""" function MSC(h) #Corners of RGB cube diff --git a/src/colormaps.jl b/src/colormaps.jl index 97fdc88a..4a023f57 100644 --- a/src/colormaps.jl +++ b/src/colormaps.jl @@ -4,7 +4,7 @@ include("maps_data.jl") # color scale generation # ---------------------- -@doc """ +""" distinguishable_colors(n, [seed]; [transform, lchoices, cchoices, hchoices]) Generate n maximally distinguishable colors. @@ -29,7 +29,7 @@ Keyword arguments: Returns: A `Vector` of colors of length `n`, of the type specified in `seed`. -""" -> +""" function distinguishable_colors{T<:Color}(n::Integer, seed::AbstractVector{T}; transform::Function = identity, @@ -46,6 +46,8 @@ function distinguishable_colors{T<:Color}(n::Integer, j = 0 for h in hchoices, c in cchoices, l in lchoices candidate[j+=1] = LCHab(l, c, h) + # rgb = convert(RGB, LCHab(l, c, h)) + # candidate[j+=1] = convert(LCHab, rgb) end # Transformed colors @@ -220,7 +222,7 @@ function diverging_palette(h1, n=N end N1 = max(ceil(Int, mid*n), 1) - N2 = @compat Int(max(n-N1, 1)) + N2 = Int(max(n-N1, 1)) pal1 = sequential_palette(h1, N1+1, w=w, d=d1, c=c, s=s, b=b, wcolor=wcolor, dcolor=dcolor1, logscale=logscale) pal1 = flipdim(pal1, 1) @@ -240,7 +242,7 @@ end # ---------------------- # Main function to handle different predefined colormaps # -@doc """ +""" colormap(cname, [N; mid, logscale, kvs...]) Returns a predefined sequential or diverging colormap computed using @@ -250,7 +252,7 @@ and `Reds`. Diverging colormap choices are `RdBu`. Optionally, you can specify the number of colors `N` (default 100). Keyword arguments include the position of the middle point `mid` (default 0.5) and the possibility to switch to log scaling with `logscale` (default false). -""" -> +""" function colormap(cname::AbstractString, N::Int=100; mid=0.5, logscale=false, kvs...) cname = lowercase(cname) diff --git a/src/colormatch.jl b/src/colormatch.jl index ca34bbed..6af0d951 100644 --- a/src/colormatch.jl +++ b/src/colormatch.jl @@ -7,7 +7,7 @@ abstract CIE1931JV_CMF <: CMF abstract CIE2006_2_CMF <: CMF abstract CIE2006_10_CMF <: CMF -@doc """ +""" colormatch(wavelength) colormatch(matchingfunction, wavelength) @@ -20,7 +20,7 @@ Args: Returns: XYZ value of perceived color. -""" -> +""" function colormatch(wavelen::Real) return colormatch(CIE1931_CMF, wavelen) end diff --git a/src/conversions.jl b/src/conversions.jl index 2dc8dc57..ec814b35 100644 --- a/src/conversions.jl +++ b/src/conversions.jl @@ -165,7 +165,7 @@ cnvt{CV<:AbstractRGB}(::Type{CV}, c::LCHab) = cnvt(CV, convert(Lab{eltype(c)}, cnvt{CV<:AbstractRGB}(::Type{CV}, c::LCHuv) = cnvt(CV, convert(Luv{eltype(c)}, c)) cnvt{CV<:AbstractRGB}(::Type{CV}, c::Color3) = cnvt(CV, convert(XYZ{eltype(c)}, c)) -cnvt{CV<:AbstractRGB{Ufixed8}}(::Type{CV}, c::RGB24) = CV(Ufixed8(c.color&0x00ff0000>>>16,0), Ufixed8(c.color&0x0000ff00>>>8,0), Ufixed8(c.color&0x000000ff,0)) +cnvt{CV<:AbstractRGB{UFixed8}}(::Type{CV}, c::RGB24) = CV(UFixed8(c.color&0x00ff0000>>>16,0), UFixed8(c.color&0x0000ff00>>>8,0), UFixed8(c.color&0x000000ff,0)) cnvt{CV<:AbstractRGB}(::Type{CV}, c::RGB24) = CV((c.color&0x00ff0000>>>16)/255, ((c.color&0x0000ff00)>>>8)/255, (c.color&0x000000ff)/255) function cnvt{CV<:AbstractRGB}(::Type{CV}, c::AbstractGray) @@ -178,21 +178,21 @@ end # ----------------- function cnvt{T}(::Type{HSV{T}}, c::AbstractRGB) - c_min = min(red(c), green(c), blue(c)) - c_max = max(red(c), green(c), blue(c)) + c_min = Float64(min(red(c), green(c), blue(c))) + c_max = Float64(max(red(c), green(c), blue(c))) if c_min == c_max - return HSV(zero(T), zero(T), c_max) + return HSV{T}(zero(T), zero(T), c_max) end if c_min == red(c) - f = green(c) - blue(c) - i = convert(T, 3) + f = Float64(green(c)) - Float64(blue(c)) + i = 3 elseif c_min == green(c) - f = blue(c) - red(c) - i = convert(T, 5) + f = Float64(blue(c)) - Float64(red(c)) + i = 5 else - f = red(c) - green(c) - i = convert(T, 1) + f = Float64(red(c)) - Float64(green(c)) + i = 1 end HSV{T}(60 * (i - f / (c_max - c_min)), @@ -316,9 +316,9 @@ cnvt{T}(::Type{XYZ{T}}, c::LCHab) = cnvt(XYZ{T}, convert(Lab{T}, c)) cnvt{T}(::Type{XYZ{T}}, c::DIN99) = cnvt(XYZ{T}, convert(Lab{T}, c)) cnvt{T}(::Type{XYZ{T}}, c::DIN99o) = cnvt(XYZ{T}, convert(Lab{T}, c)) -cnvt{T<:Ufixed}(::Type{XYZ{T}}, c::LCHab) = cnvt(XYZ{T}, convert(Lab{eltype(c)}, c)) -cnvt{T<:Ufixed}(::Type{XYZ{T}}, c::DIN99) = cnvt(XYZ{T}, convert(Lab{eltype(c)}, c)) -cnvt{T<:Ufixed}(::Type{XYZ{T}}, c::DIN99o) = cnvt(XYZ{T}, convert(Lab{eltype(c)}, c)) +cnvt{T<:UFixed}(::Type{XYZ{T}}, c::LCHab) = cnvt(XYZ{T}, convert(Lab{eltype(c)}, c)) +cnvt{T<:UFixed}(::Type{XYZ{T}}, c::DIN99) = cnvt(XYZ{T}, convert(Lab{eltype(c)}, c)) +cnvt{T<:UFixed}(::Type{XYZ{T}}, c::DIN99o) = cnvt(XYZ{T}, convert(Lab{eltype(c)}, c)) function xyz_to_uv(c::XYZ) @@ -767,19 +767,19 @@ cnvt{T}(::Type{YCbCr{T}}, c::Color3) = cnvt(YCbCr{T}, convert(RGB{T}, c)) # ------------------- convert(::Type{RGB24}, c::RGB24) = c -convert(::Type{RGB24}, c::AbstractRGB{Ufixed8}) = RGB24(red(c), green(c), blue(c)) +convert(::Type{RGB24}, c::AbstractRGB{UFixed8}) = RGB24(red(c), green(c), blue(c)) convert(::Type{RGB24}, c::AbstractRGB) = RGB24(round(UInt32, 255*red(c))<<16 + round(UInt32, 255*green(c))<<8 + round(UInt32, 255*blue(c))) -convert(::Type{RGB24}, c::Color) = convert(RGB24, convert(RGB{Ufixed8}, c)) +convert(::Type{RGB24}, c::Color) = convert(RGB24, convert(RGB{UFixed8}, c)) # To ARGB32 # ---------------- convert(::Type{ARGB32}, c::ARGB32) = c -convert{CV<:AbstractRGB{Ufixed8}}(::Type{ARGB32}, c::TransparentColor{CV}) = +convert{CV<:AbstractRGB{UFixed8}}(::Type{ARGB32}, c::TransparentColor{CV}) = ARGB32(red(c), green(c), blue(c), alpha(c)) convert(::Type{ARGB32}, c::TransparentColor) = ARGB32(convert(RGB24, c).color | round(UInt32, 255*alpha(c))<<24) @@ -796,5 +796,5 @@ else const unsafe_trunc = Base.unsafe_trunc end -convert{T<:Ufixed}(::Type{Gray{T}}, x::AbstractRGB{T}) = Gray{T}(T(unsafe_trunc(FixedPointNumbers.rawtype(T), 0.299f0*reinterpret(x.r) + 0.587f0*reinterpret(x.g) + 0.114f0*reinterpret(x.b)), 0)) +convert{T<:UFixed}(::Type{Gray{T}}, x::AbstractRGB{T}) = Gray{T}(T(unsafe_trunc(FixedPointNumbers.rawtype(T), 0.299f0*reinterpret(x.r) + 0.587f0*reinterpret(x.g) + 0.114f0*reinterpret(x.b)), 0)) convert{T}(::Type{Gray{T}}, x::AbstractRGB) = convert(Gray{T}, 0.299f0*x.r + 0.587f0*x.g + 0.114f0*x.b) diff --git a/src/differences.jl b/src/differences.jl index 36f55f38..46eaca1b 100644 --- a/src/differences.jl +++ b/src/differences.jl @@ -406,7 +406,7 @@ function colordiff(ai::Color, bi::Color, m::DE_DIN99o) end # Default to Delta E 2000 -@doc """ +""" colordiff(a, b) colordiff(a, b, metric) @@ -414,5 +414,5 @@ Compute an approximate measure of the perceptual difference between colors `a` and `b`. Optionally, a `metric` may be supplied, chosen among `DE_2000` (the default), `DE_94`, `DE_JPC79`, `DE_CMC`, `DE_BFD`, `DE_AB`, `DE_DIN99`, `DE_DIN99d`, `DE_DIN99o`. -""" -> +""" colordiff(ai::Color, bi::Color) = colordiff(ai::Color, bi::Color, DE_2000()) diff --git a/src/maps_data.jl b/src/maps_data.jl index abc4237c..058ac356 100644 --- a/src/maps_data.jl +++ b/src/maps_data.jl @@ -1,6 +1,6 @@ # Colormap parameters -const colormaps_sequential = Compat.@Dict( +const colormaps_sequential = Dict( #single hue #name hue w d c s b wcolor dcolor "blues" => [255, 0.3, 0.25, 0.88, 0.6, 0.75, RGB(1,1,0), RGB(0,0,1)], @@ -11,8 +11,7 @@ const colormaps_sequential = Compat.@Dict( "reds" => [12, 0.15, 0.25, 0.8, 0.85, 0.6, RGB(1,1,0), RGB(0.3,0.1,0.1)] ) -const colormaps_diverging = Compat.@Dict( +const colormaps_diverging = Dict( #name h1 h2 w d1 d2 c s b wcolor dcolor dcolor2 "rdbu" => [12, 255, 0.2, 0.6, 0.0, 0.85, 0.6, 0.65, RGB(1,1,0), RGB(1,0,0), RGB(0,0,1)] ) - diff --git a/src/names_data.jl b/src/names_data.jl index 2f4a5439..b650e10f 100644 --- a/src/names_data.jl +++ b/src/names_data.jl @@ -1,8 +1,7 @@ - # This is the union of every color defined in X11 and in SVG, prefering the SVG # definition when they clash. -const color_names = Compat.@Dict( +const color_names = Dict( "aliceblue" => (240, 248, 255), "antiquewhite" => (250, 235, 215), "antiquewhite1" => (255, 239, 219), diff --git a/src/parse.jl b/src/parse.jl index 1adc65ab..27c86bc5 100644 --- a/src/parse.jl +++ b/src/parse.jl @@ -47,7 +47,7 @@ function parse_alpha_num(num::AbstractString) end -@doc """ +""" parse(Colorant, desc) Parse a color description. @@ -71,7 +71,7 @@ Returns: - "rgba(r,g,b,a)" was used, in which case an `RGBA` color; - "hsla(h,s,l,a)" was used, in which case an `HSLA` color; - a specific `Colorant` type was specified in the first argument -""" -> +""" function Base.parse(::Type{Colorant}, desc::AbstractString) desc_ = replace(desc, " ", "") mat = match(col_pat_hex2, desc_) diff --git a/src/utilities.jl b/src/utilities.jl index 85123781..2d37e8e7 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -9,12 +9,12 @@ function lerp(x, a, b) end -@doc """ +""" hex(c) Print a color as a RGB hex triple, or a transparent paint as an ARGB hex quadruplet. -""" -> +""" function hex(c::RGB) @sprintf("%02X%02X%02X", round(Int, lerp(c.r, 0.0, 255.0)), @@ -44,21 +44,21 @@ for (T,a,b,c) in ((:RGB,:r,:g,:b), (:HSV,:h,:s,:v), (:HSL,:h,:s,:l), end end -@doc """ +""" weighted_color_mean(w1, c1, c2) Returns a color that is the weighted mean of `c1` and `c2`, where `c1` has a weight 0 ≤ `w1` ≤ 1. -""" -> +""" weighted_color_mean(w1::Real, c1::RGB24, c2::RGB24) = convert(RGB24, weighted_color_mean(w1, convert(RGB, c1), convert(RGB, c2))) -@doc """ +""" linspace(c1::Color, c2::Color, n=100) Generates `n` colors in a linearly interpolated ramp from `c1` to `c2`, inclusive, returning an `Array` of colors. -""" -> +""" function linspace{T<:Color}(c1::T, c2::T, n=100) a = Array(T, convert(Int, n)) if n == 1 diff --git a/test/conversion.jl b/test/conversion.jl index 0265256d..6f052181 100644 --- a/test/conversion.jl +++ b/test/conversion.jl @@ -1,6 +1,6 @@ -using Colors, FixedPointNumbers, Compat, JLD +using Colors, FixedPointNumbers, JLD using Base.Test -import ColorTypes: eltype_default +using ColorTypes: eltype_default # Color parsing const redU8 = parse(Colorant, "red") @@ -28,7 +28,7 @@ fractional_types = (RGB, BGR, RGB1, RGB4) # types that support Fractional const red24 = RGB24(0x00ff0000) const red32 = ARGB32(0xffff0000) -for T in (Float64, Float32, Ufixed8) +for T in (Float64, Float32, UFixed8) c = RGB(one(T), zero(T), zero(T)) @test eltype(c) == T c64 = convert(RGB{Float64}, c) @@ -69,11 +69,11 @@ for Cto in ColorTypes.parametric3 @test typeof(convert(Cto{Float64}, red24)) == Cto{Float64} end -# Test conversion from Ufixed types +# Test conversion from UFixed types for Cto in ColorTypes.parametric3 for Cfrom in fractional_types for Tto in (Float32, Float64) - for Tfrom in (Ufixed8, Ufixed10, Ufixed12, Ufixed14, Ufixed16) + for Tfrom in (UFixed8, UFixed10, UFixed12, UFixed14, UFixed16) c = convert(Cfrom{Tfrom}, redF64) @test typeof(c) == Cfrom{Tfrom} if !(eltype_default(Cto) <: FixedPoint) @@ -87,10 +87,10 @@ for Cto in ColorTypes.parametric3 end end -# Test conversion to Ufixed types +# Test conversion to UFixed types for Cto in fractional_types for Cfrom in ColorTypes.parametric3 - for Tto in (Ufixed8, Ufixed10, Ufixed12, Ufixed14, Ufixed16) + for Tto in (UFixed8, UFixed10, UFixed12, UFixed14, UFixed16) for Tfrom in (Float32, Float64) c = convert(Cfrom{Tfrom}, redF64) @test typeof(c) == Cfrom{Tfrom} @@ -104,8 +104,8 @@ end ac = RGBA(redF64) @test convert(RGB, ac) == RGB(1,0,0) -@test convert(RGB{Ufixed8}, ac) == RGB{Ufixed8}(1,0,0) -@test convert(RGBA{Ufixed8}, ac) == RGBA{Ufixed8}(1,0,0,1) +@test convert(RGB{UFixed8}, ac) == RGB{UFixed8}(1,0,0) +@test convert(RGBA{UFixed8}, ac) == RGBA{UFixed8}(1,0,0,1) @test convert(HSVA, ac) == HSVA{Float64}(convert(HSV, redF64), 1.0) @test convert(HSVA{Float32}, ac) == HSVA{Float32}(convert(HSV{Float32}, redF64), 1.0f0) @test convert(RGBA, redF64) == ac @@ -117,8 +117,8 @@ ac = RGBA(redF64) redhsv = convert(HSV, redF64) @test convert(RGB24, redhsv) == RGB24(0x00ff0000) -@test convert(RGB{Ufixed8}, red24) == RGB{Ufixed8}(1,0,0) -@test convert(RGBA{Ufixed8}, red32) == RGBA{Ufixed8}(1,0,0,1) +@test convert(RGB{UFixed8}, red24) == RGB{UFixed8}(1,0,0) +@test convert(RGBA{UFixed8}, red32) == RGBA{UFixed8}(1,0,0,1) @test convert(HSVA{Float64}, red32) == HSVA{Float64}(360, 1, 1, 1) if VERSION >= v"0.4.0-dev" @@ -177,15 +177,15 @@ v = -0.5226 @test convert(RGB, YIQ(0.0,0.0,-1.0)) == RGB(0,-0.6474*v,0) # Gray -c = Gray{Ufixed16}(0.8) -@test convert(RGB, c) == RGB{Ufixed16}(0.8,0.8,0.8) +c = Gray{UFixed16}(0.8) +@test convert(RGB, c) == RGB{UFixed16}(0.8,0.8,0.8) @test convert(RGB{Float32}, c) == RGB{Float32}(0.8,0.8,0.8) # More AbstractRGB r4 = RGB4(1,0,0) @test convert(RGB, r4) == RGB(1,0,0) -@test convert(RGB{Ufixed8}, r4) == RGB{Ufixed8}(1,0,0) -@test convert(RGB4{Ufixed8}, r4) == RGB4{Ufixed8}(1,0,0) +@test convert(RGB{UFixed8}, r4) == RGB{UFixed8}(1,0,0) +@test convert(RGB4{UFixed8}, r4) == RGB4{UFixed8}(1,0,0) @test convert(RGB4{Float32}, r4) == RGB4{Float32}(1,0,0) @test convert(BGR{Float32}, r4) == BGR{Float32}(1,0,0)