1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

vf_colorspace: Allow overriding input color properties

The filter needs input frames with color properties filled out by
the decoder. Since this is not always possible, add input options to
the filter so that user may override color space, color primaries,
transfer characteristics, and color range, as well as a generic option
to set all properties at once.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
This commit is contained in:
Vittorio Giovara 2016-09-03 15:19:35 +02:00 committed by Paul B Mahol
parent b6e8efb082
commit 5df993f3b1
2 changed files with 55 additions and 5 deletions

View File

@ -5235,6 +5235,7 @@ Convert colorspace, transfer characteristics or color primaries.
The filter accepts the following options: The filter accepts the following options:
@table @option @table @option
@anchor{all}
@item all @item all
Specify all color properties at once. Specify all color properties at once.
@ -5266,6 +5267,7 @@ BT.2020
@end table @end table
@anchor{space}
@item space @item space
Specify output colorspace. Specify output colorspace.
@ -5291,6 +5293,7 @@ BT.2020 with non-constant luminance
@end table @end table
@anchor{trc}
@item trc @item trc
Specify output transfer characteristics. Specify output transfer characteristics.
@ -5319,6 +5322,7 @@ BT.2020 for 12-bits content
@end table @end table
@anchor{primaries}
@item primaries @item primaries
Specify output color primaries. Specify output color primaries.
@ -5344,6 +5348,7 @@ BT.2020
@end table @end table
@anchor{range}
@item range @item range
Specify output color range. Specify output color range.
@ -5423,6 +5428,21 @@ von Kries whitepoint adaptation
identity whitepoint adaptation (i.e. no whitepoint adaptation) identity whitepoint adaptation (i.e. no whitepoint adaptation)
@end table @end table
@item iall
Override all input properties at once. Same accepted values as @ref{all}.
@item ispace
Override input colorspace. Same accepted values as @ref{space}.
@item iprimaries
Override input color primaries. Same accepted values as @ref{primaries}.
@item itrc
Override input transfer characteristics. Same accepted values as @ref{trc}.
@item irange
Override input color range. Same accepted values as @ref{range}.
@end table @end table
The filter converts the transfer characteristics, color space and color The filter converts the transfer characteristics, color space and color

View File

@ -128,11 +128,11 @@ typedef struct ColorSpaceContext {
ColorSpaceDSPContext dsp; ColorSpaceDSPContext dsp;
enum Colorspace user_all; enum Colorspace user_all, user_iall;
enum AVColorSpace in_csp, out_csp, user_csp; enum AVColorSpace in_csp, out_csp, user_csp, user_icsp;
enum AVColorRange in_rng, out_rng, user_rng; enum AVColorRange in_rng, out_rng, user_rng, user_irng;
enum AVColorTransferCharacteristic in_trc, out_trc, user_trc; enum AVColorTransferCharacteristic in_trc, out_trc, user_trc, user_itrc;
enum AVColorPrimaries in_prm, out_prm, user_prm; enum AVColorPrimaries in_prm, out_prm, user_prm, user_iprm;
enum AVPixelFormat in_format, user_format; enum AVPixelFormat in_format, user_format;
int fast_mode; int fast_mode;
enum DitherMode dither; enum DitherMode dither;
@ -581,6 +581,10 @@ static int create_filtergraph(AVFilterContext *ctx,
if (!s->out_primaries || !s->in_primaries) { if (!s->out_primaries || !s->in_primaries) {
s->in_prm = in->color_primaries; s->in_prm = in->color_primaries;
if (s->user_iall != CS_UNSPECIFIED)
s->in_prm = default_prm[FFMIN(s->user_iall, CS_NB)];
if (s->user_iprm != AVCOL_PRI_UNSPECIFIED)
s->in_prm = s->user_iprm;
s->in_primaries = get_color_primaries(s->in_prm); s->in_primaries = get_color_primaries(s->in_prm);
if (!s->in_primaries) { if (!s->in_primaries) {
av_log(ctx, AV_LOG_ERROR, av_log(ctx, AV_LOG_ERROR,
@ -638,6 +642,10 @@ static int create_filtergraph(AVFilterContext *ctx,
if (!s->in_txchr) { if (!s->in_txchr) {
av_freep(&s->lin_lut); av_freep(&s->lin_lut);
s->in_trc = in->color_trc; s->in_trc = in->color_trc;
if (s->user_iall != CS_UNSPECIFIED)
s->in_trc = default_trc[FFMIN(s->user_iall, CS_NB)];
if (s->user_itrc != AVCOL_TRC_UNSPECIFIED)
s->in_trc = s->user_itrc;
s->in_txchr = get_transfer_characteristics(s->in_trc); s->in_txchr = get_transfer_characteristics(s->in_trc);
if (!s->in_txchr) { if (!s->in_txchr) {
av_log(ctx, AV_LOG_ERROR, av_log(ctx, AV_LOG_ERROR,
@ -680,7 +688,13 @@ static int create_filtergraph(AVFilterContext *ctx,
if (!s->in_lumacoef) { if (!s->in_lumacoef) {
s->in_csp = in->colorspace; s->in_csp = in->colorspace;
if (s->user_iall != CS_UNSPECIFIED)
s->in_csp = default_csp[FFMIN(s->user_iall, CS_NB)];
if (s->user_icsp != AVCOL_SPC_UNSPECIFIED)
s->in_csp = s->user_icsp;
s->in_rng = in->color_range; s->in_rng = in->color_range;
if (s->user_irng != AVCOL_RANGE_UNSPECIFIED)
s->in_rng = s->user_irng;
s->in_lumacoef = get_luma_coefficients(s->in_csp); s->in_lumacoef = get_luma_coefficients(s->in_csp);
if (!s->in_lumacoef) { if (!s->in_lumacoef) {
av_log(ctx, AV_LOG_ERROR, av_log(ctx, AV_LOG_ERROR,
@ -1078,6 +1092,22 @@ static const AVOption colorspace_options[] = {
ENUM("vonkries", WP_ADAPT_VON_KRIES, "wpadapt"), ENUM("vonkries", WP_ADAPT_VON_KRIES, "wpadapt"),
ENUM("identity", WP_ADAPT_IDENTITY, "wpadapt"), ENUM("identity", WP_ADAPT_IDENTITY, "wpadapt"),
{ "iall", "Set all input color properties together",
OFFSET(user_iall), AV_OPT_TYPE_INT, { .i64 = CS_UNSPECIFIED },
CS_UNSPECIFIED, CS_NB - 1, FLAGS, "all" },
{ "ispace", "Input colorspace",
OFFSET(user_icsp), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED },
AVCOL_PRI_RESERVED0, AVCOL_PRI_NB - 1, FLAGS, "csp" },
{ "irange", "Input color range",
OFFSET(user_irng), AV_OPT_TYPE_INT, { .i64 = AVCOL_RANGE_UNSPECIFIED },
AVCOL_RANGE_UNSPECIFIED, AVCOL_RANGE_NB - 1, FLAGS, "rng" },
{ "iprimaries", "Input color primaries",
OFFSET(user_iprm), AV_OPT_TYPE_INT, { .i64 = AVCOL_PRI_UNSPECIFIED },
AVCOL_PRI_RESERVED0, AVCOL_PRI_NB - 1, FLAGS, "prm" },
{ "itrc", "Input transfer characteristics",
OFFSET(user_itrc), AV_OPT_TYPE_INT, { .i64 = AVCOL_TRC_UNSPECIFIED },
AVCOL_TRC_RESERVED0, AVCOL_TRC_NB - 1, FLAGS, "trc" },
{ NULL } { NULL }
}; };