diff options
author | Stefano Sabatini <stefasab@gmail.com> | 2013-03-24 13:40:57 +0100 |
---|---|---|
committer | Stefano Sabatini <stefasab@gmail.com> | 2013-03-24 20:21:20 +0100 |
commit | 1b140835b698f08f6937a1027adc78ede3afa88d (patch) | |
tree | 5cbb4237ff6a4d99cb4126fc7cd755b42d0c670a | |
parent | cbf224b631b0f0054013564e2743a84d8c39f3c4 (diff) | |
download | ffmpeg-1b140835b698f08f6937a1027adc78ede3afa88d.tar.gz |
lavfi/colormatrix: add support for named options
-rw-r--r-- | doc/filters.texi | 33 | ||||
-rw-r--r-- | libavfilter/version.h | 2 | ||||
-rw-r--r-- | libavfilter/vf_colormatrix.c | 72 |
3 files changed, 68 insertions, 39 deletions
diff --git a/doc/filters.texi b/doc/filters.texi index 74a682af86..e4aa9921c0 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -2056,12 +2056,37 @@ boxblur=min(h\,w)/10:1:min(cw\,ch)/10:1 @section colormatrix -The colormatrix filter allows conversion between any of the following color -space: BT.709 (@var{bt709}), BT.601 (@var{bt601}), SMPTE-240M (@var{smpte240m}) -and FCC (@var{fcc}). +Convert color matrix. -The syntax of the parameters is @var{source}:@var{destination}: +The filter accepts parameters as a list of @var{key}=@var{value} +pairs, separated by ":". If the key of the first options is omitted, +the arguments are interpreted according to the syntax +@var{src}:@var{dst}. + +A description of the accepted options follows: +@table @option +@item src +@item dst +Specify the source and destination color matrix. Both values must be +specified. + +The accepted values are: +@table @samp +@item bt709 +BT.709 + +@item bt601 +BT.601 + +@item smpte240m +SMPTE-240M + +@item fcc +FCC +@end table +@end table +For example to convert from BT.601 to SMPTE-240M, use the command: @example colormatrix=bt601:smpte240m @end example diff --git a/libavfilter/version.h b/libavfilter/version.h index f592fc16b8..62a9e53948 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -30,7 +30,7 @@ #define LIBAVFILTER_VERSION_MAJOR 3 #define LIBAVFILTER_VERSION_MINOR 48 -#define LIBAVFILTER_VERSION_MICRO 100 +#define LIBAVFILTER_VERSION_MICRO 101 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ LIBAVFILTER_VERSION_MINOR, \ diff --git a/libavfilter/vf_colormatrix.c b/libavfilter/vf_colormatrix.c index 4daa58e44a..316fced99b 100644 --- a/libavfilter/vf_colormatrix.c +++ b/libavfilter/vf_colormatrix.c @@ -33,6 +33,7 @@ #include "formats.h" #include "internal.h" #include "video.h" +#include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "libavutil/avstring.h" @@ -54,15 +55,39 @@ static const double yuv_coeff[4][3][3] = { { -0.4450, -0.0550, +0.5000 } }, }; +enum ColorMode { + COLOR_MODE_NONE = -1, + COLOR_MODE_BT709, + COLOR_MODE_FCC, + COLOR_MODE_BT601, + COLOR_MODE_SMPTE240M, + COLOR_MODE_COUNT +}; + typedef struct { + const AVClass *class; int yuv_convert[16][3][3]; int interlaced; - int source, dest, mode; - char src[256]; - char dst[256]; + enum ColorMode source, dest; + int mode; int hsub, vsub; } ColorMatrixContext; +#define OFFSET(x) offsetof(ColorMatrixContext, x) +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM + +static const AVOption colormatrix_options[] = { + { "src", "set source color matrix", OFFSET(source), AV_OPT_TYPE_INT, {.i64=COLOR_MODE_NONE}, COLOR_MODE_NONE, COLOR_MODE_COUNT-1, .flags=FLAGS, .unit="color_mode" }, + { "dst", "set destination color matrix", OFFSET(dest), AV_OPT_TYPE_INT, {.i64=COLOR_MODE_NONE}, COLOR_MODE_NONE, COLOR_MODE_COUNT-1, .flags=FLAGS, .unit="color_mode" }, + { "bt709", "set BT.709 colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT709}, .flags=FLAGS, .unit="color_mode" }, + { "fcc", "set FCC colorspace ", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_FCC}, .flags=FLAGS, .unit="color_mode" }, + { "bt601", "set BT.601 colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT601}, .flags=FLAGS, .unit="color_mode" }, + { "smpte240m", "set SMPTE-240M colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_SMPTE240M}, .flags=FLAGS, .unit="color_mode" }, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(colormatrix); + #define ma m[0][0] #define mb m[0][1] #define mc m[0][2] @@ -133,40 +158,14 @@ static void calc_coefficients(AVFilterContext *ctx) } } -static const char *color_modes[] = {"bt709", "FCC", "bt601", "smpte240m"}; - -static int get_color_mode_index(const char *name) -{ - int i; - - for (i = 0; i < FF_ARRAY_ELEMS(color_modes); i++) - if (!av_strcasecmp(color_modes[i], name)) - return i; - return -1; -} +static const char *color_modes[] = {"bt709", "fcc", "bt601", "smpte240m"}; static av_cold int init(AVFilterContext *ctx, const char *args) { ColorMatrixContext *color = ctx->priv; - if (!args) - goto usage; - if (sscanf(args, "%255[^:]:%255[^:]", color->src, color->dst) != 2) { - usage: - av_log(ctx, AV_LOG_ERROR, "usage: <src>:<dst>\n"); - av_log(ctx, AV_LOG_ERROR, "possible options: bt709,bt601,smpte240m,fcc\n"); - return -1; - } - - color->source = get_color_mode_index(color->src); - if (color->source < 0) { - av_log(ctx, AV_LOG_ERROR, "unknown color space %s\n", color->src); - return AVERROR(EINVAL); - } - - color->dest = get_color_mode_index(color->dst); - if (color->dest < 0) { - av_log(ctx, AV_LOG_ERROR, "unknown color space %s\n", color->dst); + if (color->source == COLOR_MODE_NONE || color->dest == COLOR_MODE_NONE) { + av_log(ctx, AV_LOG_ERROR, "Unspecified source or destination color space\n"); return AVERROR(EINVAL); } @@ -313,7 +312,8 @@ static int config_input(AVFilterLink *inlink) color->hsub = pix_desc->log2_chroma_w; color->vsub = pix_desc->log2_chroma_h; - av_log(ctx, AV_LOG_VERBOSE, "%s -> %s\n", color->src, color->dst); + av_log(ctx, AV_LOG_VERBOSE, "%s -> %s\n", + color_modes[color->source], color_modes[color->dest]); return 0; } @@ -375,13 +375,17 @@ static const AVFilterPad colormatrix_outputs[] = { { NULL } }; +static const char *const shorthand[] = { "src", "dst", NULL }; + AVFilter avfilter_vf_colormatrix = { .name = "colormatrix", - .description = NULL_IF_CONFIG_SMALL("Color matrix conversion"), + .description = NULL_IF_CONFIG_SMALL("Convert color matrix."), .priv_size = sizeof(ColorMatrixContext), .init = init, .query_formats = query_formats, .inputs = colormatrix_inputs, .outputs = colormatrix_outputs, + .priv_class = &colormatrix_class, + .shorthand = shorthand, }; |