diff --git a/examples/gui/image_processing.jl b/examples/gui/image_processing.jl index 03b1b05..d016a53 100644 --- a/examples/gui/image_processing.jl +++ b/examples/gui/image_processing.jl @@ -17,8 +17,15 @@ racoon = loadasset("racoon.png") img = convert(Matrix{RGBA{Float32}}, racoon) # create a slider that goes from 1-20 in 0.1 steps -slider, slider_s = widget(Signal(1f0), range=1f0:0.1f0:20f0, window) - +slider, slider_s = widget(Signal(1f0), range = 1f0:0.1f0:20f0, window) + +if !isdefined(:clamp01) + function clamp01(color) + mapc(color) do c + clamp(c, 0, 1) + end + end +end """ Applies a gaussian filter to `img` and converts it to RGBA{N0f8} """ diff --git a/examples/imagelike/imageio.jl b/examples/imagelike/imageio.jl index 258fb0a..f314d4c 100644 --- a/examples/imagelike/imageio.jl +++ b/examples/imagelike/imageio.jl @@ -22,13 +22,25 @@ arrays = map((RGBA{N0f8}, RGBA{Float32}, RGB{N0f8}, RGB{Float32}, BGRA{N0f8}, BG loaded_imgs = map(x->loadasset("test_images", x), readdir(assetpath("test_images"))) # combine them all into one array and add an animated gif and a few other images + +# backward compatible imconvert +imconvert(im) = im +if isdefined(:Image) + function imconvert(im::Image) + if ndims(im) == 2 + convert(Array{eltype(im), ndims(im)}, im) + else + permutedims(im.data, (2, 1, 3)) + end + end +end x = Any[ arrays..., loaded_imgs..., loadasset("kittens-look.gif"), loadasset("mario", "stand", "right.png"), loadasset("mario", "jump", "left.gif"), ] -x = map(x-> convert(Array{eltype(x), ndims(x)}, x), x) +x = map(imconvert, x) # visualize all images and convert the array to be a vector of element type context # This shouldn't be necessary, but it seems map is not able to infer the type alone diff --git a/examples/interactive/mario_game.jl b/examples/interactive/mario_game.jl index 6fdaf0f..5c23eab 100644 --- a/examples/interactive/mario_game.jl +++ b/examples/interactive/mario_game.jl @@ -74,7 +74,7 @@ for verb in ["jump", "walk", "stand"], dir in ["left", "right"] end path = assetpath("mario", verb, pic) sequence = read_sequence(path) - gif = map(img->map(RGBA{N0f8}, img), sequence) + gif = map(img->convert(Matrix{RGBA{N0f8}}, img), sequence) mario_images[verb*dir] = play(gif) end function mario2image(mario, images=mario_images)