Skip to content

Commit

Permalink
Update galaktaglare.go
Browse files Browse the repository at this point in the history
  • Loading branch information
simplyYan authored Jan 25, 2024
1 parent debc275 commit 7513dff
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions galaktaglare.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"runtime"
"sort"
"strings"

"github.com/nfnt/resize"
"github.com/pelletier/go-toml"
)

Expand Down Expand Up @@ -55,15 +55,31 @@ func (gg *GalaktaGlare) ImageScan(imagePath string) (float64, error) {
asciiImage := imageToASCII(img)

var maxSimilarity float64
var wg sync.WaitGroup

Check failure on line 58 in galaktaglare.go

View workflow job for this annotation

GitHub Actions / build

undefined: sync
similarityChan := make(chan float64)

for _, dbImagePath := range gg.imageDB {
dbImg, err := loadImage(dbImagePath)
if err != nil {
return 0, err
}
wg.Add(1)
go func(dbImagePath string) {
defer wg.Done()
dbImg, err := loadImage(dbImagePath)
if err != nil {
// handle error
return
}

dbAsciiImage := imageToASCII(dbImg)
similarity := compareImages(asciiImage, dbAsciiImage)
similarityChan <- similarity
}(dbImagePath)
}

dbAsciiImage := imageToASCII(dbImg)
similarity := compareImages(asciiImage, dbAsciiImage)
go func() {
wg.Wait()
close(similarityChan)
}()

for similarity := range similarityChan {
if similarity > maxSimilarity {
maxSimilarity = similarity
}
Expand All @@ -84,7 +100,9 @@ func loadImage(filename string) (image.Image, error) {
return nil, err
}

return img, nil
resizedImg := resize.Resize(1000, 0, img, resize.Lanczos3)

return resizedImg, nil
}

func imageToASCII(img image.Image) string {
Expand Down

0 comments on commit 7513dff

Please sign in to comment.