Open
Conversation
This is a little more flexible as you can slice the Span and easily decode multiple images from the same underlying byte[]. By using a byte[] parameter you force users to ensure the image they want to decode is available at offset '0' in the array. Additionally, by exposing QoiImage using ReadOnlyMemory<byte> it becomes immutable. The only gotcha is that implicit casting to ReadOnlyMemory<byte> can introduce subtle bugs where the user creates a QoiImage from a byte[], then reuses the byte[] for something else, which then corrupts the QoiImage.
Also fix an unsafe mutable public byte[]. Users can write arbitrary bytes to this which will corrupt the encoder for everyone in that process.
Simplifies things
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This builds on top of the previous PRs to leverage the benefits of Span in the encoding process.
Before these changes:
NOTE: I did tweak the
Encodemethod to take a pre-allocated buffer, just like the optimised method does. This means the destination byte[] is allocated once and both optimised/unoptimised methods encode to the same buffer repeatedly. The memory stats would be significantly worse otherwise.With the optimisations:
Encoding is a zero-allocation operation now (as long as you use a pre-allocated buffer). It's also a fair bit faster.