Browse Source

Fix blend

Former-commit-id: 2ff994ec48236f6d1293dfbaefdbf2a2f91fee67
Former-commit-id: 734ec6a70dd782ac2d26420621e989d9943b12ed
Former-commit-id: 87b984ebbace9d0b8108267d0d09f736ba5e1b1a
pull/1/head
James Jackson-South 10 years ago
parent
commit
6cf216b3c3
  1. 4
      README.md
  2. 12
      src/ImageProcessorCore/Filters/Blend.cs
  3. 10
      src/ImageProcessorCore/Filters/ImageFilterExtensions.cs
  4. 3
      src/ImageProcessorCore/ImageBase.cs
  5. 5
      src/ImageProcessorCore/ImageExtensions.cs
  6. 2
      tests/ImageProcessorCore.Tests/FileTestBase.cs
  7. 3
      tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs

4
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<IImageProcessor> processors = new List<IImageProcessor>()

12
src/ImageProcessorCore/Filters/Blend.cs

@ -20,7 +20,10 @@ namespace ImageProcessorCore.Filters
/// <summary>
/// Initializes a new instance of the <see cref="Blend"/> class.
/// </summary>
/// <param name="image">The image to blend.</param>
/// <param name="image">
/// The image to blend with the currently processing image.
/// Disposal of this image is the responsibility of the developer.
/// </param>
/// <param name="alpha">The opacity of the image to blend. Between 0 and 100.</param>
public Blend(ImageBase image, int alpha = 100)
{
@ -69,15 +72,10 @@ namespace ImageProcessorCore.Filters
target[x, y] = color;
}
this.OnRowProcessed();
}
});
}
/// <inheritdoc/>
protected override void AfterApply(ImageBase source, ImageBase target, Rectangle targetRectangle, Rectangle sourceRectangle)
{
this.toBlend?.Dispose();
}
}
}

10
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.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="image">
/// The image to blend with the currently processing image.
/// Disposal of this image is the responsibility of the developer.
/// </param>
/// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns>
@ -86,7 +89,10 @@ namespace ImageProcessorCore.Filters
/// Combines the given image together with the current one by blending their pixels.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="image">
/// The image to blend with the currently processing image.
/// Disposal of this image is the responsibility of the developer.
/// </param>
/// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.

3
src/ImageProcessorCore/ImageBase.cs

@ -24,6 +24,9 @@ namespace ImageProcessorCore
/// </summary>
private float[] pixelsArray;
/// <summary>
/// Provides a way to access the pixels from unmanaged memory.
/// </summary>
private GCHandle pixelsHandle;
/// <summary>

5
src/ImageProcessorCore/ImageExtensions.cs

@ -53,6 +53,7 @@ namespace ImageProcessorCore
/// <summary>
/// Applies the collection of processors to the image.
/// <remarks>This method does not resize the target image.</remarks>
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="processors">Any processors to apply to the image.</param>
@ -85,6 +86,9 @@ namespace ImageProcessorCore
/// <summary>
/// Applies the collection of processors to the image.
/// <remarks>
/// This method is not chainable.
/// </remarks>
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="width">The target image width.</param>
@ -164,6 +168,7 @@ namespace ImageProcessorCore
}
}
// Clean up.
source.Dispose();
return transformedImage;
}

2
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)

3
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");

Loading…
Cancel
Save