|
|
|
@ -17,21 +17,128 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Quantization |
|
|
|
TestImages.Png.Bike |
|
|
|
}; |
|
|
|
|
|
|
|
private static readonly QuantizerOptions NoDitherOptions = new QuantizerOptions { Dither = null }; |
|
|
|
private static readonly QuantizerOptions DiffuserDitherOptions = new QuantizerOptions { Dither = KnownDitherings.FloydSteinberg }; |
|
|
|
private static readonly QuantizerOptions OrderedDitherOptions = new QuantizerOptions { Dither = KnownDitherings.BayerDither8x8 }; |
|
|
|
|
|
|
|
private static readonly QuantizerOptions Diffuser0_ScaleDitherOptions = new QuantizerOptions |
|
|
|
{ |
|
|
|
Dither = KnownDitherings.FloydSteinberg, |
|
|
|
DitherScale = 0F |
|
|
|
}; |
|
|
|
|
|
|
|
private static readonly QuantizerOptions Diffuser0_25_ScaleDitherOptions = new QuantizerOptions |
|
|
|
{ |
|
|
|
Dither = KnownDitherings.FloydSteinberg, |
|
|
|
DitherScale = .25F |
|
|
|
}; |
|
|
|
|
|
|
|
private static readonly QuantizerOptions Diffuser0_5_ScaleDitherOptions = new QuantizerOptions |
|
|
|
{ |
|
|
|
Dither = KnownDitherings.FloydSteinberg, |
|
|
|
DitherScale = .5F |
|
|
|
}; |
|
|
|
|
|
|
|
private static readonly QuantizerOptions Diffuser0_75_ScaleDitherOptions = new QuantizerOptions |
|
|
|
{ |
|
|
|
Dither = KnownDitherings.FloydSteinberg, |
|
|
|
DitherScale = .75F |
|
|
|
}; |
|
|
|
|
|
|
|
private static readonly QuantizerOptions Ordered0_ScaleDitherOptions = new QuantizerOptions |
|
|
|
{ |
|
|
|
Dither = KnownDitherings.BayerDither8x8, |
|
|
|
DitherScale = 0F |
|
|
|
}; |
|
|
|
|
|
|
|
private static readonly QuantizerOptions Ordered0_25_ScaleDitherOptions = new QuantizerOptions |
|
|
|
{ |
|
|
|
Dither = KnownDitherings.BayerDither8x8, |
|
|
|
DitherScale = .25F |
|
|
|
}; |
|
|
|
|
|
|
|
private static readonly QuantizerOptions Ordered0_5_ScaleDitherOptions = new QuantizerOptions |
|
|
|
{ |
|
|
|
Dither = KnownDitherings.BayerDither8x8, |
|
|
|
DitherScale = .5F |
|
|
|
}; |
|
|
|
|
|
|
|
private static readonly QuantizerOptions Ordered0_75_ScaleDitherOptions = new QuantizerOptions |
|
|
|
{ |
|
|
|
Dither = KnownDitherings.BayerDither8x8, |
|
|
|
DitherScale = .75F |
|
|
|
}; |
|
|
|
|
|
|
|
public static readonly TheoryData<IQuantizer> Quantizers |
|
|
|
= new TheoryData<IQuantizer> |
|
|
|
{ |
|
|
|
// Known uses error diffusion by default.
|
|
|
|
KnownQuantizers.Octree, |
|
|
|
KnownQuantizers.WebSafe, |
|
|
|
KnownQuantizers.Werner, |
|
|
|
KnownQuantizers.Wu, |
|
|
|
new OctreeQuantizer(false), |
|
|
|
new WebSafePaletteQuantizer(false), |
|
|
|
new WernerPaletteQuantizer(false), |
|
|
|
new WuQuantizer(false), |
|
|
|
new OctreeQuantizer(KnownDitherings.BayerDither8x8), |
|
|
|
new WebSafePaletteQuantizer(KnownDitherings.BayerDither8x8), |
|
|
|
new WernerPaletteQuantizer(KnownDitherings.BayerDither8x8), |
|
|
|
new WuQuantizer(KnownDitherings.BayerDither8x8) |
|
|
|
new OctreeQuantizer(NoDitherOptions), |
|
|
|
new WebSafePaletteQuantizer(NoDitherOptions), |
|
|
|
new WernerPaletteQuantizer(NoDitherOptions), |
|
|
|
new WuQuantizer(NoDitherOptions), |
|
|
|
new OctreeQuantizer(OrderedDitherOptions), |
|
|
|
new WebSafePaletteQuantizer(OrderedDitherOptions), |
|
|
|
new WernerPaletteQuantizer(OrderedDitherOptions), |
|
|
|
new WuQuantizer(OrderedDitherOptions) |
|
|
|
}; |
|
|
|
|
|
|
|
public static readonly TheoryData<IQuantizer> DitherScaleQuantizers |
|
|
|
= new TheoryData<IQuantizer> |
|
|
|
{ |
|
|
|
new OctreeQuantizer(Diffuser0_ScaleDitherOptions), |
|
|
|
new WebSafePaletteQuantizer(Diffuser0_ScaleDitherOptions), |
|
|
|
new WernerPaletteQuantizer(Diffuser0_ScaleDitherOptions), |
|
|
|
new WuQuantizer(Diffuser0_ScaleDitherOptions), |
|
|
|
|
|
|
|
new OctreeQuantizer(Diffuser0_25_ScaleDitherOptions), |
|
|
|
new WebSafePaletteQuantizer(Diffuser0_25_ScaleDitherOptions), |
|
|
|
new WernerPaletteQuantizer(Diffuser0_25_ScaleDitherOptions), |
|
|
|
new WuQuantizer(Diffuser0_25_ScaleDitherOptions), |
|
|
|
|
|
|
|
new OctreeQuantizer(Diffuser0_5_ScaleDitherOptions), |
|
|
|
new WebSafePaletteQuantizer(Diffuser0_5_ScaleDitherOptions), |
|
|
|
new WernerPaletteQuantizer(Diffuser0_5_ScaleDitherOptions), |
|
|
|
new WuQuantizer(Diffuser0_5_ScaleDitherOptions), |
|
|
|
|
|
|
|
new OctreeQuantizer(Diffuser0_75_ScaleDitherOptions), |
|
|
|
new WebSafePaletteQuantizer(Diffuser0_75_ScaleDitherOptions), |
|
|
|
new WernerPaletteQuantizer(Diffuser0_75_ScaleDitherOptions), |
|
|
|
new WuQuantizer(Diffuser0_75_ScaleDitherOptions), |
|
|
|
|
|
|
|
new OctreeQuantizer(DiffuserDitherOptions), |
|
|
|
new WebSafePaletteQuantizer(DiffuserDitherOptions), |
|
|
|
new WernerPaletteQuantizer(DiffuserDitherOptions), |
|
|
|
new WuQuantizer(DiffuserDitherOptions), |
|
|
|
|
|
|
|
new OctreeQuantizer(Ordered0_ScaleDitherOptions), |
|
|
|
new WebSafePaletteQuantizer(Ordered0_ScaleDitherOptions), |
|
|
|
new WernerPaletteQuantizer(Ordered0_ScaleDitherOptions), |
|
|
|
new WuQuantizer(Ordered0_ScaleDitherOptions), |
|
|
|
|
|
|
|
new OctreeQuantizer(Ordered0_25_ScaleDitherOptions), |
|
|
|
new WebSafePaletteQuantizer(Ordered0_25_ScaleDitherOptions), |
|
|
|
new WernerPaletteQuantizer(Ordered0_25_ScaleDitherOptions), |
|
|
|
new WuQuantizer(Ordered0_25_ScaleDitherOptions), |
|
|
|
|
|
|
|
new OctreeQuantizer(Ordered0_5_ScaleDitherOptions), |
|
|
|
new WebSafePaletteQuantizer(Ordered0_5_ScaleDitherOptions), |
|
|
|
new WernerPaletteQuantizer(Ordered0_5_ScaleDitherOptions), |
|
|
|
new WuQuantizer(Ordered0_5_ScaleDitherOptions), |
|
|
|
|
|
|
|
new OctreeQuantizer(Ordered0_75_ScaleDitherOptions), |
|
|
|
new WebSafePaletteQuantizer(Ordered0_75_ScaleDitherOptions), |
|
|
|
new WernerPaletteQuantizer(Ordered0_75_ScaleDitherOptions), |
|
|
|
new WuQuantizer(Ordered0_75_ScaleDitherOptions), |
|
|
|
|
|
|
|
new OctreeQuantizer(OrderedDitherOptions), |
|
|
|
new WebSafePaletteQuantizer(OrderedDitherOptions), |
|
|
|
new WernerPaletteQuantizer(OrderedDitherOptions), |
|
|
|
new WuQuantizer(OrderedDitherOptions), |
|
|
|
}; |
|
|
|
|
|
|
|
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.05f); |
|
|
|
@ -42,8 +149,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Quantization |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
string quantizerName = quantizer.GetType().Name; |
|
|
|
string ditherName = quantizer.Dither?.GetType()?.Name ?? "noDither"; |
|
|
|
string ditherType = quantizer.Dither?.DitherType.ToString() ?? string.Empty; |
|
|
|
string ditherName = quantizer.Options.Dither?.GetType()?.Name ?? "noDither"; |
|
|
|
string ditherType = quantizer.Options.Dither?.DitherType.ToString() ?? string.Empty; |
|
|
|
string testOutputDetails = $"{quantizerName}_{ditherName}_{ditherType}"; |
|
|
|
|
|
|
|
provider.RunRectangleConstrainedValidatingProcessorTest( |
|
|
|
@ -59,8 +166,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Quantization |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
string quantizerName = quantizer.GetType().Name; |
|
|
|
string ditherName = quantizer.Dither?.GetType()?.Name ?? "noDither"; |
|
|
|
string ditherType = quantizer.Dither?.DitherType.ToString() ?? string.Empty; |
|
|
|
string ditherName = quantizer.Options.Dither?.GetType()?.Name ?? "noDither"; |
|
|
|
string ditherType = quantizer.Options.Dither?.DitherType.ToString() ?? string.Empty; |
|
|
|
string testOutputDetails = $"{quantizerName}_{ditherName}_{ditherType}"; |
|
|
|
|
|
|
|
provider.RunValidatingProcessorTest( |
|
|
|
@ -69,5 +176,23 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Quantization |
|
|
|
testOutputDetails: testOutputDetails, |
|
|
|
appendPixelTypeToFileName: false); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(TestImages.Png.David, nameof(DitherScaleQuantizers), PixelTypes.Rgba32)] |
|
|
|
public void ApplyQuantizationWithDitheringScale<TPixel>(TestImageProvider<TPixel> provider, IQuantizer quantizer) |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
string quantizerName = quantizer.GetType().Name; |
|
|
|
string ditherName = quantizer.Options.Dither.GetType().Name; |
|
|
|
string ditherType = quantizer.Options.Dither.DitherType.ToString(); |
|
|
|
float ditherScale = quantizer.Options.DitherScale; |
|
|
|
string testOutputDetails = $"{quantizerName}_{ditherName}_{ditherType}_{ditherScale}"; |
|
|
|
|
|
|
|
provider.RunValidatingProcessorTest( |
|
|
|
x => x.Quantize(quantizer), |
|
|
|
comparer: ValidatorComparer, |
|
|
|
testOutputDetails: testOutputDetails, |
|
|
|
appendPixelTypeToFileName: false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|