diff options
| author | Max Git <rotvel@gmail.com> | 2020-06-02 20:17:13 +0200 |
|---|---|---|
| committer | Max Git <rotvel@gmail.com> | 2020-06-02 20:17:13 +0200 |
| commit | 5577cc375e93b32ef4cc874813a90dbe50be3279 (patch) | |
| tree | b629a047a019d629c8196717d9967eaccab41982 /Emby.Drawing/ImageProcessor.cs | |
| parent | e103d087d316bc19bf6227b21e8d9dfd091fd6a7 (diff) | |
| parent | b9618c8c015b5a49110c3abad8659525bdfac4fd (diff) | |
Merge branch 'master' into feature/ffmpeg-version-check
Diffstat (limited to 'Emby.Drawing/ImageProcessor.cs')
| -rw-r--r-- | Emby.Drawing/ImageProcessor.cs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index 0b3bbe29e..89bb3068b 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -314,6 +314,27 @@ namespace Emby.Drawing => _imageEncoder.GetImageSize(path); /// <inheritdoc /> + public string GetImageBlurHash(string path) + { + var size = GetImageDimensions(path); + if (size.Width <= 0 || size.Height <= 0) + { + return string.Empty; + } + + // We want tiles to be as close to square as possible, and to *mostly* keep under 16 tiles for performance. + // One tile is (width / xComp) x (height / yComp) pixels, which means that ideally yComp = xComp * height / width. + // See more at https://github.com/woltapp/blurhash/#how-do-i-pick-the-number-of-x-and-y-components + float xCompF = MathF.Sqrt(16.0f * size.Width / size.Height); + float yCompF = xCompF * size.Height / size.Width; + + int xComp = Math.Min((int)xCompF + 1, 9); + int yComp = Math.Min((int)yCompF + 1, 9); + + return _imageEncoder.GetImageBlurHash(xComp, yComp, path); + } + + /// <inheritdoc /> public string GetImageCacheTag(BaseItem item, ItemImageInfo image) => (item.Path + image.DateModified.Ticks).GetMD5().ToString("N", CultureInfo.InvariantCulture); |
