This can be achieved by using AV_OPT_TYPE_FLAGS instead of AV_OPT_TYPE_STRING. It also avoids strcmp() when accessing the option.
Unified · Split
| @@ -24,6 +24,13 @@ · 23 unmodified lines | ||
| 24 | 24 | #include "libavformat/mux.h" |
| 25 | 25 | #include "avdevice.h" |
| 26 | 26 | |
| 27 | +enum { | |
| 28 | + LIST_ALGORITHMS = 1 << 0, | |
| 29 | + LIST_ANTIALIASES = 1 << 1, | |
| 30 | + LIST_CHARSETS = 1 << 2, | |
| 31 | + LIST_COLORS = 1 << 3, | |
| 32 | +}; | |
| 33 | + | |
| 27 | 34 | typedef struct CACAContext { |
| 28 | 35 | AVClass *class; |
| 29 | 36 | AVFormatContext *ctx; |
| @@ -38,7 +45,7 @@ typedef struct CACAContext { · 8 unmodified lines | ||
| 38 | 45 | char *charset, *color; |
| 39 | 46 | char *driver; |
| 40 | 47 | |
| 41 | − char *list_dither; | |
| 48 | + int list_dither; | |
| 42 | 49 | int list_drivers; |
| 43 | 50 | } CACAContext; |
| 44 | 51 | |
| @@ -99,21 +106,14 @@ static int caca_write_header(AVFormatContext *s) · 54 unmodified lines | ||
| 99 | 106 | return AVERROR_EXIT; |
| 100 | 107 | } |
| 101 | 108 | if (c->list_dither) { |
| 102 | − if (!strcmp(c->list_dither, "colors")) { | |
| 109 | + if (c->list_dither & LIST_COLORS) | |
| 103 | 110 | list_dither_color(c); |
| 104 | − } else if (!strcmp(c->list_dither, "charsets")) { | |
| 111 | + if (c->list_dither & LIST_CHARSETS) | |
| 105 | 112 | list_dither_charset(c); |
| 106 | − } else if (!strcmp(c->list_dither, "algorithms")) { | |
| 113 | + if (c->list_dither & LIST_ALGORITHMS) | |
| 107 | 114 | list_dither_algorithm(c); |
| 108 | − } else if (!strcmp(c->list_dither, "antialiases")) { | |
| 115 | + if (c->list_dither & LIST_ANTIALIASES) | |
| 109 | 116 | list_dither_antialias(c); |
| 110 | − } else { | |
| 111 | − av_log(s, AV_LOG_ERROR, | |
| 112 | − "Invalid argument '%s', for 'list_dither' option\n" | |
| 113 | − "Argument must be one of 'algorithms, 'antialiases', 'charsets', 'colors'\n", | |
| 114 | − c->list_dither); | |
| 115 | − return AVERROR(EINVAL); | |
| 116 | − } | |
| 117 | 117 | return AVERROR_EXIT; |
| 118 | 118 | } |
| 119 | 119 | |
| @@ -205,11 +205,11 @@ static const AVOption options[] = { · 85 unmodified lines | ||
| 205 | 205 | { "charset", "set charset used to render output", OFFSET(charset), AV_OPT_TYPE_STRING, {.str = "default" }, 0, 0, ENC }, |
| 206 | 206 | { "color", "set color used to render output", OFFSET(color), AV_OPT_TYPE_STRING, {.str = "default" }, 0, 0, ENC }, |
| 207 | 207 | { "list_drivers", "list available drivers", OFFSET(list_drivers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, ENC }, |
| 208 | − { "list_dither", "list available dither options", OFFSET(list_dither), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 1, ENC, "list_dither" }, | |
| 209 | − { "algorithms", NULL, 0, AV_OPT_TYPE_CONST, {.str = "algorithms"}, 0, 0, ENC, "list_dither" }, | |
| 210 | − { "antialiases", NULL, 0, AV_OPT_TYPE_CONST, {.str = "antialiases"},0, 0, ENC, "list_dither" }, | |
| 211 | − { "charsets", NULL, 0, AV_OPT_TYPE_CONST, {.str = "charsets"}, 0, 0, ENC, "list_dither" }, | |
| 212 | − { "colors", NULL, 0, AV_OPT_TYPE_CONST, {.str = "colors"}, 0, 0, ENC, "list_dither" }, | |
| 208 | + { "list_dither", "list available dither options", OFFSET(list_dither), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, INT_MAX, ENC, "list_dither" }, | |
| 209 | + { "algorithms", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = LIST_ALGORITHMS }, 0, 0, ENC, "list_dither" }, | |
| 210 | + { "antialiases", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = LIST_ANTIALIASES }, 0, 0, ENC, "list_dither" }, | |
| 211 | + { "charsets", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = LIST_CHARSETS }, 0, 0, ENC, "list_dither" }, | |
| 212 | + { "colors", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = LIST_COLORS }, 0, 0, ENC, "list_dither" }, | |
| 213 | 213 | { NULL }, |
| 214 | 214 | }; |
| 215 | 215 | |