From 6939e4f12e9d5b6c69aa994bbd6fc4046f8941e5 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 24 Nov 2024 18:33:38 +0100 Subject: Report if WebP is enabled and the version --- src/dwebp.h | 1 + src/version.cc | 10 ++++++++++ src/webp.c | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+) (limited to 'src') diff --git a/src/dwebp.h b/src/dwebp.h index 930380b0..11718456 100644 --- a/src/dwebp.h +++ b/src/dwebp.h @@ -11,6 +11,7 @@ extern "C" { void *a_Webp_new(DilloImage *Image, DilloUrl *url, int version); void a_Webp_callback(int Op, void *data); +const char *a_Webp_version(char *buf, int n); #ifdef __cplusplus diff --git a/src/version.cc b/src/version.cc index 417a1807..f0dc9e93 100644 --- a/src/version.cc +++ b/src/version.cc @@ -21,6 +21,7 @@ #include "djpeg.h" #include "dpng.h" +#include "dwebp.h" #include "IO/tls.h" #include @@ -53,6 +54,10 @@ static void print_libs() printf(" png/%s", a_Png_version()); #endif +#ifdef ENABLE_WEBP + printf(" webp/%s", a_Webp_version(buf, 256)); +#endif + #ifdef ENABLE_TLS /* TLS prints the name/version format, as it determines which SSL * library is in use */ @@ -85,6 +90,11 @@ static void print_features() #else " -SVG" #endif +#ifdef ENABLE_WEBP + " +WEBP" +#else + " -WEBP" +#endif #if !( defined(DISABLE_XEMBED) || defined(WIN32) || defined(__APPLE__) ) " +XEMBED" #else diff --git a/src/webp.c b/src/webp.c index ebcc238a..bd0ad88d 100644 --- a/src/webp.c +++ b/src/webp.c @@ -2,6 +2,7 @@ * File: webp.c * * Copyright (C) 2024 dogma + * Copyright (C) 2024 Rodrigo Arias Mallo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -172,6 +173,23 @@ void a_Webp_callback(int Op, void *data) } } +const char *a_Webp_version(char *buf, int n) +{ + /* Return the decoder's version number, packed in + * hexadecimal using 8bits for each of major/minor/revision. + * E.g: v2.5.7 is 0x020507. */ + int ver = WebPGetDecoderVersion(); + + int major = (ver >> 16) & 0xff; + int minor = (ver >> 8) & 0xff; + int rev = (ver >> 0) & 0xff; + + int k = snprintf(buf, n, "%d.%d.%d", major, minor, rev); + if (k >= n) + return "?"; + return buf; +} + /* * Create the image state data that must be kept between calls */ @@ -197,5 +215,6 @@ void *a_Webp_new(DilloImage *Image, DilloUrl *url, int version) void *a_Webp_new() { return 0; } void a_Webp_callback() { return; } +const char *a_Webp_version(char *buf, int n) { return NULL; } #endif /* ENABLE_WEBP */ -- cgit v1.2.3