diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2016-10-09 00:34:34 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2016-10-09 00:47:05 +0200 |
commit | 1458f8765c0a8289f359af58d9b2a801d2985e68 (patch) | |
tree | 883c1ca1072eb2e600918338b46623ef75838c46 /src | |
parent | cfd50c61bb709b15ba8729d77eba68cf1376a514 (diff) | |
download | libgd-1458f8765c0a8289f359af58d9b2a801d2985e68.tar.gz |
Support writing lossless WebP
Lossless WebP is a rather interesting alternative to PNG, and already
supported by `gdImageCreateFromWebp*()`, so we add support for
`gdImageWebp*()`, too.
We can stick with the existing API, using the quality parameter to
request lossless encoding if it is set to `gdWebpLossless`, which we
define to `PHP_INT` (to avoid adding a new dependency to gd.h, we hard-
code the value – we're assuming `sizeof(int)==4` anyway).
Diffstat (limited to 'src')
-rw-r--r-- | src/gd.h | 12 | ||||
-rw-r--r-- | src/gd_webp.c | 9 |
2 files changed, 20 insertions, 1 deletions
@@ -1068,6 +1068,18 @@ BGD_DECLARE(void) gdImageJpegCtx (gdImagePtr im, gdIOCtx * out, int quality); /* Best to free this memory with gdFree(), not free() */ BGD_DECLARE(void *) gdImageJpegPtr (gdImagePtr im, int *size, int quality); +/** + * Group: WebP + * + * Constant: gdWebpLossless + * + * Lossless quality + * + * See also: + * - <gdImageWebpEx> + */ +#define gdWebpLossless 0x7FFFFFFF + BGD_DECLARE(void) gdImageWebpEx (gdImagePtr im, FILE * outFile, int quantization); BGD_DECLARE(void) gdImageWebp (gdImagePtr im, FILE * outFile); BGD_DECLARE(void *) gdImageWebpPtr (gdImagePtr im, int *size); diff --git a/src/gd_webp.c b/src/gd_webp.c index 9886399..9b0f3fa 100644 --- a/src/gd_webp.c +++ b/src/gd_webp.c @@ -229,7 +229,11 @@ BGD_DECLARE(void) gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quality) *(p++) = a; } } - out_size = WebPEncodeRGBA(argb, gdImageSX(im), gdImageSY(im), gdImageSX(im) * 4, quality, &out); + if (quality == gdWebpLossless) { + out_size = WebPEncodeLosslessRGBA(argb, gdImageSX(im), gdImageSY(im), gdImageSX(im) * 4, &out); + } else { + out_size = WebPEncodeRGBA(argb, gdImageSX(im), gdImageSY(im), gdImageSX(im) * 4, quality, &out); + } if (out_size == 0) { gd_error("gd-webp encoding failed"); goto freeargb; @@ -256,6 +260,9 @@ freeargb: _quality_ should be a value in the range 0-100, higher quality values usually implying both higher quality and larger image sizes. + If _quality_ is <gdWebpLossless> then the image will be written in the + lossless WebP format. + Variants: <gdImageWebpCtx> stores the image using a <gdIOCtx> struct. |