Improved average color usage

This commit is contained in:
Eduard Urbach 2018-03-20 21:22:16 +01:00
parent 1fa11c162a
commit 858aec9719
4 changed files with 7 additions and 31 deletions

View File

@ -3,7 +3,7 @@ component AnimeGrid(animeList []*arn.Anime, user *arn.User)
each anime in animeList each anime in animeList
.anime-grid-cell(data-added=(user != nil && user.AnimeList().Contains(anime.ID))) .anime-grid-cell(data-added=(user != nil && user.AnimeList().Contains(anime.ID)))
a.ajax(href="/anime/" + toString(anime.ID)) a.ajax(href="/anime/" + toString(anime.ID))
img.anime-grid-image.lazy(data-src=anime.ImageLink("medium"), data-webp="true", alt=anime.Title.Romaji) img.anime-grid-image.lazy(data-src=anime.ImageLink("medium"), data-webp="true", data-color=anime.Image.AverageColor, alt=anime.Title.Romaji)
.anime-grid-title .anime-grid-title
.anime-grid-title-text= anime.Title.ByUser(user) .anime-grid-title-text= anime.Title.ByUser(user)

View File

@ -8,7 +8,7 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList,
each item in animeList.Items each item in animeList.Items
if item.Status == arn.AnimeListStatusWatching || item.Status == arn.AnimeListStatusCompleted if item.Status == arn.AnimeListStatusWatching || item.Status == arn.AnimeListStatusCompleted
a.profile-watching-list-item.ajax(href=item.Anime().Link(), title=item.Anime().Title.ByUser(user) + " (" + toString(item.Episodes) + " / " + arn.EpisodesToString(item.Anime().EpisodeCount) + ")") a.profile-watching-list-item.ajax(href=item.Anime().Link(), title=item.Anime().Title.ByUser(user) + " (" + toString(item.Episodes) + " / " + arn.EpisodesToString(item.Anime().EpisodeCount) + ")")
img.profile-watching-list-item-image.lazy(data-src=item.Anime().ImageLink("small"), data-webp="true", alt=item.Anime().Title.ByUser(user)) img.profile-watching-list-item-image.lazy(data-src=item.Anime().ImageLink("small"), data-webp="true", data-color=item.Anime().Image.AverageColor, alt=item.Anime().Title.ByUser(user))
.footer .footer
.buttons .buttons

View File

@ -73,34 +73,6 @@ func update(anime *arn.Anime, filePath string) {
return return
} }
width := img.Bounds().Dx() anime.Image.AverageColor = arn.GetAverageColor(img)
height := img.Bounds().Dy()
totalR := uint64(0)
totalG := uint64(0)
totalB := uint64(0)
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
r, g, b, _ := img.At(x, y).RGBA()
totalR += uint64(r)
totalG += uint64(g)
totalB += uint64(b)
}
}
pixels := uint64(width * height)
const max = float64(65535)
averageR := float64(totalR/pixels) / max
averageG := float64(totalG/pixels) / max
averageB := float64(totalB/pixels) / max
h, s, l := arn.RGBToHSL(averageR, averageG, averageB)
anime.Image.AverageColor.Hue = h
anime.Image.AverageColor.Saturation = s
anime.Image.AverageColor.Lightness = l
anime.Save() anime.Save()
} }

View File

@ -574,6 +574,10 @@ export class AnimeNotifier {
} }
element.onerror = () => { element.onerror = () => {
if(element.classList.contains("element-found")) {
return
}
this.elementNotFound.queue(element) this.elementNotFound.queue(element)
} }
} else { } else {