Skip to content

Commit

Permalink
fixed: Image Booster does not pre load images before switching betwee…
Browse files Browse the repository at this point in the history
…n images #1482
  • Loading branch information
d2phap committed Jan 31, 2025
1 parent 46b8e59 commit 792a3a7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,17 @@ await img.LoadAsync(ReadOptions with
/// Add index of the image to queue list
/// </summary>
/// <param name="index">Current index of image list</param>
private List<int> GetQueueList(int index)
/// <param name="includeCurrentIndex">Include current index in the queue list</param>
private List<int> GetQueueList(int index, bool includeCurrentIndex)
{
// check valid index
if (index < 0 || index >= ImgList.Count) return [];

var list = new HashSet<int> { index };
var list = new HashSet<int>();
if (includeCurrentIndex)
{
list.Add(index);
}

var maxCachedItems = (MaxQueue * 2) + 1;
var iRight = index;
Expand Down Expand Up @@ -366,8 +371,8 @@ await ImgList[index].LoadAsync(ReadOptions with
// get image data from cache
else
{
// update queue list according to index
var queueItems = GetQueueList(index);
// get queue list according to index
var queueItems = GetQueueList(index, true);

if (!queueItems.Contains(index))
{
Expand Down Expand Up @@ -405,6 +410,20 @@ await ImgList[index].LoadAsync(ReadOptions with
}


/// <summary>
/// Start caching images.
/// </summary>
/// <param name="index">Current index of image list</param>
/// <param name="includeCurrentIndex">Include current index in the queue list</param>
public void StartCaching(int index, bool includeCurrentIndex)
{
// get queue list according to index
var queueItems = GetQueueList(index, includeCurrentIndex);

QueuedList.Clear();
QueuedList.AddRange(queueItems);
}


/// <summary>
/// Adds a file path
Expand Down Expand Up @@ -603,7 +622,7 @@ public void UpdateCache()
.Select(item => item.Index)
.ToList();

// release the cachced images
// release the cached images
foreach (var index in cachedIndexList)
{
ImgList[index].Dispose();
Expand All @@ -617,8 +636,6 @@ public void UpdateCache()
/// <summary>
/// Check if the folder path of input filename exists in the list
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public bool ContainsDirPathOf(string filename)
{
var target = Path.GetDirectoryName(filename)?.ToUpperInvariant();
Expand Down
3 changes: 3 additions & 0 deletions Source/ImageGlass/FrmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,9 @@ private void HandleImageList_Loaded(ImageListLoadedEventArgs e)

LoadImageInfo(ImageInfoUpdateTypes.ListCount);

// start image caching, don't cache the current index
Local.Images.StartCaching(Local.CurrentIndex, false);

// Load thumnbnail
BHelper.RunAsThread(LoadGallery);
}
Expand Down

0 comments on commit 792a3a7

Please sign in to comment.