ImageProcessingOptions.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 IHasImages Item { get; set; }
  13. public ItemImageInfo Image { get; set; }
  14. public int ImageIndex { get; set; }
  15. public bool CropWhiteSpace { get; set; }
  16. public int? Width { get; set; }
  17. public int? Height { get; set; }
  18. public int? MaxWidth { get; set; }
  19. public int? MaxHeight { get; set; }
  20. public int Quality { get; set; }
  21. public List<IImageEnhancer> Enhancers { get; set; }
  22. public List<ImageFormat> SupportedOutputFormats { get; set; }
  23. public bool AddPlayedIndicator { get; set; }
  24. public int? UnplayedCount { get; set; }
  25. public int? Blur { get; set; }
  26. public double PercentPlayed { get; set; }
  27. public string BackgroundColor { get; set; }
  28. public string ForegroundLayer { get; set; }
  29. public bool HasDefaultOptions(string originalImagePath)
  30. {
  31. return HasDefaultOptionsWithoutSize(originalImagePath) &&
  32. !Width.HasValue &&
  33. !Height.HasValue &&
  34. !MaxWidth.HasValue &&
  35. !MaxHeight.HasValue;
  36. }
  37. public bool HasDefaultOptions(string originalImagePath, ImageSize size)
  38. {
  39. if (!HasDefaultOptionsWithoutSize(originalImagePath))
  40. {
  41. return false;
  42. }
  43. if (Width.HasValue && !size.Width.Equals(Width.Value))
  44. {
  45. return false;
  46. }
  47. if (Height.HasValue && !size.Height.Equals(Height.Value))
  48. {
  49. return false;
  50. }
  51. if (MaxWidth.HasValue && size.Width > MaxWidth.Value)
  52. {
  53. return false;
  54. }
  55. if (MaxHeight.HasValue && size.Height > MaxHeight.Value)
  56. {
  57. return false;
  58. }
  59. return true;
  60. }
  61. public bool HasDefaultOptionsWithoutSize(string originalImagePath)
  62. {
  63. return (Quality >= 90) &&
  64. IsFormatSupported(originalImagePath) &&
  65. !AddPlayedIndicator &&
  66. PercentPlayed.Equals(0) &&
  67. !UnplayedCount.HasValue &&
  68. !Blur.HasValue &&
  69. string.IsNullOrEmpty(BackgroundColor) &&
  70. string.IsNullOrEmpty(ForegroundLayer);
  71. }
  72. private bool IsFormatSupported(string originalImagePath)
  73. {
  74. var ext = Path.GetExtension(originalImagePath);
  75. return SupportedOutputFormats.Any(outputFormat => string.Equals(ext, "." + outputFormat, StringComparison.OrdinalIgnoreCase));
  76. }
  77. }
  78. }