File: program_command.cc

package info (click to toggle)
libavif 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,648 kB
  • sloc: ansic: 30,743; cpp: 14,606; xml: 1,507; sh: 1,296; java: 307; makefile: 57
file content (112 lines) | stat: -rw-r--r-- 3,602 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "program_command.h"

#include <vector>

namespace avif {

ProgramCommand::ProgramCommand(const std::string& name,
                               const std::string& short_description,
                               const std::string& long_description)
    : argparse_(argparse::ArgumentParser(
          "avifgainmaputil " + name,
          short_description + ".\n" + long_description)),
      name_(name),
      short_description_(short_description) {}

// Parses command line arguments. Should be called before Run().
avifResult ProgramCommand::ParseArgs(int argc, const char* const argv[]) {
  argparse_.parse_args(argc, argv);
  return AVIF_RESULT_OK;
}

// Prints this command's help on stdout.
void ProgramCommand::PrintUsage() { argparse_.print_help(); }

argparse::ConvertedValue<int> PixelFormatConverter::from_str(
    const std::string& str) {
  argparse::ConvertedValue<int> converted_value;

  if (str == "444") {
    converted_value.set_value(AVIF_PIXEL_FORMAT_YUV444);
  } else if (str == "422") {
    converted_value.set_value(AVIF_PIXEL_FORMAT_YUV422);
  } else if (str == "420") {
    converted_value.set_value(AVIF_PIXEL_FORMAT_YUV420);
  } else if (str == "400") {
    converted_value.set_value(AVIF_PIXEL_FORMAT_YUV400);
  } else {
    converted_value.set_error("Invalid argument value");
  }
  return converted_value;
}

std::vector<std::string> PixelFormatConverter::default_choices() {
  return {"444", "422", "420", "400"};
}

argparse::ConvertedValue<CicpValues> CicpConverter::from_str(
    const std::string& str) {
  argparse::ConvertedValue<CicpValues> converted_value;

  std::vector<uint32_t> cicp_values;
  if (!ParseList(str, '/', 3, &cicp_values)) {
    converted_value.set_error(
        "Invalid CICP values, expected format: P/T/M where each "
        "value is a positive integer, got: " +
        str);
    return converted_value;
  }

  CicpValues cicp = {};
  cicp.color_primaries = (avifColorPrimaries)cicp_values[0];
  cicp.transfer_characteristics = (avifTransferCharacteristics)cicp_values[1];
  cicp.matrix_coefficients = (avifMatrixCoefficients)cicp_values[2];
  converted_value.set_value(cicp);

  return converted_value;
}

std::vector<std::string> CicpConverter::default_choices() { return {}; }

argparse::ConvertedValue<avifContentLightLevelInformationBox>
ClliConverter::from_str(const std::string& str) {
  argparse::ConvertedValue<avifContentLightLevelInformationBox> converted_value;

  std::vector<uint16_t> clli;
  if (!ParseList(str, ',', 2, &clli)) {
    converted_value.set_error(
        "Invalid CLLI values, expected format: maxCLL,maxPALL where "
        "both maxCLL and maxPALL are positive integers, got: " +
        str);
    return converted_value;
  }
  avifContentLightLevelInformationBox clli_box = {};
  clli_box.maxCLL = clli[0];
  clli_box.maxPALL = clli[1];
  converted_value.set_value(clli_box);

  return converted_value;
}

std::vector<std::string> ClliConverter::default_choices() { return {}; }

argparse::ConvertedValue<GridOptions> GridOptionsConverter::from_str(
    const std::string& str) {
  argparse::ConvertedValue<GridOptions> converted_value;

  std::vector<int> grid_dims;
  if (!ParseList(str, 'x', 2, &grid_dims) || grid_dims[0] <= 0 ||
      grid_dims[1] <= 0) {
    converted_value.set_error("Invalid grid dimensions: " + str);
    return converted_value;
  }
  GridOptions grid_options = {grid_dims[0], grid_dims[1]};

  converted_value.set_value(grid_options);

  return converted_value;
}

std::vector<std::string> GridOptionsConverter::default_choices() { return {}; }

}  // namespace avif