2021-08-15 18:32:08 +00:00
|
|
|
using System.Collections.Generic;
|
2019-09-15 04:27:42 +00:00
|
|
|
using SkiaSharp;
|
|
|
|
|
|
|
|
namespace Jellyfin.Drawing.Skia
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Class containing helper methods for working with SkiaSharp.
|
|
|
|
/// </summary>
|
|
|
|
public static class SkiaHelper
|
|
|
|
{
|
2021-08-15 18:32:08 +00:00
|
|
|
/// <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>
|
2022-08-15 10:48:34 +00:00
|
|
|
/// <param name="currentIndex">The current checked index.</param>
|
2021-08-15 18:32:08 +00:00
|
|
|
/// <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 != null)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newIndex = currentIndex;
|
|
|
|
return bitmap;
|
|
|
|
}
|
2019-09-15 04:27:42 +00:00
|
|
|
}
|
|
|
|
}
|