From 0825faa4c10d622f2747c5b2752e7b6a6848bf3f Mon Sep 17 00:00:00 2001 From: "jzern@google.com" Date: Wed, 15 Mar 2023 18:50:37 -0700 Subject: [PATCH] img2webp: add -sharp_yuv/-near_lossless Both are global settings. Modifying them at the frame level is left as a follow up based on need. Bug: b/272739498 Change-Id: If15256c052f73fe3df56be5e0095e76d9870cc0f --- CMakeLists.txt | 3 ++- doc/tools.md | 4 ++++ examples/Makefile.am | 2 +- examples/img2webp.c | 14 ++++++++++++++ man/img2webp.1 | 14 +++++++++++++- 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f378db5b..b7e8bf6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -546,7 +546,8 @@ if(WEBP_BUILD_IMG2WEBP) add_executable(img2webp ${IMG2WEBP_SRCS}) target_link_libraries(img2webp exampleutil imagedec imageioutil webp libwebpmux) - target_include_directories(img2webp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src) + target_include_directories(img2webp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src + ${CMAKE_CURRENT_SOURCE_DIR}) install(TARGETS img2webp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/doc/tools.md b/doc/tools.md index 853af819..20fc22a3 100644 --- a/doc/tools.md +++ b/doc/tools.md @@ -308,6 +308,10 @@ File-level options (only used at the start of compression): -kmin .......... minimum number of frame between key-frames (0=disable key-frames altogether) -mixed ............... use mixed lossy/lossless automatic mode +-near_lossless . use near-lossless image preprocessing + (0..100=off), default=100 +-sharp_yuv ........... use sharper (and slower) RGB->YUV conversion + (lossy only) -v ................... verbose mode -h ................... this help -version ............. print version number and exit diff --git a/examples/Makefile.am b/examples/Makefile.am index 72aa9f91..bbf0bac9 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -92,7 +92,7 @@ webpmux_LDADD += ../src/mux/libwebpmux.la webpmux_LDADD += ../src/libwebp.la img2webp_SOURCES = img2webp.c -img2webp_CPPFLAGS = $(AM_CPPFLAGS) +img2webp_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir) img2webp_LDADD = img2webp_LDADD += libexample_util.la img2webp_LDADD += ../imageio/libimageio_util.la diff --git a/examples/img2webp.c b/examples/img2webp.c index bfb1bfc1..cdb8d574 100644 --- a/examples/img2webp.c +++ b/examples/img2webp.c @@ -28,6 +28,7 @@ #include "../imageio/imageio_util.h" #include "./stopwatch.h" #include "./unicode.h" +#include "sharpyuv/sharpyuv.h" #include "webp/encode.h" #include "webp/mux.h" @@ -46,6 +47,11 @@ static void Help(void) { printf(" -kmin .......... minimum number of frame between key-frames\n" " (0=disable key-frames altogether)\n"); printf(" -mixed ............... use mixed lossy/lossless automatic mode\n"); + printf(" -near_lossless . use near-lossless image preprocessing\n" + " (0..100=off), default=100\n"); + printf(" -sharp_yuv ........... use sharper (and slower) RGB->YUV " + "conversion\n " + "(lossy only)\n"); printf(" -v ................... verbose mode\n"); printf(" -h ................... this help\n"); printf(" -version ............. print version number and exit\n"); @@ -184,6 +190,11 @@ int main(int argc, const char* argv[]) { } else if (!strcmp(argv[c], "-mixed")) { anim_config.allow_mixed = 1; config.lossless = 0; + } else if (!strcmp(argv[c], "-near_lossless") && c + 1 < argc) { + argv[c] = NULL; + config.near_lossless = ExUtilGetInt(argv[++c], 0, &parse_error); + } else if (!strcmp(argv[c], "-sharp_yuv")) { + config.use_sharp_yuv = 1; } else if (!strcmp(argv[c], "-v")) { verbose = 1; } else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) { @@ -192,10 +203,13 @@ int main(int argc, const char* argv[]) { } else if (!strcmp(argv[c], "-version")) { const int enc_version = WebPGetEncoderVersion(); const int mux_version = WebPGetMuxVersion(); + const int sharpyuv_version = SharpYuvGetVersion(); printf("WebP Encoder version: %d.%d.%d\nWebP Mux version: %d.%d.%d\n", (enc_version >> 16) & 0xff, (enc_version >> 8) & 0xff, enc_version & 0xff, (mux_version >> 16) & 0xff, (mux_version >> 8) & 0xff, mux_version & 0xff); + printf("libsharpyuv: %d.%d.%d\n", (sharpyuv_version >> 24) & 0xff, + (sharpyuv_version >> 16) & 0xffff, sharpyuv_version & 0xff); goto End; } else { continue; diff --git a/man/img2webp.1 b/man/img2webp.1 index 5b28cede..83e9859c 100644 --- a/man/img2webp.1 +++ b/man/img2webp.1 @@ -1,5 +1,5 @@ .\" Hey, EMACS: -*- nroff -*- -.TH IMG2WEBP 1 "January 5, 2022" +.TH IMG2WEBP 1 "March 16, 2023" .SH NAME img2webp \- create animated WebP file from a sequence of input images. .SH SYNOPSIS @@ -44,6 +44,18 @@ Mixed compression mode: optimize compression of the image by picking either lossy or lossless compression for each frame heuristically. This global option disables the local option \fB-lossy\fP and \fB-lossless\fP . .TP +.BI \-near_lossless " int +Specify the level of near\-lossless image preprocessing. This option adjusts +pixel values to help compressibility, but has minimal impact on the visual +quality. It triggers lossless compression mode automatically. The range is 0 +(maximum preprocessing) to 100 (no preprocessing, the default). The typical +value is around 60. Note that lossy with \fB\-q 100\fP can at times yield +better results. +.TP +.B \-sharp_yuv +Use more accurate and sharper RGB->YUV conversion if needed. Note that this +process is slower than the default 'fast' RGB->YUV conversion. +.TP .BI \-loop " int Specifies the number of times the animation should loop. Using '0' means 'loop indefinitely'.