diff --git a/src/ImageProcessor/Filters/ColorMatrix/BlackWhite.cs b/src/ImageProcessor/Filters/ColorMatrix/BlackWhite.cs
index f1c8c78d8..26eb5f966 100644
--- a/src/ImageProcessor/Filters/ColorMatrix/BlackWhite.cs
+++ b/src/ImageProcessor/Filters/ColorMatrix/BlackWhite.cs
@@ -12,10 +12,8 @@ namespace ImageProcessor.Filters
///
public class BlackWhite : ColorMatrixFilter
{
- ///
- /// The BlackWhite matrix.
- ///
- private static readonly Matrix4x4 ColorMatrix = new Matrix4x4()
+ ///
+ public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 1.5f,
M12 = 1.5f,
@@ -30,13 +28,5 @@ namespace ImageProcessor.Filters
M42 = -1f,
M43 = -1f,
};
-
- ///
- /// Initializes a new instance of the class.
- ///
- public BlackWhite()
- : base(ColorMatrix)
- {
- }
}
}
diff --git a/src/ImageProcessor/Filters/ColorMatrix/ColorMatrixFilter.cs b/src/ImageProcessor/Filters/ColorMatrix/ColorMatrixFilter.cs
index 337dd7b57..a8382500d 100644
--- a/src/ImageProcessor/Filters/ColorMatrix/ColorMatrixFilter.cs
+++ b/src/ImageProcessor/Filters/ColorMatrix/ColorMatrixFilter.cs
@@ -11,26 +11,10 @@ namespace ImageProcessor.Filters
///
/// The color matrix filter.
///
- public class ColorMatrixFilter : ParallelImageProcessor, IColorMatrixFilter
+ public abstract class ColorMatrixFilter : ParallelImageProcessor, IColorMatrixFilter
{
- ///
- /// Initializes a new instance of the class.
- ///
- public ColorMatrixFilter()
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The to apply.
- public ColorMatrixFilter(Matrix4x4 matrix)
- {
- this.Matrix = matrix;
- }
-
///
- public Matrix4x4 Matrix { get; set; }
+ public abstract Matrix4x4 Matrix { get; }
///
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
diff --git a/src/ImageProcessor/Filters/ColorMatrix/GreyscaleBt601.cs b/src/ImageProcessor/Filters/ColorMatrix/GreyscaleBt601.cs
index 25bc63213..d12fdd9cf 100644
--- a/src/ImageProcessor/Filters/ColorMatrix/GreyscaleBt601.cs
+++ b/src/ImageProcessor/Filters/ColorMatrix/GreyscaleBt601.cs
@@ -13,10 +13,8 @@ namespace ImageProcessor.Filters
///
public class GreyscaleBt601 : ColorMatrixFilter
{
- ///
- /// The greyscale matrix.
- ///
- private static readonly Matrix4x4 ColorMatrix = new Matrix4x4()
+ ///
+ public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = .299f,
M12 = .299f,
@@ -28,13 +26,5 @@ namespace ImageProcessor.Filters
M32 = .114f,
M33 = .114f
};
-
- ///
- /// Initializes a new instance of the class.
- ///
- public GreyscaleBt601()
- : base(ColorMatrix)
- {
- }
}
}
diff --git a/src/ImageProcessor/Filters/ColorMatrix/GreyscaleBt709.cs b/src/ImageProcessor/Filters/ColorMatrix/GreyscaleBt709.cs
index 7e4559f83..7b16d1d1c 100644
--- a/src/ImageProcessor/Filters/ColorMatrix/GreyscaleBt709.cs
+++ b/src/ImageProcessor/Filters/ColorMatrix/GreyscaleBt709.cs
@@ -13,10 +13,8 @@ namespace ImageProcessor.Filters
///
public class GreyscaleBt709 : ColorMatrixFilter
{
- ///
- /// The greyscale matrix.
- ///
- private static readonly Matrix4x4 ColorMatrix = new Matrix4x4()
+ ///
+ public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = .2126f,
M12 = .2126f,
@@ -28,13 +26,5 @@ namespace ImageProcessor.Filters
M32 = .0722f,
M33 = .0722f
};
-
- ///
- /// Initializes a new instance of the class.
- ///
- public GreyscaleBt709()
- : base(ColorMatrix)
- {
- }
}
}
diff --git a/src/ImageProcessor/Filters/ColorMatrix/Kodachrome.cs b/src/ImageProcessor/Filters/ColorMatrix/Kodachrome.cs
index 464c3fcf6..5022dc318 100644
--- a/src/ImageProcessor/Filters/ColorMatrix/Kodachrome.cs
+++ b/src/ImageProcessor/Filters/ColorMatrix/Kodachrome.cs
@@ -12,10 +12,8 @@ namespace ImageProcessor.Filters
///
public class Kodachrome : ColorMatrixFilter
{
- ///
- /// The Kodachrome matrix. Purely artistic in composition.
- ///
- private static readonly Matrix4x4 ColorMatrix = new Matrix4x4()
+ ///
+ public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 0.6997023f,
M22 = 0.4609577f,
@@ -24,13 +22,5 @@ namespace ImageProcessor.Filters
M42 = -0.005f,
M43 = 0.005f
};
-
- ///
- /// Initializes a new instance of the class.
- ///
- public Kodachrome()
- : base(ColorMatrix)
- {
- }
}
}
diff --git a/src/ImageProcessor/Filters/ColorMatrix/Lomograph.cs b/src/ImageProcessor/Filters/ColorMatrix/Lomograph.cs
index 399c61e1d..88ca4003f 100644
--- a/src/ImageProcessor/Filters/ColorMatrix/Lomograph.cs
+++ b/src/ImageProcessor/Filters/ColorMatrix/Lomograph.cs
@@ -12,10 +12,8 @@ namespace ImageProcessor.Filters
///
public class Lomograph : ColorMatrixFilter
{
- ///
- /// The Lomograph matrix. Purely artistic in composition.
- ///
- private static readonly Matrix4x4 ColorMatrix = new Matrix4x4()
+ ///
+ public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 1.5f,
M22 = 1.45f,
@@ -24,13 +22,5 @@ namespace ImageProcessor.Filters
M42 = .0f,
M43 = -.08f
};
-
- ///
- /// Initializes a new instance of the class.
- ///
- public Lomograph()
- : base(ColorMatrix)
- {
- }
}
}
diff --git a/src/ImageProcessor/Filters/ColorMatrix/Polaroid.cs b/src/ImageProcessor/Filters/ColorMatrix/Polaroid.cs
index c4661033e..7bd6cfeea 100644
--- a/src/ImageProcessor/Filters/ColorMatrix/Polaroid.cs
+++ b/src/ImageProcessor/Filters/ColorMatrix/Polaroid.cs
@@ -12,10 +12,8 @@ namespace ImageProcessor.Filters
///
public class Polaroid : ColorMatrixFilter
{
- ///
- /// The Polaroid matrix. Purely artistic in composition.
- ///
- private static readonly Matrix4x4 ColorMatrix = new Matrix4x4()
+ ///
+ public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = 1.538f,
M12 = -0.062f,
@@ -30,13 +28,5 @@ namespace ImageProcessor.Filters
M42 = -0.05f,
M43 = -0.05f
};
-
- ///
- /// Initializes a new instance of the class.
- ///
- public Polaroid()
- : base(ColorMatrix)
- {
- }
}
}
diff --git a/src/ImageProcessor/Filters/ColorMatrix/Saturation.cs b/src/ImageProcessor/Filters/ColorMatrix/Saturation.cs
index 55bb06e1e..385d7a949 100644
--- a/src/ImageProcessor/Filters/ColorMatrix/Saturation.cs
+++ b/src/ImageProcessor/Filters/ColorMatrix/Saturation.cs
@@ -13,6 +13,16 @@ namespace ImageProcessor.Filters
///
public class Saturation : ColorMatrixFilter
{
+ ///
+ /// The saturation to be applied to the image.
+ ///
+ private readonly int saturation;
+
+ ///
+ /// The used to alter the image.
+ ///
+ private Matrix4x4 matrix;
+
///
/// Initializes a new instance of the class.
///
@@ -23,7 +33,16 @@ namespace ImageProcessor.Filters
public Saturation(int saturation)
{
Guard.MustBeBetweenOrEqualTo(saturation, -100, 100, nameof(saturation));
- float saturationFactor = saturation / 100f;
+ this.saturation = saturation;
+ }
+
+ ///
+ public override Matrix4x4 Matrix => this.matrix;
+
+ ///
+ protected override void OnApply(Rectangle targetRectangle, Rectangle sourceRectangle)
+ {
+ float saturationFactor = this.saturation / 100f;
// Stop at -1 to prevent inversion.
saturationFactor++;
@@ -37,7 +56,7 @@ namespace ImageProcessor.Filters
float saturationComplementG = 0.6094f * saturationComplement;
float saturationComplementB = 0.0820f * saturationComplement;
- Matrix4x4 matrix = new Matrix4x4()
+ Matrix4x4 matrix4X4 = new Matrix4x4()
{
M11 = saturationComplementR + saturationFactor,
M12 = saturationComplementR,
@@ -50,7 +69,7 @@ namespace ImageProcessor.Filters
M33 = saturationComplementB + saturationFactor,
};
- this.Matrix = matrix;
+ this.matrix = matrix4X4;
}
}
}
diff --git a/src/ImageProcessor/Filters/ColorMatrix/Sepia.cs b/src/ImageProcessor/Filters/ColorMatrix/Sepia.cs
index fbc33a7f3..eebf77571 100644
--- a/src/ImageProcessor/Filters/ColorMatrix/Sepia.cs
+++ b/src/ImageProcessor/Filters/ColorMatrix/Sepia.cs
@@ -12,10 +12,8 @@ namespace ImageProcessor.Filters
///
public class Sepia : ColorMatrixFilter
{
- ///
- /// The sepia matrix.
- ///
- private static readonly Matrix4x4 ColorMatrix = new Matrix4x4()
+ ///
+ public override Matrix4x4 Matrix => new Matrix4x4()
{
M11 = .393f,
M12 = .349f,
@@ -27,13 +25,5 @@ namespace ImageProcessor.Filters
M32 = .168f,
M33 = .131f
};
-
- ///
- /// Initializes a new instance of the class.
- ///
- public Sepia()
- : base(ColorMatrix)
- {
- }
}
}
diff --git a/src/ImageProcessor/Filters/ImageFilterExtensions.cs b/src/ImageProcessor/Filters/ImageFilterExtensions.cs
index f3913d96b..343454e7a 100644
--- a/src/ImageProcessor/Filters/ImageFilterExtensions.cs
+++ b/src/ImageProcessor/Filters/ImageFilterExtensions.cs
@@ -47,6 +47,69 @@ namespace ImageProcessor.Filters
return source.Process(source.Bounds, new Blend(image, percent));
}
+ ///
+ /// Combines the given image together with the current one by blending their pixels.
+ ///
+ /// The image this method extends.
+ /// The image to blend with the currently processing image.
+ /// The opacity of the image image to blend. Must be between 0 and 100.
+ ///
+ /// The structure that specifies the portion of the image object to alter.
+ ///
+ /// The .
+ public static Image Blend(this Image source, ImageBase image, int percent, Rectangle rectangle)
+ {
+ return source.Process(rectangle, new Blend(image, percent));
+ }
+
+ ///
+ /// Applies black and white toning to the image.
+ ///
+ /// The image this method extends.
+ /// The .
+ public static Image BlackWhite(this Image source)
+ {
+ return BlackWhite(source, source.Bounds);
+ }
+
+ ///
+ /// Applies black and white toning to the image.
+ ///
+ /// The image this method extends.
+ ///
+ /// The structure that specifies the portion of the image object to alter.
+ ///
+ /// The .
+ public static Image BlackWhite(this Image source, Rectangle rectangle)
+ {
+ return source.Process(rectangle, new BlackWhite());
+ }
+
+ ///
+ /// Alters the brightness component of the image.
+ ///
+ /// The image this method extends.
+ /// The new brightness of the image. Must be between -100 and 100.
+ /// The .
+ public static Image Brightness(this Image source, int amount)
+ {
+ return Brightness(source, amount, source.Bounds);
+ }
+
+ ///
+ /// Alters the brightness component of the image.
+ ///
+ /// The image this method extends.
+ /// The new brightness of the image. Must be between -100 and 100.
+ ///
+ /// The structure that specifies the portion of the image object to alter.
+ ///
+ /// The .
+ public static Image Brightness(this Image source, int amount, Rectangle rectangle)
+ {
+ return source.Process(rectangle, new Brightness(amount));
+ }
+
///
/// Alters the contrast component of the image.
///
@@ -72,6 +135,33 @@ namespace ImageProcessor.Filters
return source.Process(rectangle, new Contrast(amount));
}
+ ///
+ /// Applies greyscale toning to the image.
+ ///
+ /// The image this method extends.
+ /// The formula to apply to perform the operation.
+ /// The .
+ public static Image Greyscale(this Image source, GreyscaleMode mode = GreyscaleMode.Bt709)
+ {
+ return Greyscale(source, source.Bounds, mode);
+ }
+
+ ///
+ /// Applies greyscale toning to the image.
+ ///
+ /// The image this method extends.
+ ///
+ /// The structure that specifies the portion of the image object to alter.
+ ///
+ /// The formula to apply to perform the operation.
+ /// The .
+ public static Image Greyscale(this Image source, Rectangle rectangle, GreyscaleMode mode = GreyscaleMode.Bt709)
+ {
+ return mode == GreyscaleMode.Bt709
+ ? source.Process(rectangle, new GreyscaleBt709())
+ : source.Process(rectangle, new GreyscaleBt601());
+ }
+
///
/// Inverts the colors of the image.
///
@@ -96,76 +186,120 @@ namespace ImageProcessor.Filters
}
///
- /// Applies sepia toning to the image.
+ /// Alters the colors of the image recreating an old Kodachrome camera effect.
///
/// The image this method extends.
/// The .
- public static Image Sepia(this Image source)
+ public static Image Kodachrome(this Image source)
{
- return Sepia(source, source.Bounds);
+ return Kodachrome(source, source.Bounds);
}
///
- /// Applies sepia toning to the image.
+ /// Alters the colors of the image recreating an old Kodachrome camera effect.
///
/// The image this method extends.
///
/// The structure that specifies the portion of the image object to alter.
///
/// The .
- public static Image Sepia(this Image source, Rectangle rectangle)
+ public static Image Kodachrome(this Image source, Rectangle rectangle)
{
- return source.Process(rectangle, new Sepia());
+ return source.Process(rectangle, new Kodachrome());
}
///
- /// Applies black and white toning to the image.
+ /// Alters the colors of the image recreating an old Lomograph camera effect.
///
/// The image this method extends.
/// The .
- public static Image BlackWhite(this Image source)
+ public static Image Lomograph(this Image source)
{
- return BlackWhite(source, source.Bounds);
+ return Lomograph(source, source.Bounds);
}
///
- /// Applies black and white toning to the image.
+ /// Alters the colors of the image recreating an old Lomograph camera effect.
///
/// The image this method extends.
///
/// The structure that specifies the portion of the image object to alter.
///
/// The .
- public static Image BlackWhite(this Image source, Rectangle rectangle)
+ public static Image Lomograph(this Image source, Rectangle rectangle)
{
- return source.Process(rectangle, new BlackWhite());
+ return source.Process(rectangle, new Lomograph());
}
///
- /// Applies greyscale toning to the image.
+ /// Alters the colors of the image recreating an old Polaroid camera effect.
///
/// The image this method extends.
- /// The formula to apply to perform the operation.
/// The .
- public static Image Greyscale(this Image source, GreyscaleMode mode = GreyscaleMode.Bt709)
+ public static Image Polaroid(this Image source)
{
- return Greyscale(source, source.Bounds, mode);
+ return Polaroid(source, source.Bounds);
}
///
- /// Applies greyscale toning to the image.
+ /// Alters the colors of the image recreating an old Polaroid camera effect.
///
/// The image this method extends.
///
/// The structure that specifies the portion of the image object to alter.
///
- /// The formula to apply to perform the operation.
/// The .
- public static Image Greyscale(this Image source, Rectangle rectangle, GreyscaleMode mode = GreyscaleMode.Bt709)
+ public static Image Polaroid(this Image source, Rectangle rectangle)
{
- return mode == GreyscaleMode.Bt709
- ? source.Process(rectangle, new GreyscaleBt709())
- : source.Process(rectangle, new GreyscaleBt601());
+ return source.Process(rectangle, new Polaroid());
+ }
+
+ ///
+ /// Alters the saturation component of the image.
+ ///
+ /// The image this method extends.
+ /// The new saturation of the image. Must be between -100 and 100.
+ /// The .
+ public static Image Saturation(this Image source, int amount)
+ {
+ return Saturation(source, amount, source.Bounds);
+ }
+
+ ///
+ /// Alters the saturation component of the image.
+ ///
+ /// The image this method extends.
+ /// The new saturation of the image. Must be between -100 and 100.
+ ///
+ /// The structure that specifies the portion of the image object to alter.
+ ///
+ /// The .
+ public static Image Saturation(this Image source, int amount, Rectangle rectangle)
+ {
+ return source.Process(rectangle, new Saturation(amount));
+ }
+
+ ///
+ /// Applies sepia toning to the image.
+ ///
+ /// The image this method extends.
+ /// The .
+ public static Image Sepia(this Image source)
+ {
+ return Sepia(source, source.Bounds);
+ }
+
+ ///
+ /// Applies sepia toning to the image.
+ ///
+ /// The image this method extends.
+ ///
+ /// The structure that specifies the portion of the image object to alter.
+ ///
+ /// The .
+ public static Image Sepia(this Image source, Rectangle rectangle)
+ {
+ return source.Process(rectangle, new Sepia());
}
}
}