@@ -94,6 +94,21 @@ divtype(::Type{A}, ::Type{B}) where {A,B<:FixedPoint} = coltype(typeof(zero(A)/t
94
94
powtype (:: Type{A} , :: Type{B} ) where {A,B} = coltype (typeof (zero (A)^ zero (B)))
95
95
sumtype (a:: Colorant , b:: Colorant ) = coltype (sumtype (eltype (a),eltype (b)))
96
96
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
+
97
112
coltype (:: Type{T} ) where {T<: Fractional } = T
98
113
coltype (:: Type{T} ) where {T<: Number } = floattype (T)
99
114
@@ -168,6 +183,8 @@ function _div(x::AbstractFloat, y::Normed)
168
183
end
169
184
_div (x:: AbstractFloat , y:: Integer ) = _mul (x, oneunit (x) / y)
170
185
_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
171
188
_div (x, y) = (T = divtype (typeof (x), typeof (y)); _div (T (x), T (y)))
172
189
173
190
@inline _mapc (:: Type{C} , f, c) where {C<: MathTypes } = C (f .(channels (c))... )
@@ -241,10 +258,10 @@ function (/)(c::C, f::AbstractFloat) where {C<:Union{AbstractRGB, TransparentRGB
241
258
r = oneunit (divtype (eltype (c), typeof (f))) / f
242
259
_mapc (rettype (/ , c, f), v -> v * r, c)
243
260
end
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) )
261
+ (+ )(a:: AbstractRGB , b:: AbstractRGB ) = _mapc ( rettype (+ , a, b), + , a, b )
262
+ (- )(a:: AbstractRGB , b:: AbstractRGB ) = _mapc ( rettype (- , a, b), - , a, b )
263
+ (+ )(a:: TransparentRGB , b:: TransparentRGB ) = _mapc ( rettype (+ , a, b), + , a, b )
264
+ (- )(a:: TransparentRGB , b:: TransparentRGB ) = _mapc ( rettype (- , a, b), - , a, b )
248
265
249
266
# New multiplication operators
250
267
function (⋅ )(x:: AbstractRGB , y:: AbstractRGB )
@@ -290,18 +307,26 @@ middle(c::AbstractGray) = arith_colorant_type(c)(middle(gray(c)))
290
307
middle (x:: C , y:: C ) where {C<: AbstractGray } = arith_colorant_type (C)(middle (gray (x), gray (y)))
291
308
292
309
(/ )(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))
310
+ (+ )(a:: AbstractGray , b:: AbstractGray ) = _mapc (rettype (+ , a, b), + , a, b)
311
+ (+ )(a:: AbstractGray{Bool} , b:: AbstractGray{Bool} ) = _mapc (rettype (+ , a, b), ⊻ , a, b)
312
+ (+ )(a:: TransparentGray , b:: TransparentGray ) = _mapc (rettype (+ , a, b), + , a, b)
313
+ (- )(a:: AbstractGray , b:: AbstractGray ) = _mapc (rettype (- , a, b), - , a, b)
314
+ (- )(a:: AbstractGray{Bool} , b:: AbstractGray{Bool} ) = _mapc (rettype (- , a, b), ⊻ , a, b)
315
+ (- )(a:: TransparentGray , b:: TransparentGray ) = _mapc (rettype (- , a, b), - , a, b)
297
316
(* )(a:: AbstractGray , b:: AbstractGray ) = a ⊙ b
298
317
(^ )(a:: AbstractGray , b:: Integer ) = rettype (^ , a, b)(gray (a)^ convert (Int,b))
299
318
(^ )(a:: AbstractGray , b:: Real ) = rettype (^ , a, b)(gray (a)^ b)
300
319
(/ )(a:: AbstractGray , b:: AbstractGray ) = rettype (/ , a, b)(_div (gray (a), gray (b)))
301
320
(+ )(a:: AbstractGray , b:: Number ) = base_color_type (a)(gray (a)+ b)
321
+ (+ )(a:: AbstractGray{Bool} , b:: Number ) = arith_colorant_type (a){sumtype (Bool, typeof (b))}(gray (a)) + b
322
+ (+ )(a:: AbstractGray{Bool} , b:: Bool ) = a + N0f8 (b) # FIXME
302
323
(+ )(a:: Number , b:: AbstractGray ) = b+ a
303
324
(- )(a:: AbstractGray , b:: Number ) = base_color_type (a)(gray (a)- b)
304
325
(- )(a:: Number , b:: AbstractGray ) = base_color_type (b)(a- gray (b))
326
+ (- )(a:: AbstractGray{Bool} , b:: Number ) = arith_colorant_type (a){sumtype (Bool, typeof (b))}(gray (a)) - b
327
+ (- )(a:: Number , b:: AbstractGray{Bool} ) = a - arith_colorant_type (b){sumtype (typeof (a), Bool)}(gray (b))
328
+ (- )(a:: AbstractGray{Bool} , b:: Bool ) = a - N0f8 (b) # FIXME
329
+ (- )(a:: Bool , b:: AbstractGray{Bool} ) = N0f8 (a) - b # FIXME
305
330
306
331
(⋅ )(x:: C , y:: C ) where {C<: AbstractGray } = _mul (gray (x), gray (y))
307
332
(⊗ )(x:: C , y:: C ) where {C<: AbstractGray } = x ⊙ y
0 commit comments