mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: 741ed5325553c7e521375e2b6168cfd345fe69d5 Former-commit-id: f290ab071672406c5f3d846cedea2e7c280329c0 Former-commit-id: 1ca475830cd7732a17fb3f407418189aea692e8eaf/merge-core
16 changed files with 674 additions and 4 deletions
@ -0,0 +1,35 @@ |
|||
// <copyright file="BlackWhite.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Converts the colors of the image to their black and white equivalent.
|
|||
/// </summary>
|
|||
public class BlackWhite : ColorMatrixFilter |
|||
{ |
|||
/// <summary>
|
|||
/// The BlackWhite matrix.
|
|||
/// TODO: Calculate a matrix that works in the linear color space.
|
|||
/// </summary>
|
|||
private static readonly ColorMatrix Matrix = new ColorMatrix( |
|||
new[] |
|||
{ |
|||
new[] { 1.5f, 1.5f, 1.5f, 0, 0 }, |
|||
new[] { 1.5f, 1.5f, 1.5f, 0, 0 }, |
|||
new[] { 1.5f, 1.5f, 1.5f, 0, 0 }, |
|||
new float[] { 0, 0, 0, 1, 0 }, |
|||
new float[] { -1, -1, -1, 0, 1 } |
|||
}); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="BlackWhite"/> class.
|
|||
/// </summary>
|
|||
public BlackWhite() |
|||
: base(Matrix, false) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,273 @@ |
|||
// --------------------------------------------------------------------------------------------------------------------
|
|||
// <copyright file="ColorMatrix.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
// --------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessor.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Defines a 5 x 5 matrix that contains the coordinates for the RGBAW color space.
|
|||
/// </summary>
|
|||
public sealed class ColorMatrix |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ColorMatrix"/> class.
|
|||
/// </summary>
|
|||
public ColorMatrix() |
|||
{ |
|||
// Setup the identity matrix by default
|
|||
this.Matrix00 = 1.0f; |
|||
this.Matrix11 = 1.0f; |
|||
this.Matrix22 = 1.0f; |
|||
this.Matrix33 = 1.0f; |
|||
this.Matrix44 = 1.0f; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ColorMatrix"/> class with the
|
|||
/// elements in the specified matrix.
|
|||
/// </summary>
|
|||
/// <param name="colorMatrix">
|
|||
/// The elements defining the new Color Matrix.
|
|||
/// </param>
|
|||
public ColorMatrix(float[][] colorMatrix) |
|||
{ |
|||
this.SetMatrix(colorMatrix); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 0th row and 0th column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix00 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 0th row and 1st column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix01 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 0th row and 2nd column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix02 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 0th row and 3rd column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix03 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 0th row and 4th column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix04 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 1st row and 0th column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix10 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 1st row and 1st column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix11 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 1st row and 2nd column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix12 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 1st row and 3rd column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix13 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 1st row and 4th column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix14 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 2nd row and 0th column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix20 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 2nd row and 1st column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix21 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 2nd row and 2nd column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix22 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 2nd row and 3rd column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix23 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 2nd row and 4th column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix24 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 3rd row and 0th column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix30 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 3rd row and 1st column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix31 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 3rd row and 2nd column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix32 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 3rd row and 3rd column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix33 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 3rd row and 4th column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix34 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 4th row and 0th column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix40 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 4th row and 1st column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix41 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 4th row and 2nd column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix42 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 4th row and 3rd column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix43 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the element at the 4th row and 4th column of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
public float Matrix44 { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the value of the specified element of this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
/// <param name="row">
|
|||
/// The row index.
|
|||
/// </param>
|
|||
/// <param name="column">
|
|||
/// The column index.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// The <see cref="float"/>.
|
|||
/// </returns>
|
|||
public float this[int row, int column] |
|||
{ |
|||
get |
|||
{ |
|||
return this.GetMatrix()[row][column]; |
|||
} |
|||
|
|||
set |
|||
{ |
|||
float[][] tempMatrix = this.GetMatrix(); |
|||
|
|||
tempMatrix[row][column] = value; |
|||
|
|||
this.SetMatrix(tempMatrix); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Sets the values of this <see cref="ColorMatrix"/> to the values contained within the elements.
|
|||
/// </summary>
|
|||
/// <param name="colorMatrix">
|
|||
/// The new color matrix.
|
|||
/// </param>
|
|||
internal void SetMatrix(float[][] colorMatrix) |
|||
{ |
|||
this.Matrix00 = colorMatrix[0][0]; |
|||
this.Matrix01 = colorMatrix[0][1]; |
|||
this.Matrix02 = colorMatrix[0][2]; |
|||
this.Matrix03 = colorMatrix[0][3]; |
|||
this.Matrix04 = colorMatrix[0][4]; |
|||
this.Matrix10 = colorMatrix[1][0]; |
|||
this.Matrix11 = colorMatrix[1][1]; |
|||
this.Matrix12 = colorMatrix[1][2]; |
|||
this.Matrix13 = colorMatrix[1][3]; |
|||
this.Matrix14 = colorMatrix[1][4]; |
|||
this.Matrix20 = colorMatrix[2][0]; |
|||
this.Matrix21 = colorMatrix[2][1]; |
|||
this.Matrix22 = colorMatrix[2][2]; |
|||
this.Matrix23 = colorMatrix[2][3]; |
|||
this.Matrix24 = colorMatrix[2][4]; |
|||
this.Matrix30 = colorMatrix[3][0]; |
|||
this.Matrix31 = colorMatrix[3][1]; |
|||
this.Matrix32 = colorMatrix[3][2]; |
|||
this.Matrix33 = colorMatrix[3][3]; |
|||
this.Matrix34 = colorMatrix[3][4]; |
|||
this.Matrix40 = colorMatrix[4][0]; |
|||
this.Matrix41 = colorMatrix[4][1]; |
|||
this.Matrix42 = colorMatrix[4][2]; |
|||
this.Matrix43 = colorMatrix[4][3]; |
|||
this.Matrix44 = colorMatrix[4][4]; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets this <see cref="ColorMatrix"/>.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// The <see cref="T:float[][]"/>.
|
|||
/// </returns>
|
|||
internal float[][] GetMatrix() |
|||
{ |
|||
float[][] returnMatrix = new float[5][]; |
|||
|
|||
for (int i = 0; i < 5; i++) |
|||
{ |
|||
returnMatrix[i] = new float[5]; |
|||
} |
|||
|
|||
returnMatrix[0][0] = this.Matrix00; |
|||
returnMatrix[0][1] = this.Matrix01; |
|||
returnMatrix[0][2] = this.Matrix02; |
|||
returnMatrix[0][3] = this.Matrix03; |
|||
returnMatrix[0][4] = this.Matrix04; |
|||
returnMatrix[1][0] = this.Matrix10; |
|||
returnMatrix[1][1] = this.Matrix11; |
|||
returnMatrix[1][2] = this.Matrix12; |
|||
returnMatrix[1][3] = this.Matrix13; |
|||
returnMatrix[1][4] = this.Matrix14; |
|||
returnMatrix[2][0] = this.Matrix20; |
|||
returnMatrix[2][1] = this.Matrix21; |
|||
returnMatrix[2][2] = this.Matrix22; |
|||
returnMatrix[2][3] = this.Matrix23; |
|||
returnMatrix[2][4] = this.Matrix24; |
|||
returnMatrix[3][0] = this.Matrix30; |
|||
returnMatrix[3][1] = this.Matrix31; |
|||
returnMatrix[3][2] = this.Matrix32; |
|||
returnMatrix[3][3] = this.Matrix33; |
|||
returnMatrix[3][4] = this.Matrix34; |
|||
returnMatrix[4][0] = this.Matrix40; |
|||
returnMatrix[4][1] = this.Matrix41; |
|||
returnMatrix[4][2] = this.Matrix42; |
|||
returnMatrix[4][3] = this.Matrix43; |
|||
returnMatrix[4][4] = this.Matrix44; |
|||
|
|||
return returnMatrix; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,101 @@ |
|||
// <copyright file="ColorMatrixFilter.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// The color matrix filter.
|
|||
/// </summary>
|
|||
public class ColorMatrixFilter : ParallelImageProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ColorMatrixFilter"/> class.
|
|||
/// </summary>
|
|||
/// <param name="matrix">The matrix to apply.</param>
|
|||
/// <param name="gammaAdjust">Whether to gamma adjust the colors before applying the matrix.</param>
|
|||
public ColorMatrixFilter(ColorMatrix matrix, bool gammaAdjust) |
|||
{ |
|||
this.Value = matrix; |
|||
this.GammaAdjust = gammaAdjust; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the matrix value.
|
|||
/// </summary>
|
|||
public ColorMatrix Value { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value indicating whether to gamma adjust the colors before applying the matrix.
|
|||
/// </summary>
|
|||
public bool GammaAdjust { 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; |
|||
ColorMatrix matrix = this.Value; |
|||
Bgra previousColor = source[0, 0]; |
|||
Bgra pixelValue = this.ApplyMatrix(previousColor, matrix); |
|||
|
|||
for (int y = startY; y < endY; y++) |
|||
{ |
|||
if (y >= sourceY && y < sourceBottom) |
|||
{ |
|||
for (int x = startX; x < endX; x++) |
|||
{ |
|||
Bgra sourceColor = source[x, y]; |
|||
|
|||
// Check if this is the same as the last pixel. If so use that value
|
|||
// rather than calculating it again. This is an inexpensive optimization.
|
|||
if (sourceColor != previousColor) |
|||
{ |
|||
// Perform the operation on the pixel.
|
|||
pixelValue = this.ApplyMatrix(sourceColor, matrix); |
|||
|
|||
// And setup the previous pointer
|
|||
previousColor = sourceColor; |
|||
} |
|||
|
|||
target[x, y] = pixelValue; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies the color matrix against the given color.
|
|||
/// </summary>
|
|||
/// <param name="sourceColor">The source color.</param>
|
|||
/// <param name="matrix">The matrix.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="Bgra"/>.
|
|||
/// </returns>
|
|||
private Bgra ApplyMatrix(Bgra sourceColor, ColorMatrix matrix) |
|||
{ |
|||
bool gamma = this.GammaAdjust; |
|||
|
|||
if (gamma) |
|||
{ |
|||
sourceColor = PixelOperations.ToLinear(sourceColor); |
|||
} |
|||
|
|||
int sr = sourceColor.R; |
|||
int sg = sourceColor.G; |
|||
int sb = sourceColor.B; |
|||
int sa = sourceColor.A; |
|||
|
|||
// TODO: Investigate RGBAW
|
|||
byte r = ((sr * matrix.Matrix00) + (sg * matrix.Matrix10) + (sb * matrix.Matrix20) + (sa * matrix.Matrix30) + (255f * matrix.Matrix40)).ToByte(); |
|||
byte g = ((sr * matrix.Matrix01) + (sg * matrix.Matrix11) + (sb * matrix.Matrix21) + (sa * matrix.Matrix31) + (255f * matrix.Matrix41)).ToByte(); |
|||
byte b = ((sr * matrix.Matrix02) + (sg * matrix.Matrix12) + (sb * matrix.Matrix22) + (sa * matrix.Matrix32) + (255f * matrix.Matrix42)).ToByte(); |
|||
byte a = ((sr * matrix.Matrix03) + (sg * matrix.Matrix13) + (sb * matrix.Matrix23) + (sa * matrix.Matrix33) + (255f * matrix.Matrix43)).ToByte(); |
|||
|
|||
return gamma ? PixelOperations.ToSrgb(new Bgra(b, g, r, a)) : new Bgra(b, g, r, a); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// <copyright file="GreyscaleBt601.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Converts the colors of the image to greyscale applying the formula as specified by
|
|||
/// ITU-R Recommendation BT.601 <see href="https://en.wikipedia.org/wiki/Luma_%28video%29#Rec._601_luma_versus_Rec._709_luma_coefficients"/>.
|
|||
/// </summary>
|
|||
public class GreyscaleBt601 : ColorMatrixFilter |
|||
{ |
|||
/// <summary>
|
|||
/// The inversion matrix.
|
|||
/// </summary>
|
|||
private static readonly ColorMatrix Matrix = new ColorMatrix( |
|||
new[] |
|||
{ |
|||
new float[] { 0.299f, 0.299f, 0.299f, 0, 0 }, |
|||
new float[] { 0.587f, 0.587f, 0.587f, 0, 0 }, |
|||
new float[] { 0.114f, 0.114f, 0.114f, 0, 0 }, |
|||
new float[] { 0, 0, 0, 1, 0 }, |
|||
new float[] { 0, 0, 0, 0, 1 } |
|||
}); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="GreyscaleBt601"/> class.
|
|||
/// </summary>
|
|||
public GreyscaleBt601() |
|||
: base(Matrix, true) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// <copyright file="GreyscaleBt709.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Converts the colors of the image to greyscale applying the formula as specified by
|
|||
/// ITU-R Recommendation BT.709 <see href="https://en.wikipedia.org/wiki/Rec._709#Luma_coefficients"/>.
|
|||
/// </summary>
|
|||
public class GreyscaleBt709 : ColorMatrixFilter |
|||
{ |
|||
/// <summary>
|
|||
/// The inversion matrix.
|
|||
/// </summary>
|
|||
private static readonly ColorMatrix Matrix = new ColorMatrix( |
|||
new[] |
|||
{ |
|||
new float[] { 0.2126f, 0.2126f, 0.2126f, 0, 0 }, |
|||
new float[] { 0.7152f, 0.7152f, 0.7152f, 0, 0 }, |
|||
new float[] { 0.0722f, 0.0722f, 0.0722f, 0, 0 }, |
|||
new float[] { 0, 0, 0, 1, 0 }, |
|||
new float[] { 0, 0, 0, 0, 1 } |
|||
}); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="GreyscaleBt709"/> class.
|
|||
/// </summary>
|
|||
public GreyscaleBt709() |
|||
: base(Matrix, true) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// <copyright file="Invert.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Inverts the colors of the image.
|
|||
/// </summary>
|
|||
public class Invert : ColorMatrixFilter |
|||
{ |
|||
/// <summary>
|
|||
/// The inversion matrix.
|
|||
/// TODO: With gamma adjustment enabled this leaves the image too bright.
|
|||
/// </summary>
|
|||
private static readonly ColorMatrix Matrix = new ColorMatrix( |
|||
new[] |
|||
{ |
|||
new float[] { -1, 0, 0, 0, 0 }, |
|||
new float[] { 0, -1, 0, 0, 0 }, |
|||
new float[] { 0, 0, -1, 0, 0 }, |
|||
new float[] { 0, 0, 0, 1, 0 }, |
|||
new float[] { 1, 1, 1, 0, 1 } |
|||
}); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Invert"/> class.
|
|||
/// </summary>
|
|||
public Invert() |
|||
: base(Matrix, false) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// <copyright file="Lomograph.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating an old Lomograph effect.
|
|||
/// </summary>
|
|||
public class Lomograph : ColorMatrixFilter |
|||
{ |
|||
/// <summary>
|
|||
/// The Lomograph matrix. Purely artistic in composition.
|
|||
/// TODO: Calculate a matrix that works in the linear color space.
|
|||
/// </summary>
|
|||
private static readonly ColorMatrix Matrix = new ColorMatrix( |
|||
new[] |
|||
{ |
|||
new[] { 1.50f, 0, 0, 0, 0 }, |
|||
new[] { 0, 1.45f, 0, 0, 0 }, |
|||
new[] { 0, 0, 1.09f, 0, 0 }, |
|||
new float[] { 0, 0, 0, 1, 0 }, |
|||
new[] { -0.10f, 0.05f, -0.08f, 0, 1 } |
|||
}); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Lomograph"/> class.
|
|||
/// </summary>
|
|||
public Lomograph() |
|||
: base(Matrix, false) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// <copyright file="Polaroid.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating an old Polaroid effect.
|
|||
/// </summary>
|
|||
public class Polaroid : ColorMatrixFilter |
|||
{ |
|||
/// <summary>
|
|||
/// The Polaroid matrix. Purely artistic in composition.
|
|||
/// TODO: Calculate a matrix that works in the linear color space.
|
|||
/// </summary>
|
|||
private static readonly ColorMatrix Matrix = new ColorMatrix( |
|||
new[] |
|||
{ |
|||
new[] { 1.638f, -0.062f, -0.262f, 0, 0 }, |
|||
new[] { -0.122f, 1.378f, -0.122f, 0, 0 }, |
|||
new[] { 1.016f, -0.016f, 1.383f, 0, 0 }, |
|||
new float[] { 0, 0, 0, 1, 0 }, |
|||
new[] { 0.06f, -0.05f, -0.05f, 0, 1 } |
|||
}); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Polaroid"/> class.
|
|||
/// </summary>
|
|||
public Polaroid() |
|||
: base(Matrix, false) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// <copyright file="Sepia.cs" company="James South">
|
|||
// Copyright © James South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Converts the colors of the image to their sepia equivalent recreating an old photo effect.
|
|||
/// </summary>
|
|||
public class Sepia : ColorMatrixFilter |
|||
{ |
|||
/// <summary>
|
|||
/// The sepia matrix.
|
|||
/// TODO: Calculate a matrix that works in the linear color space.
|
|||
/// </summary>
|
|||
private static readonly ColorMatrix Matrix = new ColorMatrix( |
|||
new[] |
|||
{ |
|||
new[] { .393f, .349f, .272f, 0, 0 }, |
|||
new[] { .769f, .686f, .534f, 0, 0 }, |
|||
new[] { .189f, .168f, .131f, 0, 0 }, |
|||
new float[] { 0, 0, 0, 1, 0 }, |
|||
new float[] { 0, 0, 0, 0, 1 } |
|||
}); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Sepia"/> class.
|
|||
/// </summary>
|
|||
public Sepia() |
|||
: base(Matrix, false) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,5 +1,5 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="SharpZipLib.Portable" version="0.86.0.0002" targetFramework="portable-net45+win8+wp8" /> |
|||
<package id="StyleCop.Analyzers" version="1.0.0-beta013" targetFramework="portable45-net45+win8+wp8" developmentDependency="true" /> |
|||
<package id="StyleCop.Analyzers" version="1.0.0-beta015" targetFramework="portable-net45+dnxcore50+win+wpa81+wp80" developmentDependency="true" /> |
|||
</packages> |
|||
Loading…
Reference in new issue