| | 1 | | using System.Collections.Generic; |
| | 2 | | using SkiaSharp; |
| | 3 | |
|
| | 4 | | namespace Jellyfin.Drawing.Skia; |
| | 5 | |
|
| | 6 | | /// <summary> |
| | 7 | | /// Class containing helper methods for working with SkiaSharp. |
| | 8 | | /// </summary> |
| | 9 | | public static class SkiaHelper |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Gets the next valid image as a bitmap. |
| | 13 | | /// </summary> |
| | 14 | | /// <param name="skiaEncoder">The current skia encoder.</param> |
| | 15 | | /// <param name="paths">The list of image paths.</param> |
| | 16 | | /// <param name="currentIndex">The current checked index.</param> |
| | 17 | | /// <param name="newIndex">The new index.</param> |
| | 18 | | /// <returns>A valid bitmap, or null if no bitmap exists after <c>currentIndex</c>.</returns> |
| | 19 | | public static SKBitmap? GetNextValidImage(SkiaEncoder skiaEncoder, IReadOnlyList<string> paths, int currentIndex, ou |
| | 20 | | { |
| 0 | 21 | | var imagesTested = new Dictionary<int, int>(); |
| | 22 | |
|
| 0 | 23 | | while (imagesTested.Count < paths.Count) |
| | 24 | | { |
| 0 | 25 | | if (currentIndex >= paths.Count) |
| | 26 | | { |
| 0 | 27 | | currentIndex = 0; |
| | 28 | | } |
| | 29 | |
|
| 0 | 30 | | SKBitmap? bitmap = skiaEncoder.Decode(paths[currentIndex], false, null, out _); |
| | 31 | |
|
| 0 | 32 | | imagesTested[currentIndex] = 0; |
| | 33 | |
|
| 0 | 34 | | currentIndex++; |
| | 35 | |
|
| 0 | 36 | | if (bitmap is not null) |
| | 37 | | { |
| 0 | 38 | | newIndex = currentIndex; |
| 0 | 39 | | return bitmap; |
| | 40 | | } |
| | 41 | | } |
| | 42 | |
|
| 0 | 43 | | newIndex = currentIndex; |
| 0 | 44 | | return null; |
| | 45 | | } |
| | 46 | | } |