From d10de5b7f93511daa3cf239b4b4c34dc79000969 Mon Sep 17 00:00:00 2001 From: cvium Date: Wed, 10 Nov 2021 23:25:01 +0100 Subject: [PATCH 1/3] Try to use Width and Height from ImageInfo to determine aspect ratio --- Emby.Server.Implementations/Dto/DtoService.cs | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index 67ecd04e0e..4193d00184 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -1398,41 +1398,33 @@ namespace Emby.Server.Implementations.Dto return null; } - ImageDimensions size; - - var defaultAspectRatio = item.GetDefaultPrimaryImageAspectRatio(); - - if (defaultAspectRatio > 0) - { - return defaultAspectRatio; - } - if (!imageInfo.IsLocalFile) { - return null; + return item.GetDefaultPrimaryImageAspectRatio(); } - try - { - size = _imageProcessor.GetImageDimensions(item, imageInfo); + var width = imageInfo.Width; + var height = imageInfo.Height; - if (size.Width <= 0 || size.Height <= 0) + // Fallback to the image processor if the image info is somehow incorrect + if (width <= 0 || height <= 0) + { + try { - return null; + var size = _imageProcessor.GetImageDimensions(item, imageInfo); + width = size.Width; + height = size.Height; + } + catch (Exception ex) + { + _logger.LogError(ex, "Failed to determine primary image aspect ratio for {ImagePath}", imageInfo.Path); + return item.GetDefaultPrimaryImageAspectRatio(); } - } - catch (Exception ex) - { - _logger.LogError(ex, "Failed to determine primary image aspect ratio for {0}", imageInfo.Path); - return null; } - var width = size.Width; - var height = size.Height; - if (width <= 0 || height <= 0) { - return null; + return item.GetDefaultPrimaryImageAspectRatio(); } return (double)width / height; From 0415d1ccef19c48a2eaa3c545648ce657f95cfb8 Mon Sep 17 00:00:00 2001 From: cvium Date: Wed, 10 Nov 2021 23:29:41 +0100 Subject: [PATCH 2/3] Reduce indentation --- Emby.Server.Implementations/Dto/DtoService.cs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index 4193d00184..f23f4a13f3 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -1406,28 +1406,29 @@ namespace Emby.Server.Implementations.Dto var width = imageInfo.Width; var height = imageInfo.Height; + if (width > 0 && height > 0) + { + return (double)width / height; + } + // Fallback to the image processor if the image info is somehow incorrect - if (width <= 0 || height <= 0) + try { - try - { - var size = _imageProcessor.GetImageDimensions(item, imageInfo); - width = size.Width; - height = size.Height; - } - catch (Exception ex) - { - _logger.LogError(ex, "Failed to determine primary image aspect ratio for {ImagePath}", imageInfo.Path); - return item.GetDefaultPrimaryImageAspectRatio(); - } + var size = _imageProcessor.GetImageDimensions(item, imageInfo); + width = size.Width; + height = size.Height; + } + catch (Exception ex) + { + _logger.LogError(ex, "Failed to determine primary image aspect ratio for {ImagePath}", imageInfo.Path); } - if (width <= 0 || height <= 0) + if (width > 0 && height > 0) { - return item.GetDefaultPrimaryImageAspectRatio(); + return (double)width / height; } - return (double)width / height; + return item.GetDefaultPrimaryImageAspectRatio(); } } } From 5d19c26d5966db3ff48c73f409290509815cd89a Mon Sep 17 00:00:00 2001 From: cvium Date: Wed, 10 Nov 2021 23:46:56 +0100 Subject: [PATCH 3/3] Simplify --- Emby.Server.Implementations/Dto/DtoService.cs | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index f23f4a13f3..ab5d452790 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -1403,31 +1403,21 @@ namespace Emby.Server.Implementations.Dto return item.GetDefaultPrimaryImageAspectRatio(); } - var width = imageInfo.Width; - var height = imageInfo.Height; - - if (width > 0 && height > 0) - { - return (double)width / height; - } - - // Fallback to the image processor if the image info is somehow incorrect try { var size = _imageProcessor.GetImageDimensions(item, imageInfo); - width = size.Width; - height = size.Height; + var width = size.Width; + var height = size.Height; + if (width > 0 && height > 0) + { + return (double)width / height; + } } catch (Exception ex) { _logger.LogError(ex, "Failed to determine primary image aspect ratio for {ImagePath}", imageInfo.Path); } - if (width > 0 && height > 0) - { - return (double)width / height; - } - return item.GetDefaultPrimaryImageAspectRatio(); } }