Merge pull request #9065 from barronpm/drawing-use-file-namespaces
commit
515e69dcf7
@ -1,48 +1,47 @@
|
||||
using MediaBrowser.Model.Drawing;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Jellyfin.Drawing.Skia
|
||||
namespace Jellyfin.Drawing.Skia;
|
||||
|
||||
/// <summary>
|
||||
/// Static helper class for drawing 'played' indicators.
|
||||
/// </summary>
|
||||
public static class PlayedIndicatorDrawer
|
||||
{
|
||||
private const int OffsetFromTopRightCorner = 38;
|
||||
|
||||
/// <summary>
|
||||
/// Static helper class for drawing 'played' indicators.
|
||||
/// Draw a 'played' indicator in the top right corner of a canvas.
|
||||
/// </summary>
|
||||
public static class PlayedIndicatorDrawer
|
||||
/// <param name="canvas">The canvas to draw the indicator on.</param>
|
||||
/// <param name="imageSize">
|
||||
/// The dimensions of the image to draw the indicator on. The width is used to determine the x-position of the
|
||||
/// indicator.
|
||||
/// </param>
|
||||
public static void DrawPlayedIndicator(SKCanvas canvas, ImageDimensions imageSize)
|
||||
{
|
||||
private const int OffsetFromTopRightCorner = 38;
|
||||
|
||||
/// <summary>
|
||||
/// Draw a 'played' indicator in the top right corner of a canvas.
|
||||
/// </summary>
|
||||
/// <param name="canvas">The canvas to draw the indicator on.</param>
|
||||
/// <param name="imageSize">
|
||||
/// The dimensions of the image to draw the indicator on. The width is used to determine the x-position of the
|
||||
/// indicator.
|
||||
/// </param>
|
||||
public static void DrawPlayedIndicator(SKCanvas canvas, ImageDimensions imageSize)
|
||||
{
|
||||
var x = imageSize.Width - OffsetFromTopRightCorner;
|
||||
var x = imageSize.Width - OffsetFromTopRightCorner;
|
||||
|
||||
using var paint = new SKPaint
|
||||
{
|
||||
Color = SKColor.Parse("#CC00A4DC"),
|
||||
Style = SKPaintStyle.Fill
|
||||
};
|
||||
using var paint = new SKPaint
|
||||
{
|
||||
Color = SKColor.Parse("#CC00A4DC"),
|
||||
Style = SKPaintStyle.Fill
|
||||
};
|
||||
|
||||
canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint);
|
||||
canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint);
|
||||
|
||||
paint.Color = new SKColor(255, 255, 255, 255);
|
||||
paint.TextSize = 30;
|
||||
paint.IsAntialias = true;
|
||||
paint.Color = new SKColor(255, 255, 255, 255);
|
||||
paint.TextSize = 30;
|
||||
paint.IsAntialias = true;
|
||||
|
||||
// or:
|
||||
// var emojiChar = 0x1F680;
|
||||
const string Text = "✔️";
|
||||
var emojiChar = StringUtilities.GetUnicodeCharacterCode(Text, SKTextEncoding.Utf32);
|
||||
// or:
|
||||
// var emojiChar = 0x1F680;
|
||||
const string Text = "✔️";
|
||||
var emojiChar = StringUtilities.GetUnicodeCharacterCode(Text, SKTextEncoding.Utf32);
|
||||
|
||||
// ask the font manager for a font with that character
|
||||
paint.Typeface = SKFontManager.Default.MatchCharacter(emojiChar);
|
||||
// ask the font manager for a font with that character
|
||||
paint.Typeface = SKFontManager.Default.MatchCharacter(emojiChar);
|
||||
|
||||
canvas.DrawText(Text, (float)x - 12, OffsetFromTopRightCorner + 12, paint);
|
||||
}
|
||||
canvas.DrawText(Text, (float)x - 12, OffsetFromTopRightCorner + 12, paint);
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +1,44 @@
|
||||
using System.Globalization;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Jellyfin.Drawing.Skia
|
||||
namespace Jellyfin.Drawing.Skia;
|
||||
|
||||
/// <summary>
|
||||
/// Represents errors that occur during interaction with Skia codecs.
|
||||
/// </summary>
|
||||
public class SkiaCodecException : SkiaException
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents errors that occur during interaction with Skia codecs.
|
||||
/// Initializes a new instance of the <see cref="SkiaCodecException" /> class.
|
||||
/// </summary>
|
||||
public class SkiaCodecException : SkiaException
|
||||
/// <param name="result">The non-successful codec result returned by Skia.</param>
|
||||
public SkiaCodecException(SKCodecResult result)
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SkiaCodecException" /> class.
|
||||
/// </summary>
|
||||
/// <param name="result">The non-successful codec result returned by Skia.</param>
|
||||
public SkiaCodecException(SKCodecResult result)
|
||||
{
|
||||
CodecResult = result;
|
||||
}
|
||||
CodecResult = result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SkiaCodecException" /> class
|
||||
/// with a specified error message.
|
||||
/// </summary>
|
||||
/// <param name="result">The non-successful codec result returned by Skia.</param>
|
||||
/// <param name="message">The message that describes the error.</param>
|
||||
public SkiaCodecException(SKCodecResult result, string message)
|
||||
: base(message)
|
||||
{
|
||||
CodecResult = result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SkiaCodecException" /> class
|
||||
/// with a specified error message.
|
||||
/// </summary>
|
||||
/// <param name="result">The non-successful codec result returned by Skia.</param>
|
||||
/// <param name="message">The message that describes the error.</param>
|
||||
public SkiaCodecException(SKCodecResult result, string message)
|
||||
: base(message)
|
||||
{
|
||||
CodecResult = result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the non-successful codec result returned by Skia.
|
||||
/// </summary>
|
||||
public SKCodecResult CodecResult { get; }
|
||||
/// <summary>
|
||||
/// Gets the non-successful codec result returned by Skia.
|
||||
/// </summary>
|
||||
public SKCodecResult CodecResult { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
=> string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"Non-success codec result: {0}\n{1}",
|
||||
CodecResult,
|
||||
base.ToString());
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
=> string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"Non-success codec result: {0}\n{1}",
|
||||
CodecResult,
|
||||
base.ToString());
|
||||
}
|
||||
|
@ -1,39 +1,38 @@
|
||||
using System;
|
||||
|
||||
namespace Jellyfin.Drawing.Skia
|
||||
namespace Jellyfin.Drawing.Skia;
|
||||
|
||||
/// <summary>
|
||||
/// Represents errors that occur during interaction with Skia.
|
||||
/// </summary>
|
||||
public class SkiaException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents errors that occur during interaction with Skia.
|
||||
/// Initializes a new instance of the <see cref="SkiaException"/> class.
|
||||
/// </summary>
|
||||
public class SkiaException : Exception
|
||||
public SkiaException()
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SkiaException"/> class.
|
||||
/// </summary>
|
||||
public SkiaException()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SkiaException"/> class with a specified error message.
|
||||
/// </summary>
|
||||
/// <param name="message">The message that describes the error.</param>
|
||||
public SkiaException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SkiaException"/> class with a specified error message.
|
||||
/// </summary>
|
||||
/// <param name="message">The message that describes the error.</param>
|
||||
public SkiaException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SkiaException"/> class with a specified error message and a
|
||||
/// reference to the inner exception that is the cause of this exception.
|
||||
/// </summary>
|
||||
/// <param name="message">The error message that explains the reason for the exception.</param>
|
||||
/// <param name="innerException">
|
||||
/// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if
|
||||
/// no inner exception is specified.
|
||||
/// </param>
|
||||
public SkiaException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SkiaException"/> class with a specified error message and a
|
||||
/// reference to the inner exception that is the cause of this exception.
|
||||
/// </summary>
|
||||
/// <param name="message">The error message that explains the reason for the exception.</param>
|
||||
/// <param name="innerException">
|
||||
/// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if
|
||||
/// no inner exception is specified.
|
||||
/// </param>
|
||||
public SkiaException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -1,47 +1,46 @@
|
||||
using System.Collections.Generic;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Jellyfin.Drawing.Skia
|
||||
namespace Jellyfin.Drawing.Skia;
|
||||
|
||||
/// <summary>
|
||||
/// Class containing helper methods for working with SkiaSharp.
|
||||
/// </summary>
|
||||
public static class SkiaHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Class containing helper methods for working with SkiaSharp.
|
||||
/// Gets the next valid image as a bitmap.
|
||||
/// </summary>
|
||||
public static class SkiaHelper
|
||||
/// <param name="skiaEncoder">The current skia encoder.</param>
|
||||
/// <param name="paths">The list of image paths.</param>
|
||||
/// <param name="currentIndex">The current checked index.</param>
|
||||
/// <param name="newIndex">The new index.</param>
|
||||
/// <returns>A valid bitmap, or null if no bitmap exists after <c>currentIndex</c>.</returns>
|
||||
public static SKBitmap? GetNextValidImage(SkiaEncoder skiaEncoder, IReadOnlyList<string> paths, int currentIndex, out int newIndex)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the next valid image as a bitmap.
|
||||
/// </summary>
|
||||
/// <param name="skiaEncoder">The current skia encoder.</param>
|
||||
/// <param name="paths">The list of image paths.</param>
|
||||
/// <param name="currentIndex">The current checked index.</param>
|
||||
/// <param name="newIndex">The new index.</param>
|
||||
/// <returns>A valid bitmap, or null if no bitmap exists after <c>currentIndex</c>.</returns>
|
||||
public static SKBitmap? GetNextValidImage(SkiaEncoder skiaEncoder, IReadOnlyList<string> paths, int currentIndex, out int newIndex)
|
||||
{
|
||||
var imagesTested = new Dictionary<int, int>();
|
||||
SKBitmap? bitmap = null;
|
||||
var imagesTested = new Dictionary<int, int>();
|
||||
SKBitmap? bitmap = null;
|
||||
|
||||
while (imagesTested.Count < paths.Count)
|
||||
while (imagesTested.Count < paths.Count)
|
||||
{
|
||||
if (currentIndex >= paths.Count)
|
||||
{
|
||||
if (currentIndex >= paths.Count)
|
||||
{
|
||||
currentIndex = 0;
|
||||
}
|
||||
currentIndex = 0;
|
||||
}
|
||||
|
||||
bitmap = skiaEncoder.Decode(paths[currentIndex], false, null, out _);
|
||||
bitmap = skiaEncoder.Decode(paths[currentIndex], false, null, out _);
|
||||
|
||||
imagesTested[currentIndex] = 0;
|
||||
imagesTested[currentIndex] = 0;
|
||||
|
||||
currentIndex++;
|
||||
currentIndex++;
|
||||
|
||||
if (bitmap is not null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (bitmap is not null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
newIndex = currentIndex;
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
newIndex = currentIndex;
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue