Skip to content

Commit d46a180

Browse files
committed
compat fix for Julia < v1.3
1 parent a8c98e4 commit d46a180

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/ImageCore.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ using OffsetArrays # for show.jl
1212
using .ColorTypes: colorant_string
1313
using Colors: Fractional
1414
using MappedArrays: AbstractMultiMappedArray
15-
@reexport using StructArrays: StructArray # for struct of array layout
15+
@static if VERSION >= v"1.3"
16+
@reexport using StructArrays: StructArray # for struct of array layout
17+
end
1618

1719
using Base: tail, @pure, Indices
1820
import Base: float

src/matlab.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,19 @@ end
8989

9090
# Step 3: colorspace conversion
9191
_im_from_matlab(::Type{CT}, X::AbstractArray{CT}) where CT<:Colorant = X
92-
function _im_from_matlab(::Type{CT}, X::AbstractArray{T}) where {CT<:Colorant, T<:Real}
93-
_CT = isconcretetype(CT) ? CT : base_colorant_type(CT){T}
94-
# FIXME(johnnychen94): not type inferrable here
95-
return StructArray{_CT}(X; dims=3)
92+
@static if VERSION >= v"1.3"
93+
# use StructArray to inform that this is a struct of array layout
94+
function _im_from_matlab(::Type{CT}, X::AbstractArray{T,3}) where {CT<:Colorant, T<:Real}
95+
_CT = isconcretetype(CT) ? CT : base_colorant_type(CT){T}
96+
# FIXME(johnnychen94): not type inferrable here
97+
return StructArray{_CT}(X; dims=3)
98+
end
99+
else
100+
function _im_from_matlab(::Type{CT}, X::AbstractArray{T,3}) where {CT<:Colorant, T<:Real}
101+
_CT = isconcretetype(CT) ? CT : base_colorant_type(CT){T}
102+
# FIXME(johnnychen94): not type inferrable here
103+
return colorview(_CT, PermutedDimsArray(X, (3, 1, 2)))
104+
end
96105
end
97106
_im_from_matlab(::Type{CT}, X::AbstractArray{T}) where {CT<:Gray, T<:Real} = colorview(CT, X)
98107

0 commit comments

Comments
 (0)