From 68f6c462cf71fccd355c8343ae0f40b2279b4d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Wed, 1 Mar 2023 21:07:59 +0200 Subject: [PATCH] feat: Add WebP encoding support (#34) * feat: Add WebP encoding support * doc: Update documentation about WebP support --- Cargo.lock | 31 +++ Cargo.toml | 2 +- README.md | 25 +- completions/menyoki.bash | 267 ++++++++++++++++++- completions/menyoki.elvish | 93 +++++++ completions/menyoki.fish | 42 +++ completions/menyoki.powershell | 102 ++++++++ completions/menyoki.zsh | 459 +++++++++++++++++++++++++++++++++ config/menyoki.conf | 6 + man/menyoki.1 | 23 ++ man/menyoki.conf.5 | 8 + src/app.rs | 9 + src/args/mod.rs | 23 ++ src/file/format.rs | 4 + src/file/mod.rs | 4 +- src/image/settings.rs | 90 +++++++ src/settings.rs | 4 +- 17 files changed, 1182 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index db3bf34..b77a828 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,6 +116,9 @@ name = "cc" version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] [[package]] name = "cfg-if" @@ -640,6 +643,7 @@ dependencies = [ "png", "scoped_threadpool", "tiff", + "webp", ] [[package]] @@ -672,6 +676,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "jobserver" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +dependencies = [ + "libc", +] + [[package]] name = "jpeg-decoder" version = "0.3.0" @@ -717,6 +730,15 @@ version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +[[package]] +name = "libwebp-sys" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439fd1885aa28937e7edcd68d2e793cb4a22f8733460d2519fbafd2b215672bf" +dependencies = [ + "cc", +] + [[package]] name = "link-cplusplus" version = "1.0.8" @@ -1474,6 +1496,15 @@ version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" +[[package]] +name = "webp" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf022f821f166079a407d000ab57e84de020e66ffbbf4edde999bc7d6e371cae" +dependencies = [ + "libwebp-sys", +] + [[package]] name = "weezl" version = "0.1.7" diff --git a/Cargo.toml b/Cargo.toml index fb0700f..5010100 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ x11 = { version = "2.21.0", features = ["xlib", "xrandr"] } device_query = "1.1.2" ctrlc = { version = "3.2.5", features = ["termination"] } # image operations -image = "0.24.5" +image = { version = "0.24.5", features = ["webp-encoder"] } imgref = { version = "1.9.4", optional = true } rgb = { version = "0.8.36", optional = true } png = "0.17.7" diff --git a/README.md b/README.md index dc789e4..f231eda 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ - [GIF/APNG](#gifapng) - [PNG](#png) - [JPG](#jpg) + - [WEBP](#webp) - [PNM](#pnm) - [Save](#save) - [Key Bindings](#key-bindings) @@ -122,7 +123,7 @@ - [x] [TGA](https://en.wikipedia.org/wiki/Truevision_TGA) - [x] [farbfeld](https://tools.suckless.org/farbfeld/) - [x] [OpenEXR](https://en.wikipedia.org/wiki/OpenEXR) -- [ ] [WebP](https://en.wikipedia.org/wiki/WebP) +- [x] [WebP](https://en.wikipedia.org/wiki/WebP) - [ ] [AVIF](https://en.wikipedia.org/wiki/AV1) - [ ] [MP4](https://en.wikipedia.org/wiki/MPEG-4_Part_14) @@ -401,6 +402,7 @@ ARGS: SUBCOMMANDS: png Use the PNG encoder jpg Use the JPG encoder + webp Use the WebP encoder bmp Use the BMP encoder ico Use the ICO encoder tiff Use the TIFF encoder @@ -493,6 +495,7 @@ ARGS: SUBCOMMANDS: png Use the PNG encoder jpg Use the JPG encoder + webp Use the WebP encoder bmp Use the BMP encoder ico Use the ICO encoder tiff Use the TIFF encoder @@ -515,6 +518,7 @@ SUBCOMMANDS: | `menyoki capture --mouse` | Screenshot the selected window with a mouse click | | `menyoki capture png --filter avg --compression fast` | Screenshot and encode with the specified PNG options | | `menyoki capture jpg --quality 100` | Screenshot and encode with the specified JPEG options | +| `menyoki capture webp --lossless` | Screenshot and encode with the specified WEBP options | | `menyoki capture pnm --format pixmap --encoding ascii` | Screenshot and encode with the specified PNM options | | `menyoki capture ff save "test.ff" --timestamp` | Screenshot and save as "test.ff" in farbfeld format with timestamp in the file name | | `menyoki -q capture png save "-" > test.png` | Screenshot and redirect output to "test.png" | @@ -559,6 +563,7 @@ SUBCOMMANDS: apng Use the APNG encoder png Use the PNG encoder jpg Use the JPG encoder + webp Use the WebP encoder bmp Use the BMP encoder ico Use the ICO encoder tiff Use the TIFF encoder @@ -780,6 +785,20 @@ SUBCOMMANDS: save Save the output file(s) ``` +#### WEBP + +``` +FLAGS: + -l, --lossless Use lossless encoding + -h, --help Print help information + +OPTIONS: + -q, --quality Set the lossy encoding quality (1-100) [default: 80] + +SUBCOMMANDS: + save Save the output file(s) +``` + #### PNM ``` @@ -964,6 +983,10 @@ filter = sub [jpg] quality = 90 +[webp] +quality = 80 +lossless = false + [pnm] format = pixmap encoding = binary diff --git a/completions/menyoki.bash b/completions/menyoki.bash index 0496548..2674fcb 100644 --- a/completions/menyoki.bash +++ b/completions/menyoki.bash @@ -94,6 +94,9 @@ _menyoki() { view) cmd+="__view" ;; + webp) + cmd+="__webp" + ;; *) ;; esac @@ -213,7 +216,7 @@ _menyoki() { return 0 ;; menyoki__capture) - opts=" -r -f -m -h -V -b -p -s -d -c -t -i --root --focus --select --parent --with-alpha --no-keys --mouse --help --version --action-keys --cancel-keys --border --padding --size --duration --countdown --timeout --interval --font --monitor png jpg bmp ico tiff tga pnm ff exr save help out" + opts=" -r -f -m -h -V -b -p -s -d -c -t -i --root --focus --select --parent --with-alpha --no-keys --mouse --help --version --action-keys --cancel-keys --border --padding --size --duration --countdown --timeout --interval --font --monitor png jpg webp bmp ico tiff tga pnm ff exr save help out" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -1084,6 +1087,90 @@ _menyoki() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; + menyoki__capture__webp) + opts=" -l -h -V -q --lossless --help --version --quality save help out" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + --quality) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -q) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + menyoki__capture__webp__help) + opts=" -h -V --help --version " + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + menyoki__capture__webp__out) + opts=" -e -t -h -V -d --with-extension --timestamp --help --version --date " + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + --date) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -d) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + menyoki__capture__webp__save) + opts=" -e -t -h -V -d --with-extension --timestamp --help --version --date " + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + --date) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -d) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; menyoki__combine) opts=" -n -h -V -f -q -r -s -d --gifski --fast --no-sort --help --version --fps --quality --repeat --speed --cut-beginning --cut-end --dir --format ... save help out" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then @@ -1152,7 +1239,7 @@ _menyoki() { return 0 ;; menyoki__edit) - opts=" -h -V --convert --grayscale --invert --help --version --crop --resize --ratio --rotate --flip --blur --hue --contrast --brightness --filter gif apng png jpg bmp ico tiff tga pnm ff exr save help out" + opts=" -h -V --convert --grayscale --invert --help --version --crop --resize --ratio --rotate --flip --blur --hue --contrast --brightness --filter gif apng png jpg webp bmp ico tiff tga pnm ff exr save help out" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -2247,8 +2334,92 @@ _menyoki() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; + menyoki__edit__webp) + opts=" -l -h -V -q --lossless --help --version --quality save help out" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + --quality) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -q) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + menyoki__edit__webp__help) + opts=" -h -V --help --version " + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + menyoki__edit__webp__out) + opts=" -e -t -h -V -d --with-extension --timestamp --help --version --date " + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + --date) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -d) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + menyoki__edit__webp__save) + opts=" -e -t -h -V -d --with-extension --timestamp --help --version --date " + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + --date) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -d) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; menyoki__extract) - opts=" -h -V -d --help --version --dir png jpg bmp ico tiff tga pnm ff exr save help out" + opts=" -h -V -d --help --version --dir png jpg webp bmp ico tiff tga pnm ff exr save help out" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -2864,7 +3035,7 @@ _menyoki() { return 0 ;; menyoki__screenshot) - opts=" -r -f -m -h -V -b -p -s -d -c -t -i --root --focus --select --parent --with-alpha --no-keys --mouse --help --version --action-keys --cancel-keys --border --padding --size --duration --countdown --timeout --interval --font --monitor png jpg bmp ico tiff tga pnm ff exr save help out" + opts=" -r -f -m -h -V -b -p -s -d -c -t -i --root --focus --select --parent --with-alpha --no-keys --mouse --help --version --action-keys --cancel-keys --border --padding --size --duration --countdown --timeout --interval --font --monitor png jpg webp bmp ico tiff tga pnm ff exr save help out" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -2951,7 +3122,7 @@ _menyoki() { return 0 ;; menyoki__split) - opts=" -h -V -d --help --version --dir png jpg bmp ico tiff tga pnm ff exr save help out" + opts=" -h -V -d --help --version --dir png jpg webp bmp ico tiff tga pnm ff exr save help out" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -3758,8 +3929,92 @@ _menyoki() { COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 ;; + menyoki__split__webp) + opts=" -l -h -V -q --lossless --help --version --quality save help out" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + --quality) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -q) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + menyoki__split__webp__help) + opts=" -h -V --help --version " + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + menyoki__split__webp__out) + opts=" -e -t -h -V -d --with-extension --timestamp --help --version --date " + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + --date) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -d) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + menyoki__split__webp__save) + opts=" -e -t -h -V -d --with-extension --timestamp --help --version --date " + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + + --date) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -d) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; menyoki__ss) - opts=" -r -f -m -h -V -b -p -s -d -c -t -i --root --focus --select --parent --with-alpha --no-keys --mouse --help --version --action-keys --cancel-keys --border --padding --size --duration --countdown --timeout --interval --font --monitor png jpg bmp ico tiff tga pnm ff exr save help out" + opts=" -r -f -m -h -V -b -p -s -d -c -t -i --root --focus --select --parent --with-alpha --no-keys --mouse --help --version --action-keys --cancel-keys --border --padding --size --duration --countdown --timeout --interval --font --monitor png jpg webp bmp ico tiff tga pnm ff exr save help out" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 diff --git a/completions/menyoki.elvish b/completions/menyoki.elvish index fcd7736..5a5e2aa 100644 --- a/completions/menyoki.elvish +++ b/completions/menyoki.elvish @@ -187,6 +187,7 @@ edit:completion:arg-completer[menyoki] = [@words]{ cand --version 'Prints version information' cand png 'Use the PNG encoder' cand jpg 'Use the JPG encoder' + cand webp 'Use the WebP encoder' cand bmp 'Use the BMP encoder' cand ico 'Use the ICO encoder' cand tiff 'Use the TIFF encoder' @@ -255,6 +256,36 @@ edit:completion:arg-completer[menyoki] = [@words]{ cand -V 'Prints version information' cand --version 'Prints version information' } + &'menyoki;split;webp'= { + cand -q 'Set the lossy encoding quality (1-100)' + cand --quality 'Set the lossy encoding quality (1-100)' + cand -l 'Use lossless encoding' + cand --lossless 'Use lossless encoding' + cand -h 'Print help information' + cand --help 'Print help information' + cand -V 'Prints version information' + cand --version 'Prints version information' + cand save 'Save the output file(s)' + cand help 'Prints this message or the help of the given subcommand(s)' + } + &'menyoki;split;webp;save'= { + cand -d 'Add formatted date/time to the file name' + cand --date 'Add formatted date/time to the file name' + cand -e 'Always save the file with an extension' + cand --with-extension 'Always save the file with an extension' + cand -t 'Add Unix timestamp to the file name' + cand --timestamp 'Add Unix timestamp to the file name' + cand -h 'Print help information' + cand --help 'Print help information' + cand -V 'Prints version information' + cand --version 'Prints version information' + } + &'menyoki;split;webp;help'= { + cand -h 'Prints help information' + cand --help 'Prints help information' + cand -V 'Prints version information' + cand --version 'Prints version information' + } &'menyoki;split;bmp'= { cand -h 'Print help information' cand --help 'Print help information' @@ -537,6 +568,7 @@ edit:completion:arg-completer[menyoki] = [@words]{ cand --version 'Prints version information' cand png 'Use the PNG encoder' cand jpg 'Use the JPG encoder' + cand webp 'Use the WebP encoder' cand bmp 'Use the BMP encoder' cand ico 'Use the ICO encoder' cand tiff 'Use the TIFF encoder' @@ -605,6 +637,36 @@ edit:completion:arg-completer[menyoki] = [@words]{ cand -V 'Prints version information' cand --version 'Prints version information' } + &'menyoki;capture;webp'= { + cand -q 'Set the lossy encoding quality (1-100)' + cand --quality 'Set the lossy encoding quality (1-100)' + cand -l 'Use lossless encoding' + cand --lossless 'Use lossless encoding' + cand -h 'Print help information' + cand --help 'Print help information' + cand -V 'Prints version information' + cand --version 'Prints version information' + cand save 'Save the output file(s)' + cand help 'Prints this message or the help of the given subcommand(s)' + } + &'menyoki;capture;webp;save'= { + cand -d 'Add formatted date/time to the file name' + cand --date 'Add formatted date/time to the file name' + cand -e 'Always save the file with an extension' + cand --with-extension 'Always save the file with an extension' + cand -t 'Add Unix timestamp to the file name' + cand --timestamp 'Add Unix timestamp to the file name' + cand -h 'Print help information' + cand --help 'Print help information' + cand -V 'Prints version information' + cand --version 'Prints version information' + } + &'menyoki;capture;webp;help'= { + cand -h 'Prints help information' + cand --help 'Prints help information' + cand -V 'Prints version information' + cand --version 'Prints version information' + } &'menyoki;capture;bmp'= { cand -h 'Print help information' cand --help 'Print help information' @@ -831,6 +893,7 @@ edit:completion:arg-completer[menyoki] = [@words]{ cand apng 'Use the APNG encoder' cand png 'Use the PNG encoder' cand jpg 'Use the JPG encoder' + cand webp 'Use the WebP encoder' cand bmp 'Use the BMP encoder' cand ico 'Use the ICO encoder' cand tiff 'Use the TIFF encoder' @@ -985,6 +1048,36 @@ edit:completion:arg-completer[menyoki] = [@words]{ cand -V 'Prints version information' cand --version 'Prints version information' } + &'menyoki;edit;webp'= { + cand -q 'Set the lossy encoding quality (1-100)' + cand --quality 'Set the lossy encoding quality (1-100)' + cand -l 'Use lossless encoding' + cand --lossless 'Use lossless encoding' + cand -h 'Print help information' + cand --help 'Print help information' + cand -V 'Prints version information' + cand --version 'Prints version information' + cand save 'Save the output file(s)' + cand help 'Prints this message or the help of the given subcommand(s)' + } + &'menyoki;edit;webp;save'= { + cand -d 'Add formatted date/time to the file name' + cand --date 'Add formatted date/time to the file name' + cand -e 'Always save the file with an extension' + cand --with-extension 'Always save the file with an extension' + cand -t 'Add Unix timestamp to the file name' + cand --timestamp 'Add Unix timestamp to the file name' + cand -h 'Print help information' + cand --help 'Print help information' + cand -V 'Prints version information' + cand --version 'Prints version information' + } + &'menyoki;edit;webp;help'= { + cand -h 'Prints help information' + cand --help 'Prints help information' + cand -V 'Prints version information' + cand --version 'Prints version information' + } &'menyoki;edit;bmp'= { cand -h 'Print help information' cand --help 'Print help information' diff --git a/completions/menyoki.fish b/completions/menyoki.fish index 75d4013..701bcdb 100644 --- a/completions/menyoki.fish +++ b/completions/menyoki.fish @@ -93,6 +93,7 @@ complete -c menyoki -n "__fish_seen_subcommand_from split" -s h -l help -d 'Prin complete -c menyoki -n "__fish_seen_subcommand_from split" -s V -l version -d 'Prints version information' complete -c menyoki -n "__fish_seen_subcommand_from split" -f -a "png" -d 'Use the PNG encoder' complete -c menyoki -n "__fish_seen_subcommand_from split" -f -a "jpg" -d 'Use the JPG encoder' +complete -c menyoki -n "__fish_seen_subcommand_from split" -f -a "webp" -d 'Use the WebP encoder' complete -c menyoki -n "__fish_seen_subcommand_from split" -f -a "bmp" -d 'Use the BMP encoder' complete -c menyoki -n "__fish_seen_subcommand_from split" -f -a "ico" -d 'Use the ICO encoder' complete -c menyoki -n "__fish_seen_subcommand_from split" -f -a "tiff" -d 'Use the TIFF encoder' @@ -127,6 +128,19 @@ complete -c menyoki -n "__fish_seen_subcommand_from save" -s h -l help -d 'Print complete -c menyoki -n "__fish_seen_subcommand_from save" -s V -l version -d 'Prints version information' complete -c menyoki -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints help information' complete -c menyoki -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -s q -l quality -d 'Set the lossy encoding quality (1-100)' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -s l -l lossless -d 'Use lossless encoding' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -s h -l help -d 'Print help information' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -s V -l version -d 'Prints version information' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -f -a "save" -d 'Save the output file(s)' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -f -a "help" -d 'Prints this message or the help of the given subcommand(s)' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s d -l date -d 'Add formatted date/time to the file name' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s e -l with-extension -d 'Always save the file with an extension' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s t -l timestamp -d 'Add Unix timestamp to the file name' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s h -l help -d 'Print help information' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s V -l version -d 'Prints version information' +complete -c menyoki -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints help information' +complete -c menyoki -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information' complete -c menyoki -n "__fish_seen_subcommand_from bmp" -s h -l help -d 'Print help information' complete -c menyoki -n "__fish_seen_subcommand_from bmp" -s V -l version -d 'Prints version information' complete -c menyoki -n "__fish_seen_subcommand_from bmp" -f -a "save" -d 'Save the output file(s)' @@ -257,6 +271,7 @@ complete -c menyoki -n "__fish_seen_subcommand_from capture" -s h -l help -d 'Pr complete -c menyoki -n "__fish_seen_subcommand_from capture" -s V -l version -d 'Prints version information' complete -c menyoki -n "__fish_seen_subcommand_from capture" -f -a "png" -d 'Use the PNG encoder' complete -c menyoki -n "__fish_seen_subcommand_from capture" -f -a "jpg" -d 'Use the JPG encoder' +complete -c menyoki -n "__fish_seen_subcommand_from capture" -f -a "webp" -d 'Use the WebP encoder' complete -c menyoki -n "__fish_seen_subcommand_from capture" -f -a "bmp" -d 'Use the BMP encoder' complete -c menyoki -n "__fish_seen_subcommand_from capture" -f -a "ico" -d 'Use the ICO encoder' complete -c menyoki -n "__fish_seen_subcommand_from capture" -f -a "tiff" -d 'Use the TIFF encoder' @@ -291,6 +306,19 @@ complete -c menyoki -n "__fish_seen_subcommand_from save" -s h -l help -d 'Print complete -c menyoki -n "__fish_seen_subcommand_from save" -s V -l version -d 'Prints version information' complete -c menyoki -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints help information' complete -c menyoki -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -s q -l quality -d 'Set the lossy encoding quality (1-100)' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -s l -l lossless -d 'Use lossless encoding' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -s h -l help -d 'Print help information' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -s V -l version -d 'Prints version information' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -f -a "save" -d 'Save the output file(s)' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -f -a "help" -d 'Prints this message or the help of the given subcommand(s)' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s d -l date -d 'Add formatted date/time to the file name' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s e -l with-extension -d 'Always save the file with an extension' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s t -l timestamp -d 'Add Unix timestamp to the file name' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s h -l help -d 'Print help information' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s V -l version -d 'Prints version information' +complete -c menyoki -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints help information' +complete -c menyoki -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information' complete -c menyoki -n "__fish_seen_subcommand_from bmp" -s h -l help -d 'Print help information' complete -c menyoki -n "__fish_seen_subcommand_from bmp" -s V -l version -d 'Prints version information' complete -c menyoki -n "__fish_seen_subcommand_from bmp" -f -a "save" -d 'Save the output file(s)' @@ -396,6 +424,7 @@ complete -c menyoki -n "__fish_seen_subcommand_from edit" -f -a "gif" -d 'Use th complete -c menyoki -n "__fish_seen_subcommand_from edit" -f -a "apng" -d 'Use the APNG encoder' complete -c menyoki -n "__fish_seen_subcommand_from edit" -f -a "png" -d 'Use the PNG encoder' complete -c menyoki -n "__fish_seen_subcommand_from edit" -f -a "jpg" -d 'Use the JPG encoder' +complete -c menyoki -n "__fish_seen_subcommand_from edit" -f -a "webp" -d 'Use the WebP encoder' complete -c menyoki -n "__fish_seen_subcommand_from edit" -f -a "bmp" -d 'Use the BMP encoder' complete -c menyoki -n "__fish_seen_subcommand_from edit" -f -a "ico" -d 'Use the ICO encoder' complete -c menyoki -n "__fish_seen_subcommand_from edit" -f -a "tiff" -d 'Use the TIFF encoder' @@ -474,6 +503,19 @@ complete -c menyoki -n "__fish_seen_subcommand_from save" -s h -l help -d 'Print complete -c menyoki -n "__fish_seen_subcommand_from save" -s V -l version -d 'Prints version information' complete -c menyoki -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints help information' complete -c menyoki -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -s q -l quality -d 'Set the lossy encoding quality (1-100)' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -s l -l lossless -d 'Use lossless encoding' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -s h -l help -d 'Print help information' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -s V -l version -d 'Prints version information' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -f -a "save" -d 'Save the output file(s)' +complete -c menyoki -n "__fish_seen_subcommand_from webp" -f -a "help" -d 'Prints this message or the help of the given subcommand(s)' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s d -l date -d 'Add formatted date/time to the file name' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s e -l with-extension -d 'Always save the file with an extension' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s t -l timestamp -d 'Add Unix timestamp to the file name' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s h -l help -d 'Print help information' +complete -c menyoki -n "__fish_seen_subcommand_from save" -s V -l version -d 'Prints version information' +complete -c menyoki -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints help information' +complete -c menyoki -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information' complete -c menyoki -n "__fish_seen_subcommand_from bmp" -s h -l help -d 'Print help information' complete -c menyoki -n "__fish_seen_subcommand_from bmp" -s V -l version -d 'Prints version information' complete -c menyoki -n "__fish_seen_subcommand_from bmp" -f -a "save" -d 'Save the output file(s)' diff --git a/completions/menyoki.powershell b/completions/menyoki.powershell index 37d62ff..8a68014 100644 --- a/completions/menyoki.powershell +++ b/completions/menyoki.powershell @@ -202,6 +202,7 @@ Register-ArgumentCompleter -Native -CommandName 'menyoki' -ScriptBlock { [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') [CompletionResult]::new('png', 'png', [CompletionResultType]::ParameterValue, 'Use the PNG encoder') [CompletionResult]::new('jpg', 'jpg', [CompletionResultType]::ParameterValue, 'Use the JPG encoder') + [CompletionResult]::new('webp', 'webp', [CompletionResultType]::ParameterValue, 'Use the WebP encoder') [CompletionResult]::new('bmp', 'bmp', [CompletionResultType]::ParameterValue, 'Use the BMP encoder') [CompletionResult]::new('ico', 'ico', [CompletionResultType]::ParameterValue, 'Use the ICO encoder') [CompletionResult]::new('tiff', 'tiff', [CompletionResultType]::ParameterValue, 'Use the TIFF encoder') @@ -277,6 +278,39 @@ Register-ArgumentCompleter -Native -CommandName 'menyoki' -ScriptBlock { [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') break } + 'menyoki;split;webp' { + [CompletionResult]::new('-q', 'q', [CompletionResultType]::ParameterName, 'Set the lossy encoding quality (1-100)') + [CompletionResult]::new('--quality', 'quality', [CompletionResultType]::ParameterName, 'Set the lossy encoding quality (1-100)') + [CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, 'Use lossless encoding') + [CompletionResult]::new('--lossless', 'lossless', [CompletionResultType]::ParameterName, 'Use lossless encoding') + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information') + [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') + [CompletionResult]::new('save', 'save', [CompletionResultType]::ParameterValue, 'Save the output file(s)') + [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Prints this message or the help of the given subcommand(s)') + break + } + 'menyoki;split;webp;save' { + [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Add formatted date/time to the file name') + [CompletionResult]::new('--date', 'date', [CompletionResultType]::ParameterName, 'Add formatted date/time to the file name') + [CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'Always save the file with an extension') + [CompletionResult]::new('--with-extension', 'with-extension', [CompletionResultType]::ParameterName, 'Always save the file with an extension') + [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'Add Unix timestamp to the file name') + [CompletionResult]::new('--timestamp', 'timestamp', [CompletionResultType]::ParameterName, 'Add Unix timestamp to the file name') + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information') + [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') + break + } + 'menyoki;split;webp;help' { + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information') + [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information') + [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') + break + } 'menyoki;split;bmp' { [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information') @@ -585,6 +619,7 @@ Register-ArgumentCompleter -Native -CommandName 'menyoki' -ScriptBlock { [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') [CompletionResult]::new('png', 'png', [CompletionResultType]::ParameterValue, 'Use the PNG encoder') [CompletionResult]::new('jpg', 'jpg', [CompletionResultType]::ParameterValue, 'Use the JPG encoder') + [CompletionResult]::new('webp', 'webp', [CompletionResultType]::ParameterValue, 'Use the WebP encoder') [CompletionResult]::new('bmp', 'bmp', [CompletionResultType]::ParameterValue, 'Use the BMP encoder') [CompletionResult]::new('ico', 'ico', [CompletionResultType]::ParameterValue, 'Use the ICO encoder') [CompletionResult]::new('tiff', 'tiff', [CompletionResultType]::ParameterValue, 'Use the TIFF encoder') @@ -660,6 +695,39 @@ Register-ArgumentCompleter -Native -CommandName 'menyoki' -ScriptBlock { [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') break } + 'menyoki;capture;webp' { + [CompletionResult]::new('-q', 'q', [CompletionResultType]::ParameterName, 'Set the lossy encoding quality (1-100)') + [CompletionResult]::new('--quality', 'quality', [CompletionResultType]::ParameterName, 'Set the lossy encoding quality (1-100)') + [CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, 'Use lossless encoding') + [CompletionResult]::new('--lossless', 'lossless', [CompletionResultType]::ParameterName, 'Use lossless encoding') + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information') + [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') + [CompletionResult]::new('save', 'save', [CompletionResultType]::ParameterValue, 'Save the output file(s)') + [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Prints this message or the help of the given subcommand(s)') + break + } + 'menyoki;capture;webp;save' { + [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Add formatted date/time to the file name') + [CompletionResult]::new('--date', 'date', [CompletionResultType]::ParameterName, 'Add formatted date/time to the file name') + [CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'Always save the file with an extension') + [CompletionResult]::new('--with-extension', 'with-extension', [CompletionResultType]::ParameterName, 'Always save the file with an extension') + [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'Add Unix timestamp to the file name') + [CompletionResult]::new('--timestamp', 'timestamp', [CompletionResultType]::ParameterName, 'Add Unix timestamp to the file name') + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information') + [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') + break + } + 'menyoki;capture;webp;help' { + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information') + [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information') + [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') + break + } 'menyoki;capture;bmp' { [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information') @@ -909,6 +977,7 @@ Register-ArgumentCompleter -Native -CommandName 'menyoki' -ScriptBlock { [CompletionResult]::new('apng', 'apng', [CompletionResultType]::ParameterValue, 'Use the APNG encoder') [CompletionResult]::new('png', 'png', [CompletionResultType]::ParameterValue, 'Use the PNG encoder') [CompletionResult]::new('jpg', 'jpg', [CompletionResultType]::ParameterValue, 'Use the JPG encoder') + [CompletionResult]::new('webp', 'webp', [CompletionResultType]::ParameterValue, 'Use the WebP encoder') [CompletionResult]::new('bmp', 'bmp', [CompletionResultType]::ParameterValue, 'Use the BMP encoder') [CompletionResult]::new('ico', 'ico', [CompletionResultType]::ParameterValue, 'Use the ICO encoder') [CompletionResult]::new('tiff', 'tiff', [CompletionResultType]::ParameterValue, 'Use the TIFF encoder') @@ -1076,6 +1145,39 @@ Register-ArgumentCompleter -Native -CommandName 'menyoki' -ScriptBlock { [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') break } + 'menyoki;edit;webp' { + [CompletionResult]::new('-q', 'q', [CompletionResultType]::ParameterName, 'Set the lossy encoding quality (1-100)') + [CompletionResult]::new('--quality', 'quality', [CompletionResultType]::ParameterName, 'Set the lossy encoding quality (1-100)') + [CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, 'Use lossless encoding') + [CompletionResult]::new('--lossless', 'lossless', [CompletionResultType]::ParameterName, 'Use lossless encoding') + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information') + [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') + [CompletionResult]::new('save', 'save', [CompletionResultType]::ParameterValue, 'Save the output file(s)') + [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Prints this message or the help of the given subcommand(s)') + break + } + 'menyoki;edit;webp;save' { + [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Add formatted date/time to the file name') + [CompletionResult]::new('--date', 'date', [CompletionResultType]::ParameterName, 'Add formatted date/time to the file name') + [CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'Always save the file with an extension') + [CompletionResult]::new('--with-extension', 'with-extension', [CompletionResultType]::ParameterName, 'Always save the file with an extension') + [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'Add Unix timestamp to the file name') + [CompletionResult]::new('--timestamp', 'timestamp', [CompletionResultType]::ParameterName, 'Add Unix timestamp to the file name') + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information') + [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information') + [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') + break + } + 'menyoki;edit;webp;help' { + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information') + [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information') + [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information') + break + } 'menyoki;edit;bmp' { [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information') diff --git a/completions/menyoki.zsh b/completions/menyoki.zsh index a509417..0221b10 100644 --- a/completions/menyoki.zsh +++ b/completions/menyoki.zsh @@ -409,6 +409,67 @@ _arguments "${_arguments_options[@]}" \ ;; esac ;; +(webp) +_arguments "${_arguments_options[@]}" \ +'-q+[Set the lossy encoding quality (1-100)]' \ +'--quality=[Set the lossy encoding quality (1-100)]' \ +'-l[Use lossless encoding]' \ +'--lossless[Use lossless encoding]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +":: :_menyoki__split__webp_commands" \ +"*::: :->webp" \ +&& ret=0 +case $state in + (webp) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:menyoki-split-webp-command-$line[1]:" + case $line[1] in + (out) +_arguments "${_arguments_options[@]}" \ +'-d+[Add formatted date/time to the file name]' \ +'--date=[Add formatted date/time to the file name]' \ +'-e[Always save the file with an extension]' \ +'--with-extension[Always save the file with an extension]' \ +'-t[Add Unix timestamp to the file name]' \ +'--timestamp[Add Unix timestamp to the file name]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +'::file -- Set the output file:_files' \ +&& ret=0 +;; +(save) +_arguments "${_arguments_options[@]}" \ +'-d+[Add formatted date/time to the file name]' \ +'--date=[Add formatted date/time to the file name]' \ +'-e[Always save the file with an extension]' \ +'--with-extension[Always save the file with an extension]' \ +'-t[Add Unix timestamp to the file name]' \ +'--timestamp[Add Unix timestamp to the file name]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +'::file -- Set the output file:_files' \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +'-h[Prints help information]' \ +'--help[Prints help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +&& ret=0 +;; + esac + ;; +esac +;; (bmp) _arguments "${_arguments_options[@]}" \ '-h[Print help information]' \ @@ -992,6 +1053,67 @@ _arguments "${_arguments_options[@]}" \ ;; esac ;; +(webp) +_arguments "${_arguments_options[@]}" \ +'-q+[Set the lossy encoding quality (1-100)]' \ +'--quality=[Set the lossy encoding quality (1-100)]' \ +'-l[Use lossless encoding]' \ +'--lossless[Use lossless encoding]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +":: :_menyoki__split__webp_commands" \ +"*::: :->webp" \ +&& ret=0 +case $state in + (webp) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:menyoki-split-webp-command-$line[1]:" + case $line[1] in + (out) +_arguments "${_arguments_options[@]}" \ +'-d+[Add formatted date/time to the file name]' \ +'--date=[Add formatted date/time to the file name]' \ +'-e[Always save the file with an extension]' \ +'--with-extension[Always save the file with an extension]' \ +'-t[Add Unix timestamp to the file name]' \ +'--timestamp[Add Unix timestamp to the file name]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +'::file -- Set the output file:_files' \ +&& ret=0 +;; +(save) +_arguments "${_arguments_options[@]}" \ +'-d+[Add formatted date/time to the file name]' \ +'--date=[Add formatted date/time to the file name]' \ +'-e[Always save the file with an extension]' \ +'--with-extension[Always save the file with an extension]' \ +'-t[Add Unix timestamp to the file name]' \ +'--timestamp[Add Unix timestamp to the file name]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +'::file -- Set the output file:_files' \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +'-h[Prints help information]' \ +'--help[Prints help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +&& ret=0 +;; + esac + ;; +esac +;; (bmp) _arguments "${_arguments_options[@]}" \ '-h[Print help information]' \ @@ -1751,6 +1873,67 @@ _arguments "${_arguments_options[@]}" \ ;; esac ;; +(webp) +_arguments "${_arguments_options[@]}" \ +'-q+[Set the lossy encoding quality (1-100)]' \ +'--quality=[Set the lossy encoding quality (1-100)]' \ +'-l[Use lossless encoding]' \ +'--lossless[Use lossless encoding]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +":: :_menyoki__capture__webp_commands" \ +"*::: :->webp" \ +&& ret=0 +case $state in + (webp) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:menyoki-capture-webp-command-$line[1]:" + case $line[1] in + (out) +_arguments "${_arguments_options[@]}" \ +'-d+[Add formatted date/time to the file name]' \ +'--date=[Add formatted date/time to the file name]' \ +'-e[Always save the file with an extension]' \ +'--with-extension[Always save the file with an extension]' \ +'-t[Add Unix timestamp to the file name]' \ +'--timestamp[Add Unix timestamp to the file name]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +'::file -- Set the output file:_files' \ +&& ret=0 +;; +(save) +_arguments "${_arguments_options[@]}" \ +'-d+[Add formatted date/time to the file name]' \ +'--date=[Add formatted date/time to the file name]' \ +'-e[Always save the file with an extension]' \ +'--with-extension[Always save the file with an extension]' \ +'-t[Add Unix timestamp to the file name]' \ +'--timestamp[Add Unix timestamp to the file name]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +'::file -- Set the output file:_files' \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +'-h[Prints help information]' \ +'--help[Prints help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +&& ret=0 +;; + esac + ;; +esac +;; (bmp) _arguments "${_arguments_options[@]}" \ '-h[Print help information]' \ @@ -2360,6 +2543,67 @@ _arguments "${_arguments_options[@]}" \ ;; esac ;; +(webp) +_arguments "${_arguments_options[@]}" \ +'-q+[Set the lossy encoding quality (1-100)]' \ +'--quality=[Set the lossy encoding quality (1-100)]' \ +'-l[Use lossless encoding]' \ +'--lossless[Use lossless encoding]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +":: :_menyoki__capture__webp_commands" \ +"*::: :->webp" \ +&& ret=0 +case $state in + (webp) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:menyoki-capture-webp-command-$line[1]:" + case $line[1] in + (out) +_arguments "${_arguments_options[@]}" \ +'-d+[Add formatted date/time to the file name]' \ +'--date=[Add formatted date/time to the file name]' \ +'-e[Always save the file with an extension]' \ +'--with-extension[Always save the file with an extension]' \ +'-t[Add Unix timestamp to the file name]' \ +'--timestamp[Add Unix timestamp to the file name]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +'::file -- Set the output file:_files' \ +&& ret=0 +;; +(save) +_arguments "${_arguments_options[@]}" \ +'-d+[Add formatted date/time to the file name]' \ +'--date=[Add formatted date/time to the file name]' \ +'-e[Always save the file with an extension]' \ +'--with-extension[Always save the file with an extension]' \ +'-t[Add Unix timestamp to the file name]' \ +'--timestamp[Add Unix timestamp to the file name]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +'::file -- Set the output file:_files' \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +'-h[Prints help information]' \ +'--help[Prints help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +&& ret=0 +;; + esac + ;; +esac +;; (bmp) _arguments "${_arguments_options[@]}" \ '-h[Print help information]' \ @@ -2969,6 +3213,67 @@ _arguments "${_arguments_options[@]}" \ ;; esac ;; +(webp) +_arguments "${_arguments_options[@]}" \ +'-q+[Set the lossy encoding quality (1-100)]' \ +'--quality=[Set the lossy encoding quality (1-100)]' \ +'-l[Use lossless encoding]' \ +'--lossless[Use lossless encoding]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +":: :_menyoki__capture__webp_commands" \ +"*::: :->webp" \ +&& ret=0 +case $state in + (webp) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:menyoki-capture-webp-command-$line[1]:" + case $line[1] in + (out) +_arguments "${_arguments_options[@]}" \ +'-d+[Add formatted date/time to the file name]' \ +'--date=[Add formatted date/time to the file name]' \ +'-e[Always save the file with an extension]' \ +'--with-extension[Always save the file with an extension]' \ +'-t[Add Unix timestamp to the file name]' \ +'--timestamp[Add Unix timestamp to the file name]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +'::file -- Set the output file:_files' \ +&& ret=0 +;; +(save) +_arguments "${_arguments_options[@]}" \ +'-d+[Add formatted date/time to the file name]' \ +'--date=[Add formatted date/time to the file name]' \ +'-e[Always save the file with an extension]' \ +'--with-extension[Always save the file with an extension]' \ +'-t[Add Unix timestamp to the file name]' \ +'--timestamp[Add Unix timestamp to the file name]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +'::file -- Set the output file:_files' \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +'-h[Prints help information]' \ +'--help[Prints help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +&& ret=0 +;; + esac + ;; +esac +;; (bmp) _arguments "${_arguments_options[@]}" \ '-h[Print help information]' \ @@ -3713,6 +4018,67 @@ _arguments "${_arguments_options[@]}" \ ;; esac ;; +(webp) +_arguments "${_arguments_options[@]}" \ +'-q+[Set the lossy encoding quality (1-100)]' \ +'--quality=[Set the lossy encoding quality (1-100)]' \ +'-l[Use lossless encoding]' \ +'--lossless[Use lossless encoding]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +":: :_menyoki__edit__webp_commands" \ +"*::: :->webp" \ +&& ret=0 +case $state in + (webp) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:menyoki-edit-webp-command-$line[1]:" + case $line[1] in + (out) +_arguments "${_arguments_options[@]}" \ +'-d+[Add formatted date/time to the file name]' \ +'--date=[Add formatted date/time to the file name]' \ +'-e[Always save the file with an extension]' \ +'--with-extension[Always save the file with an extension]' \ +'-t[Add Unix timestamp to the file name]' \ +'--timestamp[Add Unix timestamp to the file name]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +'::file -- Set the output file:_files' \ +&& ret=0 +;; +(save) +_arguments "${_arguments_options[@]}" \ +'-d+[Add formatted date/time to the file name]' \ +'--date=[Add formatted date/time to the file name]' \ +'-e[Always save the file with an extension]' \ +'--with-extension[Always save the file with an extension]' \ +'-t[Add Unix timestamp to the file name]' \ +'--timestamp[Add Unix timestamp to the file name]' \ +'-h[Print help information]' \ +'--help[Print help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +'::file -- Set the output file:_files' \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +'-h[Prints help information]' \ +'--help[Prints help information]' \ +'-V[Prints version information]' \ +'--version[Prints version information]' \ +&& ret=0 +;; + esac + ;; +esac +;; (bmp) _arguments "${_arguments_options[@]}" \ '-h[Print help information]' \ @@ -4382,6 +4748,7 @@ _menyoki__capture_commands() { local commands; commands=( "png:Use the PNG encoder" \ "jpg:Use the JPG encoder" \ +"webp:Use the WebP encoder" \ "bmp:Use the BMP encoder" \ "ico:Use the ICO encoder" \ "tiff:Use the TIFF encoder" \ @@ -4409,6 +4776,7 @@ _menyoki__edit_commands() { "apng:Use the APNG encoder" \ "png:Use the PNG encoder" \ "jpg:Use the JPG encoder" \ +"webp:Use the WebP encoder" \ "bmp:Use the BMP encoder" \ "ico:Use the ICO encoder" \ "tiff:Use the TIFF encoder" \ @@ -4450,6 +4818,7 @@ _extract_commands() { local commands; commands=( "png:Use the PNG encoder" \ "jpg:Use the JPG encoder" \ +"webp:Use the WebP encoder" \ "bmp:Use the BMP encoder" \ "ico:Use the ICO encoder" \ "tiff:Use the TIFF encoder" \ @@ -4579,6 +4948,13 @@ _menyoki__capture__tiff__help_commands() { ) _describe -t commands 'menyoki capture tiff help commands' commands "$@" } +(( $+functions[_menyoki__capture__webp__help_commands] )) || +_menyoki__capture__webp__help_commands() { + local commands; commands=( + + ) + _describe -t commands 'menyoki capture webp help commands' commands "$@" +} (( $+functions[_menyoki__edit__apng__help_commands] )) || _menyoki__edit__apng__help_commands() { local commands; commands=( @@ -4663,6 +5039,13 @@ _menyoki__edit__tiff__help_commands() { ) _describe -t commands 'menyoki edit tiff help commands' commands "$@" } +(( $+functions[_menyoki__edit__webp__help_commands] )) || +_menyoki__edit__webp__help_commands() { + local commands; commands=( + + ) + _describe -t commands 'menyoki edit webp help commands' commands "$@" +} (( $+functions[_menyoki__help_commands] )) || _menyoki__help_commands() { local commands; commands=( @@ -4768,6 +5151,13 @@ _menyoki__split__tiff__help_commands() { ) _describe -t commands 'menyoki split tiff help commands' commands "$@" } +(( $+functions[_menyoki__split__webp__help_commands] )) || +_menyoki__split__webp__help_commands() { + local commands; commands=( + + ) + _describe -t commands 'menyoki split webp help commands' commands "$@" +} (( $+functions[_menyoki__capture__ico_commands] )) || _menyoki__capture__ico_commands() { local commands; commands=( @@ -4916,6 +5306,13 @@ _menyoki__capture__tiff__out_commands() { ) _describe -t commands 'menyoki capture tiff out commands' commands "$@" } +(( $+functions[_menyoki__capture__webp__out_commands] )) || +_menyoki__capture__webp__out_commands() { + local commands; commands=( + + ) + _describe -t commands 'menyoki capture webp out commands' commands "$@" +} (( $+functions[_menyoki__edit__apng__out_commands] )) || _menyoki__edit__apng__out_commands() { local commands; commands=( @@ -5000,6 +5397,13 @@ _menyoki__edit__tiff__out_commands() { ) _describe -t commands 'menyoki edit tiff out commands' commands "$@" } +(( $+functions[_menyoki__edit__webp__out_commands] )) || +_menyoki__edit__webp__out_commands() { + local commands; commands=( + + ) + _describe -t commands 'menyoki edit webp out commands' commands "$@" +} (( $+functions[_menyoki__make__out_commands] )) || _menyoki__make__out_commands() { local commands; commands=( @@ -5105,6 +5509,13 @@ _menyoki__split__tiff__out_commands() { ) _describe -t commands 'menyoki split tiff out commands' commands "$@" } +(( $+functions[_menyoki__split__webp__out_commands] )) || +_menyoki__split__webp__out_commands() { + local commands; commands=( + + ) + _describe -t commands 'menyoki split webp out commands' commands "$@" +} (( $+functions[_menyoki__capture__png_commands] )) || _menyoki__capture__png_commands() { local commands; commands=( @@ -5240,6 +5651,13 @@ _menyoki__capture__tiff__save_commands() { ) _describe -t commands 'menyoki capture tiff save commands' commands "$@" } +(( $+functions[_menyoki__capture__webp__save_commands] )) || +_menyoki__capture__webp__save_commands() { + local commands; commands=( + + ) + _describe -t commands 'menyoki capture webp save commands' commands "$@" +} (( $+functions[_menyoki__edit__apng__save_commands] )) || _menyoki__edit__apng__save_commands() { local commands; commands=( @@ -5324,6 +5742,13 @@ _menyoki__edit__tiff__save_commands() { ) _describe -t commands 'menyoki edit tiff save commands' commands "$@" } +(( $+functions[_menyoki__edit__webp__save_commands] )) || +_menyoki__edit__webp__save_commands() { + local commands; commands=( + + ) + _describe -t commands 'menyoki edit webp save commands' commands "$@" +} (( $+functions[_menyoki__make__save_commands] )) || _menyoki__make__save_commands() { local commands; commands=( @@ -5422,11 +5847,19 @@ _menyoki__split__tiff__save_commands() { ) _describe -t commands 'menyoki split tiff save commands' commands "$@" } +(( $+functions[_menyoki__split__webp__save_commands] )) || +_menyoki__split__webp__save_commands() { + local commands; commands=( + + ) + _describe -t commands 'menyoki split webp save commands' commands "$@" +} (( $+functions[_screenshot_commands] )) || _screenshot_commands() { local commands; commands=( "png:Use the PNG encoder" \ "jpg:Use the JPG encoder" \ +"webp:Use the WebP encoder" \ "bmp:Use the BMP encoder" \ "ico:Use the ICO encoder" \ "tiff:Use the TIFF encoder" \ @@ -5444,6 +5877,7 @@ _menyoki__split_commands() { local commands; commands=( "png:Use the PNG encoder" \ "jpg:Use the JPG encoder" \ +"webp:Use the WebP encoder" \ "bmp:Use the BMP encoder" \ "ico:Use the ICO encoder" \ "tiff:Use the TIFF encoder" \ @@ -5461,6 +5895,7 @@ _ss_commands() { local commands; commands=( "png:Use the PNG encoder" \ "jpg:Use the JPG encoder" \ +"webp:Use the WebP encoder" \ "bmp:Use the BMP encoder" \ "ico:Use the ICO encoder" \ "tiff:Use the TIFF encoder" \ @@ -5528,5 +5963,29 @@ _menyoki__view_commands() { ) _describe -t commands 'menyoki view commands' commands "$@" } +(( $+functions[_menyoki__capture__webp_commands] )) || +_menyoki__capture__webp_commands() { + local commands; commands=( + "save:Save the output file(s)" \ +"help:Prints this message or the help of the given subcommand(s)" \ + ) + _describe -t commands 'menyoki capture webp commands' commands "$@" +} +(( $+functions[_menyoki__edit__webp_commands] )) || +_menyoki__edit__webp_commands() { + local commands; commands=( + "save:Save the output file(s)" \ +"help:Prints this message or the help of the given subcommand(s)" \ + ) + _describe -t commands 'menyoki edit webp commands' commands "$@" +} +(( $+functions[_menyoki__split__webp_commands] )) || +_menyoki__split__webp_commands() { + local commands; commands=( + "save:Save the output file(s)" \ +"help:Prints this message or the help of the given subcommand(s)" \ + ) + _describe -t commands 'menyoki split webp commands' commands "$@" +} _menyoki "$@" \ No newline at end of file diff --git a/config/menyoki.conf b/config/menyoki.conf index f9d6f9a..9b33b93 100644 --- a/config/menyoki.conf +++ b/config/menyoki.conf @@ -201,6 +201,12 @@ filter = sub # Set the image quality (1-100) quality = 90 +[webp] +# Set the lossy encoding quality (1-100) +quality = 80 +# Use lossless encoding +lossless = false + [pnm] # Set the PNM format [bitmap, graymap, pixmap, arbitrary] format = pixmap diff --git a/man/menyoki.1 b/man/menyoki.1 index 2d83128..e09c694 100644 --- a/man/menyoki.1 +++ b/man/menyoki.1 @@ -275,6 +275,7 @@ ARGS: SUBCOMMANDS: png Use the PNG encoder jpg Use the JPG encoder + webp Use the WebP encoder bmp Use the BMP encoder ico Use the ICO encoder tiff Use the TIFF encoder @@ -425,6 +426,7 @@ ARGS: SUBCOMMANDS: png Use the PNG encoder jpg Use the JPG encoder + webp Use the WebP encoder bmp Use the BMP encoder ico Use the ICO encoder tiff Use the TIFF encoder @@ -483,6 +485,11 @@ T}@T{ Screenshot and encode with the specified JPEG options T} T{ +\f[C]menyoki capture webp --lossless\f[R] +T}@T{ +Screenshot and encode with the specified WEBP options +T} +T{ \f[C]menyoki capture pnm --format pixmap --encoding ascii\f[R] T}@T{ Screenshot and encode with the specified PNM options @@ -545,6 +552,7 @@ SUBCOMMANDS: apng Use the APNG encoder png Use the PNG encoder jpg Use the JPG encoder + webp Use the WebP encoder bmp Use the BMP encoder ico Use the ICO encoder tiff Use the TIFF encoder @@ -827,6 +835,21 @@ FLAGS: OPTIONS: -q, --quality Set the image quality (1-100) [default: 90] +SUBCOMMANDS: + save Save the output file(s) +\f[R] +.fi +.SS WEBP Subcommand +.IP +.nf +\f[C] +FLAGS: + -l, --lossless Use lossless encoding + -h, --help Print help information + +OPTIONS: + -q, --quality Set the lossy encoding quality (1-100) [default: 80] + SUBCOMMANDS: save Save the output file(s) \f[R] diff --git a/man/menyoki.conf.5 b/man/menyoki.conf.5 index 4d16385..b015f0b 100644 --- a/man/menyoki.conf.5 +++ b/man/menyoki.conf.5 @@ -304,6 +304,14 @@ Options that belong to the [jpg] section. .TP .B quality Set the image quality (1-100) [default: 90] +.SH WEBP +Options that belong to the [webp] section. +.TP +.B quality +Set the lossy encoding quality (1-100) [default: 80] +.TP +.B lossless +Use lossless encoding .SH PNM Options that belong to the [pnm] section. .TP diff --git a/src/app.rs b/src/app.rs index c2a20b5..817d16b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -25,6 +25,7 @@ use image::codecs::png::PngEncoder; use image::codecs::pnm::{PnmEncoder, PnmSubtype}; use image::codecs::tga::TgaEncoder; use image::codecs::tiff::TiffEncoder; +use image::codecs::webp::WebPEncoder; use image::error::{ ImageError, ImageFormatHint, UnsupportedError, UnsupportedErrorKind, }; @@ -420,6 +421,14 @@ where ), ExtendedColorType::Rgb8, ), + FileFormat::WebP => self.save_image( + image, + WebPEncoder::new_with_quality( + &mut output, + self.settings.webp.get_quality(), + ), + ExtendedColorType::Rgb8, + ), FileFormat::Bmp => self.save_image( image, BmpEncoder::new(&mut output), diff --git a/src/args/mod.rs b/src/args/mod.rs index a69ba71..b2f9099 100644 --- a/src/args/mod.rs +++ b/src/args/mod.rs @@ -752,6 +752,29 @@ where Self::get_save_args(FileFormat::Jpg).settings(&save_settings), ), ) + .subcommand( + SubCommand::with_name("webp") + .about("Use the WebP encoder") + .help_message("Print help information") + .arg( + Arg::with_name("quality") + .short("q") + .long("quality") + .value_name("QUALITY") + .default_value("80") + .help("Set the lossy encoding quality (1-100)") + .takes_value(true), + ) + .arg( + Arg::with_name("losless") + .short("l") + .long("lossless") + .help("Use lossless encoding"), + ) + .subcommand( + Self::get_save_args(FileFormat::WebP).settings(&save_settings), + ), + ) .subcommand( SubCommand::with_name("bmp") .about("Use the BMP encoder") diff --git a/src/file/format.rs b/src/file/format.rs index addc736..7393c83 100644 --- a/src/file/format.rs +++ b/src/file/format.rs @@ -12,6 +12,7 @@ pub enum FileFormat { Apng, Png, Jpg, + WebP, Bmp, Ico, Tiff, @@ -38,6 +39,7 @@ impl FromStr for FileFormat { "apng" => Ok(Self::Apng), "png" => Ok(Self::Png), "jpg" => Ok(Self::Jpg), + "webp" => Ok(Self::WebP), "bmp" => Ok(Self::Bmp), "ico" => Ok(Self::Ico), "tiff" => Ok(Self::Tiff), @@ -103,6 +105,8 @@ impl FileFormat { Self::Ico } else if matches.is_present("jpg") { Self::Jpg + } else if matches.is_present("webp") { + Self::WebP } else { Self::Png } diff --git a/src/file/mod.rs b/src/file/mod.rs index dd93c6a..d7e12e5 100644 --- a/src/file/mod.rs +++ b/src/file/mod.rs @@ -115,7 +115,9 @@ mod tests { use pretty_assertions::assert_eq; #[test] fn test_file() { - for format in &["png", "jpg", "bmp", "ico", "tiff", "tga", "pnm", "ff"] { + for format in &[ + "png", "jpg", "webp", "bmp", "ico", "tiff", "tga", "pnm", "ff", + ] { let args = App::new("test") .subcommand( SubCommand::with_name("capture") diff --git a/src/image/settings.rs b/src/image/settings.rs index c187136..8ae765d 100644 --- a/src/image/settings.rs +++ b/src/image/settings.rs @@ -2,6 +2,7 @@ use crate::args::matches::ArgMatches; use crate::args::parser::ArgParser; use image::codecs::png::{CompressionType, FilterType}; use image::codecs::pnm::{PnmSubtype, SampleEncoding}; +use image::codecs::webp::WebPQuality; /* PNG compression and filter settings */ #[derive(Clone, Copy, Debug)] @@ -122,6 +123,74 @@ impl JpgSettings { } } +/* WebP quality setting */ +#[derive(Clone, Copy, Debug)] +pub struct WebPSettings { + quality: Option, +} + +/* Default initialization values for WebPSettings */ +impl Default for WebPSettings { + fn default() -> Self { + Self { + quality: Some(WebPQuality::DEFAULT), + } + } +} + +impl WebPSettings { + /** + * Create a new WebPSettings object. + * + * @param quality + * @return WebPSettings + */ + pub fn new(quality: Option) -> Self { + Self { quality } + } + + /** + * Create a WebPQuality object from WebPSettings. + * + * @return WebPQuality + */ + pub fn get_quality(&self) -> WebPQuality { + match self.quality { + Some(quality) => WebPQuality::lossy(quality), + None => WebPQuality::lossless(), + } + } + + /** + * Create a new WebPSettings object from arguments. + * + * @param matches + * @return WebPSettings + */ + pub fn from_args(matches: &ArgMatches<'_>) -> Self { + Self::from_parser(ArgParser::from_subcommand(matches, "webp")) + } + + /** + * Create a WebPSettings object from an argument parser. + * + * @param parser + * @return WebPSettings + */ + fn from_parser(parser: ArgParser<'_>) -> Self { + match &parser.args { + Some(args) => { + if args.is_present("lossless") { + Self::new(None) + } else { + Self::new(Some(parser.parse("quality", WebPQuality::DEFAULT))) + } + } + None => Self::default(), + } + } +} + /* PNM subtype settings */ #[derive(Clone, Copy, Debug)] pub struct PnmSettings { @@ -239,6 +308,27 @@ mod tests { assert_eq!(90, JpgSettings::from_parser(ArgParser::new(None)).quality); } #[test] + fn test_webp_settings() { + let args = App::new("test") + .arg(Arg::with_name("quality").long("quality").takes_value(true)) + .get_matches_from(vec!["test", "--quality", "20"]); + assert_eq!( + Some(20), + WebPSettings::from_parser(ArgParser::from_args(&args)).quality + ); + assert_eq!( + Some(80), + WebPSettings::from_parser(ArgParser::new(None)).quality + ); + let args = App::new("test") + .arg(Arg::with_name("lossless").long("lossless")) + .get_matches_from(vec!["test", "--lossless"]); + assert_eq!( + None, + WebPSettings::from_parser(ArgParser::from_args(&args)).quality + ); + } + #[test] fn test_pnm_settings() { let args = App::new("test") .arg(Arg::with_name("format").long("format").takes_value(true)) diff --git a/src/settings.rs b/src/settings.rs index 5396089..01be680 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -5,7 +5,7 @@ use crate::edit::settings::EditSettings; use crate::file::format::FileFormat; use crate::file::settings::SaveSettings; use crate::image::geometry::Geometry; -use crate::image::settings::{JpgSettings, PngSettings, PnmSettings}; +use crate::image::settings::{JpgSettings, PngSettings, PnmSettings, WebPSettings}; use crate::record::settings::{RecordSettings, RecordWindow}; use crate::util::keys::{ActionKeys, KeyType}; use crate::util::state::InputState; @@ -21,6 +21,7 @@ pub struct AppSettings<'a> { pub split: SplitSettings, pub png: PngSettings, pub jpg: JpgSettings, + pub webp: WebPSettings, pub pnm: PnmSettings, pub edit: EditSettings, pub analyze: AnalyzeSettings, @@ -52,6 +53,7 @@ impl<'a> AppSettings<'a> { split: SplitSettings::from_args(args), png: PngSettings::from_args(args), jpg: JpgSettings::from_args(args), + webp: WebPSettings::from_args(args), analyze: AnalyzeSettings::from_args(args, Self::get_color(args)), view: ViewSettings::from_args(args), pnm,