-
Notifications
You must be signed in to change notification settings - Fork 35
/
operator_im.go
67 lines (63 loc) · 1.62 KB
/
operator_im.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
// +build !gm
package magick
// #include <magick/api.h>
import "C"
import (
"fmt"
)
func (im *Image) operateChannel(op Operator, ch Channel, value float64) error {
var cop C.MagickEvaluateOperator
switch op {
case OpAdd:
cop = C.AddEvaluateOperator
case OpAnd:
cop = C.AndEvaluateOperator
case OpAssign:
cop = C.SetEvaluateOperator
case OpDivide:
cop = C.DivideEvaluateOperator
case OpLog:
cop = C.LogEvaluateOperator
case OpLShift:
cop = C.LeftShiftEvaluateOperator
case OpMultiply:
cop = C.MultiplyEvaluateOperator
case OpGaussianNoise:
cop = C.GaussianNoiseEvaluateOperator
case OpImpulseNoise:
cop = C.ImpulseNoiseEvaluateOperator
case OpLaplacianNoise:
cop = C.LaplacianNoiseEvaluateOperator
case OpMultiplicativeNoise:
cop = C.MultiplicativeNoiseEvaluateOperator
case OpPoissonNoise:
cop = C.PoissonNoiseEvaluateOperator
case OpUniformNoise:
cop = C.UniformNoiseEvaluateOperator
case OpOr:
cop = C.OrEvaluateOperator
case OpPow:
cop = C.PowEvaluateOperator
case OpRShift:
cop = C.RightShiftEvaluateOperator
case OpSubstract:
cop = C.SubtractEvaluateOperator
case OpThresholdBlack:
cop = C.ThresholdBlackEvaluateOperator
case OpThreshold:
cop = C.ThresholdEvaluateOperator
case OpThresholdWhite:
cop = C.ThresholdWhiteEvaluateOperator
case OpXor:
cop = C.XorEvaluateOperator
default:
return notImplementedError(fmt.Sprintf("operator %s", op))
}
var ex C.ExceptionInfo
C.GetExceptionInfo(&ex)
defer C.DestroyExceptionInfo(&ex)
if C.EvaluateImageChannel(im.image, C.ChannelType(ch), cop, C.double(value), &ex) != C.MagickTrue {
return exError(&ex, "operating")
}
return nil
}