diff options
Diffstat (limited to 'MediaBrowser.Controller/Drawing/BaseImageProcessor.cs')
| -rw-r--r-- | MediaBrowser.Controller/Drawing/BaseImageProcessor.cs | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs b/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs index ebd0e22c8..8fc6564e7 100644 --- a/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs +++ b/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs @@ -1,5 +1,6 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
+using System;
using System.ComponentModel.Composition;
using System.Drawing;
using System.Drawing.Drawing2D;
@@ -15,16 +16,7 @@ namespace MediaBrowser.Controller.Drawing public abstract class BaseImageProcessor
{
/// <summary>
- /// Processes the primary image for a BaseEntity (Person, Studio, User, etc)
- /// </summary>
- /// <param name="originalImage">The original Image, before re-sizing</param>
- /// <param name="bitmap">The bitmap holding the original image, after re-sizing</param>
- /// <param name="graphics">The graphics surface on which the output is drawn</param>
- /// <param name="entity">The entity that owns the image</param>
- public abstract void ProcessImage(Image originalImage, Bitmap bitmap, Graphics graphics, BaseEntity entity);
-
- /// <summary>
- /// Processes an image for a BaseItem
+ /// Processes an image for a BaseEntity
/// </summary>
/// <param name="originalImage">The original Image, before re-sizing</param>
/// <param name="bitmap">The bitmap holding the original image, after re-sizing</param>
@@ -32,10 +24,11 @@ namespace MediaBrowser.Controller.Drawing /// <param name="entity">The entity that owns the image</param>
/// <param name="imageType">The image type</param>
/// <param name="imageIndex">The image index (currently only used with backdrops)</param>
- public abstract void ProcessImage(Image originalImage, Bitmap bitmap, Graphics graphics, BaseItem entity, ImageType imageType, int imageIndex);
+ public abstract void ProcessImage(Image originalImage, Bitmap bitmap, Graphics graphics, BaseEntity entity, ImageType imageType, int imageIndex);
/// <summary>
/// If true, the image output format will be forced to png, resulting in an output size that will generally run larger than jpg
+ /// If false, the original image format is preserved.
/// </summary>
public virtual bool RequiresTransparency
{
@@ -44,6 +37,18 @@ namespace MediaBrowser.Controller.Drawing return false;
}
}
+
+ /// <summary>
+ /// Determines if the image processor is configured to process the specified entity, image type and image index
+ /// This will aid http response caching so that we don't invalidate image caches when we don't have to
+ /// </summary>
+ public abstract bool IsConfiguredToProcess(BaseEntity entity, ImageType imageType, int imageIndex);
+
+ /// <summary>
+ /// This is used for caching purposes, since a configuration change needs to invalidate a user's image cache
+ /// If the image processor is hosted within a plugin then this should be the plugin ConfigurationDateLastModified
+ /// </summary>
+ public abstract DateTime ProcessingConfigurationDateLastModifiedUtc { get; }
}
/// <summary>
@@ -52,34 +57,44 @@ namespace MediaBrowser.Controller.Drawing //[Export(typeof(BaseImageProcessor))]
public class MyRoundedCornerImageProcessor : BaseImageProcessor
{
- public override void ProcessImage(Image originalImage, Bitmap bitmap, Graphics g, BaseEntity entity)
+ public override void ProcessImage(Image originalImage, Bitmap bitmap, Graphics graphics, BaseEntity entity, ImageType imageType, int imageIndex)
{
var CornerRadius = 20;
- g.Clear(Color.Transparent);
-
+ graphics.Clear(Color.Transparent);
+
using (GraphicsPath gp = new GraphicsPath())
{
gp.AddArc(0, 0, CornerRadius, CornerRadius, 180, 90);
gp.AddArc(0 + bitmap.Width - CornerRadius, 0, CornerRadius, CornerRadius, 270, 90);
gp.AddArc(0 + bitmap.Width - CornerRadius, 0 + bitmap.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
gp.AddArc(0, 0 + bitmap.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
-
- g.SetClip(gp);
- g.DrawImage(originalImage, 0, 0, bitmap.Width, bitmap.Height);
+
+ graphics.SetClip(gp);
+ graphics.DrawImage(originalImage, 0, 0, bitmap.Width, bitmap.Height);
}
}
- public override void ProcessImage(Image originalImage, Bitmap bitmap, Graphics graphics, BaseItem entity, ImageType imageType, int imageIndex)
+ public override bool RequiresTransparency
{
+ get
+ {
+ return true;
+ }
}
- public override bool RequiresTransparency
+ public override DateTime ProcessingConfigurationDateLastModifiedUtc
{
get
{
- return true;
+ // This will result in a situation where images are never cached, but again, this is a prototype
+ return DateTime.UtcNow;
}
}
+
+ public override bool IsConfiguredToProcess(BaseEntity entity, ImageType imageType, int imageIndex)
+ {
+ return true;
+ }
}
}
|
