From 6cf216b3c3d122c53583ae229bda51464080a32e Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 7 Apr 2016 15:46:05 +1000 Subject: [PATCH] Fix blend Former-commit-id: 2ff994ec48236f6d1293dfbaefdbf2a2f91fee67 Former-commit-id: 734ec6a70dd782ac2d26420621e989d9943b12ed Former-commit-id: 87b984ebbace9d0b8108267d0d09f736ba5e1b1a --- README.md | 4 ++-- src/ImageProcessorCore/Filters/Blend.cs | 12 +++++------- .../Filters/ImageFilterExtensions.cs | 10 ++++++++-- src/ImageProcessorCore/ImageBase.cs | 3 +++ src/ImageProcessorCore/ImageExtensions.cs | 5 +++++ tests/ImageProcessorCore.Tests/FileTestBase.cs | 2 +- .../Processors/Samplers/SamplerTests.cs | 3 ++- 7 files changed, 26 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 17de169444..d00b693ddf 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ git clone https://github.com/JimBobSquarePants/ImageProcessor ###What works so far/ What is planned? -- Encoding/decoding of image formats (plugable), progressive required +- Encoding/decoding of image formats (plugable). - [x] Jpeg (Includes Subsampling. Progressive writing required) - [x] Bmp (Read: 32bit, 24bit, 16 bit. Write: 32bit, 24bit just now) - [x] Png (Read: TrueColor, Grayscale, Indexed. Write: True color, Indexed just now) @@ -174,7 +174,7 @@ It will also be possible to pass collections of processors as params to manipula ```csharp using (FileStream stream = File.OpenRead("foo.jpg")) -using (Image image = new Image(stream) +using (Image image = new Image(stream)) using (FileStream output = File.OpenWrite("bar.jpg")) { List processors = new List() diff --git a/src/ImageProcessorCore/Filters/Blend.cs b/src/ImageProcessorCore/Filters/Blend.cs index e48a26c520..8c36c94f28 100644 --- a/src/ImageProcessorCore/Filters/Blend.cs +++ b/src/ImageProcessorCore/Filters/Blend.cs @@ -20,7 +20,10 @@ namespace ImageProcessorCore.Filters /// /// Initializes a new instance of the class. /// - /// The image to blend. + /// + /// The image to blend with the currently processing image. + /// Disposal of this image is the responsibility of the developer. + /// /// The opacity of the image to blend. Between 0 and 100. public Blend(ImageBase image, int alpha = 100) { @@ -69,15 +72,10 @@ namespace ImageProcessorCore.Filters target[x, y] = color; } + this.OnRowProcessed(); } }); } - - /// - protected override void AfterApply(ImageBase source, ImageBase target, Rectangle targetRectangle, Rectangle sourceRectangle) - { - this.toBlend?.Dispose(); - } } } diff --git a/src/ImageProcessorCore/Filters/ImageFilterExtensions.cs b/src/ImageProcessorCore/Filters/ImageFilterExtensions.cs index 5bdb72e529..b0baffa2c6 100644 --- a/src/ImageProcessorCore/Filters/ImageFilterExtensions.cs +++ b/src/ImageProcessorCore/Filters/ImageFilterExtensions.cs @@ -73,7 +73,10 @@ namespace ImageProcessorCore.Filters /// Combines the given image together with the current one by blending their pixels. /// /// The image this method extends. - /// The image to blend with the currently processing image. + /// + /// The image to blend with the currently processing image. + /// Disposal of this image is the responsibility of the developer. + /// /// The opacity of the image image to blend. Must be between 0 and 100. /// A delegate which is called as progress is made processing the image. /// The . @@ -86,7 +89,10 @@ namespace ImageProcessorCore.Filters /// Combines the given image together with the current one by blending their pixels. /// /// The image this method extends. - /// The image to blend with the currently processing image. + /// + /// The image to blend with the currently processing image. + /// Disposal of this image is the responsibility of the developer. + /// /// The opacity of the image image to blend. Must be between 0 and 100. /// /// The structure that specifies the portion of the image object to alter. diff --git a/src/ImageProcessorCore/ImageBase.cs b/src/ImageProcessorCore/ImageBase.cs index 0065d61bca..4d45416452 100644 --- a/src/ImageProcessorCore/ImageBase.cs +++ b/src/ImageProcessorCore/ImageBase.cs @@ -24,6 +24,9 @@ namespace ImageProcessorCore /// private float[] pixelsArray; + /// + /// Provides a way to access the pixels from unmanaged memory. + /// private GCHandle pixelsHandle; /// diff --git a/src/ImageProcessorCore/ImageExtensions.cs b/src/ImageProcessorCore/ImageExtensions.cs index 533d33701a..5095003498 100644 --- a/src/ImageProcessorCore/ImageExtensions.cs +++ b/src/ImageProcessorCore/ImageExtensions.cs @@ -53,6 +53,7 @@ namespace ImageProcessorCore /// /// Applies the collection of processors to the image. + /// This method does not resize the target image. /// /// The image this method extends. /// Any processors to apply to the image. @@ -85,6 +86,9 @@ namespace ImageProcessorCore /// /// Applies the collection of processors to the image. + /// + /// This method is not chainable. + /// /// /// The source image. Cannot be null. /// The target image width. @@ -164,6 +168,7 @@ namespace ImageProcessorCore } } + // Clean up. source.Dispose(); return transformedImage; } diff --git a/tests/ImageProcessorCore.Tests/FileTestBase.cs b/tests/ImageProcessorCore.Tests/FileTestBase.cs index 6c5079cd1b..d5471f4299 100644 --- a/tests/ImageProcessorCore.Tests/FileTestBase.cs +++ b/tests/ImageProcessorCore.Tests/FileTestBase.cs @@ -29,7 +29,7 @@ namespace ImageProcessorCore.Tests //"TestImages/Formats/Png/indexed.png", // Perf: Enable for local testing only "TestImages/Formats/Png/splash.png", "TestImages/Formats/Gif/rings.gif", - "TestImages/Formats/Gif/giphy.gif" // Perf: Enable for local testing only + //"TestImages/Formats/Gif/giphy.gif" // Perf: Enable for local testing only }; protected void ProgressUpdate(object sender, ProgressEventArgs e) diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs index 4aaffb3283..2e9eef9cfb 100644 --- a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs +++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs @@ -65,6 +65,7 @@ using (FileStream output = File.OpenWrite($"TestOutput/Sample/{Path.GetFileName(filename)}")) { processor.OnProgress += this.ProgressUpdate; + // Not Chainable. image = image.Process(image.Width / 2, image.Height / 2, processor); image.Save(output); processor.OnProgress -= this.ProgressUpdate; @@ -96,7 +97,7 @@ using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}")) { image.Resize(image.Width / 2, image.Height / 2, sampler, false, this.ProgressUpdate) - .Save(output); + .Save(output); } } Trace.WriteLine($"{name}: {watch.ElapsedMilliseconds}ms");