mirror of
https://github.com/jellyfin/jellyfin
synced 2024-07-21 18:04:30 +00:00
Enable nullabe reference types for Emby.Drawing and Jellyfin.Drawing.Skia
This commit is contained in:
parent
29539174a3
commit
2fcbc2a5b8
|
@ -1,3 +1,4 @@
|
|||
#nullable enable
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -121,11 +121,6 @@ namespace Emby.Drawing
|
|||
/// <inheritdoc />
|
||||
public async Task<(string path, string mimeType, DateTime dateModified)> ProcessImage(ImageProcessingOptions options)
|
||||
{
|
||||
if (options == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
var libraryManager = _libraryManager();
|
||||
|
||||
ItemImageInfo originalImage = options.Image;
|
||||
|
@ -351,19 +346,12 @@ namespace Emby.Drawing
|
|||
/// <inheritdoc />
|
||||
public string GetImageCacheTag(BaseItem item, ChapterInfo chapter)
|
||||
{
|
||||
try
|
||||
return GetImageCacheTag(item, new ItemImageInfo
|
||||
{
|
||||
return GetImageCacheTag(item, new ItemImageInfo
|
||||
{
|
||||
Path = chapter.ImagePath,
|
||||
Type = ImageType.Chapter,
|
||||
DateModified = chapter.ImageDateModified
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Path = chapter.ImagePath,
|
||||
Type = ImageType.Chapter,
|
||||
DateModified = chapter.ImageDateModified
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<(string path, DateTime dateModified)> GetSupportedImage(string originalImagePath, DateTime dateModified)
|
||||
|
|
|
@ -1991,7 +1991,14 @@ namespace Emby.Server.Implementations.Data
|
|||
|
||||
if (!string.IsNullOrEmpty(chapter.ImagePath))
|
||||
{
|
||||
chapter.ImageTag = ImageProcessor.GetImageCacheTag(item, chapter);
|
||||
try
|
||||
{
|
||||
chapter.ImageTag = ImageProcessor.GetImageCacheTag(item, chapter);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace Jellyfin.Drawing.Skia
|
|||
{
|
||||
paint.Color = SKColor.Parse("#CC00A4DC");
|
||||
paint.Style = SKPaintStyle.Fill;
|
||||
canvas.DrawCircle((float)x, OffsetFromTopRightCorner, 20, paint);
|
||||
canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint);
|
||||
}
|
||||
|
||||
using (var paint = new SKPaint())
|
||||
|
@ -39,16 +39,13 @@ namespace Jellyfin.Drawing.Skia
|
|||
|
||||
// or:
|
||||
// var emojiChar = 0x1F680;
|
||||
var text = "✔️";
|
||||
var emojiChar = StringUtilities.GetUnicodeCharacterCode(text, SKTextEncoding.Utf32);
|
||||
const string Text = "✔️";
|
||||
var emojiChar = StringUtilities.GetUnicodeCharacterCode(Text, SKTextEncoding.Utf32);
|
||||
|
||||
// ask the font manager for a font with that character
|
||||
var fontManager = SKFontManager.Default;
|
||||
var emojiTypeface = fontManager.MatchCharacter(emojiChar);
|
||||
paint.Typeface = SKFontManager.Default.MatchCharacter(emojiChar);
|
||||
|
||||
paint.Typeface = emojiTypeface;
|
||||
|
||||
canvas.DrawText(text, (float)x - 20, OffsetFromTopRightCorner + 12, paint);
|
||||
canvas.DrawText(Text, (float)x - 20, OffsetFromTopRightCorner + 12, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,11 +205,6 @@ namespace Jellyfin.Drawing.Skia
|
|||
/// <exception cref="SkiaCodecException">The file at the specified path could not be used to generate a codec.</exception>
|
||||
public ImageDimensions GetImageSize(string path)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
}
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
throw new FileNotFoundException("File not found", path);
|
||||
|
@ -297,7 +292,7 @@ namespace Jellyfin.Drawing.Skia
|
|||
/// <param name="orientation">The orientation of the image.</param>
|
||||
/// <param name="origin">The detected origin of the image.</param>
|
||||
/// <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))
|
||||
{
|
||||
|
@ -348,12 +343,17 @@ namespace Jellyfin.Drawing.Skia
|
|||
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)
|
||||
{
|
||||
using (var bitmap = Decode(path, forceAnalyzeBitmap, orientation, out origin))
|
||||
{
|
||||
if (bitmap == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return CropWhiteSpace(bitmap);
|
||||
}
|
||||
}
|
||||
|
@ -361,13 +361,11 @@ namespace Jellyfin.Drawing.Skia
|
|||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -380,7 +378,7 @@ namespace Jellyfin.Drawing.Skia
|
|||
return bitmap;
|
||||
}
|
||||
|
||||
return GetBitmap(path, cropWhitespace, false, orientation, out origin);
|
||||
return GetBitmap(path, cropWhitespace, false, orientation, out _);
|
||||
}
|
||||
|
||||
private SKBitmap OrientImage(SKBitmap bitmap, SKEncodedOrigin origin)
|
||||
|
@ -517,14 +515,14 @@ namespace Jellyfin.Drawing.Skia
|
|||
/// <inheritdoc/>
|
||||
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);
|
||||
|
@ -538,7 +536,7 @@ namespace Jellyfin.Drawing.Skia
|
|||
{
|
||||
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);
|
||||
|
|
|
@ -120,13 +120,13 @@ namespace Jellyfin.Drawing.Skia
|
|||
}
|
||||
|
||||
// resize to the same aspect as the original
|
||||
int iWidth = (int)Math.Abs(iHeight * currentBitmap.Width / currentBitmap.Height);
|
||||
int iWidth = Math.Abs(iHeight * currentBitmap.Width / currentBitmap.Height);
|
||||
using (var resizeBitmap = new SKBitmap(iWidth, iHeight, currentBitmap.ColorType, currentBitmap.AlphaType))
|
||||
{
|
||||
currentBitmap.ScalePixels(resizeBitmap, SKFilterQuality.High);
|
||||
|
||||
// crop image
|
||||
int ix = (int)Math.Abs((iWidth - iSlice) / 2);
|
||||
int ix = Math.Abs((iWidth - iSlice) / 2);
|
||||
using (var image = SKImage.FromBitmap(resizeBitmap))
|
||||
using (var subset = image.Subset(SKRectI.Create(ix, 0, iSlice, iHeight)))
|
||||
{
|
||||
|
@ -141,10 +141,10 @@ namespace Jellyfin.Drawing.Skia
|
|||
return bitmap;
|
||||
}
|
||||
|
||||
private SKBitmap GetNextValidImage(string[] paths, int currentIndex, out int newIndex)
|
||||
private SKBitmap? GetNextValidImage(string[] paths, int currentIndex, out int newIndex)
|
||||
{
|
||||
var imagesTested = new Dictionary<int, int>();
|
||||
SKBitmap bitmap = null;
|
||||
SKBitmap? bitmap = null;
|
||||
|
||||
while (imagesTested.Count < paths.Length)
|
||||
{
|
||||
|
@ -153,7 +153,7 @@ namespace Jellyfin.Drawing.Skia
|
|||
currentIndex = 0;
|
||||
}
|
||||
|
||||
bitmap = _skiaEncoder.Decode(paths[currentIndex], false, null, out var origin);
|
||||
bitmap = _skiaEncoder.Decode(paths[currentIndex], false, null, out _);
|
||||
|
||||
imagesTested[currentIndex] = 0;
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Jellyfin.Drawing.Skia
|
|||
{
|
||||
paint.Color = SKColor.Parse("#CC00A4DC");
|
||||
paint.Style = SKPaintStyle.Fill;
|
||||
canvas.DrawCircle((float)x, OffsetFromTopRightCorner, 20, paint);
|
||||
canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint);
|
||||
}
|
||||
|
||||
using (var paint = new SKPaint())
|
||||
|
@ -61,7 +61,7 @@ namespace Jellyfin.Drawing.Skia
|
|||
paint.TextSize = 18;
|
||||
}
|
||||
|
||||
canvas.DrawText(text, (float)x, y, paint);
|
||||
canvas.DrawText(text, x, y, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
Loading…
Reference in a new issue