Skip to content
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
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
style = "blue"
short_to_long_function_def = false
long_to_short_function_def = true
trailing_comma = "nothing"
always_use_return = false
import_to_using = false
Expand Down
9 changes: 3 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@ version = "0.5.0"
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
Sixel = "45858cf5-a6b0-47a3-bbea-62219f50df47"
XTermColors = "c8c2cc18-de81-4e68-b407-38a3a0c0491f"

[compat]
ColorTypes = "0.9 - 0.11"
Crayons = "^4.1"
FileIO = "^1.6"
ImageBase = "0.1"
ImageCore = "0.9"
Sixel = "0.1"
XTermColors = "0.1"
XTermColors = "0.2"
julia = "1.6"

[extras]
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
ImageQualityIndexes = "2996bd0c-7a13-11e9-2da2-2f5ce47296a9"
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
Expand All @@ -34,4 +31,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"

[targets]
test = ["CoordinateTransformations", "ImageIO", "ImageQualityIndexes", "ImageTransformations", "OffsetArrays", "ReferenceTests", "Rotations", "SparseArrays", "Test", "TestImages"]
test = ["CoordinateTransformations", "ImageBase", "ImageIO", "ImageQualityIndexes", "ImageTransformations", "OffsetArrays", "ReferenceTests", "Rotations", "SparseArrays", "Test", "TestImages"]
21 changes: 7 additions & 14 deletions src/ImageInTerminal.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module ImageInTerminal

using XTermColors
using ImageCore
using ColorTypes
using Crayons
using FileIO

import XTermColors: TermColorDepth, TermColor8bit, TermColor24bit
import ImageBase: restrict
import Sixel

# -------------------------------------------------------------------
Expand Down Expand Up @@ -57,8 +55,8 @@ function choose_sixel(img::AbstractArray)
# Small images really do not need sixel encoding.
# `60` is a randomly chosen value (10 sixel); it's not the best because
# 60x60 image will be very small in terminal after sixel encoding.
any(size(img) .<= 12) && return false
all(size(img) .<= 60) && return false
any(size(img) . 12) && return false
all(size(img) . 60) && return false
return true
end
end
Expand Down Expand Up @@ -110,24 +108,19 @@ Supported encoding:
"""

function imshow(io::IO, img::AbstractArray{<:Colorant}, maxsize::Tuple=displaysize(io))
buf = PipeBuffer()
io_color = get(io, :color, false)
iobuf = IOContext(buf, :color => io_color)
buf = IOContext(PipeBuffer(), :color => get(io, :color, false))
if choose_sixel(img)
sixel_encode(iobuf, img)
sixel_encode(buf, img)
else
if ndims(img) > 2
Base.show_nd(
iobuf,
img,
(iobuf, x) -> ascii_display(iobuf, x, COLORMODE[], maxsize),
true
buf, img, (buf, x) -> ascii_show(buf, x, COLORMODE[], :auto, maxsize), true
)
else
ascii_display(iobuf, img, COLORMODE[], maxsize)
ascii_show(buf, img, COLORMODE[], :auto, maxsize)
end
end
write(io, read(iobuf, String))
write(io, read(buf, String))
end

imshow(img::AbstractArray{<:Colorant}, args...) = imshow(stdout, img, args...)
Expand Down
15 changes: 10 additions & 5 deletions test/reference/mandril_small_24bit.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀
████████████████████
████████████████████
████████████████████
████████████████████
████████████████████
████████████████████
████████████████████
████████████████████
████████████████████
████████████████████
15 changes: 10 additions & 5 deletions test/reference/mandril_small_8bit.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀
▀▀▀▀▀▀▀▀▀▀
████████████████████
████████████████████
████████████████████
████████████████████
████████████████████
████████████████████
████████████████████
████████████████████
████████████████████
████████████████████