-
Notifications
You must be signed in to change notification settings - Fork 48
feat: add thumbhash support for image placeholders #1220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alltheseas
wants to merge
5
commits into
damus-io:master
Choose a base branch
from
alltheseas:feat/thumbhash-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
The hyper-rustls crate requires explicit features for webpki-roots fallback. This also refactors http_req() to improve type inference with hyper 1.x's async body handling: - Add webpki-roots and ring features to hyper-rustls - Import Incoming and Response types explicitly - Refactor redirect loop to extract content_type and body together - Add explicit type annotations for HeaderValue closures - Use nevernesting pattern (early return for non-redirect case) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: alltheseas
Thumbhash is a more modern alternative to blurhash that provides: - Better quality at similar hash sizes - Embedded aspect ratio information - Alpha channel support Adding to workspace and notedeck/notedeck_columns crates for upcoming encoding and decoding support. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: alltheseas
Introduces thumbhash as an alternative to blurhash for image placeholders. Thumbhash provides better quality at similar sizes and includes embedded aspect ratio information. Data structures: - Add PlaceholderHash enum with ThumbHash(Vec<u8>) and BlurHash(String) - Update ImageMetadata to use PlaceholderHash instead of blurhash string - Add ObfuscationType::ThumbHash variant (preferred over Blurhash) - Add MediaJobKind::ThumbHash and MediaJobResult::ThumbHash Decoding: - Add generate_thumbhash_texturehandle() for decoding thumbhash to texture - Update BlurCache::get_or_request() to dispatch based on hash type - Separate request_thumbhash_job() and request_blurhash_job() helpers Parsing: - Rename update_imeta_blurhashes -> update_imeta_placeholders - Parse both "thumbhash" and "blurhash" fields from imeta tags - Prefer thumbhash when both are available 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: alltheseas
Generates both thumbhash and blurhash client-side when uploading images for maximum compatibility with other Nostr clients. Not all clients support thumbhash yet, so blurhash provides a fallback. Encoding: - generate_thumbhash(): Create base64-encoded thumbhash from image bytes - generate_blurhash(): Create blurhash string with 4x3 components - generate_placeholder_hashes(): Generate both hashes at once Upload flow: - Generate hashes before sending to NIP-96 server - Merge with server-provided hashes (prefer server values if available) - Include both in Nip94Event response NIP-94 event: - Add thumbhash field to Nip94Event struct - Parse thumbhash from server response tags - Include both hashes in imeta tags when posting 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: alltheseas
Add comprehensive tests to verify: blur.rs (decoding tests): - test_thumbhash_decode: Verifies thumbhash binary decoding produces valid RGBA pixel data with correct dimensions - test_blurhash_decode: Verifies blurhash string decoding produces valid RGBA data at specified dimensions - test_placeholder_hash_variants: Ensures PlaceholderHash enum correctly stores both ThumbHash and BlurHash variants - test_image_metadata_construction: Validates ImageMetadata struct construction with different hash types and optional dimensions media_upload.rs (encoding tests): - test_generate_thumbhash: Verifies thumbhash encoding produces valid base64 output that can be decoded - test_generate_blurhash: Verifies blurhash encoding produces valid output that can be decoded - test_generate_placeholder_hashes: Ensures both hashes are generated together for maximum compatibility - test_invalid_image_returns_none: Confirms graceful handling of invalid/corrupt image data (returns None instead of panicking) These tests ensure the encoding/decoding roundtrip works correctly for both placeholder formats, supporting the transition period where not all Nostr apps support thumbhash. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: alltheseas Closes: damus-io#1218
467f15d to
92fbffa
Compare
Contributor
Author
|
there seems to be some windows CI failure, which I don't think is related to thumbhash PR |
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
Changes
Dependencies: Add
thumbhashcrate (v0.1.0)Data structures:
PlaceholderHashenum withThumbHash(Vec<u8>)andBlurHash(String)variantsImageMetadataandObfuscationTypeto support both hash typesDecoding:
MediaJobKind::ThumbHashfor async decodingEncoding:
generate_thumbhash()andgenerate_blurhash()functionsTests: Unit tests for encoding/decoding roundtrip
Test plan
cargo testpassesCloses #1218
🤖 Generated with Claude Code