Skip to content

Commit 792a3a7

Browse files
committed
fixed: Image Booster does not pre load images before switching between images #1482
1 parent 46b8e59 commit 792a3a7

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

Source/Components/ImageGlass.Base/Photoing/Services/ImageBooster.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,17 @@ await img.LoadAsync(ReadOptions with
205205
/// Add index of the image to queue list
206206
/// </summary>
207207
/// <param name="index">Current index of image list</param>
208-
private List<int> GetQueueList(int index)
208+
/// <param name="includeCurrentIndex">Include current index in the queue list</param>
209+
private List<int> GetQueueList(int index, bool includeCurrentIndex)
209210
{
210211
// check valid index
211212
if (index < 0 || index >= ImgList.Count) return [];
212213

213-
var list = new HashSet<int> { index };
214+
var list = new HashSet<int>();
215+
if (includeCurrentIndex)
216+
{
217+
list.Add(index);
218+
}
214219

215220
var maxCachedItems = (MaxQueue * 2) + 1;
216221
var iRight = index;
@@ -366,8 +371,8 @@ await ImgList[index].LoadAsync(ReadOptions with
366371
// get image data from cache
367372
else
368373
{
369-
// update queue list according to index
370-
var queueItems = GetQueueList(index);
374+
// get queue list according to index
375+
var queueItems = GetQueueList(index, true);
371376

372377
if (!queueItems.Contains(index))
373378
{
@@ -405,6 +410,20 @@ await ImgList[index].LoadAsync(ReadOptions with
405410
}
406411

407412

413+
/// <summary>
414+
/// Start caching images.
415+
/// </summary>
416+
/// <param name="index">Current index of image list</param>
417+
/// <param name="includeCurrentIndex">Include current index in the queue list</param>
418+
public void StartCaching(int index, bool includeCurrentIndex)
419+
{
420+
// get queue list according to index
421+
var queueItems = GetQueueList(index, includeCurrentIndex);
422+
423+
QueuedList.Clear();
424+
QueuedList.AddRange(queueItems);
425+
}
426+
408427

409428
/// <summary>
410429
/// Adds a file path
@@ -603,7 +622,7 @@ public void UpdateCache()
603622
.Select(item => item.Index)
604623
.ToList();
605624

606-
// release the cachced images
625+
// release the cached images
607626
foreach (var index in cachedIndexList)
608627
{
609628
ImgList[index].Dispose();
@@ -617,8 +636,6 @@ public void UpdateCache()
617636
/// <summary>
618637
/// Check if the folder path of input filename exists in the list
619638
/// </summary>
620-
/// <param name="filename"></param>
621-
/// <returns></returns>
622639
public bool ContainsDirPathOf(string filename)
623640
{
624641
var target = Path.GetDirectoryName(filename)?.ToUpperInvariant();

Source/ImageGlass/FrmMain.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,9 @@ private void HandleImageList_Loaded(ImageListLoadedEventArgs e)
11691169

11701170
LoadImageInfo(ImageInfoUpdateTypes.ListCount);
11711171

1172+
// start image caching, don't cache the current index
1173+
Local.Images.StartCaching(Local.CurrentIndex, false);
1174+
11721175
// Load thumnbnail
11731176
BHelper.RunAsThread(LoadGallery);
11741177
}

0 commit comments

Comments
 (0)