-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Support alternative color quantization algorithms #17270
base: master
Are you sure you want to change the base?
Conversation
As is, ext/gd only supports the default color quantization algorithm, which is used for `imagetruecolortopalette()`. However, libgd supports alternative algorithms as of GD 2.1.0, namely NeuQuant (which is built in) and libimagequant (which is used by pngquant). We add support for these alternative color quantization algorithms as small wrappers around the two respective libgd functions, introducing also a couple of constants. We also add the nnquant module to our bundled libgd.
if (gdImageTrueColorToPaletteSetMethod(im, method, speed)) { | ||
RETURN_TRUE; | ||
} else { | ||
php_error_docref(NULL, E_WARNING, "Couldn't set quantization method"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question you know better gd than I do, seems to me the only failure case left is when the method is not available correct ? so always will be unavailable then. dunno if we should raise an exception and this call only returns true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree, but we should add info about the available quantization methods first.
We might need to check for vcomp140.dll, too.
* proper range check for $method * error message must refer to `IMG_QUANT_*` * gd_topal.c must include libimagequant.h (like upstream does) * fix _aligned_malloc() arguments <libgd/libgd#914>
While adding a new test case, I've noticed that two others would fail when libimagequant is available. I'm somewhat surprised that this apparently hasn't been reported already. |
As is, ext/gd only supports the default color quantization algorithm, which is used for
imagetruecolortopalette()
. However, libgd supports alternative algorithms as of GD 2.1.0, namely NeuQuant (which is built in) and libimagequant (which is used by pngquant).We add support for these alternative color quantization algorithms as small wrappers around the two respective libgd functions, introducing also a couple of constants. We also add the nnquant module to our bundled libgd.
TODO:
References:
https://libgd.github.io/manuals/2.3.3/files/gd_topal-c.html