From 8fc8fc06223c567141289cde9ab00c66acfaa6e2 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sat, 12 Jan 2019 14:46:17 +0100 Subject: [PATCH 1/7] Cleanup ImageProcessor --- Emby.Drawing/ImageProcessor.cs | 231 +++++++----------- .../ApplicationHost.cs | 2 +- Jellyfin.Server/Program.cs | 5 +- .../Drawing/IImageProcessor.cs | 2 +- 4 files changed, 97 insertions(+), 143 deletions(-) diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index f919904422..625e566600 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -1,4 +1,3 @@ -using SkiaSharp; using System; using System.Collections.Generic; using System.Globalization; @@ -18,9 +17,8 @@ using MediaBrowser.Model.Entities; using MediaBrowser.Model.Extensions; using MediaBrowser.Model.IO; using MediaBrowser.Model.Net; -using MediaBrowser.Model.Serialization; -using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; +using SkiaSharp; namespace Emby.Drawing { @@ -47,28 +45,27 @@ namespace Emby.Drawing private readonly ILogger _logger; private readonly IFileSystem _fileSystem; - private readonly IJsonSerializer _jsonSerializer; private readonly IServerApplicationPaths _appPaths; private IImageEncoder _imageEncoder; private readonly Func _libraryManager; private readonly Func _mediaEncoder; - public ImageProcessor(ILogger logger, + public ImageProcessor( + ILogger logger, IServerApplicationPaths appPaths, IFileSystem fileSystem, - IJsonSerializer jsonSerializer, IImageEncoder imageEncoder, - Func libraryManager, ITimerFactory timerFactory, Func mediaEncoder) + Func libraryManager, + Func mediaEncoder) { _logger = logger; + _appPaths = appPaths; _fileSystem = fileSystem; - _jsonSerializer = jsonSerializer; _imageEncoder = imageEncoder; _libraryManager = libraryManager; _mediaEncoder = mediaEncoder; - _appPaths = appPaths; - ImageEnhancers = new IImageEnhancer[] { }; + ImageEnhancers = Array.Empty(); ImageHelper.ImageProcessor = this; } @@ -145,21 +142,19 @@ namespace Emby.Drawing return _imageEncoder.SupportedOutputFormats; } - private readonly string[] TransparentImageTypes = new string[] { ".png", ".webp", ".gif" }; + private static readonly string[] TransparentImageTypes = new string[] { ".png", ".webp", ".gif" }; public bool SupportsTransparency(string path) - { - return TransparentImageTypes.Contains(Path.GetExtension(path) ?? string.Empty); - } + => TransparentImageTypes.Contains(Path.GetExtension(path).ToLower()); - public async Task> ProcessImage(ImageProcessingOptions options) + public async Task<(string path, string mimeType, DateTime dateModified)> ProcessImage(ImageProcessingOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } - var originalImage = options.Image; - var item = options.Item; + ItemImageInfo originalImage = options.Image; + BaseItem item = options.Item; if (!originalImage.IsLocalFile) { @@ -170,19 +165,23 @@ namespace Emby.Drawing originalImage = await _libraryManager().ConvertImageToLocal(item, originalImage, options.ImageIndex).ConfigureAwait(false); } - var originalImagePath = originalImage.Path; - var dateModified = originalImage.DateModified; - var originalImageSize = originalImage.Width > 0 && originalImage.Height > 0 ? new ImageSize(originalImage.Width, originalImage.Height) : (ImageSize?)null; + string originalImagePath = originalImage.Path; + DateTime dateModified = originalImage.DateModified; + ImageSize? originalImageSize = null; + if (originalImage.Width > 0 && originalImage.Height > 0) + { + originalImageSize = new ImageSize(originalImage.Width, originalImage.Height); + } if (!_imageEncoder.SupportsImageEncoding) { - return new Tuple(originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); + return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); } var supportedImageInfo = await GetSupportedImage(originalImagePath, dateModified).ConfigureAwait(false); - originalImagePath = supportedImageInfo.Item1; - dateModified = supportedImageInfo.Item2; - var requiresTransparency = TransparentImageTypes.Contains(Path.GetExtension(originalImagePath) ?? string.Empty); + originalImagePath = supportedImageInfo.path; + dateModified = supportedImageInfo.dateModified; + bool requiresTransparency = TransparentImageTypes.Contains(Path.GetExtension(originalImagePath)); if (options.Enhancers.Length > 0) { @@ -196,20 +195,18 @@ namespace Emby.Drawing DateModified = dateModified, Type = originalImage.Type, Path = originalImagePath - }, requiresTransparency, item, options.ImageIndex, options.Enhancers, CancellationToken.None).ConfigureAwait(false); - originalImagePath = tuple.Item1; - dateModified = tuple.Item2; - requiresTransparency = tuple.Item3; + originalImagePath = tuple.path; + dateModified = tuple.dateModified; + requiresTransparency = tuple.transparent; // TODO: Get this info originalImageSize = null; } - var photo = item as Photo; - var autoOrient = false; + bool autoOrient = false; ImageOrientation? orientation = null; - if (photo != null) + if (item is Photo photo) { if (photo.Orientation.HasValue) { @@ -230,7 +227,7 @@ namespace Emby.Drawing if (options.HasDefaultOptions(originalImagePath, originalImageSize) && (!autoOrient || !options.RequiresAutoOrientation)) { // Just spit out the original file if all the options are default - return new Tuple(originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); + return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); } //ImageSize? originalImageSize = GetSavedImageSize(originalImagePath, dateModified); @@ -241,15 +238,15 @@ namespace Emby.Drawing // return new ValueTuple(originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); //} - var newSize = ImageHelper.GetNewImageSize(options, null); - var quality = options.Quality; + ImageSize newSize = ImageHelper.GetNewImageSize(options, null); + int quality = options.Quality; - var outputFormat = GetOutputFormat(options.SupportedOutputFormats, requiresTransparency); - var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, outputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.Blur, options.BackgroundColor, options.ForegroundLayer); + ImageFormat outputFormat = GetOutputFormat(options.SupportedOutputFormats, requiresTransparency); + string cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, outputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.Blur, options.BackgroundColor, options.ForegroundLayer); CheckDisposed(); - var lockInfo = GetLock(cacheFilePath); + LockInfo lockInfo = GetLock(cacheFilePath); await lockInfo.Lock.WaitAsync().ConfigureAwait(false); @@ -262,17 +259,15 @@ namespace Emby.Drawing options.CropWhiteSpace = false; } - var resultPath = _imageEncoder.EncodeImage(originalImagePath, dateModified, cacheFilePath, autoOrient, orientation, quality, options, outputFormat); + string resultPath = _imageEncoder.EncodeImage(originalImagePath, dateModified, cacheFilePath, autoOrient, orientation, quality, options, outputFormat); if (string.Equals(resultPath, originalImagePath, StringComparison.OrdinalIgnoreCase)) { - return new Tuple(originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); + return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); } - - return new Tuple(cacheFilePath, GetMimeType(outputFormat, cacheFilePath), _fileSystem.GetLastWriteTimeUtc(cacheFilePath)); } - return new Tuple(cacheFilePath, GetMimeType(outputFormat, cacheFilePath), _fileSystem.GetLastWriteTimeUtc(cacheFilePath)); + return (cacheFilePath, GetMimeType(outputFormat, cacheFilePath), _fileSystem.GetLastWriteTimeUtc(cacheFilePath)); } catch (ArgumentOutOfRangeException ex) { @@ -281,7 +276,7 @@ namespace Emby.Drawing _logger.LogError(ex, "Error encoding image"); #endif // Just spit out the original file if all the options are default - return new Tuple(originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); + return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); } catch (Exception ex) { @@ -289,7 +284,7 @@ namespace Emby.Drawing _logger.LogError(ex, "Error encoding image"); // Just spit out the original file if all the options are default - return new Tuple(originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); + return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); } finally { @@ -325,42 +320,17 @@ namespace Emby.Drawing return ImageFormat.Jpg; } - private void CopyFile(string src, string destination) - { - try - { - _fileSystem.CopyFile(src, destination, true); - } - catch - { - - } - } - private string GetMimeType(ImageFormat format, string path) { - if (format == ImageFormat.Bmp) + switch(format) { - return MimeTypes.GetMimeType("i.bmp"); + case ImageFormat.Bmp: return MimeTypes.GetMimeType("i.bmp"); + case ImageFormat.Gif: return MimeTypes.GetMimeType("i.gif"); + case ImageFormat.Jpg: return MimeTypes.GetMimeType("i.jpg"); + case ImageFormat.Png: return MimeTypes.GetMimeType("i.png"); + case ImageFormat.Webp: return MimeTypes.GetMimeType("i.webp"); + default: return MimeTypes.GetMimeType(path); } - if (format == ImageFormat.Gif) - { - return MimeTypes.GetMimeType("i.gif"); - } - if (format == ImageFormat.Jpg) - { - return MimeTypes.GetMimeType("i.jpg"); - } - if (format == ImageFormat.Png) - { - return MimeTypes.GetMimeType("i.png"); - } - if (format == ImageFormat.Webp) - { - return MimeTypes.GetMimeType("i.webp"); - } - - return MimeTypes.GetMimeType(path); } /// @@ -373,17 +343,12 @@ namespace Emby.Drawing /// private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageFormat format, bool addPlayedIndicator, double percentPlayed, int? unwatchedCount, int? blur, string backgroundColor, string foregroundLayer) { - var filename = originalPath; - - filename += "width=" + outputSize.Width; - - filename += "height=" + outputSize.Height; - - filename += "quality=" + quality; - - filename += "datemodified=" + dateModified.Ticks; - - filename += "f=" + format; + var filename = originalPath + + "width=" + outputSize.Width + + "height=" + outputSize.Height + + "quality=" + quality + + "datemodified=" + dateModified.Ticks + + "f=" + format; if (addPlayedIndicator) { @@ -421,26 +386,20 @@ namespace Emby.Drawing } public ImageSize GetImageSize(BaseItem item, ItemImageInfo info) - { - return GetImageSize(item, info, true); - } + => GetImageSize(item, info, true); public ImageSize GetImageSize(BaseItem item, ItemImageInfo info, bool updateItem) { - var width = info.Width; - var height = info.Height; + int width = info.Width; + int height = info.Height; if (height > 0 && width > 0) { - return new ImageSize - { - Width = width, - Height = height - }; + return new ImageSize(width, height); } - var path = info.Path; - _logger.LogInformation("Getting image size for item {0} {1}", item.GetType().Name, path); + string path = info.Path; + _logger.LogInformation("Getting image size for item {ItemType} {Path}", item.GetType().Name, path); var size = GetImageSize(path); @@ -466,15 +425,11 @@ namespace Emby.Drawing } using (var s = new SKFileStream(path)) - using (var codec = SKCodec.Create(s)) - { - var info = codec.Info; - return new ImageSize - { - Height = info.Height, - Width = info.Width - }; - } + using (var codec = SKCodec.Create(s)) + { + var info = codec.Info; + return new ImageSize(info.Width, info.Height); + } } /// @@ -518,9 +473,9 @@ namespace Emby.Drawing /// item public string GetImageCacheTag(BaseItem item, ItemImageInfo image, IImageEnhancer[] imageEnhancers) { - var originalImagePath = image.Path; - var dateModified = image.DateModified; - var imageType = image.Type; + string originalImagePath = image.Path; + DateTime dateModified = image.DateModified; + ImageType imageType = image.Type; // Optimization if (imageEnhancers.Length == 0) @@ -532,28 +487,28 @@ namespace Emby.Drawing var cacheKeys = imageEnhancers.Select(i => i.GetConfigurationCacheKey(item, imageType)).ToList(); cacheKeys.Add(originalImagePath + dateModified.Ticks); - return string.Join("|", cacheKeys.ToArray()).GetMD5().ToString("N"); + return string.Join("|", cacheKeys).GetMD5().ToString("N"); } - private async Task> GetSupportedImage(string originalImagePath, DateTime dateModified) + private async Task<(string path, DateTime dateModified)> GetSupportedImage(string originalImagePath, DateTime dateModified) { - var inputFormat = (Path.GetExtension(originalImagePath) ?? string.Empty) + var inputFormat = Path.GetExtension(originalImagePath) .TrimStart('.') .Replace("jpeg", "jpg", StringComparison.OrdinalIgnoreCase); // These are just jpg files renamed as tbn if (string.Equals(inputFormat, "tbn", StringComparison.OrdinalIgnoreCase)) { - return new ValueTuple(originalImagePath, dateModified); + return (originalImagePath, dateModified); } if (!_imageEncoder.SupportedInputFormats.Contains(inputFormat, StringComparer.OrdinalIgnoreCase)) { try { - var filename = (originalImagePath + dateModified.Ticks.ToString(UsCulture)).GetMD5().ToString("N"); + string filename = (originalImagePath + dateModified.Ticks.ToString(UsCulture)).GetMD5().ToString("N"); - var cacheExtension = _mediaEncoder().SupportsEncoder("libwebp") ? ".webp" : ".png"; + string cacheExtension = _mediaEncoder().SupportsEncoder("libwebp") ? ".webp" : ".png"; var outputPath = Path.Combine(_appPaths.ImageCachePath, "converted-images", filename + cacheExtension); var file = _fileSystem.GetFileInfo(outputPath); @@ -571,11 +526,11 @@ namespace Emby.Drawing } catch (Exception ex) { - _logger.LogError(ex, "Image conversion failed for {originalImagePath}", originalImagePath); + _logger.LogError(ex, "Image conversion failed for {Path}", originalImagePath); } } - return new ValueTuple(originalImagePath, dateModified); + return (originalImagePath, dateModified); } /// @@ -589,16 +544,17 @@ namespace Emby.Drawing { var enhancers = GetSupportedEnhancers(item, imageType); - var imageInfo = item.GetImageInfo(imageType, imageIndex); + ItemImageInfo imageInfo = item.GetImageInfo(imageType, imageIndex); - var inputImageSupportsTransparency = SupportsTransparency(imageInfo.Path); + bool inputImageSupportsTransparency = SupportsTransparency(imageInfo.Path); var result = await GetEnhancedImage(imageInfo, inputImageSupportsTransparency, item, imageIndex, enhancers, CancellationToken.None); - return result.Item1; + return result.path; } - private async Task> GetEnhancedImage(ItemImageInfo image, + private async Task<(string path, DateTime dateModified, bool transparent)> GetEnhancedImage( + ItemImageInfo image, bool inputImageSupportsTransparency, BaseItem item, int imageIndex, @@ -616,14 +572,14 @@ namespace Emby.Drawing // Enhance if we have enhancers var enhancedImageInfo = await GetEnhancedImageInternal(originalImagePath, item, imageType, imageIndex, enhancers, cacheGuid, cancellationToken).ConfigureAwait(false); - var enhancedImagePath = enhancedImageInfo.Item1; + string enhancedImagePath = enhancedImageInfo.path; // If the path changed update dateModified if (!string.Equals(enhancedImagePath, originalImagePath, StringComparison.OrdinalIgnoreCase)) { - var treatmentRequiresTransparency = enhancedImageInfo.Item2; + var treatmentRequiresTransparency = enhancedImageInfo.transparent; - return new ValueTuple(enhancedImagePath, _fileSystem.GetLastWriteTimeUtc(enhancedImagePath), treatmentRequiresTransparency); + return (enhancedImagePath, _fileSystem.GetLastWriteTimeUtc(enhancedImagePath), treatmentRequiresTransparency); } } catch (Exception ex) @@ -631,7 +587,7 @@ namespace Emby.Drawing _logger.LogError(ex, "Error enhancing image"); } - return new ValueTuple(originalImagePath, dateModified, inputImageSupportsTransparency); + return (originalImagePath, dateModified, inputImageSupportsTransparency); } /// @@ -649,7 +605,8 @@ namespace Emby.Drawing /// or /// item /// - private async Task> GetEnhancedImageInternal(string originalImagePath, + private async Task<(string path, bool transparent)> GetEnhancedImageInternal( + string originalImagePath, BaseItem item, ImageType imageType, int imageIndex, @@ -677,13 +634,13 @@ namespace Emby.Drawing } // All enhanced images are saved as png to allow transparency - var cacheExtension = _imageEncoder.SupportedOutputFormats.Contains(ImageFormat.Webp) ? + string cacheExtension = _imageEncoder.SupportedOutputFormats.Contains(ImageFormat.Webp) ? ".webp" : (treatmentRequiresTransparency ? ".png" : ".jpg"); - var enhancedImagePath = GetCachePath(EnhancedImageCachePath, cacheGuid + cacheExtension); + string enhancedImagePath = GetCachePath(EnhancedImageCachePath, cacheGuid + cacheExtension); - var lockInfo = GetLock(enhancedImagePath); + LockInfo lockInfo = GetLock(enhancedImagePath); await lockInfo.Lock.WaitAsync(cancellationToken).ConfigureAwait(false); @@ -692,14 +649,14 @@ namespace Emby.Drawing // Check again in case of contention if (_fileSystem.FileExists(enhancedImagePath)) { - return new ValueTuple(enhancedImagePath, treatmentRequiresTransparency); + return (enhancedImagePath, treatmentRequiresTransparency); } _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(enhancedImagePath)); await ExecuteImageEnhancers(supportedEnhancers, originalImagePath, enhancedImagePath, item, imageType, imageIndex).ConfigureAwait(false); - return new ValueTuple(enhancedImagePath, treatmentRequiresTransparency); + return (enhancedImagePath, treatmentRequiresTransparency); } finally { @@ -788,18 +745,16 @@ namespace Emby.Drawing var prefix = filename.Substring(0, 1); - path = Path.Combine(path, prefix); - - return Path.Combine(path, filename); + return Path.Combine(path, prefix, filename); } public void CreateImageCollage(ImageCollageOptions options) { - _logger.LogInformation("Creating image collage and saving to {0}", options.OutputPath); + _logger.LogInformation("Creating image collage and saving to {Path}", options.OutputPath); _imageEncoder.CreateImageCollage(options); - _logger.LogInformation("Completed creation of image collage and saved to {0}", options.OutputPath); + _logger.LogInformation("Completed creation of image collage and saved to {Path}", options.OutputPath); } public IImageEnhancer[] GetSupportedEnhancers(BaseItem item, ImageType imageType) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 3ed31e7bd4..476c61ce3a 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1050,7 +1050,7 @@ namespace Emby.Server.Implementations private IImageProcessor GetImageProcessor() { - return new ImageProcessor(LoggerFactory.CreateLogger("ImageProcessor"), ServerConfigurationManager.ApplicationPaths, FileSystemManager, JsonSerializer, ImageEncoder, () => LibraryManager, TimerFactory, () => MediaEncoder); + return new ImageProcessor(LoggerFactory.CreateLogger("ImageProcessor"), ServerConfigurationManager.ApplicationPaths, FileSystemManager, ImageEncoder, () => LibraryManager, () => MediaEncoder); } protected virtual FFMpegInstallInfo GetFfmpegInstallInfo() diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index d077616199..fccc60176e 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -103,7 +103,7 @@ namespace Jellyfin.Server { appHost.Init(); - appHost.ImageProcessor.ImageEncoder = getImageEncoder(_logger, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo, appHost.LocalizationManager); + appHost.ImageProcessor.ImageEncoder = GetImageEncoder(_logger, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo, appHost.LocalizationManager); _logger.LogInformation("Running startup tasks"); @@ -256,13 +256,12 @@ namespace Jellyfin.Server } } - public static IImageEncoder getImageEncoder( + public static IImageEncoder GetImageEncoder( ILogger logger, IFileSystem fileSystem, StartupOptions startupOptions, Func httpClient, IApplicationPaths appPaths, - IEnvironmentInfo environment, ILocalizationManager localizationManager) { try diff --git a/MediaBrowser.Controller/Drawing/IImageProcessor.cs b/MediaBrowser.Controller/Drawing/IImageProcessor.cs index 2cafc9ec19..7e6e0127fb 100644 --- a/MediaBrowser.Controller/Drawing/IImageProcessor.cs +++ b/MediaBrowser.Controller/Drawing/IImageProcessor.cs @@ -82,7 +82,7 @@ namespace MediaBrowser.Controller.Drawing /// /// The options. /// Task. - Task> ProcessImage(ImageProcessingOptions options); + Task<(string path, string mimeType, DateTime dateModified)> ProcessImage(ImageProcessingOptions options); /// /// Gets the enhanced image. From ca910325f3a0d8ce0cf71f2553d395e797b8c57d Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sun, 20 Jan 2019 14:25:13 +0100 Subject: [PATCH 2/7] Remove unneeded fields --- Emby.Drawing/PercentPlayedDrawer.cs | 4 ++-- Emby.Drawing/PlayedIndicatorDrawer.cs | 18 ++---------------- Emby.Drawing/SkiaEncoder.cs | 11 ++++------- Emby.Drawing/UnplayedCountIndicator.cs | 18 ++---------------- Jellyfin.Server/Program.cs | 5 ++--- 5 files changed, 12 insertions(+), 44 deletions(-) diff --git a/Emby.Drawing/PercentPlayedDrawer.cs b/Emby.Drawing/PercentPlayedDrawer.cs index 3ab5f34bc3..52b4329e1e 100644 --- a/Emby.Drawing/PercentPlayedDrawer.cs +++ b/Emby.Drawing/PercentPlayedDrawer.cs @@ -4,11 +4,11 @@ using SkiaSharp; namespace Emby.Drawing { - public class PercentPlayedDrawer + public static class PercentPlayedDrawer { private const int IndicatorHeight = 8; - public void Process(SKCanvas canvas, ImageSize imageSize, double percent) + public static void Process(SKCanvas canvas, ImageSize imageSize, double percent) { using (var paint = new SKPaint()) { diff --git a/Emby.Drawing/PlayedIndicatorDrawer.cs b/Emby.Drawing/PlayedIndicatorDrawer.cs index 92a164a5fe..a82398fa53 100644 --- a/Emby.Drawing/PlayedIndicatorDrawer.cs +++ b/Emby.Drawing/PlayedIndicatorDrawer.cs @@ -1,27 +1,13 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Net; using MediaBrowser.Model.Drawing; -using MediaBrowser.Model.IO; using SkiaSharp; namespace Emby.Drawing { - public class PlayedIndicatorDrawer + public static class PlayedIndicatorDrawer { private const int OffsetFromTopRightCorner = 38; - private readonly IApplicationPaths _appPaths; - private readonly IHttpClient _iHttpClient; - private readonly IFileSystem _fileSystem; - - public PlayedIndicatorDrawer(IApplicationPaths appPaths, IHttpClient iHttpClient, IFileSystem fileSystem) - { - _appPaths = appPaths; - _iHttpClient = iHttpClient; - _fileSystem = fileSystem; - } - - public void DrawPlayedIndicator(SKCanvas canvas, ImageSize imageSize) + public static void DrawPlayedIndicator(SKCanvas canvas, ImageSize imageSize) { var x = imageSize.Width - OffsetFromTopRightCorner; diff --git a/Emby.Drawing/SkiaEncoder.cs b/Emby.Drawing/SkiaEncoder.cs index dc571f4a04..601ab18958 100644 --- a/Emby.Drawing/SkiaEncoder.cs +++ b/Emby.Drawing/SkiaEncoder.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using System.Reflection; using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Net; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Extensions; using MediaBrowser.Model.Drawing; @@ -19,15 +18,13 @@ namespace Emby.Drawing { private readonly ILogger _logger; private static IApplicationPaths _appPaths; - private readonly Func _httpClientFactory; private readonly IFileSystem _fileSystem; private static ILocalizationManager _localizationManager; - public SkiaEncoder(ILogger logger, IApplicationPaths appPaths, Func httpClientFactory, IFileSystem fileSystem, ILocalizationManager localizationManager) + public SkiaEncoder(ILogger logger, IApplicationPaths appPaths, IFileSystem fileSystem, ILocalizationManager localizationManager) { _logger = logger; _appPaths = appPaths; - _httpClientFactory = httpClientFactory; _fileSystem = fileSystem; _localizationManager = localizationManager; @@ -636,16 +633,16 @@ namespace Emby.Drawing if (options.AddPlayedIndicator) { - new PlayedIndicatorDrawer(_appPaths, _httpClientFactory(), _fileSystem).DrawPlayedIndicator(canvas, currentImageSize); + PlayedIndicatorDrawer.DrawPlayedIndicator(canvas, currentImageSize); } else if (options.UnplayedCount.HasValue) { - new UnplayedCountIndicator(_appPaths, _httpClientFactory(), _fileSystem).DrawUnplayedCountIndicator(canvas, currentImageSize, options.UnplayedCount.Value); + UnplayedCountIndicator.DrawUnplayedCountIndicator(canvas, currentImageSize, options.UnplayedCount.Value); } if (options.PercentPlayed > 0) { - new PercentPlayedDrawer().Process(canvas, currentImageSize, options.PercentPlayed); + PercentPlayedDrawer.Process(canvas, currentImageSize, options.PercentPlayed); } } catch (Exception ex) diff --git a/Emby.Drawing/UnplayedCountIndicator.cs b/Emby.Drawing/UnplayedCountIndicator.cs index caa3e465be..16c084a21b 100644 --- a/Emby.Drawing/UnplayedCountIndicator.cs +++ b/Emby.Drawing/UnplayedCountIndicator.cs @@ -1,28 +1,14 @@ using System.Globalization; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Net; using MediaBrowser.Model.Drawing; -using MediaBrowser.Model.IO; using SkiaSharp; namespace Emby.Drawing { - public class UnplayedCountIndicator + public static class UnplayedCountIndicator { private const int OffsetFromTopRightCorner = 38; - private readonly IApplicationPaths _appPaths; - private readonly IHttpClient _iHttpClient; - private readonly IFileSystem _fileSystem; - - public UnplayedCountIndicator(IApplicationPaths appPaths, IHttpClient iHttpClient, IFileSystem fileSystem) - { - _appPaths = appPaths; - _iHttpClient = iHttpClient; - _fileSystem = fileSystem; - } - - public void DrawUnplayedCountIndicator(SKCanvas canvas, ImageSize imageSize, int count) + public static void DrawUnplayedCountIndicator(SKCanvas canvas, ImageSize imageSize, int count) { var x = imageSize.Width - OffsetFromTopRightCorner; var text = count.ToString(CultureInfo.InvariantCulture); diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index fccc60176e..c7d14f0670 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -103,7 +103,7 @@ namespace Jellyfin.Server { appHost.Init(); - appHost.ImageProcessor.ImageEncoder = GetImageEncoder(_logger, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo, appHost.LocalizationManager); + appHost.ImageProcessor.ImageEncoder = GetImageEncoder(_logger, fileSystem, options, appPaths, appHost.LocalizationManager); _logger.LogInformation("Running startup tasks"); @@ -260,13 +260,12 @@ namespace Jellyfin.Server ILogger logger, IFileSystem fileSystem, StartupOptions startupOptions, - Func httpClient, IApplicationPaths appPaths, ILocalizationManager localizationManager) { try { - return new SkiaEncoder(logger, appPaths, httpClient, fileSystem, localizationManager); + return new SkiaEncoder(logger, appPaths, fileSystem, localizationManager); } catch (Exception ex) { From 7e4cc9f513ff583e7a8ecf596e61d33dd9ce41d9 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sun, 20 Jan 2019 14:39:05 +0100 Subject: [PATCH 3/7] Touchup --- Emby.Drawing/ImageProcessor.cs | 10 +--------- Jellyfin.Server/Program.cs | 2 -- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index 625e566600..275b6354e2 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -230,14 +230,6 @@ namespace Emby.Drawing return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); } - //ImageSize? originalImageSize = GetSavedImageSize(originalImagePath, dateModified); - //if (originalImageSize.HasValue && options.HasDefaultOptions(originalImagePath, originalImageSize.Value) && !autoOrient) - //{ - // // Just spit out the original file if all the options are default - // _logger.LogInformation("Returning original image {0}", originalImagePath); - // return new ValueTuple(originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); - //} - ImageSize newSize = ImageHelper.GetNewImageSize(options, null); int quality = options.Quality; @@ -674,7 +666,7 @@ namespace Emby.Drawing /// Type of the image. /// Index of the image. /// Task{EnhancedImage}. - private async Task ExecuteImageEnhancers(IEnumerable imageEnhancers, string inputPath, string outputPath, BaseItem item, ImageType imageType, int imageIndex) + private static async Task ExecuteImageEnhancers(IEnumerable imageEnhancers, string inputPath, string outputPath, BaseItem item, ImageType imageType, int imageIndex) { // Run the enhancers sequentially in order of priority foreach (var enhancer in imageEnhancers) diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index c7d14f0670..2441cebd01 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -14,11 +14,9 @@ using Emby.Server.Implementations.EnvironmentInfo; using Emby.Server.Implementations.IO; using Emby.Server.Implementations.Networking; using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Net; using MediaBrowser.Controller.Drawing; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.IO; -using MediaBrowser.Model.System; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Serilog; From 7469ed4e6ef53086f35050c8fa89eb915aa119fd Mon Sep 17 00:00:00 2001 From: Andrew Rabert <6550543+nvllsvm@users.noreply.github.com> Date: Sun, 20 Jan 2019 20:46:00 -0500 Subject: [PATCH 4/7] Update logger position --- Emby.Drawing/ImageProcessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index 5fee6e5901..a6a01b7dec 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -58,8 +58,8 @@ namespace Emby.Drawing Func libraryManager, Func mediaEncoder) { - _appPaths = appPaths; _logger = loggerFactory.CreateLogger(nameof(ImageProcessor)); + _appPaths = appPaths; _fileSystem = fileSystem; _imageEncoder = imageEncoder; _libraryManager = libraryManager; From 1cf1e9bfa1339e30fb850224230d9d89a1956d88 Mon Sep 17 00:00:00 2001 From: Andrew Rabert <6550543+nvllsvm@users.noreply.github.com> Date: Sun, 20 Jan 2019 20:46:40 -0500 Subject: [PATCH 5/7] Update appPaths position --- Emby.Drawing/ImageProcessor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index a6a01b7dec..5f70070ecc 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -59,11 +59,12 @@ namespace Emby.Drawing Func mediaEncoder) { _logger = loggerFactory.CreateLogger(nameof(ImageProcessor)); - _appPaths = appPaths; _fileSystem = fileSystem; _imageEncoder = imageEncoder; _libraryManager = libraryManager; _mediaEncoder = mediaEncoder; + _appPaths = appPaths; + ImageEnhancers = Array.Empty(); ImageHelper.ImageProcessor = this; From 6a5488c65142fe5532177ea52a2a98433cd70420 Mon Sep 17 00:00:00 2001 From: Andrew Rabert <6550543+nvllsvm@users.noreply.github.com> Date: Sun, 20 Jan 2019 20:47:02 -0500 Subject: [PATCH 6/7] Formatting --- Emby.Drawing/ImageProcessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index 5f70070ecc..c750b60e2b 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -65,8 +65,8 @@ namespace Emby.Drawing _mediaEncoder = mediaEncoder; _appPaths = appPaths; - ImageEnhancers = Array.Empty(); + ImageHelper.ImageProcessor = this; } From 7327bb91a3bffd1631ffc7368d82d05b286a7f4b Mon Sep 17 00:00:00 2001 From: Andrew Rabert <6550543+nvllsvm@users.noreply.github.com> Date: Sun, 20 Jan 2019 20:48:24 -0500 Subject: [PATCH 7/7] Fix func name --- Jellyfin.Server/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 810bf9446d..0510548b56 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -254,7 +254,7 @@ namespace Jellyfin.Server } } - public static IImageEncoder getImageEncoder( + public static IImageEncoder GetImageEncoder( IFileSystem fileSystem, IApplicationPaths appPaths, ILocalizationManager localizationManager)