ImageProcessingOptions.cs 3.0 KB

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