mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-15 19:40:07 +01:00
avfilter/vf_format: add alpha_modes parameter
This commit is contained in:
@@ -14307,6 +14307,10 @@ A '|'-separated list of color space names, such as
|
|||||||
A '|'-separated list of color range names, such as
|
A '|'-separated list of color range names, such as
|
||||||
"color_ranges=tv|pc".
|
"color_ranges=tv|pc".
|
||||||
|
|
||||||
|
@item alpha_modes
|
||||||
|
A '|'-separated list of color range names, such as
|
||||||
|
"alpha_modes=straight|premultiplied".
|
||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@subsection Examples
|
@subsection Examples
|
||||||
|
|||||||
@@ -42,10 +42,12 @@ typedef struct FormatContext {
|
|||||||
char *pix_fmts;
|
char *pix_fmts;
|
||||||
char *csps;
|
char *csps;
|
||||||
char *ranges;
|
char *ranges;
|
||||||
|
char *alphamodes;
|
||||||
|
|
||||||
AVFilterFormats *formats; ///< parsed from `pix_fmts`
|
AVFilterFormats *formats; ///< parsed from `pix_fmts`
|
||||||
AVFilterFormats *color_spaces; ///< parsed from `csps`
|
AVFilterFormats *color_spaces; ///< parsed from `csps`
|
||||||
AVFilterFormats *color_ranges; ///< parsed from `ranges`
|
AVFilterFormats *color_ranges; ///< parsed from `ranges`
|
||||||
|
AVFilterFormats *alpha_modes; ///< parsed from `alphamodes`
|
||||||
} FormatContext;
|
} FormatContext;
|
||||||
|
|
||||||
static av_cold void uninit(AVFilterContext *ctx)
|
static av_cold void uninit(AVFilterContext *ctx)
|
||||||
@@ -54,6 +56,7 @@ static av_cold void uninit(AVFilterContext *ctx)
|
|||||||
ff_formats_unref(&s->formats);
|
ff_formats_unref(&s->formats);
|
||||||
ff_formats_unref(&s->color_spaces);
|
ff_formats_unref(&s->color_spaces);
|
||||||
ff_formats_unref(&s->color_ranges);
|
ff_formats_unref(&s->color_ranges);
|
||||||
|
ff_formats_unref(&s->alpha_modes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int invert_formats(AVFilterFormats **fmts,
|
static av_cold int invert_formats(AVFilterFormats **fmts,
|
||||||
@@ -133,17 +136,28 @@ static av_cold int init(AVFilterContext *ctx)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (char *sep, *cur = s->alphamodes; cur; cur = sep) {
|
||||||
|
sep = strchr(cur, '|');
|
||||||
|
if (sep && *sep)
|
||||||
|
*sep++ = 0;
|
||||||
|
if ((ret = av_alpha_mode_from_name(cur)) < 0 ||
|
||||||
|
(ret = ff_add_format(&s->alpha_modes, ret)) < 0)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (!strcmp(ctx->filter->name, "noformat")) {
|
if (!strcmp(ctx->filter->name, "noformat")) {
|
||||||
if ((ret = invert_formats(&s->formats, ff_all_formats(AVMEDIA_TYPE_VIDEO))) < 0 ||
|
if ((ret = invert_formats(&s->formats, ff_all_formats(AVMEDIA_TYPE_VIDEO))) < 0 ||
|
||||||
(ret = invert_formats(&s->color_spaces, ff_all_color_spaces())) < 0 ||
|
(ret = invert_formats(&s->color_spaces, ff_all_color_spaces())) < 0 ||
|
||||||
(ret = invert_formats(&s->color_ranges, ff_all_color_ranges())) < 0)
|
(ret = invert_formats(&s->color_ranges, ff_all_color_ranges())) < 0 ||
|
||||||
|
(ret = invert_formats(&s->alpha_modes, ff_all_alpha_modes())) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hold on to a ref for the lifetime of the filter */
|
/* hold on to a ref for the lifetime of the filter */
|
||||||
if (s->formats && (ret = ff_formats_ref(s->formats, &s->formats)) < 0 ||
|
if (s->formats && (ret = ff_formats_ref(s->formats, &s->formats)) < 0 ||
|
||||||
s->color_spaces && (ret = ff_formats_ref(s->color_spaces, &s->color_spaces)) < 0 ||
|
s->color_spaces && (ret = ff_formats_ref(s->color_spaces, &s->color_spaces)) < 0 ||
|
||||||
s->color_ranges && (ret = ff_formats_ref(s->color_ranges, &s->color_ranges)) < 0)
|
s->color_ranges && (ret = ff_formats_ref(s->color_ranges, &s->color_ranges)) < 0 ||
|
||||||
|
s->alpha_modes && (ret = ff_formats_ref(s->alpha_modes, &s->alpha_modes)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -158,7 +172,8 @@ static int query_formats(const AVFilterContext *ctx,
|
|||||||
|
|
||||||
if (s->formats && (ret = ff_set_common_formats2 (ctx, cfg_in, cfg_out, s->formats)) < 0 ||
|
if (s->formats && (ret = ff_set_common_formats2 (ctx, cfg_in, cfg_out, s->formats)) < 0 ||
|
||||||
s->color_spaces && (ret = ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, s->color_spaces)) < 0 ||
|
s->color_spaces && (ret = ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, s->color_spaces)) < 0 ||
|
||||||
s->color_ranges && (ret = ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, s->color_ranges)) < 0)
|
s->color_ranges && (ret = ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, s->color_ranges)) < 0 ||
|
||||||
|
s->alpha_modes && (ret = ff_set_common_alpha_modes2(ctx, cfg_in, cfg_out, s->alpha_modes)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -170,6 +185,7 @@ static const AVOption options[] = {
|
|||||||
{ "pix_fmts", "A '|'-separated list of pixel formats", OFFSET(pix_fmts), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
|
{ "pix_fmts", "A '|'-separated list of pixel formats", OFFSET(pix_fmts), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
|
||||||
{ "color_spaces", "A '|'-separated list of color spaces", OFFSET(csps), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
|
{ "color_spaces", "A '|'-separated list of color spaces", OFFSET(csps), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
|
||||||
{ "color_ranges", "A '|'-separated list of color ranges", OFFSET(ranges), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
|
{ "color_ranges", "A '|'-separated list of color ranges", OFFSET(ranges), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
|
||||||
|
{ "alpha_modes", "A '|'-separated list of alpha modes", OFFSET(alphamodes), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user