Browse Source

Fix decoding issues

- Lossless: Check if transforms are present on dispose
- Lossy: Set filterinfo properly
pull/1147/head
Brian Popow 6 years ago
parent
commit
885b3fb729
  1. 24
      src/ImageSharp/Formats/WebP/Vp8FilterInfo.cs
  2. 11
      src/ImageSharp/Formats/WebP/Vp8LDecoder.cs
  3. 13
      src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs

24
src/ImageSharp/Formats/WebP/Vp8FilterInfo.cs

@ -6,8 +6,27 @@ namespace SixLabors.ImageSharp.Formats.WebP
/// <summary>
/// Filter information.
/// </summary>
internal class Vp8FilterInfo
internal class Vp8FilterInfo : IDeepCloneable
{
/// <summary>
/// Initializes a new instance of the <see cref="Vp8FilterInfo"/> class.
/// </summary>
public Vp8FilterInfo()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Vp8FilterInfo"/> class.
/// </summary>
/// <param name="other">The filter info to create an instance from.</param>
public Vp8FilterInfo(Vp8FilterInfo other)
{
this.Limit = other.Limit;
this.HighEdgeVarianceThreshold = other.HighEdgeVarianceThreshold;
this.InnerLevel = other.InnerLevel;
this.UseInnerFiltering = other.UseInnerFiltering;
}
/// <summary>
/// Gets or sets the filter limit in [3..189], or 0 if no filtering.
/// </summary>
@ -28,5 +47,8 @@ namespace SixLabors.ImageSharp.Formats.WebP
/// Gets or sets the high edge variance threshold in [0..2].
/// </summary>
public byte HighEdgeVarianceThreshold { get; set; }
/// <inheritdoc/>
public IDeepCloneable DeepClone() => new Vp8FilterInfo(this);
}
}

11
src/ImageSharp/Formats/WebP/Vp8LDecoder.cs

@ -57,12 +57,15 @@ namespace SixLabors.ImageSharp.Formats.WebP
public void Dispose()
{
this.Pixels.Dispose();
foreach (Vp8LTransform transform in this.Transforms)
this.Metadata?.HuffmanImage?.Dispose();
if (this.Transforms != null)
{
transform.Data?.Dispose();
foreach (Vp8LTransform transform in this.Transforms)
{
transform.Data?.Dispose();
}
}
this.Metadata?.HuffmanImage?.Dispose();
}
}
}

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

@ -79,9 +79,11 @@ namespace SixLabors.ImageSharp.Formats.WebP
if (info.Features?.Alpha is true)
{
var alphaDecoder = new AlphaDecoder(width, height, info.Features.AlphaData, info.Features.AlphaChunkHeader, this.memoryAllocator);
alphaDecoder.Decode();
this.DecodePixelValues(width, height, decoder.Pixels, pixels, alphaDecoder.Alpha);
using (var alphaDecoder = new AlphaDecoder(width, height, info.Features.AlphaData, info.Features.AlphaChunkHeader, this.memoryAllocator))
{
alphaDecoder.Decode();
this.DecodePixelValues(width, height, decoder.Pixels, pixels, alphaDecoder.Alpha);
}
}
else
{
@ -100,7 +102,7 @@ namespace SixLabors.ImageSharp.Formats.WebP
hasAlpha = true;
alphaSpan = alpha.Memory.Span;
}
for (int y = 0; y < height; y++)
{
Span<TPixel> pixelRow = pixels.GetRowSpan(y);
@ -826,7 +828,8 @@ namespace SixLabors.ImageSharp.Formats.WebP
// Store filter info.
if (dec.Filter != LoopFilter.None)
{
dec.FilterInfo[dec.MbX] = dec.FilterStrength[blockData.Segment, blockData.IsI4x4 ? 1 : 0];
Vp8FilterInfo precomputedFilterInfo = dec.FilterStrength[blockData.Segment, blockData.IsI4x4 ? 1 : 0];
dec.FilterInfo[dec.MbX] = (Vp8FilterInfo)precomputedFilterInfo.DeepClone();
dec.FilterInfo[dec.MbX].UseInnerFiltering |= (byte)(skip is 0 ? 1 : 0);
}
}

Loading…
Cancel
Save