Lines Matching refs:dtext
228 DrawTextContext *dtext = ctx->priv;
233 /* load glyph into dtext->face->glyph */
234 if (FT_Load_Char(dtext->face, code, dtext->ft_load_flags))
245 if (FT_Get_Glyph(dtext->face->glyph, glyph->glyph)) {
250 glyph->bitmap = dtext->face->glyph->bitmap;
251 glyph->bitmap_left = dtext->face->glyph->bitmap_left;
252 glyph->bitmap_top = dtext->face->glyph->bitmap_top;
253 glyph->advance = dtext->face->glyph->advance.x >> 6;
263 av_tree_insert(&dtext->glyphs, glyph, glyph_cmp, &node);
280 DrawTextContext *dtext = ctx->priv;
283 dtext->class = &drawtext_class;
284 av_opt_set_defaults(dtext);
285 dtext->fontcolor_string = av_strdup("black");
286 dtext->boxcolor_string = av_strdup("white");
287 dtext->shadowcolor_string = av_strdup("black");
289 if ((err = (av_set_options_string(dtext, args, "=", ":"))) < 0) {
294 if (!dtext->fontfile) {
299 if (dtext->textfile) {
303 if (dtext->text) {
308 if ((err = av_file_map(dtext->textfile, &textbuf, &textbuf_size, 0, ctx)) < 0) {
311 dtext->textfile);
315 if (!(dtext->text = av_malloc(textbuf_size+1)))
317 memcpy(dtext->text, textbuf, textbuf_size);
318 dtext->text[textbuf_size] = 0;
322 if (!dtext->text) {
328 if ((err = av_parse_color(dtext->fontcolor_rgba, dtext->fontcolor_string, -1, ctx))) {
330 "Invalid font color '%s'\n", dtext->fontcolor_string);
334 if ((err = av_parse_color(dtext->boxcolor_rgba, dtext->boxcolor_string, -1, ctx))) {
336 "Invalid box color '%s'\n", dtext->boxcolor_string);
340 if ((err = av_parse_color(dtext->shadowcolor_rgba, dtext->shadowcolor_string, -1, ctx))) {
342 "Invalid shadow color '%s'\n", dtext->shadowcolor_string);
346 if ((err = FT_Init_FreeType(&(dtext->library)))) {
353 if ((err = FT_New_Face(dtext->library, dtext->fontfile, 0, &dtext->face))) {
355 dtext->fontfile, FT_ERRMSG(err));
358 if ((err = FT_Set_Pixel_Sizes(dtext->face, 0, dtext->fontsize))) {
360 dtext->fontsize, FT_ERRMSG(err));
364 dtext->use_kerning = FT_HAS_KERNING(dtext->face);
374 dtext->tabsize *= glyph->advance;
407 DrawTextContext *dtext = ctx->priv;
410 av_freep(&dtext->fontfile);
411 av_freep(&dtext->text);
412 av_freep(&dtext->expanded_text);
413 av_freep(&dtext->fontcolor_string);
414 av_freep(&dtext->boxcolor_string);
415 av_freep(&dtext->positions);
416 av_freep(&dtext->shadowcolor_string);
417 av_tree_enumerate(dtext->glyphs, NULL, NULL, glyph_enu_free);
418 av_tree_destroy(dtext->glyphs);
419 dtext->glyphs = 0;
420 FT_Done_Face(dtext->face);
421 FT_Done_FreeType(dtext->library);
424 av_freep(&dtext->box_line[i]);
425 dtext->pixel_step[i] = 0;
437 DrawTextContext *dtext = ctx->priv;
441 char *text = dtext->text;
454 uint8_t *buf = dtext->expanded_text;
455 int buf_size = dtext->expanded_text_size;
458 buf_size = 2*strlen(dtext->text)+1;
464 if (strftime(buf, buf_size, dtext->text, <ime) != 0 || *buf == 0)
471 text = dtext->expanded_text = buf;
472 dtext->expanded_text_size = buf_size;
475 if ((len = strlen(text)) > dtext->nb_positions) {
476 FT_Vector *p = av_realloc(dtext->positions,
477 len * sizeof(*dtext->positions));
479 av_freep(dtext->positions);
480 dtext->nb_positions = 0;
483 dtext->positions = p;
484 dtext->nb_positions = len;
494 glyph = av_tree_find(dtext->glyphs, &dummy, glyph_cmp, NULL);
516 str_w = FFMAX(str_w, x - dtext->x);
525 glyph = av_tree_find(dtext->glyphs, &dummy, glyph_cmp, NULL);
528 if (dtext->use_kerning && prev_glyph && glyph->code) {
529 FT_Get_Kerning(dtext->face, prev_glyph->code, glyph->code,
541 dtext->positions[i].x = x + glyph->bitmap_left;
542 dtext->positions[i].y = y - glyph->bitmap_top + baseline;
543 if (code == '\t') x = (x / dtext->tabsize + 1)*dtext->tabsize;
550 dtext->w = str_w;
551 dtext->h = y;
560 DrawTextContext *dtext = ctx->priv;
564 dtext->hsub = pix_desc->log2_chroma_w;
565 dtext->vsub = pix_desc->log2_chroma_h;
567 dtext->var_values[VAR_E ] = M_E;
568 dtext->var_values[VAR_PHI] = M_PHI;
569 dtext->var_values[VAR_PI ] = M_PI;
571 dtext->var_values[VAR_MAIN_W] =
572 dtext->var_values[VAR_MW] = ctx->inputs[0]->w;
573 dtext->var_values[VAR_MAIN_H] =
574 dtext->var_values[VAR_MH] = ctx->inputs[0]->h;
576 dtext->var_values[VAR_X] = 0;
577 dtext->var_values[VAR_Y] = 0;
578 dtext->var_values[VAR_N] = 0;
579 dtext->var_values[VAR_T] = NAN;
581 av_lfg_init(&dtext->prng, av_get_random_seed());
583 if ((ret = av_expr_parse(&dtext->x_pexpr, dtext->x_expr, var_names,
585 (ret = av_expr_parse(&dtext->y_pexpr, dtext->y_expr, var_names,
587 (ret = av_expr_parse(&dtext->d_pexpr, dtext->d_expr, var_names,
592 ff_fill_line_with_color(dtext->box_line, dtext->pixel_step,
593 inlink->w, dtext->boxcolor,
594 inlink->format, dtext->boxcolor_rgba,
595 &dtext->is_packed_rgb, dtext->rgba_map)) < 0)
598 if (!dtext->is_packed_rgb) {
599 uint8_t *rgba = dtext->fontcolor_rgba;
600 dtext->fontcolor[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
601 dtext->fontcolor[1] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
602 dtext->fontcolor[2] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
603 dtext->fontcolor[3] = rgba[3];
604 rgba = dtext->shadowcolor_rgba;
605 dtext->shadowcolor[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
606 dtext->shadowcolor[1] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
607 dtext->shadowcolor[2] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
608 dtext->shadowcolor[3] = rgba[3];
611 dtext->draw = 1;
714 static int draw_glyphs(DrawTextContext *dtext, AVFilterBufferRef *picref,
717 char *text = HAVE_LOCALTIME_R ? dtext->expanded_text : dtext->text;
732 glyph = av_tree_find(dtext->glyphs, &dummy, (void *)glyph_cmp, NULL);
738 if (dtext->is_packed_rgb) {
740 dtext->positions[i].x+x, dtext->positions[i].y+y, width, height,
741 dtext->pixel_step[0], rgbcolor, dtext->rgba_map);
744 dtext->positions[i].x+x, dtext->positions[i].y+y, width, height,
745 yuvcolor, dtext->hsub, dtext->vsub);
755 DrawTextContext *dtext = ctx->priv;
759 if (dtext->draw_box)
760 drawbox(picref, dtext->x, dtext->y, dtext->w, dtext->h,
761 dtext->box_line, dtext->pixel_step, dtext->boxcolor,
762 dtext->hsub, dtext->vsub, dtext->is_packed_rgb,
763 dtext->rgba_map);
765 if (dtext->shadowx || dtext->shadowy) {
766 if ((ret = draw_glyphs(dtext, picref, width, height,
767 dtext->shadowcolor_rgba,
768 dtext->shadowcolor,
769 dtext->x + dtext->shadowx,
770 dtext->y + dtext->shadowy)) < 0)
774 if ((ret = draw_glyphs(dtext, picref, width, height,
775 dtext->fontcolor_rgba,
776 dtext->fontcolor,
777 dtext->x,
778 dtext->y)) < 0)
804 DrawTextContext *dtext = ctx->priv;
812 dtext->var_values[VAR_T] = inpicref->pts == AV_NOPTS_VALUE ?
814 dtext->var_values[VAR_X] =
815 av_expr_eval(dtext->x_pexpr, dtext->var_values, &dtext->prng);
816 dtext->var_values[VAR_Y] =
817 av_expr_eval(dtext->y_pexpr, dtext->var_values, &dtext->prng);
818 dtext->var_values[VAR_X] =
819 av_expr_eval(dtext->x_pexpr, dtext->var_values, &dtext->prng);
821 dtext->draw = fail ? 0 :
822 av_expr_eval(dtext->d_pexpr, dtext->var_values, &dtext->prng);
824 normalize_double(&dtext->x, dtext->var_values[VAR_X]);
825 normalize_double(&dtext->y, dtext->var_values[VAR_Y]);
827 if (dtext->x < 0) dtext->x = 0;
828 if (dtext->y < 0) dtext->y = 0;
829 if ((unsigned)dtext->x + (unsigned)dtext->w > inlink->w)
830 dtext->x = inlink->w - dtext->w;
831 if ((unsigned)dtext->y + (unsigned)dtext->h > inlink->h)
832 dtext->y = inlink->h - dtext->h;
834 dtext->x &= ~((1 << dtext->hsub) - 1);
835 dtext->y &= ~((1 << dtext->vsub) - 1);
838 (int)dtext->var_values[VAR_N], dtext->var_values[VAR_T],
839 dtext->x, dtext->y, dtext->x+dtext->w, dtext->y+dtext->h);
848 DrawTextContext *dtext = inlink->dst->priv;
850 if (dtext->draw)
853 dtext->var_values[VAR_N] += 1.0;