|
|
@ -214,11 +214,6 @@ namespace Jellyfin.Drawing.Skia
|
|
|
|
/// <exception cref="SkiaCodecException">The file at the specified path could not be used to generate a codec.</exception>
|
|
|
|
/// <exception cref="SkiaCodecException">The file at the specified path could not be used to generate a codec.</exception>
|
|
|
|
public ImageDimensions GetImageSize(string path)
|
|
|
|
public ImageDimensions GetImageSize(string path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (path == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new ArgumentNullException(nameof(path));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(path))
|
|
|
|
if (!File.Exists(path))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new FileNotFoundException("File not found", path);
|
|
|
|
throw new FileNotFoundException("File not found", path);
|
|
|
@ -306,7 +301,7 @@ namespace Jellyfin.Drawing.Skia
|
|
|
|
/// <param name="orientation">The orientation of the image.</param>
|
|
|
|
/// <param name="orientation">The orientation of the image.</param>
|
|
|
|
/// <param name="origin">The detected origin of the image.</param>
|
|
|
|
/// <param name="origin">The detected origin of the image.</param>
|
|
|
|
/// <returns>The resulting bitmap of the image.</returns>
|
|
|
|
/// <returns>The resulting bitmap of the image.</returns>
|
|
|
|
internal SKBitmap Decode(string path, bool forceCleanBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin)
|
|
|
|
internal SKBitmap? Decode(string path, bool forceCleanBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!File.Exists(path))
|
|
|
|
if (!File.Exists(path))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -357,12 +352,17 @@ namespace Jellyfin.Drawing.Skia
|
|
|
|
return resultBitmap;
|
|
|
|
return resultBitmap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SKBitmap GetBitmap(string path, bool cropWhitespace, bool forceAnalyzeBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin)
|
|
|
|
private SKBitmap? GetBitmap(string path, bool cropWhitespace, bool forceAnalyzeBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (cropWhitespace)
|
|
|
|
if (cropWhitespace)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var bitmap = Decode(path, forceAnalyzeBitmap, orientation, out origin))
|
|
|
|
using (var bitmap = Decode(path, forceAnalyzeBitmap, orientation, out origin))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (bitmap == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return CropWhiteSpace(bitmap);
|
|
|
|
return CropWhiteSpace(bitmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -370,13 +370,11 @@ namespace Jellyfin.Drawing.Skia
|
|
|
|
return Decode(path, forceAnalyzeBitmap, orientation, out origin);
|
|
|
|
return Decode(path, forceAnalyzeBitmap, orientation, out origin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SKBitmap GetBitmap(string path, bool cropWhitespace, bool autoOrient, ImageOrientation? orientation)
|
|
|
|
private SKBitmap? GetBitmap(string path, bool cropWhitespace, bool autoOrient, ImageOrientation? orientation)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SKEncodedOrigin origin;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (autoOrient)
|
|
|
|
if (autoOrient)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var bitmap = GetBitmap(path, cropWhitespace, true, orientation, out origin);
|
|
|
|
var bitmap = GetBitmap(path, cropWhitespace, true, orientation, out var origin);
|
|
|
|
|
|
|
|
|
|
|
|
if (bitmap != null && origin != SKEncodedOrigin.TopLeft)
|
|
|
|
if (bitmap != null && origin != SKEncodedOrigin.TopLeft)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -389,7 +387,7 @@ namespace Jellyfin.Drawing.Skia
|
|
|
|
return bitmap;
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return GetBitmap(path, cropWhitespace, false, orientation, out origin);
|
|
|
|
return GetBitmap(path, cropWhitespace, false, orientation, out _);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SKBitmap OrientImage(SKBitmap bitmap, SKEncodedOrigin origin)
|
|
|
|
private SKBitmap OrientImage(SKBitmap bitmap, SKEncodedOrigin origin)
|
|
|
@ -526,14 +524,14 @@ namespace Jellyfin.Drawing.Skia
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, ImageOrientation? orientation, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
|
|
|
|
public string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, ImageOrientation? orientation, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(inputPath))
|
|
|
|
if (inputPath.Length == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(inputPath));
|
|
|
|
throw new ArgumentException("String can't be empty.", nameof(inputPath));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(inputPath))
|
|
|
|
if (outputPath.Length == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(outputPath));
|
|
|
|
throw new ArgumentException("String can't be empty.", nameof(outputPath));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var skiaOutputFormat = GetImageFormat(selectedOutputFormat);
|
|
|
|
var skiaOutputFormat = GetImageFormat(selectedOutputFormat);
|
|
|
@ -547,7 +545,7 @@ namespace Jellyfin.Drawing.Skia
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (bitmap == null)
|
|
|
|
if (bitmap == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new ArgumentOutOfRangeException($"Skia unable to read image {inputPath}");
|
|
|
|
throw new InvalidDataException($"Skia unable to read image {inputPath}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var originalImageSize = new ImageDimensions(bitmap.Width, bitmap.Height);
|
|
|
|
var originalImageSize = new ImageDimensions(bitmap.Width, bitmap.Height);
|
|
|
|