BaseImageEnhancer.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Model.Drawing;
  3. using MediaBrowser.Model.Entities;
  4. using System;
  5. using System.Drawing;
  6. using System.Threading.Tasks;
  7. namespace MediaBrowser.Controller.Providers
  8. {
  9. /// <summary>
  10. /// Class BaseImageEnhancer
  11. /// </summary>
  12. public abstract class BaseImageEnhancer : IDisposable
  13. {
  14. /// <summary>
  15. /// Return true only if the given image for the given item will be enhanced by this enhancer.
  16. /// </summary>
  17. /// <param name="item">The item.</param>
  18. /// <param name="imageType">Type of the image.</param>
  19. /// <returns><c>true</c> if this enhancer will enhance the supplied image for the supplied item, <c>false</c> otherwise</returns>
  20. public abstract bool Supports(BaseItem item, ImageType imageType);
  21. /// <summary>
  22. /// Gets the priority or order in which this enhancer should be run.
  23. /// </summary>
  24. /// <value>The priority.</value>
  25. public abstract MetadataProviderPriority Priority { get; }
  26. /// <summary>
  27. /// Return the date of the last configuration change affecting the provided baseitem and image type
  28. /// </summary>
  29. /// <param name="item">The item.</param>
  30. /// <param name="imageType">Type of the image.</param>
  31. /// <returns>Date of last config change</returns>
  32. public virtual DateTime LastConfigurationChange(BaseItem item, ImageType imageType)
  33. {
  34. return DateTime.MinValue;
  35. }
  36. /// <summary>
  37. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  38. /// </summary>
  39. public void Dispose()
  40. {
  41. Dispose(true);
  42. GC.SuppressFinalize(this);
  43. }
  44. /// <summary>
  45. /// Releases unmanaged and - optionally - managed resources.
  46. /// </summary>
  47. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  48. protected virtual void Dispose(bool dispose)
  49. {
  50. }
  51. /// <summary>
  52. /// Gets the size of the enhanced image.
  53. /// </summary>
  54. /// <param name="item">The item.</param>
  55. /// <param name="imageType">Type of the image.</param>
  56. /// <param name="imageIndex">Index of the image.</param>
  57. /// <param name="originalImageSize">Size of the original image.</param>
  58. /// <returns>ImageSize.</returns>
  59. public virtual ImageSize GetEnhancedImageSize(BaseItem item, ImageType imageType, int imageIndex, ImageSize originalImageSize)
  60. {
  61. return originalImageSize;
  62. }
  63. /// <summary>
  64. /// Enhances the supplied image and returns it
  65. /// </summary>
  66. /// <param name="item">The item.</param>
  67. /// <param name="originalImage">The original image.</param>
  68. /// <param name="imageType">Type of the image.</param>
  69. /// <param name="imageIndex">Index of the image.</param>
  70. /// <returns>Task{System.Drawing.Image}.</returns>
  71. protected abstract Task<Image> EnhanceImageAsyncInternal(BaseItem item, Image originalImage, ImageType imageType, int imageIndex);
  72. /// <summary>
  73. /// Enhances the image async.
  74. /// </summary>
  75. /// <param name="item">The item.</param>
  76. /// <param name="originalImage">The original image.</param>
  77. /// <param name="imageType">Type of the image.</param>
  78. /// <param name="imageIndex">Index of the image.</param>
  79. /// <returns>Task{Image}.</returns>
  80. /// <exception cref="System.ArgumentNullException"></exception>
  81. public Task<Image> EnhanceImageAsync(BaseItem item, Image originalImage, ImageType imageType, int imageIndex)
  82. {
  83. if (item == null || originalImage == null)
  84. {
  85. throw new ArgumentNullException();
  86. }
  87. return EnhanceImageAsyncInternal(item, originalImage, imageType, imageIndex);
  88. }
  89. }
  90. }