Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing Gray{T} constructor for colorant #278

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ function (::Type{C})() where {N, C <: ColorantN{N}}
C(ntuple(_ -> d0, Val(N - 1))..., dx)
end

Gray{T}(c::Colorant) where {T<:Union{Fractional,Bool}} = _new_colorant(Gray{T}, c)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure why, I tried the following but it doesn't work.

(::Type{C})(x ) where {C <: Gray } = _new_colorant(C, x)

(::Type{C})(x ) where {C <: Color } = _new_colorant(C, x)
(::Type{C})(x, y ) where {C <: ColorN{2}} = _new_colorant(C, x, y)
(::Type{C})(x, y, z ) where {C <: ColorN{3}} = _new_colorant(C, x, y, z)
Expand Down
8 changes: 8 additions & 0 deletions test/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,14 @@ end
end
end

@testset "conversions from rgb to gray" begin
# The rules are defined in Colors.jl, but we want to make sure it calls
# the `convert` method.
# Issue #277
msg = "No conversion of RGB{N0f8}(0.0, 0.0, 0.0) to Gray{Float32} has been defined"
@test_throws ErrorException(msg) Gray{Float32}(RGB())
end

@testset "conversions between different spaces" begin
@test_throws ErrorException convert(HSV, RGB(1,0,1))
@test_throws ErrorException convert(AHSV, RGB(1,0,1), 0.5)
Expand Down