diff --git a/filter/basic.go b/filter/basic.go index fbc45cf3..5c38539d 100644 --- a/filter/basic.go +++ b/filter/basic.go @@ -142,7 +142,7 @@ func (bf *Basic) Write(f []byte) (int, error) { if bf.debug { err := bf.saveFrame() if err != nil { - return len(f), err + return len(f), fmt.Errorf("image can't be encoded for debug video: %w", err) } } @@ -155,19 +155,9 @@ func (bf *Basic) Write(f []byte) (int, error) { return bf.dst.Write(f) } -func absDiff(a, b uint32) int { - c := int(a) - int(b) - if c < 0 { - return -c - } else { - return c - } - -} - // Go routine for one row of the image to be processed func (bf *Basic) process(j int, wg *sync.WaitGroup) { - for i := 0; i < bf.w; i++ { + for i, _ := range bf.bg[j] { n := bf.img.At(i, j) r, b, g, _ := n.RGBA() @@ -207,12 +197,21 @@ func (bf *Basic) saveFrame() error { Dot: fixed.P(20, 30), } var s string - if bf.motion > 1000 { + if bf.motion > bf.pix { s = strconv.Itoa(bf.motion) + " Motion" } else { s = strconv.Itoa(bf.motion) } d.DrawString(s) - err := jpeg.Encode(bf.file, bf.bwImg, nil) - return err + return jpeg.Encode(bf.file, bf.bwImg, nil) +} + +func absDiff(a, b uint32) int { + c := int(a) - int(b) + if c < 0 { + return -c + } else { + return c + } + }