~ubuntu-branches/ubuntu/trusty/libav/trusty-proposed

« back to all changes in this revision

Viewing changes to libavfilter/vf_drawbox.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2013-10-22 23:24:08 UTC
  • mfrom: (1.3.36 sid)
  • Revision ID: package-import@ubuntu.com-20131022232408-b8tvvn4pyzri9mi3
Tags: 6:9.10-1ubuntu1
* Build all -extra flavors from this source package, as libav got demoted
  from main to universe, cf LP: #1243235
* Simplify debian/rules to follow exactly the code that debian executes
* New upstream (LP: #1180288) fixes lots of security issues (LP: #1242802)
* Merge from unstable, remaining changes:
  - build-depend on libtiff5-dev rather than libtiff4-dev,
    avoids FTBFS caused by imlib
  - follow the regular debian codepaths

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 */
26
26
 
27
27
#include "libavutil/colorspace.h"
 
28
#include "libavutil/common.h"
28
29
#include "libavutil/pixdesc.h"
29
30
#include "libavutil/parseutils.h"
30
31
#include "avfilter.h"
 
32
#include "formats.h"
 
33
#include "internal.h"
 
34
#include "video.h"
31
35
 
32
36
enum { Y, U, V, A };
33
37
 
37
41
    int vsub, hsub;   ///< chroma subsampling
38
42
} DrawBoxContext;
39
43
 
40
 
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
 
44
static av_cold int init(AVFilterContext *ctx, const char *args)
41
45
{
42
46
    DrawBoxContext *drawbox= ctx->priv;
43
47
    char color_str[1024] = "black";
62
66
 
63
67
static int query_formats(AVFilterContext *ctx)
64
68
{
65
 
    enum PixelFormat pix_fmts[] = {
66
 
        PIX_FMT_YUV444P,  PIX_FMT_YUV422P,  PIX_FMT_YUV420P,
67
 
        PIX_FMT_YUV411P,  PIX_FMT_YUV410P,
68
 
        PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P,
69
 
        PIX_FMT_YUV440P,  PIX_FMT_YUVJ440P,
70
 
        PIX_FMT_NONE
 
69
    enum AVPixelFormat pix_fmts[] = {
 
70
        AV_PIX_FMT_YUV444P,  AV_PIX_FMT_YUV422P,  AV_PIX_FMT_YUV420P,
 
71
        AV_PIX_FMT_YUV411P,  AV_PIX_FMT_YUV410P,
 
72
        AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
 
73
        AV_PIX_FMT_YUV440P,  AV_PIX_FMT_YUVJ440P,
 
74
        AV_PIX_FMT_NONE
71
75
    };
72
76
 
73
 
    avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
 
77
    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
74
78
    return 0;
75
79
}
76
80
 
77
81
static int config_input(AVFilterLink *inlink)
78
82
{
79
83
    DrawBoxContext *drawbox = inlink->dst->priv;
 
84
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
80
85
 
81
 
    drawbox->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
82
 
    drawbox->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
 
86
    drawbox->hsub = desc->log2_chroma_w;
 
87
    drawbox->vsub = desc->log2_chroma_h;
83
88
 
84
89
    if (drawbox->w == 0) drawbox->w = inlink->w;
85
90
    if (drawbox->h == 0) drawbox->h = inlink->h;
86
91
 
87
 
    av_log(inlink->dst, AV_LOG_INFO, "x:%d y:%d w:%d h:%d color:0x%02X%02X%02X%02X\n",
 
92
    av_log(inlink->dst, AV_LOG_VERBOSE, "x:%d y:%d w:%d h:%d color:0x%02X%02X%02X%02X\n",
88
93
           drawbox->w, drawbox->y, drawbox->w, drawbox->h,
89
94
           drawbox->yuv_color[Y], drawbox->yuv_color[U], drawbox->yuv_color[V], drawbox->yuv_color[A]);
90
95
 
91
96
    return 0;
92
97
}
93
98
 
94
 
static void draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir)
 
99
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame)
95
100
{
96
101
    DrawBoxContext *drawbox = inlink->dst->priv;
97
102
    int plane, x, y, xb = drawbox->x, yb = drawbox->y;
98
103
    unsigned char *row[4];
99
 
    AVFilterBufferRef *picref = inlink->cur_buf;
100
104
 
101
 
    for (y = FFMAX(yb, y0); y < (y0 + h) && y < (yb + drawbox->h); y++) {
102
 
        row[0] = picref->data[0] + y * picref->linesize[0];
 
105
    for (y = FFMAX(yb, 0); y < frame->video->h && y < (yb + drawbox->h); y++) {
 
106
        row[0] = frame->data[0] + y * frame->linesize[0];
103
107
 
104
108
        for (plane = 1; plane < 3; plane++)
105
 
            row[plane] = picref->data[plane] +
106
 
                picref->linesize[plane] * (y >> drawbox->vsub);
 
109
            row[plane] = frame->data[plane] +
 
110
                 frame->linesize[plane] * (y >> drawbox->vsub);
107
111
 
108
 
        for (x = FFMAX(xb, 0); x < (xb + drawbox->w) && x < picref->video->w; x++) {
 
112
        for (x = FFMAX(xb, 0); x < (xb + drawbox->w) && x < frame->video->w; x++) {
109
113
            double alpha = (double)drawbox->yuv_color[A] / 255;
110
114
 
111
115
            if ((y - yb < 3) || (yb + drawbox->h - y < 4) ||
117
121
        }
118
122
    }
119
123
 
120
 
    avfilter_draw_slice(inlink->dst->outputs[0], y0, h, 1);
 
124
    return ff_filter_frame(inlink->dst->outputs[0], frame);
121
125
}
122
126
 
 
127
static const AVFilterPad avfilter_vf_drawbox_inputs[] = {
 
128
    {
 
129
        .name             = "default",
 
130
        .type             = AVMEDIA_TYPE_VIDEO,
 
131
        .config_props     = config_input,
 
132
        .get_video_buffer = ff_null_get_video_buffer,
 
133
        .filter_frame     = filter_frame,
 
134
        .min_perms        = AV_PERM_WRITE | AV_PERM_READ,
 
135
        .rej_perms        = AV_PERM_PRESERVE
 
136
    },
 
137
    { NULL }
 
138
};
 
139
 
 
140
static const AVFilterPad avfilter_vf_drawbox_outputs[] = {
 
141
    {
 
142
        .name = "default",
 
143
        .type = AVMEDIA_TYPE_VIDEO,
 
144
    },
 
145
    { NULL }
 
146
};
 
147
 
123
148
AVFilter avfilter_vf_drawbox = {
124
149
    .name      = "drawbox",
125
150
    .description = NULL_IF_CONFIG_SMALL("Draw a colored box on the input video."),
127
152
    .init      = init,
128
153
 
129
154
    .query_formats   = query_formats,
130
 
    .inputs    = (AVFilterPad[]) {{ .name             = "default",
131
 
                                    .type             = AVMEDIA_TYPE_VIDEO,
132
 
                                    .config_props     = config_input,
133
 
                                    .get_video_buffer = avfilter_null_get_video_buffer,
134
 
                                    .start_frame      = avfilter_null_start_frame,
135
 
                                    .draw_slice       = draw_slice,
136
 
                                    .end_frame        = avfilter_null_end_frame,
137
 
                                    .min_perms        = AV_PERM_WRITE | AV_PERM_READ,
138
 
                                    .rej_perms        = AV_PERM_PRESERVE },
139
 
                                  { .name = NULL}},
140
 
    .outputs   = (AVFilterPad[]) {{ .name             = "default",
141
 
                                    .type             = AVMEDIA_TYPE_VIDEO, },
142
 
                                  { .name = NULL}},
 
155
    .inputs    = avfilter_vf_drawbox_inputs,
 
156
    .outputs   = avfilter_vf_drawbox_outputs,
143
157
};