ImageProcessingOptions.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Providers;
  3. using MediaBrowser.Model.Drawing;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. namespace MediaBrowser.Controller.Drawing
  9. {
  10. public class ImageProcessingOptions
  11. {
  12. public ImageProcessingOptions()
  13. {
  14. RequiresAutoOrientation = true;
  15. }
  16. public string ItemId { get; set; }
  17. public string ItemType { get; set; }
  18. public IHasMetadata Item { get; set; }
  19. public ItemImageInfo Image { get; set; }
  20. public int ImageIndex { get; set; }
  21. public bool CropWhiteSpace { get; set; }
  22. public int? Width { get; set; }
  23. public int? Height { get; set; }
  24. public int? MaxWidth { get; set; }
  25. public int? MaxHeight { get; set; }
  26. public int Quality { get; set; }
  27. public List<IImageEnhancer> Enhancers { get; set; }
  28. public ImageFormat[] SupportedOutputFormats { get; set; }
  29. public bool AddPlayedIndicator { get; set; }
  30. public int? UnplayedCount { get; set; }
  31. public int? Blur { get; set; }
  32. public double PercentPlayed { get; set; }
  33. public string BackgroundColor { get; set; }
  34. public string ForegroundLayer { get; set; }
  35. public bool RequiresAutoOrientation { get; set; }
  36. public bool HasDefaultOptions(string originalImagePath)
  37. {
  38. return HasDefaultOptionsWithoutSize(originalImagePath) &&
  39. !Width.HasValue &&
  40. !Height.HasValue &&
  41. !MaxWidth.HasValue &&
  42. !MaxHeight.HasValue;
  43. }
  44. public bool HasDefaultOptions(string originalImagePath, ImageSize size)
  45. {
  46. if (!HasDefaultOptionsWithoutSize(originalImagePath))
  47. {
  48. return false;
  49. }
  50. if (Width.HasValue && !size.Width.Equals(Width.Value))
  51. {
  52. return false;
  53. }
  54. if (Height.HasValue && !size.Height.Equals(Height.Value))
  55. {
  56. return false;
  57. }
  58. if (MaxWidth.HasValue && size.Width > MaxWidth.Value)
  59. {
  60. return false;
  61. }
  62. if (MaxHeight.HasValue && size.Height > MaxHeight.Value)
  63. {
  64. return false;
  65. }
  66. return true;
  67. }
  68. public bool HasDefaultOptionsWithoutSize(string originalImagePath)
  69. {
  70. return (Quality >= 90) &&
  71. IsFormatSupported(originalImagePath) &&
  72. !AddPlayedIndicator &&
  73. PercentPlayed.Equals(0) &&
  74. !UnplayedCount.HasValue &&
  75. !Blur.HasValue &&
  76. !CropWhiteSpace &&
  77. string.IsNullOrEmpty(BackgroundColor) &&
  78. string.IsNullOrEmpty(ForegroundLayer);
  79. }
  80. private bool IsFormatSupported(string originalImagePath)
  81. {
  82. var ext = Path.GetExtension(originalImagePath);
  83. return SupportedOutputFormats.Any(outputFormat => string.Equals(ext, "." + outputFormat, StringComparison.OrdinalIgnoreCase));
  84. }
  85. }
  86. }