Browse Source

Add VP8 encoding tests

pull/1552/head
Brian Popow 5 years ago
parent
commit
ca68ecc3a0
  1. 8
      src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs
  2. 2
      src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs
  3. 57
      tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs

8
src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs

@ -367,17 +367,17 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
this.ImportLine(v.Slice(uvStartIdx - 1), uvStride, vLeft.Slice(1), uvh, 8);
}
Span<byte> yTop = this.YTop.Slice(this.yTopIdx);
Span<byte> yTop = this.YTop.Slice(this.yTopIdx, 16);
if (this.Y == 0)
{
yTop.Fill(127);
this.UvTop.GetSpan().Fill(127);
this.UvTop.Slice(this.uvTopIdx, 16).Fill(127);
}
else
{
this.ImportLine(y.Slice(yStartIdx - yStride), 1, yTop, w, 16);
this.ImportLine(u.Slice(uvStartIdx - uvStride), 1, this.UvTop.GetSpan().Slice(8), uvw, 8);
this.ImportLine(v.Slice(uvStartIdx - uvStride), 1, this.UvTop.GetSpan().Slice(8), uvw, 8);
this.ImportLine(u.Slice(uvStartIdx - uvStride), 1, this.UvTop.Slice(this.uvTopIdx, 8), uvw, 8);
this.ImportLine(v.Slice(uvStartIdx - uvStride), 1, this.UvTop.Slice(this.uvTopIdx + 8, 8), uvw, 8);
}
}

2
src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs

@ -224,7 +224,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
var alphas = new int[WebPConstants.MaxAlpha + 1];
this.alpha = this.MacroBlockAnalysis(width, height, it, y, u, v, yStride, uvStride, alphas, out this.uvAlpha);
// Analysis is done, proceed to actual coding.
// Analysis is done, proceed to actual encoding.
// TODO: EncodeAlpha();
this.segmentHeader = new Vp8EncSegmentHeader(4);

57
tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs

@ -24,11 +24,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
Quality = quality
};
using (Image<TPixel> image = provider.GetImage())
{
var testOutputDetails = string.Concat("lossless", "_q", quality);
image.VerifyEncoder(provider, "webp", testOutputDetails, encoder);
}
using Image<TPixel> image = provider.GetImage();
var testOutputDetails = string.Concat("lossless", "_q", quality);
image.VerifyEncoder(provider, "webp", testOutputDetails, encoder);
}
[Theory]
@ -46,14 +44,53 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
{
Lossy = false,
Method = method,
Quality = 100
Quality = 75
};
using (Image<TPixel> image = provider.GetImage())
using Image<TPixel> image = provider.GetImage();
var testOutputDetails = string.Concat("lossless", "_m", method);
image.VerifyEncoder(provider, "webp", testOutputDetails, encoder);
}
[Theory]
[WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 100)]
[WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 75)]
[WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 20)]
public void Encode_Lossy_WithDifferentQuality_Works<TPixel>(TestImageProvider<TPixel> provider, int quality)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebPEncoder()
{
var testOutputDetails = string.Concat("lossless", "_m", method);
image.VerifyEncoder(provider, "webp", testOutputDetails, encoder);
}
Lossy = true,
Quality = quality
};
using Image<TPixel> image = provider.GetImage();
var testOutputDetails = string.Concat("lossy", "_q", quality);
image.VerifyEncoder(provider, "webp", testOutputDetails, encoder);
}
[Theory]
[WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 0)]
[WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 1)]
[WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 2)]
[WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 3)]
[WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 4)]
[WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 5)]
[WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 6)]
public void Encode_Lossy_WithDifferentMethods_Works<TPixel>(TestImageProvider<TPixel> provider, int method)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebPEncoder()
{
Lossy = true,
Method = method,
Quality = 75
};
using Image<TPixel> image = provider.GetImage();
var testOutputDetails = string.Concat("lossy", "_m", method);
image.VerifyEncoder(provider, "webp", testOutputDetails, encoder);
}
}
}

Loading…
Cancel
Save