Skip to content

Commit e03ab12

Browse files
authored
fix tests (#319)
The ColorTypes function gray doesn't accept integers greater than 1 now, so handle integer matrices differently, maintaining the old behavior of clamping values greater than 1. Also fix another broken test where promote_type returns Any instead of Union{}.
1 parent 5a41483 commit e03ab12

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/ImageView.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function imshow(frame::Union{Gtk4.GtkFrame,Gtk4.GtkAspectFrame}, canvas::GtkObse
254254
# such errors become easier to debug.
255255
if !supported_eltype(imgc[])
256256
!supported_eltype(imgsig[]) && error("got unsupported eltype $(eltype(imgsig[])) in creating slice")
257-
error("got unsupported eltype $(eltype(imgc[])) in preparing the constrast")
257+
error("got unsupported eltype $(eltype(imgc[])) in preparing the contrast")
258258
end
259259

260260
roidict = imshow(frame, canvas, imgc, zr, anns)
@@ -564,6 +564,12 @@ function _deflt_clim(img::AbstractMatrix)
564564
Observable(CLim(saferound(gray(minval)), saferound(gray(maxval))))
565565
end
566566

567+
# The method above began throwing an error for integers >1 in mid 2025
568+
# This restores the previous "clamping" behavior
569+
function _deflt_clim(img::AbstractMatrix{T}) where {T<:Integer}
570+
Observable(CLim(0.0, 1.0))
571+
end
572+
567573
function _deflt_clim(img::AbstractMatrix{T}) where {T<:AbstractRGB}
568574
minval = RGB(0.0,0.0,0.0)
569575
maxval = RGB(1.0,1.0,1.0)
@@ -584,7 +590,11 @@ default_axes(img::AxisArray) = axisnames(img)[[1,2]]
584590

585591
function histsignals(enabled::Observable{Bool}, img::Observable, clim::Observable{CLim{T}}) where {T<:GrayLike}
586592
image, cl = img[], clim[]
587-
Th = float(promote_type(T, eltype(image)))
593+
hist_type = promote_type(T, eltype(image))
594+
if hist_type == Any
595+
error("got unsupported eltype Any in preparing the contrast")
596+
end
597+
Th = float(hist_type)
588598
function computehist(image, cl)
589599
smin, smax = valuespan(image)
590600
smin = float(min(smin, cl.min))

test/newtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ end
126126
img = [OneChannelColor(0) OneChannelColor(1);
127127
OneChannelColor(2) OneChannelColor(3);
128128
]
129-
@test_throws ErrorException("got unsupported eltype Union{} in preparing the constrast") imshow(img, CLim(0, 1))
129+
@test_throws ErrorException("got unsupported eltype Any in preparing the contrast") imshow(img, CLim(0, 1))
130130

131131
struct MyChar <: AbstractChar
132132
c::Char

0 commit comments

Comments
 (0)