Skip to content

fix(gui): read webp render sizes for the side and main views - #2463

Merged
AprilNEA merged 1 commit into
masterfrom
fix/webp-render-dimensions
Nov 8, 2026
Merged

AprilNEA merged 1 commit into
masterfrom
fix/webp-render-dimensions

Conversation

@AprilNEA

@AprilNEA AprilNEA commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Summary

The asset resolver reads each render's pixel size from its file header, and the reader accepted only a PNG IHDR. The catalog also ships renders as WebP, so:

  • Side view. resolve_side_view keeps a candidate only when its size can be read. A WebP side render was dropped, and a variant with no side.png fallback got no side view at all, so its side buttons got no hotspots in the Buttons tab.
  • Main view. On the same error the main view took the metadata origin as its size and logged "could not read PNG dimensions". The origin is calibrated against the base model's renders, not the variant's, so the hotspots were scaled against the wrong size.

Checked against the catalog on 2026-11-08 (first 32 bytes of each file over HTTP Range): in g502x_plus, the ext2 device_side (images/device/1b909bb1-…) and device_image (images/device/3253a30b-…) both start RIFF....WEBPVP8X, with canvases of 1157×2800 and 1662×2800. The depot's metadata.json origins are 936×2700 (side) and 1391×2700 (front). The base and ext1 renders are PNG. is_drawable_image already accepts WebP (#2379); only the size check rejected these files.

Changes

  • openlogi-desktop
    • services/assets/images.rs: read_png_dimensions becomes read_image_dimensions. It reads the first 30 bytes and takes the size from a PNG IHDR, or from a WebP VP8X canvas, VP8 key-frame header or VP8L header. The leading bytes pick the format, because many catalog renders have bare UUID names with no extension. No decoder runs.
    • services/assets.rs: the side view, the main view and the standalone render all use it. The fallback warning now says "image dimensions".

Why not image::ImageReader::with_guessed_format()?.into_dimensions(): this crate declares image with only the png feature (gpui enables webp through feature unification), so it would need a Cargo.toml change. Its PNG decoder also checks the IHDR CRC, so every PNG would go through a stricter check than it does today. A header-only reader keeps the PNG behaviour exactly as it is.

The png_width / png_height field names on ResolvedAsset and SideView are now inaccurate. They are used in 53 places, so renaming them is left out of this fix.

Overlap with #2461: both PRs touch resolve_side_view. #2461 changes the variant lookup and the path join, and this PR changes the size check on the next line. Whichever PR merges second rebases; the conflict is one line. With both merged, the G502 X PLUS ext2 gets its WebP front and side views.

Testing

New regression tests in services::assets::tests. With the WebP branch disabled, the first and third fail, which is the behaviour on master:

  • render_sizes_are_read_from_png_and_webp_headers: PNG, VP8X (1157×2800, the ext2 side render), lossy VP8 with the scale bits set, and lossless VP8L.
  • a_render_without_a_readable_size_has_none: truncated PNG and WebP heads, a lossy frame without the start code, a lossless stream without its signature, an unknown first chunk, the G HUB encrypted blob, an empty file and a missing file.
  • a_webp_colour_variant_gets_both_views_at_their_own_size: a depot sized like the G502 X PLUS ext2, with WebP front and side renders, no side.png, and the catalog's smaller metadata origins. Both views resolve at the renders' own sizes. The variant is keyed on the registry model id with flat names, so the test does not depend on fix(assets): fetch and draw depot renders stored under sub-directories #2461.

Local gate (Linux; affected set is openlogi-desktop only, no Cargo.toml or lockfile change):

export RUSTFLAGS="-D warnings"
cargo fmt --all -- --check
typos --config .config/typos.toml .
ast-grep scan && ast-grep scan .github
cargo clippy -p openlogi-desktop --all-targets -- -D warnings
cargo test -p openlogi-desktop

Not run locally (left to CI): macOS and Windows clippy and tests, and MSRV. No cfg-gated code changed.

Not runtime-tested on hardware. To check (with #2461 also applied): connect a G502 X PLUS whose extended model id is 2 and start with an empty asset cache. The Buttons tab should show the ext2 render with its side view beside it, and the log should not say "could not read image dimensions".

Fixes #2460

The image-size reader accepted only a PNG IHDR, while the catalog also
ships renders as WebP. A WebP side render was dropped, so the variant
lost its side view and the side buttons their hotspots; a WebP main view
fell back to the metadata origin, which is the base model's size, and
scaled its hotspots wrong.

read_image_dimensions reads the size from the first 30 bytes of either
format: PNG from IHDR, WebP from the VP8X canvas or the VP8 / VP8L
bitstream header. No decoder runs.

Fixes #2460
@AprilNEA AprilNEA added type: bug Something is broken or behaves incorrectly area: gui Graphical user interface area: assets Icons, images, and bundled assets labels Nov 8, 2026
@greptile-apps

greptile-apps Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge.

Summary

Reads PNG and WebP dimensions from file headers for side, main, and standalone renders.

  • Device views use the actual sizes of PNG and WebP renders.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read up to 30 bytes] --> B{PNG or WebP size found?}
  B -->|Yes| C[Use file dimensions]
  B -->|No: side view| D[Try next side candidate]
  B -->|No: main view| E[Use metadata origin]
  B -->|No: standalone| F[Try next asset root]
Loading

Reviews (2) · Last reviewed commit: "fix(gui): read webp render sizes for the..." · Reviewed by Greptile

@AprilNEA
AprilNEA merged commit b50c24e into master Nov 8, 2026
33 checks passed
@AprilNEA
AprilNEA deleted the fix/webp-render-dimensions branch November 8, 2026 13:14
@aprilnea aprilnea Bot mentioned this pull request Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: assets Icons, images, and bundled assets area: gui Graphical user interface type: bug Something is broken or behaves incorrectly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebP side renders give no side view (G502 X PLUS ext2)

1 participant