mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: 5e9d8e0d98e6bed499d71b0cab005c2c253ec917 Former-commit-id: 87cc61833ac266b0795f93a8c3a46ba84796e726 Former-commit-id: 2d3e58fe24556ae5701d00236b10125f878b4b63pull/1/head
92 changed files with 1647 additions and 1341 deletions
@ -0,0 +1,50 @@ |
|||
// <copyright file="BlackWhite.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Applies black and white toning to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image BlackWhite(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return BlackWhite(source, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies black and white toning to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image BlackWhite(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
BlackWhiteProcessor processor = new BlackWhiteProcessor(); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
// <copyright file="BoxBlur.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Applies a box blur to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image BoxBlur(this Image source, int radius = 7, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return BoxBlur(source, radius, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies a box blur to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image BoxBlur(this Image source, int radius, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
BoxBlurProcessor processor = new BoxBlurProcessor(radius); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,88 @@ |
|||
// <copyright file="ColorBlindness.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Applies the given colorblindness simulator to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return ColorBlindness(source, colorBlindness, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies the given colorblindness simulator to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
IImageProcessor processor; |
|||
|
|||
switch (colorBlindness) |
|||
{ |
|||
case ImageProcessorCore.ColorBlindness.Achromatomaly: |
|||
processor = new AchromatomalyProcessor(); |
|||
break; |
|||
|
|||
case ImageProcessorCore.ColorBlindness.Achromatopsia: |
|||
processor = new AchromatopsiaProcessor(); |
|||
break; |
|||
|
|||
case ImageProcessorCore.ColorBlindness.Deuteranomaly: |
|||
processor = new DeuteranomalyProcessor(); |
|||
break; |
|||
|
|||
case ImageProcessorCore.ColorBlindness.Deuteranopia: |
|||
processor = new DeuteranopiaProcessor(); |
|||
break; |
|||
|
|||
case ImageProcessorCore.ColorBlindness.Protanomaly: |
|||
processor = new ProtanomalyProcessor(); |
|||
break; |
|||
|
|||
case ImageProcessorCore.ColorBlindness.Protanopia: |
|||
processor = new ProtanopiaProcessor(); |
|||
break; |
|||
|
|||
case ImageProcessorCore.ColorBlindness.Tritanomaly: |
|||
processor = new TritanomalyProcessor(); |
|||
break; |
|||
|
|||
default: |
|||
processor = new TritanopiaProcessor(); |
|||
break; |
|||
} |
|||
|
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
// <copyright file="DetectEdges.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Detects any edges within the image. Uses the <see cref="SobelProcessor"/> filter
|
|||
/// operating in greyscale mode.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image DetectEdges(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return DetectEdges(source, source.Bounds, new SobelProcessor { Greyscale = true }, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Detects any edges within the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="filter">The filter for detecting edges.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image DetectEdges(this Image source, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return DetectEdges(source, source.Bounds, filter, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Detects any edges within the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="filter">The filter for detecting edges.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
filter.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, filter); |
|||
} |
|||
finally |
|||
{ |
|||
filter.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
// <copyright file="Greyscale.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Applies greyscale toning to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="mode">The formula to apply to perform the operation.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Greyscale(this Image source, GreyscaleMode mode = GreyscaleMode.Bt709, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Greyscale(source, source.Bounds, mode, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies greyscale toning to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="mode">The formula to apply to perform the operation.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Greyscale(this Image source, Rectangle rectangle, GreyscaleMode mode = GreyscaleMode.Bt709, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
IImageProcessor processor = mode == GreyscaleMode.Bt709 |
|||
? (IImageProcessor)new GreyscaleBt709Processor() |
|||
: new GreyscaleBt601Processor(); |
|||
|
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
// <copyright file="GuassianBlur.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Applies a Guassian blur to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image GuassianBlur(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return GuassianBlur(source, sigma, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies a Guassian blur to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image GuassianBlur(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
GuassianBlurProcessor processor = new GuassianBlurProcessor(sigma); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
// <copyright file="GuassianSharpen.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Applies a Guassian sharpening filter to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image GuassianSharpen(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return GuassianSharpen(source, sigma, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies a Guassian sharpening filter to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image GuassianSharpen(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
GuassianSharpenProcessor processor = new GuassianSharpenProcessor(sigma); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
// <copyright file="Hue.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Alters the hue component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="degrees">The angle in degrees to adjust the image.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Hue(this Image source, float degrees, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Hue(source, degrees, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the hue component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="degrees">The angle in degrees to adjust the image.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Hue(this Image source, float degrees, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
HueProcessor processor = new HueProcessor(degrees); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,784 +0,0 @@ |
|||
// <copyright file="ImageFilterExtensions.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Extensions methods for <see cref="Image"/> to apply filters to the image.
|
|||
/// </summary>
|
|||
public static class ImageFilterExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Alters the alpha component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="percent">The new opacity of the image. 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>
|
|||
public static Image Alpha(this Image source, int percent, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Alpha(source, percent, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the alpha component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="percent">The new opacity of the image. 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.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Alpha(this Image source, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
Alpha processor = new Alpha(percent); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 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="color">The color to set as the background.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image BackgroundColor(this Image source, Color color, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
BackgroundColor processor = new BackgroundColor(color); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(source.Bounds, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// 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>
|
|||
public static Image Blend(this Image source, ImageBase image, int percent = 50, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Blend(source, image, percent, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// 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.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Blend(this Image source, ImageBase image, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
Blend processor = new Blend(image, percent); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies black and white toning to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image BlackWhite(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return BlackWhite(source, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies black and white toning to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image BlackWhite(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
BlackWhite processor = new BlackWhite(); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies a box blur to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image BoxBlur(this Image source, int radius = 7, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return BoxBlur(source, radius, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies a box blur to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image BoxBlur(this Image source, int radius, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
BoxBlur processor = new BoxBlur(radius); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the brightness component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="amount">The new brightness of the image. Must be between -100 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>
|
|||
public static Image Brightness(this Image source, int amount, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Brightness(source, amount, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the brightness component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="amount">The new brightness of the image. Must be between -100 and 100.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Brightness(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
Brightness processor = new Brightness(amount); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies the given colorblindness simulator to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return ColorBlindness(source, colorBlindness, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies the given colorblindness simulator to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
IImageProcessor processor; |
|||
|
|||
switch (colorBlindness) |
|||
{ |
|||
case Filters.ColorBlindness.Achromatomaly: |
|||
processor = new Achromatomaly(); |
|||
break; |
|||
|
|||
case Filters.ColorBlindness.Achromatopsia: |
|||
processor = new Achromatopsia(); |
|||
break; |
|||
|
|||
case Filters.ColorBlindness.Deuteranomaly: |
|||
processor = new Deuteranomaly(); |
|||
break; |
|||
|
|||
case Filters.ColorBlindness.Deuteranopia: |
|||
processor = new Deuteranopia(); |
|||
break; |
|||
|
|||
case Filters.ColorBlindness.Protanomaly: |
|||
processor = new Protanomaly(); |
|||
break; |
|||
|
|||
case Filters.ColorBlindness.Protanopia: |
|||
processor = new Protanopia(); |
|||
break; |
|||
|
|||
case Filters.ColorBlindness.Tritanomaly: |
|||
processor = new Tritanomaly(); |
|||
break; |
|||
|
|||
default: |
|||
processor = new Tritanopia(); |
|||
break; |
|||
} |
|||
|
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the contrast component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="amount">The new contrast of the image. Must be between -100 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>
|
|||
public static Image Contrast(this Image source, int amount, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Contrast(source, amount, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the contrast component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="amount">The new contrast of the image. Must be between -100 and 100.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Contrast(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
Contrast processor = new Contrast(amount); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Detects any edges within the image. Uses the <see cref="Sobel"/> filter
|
|||
/// operating in greyscale mode.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image DetectEdges(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return DetectEdges(source, source.Bounds, new Sobel { Greyscale = true }, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Detects any edges within the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="filter">The filter for detecting edges.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image DetectEdges(this Image source, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return DetectEdges(source, source.Bounds, filter, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Detects any edges within the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="filter">The filter for detecting edges.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
filter.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, filter); |
|||
} |
|||
finally |
|||
{ |
|||
filter.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies greyscale toning to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="mode">The formula to apply to perform the operation.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Greyscale(this Image source, GreyscaleMode mode = GreyscaleMode.Bt709, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Greyscale(source, source.Bounds, mode, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies greyscale toning to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="mode">The formula to apply to perform the operation.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Greyscale(this Image source, Rectangle rectangle, GreyscaleMode mode = GreyscaleMode.Bt709, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
IImageProcessor processor = mode == GreyscaleMode.Bt709 |
|||
? (IImageProcessor)new GreyscaleBt709() |
|||
: new GreyscaleBt601(); |
|||
|
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies a Guassian blur to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image GuassianBlur(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return GuassianBlur(source, sigma, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies a Guassian blur to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image GuassianBlur(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
GuassianBlur processor = new GuassianBlur(sigma); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies a Guassian sharpening filter to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image GuassianSharpen(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return GuassianSharpen(source, sigma, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies a Guassian sharpening filter to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image GuassianSharpen(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
GuassianSharpen processor = new GuassianSharpen(sigma); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the hue component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="degrees">The angle in degrees to adjust the image.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Hue(this Image source, float degrees, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Hue(source, degrees, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the hue component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="degrees">The angle in degrees to adjust the image.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Hue(this Image source, float degrees, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
Hue processor = new Hue(degrees); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Inverts the colors of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Invert(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Invert(source, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Inverts the colors of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Invert(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
Invert processor = new Invert(); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Kodachrome camera effect.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Kodachrome(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Kodachrome(source, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Kodachrome camera effect.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Kodachrome(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
Kodachrome processor = new Kodachrome(); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Lomograph camera effect.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Lomograph(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Lomograph(source, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Lomograph camera effect.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Lomograph(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
Lomograph processor = new Lomograph(); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Polaroid camera effect.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Polaroid(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Polaroid(source, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Polaroid camera effect.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Polaroid(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
Polaroid processor = new Polaroid(); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Pixelates and image with the given pixel size.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="size">The size of the pixels.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Pixelate(this Image source, int size = 4, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Pixelate(source, size, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Pixelates and image with the given pixel size.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="size">The size of the pixels.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Pixelate(this Image source, int size, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
Pixelate processor = new Pixelate(size); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the saturation component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="amount">The new saturation of the image. Must be between -100 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>
|
|||
public static Image Saturation(this Image source, int amount, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Saturation(source, amount, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the saturation component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="amount">The new saturation of the image. Must be between -100 and 100.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Saturation(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
Saturation processor = new Saturation(amount); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies sepia toning to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Sepia(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Sepia(source, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies sepia toning to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Sepia(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
Sepia processor = new Sepia(); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="Kodachrome.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Kodachrome camera effect.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Kodachrome(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Kodachrome(source, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Kodachrome camera effect.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Kodachrome(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
KodachromeProcessor processor = new KodachromeProcessor(); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="Lomograph.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Lomograph camera effect.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Lomograph(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Lomograph(source, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Lomograph camera effect.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Lomograph(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
LomographProcessor processor = new LomographProcessor(); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="Polaroid.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Polaroid camera effect.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Polaroid(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Polaroid(source, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Polaroid camera effect.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Polaroid(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
PolaroidProcessor processor = new PolaroidProcessor(); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
// <copyright file="AlphaProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System; |
|||
using System.Numerics; |
|||
using System.Threading.Tasks; |
|||
|
|||
/// <summary>
|
|||
/// An <see cref="IImageProcessor"/> to change the Alpha of an <see cref="Image"/>.
|
|||
/// </summary>
|
|||
public class AlphaProcessor : ParallelImageProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="AlphaProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="percent">The percentage to adjust the opacity of the image. Must be between 0 and 100.</param>
|
|||
/// <exception cref="ArgumentException">
|
|||
/// <paramref name="percent"/> is less than 0 or is greater than 100.
|
|||
/// </exception>
|
|||
public AlphaProcessor(int percent) |
|||
{ |
|||
Guard.MustBeBetweenOrEqualTo(percent, 0, 100, nameof(percent)); |
|||
this.Value = percent; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the alpha value.
|
|||
/// </summary>
|
|||
public int Value { get; } |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) |
|||
{ |
|||
float alpha = this.Value / 100f; |
|||
int sourceY = sourceRectangle.Y; |
|||
int sourceBottom = sourceRectangle.Bottom; |
|||
int startX = sourceRectangle.X; |
|||
int endX = sourceRectangle.Right; |
|||
Vector4 alphaVector = new Vector4(1, 1, 1, alpha); |
|||
|
|||
using (PixelAccessor sourcePixels = source.Lock()) |
|||
using (PixelAccessor targetPixels = target.Lock()) |
|||
{ |
|||
Parallel.For( |
|||
startY, |
|||
endY, |
|||
y => |
|||
{ |
|||
if (y >= sourceY && y < sourceBottom) |
|||
{ |
|||
for (int x = startX; x < endX; x++) |
|||
{ |
|||
Vector4 color = Color.ToNonPremultiplied(sourcePixels[x, y]).ToVector4(); |
|||
color *= alphaVector; |
|||
targetPixels[x, y] = Color.FromNonPremultiplied(new Color(color)); |
|||
} |
|||
|
|||
this.OnRowProcessed(); |
|||
} |
|||
}); |
|||
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,78 @@ |
|||
// <copyright file="BackgroundColorProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
/// <summary>
|
|||
/// Sets the background color of the image.
|
|||
/// </summary>
|
|||
public class BackgroundColorProcessor : ParallelImageProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// The epsilon for comparing floating point numbers.
|
|||
/// </summary>
|
|||
private const float Epsilon = 0.001f; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="BackgroundColorProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="color">The <see cref="Color"/> to set the background color to.</param>
|
|||
public BackgroundColorProcessor(Color color) |
|||
{ |
|||
this.Value = Color.FromNonPremultiplied(color); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the background color value.
|
|||
/// </summary>
|
|||
public Color Value { get; } |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) |
|||
{ |
|||
int sourceY = sourceRectangle.Y; |
|||
int sourceBottom = sourceRectangle.Bottom; |
|||
int startX = sourceRectangle.X; |
|||
int endX = sourceRectangle.Right; |
|||
Color backgroundColor = this.Value; |
|||
|
|||
using (PixelAccessor sourcePixels = source.Lock()) |
|||
using (PixelAccessor targetPixels = target.Lock()) |
|||
{ |
|||
Parallel.For( |
|||
startY, |
|||
endY, |
|||
y => |
|||
{ |
|||
if (y >= sourceY && y < sourceBottom) |
|||
{ |
|||
for (int x = startX; x < endX; x++) |
|||
{ |
|||
Color color = sourcePixels[x, y]; |
|||
float a = color.A; |
|||
|
|||
if (a < 1 && a > 0) |
|||
{ |
|||
color = Color.Lerp(color, backgroundColor, .5f); |
|||
} |
|||
|
|||
if (Math.Abs(a) < Epsilon) |
|||
{ |
|||
color = backgroundColor; |
|||
} |
|||
|
|||
targetPixels[x, y] = color; |
|||
} |
|||
|
|||
this.OnRowProcessed(); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,86 @@ |
|||
// <copyright file="BlendProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System.Threading.Tasks; |
|||
|
|||
/// <summary>
|
|||
/// Combines two images together by blending the pixels.
|
|||
/// </summary>
|
|||
public class BlendProcessor : ParallelImageProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// The image to blend.
|
|||
/// </summary>
|
|||
private readonly ImageBase blend; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="BlendProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <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 BlendProcessor(ImageBase image, int alpha = 100) |
|||
{ |
|||
Guard.MustBeBetweenOrEqualTo(alpha, 0, 100, nameof(alpha)); |
|||
this.blend = image; |
|||
this.Value = alpha; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the alpha percentage value.
|
|||
/// </summary>
|
|||
public int Value { get; } |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) |
|||
{ |
|||
int sourceY = sourceRectangle.Y; |
|||
int sourceBottom = sourceRectangle.Bottom; |
|||
int startX = sourceRectangle.X; |
|||
int endX = sourceRectangle.Right; |
|||
Rectangle bounds = this.blend.Bounds; |
|||
float alpha = this.Value / 100f; |
|||
|
|||
using (PixelAccessor toBlendPixels = this.blend.Lock()) |
|||
using (PixelAccessor sourcePixels = source.Lock()) |
|||
using (PixelAccessor targetPixels = target.Lock()) |
|||
{ |
|||
Parallel.For( |
|||
startY, |
|||
endY, |
|||
y => |
|||
{ |
|||
if (y >= sourceY && y < sourceBottom) |
|||
{ |
|||
for (int x = startX; x < endX; x++) |
|||
{ |
|||
Color color = sourcePixels[x, y]; |
|||
|
|||
if (bounds.Contains(x, y)) |
|||
{ |
|||
Color blendedColor = toBlendPixels[x, y]; |
|||
|
|||
if (blendedColor.A > 0) |
|||
{ |
|||
// Lerping colors is dependent on the alpha of the blended color
|
|||
float alphaFactor = alpha > 0 ? alpha : blendedColor.A; |
|||
color = Color.Lerp(color, blendedColor, alphaFactor); |
|||
} |
|||
} |
|||
|
|||
targetPixels[x, y] = color; |
|||
} |
|||
|
|||
this.OnRowProcessed(); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
// <copyright file="BrightnessProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System; |
|||
using System.Numerics; |
|||
using System.Threading.Tasks; |
|||
|
|||
/// <summary>
|
|||
/// An <see cref="IImageProcessor"/> to change the brightness of an <see cref="Image"/>.
|
|||
/// </summary>
|
|||
public class BrightnessProcessor : ParallelImageProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="BrightnessProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="brightness">The new brightness of the image. Must be between -100 and 100.</param>
|
|||
/// <exception cref="ArgumentException">
|
|||
/// <paramref name="brightness"/> is less than -100 or is greater than 100.
|
|||
/// </exception>
|
|||
public BrightnessProcessor(int brightness) |
|||
{ |
|||
Guard.MustBeBetweenOrEqualTo(brightness, -100, 100, nameof(brightness)); |
|||
this.Value = brightness; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the brightness value.
|
|||
/// </summary>
|
|||
public int Value { get; } |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) |
|||
{ |
|||
float brightness = this.Value / 100f; |
|||
int sourceY = sourceRectangle.Y; |
|||
int sourceBottom = sourceRectangle.Bottom; |
|||
int startX = sourceRectangle.X; |
|||
int endX = sourceRectangle.Right; |
|||
|
|||
using (PixelAccessor sourcePixels = source.Lock()) |
|||
using (PixelAccessor targetPixels = target.Lock()) |
|||
{ |
|||
Parallel.For( |
|||
startY, |
|||
endY, |
|||
y => |
|||
{ |
|||
if (y >= sourceY && y < sourceBottom) |
|||
{ |
|||
for (int x = startX; x < endX; x++) |
|||
{ |
|||
Color color = Color.Expand(sourcePixels[x, y]); |
|||
|
|||
Vector3 vector3 = color.ToVector3(); |
|||
vector3 += new Vector3(brightness); |
|||
|
|||
targetPixels[x, y] = Color.Compress(new Color(vector3, color.A)); |
|||
} |
|||
this.OnRowProcessed(); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,16 +1,16 @@ |
|||
// <copyright file="BlackWhite.cs" company="James Jackson-South">
|
|||
// <copyright file="BlackWhiteProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Converts the colors of the image to their black and white equivalent.
|
|||
/// </summary>
|
|||
public class BlackWhite : ColorMatrixFilter |
|||
public class BlackWhiteProcessor : ColorMatrixFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override Matrix4x4 Matrix => new Matrix4x4() |
|||
@ -1,16 +1,16 @@ |
|||
// <copyright file="Achromatomaly.cs" company="James Jackson-South">
|
|||
// <copyright file="AchromatomalyProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness.
|
|||
/// </summary>
|
|||
public class Achromatomaly : ColorMatrixFilter |
|||
public class AchromatomalyProcessor : ColorMatrixFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override Matrix4x4 Matrix => new Matrix4x4() |
|||
@ -1,16 +1,16 @@ |
|||
// <copyright file="Achromatopsia.cs" company="James Jackson-South">
|
|||
// <copyright file="AchromatopsiaProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating Achromatopsia (Monochrome) color blindness.
|
|||
/// </summary>
|
|||
public class Achromatopsia : ColorMatrixFilter |
|||
public class AchromatopsiaProcessor : ColorMatrixFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override Matrix4x4 Matrix => new Matrix4x4() |
|||
@ -1,16 +1,16 @@ |
|||
// <copyright file="Deuteranomaly.cs" company="James Jackson-South">
|
|||
// <copyright file="DeuteranomalyProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness.
|
|||
/// </summary>
|
|||
public class Deuteranomaly : ColorMatrixFilter |
|||
public class DeuteranomalyProcessor : ColorMatrixFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override Matrix4x4 Matrix => new Matrix4x4() |
|||
@ -1,16 +1,16 @@ |
|||
// <copyright file="Deuteranopia.cs" company="James Jackson-South">
|
|||
// <copyright file="DeuteranopiaProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating Deuteranopia (Green-Blind) color blindness.
|
|||
/// </summary>
|
|||
public class Deuteranopia : ColorMatrixFilter |
|||
public class DeuteranopiaProcessor : ColorMatrixFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override Matrix4x4 Matrix => new Matrix4x4() |
|||
@ -1,16 +1,16 @@ |
|||
// <copyright file="Protanomaly.cs" company="James Jackson-South">
|
|||
// <copyright file="ProtanomalyProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating Protanopia (Red-Weak) color blindness.
|
|||
/// </summary>
|
|||
public class Protanomaly : ColorMatrixFilter |
|||
public class ProtanomalyProcessor : ColorMatrixFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override Matrix4x4 Matrix => new Matrix4x4() |
|||
@ -1,16 +1,16 @@ |
|||
// <copyright file="Protanopia.cs" company="James Jackson-South">
|
|||
// <copyright file="ProtanopiaProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness.
|
|||
/// </summary>
|
|||
public class Protanopia : ColorMatrixFilter |
|||
public class ProtanopiaProcessor : ColorMatrixFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override Matrix4x4 Matrix => new Matrix4x4() |
|||
@ -1,16 +1,16 @@ |
|||
// <copyright file="Tritanomaly.cs" company="James Jackson-South">
|
|||
// <copyright file="TritanomalyProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating Tritanomaly (Blue-Weak) color blindness.
|
|||
/// </summary>
|
|||
public class Tritanomaly : ColorMatrixFilter |
|||
public class TritanomalyProcessor : ColorMatrixFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override Matrix4x4 Matrix => new Matrix4x4() |
|||
@ -1,16 +1,16 @@ |
|||
// <copyright file="Tritanopia.cs" company="James Jackson-South">
|
|||
// <copyright file="TritanopiaProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating Tritanopia (Blue-Blind) color blindness.
|
|||
/// </summary>
|
|||
public class Tritanopia : ColorMatrixFilter |
|||
public class TritanopiaProcessor : ColorMatrixFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override Matrix4x4 Matrix => new Matrix4x4() |
|||
@ -1,16 +1,16 @@ |
|||
// <copyright file="Kodachrome.cs" company="James Jackson-South">
|
|||
// <copyright file="KodachromeProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating an old Kodachrome camera effect.
|
|||
/// </summary>
|
|||
public class Kodachrome : ColorMatrixFilter |
|||
public class KodachromeProcessor : ColorMatrixFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override Matrix4x4 Matrix => new Matrix4x4() |
|||
@ -0,0 +1,70 @@ |
|||
// <copyright file="ContrastProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System; |
|||
using System.Numerics; |
|||
using System.Threading.Tasks; |
|||
|
|||
/// <summary>
|
|||
/// An <see cref="IImageProcessor"/> to change the contrast of an <see cref="Image"/>.
|
|||
/// </summary>
|
|||
public class ContrastProcessor : ParallelImageProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ContrastProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="contrast">The new contrast of the image. Must be between -100 and 100.</param>
|
|||
/// <exception cref="ArgumentException">
|
|||
/// <paramref name="contrast"/> is less than -100 or is greater than 100.
|
|||
/// </exception>
|
|||
public ContrastProcessor(int contrast) |
|||
{ |
|||
Guard.MustBeBetweenOrEqualTo(contrast, -100, 100, nameof(contrast)); |
|||
this.Value = contrast; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the contrast value.
|
|||
/// </summary>
|
|||
public int Value { get; } |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) |
|||
{ |
|||
float contrast = (100f + this.Value) / 100f; |
|||
int sourceY = sourceRectangle.Y; |
|||
int sourceBottom = sourceRectangle.Bottom; |
|||
int startX = sourceRectangle.X; |
|||
int endX = sourceRectangle.Right; |
|||
Vector4 contrastVector = new Vector4(contrast, contrast, contrast, 1); |
|||
Vector4 shiftVector = new Vector4(.5f, .5f, .5f, 1); |
|||
|
|||
using (PixelAccessor sourcePixels = source.Lock()) |
|||
using (PixelAccessor targetPixels = target.Lock()) |
|||
{ |
|||
Parallel.For( |
|||
startY, |
|||
endY, |
|||
y => |
|||
{ |
|||
if (y >= sourceY && y < sourceBottom) |
|||
{ |
|||
for (int x = startX; x < endX; x++) |
|||
{ |
|||
Vector4 color = Color.Expand(sourcePixels[x, y]).ToVector4(); |
|||
color -= shiftVector; |
|||
color *= contrastVector; |
|||
color += shiftVector; |
|||
targetPixels[x, y] = Color.Compress(new Color(color)); |
|||
} |
|||
this.OnRowProcessed(); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,15 +1,15 @@ |
|||
// <copyright file="Kayyali.cs" company="James Jackson-South">
|
|||
// <copyright file="KayyaliProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// The Kayyali operator filter.
|
|||
/// <see href="http://edgedetection.webs.com/"/>
|
|||
/// </summary>
|
|||
public class Kayyali : EdgeDetector2DFilter |
|||
public class KayyaliProcessor : EdgeDetector2DFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override float[,] KernelX => new float[,] |
|||
@ -1,15 +1,15 @@ |
|||
// <copyright file="Kirsch.cs" company="James Jackson-South">
|
|||
// <copyright file="KirschProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// The Kirsch operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Kirsch_operator"/>
|
|||
/// </summary>
|
|||
public class Kirsch : EdgeDetector2DFilter |
|||
public class KirschProcessor : EdgeDetector2DFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override float[,] KernelX => new float[,] |
|||
@ -1,15 +1,15 @@ |
|||
// <copyright file="Laplacian3X3.cs" company="James Jackson-South">
|
|||
// <copyright file="Laplacian3X3Processor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// The Laplacian 3 x 3 operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
|
|||
/// </summary>
|
|||
public class Laplacian3X3 : EdgeDetectorFilter |
|||
public class Laplacian3X3Processor : EdgeDetectorFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override float[,] KernelXY => new float[,] |
|||
@ -1,15 +1,15 @@ |
|||
// <copyright file="Laplacian5X5.cs" company="James Jackson-South">
|
|||
// <copyright file="Laplacian5X5Processor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// The Laplacian 5 x 5 operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
|
|||
/// </summary>
|
|||
public class Laplacian5X5 : EdgeDetectorFilter |
|||
public class Laplacian5X5Processor : EdgeDetectorFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override float[,] KernelXY => new float[,] |
|||
@ -1,15 +1,15 @@ |
|||
// <copyright file="LaplacianOfGaussian.cs" company="James Jackson-South">
|
|||
// <copyright file="LaplacianOfGaussianProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// The Laplacian of Gaussian operator filter.
|
|||
/// <see href="http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html"/>
|
|||
/// </summary>
|
|||
public class LaplacianOfGaussian : EdgeDetectorFilter |
|||
public class LaplacianOfGaussianProcessor : EdgeDetectorFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override float[,] KernelXY => new float[,] |
|||
@ -1,15 +1,15 @@ |
|||
// <copyright file="Prewitt.cs" company="James Jackson-South">
|
|||
// <copyright file="PrewittProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// The Prewitt operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Prewitt_operator"/>
|
|||
/// </summary>
|
|||
public class Prewitt : EdgeDetector2DFilter |
|||
public class PrewittProcessor : EdgeDetector2DFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override float[,] KernelX => new float[,] |
|||
@ -1,15 +1,15 @@ |
|||
// <copyright file="RobertsCross.cs" company="James Jackson-South">
|
|||
// <copyright file="RobertsCrossProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// The Roberts Cross operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Roberts_cross"/>
|
|||
/// </summary>
|
|||
public class RobertsCross : EdgeDetector2DFilter |
|||
public class RobertsCrossProcessor : EdgeDetector2DFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override float[,] KernelX => new float[,] |
|||
@ -1,15 +1,15 @@ |
|||
// <copyright file="Scharr.cs" company="James Jackson-South">
|
|||
// <copyright file="ScharrProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// The Scharr operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator#Alternative_operators"/>
|
|||
/// </summary>
|
|||
public class Scharr : EdgeDetector2DFilter |
|||
public class ScharrProcessor : EdgeDetector2DFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override float[,] KernelX => new float[,] |
|||
@ -1,15 +1,15 @@ |
|||
// <copyright file="Sobel.cs" company="James Jackson-South">
|
|||
// <copyright file="SobelProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Filters |
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// The Sobel operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator"/>
|
|||
/// </summary>
|
|||
public class Sobel : EdgeDetector2DFilter |
|||
public class SobelProcessor : EdgeDetector2DFilter |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override float[,] KernelX => new float[,] |
|||
@ -0,0 +1,48 @@ |
|||
// <copyright file="InvertProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System.Numerics; |
|||
using System.Threading.Tasks; |
|||
|
|||
/// <summary>
|
|||
/// An <see cref="IImageProcessor"/> to invert the colors of an <see cref="Image"/>.
|
|||
/// </summary>
|
|||
public class InvertProcessor : ParallelImageProcessor |
|||
{ |
|||
/// <inheritdoc/>
|
|||
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) |
|||
{ |
|||
int sourceY = sourceRectangle.Y; |
|||
int sourceBottom = sourceRectangle.Bottom; |
|||
int startX = sourceRectangle.X; |
|||
int endX = sourceRectangle.Right; |
|||
Vector3 inverseVector = Vector3.One; |
|||
|
|||
using (PixelAccessor sourcePixels = source.Lock()) |
|||
using (PixelAccessor targetPixels = target.Lock()) |
|||
{ |
|||
Parallel.For( |
|||
startY, |
|||
endY, |
|||
y => |
|||
{ |
|||
if (y >= sourceY && y < sourceBottom) |
|||
{ |
|||
for (int x = startX; x < endX; x++) |
|||
{ |
|||
Color color = sourcePixels[x, y]; |
|||
Vector3 vector = inverseVector - color.ToVector3(); |
|||
targetPixels[x, y] = new Color(vector, color.A); |
|||
} |
|||
|
|||
this.OnRowProcessed(); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,97 @@ |
|||
// <copyright file="PixelateProcessor.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Processors |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
/// <summary>
|
|||
/// An <see cref="IImageProcessor"/> to invert the colors of an <see cref="Image"/>.
|
|||
/// </summary>
|
|||
public class PixelateProcessor : ParallelImageProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="PixelateProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="size">The size of the pixels. Must be greater than 0.</param>
|
|||
/// <exception cref="ArgumentException">
|
|||
/// <paramref name="size"/> is less than 0 or equal to 0.
|
|||
/// </exception>
|
|||
public PixelateProcessor(int size) |
|||
{ |
|||
Guard.MustBeGreaterThan(size, 0, nameof(size)); |
|||
this.Value = size; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int Parallelism { get; set; } = 1; |
|||
|
|||
/// <summary>
|
|||
/// Gets or the pixel size.
|
|||
/// </summary>
|
|||
public int Value { get; } |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) |
|||
{ |
|||
int sourceY = sourceRectangle.Y; |
|||
int sourceBottom = sourceRectangle.Bottom; |
|||
int startX = sourceRectangle.X; |
|||
int endX = sourceRectangle.Right; |
|||
int size = this.Value; |
|||
int offset = this.Value / 2; |
|||
|
|||
// Get the range on the y-plane to choose from.
|
|||
IEnumerable<int> range = EnumerableExtensions.SteppedRange(startY, i => i < endY, size); |
|||
|
|||
using (PixelAccessor sourcePixels = source.Lock()) |
|||
using (PixelAccessor targetPixels = target.Lock()) |
|||
{ |
|||
Parallel.ForEach( |
|||
range, |
|||
y => |
|||
{ |
|||
if (y >= sourceY && y < sourceBottom) |
|||
{ |
|||
for (int x = startX; x < endX; x += size) |
|||
{ |
|||
|
|||
int offsetX = offset; |
|||
int offsetY = offset; |
|||
|
|||
// Make sure that the offset is within the boundary of the
|
|||
// image.
|
|||
while (y + offsetY >= sourceBottom) |
|||
{ |
|||
offsetY--; |
|||
} |
|||
|
|||
while (x + offsetX >= endX) |
|||
{ |
|||
offsetX--; |
|||
} |
|||
|
|||
// Get the pixel color in the centre of the soon to be pixelated area.
|
|||
// ReSharper disable AccessToDisposedClosure
|
|||
Color pixel = sourcePixels[x + offsetX, y + offsetY]; |
|||
|
|||
// For each pixel in the pixelate size, set it to the centre color.
|
|||
for (int l = y; l < y + size && l < sourceBottom; l++) |
|||
{ |
|||
for (int k = x; k < x + size && k < endX; k++) |
|||
{ |
|||
targetPixels[k, l] = pixel; |
|||
} |
|||
} |
|||
} |
|||
this.OnRowProcessed(); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
// <copyright file="Saturation.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Alters the saturation component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="amount">The new saturation of the image. Must be between -100 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>
|
|||
public static Image Saturation(this Image source, int amount, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Saturation(source, amount, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the saturation component of the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="amount">The new saturation of the image. Must be between -100 and 100.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Saturation(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
SaturationProcessor processor = new SaturationProcessor(amount); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="Sepia.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>-------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using Processors; |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Applies sepia toning to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Sepia(this Image source, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
return Sepia(source, source.Bounds, progressHandler); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies sepia toning to the image.
|
|||
/// </summary>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|||
/// <returns>The <see cref="Image"/>.</returns>
|
|||
public static Image Sepia(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null) |
|||
{ |
|||
SepiaProcessor processor = new SepiaProcessor(); |
|||
processor.OnProgress += progressHandler; |
|||
|
|||
try |
|||
{ |
|||
return source.Process(rectangle, processor); |
|||
} |
|||
finally |
|||
{ |
|||
processor.OnProgress -= progressHandler; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue