diff options
| author | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-09-19 12:51:37 -0400 |
|---|---|---|
| committer | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-09-19 12:51:37 -0400 |
| commit | d8c01ded6eb57ba312e1cd62c4fa51dbcce6053a (patch) | |
| tree | 9019e5b8992e1882d492dc04fbabc2cdb61c59a7 /MediaBrowser.Controller | |
| parent | 19e202d5e1e107de9ac9bc110422187b8c6899ce (diff) | |
made some improvements to the base http handler
Diffstat (limited to 'MediaBrowser.Controller')
| -rw-r--r-- | MediaBrowser.Controller/Drawing/BaseImageProcessor.cs | 102 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Drawing/ImageProcessor.cs | 32 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Kernel.cs | 6 | ||||
| -rw-r--r-- | MediaBrowser.Controller/MediaBrowser.Controller.csproj | 1 |
4 files changed, 0 insertions, 141 deletions
diff --git a/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs b/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs deleted file mode 100644 index a1441cf7f..000000000 --- a/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs +++ /dev/null @@ -1,102 +0,0 @@ -using MediaBrowser.Controller.Entities;
-using MediaBrowser.Model.Entities;
-using System;
-using System.ComponentModel.Composition;
-using System.Drawing;
-using System.Drawing.Drawing2D;
-
-namespace MediaBrowser.Controller.Drawing
-{
- /// <summary>
- /// Provides a base image processor class that plugins can use to process images as they are being writen to http responses
- /// Since this is completely modular with MEF, a plugin only needs to have a subclass in their assembly with the following attribute on the class:
- /// [Export(typeof(BaseImageProcessor))]
- /// This will require a reference to System.ComponentModel.Composition
- /// </summary>
- public abstract class BaseImageProcessor
- {
- /// <summary>
- /// 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>
- /// <param name="graphics">The graphics surface on which the output is drawn</param>
- /// <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, 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
- {
- get
- {
- 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>
- /// This is demo-ware and should be deleted eventually
- /// </summary>
- //[Export(typeof(BaseImageProcessor))]
- public class MyRoundedCornerImageProcessor : BaseImageProcessor
- {
- public override void ProcessImage(Image originalImage, Bitmap bitmap, Graphics graphics, BaseEntity entity, ImageType imageType, int imageIndex)
- {
- var CornerRadius = 20;
-
- 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);
-
- graphics.SetClip(gp);
- graphics.DrawImage(originalImage, 0, 0, bitmap.Width, bitmap.Height);
- }
- }
-
- public override bool RequiresTransparency
- {
- get
- {
- return true;
- }
- }
-
- private static DateTime testDate = DateTime.UtcNow;
-
- public override DateTime ProcessingConfigurationDateLastModifiedUtc
- {
- get
- {
- // This will result in a situation where images are only cached throughout a server session, but again, this is a prototype
- return testDate;
- }
- }
-
- public override bool IsConfiguredToProcess(BaseEntity entity, ImageType imageType, int imageIndex)
- {
- return true;
- }
- }
-}
diff --git a/MediaBrowser.Controller/Drawing/ImageProcessor.cs b/MediaBrowser.Controller/Drawing/ImageProcessor.cs index 7ee4ef734..29e40d17d 100644 --- a/MediaBrowser.Controller/Drawing/ImageProcessor.cs +++ b/MediaBrowser.Controller/Drawing/ImageProcessor.cs @@ -59,17 +59,6 @@ namespace MediaBrowser.Controller.Drawing ImageFormat outputFormat = originalImage.RawFormat;
- // Run Kernel image processors
- if (Kernel.Instance.ImageProcessors.Any())
- {
- ExecuteAdditionalImageProcessors(originalImage, thumbnail, thumbnailGraph, entity, imageType, imageIndex);
-
- if (Kernel.Instance.ImageProcessors.Any(i => i.RequiresTransparency))
- {
- outputFormat = ImageFormat.Png;
- }
- }
-
// Write to the output stream
SaveImage(outputFormat, thumbnail, toStream, quality);
@@ -109,27 +98,6 @@ namespace MediaBrowser.Controller.Drawing return entity.PrimaryImagePath;
}
-
- /// <summary>
- /// Executes additional image processors that are registered with the Kernel
- /// </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>
- /// <param name="imageType">The image type</param>
- /// <param name="imageIndex">The image index (currently only used with backdrops)</param>
- private static void ExecuteAdditionalImageProcessors(Image originalImage, Bitmap bitmap, Graphics graphics, BaseEntity entity, ImageType imageType, int imageIndex)
- {
- foreach (var processor in Kernel.Instance.ImageProcessors)
- {
- if (processor.IsConfiguredToProcess(entity, imageType, imageIndex))
- {
- processor.ProcessImage(originalImage, bitmap, graphics, entity, imageType, imageIndex);
- }
- }
- }
-
public static void SaveImage(ImageFormat outputFormat, Image newImage, Stream toStream, int? quality)
{
// Use special save methods for jpeg and png that will result in a much higher quality image
diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 1c11b9fc8..bf03d1af1 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -78,12 +78,6 @@ namespace MediaBrowser.Controller internal IBaseItemResolver[] EntityResolvers { get; private set; }
/// <summary>
- /// Gets the list of currently registered entity resolvers
- /// </summary>
- [ImportMany(typeof(BaseImageProcessor))]
- public IEnumerable<BaseImageProcessor> ImageProcessors { get; private set; }
-
- /// <summary>
/// Creates a kernel based on a Data path, which is akin to our current programdata path
/// </summary>
public Kernel()
diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 131825af3..fd2be689e 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -59,7 +59,6 @@ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="Drawing\BaseImageProcessor.cs" />
<Compile Include="Drawing\DrawingUtils.cs" />
<Compile Include="Drawing\ImageProcessor.cs" />
<Compile Include="Entities\Audio.cs" />
|
