diff --git a/src/Sixel.jl b/src/Sixel.jl index a68ce6f..f05a25a 100644 --- a/src/Sixel.jl +++ b/src/Sixel.jl @@ -3,6 +3,7 @@ module Sixel export sixel_encode, sixel_decode using ImageCore +using OffsetArrays using IndirectArrays # sixel sequence is actually an indexed image format import REPL: Terminals diff --git a/src/encoder.jl b/src/encoder.jl index 9dc25ff..1673e32 100644 --- a/src/encoder.jl +++ b/src/encoder.jl @@ -63,6 +63,9 @@ sixel_encode(io::IO, img::AbstractVector, enc::SEC=default_encoder(img); kwargs. sixel_encode(io, reshape(img, :, 1), enc; kwargs...) function sixel_encode(io::IO, img::AbstractArray, enc::SEC=default_encoder(img); transpose=false, kwargs...) + # Conversion from OffsetArrays to Array is not very well supported, so we have to de-offset first. + img = OffsetArrays.no_offset_view(img) + # make sure it always tiles along row order @assert ndims(img) >= 3 nrow = transpose ? prod(size(img)[3:end]) : 1 @@ -76,6 +79,8 @@ function sixel_encode( img::AbstractMatrix, enc::SEC=default_encoder(img); transpose=false, kwargs...) + # Conversion from OffsetArrays to Array is not very well supported, so we have to de-offset first. + img = OffsetArrays.no_offset_view(img) if enc isa LibSixelEncoder T = canonical_sixel_eltype(enc, eltype(img)) AT = Array{T, ndims(img)} diff --git a/test/Project.toml b/test/Project.toml index cc96d8c..6262310 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -6,5 +6,6 @@ ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" ImageQualityIndexes = "2996bd0c-7a13-11e9-2da2-2f5ce47296a9" IndirectArrays = "9b13fd28-a010-5f03-acff-a1bbcff69959" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990" diff --git a/test/backend/libsixel.jl b/test/backend/libsixel.jl index 241a183..084ddf0 100644 --- a/test/backend/libsixel.jl +++ b/test/backend/libsixel.jl @@ -214,6 +214,25 @@ sixel_encode(io, img, transpose=false) @test bufferdata == String(take!(io)) end + + @testset "OffsetArray" begin + enc = Sixel.LibSixelEncoder() + for img in [ + repeat(distinguishable_colors(10), inner=(10, )), + repeat(distinguishable_colors(10), inner=(10, 50)), + repeat(distinguishable_colors(5), inner=(20, 50, 3)) + ] + io = IOBuffer() + sixel_encode(io, img, enc) + ref = String(take!(io)) + + imgo = OffsetArray(img, OffsetArrays.Origin(0)) + io = IOBuffer() + sixel_encode(io, imgo, enc) + actual = String(take!(io)) + @test ref == actual + end + end end @testset "decoder" begin diff --git a/test/runtests.jl b/test/runtests.jl index 1c1772e..71ba9ac 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,6 @@ using Sixel using Test -using ImageCore, IndirectArrays +using ImageCore, IndirectArrays, OffsetArrays using ImageQualityIndexes using LinearAlgebra using FileIO, TestImages