-
Notifications
You must be signed in to change notification settings - Fork 21
/
effects_cb.go
70 lines (63 loc) · 1.74 KB
/
effects_cb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// +build js,wasm
package shimmer
import (
"syscall/js"
"time"
"github.com/anthonynsimon/bild/adjust"
)
func (s *Shimmer) setupBrightnessCb() {
s.brightnessCb = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// quick return if no source image is yet uploaded
if s.sourceImg == nil {
return nil
}
delta := args[0].Get("target").Get("valueAsNumber").Float()
start := time.Now()
res := adjust.Brightness(s.sourceImg, delta)
s.updateImage(res, start)
args[0].Call("preventDefault")
return nil
})
}
func (s *Shimmer) setupContrastCb() {
s.contrastCb = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// quick return if no source image is yet uploaded
if s.sourceImg == nil {
return nil
}
delta := args[0].Get("target").Get("valueAsNumber").Float()
start := time.Now()
res := adjust.Contrast(s.sourceImg, delta)
s.updateImage(res, start)
args[0].Call("preventDefault")
return nil
})
}
func (s *Shimmer) setupHueCb() {
s.hueCb = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// quick return if no source image is yet uploaded
if s.sourceImg == nil {
return nil
}
delta := args[0].Get("target").Get("valueAsNumber").Int()
start := time.Now()
res := adjust.Hue(s.sourceImg, delta)
s.updateImage(res, start)
args[0].Call("preventDefault")
return nil
})
}
func (s *Shimmer) setupSatCb() {
s.satCb = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// quick return if no source image is yet uploaded
if s.sourceImg == nil {
return nil
}
delta := args[0].Get("target").Get("valueAsNumber").Float()
start := time.Now()
res := adjust.Saturation(s.sourceImg, delta)
s.updateImage(res, start)
args[0].Call("preventDefault")
return nil
})
}