| | | 1 | | #nullable disable |
| | | 2 | | |
| | | 3 | | #pragma warning disable CS1591 |
| | | 4 | | |
| | | 5 | | using System; |
| | | 6 | | using System.Collections.Generic; |
| | | 7 | | using System.IO; |
| | | 8 | | using System.Linq; |
| | | 9 | | using MediaBrowser.Controller.Entities; |
| | | 10 | | using MediaBrowser.Model.Drawing; |
| | | 11 | | |
| | | 12 | | namespace MediaBrowser.Controller.Drawing |
| | | 13 | | { |
| | | 14 | | public class ImageProcessingOptions |
| | | 15 | | { |
| | | 16 | | public ImageProcessingOptions() |
| | | 17 | | { |
| | 0 | 18 | | RequiresAutoOrientation = true; |
| | 0 | 19 | | } |
| | | 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 | | { |
| | 0 | 59 | | return HasDefaultOptionsWithoutSize(originalImagePath) && |
| | 0 | 60 | | !Width.HasValue && |
| | 0 | 61 | | !Height.HasValue && |
| | 0 | 62 | | !MaxWidth.HasValue && |
| | 0 | 63 | | !MaxHeight.HasValue; |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | public bool HasDefaultOptions(string originalImagePath, ImageDimensions? size) |
| | | 67 | | { |
| | 0 | 68 | | if (!size.HasValue) |
| | | 69 | | { |
| | 0 | 70 | | return HasDefaultOptions(originalImagePath); |
| | | 71 | | } |
| | | 72 | | |
| | 0 | 73 | | if (!HasDefaultOptionsWithoutSize(originalImagePath)) |
| | | 74 | | { |
| | 0 | 75 | | return false; |
| | | 76 | | } |
| | | 77 | | |
| | 0 | 78 | | var sizeValue = size.Value; |
| | | 79 | | |
| | 0 | 80 | | if (Width.HasValue && !sizeValue.Width.Equals(Width.Value)) |
| | | 81 | | { |
| | 0 | 82 | | return false; |
| | | 83 | | } |
| | | 84 | | |
| | 0 | 85 | | if (Height.HasValue && !sizeValue.Height.Equals(Height.Value)) |
| | | 86 | | { |
| | 0 | 87 | | return false; |
| | | 88 | | } |
| | | 89 | | |
| | 0 | 90 | | if (MaxWidth.HasValue && sizeValue.Width > MaxWidth.Value) |
| | | 91 | | { |
| | 0 | 92 | | return false; |
| | | 93 | | } |
| | | 94 | | |
| | 0 | 95 | | if (MaxHeight.HasValue && sizeValue.Height > MaxHeight.Value) |
| | | 96 | | { |
| | 0 | 97 | | return false; |
| | | 98 | | } |
| | | 99 | | |
| | 0 | 100 | | if (sizeValue.Width > FillWidth || sizeValue.Height > FillHeight) |
| | | 101 | | { |
| | 0 | 102 | | return false; |
| | | 103 | | } |
| | | 104 | | |
| | 0 | 105 | | return true; |
| | | 106 | | } |
| | | 107 | | |
| | | 108 | | private bool HasDefaultOptionsWithoutSize(string originalImagePath) |
| | | 109 | | { |
| | 0 | 110 | | return (Quality >= 90) && |
| | 0 | 111 | | IsFormatSupported(originalImagePath) && |
| | 0 | 112 | | PercentPlayed.Equals(0) && |
| | 0 | 113 | | !UnplayedCount.HasValue && |
| | 0 | 114 | | !Blur.HasValue && |
| | 0 | 115 | | string.IsNullOrEmpty(BackgroundColor) && |
| | 0 | 116 | | string.IsNullOrEmpty(ForegroundLayer); |
| | | 117 | | } |
| | | 118 | | |
| | | 119 | | private bool IsFormatSupported(string originalImagePath) |
| | | 120 | | { |
| | 0 | 121 | | var ext = Path.GetExtension(originalImagePath); |
| | 0 | 122 | | ext = ext.Replace(".jpeg", ".jpg", StringComparison.OrdinalIgnoreCase); |
| | 0 | 123 | | return SupportedOutputFormats.Any(outputFormat => string.Equals(ext, outputFormat.GetExtension(), StringComp |
| | | 124 | | } |
| | | 125 | | } |
| | | 126 | | } |