From 4fdbc88a108a310bf4ee83b5d18d76057301b7eb Mon Sep 17 00:00:00 2001 From: Michael Vinther Date: Sun, 15 Mar 2026 10:06:42 +0100 Subject: [PATCH 1/4] Update PsdPlugin --- PsdPlugin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PsdPlugin b/PsdPlugin index f764101..02d5c1c 160000 --- a/PsdPlugin +++ b/PsdPlugin @@ -1 +1 @@ -Subproject commit f764101bd5a95579bce758a0cb99dbd1108ecff7 +Subproject commit 02d5c1cb9ca0c6b1b24a6aa92022e6f8ab6fdefc From fef6fd3aeac4d8cba52270343be8274c7e56b47e Mon Sep 17 00:00:00 2001 From: Michael Vinther Date: Wed, 11 Mar 2026 22:46:00 +0100 Subject: [PATCH 2/4] Bitmap debugging --- PhotoLocator/BitmapOperations/FloatBitmap.cs | 4 ++-- PhotoLocator/BitmapOperations/IIRSmoothOperation.cs | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/PhotoLocator/BitmapOperations/FloatBitmap.cs b/PhotoLocator/BitmapOperations/FloatBitmap.cs index ca59f80..e980b92 100644 --- a/PhotoLocator/BitmapOperations/FloatBitmap.cs +++ b/PhotoLocator/BitmapOperations/FloatBitmap.cs @@ -53,7 +53,7 @@ public FloatBitmap(BitmapSource source, double gamma) public override string ToString() { - return Stride + " x " + Height; + return $"{Width}x{Height}x{PlaneCount}"; } public void New(int width, int height, int planes) @@ -463,7 +463,7 @@ public void ProcessElementWise(FloatBitmap other, Func oper }); } else - throw new InvalidOperationException("Unsupported number of planes"); + throw new InvalidOperationException("Unsupported number of planes " + PlaneCount); } } diff --git a/PhotoLocator/BitmapOperations/IIRSmoothOperation.cs b/PhotoLocator/BitmapOperations/IIRSmoothOperation.cs index fe65ea5..790af72 100644 --- a/PhotoLocator/BitmapOperations/IIRSmoothOperation.cs +++ b/PhotoLocator/BitmapOperations/IIRSmoothOperation.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Diagnostics; +using System.Threading.Tasks; namespace PhotoLocator.BitmapOperations { @@ -8,6 +9,7 @@ public static void Apply(FloatBitmap plane, float filterSize) { if (filterSize == 0) return; + Debug.Assert(plane.PlaneCount == 1); filterSize /= 4f; var scale = 1f / (1f + filterSize); unsafe From f8cb95e337f3f51ead5c298421e9893eb66ef2d9 Mon Sep 17 00:00:00 2001 From: Michael Vinther Date: Sun, 15 Mar 2026 11:22:32 +0100 Subject: [PATCH 3/4] Fix CMYK PSD color preview --- .../PictureFileFormats/PhotoshopFileFormatHandler.cs | 2 ++ .../PhotoLocator.PhotoshopImageLoader.csproj | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs b/PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs index ceade3e..23d2a32 100644 --- a/PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs +++ b/PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs @@ -68,6 +68,8 @@ public static BitmapSource CreateLayerBitmap(PsdFile psd, Layer layer) { 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]); return BitmapSource.Create(layer.Rect.Width, layer.Rect.Height, 96, 96, PixelFormats.Cmyk32, null, pixels, layer.Rect.Width * 4); } diff --git a/PhotoshopImageLoader/PhotoLocator.PhotoshopImageLoader.csproj b/PhotoshopImageLoader/PhotoLocator.PhotoshopImageLoader.csproj index 2525dc7..eea74c8 100644 --- a/PhotoshopImageLoader/PhotoLocator.PhotoshopImageLoader.csproj +++ b/PhotoshopImageLoader/PhotoLocator.PhotoshopImageLoader.csproj @@ -46,12 +46,6 @@ - - - - - - From bb9b5eb148c744bfae88c15dcbd98a6133457e2f Mon Sep 17 00:00:00 2001 From: Michael Vinther Date: Sun, 15 Mar 2026 11:39:35 +0100 Subject: [PATCH 4/4] Review fix --- .../PhotoshopFileFormatHandler.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs b/PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs index 23d2a32..11868aa 100644 --- a/PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs +++ b/PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs @@ -24,6 +24,7 @@ public static BitmapSource LoadFromStream(Stream stream, Rotation rotation, int var psd = new PsdFile(stream, new LoadContext()); foreach (var psdLayer in (new[] { psd.BaseLayer }).Concat(psd.Layers)) { + ct.ThrowIfCancellationRequested(); if (psdLayer != psd.BaseLayer && (!psdLayer.Visible || psdLayer.Opacity == 0) || psdLayer.Rect.Width == 0 || psdLayer.Rect.Height == 0) continue; @@ -67,9 +68,7 @@ public static BitmapSource CreateLayerBitmap(PsdFile psd, Layer layer) 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); } @@ -85,6 +84,14 @@ private static void GetChannelPixels8(Channel channel, byte[] dest, int offset, dest[iDst] = source[iSrc]; } + 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]); + } + private static void GetChannelPixels16(Channel channel, byte[] dest, int offset, int dist) { dist -= 2;