소스 검색

Remove CropWhitespace function

Bond_009 4 년 전
부모
커밋
620fbf0f89

+ 0 - 5
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))

+ 1 - 4
Jellyfin.Api/Controllers/ImageController.cs

@@ -1681,7 +1681,7 @@ namespace Jellyfin.Api.Controllers
             int? width,
             int? height,
             int? quality,
-            bool? cropWhitespace,
+            bool? cropWhitespace, // TODO: Remove
             bool? addPlayedIndicator,
             int? blur,
             string? backgroundColor,
@@ -1756,7 +1756,6 @@ namespace Jellyfin.Api.Controllers
                 backgroundColor,
                 foregroundLayer,
                 imageInfo,
-                cropWhitespace.Value,
                 outputFormats,
                 cacheDuration,
                 responseHeaders,
@@ -1855,7 +1854,6 @@ namespace Jellyfin.Api.Controllers
             string? backgroundColor,
             string? foregroundLayer,
             ItemImageInfo imageInfo,
-            bool cropWhitespace,
             IReadOnlyCollection<ImageFormat> supportedFormats,
             TimeSpan? cacheDuration,
             IDictionary<string, string> headers,
@@ -1868,7 +1866,6 @@ namespace Jellyfin.Api.Controllers
 
             var options = new ImageProcessingOptions
             {
-                CropWhiteSpace = cropWhitespace,
                 Height = height,
                 ImageIndex = index ?? 0,
                 Image = imageInfo,

+ 5 - 80
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.Skia
             return 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.Skia
                 return 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.Skia
             var 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.Skia
 
             var 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 default
                 return inputPath;

+ 0 - 3
MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs

@@ -24,8 +24,6 @@ namespace MediaBrowser.Controller.Drawing
 
         public 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.Drawing
                 PercentPlayed.Equals(0) &&
                 !UnplayedCount.HasValue &&
                 !Blur.HasValue &&
-                !CropWhiteSpace &&
                 string.IsNullOrEmpty(BackgroundColor) &&
                 string.IsNullOrEmpty(ForegroundLayer);
         }