@@ -94,6 +94,21 @@ divtype(::Type{A}, ::Type{B}) where {A,B<:FixedPoint} = coltype(typeof(zero(A)/t
9494powtype (:: Type{A} , :: Type{B} ) where {A,B} = coltype (typeof (zero (A)^ zero (B)))
9595sumtype (a:: Colorant , b:: Colorant ) = coltype (sumtype (eltype (a),eltype (b)))
9696
97+ multype (:: Type{Bool} , :: Type{B} ) where {B} = B
98+ multype (:: Type{A} , :: Type{Bool} ) where {A} = A <: Integer ? multype (A, N0f8) : A
99+ multype (:: Type{Bool} , :: Type{Bool} ) = Bool
100+ sumtype (:: Type{Bool} , :: Type{B} ) where {B} = B <: Integer ? N0f8 : sumtype (N0f8, B) # FIXME
101+ sumtype (:: Type{A} , :: Type{Bool} ) where {A} = sumtype (Bool, A)
102+ sumtype (:: Type{Bool} , :: Type{Bool} ) = N0f8 # FIXME
103+ divtype (:: Type{Bool} , :: Type{B} ) where {B} = divtype (B <: Integer ? N0f8 : UInt8, B)
104+ divtype (:: Type{Bool} , :: Type{B} ) where {B<: FixedPoint } = divtype (N0f8, B) # FIXME
105+ divtype (:: Type{A} , :: Type{Bool} ) where {A} = divtype (A, A <: FixedPoint ? N0f8 : UInt8) # FIXME
106+ divtype (:: Type{A} , :: Type{Bool} ) where {A<: Integer } = Float32 # FIXME
107+ divtype (:: Type{Bool} , :: Type{Bool} ) = divtype (N0f8, UInt8)
108+ powtype (:: Type{Bool} , :: Type{B} ) where {B} = B <: Integer ? Bool : B
109+ powtype (:: Type{A} , :: Type{Bool} ) where {A} = A
110+ powtype (:: Type{Bool} , :: Type{Bool} ) = Bool
111+
97112coltype (:: Type{T} ) where {T<: Fractional } = T
98113coltype (:: Type{T} ) where {T<: Number } = floattype (T)
99114
@@ -168,6 +183,9 @@ function _div(x::AbstractFloat, y::Normed)
168183end
169184_div (x:: AbstractFloat , y:: Integer ) = _mul (x, oneunit (x) / y)
170185_div (x:: T , y:: T ) where {T} = x / y
186+ _div (x:: Bool , y:: Bool ) = (T = divtype (typeof (x), typeof (y)); _div (T (x), T (y)))
187+ _div (x:: FixedPoint , y:: Bool ) = (T = divtype (typeof (x), typeof (y)); T (_div (T (x), T (y)))) # FIXME
188+ _div (x:: Bool , y:: FixedPoint ) = (T = divtype (typeof (x), typeof (y)); T (_div (T (x), T (y)))) # FIXME
171189_div (x, y) = (T = divtype (typeof (x), typeof (y)); _div (T (x), T (y)))
172190
173191@inline _mapc (:: Type{C} , f, c) where {C<: MathTypes } = C (f .(channels (c))... )
@@ -241,10 +259,10 @@ function (/)(c::C, f::AbstractFloat) where {C<:Union{AbstractRGB, TransparentRGB
241259 r = oneunit (divtype (eltype (c), typeof (f))) / f
242260 _mapc (rettype (/ , c, f), v -> v * r, c)
243261end
244- (+ )(a:: AbstractRGB , b:: AbstractRGB ) = rettype (+ , a, b)( red (a) + red (b), green (a) + green (b), blue (a) + blue (b) )
245- (- )(a:: AbstractRGB , b:: AbstractRGB ) = rettype (- , a, b)( red (a) - red (b), green (a) - green (b), blue (a) - blue (b) )
246- (+ )(a:: TransparentRGB , b:: TransparentRGB ) = rettype (+ , a, b)( red (a) + red (b), green (a) + green (b), blue (a) + blue (b), alpha (a) + alpha (b) )
247- (- )(a:: TransparentRGB , b:: TransparentRGB ) = rettype (- , a, b)( red (a) - red (b), green (a) - green (b), blue (a) - blue (b), alpha (a) - alpha (b) )
262+ (+ )(a:: AbstractRGB , b:: AbstractRGB ) = _mapc ( rettype (+ , a, b), + , a, b )
263+ (- )(a:: AbstractRGB , b:: AbstractRGB ) = _mapc ( rettype (- , a, b), - , a, b )
264+ (+ )(a:: TransparentRGB , b:: TransparentRGB ) = _mapc ( rettype (+ , a, b), + , a, b )
265+ (- )(a:: TransparentRGB , b:: TransparentRGB ) = _mapc ( rettype (- , a, b), - , a, b )
248266
249267# New multiplication operators
250268function (⋅ )(x:: AbstractRGB , y:: AbstractRGB )
@@ -290,18 +308,26 @@ middle(c::AbstractGray) = arith_colorant_type(c)(middle(gray(c)))
290308middle (x:: C , y:: C ) where {C<: AbstractGray } = arith_colorant_type (C)(middle (gray (x), gray (y)))
291309
292310(/ )(n:: Number , c:: AbstractGray ) = base_color_type (c)(_div (real (n), gray (c)))
293- (+ )(a:: AbstractGray , b:: AbstractGray ) = rettype (+ , a, b)(gray (a)+ gray (b))
294- (+ )(a:: TransparentGray , b:: TransparentGray ) = rettype (+ , a, b)(gray (a)+ gray (b), alpha (a)+ alpha (b))
295- (- )(a:: AbstractGray , b:: AbstractGray ) = rettype (- , a, b)(gray (a)- gray (b))
296- (- )(a:: TransparentGray , b:: TransparentGray ) = rettype (- , a, b)(gray (a)- gray (b), alpha (a)- alpha (b))
311+ (+ )(a:: AbstractGray , b:: AbstractGray ) = _mapc (rettype (+ , a, b), + , a, b)
312+ (+ )(a:: AbstractGray{Bool} , b:: AbstractGray{Bool} ) = _mapc (rettype (+ , a, b), ⊻ , a, b)
313+ (+ )(a:: TransparentGray , b:: TransparentGray ) = _mapc (rettype (+ , a, b), + , a, b)
314+ (- )(a:: AbstractGray , b:: AbstractGray ) = _mapc (rettype (- , a, b), - , a, b)
315+ (- )(a:: AbstractGray{Bool} , b:: AbstractGray{Bool} ) = _mapc (rettype (- , a, b), ⊻ , a, b)
316+ (- )(a:: TransparentGray , b:: TransparentGray ) = _mapc (rettype (- , a, b), - , a, b)
297317(* )(a:: AbstractGray , b:: AbstractGray ) = a ⊙ b
298318(^ )(a:: AbstractGray , b:: Integer ) = rettype (^ , a, b)(gray (a)^ convert (Int,b))
299319(^ )(a:: AbstractGray , b:: Real ) = rettype (^ , a, b)(gray (a)^ b)
300320(/ )(a:: AbstractGray , b:: AbstractGray ) = rettype (/ , a, b)(_div (gray (a), gray (b)))
301321(+ )(a:: AbstractGray , b:: Number ) = base_color_type (a)(gray (a)+ b)
322+ (+ )(a:: AbstractGray{Bool} , b:: Number ) = arith_colorant_type (a){sumtype (Bool, typeof (b))}(gray (a) + b)
323+ (+ )(a:: AbstractGray{Bool} , b:: Bool ) = a + N0f8 (b) # FIXME
302324(+ )(a:: Number , b:: AbstractGray ) = b+ a
303325(- )(a:: AbstractGray , b:: Number ) = base_color_type (a)(gray (a)- b)
304326(- )(a:: Number , b:: AbstractGray ) = base_color_type (b)(a- gray (b))
327+ (- )(a:: AbstractGray{Bool} , b:: Number ) = arith_colorant_type (a){sumtype (Bool, typeof (b))}(gray (a) - b)
328+ (- )(a:: Number , b:: AbstractGray{Bool} ) = arith_colorant_type (b){sumtype (typeof (a), Bool)}(a - gray (b))
329+ (- )(a:: AbstractGray{Bool} , b:: Bool ) = a - N0f8 (b) # FIXME
330+ (- )(a:: Bool , b:: AbstractGray{Bool} ) = N0f8 (a) - b # FIXME
305331
306332(⋅ )(x:: C , y:: C ) where {C<: AbstractGray } = _mul (gray (x), gray (y))
307333(⊗ )(x:: C , y:: C ) where {C<: AbstractGray } = x ⊙ y
0 commit comments