-
-
Notifications
You must be signed in to change notification settings - Fork 887
Add support for encoding lossy webp images with alpha channels #1971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
{ | ||
int width = image.Width; | ||
int height = image.Height; | ||
IMemoryOwner<byte> alphaData = ExtractAlphaChannel(image, configuration, memoryAllocator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see where this is getting disposed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its done in the Dispose
of the Vp8Encoder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to keep the responsibility of disposing to the AlphaEncoder
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that's wise. Difficult to keep track of otherwise.
private readonly int[] scratch = new int[16]; | ||
private readonly bool alphaCompression; | ||
|
||
private readonly byte[] averageBytesPerMb = { 50, 24, 16, 9, 7, 5, 3, 2 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private readonly byte[] averageBytesPerMb = { 50, 24, 16, 9, 7, 5, 3, 2 }; | |
// This uses C#'s optimization to refer to the static data segment of the assembly, no allocation occurs. | |
private static ReadOnlySpan<byte> AverageBytesPerMb => new byte[] { 50, 24, 16, 9, 7, 5, 3, 2 }; |
While you're on it.
Need to update
int averageBytesPerMacroBlock = this.averageBytesPerMb[this.BaseQuant >> 4]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for pushing this through so quickly!
Prerequisites
Description
This PR adds support for encoding lossy webp images with alpha channels.
The alpha data can be either compressed (with webp lossless compression) or uncompressed.
Related to #1802