Browse Source

Fix some lossy decoding bugs

pull/1552/head
Brian Popow 6 years ago
parent
commit
9567e17fa5
  1. 8
      src/ImageSharp/Formats/WebP/LossyUtils.cs
  2. 4
      src/ImageSharp/Formats/WebP/Vp8Decoder.cs
  3. 4
      src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs

8
src/ImageSharp/Formats/WebP/LossyUtils.cs

@ -596,7 +596,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
{
for (int k = 3; k > 0; --k)
{
offset += stride;
offset += 4;
SimpleHFilter16(p, offset, stride, thresh);
}
}
@ -781,7 +781,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
int q0 = p[offset];
int q1 = p[offset + step];
int q2 = p[offset + (2 * step)];
int a = Vp8LookupTables.Clip1[(3 * (q0 - p0)) + Vp8LookupTables.Clip1[p1 - q1]];
int a = Vp8LookupTables.Sclip1[(3 * (q0 - p0)) + Vp8LookupTables.Sclip1[p1 - q1]];
// a is in [-128,127], a1 in [-27,27], a2 in [-18,18] and a3 in [-9,9]
int a1 = ((27 * a) + 63) >> 7; // eq. to ((3 * a + 7) * 9) >> 7
@ -795,13 +795,13 @@ namespace SixLabors.ImageSharp.Formats.WebP
p[offset + (2 * step)] = Vp8LookupTables.Clip1[q2 - a3];
}
private static bool NeedsFilter(byte[] p, int offset, int step, int thresh)
private static bool NeedsFilter(byte[] p, int offset, int step, int t)
{
int p1 = p[offset + (-2 * step)];
int p0 = p[offset - step];
int q0 = p[offset];
int q1 = p[offset + step];
return (Vp8LookupTables.Abs0[p1 - p0] > thresh) || (Vp8LookupTables.Abs0[q1 - q0] > thresh);
return ((4 * Vp8LookupTables.Abs0[p0 - q0]) + Vp8LookupTables.Abs0[p1 - q1]) <= t;
}
private static bool NeedsFilter2(byte[] p, int offset, int step, int t, int it)

4
src/ImageSharp/Formats/WebP/Vp8Decoder.cs

@ -234,7 +234,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
{
int baseLevel;
// First, compute the initial level
// First, compute the initial level.
if (this.SegmentHeader.UseSegment)
{
baseLevel = this.SegmentHeader.FilterStrength[s];
@ -296,7 +296,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
info.Limit = 0; // no filtering.
}
info.InnerLevel = (byte)i4x4;
info.UseInnerFiltering = (byte)i4x4;
}
}
}

4
src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs

@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
// Paragraph 9.6: Dequantization Indices.
this.ParseDequantizationIndices(decoder);
// Ignore the value of update_proba
// Ignore the value of update probabilities.
this.bitReader.ReadBool();
// Paragraph 13.4: Parse probabilities.
@ -475,7 +475,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
private void DoFilter(Vp8Decoder dec, int mbx, int mby)
{
int yBps = dec.CacheYStride;
Vp8FilterInfo filterInfo = dec.FilterInfo[dec.MbX];
Vp8FilterInfo filterInfo = dec.FilterInfo[mbx];
int iLevel = filterInfo.InnerLevel;
int limit = filterInfo.Limit;

Loading…
Cancel
Save