Skip to content

Commit

Permalink
More expansive nospecialize annotations (#208)
Browse files Browse the repository at this point in the history
This helps the tests run considerably faster
  • Loading branch information
timholy committed Jan 26, 2020
1 parent fca85eb commit 369867f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
40 changes: 26 additions & 14 deletions src/ImageView.jl
Expand Up @@ -169,32 +169,35 @@ Finally, you may specify [`GtkReactive.ZoomRegion`](@ref) and
[`SliceData`](@ref) signals. See also [`roi`](@ref), as well as any
`annotations` that you wish to apply.
"""
function imshow(@nospecialize(img::AbstractArray);
function imshow(img::AbstractArray;
axes=default_axes(img), name="ImageView", scalei=identity, aspect=:auto,
kwargs...)
@nospecialize
imgmapped = kwhandler(_mappedarray(scalei, img), axes; kwargs...)
zr, sd = roi(imgmapped, axes)
v = slice2d(imgmapped, value(zr), sd)
imshow(imgmapped, default_clim(v), zr, sd; name=name, aspect=aspect)
end

imshow(@nospecialize(img::AbstractVector); kwargs...) = imshow(reshape(img, :, 1); kwargs...)
imshow(img::AbstractVector; kwargs...) = (@nospecialize; imshow(reshape(img, :, 1); kwargs...))

function imshow(c::GtkReactive.Canvas, @nospecialize(img::AbstractMatrix), anns=annotations();
kwargs...)
function imshow(c::GtkReactive.Canvas, img::AbstractMatrix, anns=annotations(); kwargs...)
@nospecialize
f = parent(widget(c))
imshow(f, c, img, default_clim(img), roi(img, default_axes(img))..., anns; kwargs...)
end

function imshow(@nospecialize(img::AbstractArray), clim;
function imshow(img::AbstractArray, clim;
axes = default_axes(img), name="ImageView", aspect=:auto)
@nospecialize
imshow(img, clim, roi(img, axes)...; name=name, aspect=aspect)
end

function imshow(@nospecialize(img::AbstractArray), clim,
function imshow(img::AbstractArray, clim,
zr::Signal{ZoomRegion{T}}, sd::SliceData,
anns=annotations();
name="ImageView", aspect=:auto) where T
@nospecialize
v = slice2d(img, value(zr), sd)
ps = map(abs, pixelspacing(v))
csz = default_canvas_size(fullsize(value(zr)), ps[2]/ps[1])
Expand All @@ -214,10 +217,12 @@ function imshow(@nospecialize(img::AbstractArray), clim,
end

function imshow(frame::Gtk.GtkFrame, canvas::GtkReactive.Canvas,
@nospecialize(img::AbstractArray), clim::Union{Nothing,Signal{<:CLim}},
img::AbstractArray, clim::Union{Nothing,Signal{<:CLim}},
zr::Signal{ZoomRegion{T}}, sd::SliceData,
anns::Annotations=annotations()) where T
@nospecialize
imgsig = map(zr, sd.signals...; name="imgsig") do r, s...
@nospecialize
while length(s) < 2
s = (s..., 1)
end
Expand All @@ -238,16 +243,18 @@ end
# For things that are not AbstractArrays, we don't offer the clim
# option. We also don't display hoverinfo, as there is no guarantee
# that one can quickly compute intensities at a point.
function imshow(@nospecialize(img);
function imshow(img;
axes = default_axes(img), name="ImageView", aspect=:auto)
@nospecialize
zr, sd = roi(img, axes)
imshow(img, zr, sd; name=name, aspect=aspect)
end

function imshow(@nospecialize(img),
function imshow(img,
zr::Signal{ZoomRegion{T}}, sd::SliceData,
anns=annotations();
name="ImageView", aspect=:auto) where T
@nospecialize
v = slice2d(img, value(zr), sd)
ps = map(abs, pixelspacing(v))
csz = default_canvas_size(fullsize(value(zr)), ps[2]/ps[1])
Expand All @@ -263,9 +270,11 @@ function imshow(@nospecialize(img),
end

function imshow(frame::Gtk.GtkFrame, canvas::GtkReactive.Canvas,
@nospecialize(img), zr::Signal{ZoomRegion{T}}, sd::SliceData,
img, zr::Signal{ZoomRegion{T}}, sd::SliceData,
anns::Annotations=annotations()) where T
@nospecialize
imgsig = map(zr, sd.signals...; name="imgsig") do r, s...
@nospecialize
slice2d(img, r, sd)
end
set_aspect!(frame, value(imgsig))
Expand Down Expand Up @@ -397,9 +406,10 @@ push!(imgsig, mri[:,:,8])
```
"""
function imshow(canvas::GtkReactive.Canvas{UserUnit},
@nospecialize(imgsig::Signal),
imgsig::Signal,
zr::Signal{ZoomRegion{T}}=Signal(ZoomRegion(value(imgsig))),
anns::Annotations=annotations()) where T<:RInteger
@nospecialize
zoomrb = init_zoom_rubberband(canvas, zr)
zooms = init_zoom_scroll(canvas, zr)
pans = init_pan_scroll(canvas, zr)
Expand All @@ -414,9 +424,10 @@ end

function imshow(frame::Frame,
canvas::GtkReactive.Canvas{UserUnit},
@nospecialize(imgsig::Signal),
imgsig::Signal,
zr::Signal{ZoomRegion{T}},
anns::Annotations=annotations()) where T<:RInteger
@nospecialize
zoomrb = init_zoom_rubberband(canvas, zr)
zooms = init_zoom_scroll(canvas, zr)
pans = init_pan_scroll(canvas, zr)
Expand All @@ -435,7 +446,8 @@ end
Display `img`, but showing the pixel's `label` rather than the color
value in the status bar.
"""
function imshowlabeled(@nospecialize(img::AbstractArray), @nospecialize(label::AbstractArray); proplist...)
function imshowlabeled(img::AbstractArray, label::AbstractArray; proplist...)
@nospecialize
axes(img) == axes(label) || throw(DimensionMismatch("axes $(axes(label)) of label array disagree with axes $(axes(img)) of the image"))
guidict = imshow(img; proplist...)
gui = guidict["gui"]
Expand All @@ -447,7 +459,7 @@ function imshowlabeled(@nospecialize(img::AbstractArray), @nospecialize(label::A
guidict
end

function hoverinfo(lbl, btn, @nospecialize(img), sd::SliceData{transpose}) where transpose
function hoverinfo(lbl, btn, img, sd::SliceData{transpose}) where transpose
io = IOBuffer()
y, x = round(Int, btn.position.y.val), round(Int, btn.position.x.val)
axes = sliceinds(img, transpose ? (x, y) : (y, x), makeslices(sd)...)
Expand Down
13 changes: 8 additions & 5 deletions test/runtests.jl
Expand Up @@ -4,11 +4,14 @@ using Images, OffsetArrays
using Gtk
using Test

function imshow_now(@nospecialize(args...); @nospecialize(kwargs...))
guidict = imshow(args...; kwargs...)
Gtk.showall(guidict["gui"]["window"])
sleep(0.01)
guidict
if !isdefined(@__MODULE__, :imshow_now)
function imshow_now(args...; kwargs...)
@nospecialize
guidict = imshow(args...; kwargs...)
Gtk.showall(guidict["gui"]["window"])
sleep(0.01)
guidict
end
end

include("simple.jl")
Expand Down

2 comments on commit 369867f

@timholy
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/8467

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.5 -m "<description of version>" 369867fdaa40abd48c188db4bfaf486ba40bfafd
git push origin v0.10.5

Please sign in to comment.