Skip to content

Conversation

@meesoft
Copy link
Owner

@meesoft meesoft commented Jan 17, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved metadata retrieval and caching behavior for image processing operations.
    • Enhanced image format boundary detection for better reliability.
  • Performance Improvements

    • Converted image loading operations to asynchronous processing for improved responsiveness and UI fluidity.
    • Optimized cache refresh workflow to ensure data consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

@meesoft meesoft marked this pull request as ready for review January 17, 2026 15:06
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 17, 2026

Walkthrough

The pull request converts synchronous image preview and metadata loading methods to asynchronous variants across the codebase. Changes include converting LoadPreview to LoadPreviewAsync, LoadImageWithMetadata to LoadImageWithMetadataAsync, updating command handlers to use async lambdas, adjusting bitmap creation options, and refining span slicing operations. Additionally, metadata preloading is now performed within PictureItemViewModel.LoadPreviewAsync.

Changes

Cohort / File(s) Summary
Async Image Loading API
PhotoLocator/PictureItemViewModel.cs, PhotoLocator/JpegTransformCommands.cs
Converts synchronous preview/metadata loading methods to async variants; LoadPreviewLoadPreviewAsync with Task<BitmapSource?> return type; LoadImageWithMetadataLoadImageWithMetadataAsync with Task<(BitmapSource, BitmapMetadata?)> return type; adds metadata preload via LoadMetadataAsync in PictureItemViewModel.LoadPreviewAsync before preview loading.
Command Handler Updates
PhotoLocator/VideoTransformCommands.cs, PhotoLocator/MainViewModel.cs
Converts SetupLocalContrastCommand to async lambda; updates RefreshFolderCommand to clear picture cache; replaces synchronous LoadPreview calls with awaited LoadPreviewAsync calls.
Preview Loading Updates
PhotoLocator/SlideShowWindow.xaml.cs
Removes pre-load thumbnail/metadata call in UpdatePictureAsync; switches to asynchronous LoadPreviewAsync with await; adds clarifying comment in UpdateResampledImage.
Bitmap Creation Options
PhotoLocator/PictureFileFormats/GeneralFileFormatHandler.cs
Adjusts CreateOptions flag to combine PreservePixelFormat with IgnoreColorProfile when preservePixelFormat is true.
Span Slicing Refactoring
PhotoLocator/PictureFileFormats/CR3FileFormatHandler.cs
Replaces Span.Slice calls with range operators (buffer[..length], buffer[index..length]) for header boundary detection in preview and JPEG header search logic.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Command/Caller
    participant PVM as PictureItemViewModel
    participant Metadata as MetadataLoader
    participant BitmapLoader as BitmapSource Loader
    
    Client->>PVM: LoadPreviewAsync(ct, maxWidth, preservePixelFormat)
    activate PVM
    
    alt _metadataString is null
        PVM->>Metadata: LoadMetadataAsync(ct)
        activate Metadata
        Metadata-->>PVM: metadata loaded
        deactivate Metadata
    end
    
    PVM->>BitmapLoader: Load preview bitmap with options
    activate BitmapLoader
    BitmapLoader-->>PVM: BitmapSource
    deactivate BitmapLoader
    
    PVM-->>Client: Task<BitmapSource?>
    deactivate PVM
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 1 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Fix color profile' is vague and overly broad. While the PR does include a color profile change in GeneralFileFormatHandler.cs, the substantial majority of changes involve converting synchronous image loading to asynchronous variants across multiple files. Consider a more descriptive title that reflects the primary refactoring work, such as 'Convert image loading to async/await pattern' or 'Refactor image loading and fix color profile handling'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch features/FixColorProfile

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@PhotoLocator/PictureFileFormats/GeneralFileFormatHandler.cs`:
- Around line 23-25: Current code unconditionally adds
BitmapCreateOptions.IgnoreColorProfile when preservePixelFormat is true, which
suppresses embedded ICC profiles; change this so IgnoreColorProfile is not
applied by default. Update the bitmap.CreateOptions assignment to only include
BitmapCreateOptions.PreservePixelFormat when preservePixelFormat is true, and
add a conditional code path that appends BitmapCreateOptions.IgnoreColorProfile
only when a new explicit signal indicates it's required (e.g., an added
parameter/field like ignoreColorProfileForCorruptMetadata or a helper
IsColorProfileCorrupt(bitmapMetadata) that detects broken profiles). Reference
preservePixelFormat, bitmap.CreateOptions,
BitmapCreateOptions.PreservePixelFormat and
BitmapCreateOptions.IgnoreColorProfile to locate and adjust the logic; ensure
BitmapCacheOption.OnLoad remains unchanged.

In `@PhotoLocator/SlideShowWindow.xaml.cs`:
- Around line 133-136: The preview load can overlap with subsequent timer ticks;
wrap the async load in a version/cancellation guard and only restart the
DispatcherTimer after applying the preview: increment a private int version
field (e.g., _pictureLoadVersion) at the start of UpdatePictureAsync, capture it
into a local variable before awaiting SelectedPicture.LoadPreviewAsync, then
after the await verify the local version still equals _pictureLoadVersion before
assigning _sourceImage and calling UpdateResampledImage; also stop or avoid
starting _timer until after the successful guarded update so ticks won't trigger
concurrent loads.
🧹 Nitpick comments (1)
PhotoLocator/JpegTransformCommands.cs (1)

131-155: CancellationToken not propagated to async operations.

The method uses default for the cancellation token on line 134, but in BatchProcessLocalContrastAsync (line 192), the caller has access to ct. This means batch processing cancellation won't interrupt ongoing LoadPreviewAsync calls.

Consider accepting a CancellationToken parameter:

♻️ Suggested refactor
-private static async Task<(BitmapSource, BitmapMetadata?)> LoadImageWithMetadataAsync(PictureItemViewModel item)
+private static async Task<(BitmapSource, BitmapMetadata?)> LoadImageWithMetadataAsync(PictureItemViewModel item, CancellationToken ct = default)
 {
     BitmapMetadata? metadata = null;
-    var image = await item.LoadPreviewAsync(default, int.MaxValue, preservePixelFormat: true);
+    var image = await item.LoadPreviewAsync(ct, int.MaxValue, preservePixelFormat: true);

@meesoft meesoft merged commit 83f5460 into main Jan 17, 2026
5 checks passed
@meesoft meesoft deleted the features/FixColorProfile branch January 17, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants