-
-
Notifications
You must be signed in to change notification settings - Fork 120
feat: Optimize avatar size multiplier for 2 << n px avatars
#7827
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
base: main
Are you sure you want to change the base?
Conversation
Instead of 2/3 which is not optimal for 512 px avatars usually passed to Core, use the sequence 3/4, 5/8, 4/8, 3/8... to reduce aliasing effects. Also divide the original avatar size, not the Core constant (which is 512 px currently), this makes sense if e.g. 640 px avatars are passed. Before, it was discussed that just 3/4 can be used. However: - If we repeat the reduction step, we get `3 << n` as a numerator and this way accumulate aliasing effects. Better limit it to 5. - If a 640 px avatar is passed, giving that `BALANCED_AVATAR_SIZE` is 512, 3/4 gives 384 i.e. 3/5 of 640 which is good but still worse than 3/4.
|
Note: The Android-app of Delta Chat does now use 512 * 512 for avatar-images. The resampling ("resizing") is done from the original image, on each iteration, so aliasing-effects do not accumulate (here, Lines 450 to 454 in 5028842
The encoded images are then made from the image resized from the original ( Lines 456 to 462 in 5028842
Lines 664 to 684 in 5028842
A previously encoded image ( Lines 644 to 662 in 5028842
|
Ok, "accumulate" is probably a bad wording. I meant that if we need to resize a 512 px avatar, using e.g. 27/64 as a multiplier is worse than 1/2 or 3/8 in terms of aliasing effects. So the PR limits the numerator to 5. |
|
If i understand correctly, these would be the resolution-values used for resampling, if the file-size is too large at 512x512 (until the target-resolution is below 200 pixels in the first table, and 128 pixels in the second table; rounded down after every step; only resolutions below 512x512):
I see two issues with this change:
Other than that, it would be a nice improvement in quality. A simpler change, that would almost always improve quality, compared to using I hope this is useful. :) |
Instead of 2/3 which is not optimal for 512 px avatars usually passed to Core, use the sequence 3/4,
5/8, 4/8, 3/8... to reduce aliasing effects. Also divide the original avatar size, not the Core
constant (which is 512 px currently), this makes sense if e.g. 640 px avatars are passed.
Before, it was discussed that just 3/4 can be used. However:
3 << nas a numerator and this way accumulate aliasingeffects. Better limit it to 5.
BALANCED_AVATAR_SIZEis 512, 3/4 gives 384 i.e. 3/5 of640 which is good but still worse than 3/4.
No test yet, but can add if the approach is agreed.