using System.Collections.Generic;
using SkiaSharp;
namespace Jellyfin.Drawing.Skia
{
///
/// Class containing helper methods for working with SkiaSharp.
///
public static class SkiaHelper
{
///
/// Gets the next valid image as a bitmap.
///
/// The current skia encoder.
/// The list of image paths.
/// The current checked index.
/// The new index.
/// A valid bitmap, or null if no bitmap exists after currentIndex.
public static SKBitmap? GetNextValidImage(SkiaEncoder skiaEncoder, IReadOnlyList paths, int currentIndex, out int newIndex)
{
var imagesTested = new Dictionary();
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;
}
}
}