Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GenericImage and GenericRGBImage alias #80

Merged
merged 7 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ImageCore"
uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534"
version = "0.8.2"
version = "0.8.3"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand Down
10 changes: 7 additions & 3 deletions src/ImageCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ const RRArray{To,From,N,M,P} = Base.ReshapedArray{To,N,Base.ReinterpretArray{To,
const RGArray = Union{Base.ReinterpretArray{<:AbstractGray,M,<:Number,P}, Base.ReinterpretArray{<:Number,M,<:AbstractGray,P}} where {M,P}

# delibrately not export these constants to enable extensibility for downstream packages
const NumberLike{T<:Number} = Union{T,AbstractGray{T}}
const PixelLike{T<:Number} = Union{T, Colorant{T}}
const NumberLike{T<:Number} = Union{T, AbstractGray{T}}
const RealLike{T<:Real} = NumberLike{T}
const FloatLike{T<:AbstractFloat} = RealLike{T}
const FractionalLike{T<:Union{FixedPoint, AbstractFloat}} = RealLike{T}
const GrayLike{T<:Union{Bool, FixedPoint, AbstractFloat}} = RealLike{T}
const GenericGrayImage{N, T<:GrayLike} = AbstractArray{<:GrayLike{T}, N}
const Gray2dImage{T<:GrayLike} = GenericGrayImage{2, T}
const GenericImage{N, T<:Number} = AbstractArray{<:PixelLike{T}, N}
johnnychen94 marked this conversation as resolved.
Show resolved Hide resolved
const GenericGrayImage{N, T<:Number} = AbstractArray{<:GrayLike{T}, N}
const GenericRGBImage{N, T<:Number} = AbstractArray{<:AbstractRGB{T}, N}
const Gray2dImage{T<:Number} = GenericGrayImage{2, T}
const RGB2dImage{T<:Number} = GenericRGBImage{2, T}

export
## Types
Expand Down
74 changes: 71 additions & 3 deletions test/traits.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using ImageCore, Colors, FixedPointNumbers, ColorVectorSpace, MappedArrays, OffsetArrays
using Test
using ImageCore: NumberLike, RealLike, FloatLike, FractionalLike,
GrayLike, GenericGrayImage, Gray2dImage
using ImageCore: PixelLike, NumberLike, RealLike, FloatLike, FractionalLike,
GrayLike,
GenericImage, GenericGrayImage, GenericRGBImage, Gray2dImage, RGB2dImage

@testset "Image traits" begin
for (B, swap) in ((rand(UInt16(1):UInt16(20), 3, 5), false),
Expand Down Expand Up @@ -35,8 +36,20 @@ using ImageCore: NumberLike, RealLike, FloatLike, FractionalLike,
end
end

# delibrately written in a redundant way
@testset "*Like traits" begin
# delibrately written in a redundant way
@testset "PixelLike" begin
@test NumberLike <: PixelLike
@test FloatLike <: PixelLike
@test FractionalLike <: PixelLike

@test Gray <: PixelLike
@test RGB <: PixelLike

@test isa(oneunit(Gray), PixelLike)
@test isa(RGB(1.0, 0.0, 0.0), PixelLike)
end

@testset "NumberLike" begin
@test RealLike <: NumberLike
@test FloatLike <: NumberLike
Expand Down Expand Up @@ -106,6 +119,61 @@ end
@test !isa(oneunit(Gray), FloatLike)
end

@testset "GenericImage" begin
@test GenericGrayImage <: GenericImage
@test GenericRGBImage <: GenericImage

sz = (3,3)
@test isa(rand(Bool, sz), GenericImage)
@test isa(rand(N0f8, sz), GenericImage)
@test isa(rand(Float32, sz), GenericImage)

@test isa(rand(Gray, sz), GenericImage)
@test isa(rand(Gray{Bool}, sz), GenericImage)
@test isa(rand(Gray{N0f8}, sz), GenericImage)
@test isa(rand(Gray{Float32}, sz), GenericImage)

@test isa(rand(GrayA, sz), GenericImage)
@test isa(rand(GrayA{N0f8}, sz), GenericImage)
@test isa(rand(GrayA{Float32}, sz), GenericImage)

@test isa(rand(RGB, sz), GenericImage)
@test isa(rand(RGB{N0f8}, sz), GenericImage)
@test isa(rand(RGB{Float32}, sz), GenericImage)

@test isa(rand(RGBA, sz), GenericImage)
@test isa(rand(RGBA{N0f8}, sz), GenericImage)
@test isa(rand(RGBA{Float32}, sz), GenericImage)

@test isa(rand(Lab, sz), GenericImage)
@test isa(rand(Lab{Float32}, sz), GenericImage)

foo(img::GenericImage) = "Generic"
foo(img::GenericImage{N, <:AbstractFloat}) where N = "AbstractFloat"
foo(img::GenericImage{N, <:FixedPoint}) where N = "FixedPoint"
@test foo(rand(Bool, sz)) == "Generic"
@test foo(rand(Gray{Bool}, sz)) == "Generic"
@test foo(rand(Gray{Float32}, sz)) == "AbstractFloat"
@test foo(rand(Float32, sz)) == "AbstractFloat"
@test foo(rand(Gray{N0f8}, sz)) == "FixedPoint"
@test foo(rand(N0f8, sz)) == "FixedPoint"
end

@testset "RGBImage" begin
@test RGB2dImage{Float32} == GenericRGBImage{2, Float32}

sz = (3,3)
@test isa(rand(RGB, sz), GenericImage)
@test isa(rand(RGB{N0f8}, sz), GenericImage)
@test isa(rand(RGB{Float32}, sz), GenericImage)

foo(img::RGB2dImage) = "Generic"
foo(img::RGB2dImage{<:AbstractFloat}) = "AbstractFloat"
foo(img::RGB2dImage{<:FixedPoint}) = "FixedPoint"
@test foo(rand(RGB{Float32}, sz)) == "AbstractFloat"
@test foo(rand(RGB{N0f8}, sz)) == "FixedPoint"
end

@testset "GrayImage" begin
@test Gray2dImage{Float32} == GenericGrayImage{2, Float32}

Expand Down