Skip to content

Commit f1b1ed1

Browse files
committed
refactor package structure
1 parent 4cd5beb commit f1b1ed1

34 files changed

+549
-235
lines changed

.github/workflows/CI.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI
2+
on: [push, pull_request]
3+
defaults:
4+
run:
5+
shell: bash
6+
jobs:
7+
test:
8+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
9+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ github.event_name }}
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
version:
15+
- '1.6' # oldest supported in Project.toml
16+
- '1' # latest stable
17+
- 'nightly'
18+
os:
19+
- ubuntu-latest
20+
include: # spare windows/macos CI credits
21+
- os: windows-latest
22+
version: '1'
23+
- os: macOS-latest
24+
version: '1'
25+
26+
steps:
27+
- uses: actions/checkout@v2
28+
- uses: julia-actions/setup-julia@v1
29+
with:
30+
version: ${{ matrix.version }}
31+
- name: Cache artifacts
32+
uses: actions/cache@v1
33+
env:
34+
cache-name: cache-artifacts
35+
with:
36+
path: ~/.julia/artifacts
37+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
38+
restore-keys: |
39+
${{ runner.os }}-test-${{ env.cache-name }}-
40+
${{ runner.os }}-test-
41+
${{ runner.os }}-
42+
- name: Test ImageEncoding
43+
run: |
44+
julia --project -e 'using Pkg; Pkg.develop(path="ImageEncoding")'
45+
julia --project -e 'using Pkg; Pkg.test("ImageEncoding")'
46+
- uses: julia-actions/julia-buildpkg@v1
47+
- uses: julia-actions/julia-runtest@v1

.github/workflows/UnitTest.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

ImageEncoding/Project.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name = "ImageEncoding"
2+
uuid = "d64ea8f1-9d40-4cda-bb88-5de2505cd5c8"
3+
version = "0.1.0"
4+
5+
[deps]
6+
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
7+
ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e"
8+
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
9+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
10+
11+
[compat]
12+
Crayons = "0.5, 1, 2, 3, 4"
13+
ImageBase = "0.1"
14+
ImageCore = "0.9"
15+
Requires = "1"
16+
julia = "1.6"
17+
18+
[extras]
19+
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
20+
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
21+
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
22+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
23+
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
24+
25+
[targets]
26+
test = ["ImageMagick", "OffsetArrays", "ReferenceTests", "Test", "TestImages"]

ImageEncoding/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ImageEncoder
2+
3+
ImageEncoder is a backend for [ImageInTerminal](https://github.com/JuliaImages/ImageInTerminal.jl).

ImageEncoding/src/ImageEncoding.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module ImageEncoding
2+
3+
using ImageBase: restrict
4+
using ImageCore
5+
using Requires
6+
using Crayons
7+
8+
export
9+
TermColorDepth, TermColor256, TermColor24bit,
10+
ImageEncoder, BigBlocks, SmallBlocks,
11+
colorant2ansi, encodeimg, sixel_encode
12+
13+
include("colorant2ansi.jl")
14+
include("encodeimg.jl")
15+
16+
function __init__()
17+
# Sixel requires Julia at least v1.6. We don't want to maintain an ImageInTerminal branch
18+
# for old Julia versions so here we use Requires to conditionally load Sixel as an advanced
19+
# image encoding choice. All ImageInTerminal functionality is still there even without Sixel
20+
# -- well, basically.
21+
@require Sixel = "45858cf5-a6b0-47a3-bbea-62219f50df47" begin
22+
Sixel.is_sixel_supported() && (encoder_backend[] = :Sixel)
23+
sixel_encode(args...; kwargs...) = Sixel.sixel_encode(args...; kwargs...)
24+
end
25+
end
26+
27+
end # module

src/colorant2ansi.jl renamed to ImageEncoding/src/colorant2ansi.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ _colorant2ansi(gr::TransparentColor, colordepth::TermColorDepth) =
3535
# 256 colors
3636
function _colorant2ansi(col::AbstractRGB, ::TermColor256)
3737
r, g, b = clamp01nan(red(col)), clamp01nan(green(col)), clamp01nan(blue(col))
38-
r24, g24, b24 = map(c->round(Int, c * 23), (r, g, b))
38+
r24, g24, b24 = map(c->round(Int, 23c), (r, g, b))
3939
if r24 == g24 == b24
4040
# Use grayscales because of higher resultion
4141
# This way even grayscale RGB images look good.
4242
232 + r24
4343
else
44-
r6, g6, b6 = map(c->round(Int, c * 5), (r, g, b))
45-
16 + 36 * r6 + 6 * g6 + b6
44+
r6, g6, b6 = map(c->round(Int, 5c), (r, g, b))
45+
16 + 36r6 + 6g6 + b6
4646
end
4747
end
4848

49-
_colorant2ansi(gr::Color{<:Any,1}, ::TermColor256) = round(Int, 232 + clamp01nan(real(gr)) * 23)
49+
_colorant2ansi(gr::Color{<:Any,1}, ::TermColor256) = round(Int, 232 + 23clamp01nan(real(gr)))
5050

5151
# 24 bit colors
5252
function _colorant2ansi(col::AbstractRGB, ::TermColor24bit)
5353
r, g, b = clamp01nan(red(col)), clamp01nan(green(col)), clamp01nan(blue(col))
54-
map(c->round(Int, c * 255), (r, g, b))
54+
map(c->round(Int, 255c), (r, g, b))
5555
end
5656

5757
function _colorant2ansi(gr::Color{<:Any,1}, ::TermColor24bit)
58-
r = round(Int, clamp01nan(real(gr)) * 255)
58+
r = round(Int, 255clamp01nan(real(gr)))
5959
r, r, r
6060
end
6161

src/encodeimg.jl renamed to ImageEncoding/src/encodeimg.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# not exported
21
abstract type ImageEncoder end
32
struct BigBlocks <: ImageEncoder end
43
struct SmallBlocks <: ImageEncoder end
@@ -146,5 +145,5 @@ function encodeimg(
146145
end
147146
end
148147
println(io, Crayon(reset = true))
149-
replace.(readlines(seek(io,0)), Ref("\n" => ""))::Vector{String}, 1, n < w ? 3*(length(1:n) + 1 + length(w-n+1:w)) : 3w
148+
replace.(readlines(seek(io,0)), Ref("\n" => ""))::Vector{String}, 1, n < w ? 3(length(1:n) + 1 + length(w-n+1:w)) : 3w
150149
end

ImageEncoding/test/common.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# common test files for ImageInTerminal and ImageEncoding
2+
3+
# define some test images
4+
gray_square = colorview(Gray, N0f8[0. 0.3; 0.7 1])
5+
gray_square_alpha = colorview(GrayA, N0f8[0. 0.3; 0.7 1], N0f8[1 0.7; 0.3 0])
6+
gray_line = colorview(Gray, N0f8[0., 0.3, 0.7, 1])
7+
gray_line_alpha = colorview(GrayA, N0f8[0., 0.3, 0.7, 1], N0f8[1, 0.7, 0.3, 0])
8+
rgb_line = colorview(RGB, range(0, stop=1, length=20), zeroarray, range(1, stop=0, length=20))
9+
rgb_line_4d = repeat(repeat(rgb_line', 1, 1, 1, 1), 1, 1, 2, 2)
10+
11+
camera_man = testimage("camera")
12+
lighthouse = testimage("lighthouse")
13+
toucan = testimage("toucan")
14+
lena = testimage("lena_color_256")
15+
16+
function ensurecolor(f, args...)
17+
old_color = Base.have_color
18+
try
19+
Core.eval(Base, :(have_color = true))
20+
return f(args...)
21+
finally
22+
Core.eval(Base, :(have_color = $old_color))
23+
end
24+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
██████████████████████████████████
2+
██████████████████████████████████
3+
██████████████████████████████████
4+
██████████████████████████████████
5+
██████████████████████████████████
6+
██████████████████████████████████
7+
██████████████████████████████████
8+
██████████████████████████████████
9+
██████████████████████████████████
10+
██████████████████████████████████
11+
██████████████████████████████████
12+
██████████████████████████████████
13+
██████████████████████████████████
14+
██████████████████████████████████
15+
██████████████████████████████████
16+
██████████████████████████████████
17+
██████████████████████████████████
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
██████████████████████████████████
2+
██████████████████████████████████
3+
██████████████████████████████████
4+
██████████████████████████████████
5+
██████████████████████████████████
6+
██████████████████████████████████
7+
██████████████████████████████████
8+
██████████████████████████████████
9+
██████████████████████████████████
10+
██████████████████████████████████
11+
██████████████████████████████████
12+
██████████████████████████████████
13+
██████████████████████████████████
14+
██████████████████████████████████
15+
██████████████████████████████████
16+
██████████████████████████████████
17+
██████████████████████████████████

0 commit comments

Comments
 (0)