mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-03 22:38:30 +01:00
support null image encoder
This commit is contained in:
@@ -75,6 +75,7 @@
|
||||
<Compile Include="ImageProcessor.cs" />
|
||||
<Compile Include="ImageMagick\PercentPlayedDrawer.cs" />
|
||||
<Compile Include="ImageMagick\PlayedIndicatorDrawer.cs" />
|
||||
<Compile Include="NullImageEncoder.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ImageMagick\UnplayedCountIndicator.cs" />
|
||||
</ItemGroup>
|
||||
@@ -99,6 +100,9 @@
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="GDI\empty.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Drawing;
|
||||
using MediaBrowser.Controller.Drawing;
|
||||
using MediaBrowser.Model.Drawing;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
@@ -23,7 +22,20 @@ namespace Emby.Drawing.GDI
|
||||
_fileSystem = fileSystem;
|
||||
_logger = logger;
|
||||
|
||||
_logger.Info("GDI image processor initialized");
|
||||
LogInfo();
|
||||
}
|
||||
|
||||
private void LogInfo()
|
||||
{
|
||||
_logger.Info("GDIImageEncoder starting");
|
||||
using (var stream = GetType().Assembly.GetManifestResourceStream(GetType().Namespace + ".empty.png"))
|
||||
{
|
||||
using (var img = Image.FromStream(stream))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
_logger.Info("GDIImageEncoder started");
|
||||
}
|
||||
|
||||
public string[] SupportedInputFormats
|
||||
@@ -253,5 +265,15 @@ namespace Emby.Drawing.GDI
|
||||
{
|
||||
get { return "GDI"; }
|
||||
}
|
||||
|
||||
public bool SupportsImageCollageCreation
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool SupportsImageEncoding
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Emby.Drawing/GDI/empty.png
Normal file
BIN
Emby.Drawing/GDI/empty.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 158 B |
@@ -17,12 +17,6 @@ namespace Emby.Drawing
|
||||
/// <value>The supported output formats.</value>
|
||||
ImageFormat[] SupportedOutputFormats { get; }
|
||||
/// <summary>
|
||||
/// Gets the size of the image.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns>ImageSize.</returns>
|
||||
ImageSize GetImageSize(string path);
|
||||
/// <summary>
|
||||
/// Crops the white space.
|
||||
/// </summary>
|
||||
/// <param name="inputPath">The input path.</param>
|
||||
@@ -49,5 +43,17 @@ namespace Emby.Drawing
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether [supports image collage creation].
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [supports image collage creation]; otherwise, <c>false</c>.</value>
|
||||
bool SupportsImageCollageCreation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether [supports image encoding].
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [supports image encoding]; otherwise, <c>false</c>.</value>
|
||||
bool SupportsImageEncoding { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using CommonIO;
|
||||
using MediaBrowser.Common.IO;
|
||||
|
||||
namespace Emby.Drawing.ImageMagick
|
||||
{
|
||||
@@ -27,7 +26,7 @@ namespace Emby.Drawing.ImageMagick
|
||||
_httpClient = httpClient;
|
||||
_fileSystem = fileSystem;
|
||||
|
||||
LogImageMagickVersion();
|
||||
LogVersion();
|
||||
}
|
||||
|
||||
public string[] SupportedInputFormats
|
||||
@@ -68,7 +67,7 @@ namespace Emby.Drawing.ImageMagick
|
||||
}
|
||||
}
|
||||
|
||||
private void LogImageMagickVersion()
|
||||
private void LogVersion()
|
||||
{
|
||||
_logger.Info("ImageMagick version: " + Wand.VersionString);
|
||||
TestWebp();
|
||||
@@ -88,9 +87,9 @@ namespace Emby.Drawing.ImageMagick
|
||||
wand.SaveImage(tmpPath);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch
|
||||
{
|
||||
_logger.ErrorException("Error loading webp: ", ex);
|
||||
//_logger.ErrorException("Error loading webp: ", ex);
|
||||
_webpAvailable = false;
|
||||
}
|
||||
}
|
||||
@@ -255,5 +254,15 @@ namespace Emby.Drawing.ImageMagick
|
||||
throw new ObjectDisposedException(GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
public bool SupportsImageCollageCreation
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool SupportsImageEncoding
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,14 +354,14 @@ namespace Emby.Drawing.ImageMagick
|
||||
|
||||
private MagickWand BuildSquareCollageWand(List<string> paths, int width, int height)
|
||||
{
|
||||
var inputPaths = ImageHelpers.ProjectPaths(paths, 4);
|
||||
var inputPaths = ImageHelpers.ProjectPaths(paths, 3);
|
||||
using (var wandImages = new MagickWand(inputPaths.ToArray()))
|
||||
{
|
||||
var wand = new MagickWand(width, height);
|
||||
wand.OpenImage("gradient:#111111-#111111");
|
||||
using (var draw = new DrawingWand())
|
||||
{
|
||||
var iSlice = Convert.ToInt32(width * .225);
|
||||
var iSlice = Convert.ToInt32(width * .3);
|
||||
int iTrans = Convert.ToInt32(height * .25);
|
||||
int iHeight = Convert.ToInt32(height * .63);
|
||||
var horizontalImagePadding = Convert.ToInt32(width * 0.02);
|
||||
|
||||
@@ -110,6 +110,15 @@ namespace Emby.Drawing
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool SupportsImageCollageCreation
|
||||
{
|
||||
get
|
||||
{
|
||||
return _imageEncoder.SupportsImageCollageCreation;
|
||||
}
|
||||
}
|
||||
|
||||
private string ResizedImageCachePath
|
||||
{
|
||||
get
|
||||
@@ -170,6 +179,11 @@ namespace Emby.Drawing
|
||||
|
||||
var originalImagePath = originalImage.Path;
|
||||
|
||||
if (!_imageEncoder.SupportsImageEncoding)
|
||||
{
|
||||
return originalImagePath;
|
||||
}
|
||||
|
||||
if (options.HasDefaultOptions(originalImagePath) && options.Enhancers.Count == 0 && !options.CropWhiteSpace)
|
||||
{
|
||||
// Just spit out the original file if all the options are default
|
||||
@@ -178,7 +192,7 @@ namespace Emby.Drawing
|
||||
|
||||
var dateModified = originalImage.DateModified;
|
||||
|
||||
if (options.CropWhiteSpace)
|
||||
if (options.CropWhiteSpace && _imageEncoder.SupportsImageEncoding)
|
||||
{
|
||||
var tuple = await GetWhitespaceCroppedImage(originalImagePath, dateModified).ConfigureAwait(false);
|
||||
|
||||
@@ -295,6 +309,11 @@ namespace Emby.Drawing
|
||||
|
||||
_imageEncoder.CropWhiteSpace(originalImagePath, croppedImagePath);
|
||||
}
|
||||
catch (NotImplementedException)
|
||||
{
|
||||
// No need to spam the log with an error message
|
||||
return new Tuple<string, DateTime>(originalImagePath, dateModified);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// We have to have a catch-all here because some of the .net image methods throw a plain old Exception
|
||||
|
||||
64
Emby.Drawing/NullImageEncoder.cs
Normal file
64
Emby.Drawing/NullImageEncoder.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using MediaBrowser.Controller.Drawing;
|
||||
using MediaBrowser.Model.Drawing;
|
||||
|
||||
namespace Emby.Drawing
|
||||
{
|
||||
public class NullImageEncoder : IImageEncoder
|
||||
{
|
||||
public string[] SupportedInputFormats
|
||||
{
|
||||
get
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
"png",
|
||||
"jpeg",
|
||||
"jpg"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public ImageFormat[] SupportedOutputFormats
|
||||
{
|
||||
get
|
||||
{
|
||||
return new[] { ImageFormat.Jpg, ImageFormat.Png };
|
||||
}
|
||||
}
|
||||
|
||||
public void CropWhiteSpace(string inputPath, string outputPath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void EncodeImage(string inputPath, string outputPath, int width, int height, int quality, ImageProcessingOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void CreateImageCollage(ImageCollageOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Null Image Encoder"; }
|
||||
}
|
||||
|
||||
public bool SupportsImageCollageCreation
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool SupportsImageEncoding
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user