From 88928118eb51b121aed0348494ef7456c1c55379 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Fri, 13 Dec 2019 20:57:23 +0100 Subject: [PATCH] Add missing documentation in Jellyfun.Drawing.Skia --- Jellyfin.Drawing.Skia/PercentPlayedDrawer.cs | 9 +++++++ .../PlayedIndicatorDrawer.cs | 11 ++++++++ Jellyfin.Drawing.Skia/SkiaEncoder.cs | 21 ++++++++++++++++ Jellyfin.Drawing.Skia/StripCollageBuilder.cs | 25 +++++++++++++++++++ .../UnplayedCountIndicator.cs | 15 +++++++++++ .../Drawing/IImageEncoder.cs | 16 ++++++++---- 6 files changed, 92 insertions(+), 5 deletions(-) diff --git a/Jellyfin.Drawing.Skia/PercentPlayedDrawer.cs b/Jellyfin.Drawing.Skia/PercentPlayedDrawer.cs index c72f295fdd..f2df066ec8 100644 --- a/Jellyfin.Drawing.Skia/PercentPlayedDrawer.cs +++ b/Jellyfin.Drawing.Skia/PercentPlayedDrawer.cs @@ -4,10 +4,19 @@ using SkiaSharp; namespace Jellyfin.Drawing.Skia { + /// + /// Static helper class used to draw percentage-played indicators on images. + /// public static class PercentPlayedDrawer { private const int IndicatorHeight = 8; + /// + /// Draw a percentage played indicator on a canvas. + /// + /// The canvas to draw the indicator on. + /// The size of the image being drawn on. + /// The percentage played to display with the indicator. public static void Process(SKCanvas canvas, ImageDimensions imageSize, double percent) { using (var paint = new SKPaint()) diff --git a/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs b/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs index 7f3c18bb24..9842c33fc0 100644 --- a/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs +++ b/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs @@ -3,10 +3,21 @@ using SkiaSharp; namespace Jellyfin.Drawing.Skia { + /// + /// Static helper class for drawing 'played' indicators. + /// public static class PlayedIndicatorDrawer { private const int OffsetFromTopRightCorner = 38; + /// + /// Draw a 'played' indicator in the top right corner of a canvas. + /// + /// The canvas to draw the indicator on. + /// + /// The dimensions of the image to draw the indicator on. The width is used to determine the x-position of the + /// indicator. + /// public static void DrawPlayedIndicator(SKCanvas canvas, ImageDimensions imageSize) { var x = imageSize.Width - OffsetFromTopRightCorner; diff --git a/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/Jellyfin.Drawing.Skia/SkiaEncoder.cs index 66b814f6eb..05d9bfdd64 100644 --- a/Jellyfin.Drawing.Skia/SkiaEncoder.cs +++ b/Jellyfin.Drawing.Skia/SkiaEncoder.cs @@ -13,6 +13,9 @@ using static Jellyfin.Drawing.Skia.SkiaHelper; namespace Jellyfin.Drawing.Skia { + /// + /// Image encoder that uses to manipulate images. + /// public class SkiaEncoder : IImageEncoder { private readonly ILogger _logger; @@ -22,6 +25,9 @@ namespace Jellyfin.Drawing.Skia private static readonly HashSet _transparentImageTypes = new HashSet(StringComparer.OrdinalIgnoreCase) { ".png", ".gif", ".webp" }; + /// + /// Initializes a new instance of the class. + /// public SkiaEncoder( ILogger logger, IApplicationPaths appPaths, @@ -32,12 +38,16 @@ namespace Jellyfin.Drawing.Skia _localizationManager = localizationManager; } + /// public string Name => "Skia"; + /// public bool SupportsImageCollageCreation => true; + /// public bool SupportsImageEncoding => true; + /// public IReadOnlyCollection SupportedInputFormats => new HashSet(StringComparer.OrdinalIgnoreCase) { @@ -65,6 +75,7 @@ namespace Jellyfin.Drawing.Skia "arw" }; + /// public IReadOnlyCollection SupportedOutputFormats => new HashSet() { ImageFormat.Webp, ImageFormat.Jpg, ImageFormat.Png }; @@ -80,6 +91,11 @@ namespace Jellyfin.Drawing.Skia private static bool IsTransparent(SKColor color) => (color.Red == 255 && color.Green == 255 && color.Blue == 255) || color.Alpha == 0; + /// + /// Convert a to a . + /// + /// The format to convert. + /// The converted format. public static SKEncodedImageFormat GetImageFormat(ImageFormat selectedFormat) { switch (selectedFormat) @@ -186,6 +202,9 @@ namespace Jellyfin.Drawing.Skia } /// + /// If path is null. + /// If the path is not valid. + /// If the file at the specified path could not be used to generate a codec. public ImageDimensions GetImageSize(string path) { if (path == null) @@ -497,6 +516,7 @@ namespace Jellyfin.Drawing.Skia } } + /// public string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, ImageOrientation? orientation, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat) { if (string.IsNullOrWhiteSpace(inputPath)) @@ -612,6 +632,7 @@ namespace Jellyfin.Drawing.Skia return outputPath; } + /// public void CreateImageCollage(ImageCollageOptions options) { double ratio = (double)options.Width / options.Height; diff --git a/Jellyfin.Drawing.Skia/StripCollageBuilder.cs b/Jellyfin.Drawing.Skia/StripCollageBuilder.cs index 1f2a6e81a4..0a123ea250 100644 --- a/Jellyfin.Drawing.Skia/StripCollageBuilder.cs +++ b/Jellyfin.Drawing.Skia/StripCollageBuilder.cs @@ -5,15 +5,26 @@ using SkiaSharp; namespace Jellyfin.Drawing.Skia { + /// + /// Used to build collages of multiple images arranged in vertical strips. + /// public class StripCollageBuilder { private readonly SkiaEncoder _skiaEncoder; + /// + /// Initializes a new instance of the class. + /// public StripCollageBuilder(SkiaEncoder skiaEncoder) { _skiaEncoder = skiaEncoder; } + /// + /// Check which format an image has been encoded with using its filename extension. + /// + /// The path to the image to get the format for. + /// The image format. public static SKEncodedImageFormat GetEncodedFormat(string outputPath) { if (outputPath == null) @@ -48,6 +59,13 @@ namespace Jellyfin.Drawing.Skia return SKEncodedImageFormat.Png; } + /// + /// Create a square collage. + /// + /// The paths of the images to use in the collage. + /// The path at which to place the resulting collage image. + /// The desired width of the collage. + /// The desired height of the collage. public void BuildSquareCollage(string[] paths, string outputPath, int width, int height) { using (var bitmap = BuildSquareCollageBitmap(paths, width, height)) @@ -58,6 +76,13 @@ namespace Jellyfin.Drawing.Skia } } + /// + /// Create a thumb collage. + /// + /// The paths of the images to use in the collage. + /// The path at which to place the resulting image. + /// The desired width of the collage. + /// The desired height of the collage. public void BuildThumbCollage(string[] paths, string outputPath, int width, int height) { using (var bitmap = BuildThumbCollageBitmap(paths, width, height)) diff --git a/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs b/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs index dbf935f4e7..5cab1115fb 100644 --- a/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs +++ b/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs @@ -4,10 +4,25 @@ using SkiaSharp; namespace Jellyfin.Drawing.Skia { + /// + /// Static helper class for drawing unplayed count indicators. + /// public static class UnplayedCountIndicator { + /// + /// The x-offset used when drawing an unplayed count indicator. + /// private const int OffsetFromTopRightCorner = 38; + /// + /// Draw an unplayed count indicator in the top right corner of a canvas. + /// + /// The canvas to draw the indicator on. + /// + /// The dimensions of the image to draw the indicator on. The width is used to determine the x-position of the + /// indicator. + /// + /// The number to draw in the indicator. public static void DrawUnplayedCountIndicator(SKCanvas canvas, ImageDimensions imageSize, int count) { var x = imageSize.Width - OffsetFromTopRightCorner; diff --git a/MediaBrowser.Controller/Drawing/IImageEncoder.cs b/MediaBrowser.Controller/Drawing/IImageEncoder.cs index a0f9ae46e4..88e67b6486 100644 --- a/MediaBrowser.Controller/Drawing/IImageEncoder.cs +++ b/MediaBrowser.Controller/Drawing/IImageEncoder.cs @@ -11,6 +11,7 @@ namespace MediaBrowser.Controller.Drawing /// /// The supported input formats. IReadOnlyCollection SupportedInputFormats { get; } + /// /// Gets the supported output formats. /// @@ -18,9 +19,9 @@ namespace MediaBrowser.Controller.Drawing IReadOnlyCollection SupportedOutputFormats { get; } /// - /// Gets the name. + /// Gets the display name for the encoder. /// - /// The name. + /// The display name. string Name { get; } /// @@ -35,17 +36,22 @@ namespace MediaBrowser.Controller.Drawing /// true if [supports image encoding]; otherwise, false. bool SupportsImageEncoding { get; } + /// + /// Get the dimensions of an image from the filesystem. + /// + /// The filepath of the image. + /// The image dimensions. ImageDimensions GetImageSize(string path); /// - /// Encodes the image. + /// Encode an image. /// string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, ImageOrientation? orientation, int quality, ImageProcessingOptions options, ImageFormat outputFormat); /// - /// Creates the image collage. + /// Create an image collage. /// - /// The options. + /// The options to use when creating the collage. void CreateImageCollage(ImageCollageOptions options); } }