aboutsummaryrefslogtreecommitdiff
path: root/Emby.Drawing/ImageProcessor.cs
diff options
context:
space:
mode:
authorVasily <JustAMan@users.noreply.github.com>2020-06-02 17:25:45 +0300
committerGitHub <noreply@github.com>2020-06-02 17:25:45 +0300
commitb9618c8c015b5a49110c3abad8659525bdfac4fd (patch)
tree11dded5020a3690a728c30898f7674e7c8a1cf01 /Emby.Drawing/ImageProcessor.cs
parentd38adb95a727203b0d0dcee344f03b374b5d2b8f (diff)
parent26eef1bbf823e6f9fc22b11d95a17b1370b21842 (diff)
Merge pull request #2676 from GranPC/public-pr/blurhash
Implement Blurhash generation for images
Diffstat (limited to 'Emby.Drawing/ImageProcessor.cs')
-rw-r--r--Emby.Drawing/ImageProcessor.cs21
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);