Browse Source

Remove Compand from IImageProcessor

af/merge-core
James Jackson-South 9 years ago
parent
commit
91209de88b
  1. 6
      src/ImageSharp/Image/IImageProcessor.cs
  2. 3
      src/ImageSharp/Processing/Processors/CloningImageProcessor.cs
  3. 1
      src/ImageSharp/Processing/Processors/ColorMatrix/BlackWhiteProcessor.cs
  4. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs
  5. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs
  6. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs
  7. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs
  8. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs
  9. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs
  10. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs
  11. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs
  12. 45
      src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs
  13. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt601Processor.cs
  14. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt709Processor.cs
  15. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs
  16. 8
      src/ImageSharp/Processing/Processors/ColorMatrix/IColorMatrixProcessor.cs
  17. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/KodachromeProcessor.cs
  18. 5
      src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs
  19. 13
      src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs
  20. 3
      src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs
  21. 1
      src/ImageSharp/Processing/Processors/ColorMatrix/SepiaProcessor.cs
  22. 3
      src/ImageSharp/Processing/Processors/ImageProcessor.cs
  23. 5
      src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs

6
src/ImageSharp/Image/IImageProcessor.cs

@ -13,12 +13,6 @@ namespace SixLabors.ImageSharp.Processing
public interface IImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Gets or sets a value indicating whether to compress
/// or expand individual pixel colors the value on processing.
/// </summary>
bool Compand { get; set; }
/// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TPixel}"/>.
/// </summary>

3
src/ImageSharp/Processing/Processors/CloningImageProcessor.cs

@ -15,9 +15,6 @@ namespace SixLabors.ImageSharp.Processing
internal abstract class CloningImageProcessor<TPixel> : ICloningImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public virtual bool Compand { get; set; } = false;
/// <inheritdoc/>
public Image<TPixel> CloneAndApply(Image<TPixel> source, Rectangle sourceRectangle)
{

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

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;

3
src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = .618F,
M12 = .163F,

3
src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = .299F,
M12 = .299F,

3
src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = 0.8F,
M12 = 0.258F,

3
src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = 0.625F,
M12 = 0.7F,

3
src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = 0.817F,
M12 = 0.333F,

3
src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = 0.567F,
M12 = 0.558F,

3
src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = 0.967F,
M21 = 0.33F,

3
src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = 0.95F,
M21 = 0.05F,

45
src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs

@ -13,14 +13,14 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// The color matrix filter. Inherit from this class to perform operation involving color matrices.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal abstract class ColorMatrixProcessor<TPixel> : ImageProcessor<TPixel>, IColorMatrixFilter<TPixel>
internal abstract class ColorMatrixProcessor<TPixel> : ImageProcessor<TPixel>, IColorMatrixProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public abstract Matrix4x4 Matrix { get; }
/// <inheritdoc/>
public override bool Compand { get; set; } = true;
public virtual bool Compand { get; set; } = true;
/// <inheritdoc/>
protected override void OnApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
@ -50,31 +50,28 @@ namespace SixLabors.ImageSharp.Processing.Processors
Matrix4x4 matrix = this.Matrix;
bool compand = this.Compand;
using (PixelAccessor<TPixel> sourcePixels = source.Lock())
{
Parallel.For(
minY,
maxY,
source.Configuration.ParallelOptions,
y =>
{
Span<TPixel> row = source.GetRowSpan(y - startY);
Parallel.For(
minY,
maxY,
source.Configuration.ParallelOptions,
y =>
{
Span<TPixel> row = source.GetRowSpan(y - startY);
for (int x = minX; x < maxX; x++)
{
ref TPixel pixel = ref row[x - startX];
var vector = pixel.ToVector4();
for (int x = minX; x < maxX; x++)
{
ref TPixel pixel = ref row[x - startX];
var vector = pixel.ToVector4();
if (compand)
{
vector = vector.Expand();
}
if (compand)
{
vector = vector.Expand();
}
vector = Vector4.Transform(vector, matrix);
pixel.PackFromVector4(compand ? vector.Compress() : vector);
}
});
}
vector = Vector4.Transform(vector, matrix);
pixel.PackFromVector4(compand ? vector.Compress() : vector);
}
});
}
}
}

3
src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt601Processor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -16,7 +15,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = .299F,
M12 = .299F,

3
src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt709Processor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -16,7 +15,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = .2126F,
M12 = .2126F,

3
src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -46,7 +45,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
// The matrix is set up to preserve the luminance of the image.
// See http://graficaobscura.com/matrix/index.html
// Number are taken from https://msdn.microsoft.com/en-us/library/jj192162(v=vs.85).aspx
Matrix4x4 matrix4X4 = new Matrix4x4()
var matrix4X4 = new Matrix4x4
{
M11 = lumR + (cosradians * oneMinusLumR) - (sinradians * lumR),
M12 = lumR - (cosradians * lumR) - (sinradians * 0.143F),

8
src/ImageSharp/Processing/Processors/ColorMatrix/IColorMatrixFilter.cs → src/ImageSharp/Processing/Processors/ColorMatrix/IColorMatrixProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -12,12 +11,17 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// alter the image pixels.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal interface IColorMatrixFilter<TPixel> : IImageProcessor<TPixel>
internal interface IColorMatrixProcessor<TPixel> : IImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Gets the <see cref="Matrix4x4"/> used to alter the image.
/// </summary>
Matrix4x4 Matrix { get; }
/// <summary>
/// Gets or sets a value indicating whether to compress or expand individual pixel color values on processing.
/// </summary>
bool Compand { get; set; }
}
}

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

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -15,7 +14,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = 0.6997023F,
M22 = 0.4609577F,

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

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
@ -16,7 +15,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
where TPixel : struct, IPixel<TPixel>
{
private static readonly TPixel VeryDarkGreen = ColorBuilder<TPixel>.FromRGBA(0, 10, 0, 255);
private GraphicsOptions options;
private readonly GraphicsOptions options;
/// <summary>
/// Initializes a new instance of the <see cref="LomographProcessor{TPixel}" /> class.
@ -28,7 +27,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
}
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = 1.5F,
M22 = 1.45F,

13
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;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
@ -15,9 +14,9 @@ namespace SixLabors.ImageSharp.Processing.Processors
internal class PolaroidProcessor<TPixel> : ColorMatrixProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private static TPixel veryDarkOrange = ColorBuilder<TPixel>.FromRGB(102, 34, 0);
private static TPixel lightOrange = ColorBuilder<TPixel>.FromRGBA(255, 153, 102, 178);
private GraphicsOptions options;
private static readonly TPixel VeryDarkOrange = ColorBuilder<TPixel>.FromRGB(102, 34, 0);
private static readonly TPixel LightOrange = ColorBuilder<TPixel>.FromRGBA(255, 153, 102, 178);
private readonly GraphicsOptions options;
/// <summary>
/// Initializes a new instance of the <see cref="PolaroidProcessor{TPixel}" /> class.
@ -29,7 +28,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
}
/// <inheritdoc/>
public override Matrix4x4 Matrix => new Matrix4x4()
public override Matrix4x4 Matrix => new Matrix4x4
{
M11 = 1.538F,
M12 = -0.062F,
@ -49,8 +48,8 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// <inheritdoc/>
protected override void AfterApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
{
new VignetteProcessor<TPixel>(veryDarkOrange, this.options).Apply(source, sourceRectangle);
new GlowProcessor<TPixel>(lightOrange, source.Width / 4F, this.options).Apply(source, sourceRectangle);
new VignetteProcessor<TPixel>(VeryDarkOrange, this.options).Apply(source, sourceRectangle);
new GlowProcessor<TPixel>(LightOrange, source.Width / 4F, this.options).Apply(source, sourceRectangle);
}
}
}

3
src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
@ -39,7 +38,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
float saturationComplementG = 0.6094f * saturationComplement;
float saturationComplementB = 0.0820f * saturationComplement;
Matrix4x4 matrix4X4 = new Matrix4x4
var matrix4X4 = new Matrix4x4
{
M11 = saturationComplementR + saturationFactor,
M12 = saturationComplementR,

1
src/ImageSharp/Processing/Processors/ColorMatrix/SepiaProcessor.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;

3
src/ImageSharp/Processing/Processors/ImageProcessor.cs

@ -15,9 +15,6 @@ namespace SixLabors.ImageSharp.Processing
internal abstract class ImageProcessor<TPixel> : IImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public virtual bool Compand { get; set; } = false;
/// <inheritdoc/>
public void Apply(Image<TPixel> source, Rectangle sourceRectangle)
{

5
src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs

@ -42,6 +42,11 @@ namespace SixLabors.ImageSharp.Processing.Processors
{
}
/// <summary>
/// Gets or sets a value indicating whether to compress or expand individual pixel color values on processing.
/// </summary>
public bool Compand { get; set; }
/// <inheritdoc/>
protected override Image<TPixel> CreateDestination(Image<TPixel> source, Rectangle sourceRectangle)
{

Loading…
Cancel
Save