This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
/
image.go
98 lines (91 loc) · 2.01 KB
/
image.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package util
import (
"errors"
"github.com/disintegration/imaging"
"image"
)
func IsSolidColor(img image.Image) bool {
base := img.At(img.Bounds().Min.X, img.Bounds().Min.Y)
for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ {
if img.At(x, y) != base {
return false
}
}
}
return true
}
func ParseScale(name string) (filter *imaging.ResampleFilter, err error) {
switch name {
case "NearestNeighbor":
filter = &imaging.NearestNeighbor
case "Box":
filter = &imaging.Box
case "Linear":
filter = &imaging.Linear
case "Hermite":
filter = &imaging.Hermite
case "MitchellNetravali":
filter = &imaging.MitchellNetravali
case "CatmullRom":
filter = &imaging.CatmullRom
case "BSpline":
filter = &imaging.BSpline
case "Gaussian":
filter = &imaging.Gaussian
case "Bartlett":
filter = &imaging.Bartlett
case "Lanczos":
filter = &imaging.Lanczos
case "Hann":
filter = &imaging.Hann
case "Hamming":
filter = &imaging.Hamming
case "Blackman":
filter = &imaging.Blackman
case "Welch":
filter = &imaging.Welch
case "Cosine":
filter = &imaging.Cosine
default:
err = errors.New("Unknown resample filter: " + name)
}
return
}
func ScaleName(filter *imaging.ResampleFilter) (name string) {
switch filter {
case &imaging.NearestNeighbor:
name = "NearestNeighbor"
case &imaging.Box:
name = "Box"
case &imaging.Linear:
name = "Linear"
case &imaging.Hermite:
name = "Hermite"
case &imaging.MitchellNetravali:
name = "MitchellNetravali"
case &imaging.CatmullRom:
name = "CatmullRom"
case &imaging.BSpline:
name = "BSpline"
case &imaging.Gaussian:
name = "Gaussian"
case &imaging.Bartlett:
name = "Bartlett"
case &imaging.Lanczos:
name = "Lanczos"
case &imaging.Hann:
name = "Hann"
case &imaging.Hamming:
name = "Hamming"
case &imaging.Blackman:
name = "Blackman"
case &imaging.Welch:
name = "Welch"
case &imaging.Cosine:
name = "Cosine"
default:
panic("Unknown resample filter")
}
return
}