-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
inconsistent resize behaviour re. premultiplication #1629
Comments
Hi @jaubourg, You're right, there's a bug here, or an inconsistency anyway. As a workaround, you can just remove the premultiply/unpremultiply for upsizing. For 8.10, we need to make Thanks for reporting this dumbness! |
Python test program: #!/usr/bin/python3
import sys
import pyvips
image = pyvips.Image.new_from_file(sys.argv[1])
#image = image.premultiply()
image = image.resize(1.5)
#image = image.unpremultiply()
image = image.flatten(background=255)
image.write_to_file(sys.argv[2]) |
Ideal solution would be to have a premultiplied flag in the options for resize like we have for embed. I admit I kinda micro-manage the orders I do premultiplications, color transformations and re-orientation of images to gain a little speed here and there. |
The question becomes : should resize assume premultiplied or not premultiplied by default ;) |
vips_resize() uses vips_affine() for upsizing and vips_reduce() for downsizing. Affine automaticaly does a vips_premultiply() for images with an alpha channel, but reduce does not. This meant that we could sometimes premultiply twice. This patch adds a "premultiplied" flag for affine which turns automatic premultiuplication off, vips_resize() uses this to block affine's auto premul feature, and the resize docs are clarified to stress that the operation does not do premultiplication for you. See #1629
OK, I think this is fixed. I've revised the docs to stress that you need to premultiply before resize if the image has an alpha (thumbnail has always done this). Affine has a new flag to disable auto premultiplication. |
(and thanks again for the report!) |
Well, thank you for the fix! :) Looks perfect. Which version will it be in (looks like kinda of a breaking change)? |
It's in git master, so it'll be part of 8.10, due in a few months. |
I'm using libvips 8.9.1 and I've reduced my case to the following snippet:
This works splendidly with a png32 but there are artefacts appearing at opacity edges with a png8 image (see images attached at the end of this post).
flatten()
is only used to clearly and visually exhibit the issue (artefacts appear on a transparent output all the same).From what I can gather:
colourspace()
is not to be blamed (the same artefacts appear without it).premultiply()
andunpremultiply()
removes the issueI honestly have no clue what the problem can be. Am I supposed not to premultiply for upscaling?
PNG 8 INPUT
PNG 8 OUTPUT
The text was updated successfully, but these errors were encountered: