diff --git a/src/conversions.jl b/src/conversions.jl index 8c0d2d7..7b7a459 100644 --- a/src/conversions.jl +++ b/src/conversions.jl @@ -27,7 +27,7 @@ for (ElementClass, Colorspace) in [(Fractional, CVfractional), (FloatingPoint, C # preserves the datatype of the original space convert{T<:$ElementClass}(::Type{$CV}, c::ColorValue{T}) = convert($CV{T}, c) # fallback is Float64 (needed for RGB24) - convert(::Type{$CV}, c) = convert($CV{Float64}, c) + convert{T}(::Type{$CV}, c::ColorValue{T}) = convert($CV{Float64}, c) end end end @@ -688,8 +688,16 @@ convert{C,T}(::Type{AlphaColorValue{C,T}}, c::AlphaColorValue{C,T}) = c function convert{C,T,D,U}(::Type{AlphaColorValue{C,T}}, c::AbstractAlphaColorValue{D,U}) AlphaColorValue{C,T}(convert(C, c.c), c.alpha) end +function convert{D,T}(AC::TypeConstructor, c::AbstractAlphaColorValue{D,T}) + AlphaColorValue(convert(colortype(AC), c.c), c.alpha) +end + convert{C,T}(::Type{AlphaColorValue{C,T}}, c::ColorValue) = AlphaColorValue{C,T}(convert(C, c), one(T)) +function convert(AC::TypeConstructor, c::ColorValue) + AlphaColorValue(convert(colortype(AC), c)) +end +convert{C<:ColorValue,D,T}(::Type{C}, c::AlphaColorValue{D, T}) = convert(C, c.c) convert(::Type{ARGB32}, c::ARGB32) = c convert{CV<:AbstractRGB{Ufixed8}}(::Type{ARGB32}, c::AbstractAlphaColorValue{CV,Ufixed8}) = diff --git a/test/conversion.jl b/test/conversion.jl index 2c27180..83d62be 100644 --- a/test/conversion.jl +++ b/test/conversion.jl @@ -67,6 +67,14 @@ for Cto in Color.CVfractional end ac = rgba(red) + +@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(HSVA, ac) == HSVA{Float64}(convert(HSV, red), 1.0) +@test convert(HSVA{Float32}, ac) == HSVA{Float32}(convert(HSV{Float32}, red), 1.0f0) +@test convert(RGBA, red) == ac + @test convert(ARGB32, ac) == ARGB32(0xffff0000) @test convert(Uint32, convert(ARGB32, ac)) == 0xffff0000 @test convert(RGB24, RGB(0xffuf8,0x00uf8,0x00uf8)) == RGB24(0x00ff0000)