~ubuntu-branches/ubuntu/trusty/gst-libav1.0/trusty-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavfilter/vf_fade.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-09-24 17:07:00 UTC
  • mfrom: (1.1.17) (7.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130924170700-4dg62s3pwl0pdakz
Tags: 1.2.0-1
* New upstream stable release:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 * based heavily on vf_negate.c by Bobby Bingham
26
26
 */
27
27
 
 
28
#include "libavutil/common.h"
28
29
#include "libavutil/pixdesc.h"
29
30
#include "avfilter.h"
 
31
#include "formats.h"
 
32
#include "internal.h"
 
33
#include "video.h"
30
34
 
31
35
typedef struct {
32
36
    int factor, fade_per_frame;
34
38
    int hsub, vsub, bpp;
35
39
} FadeContext;
36
40
 
37
 
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
 
41
static av_cold int init(AVFilterContext *ctx, const char *args)
38
42
{
39
43
    FadeContext *fade = ctx->priv;
40
44
    unsigned int nb_frames;
61
65
    }
62
66
    fade->stop_frame = fade->start_frame + nb_frames;
63
67
 
64
 
    av_log(ctx, AV_LOG_INFO,
 
68
    av_log(ctx, AV_LOG_VERBOSE,
65
69
           "type:%s start_frame:%d nb_frames:%d\n",
66
70
           in_out, fade->start_frame, nb_frames);
67
71
    return 0;
69
73
 
70
74
static int query_formats(AVFilterContext *ctx)
71
75
{
72
 
    static const enum PixelFormat pix_fmts[] = {
73
 
        PIX_FMT_YUV444P,  PIX_FMT_YUV422P,  PIX_FMT_YUV420P,
74
 
        PIX_FMT_YUV411P,  PIX_FMT_YUV410P,
75
 
        PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P,
76
 
        PIX_FMT_YUV440P,  PIX_FMT_YUVJ440P,
77
 
        PIX_FMT_RGB24,    PIX_FMT_BGR24,
78
 
        PIX_FMT_NONE
 
76
    static const enum AVPixelFormat pix_fmts[] = {
 
77
        AV_PIX_FMT_YUV444P,  AV_PIX_FMT_YUV422P,  AV_PIX_FMT_YUV420P,
 
78
        AV_PIX_FMT_YUV411P,  AV_PIX_FMT_YUV410P,
 
79
        AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
 
80
        AV_PIX_FMT_YUV440P,  AV_PIX_FMT_YUVJ440P,
 
81
        AV_PIX_FMT_RGB24,    AV_PIX_FMT_BGR24,
 
82
        AV_PIX_FMT_NONE
79
83
    };
80
84
 
81
 
    avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
 
85
    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
82
86
    return 0;
83
87
}
84
88
 
85
89
static int config_props(AVFilterLink *inlink)
86
90
{
87
91
    FadeContext *fade = inlink->dst->priv;
88
 
    const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[inlink->format];
 
92
    const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(inlink->format);
89
93
 
90
94
    fade->hsub = pixdesc->log2_chroma_w;
91
95
    fade->vsub = pixdesc->log2_chroma_h;
94
98
    return 0;
95
99
}
96
100
 
97
 
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 
101
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame)
98
102
{
99
103
    FadeContext *fade = inlink->dst->priv;
100
 
    AVFilterBufferRef *outpic = inlink->cur_buf;
101
104
    uint8_t *p;
102
105
    int i, j, plane;
103
106
 
104
107
    if (fade->factor < UINT16_MAX) {
105
108
        /* luma or rgb plane */
106
 
        for (i = 0; i < h; i++) {
107
 
            p = outpic->data[0] + (y+i) * outpic->linesize[0];
 
109
        for (i = 0; i < frame->video->h; i++) {
 
110
            p = frame->data[0] + i * frame->linesize[0];
108
111
            for (j = 0; j < inlink->w * fade->bpp; j++) {
109
112
                /* fade->factor is using 16 lower-order bits for decimal
110
113
                 * places. 32768 = 1 << 15, it is an integer representation
114
117
            }
115
118
        }
116
119
 
117
 
        if (outpic->data[1] && outpic->data[2]) {
 
120
        if (frame->data[1] && frame->data[2]) {
118
121
            /* chroma planes */
119
122
            for (plane = 1; plane < 3; plane++) {
120
 
                for (i = 0; i < h; i++) {
121
 
                    p = outpic->data[plane] + ((y+i) >> fade->vsub) * outpic->linesize[plane];
 
123
                for (i = 0; i < frame->video->h; i++) {
 
124
                    p = frame->data[plane] + (i >> fade->vsub) * frame->linesize[plane];
122
125
                    for (j = 0; j < inlink->w >> fade->hsub; j++) {
123
126
                        /* 8421367 = ((128 << 1) + 1) << 15. It is an integer
124
127
                         * representation of 128.5. The .5 is for rounding
131
134
        }
132
135
    }
133
136
 
134
 
    avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
135
 
}
136
 
 
137
 
static void end_frame(AVFilterLink *inlink)
138
 
{
139
 
    FadeContext *fade = inlink->dst->priv;
140
 
 
141
 
    avfilter_end_frame(inlink->dst->outputs[0]);
142
 
 
143
137
    if (fade->frame_index >= fade->start_frame &&
144
138
        fade->frame_index <= fade->stop_frame)
145
139
        fade->factor += fade->fade_per_frame;
146
140
    fade->factor = av_clip_uint16(fade->factor);
147
141
    fade->frame_index++;
 
142
 
 
143
    return ff_filter_frame(inlink->dst->outputs[0], frame);
148
144
}
149
145
 
 
146
static const AVFilterPad avfilter_vf_fade_inputs[] = {
 
147
    {
 
148
        .name             = "default",
 
149
        .type             = AVMEDIA_TYPE_VIDEO,
 
150
        .config_props     = config_props,
 
151
        .get_video_buffer = ff_null_get_video_buffer,
 
152
        .filter_frame     = filter_frame,
 
153
        .min_perms        = AV_PERM_READ | AV_PERM_WRITE,
 
154
        .rej_perms        = AV_PERM_PRESERVE,
 
155
    },
 
156
    { NULL }
 
157
};
 
158
 
 
159
static const AVFilterPad avfilter_vf_fade_outputs[] = {
 
160
    {
 
161
        .name = "default",
 
162
        .type = AVMEDIA_TYPE_VIDEO,
 
163
    },
 
164
    { NULL }
 
165
};
 
166
 
150
167
AVFilter avfilter_vf_fade = {
151
168
    .name          = "fade",
152
169
    .description   = NULL_IF_CONFIG_SMALL("Fade in/out input video"),
154
171
    .priv_size     = sizeof(FadeContext),
155
172
    .query_formats = query_formats,
156
173
 
157
 
    .inputs    = (AVFilterPad[]) {{ .name            = "default",
158
 
                                    .type            = AVMEDIA_TYPE_VIDEO,
159
 
                                    .config_props    = config_props,
160
 
                                    .get_video_buffer = avfilter_null_get_video_buffer,
161
 
                                    .start_frame      = avfilter_null_start_frame,
162
 
                                    .draw_slice      = draw_slice,
163
 
                                    .end_frame       = end_frame,
164
 
                                    .min_perms       = AV_PERM_READ | AV_PERM_WRITE,
165
 
                                    .rej_perms       = AV_PERM_PRESERVE, },
166
 
                                  { .name = NULL}},
167
 
    .outputs   = (AVFilterPad[]) {{ .name            = "default",
168
 
                                    .type            = AVMEDIA_TYPE_VIDEO, },
169
 
                                  { .name = NULL}},
 
174
    .inputs    = avfilter_vf_fade_inputs,
 
175
    .outputs   = avfilter_vf_fade_outputs,
170
176
};