Browse Source

Add more filter methods to API

Former-commit-id: d6ae1aee8613ad004d76fba528cd1bc7a2ca3054
Former-commit-id: 77bb86b4723c5074860e3fd8574115dc21380c04
Former-commit-id: dca053caa530602fd33a3805192e7060df900515
af/merge-core
James Jackson-South 10 years ago
parent
commit
73414b9c78
  1. 18
      src/ImageProcessor/Common/Exceptions/ImageFormatException.cs
  2. 23
      src/ImageProcessor/Filters/ColorMatrix/GreyscaleMode.cs
  3. 117
      src/ImageProcessor/Filters/ImageFilterExtensions.cs
  4. 11
      src/ImageProcessor/Formats/IImageDecoder.cs
  5. 7
      src/ImageProcessor/Samplers/Resize.cs

18
src/ImageProcessor/Common/Exceptions/ImageFormatException.cs

@ -1,13 +1,7 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ImageFormatException.cs" company="James South">
// Copyright (c) James South and contributors.
// Licensed under the Apache License, Version 2.0.
// <copyright file="ImageFormatException.cs" company="James South">
// Copyright (c) James South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// The exception that is thrown when the library tries to load
// an image, which has an invalid format.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor
{
@ -27,7 +21,7 @@ namespace ImageProcessor
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageFormatException"/> class with the name of the
/// Initializes a new instance of the <see cref="ImageFormatException"/> class with the name of the
/// parameter that causes this exception.
/// </summary>
/// <param name="errorMessage">The error message that explains the reason for this exception.</param>
@ -37,11 +31,11 @@ namespace ImageProcessor
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageFormatException"/> class with a specified
/// Initializes a new instance of the <see cref="ImageFormatException"/> class with a specified
/// error message and the exception that is the cause of this exception.
/// </summary>
/// <param name="errorMessage">The error message that explains the reason for this exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic)
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic)
/// if no inner exception is specified.</param>
public ImageFormatException(string errorMessage, Exception innerException)
: base(errorMessage, innerException)

23
src/ImageProcessor/Filters/ColorMatrix/GreyscaleMode.cs

@ -0,0 +1,23 @@
// <copyright file="GreyscaleMode.cs" company="James South">
// Copyright (c) James South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessor.Filters
{
/// <summary>
/// Provides enumeration over the various greyscale methods available.
/// </summary>
public enum GreyscaleMode
{
/// <summary>
/// ITU-R Recommendation BT.709
/// </summary>
Bt709,
/// <summary>
/// ITU-R Recommendation BT.601
/// </summary>
Bt601
}
}

117
src/ImageProcessor/Filters/ImageFilterExtensions.cs

@ -10,6 +10,31 @@ namespace ImageProcessor.Filters
/// </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>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Alpha(this Image source, int percent)
{
return Alpha(source, percent, source.Bounds);
}
/// <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>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Alpha(this Image source, int percent, Rectangle rectangle)
{
return source.Process(rectangle, new Alpha(percent));
}
/// <summary>
/// Alters the contrast component of the image.
/// </summary>
@ -26,61 +51,109 @@ namespace ImageProcessor.Filters
/// </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="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Contrast(this Image source, int amount, Rectangle sourceRectangle)
public static Image Contrast(this Image source, int amount, Rectangle rectangle)
{
return source.Process(sourceRectangle, new Contrast(amount));
return source.Process(rectangle, new Contrast(amount));
}
/// <summary>
/// Alters the alpha component of the image.
/// Inverts the colors 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>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Alpha(this Image source, int percent)
public static Image Invert(this Image source)
{
return Alpha(source, percent, source.Bounds);
return Invert(source, source.Bounds);
}
/// <summary>
/// Alters the alpha component of the image.
/// Inverts the colors 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="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Alpha(this Image source, int percent, Rectangle sourceRectangle)
public static Image Invert(this Image source, Rectangle rectangle)
{
return source.Process(sourceRectangle, new Alpha(percent));
return source.Process(rectangle, new Invert());
}
/// <summary>
/// Alters the alpha component of the image.
/// Applies sepia toning to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Invert(this Image source)
public static Image Sepia(this Image source)
{
return Invert(source, source.Bounds);
return Sepia(source, source.Bounds);
}
/// <summary>
/// Alters the alpha component of the image.
/// 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>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Sepia(this Image source, Rectangle rectangle)
{
return source.Process(rectangle, new Sepia());
}
/// <summary>
/// Applies black and white toning to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image BlackWhite(this Image source)
{
return BlackWhite(source, source.Bounds);
}
/// <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>
/// <returns>The <see cref="Image"/>.</returns>
public static Image BlackWhite(this Image source, Rectangle rectangle)
{
return source.Process(rectangle, new BlackWhite());
}
/// <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>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Greyscale(this Image source, GreyscaleMode mode = GreyscaleMode.Bt709)
{
return Greyscale(source, source.Bounds, mode);
}
/// <summary>
/// Applies greyscale toning to the image.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// <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>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Invert(this Image source, Rectangle sourceRectangle)
public static Image Greyscale(this Image source, Rectangle rectangle, GreyscaleMode mode = GreyscaleMode.Bt709)
{
return source.Process(sourceRectangle, new Invert());
return mode == GreyscaleMode.Bt709
? source.Process(rectangle, new GreyscaleBt709())
: source.Process(rectangle, new GreyscaleBt601());
}
}
}

11
src/ImageProcessor/Formats/IImageDecoder.cs

@ -1,12 +1,7 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IImageDecoder.cs" company="James South">
// Copyright (c) James South and contributors.
// Licensed under the Apache License, Version 2.0.
// <copyright file="IImageDecoder.cs" company="James South">
// Copyright (c) James South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// Encapsulates properties and methods required for decoding an image from a stream.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Formats
{

7
src/ImageProcessor/Samplers/Resize.cs

@ -17,7 +17,7 @@ namespace ImageProcessor.Samplers
/// <summary>
/// The epsilon for comparing floating point numbers.
/// </summary>
private const float Epsilon = 0.0000001f;
private const float Epsilon = 0.00001f;
/// <summary>
/// The horizontal weights.
@ -99,6 +99,11 @@ namespace ImageProcessor.Samplers
int originX = xw.Index;
Color sourceColor = PixelOperations.ToLinear(source[originX, originY]);
if (Math.Abs(sourceColor.A) < Epsilon)
{
continue;
}
float weight = (yw.Value / verticalSum) * (xw.Value / horizontalSum);
destination.R += sourceColor.R * weight;

Loading…
Cancel
Save