Skip to content

Commit

Permalink
fix overflow in GetGrayAvg
Browse files Browse the repository at this point in the history
  • Loading branch information
abe-winter committed Sep 4, 2023
1 parent ceb4343 commit 60f60f3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rimage/gray_image_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func MultiplyGrays(g1, g2 *image.Gray) (*image.Gray16, error) {

// GetGrayAvg takes in a grayscale image and returns the average value as an int.
func GetGrayAvg(pic *image.Gray16) int {
var sum int
var sum int64
for y := pic.Bounds().Min.Y; y < pic.Bounds().Max.Y; y++ {
for x := pic.Bounds().Min.X; x < pic.Bounds().Max.X; x++ {
val := pic.At(x, y).(color.Gray16).Y
sum += int(val)
sum += int64(val)
}
}
return sum / (pic.Bounds().Max.X * pic.Bounds().Max.Y)
return int(sum / int64(pic.Bounds().Max.X * pic.Bounds().Max.Y))
}

// GetGraySum takes in a grayscale image and returns the total sum as an int.
Expand Down

0 comments on commit 60f60f3

Please sign in to comment.