filter: basic: comments

This commit is contained in:
Ella Pietraroia 2020-02-03 11:11:38 +10:30
parent 17e1eb0436
commit cd1088c2fa
1 changed files with 4 additions and 2 deletions

View File

@ -99,7 +99,7 @@ func (bf *Basic) Write(f []byte) (int, error) {
return 0, fmt.Errorf("image can't be decoded: %w", err) return 0, fmt.Errorf("image can't be decoded: %w", err)
} }
// First frame must be set as the first background image // First frame must be set as the first background image.
if bf.bg == nil { if bf.bg == nil {
bounds := bf.img.Bounds() bounds := bf.img.Bounds()
bf.w = bounds.Max.X bf.w = bounds.Max.X
@ -153,7 +153,7 @@ func (bf *Basic) Write(f []byte) (int, error) {
return bf.dst.Write(f) return bf.dst.Write(f)
} }
// Go routine for one row of the image to be processed // Go routine for one row of the image to be processed.
func (bf *Basic) process(j int, wg *sync.WaitGroup) { func (bf *Basic) process(j int, wg *sync.WaitGroup) {
for i, _ := range bf.bg[j] { for i, _ := range bf.bg[j] {
n := bf.img.At(i, j) n := bf.img.At(i, j)
@ -186,6 +186,7 @@ func (bf *Basic) process(j int, wg *sync.WaitGroup) {
wg.Done() wg.Done()
} }
// Writes a visualisation of the motion being detected to file.
func (bf *Basic) saveFrame() error { func (bf *Basic) saveFrame() error {
col := color.RGBA{200, 100, 0, 255} // Red text. col := color.RGBA{200, 100, 0, 255} // Red text.
d := &font.Drawer{ d := &font.Drawer{
@ -204,6 +205,7 @@ func (bf *Basic) saveFrame() error {
return jpeg.Encode(bf.file, bf.bwImg, nil) return jpeg.Encode(bf.file, bf.bwImg, nil)
} }
// Returns the absolute value of the difference of two uint32 numbers.
func absDiff(a, b uint32) int { func absDiff(a, b uint32) int {
c := int(a) - int(b) c := int(a) - int(b)
if c < 0 { if c < 0 {