Skip to content
Merged
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
7 changes: 3 additions & 4 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
julia 0.3
ColorTypes
FixedPointNumbers
Compat 0.2
julia 0.4
ColorTypes 0.2
FixedPointNumbers 0.1
Reexport
8 changes: 2 additions & 6 deletions src/Colors.jl
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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,
Expand Down
22 changes: 11 additions & 11 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -13,7 +13,7 @@
# Chromatic Adaptation / Whitebalancing
# -------------------------------------

@doc """
"""
whitebalance(c, src_white, ref_white)

Whitebalance a color.
Expand All @@ -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)
Expand Down Expand Up @@ -75,15 +75,15 @@ function brettel_abc(neutral::LMS, anchor::LMS)
end


@doc """
"""
protanopic(c)
protanopic(c, p)

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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/colormaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/colormatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ abstract CIE1931JV_CMF <: CMF
abstract CIE2006_2_CMF <: CMF
abstract CIE2006_10_CMF <: CMF

@doc """
"""
colormatch(wavelength)
colormatch(matchingfunction, wavelength)

Expand All @@ -20,7 +20,7 @@ Args:

Returns:
XYZ value of perceived color.
""" ->
"""
function colormatch(wavelen::Real)
return colormatch(CIE1931_CMF, wavelen)
end
Expand Down
34 changes: 17 additions & 17 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
4 changes: 2 additions & 2 deletions src/differences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@ function colordiff(ai::Color, bi::Color, m::DE_DIN99o)
end

# Default to Delta E 2000
@doc """
"""
colordiff(a, b)
colordiff(a, b, metric)

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())
5 changes: 2 additions & 3 deletions src/maps_data.jl
Original file line number Diff line number Diff line change
@@ -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)],
Expand All @@ -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)]
)

3 changes: 1 addition & 2 deletions src/names_data.jl
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function parse_alpha_num(num::AbstractString)
end


@doc """
"""
parse(Colorant, desc)

Parse a color description.
Expand All @@ -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_)
Expand Down
12 changes: 6 additions & 6 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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
Expand Down
Loading