Browse Source

Complete Quantization and Dithering

af/merge-core
James Jackson-South 8 years ago
parent
commit
c93c3c7a71
  1. 2
      src/ImageSharp/Processing/Binarization/BinaryDiffuseExtensions.cs
  2. 2
      src/ImageSharp/Processing/Binarization/BinaryDitherExtensions.cs
  3. 2
      src/ImageSharp/Processing/Binarization/Processors/BinaryErrorDiffusionProcessor.cs
  4. 2
      src/ImageSharp/Processing/Binarization/Processors/BinaryOrderedDitherProcessor.cs
  5. 0
      src/ImageSharp/Processing/Dithering/DHALF.TXT
  6. 0
      src/ImageSharp/Processing/Dithering/DITHER.TXT
  7. 43
      src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs
  8. 32
      src/ImageSharp/Processing/Dithering/DitherExtensions.cs
  9. 4
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/AtkinsonDiffuser.cs
  10. 3
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/BurksDiffuser.cs
  11. 2
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/Diffusers.cs
  12. 2
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs
  13. 3
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/FloydSteinbergDiffuser.cs
  14. 2
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/IErrorDiffuser.cs
  15. 3
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/JarvisJudiceNinkeDiffuser.cs
  16. 3
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra2Diffuser.cs
  17. 3
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra3Diffuser.cs
  18. 3
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/SierraLiteDiffuser.cs
  19. 5
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/StevensonArceDiffuser.cs
  20. 3
      src/ImageSharp/Processing/Dithering/ErrorDiffusion/StuckiDiffuser.cs
  21. 2
      src/ImageSharp/Processing/Dithering/Ordered/BayerDither2x2.cs
  22. 2
      src/ImageSharp/Processing/Dithering/Ordered/BayerDither4x4.cs
  23. 2
      src/ImageSharp/Processing/Dithering/Ordered/BayerDither8x8.cs
  24. 2
      src/ImageSharp/Processing/Dithering/Ordered/Ditherers.cs
  25. 2
      src/ImageSharp/Processing/Dithering/Ordered/IOrderedDither.cs
  26. 4
      src/ImageSharp/Processing/Dithering/Ordered/OrderedDither.cs
  27. 2
      src/ImageSharp/Processing/Dithering/Ordered/OrderedDither3x3.cs
  28. 2
      src/ImageSharp/Processing/Dithering/Ordered/OrderedDitherFactory.cs
  29. 2
      src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs
  30. 2
      src/ImageSharp/Processing/Dithering/Processors/OrderedDitherPaletteProcessor.cs
  31. 0
      src/ImageSharp/Processing/Dithering/error_diffusion.txt
  32. 2
      src/ImageSharp/Processing/Quantization/IQuantizer{TPixel}.cs
  33. 8
      src/ImageSharp/Processing/Quantization/QuantizerBase{TPixel}.cs
  34. 5
      tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs
  35. 3
      tests/ImageSharp.Tests/Processing/Binarization/OrderedDitherFactoryTests.cs
  36. 3
      tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs
  37. 17
      tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs
  38. 25
      tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs

2
src/ImageSharp/Processing/Binarization/BinaryDiffuseExtensions.cs

@ -1,9 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Binarization.Processors;
using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Binarization

2
src/ImageSharp/Processing/Binarization/BinaryDitherExtensions.cs

@ -1,9 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Binarization.Processors;
using SixLabors.ImageSharp.Processing.Dithering.Ordered;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Binarization

2
src/ImageSharp/Processing/Binarization/Processors/BinaryErrorDiffusionProcessor.cs

@ -3,9 +3,9 @@
using System;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;

2
src/ImageSharp/Processing/Binarization/Processors/BinaryOrderedDitherProcessor.cs

@ -3,9 +3,9 @@
using System;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Dithering.Ordered;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;

0
src/ImageSharp/Dithering/DHALF.TXT → src/ImageSharp/Processing/Dithering/DHALF.TXT

0
src/ImageSharp/Dithering/DITHER.TXT → src/ImageSharp/Processing/Dithering/DITHER.TXT

43
src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs

@ -1,8 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion;
using SixLabors.ImageSharp.Processing.Dithering.Processors;
using SixLabors.Primitives;
@ -13,6 +13,27 @@ namespace SixLabors.ImageSharp.Processing.Dithering
/// </summary>
public static class DiffuseExtensions
{
/// <summary>
/// Dithers the image reducing it to a web-safe palette using error diffusion.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Diffuse<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> Diffuse(source, Diffusers.FloydSteinberg, .5F);
/// <summary>
/// Dithers the image reducing it to a web-safe palette using error diffusion.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Diffuse<TPixel>(this IImageProcessingContext<TPixel> source, float threshold)
where TPixel : struct, IPixel<TPixel>
=> Diffuse(source, Diffusers.FloydSteinberg, threshold);
/// <summary>
/// Dithers the image reducing it to a web-safe palette using error diffusion.
/// </summary>
@ -23,10 +44,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Diffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new ErrorDiffusionPaletteProcessor<TPixel>(diffuser, threshold));
return source;
}
=> source.ApplyProcessor(new ErrorDiffusionPaletteProcessor<TPixel>(diffuser, threshold));
/// <summary>
/// Dithers the image reducing it to a web-safe palette using error diffusion.
@ -41,10 +59,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Diffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new ErrorDiffusionPaletteProcessor<TPixel>(diffuser, threshold), rectangle);
return source;
}
=> source.ApplyProcessor(new ErrorDiffusionPaletteProcessor<TPixel>(diffuser, threshold), rectangle);
/// <summary>
/// Dithers the image reducing it to the given palette using error diffusion.
@ -57,10 +72,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Diffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold, TPixel[] palette)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new ErrorDiffusionPaletteProcessor<TPixel>(diffuser, threshold, palette));
return source;
}
=> source.ApplyProcessor(new ErrorDiffusionPaletteProcessor<TPixel>(diffuser, threshold, palette));
/// <summary>
/// Dithers the image reducing it to the given palette using error diffusion.
@ -76,9 +88,6 @@ namespace SixLabors.ImageSharp.Processing.Dithering
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Diffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold, TPixel[] palette, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new ErrorDiffusionPaletteProcessor<TPixel>(diffuser, threshold, palette), rectangle);
return source;
}
=> source.ApplyProcessor(new ErrorDiffusionPaletteProcessor<TPixel>(diffuser, threshold, palette), rectangle);
}
}

32
src/ImageSharp/Processing/Dithering/DitherExtensions.cs

@ -1,8 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Dithering.Ordered;
using SixLabors.ImageSharp.Processing.Dithering.Processors;
using SixLabors.Primitives;
@ -13,6 +13,16 @@ namespace SixLabors.ImageSharp.Processing.Dithering
/// </summary>
public static class DitherExtensions
{
/// <summary>
/// Dithers the image reducing it to a web-safe palette using Bayer4x4 ordered dithering.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Dither<TPixel>(this IImageProcessingContext<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> Dither(source, Ditherers.BayerDither4x4);
/// <summary>
/// Dithers the image reducing it to a web-safe palette using ordered dithering.
/// </summary>
@ -22,10 +32,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Dither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new OrderedDitherPaletteProcessor<TPixel>(dither));
return source;
}
=> source.ApplyProcessor(new OrderedDitherPaletteProcessor<TPixel>(dither));
/// <summary>
/// Dithers the image reducing it to the given palette using ordered dithering.
@ -37,10 +44,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Dither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither, TPixel[] palette)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new OrderedDitherPaletteProcessor<TPixel>(dither, palette));
return source;
}
=> source.ApplyProcessor(new OrderedDitherPaletteProcessor<TPixel>(dither, palette));
/// <summary>
/// Dithers the image reducing it to a web-safe palette using ordered dithering.
@ -54,10 +58,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Dither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new OrderedDitherPaletteProcessor<TPixel>(dither), rectangle);
return source;
}
=> source.ApplyProcessor(new OrderedDitherPaletteProcessor<TPixel>(dither), rectangle);
/// <summary>
/// Dithers the image reducing it to the given palette using ordered dithering.
@ -72,9 +73,6 @@ namespace SixLabors.ImageSharp.Processing.Dithering
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Dither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither, TPixel[] palette, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new OrderedDitherPaletteProcessor<TPixel>(dither, palette), rectangle);
return source;
}
=> source.ApplyProcessor(new OrderedDitherPaletteProcessor<TPixel>(dither, palette), rectangle);
}
}

4
src/ImageSharp/Dithering/ErrorDiffusion/AtkinsonDiffuser.cs → src/ImageSharp/Processing/Dithering/ErrorDiffusion/AtkinsonDiffuser.cs

@ -1,11 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering.Base;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
{
/// <summary>
/// Applies error diffusion based dithering using the Atkinson image dithering algorithm.

3
src/ImageSharp/Dithering/ErrorDiffusion/BurksDiffuser.cs → src/ImageSharp/Processing/Dithering/ErrorDiffusion/BurksDiffuser.cs

@ -1,10 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering.Base;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
{
/// <summary>
/// Applies error diffusion based dithering using the Burks image dithering algorithm.

2
src/ImageSharp/Dithering/ErrorDiffusion/Diffusers.cs → src/ImageSharp/Processing/Dithering/ErrorDiffusion/Diffusers.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
{
/// <summary>
/// Contains reusable static instances of known error diffusion algorithms

2
src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs → src/ImageSharp/Processing/Dithering/ErrorDiffusion/ErrorDiffuserBase.cs

@ -8,7 +8,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Dithering.Base
namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
{
/// <summary>
/// The base class for performing error diffusion based dithering.

3
src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinbergDiffuser.cs → src/ImageSharp/Processing/Dithering/ErrorDiffusion/FloydSteinbergDiffuser.cs

@ -1,10 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering.Base;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
{
/// <summary>
/// Applies error diffusion based dithering using the Floyd–Steinberg image dithering algorithm.

2
src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs → src/ImageSharp/Processing/Dithering/ErrorDiffusion/IErrorDiffuser.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
{
/// <summary>
/// Encapsulates properties and methods required to perform diffused error dithering on an image.

3
src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinkeDiffuser.cs → src/ImageSharp/Processing/Dithering/ErrorDiffusion/JarvisJudiceNinkeDiffuser.cs

@ -1,10 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering.Base;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
{
/// <summary>
/// Applies error diffusion based dithering using the JarvisJudiceNinke image dithering algorithm.

3
src/ImageSharp/Dithering/ErrorDiffusion/Sierra2Diffuser.cs → src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra2Diffuser.cs

@ -1,10 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering.Base;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
{
/// <summary>
/// Applies error diffusion based dithering using the Sierra2 image dithering algorithm.

3
src/ImageSharp/Dithering/ErrorDiffusion/Sierra3Diffuser.cs → src/ImageSharp/Processing/Dithering/ErrorDiffusion/Sierra3Diffuser.cs

@ -1,10 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering.Base;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
{
/// <summary>
/// Applies error diffusion based dithering using the Sierra3 image dithering algorithm.

3
src/ImageSharp/Dithering/ErrorDiffusion/SierraLiteDiffuser.cs → src/ImageSharp/Processing/Dithering/ErrorDiffusion/SierraLiteDiffuser.cs

@ -1,10 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering.Base;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
{
/// <summary>
/// Applies error diffusion based dithering using the SierraLite image dithering algorithm.

5
src/ImageSharp/Dithering/ErrorDiffusion/StevensonArceDiffuser.cs → src/ImageSharp/Processing/Dithering/ErrorDiffusion/StevensonArceDiffuser.cs

@ -1,10 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering.Base;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
{
/// <summary>
/// Applies error diffusion based dithering using the Stevenson-Arce image dithering algorithm.
@ -31,4 +30,4 @@ namespace SixLabors.ImageSharp.Dithering
{
}
}
}
}

3
src/ImageSharp/Dithering/ErrorDiffusion/StuckiDiffuser.cs → src/ImageSharp/Processing/Dithering/ErrorDiffusion/StuckiDiffuser.cs

@ -1,10 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering.Base;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion
{
/// <summary>
/// Applies error diffusion based dithering using the Stucki image dithering algorithm.

2
src/ImageSharp/Dithering/Ordered/BayerDither2x2.cs → src/ImageSharp/Processing/Dithering/Ordered/BayerDither2x2.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.Ordered
{
/// <summary>
/// Applies order dithering using the 2x2 Bayer dithering matrix.

2
src/ImageSharp/Dithering/Ordered/BayerDither4x4.cs → src/ImageSharp/Processing/Dithering/Ordered/BayerDither4x4.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.Ordered
{
/// <summary>
/// Applies order dithering using the 4x4 Bayer dithering matrix.

2
src/ImageSharp/Dithering/Ordered/BayerDither8x8.cs → src/ImageSharp/Processing/Dithering/Ordered/BayerDither8x8.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.Ordered
{
/// <summary>
/// Applies order dithering using the 8x8 Bayer dithering matrix.

2
src/ImageSharp/Dithering/Ordered/Ditherers.cs → src/ImageSharp/Processing/Dithering/Ordered/Ditherers.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.Ordered
{
/// <summary>
/// Contains reusable static instances of known ordered dither matrices

2
src/ImageSharp/Dithering/Ordered/IOrderedDither.cs → src/ImageSharp/Processing/Dithering/Ordered/IOrderedDither.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.Ordered
{
/// <summary>
/// Encapsulates properties and methods required to perform ordered dithering on an image.

4
src/ImageSharp/Dithering/Ordered/OrderedDither.cs → src/ImageSharp/Processing/Dithering/Ordered/OrderedDither.cs

@ -4,7 +4,7 @@
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.Ordered
{
/// <summary>
/// An ordered dithering matrix with equal sides of arbitrary length
@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Dithering
this.modulusY = ditherMatrix.Rows;
// Adjust the matrix range for 0-255
// It looks like it's actually possible to dither an image using it's own colors. We should investigate for V2
// TODO: It looks like it's actually possible to dither an image using it's own colors. We should investigate for V2
// https://stackoverflow.com/questions/12422407/monochrome-dithering-in-javascript-bayer-atkinson-floyd-steinberg
int multiplier = 256 / ditherMatrix.Count;
for (int y = 0; y < ditherMatrix.Rows; y++)

2
src/ImageSharp/Dithering/Ordered/OrderedDither3x3.cs → src/ImageSharp/Processing/Dithering/Ordered/OrderedDither3x3.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.Ordered
{
/// <summary>
/// Applies order dithering using the 3x3 dithering matrix.

2
src/ImageSharp/Dithering/Ordered/OrderedDitherFactory.cs → src/ImageSharp/Processing/Dithering/Ordered/OrderedDitherFactory.cs

@ -4,7 +4,7 @@
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Dithering
namespace SixLabors.ImageSharp.Processing.Dithering.Ordered
{
/// <summary>
/// A factory for creating ordered dither matrices.

2
src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs

@ -3,9 +3,9 @@
using System;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;

2
src/ImageSharp/Processing/Dithering/Processors/OrderedDitherPaletteProcessor.cs

@ -3,9 +3,9 @@
using System;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Dithering.Ordered;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;

0
src/ImageSharp/Dithering/error_diffusion.txt → src/ImageSharp/Processing/Dithering/error_diffusion.txt

2
src/ImageSharp/Processing/Quantization/IQuantizer{TPixel}.cs

@ -1,8 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion;
namespace SixLabors.ImageSharp.Processing.Quantization
{

8
src/ImageSharp/Processing/Quantization/QuantizerBase{TPixel}.cs

@ -5,9 +5,8 @@ using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion;
namespace SixLabors.ImageSharp.Processing.Quantization
{
@ -93,7 +92,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization
}
/// <summary>
/// Execute a second pass through the bitmap
/// Execute a second pass through the image
/// </summary>
/// <param name="source">The source image.</param>
/// <param name="output">The output pixel array</param>
@ -102,7 +101,8 @@ namespace SixLabors.ImageSharp.Processing.Quantization
protected abstract void SecondPass(ImageFrame<TPixel> source, byte[] output, int width, int height);
/// <summary>
/// Retrieve the palette for the quantized image. Can be called more than once so make sure calls are cached.
/// Retrieve the palette for the quantized image.
/// <remarks>Can be called more than once so make sure calls are cached.</remarks>
/// </summary>
/// <returns>
/// <see cref="T:TPixel[]"/>

5
tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs

@ -1,15 +1,16 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Binarization
{
using SixLabors.ImageSharp.Processing.Binarization;
using SixLabors.ImageSharp.Processing.Binarization.Processors;
using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion;
using SixLabors.ImageSharp.Processing.Dithering.Ordered;
public class BinaryDitherTest : BaseImageOperationsExtensionTest
{

3
tests/ImageSharp.Tests/Processing/Binarization/OrderedDitherFactoryTests.cs

@ -1,13 +1,12 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.Memory;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Binarization
{
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Dithering.Ordered;
public class OrderedDitherFactoryTests
{

3
tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using Xunit;
@ -9,6 +8,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Binarization
{
using SixLabors.ImageSharp.Processing.Dithering;
using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion;
using SixLabors.ImageSharp.Processing.Dithering.Ordered;
using SixLabors.ImageSharp.Processing.Dithering.Processors;
public class DitherTest : BaseImageOperationsExtensionTest

17
tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
@ -13,6 +12,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
{
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Binarization;
using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion;
using SixLabors.ImageSharp.Processing.Dithering.Ordered;
public class BinaryDitherTests : FileTestBase
{
@ -21,12 +22,12 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
TestImages.Png.CalliphoraPartial, TestImages.Png.Bike
};
public static readonly TheoryData<string, IOrderedDither> Ditherers = new TheoryData<string, IOrderedDither>
public static readonly TheoryData<string, IOrderedDither> OrderedDitherers = new TheoryData<string, IOrderedDither>
{
{ "Bayer8x8", Dithering.Ditherers.BayerDither8x8 },
{ "Bayer4x4", Dithering.Ditherers.BayerDither4x4 },
{ "Ordered3x3", Dithering.Ditherers.OrderedDither3x3 },
{ "Bayer2x2", Dithering.Ditherers.BayerDither2x2 }
{ "Bayer8x8", Ditherers.BayerDither8x8 },
{ "Bayer4x4", Ditherers.BayerDither4x4 },
{ "Ordered3x3", Ditherers.OrderedDither3x3 },
{ "Bayer2x2", Ditherers.BayerDither2x2 }
};
public static readonly TheoryData<string, IErrorDiffuser> ErrorDiffusers = new TheoryData<string, IErrorDiffuser>
@ -48,8 +49,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
private static IErrorDiffuser DefaultErrorDiffuser => Diffusers.Atkinson;
[Theory]
[WithFileCollection(nameof(CommonTestImages), nameof(Ditherers), DefaultPixelType)]
[WithTestPatternImages(nameof(Ditherers), 100, 100, DefaultPixelType)]
[WithFileCollection(nameof(CommonTestImages), nameof(OrderedDitherers), DefaultPixelType)]
[WithTestPatternImages(nameof(OrderedDitherers), 100, 100, DefaultPixelType)]
public void BinaryDitherFilter_WorksWithAllDitherers<TPixel>(TestImageProvider<TPixel> provider, string name, IOrderedDither ditherer)
where TPixel : struct, IPixel<TPixel>
{

25
tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs

@ -1,18 +1,19 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Dithering;
using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion;
using SixLabors.ImageSharp.Processing.Dithering.Ordered;
using SixLabors.Primitives;
using Xunit;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
{
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Dithering;
public class DitherTests : FileTestBase
{
@ -21,12 +22,12 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
TestImages.Png.CalliphoraPartial, TestImages.Png.Bike
};
public static readonly TheoryData<string, IOrderedDither> Ditherers = new TheoryData<string, IOrderedDither>
public static readonly TheoryData<string, IOrderedDither> OrderedDitherers = new TheoryData<string, IOrderedDither>
{
{ "Bayer8x8", Dithering.Ditherers.BayerDither8x8 },
{ "Bayer4x4", Dithering.Ditherers.BayerDither4x4 },
{ "Ordered3x3", Dithering.Ditherers.OrderedDither3x3 },
{ "Bayer2x2", Dithering.Ditherers.BayerDither2x2 }
{ "Bayer8x8", Ditherers.BayerDither8x8 },
{ "Bayer4x4", Ditherers.BayerDither4x4 },
{ "Ordered3x3", Ditherers.OrderedDither3x3 },
{ "Bayer2x2", Ditherers.BayerDither2x2 }
};
public static readonly TheoryData<string, IErrorDiffuser> ErrorDiffusers = new TheoryData<string, IErrorDiffuser>
@ -43,13 +44,13 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
};
private static IOrderedDither DefaultDitherer => Dithering.Ditherers.BayerDither4x4;
private static IOrderedDither DefaultDitherer => Ditherers.BayerDither4x4;
private static IErrorDiffuser DefaultErrorDiffuser => Diffusers.Atkinson;
[Theory]
[WithFileCollection(nameof(CommonTestImages), nameof(Ditherers), DefaultPixelType)]
[WithTestPatternImages(nameof(Ditherers), 100, 100, DefaultPixelType)]
[WithFileCollection(nameof(CommonTestImages), nameof(OrderedDitherers), DefaultPixelType)]
[WithTestPatternImages(nameof(OrderedDitherers), 100, 100, DefaultPixelType)]
public void DitherFilter_WorksWithAllDitherers<TPixel>(TestImageProvider<TPixel> provider, string name, IOrderedDither ditherer)
where TPixel : struct, IPixel<TPixel>
{

Loading…
Cancel
Save