ImageProcessingOptions.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 double PercentPlayed { get; set; }
  26. public string BackgroundColor { get; set; }
  27. public string ForegroundLayer { get; set; }
  28. public bool HasDefaultOptions(string originalImagePath)
  29. {
  30. return HasDefaultOptionsWithoutSize(originalImagePath) &&
  31. !Width.HasValue &&
  32. !Height.HasValue &&
  33. !MaxWidth.HasValue &&
  34. !MaxHeight.HasValue;
  35. }
  36. public bool HasDefaultOptions(string originalImagePath, ImageSize size)
  37. {
  38. if (!HasDefaultOptionsWithoutSize(originalImagePath))
  39. {
  40. return false;
  41. }
  42. if (Width.HasValue && !size.Width.Equals(Width.Value))
  43. {
  44. return false;
  45. }
  46. if (Height.HasValue && !size.Height.Equals(Height.Value))
  47. {
  48. return false;
  49. }
  50. if (MaxWidth.HasValue && size.Width > MaxWidth.Value)
  51. {
  52. return false;
  53. }
  54. if (MaxHeight.HasValue && size.Height > MaxHeight.Value)
  55. {
  56. return false;
  57. }
  58. return true;
  59. }
  60. public bool HasDefaultOptionsWithoutSize(string originalImagePath)
  61. {
  62. return (Quality >= 90) &&
  63. IsFormatSupported(originalImagePath) &&
  64. !AddPlayedIndicator &&
  65. PercentPlayed.Equals(0) &&
  66. !UnplayedCount.HasValue &&
  67. string.IsNullOrEmpty(BackgroundColor) &&
  68. string.IsNullOrEmpty(ForegroundLayer);
  69. }
  70. private bool IsFormatSupported(string originalImagePath)
  71. {
  72. var ext = Path.GetExtension(originalImagePath);
  73. return SupportedOutputFormats.Any(outputFormat => string.Equals(ext, "." + outputFormat, StringComparison.OrdinalIgnoreCase));
  74. }
  75. }
  76. }