History

avdevice/caca: Allow to list multiple dither option types at once

This can be achieved by using AV_OPT_TYPE_FLAGS instead of AV_OPT_TYPE_STRING. It also avoids strcmp() when accessing the option.

Andreas Rheinhardt committed 2 years ago

Commit e05d3c11 parent ed56ca81 file · +17 −17Browse files

Unified · Split

libavdevice/caca.c+17−17
@@ -24,6 +24,13 @@ · 23 unmodified lines
2424 #include "libavformat/mux.h"
2525 #include "avdevice.h"
2626
27+enum {
28+ LIST_ALGORITHMS = 1 << 0,
29+ LIST_ANTIALIASES = 1 << 1,
30+ LIST_CHARSETS = 1 << 2,
31+ LIST_COLORS = 1 << 3,
32+};
33+
2734 typedef struct CACAContext {
2835 AVClass *class;
2936 AVFormatContext *ctx;
@@ -38,7 +45,7 @@ typedef struct CACAContext { · 8 unmodified lines
3845 char *charset, *color;
3946 char *driver;
4047
41− char *list_dither;
48+ int list_dither;
4249 int list_drivers;
4350 } CACAContext;
4451
@@ -99,21 +106,14 @@ static int caca_write_header(AVFormatContext *s) · 54 unmodified lines
99106 return AVERROR_EXIT;
100107 }
101108 if (c->list_dither) {
102− if (!strcmp(c->list_dither, "colors")) {
109+ if (c->list_dither & LIST_COLORS)
103110 list_dither_color(c);
104− } else if (!strcmp(c->list_dither, "charsets")) {
111+ if (c->list_dither & LIST_CHARSETS)
105112 list_dither_charset(c);
106− } else if (!strcmp(c->list_dither, "algorithms")) {
113+ if (c->list_dither & LIST_ALGORITHMS)
107114 list_dither_algorithm(c);
108− } else if (!strcmp(c->list_dither, "antialiases")) {
115+ if (c->list_dither & LIST_ANTIALIASES)
109116 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− }
117117 return AVERROR_EXIT;
118118 }
119119
@@ -205,11 +205,11 @@ static const AVOption options[] = { · 85 unmodified lines
205205 { "charset", "set charset used to render output", OFFSET(charset), AV_OPT_TYPE_STRING, {.str = "default" }, 0, 0, ENC },
206206 { "color", "set color used to render output", OFFSET(color), AV_OPT_TYPE_STRING, {.str = "default" }, 0, 0, ENC },
207207 { "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" },
213213 { NULL },
214214 };
215215

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t