Browse Source

hoist some calculations out

pull/1818/head
Kunal Pathak 5 years ago
parent
commit
6885d97c88
  1. 26
      src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs
  2. 2
      tests/ImageSharp.Benchmarks/Codecs/EncodeIndexedPng.cs

26
src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs

@ -418,18 +418,44 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
for (int r = 1; r < IndexCount; r++) for (int r = 1; r < IndexCount; r++)
{ {
volumeSpan.Clear(); volumeSpan.Clear();
#if ALTERNATE
int ind1_r = (r << ((IndexBits * 2) + IndexAlphaBits)) +
(r << (IndexBits + IndexAlphaBits + 1)) +
(r << (IndexBits * 2)) +
(r << (IndexBits + 1)) +
r;
#endif
for (int g = 1; g < IndexCount; g++) for (int g = 1; g < IndexCount; g++)
{ {
areaSpan.Clear(); areaSpan.Clear();
#if ALTERNATE
int ind1_g = ind1_r +
(g << (IndexBits + IndexAlphaBits)) +
(g << IndexBits) +
g;
int r_g = r + g;
#endif
for (int b = 1; b < IndexCount; b++) for (int b = 1; b < IndexCount; b++)
{ {
#if ALTERNATE
int ind1_b = ind1_g +
((r_g + b) << IndexAlphaBits) +
b;
#endif
Moment line = default; Moment line = default;
for (int a = 1; a < IndexAlphaCount; a++) for (int a = 1; a < IndexAlphaCount; a++)
{ {
#if ALTERNATE
int ind1 = ind1_b + a;
#else
int ind1 = GetPaletteIndex(r, g, b, a); int ind1 = GetPaletteIndex(r, g, b, a);
#endif
line += momentSpan[ind1]; line += momentSpan[ind1];
areaSpan[a] += line; areaSpan[a] += line;

2
tests/ImageSharp.Benchmarks/Codecs/EncodeIndexedPng.cs

@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs
public void PngCoreWuNoDither() public void PngCoreWuNoDither()
{ {
using var memoryStream = new MemoryStream(); using var memoryStream = new MemoryStream();
var options = new PngEncoder { Quantizer = new WuQuantizer(new QuantizerOptions { Dither = null }) }; var options = new PngEncoder { Quantizer = new WuQuantizer(new QuantizerOptions { Dither = null }), ColorType = PngColorType.Palette };
this.bmpCore.SaveAsPng(memoryStream, options); this.bmpCore.SaveAsPng(memoryStream, options);
} }
} }

Loading…
Cancel
Save