-
-
Notifications
You must be signed in to change notification settings - Fork 646
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
Quality handling in WebP near-lossless (and arguably lossless) mode is incorrect #3881
Comments
I'm happy to do a PR to fix this, but before doing so, I'd like to hear some thoughts on how to solve this from an API level, whether you have any backwards compatibility concerns, etc. |
Only half related to this issue - and I stumbled over the same thing in the past, so I fully agree it would be awesome to have those options - I don't think |
Hi @geomaster, I agree the libvips webp API needs fixing. I think we should design a new API that reflects webp best practice and has options that match The constraint is that we can't change the meaning of existing We can tag the existing arguments as At a pinch we could tag the whole of |
Bug report
Describe the bug
In
webpsave.c
:i.e.,
near_lossless
is a boolean flag in libvips, but an integer flag inlibwebp
:libivps uses the quality (Q) value to double as the value for
near_lossless
. However, this has an unfortunate side effect, due to the overloaded meaning for Q in lossless mode:This means that in lossless mode, the quality factor actually means an additional type of "effort". This is OK for the libvips user (even if terribly unintuitive), because we can always pass a
quality
of 100 in lossless mode to get the best encode.But in near-lossless mode, we cannot do so, as the near-lossless parameter value and the quality we pass share the same value, see the code snippet above. That means we can never get the "absolute best" of near-lossless mode, which is
-near_lossless 0 -quality 100
.One would think this is not a big deal, but unfortunately I've noticed considerable file size differences between
-q 0
and-q 100
in lossless mode, on the order of 10-20% bigger files for-q 0
. This means that, for example,-q 50 -near_lossless 50
can be worse than-q 100 -near_lossless 0
.And, it's really unclear how this quality interacts with the "effort" that libvips passes as
webp->method
, and it should probably be at least documented to affect the file size in lossless mode, because the "quality" association is not very clear IMO.To Reproduce
Steps to reproduce the behavior:
VImage
with libvips, any logo-like graphic with gradients @ ~600x300px should doVImage::webpsave()
withnear_lossless = true
,q = 100
VImage::webpsave()
withnear_lossless = true
,q = 0
cwebp -lossless -q 100 -near_lossless 0
Expected behavior
Expected to be able to get outputs similar to the
cwebp
one usinglibvips
.near_lossless
is actually disabled and the results are the same as withoutnear_lossless
near_lossless
preprocessing is the most aggressive (at 0)Screenshots
If applicable, add screenshots to help explain your problem.
The text was updated successfully, but these errors were encountered: