From 186371e1e47badae584e017cb7232c96e85df304 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Sat, 13 Jan 2024 14:15:51 +1100 Subject: [PATCH] examples: allow heif-enc to show params without needing input file --- examples/heif-enc.1 | 2 +- examples/heif_enc.cc | 32 +++++++++++++++----------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/examples/heif-enc.1 b/examples/heif-enc.1 index a2d59b9cf6..b7ee50bd2b 100644 --- a/examples/heif-enc.1 +++ b/examples/heif-enc.1 @@ -42,7 +42,7 @@ Output filename (optional). Enable logging output (more will increase logging level). .TP .BR \-P ", "\-\-params\fR -Show all encoder parameters. +Show all encoder parameters and exit. Input file is not required or used. .TP .BR \-b\fR\ \fIDEPTH\fR Bit-depth of generated HEIF file when using 16-bit PNG input (default: 10 bit). diff --git a/examples/heif_enc.cc b/examples/heif_enc.cc index 754f566379..86f9e548e2 100644 --- a/examples/heif_enc.cc +++ b/examples/heif_enc.cc @@ -155,7 +155,7 @@ void show_help(const char* argv0) << " --no-thumb-alpha do not save alpha channel in thumbnail image\n" << " -o, --output output filename (optional)\n" << " --verbose enable logging output (more will increase logging level)\n" - << " -P, --params show all encoder parameters\n" + << " -P, --params show all encoder parameters and exit, input file not required or used.\n" << " -b, --bit-depth # bit-depth of generated HEIF/AVIF file when using 16-bit PNG input (default: 10 bit)\n" << " -p set encoder parameter (NAME=VALUE)\n" << " -A, --avif encode as AVIF (not needed if output filename with .avif suffix is provided)\n" @@ -626,22 +626,6 @@ int main(int argc, char** argv) return 0; } - if (optind > argc - 1) { - show_help(argv[0]); - return 0; - } - - - // If we were given a list of filenames and no '-o' option, check whether the last filename is the desired output filename. - - if (output_filename.empty() && argc>1) { - if (guess_compression_format_from_filename(argv[argc-1]) != heif_compression_undefined) { - output_filename = argv[argc-1]; - argc--; - } - } - - // --- determine output compression format (from output filename or command line parameter) heif_compression_format compressionFormat; @@ -720,6 +704,20 @@ int main(int argc, char** argv) return 0; } + if (optind > argc - 1) { + show_help(argv[0]); + return 0; + } + + + // If we were given a list of filenames and no '-o' option, check whether the last filename is the desired output filename. + + if (output_filename.empty() && argc>1) { + if (guess_compression_format_from_filename(argv[argc-1]) != heif_compression_undefined) { + output_filename = argv[argc-1]; + argc--; + } + } struct heif_error error;