[PR #7856] HUD: decode WebP and JPEG beside PNG #7863

Open
opened 2026-11-03 07:25:41 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7856
Author: @itarqos5
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: feat/image-decoders


📝 Commits (1)

  • 9cb1c15 feat(hud): decode WebP and JPEG images beside PNG

📊 Changes

3 files changed (+4075 additions, -3924 deletions)

View changed files

📝 Cargo.lock (+39 -0)
📝 crates/horizon-client-render/Cargo.toml (+4 -0)
📝 crates/horizon-client-render/src/hud.rs (+4032 -3924)

📄 Description

🤖 Opened by itarqos5's AI agent (Claude Opus 5), not by itarqos5 personally.

crate::hud::decode_bytes read PNG only, so anything else silently failed. That is fine for the game's own resources, which are PNG throughout, but not for images fetched over the network: Modrinth serves a large share of project icons as WebP, and those simply did not appear.

How the format is chosen

By the leading bytes, not by a file name — a name is not always present and would not be trustworthy anyway:

Format Signature
PNG 89 50 4E 47 0D 0A 1A 0A
WebP RIFF and WEBP at byte 8
JPEG FF D8

Checking the tag at byte 8 matters: WAV is also a RIFF container, and the test covers that case. Anything unrecognised falls through to the PNG reader unchanged, so its error is still the one reported.

Dependencies

Two small pure-Rust decoders rather than the whole image stack:

  • image-webp (default features off)
  • zune-jpeg (default features off, std)

Both MIT/Apache-2.0, consistent with this repository's MIT licence. WebP animations give their first frame, as an animated PNG already does via first_frame. JPEG has no alpha so every pixel is opaque, and greyscale JPEGs expand to RGBA like colour ones.

Checks

  • cargo test -p horizon-client-render --lib -- hud::tests — 45 passed, 0 failed on this branch off a clean origin/main, including the new image_formats_are_told_apart_by_their_leading_bytes
  • Not a full tools/pr_ready.py run; the vanilla harnesses were not run here. Cargo.lock changes alongside Cargo.toml, as the self-check expects.

This is useful on its own, and is also what makes icons appear in the resource pack browser in a follow-up.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/7856 **Author:** [@itarqos5](https://github.com/itarqos5) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/image-decoders` --- ### 📝 Commits (1) - [`9cb1c15`](https://github.com/horizon-rust/horizon/commit/9cb1c15761cf5da3309e1e93610932bf0dc33b1c) feat(hud): decode WebP and JPEG images beside PNG ### 📊 Changes **3 files changed** (+4075 additions, -3924 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+39 -0) 📝 `crates/horizon-client-render/Cargo.toml` (+4 -0) 📝 `crates/horizon-client-render/src/hud.rs` (+4032 -3924) </details> ### 📄 Description > 🤖 Opened by itarqos5's AI agent (Claude Opus 5), not by itarqos5 personally. `crate::hud::decode_bytes` read PNG only, so anything else silently failed. That is fine for the game's own resources, which are PNG throughout, but not for images fetched over the network: Modrinth serves a large share of project icons as WebP, and those simply did not appear. ## How the format is chosen By the leading bytes, not by a file name — a name is not always present and would not be trustworthy anyway: | Format | Signature | |---|---| | PNG | `89 50 4E 47 0D 0A 1A 0A` | | WebP | `RIFF` **and** `WEBP` at byte 8 | | JPEG | `FF D8` | Checking the tag at byte 8 matters: WAV is also a RIFF container, and the test covers that case. Anything unrecognised falls through to the PNG reader unchanged, so its error is still the one reported. ## Dependencies Two small pure-Rust decoders rather than the whole `image` stack: - `image-webp` (default features off) - `zune-jpeg` (default features off, `std`) Both MIT/Apache-2.0, consistent with this repository's MIT licence. WebP animations give their first frame, as an animated PNG already does via `first_frame`. JPEG has no alpha so every pixel is opaque, and greyscale JPEGs expand to RGBA like colour ones. ## Checks - `cargo test -p horizon-client-render --lib -- hud::tests` — **45 passed, 0 failed** on this branch off a clean `origin/main`, including the new `image_formats_are_told_apart_by_their_leading_bytes` - Not a full `tools/pr_ready.py` run; the vanilla harnesses were not run here. `Cargo.lock` changes alongside `Cargo.toml`, as the self-check expects. This is useful on its own, and is also what makes icons appear in the resource pack browser in a follow-up. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#7863
No description provided.