diff --git a/Project.toml b/Project.toml index c102ff3..93dcaf4 100644 --- a/Project.toml +++ b/Project.toml @@ -19,9 +19,9 @@ 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, 0.4" -MosaicViews = "0.2.3" +MosaicViews = "0.3.3" OffsetArrays = "0.8, 0.9, 0.10, 0.11, 1.0.1" -PaddedViews = "0.5.4" +PaddedViews = "0.5.8" Reexport = "0.2, 1.0" julia = "1" diff --git a/src/ImageCore.jl b/src/ImageCore.jl index 300f8ce..f8b3223 100644 --- a/src/ImageCore.jl +++ b/src/ImageCore.jl @@ -164,6 +164,12 @@ _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{T}, ::Type{S}) where {T<:Colorant,S<:Colorant} = promote_type(T, S) +MosaicViews.promote_wrapped_type(::Type{T}, ::Type{S}) where {T,S<:Colorant} = S === Union{} ? T : base_colorant_type(S){MosaicViews.promote_wrapped_type(T, eltype(S))} +MosaicViews.promote_wrapped_type(::Type{T}, ::Type{S}) where {T<:Colorant,S} = MosaicViews.promote_wrapped_type(S, T) + # Support transpose Base.transpose(a::AbstractMatrix{C}) where {C<:Colorant} = permutedims(a, (2,1)) function Base.transpose(a::AbstractVector{C}) where C<:Colorant diff --git a/test/views.jl b/test/views.jl index f569d34..b84240e 100644 --- a/test/views.jl +++ b/test/views.jl @@ -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 @@ -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 @@ -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 @@ -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