|
|
|
@ -18,6 +18,7 @@ using System.Threading.Tasks;
|
|
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
|
using Emby.Drawing.Common;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
|
|
|
|
using MediaBrowser.Model.Net;
|
|
|
|
|
using MediaBrowser.Model.Threading;
|
|
|
|
|
using MediaBrowser.Model.Extensions;
|
|
|
|
@ -56,22 +57,24 @@ namespace Emby.Drawing
|
|
|
|
|
private readonly IServerApplicationPaths _appPaths;
|
|
|
|
|
private IImageEncoder _imageEncoder;
|
|
|
|
|
private readonly Func<ILibraryManager> _libraryManager;
|
|
|
|
|
private readonly Func<IMediaEncoder> _mediaEncoder;
|
|
|
|
|
|
|
|
|
|
public ImageProcessor(ILogger logger,
|
|
|
|
|
IServerApplicationPaths appPaths,
|
|
|
|
|
IFileSystem fileSystem,
|
|
|
|
|
IJsonSerializer jsonSerializer,
|
|
|
|
|
IImageEncoder imageEncoder,
|
|
|
|
|
Func<ILibraryManager> libraryManager, ITimerFactory timerFactory)
|
|
|
|
|
Func<ILibraryManager> libraryManager, ITimerFactory timerFactory, Func<IMediaEncoder> mediaEncoder)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
|
_jsonSerializer = jsonSerializer;
|
|
|
|
|
_imageEncoder = imageEncoder;
|
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
|
_mediaEncoder = mediaEncoder;
|
|
|
|
|
_appPaths = appPaths;
|
|
|
|
|
|
|
|
|
|
ImageEnhancers = new IImageEnhancer[] {};
|
|
|
|
|
ImageEnhancers = new IImageEnhancer[] { };
|
|
|
|
|
_saveImageSizeTimer = timerFactory.Create(SaveImageSizeCallback, null, Timeout.Infinite, Timeout.Infinite);
|
|
|
|
|
ImageHelper.ImageProcessor = this;
|
|
|
|
|
|
|
|
|
@ -120,7 +123,36 @@ namespace Emby.Drawing
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _imageEncoder.SupportedInputFormats;
|
|
|
|
|
return new string[]
|
|
|
|
|
{
|
|
|
|
|
"tiff",
|
|
|
|
|
"jpeg",
|
|
|
|
|
"jpg",
|
|
|
|
|
"png",
|
|
|
|
|
"aiff",
|
|
|
|
|
"cr2",
|
|
|
|
|
"crw",
|
|
|
|
|
"dng",
|
|
|
|
|
|
|
|
|
|
// Remove until supported
|
|
|
|
|
//"nef",
|
|
|
|
|
"orf",
|
|
|
|
|
"pef",
|
|
|
|
|
"arw",
|
|
|
|
|
"webp",
|
|
|
|
|
"gif",
|
|
|
|
|
"bmp",
|
|
|
|
|
"erf",
|
|
|
|
|
"raf",
|
|
|
|
|
"rw2",
|
|
|
|
|
"nrw",
|
|
|
|
|
"dng",
|
|
|
|
|
"ico",
|
|
|
|
|
"astc",
|
|
|
|
|
"ktx",
|
|
|
|
|
"pkm",
|
|
|
|
|
"wbmp"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -203,6 +235,10 @@ namespace Emby.Drawing
|
|
|
|
|
return new Tuple<string, string, DateTime>(originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var supportedImageInfo = await GetSupportedImage(originalImagePath, dateModified).ConfigureAwait(false);
|
|
|
|
|
originalImagePath = supportedImageInfo.Item1;
|
|
|
|
|
dateModified = supportedImageInfo.Item2;
|
|
|
|
|
|
|
|
|
|
if (options.Enhancers.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
if (item == null)
|
|
|
|
@ -663,6 +699,42 @@ namespace Emby.Drawing
|
|
|
|
|
return string.Join("|", cacheKeys.ToArray(cacheKeys.Count)).GetMD5().ToString("N");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<Tuple<string, DateTime>> GetSupportedImage(string originalImagePath, DateTime dateModified)
|
|
|
|
|
{
|
|
|
|
|
var inputFormat = (Path.GetExtension(originalImagePath) ?? string.Empty)
|
|
|
|
|
.TrimStart('.')
|
|
|
|
|
.Replace("jpeg", "jpg", StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
if (!_imageEncoder.SupportedInputFormats.Contains(inputFormat, StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var filename = (originalImagePath + dateModified.Ticks.ToString(UsCulture)).GetMD5().ToString("N");
|
|
|
|
|
|
|
|
|
|
var outputPath = Path.Combine(_appPaths.ImageCachePath, "converted-images", filename + ".webp");
|
|
|
|
|
|
|
|
|
|
var file = _fileSystem.GetFileInfo(outputPath);
|
|
|
|
|
if (!file.Exists)
|
|
|
|
|
{
|
|
|
|
|
await _mediaEncoder().ConvertImage(originalImagePath, outputPath).ConfigureAwait(false);
|
|
|
|
|
dateModified = _fileSystem.GetLastWriteTimeUtc(outputPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dateModified = file.LastWriteTimeUtc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
originalImagePath = outputPath;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Image conversion failed for {0}", ex, originalImagePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Tuple<string, DateTime>(originalImagePath, dateModified);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the enhanced image.
|
|
|
|
|
/// </summary>
|
|
|
|
|