Browse Source

Quantizer

af/merge-core
James Jackson-South 8 years ago
parent
commit
4bc09cf794
  1. 1
      src/ImageSharp.Drawing/DrawImage.cs
  2. 1
      src/ImageSharp.Drawing/FillRegion.cs
  3. 1
      src/ImageSharp.Drawing/Paths/DrawBeziers.cs
  4. 1
      src/ImageSharp.Drawing/Paths/DrawLines.cs
  5. 1
      src/ImageSharp.Drawing/Paths/DrawPath.cs
  6. 1
      src/ImageSharp.Drawing/Paths/DrawPathCollection.cs
  7. 1
      src/ImageSharp.Drawing/Paths/DrawPolygon.cs
  8. 1
      src/ImageSharp.Drawing/Paths/DrawRectangle.cs
  9. 1
      src/ImageSharp.Drawing/Paths/FillPathBuilder.cs
  10. 1
      src/ImageSharp.Drawing/Paths/FillPathCollection.cs
  11. 1
      src/ImageSharp.Drawing/Paths/FillPaths.cs
  12. 1
      src/ImageSharp.Drawing/Paths/FillPolygon.cs
  13. 1
      src/ImageSharp.Drawing/Paths/FillRectangle.cs
  14. 2
      src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
  15. 7
      src/ImageSharp.Drawing/Processors/FillProcessor.cs
  16. 9
      src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
  17. 1
      src/ImageSharp.Drawing/Text/DrawText.Path.cs
  18. 1
      src/ImageSharp.Drawing/Text/DrawText.cs
  19. 5
      src/ImageSharp/Configuration.cs
  20. 5
      src/ImageSharp/Formats/Gif/GifEncoder.cs
  21. 13
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  22. 10
      src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs
  23. 7
      src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
  24. 3
      src/ImageSharp/Formats/Png/PngEncoder.cs
  25. 11
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  26. 1
      src/ImageSharp/Processing/Binarization/Processors/BinaryErrorDiffusionProcessor.cs
  27. 1
      src/ImageSharp/Processing/Binarization/Processors/BinaryOrderedDitherProcessor.cs
  28. 1
      src/ImageSharp/Processing/Binarization/Processors/BinaryThresholdProcessor.cs
  29. 1
      src/ImageSharp/Processing/Convolution/Processors/BoxBlurProcessor.cs
  30. 1
      src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs
  31. 1
      src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs
  32. 1
      src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs
  33. 1
      src/ImageSharp/Processing/Convolution/Processors/EdgeDetector2DProcessor.cs
  34. 1
      src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorCompassProcessor.cs
  35. 1
      src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorProcessor.cs
  36. 1
      src/ImageSharp/Processing/Convolution/Processors/GaussianBlurProcessor.cs
  37. 1
      src/ImageSharp/Processing/Convolution/Processors/GaussianSharpenProcessor.cs
  38. 1
      src/ImageSharp/Processing/Convolution/Processors/IEdgeDetectorProcessor.cs
  39. 4
      src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs
  40. 1
      src/ImageSharp/Processing/Dithering/Processors/ErrorDiffusionPaletteProcessor.cs
  41. 1
      src/ImageSharp/Processing/Dithering/Processors/OrderedDitherPaletteProcessor.cs
  42. 1
      src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs
  43. 1
      src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs
  44. 1
      src/ImageSharp/Processing/Effects/Processors/PixelateProcessor.cs
  45. 13
      src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs
  46. 1
      src/ImageSharp/Processing/Filters/GrayscaleExtensions.cs
  47. 3
      src/ImageSharp/Processing/Filters/Processors/FilterProcessor.cs
  48. 8
      src/ImageSharp/Processing/IImageProcessingContextFactory.cs
  49. 4
      src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs
  50. 1
      src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs
  51. 1
      src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs
  52. 1
      src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs
  53. 2
      src/ImageSharp/Processing/ProcessingExtensions.cs
  54. 8
      src/ImageSharp/Processing/Processors/ICloningImageProcessor.cs
  55. 4
      src/ImageSharp/Processing/Processors/IImageProcessor.cs
  56. 6
      src/ImageSharp/Processing/Processors/ImageProcessor.cs
  57. 2
      src/ImageSharp/Processing/Quantization/Box.cs
  58. 6
      src/ImageSharp/Processing/Quantization/IQuantizer{TPixel}.cs
  59. 64
      src/ImageSharp/Processing/Quantization/OctreeQuantizer{TPixel}.cs
  60. 5
      src/ImageSharp/Processing/Quantization/PaletteQuantizer{TPixel}.cs
  61. 72
      src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs
  62. 4
      src/ImageSharp/Processing/Quantization/QuantizationMode.cs
  63. 49
      src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs
  64. 18
      src/ImageSharp/Processing/Quantization/QuantizedFrame{TPixel}.cs
  65. 31
      src/ImageSharp/Processing/Quantization/QuantizerBase{TPixel}.cs
  66. 27
      src/ImageSharp/Processing/Quantization/WuQuantizer{TPixel}.cs
  67. 1
      src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs
  68. 1
      src/ImageSharp/Processing/Transforms/Processors/EntropyCropProcessor.cs
  69. 1
      src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs
  70. 3
      tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs
  71. 3
      tests/ImageSharp.Benchmarks/Image/EncodePng.cs
  72. 1
      tests/ImageSharp.Benchmarks/Samplers/Glow.cs
  73. 2
      tests/ImageSharp.Tests/FakeImageOperationsProvider.cs
  74. 7
      tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs
  75. 5
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  76. 11
      tests/ImageSharp.Tests/ImageOperationTests.cs
  77. 1
      tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs
  78. 1
      tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs
  79. 10
      tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs

1
src/ImageSharp.Drawing/DrawImage.cs

@ -3,6 +3,7 @@
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp

1
src/ImageSharp.Drawing/FillRegion.cs

@ -5,6 +5,7 @@ using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
namespace SixLabors.ImageSharp
{

1
src/ImageSharp.Drawing/Paths/DrawBeziers.cs

@ -6,6 +6,7 @@ using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using SixLabors.Shapes;

1
src/ImageSharp.Drawing/Paths/DrawLines.cs

@ -6,6 +6,7 @@ using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using SixLabors.Shapes;

1
src/ImageSharp.Drawing/Paths/DrawPath.cs

@ -5,6 +5,7 @@ using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp

1
src/ImageSharp.Drawing/Paths/DrawPathCollection.cs

@ -5,6 +5,7 @@ using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp

1
src/ImageSharp.Drawing/Paths/DrawPolygon.cs

@ -6,6 +6,7 @@ using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using SixLabors.Shapes;

1
src/ImageSharp.Drawing/Paths/DrawRectangle.cs

@ -5,6 +5,7 @@ using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp

1
src/ImageSharp.Drawing/Paths/FillPathBuilder.cs

@ -5,6 +5,7 @@ using System;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp

1
src/ImageSharp.Drawing/Paths/FillPathCollection.cs

@ -4,6 +4,7 @@
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp

1
src/ImageSharp.Drawing/Paths/FillPaths.cs

@ -4,6 +4,7 @@
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp

1
src/ImageSharp.Drawing/Paths/FillPolygon.cs

@ -6,6 +6,7 @@ using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using SixLabors.Shapes;

1
src/ImageSharp.Drawing/Paths/FillRectangle.cs

@ -4,6 +4,7 @@
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp

2
src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs

@ -7,7 +7,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing.Processors

7
src/ImageSharp.Drawing/Processors/FillProcessor.cs

@ -2,21 +2,18 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Brushes.Processors;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing.Processors
{
/// <summary>
/// Using the bursh as a source of pixels colors blends the brush color with source.
/// Using the brush as a source of pixels colors blends the brush color with source.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class FillProcessor<TPixel> : ImageProcessor<TPixel>

9
src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs

@ -2,24 +2,21 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Buffers;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Brushes.Processors;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing.Processors
{
/// <summary>
/// Usinf a brsuh and a shape fills shape with contents of brush the
/// Using a brush and a shape fills shape with contents of brush the
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <seealso cref="ImageSharp.Processing.ImageProcessor{TPixel}" />
/// <seealso cref="ImageProcessor{TPixel}" />
internal class FillRegionProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{

1
src/ImageSharp.Drawing/Text/DrawText.Path.cs

@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp

1
src/ImageSharp.Drawing/Text/DrawText.cs

@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using SixLabors.Shapes;

5
src/ImageSharp/Configuration.cs

@ -2,17 +2,18 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Png;
#if !NETSTANDARD1_1
using SixLabors.ImageSharp.IO;
#endif
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Processing;
namespace SixLabors.ImageSharp
{

5
src/ImageSharp/Formats/Gif/GifEncoder.cs

@ -1,14 +1,11 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
namespace SixLabors.ImageSharp.Formats.Gif
{

13
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Buffers;
using System.IO;
using System.Linq;
using System.Text;
@ -10,7 +9,7 @@ using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
namespace SixLabors.ImageSharp.Formats.Gif
{
@ -106,7 +105,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
var pixelQuantizer = (IQuantizer<TPixel>)this.quantizer;
// Quantize the image returning a palette.
QuantizedImage<TPixel> quantized = pixelQuantizer.Quantize(image.Frames.RootFrame, size);
QuantizedFrame<TPixel> quantized = pixelQuantizer.Quantize(image.Frames.RootFrame, size);
int index = this.GetTransparentIndex(quantized);
@ -154,7 +153,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <returns>
/// The <see cref="int"/>.
/// </returns>
private int GetTransparentIndex<TPixel>(QuantizedImage<TPixel> quantized)
private int GetTransparentIndex<TPixel>(QuantizedFrame<TPixel> quantized)
where TPixel : struct, IPixel<TPixel>
{
// Transparent pixels are much more likely to be found at the end of a palette
@ -347,7 +346,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageFrame{TPixel}"/> to encode.</param>
/// <param name="writer">The writer to write to the stream with.</param>
private void WriteColorTable<TPixel>(QuantizedImage<TPixel> image, EndianBinaryWriter writer)
private void WriteColorTable<TPixel>(QuantizedFrame<TPixel> image, EndianBinaryWriter writer)
where TPixel : struct, IPixel<TPixel>
{
// Grab the palette and write it to the stream.
@ -377,9 +376,9 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Writes the image pixel data to the stream.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="QuantizedImage{TPixel}"/> containing indexed pixels.</param>
/// <param name="image">The <see cref="QuantizedFrame{TPixel}"/> containing indexed pixels.</param>
/// <param name="writer">The stream to write to.</param>
private void WriteImageData<TPixel>(QuantizedImage<TPixel> image, EndianBinaryWriter writer)
private void WriteImageData<TPixel>(QuantizedFrame<TPixel> image, EndianBinaryWriter writer)
where TPixel : struct, IPixel<TPixel>
{
using (var encoder = new LzwEncoder(this.memoryManager, image.Pixels, (byte)this.bitDepth))

10
src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs

@ -1,12 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
namespace SixLabors.ImageSharp.Formats.Gif
{
@ -38,6 +34,6 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary>
/// Gets the quantizer for reducing the color count.
/// </summary>
IQuantizer Quantizer { get; }
IQuantizer Quantizer { get; }
}
}
}

7
src/ImageSharp/Formats/Png/IPngEncoderOptions.cs

@ -1,15 +1,12 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using System.IO;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
namespace SixLabors.ImageSharp.Formats.Png
{
/// <summary>
/// The options availible for manipulating the encoder pipeline
/// The options available for manipulating the encoder pipeline
/// </summary>
internal interface IPngEncoderOptions
{

3
src/ImageSharp/Formats/Png/PngEncoder.cs

@ -3,9 +3,8 @@
using System.IO;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
namespace SixLabors.ImageSharp.Formats.Png
{

11
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Buffers;
using System.IO;
using System.Linq;
using SixLabors.ImageSharp.Advanced;
@ -10,7 +9,7 @@ using SixLabors.ImageSharp.Formats.Png.Filters;
using SixLabors.ImageSharp.Formats.Png.Zlib;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
namespace SixLabors.ImageSharp.Formats.Png
{
@ -308,7 +307,7 @@ namespace SixLabors.ImageSharp.Formats.Png
where TPixel : struct, IPixel<TPixel>
{
// Quantize the image and get the pixels.
QuantizedImage<TPixel> quantized = this.WritePaletteChunk(stream, header, image);
QuantizedFrame<TPixel> quantized = this.WritePaletteChunk(stream, header, image);
this.palettePixelData = quantized.Pixels;
}
@ -498,8 +497,8 @@ namespace SixLabors.ImageSharp.Formats.Png
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="header">The <see cref="PngHeader"/>.</param>
/// <param name="image">The image to encode.</param>
/// <returns>The <see cref="QuantizedImage{TPixel}"/></returns>
private QuantizedImage<TPixel> WritePaletteChunk<TPixel>(Stream stream, PngHeader header, ImageFrame<TPixel> image)
/// <returns>The <see cref="QuantizedFrame{TPixel}"/></returns>
private QuantizedFrame<TPixel> WritePaletteChunk<TPixel>(Stream stream, PngHeader header, ImageFrame<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
if (this.paletteSize > 256)
@ -513,7 +512,7 @@ namespace SixLabors.ImageSharp.Formats.Png
}
// Quantize the image returning a palette. This boxing is icky.
QuantizedImage<TPixel> quantized = ((IQuantizer<TPixel>)this.quantizer).Quantize(image, this.paletteSize);
QuantizedFrame<TPixel> quantized = ((IQuantizer<TPixel>)this.quantizer).Quantize(image, this.paletteSize);
// Grab the palette and write it to the stream.
TPixel[] palette = quantized.Palette;

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

@ -6,6 +6,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Binarization.Processors

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

@ -6,6 +6,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Binarization.Processors

1
src/ImageSharp/Processing/Binarization/Processors/BinaryThresholdProcessor.cs

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Binarization.Processors

1
src/ImageSharp/Processing/Convolution/Processors/BoxBlurProcessor.cs

@ -3,6 +3,7 @@
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors

1
src/ImageSharp/Processing/Convolution/Processors/Convolution2DProcessor.cs

@ -8,6 +8,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors

1
src/ImageSharp/Processing/Convolution/Processors/Convolution2PassProcessor.cs

@ -8,6 +8,7 @@ using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors

1
src/ImageSharp/Processing/Convolution/Processors/ConvolutionProcessor.cs

@ -9,6 +9,7 @@ using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors

1
src/ImageSharp/Processing/Convolution/Processors/EdgeDetector2DProcessor.cs

@ -4,6 +4,7 @@
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors

1
src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorCompassProcessor.cs

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors

1
src/ImageSharp/Processing/Convolution/Processors/EdgeDetectorProcessor.cs

@ -4,6 +4,7 @@
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors

1
src/ImageSharp/Processing/Convolution/Processors/GaussianBlurProcessor.cs

@ -4,6 +4,7 @@
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors

1
src/ImageSharp/Processing/Convolution/Processors/GaussianSharpenProcessor.cs

@ -4,6 +4,7 @@
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors

1
src/ImageSharp/Processing/Convolution/Processors/IEdgeDetectorProcessor.cs

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
namespace SixLabors.ImageSharp.Processing.Convolution.Processors
{

4
src/ImageSharp/DefaultInternalImageProcessorContext.cs → src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs

@ -5,10 +5,10 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Performs processor application operations on the source image

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

@ -6,6 +6,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Dithering.Processors

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

@ -6,6 +6,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Dithering.Processors

1
src/ImageSharp/Processing/Dithering/Processors/PaletteDitherProcessorBase.cs

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
namespace SixLabors.ImageSharp.Processing.Dithering.Processors
{

1
src/ImageSharp/Processing/Effects/Processors/OilPaintingProcessor.cs

@ -8,6 +8,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Effects.Processors

1
src/ImageSharp/Processing/Effects/Processors/PixelateProcessor.cs

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Common;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Effects.Processors

13
src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs

@ -3,6 +3,7 @@
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Filters
@ -21,10 +22,7 @@ namespace SixLabors.ImageSharp.Processing.Filters
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> ColorBlindness<TPixel>(this IImageProcessingContext<TPixel> source, ColorBlindness colorBlindness)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(GetProcessor<TPixel>(colorBlindness));
return source;
}
=> source.ApplyProcessor(GetProcessor<TPixel>(colorBlindness));
/// <summary>
/// Applies the given colorblindness simulator to the image.
@ -38,10 +36,7 @@ namespace SixLabors.ImageSharp.Processing.Filters
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> ColorBlindness<TPixel>(this IImageProcessingContext<TPixel> source, ColorBlindness colorBlindness, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(GetProcessor<TPixel>(colorBlindness), rectangle);
return source;
}
=> source.ApplyProcessor(GetProcessor<TPixel>(colorBlindness), rectangle);
private static IImageProcessor<TPixel> GetProcessor<TPixel>(ColorBlindness colorBlindness)
where TPixel : struct, IPixel<TPixel>
@ -67,4 +62,4 @@ namespace SixLabors.ImageSharp.Processing.Filters
}
}
}
}
}

1
src/ImageSharp/Processing/Filters/GrayscaleExtensions.cs

@ -3,6 +3,7 @@
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Filters

3
src/ImageSharp/Processing/Filters/Processors/FilterProcessor.cs

@ -7,12 +7,13 @@ using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Filters.Processors
{
/// <summary>
/// Provides methods that accept a <see cref="Matrix4x4"/> matrix to apply freeform filters to images.
/// Provides methods that accept a <see cref="Matrix4x4"/> matrix to apply free-form filters to images.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class FilterProcessor<TPixel> : ImageProcessor<TPixel>

8
src/ImageSharp/IImageProcessingContextFactory.cs → src/ImageSharp/Processing/IImageProcessingContextFactory.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Represents an interface that will create IInternalImageProcessingContext instances
@ -16,13 +16,13 @@ namespace SixLabors.ImageSharp
/// <typeparam name="TPixel">The pixel format</typeparam>
/// <param name="source">The source image.</param>
/// <param name="mutate">A flag to determine whether image operations are allowed to mutate the source image.</param>
/// <returns>A new IImageOPeration</returns>
/// <returns>A new <see cref="IInternalImageProcessingContext{TPixel}"/></returns>
IInternalImageProcessingContext<TPixel> CreateImageProcessingContext<TPixel>(Image<TPixel> source, bool mutate)
where TPixel : struct, IPixel<TPixel>;
}
/// <summary>
/// The default implmentation of <see cref="IImageProcessingContextFactory"/>
/// The default implementation of <see cref="IImageProcessingContextFactory"/>
/// </summary>
internal class DefaultImageOperationsProviderFactory : IImageProcessingContextFactory
{
@ -33,4 +33,4 @@ namespace SixLabors.ImageSharp
return new DefaultInternalImageProcessorContext<TPixel>(source, mutate);
}
}
}
}

4
src/ImageSharp/IImageProcessingContext{TPixel}.cs → src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs

@ -3,10 +3,10 @@
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// An interface to queue up image operations to apply to an image.

1
src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Overlays.Processors

1
src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs

@ -9,6 +9,7 @@ using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Overlays.Processors

1
src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs

@ -9,6 +9,7 @@ using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Overlays.Processors

2
src/ImageSharp/Processing/ProcessingExtensions.cs

@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Processing
}
/// <summary>
/// Applies the given <see cref="SixLabors.ImageSharp.IImageProcessor{TPixel}"/> collection against the context
/// Applies the given <see cref="IImageProcessor{TPixel}"/> collection against the context
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image processing context.</param>

8
src/ImageSharp/ICloningImageProcessor.cs → src/ImageSharp/Processing/Processors/ICloningImageProcessor.cs

@ -4,7 +4,7 @@
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
namespace SixLabors.ImageSharp.Processing.Processors
{
/// <summary>
/// Encapsulates methods to alter the pixels of a new image, cloned from the original image.
@ -24,9 +24,9 @@ namespace SixLabors.ImageSharp.Processing
/// <paramref name="source"/> is null.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="sourceRectangle"/> doesnt fit the dimension of the image.
/// <paramref name="sourceRectangle"/> doesn't fit the dimension of the image.
/// </exception>
/// <returns>Returns the cloned image after thre processor has been applied to it.</returns>
/// <returns>Returns the cloned image after there processor has been applied to it.</returns>
Image<TPixel> CloneAndApply(Image<TPixel> source, Rectangle sourceRectangle);
}
}
}

4
src/ImageSharp/IImageProcessor.cs → src/ImageSharp/Processing/Processors/IImageProcessor.cs

@ -4,7 +4,7 @@
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Processors
{
/// <summary>
/// Encapsulates methods to alter the pixels of an image.
@ -28,4 +28,4 @@ namespace SixLabors.ImageSharp
/// </exception>
void Apply(Image<TPixel> source, Rectangle sourceRectangle);
}
}
}

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

@ -6,7 +6,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
namespace SixLabors.ImageSharp.Processing.Processors
{
/// <summary>
/// Allows the application of processors to images.
@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing
#else
catch (Exception ex)
{
throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex);
throw new ImageProcessingException($"An error occurred when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex);
#endif
}
}
@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Processing
#else
catch (Exception ex)
{
throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex);
throw new ImageProcessingException($"An error occurred when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex);
#endif
}
}

2
src/ImageSharp/Processing/Quantization/Box.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Quantizers
namespace SixLabors.ImageSharp.Processing.Quantization
{
/// <summary>
/// Represents a box color cube.

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

@ -4,7 +4,7 @@
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Quantizers
namespace SixLabors.ImageSharp.Processing.Quantization
{
/// <summary>
/// Provides methods for for allowing quantization of images pixels with configurable dithering.
@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Quantizers
/// <returns>
/// A <see cref="T:QuantizedImage"/> representing a quantized version of the image pixels.
/// </returns>
QuantizedImage<TPixel> Quantize(ImageFrame<TPixel> image, int maxColors);
QuantizedFrame<TPixel> Quantize(ImageFrame<TPixel> image, int maxColors);
}
/// <summary>
@ -39,4 +39,4 @@ namespace SixLabors.ImageSharp.Quantizers
/// </summary>
IErrorDiffuser DitherType { get; set; }
}
}
}

64
src/ImageSharp/Processing/Quantization/OctreeQuantizer{TPixel}.cs

@ -4,11 +4,11 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers.Base;
namespace SixLabors.ImageSharp.Quantizers
namespace SixLabors.ImageSharp.Processing.Quantization
{
/// <summary>
/// Encapsulates methods to calculate the color palette if an image using an Octree pattern.
@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.Quantizers
}
/// <inheritdoc/>
public override QuantizedImage<TPixel> Quantize(ImageFrame<TPixel> image, int maxColors)
public override QuantizedFrame<TPixel> Quantize(ImageFrame<TPixel> image, int maxColors)
{
this.colors = (byte)maxColors.Clamp(1, 255);
this.octree = new Octree(this.GetBitsNeededForColorDepth(this.colors));
@ -66,6 +66,28 @@ namespace SixLabors.ImageSharp.Quantizers
return base.Quantize(image, this.colors);
}
/// <inheritdoc/>
protected override void FirstPass(ImageFrame<TPixel> source, int width, int height)
{
// Loop through each row
for (int y = 0; y < height; y++)
{
Span<TPixel> row = source.GetPixelRowSpan(y);
ref TPixel scanBaseRef = ref MemoryMarshal.GetReference(row);
// And loop through each column
var rgba = default(Rgba32);
for (int x = 0; x < width; x++)
{
ref TPixel pixel = ref Unsafe.Add(ref scanBaseRef, x);
pixel.ToRgba32(ref rgba);
// Add the color to the Octree
this.octree.AddColor(ref pixel, ref rgba);
}
}
}
/// <inheritdoc/>
protected override void SecondPass(ImageFrame<TPixel> source, byte[] output, int width, int height)
{
@ -115,14 +137,6 @@ namespace SixLabors.ImageSharp.Quantizers
}
}
/// <inheritdoc/>
protected override void InitialQuantizePixel(TPixel pixel)
{
// Add the color to the Octree
var rgba = default(Rgba32);
this.octree.AddColor(pixel, ref rgba);
}
/// <inheritdoc/>
protected override TPixel[] GetPalette()
{
@ -173,7 +187,7 @@ namespace SixLabors.ImageSharp.Quantizers
{
if (this.Dither)
{
// The colors have changed so we need to use Euclidean distance caclulation to find the closest value.
// The colors have changed so we need to use Euclidean distance calculation to find the closest value.
// This palette can never be null here.
return this.GetClosestPixel(pixel, this.palette, this.colorMap);
}
@ -184,7 +198,7 @@ namespace SixLabors.ImageSharp.Quantizers
return this.transparentIndex;
}
return (byte)this.octree.GetPaletteIndex(pixel, ref rgba);
return (byte)this.octree.GetPaletteIndex(ref pixel, ref rgba);
}
/// <summary>
@ -268,7 +282,7 @@ namespace SixLabors.ImageSharp.Quantizers
/// </summary>
/// <param name="pixel">The pixel data.</param>
/// <param name="rgba">The color.</param>
public void AddColor(TPixel pixel, ref Rgba32 rgba)
public void AddColor(ref TPixel pixel, ref Rgba32 rgba)
{
// Check if this request is for the same color as the last
if (this.previousColor.Equals(pixel))
@ -278,18 +292,18 @@ namespace SixLabors.ImageSharp.Quantizers
if (this.previousNode == null)
{
this.previousColor = pixel;
this.root.AddColor(pixel, this.maxColorBits, 0, this, ref rgba);
this.root.AddColor(ref pixel, this.maxColorBits, 0, this, ref rgba);
}
else
{
// Just update the previous node
this.previousNode.Increment(pixel, ref rgba);
this.previousNode.Increment(ref pixel, ref rgba);
}
}
else
{
this.previousColor = pixel;
this.root.AddColor(pixel, this.maxColorBits, 0, this, ref rgba);
this.root.AddColor(ref pixel, this.maxColorBits, 0, this, ref rgba);
}
}
@ -325,9 +339,9 @@ namespace SixLabors.ImageSharp.Quantizers
/// <returns>
/// The <see cref="int"/>.
/// </returns>
public int GetPaletteIndex(TPixel pixel, ref Rgba32 rgba)
public int GetPaletteIndex(ref TPixel pixel, ref Rgba32 rgba)
{
return this.root.GetPaletteIndex(pixel, 0, ref rgba);
return this.root.GetPaletteIndex(ref pixel, 0, ref rgba);
}
/// <summary>
@ -454,12 +468,12 @@ namespace SixLabors.ImageSharp.Quantizers
/// <param name="level">The level in the tree</param>
/// <param name="octree">The tree to which this node belongs</param>
/// <param name="rgba">The color to map to.</param>
public void AddColor(TPixel pixel, int colorBits, int level, Octree octree, ref Rgba32 rgba)
public void AddColor(ref TPixel pixel, int colorBits, int level, Octree octree, ref Rgba32 rgba)
{
// Update the color information if this is a leaf
if (this.leaf)
{
this.Increment(pixel, ref rgba);
this.Increment(ref pixel, ref rgba);
// Setup the previous node
octree.TrackPrevious(this);
@ -484,7 +498,7 @@ namespace SixLabors.ImageSharp.Quantizers
}
// Add the color to the child node
child.AddColor(pixel, colorBits, level + 1, octree, ref rgba);
child.AddColor(ref pixel, colorBits, level + 1, octree, ref rgba);
}
}
@ -562,7 +576,7 @@ namespace SixLabors.ImageSharp.Quantizers
/// <returns>
/// The <see cref="int"/> representing the index of the pixel in the palette.
/// </returns>
public int GetPaletteIndex(TPixel pixel, int level, ref Rgba32 rgba)
public int GetPaletteIndex(ref TPixel pixel, int level, ref Rgba32 rgba)
{
int index = this.paletteIndex;
@ -577,7 +591,7 @@ namespace SixLabors.ImageSharp.Quantizers
if (this.children[pixelIndex] != null)
{
index = this.children[pixelIndex].GetPaletteIndex(pixel, level + 1, ref rgba);
index = this.children[pixelIndex].GetPaletteIndex(ref pixel, level + 1, ref rgba);
}
else
{
@ -593,7 +607,7 @@ namespace SixLabors.ImageSharp.Quantizers
/// </summary>
/// <param name="pixel">The pixel to add.</param>
/// <param name="rgba">The color to map to.</param>
public void Increment(TPixel pixel, ref Rgba32 rgba)
public void Increment(ref TPixel pixel, ref Rgba32 rgba)
{
pixel.ToRgba32(ref rgba);
this.pixelCount++;

5
src/ImageSharp/Processing/Quantization/PaletteQuantizer{TPixel}.cs

@ -6,9 +6,8 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers.Base;
namespace SixLabors.ImageSharp.Quantizers
namespace SixLabors.ImageSharp.Processing.Quantization
{
/// <summary>
/// Encapsulates methods to create a quantized image based upon the given palette.
@ -49,7 +48,7 @@ namespace SixLabors.ImageSharp.Quantizers
}
/// <inheritdoc/>
public override QuantizedImage<TPixel> Quantize(ImageFrame<TPixel> image, int maxColors)
public override QuantizedFrame<TPixel> Quantize(ImageFrame<TPixel> image, int maxColors)
{
Array.Resize(ref this.colors, maxColors.Clamp(1, 255));
this.colorMap.Clear();

72
src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs

@ -0,0 +1,72 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Quantization.Processors
{
/// <summary>
/// Enables the quantization of images to remove the number of colors used in the image palette.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class QuantizeProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="QuantizeProcessor{TPixel}"/> class.
/// </summary>
/// <param name="quantizer">The quantizer used to reduce the color palette</param>
/// <param name="maxColors">The maximum number of colors to reduce the palette to</param>
public QuantizeProcessor(IQuantizer<TPixel> quantizer, int maxColors)
{
Guard.NotNull(quantizer, nameof(quantizer));
Guard.MustBeGreaterThan(maxColors, 0, nameof(maxColors));
this.Quantizer = quantizer;
this.MaxColors = maxColors;
}
/// <summary>
/// Gets the quantizer
/// </summary>
public IQuantizer<TPixel> Quantizer { get; }
/// <summary>
/// Gets the maximum number of palette colors
/// </summary>
public int MaxColors { get; }
/// <inheritdoc />
protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
QuantizedFrame<TPixel> quantized = this.Quantizer.Quantize(source, this.MaxColors);
int paletteCount = quantized.Palette.Length - 1;
using (Buffer2D<TPixel> pixels = source.MemoryManager.Allocate2D<TPixel>(quantized.Width, quantized.Height))
{
Parallel.For(
0,
pixels.Height,
configuration.ParallelOptions,
y =>
{
Span<TPixel> row = pixels.GetRowSpan(y);
int yy = y * pixels.Width;
for (int x = 0; x < pixels.Width; x++)
{
int i = x + yy;
TPixel color = quantized.Palette[Math.Min(paletteCount, quantized.Pixels[i])];
row[x] = color;
}
});
Buffer2D<TPixel>.SwapContents(source.PixelBuffer, pixels);
}
}
}
}

4
src/ImageSharp/Processing/Quantization/Quantization.cs → src/ImageSharp/Processing/Quantization/QuantizationMode.cs

@ -1,12 +1,12 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Quantization
{
/// <summary>
/// Provides enumeration over how an image should be quantized.
/// </summary>
public enum Quantization
public enum QuantizationMode
{
/// <summary>
/// An adaptive Octree quantizer. Fast with good quality.

49
src/ImageSharp/Processing/Quantization/Quantize.cs → src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs

@ -1,20 +1,15 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization.Processors;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Quantization
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the application of quantizing algorithms to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class QuantizeExtensions
{
/// <summary>
/// Applies quantization to the image.
@ -24,17 +19,17 @@ namespace SixLabors.ImageSharp
/// <param name="mode">The quantization mode to apply to perform the operation.</param>
/// <param name="maxColors">The maximum number of colors to return. Defaults to 256.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Quantize<TPixel>(this IImageProcessingContext<TPixel> source, Quantization mode = Quantization.Octree, int maxColors = 256)
public static IImageProcessingContext<TPixel> Quantize<TPixel>(this IImageProcessingContext<TPixel> source, QuantizationMode mode = QuantizationMode.Octree, int maxColors = 256)
where TPixel : struct, IPixel<TPixel>
{
IQuantizer<TPixel> quantizer;
switch (mode)
{
case Quantization.Wu:
case QuantizationMode.Wu:
quantizer = new WuQuantizer<TPixel>();
break;
case Quantization.Palette:
case QuantizationMode.Palette:
quantizer = new PaletteQuantizer<TPixel>();
break;
@ -56,34 +51,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Quantize<TPixel>(this IImageProcessingContext<TPixel> source, IQuantizer<TPixel> quantizer, int maxColors)
where TPixel : struct, IPixel<TPixel>
{
return source.Apply(img =>
{
// TODO : move helper logic into the processor
QuantizedImage<TPixel> quantized = quantizer.Quantize(img.Frames.RootFrame, maxColors);
int palleteCount = quantized.Palette.Length - 1;
using (Buffer2D<TPixel> pixels = source.MemoryManager.Allocate2D<TPixel>(quantized.Width, quantized.Height))
{
Parallel.For(
0,
pixels.Height,
img.GetConfiguration().ParallelOptions,
y =>
{
Span<TPixel> row = pixels.GetRowSpan(y);
int yy = y * pixels.Width;
for (int x = 0; x < pixels.Width; x++)
{
int i = x + yy;
TPixel color = quantized.Palette[Math.Min(palleteCount, quantized.Pixels[i])];
row[x] = color;
}
});
Buffer2D<TPixel>.SwapContents(img.Frames[0].PixelBuffer, pixels);
}
});
}
=> source.ApplyProcessor(new QuantizeProcessor<TPixel>(quantizer, maxColors));
}
}

18
src/ImageSharp/Processing/Quantization/QuantizedImage{TPixel}.cs → src/ImageSharp/Processing/Quantization/QuantizedFrame{TPixel}.cs

@ -4,23 +4,23 @@
using System;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Quantizers
namespace SixLabors.ImageSharp.Processing.Quantization
{
/// <summary>
/// Represents a quantized image where the pixels indexed by a color palette.
/// Represents a quantized image frame where the pixels indexed by a color palette.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public class QuantizedImage<TPixel>
public class QuantizedFrame<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="QuantizedImage{TPixel}"/> class.
/// Initializes a new instance of the <see cref="QuantizedFrame{TPixel}"/> class.
/// </summary>
/// <param name="width">The image width.</param>
/// <param name="height">The image height.</param>
/// <param name="palette">The color palette.</param>
/// <param name="pixels">The quantized pixels.</param>
public QuantizedImage(int width, int height, TPixel[] palette, byte[] pixels)
public QuantizedFrame(int width, int height, TPixel[] palette, byte[] pixels)
{
Guard.MustBeGreaterThan(width, 0, nameof(width));
Guard.MustBeGreaterThan(height, 0, nameof(height));
@ -39,22 +39,22 @@ namespace SixLabors.ImageSharp.Quantizers
}
/// <summary>
/// Gets the width of this <see cref="T:QuantizedImage"/>.
/// Gets the width of this <see cref="QuantizedFrame{TPixel}"/>.
/// </summary>
public int Width { get; }
/// <summary>
/// Gets the height of this <see cref="T:QuantizedImage"/>.
/// Gets the height of this <see cref="QuantizedFrame{TPixel}"/>.
/// </summary>
public int Height { get; }
/// <summary>
/// Gets the color palette of this <see cref="T:QuantizedImage"/>.
/// Gets the color palette of this <see cref="QuantizedFrame{TPixel}"/>.
/// </summary>
public TPixel[] Palette { get; }
/// <summary>
/// Gets the pixels of this <see cref="T:QuantizedImage"/>.
/// Gets the pixels of this <see cref="QuantizedFrame{TPixel}"/>.
/// </summary>
public byte[] Pixels { get; }
}

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

@ -9,7 +9,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Quantizers.Base
namespace SixLabors.ImageSharp.Processing.Quantization
{
/// <summary>
/// Encapsulates methods to calculate the color palette of an image.
@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Quantizers.Base
public IErrorDiffuser DitherType { get; set; } = Diffusers.FloydSteinberg;
/// <inheritdoc/>
public virtual QuantizedImage<TPixel> Quantize(ImageFrame<TPixel> image, int maxColors)
public virtual QuantizedFrame<TPixel> Quantize(ImageFrame<TPixel> image, int maxColors)
{
Guard.NotNull(image, nameof(image));
@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.Quantizers.Base
this.SecondPass(image, quantizedPixels, width, height);
}
return new QuantizedImage<TPixel>(width, height, colorPalette, quantizedPixels);
return new QuantizedFrame<TPixel>(width, height, colorPalette, quantizedPixels);
}
/// <summary>
@ -90,18 +90,6 @@ namespace SixLabors.ImageSharp.Quantizers.Base
/// <param name="height">The height in pixels of the image.</param>
protected virtual void FirstPass(ImageFrame<TPixel> source, int width, int height)
{
// Loop through each row
for (int y = 0; y < height; y++)
{
Span<TPixel> row = source.GetPixelRowSpan(y);
// And loop through each column
for (int x = 0; x < width; x++)
{
// Now I have the pixel, call the FirstPassQuantize function...
this.InitialQuantizePixel(row[x]);
}
}
}
/// <summary>
@ -113,19 +101,6 @@ namespace SixLabors.ImageSharp.Quantizers.Base
/// <param name="height">The height in pixels of the image</param>
protected abstract void SecondPass(ImageFrame<TPixel> source, byte[] output, int width, int height);
/// <summary>
/// Override this to process the pixel in the first pass of the algorithm
/// TODO: We really should do this on a per-row basis! Shouldn't we internalize this method?
/// </summary>
/// <param name="pixel">The pixel to quantize</param>
/// <remarks>
/// This function need only be overridden if your quantize algorithm needs two passes,
/// such as an Octree quantizer.
/// </remarks>
protected virtual void InitialQuantizePixel(TPixel pixel)
{
}
/// <summary>
/// Retrieve the palette for the quantized image. Can be called more than once so make sure calls are cached.
/// </summary>

27
src/ImageSharp/Processing/Quantization/WuQuantizer{TPixel}.cs

@ -2,16 +2,15 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers.Base;
namespace SixLabors.ImageSharp.Quantizers
namespace SixLabors.ImageSharp.Processing.Quantization
{
/// <summary>
/// An implementation of Wu's color quantizer with alpha channel.
@ -137,7 +136,7 @@ namespace SixLabors.ImageSharp.Quantizers
}
/// <inheritdoc/>
public override QuantizedImage<TPixel> Quantize(ImageFrame<TPixel> image, int maxColors)
public override QuantizedFrame<TPixel> Quantize(ImageFrame<TPixel> image, int maxColors)
{
Guard.NotNull(image, nameof(image));
@ -199,14 +198,13 @@ namespace SixLabors.ImageSharp.Quantizers
return this.palette;
}
/// <inheritdoc/>
protected override void InitialQuantizePixel(TPixel pixel)
/// <summary>
/// Quantizes the pixel
/// </summary>
/// <param name="rgba">The rgba used to quantize the pixel input</param>
private void QuantizePixel(ref Rgba32 rgba)
{
// Add the color to a 3-D color histogram.
// Colors are expected in r->g->b->a format
var rgba = default(Rgba32);
pixel.ToRgba32(ref rgba);
int r = rgba.R >> (8 - IndexBits);
int g = rgba.G >> (8 - IndexBits);
int b = rgba.B >> (8 - IndexBits);
@ -238,11 +236,16 @@ namespace SixLabors.ImageSharp.Quantizers
// Loop through each row
for (int y = 0; y < height; y++)
{
Span<TPixel> row = source.GetPixelRowSpan(y);
ref TPixel scanBaseRef = ref MemoryMarshal.GetReference(row);
// And loop through each column
var rgba = default(Rgba32);
for (int x = 0; x < width; x++)
{
// Now I have the pixel, call the FirstPassQuantize function...
this.InitialQuantizePixel(source[x, y]);
ref TPixel pixel = ref Unsafe.Add(ref scanBaseRef, x);
pixel.ToRgba32(ref rgba);
this.QuantizePixel(ref rgba);
}
}

1
src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs

@ -4,6 +4,7 @@
using System;
using SixLabors.ImageSharp.MetaData.Profiles.Exif;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Transforms.Processors

1
src/ImageSharp/Processing/Transforms/Processors/EntropyCropProcessor.cs

@ -5,6 +5,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Binarization.Processors;
using SixLabors.ImageSharp.Processing.Convolution.Processors;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Transforms.Processors

1
src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs

@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Transforms.Processors

3
tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs

@ -10,9 +10,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Image
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
using CoreImage = ImageSharp.Image;

3
tests/ImageSharp.Benchmarks/Image/EncodePng.cs

@ -11,8 +11,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Image
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Quantizers.Base;
using SixLabors.ImageSharp.Processing.Quantization;
using SixLabors.ImageSharp.Tests;
using CoreImage = ImageSharp.Image;

1
tests/ImageSharp.Benchmarks/Samplers/Glow.cs

@ -19,6 +19,7 @@ namespace SixLabors.ImageSharp.Benchmarks
using SixLabors.Primitives;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Processing.Overlays.Processors;
using SixLabors.ImageSharp.Processing.Processors;
public class Glow : BenchmarkBase
{

2
tests/ImageSharp.Tests/FakeImageOperationsProvider.cs

@ -7,6 +7,8 @@ using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Tests

7
tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs

@ -15,6 +15,7 @@ namespace SixLabors.ImageSharp.Tests
using System;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Quantization;
public class GeneralFormatTests : FileTestBase
{
@ -73,7 +74,7 @@ namespace SixLabors.ImageSharp.Tests
{
using (FileStream output = File.OpenWrite($"{path}/Octree-{file.FileName}"))
{
image.Mutate(x => x.Quantize(Quantization.Octree));
image.Mutate(x => x.Quantize(QuantizationMode.Octree));
image.Save(output, mimeType);
}
@ -83,7 +84,7 @@ namespace SixLabors.ImageSharp.Tests
{
using (FileStream output = File.OpenWrite($"{path}/Wu-{file.FileName}"))
{
image.Mutate(x => x.Quantize(Quantization.Wu));
image.Mutate(x => x.Quantize(QuantizationMode.Wu));
image.Save(output, mimeType);
}
}
@ -92,7 +93,7 @@ namespace SixLabors.ImageSharp.Tests
{
using (FileStream output = File.OpenWrite($"{path}/Palette-{file.FileName}"))
{
image.Mutate(x => x.Quantize(Quantization.Palette));
image.Mutate(x => x.Quantize(QuantizationMode.Palette));
image.Save(output, mimeType);
}
}

5
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -1,13 +1,11 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
// ReSharper disable InconsistentNaming
@ -15,7 +13,6 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests
{
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
public class PngEncoderTests

11
tests/ImageSharp.Tests/ImageOperationTests.cs

@ -2,15 +2,12 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using Moq;
using SixLabors.Primitives;
using Xunit;
namespace SixLabors.ImageSharp.Tests
@ -42,7 +39,7 @@ namespace SixLabors.ImageSharp.Tests
this.image.Mutate(x => x.ApplyProcessor(this.processor));
Assert.True(this.provider.HasCreated(this.image));
Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x=>x.Processor));
Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.Processor));
}
[Fact]

1
tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs

@ -11,6 +11,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters
{
using SixLabors.ImageSharp.Processing.Filters;
using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
public class ColorBlindnessTest : BaseImageOperationsExtensionTest
{

1
tests/ImageSharp.Tests/Processing/Filters/GrayscaleTest.cs

@ -11,6 +11,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters
{
using SixLabors.ImageSharp.Processing.Filters;
using SixLabors.ImageSharp.Processing.Filters.Processors;
using SixLabors.ImageSharp.Processing.Processors;
public class GrayscaleTest : BaseImageOperationsExtensionTest
{

10
tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs

@ -1,7 +1,7 @@
namespace SixLabors.ImageSharp.Tests
{
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
using Xunit;
@ -33,7 +33,7 @@
foreach (ImageFrame<TPixel> frame in image.Frames)
{
QuantizedImage<TPixel> quantized = quantizer.Quantize(frame, 256);
QuantizedFrame<TPixel> quantized = quantizer.Quantize(frame, 256);
int index = this.GetTransparentIndex(quantized);
Assert.Equal(index, quantized.Pixels[0]);
@ -55,7 +55,7 @@
foreach (ImageFrame<TPixel> frame in image.Frames)
{
QuantizedImage<TPixel> quantized = quantizer.Quantize(frame, 256);
QuantizedFrame<TPixel> quantized = quantizer.Quantize(frame, 256);
int index = this.GetTransparentIndex(quantized);
Assert.Equal(index, quantized.Pixels[0]);
@ -77,7 +77,7 @@
foreach (ImageFrame<TPixel> frame in image.Frames)
{
QuantizedImage<TPixel> quantized = quantizer.Quantize(frame, 256);
QuantizedFrame<TPixel> quantized = quantizer.Quantize(frame, 256);
int index = this.GetTransparentIndex(quantized);
Assert.Equal(index, quantized.Pixels[0]);
@ -85,7 +85,7 @@
}
}
private int GetTransparentIndex<TPixel>(QuantizedImage<TPixel> quantized)
private int GetTransparentIndex<TPixel>(QuantizedFrame<TPixel> quantized)
where TPixel : struct, IPixel<TPixel>
{
// Transparent pixels are much more likely to be found at the end of a palette

Loading…
Cancel
Save