Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -19,7 +19,7 @@ Colors = "0.9, 0.10, 0.11, 0.12"
FixedPointNumbers = "0.6.1, 0.7, 0.8"
Graphics = "0.4, 1.0"
MappedArrays = "0.2, 0.3"
MosaicViews = "0.2.3"
MosaicViews = "0.3.1"
OffsetArrays = "0.8, 0.9, 0.10, 0.11, 1.0.1"
PaddedViews = "0.5.4"
Reexport = "0.2, 1.0"
Expand Down
10 changes: 10 additions & 0 deletions src/ImageCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ _filltype(::Type{FC}, ::Type{C}) where {FC<:TransparentColor, C<:AbstractGray} =
_filltype(::Type{FC}, ::Type{C}) where {FC<:TransparentColor, C<:Color3} =
alphacolor(C){promote_type(eltype(FC), eltype(C))}


# MosaicViews support (require MosaicViews >= v0.3.0)
MosaicViews.promote_wrapped_type(::Type{C1}, ::Type{C2}) where {C1<:Colorant, C2<:Colorant} =
promote_type(base_colorant_type(C1), base_colorant_type(C2)){promote_type(eltype(C1), eltype(C2))}
MosaicViews.promote_wrapped_type(::Type{C}, ::Type{T}) where {C<:Colorant, T} =
base_colorant_type(C){promote_type(eltype(C), T)}
MosaicViews.promote_wrapped_type(::Type{T}, ::Type{C}) where {C<:Colorant, T} =
base_colorant_type(C){promote_type(eltype(C), T)}
MosaicViews.promote_wrapped_type(::Type{Union{}}, ::Type{C}) where C<:Colorant = C # ambiguity fix

# Support transpose
Base.transpose(a::AbstractMatrix{C}) where {C<:Colorant} = permutedims(a, (2,1))
function Base.transpose(a::AbstractVector{C}) where C<:Colorant
Expand Down
58 changes: 29 additions & 29 deletions test/views.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,21 @@ end
A1 = fill(Gray(1.), 2, 2)
A2 = fill(RGB(1., 0., 0.), 3, 3)
A3 = fill(RGB(0., 1., 0.), 3, 3)
out = mosaicview(A1, A2, A3) |> collect
out = mosaic(A1, A2, A3) |> collect
@test_reference "references/mosaicviews/2d_opaque_1.png" out by=isequal
out = mosaicview(A1, A2, A3; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
out = mosaic(A1, A2, A3; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
@test_reference "references/mosaicviews/2d_opaque_2.png" out by=isequal
out = mosaicview(A1, A2, A3; npad=2, fillvalue=Gray(0.), nrow=2, rowmajor=true) |> collect
out = mosaic(A1, A2, A3; npad=2, fillvalue=Gray(0.), nrow=2, rowmajor=true) |> collect
@test_reference "references/mosaicviews/2d_opaque_3.png" out by=isequal

A1 = fill(GrayA(1.), 2, 2)
A2 = fill(RGBA(1., 0., 0.), 3, 3)
A3 = fill(RGBA(0., 1., 0.), 3, 3)
out = mosaicview(A1, A2, A3) |> collect
out = mosaic(A1, A2, A3) |> collect
@test_reference "references/mosaicviews/2d_transparent_1.png" out by=isequal
out = mosaicview(A1, A2, A3; npad=2, fillvalue=GrayA(0., 0.), nrow=2) |> collect
out = mosaic(A1, A2, A3; npad=2, fillvalue=GrayA(0., 0.), nrow=2) |> collect
@test_reference "references/mosaicviews/2d_transparent_2.png" out by=isequal
out = mosaicview(A1, A2, A3; npad=2, fillvalue=GrayA(0., 0.), nrow=2, rowmajor=true) |> collect
out = mosaic(A1, A2, A3; npad=2, fillvalue=GrayA(0., 0.), nrow=2, rowmajor=true) |> collect
@test_reference "references/mosaicviews/2d_transparent_3.png" out by=isequal
end

Expand All @@ -209,26 +209,26 @@ end
A[:, :, 1] .= RGB(1., 0., 0.)
A[:, :, 2] .= RGB(0., 1., 0.)
A[:, :, 3] .= RGB(0., 0., 1.)
out = mosaicview(A) |> collect
out = mosaic(A) |> collect
@test_reference "references/mosaicviews/3d_opaque_1.png" out by=isequal
out = mosaicview(A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
out = mosaic(A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
@test_reference "references/mosaicviews/3d_opaque_2.png" out by=isequal
out = mosaicview(A; npad=2, fillvalue=Gray(0.), nrow=2, rowmajor=true) |> collect
out = mosaic(A; npad=2, fillvalue=Gray(0.), nrow=2, rowmajor=true) |> collect
@test_reference "references/mosaicviews/3d_opaque_3.png" out by=isequal
out = mosaicview(A, A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
out = mosaic(A, A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
@test_reference "references/mosaicviews/3d_opaque_4.png" out by=isequal

A = fill(RGBA(0., 0., 0.), 2, 2, 3)
A[:, :, 1] .= RGBA(1., 0., 0.)
A[:, :, 2] .= RGBA(0., 1., 0.)
A[:, :, 3] .= RGBA(0., 0., 1.)
out = mosaicview(A) |> collect
out = mosaic(A) |> collect
@test_reference "references/mosaicviews/3d_transparent_1.png" out by=isequal
out = mosaicview(A; npad=2, fillvalue=GrayA(0., 0.), nrow=2) |> collect
out = mosaic(A; npad=2, fillvalue=GrayA(0., 0.), nrow=2) |> collect
@test_reference "references/mosaicviews/3d_transparent_2.png" out by=isequal
out = mosaicview(A; npad=2, fillvalue=GrayA(0.), nrow=2, rowmajor=true) |> collect
out = mosaic(A; npad=2, fillvalue=GrayA(0.), nrow=2, rowmajor=true) |> collect
@test_reference "references/mosaicviews/3d_transparent_3.png" out by=isequal
out = mosaicview(A, A; npad=2, fillvalue=GrayA(0.), nrow=2) |> collect
out = mosaic(A, A; npad=2, fillvalue=GrayA(0.), nrow=2) |> collect
@test_reference "references/mosaicviews/3d_transparent_4.png" out by=isequal
end

Expand All @@ -237,26 +237,26 @@ end
A[1, :, 1, 1] .= RGB(1., 0., 0.)
A[:, :, 1, 2] .= RGB(0., 1., 0.)
A[:, :, 2, 1] .= RGB(0., 0., 1.)
out = mosaicview(A) |> collect
out = mosaic(A) |> collect
@test_reference "references/mosaicviews/4d_opaque_1.png" out by=isequal
out = mosaicview(A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
out = mosaic(A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
@test_reference "references/mosaicviews/4d_opaque_2.png" out by=isequal
out = mosaicview(A; npad=2, fillvalue=Gray(0.), nrow=2, rowmajor=true) |> collect
out = mosaic(A; npad=2, fillvalue=Gray(0.), nrow=2, rowmajor=true) |> collect
@test_reference "references/mosaicviews/4d_opaque_3.png" out by=isequal
out = mosaicview(A, A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
out = mosaic(A, A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
@test_reference "references/mosaicviews/4d_opaque_4.png" out by=isequal

A = fill(RGBA(0., 0., 0.), 2, 2, 2, 2)
A[1, :, 1, 1] .= RGBA(1., 0., 0.)
A[:, :, 1, 2] .= RGBA(0., 1., 0.)
A[:, :, 2, 1] .= RGBA(0., 0., 1.)
out = mosaicview(A) |> collect
out = mosaic(A) |> collect
@test_reference "references/mosaicviews/4d_transparent_1.png" out by=isequal
out = mosaicview(A; npad=2, fillvalue=GrayA(0., 0.), nrow=2) |> collect
out = mosaic(A; npad=2, fillvalue=GrayA(0., 0.), nrow=2) |> collect
@test_reference "references/mosaicviews/4d_transparent_2.png" out by=isequal
out = mosaicview(A; npad=2, fillvalue=GrayA(0., 0.), nrow=2, rowmajor=true) |> collect
out = mosaic(A; npad=2, fillvalue=GrayA(0., 0.), nrow=2, rowmajor=true) |> collect
@test_reference "references/mosaicviews/4d_transparent_3.png" out by=isequal
out = mosaicview(A, A; npad=2, fillvalue=GrayA(0.), nrow=2) |> collect
out = mosaic(A, A; npad=2, fillvalue=GrayA(0.), nrow=2) |> collect
@test_reference "references/mosaicviews/4d_transparent_4.png" out by=isequal
end
end
Expand Down Expand Up @@ -351,22 +351,22 @@ end
@test Ap[axes(A)...] == ARGB{Float32}.(A)

# order irrelevant
A = mosaicview(rand(Float32, 4, 4), rand(RGB{N0f8}, 4, 4))
A = mosaic(rand(Float32, 4, 4), rand(RGB{N0f8}, 4, 4))
@test eltype(A) == RGB{Float32}
A = mosaicview(rand(RGB{N0f8}, 4, 4), rand(Float32, 4, 4))
A = mosaic(rand(RGB{N0f8}, 4, 4), rand(Float32, 4, 4))
@test eltype(A) == RGB{Float32}

A = mosaicview(rand(Float32, 4, 4), rand(Gray{Float64}, 4, 4))
A = mosaic(rand(Float32, 4, 4), rand(Gray{Float64}, 4, 4))
@test eltype(A) == Gray{Float64}
A = mosaicview(rand(Gray{Float64}, 4, 4), rand(Float32, 4, 4))
A = mosaic(rand(Gray{Float64}, 4, 4), rand(Float32, 4, 4))
@test eltype(A) == Gray{Float64}

A = mosaicview(rand(Float32, 4, 4), rand(Gray{Float64}, 4, 4), rand(RGB{N0f8}, 4, 4))
A = mosaic(rand(Float32, 4, 4), rand(Gray{Float64}, 4, 4), rand(RGB{N0f8}, 4, 4))
@test eltype(A) == RGB{Float64}
A = mosaicview(rand(Float32, 4, 4), rand(RGB{N0f8}, 4, 4), rand(Gray{Float64}, 4, 4))
A = mosaic(rand(Float32, 4, 4), rand(RGB{N0f8}, 4, 4), rand(Gray{Float64}, 4, 4))
@test eltype(A) == RGB{Float64}

A = mosaicview(rand(Gray, 4, 4), rand(RGB, 4, 4))
A = mosaic(rand(Gray, 4, 4), rand(RGB, 4, 4))
@test eltype(A) == RGB{Float64} # the filltype is always a concrete type
end

Expand Down