Browse Source

Remove duplicate FTransform method

pull/1849/head
Brian Popow 5 years ago
parent
commit
6393484e42
  1. 44
      src/ImageSharp/Formats/Webp/Lossy/Vp8Histogram.cs

44
src/ImageSharp/Formats/Webp/Lossy/Vp8Histogram.cs

@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
this.distribution.AsSpan().Clear();
for (j = startBlock; j < endBlock; j++)
{
this.Vp8FTransform(reference.Slice(WebpLookupTables.Vp8DspScan[j]), pred.Slice(WebpLookupTables.Vp8DspScan[j]), this.output);
Vp8Encoding.FTransform(reference.Slice(WebpLookupTables.Vp8DspScan[j]), pred.Slice(WebpLookupTables.Vp8DspScan[j]), this.output, this.scratch);
// Convert coefficients to bin.
for (int k = 0; k < 16; ++k)
@ -98,48 +98,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
this.lastNonZero = lastNonZero;
}
private void Vp8FTransform(Span<byte> src, Span<byte> reference, Span<short> output)
{
int i;
Span<int> tmp = this.scratch;
tmp.Clear();
for (i = 0; i < 4; i++)
{
int d0 = src[0] - reference[0]; // 9bit dynamic range ([-255,255])
int d1 = src[1] - reference[1];
int d2 = src[2] - reference[2];
int d3 = src[3] - reference[3];
int a0 = d0 + d3; // 10b [-510,510]
int a1 = d1 + d2;
int a2 = d1 - d2;
int a3 = d0 - d3;
tmp[0 + (i * 4)] = (a0 + a1) * 8; // 14b [-8160,8160]
tmp[1 + (i * 4)] = ((a2 * 2217) + (a3 * 5352) + 1812) >> 9; // [-7536,7542]
tmp[2 + (i * 4)] = (a0 - a1) * 8;
tmp[3 + (i * 4)] = ((a3 * 2217) - (a2 * 5352) + 937) >> 9;
// Do not change the span in the last iteration.
if (i < 3)
{
src = src.Slice(WebpConstants.Bps);
reference = reference.Slice(WebpConstants.Bps);
}
}
for (i = 0; i < 4; i++)
{
int a0 = tmp[0 + i] + tmp[12 + i]; // 15b
int a1 = tmp[4 + i] + tmp[8 + i];
int a2 = tmp[4 + i] - tmp[8 + i];
int a3 = tmp[0 + i] - tmp[12 + i];
output[0 + i] = (short)((a0 + a1 + 7) >> 4); // 12b
output[4 + i] = (short)((((a2 * 2217) + (a3 * 5352) + 12000) >> 16) + (a3 != 0 ? 1 : 0));
output[8 + i] = (short)((a0 - a1 + 7) >> 4);
output[12 + i] = (short)(((a3 * 2217) - (a2 * 5352) + 51000) >> 16);
}
}
[MethodImpl(InliningOptions.ShortMethod)]
private static int ClipMax(int v, int max) => v > max ? max : v;
}

Loading…
Cancel
Save