Skip to content

Commit

Permalink
Merge 2048d89 into 3aebbb8
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Sep 12, 2014
2 parents 3aebbb8 + 2048d89 commit 0854b0a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Color.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import Base.Graphics: set_source, set_source_rgb, GraphicsContext
export ColorValue, color,
ColourValue, colour,
AlphaColorValue, AbstractAlphaColorValue, AbstractRGB,
weighted_color_mean, hex,
RGB, HSV, HSL, XYZ, xyY, Lab, LAB, Luv, LUV, LCHab, LCHuv, DIN99, DIN99d, DIN99o, LMS, RGB24,
RGBA, HSVA, HSLA, XYZA, xyYA, LabA, LuvA, LCHabA, LCHuvA, DIN99A, DIN99dA, DIN99oA, LMSA, ARGB32,
rgba, hsva, hsla, xyza, xyYa, laba, luva, lchaba, lchuva, din99a, din99da, din99oa, lmsa, argb32,
colortype, weighted_color_mean, hex,
protanopic, deuteranopic, tritanopic,
distinguishable_colors,
colordiff, DE_2000, DE_94, DE_JPC79, DE_CMC, DE_BFD, DE_AB, DE_DIN99, DE_DIN99d, DE_DIN99o,
Expand Down
31 changes: 30 additions & 1 deletion src/colorspaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ eltype{T}(::ColorValue{T}) = T
eltype{T}(::Type{ColorValue{T}}) = T
eltype{CV<:ColorValue}(::Type{CV}) = eltype(super(CV))

# colortype is defined at the end of this file

# Transparency support
immutable AlphaColorValue{C <: ColorValue, T <: Fractional} <: AbstractAlphaColorValue{C, T}
c::C
Expand All @@ -28,6 +30,11 @@ eltype{CV<:AbstractAlphaColorValue}(::Type{CV}) = _eltype(CV, super(CV))
_eltype{CV1<:AbstractAlphaColorValue, CV2<:AbstractAlphaColorValue}(::Type{CV1}, ::Type{CV2}) = _eltype(CV2, super(CV2))
_eltype{CV<:ColorValue,T}(::Type{AbstractAlphaColorValue{CV,T}}, ::Type{Any}) = T

colortype{C}(::AbstractAlphaColorValue{C}) = colortype(C)
colortype{AC<:AbstractAlphaColorValue}(::Type{AC}) = _colortype(AC, super(AC))
_colortype{CV1<:AbstractAlphaColorValue, CV2<:AbstractAlphaColorValue}(::Type{CV1}, ::Type{CV2}) = _colortype(CV2, super(CV2))
_colortype{CV<:ColorValue,T}(::Type{AbstractAlphaColorValue{CV,T}}, ::Type{Any}) = colortype(CV)

# sRGB (standard Red-Green-Blue)
immutable RGB{T<:Fractional} <: AbstractRGB{T}
r::T # Red [0,1]
Expand Down Expand Up @@ -204,7 +211,7 @@ immutable DIN99d{T<:FloatingPoint} <: ColorValue{T}
end
end
DIN99d{T<:FloatingPoint}(l::T, a::T, b::T) = DIN99d{T}(l, a, b)
DIN99d(l, a, b) = DIN99{Float64}(l, a, b)
DIN99d(l, a, b) = DIN99d{Float64}(l, a, b)
DIN99d() = DIN99d(0.0, 0.0, 0.0)


Expand Down Expand Up @@ -293,3 +300,25 @@ argb32{T}(c::ColorValue{T}) = ARGB32(convert(RGB24,c).color | 0xff000000)

const CVconcrete = (HSV, HSL, XYZ, xyY, Lab, Luv, LCHab, LCHuv, DIN99, DIN99d, DIN99o, LMS)
const CVparametric = tuple(RGB, CVconcrete...)

for CV in CVparametric
@eval begin
colortype(::$CV) = $CV
colortype(::Type{$CV}) = $CV
colortype{T}(::Type{$CV{T}}) = $CV
end
end

colortype(::Type{RGBA}) = RGB
colortype(::Type{HSVA}) = HSV
colortype(::Type{HSLA}) = HSL
colortype(::Type{XYZA}) = XYZ
colortype(::Type{xyYA}) = xyY
colortype(::Type{LabA}) = Lab
colortype(::Type{LCHabA}) = LCHab
colortype(::Type{LuvA}) = Luv
colortype(::Type{LCHuvA}) = LCHuv
colortype(::Type{DIN99A}) = DIN99
colortype(::Type{DIN99dA}) = DIN99d
colortype(::Type{DIN99oA}) = DIN99o
colortype(::Type{LMSA}) = LMS
16 changes: 13 additions & 3 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ const red24 = RGB24(0x00ff0000)
for CV in Color.CVparametric
@test eltype(CV{Float32}) == Float32
@test eltype(CV(1,0,0)) == Float64
@test colortype(CV(1,0,0)) == CV
@test colortype(CV) == CV
@test colortype(CV{Float32}) == CV
end
for CV in (RGBA, HSVA, HSLA, XYZA, xyYA, LabA,
LCHabA, LuvA, LCHuvA, DIN99A, DIN99dA, DIN99oA, LMSA)
@test eltype(CV{Float32}) == Float32
for (ACV,CV) in ((RGBA, RGB), (HSVA, HSV), (HSLA, HSL),
(XYZA, XYZ), (xyYA, xyY), (LabA, Lab),
(LCHabA, LCHab), (LuvA, Luv),
(LCHuvA, LCHuv), (DIN99A, DIN99),
(DIN99dA, DIN99d), (DIN99oA, DIN99o),
(LMSA, LMS))
@test eltype(ACV{Float32}) == Float32
@test colortype(ACV) == CV
@test colortype(ACV{Float32}) == CV
@test colortype(ACV{Float64}(1,0,0,1)) == CV
end
for f in (rgba, hsva, hsla, xyza, xyYa, laba,
lchaba, luva, lchuva, din99a, din99da, din99oa, lmsa)
Expand Down

0 comments on commit 0854b0a

Please sign in to comment.