~ubuntu-branches/ubuntu/utopic/libav/utopic

« back to all changes in this revision

Viewing changes to libavfilter/vf_drawtext.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-12-21 15:32:13 UTC
  • mto: (1.2.18)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: package-import@ubuntu.com-20121221153213-fudzrugjzivtv0wp
Tags: upstream-9~beta3
ImportĀ upstreamĀ versionĀ 9~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#include "internal.h"
47
47
#include "video.h"
48
48
 
49
 
#undef time
50
 
 
51
49
#include <ft2build.h>
52
50
#include <freetype/config/ftheader.h>
53
51
#include FT_FREETYPE_H
263
261
    FT_Glyph_Get_CBox(*glyph->glyph, ft_glyph_bbox_pixels, &glyph->bbox);
264
262
 
265
263
    /* cache the newly created glyph */
266
 
    if (!(node = av_mallocz(av_tree_node_size))) {
 
264
    if (!(node = av_tree_node_alloc())) {
267
265
        ret = AVERROR(ENOMEM);
268
266
        goto error;
269
267
    }
792
790
    return 0;
793
791
}
794
792
 
795
 
static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
796
 
{
797
 
    return 0;
798
 
}
799
 
 
800
793
static inline int normalize_double(int *n, double d)
801
794
{
802
795
    int ret = 0;
812
805
    return ret;
813
806
}
814
807
 
815
 
static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 
808
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame)
816
809
{
817
810
    AVFilterContext *ctx = inlink->dst;
818
811
    DrawTextContext *dtext = ctx->priv;
819
 
    AVFilterBufferRef *buf_out;
820
812
    int ret = 0;
821
813
 
822
814
    if ((ret = dtext_prepare_text(ctx)) < 0) {
823
815
        av_log(ctx, AV_LOG_ERROR, "Can't draw text\n");
 
816
        avfilter_unref_bufferp(&frame);
824
817
        return ret;
825
818
    }
826
819
 
827
 
    dtext->var_values[VAR_T] = inpicref->pts == AV_NOPTS_VALUE ?
828
 
        NAN : inpicref->pts * av_q2d(inlink->time_base);
 
820
    dtext->var_values[VAR_T] = frame->pts == AV_NOPTS_VALUE ?
 
821
        NAN : frame->pts * av_q2d(inlink->time_base);
829
822
    dtext->var_values[VAR_X] =
830
823
        av_expr_eval(dtext->x_pexpr, dtext->var_values, &dtext->prng);
831
824
    dtext->var_values[VAR_Y] =
854
847
            (int)dtext->var_values[VAR_N], dtext->var_values[VAR_T],
855
848
            dtext->x, dtext->y, dtext->x+dtext->w, dtext->y+dtext->h);
856
849
 
857
 
    buf_out = avfilter_ref_buffer(inpicref, ~0);
858
 
    if (!buf_out)
859
 
        return AVERROR(ENOMEM);
860
 
 
861
 
    return ff_start_frame(inlink->dst->outputs[0], buf_out);
862
 
}
863
 
 
864
 
static int end_frame(AVFilterLink *inlink)
865
 
{
866
 
    AVFilterLink *outlink = inlink->dst->outputs[0];
867
 
    AVFilterBufferRef *picref = inlink->cur_buf;
868
 
    DrawTextContext *dtext = inlink->dst->priv;
869
 
    int ret;
870
 
 
871
850
    if (dtext->draw)
872
 
        draw_text(inlink->dst, picref, picref->video->w, picref->video->h);
 
851
        draw_text(inlink->dst, frame, frame->video->w, frame->video->h);
873
852
 
874
853
    dtext->var_values[VAR_N] += 1.0;
875
854
 
876
 
    if ((ret = ff_draw_slice(outlink, 0, picref->video->h, 1)) < 0 ||
877
 
        (ret = ff_end_frame(outlink)) < 0)
878
 
        return ret;
879
 
    return 0;
 
855
    return ff_filter_frame(inlink->dst->outputs[0], frame);
880
856
}
881
857
 
882
858
static const AVFilterPad avfilter_vf_drawtext_inputs[] = {
884
860
        .name             = "default",
885
861
        .type             = AVMEDIA_TYPE_VIDEO,
886
862
        .get_video_buffer = ff_null_get_video_buffer,
887
 
        .start_frame      = start_frame,
888
 
        .draw_slice       = null_draw_slice,
889
 
        .end_frame        = end_frame,
 
863
        .filter_frame     = filter_frame,
890
864
        .config_props     = config_input,
891
865
        .min_perms        = AV_PERM_WRITE |
892
866
                            AV_PERM_READ,