image_dec: add WebPGetEnabledInputFileFormats()

and use it to output the types supported in the examples

Change-Id: Ia6b8624a2146cf72c679129065a72f215644e1e9
This commit is contained in:
James Zern 2022-03-26 15:17:58 -07:00
parent 7a68afaac5
commit 617cf03656
5 changed files with 27 additions and 2 deletions

View File

@ -620,6 +620,7 @@ static void HelpLong(void) {
printf(" -af .................... auto-adjust filter strength\n"); printf(" -af .................... auto-adjust filter strength\n");
printf(" -pre <int> ............. pre-processing filter\n"); printf(" -pre <int> ............. pre-processing filter\n");
printf("\n"); printf("\n");
printf("Supported input formats:\n %s\n", WebPGetEnabledInputFileFormats());
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -65,6 +65,8 @@ static void Help(void) {
"arguments will be\n"); "arguments will be\n");
printf("tokenized from this file. The file name must not start with " printf("tokenized from this file. The file name must not start with "
"the character '-'.\n"); "the character '-'.\n");
printf("\nSupported input formats:\n %s\n",
WebPGetEnabledInputFileFormats());
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -186,7 +188,7 @@ int main(int argc, const char* argv[]) {
verbose = 1; verbose = 1;
} else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) { } else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
Help(); Help();
goto End; FREE_WARGV_AND_RETURN(0);
} else if (!strcmp(argv[c], "-version")) { } else if (!strcmp(argv[c], "-version")) {
const int enc_version = WebPGetEncoderVersion(); const int enc_version = WebPGetEncoderVersion();
const int mux_version = WebPGetMuxVersion(); const int mux_version = WebPGetMuxVersion();

View File

@ -223,7 +223,8 @@ static void Help(void) {
" -o <file> . save the diff map as a WebP lossless file\n" " -o <file> . save the diff map as a WebP lossless file\n"
" -scale .... scale the difference map to fit [0..255] range\n" " -scale .... scale the difference map to fit [0..255] range\n"
" -gray ..... use grayscale for difference map (-scale)\n" " -gray ..... use grayscale for difference map (-scale)\n"
" Also handles PNG, JPG and TIFF files, in addition to WebP.\n"); "\nSupported input formats:\n %s\n",
WebPGetEnabledInputFileFormats());
} }
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {

View File

@ -11,6 +11,24 @@
#include "./image_dec.h" #include "./image_dec.h"
const char* WebPGetEnabledInputFileFormats(void) {
return "WebP"
#ifdef WEBP_HAVE_JPEG
", JPEG"
#endif
#ifdef WEBP_HAVE_PNG
", PNG"
#endif
", PNM (PGM, PPM, PAM)"
#ifdef WEBP_HAVE_TIFF
", TIFF"
#endif
#ifdef HAVE_WINCODEC_H
", Windows Imaging Component (WIC)"
#endif
"";
}
static WEBP_INLINE uint32_t GetBE32(const uint8_t buf[]) { static WEBP_INLINE uint32_t GetBE32(const uint8_t buf[]) {
return ((uint32_t)buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; return ((uint32_t)buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
} }

View File

@ -41,6 +41,9 @@ typedef enum {
WEBP_UNSUPPORTED_FORMAT WEBP_UNSUPPORTED_FORMAT
} WebPInputFileFormat; } WebPInputFileFormat;
// Returns a comma separated list of enabled input formats.
const char* WebPGetEnabledInputFileFormats(void);
// Try to infer the image format. 'data_size' should be larger than 12. // Try to infer the image format. 'data_size' should be larger than 12.
// Returns WEBP_UNSUPPORTED_FORMAT if format can't be guess safely. // Returns WEBP_UNSUPPORTED_FORMAT if format can't be guess safely.
WebPInputFileFormat WebPGuessImageType(const uint8_t* const data, WebPInputFileFormat WebPGuessImageType(const uint8_t* const data,