Skip to content

Commit

Permalink
avdevice/caca: Allow to list multiple dither option types at once
Browse files Browse the repository at this point in the history
This can be achieved by using AV_OPT_TYPE_FLAGS instead of
AV_OPT_TYPE_STRING. It also avoids strcmp() when accessing
the option.

Reviewed-by: Stefano Sabatini <stefasab@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
  • Loading branch information
mkver committed Feb 7, 2024
1 parent ed56ca8 commit e05d3c1
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions libavdevice/caca.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
#include "libavformat/mux.h"
#include "avdevice.h"

enum {
LIST_ALGORITHMS = 1 << 0,
LIST_ANTIALIASES = 1 << 1,
LIST_CHARSETS = 1 << 2,
LIST_COLORS = 1 << 3,
};

typedef struct CACAContext {
AVClass *class;
AVFormatContext *ctx;
Expand All @@ -38,7 +45,7 @@ typedef struct CACAContext {
char *charset, *color;
char *driver;

char *list_dither;
int list_dither;
int list_drivers;
} CACAContext;

Expand Down Expand Up @@ -99,21 +106,14 @@ static int caca_write_header(AVFormatContext *s)
return AVERROR_EXIT;
}
if (c->list_dither) {
if (!strcmp(c->list_dither, "colors")) {
if (c->list_dither & LIST_COLORS)
list_dither_color(c);
} else if (!strcmp(c->list_dither, "charsets")) {
if (c->list_dither & LIST_CHARSETS)
list_dither_charset(c);
} else if (!strcmp(c->list_dither, "algorithms")) {
if (c->list_dither & LIST_ALGORITHMS)
list_dither_algorithm(c);
} else if (!strcmp(c->list_dither, "antialiases")) {
if (c->list_dither & LIST_ANTIALIASES)
list_dither_antialias(c);
} else {
av_log(s, AV_LOG_ERROR,
"Invalid argument '%s', for 'list_dither' option\n"
"Argument must be one of 'algorithms, 'antialiases', 'charsets', 'colors'\n",
c->list_dither);
return AVERROR(EINVAL);
}
return AVERROR_EXIT;
}

Expand Down Expand Up @@ -205,11 +205,11 @@ static const AVOption options[] = {
{ "charset", "set charset used to render output", OFFSET(charset), AV_OPT_TYPE_STRING, {.str = "default" }, 0, 0, ENC },
{ "color", "set color used to render output", OFFSET(color), AV_OPT_TYPE_STRING, {.str = "default" }, 0, 0, ENC },
{ "list_drivers", "list available drivers", OFFSET(list_drivers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, ENC },
{ "list_dither", "list available dither options", OFFSET(list_dither), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 1, ENC, "list_dither" },
{ "algorithms", NULL, 0, AV_OPT_TYPE_CONST, {.str = "algorithms"}, 0, 0, ENC, "list_dither" },
{ "antialiases", NULL, 0, AV_OPT_TYPE_CONST, {.str = "antialiases"},0, 0, ENC, "list_dither" },
{ "charsets", NULL, 0, AV_OPT_TYPE_CONST, {.str = "charsets"}, 0, 0, ENC, "list_dither" },
{ "colors", NULL, 0, AV_OPT_TYPE_CONST, {.str = "colors"}, 0, 0, ENC, "list_dither" },
{ "list_dither", "list available dither options", OFFSET(list_dither), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, INT_MAX, ENC, "list_dither" },
{ "algorithms", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = LIST_ALGORITHMS }, 0, 0, ENC, "list_dither" },
{ "antialiases", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = LIST_ANTIALIASES }, 0, 0, ENC, "list_dither" },
{ "charsets", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = LIST_CHARSETS }, 0, 0, ENC, "list_dither" },
{ "colors", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = LIST_COLORS }, 0, 0, ENC, "list_dither" },
{ NULL },
};

Expand Down

0 comments on commit e05d3c1

Please sign in to comment.