Skip to content

Commit f0ce591

Browse files
Rename quantizer and update tests
1 parent 90f0c0b commit f0ce591

File tree

90 files changed

+383
-354
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+383
-354
lines changed

src/ImageSharp/Advanced/AotCompilerTools.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal static class AotCompilerTools
5454
/// <remarks>
5555
/// This method doesn't actually do anything but serves an important purpose...
5656
/// If you are running ImageSharp on iOS and try to call SaveAsGif, it will throw an exception:
57-
/// "Attempting to JIT compile method... OctreeFrameQuantizer.ConstructPalette... while running in aot-only mode."
57+
/// "Attempting to JIT compile method... HexadecatreeQuantizer.ConstructPalette... while running in aot-only mode."
5858
/// The reason this happens is the SaveAsGif method makes heavy use of generics, which are too confusing for the AoT
5959
/// compiler used on Xamarin.iOS. It spins up the JIT compiler to try and figure it out, but that is an illegal op on
6060
/// iOS so it bombs out.
@@ -479,7 +479,7 @@ private static void AotCompileResampler<TPixel, TResampler>()
479479
private static void AotCompileQuantizers<TPixel>()
480480
where TPixel : unmanaged, IPixel<TPixel>
481481
{
482-
AotCompileQuantizer<TPixel, OctreeQuantizer>();
482+
AotCompileQuantizer<TPixel, HexadecatreeQuantizer>();
483483
AotCompileQuantizer<TPixel, PaletteQuantizer>();
484484
AotCompileQuantizer<TPixel, WebSafePaletteQuantizer>();
485485
AotCompileQuantizer<TPixel, WernerPaletteQuantizer>();
@@ -549,8 +549,8 @@ private static void AotCompileDither<TPixel, TDither>()
549549
where TPixel : unmanaged, IPixel<TPixel>
550550
where TDither : struct, IDither
551551
{
552-
OctreeQuantizer<TPixel> octree = default;
553-
default(TDither).ApplyQuantizationDither<OctreeQuantizer<TPixel>, TPixel>(ref octree, default, default, default);
552+
HexadecatreeQuantizer<TPixel> hexadecatree = default;
553+
default(TDither).ApplyQuantizationDither<HexadecatreeQuantizer<TPixel>, TPixel>(ref hexadecatree, default, default, default);
554554

555555
PaletteQuantizer<TPixel> palette = default;
556556
default(TDither).ApplyQuantizationDither<PaletteQuantizer<TPixel>, TPixel>(ref palette, default, default, default);

src/ImageSharp/Formats/Bmp/BmpEncoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class BmpEncoder : QuantizingImageEncoder
1313
/// <summary>
1414
/// Initializes a new instance of the <see cref="BmpEncoder"/> class.
1515
/// </summary>
16-
public BmpEncoder() => this.Quantizer = KnownQuantizers.Octree;
16+
public BmpEncoder() => this.Quantizer = KnownQuantizers.Hexadecatree;
1717

1818
/// <summary>
1919
/// Gets the number of bits per pixel.

src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public BmpEncoderCore(BmpEncoder encoder, MemoryAllocator memoryAllocator)
116116
this.bitsPerPixel = encoder.BitsPerPixel;
117117

118118
// TODO: Use a palette quantizer if supplied.
119-
this.quantizer = encoder.Quantizer ?? KnownQuantizers.Octree;
119+
this.quantizer = encoder.Quantizer ?? KnownQuantizers.Hexadecatree;
120120
this.pixelSamplingStrategy = encoder.PixelSamplingStrategy;
121121
this.transparentColorMode = encoder.TransparentColorMode;
122122
this.infoHeaderType = encoder.SupportTransparency ? BmpInfoHeaderType.WinVersion4 : BmpInfoHeaderType.WinVersion3;

src/ImageSharp/Formats/Gif/GifEncoderCore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
117117

118118
if (globalQuantizer is null)
119119
{
120-
// Is this a gif with color information. If so use that, otherwise use octree.
120+
// Is this a gif with color information. If so use that, otherwise use the adaptive hexadecatree quantizer.
121121
if (gifMetadata.ColorTableMode == FrameColorTableMode.Global && gifMetadata.GlobalColorTable?.Length > 0)
122122
{
123123
int ti = GetTransparentIndex(quantized, frameMetadata);
@@ -132,12 +132,12 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
132132
}
133133
else
134134
{
135-
globalQuantizer = new OctreeQuantizer(options);
135+
globalQuantizer = new HexadecatreeQuantizer(options);
136136
}
137137
}
138138
else
139139
{
140-
globalQuantizer = new OctreeQuantizer(options);
140+
globalQuantizer = new HexadecatreeQuantizer(options);
141141
}
142142
}
143143

src/ImageSharp/Formats/Tiff/TiffEncoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class TiffEncoder : QuantizingImageEncoder
1515
/// <summary>
1616
/// Initializes a new instance of the <see cref="TiffEncoder"/> class.
1717
/// </summary>
18-
public TiffEncoder() => this.Quantizer = KnownQuantizers.Octree;
18+
public TiffEncoder() => this.Quantizer = KnownQuantizers.Hexadecatree;
1919

2020
/// <summary>
2121
/// Gets the number of bits per pixel.

src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public TiffEncoderCore(TiffEncoder encoder, Configuration configuration)
7171
this.configuration = configuration;
7272
this.memoryAllocator = configuration.MemoryAllocator;
7373
this.PhotometricInterpretation = encoder.PhotometricInterpretation;
74-
this.quantizer = encoder.Quantizer ?? KnownQuantizers.Octree;
74+
this.quantizer = encoder.Quantizer ?? KnownQuantizers.Hexadecatree;
7575
this.pixelSamplingStrategy = encoder.PixelSamplingStrategy;
7676
this.BitsPerPixel = encoder.BitsPerPixel;
7777
this.HorizontalPredictor = encoder.HorizontalPredictor;

src/ImageSharp/Processing/Extensions/Quantization/QuantizeExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ namespace SixLabors.ImageSharp.Processing;
1212
public static class QuantizeExtensions
1313
{
1414
/// <summary>
15-
/// Applies quantization to the image using the <see cref="OctreeQuantizer"/>.
15+
/// Applies quantization to the image using the <see cref="HexadecatreeQuantizer"/>.
1616
/// </summary>
1717
/// <param name="source">The current image processing context.</param>
1818
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
1919
public static IImageProcessingContext Quantize(this IImageProcessingContext source) =>
20-
Quantize(source, KnownQuantizers.Octree);
20+
Quantize(source, KnownQuantizers.Hexadecatree);
2121

2222
/// <summary>
2323
/// Applies quantization to the image.
@@ -29,15 +29,15 @@ public static IImageProcessingContext Quantize(this IImageProcessingContext sour
2929
source.ApplyProcessor(new QuantizeProcessor(quantizer));
3030

3131
/// <summary>
32-
/// Applies quantization to the image using the <see cref="OctreeQuantizer"/>.
32+
/// Applies quantization to the image using the <see cref="HexadecatreeQuantizer"/>.
3333
/// </summary>
3434
/// <param name="source">The current image processing context.</param>
3535
/// <param name="rectangle">
3636
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
3737
/// </param>
3838
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
3939
public static IImageProcessingContext Quantize(this IImageProcessingContext source, Rectangle rectangle) =>
40-
Quantize(source, KnownQuantizers.Octree, rectangle);
40+
Quantize(source, KnownQuantizers.Hexadecatree, rectangle);
4141

4242
/// <summary>
4343
/// Applies quantization to the image.

src/ImageSharp/Processing/KnownQuantizers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
// Copyright (c) Six Labors.
1+
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

44
using SixLabors.ImageSharp.Processing.Processors.Quantization;
55

66
namespace SixLabors.ImageSharp.Processing;
77

88
/// <summary>
9-
/// Contains reusable static instances of known quantizing algorithms
9+
/// Contains reusable static instances of known quantizing algorithms.
1010
/// </summary>
1111
public static class KnownQuantizers
1212
{
1313
/// <summary>
14-
/// Gets the adaptive Octree quantizer. Fast with good quality.
14+
/// Gets the adaptive hexadecatree quantizer. Fast with good quality.
1515
/// </summary>
16-
public static IQuantizer Octree { get; } = new OctreeQuantizer();
16+
public static IQuantizer Hexadecatree { get; } = new HexadecatreeQuantizer();
1717

1818
/// <summary>
1919
/// Gets the Xiaolin Wu's Color Quantizer which generates high quality output.

src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer.cs renamed to src/ImageSharp/Processing/Processors/Quantization/HexadecatreeQuantizer.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,29 @@
66
namespace SixLabors.ImageSharp.Processing.Processors.Quantization;
77

88
/// <summary>
9-
/// Allows the quantization of images pixels using Octrees.
10-
/// <see href="http://msdn.microsoft.com/en-us/library/aa479306.aspx"/>
9+
/// Quantizes images by grouping colors in an adaptive 16-way tree and reducing those groups into a palette.
1110
/// </summary>
12-
public class OctreeQuantizer : IQuantizer
11+
/// <remarks>
12+
/// Each level routes colors using one bit of RGB and, when useful, one bit of alpha. Fully opaque mid-tone colors
13+
/// use RGB-only routing so more branch resolution is spent on visible color detail, while transparent, dark, and
14+
/// light colors use alpha-aware routing so opacity changes can form their own palette buckets.
15+
/// </remarks>
16+
public class HexadecatreeQuantizer : IQuantizer
1317
{
1418
/// <summary>
15-
/// Initializes a new instance of the <see cref="OctreeQuantizer"/> class
19+
/// Initializes a new instance of the <see cref="HexadecatreeQuantizer"/> class
1620
/// using the default <see cref="QuantizerOptions"/>.
1721
/// </summary>
18-
public OctreeQuantizer()
22+
public HexadecatreeQuantizer()
1923
: this(new QuantizerOptions())
2024
{
2125
}
2226

2327
/// <summary>
24-
/// Initializes a new instance of the <see cref="OctreeQuantizer"/> class.
28+
/// Initializes a new instance of the <see cref="HexadecatreeQuantizer"/> class.
2529
/// </summary>
26-
/// <param name="options">The quantizer options defining quantization rules.</param>
27-
public OctreeQuantizer(QuantizerOptions options)
30+
/// <param name="options">The quantizer options that control palette size, dithering, and transparency behavior.</param>
31+
public HexadecatreeQuantizer(QuantizerOptions options)
2832
{
2933
Guard.NotNull(options, nameof(options));
3034
this.Options = options;
@@ -41,5 +45,5 @@ public IQuantizer<TPixel> CreatePixelSpecificQuantizer<TPixel>(Configuration con
4145
/// <inheritdoc />
4246
public IQuantizer<TPixel> CreatePixelSpecificQuantizer<TPixel>(Configuration configuration, QuantizerOptions options)
4347
where TPixel : unmanaged, IPixel<TPixel>
44-
=> new OctreeQuantizer<TPixel>(configuration, options);
48+
=> new HexadecatreeQuantizer<TPixel>(configuration, options);
4549
}

0 commit comments

Comments
 (0)