diff options
author | jiyong.min <jiyong.min@samsung.com> | 2022-12-02 12:23:48 +0900 |
---|---|---|
committer | jiyong.min <jiyong.min@samsung.com> | 2022-12-02 12:25:00 +0900 |
commit | 7fa2aaed0a5c855460b77fb1fedcc01591ff6470 (patch) | |
tree | d06014f551165519387ed1d3a2645ad24b90c3f1 /tools/args.h | |
parent | b8aee4491f6498d0cc17d18c80f6b3505e2a62ef (diff) | |
download | libjxl-7fa2aaed0a5c855460b77fb1fedcc01591ff6470.tar.gz libjxl-7fa2aaed0a5c855460b77fb1fedcc01591ff6470.tar.bz2 libjxl-7fa2aaed0a5c855460b77fb1fedcc01591ff6470.zip |
Imported Upstream version 0.7.0upstream/0.7.0
Change-Id: Ice1364b8cdf314cd19cc443865a3c02b7b0c1d5c
Diffstat (limited to 'tools/args.h')
-rw-r--r-- | tools/args.h | 78 |
1 files changed, 10 insertions, 68 deletions
diff --git a/tools/args.h b/tools/args.h index c05f37c..7d04ce3 100644 --- a/tools/args.h +++ b/tools/args.h @@ -8,13 +8,15 @@ // Helpers for parsing command line arguments. No include guard needed. +#include <inttypes.h> +#include <stdint.h> #include <stdio.h> #include <string.h> #include <string> #include <vector> -#include "lib/extras/color_hints.h" +#include "lib/extras/dec/color_hints.h" #include "lib/jxl/base/override.h" #include "lib/jxl/base/status.h" #include "lib/jxl/codec_in_out.h" // DecoderHints @@ -38,43 +40,6 @@ static inline bool ParseOverride(const char* arg, jxl::Override* out) { return JXL_FAILURE("Args"); } -static inline bool ParseUnsigned(const char* arg, size_t* out) { - char* end; - *out = static_cast<size_t>(strtoull(arg, &end, 0)); - if (end[0] != '\0') { - fprintf(stderr, "Unable to interpret as unsigned integer: %s.\n", arg); - return JXL_FAILURE("Args"); - } - return true; -} - -static inline bool ParseUint32(const char* arg, uint32_t* out) { - size_t value = 0; - bool ret = ParseUnsigned(arg, &value); - if (ret) *out = value; - return ret; -} - -static inline bool ParseSigned(const char* arg, int* out) { - char* end; - *out = static_cast<int>(strtol(arg, &end, 0)); - if (end[0] != '\0') { - fprintf(stderr, "Unable to interpret as signed integer: %s.\n", arg); - return JXL_FAILURE("Args"); - } - return true; -} - -static inline bool ParseFloat(const char* arg, float* out) { - char* end; - *out = static_cast<float>(strtod(arg, &end)); - if (end[0] != '\0') { - fprintf(stderr, "Unable to interpret as float: %s.\n", arg); - return JXL_FAILURE("Args"); - } - return true; -} - static inline bool ParseFloatPair(const char* arg, std::pair<float, float>* out) { int parsed = sscanf(arg, "%f,%f", &out->first, &out->second); @@ -89,18 +54,8 @@ static inline bool ParseFloatPair(const char* arg, return true; } -static inline bool ParseDouble(const char* arg, double* out) { - char* end; - *out = static_cast<double>(strtod(arg, &end)); - if (end[0] != '\0') { - fprintf(stderr, "Unable to interpret as double: %s.\n", arg); - return JXL_FAILURE("Args"); - } - return true; -} - static inline bool ParseAndAppendKeyValue(const char* arg, - jxl::ColorHints* out) { + jxl::extras::ColorHints* out) { const char* eq = strchr(arg, '='); if (!eq) { fprintf(stderr, "Expected argument as 'key=value' but received '%s'\n", @@ -114,40 +69,27 @@ static inline bool ParseAndAppendKeyValue(const char* arg, static inline bool ParsePredictor(const char* arg, jxl::Predictor* out) { char* end; - size_t p = static_cast<size_t>(strtoull(arg, &end, 0)); + uint64_t p = static_cast<uint64_t>(strtoull(arg, &end, 0)); if (end[0] != '\0') { fprintf(stderr, "Invalid predictor: %s.\n", arg); return JXL_FAILURE("Args"); } - if (p >= jxl::kNumModularPredictors) { - fprintf(stderr, "Invalid predictor value %zu, must be less than %zu.\n", p, - jxl::kNumModularPredictors); + if (p >= jxl::kNumModularEncoderPredictors) { + fprintf(stderr, + "Invalid predictor value %" PRIu64 ", must be less than %" PRIu64 + ".\n", + p, static_cast<uint64_t>(jxl::kNumModularEncoderPredictors)); return JXL_FAILURE("Args"); } *out = static_cast<jxl::Predictor>(p); return true; } -static inline bool ParseString(const char* arg, std::string* out) { - out->assign(arg); - return true; -} - static inline bool ParseCString(const char* arg, const char** out) { *out = arg; return true; } -static inline bool SetBooleanTrue(bool* out) { - *out = true; - return true; -} - -static inline bool SetBooleanFalse(bool* out) { - *out = false; - return true; -} - static inline bool IncrementUnsigned(size_t* out) { (*out)++; return true; |