From f999d94f4a7ed328a16fca128b574dd31bb5c7fb Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 4 Nov 2024 12:21:40 -0800 Subject: [PATCH] gif2webp: add -sharp_yuv/-near_lossless This change is the same as the one that introduced the options to img2webp: 0825faa4 img2webp: add -sharp_yuv/-near_lossless Change-Id: Id380d159299c38dd6440f833d487e00c0976afec --- CMakeLists.txt | 3 ++- doc/tools.md | 4 ++++ examples/Makefile.am | 2 +- examples/gif2webp.c | 13 +++++++++++++ man/gif2webp.1 | 14 +++++++++++++- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1ea7450..d7e8963f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -567,7 +567,8 @@ if(WEBP_BUILD_GIF2WEBP) add_executable(gif2webp ${GIF2WEBP_SRCS}) target_link_libraries(gif2webp exampleutil imageioutil webp libwebpmux ${WEBP_DEP_GIF_LIBRARIES}) - target_include_directories(gif2webp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src) + target_include_directories(gif2webp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src + ${CMAKE_CURRENT_SOURCE_DIR}) install(TARGETS gif2webp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/doc/tools.md b/doc/tools.md index cf67db5b..de8eab49 100644 --- a/doc/tools.md +++ b/doc/tools.md @@ -354,6 +354,10 @@ Options: -lossy ................. encode image using lossy compression -mixed ................. for each frame in the image, pick lossy or lossless compression heuristically +-near_lossless ... use near-lossless image preprocessing + (0..100=off), default=100 +-sharp_yuv ............. use sharper (and slower) RGB->YUV conversion + (lossy only) -q ............. quality factor (0:small..100:big) -m ............... compression method (0=fast, 6=slowest) -min_size .............. minimize output size (default:off) diff --git a/examples/Makefile.am b/examples/Makefile.am index bbf0bac9..b8c669c6 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -67,7 +67,7 @@ dwebp_LDADD += ../src/libwebp.la dwebp_LDADD +=$(PNG_LIBS) $(JPEG_LIBS) gif2webp_SOURCES = gif2webp.c gifdec.c gifdec.h -gif2webp_CPPFLAGS = $(AM_CPPFLAGS) $(GIF_INCLUDES) +gif2webp_CPPFLAGS = $(AM_CPPFLAGS) $(GIF_INCLUDES) -I$(top_srcdir) gif2webp_LDADD = gif2webp_LDADD += libexample_util.la gif2webp_LDADD += ../imageio/libimageio_util.la diff --git a/examples/gif2webp.c b/examples/gif2webp.c index 7130a3da..76fb4787 100644 --- a/examples/gif2webp.c +++ b/examples/gif2webp.c @@ -28,6 +28,7 @@ #endif #include +#include "sharpyuv/sharpyuv.h" #include "webp/encode.h" #include "webp/mux.h" #include "../examples/example_util.h" @@ -70,6 +71,11 @@ static void Help(void) { printf(" -lossy ................. encode image using lossy compression\n"); printf(" -mixed ................. for each frame in the image, pick lossy\n" " or lossless compression heuristically\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(" -q ............. quality factor (0:small..100:big)\n"); printf(" -m ............... compression method (0=fast, 6=slowest)\n"); printf(" -min_size .............. minimize output size (default:off)\n" @@ -166,6 +172,10 @@ int main(int argc, const char* argv[]) { } else if (!strcmp(argv[c], "-mixed")) { enc_options.allow_mixed = 1; config.lossless = 0; + } else if (!strcmp(argv[c], "-near_lossless") && c < argc - 1) { + 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], "-loop_compatibility")) { loop_compatibility = 1; } else if (!strcmp(argv[c], "-q") && c < argc - 1) { @@ -226,10 +236,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); FREE_WARGV_AND_RETURN(EXIT_SUCCESS); } else if (!strcmp(argv[c], "-quiet")) { quiet = 1; diff --git a/man/gif2webp.1 b/man/gif2webp.1 index 6a38f025..2b0e7e1f 100644 --- a/man/gif2webp.1 +++ b/man/gif2webp.1 @@ -1,5 +1,5 @@ .\" Hey, EMACS: -*- nroff -*- -.TH GIF2WEBP 1 "July 18, 2024" +.TH GIF2WEBP 1 "November 4, 2024" .SH NAME gif2webp \- Convert a GIF image to WebP .SH SYNOPSIS @@ -39,6 +39,18 @@ Encode the image using lossy compression. Mixed compression mode: optimize compression of the image by picking either lossy or lossless compression for each frame heuristically. .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. Note that this process is +slower than the default 'fast' RGB->YUV conversion. +.TP .BI \-q " float Specify the compression factor for RGB channels between 0 and 100. The default is 75.