diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-05-16 10:33:31 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-05-16 10:33:31 +0200 |
commit | 04dd5ddedad384669d531e4b334888e8d8888d54 (patch) | |
tree | 450c4ce9b1293a6f894e16185c39463de2ec92fe | |
parent | a134f9676e4f7988d360b69e0aed176055c47bcb (diff) | |
parent | c0279956b3ca3e5fd0a6a25253893d6f07000e68 (diff) | |
download | ffmpeg-04dd5ddedad384669d531e4b334888e8d8888d54.tar.gz |
Merge commit 'c0279956b3ca3e5fd0a6a25253893d6f07000e68'
* commit 'c0279956b3ca3e5fd0a6a25253893d6f07000e68':
vf_fade: use the name 's' for the pointer to the private context
vf_drawtext: use the name 's' for the pointer to the private context
vf_drawbox: use the name 's' for the pointer to the private context
Conflicts:
libavfilter/vf_drawbox.c
libavfilter/vf_drawtext.c
libavfilter/vf_fade.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavfilter/vf_drawbox.c | 64 | ||||
-rw-r--r-- | libavfilter/vf_drawtext.c | 328 | ||||
-rw-r--r-- | libavfilter/vf_fade.c | 116 |
3 files changed, 255 insertions, 253 deletions
diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c index 2747fbcd3e..9189e4de3c 100644 --- a/libavfilter/vf_drawbox.c +++ b/libavfilter/vf_drawbox.c @@ -47,19 +47,19 @@ typedef struct { static av_cold int init(AVFilterContext *ctx) { - DrawBoxContext *drawbox = ctx->priv; + DrawBoxContext *s = ctx->priv; uint8_t rgba_color[4]; - if (!strcmp(drawbox->color_str, "invert")) - drawbox->invert_color = 1; - else if (av_parse_color(rgba_color, drawbox->color_str, -1, ctx) < 0) + if (!strcmp(s->color_str, "invert")) + s->invert_color = 1; + else if (av_parse_color(rgba_color, s->color_str, -1, ctx) < 0) return AVERROR(EINVAL); - if (!drawbox->invert_color) { - drawbox->yuv_color[Y] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]); - drawbox->yuv_color[U] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0); - drawbox->yuv_color[V] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0); - drawbox->yuv_color[A] = rgba_color[3]; + if (!s->invert_color) { + s->yuv_color[Y] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]); + s->yuv_color[U] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0); + s->yuv_color[V] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0); + s->yuv_color[A] = rgba_color[3]; } return 0; @@ -81,49 +81,49 @@ static int query_formats(AVFilterContext *ctx) static int config_input(AVFilterLink *inlink) { - DrawBoxContext *drawbox = inlink->dst->priv; + DrawBoxContext *s = inlink->dst->priv; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); - drawbox->hsub = desc->log2_chroma_w; - drawbox->vsub = desc->log2_chroma_h; + s->hsub = desc->log2_chroma_w; + s->vsub = desc->log2_chroma_h; - if (drawbox->w == 0) drawbox->w = inlink->w; - if (drawbox->h == 0) drawbox->h = inlink->h; + if (s->w == 0) s->w = inlink->w; + if (s->h == 0) s->h = inlink->h; av_log(inlink->dst, AV_LOG_VERBOSE, "x:%d y:%d w:%d h:%d color:0x%02X%02X%02X%02X\n", - drawbox->x, drawbox->y, drawbox->w, drawbox->h, - drawbox->yuv_color[Y], drawbox->yuv_color[U], drawbox->yuv_color[V], drawbox->yuv_color[A]); + s->x, s->y, s->w, s->h, + s->yuv_color[Y], s->yuv_color[U], s->yuv_color[V], s->yuv_color[A]); return 0; } static int filter_frame(AVFilterLink *inlink, AVFrame *frame) { - DrawBoxContext *drawbox = inlink->dst->priv; - int plane, x, y, xb = drawbox->x, yb = drawbox->y; + DrawBoxContext *s = inlink->dst->priv; + int plane, x, y, xb = s->x, yb = s->y; unsigned char *row[4]; - for (y = FFMAX(yb, 0); y < frame->height && y < (yb + drawbox->h); y++) { + for (y = FFMAX(yb, 0); y < frame->height && y < (yb + s->h); y++) { row[0] = frame->data[0] + y * frame->linesize[0]; for (plane = 1; plane < 3; plane++) row[plane] = frame->data[plane] + - frame->linesize[plane] * (y >> drawbox->vsub); + frame->linesize[plane] * (y >> s->vsub); - if (drawbox->invert_color) { - for (x = FFMAX(xb, 0); x < xb + drawbox->w && x < frame->width; x++) - if ((y - yb < drawbox->thickness-1) || (yb + drawbox->h - y < drawbox->thickness) || - (x - xb < drawbox->thickness-1) || (xb + drawbox->w - x < drawbox->thickness)) + if (s->invert_color) { + for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++) + if ((y - yb < s->thickness-1) || (yb + s->h - y < s->thickness) || + (x - xb < s->thickness-1) || (xb + s->w - x < s->thickness)) row[0][x] = 0xff - row[0][x]; } else { - for (x = FFMAX(xb, 0); x < xb + drawbox->w && x < frame->width; x++) { - double alpha = (double)drawbox->yuv_color[A] / 255; - - if ((y - yb < drawbox->thickness-1) || (yb + drawbox->h - y < drawbox->thickness) || - (x - xb < drawbox->thickness-1) || (xb + drawbox->w - x < drawbox->thickness)) { - row[0][x ] = (1 - alpha) * row[0][x ] + alpha * drawbox->yuv_color[Y]; - row[1][x >> drawbox->hsub] = (1 - alpha) * row[1][x >> drawbox->hsub] + alpha * drawbox->yuv_color[U]; - row[2][x >> drawbox->hsub] = (1 - alpha) * row[2][x >> drawbox->hsub] + alpha * drawbox->yuv_color[V]; + for (x = FFMAX(xb, 0); x < xb + s->w && x < frame->width; x++) { + double alpha = (double)s->yuv_color[A] / 255; + + if ((y - yb < s->thickness-1) || (yb + s->h - y < s->thickness) || + (x - xb < s->thickness-1) || (xb + s->w - x < s->thickness)) { + row[0][x ] = (1 - alpha) * row[0][x ] + alpha * s->yuv_color[Y]; + row[1][x >> s->hsub] = (1 - alpha) * row[1][x >> s->hsub] + alpha * s->yuv_color[U]; + row[2][x >> s->hsub] = (1 - alpha) * row[2][x >> s->hsub] + alpha * s->yuv_color[V]; } } } diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index ef5bb03be4..f0ff5aad64 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -260,13 +260,13 @@ static int glyph_cmp(void *key, const void *b) */ static int load_glyph(AVFilterContext *ctx, Glyph **glyph_ptr, uint32_t code) { - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; Glyph *glyph; struct AVTreeNode *node = NULL; int ret; - /* load glyph into dtext->face->glyph */ - if (FT_Load_Char(dtext->face, code, dtext->ft_load_flags)) + /* load glyph into s->face->glyph */ + if (FT_Load_Char(s->face, code, s->ft_load_flags)) return AVERROR(EINVAL); /* save glyph */ @@ -277,15 +277,15 @@ static int load_glyph(AVFilterContext *ctx, Glyph **glyph_ptr, uint32_t code) } glyph->code = code; - if (FT_Get_Glyph(dtext->face->glyph, glyph->glyph)) { + if (FT_Get_Glyph(s->face->glyph, glyph->glyph)) { ret = AVERROR(EINVAL); goto error; } - glyph->bitmap = dtext->face->glyph->bitmap; - glyph->bitmap_left = dtext->face->glyph->bitmap_left; - glyph->bitmap_top = dtext->face->glyph->bitmap_top; - glyph->advance = dtext->face->glyph->advance.x >> 6; + glyph->bitmap = s->face->glyph->bitmap; + glyph->bitmap_left = s->face->glyph->bitmap_left; + glyph->bitmap_top = s->face->glyph->bitmap_top; + glyph->advance = s->face->glyph->advance.x >> 6; /* measure text height to calculate text_height (or the maximum text height) */ FT_Glyph_Get_CBox(*glyph->glyph, ft_glyph_bbox_pixels, &glyph->bbox); @@ -295,7 +295,7 @@ static int load_glyph(AVFilterContext *ctx, Glyph **glyph_ptr, uint32_t code) ret = AVERROR(ENOMEM); goto error; } - av_tree_insert(&dtext->glyphs, glyph, glyph_cmp, &node); + av_tree_insert(&s->glyphs, glyph, glyph_cmp, &node); if (glyph_ptr) *glyph_ptr = glyph; @@ -312,10 +312,10 @@ error: static int load_font_file(AVFilterContext *ctx, const char *path, int index, const char **error) { - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; int err; - err = FT_New_Face(dtext->library, path, index, &dtext->face); + err = FT_New_Face(s->library, path, index, &s->face); if (err) { *error = FT_ERRMSG(err); return AVERROR(EINVAL); @@ -326,7 +326,7 @@ static int load_font_file(AVFilterContext *ctx, const char *path, int index, #if CONFIG_FONTCONFIG static int load_font_fontconfig(AVFilterContext *ctx, const char **error) { - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; FcConfig *fontconfig; FcPattern *pattern, *fpat; FcResult result = FcResultMatch; @@ -339,7 +339,7 @@ static int load_font_fontconfig(AVFilterContext *ctx, const char **error) *error = "impossible to init fontconfig\n"; return AVERROR(EINVAL); } - pattern = FcNameParse(dtext->fontfile ? dtext->fontfile : + pattern = FcNameParse(s->fontfile ? s->fontfile : (uint8_t *)(intptr_t)"default"); if (!pattern) { *error = "could not parse fontconfig pattern"; @@ -362,8 +362,8 @@ static int load_font_fontconfig(AVFilterContext *ctx, const char **error) return AVERROR(EINVAL); } av_log(ctx, AV_LOG_INFO, "Using \"%s\"\n", filename); - if (!dtext->fontsize) - dtext->fontsize = size + 0.5; + if (!s->fontsize) + s->fontsize = size + 0.5; err = load_font_file(ctx, filename, index, error); if (err) return err; @@ -376,12 +376,12 @@ static int load_font_fontconfig(AVFilterContext *ctx, const char **error) static int load_font(AVFilterContext *ctx) { - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; int err; const char *error = "unknown error\n"; /* load the face, and set up the encoding, which is by default UTF-8 */ - err = load_font_file(ctx, dtext->fontfile, 0, &error); + err = load_font_file(ctx, s->fontfile, 0, &error); if (!err) return 0; #if CONFIG_FONTCONFIG @@ -390,28 +390,28 @@ static int load_font(AVFilterContext *ctx) return 0; #endif av_log(ctx, AV_LOG_ERROR, "Could not load font \"%s\": %s\n", - dtext->fontfile, error); + s->fontfile, error); return err; } static int load_textfile(AVFilterContext *ctx) { - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; int err; uint8_t *textbuf; size_t textbuf_size; - if ((err = av_file_map(dtext->textfile, &textbuf, &textbuf_size, 0, ctx)) < 0) { + if ((err = av_file_map(s->textfile, &textbuf, &textbuf_size, 0, ctx)) < 0) { av_log(ctx, AV_LOG_ERROR, "The text file '%s' could not be read or is empty\n", - dtext->textfile); + s->textfile); return err; } - if (!(dtext->text = av_realloc(dtext->text, textbuf_size + 1))) + if (!(s->text = av_realloc(s->text, textbuf_size + 1))) return AVERROR(ENOMEM); - memcpy(dtext->text, textbuf, textbuf_size); - dtext->text[textbuf_size] = 0; + memcpy(s->text, textbuf, textbuf_size); + s->text[textbuf_size] = 0; av_file_unmap(textbuf, textbuf_size); return 0; @@ -420,16 +420,16 @@ static int load_textfile(AVFilterContext *ctx) static av_cold int init(AVFilterContext *ctx) { int err; - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; Glyph *glyph; - if (!dtext->fontfile && !CONFIG_FONTCONFIG) { + if (!s->fontfile && !CONFIG_FONTCONFIG) { av_log(ctx, AV_LOG_ERROR, "No font filename provided\n"); return AVERROR(EINVAL); } - if (dtext->textfile) { - if (dtext->text) { + if (s->textfile) { + if (s->text) { av_log(ctx, AV_LOG_ERROR, "Both text and text file provided. Please provide only one\n"); return AVERROR(EINVAL); @@ -438,45 +438,45 @@ static av_cold int init(AVFilterContext *ctx) return err; } - if (dtext->reload && !dtext->textfile) + if (s->reload && !s->textfile) av_log(ctx, AV_LOG_WARNING, "No file to reload\n"); - if (dtext->tc_opt_string) { - int ret = av_timecode_init_from_string(&dtext->tc, dtext->tc_rate, - dtext->tc_opt_string, ctx); + if (s->tc_opt_string) { + int ret = av_timecode_init_from_string(&s->tc, s->tc_rate, + s->tc_opt_string, ctx); if (ret < 0) return ret; - if (dtext->tc24hmax) - dtext->tc.flags |= AV_TIMECODE_FLAG_24HOURSMAX; - if (!dtext->text) - dtext->text = av_strdup(""); + if (s->tc24hmax) + s->tc.flags |= AV_TIMECODE_FLAG_24HOURSMAX; + if (!s->text) + s->text = av_strdup(""); } - if (!dtext->text) { + if (!s->text) { av_log(ctx, AV_LOG_ERROR, "Either text, a valid file or a timecode must be provided\n"); return AVERROR(EINVAL); } - if ((err = av_parse_color(dtext->fontcolor.rgba, dtext->fontcolor_string, -1, ctx))) { + if ((err = av_parse_color(s->fontcolor.rgba, s->fontcolor_string, -1, ctx))) { av_log(ctx, AV_LOG_ERROR, - "Invalid font color '%s'\n", dtext->fontcolor_string); + "Invalid font color '%s'\n", s->fontcolor_string); return err; } - if ((err = av_parse_color(dtext->boxcolor.rgba, dtext->boxcolor_string, -1, ctx))) { + if ((err = av_parse_color(s->boxcolor.rgba, s->boxcolor_string, -1, ctx))) { av_log(ctx, AV_LOG_ERROR, - "Invalid box color '%s'\n", dtext->boxcolor_string); + "Invalid box color '%s'\n", s->boxcolor_string); return err; } - if ((err = av_parse_color(dtext->shadowcolor.rgba, dtext->shadowcolor_string, -1, ctx))) { + if ((err = av_parse_color(s->shadowcolor.rgba, s->shadowcolor_string, -1, ctx))) { av_log(ctx, AV_LOG_ERROR, - "Invalid shadow color '%s'\n", dtext->shadowcolor_string); + "Invalid shadow color '%s'\n", s->shadowcolor_string); return err; } - if ((err = FT_Init_FreeType(&(dtext->library)))) { + if ((err = FT_Init_FreeType(&(s->library)))) { av_log(ctx, AV_LOG_ERROR, "Could not load FreeType: %s\n", FT_ERRMSG(err)); return AVERROR(EINVAL); @@ -485,15 +485,15 @@ static av_cold int init(AVFilterContext *ctx) err = load_font(ctx); if (err) return err; - if (!dtext->fontsize) - dtext->fontsize = 16; - if ((err = FT_Set_Pixel_Sizes(dtext->face, 0, dtext->fontsize))) { + if (!s->fontsize) + s->fontsize = 16; + if ((err = FT_Set_Pixel_Sizes(s->face, 0, s->fontsize))) { av_log(ctx, AV_LOG_ERROR, "Could not set font size to %d pixels: %s\n", - dtext->fontsize, FT_ERRMSG(err)); + s->fontsize, FT_ERRMSG(err)); return AVERROR(EINVAL); } - dtext->use_kerning = FT_HAS_KERNING(dtext->face); + s->use_kerning = FT_HAS_KERNING(s->face); /* load the fallback glyph with code 0 */ load_glyph(ctx, NULL, 0); @@ -503,13 +503,13 @@ static av_cold int init(AVFilterContext *ctx) av_log(ctx, AV_LOG_ERROR, "Could not set tabsize.\n"); return err; } - dtext->tabsize *= glyph->advance; + s->tabsize *= glyph->advance; - if (dtext->exp_mode == EXP_STRFTIME && - (strchr(dtext->text, '%') || strchr(dtext->text, '\\'))) + if (s->exp_mode == EXP_STRFTIME && + (strchr(s->text, '%') || strchr(s->text, '\\'))) av_log(ctx, AV_LOG_WARNING, "expansion=strftime is deprecated.\n"); - av_bprint_init(&dtext->expanded_text, 0, AV_BPRINT_SIZE_UNLIMITED); + av_bprint_init(&s->expanded_text, 0, AV_BPRINT_SIZE_UNLIMITED); return 0; } @@ -532,24 +532,24 @@ static int glyph_enu_free(void *opaque, void *elem) static av_cold void uninit(AVFilterContext *ctx) { - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; - av_expr_free(dtext->x_pexpr); dtext->x_pexpr = NULL; - av_expr_free(dtext->y_pexpr); dtext->y_pexpr = NULL; - av_expr_free(dtext->draw_pexpr); dtext->draw_pexpr = NULL; + av_expr_free(s->x_pexpr); s->x_pexpr = NULL; + av_expr_free(s->y_pexpr); s->y_pexpr = NULL; + av_expr_free(s->draw_pexpr); s->draw_pexpr = NULL; - av_freep(&dtext->positions); - dtext->nb_positions = 0; + av_freep(&s->positions); + s->nb_positions = 0; - av_tree_enumerate(dtext->glyphs, NULL, NULL, glyph_enu_free); - av_tree_destroy(dtext->glyphs); - dtext->glyphs = NULL; + av_tree_enumerate(s->glyphs, NULL, NULL, glyph_enu_free); + av_tree_destroy(s->glyphs); + s->glyphs = NULL; - FT_Done_Face(dtext->face); - FT_Done_FreeType(dtext->library); + FT_Done_Face(s->face); + FT_Done_FreeType(s->library); - av_bprint_finalize(&dtext->expanded_text, NULL); + av_bprint_finalize(&s->expanded_text, NULL); } static inline int is_newline(uint32_t c) @@ -560,33 +560,33 @@ static inline int is_newline(uint32_t c) static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; int ret; - ff_draw_init(&dtext->dc, inlink->format, 0); - ff_draw_color(&dtext->dc, &dtext->fontcolor, dtext->fontcolor.rgba); - ff_draw_color(&dtext->dc, &dtext->shadowcolor, dtext->shadowcolor.rgba); - ff_draw_color(&dtext->dc, &dtext->boxcolor, dtext->boxcolor.rgba); - - dtext->var_values[VAR_w] = dtext->var_values[VAR_W] = dtext->var_values[VAR_MAIN_W] = inlink->w; - dtext->var_values[VAR_h] = dtext->var_values[VAR_H] = dtext->var_values[VAR_MAIN_H] = inlink->h; - dtext->var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ? av_q2d(inlink->sample_aspect_ratio) : 1; - dtext->var_values[VAR_DAR] = (double)inlink->w / inlink->h * dtext->var_values[VAR_SAR]; - dtext->var_values[VAR_HSUB] = 1 << dtext->dc.hsub_max; - dtext->var_values[VAR_VSUB] = 1 << dtext->dc.vsub_max; - dtext->var_values[VAR_X] = NAN; - dtext->var_values[VAR_Y] = NAN; - if (!dtext->reinit) - dtext->var_values[VAR_N] = 0; - dtext->var_values[VAR_T] = NAN; - - av_lfg_init(&dtext->prng, av_get_random_seed()); - - if ((ret = av_expr_parse(&dtext->x_pexpr, dtext->x_expr, var_names, + ff_draw_init(&s->dc, inlink->format, 0); + ff_draw_color(&s->dc, &s->fontcolor, s->fontcolor.rgba); + ff_draw_color(&s->dc, &s->shadowcolor, s->shadowcolor.rgba); + ff_draw_color(&s->dc, &s->boxcolor, s->boxcolor.rgba); + + s->var_values[VAR_w] = s->var_values[VAR_W] = s->var_values[VAR_MAIN_W] = inlink->w; + s->var_values[VAR_h] = s->var_values[VAR_H] = s->var_values[VAR_MAIN_H] = inlink->h; + s->var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ? av_q2d(inlink->sample_aspect_ratio) : 1; + s->var_values[VAR_DAR] = (double)inlink->w / inlink->h * s->var_values[VAR_SAR]; + s->var_values[VAR_HSUB] = 1 << s->dc.hsub_max; + s->var_values[VAR_VSUB] = 1 << s->dc.vsub_max; + s->var_values[VAR_X] = NAN; + s->var_values[VAR_Y] = NAN; + if (!s->reinit) + s->var_values[VAR_N] = 0; + s->var_values[VAR_T] = NAN; + + av_lfg_init(&s->prng, av_get_random_seed()); + + if ((ret = av_expr_parse(&s->x_pexpr, s->x_expr, var_names, NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 || - (ret = av_expr_parse(&dtext->y_pexpr, dtext->y_expr, var_names, + (ret = av_expr_parse(&s->y_pexpr, s->y_expr, var_names, NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 || - (ret = av_expr_parse(&dtext->draw_pexpr, dtext->draw_expr, var_names, + (ret = av_expr_parse(&s->draw_pexpr, s->draw_expr, var_names, NULL, NULL, fun2_names, fun2, 0, ctx)) < 0) return AVERROR(EINVAL); @@ -596,12 +596,12 @@ static int config_input(AVFilterLink *inlink) static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags) { - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; if (!strcmp(cmd, "reinit")) { int ret; uninit(ctx); - dtext->reinit = 1; + s->reinit = 1; if ((ret = init(ctx)) < 0) return ret; return config_input(ctx->inputs[0]); @@ -613,27 +613,27 @@ static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char static int func_pict_type(AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag) { - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; - av_bprintf(bp, "%c", av_get_picture_type_char(dtext->var_values[VAR_PICT_TYPE])); + av_bprintf(bp, "%c", av_get_picture_type_char(s->var_values[VAR_PICT_TYPE])); return 0; } static int func_pts(AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag) { - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; - av_bprintf(bp, "%.6f", dtext->var_values[VAR_T]); + av_bprintf(bp, "%.6f", s->var_values[VAR_T]); return 0; } static int func_frame_num(AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag) { - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; - av_bprintf(bp, "%d", (int)dtext->var_values[VAR_N]); + av_bprintf(bp, "%d", (int)s->var_values[VAR_N]); return 0; } @@ -663,13 +663,13 @@ static int func_strftime(AVFilterContext *ctx, AVBPrint *bp, static int func_eval_expr(AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag) { - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; double res; int ret; - ret = av_expr_parse_and_eval(&res, argv[0], var_names, dtext->var_values, + ret = av_expr_parse_and_eval(&res, argv[0], var_names, s->var_values, NULL, NULL, fun2_names, fun2, - &dtext->prng, 0, ctx); + &s->prng, 0, ctx); if (ret < 0) av_log(ctx, AV_LOG_ERROR, "Expression '%s' for the expr text expansion function is not valid\n", @@ -765,9 +765,9 @@ end: static int expand_text(AVFilterContext *ctx) { - DrawTextContext *dtext = ctx->priv; - char *text = dtext->text; - AVBPrint *bp = &dtext->expanded_text; + DrawTextContext *s = ctx->priv; + char *text = s->text; + AVBPrint *bp = &s->expanded_text; int ret; av_bprint_clear(bp); @@ -789,10 +789,10 @@ static int expand_text(AVFilterContext *ctx) return 0; } -static int draw_glyphs(DrawTextContext *dtext, AVFrame *frame, +static int draw_glyphs(DrawTextContext *s, AVFrame *frame, int width, int height, const uint8_t rgbcolor[4], FFDrawColor *color, int x, int y) { - char *text = dtext->expanded_text.str; + char *text = s->expanded_text.str; uint32_t code = 0; int i, x1, y1; uint8_t *p; @@ -807,16 +807,16 @@ static int draw_glyphs(DrawTextContext *dtext, AVFrame *frame, continue; dummy.code = code; - glyph = av_tree_find(dtext->glyphs, &dummy, (void *)glyph_cmp, NULL); + glyph = av_tree_find(s->glyphs, &dummy, (void *)glyph_cmp, NULL); if (glyph->bitmap.pixel_mode != FT_PIXEL_MODE_MONO && glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY) return AVERROR(EINVAL); - x1 = dtext->positions[i].x+dtext->x+x; - y1 = dtext->positions[i].y+dtext->y+y; + x1 = s->positions[i].x+s->x+x; + y1 = s->positions[i].y+s->y+y; - ff_blend_mask(&dtext->dc, color, + ff_blend_mask(&s->dc, color, frame->data, frame->linesize, width, height, glyph->bitmap.buffer, glyph->bitmap.pitch, glyph->bitmap.width, glyph->bitmap.rows, @@ -830,13 +830,14 @@ static int draw_glyphs(DrawTextContext *dtext, AVFrame *frame, static int draw_text(AVFilterContext *ctx, AVFrame *frame, int width, int height) { - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; + uint32_t code = 0, prev_code = 0; int x = 0, y = 0, i = 0, ret; int max_text_line_w = 0, len; int box_w, box_h; - char *text = dtext->text; + char *text = s->text; uint8_t *p; int y_min = 32000, y_max = -32000; int x_min = 32000, x_max = -32000; @@ -846,16 +847,16 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, time_t now = time(0); struct tm ltime; - AVBPrint *bp = &dtext->expanded_text; + AVBPrint *bp = &s->expanded_text; av_bprint_clear(bp); - if(dtext->basetime != AV_NOPTS_VALUE) - now= frame->pts*av_q2d(ctx->inputs[0]->time_base) + dtext->basetime/1000000; + if(s->basetime != AV_NOPTS_VALUE) + now= frame->pts*av_q2d(ctx->inputs[0]->time_base) + s->basetime/1000000; - switch (dtext->exp_mode) { + switch (s->exp_mode) { case EXP_NONE: - av_bprintf(bp, "%s", dtext->text); + av_bprintf(bp, "%s", s->text); break; case EXP_NORMAL: if ((ret = expand_text(ctx)) < 0) @@ -863,25 +864,25 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, break; case EXP_STRFTIME: localtime_r(&now, <ime); - av_bprint_strftime(bp, dtext->text, <ime); + av_bprint_strftime(bp, s->text, <ime); break; } - if (dtext->tc_opt_string) { + if (s->tc_opt_string) { char tcbuf[AV_TIMECODE_STR_SIZE]; - av_timecode_make_string(&dtext->tc, tcbuf, inlink->frame_count); + av_timecode_make_string(&s->tc, tcbuf, inlink->frame_count); av_bprint_clear(bp); - av_bprintf(bp, "%s%s", dtext->text, tcbuf); + av_bprintf(bp, "%s%s", s->text, tcbuf); } if (!av_bprint_is_complete(bp)) return AVERROR(ENOMEM); - text = dtext->expanded_text.str; - if ((len = dtext->expanded_text.len) > dtext->nb_positions) { - if (!(dtext->positions = - av_realloc(dtext->positions, len*sizeof(*dtext->positions)))) + text = s->expanded_text.str; + if ((len = s->expanded_text.len) > s->nb_positions) { + if (!(s->positions = + av_realloc(s->positions, len*sizeof(*s->positions)))) return AVERROR(ENOMEM); - dtext->nb_positions = len; + s->nb_positions = len; } x = 0; @@ -893,7 +894,7 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, /* get glyph */ dummy.code = code; - glyph = av_tree_find(dtext->glyphs, &dummy, glyph_cmp, NULL); + glyph = av_tree_find(s->glyphs, &dummy, glyph_cmp, NULL); if (!glyph) { load_glyph(ctx, &glyph, code); } @@ -903,8 +904,8 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, x_min = FFMIN(glyph->bbox.xMin, x_min); x_max = FFMAX(glyph->bbox.xMax, x_max); } - dtext->max_glyph_h = y_max - y_min; - dtext->max_glyph_w = x_max - x_min; + s->max_glyph_h = y_max - y_min; + s->max_glyph_w = x_max - x_min; /* compute and save position for each glyph */ glyph = NULL; @@ -917,8 +918,9 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, prev_code = code; if (is_newline(code)) { + max_text_line_w = FFMAX(max_text_line_w, x); - y += dtext->max_glyph_h; + y += s->max_glyph_h; x = 0; continue; } @@ -926,59 +928,59 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, /* get glyph */ prev_glyph = glyph; dummy.code = code; - glyph = av_tree_find(dtext->glyphs, &dummy, glyph_cmp, NULL); + glyph = av_tree_find(s->glyphs, &dummy, glyph_cmp, NULL); /* kerning */ - if (dtext->use_kerning && prev_glyph && glyph->code) { - FT_Get_Kerning(dtext->face, prev_glyph->code, glyph->code, + if (s->use_kerning && prev_glyph && glyph->code) { + FT_Get_Kerning(s->face, prev_glyph->code, glyph->code, ft_kerning_default, &delta); x += delta.x >> 6; } /* save position */ - dtext->positions[i].x = x + glyph->bitmap_left; - dtext->positions[i].y = y - glyph->bitmap_top + y_max; - if (code == '\t') x = (x / dtext->tabsize + 1)*dtext->tabsize; + s->positions[i].x = x + glyph->bitmap_left; + s->positions[i].y = y - glyph->bitmap_top + y_max; + if (code == '\t') x = (x / s->tabsize + 1)*s->tabsize; else x += glyph->advance; } max_text_line_w = FFMAX(x, max_text_line_w); - dtext->var_values[VAR_TW] = dtext->var_values[VAR_TEXT_W] = max_text_line_w; - dtext->var_values[VAR_TH] = dtext->var_values[VAR_TEXT_H] = y + dtext->max_glyph_h; + s->var_values[VAR_TW] = s->var_values[VAR_TEXT_W] = max_text_line_w; + s->var_values[VAR_TH] = s->var_values[VAR_TEXT_H] = y + s->max_glyph_h; - dtext->var_values[VAR_MAX_GLYPH_W] = dtext->max_glyph_w; - dtext->var_values[VAR_MAX_GLYPH_H] = dtext->max_glyph_h; - dtext->var_values[VAR_MAX_GLYPH_A] = dtext->var_values[VAR_ASCENT ] = y_max; - dtext->var_values[VAR_MAX_GLYPH_D] = dtext->var_values[VAR_DESCENT] = y_min; + s->var_values[VAR_MAX_GLYPH_W] = s->max_glyph_w; + s->var_values[VAR_MAX_GLYPH_H] = s->max_glyph_h; + s->var_values[VAR_MAX_GLYPH_A] = s->var_values[VAR_ASCENT ] = y_max; + s->var_values[VAR_MAX_GLYPH_D] = s->var_values[VAR_DESCENT] = y_min; - dtext->var_values[VAR_LINE_H] = dtext->var_values[VAR_LH] = dtext->max_glyph_h; + s->var_values[VAR_LINE_H] = s->var_values[VAR_LH] = s->max_glyph_h; - dtext->x = dtext->var_values[VAR_X] = av_expr_eval(dtext->x_pexpr, dtext->var_values, &dtext->prng); - dtext->y = dtext->var_values[VAR_Y] = av_expr_eval(dtext->y_pexpr, dtext->var_values, &dtext->prng); - dtext->x = dtext->var_values[VAR_X] = av_expr_eval(dtext->x_pexpr, dtext->var_values, &dtext->prng); - dtext->draw = av_expr_eval(dtext->draw_pexpr, dtext->var_values, &dtext->prng); + s->x = s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, &s->prng); + s->y = s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, &s->prng); + s->x = s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, &s->prng); + s->draw = av_expr_eval(s->draw_pexpr, s->var_values, &s->prng); - if(!dtext->draw) + if(!s->draw) return 0; box_w = FFMIN(width - 1 , max_text_line_w); - box_h = FFMIN(height - 1, y + dtext->max_glyph_h); + box_h = FFMIN(height - 1, y + s->max_glyph_h); /* draw box */ - if (dtext->draw_box) - ff_blend_rectangle(&dtext->dc, &dtext->boxcolor, + if (s->draw_box) + ff_blend_rectangle(&s->dc, &s->boxcolor, frame->data, frame->linesize, width, height, - dtext->x, dtext->y, box_w, box_h); + s->x, s->y, box_w, box_h); - if (dtext->shadowx || dtext->shadowy) { - if ((ret = draw_glyphs(dtext, frame, width, height, dtext->shadowcolor.rgba, - &dtext->shadowcolor, dtext->shadowx, dtext->shadowy)) < 0) + if (s->shadowx || s->shadowy) { + if ((ret = draw_glyphs(s, frame, width, height, s->shadowcolor.rgba, + &s->shadowcolor, s->shadowx, s->shadowy)) < 0) return ret; } - if ((ret = draw_glyphs(dtext, frame, width, height, dtext->fontcolor.rgba, - &dtext->fontcolor, 0, 0)) < 0) + if ((ret = draw_glyphs(s, frame, width, height, s->fontcolor.rgba, + &s->fontcolor, 0, 0)) < 0) return ret; return 0; @@ -988,25 +990,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) { AVFilterContext *ctx = inlink->dst; AVFilterLink *outlink = ctx->outputs[0]; - DrawTextContext *dtext = ctx->priv; + DrawTextContext *s = ctx->priv; int ret; - if (dtext->reload) + if (s->reload) if ((ret = load_textfile(ctx)) < 0) return ret; - dtext->var_values[VAR_N] = inlink->frame_count; - dtext->var_values[VAR_T] = frame->pts == AV_NOPTS_VALUE ? + s->var_values[VAR_N] = inlink->frame_count; + s->var_values[VAR_T] = frame->pts == AV_NOPTS_VALUE ? NAN : frame->pts * av_q2d(inlink->time_base); - dtext->var_values[VAR_PICT_TYPE] = frame->pict_type; + s->var_values[VAR_PICT_TYPE] = frame->pict_type; draw_text(ctx, frame, frame->width, frame->height); av_log(ctx, AV_LOG_DEBUG, "n:%d t:%f text_w:%d text_h:%d x:%d y:%d\n", - (int)dtext->var_values[VAR_N], dtext->var_values[VAR_T], - (int)dtext->var_values[VAR_TEXT_W], (int)dtext->var_values[VAR_TEXT_H], - dtext->x, dtext->y); + (int)s->var_values[VAR_N], s->var_values[VAR_T], + (int)s->var_values[VAR_TEXT_W], (int)s->var_values[VAR_TEXT_H], + s->x, s->y); return ff_filter_frame(outlink, frame); } diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c index 96f04080f4..a24fb2ac8e 100644 --- a/libavfilter/vf_fade.c +++ b/libavfilter/vf_fade.c @@ -66,28 +66,28 @@ typedef struct { static av_cold int init(AVFilterContext *ctx) { - FadeContext *fade = ctx->priv; + FadeContext *s = ctx->priv; - fade->fade_per_frame = (1 << 16) / fade->nb_frames; - fade->fade_state = VF_FADE_WAITING; + s->fade_per_frame = (1 << 16) / s->nb_frames; + s->fade_state = VF_FADE_WAITING; - if (fade->duration != 0) { + if (s->duration != 0) { // If duration (seconds) is non-zero, assume that we are not fading based on frames - fade->nb_frames = 0; // Mostly to clean up logging + s->nb_frames = 0; // Mostly to clean up logging } // Choose what to log. If both time-based and frame-based options, both lines will be in the log - if (fade->start_frame || fade->nb_frames) { + if (s->start_frame || s->nb_frames) { av_log(ctx, AV_LOG_VERBOSE, "type:%s start_frame:%d nb_frames:%d alpha:%d\n", - fade->type == FADE_IN ? "in" : "out", fade->start_frame, - fade->nb_frames,fade->alpha); + s->type == FADE_IN ? "in" : "out", s->start_frame, + s->nb_frames,s->alpha); } - if (fade->start_time || fade->duration) { + if (s->start_time || s->duration) { av_log(ctx, AV_LOG_VERBOSE, "type:%s start_time:%f duration:%f alpha:%d\n", - fade->type == FADE_IN ? "in" : "out", (fade->start_time / (double)AV_TIME_BASE), - (fade->duration / (double)AV_TIME_BASE),fade->alpha); + s->type == FADE_IN ? "in" : "out", (s->start_time / (double)AV_TIME_BASE), + (s->duration / (double)AV_TIME_BASE),s->alpha); } return 0; @@ -120,22 +120,22 @@ const static enum AVPixelFormat studio_level_pix_fmts[] = { static int config_props(AVFilterLink *inlink) { - FadeContext *fade = inlink->dst->priv; + FadeContext *s = inlink->dst->priv; const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(inlink->format); - fade->hsub = pixdesc->log2_chroma_w; - fade->vsub = pixdesc->log2_chroma_h; + s->hsub = pixdesc->log2_chroma_w; + s->vsub = pixdesc->log2_chroma_h; - fade->bpp = av_get_bits_per_pixel(pixdesc) >> 3; - fade->alpha &= pixdesc->flags & AV_PIX_FMT_FLAG_ALPHA; - fade->is_packed_rgb = ff_fill_rgba_map(fade->rgba_map, inlink->format) >= 0; + s->bpp = av_get_bits_per_pixel(pixdesc) >> 3; + s->alpha &= pixdesc->flags & AV_PIX_FMT_FLAG_ALPHA; + s->is_packed_rgb = ff_fill_rgba_map(s->rgba_map, inlink->format) >= 0; /* use CCIR601/709 black level for studio-level pixel non-alpha components */ - fade->black_level = - ff_fmt_is_in(inlink->format, studio_level_pix_fmts) && !fade->alpha ? 16 : 0; + s->black_level = + ff_fmt_is_in(inlink->format, studio_level_pix_fmts) && !s->alpha ? 16 : 0; /* 32768 = 1 << 15, it is an integer representation * of 0.5 and is for rounding. */ - fade->black_level_scaled = (fade->black_level << 16) + 32768; + s->black_level_scaled = (s->black_level << 16) + 32768; return 0; } @@ -151,7 +151,7 @@ static void fade_plane(int y, int h, int w, for (i = 0; i < h; i++) { p = data + offset + (y+i) * line_size; for (j = 0; j < w * bytes_per_plane; j++) { - /* fade->factor is using 16 lower-order bits for decimal places. */ + /* s->factor is using 16 lower-order bits for decimal places. */ *p = ((*p - black_level) * fade_factor + black_level_scaled) >> 16; p+=step; } @@ -160,86 +160,86 @@ static void fade_plane(int y, int h, int w, static int filter_frame(AVFilterLink *inlink, AVFrame *frame) { - FadeContext *fade = inlink->dst->priv; + FadeContext *s = inlink->dst->priv; uint8_t *p; int i, j, plane; double frame_timestamp = frame->pts == AV_NOPTS_VALUE ? -1 : frame->pts * av_q2d(inlink->time_base); // Calculate Fade assuming this is a Fade In - if (fade->fade_state == VF_FADE_WAITING) { - fade->factor=0; - if ((frame_timestamp >= (fade->start_time/(double)AV_TIME_BASE)) - && (fade->frame_index >= fade->start_frame)) { + if (s->fade_state == VF_FADE_WAITING) { + s->factor=0; + if ((frame_timestamp >= (s->start_time/(double)AV_TIME_BASE)) + && (s->frame_index >= s->start_frame)) { // Time to start fading - fade->fade_state = VF_FADE_FADING; + s->fade_state = VF_FADE_FADING; // Save start time in case we are starting based on frames and fading based on time - if ((fade->start_time == 0) && (fade->start_frame != 0)) { - fade->start_time = frame_timestamp*(double)AV_TIME_BASE; + if ((s->start_time == 0) && (s->start_frame != 0)) { + s->start_time = frame_timestamp*(double)AV_TIME_BASE; } // Save start frame in case we are starting based on time and fading based on frames - if ((fade->start_time != 0) && (fade->start_frame == 0)) { - fade->start_frame = fade->frame_index; + if ((s->start_time != 0) && (s->start_frame == 0)) { + s->start_frame = s->frame_index; } } } - if (fade->fade_state == VF_FADE_FADING) { - if (fade->duration == 0) { + if (s->fade_state == VF_FADE_FADING) { + if (s->duration == 0) { // Fading based on frame count - fade->factor = (fade->frame_index - fade->start_frame) * fade->fade_per_frame; - if (fade->frame_index > (fade->start_frame + fade->nb_frames)) { - fade->fade_state = VF_FADE_DONE; + s->factor = (s->frame_index - s->start_frame) * s->fade_per_frame; + if (s->frame_index > (s->start_frame + s->nb_frames)) { + s->fade_state = VF_FADE_DONE; } } else { // Fading based on duration - fade->factor = (frame_timestamp - (fade->start_time/(double)AV_TIME_BASE)) - * (float) UINT16_MAX / (fade->duration/(double)AV_TIME_BASE); - if (frame_timestamp > ((fade->start_time/(double)AV_TIME_BASE) - + (fade->duration/(double)AV_TIME_BASE))) { - fade->fade_state = VF_FADE_DONE; + s->factor = (frame_timestamp - (s->start_time/(double)AV_TIME_BASE)) + * (float) UINT16_MAX / (s->duration/(double)AV_TIME_BASE); + if (frame_timestamp > ((s->start_time/(double)AV_TIME_BASE) + + (s->duration/(double)AV_TIME_BASE))) { + s->fade_state = VF_FADE_DONE; } } } - if (fade->fade_state == VF_FADE_DONE) { - fade->factor=UINT16_MAX; + if (s->fade_state == VF_FADE_DONE) { + s->factor=UINT16_MAX; } - fade->factor = av_clip_uint16(fade->factor); + s->factor = av_clip_uint16(s->factor); // Invert fade_factor if Fading Out - if (fade->type == 1) { - fade->factor=UINT16_MAX-fade->factor; + if (s->type == 1) { + s->factor=UINT16_MAX-s->factor; } - if (fade->factor < UINT16_MAX) { - if (fade->alpha) { + if (s->factor < UINT16_MAX) { + if (s->alpha) { // alpha only - plane = fade->is_packed_rgb ? 0 : A; // alpha is on plane 0 for packed formats + plane = s->is_packed_rgb ? 0 : A; // alpha is on plane 0 for packed formats // or plane 3 for planar formats fade_plane(0, frame->height, inlink->w, - fade->factor, fade->black_level, fade->black_level_scaled, - fade->is_packed_rgb ? fade->rgba_map[A] : 0, // alpha offset for packed formats - fade->is_packed_rgb ? 4 : 1, // pixstep for 8 bit packed formats + s->factor, s->black_level, s->black_level_scaled, + s->is_packed_rgb ? s->rgba_map[A] : 0, // alpha offset for packed formats + s->is_packed_rgb ? 4 : 1, // pixstep for 8 bit packed formats 1, frame->data[plane], frame->linesize[plane]); } else { /* luma or rgb plane */ fade_plane(0, frame->height, inlink->w, - fade->factor, fade->black_level, fade->black_level_scaled, + s->factor, s->black_level, s->black_level_scaled, 0, 1, // offset & pixstep for Y plane or RGB packed format - fade->bpp, frame->data[0], frame->linesize[0]); + s->bpp, frame->data[0], frame->linesize[0]); if (frame->data[1] && frame->data[2]) { /* chroma planes */ for (plane = 1; plane < 3; plane++) { for (i = 0; i < frame->height; i++) { - const int width = FF_CEIL_RSHIFT(inlink->w, fade->hsub); - p = frame->data[plane] + (i >> fade->vsub) * frame->linesize[plane]; + const int width = FF_CEIL_RSHIFT(inlink->w, s->hsub); + p = frame->data[plane] + (i >> s->vsub) * frame->linesize[plane]; for (j = 0; j < width; j++) { /* 8421367 = ((128 << 1) + 1) << 15. It is an integer * representation of 128.5. The .5 is for rounding * purposes. */ - *p = ((*p - 128) * fade->factor + 8421367) >> 16; + *p = ((*p - 128) * s->factor + 8421367) >> 16; p++; } } @@ -248,7 +248,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) } } - fade->frame_index++; + s->frame_index++; return ff_filter_frame(inlink->dst->outputs[0], frame); } |