Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper Normed handling in the contrast GUI #310

Closed
kimikage opened this issue Jun 10, 2024 · 3 comments · Fixed by #311
Closed

Improper Normed handling in the contrast GUI #310

kimikage opened this issue Jun 10, 2024 · 3 comments · Fixed by #311

Comments

@kimikage
Copy link

kimikage commented Jun 10, 2024

This is a little related to issue #308 and PR #309. The contrast GUI causes errors with the images using Normed, such as N0f8.

julia> using ImageView

julia> using ImageView.FixedPointNumbers

julia> VERSION
v"1.10.4"

julia> pkgversion(ImageView)
v"0.12.4"

julia> n0f8s = N0f8[0.2 0.8];

julia> imshow(n0f8s); # and then slide "slider_max" to the left

┌ Warning: Executing #14:
└ @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\signals.jl:122
ERROR: 0.2N0f8 is not within the span of 0.20000000298023224:0.002362204759609042:0.800000011920929
Stacktrace:
  [1] error(s::String)
    @ Base .\error.jl:35
  [2] setindex!(s::GtkObservables.Slider{Float32}, ::Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, N0f8})
    @ GtkObservables C:\Users\username\.julia\packages\GtkObservables\gSI6s\src\widgets.jl:173
  [3] (::ImageView.var"#130#133"{Observables.Observable{CLim{N0f8}}, Dict{String, Any}, N0f8, DataType})(cmin::Float32, cmax::Float32)
    @ ImageView C:\Users\username\.julia\packages\ImageView\QLmQc\src\contrast_gui.jl:103
  [4] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\essentials.jl:892
  [5] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\essentials.jl:889
  [6] (::Observables.MapCallback)(value::Any)
    @ Observables C:\Users\username\.julia\packages\Observables\YdEbO\src\Observables.jl:436
  [7] #invokelatest#2
    @ .\essentials.jl:892 [inlined]
  [8] invokelatest
    @ .\essentials.jl:889 [inlined]
  [9] notify
    @ C:\Users\username\.julia\packages\Observables\YdEbO\src\Observables.jl:206 [inlined]
 [10] setindex!(observable::Observables.Observable, val::Any)
    @ Observables C:\Users\username\.julia\packages\Observables\YdEbO\src\Observables.jl:123
 [11] (::GtkObservables.var"#14#15"{Observables.Observable{Float32}})(w::Gtk4.GtkScaleLeaf)
    @ GtkObservables C:\Users\username\.julia\packages\GtkObservables\gSI6s\src\widgets.jl:155
 [12] (::Gtk4.GLib.var"#134#136"{Ptr{Gtk4.GLib.GValue}, UInt32, Ptr{Gtk4.GLib.GValue}, Vector{Any}, GtkObservables.var"#14#15"{Observables.Observable{Float32}}})()
    @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\signals.jl:63
 [13] g_siginterruptible(f::Gtk4.GLib.var"#134#136"{Ptr{Gtk4.GLib.GValue}, UInt32, Ptr{Gtk4.GLib.GValue}, Vector{Any}, GtkObservables.var"#14#15"{Observables.Observable{Float32}}}, cb::Any)
    @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\signals.jl:244
 [14] GClosureMarshal(closuref::Ptr{Nothing}, return_value::Ptr{Gtk4.GLib.GValue}, n_param_values::UInt32, param_values::Ptr{Gtk4.GLib.GValue}, invocation_hint::Ptr{Nothing}, marshal_data::Ptr{Nothing})
    @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\signals.jl:57
 [15] (::Gtk4.GLib.var"#233#234")()
    @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\loop.jl:83
 [16] g_sigatom(f::Any)
    @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\signals.jl:211
 [17] glib_main()
    @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\loop.jl:80
@kimikage
Copy link
Author

This may be directly due to the fact that the slider range is based on Float64 while the slider value can be Normed.
This should be solved by converting the values to float.

cmin, cmax = T(clamp(cminT, mn, mx)), T(clamp(cmaxT, mn, mx))

cgui["slider_min"][] = (rng, clamp(cl.min, mn, mx))
cgui["slider_max"][] = (rng, clamp(cl.max, mn, mx))

cc: @jwahlstrand

@jwahlstrand
Copy link
Collaborator

jwahlstrand commented Jun 10, 2024

Thanks, your suggestion does prevent the error! I'll submit a PR (unless you'd like to?)

@kimikage
Copy link
Author

I do not have merge privileges on this repository, so I would like to ask you to make a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants