The Free Software Media System - Server Backend & API
Enable nullabe reference types for Emby.Drawing and Jellyfin.Drawing.Skia
Bond_0092fcbc2a5b804
diff --git a/Emby.Dlna/ConfigurationExtension.cs b/Emby.Dlna/ConfigurationExtension.csindex e224d10bd3..dba9019677 100644--- a/Emby.Dlna/ConfigurationExtension.cs+++ b/Emby.Dlna/ConfigurationExtension.cs@@ -1,3 +1,4 @@+#nullable enable#pragma warning disable CS1591using System.Collections.Generic;diff --git a/Emby.Drawing/Emby.Drawing.csproj b/Emby.Drawing/Emby.Drawing.csprojindex b7090b2629..b17fff751b 100644--- a/Emby.Drawing/Emby.Drawing.csproj+++ b/Emby.Drawing/Emby.Drawing.csproj@@ -5,6 +5,7 @@<GenerateAssemblyInfo>false</GenerateAssemblyInfo><GenerateDocumentationFile>true</GenerateDocumentationFile><TreatWarningsAsErrors>true</TreatWarningsAsErrors>+ <Nullable>enable</Nullable></PropertyGroup><ItemGroup>diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.csindex eca4b56eb9..3d6bcc045d 100644--- a/Emby.Drawing/ImageProcessor.cs+++ b/Emby.Drawing/ImageProcessor.cs@@ -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)diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.csindex 46c6d55200..d3b3f7b7af 100644--- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs+++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs@@ -1991,7 +1991,14 @@ namespace Emby.Server.Implementations.Dataif (!string.IsNullOrEmpty(chapter.ImagePath)){- chapter.ImageTag = ImageProcessor.GetImageCacheTag(item, chapter);+ try+ {+ chapter.ImageTag = ImageProcessor.GetImageCacheTag(item, chapter);+ }+ catch+ {++ }}}diff --git a/Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csproj b/Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csprojindex d0a99e1e28..e4b4c058ec 100644--- a/Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csproj+++ b/Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csproj@@ -5,6 +5,7 @@<GenerateAssemblyInfo>false</GenerateAssemblyInfo><GenerateDocumentationFile>true</GenerateDocumentationFile><TreatWarningsAsErrors>true</TreatWarningsAsErrors>+ <Nullable>enable</Nullable></PropertyGroup><ItemGroup>diff --git a/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs b/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.csindex 5084fd211c..7eed5f4f79 100644--- a/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs+++ b/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs@@ -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);}}}diff --git a/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/Jellyfin.Drawing.Skia/SkiaEncoder.csindex a67118f188..723c523405 100644--- a/Jellyfin.Drawing.Skia/SkiaEncoder.cs+++ b/Jellyfin.Drawing.Skia/SkiaEncoder.cs@@ -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.Skiareturn 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.Skiareturn 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.Skiareturn 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);diff --git a/Jellyfin.Drawing.Skia/StripCollageBuilder.cs b/Jellyfin.Drawing.Skia/StripCollageBuilder.csindex 0735ef194a..61bef90ec5 100644--- a/Jellyfin.Drawing.Skia/StripCollageBuilder.cs+++ b/Jellyfin.Drawing.Skia/StripCollageBuilder.cs@@ -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.Skiareturn 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.SkiacurrentIndex = 0;}- bitmap = _skiaEncoder.Decode(paths[currentIndex], false, null, out var origin);+ bitmap = _skiaEncoder.Decode(paths[currentIndex], false, null, out _);imagesTested[currentIndex] = 0;diff --git a/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs b/Jellyfin.Drawing.Skia/UnplayedCountIndicator.csindex a10fff9dfe..cf3dbde2c0 100644--- a/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs+++ b/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs@@ -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.Skiapaint.TextSize = 18;}- canvas.DrawText(text, (float)x, y, paint);+ canvas.DrawText(text, x, y, paint);}}}diff --git a/MediaBrowser.Common/Extensions/ShuffleExtensions.cs b/MediaBrowser.Common/Extensions/ShuffleExtensions.csindex 0432f36b57..459bec1105 100644--- a/MediaBrowser.Common/Extensions/ShuffleExtensions.cs+++ b/MediaBrowser.Common/Extensions/ShuffleExtensions.cs@@ -1,3 +1,5 @@+#nullable enable+using System;using System.Collections.Generic;