From 792a3a728beadd4662beced61f009ef0cfbbe8ea Mon Sep 17 00:00:00 2001 From: Phap Dieu Duong Date: Fri, 31 Jan 2025 20:54:15 +0700 Subject: [PATCH] fixed: Image Booster does not pre load images before switching between images #1482 --- .../Photoing/Services/ImageBooster.cs | 31 ++++++++++++++----- Source/ImageGlass/FrmMain.cs | 3 ++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Source/Components/ImageGlass.Base/Photoing/Services/ImageBooster.cs b/Source/Components/ImageGlass.Base/Photoing/Services/ImageBooster.cs index 766b0fa53..3dbf4e3a6 100644 --- a/Source/Components/ImageGlass.Base/Photoing/Services/ImageBooster.cs +++ b/Source/Components/ImageGlass.Base/Photoing/Services/ImageBooster.cs @@ -205,12 +205,17 @@ await img.LoadAsync(ReadOptions with /// Add index of the image to queue list /// /// Current index of image list - private List GetQueueList(int index) + /// Include current index in the queue list + private List GetQueueList(int index, bool includeCurrentIndex) { // check valid index if (index < 0 || index >= ImgList.Count) return []; - var list = new HashSet { index }; + var list = new HashSet(); + if (includeCurrentIndex) + { + list.Add(index); + } var maxCachedItems = (MaxQueue * 2) + 1; var iRight = index; @@ -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)) { @@ -405,6 +410,20 @@ await ImgList[index].LoadAsync(ReadOptions with } + /// + /// Start caching images. + /// + /// Current index of image list + /// Include current index in the queue list + public void StartCaching(int index, bool includeCurrentIndex) + { + // get queue list according to index + var queueItems = GetQueueList(index, includeCurrentIndex); + + QueuedList.Clear(); + QueuedList.AddRange(queueItems); + } + /// /// Adds a file path @@ -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(); @@ -617,8 +636,6 @@ public void UpdateCache() /// /// Check if the folder path of input filename exists in the list /// - /// - /// public bool ContainsDirPathOf(string filename) { var target = Path.GetDirectoryName(filename)?.ToUpperInvariant(); diff --git a/Source/ImageGlass/FrmMain.cs b/Source/ImageGlass/FrmMain.cs index 8f3358bec..a5ca1cf7a 100644 --- a/Source/ImageGlass/FrmMain.cs +++ b/Source/ImageGlass/FrmMain.cs @@ -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); }