diff options
| author | Bond_009 <bond.009@outlook.com> | 2019-01-26 13:16:47 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2019-01-26 13:16:47 +0100 |
| commit | 883575893b3f4a4224f920e8c143a9edefca13e4 (patch) | |
| tree | 34de1fd8fb3735835fb30dc634a7cea9088521aa /Emby.Drawing | |
| parent | d1a0497f55c7f41fe9f01bbed328967e381fd394 (diff) | |
Change image dimentions from double to int
Rename ImageSize -> ImageDimensions
Diffstat (limited to 'Emby.Drawing')
| -rw-r--r-- | Emby.Drawing/ImageProcessor.cs | 40 | ||||
| -rw-r--r-- | Emby.Drawing/NullImageEncoder.cs | 2 | ||||
| -rw-r--r-- | Emby.Drawing/PercentPlayedDrawer.cs | 4 | ||||
| -rw-r--r-- | Emby.Drawing/PlayedIndicatorDrawer.cs | 2 | ||||
| -rw-r--r-- | Emby.Drawing/SkiaEncoder.cs | 16 | ||||
| -rw-r--r-- | Emby.Drawing/UnplayedCountIndicator.cs | 2 |
6 files changed, 24 insertions, 42 deletions
diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index c750b60e2..8ac2b9b27 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -18,7 +18,6 @@ using MediaBrowser.Model.Extensions; using MediaBrowser.Model.IO; using MediaBrowser.Model.Net; using Microsoft.Extensions.Logging; -using SkiaSharp; namespace Emby.Drawing { @@ -66,7 +65,7 @@ namespace Emby.Drawing _appPaths = appPaths; ImageEnhancers = Array.Empty<IImageEnhancer>(); - + ImageHelper.ImageProcessor = this; } @@ -168,10 +167,10 @@ namespace Emby.Drawing string originalImagePath = originalImage.Path; DateTime dateModified = originalImage.DateModified; - ImageSize? originalImageSize = null; + ImageDimensions? originalImageSize = null; if (originalImage.Width > 0 && originalImage.Height > 0) { - originalImageSize = new ImageSize(originalImage.Width, originalImage.Height); + originalImageSize = new ImageDimensions(originalImage.Width, originalImage.Height); } if (!_imageEncoder.SupportsImageEncoding) @@ -231,7 +230,7 @@ namespace Emby.Drawing return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); } - ImageSize newSize = ImageHelper.GetNewImageSize(options, null); + ImageDimensions newSize = ImageHelper.GetNewImageSize(options, null); int quality = options.Quality; ImageFormat outputFormat = GetOutputFormat(options.SupportedOutputFormats, requiresTransparency); @@ -334,7 +333,7 @@ namespace Emby.Drawing /// <summary> /// Gets the cache file path based on a set of parameters /// </summary> - 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) + private string GetCacheFilePath(string originalPath, ImageDimensions outputSize, int quality, DateTime dateModified, ImageFormat format, bool addPlayedIndicator, double percentPlayed, int? unwatchedCount, int? blur, string backgroundColor, string foregroundLayer) { var filename = originalPath + "width=" + outputSize.Width @@ -378,26 +377,25 @@ namespace Emby.Drawing return GetCachePath(ResizedImageCachePath, filename, "." + format.ToString().ToLower()); } - public ImageSize GetImageSize(BaseItem item, ItemImageInfo info) + public ImageDimensions GetImageSize(BaseItem item, ItemImageInfo info) => GetImageSize(item, info, true); - public ImageSize GetImageSize(BaseItem item, ItemImageInfo info, bool updateItem) + public ImageDimensions GetImageSize(BaseItem item, ItemImageInfo info, bool updateItem) { int width = info.Width; int height = info.Height; if (height > 0 && width > 0) { - return new ImageSize(width, height); + return new ImageDimensions(width, height); } string path = info.Path; _logger.LogInformation("Getting image size for item {ItemType} {Path}", item.GetType().Name, path); - var size = GetImageSize(path); - - info.Height = Convert.ToInt32(size.Height); - info.Width = Convert.ToInt32(size.Width); + ImageDimensions size = GetImageSize(path); + info.Width = size.Width; + info.Height = size.Height; if (updateItem) { @@ -410,20 +408,8 @@ namespace Emby.Drawing /// <summary> /// Gets the size of the image. /// </summary> - public ImageSize GetImageSize(string path) - { - if (string.IsNullOrEmpty(path)) - { - throw new ArgumentNullException(nameof(path)); - } - - using (var s = new SKFileStream(path)) - using (var codec = SKCodec.Create(s)) - { - var info = codec.Info; - return new ImageSize(info.Width, info.Height); - } - } + public ImageDimensions GetImageSize(string path) + => _imageEncoder.GetImageSize(path); /// <summary> /// Gets the image cache tag. diff --git a/Emby.Drawing/NullImageEncoder.cs b/Emby.Drawing/NullImageEncoder.cs index e6f205a1f..14f0424ac 100644 --- a/Emby.Drawing/NullImageEncoder.cs +++ b/Emby.Drawing/NullImageEncoder.cs @@ -37,7 +37,7 @@ namespace Emby.Drawing public bool SupportsImageEncoding => false; - public ImageSize GetImageSize(string path) + public ImageDimensions GetImageSize(string path) { throw new NotImplementedException(); } diff --git a/Emby.Drawing/PercentPlayedDrawer.cs b/Emby.Drawing/PercentPlayedDrawer.cs index 52b4329e1..3ce46bc12 100644 --- a/Emby.Drawing/PercentPlayedDrawer.cs +++ b/Emby.Drawing/PercentPlayedDrawer.cs @@ -8,7 +8,7 @@ namespace Emby.Drawing { private const int IndicatorHeight = 8; - public static void Process(SKCanvas canvas, ImageSize imageSize, double percent) + public static void Process(SKCanvas canvas, ImageDimensions imageSize, double percent) { using (var paint = new SKPaint()) { @@ -24,7 +24,7 @@ namespace Emby.Drawing foregroundWidth /= 100; paint.Color = SKColor.Parse("#FF52B54B"); - canvas.DrawRect(SKRect.Create(0, (float)endY - IndicatorHeight, Convert.ToInt32(Math.Round(foregroundWidth)), (float)endY), paint); + canvas.DrawRect(SKRect.Create(0, (float)endY - IndicatorHeight, Convert.ToInt32(foregroundWidth), (float)endY), paint); } } } diff --git a/Emby.Drawing/PlayedIndicatorDrawer.cs b/Emby.Drawing/PlayedIndicatorDrawer.cs index a82398fa5..38b5edc92 100644 --- a/Emby.Drawing/PlayedIndicatorDrawer.cs +++ b/Emby.Drawing/PlayedIndicatorDrawer.cs @@ -7,7 +7,7 @@ namespace Emby.Drawing { private const int OffsetFromTopRightCorner = 38; - public static void DrawPlayedIndicator(SKCanvas canvas, ImageSize imageSize) + public static void DrawPlayedIndicator(SKCanvas canvas, ImageDimensions imageSize) { var x = imageSize.Width - OffsetFromTopRightCorner; diff --git a/Emby.Drawing/SkiaEncoder.cs b/Emby.Drawing/SkiaEncoder.cs index 9883b3cca..aae10f6cc 100644 --- a/Emby.Drawing/SkiaEncoder.cs +++ b/Emby.Drawing/SkiaEncoder.cs @@ -168,18 +168,14 @@ namespace Emby.Drawing } } - public ImageSize GetImageSize(string path) + public ImageDimensions GetImageSize(string path) { using (var s = new SKFileStream(path)) using (var codec = SKCodec.Create(s)) { var info = codec.Info; - return new ImageSize - { - Width = info.Width, - Height = info.Height - }; + return new ImageDimensions(info.Width, info.Height); } } @@ -513,7 +509,7 @@ namespace Emby.Drawing //_logger.LogInformation("Color type {0}", bitmap.Info.ColorType); - var originalImageSize = new ImageSize(bitmap.Width, bitmap.Height); + var originalImageSize = new ImageDimensions(bitmap.Width, bitmap.Height); if (!options.CropWhiteSpace && options.HasDefaultOptions(inputPath, originalImageSize) && !autoOrient) { @@ -523,8 +519,8 @@ namespace Emby.Drawing var newImageSize = ImageHelper.GetNewImageSize(options, originalImageSize); - var width = Convert.ToInt32(Math.Round(newImageSize.Width)); - var height = Convert.ToInt32(Math.Round(newImageSize.Height)); + var width = newImageSize.Width; + var height = newImageSize.Height; using (var resizedBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType)) { @@ -626,7 +622,7 @@ namespace Emby.Drawing { try { - var currentImageSize = new ImageSize(imageWidth, imageHeight); + var currentImageSize = new ImageDimensions(imageWidth, imageHeight); if (options.AddPlayedIndicator) { diff --git a/Emby.Drawing/UnplayedCountIndicator.cs b/Emby.Drawing/UnplayedCountIndicator.cs index 16c084a21..4d0cc9d40 100644 --- a/Emby.Drawing/UnplayedCountIndicator.cs +++ b/Emby.Drawing/UnplayedCountIndicator.cs @@ -8,7 +8,7 @@ namespace Emby.Drawing { private const int OffsetFromTopRightCorner = 38; - public static void DrawUnplayedCountIndicator(SKCanvas canvas, ImageSize imageSize, int count) + public static void DrawUnplayedCountIndicator(SKCanvas canvas, ImageDimensions imageSize, int count) { var x = imageSize.Width - OffsetFromTopRightCorner; var text = count.ToString(CultureInfo.InvariantCulture); |
