-
-
Notifications
You must be signed in to change notification settings - Fork 702
Add new operation alpha_resize meant for downsampling images with alpha #1675
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
Conversation
…ha. New tests in test_resample demonstrate cases that it doesn't add artifacts added by the existing premultiply/resize/unpremultiply procedure.
Yes, this branch was based on master and when resizing the two test images added here (logo2.png and logo3.png) I see artifacts are added - unless I'm missing something of course :) |
p.s. I did notice the fix for upsizing, here I'm talking about downsizing |
Could you explain the motivation here? What are the artifacts, what causes them, how this patch fixes it, etc. Do you have a link with some background? |
So the story is, in Wix we get some users' images that are actually logos in PNG format with an alpha channel. Specifically on some images we see some artifacts, I guess I could describe them as "jagged stripes". Here are two examples: https://storage.googleapis.com/tempvid/alpha-resize/alpha-resize2a.html On the left side you see the results of the existing implementation, on the right side you see the new implementation. You'll probably have to zoom to about 250% in your browser to really see that, my html skills are not good enough to make the page do that on its own :) I tried the same resizes in ImageMagick and saw that there these artifacts didn't show, so I followed the ImageMagick implementation and adapted it as best I could to libvips. This is the image Magick code I followed: https://github.com/ImageMagick/ImageMagick/blob/8a36f4e4187f3ccf44e839923f3c9544afb548b4/MagickCore/resize.c What causes the artifact - somehow (not sure exactly) premultiply and unpremultiply. I suspect some information is lost in those steps. The new implementation blends the alpha as part of the resize process which seems to help. Feel free to treat the new implementation as a kind of reference, it really probably shouldn't be a separate operation at the end of the day. |
I think the difference is that |
Also note that in the test pages I sent, in the left column, when I did resize I also did premultiply before and unpremultiply after. These files were generated by this test code: |
We were clipping alpha very aggressively. With over- and under-shoot ringing on edges, this could introduce extra fringes. see #1675
I think I might have fixed it in git master, would you have time to test? |
Absolutely, thanks! |
Looks good to me |
Ah fantastic, thanks for testing, and thanks for pointing out this dumbness. This will be in 8.10. The revised unpremultiply is even slightly quicker. |
Thanks a million! |
Hello, I've had to revise this code again :( I hope I've not broken your case. Would you have time to quickly double-check this? It's this branch: https://github.com/libvips/libvips/tree/revise-premultiply There's a test for this this too, so hopefully it won't break again. |
Add new operation alpha_resize meant for downsampling images with alpha. New tests in test_resample demonstrate cases that it doesn't add artifacts added by the existing premultiply/resize/unpremultiply procedure.