Skip to content

Fix CMYK PSD color preview#74

Merged
meesoft merged 4 commits intomainfrom
features/UpdatePsdPlugin
Mar 17, 2026
Merged

Fix CMYK PSD color preview#74
meesoft merged 4 commits intomainfrom
features/UpdatePsdPlugin

Conversation

@meesoft
Copy link
Owner

@meesoft meesoft commented Mar 15, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Fixed CMYK image handling for Photoshop files so pixel values are now processed correctly.
  • Improvements

    • Improved error messages and validation around multi‑plane image processing.
    • Added support for cancelling Photoshop layer loading to make aborting large imports responsive.
    • Normalized bitmap metadata string format for clearer display.
  • Chores

    • Cleaned up project file entries and updated a plugin subcomponent reference.

@meesoft meesoft changed the title Update PsdPlugin Fix CMYK PSD color preview Mar 15, 2026
@meesoft meesoft marked this pull request as ready for review March 15, 2026 10:28
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ce4d28fc-2063-4fe8-b463-9a6fe3bc01a8

📥 Commits

Reviewing files that changed from the base of the PR and between f8cb95e and bb9b5eb.

📒 Files selected for processing (1)
  • PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs

Walkthrough

Updates across PhotoLocator: FloatBitmap string/error text changes; a Debug.Assert added to IIRSmoothOperation; CMYK 8-bit channel bytes are inverted during PSD loading; removed explicit empty-folder entries from the PhotoshopImageLoader project; submodule commit hash bumped.

Changes

Cohort / File(s) Summary
BitmapOperations
PhotoLocator/BitmapOperations/FloatBitmap.cs, PhotoLocator/BitmapOperations/IIRSmoothOperation.cs
FloatBitmap.ToString() format changed to "WidthxHeightxPlaneCount" and ProcessElementWise error now includes actual PlaneCount. IIRSmoothOperation.Apply adds Debug.Assert(plane.PlaneCount == 1) (runtime-only debug check).
Image Format Processing
PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs
PSD loader: checks ct.ThrowIfCancellationRequested() during layer iteration and switches CMYK 8-bit channel extraction to use an inverted routine (dest = 255 - source) when assembling channels.
Project Configuration
PhotoshopImageLoader/PhotoLocator.PhotoshopImageLoader.csproj
Removed explicit Folder include entries for PsdFile\Compression, PsdFile\ImageResources, and PsdFile\Layers\LayerInfo.
Submodule
PsdPlugin
Subproject commit hash updated (no code changes).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Update to .net10 #55 — modifies the same PhotoLocator/BitmapOperations/FloatBitmap.cs class and may overlap with these FloatBitmap changes.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix CMYK PSD color preview' directly describes the main change: inverting CMYK channel pixels during Photoshop file loading to fix color preview rendering.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch features/UpdatePsdPlugin
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

You can disable sequence diagrams in the walkthrough.

Disable the reviews.sequence_diagrams setting to disable sequence diagrams in the walkthrough.

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.

🧹 Nitpick comments (1)
PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs (1)

71-74: Correct fix for CMYK color space conversion.

PSD files store CMYK as ink density (0 = no ink, 255 = full ink), while WPF's Cmyk32 expects the inverse (255 = no ink). The byte inversion correctly resolves this mismatch.

Minor optimization: the inversion could be folded into the parallel extraction to avoid a second pass over the pixel array, though the current approach is perfectly acceptable for typical image sizes.

♻️ Optional: Merge inversion into parallel loop
 if (psd.BitDepth == 8)
 {
     var pixels = new byte[layer.Rect.Width * layer.Rect.Height * 4];
-    Parallel.For(0, 4, ch => GetChannelPixels8(layer.Channels.GetId(ch), pixels, ch, 4));
-    for (int i = 0; i < pixels.Length; i++)
-        pixels[i] = (byte)(255 - pixels[i]);
+    Parallel.For(0, 4, ch => GetChannelPixels8Inverted(layer.Channels.GetId(ch), pixels, ch, 4));
     return BitmapSource.Create(layer.Rect.Width, layer.Rect.Height, 96, 96, PixelFormats.Cmyk32, null,
         pixels, layer.Rect.Width * 4);
 }

Add a new helper method:

private static void GetChannelPixels8Inverted(Channel channel, byte[] dest, int offset, int dist)
{
    var size = channel.Rect.Width * channel.Rect.Height;
    var source = channel.ImageData;
    for (int iSrc = 0, iDst = offset; iSrc < size; iSrc++, iDst += dist)
        dest[iDst] = (byte)(255 - source[iSrc]);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs` around lines
71 - 74, PSD CMYK channels store ink density (0=no ink, 255=full ink) but WPF's
Cmyk32 expects the inverse, so keep the byte inversion when building the pixel
buffer in PhotoshopFileFormatHandler (the current two-pass inversion is
correct); as an optional optimization, avoid the separate inversion loop by
folding inversion into the channel extraction step—add a helper like
GetChannelPixels8Inverted and call it in place of the current GetChannelPixels8
so the pixels array is filled already inverted before calling
BitmapSource.Create.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs`:
- Around line 71-74: PSD CMYK channels store ink density (0=no ink, 255=full
ink) but WPF's Cmyk32 expects the inverse, so keep the byte inversion when
building the pixel buffer in PhotoshopFileFormatHandler (the current two-pass
inversion is correct); as an optional optimization, avoid the separate inversion
loop by folding inversion into the channel extraction step—add a helper like
GetChannelPixels8Inverted and call it in place of the current GetChannelPixels8
so the pixels array is filled already inverted before calling
BitmapSource.Create.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e97f77c1-4ebf-40ff-927e-9ad083457d7e

📥 Commits

Reviewing files that changed from the base of the PR and between 33762d6 and f8cb95e.

📒 Files selected for processing (5)
  • PhotoLocator/BitmapOperations/FloatBitmap.cs
  • PhotoLocator/BitmapOperations/IIRSmoothOperation.cs
  • PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs
  • PhotoshopImageLoader/PhotoLocator.PhotoshopImageLoader.csproj
  • PsdPlugin
💤 Files with no reviewable changes (1)
  • PhotoshopImageLoader/PhotoLocator.PhotoshopImageLoader.csproj

@meesoft meesoft merged commit c06e9ca into main Mar 17, 2026
5 checks passed
@meesoft meesoft deleted the features/UpdatePsdPlugin branch March 17, 2026 19:51
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.

1 participant