ImageProcessingOptions.cs 2.7 KB

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