Skip to content

Commit 0710e1d

Browse files
committed
Add the CMY color model
1 parent 4c829c9 commit 0710e1d

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/ColorVectorSpace.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ isdefined(Base, :get_extension) || using Requires
3030

3131
export RGBRGB, complement, nan, dotc, dot, , hadamard, , tensor, , norm, varmult, stdmult
3232

33-
MathTypes{T,C<:Union{AbstractGray{T},AbstractRGB{T}}} = Union{C,TransparentColor{C,T}}
33+
MathTypes{T,C<:Union{AbstractGray{T},AbstractRGB{T},CMY}} = Union{C,TransparentColor{C,T}}
3434

3535
## Version compatibility with ColorTypes
3636
### TODO: Remove the definitons other than `one` when dropping ColorTypes v0.10 support
@@ -161,6 +161,7 @@ channels(c::AbstractGray) = (gray(c),)
161161
channels(c::TransparentGray) = (gray(c), alpha(c))
162162
channels(c::AbstractRGB) = (red(c), green(c), blue(c))
163163
channels(c::TransparentRGB) = (red(c), green(c), blue(c), alpha(c))
164+
channels(c::CMY) = (cyan(c), magenta(c), yellow(c))
164165

165166
if reinterpret(N0f16, 0xBADb)^2 === N0f16(float(reinterpret(N0f16, 0xBADb))^2)
166167
function _mul(x::N0f8, y::N0f8)
@@ -291,6 +292,14 @@ end
291292
dotc(x::T, y::T) where {T<:AbstractRGB} = 0.200f0 * acc(red(x))*acc(red(y)) + 0.771f0 * acc(green(x))*acc(green(y)) + 0.029f0 * acc(blue(x))*acc(blue(y))
292293
dotc(x::AbstractRGB, y::AbstractRGB) = dotc(promote(x, y)...)
293294

295+
# CMY
296+
function (/)(c::CMY, f::AbstractFloat)
297+
r = oneunit(divtype(eltype(c), typeof(f))) / f
298+
_mapc(rettype(/, c, f), v -> v * r, c)
299+
end
300+
(+)(a::CMY, b::CMY) = _mapc(rettype(+, a, b), +, a, b)
301+
(-)(a::CMY, b::CMY) = _mapc(rettype(-, a, b), -, a, b)
302+
294303
# Scalar Gray
295304
const unaryops = (:~, :conj, :abs,
296305
:sin, :cos, :tan, :sinh, :cosh, :tanh,

0 commit comments

Comments
 (0)