|
|
@ -71,10 +71,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
private int uvAlpha; |
|
|
private int uvAlpha; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
private readonly bool alphaCompression; |
|
|
/// Scratch buffer to reduce allocations.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private readonly int[] scratch = new int[16]; |
|
|
|
|
|
|
|
|
|
|
|
private readonly byte[] averageBytesPerMb = { 50, 24, 16, 9, 7, 5, 3, 2 }; |
|
|
private readonly byte[] averageBytesPerMb = { 50, 24, 16, 9, 7, 5, 3, 2 }; |
|
|
|
|
|
|
|
|
@ -105,6 +102,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy |
|
|
/// <param name="entropyPasses">Number of entropy-analysis passes (in [1..10]).</param>
|
|
|
/// <param name="entropyPasses">Number of entropy-analysis passes (in [1..10]).</param>
|
|
|
/// <param name="filterStrength">The filter the strength of the deblocking filter, between 0 (no filtering) and 100 (maximum filtering).</param>
|
|
|
/// <param name="filterStrength">The filter the strength of the deblocking filter, between 0 (no filtering) and 100 (maximum filtering).</param>
|
|
|
/// <param name="spatialNoiseShaping">The spatial noise shaping. 0=off, 100=maximum.</param>
|
|
|
/// <param name="spatialNoiseShaping">The spatial noise shaping. 0=off, 100=maximum.</param>
|
|
|
|
|
|
/// <param name="alphaCompression">If true, the alpha channel will be compressed with the lossless compression.</param>
|
|
|
public Vp8Encoder( |
|
|
public Vp8Encoder( |
|
|
MemoryAllocator memoryAllocator, |
|
|
MemoryAllocator memoryAllocator, |
|
|
Configuration configuration, |
|
|
Configuration configuration, |
|
|
@ -114,7 +112,8 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy |
|
|
WebpEncodingMethod method, |
|
|
WebpEncodingMethod method, |
|
|
int entropyPasses, |
|
|
int entropyPasses, |
|
|
int filterStrength, |
|
|
int filterStrength, |
|
|
int spatialNoiseShaping) |
|
|
int spatialNoiseShaping, |
|
|
|
|
|
bool alphaCompression) |
|
|
{ |
|
|
{ |
|
|
this.memoryAllocator = memoryAllocator; |
|
|
this.memoryAllocator = memoryAllocator; |
|
|
this.configuration = configuration; |
|
|
this.configuration = configuration; |
|
|
@ -125,6 +124,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy |
|
|
this.entropyPasses = Numerics.Clamp(entropyPasses, 1, 10); |
|
|
this.entropyPasses = Numerics.Clamp(entropyPasses, 1, 10); |
|
|
this.filterStrength = Numerics.Clamp(filterStrength, 0, 100); |
|
|
this.filterStrength = Numerics.Clamp(filterStrength, 0, 100); |
|
|
this.spatialNoiseShaping = Numerics.Clamp(spatialNoiseShaping, 0, 100); |
|
|
this.spatialNoiseShaping = Numerics.Clamp(spatialNoiseShaping, 0, 100); |
|
|
|
|
|
this.alphaCompression = alphaCompression; |
|
|
this.rdOptLevel = method is WebpEncodingMethod.BestQuality ? Vp8RdLevel.RdOptTrellisAll |
|
|
this.rdOptLevel = method is WebpEncodingMethod.BestQuality ? Vp8RdLevel.RdOptTrellisAll |
|
|
: method >= WebpEncodingMethod.Level5 ? Vp8RdLevel.RdOptTrellis |
|
|
: method >= WebpEncodingMethod.Level5 ? Vp8RdLevel.RdOptTrellis |
|
|
: method >= WebpEncodingMethod.Level3 ? Vp8RdLevel.RdOptBasic |
|
|
: method >= WebpEncodingMethod.Level3 ? Vp8RdLevel.RdOptBasic |
|
|
@ -327,7 +327,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy |
|
|
if (hasAlpha) |
|
|
if (hasAlpha) |
|
|
{ |
|
|
{ |
|
|
// TODO: This can potentially run in an separate task.
|
|
|
// TODO: This can potentially run in an separate task.
|
|
|
alphaData = AlphaEncoder.EncodeAlpha(image, this.configuration, this.memoryAllocator); |
|
|
alphaData = AlphaEncoder.EncodeAlpha(image, this.configuration, this.memoryAllocator, this.alphaCompression); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Stats-collection loop.
|
|
|
// Stats-collection loop.
|
|
|
@ -363,7 +363,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy |
|
|
// Write bytes from the bitwriter buffer to the stream.
|
|
|
// Write bytes from the bitwriter buffer to the stream.
|
|
|
ImageMetadata metadata = image.Metadata; |
|
|
ImageMetadata metadata = image.Metadata; |
|
|
metadata.SyncProfiles(); |
|
|
metadata.SyncProfiles(); |
|
|
this.bitWriter.WriteEncodedImageToStream(stream, metadata.ExifProfile, metadata.XmpProfile, (uint)width, (uint)height, hasAlpha, alphaData); |
|
|
this.bitWriter.WriteEncodedImageToStream(stream, metadata.ExifProfile, metadata.XmpProfile, (uint)width, (uint)height, hasAlpha, alphaData, this.alphaCompression); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
/// <inheritdoc/>
|
|
|
|