Browse Source

Convert photo effects

pull/404/head
James Jackson-South 8 years ago
parent
commit
32dfb7cb61
  1. 2
      src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs
  2. 72
      src/ImageSharp/Processing/ColorMatrix/Matrix4x4Extensions.cs
  3. 29
      src/ImageSharp/Processing/Processors/ColorMatrix/BlackWhiteProcessor.cs
  4. 23
      src/ImageSharp/Processing/Processors/ColorMatrix/KodachromeProcessor.cs
  5. 15
      src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs
  6. 24
      src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs

2
src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs

@ -43,4 +43,4 @@ namespace SixLabors.ImageSharp
return source;
}
}
}
}

72
src/ImageSharp/Processing/ColorMatrix/Matrix4x4Extensions.cs

@ -12,6 +12,78 @@ namespace SixLabors.ImageSharp.Processing
// ReSharper disable once InconsistentNaming
public static class Matrix4x4Extensions
{
/// <summary>
/// Gets an approximated black and white filter
/// </summary>
public static Matrix4x4 BlackWhiteFilter { get; } = new Matrix4x4()
{
M11 = 1.5F,
M12 = 1.5F,
M13 = 1.5F,
M21 = 1.5F,
M22 = 1.5F,
M23 = 1.5F,
M31 = 1.5F,
M32 = 1.5F,
M33 = 1.5F,
M41 = -1F,
M42 = -1F,
M43 = -1F,
M44 = 1
};
/// <summary>
/// Gets a filter recreating an old Kodachrome camera effect.
/// </summary>
public static Matrix4x4 KodachromeFilter { get; } = new Matrix4x4
{
M11 = 0.7297023F,
M22 = 0.6109577F,
M33 = 0.597218F,
M41 = 0.105F,
M42 = 0.145F,
M43 = 0.155F,
M44 = 1
}
* CreateSaturateFilter(1.2F) * CreateContrastFilter(1.35F);
/// <summary>
/// Gets a filter recreating an old Lomograph camera effect.
/// </summary>
public static Matrix4x4 LomographFilter { get; } = new Matrix4x4
{
M11 = 1.5F,
M22 = 1.45F,
M33 = 1.16F,
M41 = -.1F,
M42 = -.02F,
M43 = -.07F,
M44 = 1
}
* CreateSaturateFilter(1.1F) * CreateContrastFilter(1.33F);
/// <summary>
/// Gets a filter recreating an old Polaroid camera effect.
/// </summary>
public static Matrix4x4 PolaroidFilter { get; } = new Matrix4x4
{
M11 = 1.538F,
M12 = -0.062F,
M13 = -0.262F,
M21 = -0.022F,
M22 = 1.578F,
M23 = -0.022F,
M31 = .216F,
M32 = -.16F,
M33 = 1.5831F,
M41 = 0.02F,
M42 = -0.05F,
M43 = -0.05F,
M44 = 1
};
/// <summary>
/// Create a brightness filter matrix using the given amount.
/// </summary>

29
src/ImageSharp/Processing/Processors/ColorMatrix/BlackWhiteProcessor.cs

@ -1,34 +1,23 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors
{
/// <summary>
/// Converts the colors of the image to their black and white equivalent.
/// Applies a black and white filter matrix to the image
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class BlackWhiteProcessor<TPixel> : ColorMatrixProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class BlackWhiteProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
/// <summary>
/// Initializes a new instance of the <see cref="BlackWhiteProcessor{TPixel}"/> class.
/// </summary>
public BlackWhiteProcessor()
: base(Matrix4x4Extensions.BlackWhiteFilter)
{
M11 = 1.5F,
M12 = 1.5F,
M13 = 1.5F,
M21 = 1.5F,
M22 = 1.5F,
M23 = 1.5F,
M31 = 1.5F,
M32 = 1.5F,
M33 = 1.5F,
M41 = -1F,
M42 = -1F,
M43 = -1F,
M44 = 1
};
}
}
}

23
src/ImageSharp/Processing/Processors/ColorMatrix/KodachromeProcessor.cs

@ -1,28 +1,23 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing.Processors
{
/// <summary>
/// Converts the colors of the image recreating an old Kodachrome camera effect.
/// Applies a filter matrix recreating an old Kodachrome camera effect matrix to the image
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class KodachromeProcessor<TPixel> : ColorMatrixProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
internal class KodachromeProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4
/// <summary>
/// Initializes a new instance of the <see cref="KodachromeProcessor{TPixel}"/> class.
/// </summary>
public KodachromeProcessor()
: base(Matrix4x4Extensions.KodachromeFilter)
{
M11 = 0.6997023F,
M22 = 0.4609577F,
M33 = 0.397218F,
M41 = 0.005F,
M42 = -0.005F,
M43 = 0.005F,
M44 = 1
};
}
}
}

15
src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Converts the colors of the image recreating an old Lomograph effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class LomographProcessor<TPixel> : ColorMatrixProcessor<TPixel>
internal class LomographProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private static readonly TPixel VeryDarkGreen = ColorBuilder<TPixel>.FromRGBA(0, 10, 0, 255);
@ -22,22 +22,11 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// </summary>
/// <param name="options">The options effecting blending and composition.</param>
public LomographProcessor(GraphicsOptions options)
: base(Matrix4x4Extensions.LomographFilter)
{
this.options = options;
}
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = 1.5F,
M22 = 1.45F,
M33 = 1.11F,
M41 = -.1F,
M42 = .0F,
M43 = -.08F,
M44 = 1
};
/// <inheritdoc/>
protected override void AfterApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{

24
src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
@ -11,11 +10,11 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Converts the colors of the image recreating an old Polaroid effect.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class PolaroidProcessor<TPixel> : ColorMatrixProcessor<TPixel>
internal class PolaroidProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private static readonly TPixel VeryDarkOrange = ColorBuilder<TPixel>.FromRGB(102, 34, 0);
private static readonly TPixel LightOrange = ColorBuilder<TPixel>.FromRGBA(255, 153, 102, 178);
private static readonly TPixel LightOrange = ColorBuilder<TPixel>.FromRGBA(255, 153, 102, 128);
private readonly GraphicsOptions options;
/// <summary>
@ -23,28 +22,11 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// </summary>
/// <param name="options">The options effecting blending and composition.</param>
public PolaroidProcessor(GraphicsOptions options)
: base(Matrix4x4Extensions.PolaroidFilter)
{
this.options = options;
}
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = 1.538F,
M12 = -0.062F,
M13 = -0.262F,
M21 = -0.022F,
M22 = 1.578F,
M23 = -0.022F,
M31 = .216F,
M32 = -.16F,
M33 = 1.5831F,
M41 = 0.02F,
M42 = -0.05F,
M43 = -0.05F,
M44 = 1
};
/// <inheritdoc/>
protected override void AfterApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{

Loading…
Cancel
Save