Skip to content

feat: add SVGA 1.x (ZIP/JSON) format support - #1994

Open
yancongya wants to merge 2 commits into
QL-Win:masterfrom
yancongya:master
Open

feat: add SVGA 1.x (ZIP/JSON) format support#1994
yancongya wants to merge 2 commits into
QL-Win:masterfrom
yancongya:master

Conversation

@yancongya

@yancongya yancongya commented Aug 28, 2026

Copy link
Copy Markdown

Summary

This PR adds support for SVGA 1.x format (ZIP/JSON) to the built-in SVGA viewer.

Problem

  • SVGA 1.x files (ZIP archive containing JSON) were showing blank preview
  • Only SVGA 2.x format (zlib compressed protobuf) was supported
  • Users with older SVGA files could not preview them

Changes

Backend (SvgaPlayer.Data.cs):

  • Add IsZipArchive() method to detect ZIP format by file header (PK)
  • Add ExtractFromZip() method to extract movie.spec from ZIP archive
  • Add InitMovieEntityFromJson() method to parse SVGA 1.x JSON format
  • Modify InflateSvgaFile() to support both formats automatically

Frontend (svga2html.html):

  • Add jszip.min.js and jszip-utils.min.js libraries
  • Update script loading order to ensure JSZip is available for SVGAPlayer-Web

Testing

Verified with test files:

  • matteBitmap_1.x.svga (SVGA 1.x ZIP/JSON) - 400x400, 30 frames
  • TwitterHeart.svga (SVGA 2.x zlib/protobuf) - 100x100, 116 frames
  • rose.svga (SVGA 2.x zlib/protobuf) - 750x750, 60 frames

Workaround 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:

  • Add support for previewing SVGA 1.x ZIP archives containing JSON animation data alongside existing SVGA 2.x files.

Bug Fixes:

  • Fix blank previews for SVGA 1.x files.

Enhancements:

  • Automatically detect SVGA format and initialize animation metadata from either JSON or protobuf data.
  • Bundle the JSZip libraries required by the web-based SVGA player.

- 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)
@sourcery-ai

sourcery-ai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Reviewer's Guide

The 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 loading

flowchart 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
Loading

File-Level Changes

Change Details Files
Add automatic SVGA format detection and decoding for ZIP/JSON and zlib/protobuf inputs.
  • Detect ZIP archives from the PK signature while preserving stream position.
  • Extract movie.spec or a fallback .spec entry from the archive.
  • Retain the existing zlib/protobuf decompression path for SVGA 2.x files.
  • Track the decoded representation so initialization dispatches to JSON or protobuf parsing.
QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Webview/Svga/SvgaPlayer.Data.cs
Parse SVGA 1.x JSON metadata into the player’s existing movie state model.
  • Read dimensions, frame count, FPS, and sprite count from the JSON document.
  • Populate MovieParams and initialize an empty SpriteEntity collection for compatibility with the current rendering pipeline.
QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Webview/Svga/SvgaPlayer.Data.cs
Bundle JSZip dependencies required by the web SVGA player for legacy asset loading.
  • Load JSZip and JSZip utilities before the SVGA player script.
  • Add the minified dependency assets to the embedded web resources.
QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Resources/Web/svga2html.html
QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Resources/Web/svgaplayerweb/jszip.min.js
QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Resources/Web/svgaplayerweb/jszip-utils.min.js

Assessment against linked issues

Issue Objective Addressed Explanation
#1991 Add the SvgaViewer v1.0.0 plugin entry, including its repository, release link, date, and description, to the Available Plugins wiki page. The PR adds SVGA 1.x support to the built-in ImageViewer and includes a workaround link to the standalone plugin, but it does not modify or document the Available Plugins wiki entry for SvgaViewer.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Webview/Svga/SvgaPlayer.Data.cs Outdated
- Add IsJsonPayload() method to skip BOM (EF BB BF) and whitespace
- Fixes issue where SVGA 1.x files with BOM were misclassified as protobuf

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add SvgaViewer plugin to Available Plugins list

1 participant