1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-03-22 20:21:28 +02:00

Cleanup avif speed code

This commit is contained in:
DarthSim 2021-04-26 18:31:57 +06:00
parent a7d451b8f2
commit 8fcc839925
3 changed files with 10 additions and 11 deletions

@ -122,6 +122,10 @@ Also you may want imgproxy to respond with the same error message that it writes
* `IMGPROXY_GIF_OPTIMIZE_FRAMES`: <img class='pro-badge' src='assets/pro.svg' alt='pro' /> when true, enables GIF frames optimization. This may produce a smaller result, but may increase compression time.
* `IMGPROXY_GIF_OPTIMIZE_TRANSPARENCY`: <img class='pro-badge' src='assets/pro.svg' alt='pro' /> when true, enables GIF transparency optimization. This may produce a smaller result, but may increase compression time.
### Advanced AVIF compression
* `IMGPROXY_AVIF_SPEED`: controls the CPU effort spent improving compression. 0 slowest - 8 fastest. Default: `5`;
## AVIF/WebP support detection
imgproxy can use the `Accept` HTTP header to detect if the browser supports AVIF or WebP and use it as the default format. This feature is disabled by default and can be enabled by the following options:
@ -130,7 +134,6 @@ imgproxy can use the `Accept` HTTP header to detect if the browser supports AVIF
* `IMGPROXY_ENFORCE_WEBP`: enables WebP support detection and enforces WebP usage. If the browser supports WebP, it will be used as resulting format even if another extension is specified in the imgproxy URL.
* `IMGPROXY_ENABLE_AVIF_DETECTION`: enables AVIF support detection. When the file extension is omitted in the imgproxy URL and browser supports AVIF, imgproxy will use it as the resulting format;
* `IMGPROXY_ENFORCE_AVIF`: enables AVIF support detection and enforces AVIF usage. If the browser supports AVIF, it will be used as resulting format even if another extension is specified in the imgproxy URL.
* `IMGPROXY_AVIF_SPEED`: controls the CPU effort spent improving compression. 0 slowest - 8 fastest. Default: `5`;
**📝Note:** imgproxy prefers AVIF over WebP. This means that if both AVIF and WebP detection/enforcement are enabled and the browser supports both of them, AVIF will be used.

14
vips.c

@ -263,11 +263,6 @@ vips_support_webp_animation() {
return VIPS_SUPPORT_WEBP_ANIMATION;
}
gboolean
vips_support_avif_speed() {
return VIPS_SUPPORT_AVIF_SPEED;
}
gboolean
vips_is_animated(VipsImage * in) {
return( vips_image_get_typeof(in, "page-height") != G_TYPE_INVALID &&
@ -715,11 +710,14 @@ vips_tiffsave_go(VipsImage *in, void **buf, size_t *len, int quality) {
int
vips_avifsave_go(VipsImage *in, void **buf, size_t *len, int quality, int speed) {
#if VIPS_SUPPORT_AVIF
return vips_heifsave_buffer(
in, buf, len,
"Q", quality,
"compression", VIPS_FOREIGN_HEIF_COMPRESSION_AV1,
#if VIPS_SUPPORT_AVIF_SPEED
return vips_heifsave_buffer(in, buf, len, "Q", quality, "compression", VIPS_FOREIGN_HEIF_COMPRESSION_AV1, "speed", speed, NULL);
#else
return vips_heifsave_buffer(in, buf, len, "Q", quality, "compression", VIPS_FOREIGN_HEIF_COMPRESSION_AV1, NULL);
"speed", speed,
#endif
NULL);
#else
vips_error("vips_avifsave_go", "Saving AVIF is not supported (libvips 8.9+ reuired)");
return 1;

2
vips.h

@ -47,8 +47,6 @@ VipsBandFormat vips_band_format(VipsImage *in);
gboolean vips_support_webp_animation();
gboolean vips_is_animated(VipsImage * in);
gboolean vips_support_avif_speed();
int vips_image_get_array_int_go(VipsImage *image, const char *name, int **out, int *n);
void vips_image_set_array_int_go(VipsImage *image, const char *name, const int *array, int n);