mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-06 10:16:18 +00:00
Jellyfin.Drawing minor improvements
Reduce duplicate/dead code
This commit is contained in:
@@ -200,20 +200,10 @@ public class SkiaEncoder : IImageEncoder
|
||||
{
|
||||
if (!orientation.HasValue)
|
||||
{
|
||||
return SKEncodedOrigin.TopLeft;
|
||||
return SKEncodedOrigin.Default;
|
||||
}
|
||||
|
||||
return orientation.Value switch
|
||||
{
|
||||
ImageOrientation.TopRight => SKEncodedOrigin.TopRight,
|
||||
ImageOrientation.RightTop => SKEncodedOrigin.RightTop,
|
||||
ImageOrientation.RightBottom => SKEncodedOrigin.RightBottom,
|
||||
ImageOrientation.LeftTop => SKEncodedOrigin.LeftTop,
|
||||
ImageOrientation.LeftBottom => SKEncodedOrigin.LeftBottom,
|
||||
ImageOrientation.BottomRight => SKEncodedOrigin.BottomRight,
|
||||
ImageOrientation.BottomLeft => SKEncodedOrigin.BottomLeft,
|
||||
_ => SKEncodedOrigin.TopLeft
|
||||
};
|
||||
return (SKEncodedOrigin)orientation.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -107,22 +107,10 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
|
||||
/// <inheritdoc />
|
||||
public bool SupportsImageCollageCreation => _imageEncoder.SupportsImageCollageCreation;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task ProcessImage(ImageProcessingOptions options, Stream toStream)
|
||||
{
|
||||
var file = await ProcessImage(options).ConfigureAwait(false);
|
||||
using var fileStream = AsyncFile.OpenRead(file.Path);
|
||||
await fileStream.CopyToAsync(toStream).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<ImageFormat> GetSupportedImageOutputFormats()
|
||||
=> _imageEncoder.SupportedOutputFormats;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SupportsTransparency(string path)
|
||||
=> _transparentImageTypes.Contains(Path.GetExtension(path));
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<(string Path, string? MimeType, DateTime DateModified)> ProcessImage(ImageProcessingOptions options)
|
||||
{
|
||||
@@ -224,7 +212,7 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
return (cacheFilePath, GetMimeType(outputFormat, cacheFilePath), _fileSystem.GetLastWriteTimeUtc(cacheFilePath));
|
||||
return (cacheFilePath, outputFormat.GetMimeType(), _fileSystem.GetLastWriteTimeUtc(cacheFilePath));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -262,17 +250,6 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
|
||||
return ImageFormat.Jpg;
|
||||
}
|
||||
|
||||
private string GetMimeType(ImageFormat format, string path)
|
||||
=> format switch
|
||||
{
|
||||
ImageFormat.Bmp => MimeTypes.GetMimeType("i.bmp"),
|
||||
ImageFormat.Gif => MimeTypes.GetMimeType("i.gif"),
|
||||
ImageFormat.Jpg => MimeTypes.GetMimeType("i.jpg"),
|
||||
ImageFormat.Png => MimeTypes.GetMimeType("i.png"),
|
||||
ImageFormat.Webp => MimeTypes.GetMimeType("i.webp"),
|
||||
_ => MimeTypes.GetMimeType(path)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cache file path based on a set of parameters.
|
||||
/// </summary>
|
||||
@@ -374,7 +351,7 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
|
||||
filename.Append(",v=");
|
||||
filename.Append(Version);
|
||||
|
||||
return GetCachePath(ResizedImageCachePath, filename.ToString(), "." + format.ToString().ToLowerInvariant());
|
||||
return GetCachePath(ResizedImageCachePath, filename.ToString(), format.GetExtension());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -471,35 +448,6 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
|
||||
return Task.FromResult((originalImagePath, dateModified));
|
||||
}
|
||||
|
||||
// TODO _mediaEncoder.ConvertImage is not implemented
|
||||
// if (!_imageEncoder.SupportedInputFormats.Contains(inputFormat))
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// string filename = (originalImagePath + dateModified.Ticks.ToString(CultureInfo.InvariantCulture)).GetMD5().ToString("N", CultureInfo.InvariantCulture);
|
||||
//
|
||||
// string cacheExtension = _mediaEncoder.SupportsEncoder("libwebp") ? ".webp" : ".png";
|
||||
// var outputPath = Path.Combine(_appPaths.ImageCachePath, "converted-images", filename + cacheExtension);
|
||||
//
|
||||
// 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.LogError(ex, "Image conversion failed for {Path}", originalImagePath);
|
||||
// }
|
||||
// }
|
||||
|
||||
return Task.FromResult((originalImagePath, dateModified));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user