JuliaGraphics / Colors.jl

Color manipulation utilities for Julia
Other
202 stars 47 forks source link

colordiff not work with all colors? #437

Closed cormullion closed 4 years ago

cormullion commented 4 years ago

Just wondering why colordiff doesn't work with all colors?

julia> using Colors
julia> colordiff(RGBA(0.35, 0.18, 0.90, 1), RGBA(0.34, 0.18, 0.90, 1))
ERROR: MethodError: no method matching colordiff(::RGBA{Float64}, ::RGBA{Float64})
Stacktrace:
 [1] top-level scope at none:1

There's probably a good reason, but I'm interested to know what it is.

Colors v0.12.3, Julia 1.5.0

kimikage commented 4 years ago

cf. #250

cormullion commented 4 years ago

Yes, I kind of see. Although the alpha values are 1 here.

kimikage commented 4 years ago

It is possible to provide special treatments for transparent colors when the alpha values are 1, but I don't see the need to do that. If the users know that the alpha values are always 1, they can use color().

I think what we need to do is to improve the error message.

cormullion commented 4 years ago

I suppose you could do something like:

function colordiff(ai::RGBA, bi::RGBA;
        metric::DifferenceMetric=DE_2000()) 
    if ai.alpha != 1 || bi.alpha != 1
        @warn "Ignoring alpha value of transparent colors..."
    end
    _colordiff(convert(RGB, ai), convert(RGB, bi), metric)
end

just to help people keep working. The warnings could prompt them to change their code... :)

johnnychen94 commented 4 years ago

This could print thousands of warnings if it's an image...