-
Notifications
You must be signed in to change notification settings - Fork 297
Add ThumbHash support for image placeholders #3429
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
6
commits into
damus-io:master
Choose a base branch
from
alltheseas: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.
Open
+980
−46
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
Add ThumbHash library for compact image placeholders. ThumbHash offers advantages over BlurHash: - Better detail preservation - Embedded aspect ratio information - Alpha channel (transparency) support - More accurate color representation Source: https://github.com/evanw/thumbhash (MIT License) Closes damus-io#3427 Signed-off-by: alltheseas 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add thumbhash field to ImageMetadata struct - Update decode_image_metadata() to parse thumbhash from imeta tags - Update image_metadata_to_tag() to include thumbhash in output - Add process_thumbhash() to decode base64 thumbhash to UIImage - Add process_placeholder() helper that prefers thumbhash over blurhash - Update process_image_metadatas() to use process_placeholder() This enables displaying ThumbHash placeholders from other clients while maintaining backwards compatibility with BlurHash. Closes damus-io#3427 Signed-off-by: alltheseas 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add calculate_thumbhash() function for encoding UIImage to base64 hash - Update calculate_image_metadata() to use thumbhash parameter - Update PostView.handle_upload() to use calculate_thumbhash() Uploaded images now include thumbhash in their imeta tags, providing better quality placeholders for other clients. Closes damus-io#3427 Signed-off-by: alltheseas 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add ThumbHash.swift to the following targets: - damus - HighlighterActionExtension - ShareExtension Closes damus-io#3427 Signed-off-by: alltheseas 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add 5 unit tests for ThumbHash functionality: - testThumbHashEncodeDecodeRoundtrip - testThumbHashBase64Roundtrip - testImageMetadataWithThumbHash - testImageMetadataWithBothHashes - testImageMetadataToTagWithThumbHash - Fix ImageMetaProcessState type name (was ImageMetadataProcessState) Closes damus-io#3427 Signed-off-by: alltheseas 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Calculate both placeholder hashes concurrently during image upload: - thumbhash: better quality, aspect ratio, alpha (newer clients) - blurhash: backwards compatibility with existing Nostr clients Both hashes are computed in parallel with the upload, so there's minimal additional latency. The imeta tag now includes both: thumbhash <base64> blurhash <string> Closes damus-io#3427 Signed-off-by: alltheseas 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Collaborator
|
Even if thumbhash might be better in some ways, blurhash is more widely supported around Nostr protocols (https://github.com/search?q=repo%3Anostr-protocol%2Fnips+blurhash&type=code). I have not seen references to thumbhash in the Nostr protocol specs (https://github.com/search?q=repo%3Anostr-protocol%2Fnips+thumbhash&type=code). @alltheseas, do other Nostr clients support thumbhash? |
Collaborator
Author
|
Fevela, and nostria |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
media
pr-in-queue
This PR is waiting in a queue behind their other PRs marked with the label `pr-active-review`.
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
Add ThumbHash support for compact image placeholders. ThumbHash offers advantages over BlurHash:
Implementation:
Checklist
Standard PR Checklist
Closes:orFixes:tags in the commit messages wherever applicable, or made sure those are not needed. See Submitting patchesTest report
Device: iPhone 15 Pro Simulator
iOS: 17.5
Damus: master + this PR
Setup: Unit tests for encode/decode roundtrip
Steps:
xcodebuild test -only-testing:damusTests/ImageMetadataTestResults:
testThumbHashEncodeDecodeRoundtrip✅testThumbHashBase64Roundtrip✅testImageMetadataWithThumbHash✅testImageMetadataWithBothHashes✅testImageMetadataToTagWithThumbHash✅testImageMetadataToTagWithBothHashes✅testRemoveGPSData✅Other notes
Commits:
thumbhash: add ThumbHash implementation- MIT-licensed implementation from evanw/thumbhashthumbhash: add decoding support to ImageMetadata- Parse and decode thumbhash from imeta tagsthumbhash: use ThumbHash for encoding uploaded images- Encode with thumbhash on uploadthumbhash: add ThumbHash.swift to Xcode project- Add to damus, HighlighterActionExtension, ShareExtension targetsthumbhash: add unit tests and fix type name- 7 unit teststhumbhash: encode both thumbhash AND blurhash for compatibility- Backwards compat with existing clientsReferences: