Skip to content

Commit

Permalink
Fix depwarn on 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed May 12, 2016
1 parent fbf9e98 commit 6f800ee
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 36 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ SIUnits
Zlib
Graphics 0.1
FileIO
Compat 0.7.15
4 changes: 2 additions & 2 deletions docs/src/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ are the only two fields in the first concrete image type, called `Image`:
```julia
type Image{T,N,A<:AbstractArray} <: AbstractImageDirect{T,N}
data::A
properties::Dict{ASCIIString,Any}
properties::Dict{String,Any}
end
```

Expand All @@ -82,7 +82,7 @@ The only other concrete image type is for indexed images:
type ImageCmap{T,N,A<:AbstractArray,C<:AbstractArray} <: AbstractImageIndexed{T,N}
data::A
cmap::C
properties::Dict{ASCIIString,Any}
properties::Dict{String,Any}
end
```

Expand Down
2 changes: 2 additions & 0 deletions src/Images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ typealias TransparentGray{C<:AbstractGray,T} TransparentColor{C,T,2}
using Graphics
import Graphics: width, height, Point
import FixedPointNumbers: ufixed8, ufixed10, ufixed12, ufixed14, ufixed16
using Compat
import Compat.String

using Base.Cartesian
include("compatibility/forcartesian.jl")
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ end

# flips the dimension specified by name instead of index
# it is thus independent of the storage order
Base.flipdim(img::AbstractImage, dimname::ASCIIString) = shareproperties(img, flipdim(data(img), dimindex(img, dimname)))
Base.flipdim(img::AbstractImage, dimname::String) = shareproperties(img, flipdim(data(img), dimindex(img, dimname)))

flipx(img::AbstractImage) = flipdim(img, "x")
flipy(img::AbstractImage) = flipdim(img, "y")
Expand Down Expand Up @@ -1259,7 +1259,7 @@ function restrict(A::AbstractArray, region::Union{Dims, Vector{Int}}=coords_spat
A
end

function restrict{S<:ByteString}(img::AbstractImageDirect, region::Union{Tuple{Vararg{ByteString}}, Vector{S}})
function restrict{S<:String}(img::AbstractImageDirect, region::Union{Tuple{Vararg{String}}, Vector{S}})
so = spatialorder(img)
regioni = Int[]
for i = 1:length(region)
Expand Down Expand Up @@ -1406,7 +1406,7 @@ imresize(original, new_size) = imresize!(similar(original, new_size), original)

convertsafely{T<:AbstractFloat}(::Type{T}, val) = convert(T, val)
convertsafely{T<:Integer}(::Type{T}, val::Integer) = convert(T, val)
convertsafely{T<:Integer}(::Type{T}, val::AbstractFloat) = trunc(T, val+oftype(val, 0.5))
convertsafely{T<:Integer}(::Type{T}, val::AbstractFloat) = round(T, val)
convertsafely{T}(::Type{T}, val) = convert(T, val)


Expand Down
2 changes: 1 addition & 1 deletion src/connected.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function label_components!(Albl::AbstractArray{Int}, A::Array, region::Union{Dim
# Need to generate the function
N = length(uregion)
ND = ndims(A)
iregion = [symbol(string("i_",d)) for d in uregion]
iregion = [Symbol("i_", d) for d in uregion]
f! = eval(quote
local lc!
function lc!(Albl::AbstractArray{Int}, sets, A::Array, bkg)
Expand Down
36 changes: 18 additions & 18 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ along one of the dimensions of the array (as opposed to using a
"""
type Image{T,N,A<:AbstractArray} <: AbstractImageDirect{T,N}
data::A
properties::Dict{ASCIIString,Any}
properties::Dict{Compat.ASCIIString,Any}
end
Image(data::AbstractArray, props::Dict) = Image{eltype(data),ndims(data),typeof(data)}(data,props)
Image{T,N}(data::AbstractArray{T,N}, props::Dict) = Image{T,N,typeof(data)}(data,props)
Expand All @@ -46,7 +46,7 @@ creates an indexed (colormap) image.
type ImageCmap{T<:Colorant,N,A<:AbstractArray} <: AbstractImageIndexed{T,N}
data::A
cmap::Vector{T}
properties::Dict{ASCIIString,Any}
properties::Dict{Compat.ASCIIString,Any}
end
ImageCmap{_,N}(data::AbstractArray{_,N}, cmap::AbstractVector, props::Dict) = ImageCmap{eltype(cmap),N,typeof(data)}(data, cmap, props)
ImageCmap(data::AbstractArray, cmap::AbstractVector; kwargs...) = ImageCmap(data, cmap, kwargs2dict(kwargs))
Expand Down Expand Up @@ -157,7 +157,7 @@ if VERSION < v"0.5.0-dev"
function dictcopy(dct)
newkeys = [copy(key) for key in keys(dct)]
newvals = [copy(val) for val in values(dct)]
Dict{ASCIIString,Any}(zip(newkeys,newvals))
Dict{Compat.ASCIIString,Any}(zip(newkeys,newvals))
end
else
dictcopy(dct) = deepcopy(dct)
Expand Down Expand Up @@ -212,7 +212,7 @@ similar{T}(img::AbstractImageIndexed, ::Type{T}) = ImageCmap(similar(img.data, T
similar{T}(img::AbstractImageIndexed, ::Type{T}, dims::Dims) = ImageCmap(similar(img.data, T, dims), copy(img.cmap), copy(img.properties))

# copy properties
function copy!(imgdest::AbstractImage, imgsrc::AbstractImage, prop1::ASCIIString, props::ASCIIString...)
function copy!(imgdest::AbstractImage, imgsrc::AbstractImage, prop1::String, props::String...)
imgdest[prop1] = imgsrc[prop1]
for p in props
imgdest[p] = imgsrc[p]
Expand Down Expand Up @@ -504,20 +504,20 @@ getindex(img::AbstractImage, I::RealIndex, J::RealIndex,
getindex(img::AbstractImage, I::RealIndex...) = getindex(img.data, I...)

# getindex(img::AbstractImage, dimname::AbstractString, ind::RealIndex, nameind...) = getindex(img.data, coords(img, dimname, ind, nameind...)...)
getindex(img::AbstractImage, dimname::ASCIIString, ind, nameind...) = getindex(img.data, coords(img, dimname, ind, nameind...)...)
getindex(img::AbstractImage, dimname::String, ind, nameind...) = getindex(img.data, coords(img, dimname, ind, nameind...)...)

getindex(img::AbstractImage, propname::ASCIIString) = getindex(img.properties, propname)
getindex(img::AbstractImage, propname::String) = getindex(img.properties, propname)

typealias Indexable{T<:Real} Union{Int, AbstractVector{T}, Colon} # for ambiguity resolution
sub(img::AbstractImage, I::Indexable...) = sub(img.data, I...)
sub(img::AbstractImage, I::RealIndex...) = sub(img.data, I...)

sub(img::AbstractImage, dimname::ASCIIString, ind::RealIndex, nameind...) = sub(img.data, coords(img, dimname, ind, nameind...)...)
sub(img::AbstractImage, dimname::String, ind::RealIndex, nameind...) = sub(img.data, coords(img, dimname, ind, nameind...)...)

slice(img::AbstractImage, I::Indexable...) = slice(img.data, I...)
slice(img::AbstractImage, I::RealIndex...) = slice(img.data, I...)

slice(img::AbstractImage, dimname::ASCIIString, ind::RealIndex, nameind...) = slice(img.data, coords(img, dimname, ind, nameind...)...)
slice(img::AbstractImage, dimname::String, ind::RealIndex, nameind...) = slice(img.data, coords(img, dimname, ind, nameind...)...)

"""
```
Expand Down Expand Up @@ -555,7 +555,7 @@ _length(indx, A, d) = length(indx)
_length(indx::Colon, A, d) = size(A,d)


getindexim(img::AbstractImage, dimname::ASCIIString, ind::RealIndex, nameind...) = getindexim(img, coords(img, dimname, ind, nameind...)...)
getindexim(img::AbstractImage, dimname::String, ind::RealIndex, nameind...) = getindexim(img, coords(img, dimname, ind, nameind...)...)

"""
```
Expand All @@ -567,7 +567,7 @@ returns an `Image` with `SubArray` data, with indexing semantics similar to `sub
subim(img::AbstractImage, I::RealIndex...) = _subim(img, I)
_subim{TT}(img, I::TT) = shareproperties(img, sub(img.data, I...)) # work around #8504

subim(img::AbstractImage, dimname::ASCIIString, ind::RealIndex, nameind...) = subim(img, coords(img, dimname, ind, nameind...)...)
subim(img::AbstractImage, dimname::String, ind::RealIndex, nameind...) = subim(img, coords(img, dimname, ind, nameind...)...)

"""
```
Expand Down Expand Up @@ -907,15 +907,15 @@ csinfer{C<:Colorant}(::Type{C}) = ColorTypes.colorant_string(C)
csinfer(C) = "Unknown"
colorspace(img::AbstractImage) = get(img.properties, "colorspace", "Unknown")

colorspacedict = Dict{ASCIIString,Any}()
colorspacedict = Dict{Compat.ASCIIString,Any}()
for ACV in (Color, AbstractRGB)
for CV in subtypes(ACV)
(length(CV.parameters) == 1 && !(CV.abstract)) || continue
str = string(CV.name.name)
colorspacedict[str] = CV
end
end
function getcolortype{T}(str::ASCIIString, ::Type{T})
function getcolortype{T}(str::String, ::Type{T})
if haskey(colorspacedict, str)
CV = colorspacedict[str]
return CV{T}
Expand Down Expand Up @@ -1045,7 +1045,7 @@ and `"color"` for color.
See also: `spatialorder`, `colordim`, `timedim`.
"""
function storageorder(img::AbstractArray)
so = Array(ASCIIString, ndims(img))
so = Array(Compat.ASCIIString, ndims(img))
so[coords_spatial(img)] = spatialorder(img)
cd = colordim(img)
if cd != 0
Expand Down Expand Up @@ -1363,7 +1363,7 @@ function spatialproperties(img::AbstractImage)
if haskey(img, "spatialproperties")
return img.properties["spatialproperties"]
end
spatialprops = ASCIIString[]
spatialprops = Compat.ASCIIString[]
if haskey(img, "spatialorder")
push!(spatialprops, "spatialorder")
end
Expand All @@ -1375,7 +1375,7 @@ function spatialproperties(img::AbstractImage)
end
spatialprops
end
spatialproperties(img::AbstractVector) = ASCIIString[] # these are not mutable
spatialproperties(img::AbstractVector) = Compat.ASCIIString[] # these are not mutable


#### Low-level utilities ####
Expand Down Expand Up @@ -1424,7 +1424,7 @@ end
# Support indexing via
# img["t", 32, "x", 100:400]
# where anything not mentioned by name is assumed to include the whole range
function coords(img::AbstractImage, dimname::ASCIIString, ind, nameind...)
function coords(img::AbstractImage, dimname::String, ind, nameind...)
c = Any[1:d for d in size(img)]
so = spatialorder(img)
c[require_dimindex(img, dimname, so)] = ind
Expand All @@ -1446,7 +1446,7 @@ function coords(img::AbstractImage; kwargs...)
end


function dimindex(img::AbstractImage, dimname::ASCIIString, so = spatialorder(img))
function dimindex(img::AbstractImage, dimname::String, so = spatialorder(img))
n::Int = 0
if dimname == "color"
n = colordim(img)
Expand Down Expand Up @@ -1482,7 +1482,7 @@ to_vector(v::Tuple) = [v...]

# converts keyword argument to a dictionary
function kwargs2dict(kwargs)
d = Dict{ASCIIString,Any}()
d = Dict{Compat.ASCIIString,Any}()
for (k, v) in kwargs
d[string(k)] = v
end
Expand Down
3 changes: 0 additions & 3 deletions src/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,3 @@ end

ufixedsc{T<:UFixed}(::Type{T}, img::AbstractImageDirect) = immap(mapinfo(T, img), img)
ufixed8sc(img::AbstractImageDirect) = ufixedsc(UFixed8, img)

convertsafely{T}(::Type{T}, val) = convert(T, val)
convertsafely{T<:Integer}(::Type{T}, val::AbstractFloat) = round(T, val)
2 changes: 1 addition & 1 deletion src/overlays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ end
for NC = 1:3
NCm = NC-1
for K = 1:4
indexargs = Symbol[symbol(string("i_",d)) for d = 1:K]
indexargs = Symbol[Symbol("i_", d) for d = 1:K]
sigargs = Expr[:($a::Integer) for a in indexargs]
@eval begin
function getindex{T,N,AT,MITypes}(O::Overlay{T,N,$NC,AT,MITypes}, $(sigargs...))
Expand Down
9 changes: 5 additions & 4 deletions test/core.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FactCheck, Images, Colors, FixedPointNumbers
using Compat

testing_units = Int == Int64
if testing_units
Expand All @@ -15,7 +16,7 @@ facts("Core") do
# img, imgd, and imgds will be used in many more tests
# Thus, these must be defined as local if reassigned in any context() blocks
cmap = reinterpret(RGB, repmat(reinterpret(UFixed8, round(UInt8, linspace(12, 255, 20)))', 3, 1))
img = ImageCmap(copy(B), cmap, Dict{ASCIIString, Any}([("pixelspacing", [2.0, 3.0]), ("spatialorder", Images.yx)]))
img = ImageCmap(copy(B), cmap, Dict{Compat.ASCIIString, Any}([("pixelspacing", [2.0, 3.0]), ("spatialorder", Images.yx)]))
imgd = convert(Image, img)
if testing_units
imgd["pixelspacing"] = [2.0mm, 3.0mm]
Expand Down Expand Up @@ -84,7 +85,7 @@ facts("Core") do

context("Indexed color") do
let cmap = linspace(RGB(0x0cuf8, 0x00uf8, 0x00uf8), RGB(0xffuf8, 0x00uf8, 0x00uf8), 20)
img_ = ImageCmap(copy(B), cmap, Dict{ASCIIString, Any}([("spatialorder", Images.yx)]))
img_ = ImageCmap(copy(B), cmap, Dict{Compat.ASCIIString, Any}([("spatialorder", Images.yx)]))
@fact colorspace(img_) --> "RGB"
img_ = ImageCmap(copy(B), cmap, spatialorder=Images.yx)
@fact colorspace(img_) --> "RGB"
Expand Down Expand Up @@ -193,9 +194,9 @@ facts("Core") do
@fact coords_spatial(img) --> coords_spatial(imgd)
@fact size_spatial(img) --> size_spatial(imgd)
A = randn(3,5,3)
tmp = Image(A, Dict{ASCIIString,Any}())
tmp = Image(A, Dict{Compat.ASCIIString,Any}())
copy!(tmp, imgd, "spatialorder")
@fact properties(tmp) --> Dict{ASCIIString,Any}([("spatialorder",Images.yx)])
@fact properties(tmp) --> Dict{Compat.ASCIIString,Any}([("spatialorder",Images.yx)])
copy!(tmp, imgd, "spatialorder", "pixelspacing")
if testing_units
@fact tmp["pixelspacing"] --> [2.0mm, 3.0mm]
Expand Down
7 changes: 4 additions & 3 deletions test/map.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FactCheck, Images, Colors, FixedPointNumbers
using Compat

macro chk(a, b)
:(@fact ($a == $b && typeof($a) == typeof($b)) --> true)
Expand Down Expand Up @@ -265,7 +266,7 @@ facts("Map") do
gray = collect(linspace(0.0,1.0,5)) # a 1-dimensional image
gray8 = round(UInt8, 255*gray)
gray32 = UInt32[convert(UInt32, g)<<16 | convert(UInt32, g)<<8 | convert(UInt32, g) for g in gray8]
imgray = Images.Image(gray, Dict{ASCIIString,Any}([("colordim",0), ("colorspace","Gray")]))
imgray = Images.Image(gray, Dict{Compat.ASCIIString,Any}([("colordim",0), ("colorspace","Gray")]))
buf = map(Images.mapinfo(UInt32, imgray), imgray) # Images.uint32color(imgray)
@fact buf --> gray32
rgb = RGB{Float64}[RGB(g, g, g) for g in gray]
Expand All @@ -277,13 +278,13 @@ facts("Map") do
buf = map(Images.mapinfo(UInt32, img), img) # Images.uint32color(img)
@fact buf --> gray32
rgb = repeat(gray, outer=[1,3])
img = Images.Image(rgb, Dict{ASCIIString,Any}([("colordim",2), ("colorspace","RGB"), ("spatialorder",["x"])]))
img = Images.Image(rgb, Dict{Compat.ASCIIString,Any}([("colordim",2), ("colorspace","RGB"), ("spatialorder",["x"])]))
buf = map(Images.mapinfo(UInt32, img), img) # Images.uint32color(img)
@fact buf --> gray32
g = green(img)
@fact g --> gray
rgb = repeat(gray', outer=[3,1])
img = Images.Image(rgb, Dict{ASCIIString,Any}([("colordim",1), ("colorspace","RGB"), ("spatialorder",["x"])]))
img = Images.Image(rgb, Dict{Compat.ASCIIString,Any}([("colordim",1), ("colorspace","RGB"), ("spatialorder",["x"])]))
buf = map(Images.mapinfo(UInt32, img), img) # Images.uint32color(img)
@fact buf --> gray32
b = blue(img)
Expand Down
3 changes: 2 additions & 1 deletion test/overlays.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FactCheck, Images, Colors, FixedPointNumbers
using Compat

facts("Overlay") do
gray = linspace(0.0, 1.0, 5)
Expand Down Expand Up @@ -52,7 +53,7 @@ facts("Overlay") do
end

context("Four") do
img1 = Images.Image(gray, Dict{ASCIIString, Any}([("colorspace", "Gray"), ("spatialorder",["x"])]))
img1 = Images.Image(gray, Dict{Compat.ASCIIString, Any}([("colorspace", "Gray"), ("spatialorder",["x"])]))
ovr = Images.OverlayImage((2gray, img1), (RGB{Float32}(1, 0, 1), RGB{Float32}(0, 1, 0)), ((0, 1),(0, 1)))
@fact isa(ovr, Images.Image) --> true
@fact haskey(ovr, "colorspace") --> false
Expand Down

0 comments on commit 6f800ee

Please sign in to comment.