-
Notifications
You must be signed in to change notification settings - Fork 35
/
statistics_gm.go
36 lines (31 loc) · 983 Bytes
/
statistics_gm.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
// +build gm
package magick
// #include <magick/api.h>
import "C"
func (im *Image) statistics() (*Statistics, error) {
var ex C.ExceptionInfo
C.GetExceptionInfo(&ex)
defer C.DestroyExceptionInfo(&ex)
var stats C.ImageStatistics
C.GetImageStatistics(im.image, &stats, &ex)
if ex.severity != C.UndefinedException {
return nil, exError(&ex, "getting statistics")
}
return newStatistics(&stats), nil
}
func newChannelStatistics(ch *C.ImageChannelStatistics) *ChannelStatistics {
return &ChannelStatistics{
Minimum: float64(ch.minimum),
Maximum: float64(ch.maximum),
Mean: float64(ch.mean),
StdDev: float64(ch.standard_deviation),
Variance: float64(ch.variance),
}
}
func newStatistics(stats *C.ImageStatistics) *Statistics {
red := newChannelStatistics(&stats.red)
green := newChannelStatistics(&stats.green)
blue := newChannelStatistics(&stats.blue)
opacity := newChannelStatistics(&stats.opacity)
return &Statistics{red, green, blue, opacity}
}