@@ -188,11 +188,15 @@ copy(c::MathTypes) = c
188
188
abs (c:: MathTypes ) = mapc (abs, c)
189
189
norm (c:: MathTypes , p:: Real = 2 ) = (cc = channels (c); norm (cc, p)/ (p == 0 ? length (cc) : length (cc)^ (1 / p)))
190
190
(⊙ )(a:: C , b:: C ) where {C<: MathTypes } = mapc (* , a, b)
191
+ (⋅ )(a:: C , b:: C ) where {C<: MathTypes } = throw (MethodError (dot, (a, b)))
192
+ (⊗ )(a:: C , b:: C ) where {C<: MathTypes } = throw (MethodError (tensor, (a, b)))
191
193
192
194
# # Mixed types
193
195
(+ )(a:: MathTypes , b:: MathTypes ) = (+ )(promote (a, b)... )
194
196
(- )(a:: MathTypes , b:: MathTypes ) = (- )(promote (a, b)... )
195
197
(⊙ )(a:: MathTypes , b:: MathTypes ) = (⊙ )(promote (a, b)... )
198
+ (⋅ )(a:: MathTypes , b:: MathTypes ) = (⋅ )(promote (a, b)... ) # not fully supported, but used for error hints
199
+ (⊗ )(a:: MathTypes , b:: MathTypes ) = (⊗ )(promote (a, b)... ) # not fully supported, but used for error hints
196
200
197
201
198
202
# Scalar RGB
220
224
(- )(a:: TransparentRGB , b:: TransparentRGB ) = rettype (- , a, b)(red (a)- red (b), green (a)- green (b), blue (a)- blue (b), alpha (a)- alpha (b))
221
225
222
226
# New multiplication operators
223
- (⋅ )(x:: AbstractRGB , y:: AbstractRGB ) = (T = acctype (eltype (x), eltype (y)); T (red (x))* T (red (y)) + T (green (x))* T (green (y)) + T (blue (x))* T (blue (y)))/ 3
224
- (⋅ )(x:: Union{AbstractRGB,AbstractGray} , y:: Union{AbstractRGB,AbstractGray} ) = ⋅ (promote (x, y)... )
227
+ function (⋅ )(x:: AbstractRGB , y:: AbstractRGB )
228
+ T = acctype (eltype (x), eltype (y))
229
+ (T (red (x))* T (red (y)) + T (green (x))* T (green (y)) + T (blue (x))* T (blue (y)))/ 3
230
+ end
225
231
# ⊗ defined below
226
232
227
233
@@ -277,8 +283,8 @@ middle(x::C, y::C) where {C<:AbstractGray} = arith_colorant_type(C)(middle(gray(
277
283
(- )(a:: AbstractGray , b:: Number ) = base_color_type (a)(gray (a)- b)
278
284
(- )(a:: Number , b:: AbstractGray ) = base_color_type (b)(a- gray (b))
279
285
280
- (⋅ )(x:: AbstractGray , y:: AbstractGray ) = gray (x)* gray (y)
281
- (⊗ )(x:: AbstractGray , y:: AbstractGray ) = x ⊙ y
286
+ (⋅ )(x:: C , y:: C ) where {C <: AbstractGray } = gray (x)* gray (y)
287
+ (⊗ )(x:: C , y:: C ) where {C <: AbstractGray } = x ⊙ y
282
288
283
289
max (a:: T , b:: T ) where {T<: AbstractGray } = T (max (gray (a),gray (b)))
284
290
max (a:: AbstractGray , b:: AbstractGray ) = max (promote (a,b)... )
@@ -384,7 +390,6 @@ function ⊗(a::AbstractRGB, b::AbstractRGB)
384
390
agbr, abbg, arbb, abbr, arbg, agbb = ag* br, ab* bg, ar* bb, ab* br, ar* bg, ag* bb
385
391
return RGBRGB (ar* br, agbr, abbr, arbg, ag* bg, abbg, arbb, agbb, ab* bb)
386
392
end
387
- ⊗ (a:: Union{AbstractRGB,AbstractGray} , b:: Union{AbstractRGB,AbstractGray} ) = ⊗ (promote (a, b)... )
388
393
389
394
"""
390
395
varmult(op, itr; corrected::Bool=true, mean=Statistics.mean(itr), dims=:)
@@ -432,6 +437,26 @@ function __init__()
432
437
# Color is not necessary, this is just to show it's possible.
433
438
A, B = argtypes
434
439
A != = B && print (io, " \n In binary operation with $A and $B , the return type is ambiguous" )
440
+ elseif exc. f === dot && length (argtypes) == 2
441
+ if any (C -> C <: Union{TransparentGray, TransparentRGB} , argtypes)
442
+ print (io, " \n `dot` (or `⋅`) for transparent colors is not supported " )
443
+ print (io, " because the normalization is designed for opaque grays and RGBs." )
444
+ print (io, " \n You can use `reducec(+, 0, mapc(float, a) ⊙ mapc(float, b))` " )
445
+ print (io, " to get the dot product without normalization." )
446
+ end
447
+ elseif exc. f === tensor && length (argtypes) == 2
448
+ if any (C -> C <: Union{TransparentGray, TransparentRGB} , argtypes)
449
+ print (io, " \n `tensor` (or `⊗`) for transparent colors is not supported " )
450
+ print (io, " due to the non-high demand." )
451
+ end
452
+ elseif exc. f === abs2 && length (argtypes) == 1
453
+ C = argtypes[1 ]
454
+ if C <: MathTypes
455
+ print (io, " \n It is ambiguous whether `abs2(::$C )` should return a real number " )
456
+ print (io, " or a color object." )
457
+ print (io, " \n You can use `_abs2(c) = mapreducec(v->float(v)^2, +, 0, c)` " )
458
+ print (io, " to get the value compatible with ColorVectorSpace v0.8 or earlier." )
459
+ end
435
460
end
436
461
end
437
462
end
0 commit comments