Skip to content

Commit

Permalink
Merge pull request #22 from JuliaImages/teh/more_0.6depwarns
Browse files Browse the repository at this point in the history
Fix typealias and IndexStyle depwarns on Julia 0.6
  • Loading branch information
timholy authored Feb 18, 2017
2 parents b31e927 + 15087c5 commit 0077965
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 33 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ MappedArrays 0.0.3
Graphics
ShowItLikeYouBuildIt
OffsetArrays
Compat 0.19
5 changes: 3 additions & 2 deletions src/ImageCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ module ImageCore

using Colors, FixedPointNumbers, MappedArrays, Graphics, ShowItLikeYouBuildIt
using OffsetArrays # for show.jl
using Compat
using ColorTypes: colorant_string
using Colors: Fractional

using Base: tail, @pure, Indices

import Graphics: width, height

typealias AbstractGray{T} Color{T,1}
typealias RealLike Union{Real,AbstractGray}
@compat AbstractGray{T} = Color{T,1}
const RealLike = Union{Real,AbstractGray}

export
## Types
Expand Down
26 changes: 13 additions & 13 deletions src/colorchannels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
# switch:
const squeeze1 = true # when true, don't use a dimension for the color channel of grayscale

typealias Color1{T} Colorant{T,1}
typealias Color2{T} Colorant{T,2}
typealias Color3{T} Colorant{T,3}
typealias Color4{T} Colorant{T,4}
typealias AColor{N,C,T} AlphaColor{C,T,N}
typealias ColorA{N,C,T} ColorAlpha{C,T,N}
typealias NonparametricColors Union{RGB24,ARGB32,Gray24,AGray32}
@compat Color1{T} = Colorant{T,1}
@compat Color2{T} = Colorant{T,2}
@compat Color3{T} = Colorant{T,3}
@compat Color4{T} = Colorant{T,4}
@compat AColor{N,C,T} = AlphaColor{C,T,N}
@compat ColorA{N,C,T} = ColorAlpha{C,T,N}
const NonparametricColors = Union{RGB24,ARGB32,Gray24,AGray32}

## ChannelView

Expand Down Expand Up @@ -59,16 +59,16 @@ function _channelview{C<:Colorant,N}(parent::AbstractArray{C}, inds::Indices{N})
ChannelView{eltype(C),N,typeof(parent)}(parent)
end

typealias Color1Array{C<:Color1,N} AbstractArray{C,N}
typealias ChannelView1{T,N,A<:Color1Array} ChannelView{T,N,A}
@compat Color1Array{C<:Color1,N} = AbstractArray{C,N}
@compat ChannelView1{T,N,A<:Color1Array} = ChannelView{T,N,A}

Base.parent(A::ChannelView) = A.parent
parenttype{T,N,A}(::Type{ChannelView{T,N,A}}) = A
@inline Base.size(A::ChannelView) = channelview_size(parent(A))
@inline Base.indices(A::ChannelView) = channelview_indices(parent(A))

# Can be LinearFast for grayscale (1-channel images), otherwise must be LinearSlow
@pure Base.linearindexing{T<:ChannelView1}(::Type{T}) = Base.linearindexing(parenttype(T))
# Can be IndexLinear for grayscale (1-channel images), otherwise must be IndexCartesian
@compat Base.IndexStyle{T<:ChannelView1}(::Type{T}) = IndexStyle(parenttype(T))

# colortype(A::ChannelView) = eltype(parent(A))

Expand Down Expand Up @@ -140,8 +140,8 @@ parenttype{T,N,A}(::Type{ColorView{T,N,A}}) = A
@inline Base.size(A::ColorView) = colorview_size(eltype(A), parent(A))
@inline Base.indices(A::ColorView) = colorview_indices(eltype(A), parent(A))

@pure Base.linearindexing{C<:Color1,N,A<:AbstractArray}(::Type{ColorView{C,N,A}}) = Base.linearindexing(A)
@pure Base.linearindexing{V<:ColorView}(::Type{V}) = Base.LinearSlow()
@compat Base.IndexStyle{C<:Color1,N,A<:AbstractArray}(::Type{ColorView{C,N,A}}) = IndexStyle(A)
@compat Base.IndexStyle{V<:ColorView}(::Type{V}) = IndexCartesian()

Base.@propagate_inbounds function Base.getindex{C,N}(A::ColorView{C,N}, I::Vararg{Int,N})
P = parent(A)
Expand Down
2 changes: 1 addition & 1 deletion src/convert_reinterpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function Base.convert{Cdest<:Color1,n,T<:Real}(::Type{Array{Cdest,n}},
end

# for docstrings in the operations below
shortname{T<:FixedPoint}(::Type{T}) = (io = IOBuffer(); FixedPointNumbers.showtype(io, T); takebuf_string(io))
shortname{T<:FixedPoint}(::Type{T}) = (io = IOBuffer(); FixedPointNumbers.showtype(io, T); String(take!(io)))
shortname{T}(::Type{T}) = string(T)

# float32, float64, etc. Used for conversions like
Expand Down
4 changes: 2 additions & 2 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end
Base.summary(A::Base.PermutedDimsArrays.PermutedDimsArray) = summary_build(A)

# rawview
typealias AAFixed{T<:FixedPoint,N} AbstractArray{T,N}
@compat AAFixed{T<:FixedPoint,N} = AbstractArray{T,N}
function ShowItLikeYouBuildIt.showarg{T<:Integer,N,AA<:AAFixed}(io::IO, A::MappedArray{T,N,AA,typeof(reinterpret)})
print(io, "rawview(")
showarg(io, parent(A))
Expand All @@ -35,7 +35,7 @@ end
Base.summary{T<:Integer,N,AA}(A::MappedArray{T,N,AA,typeof(reinterpret)}) = summary_build(A)

# normedview
typealias AAInteger{T<:Integer,N} AbstractArray{T,N}
@compat AAInteger{T<:Integer,N} = AbstractArray{T,N}
function ShowItLikeYouBuildIt.showarg{T<:FixedPoint,N,AA<:AAInteger,F}(io::IO, A::MappedArray{T,N,AA,F,typeof(reinterpret)})
print(io, "normedview(")
showcoloranttype(io, T)
Expand Down
2 changes: 1 addition & 1 deletion src/traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ By default this is computed from `pixelspacing`, but you can set this
manually using ImagesMeta.
"""
spacedirections(img::AbstractArray) = _spacedirections(pixelspacing(img))
function _spacedirections{N}(ps::NTuple{N})
function _spacedirections{N}(ps::NTuple{N,Any})
ntuple(i->ntuple(d->d==i ? ps[d] : zero(ps[d]), Val{N}), Val{N})
end

Expand Down
29 changes: 15 additions & 14 deletions test/colorchannels.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using Colors, ImageCore, OffsetArrays, FixedPointNumbers, Base.Test
using Compat

immutable ArrayLF{T,N} <: AbstractArray{T,N}
A::Array{T,N}
end
Base.linearindexing{A<:ArrayLF}(::Type{A}) = Base.LinearFast()
@compat Base.IndexStyle{A<:ArrayLF}(::Type{A}) = IndexLinear()
Base.size(A::ArrayLF) = size(A.A)
Base.getindex(A::ArrayLF, i::Int) = A.A[i]
Base.setindex!(A::ArrayLF, val, i::Int) = A.A[i] = val

immutable ArrayLS{T,N} <: AbstractArray{T,N}
A::Array{T,N}
end
Base.linearindexing{A<:ArrayLS}(::Type{A}) = Base.LinearSlow()
@compat Base.IndexStyle{A<:ArrayLS}(::Type{A}) = IndexCartesian()
Base.size(A::ArrayLS) = size(A.A)
Base.getindex{T,N}(A::ArrayLS{T,N}, i::Vararg{Int,N}) = A.A[i...]
Base.setindex!{T,N}(A::ArrayLS{T,N}, val, i::Vararg{Int,N}) = A.A[i...] = val
Expand All @@ -23,12 +24,12 @@ Base.setindex!{T,N}(A::ArrayLS{T,N}, val, i::Vararg{Int,N}) = A.A[i...] = val
@test channelview(a) === a

a0 = [Gray(N0f8(0.2)), Gray(N0f8(0.4))]
for (a, VT, LI) in ((copy(a0), Array, Base.LinearFast()),
(ArrayLF(copy(a0)), ChannelView, Base.LinearFast()),
(ArrayLS(copy(a0)), ChannelView, Base.LinearSlow()))
for (a, VT, LI) in ((copy(a0), Array, IndexLinear()),
(ArrayLF(copy(a0)), ChannelView, IndexLinear()),
(ArrayLS(copy(a0)), ChannelView, IndexCartesian()))
v = ChannelView(a)
@test isa(channelview(a), VT)
@test Base.linearindexing(v) == LI
@test IndexStyle(v) == LI
@test isa(colorview(Gray, v), typeof(a))
@test ndims(v) == 2 - ImageCore.squeeze1
@test size(v) == (ImageCore.squeeze1 ? (2,) : (1, 2))
Expand Down Expand Up @@ -223,13 +224,13 @@ end
@testset "grayscale" begin
_a0 = [N0f8(0.2), N0f8(0.4)]
a0 = ImageCore.squeeze1 ? _a0 : reshape(_a0, (1, 2))
for (a, VT, LI) in ((copy(a0), Array{Gray{N0f8}}, Base.LinearFast()),
(ArrayLF(copy(a0)), ColorView{Gray{N0f8}}, Base.LinearFast()),
(ArrayLS(copy(a0)), ColorView{Gray{N0f8}}, Base.LinearSlow()))
for (a, VT, LI) in ((copy(a0), Array{Gray{N0f8}}, IndexLinear()),
(ArrayLF(copy(a0)), ColorView{Gray{N0f8}}, IndexLinear()),
(ArrayLS(copy(a0)), ColorView{Gray{N0f8}}, IndexCartesian()))
@test_throws ErrorException ColorView(a)
v = ColorView{Gray}(a)
@test isa(colorview(Gray,a), VT)
@test Base.linearindexing(v) == LI
@test IndexStyle(v) == LI
@test isa(channelview(v), typeof(a))
@test ndims(v) == 1
@test size(v) == (2,)
Expand Down Expand Up @@ -261,13 +262,13 @@ end
# two dimensional images and linear indexing
_a0 = N0f8[0.2 0.4; 0.6 0.8]
a0 = ImageCore.squeeze1 ? _a0 : reshape(_a0, (1, 2, 2))
for (a, VT, LI) in ((copy(a0), Array{Gray{N0f8}}, Base.LinearFast()),
(ArrayLF(copy(a0)), ColorView{Gray{N0f8}}, Base.LinearFast()),
(ArrayLS(copy(a0)), ColorView{Gray{N0f8}}, Base.LinearSlow()))
for (a, VT, LI) in ((copy(a0), Array{Gray{N0f8}}, IndexLinear()),
(ArrayLF(copy(a0)), ColorView{Gray{N0f8}}, IndexLinear()),
(ArrayLS(copy(a0)), ColorView{Gray{N0f8}}, IndexCartesian()))
@test_throws ErrorException ColorView(a)
v = ColorView{Gray}(a)
@test isa(colorview(Gray,a), VT)
@test Base.linearindexing(v) == LI
@test IndexStyle(v) == LI
@test isa(channelview(v), typeof(a))
@test ndims(v) == 2
@test size(v) == (2,2)
Expand Down

0 comments on commit 0077965

Please sign in to comment.