feat: add SVGA 1.x (ZIP/JSON) format support - #1994
Open
yancongya wants to merge 2 commits into
Open
Conversation
- Add ZIP archive detection and extraction in SvgaPlayer.Data.cs - Add JSON parsing for SVGA 1.x movie.spec format - Add JSZip libraries for frontend SVGA 1.x support - Update svga2html.html to load JSZip before SVGAPlayer-Web Fixes: SVGA 1.x files showing blank preview (only 2.x was supported)
Reviewer's GuideThe viewer now detects SVGA 1.x ZIP/JSON files, extracts and parses their metadata, while preserving SVGA 2.x zlib/protobuf handling; the embedded web page also bundles and loads JSZip dependencies before SVGAPlayer-Web. Flow diagram for dual-format SVGA loadingflowchart TD
A[SVGA file] --> B{IsZipArchive}
B -->|ZIP header PK| C[ExtractFromZip]
C --> D[JSON movie.spec]
D --> E[InitMovieEntityFromJson]
B -->|Not ZIP| F[DeflateStream zlib decompression]
F --> G[Protobuf bytes]
G --> H[MovieEntity.Parser.ParseFrom]
E --> I[Movie metadata and sprites]
H --> I
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Webview/Svga/SvgaPlayer.Data.cs" line_range="180" />
<code_context>
+ var data = memoryStream.ToArray();
+
+ // Check if it's JSON (starts with '{') or protobuf
+ bool isJson = data.Length > 0 && data[0] == '{';
+ return (data, isJson);
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** Valid SVGA 1.x JSON containing leading whitespace or a UTF-8 BOM is classified as protobuf because the format check examines only `data[0]` for `{`; `InitMovieEntity` then passes the JSON bytes to `MovieEntity.Parser.ParseFrom`, which throws instead of parsing the animation.
**Triggers:** When `movie.spec` is encoded with a BOM or begins with JSON whitespace.
**Suggested fix:** Decode the data and parse it as JSON, or skip a BOM and leading whitespace before deciding whether the payload is JSON.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Webview/Svga/SvgaPlayer.Data.cs:180
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- Add IsJsonPayload() method to skip BOM (EF BB BF) and whitespace - Fixes issue where SVGA 1.x files with BOM were misclassified as protobuf
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.
Summary
This PR adds support for SVGA 1.x format (ZIP/JSON) to the built-in SVGA viewer.
Problem
Changes
Backend (
SvgaPlayer.Data.cs):IsZipArchive()method to detect ZIP format by file header (PK)ExtractFromZip()method to extractmovie.specfrom ZIP archiveInitMovieEntityFromJson()method to parse SVGA 1.x JSON formatInflateSvgaFile()to support both formats automaticallyFrontend (
svga2html.html):jszip.min.jsandjszip-utils.min.jslibrariesTesting
Verified with test files:
matteBitmap_1.x.svga(SVGA 1.x ZIP/JSON) - 400x400, 30 framesTwitterHeart.svga(SVGA 2.x zlib/protobuf) - 100x100, 116 framesrose.svga(SVGA 2.x zlib/protobuf) - 750x750, 60 framesWorkaround for Old Versions
For users on older QuickLook versions who need SVGA 1.x support immediately:
Related Issues
Summary by Sourcery
Support both SVGA 1.x ZIP/JSON and SVGA 2.x compressed protobuf animations in the built-in viewer.
New Features:
Bug Fixes:
Enhancements: