The Free Software Media System - Server Backend & API
Remove CropWhitespace function
Bond_009620fbf0f89d3
diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.csindex 8a2301d2d6..af6e5b339b 100644--- a/Emby.Drawing/ImageProcessor.cs+++ b/Emby.Drawing/ImageProcessor.cs@@ -181,11 +181,6 @@ namespace Emby.Drawing{if (!File.Exists(cacheFilePath)){- if (options.CropWhiteSpace && !SupportsTransparency(originalImagePath))- {- options.CropWhiteSpace = false;- }-string resultPath = _imageEncoder.EncodeImage(originalImagePath, dateModified, cacheFilePath, autoOrient, orientation, quality, options, outputFormat);if (string.Equals(resultPath, originalImagePath, StringComparison.OrdinalIgnoreCase))diff --git a/Jellyfin.Api/Controllers/ImageController.cs b/Jellyfin.Api/Controllers/ImageController.csindex c606d327c5..cd12963104 100644--- a/Jellyfin.Api/Controllers/ImageController.cs+++ b/Jellyfin.Api/Controllers/ImageController.cs@@ -1681,7 +1681,7 @@ namespace Jellyfin.Api.Controllersint? width,int? height,int? quality,- bool? cropWhitespace,+ bool? cropWhitespace, // TODO: Removebool? addPlayedIndicator,int? blur,string? backgroundColor,@@ -1756,7 +1756,6 @@ namespace Jellyfin.Api.ControllersbackgroundColor,foregroundLayer,imageInfo,- cropWhitespace.Value,outputFormats,cacheDuration,responseHeaders,@@ -1855,7 +1854,6 @@ namespace Jellyfin.Api.Controllersstring? backgroundColor,string? foregroundLayer,ItemImageInfo imageInfo,- bool cropWhitespace,IReadOnlyCollection<ImageFormat> supportedFormats,TimeSpan? cacheDuration,IDictionary<string, string> headers,@@ -1868,7 +1866,6 @@ namespace Jellyfin.Api.Controllersvar options = new ImageProcessingOptions{- CropWhiteSpace = cropWhitespace,Height = height,ImageIndex = index ?? 0,Image = imageInfo,diff --git a/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/Jellyfin.Drawing.Skia/SkiaEncoder.csindex eab5777d5d..a786c01a60 100644--- a/Jellyfin.Drawing.Skia/SkiaEncoder.cs+++ b/Jellyfin.Drawing.Skia/SkiaEncoder.cs@@ -91,9 +91,6 @@ namespace Jellyfin.Drawing.Skia}}- private static bool IsTransparent(SKColor color)- => (color.Red == 255 && color.Green == 255 && color.Blue == 255) || color.Alpha == 0;-/// <summary>/// Convert a <see cref="ImageFormat"/> to a <see cref="SKEncodedImageFormat"/>./// </summary>@@ -111,65 +108,6 @@ namespace Jellyfin.Drawing.Skia};}- private static bool IsTransparentRow(SKBitmap bmp, int row)- {- for (var i = 0; i < bmp.Width; ++i)- {- if (!IsTransparent(bmp.GetPixel(i, row)))- {- return false;- }- }-- return true;- }-- private static bool IsTransparentColumn(SKBitmap bmp, int col)- {- for (var i = 0; i < bmp.Height; ++i)- {- if (!IsTransparent(bmp.GetPixel(col, i)))- {- return false;- }- }-- return true;- }-- private SKBitmap CropWhiteSpace(SKBitmap bitmap)- {- var topmost = 0;- while (topmost < bitmap.Height && IsTransparentRow(bitmap, topmost))- {- topmost++;- }-- int bottommost = bitmap.Height;- while (bottommost >= 0 && IsTransparentRow(bitmap, bottommost - 1))- {- bottommost--;- }-- var leftmost = 0;- while (leftmost < bitmap.Width && IsTransparentColumn(bitmap, leftmost))- {- leftmost++;- }-- var rightmost = bitmap.Width;- while (rightmost >= 0 && IsTransparentColumn(bitmap, rightmost - 1))- {- rightmost--;- }-- var newRect = SKRectI.Create(leftmost, topmost, rightmost - leftmost, bottommost - topmost);-- using var image = SKImage.FromBitmap(bitmap);- using var subset = image.Subset(newRect);- return SKBitmap.FromImage(subset);- }-/// <inheritdoc />/// <exception cref="ArgumentNullException">The path is null.</exception>/// <exception cref="FileNotFoundException">The path is not valid.</exception>@@ -312,22 +250,11 @@ namespace Jellyfin.Drawing.Skiareturn resultBitmap;}- private SKBitmap? GetBitmap(string path, bool cropWhitespace, bool forceAnalyzeBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin)- {- if (cropWhitespace)- {- using var bitmap = Decode(path, forceAnalyzeBitmap, orientation, out origin);- return bitmap == null ? null : CropWhiteSpace(bitmap);- }-- return Decode(path, forceAnalyzeBitmap, orientation, out origin);- }-- private SKBitmap? GetBitmap(string path, bool cropWhitespace, bool autoOrient, ImageOrientation? orientation)+ private SKBitmap? GetBitmap(string path, bool autoOrient, ImageOrientation? orientation){if (autoOrient){- var bitmap = GetBitmap(path, cropWhitespace, true, orientation, out var origin);+ var bitmap = Decode(path, true, orientation, out var origin);if (bitmap != null && origin != SKEncodedOrigin.TopLeft){@@ -340,7 +267,7 @@ namespace Jellyfin.Drawing.Skiareturn bitmap;}- return GetBitmap(path, cropWhitespace, false, orientation, out _);+ return Decode(path, false, orientation, out _);}private SKBitmap OrientImage(SKBitmap bitmap, SKEncodedOrigin origin)@@ -466,7 +393,7 @@ namespace Jellyfin.Drawing.Skiavar blur = options.Blur ?? 0;var hasIndicator = options.AddPlayedIndicator || options.UnplayedCount.HasValue || !options.PercentPlayed.Equals(0);- using var bitmap = GetBitmap(inputPath, options.CropWhiteSpace, autoOrient, orientation);+ using var bitmap = GetBitmap(inputPath, autoOrient, orientation);if (bitmap == null){throw new InvalidDataException($"Skia unable to read image {inputPath}");@@ -474,9 +401,7 @@ namespace Jellyfin.Drawing.Skiavar originalImageSize = new ImageDimensions(bitmap.Width, bitmap.Height);- if (!options.CropWhiteSpace- && options.HasDefaultOptions(inputPath, originalImageSize)- && !autoOrient)+ if (options.HasDefaultOptions(inputPath, originalImageSize) && !autoOrient){// Just spit out the original file if all the options are defaultreturn inputPath;diff --git a/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs b/MediaBrowser.Controller/Drawing/ImageProcessingOptions.csindex 22105b7d79..22de9a43e8 100644--- a/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs+++ b/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs@@ -24,8 +24,6 @@ namespace MediaBrowser.Controller.Drawingpublic int ImageIndex { get; set; }- public bool CropWhiteSpace { get; set; }-public int? Width { get; set; }public int? Height { get; set; }@@ -106,7 +104,6 @@ namespace MediaBrowser.Controller.DrawingPercentPlayed.Equals(0) &&!UnplayedCount.HasValue &&!Blur.HasValue &&- !CropWhiteSpace &&string.IsNullOrEmpty(BackgroundColor) &&string.IsNullOrEmpty(ForegroundLayer);}