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
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ version = "0.3.1"
[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StackViews = "cae243ae-269e-4f55-b966-ac2d0dc13c15"

[compat]
FileIO = "1"
ImageCore = "0.8.1, 0.9"
ImageBase = "0.1"
ImageCore = "0.9"
OffsetArrays = "0.8, 0.9, 0.10, 0.11, 1"
Requires = "0.5.2, 1"
StackViews = "0.1.1"
julia = "1"

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ Things that users of `ImageShow` need to know:
for generic image.
* Once you load this package, 2d image will be encoded and displayed as a PNG image. To encode the
data as PNG image, either `ImageIO` or `ImageMagick` should be installed.
* Advanced anti-aliased reduction is applied if `ImageTransformations` is loaded.
* `using Images` automatically loads `ImageShow` and `ImageTransformations` for you.
* `using Images` automatically loads `ImageShow` for you.

## Functions

Expand Down
9 changes: 1 addition & 8 deletions src/ImageShow.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
module ImageShow

using Requires
using FileIO
using ImageCore, OffsetArrays
import ImageBase: restrict

using StackViews
using ImageCore.MappedArrays
using ImageCore.PaddedViews

const _have_restrict=Ref(false)
function _use_restrict(val::Bool)
_have_restrict[] = val
end
function __init__()
@require ImageTransformations="02fcd773-0e25-5acc-982a-7f6622650795" _use_restrict(true)
end
include("showmime.jl")
include("gif.jl")
include("multipage.jl")
Expand Down
12 changes: 1 addition & 11 deletions src/showmime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Base.show(io::IO, mime::MIME"image/png", img::AbstractMatrix{C};
end
if !get(io, :full_fidelity, false)
while _length1(img) > maxpixels
img = _restrict1(img) # big images
img = restrict(img) # big images
end
npix = _length1(img)
if npix < minpixels
Expand Down Expand Up @@ -124,15 +124,5 @@ function show_element(io::IOContext, img)
write(io,"\">")
end

function _restrict1(img)
if _have_restrict[]
res = ImageTransformations.restrict(img)
else
@info "For better quality inline display of large images or thumbnails, load the Images package." maxlog=1
res = img[1:2:end,1:2:end]
end
res
end

_length1(A::AbstractArray) = length(eachindex(A))
_length1(A) = length(A)
39 changes: 4 additions & 35 deletions test/writemime.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using ImageShow, ImageCore, FileIO, OffsetArrays
using ImageCore: PaddedViews
# We jump through some hoops so that this test script may work
# whether or not ImageTransformations (a fortiori Images) is loaded.
# See below for details.

# don't import ImageTransformations: restrict
import ImageBase: restrict

using Test

Expand Down Expand Up @@ -95,36 +91,13 @@ end
end
end

# We do this after the FileIO backend has gotten comfortable.
const have_restrict = Ref{Bool}(false)
const restrict_mod = Ref{Module}()
for mod in values(Base.loaded_modules)
if string(mod) == "ImageTransformations"
have_restrict[] = true
restrict_mod[] = mod
end
end

if have_restrict[]
@info "Tests will use restrict from ImageTransformations"
const restrict = restrict_mod[].restrict
end

@testset "Big images and matrices" begin
@testset "big images (use of restrict)" begin
A = N0f8[0.01 0.4 0.99; 0.25 0.8 0.75; 0.6 0.2 0.0]
if have_restrict[]
Ar = restrict(A)
else
Ar = N0f8[0.01 0.99; 0.6 0.0]
end
Ar = restrict(A)
fn = joinpath(workdir, "writemime.png")
open(fn, "w") do file
if !have_restrict[]
@test_logs (:info, r"^For better quality") show(file, MIME("image/png"), Gray.(A), minpixels=0, maxpixels=5)
else
show(file, MIME("image/png"), Gray.(A), minpixels=0, maxpixels=5)
end
show(file, MIME("image/png"), Gray.(A), minpixels=0, maxpixels=5)
end
@test load(fn) == N0f8.(Ar)
# a genuinely big image (tests the defaults)
Expand All @@ -134,11 +107,7 @@ end
show(file, MIME("image/png"), abig, maxpixels=10^6)
end
b = load(fn)
if have_restrict[]
btmp = restrict(abig, (1,2))
else
btmp = abig[1:2:end,1:2:end]
end
btmp = restrict(abig, (1,2))
@test b == N0f8.(btmp)
end
@testset "display matrix of images" begin
Expand Down