Переглянути джерело

More plugins: contrast, brightness, invert, colors

+ move plugins to plugins.available by default
Gildas Chabot 8 роки тому
батько
коміт
4c375128ad

+ 2 - 2
buildAndRun.sh

@@ -6,7 +6,7 @@ set -x
6 6
 
7 7
 pluginSrc='pluginSrc'
8 8
 pluginDirs=`ls $pluginSrc`
9
-mkdir -p plugins
9
+mkdir -p plugins.available plugins
10 10
 
11 11
 for i in ${pluginDirs}
12 12
 do
@@ -14,7 +14,7 @@ do
14 14
     (cd $fullPath; docker run --rm -v "$PWD":/usr/src/$fullPath -w /usr/src/$fullPath golang:1.8 go build -buildmode=plugin)
15 15
 done
16 16
 
17
-mv -f `find $pluginSrc -name '*.so'` plugins/
17
+mv -f `find $pluginSrc -name '*.so'` plugins.available/
18 18
 
19 19
 # Compile main app
20 20
 

+ 20 - 0
pluginSrc/blue/plugin.go

@@ -0,0 +1,20 @@
1
+package main
2
+
3
+import (
4
+	"image"
5
+	"image/color"
6
+)
7
+
8
+// Convert to binary image
9
+func Transform(src image.Image) image.Image {
10
+	bounds := src.Bounds()
11
+	w, h := bounds.Max.X, bounds.Max.Y
12
+	ret := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{w, h}})
13
+	for x := 0; x < w; x++ {
14
+		for y := 0; y < h; y++ {
15
+			_, _, b, _ := src.At(x, y).RGBA()
16
+			ret.Set(x, y, color.RGBA{0, 0, uint8(b / 255), 0})
17
+		}
18
+	}
19
+	return ret
20
+}

+ 34 - 0
pluginSrc/brightness/plugin.go

@@ -0,0 +1,34 @@
1
+package main
2
+
3
+import (
4
+	"image"
5
+	"image/color"
6
+)
7
+
8
+func add(v uint32) uint32 {
9
+	v += 50
10
+	if v > 255 {
11
+		v = 255
12
+	}
13
+	return v
14
+}
15
+
16
+// Convert to binary image
17
+func Transform(src image.Image) image.Image {
18
+	bounds := src.Bounds()
19
+	w, h := bounds.Max.X, bounds.Max.Y
20
+	ret := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{w, h}})
21
+	for x := 0; x < w; x++ {
22
+		for y := 0; y < h; y++ {
23
+			r, g, b, _ := src.At(x, y).RGBA()
24
+			r, g, b = r/256, g/256, b/256
25
+
26
+			r = add(r)
27
+			g = add(g)
28
+			b = add(b)
29
+
30
+			ret.Set(x, y, color.RGBA{uint8(r), uint8(g), uint8(b), 0})
31
+		}
32
+	}
33
+	return ret
34
+}

+ 43 - 0
pluginSrc/contrast/plugin.go

@@ -0,0 +1,43 @@
1
+package main
2
+
3
+import (
4
+	"image"
5
+	"image/color"
6
+)
7
+
8
+func contrast(v uint32) uint32 {
9
+	vf := float64(v) / 255
10
+	if vf < 0.5 {
11
+		vf = vf * vf * 2
12
+	} else {
13
+		vf = 1 - vf
14
+		vf = 1 - vf*vf*2
15
+	}
16
+	return uint32(255 * vf)
17
+
18
+	// if v < 128 {
19
+	// 	return v * v * 2
20
+	// }
21
+	// v = 128 - v
22
+	// return 128 - v*v*2
23
+}
24
+
25
+// Convert to binary image
26
+func Transform(src image.Image) image.Image {
27
+	bounds := src.Bounds()
28
+	w, h := bounds.Max.X, bounds.Max.Y
29
+	ret := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{w, h}})
30
+	for x := 0; x < w; x++ {
31
+		for y := 0; y < h; y++ {
32
+			r, g, b, _ := src.At(x, y).RGBA()
33
+			r, g, b = r/256, g/256, b/256
34
+
35
+			r = contrast(r)
36
+			g = contrast(g)
37
+			b = contrast(b)
38
+
39
+			ret.Set(x, y, color.RGBA{uint8(r), uint8(g), uint8(b), 0})
40
+		}
41
+	}
42
+	return ret
43
+}

+ 20 - 0
pluginSrc/green/plugin.go

@@ -0,0 +1,20 @@
1
+package main
2
+
3
+import (
4
+	"image"
5
+	"image/color"
6
+)
7
+
8
+// Convert to binary image
9
+func Transform(src image.Image) image.Image {
10
+	bounds := src.Bounds()
11
+	w, h := bounds.Max.X, bounds.Max.Y
12
+	ret := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{w, h}})
13
+	for x := 0; x < w; x++ {
14
+		for y := 0; y < h; y++ {
15
+			_, g, _, _ := src.At(x, y).RGBA()
16
+			ret.Set(x, y, color.RGBA{0, uint8(g / 255), 0, 0})
17
+		}
18
+	}
19
+	return ret
20
+}

+ 22 - 0
pluginSrc/invert/plugin.go

@@ -0,0 +1,22 @@
1
+package main
2
+
3
+import (
4
+	"image"
5
+	"image/color"
6
+)
7
+
8
+// Convert to binary image
9
+func Transform(src image.Image) image.Image {
10
+	bounds := src.Bounds()
11
+	w, h := bounds.Max.X, bounds.Max.Y
12
+	ret := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{w, h}})
13
+	for x := 0; x < w; x++ {
14
+		for y := 0; y < h; y++ {
15
+			r, g, b, _ := src.At(x, y).RGBA()
16
+			r, g, b = 255-r/256, 255-g/256, 255-b/256
17
+
18
+			ret.Set(x, y, color.RGBA{uint8(r), uint8(g), uint8(b), 0})
19
+		}
20
+	}
21
+	return ret
22
+}

+ 20 - 0
pluginSrc/red/plugin.go

@@ -0,0 +1,20 @@
1
+package main
2
+
3
+import (
4
+	"image"
5
+	"image/color"
6
+)
7
+
8
+// Convert to binary image
9
+func Transform(src image.Image) image.Image {
10
+	bounds := src.Bounds()
11
+	w, h := bounds.Max.X, bounds.Max.Y
12
+	ret := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{w, h}})
13
+	for x := 0; x < w; x++ {
14
+		for y := 0; y < h; y++ {
15
+			r, _, _, _ := src.At(x, y).RGBA()
16
+			ret.Set(x, y, color.RGBA{uint8(r / 255), 0, 0, 0})
17
+		}
18
+	}
19
+	return ret
20
+}