From 2c3e1b8562cb86d4e236eefd4de7554ee426896c Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Sat, 14 Dec 2019 11:04:22 +0100 Subject: [PATCH] Enable StyleCop analyzer and fix existing issues --- .../Jellyfin.Drawing.Skia.csproj | 2 +- .../PlayedIndicatorDrawer.cs | 4 ++-- Jellyfin.Drawing.Skia/SkiaCodecException.cs | 13 ++++++------ Jellyfin.Drawing.Skia/SkiaEncoder.cs | 20 +++++++++++++++---- Jellyfin.Drawing.Skia/StripCollageBuilder.cs | 2 ++ 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csproj b/Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csproj index 2ca8211f44..9b7027475f 100644 --- a/Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csproj +++ b/Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csproj @@ -26,7 +26,7 @@ - + diff --git a/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs b/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs index 9842c33fc0..5084fd211c 100644 --- a/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs +++ b/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs @@ -37,10 +37,10 @@ namespace Jellyfin.Drawing.Skia paint.TextSize = 30; paint.IsAntialias = true; + // or: + // var emojiChar = 0x1F680; var text = "✔️"; var emojiChar = StringUtilities.GetUnicodeCharacterCode(text, SKTextEncoding.Utf32); - // or: - //var emojiChar = 0x1F680; // ask the font manager for a font with that character var fontManager = SKFontManager.Default; diff --git a/Jellyfin.Drawing.Skia/SkiaCodecException.cs b/Jellyfin.Drawing.Skia/SkiaCodecException.cs index c103670520..0cfb55c268 100644 --- a/Jellyfin.Drawing.Skia/SkiaCodecException.cs +++ b/Jellyfin.Drawing.Skia/SkiaCodecException.cs @@ -10,12 +10,6 @@ namespace Jellyfin.Drawing.Skia [SuppressMessage("Design", "CA1032:Implement standard exception constructors", Justification = "A custom property, CodecResult, is required when creating this exception type.")] public class SkiaCodecException : SkiaException { - /// - /// Returns the non-successful codec result returned by Skia. - /// - /// The non-successful codec result returned by Skia. - public SKCodecResult CodecResult { get; } - /// /// Initializes a new instance of the class. /// @@ -37,12 +31,17 @@ namespace Jellyfin.Drawing.Skia CodecResult = result; } + /// + /// Gets the non-successful codec result returned by Skia. + /// + public SKCodecResult CodecResult { get; } + /// public override string ToString() => string.Format( CultureInfo.InvariantCulture, "Non-success codec result: {0}\n{1}", CodecResult, - base.ToString()); + base.ToString()); } } diff --git a/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/Jellyfin.Drawing.Skia/SkiaEncoder.cs index 3b781625fa..fdca59b699 100644 --- a/Jellyfin.Drawing.Skia/SkiaEncoder.cs +++ b/Jellyfin.Drawing.Skia/SkiaEncoder.cs @@ -28,6 +28,9 @@ namespace Jellyfin.Drawing.Skia /// /// Initializes a new instance of the class. /// + /// The application logger. + /// The application paths. + /// The application localization manager. public SkiaEncoder( ILogger logger, IApplicationPaths appPaths, @@ -80,7 +83,7 @@ namespace Jellyfin.Drawing.Skia => new HashSet() { ImageFormat.Webp, ImageFormat.Jpg, ImageFormat.Png }; /// - /// Test to determine if the native lib is available + /// Test to determine if the native lib is available. /// public static void TestSkia() { @@ -288,6 +291,14 @@ namespace Jellyfin.Drawing.Skia } } + /// + /// Decode an image. + /// + /// The filepath of the image to decode. + /// Whether to force clean the bitmap. + /// The orientation of the image. + /// The detected origin of the image. + /// The resulting bitmap of the image. internal SKBitmap Decode(string path, bool forceCleanBitmap, ImageOrientation? orientation, out SKEncodedOrigin origin) { if (!File.Exists(path)) @@ -377,7 +388,7 @@ namespace Jellyfin.Drawing.Skia private SKBitmap OrientImage(SKBitmap bitmap, SKEncodedOrigin origin) { - //var transformations = { + // var transformations = { // 2: { rotate: 0, flip: true}, // 3: { rotate: 180, flip: false}, // 4: { rotate: 180, flip: true}, @@ -385,7 +396,7 @@ namespace Jellyfin.Drawing.Skia // 6: { rotate: 90, flip: false}, // 7: { rotate: 270, flip: true}, // 8: { rotate: 270, flip: false}, - //} + // } switch (origin) { @@ -576,7 +587,7 @@ namespace Jellyfin.Drawing.Skia } // create bitmap to use for canvas drawing used to draw into bitmap - using (var saveBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType)) + using (var saveBitmap = new SKBitmap(width, height)) // , bitmap.ColorType, bitmap.AlphaType)) using (var canvas = new SKCanvas(saveBitmap)) { // set background color if present @@ -629,6 +640,7 @@ namespace Jellyfin.Drawing.Skia } } } + return outputPath; } diff --git a/Jellyfin.Drawing.Skia/StripCollageBuilder.cs b/Jellyfin.Drawing.Skia/StripCollageBuilder.cs index 0a123ea250..0735ef194a 100644 --- a/Jellyfin.Drawing.Skia/StripCollageBuilder.cs +++ b/Jellyfin.Drawing.Skia/StripCollageBuilder.cs @@ -15,6 +15,7 @@ namespace Jellyfin.Drawing.Skia /// /// Initializes a new instance of the class. /// + /// The encoder to use for building collages. public StripCollageBuilder(SkiaEncoder skiaEncoder) { _skiaEncoder = skiaEncoder; @@ -123,6 +124,7 @@ namespace Jellyfin.Drawing.Skia 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); using (var image = SKImage.FromBitmap(resizeBitmap))