feat: Optimize avatar size multiplier for 2 << n px avatars#7827
feat: Optimize avatar size multiplier for 2 << n px avatars#7827
2 << n px avatars#7827Conversation
|
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. DetailsHere, 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. :) |
We don't need to try the exact previous integer values, |
35930f3 to
abdfeb9
Compare
|
Regarding aliasing: An example of that, is visible in two of the example-images in your message: in the 256x256-image, in the second line of text from the bottom, the How noticeable the aliasing will be, can also change, depending on where one crops an image; even if it shows the same content.
I was arguing unnecessarily complicated there, by adding the part about the relation to the original resolution. ^^' The actual problem is, that the target-resolution varies strongly; and additionally, in a way that is not easy to understand for the people who set their avatar-images, so that they could not even work around that easily. When setting an avatar-image that happens to have a resolution of 960x960 (after cropping), the first target-resolution after 512x512 would then be 480x480 pixels; but if it had a resolution of 1030x1030 (after cropping), it would be 386x386 pixels, which is about ~35% lower in resolution. Footnotes
|
I agree that 320 px is probably worse because 341 px is quite bigger, but this PR tries 384 px first. Why assume that most images won't fit at 384 px? If it's really the case, we should consider multipliers closer to 1, but optimizing the algo so that it tries exactly 341 px doesn't make sense. Yes, some users will get slightly smaller avatars, but most users will gain.
If this happens for most avatars, it means that 512 px are too restrictive and we should increase the limit to 1024 px. But even if we remove this limit at all, w/o this PR, passing a bigger (less cropped) image doesn't mean getting a bigger image in result because it may stop fitting into 60 kB and we may need to repeat the downscaling step. But ok, as we still want to try 512 px (btw, i don't understand why, but i don't want to change the code too much) which doesn't care about aliasing (e.g. resizing from 520 to 512 px definitely adds aliasing), i'll remove the try to take into account the original resolution from the code. |
2312e40 to
463c78f
Compare
Me neither, but i just found a reason why the limit should have been increased to 640 in Core, instead of reducing it to 512 in the Android-app of Delta Chat. Making avatar-images have a high enough resolution to properly fill the largest size at which it will be used in a GUI, seems like a good reason to try resizing it to the limit first. |
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 do "smaller" downscaling steps and reduce aliasing effects. 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 increase aliasing effects on each step. Better limit the numerator to 5.
463c78f to
11a8cd0
Compare







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 do "smaller" downscaling steps and reduce aliasing effects.
Before, it was discussed that just 3/4 can be used. However, if we repeat the reduction step, we get
3 << nas a numerator and this way increase aliasing effects on each step. Better limit thenumerator to 5.