jellyfin/MediaBrowser.Api/Images/ImageWriter.cs

82 lines
2.5 KiB
C#
Raw Normal View History

2013-02-21 01:33:05 +00:00
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
2013-06-04 02:02:49 +00:00
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
2013-02-21 01:33:05 +00:00
using ServiceStack.Service;
using ServiceStack.ServiceHost;
2013-02-21 01:33:05 +00:00
using System;
using System.Collections.Generic;
2013-02-21 01:33:05 +00:00
using System.IO;
using System.Threading.Tasks;
namespace MediaBrowser.Api.Images
{
/// <summary>
/// Class ImageWriter
/// </summary>
public class ImageWriter : IStreamWriter, IHasOptions
2013-02-21 01:33:05 +00:00
{
2013-06-04 02:02:49 +00:00
public List<IImageEnhancer> Enhancers;
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets or sets the request.
/// </summary>
/// <value>The request.</value>
public ImageRequest Request { get; set; }
/// <summary>
/// Gets or sets the item.
/// </summary>
/// <value>The item.</value>
public BaseItem Item { get; set; }
/// <summary>
/// The original image date modified
/// </summary>
public DateTime OriginalImageDateModified;
2013-06-18 19:43:14 +00:00
public string OriginalImagePath;
/// <summary>
/// The _options
/// </summary>
private readonly IDictionary<string, string> _options = new Dictionary<string, string>();
/// <summary>
/// Gets the options.
/// </summary>
/// <value>The options.</value>
public IDictionary<string, string> Options
{
get { return _options; }
}
2013-02-21 01:33:05 +00:00
/// <summary>
/// Writes to.
/// </summary>
/// <param name="responseStream">The response stream.</param>
public void WriteTo(Stream responseStream)
{
var task = WriteToAsync(responseStream);
Task.WaitAll(task);
}
/// <summary>
/// Writes to async.
/// </summary>
/// <param name="responseStream">The response stream.</param>
/// <returns>Task.</returns>
private Task WriteToAsync(Stream responseStream)
{
var cropwhitespace = Request.Type == ImageType.Logo || Request.Type == ImageType.Art;
if (Request.CropWhitespace.HasValue)
{
cropwhitespace = Request.CropWhitespace.Value;
}
2013-06-18 19:43:14 +00:00
return Kernel.Instance.ImageManager.ProcessImage(Item, Request.Type, Request.Index ?? 0, OriginalImagePath, cropwhitespace,
2013-02-21 01:33:05 +00:00
OriginalImageDateModified, responseStream, Request.Width, Request.Height, Request.MaxWidth,
2013-06-04 02:02:49 +00:00
Request.MaxHeight, Request.Quality, Enhancers);
2013-02-21 01:33:05 +00:00
}
}
}