using System.Collections.Generic;
using SkiaSharp;
namespace Jellyfin.Drawing.Skia
{
///
/// Class containing helper methods for working with SkiaSharp.
///
public static class SkiaHelper
{
///
/// Ensures the result is a success
/// by throwing an exception when that's not the case.
///
/// The result returned by Skia.
public static void EnsureSuccess(SKCodecResult result)
{
if (result != SKCodecResult.Success)
{
throw new SkiaCodecException(result);
}
}
///
/// Gets the next valid image as a bitmap.
///
/// The current skia encoder.
/// The list of image paths.
/// The current checked indes.
/// 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;
}
}
}