2009-10-23 00:00:33 +02:00
|
|
|
/*
|
2010-11-28 11:22:58 +01:00
|
|
|
* Copyright (c) 2007 Bobby Bingham
|
2009-10-23 00:00:33 +02:00
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* This file is part of Libav.
|
2009-10-23 00:00:33 +02:00
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2009-10-23 00:00:33 +02:00
|
|
|
* 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.
|
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2009-10-23 00:00:33 +02:00
|
|
|
* 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
|
2011-03-18 18:35:10 +01:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2009-10-23 00:00:33 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 16:45:34 +02:00
|
|
|
* @file
|
2009-10-23 00:00:33 +02:00
|
|
|
* video vertical flip filter
|
|
|
|
*/
|
|
|
|
|
2012-08-06 15:49:32 +02:00
|
|
|
#include "libavutil/internal.h"
|
2010-01-31 17:33:29 +01:00
|
|
|
#include "libavutil/pixdesc.h"
|
2009-10-23 00:00:33 +02:00
|
|
|
#include "avfilter.h"
|
2012-06-12 20:12:42 +02:00
|
|
|
#include "internal.h"
|
2012-05-19 10:37:56 +02:00
|
|
|
#include "video.h"
|
2009-10-23 00:00:33 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int vsub; ///< vertical chroma subsampling
|
|
|
|
} FlipContext;
|
|
|
|
|
|
|
|
static int config_input(AVFilterLink *link)
|
|
|
|
{
|
|
|
|
FlipContext *flip = link->dst->priv;
|
2012-10-06 13:29:37 +02:00
|
|
|
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
|
2009-10-23 00:00:33 +02:00
|
|
|
|
2012-10-06 13:29:37 +02:00
|
|
|
flip->vsub = desc->log2_chroma_h;
|
2009-10-23 00:00:33 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-28 08:41:07 +01:00
|
|
|
static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h)
|
2009-10-23 00:00:33 +02:00
|
|
|
{
|
|
|
|
FlipContext *flip = link->dst->priv;
|
2012-11-28 08:41:07 +01:00
|
|
|
AVFrame *frame;
|
2009-10-23 00:00:33 +02:00
|
|
|
int i;
|
|
|
|
|
2012-11-28 08:41:07 +01:00
|
|
|
frame = ff_get_video_buffer(link->dst->outputs[0], w, h);
|
|
|
|
if (!frame)
|
2012-07-15 11:16:53 +02:00
|
|
|
return NULL;
|
|
|
|
|
2009-12-08 18:08:49 +01:00
|
|
|
for (i = 0; i < 4; i ++) {
|
|
|
|
int vsub = i == 1 || i == 2 ? flip->vsub : 0;
|
|
|
|
|
2012-11-28 08:41:07 +01:00
|
|
|
if (frame->data[i]) {
|
|
|
|
frame->data[i] += ((h >> vsub) - 1) * frame->linesize[i];
|
|
|
|
frame->linesize[i] = -frame->linesize[i];
|
2009-10-23 00:00:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 08:41:07 +01:00
|
|
|
return frame;
|
2009-10-23 00:00:33 +02:00
|
|
|
}
|
|
|
|
|
2012-11-28 08:41:07 +01:00
|
|
|
static int filter_frame(AVFilterLink *link, AVFrame *frame)
|
2009-10-23 00:00:33 +02:00
|
|
|
{
|
|
|
|
FlipContext *flip = link->dst->priv;
|
|
|
|
int i;
|
|
|
|
|
2009-12-08 18:08:49 +01:00
|
|
|
for (i = 0; i < 4; i ++) {
|
|
|
|
int vsub = i == 1 || i == 2 ? flip->vsub : 0;
|
|
|
|
|
2012-11-27 07:49:45 +01:00
|
|
|
if (frame->data[i]) {
|
|
|
|
frame->data[i] += ((link->h >> vsub)-1) * frame->linesize[i];
|
|
|
|
frame->linesize[i] = -frame->linesize[i];
|
2009-10-23 00:00:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-27 07:49:45 +01:00
|
|
|
return ff_filter_frame(link->dst->outputs[0], frame);
|
2009-10-23 00:00:33 +02:00
|
|
|
}
|
2012-07-24 15:14:01 +02:00
|
|
|
static const AVFilterPad avfilter_vf_vflip_inputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.get_video_buffer = get_video_buffer,
|
2012-11-27 07:49:45 +01:00
|
|
|
.filter_frame = filter_frame,
|
2012-07-24 15:14:01 +02:00
|
|
|
.config_props = config_input,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad avfilter_vf_vflip_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2009-10-23 00:00:33 +02:00
|
|
|
AVFilter avfilter_vf_vflip = {
|
|
|
|
.name = "vflip",
|
2009-10-27 01:43:45 +01:00
|
|
|
.description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
|
|
|
|
|
2009-10-23 00:00:33 +02:00
|
|
|
.priv_size = sizeof(FlipContext),
|
|
|
|
|
2012-07-24 15:14:01 +02:00
|
|
|
.inputs = avfilter_vf_vflip_inputs,
|
|
|
|
.outputs = avfilter_vf_vflip_outputs,
|
2009-10-23 00:00:33 +02:00
|
|
|
};
|