Skip to content

Commit

Permalink
simplify grayscaling
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDen committed Aug 10, 2023
1 parent 82eb4bf commit e582f44
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions internal/generator/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"image"
"image/color"
"image/draw"
"runtime"
"time"

Expand Down Expand Up @@ -139,16 +139,7 @@ func convertToGrayscale(imgPtr *image.Image) image.Image {
img := *imgPtr
bounds := img.Bounds()
grayImg := image.NewGray(bounds)

for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
colorRGB := img.At(x, y)
r, g, b, _ := colorRGB.RGBA()

grayValue := uint8((r + g + b) / 3 >> 8)
grayImg.SetGray(x, y, color.Gray{Y: grayValue})
}
}
draw.Draw(grayImg, grayImg.Bounds(), img, img.Bounds().Min, draw.Src)
return grayImg
}

Expand Down

0 comments on commit e582f44

Please sign in to comment.