From ae919707613e5a53ec8c269dc48b765b90a8d9d8 Mon Sep 17 00:00:00 2001 From: JohnnyChen Date: Sun, 15 Dec 2019 03:13:47 +0800 Subject: [PATCH 1/4] enable image display using ImageShow --- Project.toml | 2 ++ src/ReferenceTests.jl | 1 + src/render.jl | 27 +++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 8f3e74b..47cb633 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,7 @@ Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254" +PaddedViews = "5432bcbf-9aad-5242-b902-cca2824c8663" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" @@ -19,6 +20,7 @@ Distances = "0.7, 0.8" FileIO = "1" ImageCore = "0.8.1" ImageInTerminal = "0.3, 0.4" +PaddedViews = "0.4" julia = "1" [extras] diff --git a/src/ReferenceTests.jl b/src/ReferenceTests.jl index ef7c750..3423c44 100644 --- a/src/ReferenceTests.jl +++ b/src/ReferenceTests.jl @@ -8,6 +8,7 @@ using ImageInTerminal using SHA using DeepDiffs using Random +using PaddedViews export @withcolor, diff --git a/src/render.jl b/src/render.jl index f439dc5..f0d1624 100644 --- a/src/render.jl +++ b/src/render.jl @@ -24,6 +24,13 @@ end ## 2 arg form render for comparing function render(mode::BeforeAfter, reference, actual) + if showable(MIME("image/png"), actual) + render(MIME("image/png"), mode, reference, actual) + else + render(MIME("text/plain"), mode, reference, actual) + end +end +function render(::MIME"text/plain", mode::BeforeAfter, reference, actual) println("- REFERENCE -------------------") render_item(mode, reference) println("-------------------------------") @@ -31,7 +38,14 @@ function render(mode::BeforeAfter, reference, actual) render_item(mode, actual) println("-------------------------------") end -function render(::Diff, reference, actual) + +function render(::MIME"image/png", mode::BeforeAfterImage, reference, actual) + fill_value = zero(eltype(reference)) + out = paddedviews(zero(RGB{eltype(eltype(reference))}), reference, actual) + println("- REFERENCE --------|--------- ACTUAL -") + display(hcat(out...)) +end +function render(::MIME"text/plain", ::Diff, reference, actual) println("- DIFF ------------------------") @withcolor println(deepdiff(reference, actual)) println("-------------------------------") @@ -39,11 +53,16 @@ end ## 1 arg form render for new content function render(mode::RenderMode, actual) - println("- NEW CONTENT -----------------") - render_item(mode, actual) - println("-------------------------------") + if showable(MIME("image/png"), actual) + display(actual) + else + println("- NEW CONTENT -----------------") + render_item(mode, actual) + println("-------------------------------") + end end + """ default_rendermode(::DataFormat, actual) From 4cd2160f2613a45e6e7f9117cbb56a350fb9e340 Mon Sep 17 00:00:00 2001 From: JohnnyChen Date: Sun, 15 Dec 2019 03:22:18 +0800 Subject: [PATCH 2/4] typo fix --- src/render.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render.jl b/src/render.jl index f0d1624..9108485 100644 --- a/src/render.jl +++ b/src/render.jl @@ -41,7 +41,7 @@ end function render(::MIME"image/png", mode::BeforeAfterImage, reference, actual) fill_value = zero(eltype(reference)) - out = paddedviews(zero(RGB{eltype(eltype(reference))}), reference, actual) + out = paddedviews(fill_value, reference, actual) println("- REFERENCE --------|--------- ACTUAL -") display(hcat(out...)) end From 340a117beaaa1d9ee36b399aead67be300215599 Mon Sep 17 00:00:00 2001 From: JohnnyChen Date: Sun, 15 Dec 2019 03:48:55 +0800 Subject: [PATCH 3/4] remove MIME for DIFF method --- src/render.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/render.jl b/src/render.jl index 9108485..c29682a 100644 --- a/src/render.jl +++ b/src/render.jl @@ -38,14 +38,14 @@ function render(::MIME"text/plain", mode::BeforeAfter, reference, actual) render_item(mode, actual) println("-------------------------------") end - function render(::MIME"image/png", mode::BeforeAfterImage, reference, actual) fill_value = zero(eltype(reference)) out = paddedviews(fill_value, reference, actual) println("- REFERENCE --------|--------- ACTUAL -") display(hcat(out...)) end -function render(::MIME"text/plain", ::Diff, reference, actual) + +function render(::Diff, reference, actual) println("- DIFF ------------------------") @withcolor println(deepdiff(reference, actual)) println("-------------------------------") From 0f2af14b72a7f30e2569537e6520b82ef9f3199b Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Sun, 15 Mar 2020 03:54:35 +0800 Subject: [PATCH 4/4] use MosaicView 0.2 --- Project.toml | 6 ++++-- src/ReferenceTests.jl | 3 ++- src/render.jl | 10 ++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index 47cb633..f3226f0 100644 --- a/Project.toml +++ b/Project.toml @@ -9,7 +9,8 @@ Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254" -PaddedViews = "5432bcbf-9aad-5242-b902-cca2824c8663" +ImageShow = "4e3cecfd-b093-5904-9786-8bbb286a6a31" +MosaicViews = "e94cdb99-869f-56ef-bcf0-1ae2bcbe0389" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" @@ -20,7 +21,8 @@ Distances = "0.7, 0.8" FileIO = "1" ImageCore = "0.8.1" ImageInTerminal = "0.3, 0.4" -PaddedViews = "0.4" +ImageShow = "0.2" +MosaicViews = "0.2" julia = "1" [extras] diff --git a/src/ReferenceTests.jl b/src/ReferenceTests.jl index 3423c44..4812912 100644 --- a/src/ReferenceTests.jl +++ b/src/ReferenceTests.jl @@ -8,7 +8,8 @@ using ImageInTerminal using SHA using DeepDiffs using Random -using PaddedViews +using MosaicViews +using ImageShow export @withcolor, diff --git a/src/render.jl b/src/render.jl index c29682a..da2524f 100644 --- a/src/render.jl +++ b/src/render.jl @@ -24,7 +24,7 @@ end ## 2 arg form render for comparing function render(mode::BeforeAfter, reference, actual) - if showable(MIME("image/png"), actual) + if displayable(MIME("image/png")) render(MIME("image/png"), mode, reference, actual) else render(MIME("text/plain"), mode, reference, actual) @@ -39,10 +39,8 @@ function render(::MIME"text/plain", mode::BeforeAfter, reference, actual) println("-------------------------------") end function render(::MIME"image/png", mode::BeforeAfterImage, reference, actual) - fill_value = zero(eltype(reference)) - out = paddedviews(fill_value, reference, actual) println("- REFERENCE --------|--------- ACTUAL -") - display(hcat(out...)) + display(MIME("image/png"), mosaicview(reference, actual; nrow=1, npad=5)) end function render(::Diff, reference, actual) @@ -53,8 +51,8 @@ end ## 1 arg form render for new content function render(mode::RenderMode, actual) - if showable(MIME("image/png"), actual) - display(actual) + if displayable(MIME("image/png")) + display(MIME("image/png"), actual) else println("- NEW CONTENT -----------------") render_item(mode, actual)