JuliaGraphics / ColorTypes.jl

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

`GrayA{Bool}` and `AGray{Bool}` are unavailable #152

Open kimikage opened 4 years ago

kimikage commented 4 years ago

I don't know whether GrayA{Bool} and AGray{Bool} are really needed. I don't mind if they are invalid types, but there are some inconsistencies.

julia> using ColorTypes

julia> Gray{Bool}(1) # this is ok
Gray{Bool}(true)

julia> GrayA{Bool}(1,1)
ERROR: TypeError: in GrayA, in T, expected T<:Union{AbstractFloat, FixedPointNumbers.FixedPoint}, got Type{Bool}

julia> coloralpha(Gray{Bool}) # this is ok, but disquieting
GrayA

julia> coloralpha(Gray{Bool}(1)) # gotcha!
ERROR: TypeError: in GrayA, in T, expected T<:Union{AbstractFloat, FixedPointNumbers.FixedPoint}, got Type{Bool}

julia> color_type(Gray)
Gray

julia> color_type(GrayA) # this is not wrong, but counterintuitive
Gray{T} where T<:Union{AbstractFloat, FixedPointNumbers.FixedPoint}

julia> color_type(GrayA) === Gray
false

julia> color_type(RGBA) === RGB # this is simple and intuitive
true

julia> base_color_type(GrayA) # this is not wrong, but inconsistent with `color_type`
Gray

I don't fully understand why Bool is allowed only for Gray and not for RGB. I also think Gray{Bool} is useful for binary (black/white) images (cf. PR #35, issue #76, #29), but that is not a reason to prohibit GrayA{Bool} and AGray{Bool}.

kimikage commented 4 years ago

What's this again? https://github.com/JuliaGraphics/ColorTypes.jl/blob/53c59257c3dddbebb05a899324a202a89d5ed213/src/traits.jl#L176

Is this necessary? If so, why is it only for instances? Personally, it looks better to remove this than to add support for Number to color_type andbase_colorant_type.

kimikage commented 3 years ago

If we relax the component types to Real in v0.13 (cf. https://github.com/JuliaGraphics/ColorTypes.jl/issues/131#issuecomment-824544538), this issue will be solved automatically. Of course, there are several problems with the relaxing, though.