Browse Source

Change image dimentions from double to int

Rename ImageSize -> ImageDimensions
Bond_009 6 years ago
parent
commit
883575893b

+ 7 - 12
Emby.Dlna/Didl/DidlBuilder.cs

@@ -1088,8 +1088,8 @@ namespace Emby.Dlna.Didl
             //{
             //{
             //    var size = _imageProcessor.GetImageSize(imageInfo);
             //    var size = _imageProcessor.GetImageSize(imageInfo);
 
 
-            //    width = Convert.ToInt32(size.Width);
-            //    height = Convert.ToInt32(size.Height);
+            //    width = size.Width;
+            //    height = size.Height;
             //}
             //}
             //catch
             //catch
             //{
             //{
@@ -1162,8 +1162,7 @@ namespace Emby.Dlna.Didl
                 info.ImageTag,
                 info.ImageTag,
                 format,
                 format,
                 maxWidth.ToString(CultureInfo.InvariantCulture),
                 maxWidth.ToString(CultureInfo.InvariantCulture),
-                maxHeight.ToString(CultureInfo.InvariantCulture)
-                );
+                maxHeight.ToString(CultureInfo.InvariantCulture));
 
 
             var width = info.Width;
             var width = info.Width;
             var height = info.Height;
             var height = info.Height;
@@ -1172,15 +1171,11 @@ namespace Emby.Dlna.Didl
 
 
             if (width.HasValue && height.HasValue)
             if (width.HasValue && height.HasValue)
             {
             {
-                var newSize = DrawingUtils.Resize(new ImageSize
-                {
-                    Height = height.Value,
-                    Width = width.Value
-
-                }, 0, 0, maxWidth, maxHeight);
+                var newSize = DrawingUtils.Resize(
+                        new ImageDimensions(width.Value, height.Value), 0, 0, maxWidth, maxHeight);
 
 
-                width = Convert.ToInt32(newSize.Width);
-                height = Convert.ToInt32(newSize.Height);
+                width = newSize.Width;
+                height = newSize.Height;
 
 
                 var normalizedFormat = format
                 var normalizedFormat = format
                     .Replace("jpeg", "jpg", StringComparison.OrdinalIgnoreCase);
                     .Replace("jpeg", "jpg", StringComparison.OrdinalIgnoreCase);

+ 13 - 27
Emby.Drawing/ImageProcessor.cs

@@ -18,7 +18,6 @@ using MediaBrowser.Model.Extensions;
 using MediaBrowser.Model.IO;
 using MediaBrowser.Model.IO;
 using MediaBrowser.Model.Net;
 using MediaBrowser.Model.Net;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Logging;
-using SkiaSharp;
 
 
 namespace Emby.Drawing
 namespace Emby.Drawing
 {
 {
@@ -66,7 +65,7 @@ namespace Emby.Drawing
             _appPaths = appPaths;
             _appPaths = appPaths;
 
 
             ImageEnhancers = Array.Empty<IImageEnhancer>();
             ImageEnhancers = Array.Empty<IImageEnhancer>();
-            
+
             ImageHelper.ImageProcessor = this;
             ImageHelper.ImageProcessor = this;
         }
         }
 
 
@@ -168,10 +167,10 @@ namespace Emby.Drawing
 
 
             string originalImagePath = originalImage.Path;
             string originalImagePath = originalImage.Path;
             DateTime dateModified = originalImage.DateModified;
             DateTime dateModified = originalImage.DateModified;
-            ImageSize? originalImageSize = null;
+            ImageDimensions? originalImageSize = null;
             if (originalImage.Width > 0 && originalImage.Height > 0)
             if (originalImage.Width > 0 && originalImage.Height > 0)
             {
             {
-                originalImageSize = new ImageSize(originalImage.Width, originalImage.Height);
+                originalImageSize = new ImageDimensions(originalImage.Width, originalImage.Height);
             }
             }
 
 
             if (!_imageEncoder.SupportsImageEncoding)
             if (!_imageEncoder.SupportsImageEncoding)
@@ -231,7 +230,7 @@ namespace Emby.Drawing
                 return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified);
                 return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified);
             }
             }
 
 
-            ImageSize newSize = ImageHelper.GetNewImageSize(options, null);
+            ImageDimensions newSize = ImageHelper.GetNewImageSize(options, null);
             int quality = options.Quality;
             int quality = options.Quality;
 
 
             ImageFormat outputFormat = GetOutputFormat(options.SupportedOutputFormats, requiresTransparency);
             ImageFormat outputFormat = GetOutputFormat(options.SupportedOutputFormats, requiresTransparency);
@@ -334,7 +333,7 @@ namespace Emby.Drawing
         /// <summary>
         /// <summary>
         /// Gets the cache file path based on a set of parameters
         /// Gets the cache file path based on a set of parameters
         /// </summary>
         /// </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
             var filename = originalPath
                 + "width=" + outputSize.Width
                 + "width=" + outputSize.Width
@@ -378,26 +377,25 @@ namespace Emby.Drawing
             return GetCachePath(ResizedImageCachePath, filename, "." + format.ToString().ToLower());
             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);
             => 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 width = info.Width;
             int height = info.Height;
             int height = info.Height;
 
 
             if (height > 0 && width > 0)
             if (height > 0 && width > 0)
             {
             {
-                return new ImageSize(width, height);
+                return new ImageDimensions(width, height);
             }
             }
 
 
             string path = info.Path;
             string path = info.Path;
             _logger.LogInformation("Getting image size for item {ItemType} {Path}", item.GetType().Name, 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)
             if (updateItem)
             {
             {
@@ -410,20 +408,8 @@ namespace Emby.Drawing
         /// <summary>
         /// <summary>
         /// Gets the size of the image.
         /// Gets the size of the image.
         /// </summary>
         /// </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>
         /// <summary>
         /// Gets the image cache tag.
         /// Gets the image cache tag.

+ 1 - 1
Emby.Drawing/NullImageEncoder.cs

@@ -37,7 +37,7 @@ namespace Emby.Drawing
 
 
         public bool SupportsImageEncoding => false;
         public bool SupportsImageEncoding => false;
 
 
-        public ImageSize GetImageSize(string path)
+        public ImageDimensions GetImageSize(string path)
         {
         {
             throw new NotImplementedException();
             throw new NotImplementedException();
         }
         }

+ 2 - 2
Emby.Drawing/PercentPlayedDrawer.cs

@@ -8,7 +8,7 @@ namespace Emby.Drawing
     {
     {
         private const int IndicatorHeight = 8;
         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())
             using (var paint = new SKPaint())
             {
             {
@@ -24,7 +24,7 @@ namespace Emby.Drawing
                 foregroundWidth /= 100;
                 foregroundWidth /= 100;
 
 
                 paint.Color = SKColor.Parse("#FF52B54B");
                 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);
             }
             }
         }
         }
     }
     }

+ 1 - 1
Emby.Drawing/PlayedIndicatorDrawer.cs

@@ -7,7 +7,7 @@ namespace Emby.Drawing
     {
     {
         private const int OffsetFromTopRightCorner = 38;
         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;
             var x = imageSize.Width - OffsetFromTopRightCorner;
 
 

+ 6 - 10
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 s = new SKFileStream(path))
             using (var codec = SKCodec.Create(s))
             using (var codec = SKCodec.Create(s))
             {
             {
                 var info = codec.Info;
                 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);
                 //_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)
                 if (!options.CropWhiteSpace && options.HasDefaultOptions(inputPath, originalImageSize) && !autoOrient)
                 {
                 {
@@ -523,8 +519,8 @@ namespace Emby.Drawing
 
 
                 var newImageSize = ImageHelper.GetNewImageSize(options, originalImageSize);
                 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))
                 using (var resizedBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType))
                 {
                 {
@@ -626,7 +622,7 @@ namespace Emby.Drawing
         {
         {
             try
             try
             {
             {
-                var currentImageSize = new ImageSize(imageWidth, imageHeight);
+                var currentImageSize = new ImageDimensions(imageWidth, imageHeight);
 
 
                 if (options.AddPlayedIndicator)
                 if (options.AddPlayedIndicator)
                 {
                 {

+ 1 - 1
Emby.Drawing/UnplayedCountIndicator.cs

@@ -8,7 +8,7 @@ namespace Emby.Drawing
     {
     {
         private const int OffsetFromTopRightCorner = 38;
         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 x = imageSize.Width - OffsetFromTopRightCorner;
             var text = count.ToString(CultureInfo.InvariantCulture);
             var text = count.ToString(CultureInfo.InvariantCulture);

+ 2 - 2
Emby.Photos/PhotoProvider.cs

@@ -185,8 +185,8 @@ namespace Emby.Photos
 
 
                     if (size.Width > 0 && size.Height > 0)
                     if (size.Width > 0 && size.Height > 0)
                     {
                     {
-                        item.Width = Convert.ToInt32(size.Width);
-                        item.Height = Convert.ToInt32(size.Height);
+                        item.Width = size.Width;
+                        item.Height = size.Height;
                     }
                     }
                 }
                 }
                 catch (ArgumentException)
                 catch (ArgumentException)

+ 5 - 5
Emby.Server.Implementations/Dto/DtoService.cs

@@ -1428,7 +1428,7 @@ namespace Emby.Server.Implementations.Dto
 
 
             var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary);
             var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary);
 
 
-            ImageSize size;
+            ImageDimensions size;
 
 
             var defaultAspectRatio = item.GetDefaultPrimaryImageAspectRatio();
             var defaultAspectRatio = item.GetDefaultPrimaryImageAspectRatio();
 
 
@@ -1439,9 +1439,9 @@ namespace Emby.Server.Implementations.Dto
                     return defaultAspectRatio;
                     return defaultAspectRatio;
                 }
                 }
 
 
-                double dummyWidth = 200;
-                double dummyHeight = dummyWidth / defaultAspectRatio;
-                size = new ImageSize(dummyWidth, dummyHeight);
+                int dummyWidth = 200;
+                int dummyHeight = Convert.ToInt32(dummyWidth / defaultAspectRatio);
+                size = new ImageDimensions(dummyWidth, dummyHeight);
             }
             }
             else
             else
             {
             {
@@ -1481,7 +1481,7 @@ namespace Emby.Server.Implementations.Dto
             var width = size.Width;
             var width = size.Width;
             var height = size.Height;
             var height = size.Height;
 
 
-            if (width.Equals(0) || height.Equals(0))
+            if (width <= 0 || height <= 0)
             {
             {
                 return null;
                 return null;
             }
             }

+ 3 - 4
MediaBrowser.Api/Images/ImageService.cs

@@ -328,10 +328,9 @@ namespace MediaBrowser.Api.Images
                         var fileInfo = _fileSystem.GetFileInfo(info.Path);
                         var fileInfo = _fileSystem.GetFileInfo(info.Path);
                         length = fileInfo.Length;
                         length = fileInfo.Length;
 
 
-                        var size = _imageProcessor.GetImageSize(item, info, true);
-
-                        width = Convert.ToInt32(size.Width);
-                        height = Convert.ToInt32(size.Height);
+                        ImageDimensions size = _imageProcessor.GetImageSize(item, info, true);
+                        width = size.Width;
+                        height = size.Height;
 
 
                         if (width <= 0 || height <= 0)
                         if (width <= 0 || height <= 0)
                         {
                         {

+ 1 - 1
MediaBrowser.Controller/Drawing/IImageEncoder.cs

@@ -44,6 +44,6 @@ namespace MediaBrowser.Controller.Drawing
         /// <value><c>true</c> if [supports image encoding]; otherwise, <c>false</c>.</value>
         /// <value><c>true</c> if [supports image encoding]; otherwise, <c>false</c>.</value>
         bool SupportsImageEncoding { get; }
         bool SupportsImageEncoding { get; }
 
 
-        ImageSize GetImageSize(string path);
+        ImageDimensions GetImageSize(string path);
     }
     }
 }
 }

+ 3 - 3
MediaBrowser.Controller/Drawing/IImageProcessor.cs

@@ -26,16 +26,16 @@ namespace MediaBrowser.Controller.Drawing
         /// <value>The image enhancers.</value>
         /// <value>The image enhancers.</value>
         IImageEnhancer[] ImageEnhancers { get; }
         IImageEnhancer[] ImageEnhancers { get; }
 
 
-        ImageSize GetImageSize(string path);
+        ImageDimensions GetImageSize(string path);
 
 
         /// <summary>
         /// <summary>
         /// Gets the size of the image.
         /// Gets the size of the image.
         /// </summary>
         /// </summary>
         /// <param name="info">The information.</param>
         /// <param name="info">The information.</param>
         /// <returns>ImageSize.</returns>
         /// <returns>ImageSize.</returns>
-        ImageSize GetImageSize(BaseItem item, ItemImageInfo info);
+        ImageDimensions GetImageSize(BaseItem item, ItemImageInfo info);
 
 
-        ImageSize GetImageSize(BaseItem item, ItemImageInfo info, bool updateItem);
+        ImageDimensions GetImageSize(BaseItem item, ItemImageInfo info, bool updateItem);
 
 
         /// <summary>
         /// <summary>
         /// Adds the parts.
         /// Adds the parts.

+ 10 - 9
MediaBrowser.Controller/Drawing/ImageHelper.cs

@@ -1,3 +1,4 @@
+using System;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Model.Drawing;
 using MediaBrowser.Model.Drawing;
 using MediaBrowser.Model.Entities;
 using MediaBrowser.Model.Entities;
@@ -6,7 +7,7 @@ namespace MediaBrowser.Controller.Drawing
 {
 {
     public static class ImageHelper
     public static class ImageHelper
     {
     {
-        public static ImageSize GetNewImageSize(ImageProcessingOptions options, ImageSize? originalImageSize)
+        public static ImageDimensions GetNewImageSize(ImageProcessingOptions options, ImageDimensions? originalImageSize)
         {
         {
             if (originalImageSize.HasValue)
             if (originalImageSize.HasValue)
             {
             {
@@ -20,26 +21,26 @@ namespace MediaBrowser.Controller.Drawing
 
 
         public static IImageProcessor ImageProcessor { get; set; }
         public static IImageProcessor ImageProcessor { get; set; }
 
 
-        private static ImageSize GetSizeEstimate(ImageProcessingOptions options)
+        private static ImageDimensions GetSizeEstimate(ImageProcessingOptions options)
         {
         {
             if (options.Width.HasValue && options.Height.HasValue)
             if (options.Width.HasValue && options.Height.HasValue)
             {
             {
-                return new ImageSize(options.Width.Value, options.Height.Value);
+                return new ImageDimensions(options.Width.Value, options.Height.Value);
             }
             }
 
 
-            var aspect = GetEstimatedAspectRatio(options.Image.Type, options.Item);
+            double aspect = GetEstimatedAspectRatio(options.Image.Type, options.Item);
 
 
-            var width = options.Width ?? options.MaxWidth;
+            int? width = options.Width ?? options.MaxWidth;
 
 
             if (width.HasValue)
             if (width.HasValue)
             {
             {
-                var heightValue = width.Value / aspect;
-                return new ImageSize(width.Value, heightValue);
+                int heightValue = Convert.ToInt32((double)width.Value / aspect);
+                return new ImageDimensions(width.Value, heightValue);
             }
             }
 
 
             var height = options.Height ?? options.MaxHeight ?? 200;
             var height = options.Height ?? options.MaxHeight ?? 200;
-            var widthValue = aspect * height;
-            return new ImageSize(widthValue, height);
+            int widthValue = Convert.ToInt32(aspect * height);
+            return new ImageDimensions(widthValue, height);
         }
         }
 
 
         private static double GetEstimatedAspectRatio(ImageType type, BaseItem item)
         private static double GetEstimatedAspectRatio(ImageType type, BaseItem item)

+ 1 - 1
MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs

@@ -57,7 +57,7 @@ namespace MediaBrowser.Controller.Drawing
                 !MaxHeight.HasValue;
                 !MaxHeight.HasValue;
         }
         }
 
 
-        public bool HasDefaultOptions(string originalImagePath, ImageSize? size)
+        public bool HasDefaultOptions(string originalImagePath, ImageDimensions? size)
         {
         {
             if (!size.HasValue)
             if (!size.HasValue)
             {
             {

+ 1 - 5
MediaBrowser.Controller/Entities/BaseItem.cs

@@ -2235,11 +2235,7 @@ namespace MediaBrowser.Controller.Entities
         /// </exception>
         /// </exception>
         /// <exception cref="ArgumentNullException">item</exception>
         /// <exception cref="ArgumentNullException">item</exception>
         public string GetImagePath(ImageType imageType, int imageIndex)
         public string GetImagePath(ImageType imageType, int imageIndex)
-        {
-            var info = GetImageInfo(imageType, imageIndex);
-
-            return info == null ? null : info.Path;
-        }
+            => GetImageInfo(imageType, imageIndex)?.Path;
 
 
         /// <summary>
         /// <summary>
         /// Gets the image information.
         /// Gets the image information.

+ 2 - 4
MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs

@@ -424,11 +424,9 @@ namespace MediaBrowser.Controller.MediaEncoding
                     if (state.VideoStream != null && state.VideoStream.Width.HasValue)
                     if (state.VideoStream != null && state.VideoStream.Width.HasValue)
                     {
                     {
                         // This is hacky but not sure how to get the exact subtitle resolution
                         // This is hacky but not sure how to get the exact subtitle resolution
-                        double height = state.VideoStream.Width.Value;
-                        height /= 16;
-                        height *= 9;
+                        int height = Convert.ToInt32((double)state.VideoStream.Width.Value / 16.0 * 9.0);
 
 
-                        arg += string.Format(" -canvas_size {0}:{1}", state.VideoStream.Width.Value.ToString(CultureInfo.InvariantCulture), Convert.ToInt32(height).ToString(CultureInfo.InvariantCulture));
+                        arg += string.Format(" -canvas_size {0}:{1}", state.VideoStream.Width.Value.ToString(CultureInfo.InvariantCulture), height.ToString(CultureInfo.InvariantCulture));
                     }
                     }
 
 
                     var subtitlePath = state.SubtitleStream.Path;
                     var subtitlePath = state.SubtitleStream.Path;

+ 4 - 4
MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs

@@ -319,7 +319,7 @@ namespace MediaBrowser.Controller.MediaEncoding
             {
             {
                 if (VideoStream != null && VideoStream.Width.HasValue && VideoStream.Height.HasValue)
                 if (VideoStream != null && VideoStream.Width.HasValue && VideoStream.Height.HasValue)
                 {
                 {
-                    var size = new ImageSize
+                    var size = new ImageDimensions
                     {
                     {
                         Width = VideoStream.Width.Value,
                         Width = VideoStream.Width.Value,
                         Height = VideoStream.Height.Value
                         Height = VideoStream.Height.Value
@@ -331,7 +331,7 @@ namespace MediaBrowser.Controller.MediaEncoding
                         BaseRequest.MaxWidth ?? 0,
                         BaseRequest.MaxWidth ?? 0,
                         BaseRequest.MaxHeight ?? 0);
                         BaseRequest.MaxHeight ?? 0);
 
 
-                    return Convert.ToInt32(newSize.Width);
+                    return newSize.Width;
                 }
                 }
 
 
                 if (!IsVideoRequest)
                 if (!IsVideoRequest)
@@ -349,7 +349,7 @@ namespace MediaBrowser.Controller.MediaEncoding
             {
             {
                 if (VideoStream != null && VideoStream.Width.HasValue && VideoStream.Height.HasValue)
                 if (VideoStream != null && VideoStream.Width.HasValue && VideoStream.Height.HasValue)
                 {
                 {
-                    var size = new ImageSize
+                    var size = new ImageDimensions
                     {
                     {
                         Width = VideoStream.Width.Value,
                         Width = VideoStream.Width.Value,
                         Height = VideoStream.Height.Value
                         Height = VideoStream.Height.Value
@@ -361,7 +361,7 @@ namespace MediaBrowser.Controller.MediaEncoding
                         BaseRequest.MaxWidth ?? 0,
                         BaseRequest.MaxWidth ?? 0,
                         BaseRequest.MaxHeight ?? 0);
                         BaseRequest.MaxHeight ?? 0);
 
 
-                    return Convert.ToInt32(newSize.Height);
+                    return newSize.Height;
                 }
                 }
 
 
                 if (!IsVideoRequest)
                 if (!IsVideoRequest)

+ 1 - 1
MediaBrowser.Controller/Providers/IImageEnhancer.cs

@@ -37,7 +37,7 @@ namespace MediaBrowser.Controller.Providers
         /// <param name="imageIndex">Index of the image.</param>
         /// <param name="imageIndex">Index of the image.</param>
         /// <param name="originalImageSize">Size of the original image.</param>
         /// <param name="originalImageSize">Size of the original image.</param>
         /// <returns>ImageSize.</returns>
         /// <returns>ImageSize.</returns>
-        ImageSize GetEnhancedImageSize(BaseItem item, ImageType imageType, int imageIndex, ImageSize originalImageSize);
+        ImageDimensions GetEnhancedImageSize(BaseItem item, ImageType imageType, int imageIndex, ImageDimensions originalImageSize);
 
 
         EnhancedImageInfo GetEnhancedImageInfo(BaseItem item, string inputFile, ImageType imageType, int imageIndex);
         EnhancedImageInfo GetEnhancedImageInfo(BaseItem item, string inputFile, ImageType imageType, int imageIndex);
 
 

+ 6 - 28
MediaBrowser.Model/Dlna/StreamInfo.cs

@@ -953,22 +953,11 @@ namespace MediaBrowser.Model.Dlna
 
 
                 if (videoStream != null && videoStream.Width.HasValue && videoStream.Height.HasValue)
                 if (videoStream != null && videoStream.Width.HasValue && videoStream.Height.HasValue)
                 {
                 {
-                    var size = new ImageSize
-                    {
-                        Width = videoStream.Width.Value,
-                        Height = videoStream.Height.Value
-                    };
-
-                    double? maxWidth = MaxWidth.HasValue ? (double)MaxWidth.Value : (double?)null;
-                    double? maxHeight = MaxHeight.HasValue ? (double)MaxHeight.Value : (double?)null;
+                    ImageDimensions size = new ImageDimensions(videoStream.Width.Value, videoStream.Height.Value);
 
 
-                    var newSize = DrawingUtils.Resize(size,
-                        0,
-                        0,
-                        maxWidth ?? 0,
-                        maxHeight ?? 0);
+                    size = DrawingUtils.Resize(size, 0, 0, MaxWidth ?? 0, MaxHeight ?? 0);
 
 
-                    return Convert.ToInt32(newSize.Width);
+                    return size.Width;
                 }
                 }
 
 
                 return MaxWidth;
                 return MaxWidth;
@@ -983,22 +972,11 @@ namespace MediaBrowser.Model.Dlna
 
 
                 if (videoStream != null && videoStream.Width.HasValue && videoStream.Height.HasValue)
                 if (videoStream != null && videoStream.Width.HasValue && videoStream.Height.HasValue)
                 {
                 {
-                    var size = new ImageSize
-                    {
-                        Width = videoStream.Width.Value,
-                        Height = videoStream.Height.Value
-                    };
-
-                    double? maxWidth = MaxWidth.HasValue ? (double)MaxWidth.Value : (double?)null;
-                    double? maxHeight = MaxHeight.HasValue ? (double)MaxHeight.Value : (double?)null;
+                    ImageDimensions size = new ImageDimensions(videoStream.Width.Value, videoStream.Height.Value);
 
 
-                    var newSize = DrawingUtils.Resize(size,
-                        0,
-                        0,
-                        maxWidth ?? 0,
-                        maxHeight ?? 0);
+                    size = DrawingUtils.Resize(size, 0, 0, MaxWidth ?? 0, MaxHeight ?? 0);
 
 
-                    return Convert.ToInt32(newSize.Height);
+                    return size.Height;
                 }
                 }
 
 
                 return MaxHeight;
                 return MaxHeight;

+ 15 - 27
MediaBrowser.Model/Drawing/DrawingUtils.cs

@@ -1,3 +1,5 @@
+using System;
+
 namespace MediaBrowser.Model.Drawing
 namespace MediaBrowser.Model.Drawing
 {
 {
     /// <summary>
     /// <summary>
@@ -14,27 +16,25 @@ namespace MediaBrowser.Model.Drawing
         /// <param name="maxWidth">A max fixed width, if desired</param>
         /// <param name="maxWidth">A max fixed width, if desired</param>
         /// <param name="maxHeight">A max fixed height, if desired</param>
         /// <param name="maxHeight">A max fixed height, if desired</param>
         /// <returns>A new size object</returns>
         /// <returns>A new size object</returns>
-        public static ImageSize Resize(ImageSize size,
-            double width,
-            double height,
-            double maxWidth,
-            double maxHeight)
+        public static ImageDimensions Resize(ImageDimensions size,
+            int width,
+            int height,
+            int maxWidth,
+            int maxHeight)
         {
         {
-            double newWidth = size.Width;
-            double newHeight = size.Height;
+            int newWidth = size.Width;
+            int newHeight = size.Height;
 
 
             if (width > 0 && height > 0)
             if (width > 0 && height > 0)
             {
             {
                 newWidth = width;
                 newWidth = width;
                 newHeight = height;
                 newHeight = height;
             }
             }
-
             else if (height > 0)
             else if (height > 0)
             {
             {
                 newWidth = GetNewWidth(newHeight, newWidth, height);
                 newWidth = GetNewWidth(newHeight, newWidth, height);
                 newHeight = height;
                 newHeight = height;
             }
             }
-
             else if (width > 0)
             else if (width > 0)
             {
             {
                 newHeight = GetNewHeight(newHeight, newWidth, width);
                 newHeight = GetNewHeight(newHeight, newWidth, width);
@@ -53,7 +53,7 @@ namespace MediaBrowser.Model.Drawing
                 newWidth = maxWidth;
                 newWidth = maxWidth;
             }
             }
 
 
-            return new ImageSize { Width = newWidth, Height = newHeight };
+            return new ImageDimensions(newWidth, newHeight);
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -62,15 +62,9 @@ namespace MediaBrowser.Model.Drawing
         /// <param name="currentHeight">Height of the current.</param>
         /// <param name="currentHeight">Height of the current.</param>
         /// <param name="currentWidth">Width of the current.</param>
         /// <param name="currentWidth">Width of the current.</param>
         /// <param name="newHeight">The new height.</param>
         /// <param name="newHeight">The new height.</param>
-        /// <returns>System.Double.</returns>
-        private static double GetNewWidth(double currentHeight, double currentWidth, double newHeight)
-        {
-            double scaleFactor = newHeight;
-            scaleFactor /= currentHeight;
-            scaleFactor *= currentWidth;
-
-            return scaleFactor;
-        }
+        /// <returns>the new width</returns>
+        private static int GetNewWidth(int currentHeight, int currentWidth, int newHeight)
+            => Convert.ToInt32((double)newHeight / currentHeight * currentWidth);
 
 
         /// <summary>
         /// <summary>
         /// Gets the new height.
         /// Gets the new height.
@@ -79,13 +73,7 @@ namespace MediaBrowser.Model.Drawing
         /// <param name="currentWidth">Width of the current.</param>
         /// <param name="currentWidth">Width of the current.</param>
         /// <param name="newWidth">The new width.</param>
         /// <param name="newWidth">The new width.</param>
         /// <returns>System.Double.</returns>
         /// <returns>System.Double.</returns>
-        private static double GetNewHeight(double currentHeight, double currentWidth, double newWidth)
-        {
-            double scaleFactor = newWidth;
-            scaleFactor /= currentWidth;
-            scaleFactor *= currentHeight;
-
-            return scaleFactor;
-        }
+        private static int GetNewHeight(int currentHeight, int currentWidth, int newWidth)
+            => Convert.ToInt32((double)newWidth / currentWidth * currentHeight);
     }
     }
 }
 }

+ 7 - 56
MediaBrowser.Model/Drawing/ImageSize.cs

@@ -1,36 +1,23 @@
-using System.Globalization;
-
 namespace MediaBrowser.Model.Drawing
 namespace MediaBrowser.Model.Drawing
 {
 {
     /// <summary>
     /// <summary>
     /// Struct ImageSize
     /// Struct ImageSize
     /// </summary>
     /// </summary>
-    public struct ImageSize
+    public struct ImageDimensions
     {
     {
-        private double _height;
-        private double _width;
-
         /// <summary>
         /// <summary>
         /// Gets or sets the height.
         /// Gets or sets the height.
         /// </summary>
         /// </summary>
         /// <value>The height.</value>
         /// <value>The height.</value>
-        public double Height
-        {
-            get => _height;
-            set => _height = value;
-        }
+        public int Height { get; set; }
 
 
         /// <summary>
         /// <summary>
         /// Gets or sets the width.
         /// Gets or sets the width.
         /// </summary>
         /// </summary>
         /// <value>The width.</value>
         /// <value>The width.</value>
-        public double Width
-        {
-            get => _width;
-            set => _width = value;
-        }
+        public int Width { get; set; }
 
 
-        public bool Equals(ImageSize size)
+        public bool Equals(ImageDimensions size)
         {
         {
             return Width.Equals(size.Width) && Height.Equals(size.Height);
             return Width.Equals(size.Width) && Height.Equals(size.Height);
         }
         }
@@ -40,46 +27,10 @@ namespace MediaBrowser.Model.Drawing
             return string.Format("{0}-{1}", Width, Height);
             return string.Format("{0}-{1}", Width, Height);
         }
         }
 
 
-        public ImageSize(string value)
+        public ImageDimensions(int width, int height)
         {
         {
-            _width = 0;
-
-            _height = 0;
-
-            ParseValue(value);
-        }
-
-        public ImageSize(int width, int height)
-        {
-            _width = width;
-            _height = height;
-        }
-
-        public ImageSize(double width, double height)
-        {
-            _width = width;
-            _height = height;
-        }
-
-        private void ParseValue(string value)
-        {
-            if (!string.IsNullOrEmpty(value))
-            {
-                string[] parts = value.Split('-');
-
-                if (parts.Length == 2)
-                {
-                    if (double.TryParse(parts[0], NumberStyles.Any, CultureInfo.InvariantCulture, out var val))
-                    {
-                        _width = val;
-                    }
-
-                    if (double.TryParse(parts[1], NumberStyles.Any, CultureInfo.InvariantCulture, out val))
-                    {
-                        _height = val;
-                    }
-                }
-            }
+            Width = width;
+            Height = height;
         }
         }
     }
     }
 }
 }