JuliaGraphics / ColorTypes.jl

Basic color definitions and traits
Other
78 stars 36 forks source link

Generalization of conversions within the same base color (adding/stripping alpha) #241

Closed kimikage closed 3 years ago

kimikage commented 3 years ago

Currently, there are the methods for Color3 and AbstractGray, but Color{T,2} and Color{T,4} are not supported. https://github.com/JuliaGraphics/ColorTypes.jl/blob/baf7faa3e6cd4a441c971c837034696bf69adeba/src/conversions.jl#L90-L97

Colors.jl extends the conversion mechanism, but Colors.jl does not fully support conversions within the same color space.

using ColorTypes
struct C2{T} <: Color{T, 2}; c1::T; c2::T; end
struct C2A{T} <: ColorAlpha{C2{T}, T, 3}; c1::T; c2::T; alpha::T; end
ColorTypes.coloralpha(::Type{<:C2}) = C2A
julia> convert(AHSV, HSV(60, 0.5, 0.8)) # `Color3`s are supported
AHSV{Float64}(60.0,0.5,0.8,1.0)

julia> convert(C2A, C2(1.0, 0.5))
ERROR: No conversion of C2{Float64}(1.0,0.5) to C2A{Float64} has been defined

julia> convert(C2, C2A(1.0, 0.5, 0.8))
ERROR: No conversion of C2A{Float64}(1.0,0.5,0.8) to C2{Float64} has been defined

julia> using Colors;

julia> convert(C2A, C2(1.0, 0.5))
ERROR: StackOverflowError:

julia> convert(C2, C2A(1.0, 0.5, 0.8))
C2{Float64}(1.0,0.5)

Essentially, this is a separate issue, but it is slightly related to: https://github.com/JuliaGraphics/Colors.jl/issues/465