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 diff --git a/PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs b/PhotoLocator/PictureFileFormats/PhotoshopFileFormatHandler.cs index ceade3e..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,7 +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)); + 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); } @@ -83,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; 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 @@ - - - - - - diff --git a/PsdPlugin b/PsdPlugin index f764101..02d5c1c 160000 --- a/PsdPlugin +++ b/PsdPlugin @@ -1 +1 @@ -Subproject commit f764101bd5a95579bce758a0cb99dbd1108ecff7 +Subproject commit 02d5c1cb9ca0c6b1b24a6aa92022e6f8ab6fdefc