Skip to content

Commit

Permalink
Deprecate eltype-specific convert methods
Browse files Browse the repository at this point in the history
These are technically pirating and cause quite a few invalidations.
Now that we have generic broadcasting they are no longer necessary.
  • Loading branch information
timholy committed Jun 19, 2020
1 parent bc9b086 commit dc65d29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 53 deletions.
53 changes: 0 additions & 53 deletions src/convert_reinterpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,59 +59,6 @@ ccolor_number(::Type{CV}, ::Type{T}) where {CV<:Colorant,T<:Number} =
ccolor_number(::Type{CV}, ::Type{CVT}, ::Type{T}) where {CV,CVT<:Number,T} = CV # form 1
ccolor_number(::Type{CV}, ::Type{Any}, ::Type{T}) where {CV<:Colorant,T} = CV{T} # form 2


### convert
#
# The main contribution here is "concretizing" the colorant type: allow
# convert(RGB, a)
# rather than requiring
# convert(RGB{N0f8}, a)
# Where possible the raw element type of the source is retained.
Base.convert(::Type{Array{C}}, img::Array{C,n}) where {C<:Color1,n} = img
Base.convert(::Type{Array{C,n}}, img::Array{C,n}) where {C<:Color1,n} = img
Base.convert(::Type{Array{C}}, img::Array{C,n}) where {C<:Colorant,n} = img
Base.convert(::Type{Array{C,n}}, img::Array{C,n}) where {C<:Colorant,n} = img

function Base.convert(::Type{Array{Cdest}},
img::AbstractArray{Csrc,n}) where {Cdest<:Colorant,n,Csrc<:Colorant}
convert(Array{Cdest,n}, img)
end

function Base.convert(::Type{Array{Cdest,n}},
img::AbstractArray{Csrc,n}) where {Cdest<:Colorant,n,Csrc<:Colorant}
copyto!(Array{ccolor(Cdest, Csrc)}(undef, size(img)), img)
end

function Base.convert(::Type{Array{Cdest}},
img::BitArray{n}) where {Cdest<:Color1,n}
convert(Array{Cdest,n}, img)
end

function Base.convert(::Type{Array{Cdest}},
img::AbstractArray{T,n}) where {Cdest<:Color1,n,T<:Real}
convert(Array{Cdest,n}, img)
end

function Base.convert(::Type{Array{Cdest,n}},
img::BitArray{n}) where {Cdest<:Color1,n}
copyto!(Array{ccolor(Cdest, Gray{Bool})}(undef, size(img)), img)
end

function Base.convert(::Type{Array{Cdest,n}},
img::AbstractArray{T,n}) where {Cdest<:Color1,n,T<:Real}
copyto!(Array{ccolor(Cdest, Gray{T})}(undef, size(img)), img)
end

function Base.convert(::Type{OffsetArray{Cdest,n,A}},
img::AbstractArray{Csrc,n}) where {Cdest<:Colorant,n, A <:AbstractArray,Csrc<:Colorant}
copyto!(OffsetArray{ccolor(Cdest, Csrc)}(undef, axes(img)),img)
end

function Base.convert(::Type{OffsetArray{C,n,A}},
img::AbstractArray{C,n}) where {C<:Colorant,n, A <:AbstractArray}
img
end

# for docstrings in the operations below
shortname(::Type{T}) where {T<:FixedPoint} = (io = IOBuffer(); FixedPointNumbers.showtype(io, T); String(take!(io)))
shortname(::Type{T}) where {T} = string(T)
Expand Down
25 changes: 25 additions & 0 deletions src/deprecations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,28 @@ end
ColorView(parent::AbstractArray) = error("must specify the colortype, use colorview(C, A)")

Base.@deprecate_binding squeeze1 true

import Base: convert

function cname(::Type{C}) where C
io = IOBuffer()
ColorTypes.colorant_string_with_eltype(io, C)
return String(take!(io))
end

function convert(::Type{Array{Cdest}}, img::AbstractArray{Csrc,n}) where {Cdest<:Colorant,n,Csrc<:Colorant}
Base.depwarn("`convert(Array{$(cname(Cdest))}, img)` is deprecated, use $(cname(Cdest)).(img) instead", :convert)
Cdest.(img)
end

function convert(::Type{Array{Cdest}}, img::AbstractArray{T,n}) where {Cdest<:Color1,n,T<:Real}
Base.depwarn("`convert(Array{$(cname(Cdest))}, img)` is deprecated, use $(cname(Cdest)).(img) instead", :convert)
Cdest.(img)
end

function convert(::Type{OffsetArray{Cdest,n,A}}, img::AbstractArray{Csrc,n}) where {Cdest<:Colorant,n, A <:AbstractArray,Csrc<:Colorant}
Base.depwarn("`convert(OffsetArray{$(cname(Cdest))}, img)` is deprecated, use $(cname(Cdest)).(img) instead", :convert)
Cdest.(img)
end

convert(::Type{OffsetArray{Cdest,n,A}}, img::OffsetArray{Cdest,n,A}) where {Cdest<:Colorant,n, A <:AbstractArray} = img

0 comments on commit dc65d29

Please sign in to comment.