Skip to content

Commit

Permalink
add missing Gray{T} constructor for colorant
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 committed May 15, 2022
1 parent b8ed378 commit 033baf4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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)
(::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

0 comments on commit 033baf4

Please sign in to comment.