From e582f44a757325ffec97ba86c32eb4683beb1838 Mon Sep 17 00:00:00 2001 From: TheDen Date: Fri, 11 Aug 2023 06:20:18 +1000 Subject: [PATCH] simplify grayscaling --- internal/generator/image.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/internal/generator/image.go b/internal/generator/image.go index db3a2fc7..2d6d20a7 100644 --- a/internal/generator/image.go +++ b/internal/generator/image.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "image" - "image/color" + "image/draw" "runtime" "time" @@ -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 }