|
@@ -1,5 +1,4 @@
|
|
using MediaBrowser.Common.Extensions;
|
|
using MediaBrowser.Common.Extensions;
|
|
-using MediaBrowser.Common.IO;
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
|
using MediaBrowser.Controller.Drawing;
|
|
using MediaBrowser.Controller.Entities;
|
|
using MediaBrowser.Controller.Entities;
|
|
using MediaBrowser.Controller.Library;
|
|
using MediaBrowser.Controller.Library;
|
|
@@ -18,7 +17,6 @@ using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using CommonIO;
|
|
using CommonIO;
|
|
-using MimeTypes = MediaBrowser.Model.Net.MimeTypes;
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.Images
|
|
namespace MediaBrowser.Api.Images
|
|
{
|
|
{
|
|
@@ -571,8 +569,7 @@ namespace MediaBrowser.Api.Images
|
|
cropwhitespace = request.CropWhitespace.Value;
|
|
cropwhitespace = request.CropWhitespace.Value;
|
|
}
|
|
}
|
|
|
|
|
|
- var format = GetOutputFormat(request, imageInfo, cropwhitespace, supportedImageEnhancers);
|
|
|
|
- var contentType = GetMimeType(format, imageInfo.Path);
|
|
|
|
|
|
+ var outputFormats = GetOutputFormats(request, imageInfo, cropwhitespace, supportedImageEnhancers);
|
|
|
|
|
|
var cacheGuid = new Guid(_imageProcessor.GetImageCacheTag(item, imageInfo, supportedImageEnhancers));
|
|
var cacheGuid = new Guid(_imageProcessor.GetImageCacheTag(item, imageInfo, supportedImageEnhancers));
|
|
|
|
|
|
@@ -593,9 +590,8 @@ namespace MediaBrowser.Api.Images
|
|
request,
|
|
request,
|
|
imageInfo,
|
|
imageInfo,
|
|
cropwhitespace,
|
|
cropwhitespace,
|
|
- format,
|
|
|
|
|
|
+ outputFormats,
|
|
supportedImageEnhancers,
|
|
supportedImageEnhancers,
|
|
- contentType,
|
|
|
|
cacheDuration,
|
|
cacheDuration,
|
|
responseHeaders,
|
|
responseHeaders,
|
|
isHeadRequest)
|
|
isHeadRequest)
|
|
@@ -606,9 +602,8 @@ namespace MediaBrowser.Api.Images
|
|
ImageRequest request,
|
|
ImageRequest request,
|
|
ItemImageInfo image,
|
|
ItemImageInfo image,
|
|
bool cropwhitespace,
|
|
bool cropwhitespace,
|
|
- ImageFormat format,
|
|
|
|
|
|
+ List<ImageFormat> supportedFormats,
|
|
List<IImageEnhancer> enhancers,
|
|
List<IImageEnhancer> enhancers,
|
|
- string contentType,
|
|
|
|
TimeSpan? cacheDuration,
|
|
TimeSpan? cacheDuration,
|
|
IDictionary<string, string> headers,
|
|
IDictionary<string, string> headers,
|
|
bool isHeadRequest)
|
|
bool isHeadRequest)
|
|
@@ -623,16 +618,16 @@ namespace MediaBrowser.Api.Images
|
|
Item = item,
|
|
Item = item,
|
|
MaxHeight = request.MaxHeight,
|
|
MaxHeight = request.MaxHeight,
|
|
MaxWidth = request.MaxWidth,
|
|
MaxWidth = request.MaxWidth,
|
|
- Quality = request.Quality,
|
|
|
|
|
|
+ Quality = request.Quality ?? 100,
|
|
Width = request.Width,
|
|
Width = request.Width,
|
|
AddPlayedIndicator = request.AddPlayedIndicator,
|
|
AddPlayedIndicator = request.AddPlayedIndicator,
|
|
PercentPlayed = request.PercentPlayed ?? 0,
|
|
PercentPlayed = request.PercentPlayed ?? 0,
|
|
UnplayedCount = request.UnplayedCount,
|
|
UnplayedCount = request.UnplayedCount,
|
|
BackgroundColor = request.BackgroundColor,
|
|
BackgroundColor = request.BackgroundColor,
|
|
- OutputFormat = format
|
|
|
|
|
|
+ SupportedOutputFormats = supportedFormats
|
|
};
|
|
};
|
|
|
|
|
|
- var file = await _imageProcessor.ProcessImage(options).ConfigureAwait(false);
|
|
|
|
|
|
+ var imageResult = await _imageProcessor.ProcessImage(options).ConfigureAwait(false);
|
|
|
|
|
|
headers["Vary"] = "Accept";
|
|
headers["Vary"] = "Accept";
|
|
|
|
|
|
@@ -640,20 +635,20 @@ namespace MediaBrowser.Api.Images
|
|
{
|
|
{
|
|
CacheDuration = cacheDuration,
|
|
CacheDuration = cacheDuration,
|
|
ResponseHeaders = headers,
|
|
ResponseHeaders = headers,
|
|
- ContentType = contentType,
|
|
|
|
|
|
+ ContentType = imageResult.Item2,
|
|
IsHeadRequest = isHeadRequest,
|
|
IsHeadRequest = isHeadRequest,
|
|
- Path = file
|
|
|
|
|
|
+ Path = imageResult.Item1
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- private ImageFormat GetOutputFormat(ImageRequest request, ItemImageInfo image, bool cropwhitespace, List<IImageEnhancer> enhancers)
|
|
|
|
|
|
+ private List<ImageFormat> GetOutputFormats(ImageRequest request, ItemImageInfo image, bool cropwhitespace, List<IImageEnhancer> enhancers)
|
|
{
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(request.Format))
|
|
if (!string.IsNullOrWhiteSpace(request.Format))
|
|
{
|
|
{
|
|
ImageFormat format;
|
|
ImageFormat format;
|
|
if (Enum.TryParse(request.Format, true, out format))
|
|
if (Enum.TryParse(request.Format, true, out format))
|
|
{
|
|
{
|
|
- return format;
|
|
|
|
|
|
+ return new List<ImageFormat> { format };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -671,39 +666,30 @@ namespace MediaBrowser.Api.Images
|
|
}
|
|
}
|
|
|
|
|
|
var clientSupportedFormats = GetClientSupportedFormats();
|
|
var clientSupportedFormats = GetClientSupportedFormats();
|
|
- if (inputFormat.HasValue && clientSupportedFormats.Contains(inputFormat.Value) && enhancers.Count == 0)
|
|
|
|
- {
|
|
|
|
- if ((request.Quality ?? 100) == 100 && !request.Height.HasValue && !request.Width.HasValue &&
|
|
|
|
- !request.AddPlayedIndicator && !request.PercentPlayed.HasValue && !request.UnplayedCount.HasValue && string.IsNullOrWhiteSpace(request.BackgroundColor))
|
|
|
|
- {
|
|
|
|
- // TODO: Allow this when specfying max width/height if the value is in range
|
|
|
|
- if (!cropwhitespace && !request.MaxHeight.HasValue && !request.MaxWidth.HasValue)
|
|
|
|
- {
|
|
|
|
- return inputFormat.Value;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
var serverFormats = _imageProcessor.GetSupportedImageOutputFormats();
|
|
var serverFormats = _imageProcessor.GetSupportedImageOutputFormats();
|
|
|
|
+ var outputFormats = new List<ImageFormat>();
|
|
|
|
|
|
// Client doesn't care about format, so start with webp if supported
|
|
// Client doesn't care about format, so start with webp if supported
|
|
if (serverFormats.Contains(ImageFormat.Webp) && clientSupportedFormats.Contains(ImageFormat.Webp))
|
|
if (serverFormats.Contains(ImageFormat.Webp) && clientSupportedFormats.Contains(ImageFormat.Webp))
|
|
{
|
|
{
|
|
- return ImageFormat.Webp;
|
|
|
|
|
|
+ outputFormats.Add(ImageFormat.Webp);
|
|
}
|
|
}
|
|
|
|
|
|
if (enhancers.Count > 0)
|
|
if (enhancers.Count > 0)
|
|
{
|
|
{
|
|
- return ImageFormat.Png;
|
|
|
|
|
|
+ outputFormats.Add(ImageFormat.Png);
|
|
}
|
|
}
|
|
|
|
|
|
if (inputFormat.HasValue && inputFormat.Value == ImageFormat.Jpg)
|
|
if (inputFormat.HasValue && inputFormat.Value == ImageFormat.Jpg)
|
|
{
|
|
{
|
|
- return ImageFormat.Jpg;
|
|
|
|
|
|
+ outputFormats.Add(ImageFormat.Jpg);
|
|
}
|
|
}
|
|
|
|
|
|
// We can't predict if there will be transparency or not, so play it safe
|
|
// We can't predict if there will be transparency or not, so play it safe
|
|
- return ImageFormat.Png;
|
|
|
|
|
|
+ outputFormats.Add(ImageFormat.Png);
|
|
|
|
+
|
|
|
|
+ return outputFormats;
|
|
}
|
|
}
|
|
|
|
|
|
private ImageFormat[] GetClientSupportedFormats()
|
|
private ImageFormat[] GetClientSupportedFormats()
|
|
@@ -712,10 +698,21 @@ namespace MediaBrowser.Api.Images
|
|
|
|
|
|
var userAgent = Request.UserAgent ?? string.Empty;
|
|
var userAgent = Request.UserAgent ?? string.Empty;
|
|
|
|
|
|
- if (userAgent.IndexOf("crosswalk", StringComparison.OrdinalIgnoreCase) != -1 &&
|
|
|
|
- userAgent.IndexOf("android", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
|
|
+ if (!supportsWebP)
|
|
{
|
|
{
|
|
- supportsWebP = true;
|
|
|
|
|
|
+ if (string.Equals(Request.QueryString["accept"], "webp", StringComparison.OrdinalIgnoreCase))
|
|
|
|
+ {
|
|
|
|
+ supportsWebP = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!supportsWebP)
|
|
|
|
+ {
|
|
|
|
+ if (userAgent.IndexOf("crosswalk", StringComparison.OrdinalIgnoreCase) != -1 &&
|
|
|
|
+ userAgent.IndexOf("android", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
+ {
|
|
|
|
+ supportsWebP = true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if (supportsWebP)
|
|
if (supportsWebP)
|
|
@@ -730,32 +727,6 @@ namespace MediaBrowser.Api.Images
|
|
return new[] { ImageFormat.Jpg, ImageFormat.Png };
|
|
return new[] { ImageFormat.Jpg, ImageFormat.Png };
|
|
}
|
|
}
|
|
|
|
|
|
- private string GetMimeType(ImageFormat format, string path)
|
|
|
|
- {
|
|
|
|
- if (format == ImageFormat.Bmp)
|
|
|
|
- {
|
|
|
|
- return MimeTypes.GetMimeType("i.bmp");
|
|
|
|
- }
|
|
|
|
- if (format == ImageFormat.Gif)
|
|
|
|
- {
|
|
|
|
- return MimeTypes.GetMimeType("i.gif");
|
|
|
|
- }
|
|
|
|
- if (format == ImageFormat.Jpg)
|
|
|
|
- {
|
|
|
|
- return MimeTypes.GetMimeType("i.jpg");
|
|
|
|
- }
|
|
|
|
- if (format == ImageFormat.Png)
|
|
|
|
- {
|
|
|
|
- return MimeTypes.GetMimeType("i.png");
|
|
|
|
- }
|
|
|
|
- if (format == ImageFormat.Webp)
|
|
|
|
- {
|
|
|
|
- return MimeTypes.GetMimeType("i.webp");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return MimeTypes.GetMimeType(path);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets the image path.
|
|
/// Gets the image path.
|
|
/// </summary>
|
|
/// </summary>
|