-
Notifications
You must be signed in to change notification settings - Fork 1
/
nearest_neighbour.go
56 lines (50 loc) · 1.13 KB
/
nearest_neighbour.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
package bayer
type nearestNeighbour struct {
base
}
// NewNearestNeighbour instanciates a nearest neighbour algorithm to parse the CFA provided as buf.
func NewNearestNeighbour(buf []byte, opts *Options) Bayer {
return &nearestNeighbour{
base: base{
buf: buf,
bytesPerPixels: opts.Depth / 8,
Options: opts,
},
}
}
func (byr *nearestNeighbour) At(x, y int) (r, g, b float64) {
r = float64(byr.red(x, y))
g = float64(byr.green(x, y))
b = float64(byr.blue(x, y))
return
}
func (byr *nearestNeighbour) red(x, y int) float64 {
if byr.isGreenR(x, y) {
return byr.pixel(x+1, y)
}
if byr.isGreenB(x, y) {
return byr.pixel(x, y+1)
}
if byr.isBlue(x, y) {
return byr.pixel(x+1, y+1)
}
return byr.pixel(x, y)
}
func (byr *nearestNeighbour) green(x, y int) float64 {
if byr.isRed(x, y) || byr.isBlue(x, y) {
return byr.pixel(x+1, y)
}
return byr.pixel(x, y)
}
func (byr *nearestNeighbour) blue(x, y int) float64 {
if byr.isRed(x, y) {
return byr.pixel(x+1, y+1)
}
if byr.isGreenR(x, y) {
return byr.pixel(x, y+1)
}
if byr.isGreenB(x, y) {
return byr.pixel(x+1, y)
}
return byr.pixel(x, y)
}