Statistics
| Branch: | Revision:

ffmpeg / libavfilter / vf_vflip.c @ 5eb901cf

History | View | Annotate | Download (3.35 KB)

1 c38ae71f Stefano Sabatini
/*
2 3fa77bde Stefano Sabatini
 * Copyright (c) 2007 Bobby Bingham
3 c38ae71f Stefano Sabatini
 *
4 2912e87a Mans Rullgard
 * This file is part of Libav.
5 c38ae71f Stefano Sabatini
 *
6 2912e87a Mans Rullgard
 * Libav is free software; you can redistribute it and/or
7 c38ae71f Stefano Sabatini
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11 2912e87a Mans Rullgard
 * Libav is distributed in the hope that it will be useful,
12 c38ae71f Stefano Sabatini
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17 2912e87a Mans Rullgard
 * License along with Libav; if not, write to the Free Software
18 c38ae71f Stefano Sabatini
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21
/**
22 ba87f080 Diego Biurrun
 * @file
23 c38ae71f Stefano Sabatini
 * video vertical flip filter
24
 */
25
26 b4b66456 Stefano Sabatini
#include "libavutil/pixdesc.h"
27 c38ae71f Stefano Sabatini
#include "avfilter.h"
28
29
typedef struct {
30
    int vsub;   ///< vertical chroma subsampling
31
} FlipContext;
32
33
static int config_input(AVFilterLink *link)
34
{
35
    FlipContext *flip = link->dst->priv;
36
37 b4b66456 Stefano Sabatini
    flip->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
38 c38ae71f Stefano Sabatini
39
    return 0;
40
}
41
42 ecc8dada S.N. Hemanth Meenakshisundaram
static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
43 c38ae71f Stefano Sabatini
                                        int w, int h)
44
{
45
    FlipContext *flip = link->dst->priv;
46 0ccabeea Michael Niedermayer
    AVFilterBufferRef *picref;
47 c38ae71f Stefano Sabatini
    int i;
48
49 0ccabeea Michael Niedermayer
    if (!(perms & AV_PERM_NEG_LINESIZES))
50
        return avfilter_default_get_video_buffer(link, perms, w, h);
51 c38ae71f Stefano Sabatini
52 0ccabeea Michael Niedermayer
    picref = avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h);
53 e87eb039 Stefano Sabatini
    for (i = 0; i < 4; i ++) {
54
        int vsub = i == 1 || i == 2 ? flip->vsub : 0;
55
56 c38ae71f Stefano Sabatini
        if (picref->data[i]) {
57 e87eb039 Stefano Sabatini
            picref->data[i] += ((h >> vsub)-1) * picref->linesize[i];
58 c38ae71f Stefano Sabatini
            picref->linesize[i] = -picref->linesize[i];
59
        }
60
    }
61
62
    return picref;
63
}
64
65 2609ad3e Stefano Sabatini
static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
66 c38ae71f Stefano Sabatini
{
67
    FlipContext *flip = link->dst->priv;
68 2609ad3e Stefano Sabatini
    AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
69 c38ae71f Stefano Sabatini
    int i;
70
71 e87eb039 Stefano Sabatini
    for (i = 0; i < 4; i ++) {
72
        int vsub = i == 1 || i == 2 ? flip->vsub : 0;
73
74 2609ad3e Stefano Sabatini
        if (outpicref->data[i]) {
75
            outpicref->data[i] += ((link->h >> vsub)-1) * outpicref->linesize[i];
76
            outpicref->linesize[i] = -outpicref->linesize[i];
77 c38ae71f Stefano Sabatini
        }
78
    }
79
80 2609ad3e Stefano Sabatini
    avfilter_start_frame(link->dst->outputs[0], outpicref);
81 c38ae71f Stefano Sabatini
}
82
83 a13a5437 Stefano Sabatini
static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
84 c38ae71f Stefano Sabatini
{
85
    AVFilterContext *ctx = link->dst;
86
87 a13a5437 Stefano Sabatini
    avfilter_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
88 c38ae71f Stefano Sabatini
}
89
90
AVFilter avfilter_vf_vflip = {
91
    .name      = "vflip",
92 b70bc022 Stefano Sabatini
    .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
93
94 c38ae71f Stefano Sabatini
    .priv_size = sizeof(FlipContext),
95
96
    .inputs    = (AVFilterPad[]) {{ .name             = "default",
97 72415b2a Stefano Sabatini
                                    .type             = AVMEDIA_TYPE_VIDEO,
98 c38ae71f Stefano Sabatini
                                    .get_video_buffer = get_video_buffer,
99
                                    .start_frame      = start_frame,
100
                                    .draw_slice       = draw_slice,
101
                                    .config_props     = config_input, },
102
                                  { .name = NULL}},
103
    .outputs   = (AVFilterPad[]) {{ .name             = "default",
104 72415b2a Stefano Sabatini
                                    .type             = AVMEDIA_TYPE_VIDEO, },
105 c38ae71f Stefano Sabatini
                                  { .name = NULL}},
106
};