-
Notifications
You must be signed in to change notification settings - Fork 55
/
imagefiltermanager.go
51 lines (41 loc) · 1.2 KB
/
imagefiltermanager.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
// Copyright 2013 hanguofeng. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gocaptcha
import ()
//ImageFilterManager
type ImageFilterManager struct {
filters []ImageFilter
}
func init() {
RegisterImageFilter(IMAGE_FILTER_NOISE_LINE, imageFilterNoiseLineCreator)
RegisterImageFilter(IMAGE_FILTER_NOISE_POINT, imageFilterNoisePointCreator)
RegisterImageFilter(IMAGE_FILTER_STRIKE, imageFilterStrikeCreator)
}
func CreateImageFilterManager() *ImageFilterManager {
ret := new(ImageFilterManager)
ret.filters = []ImageFilter{}
return ret
}
func (manager *ImageFilterManager) AddFilter(filter ImageFilter) {
manager.filters = append(manager.filters, filter)
}
func (manager *ImageFilterManager) GetFilters() []ImageFilter {
return manager.filters
}
func CreateImageFilterManagerByConfig(config *FilterConfig) *ImageFilterManager {
mgr := new(ImageFilterManager)
mgr.filters = []ImageFilter{}
for _, cfgId := range config.Filters {
creator, has := imageFilterCreators[cfgId]
if !has {
continue
}
cfgGroup, has := config.GetGroup(cfgId)
if !has {
continue
}
mgr.AddFilter(creator(cfgGroup))
}
return mgr
}