Skip to content

Commit 84bf26f

Browse files
committed
upgrade MosaicViews to 0.3
- extending the `promote_wrapped_type` method for `Colorant`s - deprecate `mosaicview` in favor of `mosaic`
1 parent a8f3d2c commit 84bf26f

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Colors = "0.9, 0.10, 0.11, 0.12"
1919
FixedPointNumbers = "0.6.1, 0.7, 0.8"
2020
Graphics = "0.4, 1.0"
2121
MappedArrays = "0.2, 0.3, 0.4"
22-
MosaicViews = "0.2.3"
22+
MosaicViews = "0.3"
2323
OffsetArrays = "0.8, 0.9, 0.10, 0.11, 1.0.1"
24-
PaddedViews = "0.5.4"
24+
PaddedViews = "0.5.8"
2525
Reexport = "0.2, 1.0"
2626
julia = "1"
2727

src/ImageCore.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ _filltype(::Type{FC}, ::Type{C}) where {FC<:TransparentColor, C<:AbstractGray} =
164164
_filltype(::Type{FC}, ::Type{C}) where {FC<:TransparentColor, C<:Color3} =
165165
alphacolor(C){promote_type(eltype(FC), eltype(C))}
166166

167+
168+
# MosaicViews support (require MosaicViews >= v0.3.0)
169+
MosaicViews.promote_wrapped_type(::Type{T}, ::Type{S}) where {T<:Colorant,S<:Colorant} = promote_type(T, S)
170+
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))}
171+
MosaicViews.promote_wrapped_type(::Type{T}, ::Type{S}) where {T<:Colorant,S} = MosaicViews.promote_wrapped_type(S, T)
172+
167173
# Support transpose
168174
Base.transpose(a::AbstractMatrix{C}) where {C<:Colorant} = permutedims(a, (2,1))
169175
function Base.transpose(a::AbstractVector{C}) where C<:Colorant

test/views.jl

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,21 @@ end
186186
A1 = fill(Gray(1.), 2, 2)
187187
A2 = fill(RGB(1., 0., 0.), 3, 3)
188188
A3 = fill(RGB(0., 1., 0.), 3, 3)
189-
out = mosaicview(A1, A2, A3) |> collect
189+
out = mosaic(A1, A2, A3) |> collect
190190
@test_reference "references/mosaicviews/2d_opaque_1.png" out by=isequal
191-
out = mosaicview(A1, A2, A3; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
191+
out = mosaic(A1, A2, A3; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
192192
@test_reference "references/mosaicviews/2d_opaque_2.png" out by=isequal
193-
out = mosaicview(A1, A2, A3; npad=2, fillvalue=Gray(0.), nrow=2, rowmajor=true) |> collect
193+
out = mosaic(A1, A2, A3; npad=2, fillvalue=Gray(0.), nrow=2, rowmajor=true) |> collect
194194
@test_reference "references/mosaicviews/2d_opaque_3.png" out by=isequal
195195

196196
A1 = fill(GrayA(1.), 2, 2)
197197
A2 = fill(RGBA(1., 0., 0.), 3, 3)
198198
A3 = fill(RGBA(0., 1., 0.), 3, 3)
199-
out = mosaicview(A1, A2, A3) |> collect
199+
out = mosaic(A1, A2, A3) |> collect
200200
@test_reference "references/mosaicviews/2d_transparent_1.png" out by=isequal
201-
out = mosaicview(A1, A2, A3; npad=2, fillvalue=GrayA(0., 0.), nrow=2) |> collect
201+
out = mosaic(A1, A2, A3; npad=2, fillvalue=GrayA(0., 0.), nrow=2) |> collect
202202
@test_reference "references/mosaicviews/2d_transparent_2.png" out by=isequal
203-
out = mosaicview(A1, A2, A3; npad=2, fillvalue=GrayA(0., 0.), nrow=2, rowmajor=true) |> collect
203+
out = mosaic(A1, A2, A3; npad=2, fillvalue=GrayA(0., 0.), nrow=2, rowmajor=true) |> collect
204204
@test_reference "references/mosaicviews/2d_transparent_3.png" out by=isequal
205205
end
206206

@@ -209,26 +209,26 @@ end
209209
A[:, :, 1] .= RGB(1., 0., 0.)
210210
A[:, :, 2] .= RGB(0., 1., 0.)
211211
A[:, :, 3] .= RGB(0., 0., 1.)
212-
out = mosaicview(A) |> collect
212+
out = mosaic(A) |> collect
213213
@test_reference "references/mosaicviews/3d_opaque_1.png" out by=isequal
214-
out = mosaicview(A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
214+
out = mosaic(A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
215215
@test_reference "references/mosaicviews/3d_opaque_2.png" out by=isequal
216-
out = mosaicview(A; npad=2, fillvalue=Gray(0.), nrow=2, rowmajor=true) |> collect
216+
out = mosaic(A; npad=2, fillvalue=Gray(0.), nrow=2, rowmajor=true) |> collect
217217
@test_reference "references/mosaicviews/3d_opaque_3.png" out by=isequal
218-
out = mosaicview(A, A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
218+
out = mosaic(A, A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
219219
@test_reference "references/mosaicviews/3d_opaque_4.png" out by=isequal
220220

221221
A = fill(RGBA(0., 0., 0.), 2, 2, 3)
222222
A[:, :, 1] .= RGBA(1., 0., 0.)
223223
A[:, :, 2] .= RGBA(0., 1., 0.)
224224
A[:, :, 3] .= RGBA(0., 0., 1.)
225-
out = mosaicview(A) |> collect
225+
out = mosaic(A) |> collect
226226
@test_reference "references/mosaicviews/3d_transparent_1.png" out by=isequal
227-
out = mosaicview(A; npad=2, fillvalue=GrayA(0., 0.), nrow=2) |> collect
227+
out = mosaic(A; npad=2, fillvalue=GrayA(0., 0.), nrow=2) |> collect
228228
@test_reference "references/mosaicviews/3d_transparent_2.png" out by=isequal
229-
out = mosaicview(A; npad=2, fillvalue=GrayA(0.), nrow=2, rowmajor=true) |> collect
229+
out = mosaic(A; npad=2, fillvalue=GrayA(0.), nrow=2, rowmajor=true) |> collect
230230
@test_reference "references/mosaicviews/3d_transparent_3.png" out by=isequal
231-
out = mosaicview(A, A; npad=2, fillvalue=GrayA(0.), nrow=2) |> collect
231+
out = mosaic(A, A; npad=2, fillvalue=GrayA(0.), nrow=2) |> collect
232232
@test_reference "references/mosaicviews/3d_transparent_4.png" out by=isequal
233233
end
234234

@@ -237,26 +237,26 @@ end
237237
A[1, :, 1, 1] .= RGB(1., 0., 0.)
238238
A[:, :, 1, 2] .= RGB(0., 1., 0.)
239239
A[:, :, 2, 1] .= RGB(0., 0., 1.)
240-
out = mosaicview(A) |> collect
240+
out = mosaic(A) |> collect
241241
@test_reference "references/mosaicviews/4d_opaque_1.png" out by=isequal
242-
out = mosaicview(A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
242+
out = mosaic(A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
243243
@test_reference "references/mosaicviews/4d_opaque_2.png" out by=isequal
244-
out = mosaicview(A; npad=2, fillvalue=Gray(0.), nrow=2, rowmajor=true) |> collect
244+
out = mosaic(A; npad=2, fillvalue=Gray(0.), nrow=2, rowmajor=true) |> collect
245245
@test_reference "references/mosaicviews/4d_opaque_3.png" out by=isequal
246-
out = mosaicview(A, A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
246+
out = mosaic(A, A; npad=2, fillvalue=Gray(0.), nrow=2) |> collect
247247
@test_reference "references/mosaicviews/4d_opaque_4.png" out by=isequal
248248

249249
A = fill(RGBA(0., 0., 0.), 2, 2, 2, 2)
250250
A[1, :, 1, 1] .= RGBA(1., 0., 0.)
251251
A[:, :, 1, 2] .= RGBA(0., 1., 0.)
252252
A[:, :, 2, 1] .= RGBA(0., 0., 1.)
253-
out = mosaicview(A) |> collect
253+
out = mosaic(A) |> collect
254254
@test_reference "references/mosaicviews/4d_transparent_1.png" out by=isequal
255-
out = mosaicview(A; npad=2, fillvalue=GrayA(0., 0.), nrow=2) |> collect
255+
out = mosaic(A; npad=2, fillvalue=GrayA(0., 0.), nrow=2) |> collect
256256
@test_reference "references/mosaicviews/4d_transparent_2.png" out by=isequal
257-
out = mosaicview(A; npad=2, fillvalue=GrayA(0., 0.), nrow=2, rowmajor=true) |> collect
257+
out = mosaic(A; npad=2, fillvalue=GrayA(0., 0.), nrow=2, rowmajor=true) |> collect
258258
@test_reference "references/mosaicviews/4d_transparent_3.png" out by=isequal
259-
out = mosaicview(A, A; npad=2, fillvalue=GrayA(0.), nrow=2) |> collect
259+
out = mosaic(A, A; npad=2, fillvalue=GrayA(0.), nrow=2) |> collect
260260
@test_reference "references/mosaicviews/4d_transparent_4.png" out by=isequal
261261
end
262262
end
@@ -351,22 +351,22 @@ end
351351
@test Ap[axes(A)...] == ARGB{Float32}.(A)
352352

353353
# order irrelevant
354-
A = mosaicview(rand(Float32, 4, 4), rand(RGB{N0f8}, 4, 4))
354+
A = mosaic(rand(Float32, 4, 4), rand(RGB{N0f8}, 4, 4))
355355
@test eltype(A) == RGB{Float32}
356-
A = mosaicview(rand(RGB{N0f8}, 4, 4), rand(Float32, 4, 4))
356+
A = mosaic(rand(RGB{N0f8}, 4, 4), rand(Float32, 4, 4))
357357
@test eltype(A) == RGB{Float32}
358358

359-
A = mosaicview(rand(Float32, 4, 4), rand(Gray{Float64}, 4, 4))
359+
A = mosaic(rand(Float32, 4, 4), rand(Gray{Float64}, 4, 4))
360360
@test eltype(A) == Gray{Float64}
361-
A = mosaicview(rand(Gray{Float64}, 4, 4), rand(Float32, 4, 4))
361+
A = mosaic(rand(Gray{Float64}, 4, 4), rand(Float32, 4, 4))
362362
@test eltype(A) == Gray{Float64}
363363

364-
A = mosaicview(rand(Float32, 4, 4), rand(Gray{Float64}, 4, 4), rand(RGB{N0f8}, 4, 4))
364+
A = mosaic(rand(Float32, 4, 4), rand(Gray{Float64}, 4, 4), rand(RGB{N0f8}, 4, 4))
365365
@test eltype(A) == RGB{Float64}
366-
A = mosaicview(rand(Float32, 4, 4), rand(RGB{N0f8}, 4, 4), rand(Gray{Float64}, 4, 4))
366+
A = mosaic(rand(Float32, 4, 4), rand(RGB{N0f8}, 4, 4), rand(Gray{Float64}, 4, 4))
367367
@test eltype(A) == RGB{Float64}
368368

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

0 commit comments

Comments
 (0)