diff options
author | Thomas Mundt <loudmax-at-yahoo.de@ffmpeg.org> | 2016-03-25 23:31:36 +0100 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2016-06-05 19:46:38 +0200 |
commit | a0a4a4b370101f3e8f07bf62a742f3e460883c0e (patch) | |
tree | ea6afee3b09fac5bb3e858ea162e5fbac3095822 | |
parent | 2e395bbccffed726bd73e841740f767218f791bc (diff) | |
download | ffmpeg-a0a4a4b370101f3e8f07bf62a742f3e460883c0e.tar.gz |
avfilter/vf_colormatrix: add bt.2020 colorspace
Signed-off-by: Thomas Mundt <loudmax@yahoo.de>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | doc/filters.texi | 3 | ||||
-rw-r--r-- | libavfilter/vf_colormatrix.c | 38 |
2 files changed, 25 insertions, 16 deletions
diff --git a/doc/filters.texi b/doc/filters.texi index ba3f2b378c..707fb0476a 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -5025,6 +5025,9 @@ SMPTE-240M @item fcc FCC + +@item bt2020 +BT.2020 @end table @end table diff --git a/libavfilter/vf_colormatrix.c b/libavfilter/vf_colormatrix.c index c783671d12..15fb680e4a 100644 --- a/libavfilter/vf_colormatrix.c +++ b/libavfilter/vf_colormatrix.c @@ -40,11 +40,12 @@ #define NS(n) ((n) < 0 ? (int)((n)*65536.0-0.5+DBL_EPSILON) : (int)((n)*65536.0+0.5)) #define CB(n) av_clip_uint8(n) -static const double yuv_coeff_luma[4][3] = { +static const double yuv_coeff_luma[5][3] = { { +0.7152, +0.0722, +0.2126 }, // Rec.709 (0) { +0.5900, +0.1100, +0.3000 }, // FCC (1) { +0.5870, +0.1140, +0.2990 }, // Rec.601 (ITU-R BT.470-2/SMPTE 170M) (2) { +0.7010, +0.0870, +0.2120 }, // SMPTE 240M (3) + { +0.6780, +0.0593, +0.2627 }, // Rec.2020 (4) }; enum ColorMode { @@ -53,12 +54,13 @@ enum ColorMode { COLOR_MODE_FCC, COLOR_MODE_BT601, COLOR_MODE_SMPTE240M, + COLOR_MODE_BT2020, COLOR_MODE_COUNT }; typedef struct { const AVClass *class; - int yuv_convert[16][3][3]; + int yuv_convert[25][3][3]; int interlaced; int source, dest; ///< ColorMode int mode; @@ -89,6 +91,7 @@ static const AVOption colormatrix_options[] = { { "bt470bg", "set BT.470 colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT601}, .flags=FLAGS, .unit="color_mode" }, { "smpte170m", "set SMTPE-170M 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" }, + { "bt2020", "set BT.2020 colorspace", 0, AV_OPT_TYPE_CONST, {.i64=COLOR_MODE_BT2020}, .flags=FLAGS, .unit="color_mode" }, { NULL } }; @@ -140,13 +143,13 @@ static void solve_coefficients(double cm[3][3], double rgb[3][3], double yuv[3][ static void calc_coefficients(AVFilterContext *ctx) { ColorMatrixContext *color = ctx->priv; - double yuv_coeff[4][3][3]; - double rgb_coeffd[4][3][3]; - double yuv_convertd[16][3][3]; + double yuv_coeff[5][3][3]; + double rgb_coeffd[5][3][3]; + double yuv_convertd[25][3][3]; double bscale, rscale; int v = 0; int i, j, k; - for (i = 0; i < 4; i++) { + for (i = 0; i < 5; i++) { yuv_coeff[i][0][0] = yuv_coeff_luma[i][0]; yuv_coeff[i][0][1] = yuv_coeff_luma[i][1]; yuv_coeff[i][0][2] = yuv_coeff_luma[i][2]; @@ -159,10 +162,10 @@ static void calc_coefficients(AVFilterContext *ctx) yuv_coeff[i][2][1] = rscale * yuv_coeff[i][0][1]; yuv_coeff[i][2][2] = 0.5; } - for (i = 0; i < 4; i++) + for (i = 0; i < 5; i++) inverse3x3(rgb_coeffd[i], yuv_coeff[i]); - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { + for (i = 0; i < 5; i++) { + for (j = 0; j < 5; j++) { solve_coefficients(yuv_convertd[v], rgb_coeffd[i], yuv_coeff[j]); for (k = 0; k < 3; k++) { color->yuv_convert[v][k][0] = NS(yuv_convertd[v][k][0]); @@ -178,7 +181,7 @@ static void calc_coefficients(AVFilterContext *ctx) } } -static const char * const color_modes[] = {"bt709", "fcc", "bt601", "smpte240m"}; +static const char * const color_modes[] = {"bt709", "fcc", "bt601", "smpte240m", "bt2020"}; static av_cold int init(AVFilterContext *ctx) { @@ -441,20 +444,23 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) case AVCOL_SPC_SMPTE240M : source = COLOR_MODE_SMPTE240M ; break; case AVCOL_SPC_BT470BG : source = COLOR_MODE_BT601 ; break; case AVCOL_SPC_SMPTE170M : source = COLOR_MODE_BT601 ; break; + case AVCOL_SPC_BT2020_NCL: source = COLOR_MODE_BT2020 ; break; + case AVCOL_SPC_BT2020_CL : source = COLOR_MODE_BT2020 ; break; default : av_log(ctx, AV_LOG_ERROR, "Input frame does not specify a supported colorspace, and none has been specified as source either\n"); av_frame_free(&out); return AVERROR(EINVAL); } - color->mode = source * 4 + color->dest; + color->mode = source * 5 + color->dest; } else - color->mode = color->source * 4 + color->dest; + color->mode = color->source * 5 + color->dest; switch(color->dest) { - case COLOR_MODE_BT709 : av_frame_set_colorspace(out, AVCOL_SPC_BT709) ; break; - case COLOR_MODE_FCC : av_frame_set_colorspace(out, AVCOL_SPC_FCC) ; break; - case COLOR_MODE_SMPTE240M: av_frame_set_colorspace(out, AVCOL_SPC_SMPTE240M); break; - case COLOR_MODE_BT601 : av_frame_set_colorspace(out, AVCOL_SPC_BT470BG) ; break; + case COLOR_MODE_BT709 : av_frame_set_colorspace(out, AVCOL_SPC_BT709) ; break; + case COLOR_MODE_FCC : av_frame_set_colorspace(out, AVCOL_SPC_FCC) ; break; + case COLOR_MODE_SMPTE240M: av_frame_set_colorspace(out, AVCOL_SPC_SMPTE240M) ; break; + case COLOR_MODE_BT601 : av_frame_set_colorspace(out, AVCOL_SPC_BT470BG) ; break; + case COLOR_MODE_BT2020 : av_frame_set_colorspace(out, AVCOL_SPC_BT2020_NCL); break; } td.src = in; |