aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Drawing.Skia/SkiaHelper.cs
diff options
context:
space:
mode:
authorPatrick Barron <barronpm@gmail.com>2023-01-10 19:35:06 -0500
committerPatrick Barron <barronpm@gmail.com>2023-01-10 19:35:06 -0500
commit16e33665a217cb6b37d88cca244eb1538d41b873 (patch)
treeb1424449e56c3d7a8dbd950749d546eae625232d /src/Jellyfin.Drawing.Skia/SkiaHelper.cs
parent9a2f2330b7fb796baa74945fa2c74045e12005d5 (diff)
Move Jellyfin.Drawing.Skia to src
Diffstat (limited to 'src/Jellyfin.Drawing.Skia/SkiaHelper.cs')
-rw-r--r--src/Jellyfin.Drawing.Skia/SkiaHelper.cs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/Jellyfin.Drawing.Skia/SkiaHelper.cs b/src/Jellyfin.Drawing.Skia/SkiaHelper.cs
new file mode 100644
index 000000000..23e92dcb2
--- /dev/null
+++ b/src/Jellyfin.Drawing.Skia/SkiaHelper.cs
@@ -0,0 +1,47 @@
+using System.Collections.Generic;
+using SkiaSharp;
+
+namespace Jellyfin.Drawing.Skia
+{
+ /// <summary>
+ /// Class containing helper methods for working with SkiaSharp.
+ /// </summary>
+ public static class SkiaHelper
+ {
+ /// <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;
+
+ while (imagesTested.Count < paths.Count)
+ {
+ if (currentIndex >= paths.Count)
+ {
+ currentIndex = 0;
+ }
+
+ bitmap = skiaEncoder.Decode(paths[currentIndex], false, null, out _);
+
+ imagesTested[currentIndex] = 0;
+
+ currentIndex++;
+
+ if (bitmap is not null)
+ {
+ break;
+ }
+ }
+
+ newIndex = currentIndex;
+ return bitmap;
+ }
+ }
+}