< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Drawing.ImageProcessingOptions
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 33
Coverable lines: 33
Total lines: 126
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 44
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
HasDefaultOptions(...)0%7280%
HasDefaultOptions(...)0%600240%
HasDefaultOptionsWithoutSize(...)0%156120%
IsFormatSupported(...)100%210%

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System;
 6using System.Collections.Generic;
 7using System.IO;
 8using System.Linq;
 9using MediaBrowser.Controller.Entities;
 10using MediaBrowser.Model.Drawing;
 11
 12namespace MediaBrowser.Controller.Drawing
 13{
 14    public class ImageProcessingOptions
 15    {
 16        public ImageProcessingOptions()
 17        {
 018            RequiresAutoOrientation = true;
 019        }
 20
 21        public Guid ItemId { get; set; }
 22
 23        public BaseItem Item { get; set; }
 24
 25        public ItemImageInfo Image { get; set; }
 26
 27        public int ImageIndex { get; set; }
 28
 29        public int? Width { get; set; }
 30
 31        public int? Height { get; set; }
 32
 33        public int? MaxWidth { get; set; }
 34
 35        public int? MaxHeight { get; set; }
 36
 37        public int? FillWidth { get; set; }
 38
 39        public int? FillHeight { get; set; }
 40
 41        public int Quality { get; set; }
 42
 43        public IReadOnlyCollection<ImageFormat> SupportedOutputFormats { get; set; }
 44
 45        public int? UnplayedCount { get; set; }
 46
 47        public int? Blur { get; set; }
 48
 49        public double PercentPlayed { get; set; }
 50
 51        public string BackgroundColor { get; set; }
 52
 53        public string ForegroundLayer { get; set; }
 54
 55        public bool RequiresAutoOrientation { get; set; }
 56
 57        private bool HasDefaultOptions(string originalImagePath)
 58        {
 059            return HasDefaultOptionsWithoutSize(originalImagePath) &&
 060                !Width.HasValue &&
 061                !Height.HasValue &&
 062                !MaxWidth.HasValue &&
 063                !MaxHeight.HasValue;
 64        }
 65
 66        public bool HasDefaultOptions(string originalImagePath, ImageDimensions? size)
 67        {
 068            if (!size.HasValue)
 69            {
 070                return HasDefaultOptions(originalImagePath);
 71            }
 72
 073            if (!HasDefaultOptionsWithoutSize(originalImagePath))
 74            {
 075                return false;
 76            }
 77
 078            var sizeValue = size.Value;
 79
 080            if (Width.HasValue && !sizeValue.Width.Equals(Width.Value))
 81            {
 082                return false;
 83            }
 84
 085            if (Height.HasValue && !sizeValue.Height.Equals(Height.Value))
 86            {
 087                return false;
 88            }
 89
 090            if (MaxWidth.HasValue && sizeValue.Width > MaxWidth.Value)
 91            {
 092                return false;
 93            }
 94
 095            if (MaxHeight.HasValue && sizeValue.Height > MaxHeight.Value)
 96            {
 097                return false;
 98            }
 99
 0100            if (sizeValue.Width > FillWidth || sizeValue.Height > FillHeight)
 101            {
 0102                return false;
 103            }
 104
 0105            return true;
 106        }
 107
 108        private bool HasDefaultOptionsWithoutSize(string originalImagePath)
 109        {
 0110            return (Quality >= 90) &&
 0111                IsFormatSupported(originalImagePath) &&
 0112                PercentPlayed.Equals(0) &&
 0113                !UnplayedCount.HasValue &&
 0114                !Blur.HasValue &&
 0115                string.IsNullOrEmpty(BackgroundColor) &&
 0116                string.IsNullOrEmpty(ForegroundLayer);
 117        }
 118
 119        private bool IsFormatSupported(string originalImagePath)
 120        {
 0121            var ext = Path.GetExtension(originalImagePath);
 0122            ext = ext.Replace(".jpeg", ".jpg", StringComparison.OrdinalIgnoreCase);
 0123            return SupportedOutputFormats.Any(outputFormat => string.Equals(ext, outputFormat.GetExtension(), StringComp
 124        }
 125    }
 126}