Skip to content
Snippets Groups Projects
Commit 3062ac4c authored by Anton Khirnov's avatar Anton Khirnov
Browse files

vf_pad: use the name 's' for the pointer to the private context

This is shorter and consistent across filters.
parent a70519aa
No related branches found
No related tags found
No related merge requests found
...@@ -114,9 +114,9 @@ typedef struct { ...@@ -114,9 +114,9 @@ typedef struct {
static av_cold int init(AVFilterContext *ctx) static av_cold int init(AVFilterContext *ctx)
{ {
PadContext *pad = ctx->priv; PadContext *s = ctx->priv;
if (av_parse_color(pad->color, pad->color_str, -1, ctx) < 0) if (av_parse_color(s->color, s->color_str, -1, ctx) < 0)
return AVERROR(EINVAL); return AVERROR(EINVAL);
return 0; return 0;
...@@ -124,27 +124,27 @@ static av_cold int init(AVFilterContext *ctx) ...@@ -124,27 +124,27 @@ static av_cold int init(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx) static av_cold void uninit(AVFilterContext *ctx)
{ {
PadContext *pad = ctx->priv; PadContext *s = ctx->priv;
int i; int i;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
av_freep(&pad->line[i]); av_freep(&s->line[i]);
pad->line_step[i] = 0; s->line_step[i] = 0;
} }
} }
static int config_input(AVFilterLink *inlink) static int config_input(AVFilterLink *inlink)
{ {
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
PadContext *pad = ctx->priv; PadContext *s = ctx->priv;
const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
uint8_t rgba_color[4]; uint8_t rgba_color[4];
int ret, is_packed_rgba; int ret, is_packed_rgba;
double var_values[VARS_NB], res; double var_values[VARS_NB], res;
char *expr; char *expr;
pad->hsub = pix_desc->log2_chroma_w; s->hsub = pix_desc->log2_chroma_w;
pad->vsub = pix_desc->log2_chroma_h; s->vsub = pix_desc->log2_chroma_h;
var_values[VAR_PI] = M_PI; var_values[VAR_PI] = M_PI;
var_values[VAR_PHI] = M_PHI; var_values[VAR_PHI] = M_PHI;
...@@ -154,78 +154,78 @@ static int config_input(AVFilterLink *inlink) ...@@ -154,78 +154,78 @@ static int config_input(AVFilterLink *inlink)
var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN; var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN; var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
var_values[VAR_A] = (double) inlink->w / inlink->h; var_values[VAR_A] = (double) inlink->w / inlink->h;
var_values[VAR_HSUB] = 1<<pad->hsub; var_values[VAR_HSUB] = 1<<s->hsub;
var_values[VAR_VSUB] = 1<<pad->vsub; var_values[VAR_VSUB] = 1<<s->vsub;
/* evaluate width and height */ /* evaluate width and height */
av_expr_parse_and_eval(&res, (expr = pad->w_expr), av_expr_parse_and_eval(&res, (expr = s->w_expr),
var_names, var_values, var_names, var_values,
NULL, NULL, NULL, NULL, NULL, 0, ctx); NULL, NULL, NULL, NULL, NULL, 0, ctx);
pad->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
if ((ret = av_expr_parse_and_eval(&res, (expr = pad->h_expr), if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
var_names, var_values, var_names, var_values,
NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
goto eval_fail; goto eval_fail;
pad->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res; s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
/* evaluate the width again, as it may depend on the evaluated output height */ /* evaluate the width again, as it may depend on the evaluated output height */
if ((ret = av_expr_parse_and_eval(&res, (expr = pad->w_expr), if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
var_names, var_values, var_names, var_values,
NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
goto eval_fail; goto eval_fail;
pad->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
/* evaluate x and y */ /* evaluate x and y */
av_expr_parse_and_eval(&res, (expr = pad->x_expr), av_expr_parse_and_eval(&res, (expr = s->x_expr),
var_names, var_values, var_names, var_values,
NULL, NULL, NULL, NULL, NULL, 0, ctx); NULL, NULL, NULL, NULL, NULL, 0, ctx);
pad->x = var_values[VAR_X] = res; s->x = var_values[VAR_X] = res;
if ((ret = av_expr_parse_and_eval(&res, (expr = pad->y_expr), if ((ret = av_expr_parse_and_eval(&res, (expr = s->y_expr),
var_names, var_values, var_names, var_values,
NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
goto eval_fail; goto eval_fail;
pad->y = var_values[VAR_Y] = res; s->y = var_values[VAR_Y] = res;
/* evaluate x again, as it may depend on the evaluated y value */ /* evaluate x again, as it may depend on the evaluated y value */
if ((ret = av_expr_parse_and_eval(&res, (expr = pad->x_expr), if ((ret = av_expr_parse_and_eval(&res, (expr = s->x_expr),
var_names, var_values, var_names, var_values,
NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
goto eval_fail; goto eval_fail;
pad->x = var_values[VAR_X] = res; s->x = var_values[VAR_X] = res;
/* sanity check params */ /* sanity check params */
if (pad->w < 0 || pad->h < 0 || pad->x < 0 || pad->y < 0) { if (s->w < 0 || s->h < 0 || s->x < 0 || s->y < 0) {
av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\n"); av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\n");
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
if (!pad->w) if (!s->w)
pad->w = inlink->w; s->w = inlink->w;
if (!pad->h) if (!s->h)
pad->h = inlink->h; s->h = inlink->h;
pad->w &= ~((1 << pad->hsub) - 1); s->w &= ~((1 << s->hsub) - 1);
pad->h &= ~((1 << pad->vsub) - 1); s->h &= ~((1 << s->vsub) - 1);
pad->x &= ~((1 << pad->hsub) - 1); s->x &= ~((1 << s->hsub) - 1);
pad->y &= ~((1 << pad->vsub) - 1); s->y &= ~((1 << s->vsub) - 1);
pad->in_w = inlink->w & ~((1 << pad->hsub) - 1); s->in_w = inlink->w & ~((1 << s->hsub) - 1);
pad->in_h = inlink->h & ~((1 << pad->vsub) - 1); s->in_h = inlink->h & ~((1 << s->vsub) - 1);
memcpy(rgba_color, pad->color, sizeof(rgba_color)); memcpy(rgba_color, s->color, sizeof(rgba_color));
ff_fill_line_with_color(pad->line, pad->line_step, pad->w, pad->color, ff_fill_line_with_color(s->line, s->line_step, s->w, s->color,
inlink->format, rgba_color, &is_packed_rgba, NULL); inlink->format, rgba_color, &is_packed_rgba, NULL);
av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X[%s]\n", av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X[%s]\n",
inlink->w, inlink->h, pad->w, pad->h, pad->x, pad->y, inlink->w, inlink->h, s->w, s->h, s->x, s->y,
pad->color[0], pad->color[1], pad->color[2], pad->color[3], s->color[0], s->color[1], s->color[2], s->color[3],
is_packed_rgba ? "rgba" : "yuva"); is_packed_rgba ? "rgba" : "yuva");
if (pad->x < 0 || pad->y < 0 || if (s->x < 0 || s->y < 0 ||
pad->w <= 0 || pad->h <= 0 || s->w <= 0 || s->h <= 0 ||
(unsigned)pad->x + (unsigned)inlink->w > pad->w || (unsigned)s->x + (unsigned)inlink->w > s->w ||
(unsigned)pad->y + (unsigned)inlink->h > pad->h) { (unsigned)s->y + (unsigned)inlink->h > s->h) {
av_log(ctx, AV_LOG_ERROR, av_log(ctx, AV_LOG_ERROR,
"Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\n", "Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\n",
pad->x, pad->y, pad->x + inlink->w, pad->y + inlink->h, pad->w, pad->h); s->x, s->y, s->x + inlink->w, s->y + inlink->h, s->w, s->h);
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
...@@ -240,20 +240,20 @@ eval_fail: ...@@ -240,20 +240,20 @@ eval_fail:
static int config_output(AVFilterLink *outlink) static int config_output(AVFilterLink *outlink)
{ {
PadContext *pad = outlink->src->priv; PadContext *s = outlink->src->priv;
outlink->w = pad->w; outlink->w = s->w;
outlink->h = pad->h; outlink->h = s->h;
return 0; return 0;
} }
static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h) static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
{ {
PadContext *pad = inlink->dst->priv; PadContext *s = inlink->dst->priv;
AVFrame *frame = ff_get_video_buffer(inlink->dst->outputs[0], AVFrame *frame = ff_get_video_buffer(inlink->dst->outputs[0],
w + (pad->w - pad->in_w), w + (s->w - s->in_w),
h + (pad->h - pad->in_h)); h + (s->h - s->in_h));
int plane; int plane;
if (!frame) if (!frame)
...@@ -263,11 +263,11 @@ static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h) ...@@ -263,11 +263,11 @@ static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
frame->height = h; frame->height = h;
for (plane = 0; plane < 4 && frame->data[plane]; plane++) { for (plane = 0; plane < 4 && frame->data[plane]; plane++) {
int hsub = (plane == 1 || plane == 2) ? pad->hsub : 0; int hsub = (plane == 1 || plane == 2) ? s->hsub : 0;
int vsub = (plane == 1 || plane == 2) ? pad->vsub : 0; int vsub = (plane == 1 || plane == 2) ? s->vsub : 0;
frame->data[plane] += (pad->x >> hsub) * pad->line_step[plane] + frame->data[plane] += (s->x >> hsub) * s->line_step[plane] +
(pad->y >> vsub) * frame->linesize[plane]; (s->y >> vsub) * frame->linesize[plane];
} }
return frame; return frame;
...@@ -342,15 +342,15 @@ static int frame_needs_copy(PadContext *s, AVFrame *frame) ...@@ -342,15 +342,15 @@ static int frame_needs_copy(PadContext *s, AVFrame *frame)
static int filter_frame(AVFilterLink *inlink, AVFrame *in) static int filter_frame(AVFilterLink *inlink, AVFrame *in)
{ {
PadContext *pad = inlink->dst->priv; PadContext *s = inlink->dst->priv;
AVFrame *out; AVFrame *out;
int needs_copy = frame_needs_copy(pad, in); int needs_copy = frame_needs_copy(s, in);
if (needs_copy) { if (needs_copy) {
av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n"); av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n");
out = ff_get_video_buffer(inlink->dst->outputs[0], out = ff_get_video_buffer(inlink->dst->outputs[0],
FFMAX(inlink->w, pad->w), FFMAX(inlink->w, s->w),
FFMAX(inlink->h, pad->h)); FFMAX(inlink->h, s->h));
if (!out) { if (!out) {
av_frame_free(&in); av_frame_free(&in);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
...@@ -362,45 +362,45 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) ...@@ -362,45 +362,45 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
out = in; out = in;
for (i = 0; i < FF_ARRAY_ELEMS(out->data) && out->data[i]; i++) { for (i = 0; i < FF_ARRAY_ELEMS(out->data) && out->data[i]; i++) {
int hsub = (i == 1 || i == 2) ? pad->hsub : 0; int hsub = (i == 1 || i == 2) ? s->hsub : 0;
int vsub = (i == 1 || i == 2) ? pad->vsub : 0; int vsub = (i == 1 || i == 2) ? s->vsub : 0;
out->data[i] -= (pad->x >> hsub) * pad->line_step[i] + out->data[i] -= (s->x >> hsub) * s->line_step[i] +
(pad->y >> vsub) * out->linesize[i]; (s->y >> vsub) * out->linesize[i];
} }
} }
/* top bar */ /* top bar */
if (pad->y) { if (s->y) {
ff_draw_rectangle(out->data, out->linesize, ff_draw_rectangle(out->data, out->linesize,
pad->line, pad->line_step, pad->hsub, pad->vsub, s->line, s->line_step, s->hsub, s->vsub,
0, 0, pad->w, pad->y); 0, 0, s->w, s->y);
} }
/* bottom bar */ /* bottom bar */
if (pad->h > pad->y + pad->in_h) { if (s->h > s->y + s->in_h) {
ff_draw_rectangle(out->data, out->linesize, ff_draw_rectangle(out->data, out->linesize,
pad->line, pad->line_step, pad->hsub, pad->vsub, s->line, s->line_step, s->hsub, s->vsub,
0, pad->y + pad->in_h, pad->w, pad->h - pad->y - pad->in_h); 0, s->y + s->in_h, s->w, s->h - s->y - s->in_h);
} }
/* left border */ /* left border */
ff_draw_rectangle(out->data, out->linesize, pad->line, pad->line_step, ff_draw_rectangle(out->data, out->linesize, s->line, s->line_step,
pad->hsub, pad->vsub, 0, pad->y, pad->x, in->height); s->hsub, s->vsub, 0, s->y, s->x, in->height);
if (needs_copy) { if (needs_copy) {
ff_copy_rectangle(out->data, out->linesize, in->data, in->linesize, ff_copy_rectangle(out->data, out->linesize, in->data, in->linesize,
pad->line_step, pad->hsub, pad->vsub, s->line_step, s->hsub, s->vsub,
pad->x, pad->y, 0, in->width, in->height); s->x, s->y, 0, in->width, in->height);
} }
/* right border */ /* right border */
ff_draw_rectangle(out->data, out->linesize, ff_draw_rectangle(out->data, out->linesize,
pad->line, pad->line_step, pad->hsub, pad->vsub, s->line, s->line_step, s->hsub, s->vsub,
pad->x + pad->in_w, pad->y, pad->w - pad->x - pad->in_w, s->x + s->in_w, s->y, s->w - s->x - s->in_w,
in->height); in->height);
out->width = pad->w; out->width = s->w;
out->height = pad->h; out->height = s->h;
if (in != out) if (in != out)
av_frame_free(&in); av_frame_free(&in);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment