2009-10-23 01:00:33 +03:00
|
|
|
/*
|
2010-11-28 12:22:58 +02:00
|
|
|
* Copyright (c) 2007 Bobby Bingham
|
2009-10-23 01:00:33 +03:00
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 17:45:34 +03:00
|
|
|
* @file
|
2009-10-23 01:00:33 +03:00
|
|
|
* video vertical flip filter
|
|
|
|
*/
|
|
|
|
|
2010-01-31 18:33:29 +02:00
|
|
|
#include "libavutil/pixdesc.h"
|
2009-10-23 01:00:33 +03:00
|
|
|
#include "avfilter.h"
|
2012-05-19 11:37:56 +03:00
|
|
|
#include "video.h"
|
2009-10-23 01:00:33 +03:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int vsub; ///< vertical chroma subsampling
|
|
|
|
} FlipContext;
|
|
|
|
|
|
|
|
static int config_input(AVFilterLink *link)
|
|
|
|
{
|
|
|
|
FlipContext *flip = link->dst->priv;
|
|
|
|
|
2010-01-31 18:33:29 +02:00
|
|
|
flip->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
|
2009-10-23 01:00:33 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-07 04:15:19 +03:00
|
|
|
static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
|
2009-10-23 01:00:33 +03:00
|
|
|
int w, int h)
|
|
|
|
{
|
|
|
|
FlipContext *flip = link->dst->priv;
|
2010-12-27 17:10:21 +02:00
|
|
|
AVFilterBufferRef *picref;
|
2009-10-23 01:00:33 +03:00
|
|
|
int i;
|
|
|
|
|
2010-12-27 17:10:21 +02:00
|
|
|
if (!(perms & AV_PERM_NEG_LINESIZES))
|
2012-05-19 11:37:56 +03:00
|
|
|
return ff_default_get_video_buffer(link, perms, w, h);
|
2009-10-23 01:00:33 +03:00
|
|
|
|
2010-12-27 17:10:21 +02:00
|
|
|
picref = avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h);
|
2009-12-08 19:08:49 +02:00
|
|
|
for (i = 0; i < 4; i ++) {
|
|
|
|
int vsub = i == 1 || i == 2 ? flip->vsub : 0;
|
|
|
|
|
2009-10-23 01:00:33 +03:00
|
|
|
if (picref->data[i]) {
|
2009-12-08 19:08:49 +02:00
|
|
|
picref->data[i] += ((h >> vsub)-1) * picref->linesize[i];
|
2009-10-23 01:00:33 +03:00
|
|
|
picref->linesize[i] = -picref->linesize[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return picref;
|
|
|
|
}
|
|
|
|
|
2010-12-19 20:17:11 +02:00
|
|
|
static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
|
2009-10-23 01:00:33 +03:00
|
|
|
{
|
|
|
|
FlipContext *flip = link->dst->priv;
|
2010-12-19 20:17:11 +02:00
|
|
|
AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
|
2009-10-23 01:00:33 +03:00
|
|
|
int i;
|
|
|
|
|
2009-12-08 19:08:49 +02:00
|
|
|
for (i = 0; i < 4; i ++) {
|
|
|
|
int vsub = i == 1 || i == 2 ? flip->vsub : 0;
|
|
|
|
|
2010-12-19 20:17:11 +02:00
|
|
|
if (outpicref->data[i]) {
|
|
|
|
outpicref->data[i] += ((link->h >> vsub)-1) * outpicref->linesize[i];
|
|
|
|
outpicref->linesize[i] = -outpicref->linesize[i];
|
2009-10-23 01:00:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:20:32 +03:00
|
|
|
ff_start_frame(link->dst->outputs[0], outpicref);
|
2009-10-23 01:00:33 +03:00
|
|
|
}
|
|
|
|
|
2009-12-05 01:26:13 +02:00
|
|
|
static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
|
2009-10-23 01:00:33 +03:00
|
|
|
{
|
|
|
|
AVFilterContext *ctx = link->dst;
|
|
|
|
|
2012-05-30 12:20:32 +03:00
|
|
|
ff_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
|
2009-10-23 01:00:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
AVFilter avfilter_vf_vflip = {
|
|
|
|
.name = "vflip",
|
2009-10-27 02:43:45 +02:00
|
|
|
.description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
|
|
|
|
|
2009-10-23 01:00:33 +03:00
|
|
|
.priv_size = sizeof(FlipContext),
|
|
|
|
|
2011-11-05 16:39:24 +03:00
|
|
|
.inputs = (const AVFilterPad[]) {{ .name = "default",
|
2010-03-31 02:30:55 +03:00
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2009-10-23 01:00:33 +03:00
|
|
|
.get_video_buffer = get_video_buffer,
|
|
|
|
.start_frame = start_frame,
|
|
|
|
.draw_slice = draw_slice,
|
|
|
|
.config_props = config_input, },
|
|
|
|
{ .name = NULL}},
|
2011-11-05 16:39:24 +03:00
|
|
|
.outputs = (const AVFilterPad[]) {{ .name = "default",
|
2010-03-31 02:30:55 +03:00
|
|
|
.type = AVMEDIA_TYPE_VIDEO, },
|
2009-10-23 01:00:33 +03:00
|
|
|
{ .name = NULL}},
|
|
|
|
};
|