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
24#include "libavformat/mux.h"24#include "libavformat/mux.h"
25#include "avdevice.h"25#include "avdevice.h"
26 26
27enum {
28 LIST_ALGORITHMS = 1 << 0,
29 LIST_ANTIALIASES = 1 << 1,
30 LIST_CHARSETS = 1 << 2,
31 LIST_COLORS = 1 << 3,
32};
33
27typedef struct CACAContext {34typedef struct CACAContext {
28 AVClass *class;35 AVClass *class;
29 AVFormatContext *ctx;36 AVFormatContext *ctx;
@@ -38,7 +45,7 @@ typedef struct CACAContext { · 8 unmodified lines
38 char *charset, *color;45 char *charset, *color;
39 char *driver;46 char *driver;
40 47
41 char *list_dither;48 int list_dither;
42 int list_drivers;49 int list_drivers;
43} CACAContext;50} CACAContext;
44 51
@@ -99,21 +106,14 @@ static int caca_write_header(AVFormatContext *s) · 54 unmodified lines
99 return AVERROR_EXIT;106 return AVERROR_EXIT;
100 }107 }
101 if (c->list_dither) {108 if (c->list_dither) {
102 if (!strcmp(c->list_dither, "colors")) {109 if (c->list_dither & LIST_COLORS)
103 list_dither_color(c);110 list_dither_color(c);
104 } else if (!strcmp(c->list_dither, "charsets")) {111 if (c->list_dither & LIST_CHARSETS)
105 list_dither_charset(c);112 list_dither_charset(c);
106 } else if (!strcmp(c->list_dither, "algorithms")) {113 if (c->list_dither & LIST_ALGORITHMS)
107 list_dither_algorithm(c);114 list_dither_algorithm(c);
108 } else if (!strcmp(c->list_dither, "antialiases")) {115 if (c->list_dither & LIST_ANTIALIASES)
109 list_dither_antialias(c);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 return AVERROR_EXIT;117 return AVERROR_EXIT;
118 }118 }
119 119
@@ -205,11 +205,11 @@ static const AVOption options[] = { · 85 unmodified lines
205 { "charset", "set charset used to render output", OFFSET(charset), AV_OPT_TYPE_STRING, {.str = "default" }, 0, 0, ENC },205 { "charset", "set charset used to render output", OFFSET(charset), AV_OPT_TYPE_STRING, {.str = "default" }, 0, 0, ENC },
206 { "color", "set color used to render output", OFFSET(color), AV_OPT_TYPE_STRING, {.str = "default" }, 0, 0, ENC },206 { "color", "set color used to render output", OFFSET(color), AV_OPT_TYPE_STRING, {.str = "default" }, 0, 0, ENC },
207 { "list_drivers", "list available drivers", OFFSET(list_drivers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, ENC },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" },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, {.str = "algorithms"}, 0, 0, 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, {.str = "antialiases"},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, {.str = "charsets"}, 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, {.str = "colors"}, 0, 0, ENC, "list_dither" },212 { "colors", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = LIST_COLORS }, 0, 0, ENC, "list_dither" },
213 { NULL },213 { NULL },
214};214};
215 215

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