-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrop.go
47 lines (40 loc) · 787 Bytes
/
crop.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
package snip
import (
"image"
)
/*
FieldMask is the struct to define a mask used on
crop method
*/
type FieldMask struct {
X int `json:"x"`
Y int `json:"y"`
Width int `json:"width"`
Height int `json:"height"`
}
/*
Crop is responsible for cutting the selected region of an image.
*/
func Crop(img image.Image, field Field, c *chan ExtractedIMG) {
defer wg.Done()
mask := field.Mask
fieldIMG := image.NewRGBA(image.Rectangle{
Min: image.Point{
X: mask.X,
Y: mask.Y,
},
Max: image.Point{
X: mask.X + mask.Width,
Y: mask.Y + mask.Height,
},
})
for x := mask.X; x < mask.X+mask.Width; x++ {
for y := mask.Y; y < mask.Y+mask.Height; y++ {
fieldIMG.Set(x, y, img.At(x, y))
}
}
*c <- ExtractedIMG{
Image: fieldIMG,
Field: field,
}
}