Skip to content
This repository was archived by the owner on Apr 28, 2021. It is now read-only.

Commit 26b3481

Browse files
committed
make it backwards compatible
1 parent dd867a0 commit 26b3481

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

examples/gui/image_processing.jl

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ racoon = loadasset("racoon.png")
1717
img = convert(Matrix{RGBA{Float32}}, racoon)
1818

1919
# create a slider that goes from 1-20 in 0.1 steps
20-
slider, slider_s = widget(Signal(1f0), range=1f0:0.1f0:20f0, window)
21-
20+
slider, slider_s = widget(Signal(1f0), range = 1f0:0.1f0:20f0, window)
21+
22+
if !isdefined(:clamp01)
23+
function clamp01(color)
24+
mapc(color) do c
25+
clamp(c, 0, 1)
26+
end
27+
end
28+
end
2229
"""
2330
Applies a gaussian filter to `img` and converts it to RGBA{N0f8}
2431
"""

examples/imagelike/imageio.jl

+13-1
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,25 @@ arrays = map((RGBA{N0f8}, RGBA{Float32}, RGB{N0f8}, RGB{Float32}, BGRA{N0f8}, BG
2222
loaded_imgs = map(x->loadasset("test_images", x), readdir(assetpath("test_images")))
2323

2424
# combine them all into one array and add an animated gif and a few other images
25+
26+
# backward compatible imconvert
27+
imconvert(im) = im
28+
if isdefined(:Image)
29+
function imconvert(im::Image)
30+
if ndims(im) == 2
31+
convert(Array{eltype(im), ndims(im)}, im)
32+
else
33+
permutedims(im.data, (2, 1, 3))
34+
end
35+
end
36+
end
2537
x = Any[
2638
arrays..., loaded_imgs...,
2739
loadasset("kittens-look.gif"),
2840
loadasset("mario", "stand", "right.png"),
2941
loadasset("mario", "jump", "left.gif"),
3042
]
31-
x = map(x-> convert(Array{eltype(x), ndims(x)}, x), x)
43+
x = map(imconvert, x)
3244

3345
# visualize all images and convert the array to be a vector of element type context
3446
# This shouldn't be necessary, but it seems map is not able to infer the type alone

examples/interactive/mario_game.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ for verb in ["jump", "walk", "stand"], dir in ["left", "right"]
7474
end
7575
path = assetpath("mario", verb, pic)
7676
sequence = read_sequence(path)
77-
gif = map(img->map(RGBA{N0f8}, img), sequence)
77+
gif = map(img->convert(Matrix{RGBA{N0f8}}, img), sequence)
7878
mario_images[verb*dir] = play(gif)
7979
end
8080
function mario2image(mario, images=mario_images)

0 commit comments

Comments
 (0)