-
-
Notifications
You must be signed in to change notification settings - Fork 99
fix: Change thumbnail
-function to resize
-function
#6815
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
fix: Change thumbnail
-function to resize
-function
#6815
Conversation
to reduce visual artifacts in resized images.
thanks a lot! this is a very welcome and on point PR! we're getting somewhere and have options now :) what needs to be considered is that the chosen algorithm is 10 times slower, according to https://docs.rs/image/latest/image/imageops/enum.FilterType.html a typical photo of nowadays cams takes 414 ms instead of 31 ms - with an impressive improvement in quality on that page otoh, not sure, what what's pretty nice is that we get the improvement in quality probably by not really larger image sizes. this is welcome esp. for avatars, where we just these days are improving things, #6611 - i can imaging better interpolation will result in another boost
as we're supporting also very old phones (which, however, usually have less MP), i am wondering, if |
The 31ms are for Nearest Neighbor, which is faster because it does not interpolate much; it is not useful for downscaling photos. Linear interpolation is a very basic type of image-interpolation for resizing. According to the documentation, The file-sizes can actually be smaller with the Triangle-interpolation, because the visual artifacts that the |
Just to clarify, EDIT: Image scaling using EDIT: For avatars it was introduced in a5f949c. EDIT: I tried this on my Desktop and let now = std::time::Instant::now();
let new_img = if crate::tools::time() % 60 < 30 {
info!(context, "thumbnail()...");
img.thumbnail(img_wh, img_wh)
} else {
info!(context, "resize()...");
img.resize(img_wh, img_wh, image::imageops::FilterType::Triangle)
};
info!(context, "time: {}", (std::time::Instant::now() - now).as_nanos()); |
thanks a lot for explanations, @iequidoo - and for the snippet i tried on some real devices, see here for details. the summary: i can confirm that things are about 4 times slower. on many devices, the additional slowness is significant - on a modern iPhone it is 1 second instead of 0.3 seconds, on an older android7, it is 5 seconds instead of 1.5 seconds - both using the camera image as is. note, that the given android device is by far not the oldest one we're supporting and caring for and that even newer budget phones are quite slow. we're often praised for good support of old hardware, this PR would make things worse for few benefit the slowness is esp. worse as the image appears in the chat only after it is recoded, so it is also bad UX as for seconds the image is lost (sure, that part can be improved, but that is another effort). using this PR we would introduce waiting times for lots of devices that have instant photo sending up to now so, really not sure, if the slight improvements in quality are worth the slowness. we are also usually hesitant to user options, unless there is some large impact and need, i do not see this in this case as well. also, the differnence is too small and it will cost resources in support, follow up, whatnot. but, we can consider using conditional compiling so that desktop is using resize - while android stays with thumbnail. or can we even estimate the speed of the processor somehow? all in all, -1 for changing unconditonally - |
We can add a config option, w/o UI for it, at least on Desktop it's easy to set via environment, then advanced users can experiment. |
I don't think there may be user-friendly wizard-like solutions, moreover they need some UI code, rather there should be a good default with a capability to change encoding. Alternatively, we can start with The good thing is that with |
okay, thanks all for figuring out some facts! to sum up:
i had some internal discussion with other devs meanwhile. weighted all points, it is clear that that this PR is not a good tradeoff. for more or less complex ideas mentioned above - we currently do not want that to consume more time and resources; it prevents us from doing more impactful things. we might come back to some of the ideas at some point - and also, the PR was not wasted - if point 3. would not be there, it could have been an easy change :) it is known and accepted that the scaled down image is lossy and not perfect. we buy speed with that. if one really needs to transfer an image as close as possible, one should attach it as "File". @MoonlightWave-12 i feel a bit bad to be - again - the guy with the bad news, saying what we cannot do atm. still, i need to have the full picture in mind. in general, it is more helpful to contribute on things that actually need to be done, picking issues from the issue tracker eg. |
this PR scaled avatars using the Triangle-filter, resulting in often better image quality and smaller files (5%). it comes at high costs, therefore, we do not do that unconditionally for each image sent, see comment in the code and #6815
i created a PR that picks up this discussion to improve avatars, #6822 |
I see. Well, at least the avatars will look better. :) |
this PR scaled avatars using the Triangle-filter, resulting in often better image quality and smaller files (5%). it comes at high costs, therefore, we do not do that unconditionally for each image sent, see comment in the code and #6815 --------- Co-authored-by: iequidoo <117991069+iequidoo@users.noreply.github.com>
to reduce visual artifacts in resized images.
The
thumbnail
-function was designed to be fast instead of accurate:For resizing images, the
resize
-function is more appropriate.I chose the
Triangle
-interpolation (linear interpolation) because it does not add more visual artifacts.Gaussian
seems to blur the image slightly,Lanczos3
andCatmullRom
can add halos near edges.Improves: deltachat/deltachat-desktop#5018 (comment)