aboutsummaryrefslogtreecommitdiff
path: root/Emby.Drawing
diff options
context:
space:
mode:
authorVasily <just.one.man@yandex.ru>2020-06-01 18:12:49 +0300
committerVasily <just.one.man@yandex.ru>2020-06-01 18:12:49 +0300
commit26eef1bbf823e6f9fc22b11d95a17b1370b21842 (patch)
tree78d200c9530bfb2bd9c7c5a6fc42d1dc00796b45 /Emby.Drawing
parent58f099c0e2fec23d861bc9bdb76ac0d6d8e239b7 (diff)
Move logic of computing Blurhash components to ImageProcessor
Also rename last few instances of GetImageHash to GetImageBlurHash for clarity
Diffstat (limited to 'Emby.Drawing')
-rw-r--r--Emby.Drawing/ImageProcessor.cs19
-rw-r--r--Emby.Drawing/NullImageEncoder.cs2
2 files changed, 19 insertions, 2 deletions
diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs
index 35da6f635..89bb3068b 100644
--- a/Emby.Drawing/ImageProcessor.cs
+++ b/Emby.Drawing/ImageProcessor.cs
@@ -315,7 +315,24 @@ namespace Emby.Drawing
/// <inheritdoc />
public string GetImageBlurHash(string path)
- => _imageEncoder.GetImageHash(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)
diff --git a/Emby.Drawing/NullImageEncoder.cs b/Emby.Drawing/NullImageEncoder.cs
index 54de7212a..bbb5c1716 100644
--- a/Emby.Drawing/NullImageEncoder.cs
+++ b/Emby.Drawing/NullImageEncoder.cs
@@ -44,7 +44,7 @@ namespace Emby.Drawing
}
/// <inheritdoc />
- public string GetImageHash(string path)
+ public string GetImageBlurHash(int xComp, int yComp, string path)
{
throw new NotImplementedException();
}