-
Notifications
You must be signed in to change notification settings - Fork 8
/
lines.go
49 lines (43 loc) · 943 Bytes
/
lines.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
package imageutil
import (
"image"
"image/color"
"github.com/grokify/mogo/image/colors"
)
func RowsFilteredColor(img image.Image, c color.Color, cmore ...color.Color) []int {
minPt := img.Bounds().Min
maxPt := img.Bounds().Max
rows := []int{}
cmore = append([]color.Color{c}, cmore...)
for y := minPt.Y; y <= maxPt.Y; y++ {
for x := minPt.X; x <= maxPt.X; x++ {
for _, ci := range cmore {
if colors.ColorToHex(img.At(x, y)) == colors.ColorToHex(ci) {
rows = append(rows, y)
continue
}
}
}
}
return rows
}
func ColsFilteredColor(img image.Image, c ...color.Color) []int {
cols := []int{}
if len(c) == 0 {
return cols
}
clrs := colors.Colors(c)
minPt := img.Bounds().Min
maxPt := img.Bounds().Max
COL:
for x := minPt.X; x <= maxPt.X; x++ {
for y := minPt.Y; y <= maxPt.Y; y++ {
cx := img.At(x, y)
if !clrs.In(cx) {
continue COL
}
}
cols = append(cols, x)
}
return cols
}