From f30b07130fc21247e3c6edd61d004a9286c5340c Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 27 May 2020 19:29:57 +0300 Subject: [PATCH] Workaround a bug in BlurHashSharp --- Jellyfin.Drawing.Skia/SkiaEncoder.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/Jellyfin.Drawing.Skia/SkiaEncoder.cs index ccd501214e..85461ca4ef 100644 --- a/Jellyfin.Drawing.Skia/SkiaEncoder.cs +++ b/Jellyfin.Drawing.Skia/SkiaEncoder.cs @@ -251,10 +251,18 @@ namespace Jellyfin.Drawing.Skia // 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 xComp = MathF.Sqrt(16.0f * dims.Width / dims.Height); - float yComp = xComp * dims.Height / dims.Width; + float xCompF = MathF.Sqrt(16.0f * dims.Width / dims.Height); + float yCompF = xCompF * dims.Height / dims.Width; - return BlurHashEncoder.Encode(Math.Min((int)xComp + 1, 9), Math.Min((int)yComp + 1, 9), path); + int xComp = Math.Min((int)xCompF + 1, 9); + int yComp = Math.Min((int)yCompF + 1, 9); + + // FIXME: current lib is bugged for xComp != yComp + // remove when https://github.com/Bond-009/BlurHashSharp/pull/1 is merged + int tmp = Math.Max(xComp, yComp); + xComp = yComp = tmp; + + return BlurHashEncoder.Encode(xComp, yComp, path); } private static bool HasDiacritics(string text)