Antialiasing not working correctly
Opened this issue ยท 7 comments
Hi Artem, I've noticed that the current implementation of the antialiasing doesn't work correctly. I've made a comparison of a thumbnail antialiased by swayimg against imagemagick's cubic filter and there is a massive difference.
I have set my thumbnails to a 300 x 300 pixel size so I ran this command on the images with imagemagick:
magick image_file.jpg -resize 300x300^ -filter cubic -gravity center -extent 300x300 image_file.png
Please check the top row images and compare the left image (swayimg scaling) with the right image (imagemagick scaling). The jagermeister image is inverted, the right image is swayimg's scaling and the left one is imagemagick's scaling.
I think the scaling/antialiasing can be further improved, as it is right now, it is as if nothing is being done to antialias the images. I guess this applies to both viewer and gallery mode although it is more noticeable when viweing the small thumbnails.
Here are the images I used for the screenshot above:
https://drive.google.com/drive/folders/1uBYhZc1STvh3qZPcyRWNxExgPBrLkpB2?usp=sharing
Yes, unfortunately the current implementation of antialiasing only works well for zooming.
To be honest, I'm afraid to change it because it's not very simple and I've already forgotten what I wrote there =)
I found this website from the creator of the Magic Kernel which is supposedly what facebook and instagram use to scale their images... It even has a 2021 Reference ANSI C implementation of the Magic Kernel Sharp (MIT-0 License).
https://johncostella.com/magic/
https://johncostella.com/magic/magic-kernel-sharp.tar.gz
Maybe it is worth having a look, I really have no idea how hard it could be to implement it in swayimg
Thank you!
Looks interesting but it will take a lot of time to study this code.
Image transformation is math, but I'm more of an engineer than a mathematician =)
Hello Artem! Sorry for bothering you again. I had the chance to check the antialiasing today and unfortunately I did not notice any improvement, just the jagged edges shifting in place. I've made a comparison between feh's antialiasing and swayimg's and there is a vast difference:
As a matter of fact it is impossible to distinguish when antialiasing is enabled in swayimg since it doesn't really change that much.
FYI, I've started work on antialiasing; I did quite a bit of research into MKS and its ANSI C reference code, plus the Rust implementation referenced from its website. I plan to implement MKS for swayimg (and maybe take another look at the bicubic scaling); this is the reason I've recently started opening issues and pull requests.
FYI, I've started work on antialiasing; I did quite a bit of research into MKS and its ANSI C reference code, plus the Rust implementation referenced from its website. I plan to implement MKS for swayimg (and maybe take another look at the bicubic scaling); this is the reason I've recently started opening issues and pull requests.
That's great news!