Support alternative color quantization algorithms#17270
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.
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.
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. |
|
Also would need to cater to libgd/libgd#953. |
|
My plan was to expose them once #22532 is merged. That's the libgd/ sync only. Following PR adds new APIs etc. See https://wiki.php.net/rfc/ext-gd-2.4 (draft, writing it) |
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