Support loading animations with BOM - #2167
Merged
Merged
Conversation
mattleibow
commented
Jul 14, 2022
| throw new ArgumentNullException (nameof (stream)); | ||
| if (stream.CanSeek) { | ||
| return Create (stream, stream.Length); | ||
| return Create (stream, stream.Length - stream.Position); |
Contributor
Author
There was a problem hiding this comment.
This was a bug I found when you pass a stream that was not at 0. This can be used to create a data object from a section of a stream.
Comment on lines
+22
to
+29
| if (len >= 2 && buffer[0] == 0xfe && buffer[1] == 0xff) | ||
| return 2; | ||
| else if (len >= 3 && buffer[0] == 0xef && buffer[1] == 0xbb && buffer[2] == 0xbf) | ||
| return 3; | ||
| else if (len >= 3 && buffer[0] == 0x2b && buffer[1] == 0x2f && buffer[2] == 0x76) | ||
| return 3; | ||
| else if (len >= 4 && buffer[0] == 0 && buffer[1] == 0 && buffer[2] == 0xfe && buffer[3] == 0xff) | ||
| return 4; |
Contributor
Author
There was a problem hiding this comment.
BOM detection. Right now just the basic UTF-7/8/16/32
Comment on lines
-59
to
+64
| animation = GetObject (SkottieApi.skottie_animation_make_from_stream (stream.Handle)); | ||
| return animation != null; | ||
| using var data = SKData.Create (stream); | ||
| return TryCreate (data, out animation); |
Contributor
Author
There was a problem hiding this comment.
All animations are now created through the SKData overload, which we then use to detect the BOM.
We could use the stream, but then we have to use buffering and all other manner of complex mechanisms. This way we load the full data, and then optionally skip 4 bytes before passing it to C++.
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.
Description of Change
The JSON parser inside skia does not support BOMs, so we have to do it.
Bugs Fixed
API Changes
None.
Behavioral Changes
None.
Required skia PR
None.
PR Checklist