Skip to content

use ImageBase.restrict #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 2, 2021
Merged
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
9 changes: 5 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ version = "0.4.6"

[deps]
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[compat]
Crayons = "0.5, 1, 2, 3, 4"
ImageCore = "0.8.1, 0.9"
ImageTransformations = "0.5, 0.6, 0.7, 0.8"
ImageBase = "0.1"
ImageCore = "0.9"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restrict requires ColorVectorSpace to work. I bump the lower bound of ImageCore to 0.9 because it loads ColorVectorSpace JuliaImages/ImageCore.jl#157

Requires = "1"
julia = "1"

[extras]
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
ImageQualityIndexes = "2996bd0c-7a13-11e9-2da2-2f5ce47296a9"
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
Expand All @@ -28,4 +29,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"

[targets]
test = ["CoordinateTransformations", "ImageMagick", "ImageQualityIndexes", "ReferenceTests", "Rotations", "SparseArrays", "OffsetArrays", "Pkg", "Test", "TestImages"]
test = ["CoordinateTransformations", "ImageMagick", "ImageQualityIndexes", "ImageTransformations", "ReferenceTests", "Rotations", "SparseArrays", "OffsetArrays", "Pkg", "Test", "TestImages"]
2 changes: 1 addition & 1 deletion src/ImageInTerminal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module ImageInTerminal
using Requires
using Crayons
using ImageCore
using ImageTransformations
using ImageBase: restrict

export

Expand Down
8 changes: 3 additions & 5 deletions src/encodeimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ function encodeimg(
img::AbstractVector{<:Colorant},
maxwidth::Int = 80)
maxwidth = max(maxwidth, 5)
w = length(axes(img, 1))
if w > maxwidth
img = imresize(img, maxwidth)
w = length(axes(img, 1))
while size(img, 1) > maxwidth
img = restrict(img)
end
io = IOBuffer()
print(io, Crayon(reset = true))
Expand All @@ -118,7 +116,7 @@ function encodeimg(
print(io, Crayon(foreground = fgcol), chr)
end
println(io, Crayon(reset = true))
replace.(readlines(seek(io,0)), Ref("\n" => ""))::Vector{String}, 1, w
replace.(readlines(seek(io,0)), Ref("\n" => ""))::Vector{String}, 1, size(img, 1)
end

function encodeimg(
Expand Down
2 changes: 1 addition & 1 deletion test/reference/rgbline_small2_imshow24bit.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
███████████████████
███████████
2 changes: 1 addition & 1 deletion test/reference/rgbline_small2_imshow256.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
███████████████████
███████████
12 changes: 6 additions & 6 deletions test/tst_encodeimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ end
res, h, w = ensurecolor(ImageInTerminal.encodeimg, ImageInTerminal.SmallBlocks(), ImageInTerminal.TermColor256(), rgb_line, 8)
@test typeof(res) <: Vector{String}
@test h === 1
@test w === 8
@test w === 6
@test length(res) === 1
@test res[1] == "\e[0m\e[38;5;21m█\e[38;5;56m█\e[38;5;91m█\e[38;5;91m█\e[38;5;126m█\e[38;5;126m█\e[38;5;161m█\e[38;5;196m█\e[0m"
@test res[1] == "\e[0m\e[38;5;18m█\e[38;5;56m█\e[38;5;91m█\e[38;5;126m█\e[38;5;161m█\e[38;5;88m█\e[0m"
end
end

Expand Down Expand Up @@ -312,9 +312,9 @@ end
res, h, w = ensurecolor(ImageInTerminal.encodeimg, ImageInTerminal.SmallBlocks(), ImageInTerminal.TermColor24bit(), rgb_line, 8)
@test typeof(res) <: Vector{String}
@test h === 1
@test w === 8
@test w === 6
@test length(res) === 1
@test res[1] == "\e[0m\e[38;2;10;0;245m█\e[38;2;44;0;211m█\e[38;2;77;0;178m█\e[38;2;111;0;144m█\e[38;2;144;0;111m█\e[38;2;178;0;77m█\e[38;2;211;0;44m█\e[38;2;245;0;10m█\e[0m"
@test res[1] == "\e[0m\e[38;2;6;0;122m█\e[38;2;47;0;208m█\e[38;2;101;0;154m█\e[38;2;154;0;101m█\e[38;2;208;0;47m█\e[38;2;122;0;6m█\e[0m"
end
end

Expand Down Expand Up @@ -370,9 +370,9 @@ end
res, h, w = ensurecolor(ImageInTerminal.encodeimg, ImageInTerminal.SmallBlocks(), ImageInTerminal.TermColor256(), OffsetArray(rgb_line, (-1,)), 8)
@test typeof(res) <: Vector{String}
@test h === 1
@test w === 8
@test w === 6
@test length(res) === 1
@test res[1] == "\e[0m\e[38;5;21m█\e[38;5;56m█\e[38;5;91m█\e[38;5;91m█\e[38;5;126m█\e[38;5;126m█\e[38;5;161m█\e[38;5;196m█\e[0m"
@test res[1] == "\e[0m\e[38;5;18m█\e[38;5;56m█\e[38;5;91m█\e[38;5;126m█\e[38;5;161m█\e[38;5;88m█\e[0m"
end
@testset "rgb line2" begin
res, h, w = ensurecolor(ImageInTerminal.encodeimg, ImageInTerminal.BigBlocks(), ImageInTerminal.TermColor256(), OffsetArray(rgb_line, (2,)), 9)
Expand Down