2010-08-17 14:59:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Benoit Fouet
|
|
|
|
* Copyright (c) 2010 Stefano Sabatini
|
|
|
|
*
|
|
|
|
* 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-08-18 21:07:57 +00:00
|
|
|
* @file
|
2010-08-17 14:59:12 +00:00
|
|
|
* horizontal flip filter
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avfilter.h"
|
2012-05-30 08:12:55 +00:00
|
|
|
#include "formats.h"
|
2012-06-12 18:12:42 +00:00
|
|
|
#include "internal.h"
|
2012-05-30 09:20:32 +00:00
|
|
|
#include "video.h"
|
2010-08-17 14:59:12 +00:00
|
|
|
#include "libavutil/pixdesc.h"
|
|
|
|
#include "libavutil/intreadwrite.h"
|
2011-02-07 13:37:08 +00:00
|
|
|
#include "libavutil/imgutils.h"
|
2010-08-17 14:59:12 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int max_step[4]; ///< max pixel step for each plane, expressed as a number of bytes
|
|
|
|
int hsub, vsub; ///< chroma subsampling
|
|
|
|
} FlipContext;
|
|
|
|
|
|
|
|
static int query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
static const enum PixelFormat pix_fmts[] = {
|
|
|
|
PIX_FMT_RGB48BE, PIX_FMT_RGB48LE,
|
2011-03-19 11:11:03 +00:00
|
|
|
PIX_FMT_BGR48BE, PIX_FMT_BGR48LE,
|
2010-08-17 14:59:12 +00:00
|
|
|
PIX_FMT_ARGB, PIX_FMT_RGBA,
|
|
|
|
PIX_FMT_ABGR, PIX_FMT_BGRA,
|
|
|
|
PIX_FMT_RGB24, PIX_FMT_BGR24,
|
|
|
|
PIX_FMT_RGB565BE, PIX_FMT_RGB565LE,
|
|
|
|
PIX_FMT_RGB555BE, PIX_FMT_RGB555LE,
|
2012-03-25 21:18:19 +00:00
|
|
|
PIX_FMT_RGB444BE, PIX_FMT_RGB444LE,
|
2010-08-17 14:59:12 +00:00
|
|
|
PIX_FMT_BGR565BE, PIX_FMT_BGR565LE,
|
|
|
|
PIX_FMT_BGR555BE, PIX_FMT_BGR555LE,
|
2012-03-25 21:18:19 +00:00
|
|
|
PIX_FMT_BGR444BE, PIX_FMT_BGR444LE,
|
2010-08-17 14:59:12 +00:00
|
|
|
PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE,
|
|
|
|
PIX_FMT_YUV420P16LE, PIX_FMT_YUV420P16BE,
|
|
|
|
PIX_FMT_YUV422P16LE, PIX_FMT_YUV422P16BE,
|
|
|
|
PIX_FMT_YUV444P16LE, PIX_FMT_YUV444P16BE,
|
|
|
|
PIX_FMT_YUV444P, PIX_FMT_YUV422P,
|
|
|
|
PIX_FMT_YUV420P, PIX_FMT_YUV411P,
|
|
|
|
PIX_FMT_YUV410P, PIX_FMT_YUV440P,
|
|
|
|
PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P,
|
|
|
|
PIX_FMT_YUVJ420P, PIX_FMT_YUVJ440P,
|
|
|
|
PIX_FMT_YUVA420P,
|
|
|
|
PIX_FMT_RGB8, PIX_FMT_BGR8,
|
|
|
|
PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE,
|
|
|
|
PIX_FMT_PAL8, PIX_FMT_GRAY8,
|
|
|
|
PIX_FMT_NONE
|
|
|
|
};
|
|
|
|
|
2012-05-30 08:12:55 +00:00
|
|
|
ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
|
2010-08-17 14:59:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int config_props(AVFilterLink *inlink)
|
|
|
|
{
|
|
|
|
FlipContext *flip = inlink->dst->priv;
|
|
|
|
const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format];
|
|
|
|
|
2010-09-07 19:15:29 +00:00
|
|
|
av_image_fill_max_pixsteps(flip->max_step, NULL, pix_desc);
|
2010-08-17 14:59:12 +00:00
|
|
|
flip->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
|
|
|
|
flip->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-07 07:57:07 +00:00
|
|
|
static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
|
|
|
|
{
|
|
|
|
AVFilterLink *outlink = inlink->dst->outputs[0];
|
|
|
|
|
|
|
|
outlink->out_buf =
|
2012-06-16 09:47:46 +00:00
|
|
|
ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
|
2012-04-07 07:57:07 +00:00
|
|
|
avfilter_copy_buffer_ref_props(outlink->out_buf, picref);
|
|
|
|
|
|
|
|
/* copy palette if required */
|
|
|
|
if (av_pix_fmt_descriptors[inlink->format].flags & PIX_FMT_PAL)
|
|
|
|
memcpy(inlink->dst->outputs[0]->out_buf->data[1], picref->data[1], AVPALETTE_SIZE);
|
|
|
|
|
2012-06-16 09:47:46 +00:00
|
|
|
ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
|
2012-04-07 07:57:07 +00:00
|
|
|
}
|
|
|
|
|
2010-08-17 14:59:12 +00:00
|
|
|
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
|
|
|
|
{
|
|
|
|
FlipContext *flip = inlink->dst->priv;
|
|
|
|
AVFilterBufferRef *inpic = inlink->cur_buf;
|
|
|
|
AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
|
|
|
|
uint8_t *inrow, *outrow;
|
|
|
|
int i, j, plane, step, hsub, vsub;
|
|
|
|
|
|
|
|
for (plane = 0; plane < 4 && inpic->data[plane]; plane++) {
|
|
|
|
step = flip->max_step[plane];
|
|
|
|
hsub = (plane == 1 || plane == 2) ? flip->hsub : 0;
|
|
|
|
vsub = (plane == 1 || plane == 2) ? flip->vsub : 0;
|
|
|
|
|
|
|
|
outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane];
|
|
|
|
inrow = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane] + ((inlink->w >> hsub) - 1) * step;
|
|
|
|
for (i = 0; i < h>>vsub; i++) {
|
|
|
|
switch (step) {
|
|
|
|
case 1:
|
|
|
|
for (j = 0; j < (inlink->w >> hsub); j++)
|
|
|
|
outrow[j] = inrow[-j];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
uint16_t *outrow16 = (uint16_t *)outrow;
|
|
|
|
uint16_t * inrow16 = (uint16_t *) inrow;
|
|
|
|
for (j = 0; j < (inlink->w >> hsub); j++)
|
|
|
|
outrow16[j] = inrow16[-j];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
uint8_t *in = inrow;
|
|
|
|
uint8_t *out = outrow;
|
|
|
|
for (j = 0; j < (inlink->w >> hsub); j++, out += 3, in -= 3) {
|
|
|
|
int32_t v = AV_RB24(in);
|
|
|
|
AV_WB24(out, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
uint32_t *outrow32 = (uint32_t *)outrow;
|
|
|
|
uint32_t * inrow32 = (uint32_t *) inrow;
|
|
|
|
for (j = 0; j < (inlink->w >> hsub); j++)
|
|
|
|
outrow32[j] = inrow32[-j];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
for (j = 0; j < (inlink->w >> hsub); j++)
|
|
|
|
memcpy(outrow + j*step, inrow - j*step, step);
|
|
|
|
}
|
|
|
|
|
|
|
|
inrow += inpic ->linesize[plane];
|
|
|
|
outrow += outpic->linesize[plane];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 09:20:32 +00:00
|
|
|
ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
|
2010-08-17 14:59:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AVFilter avfilter_vf_hflip = {
|
|
|
|
.name = "hflip",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Horizontally flip the input video."),
|
|
|
|
.priv_size = sizeof(FlipContext),
|
|
|
|
.query_formats = query_formats,
|
|
|
|
|
2012-07-21 16:45:52 +00:00
|
|
|
.inputs = (const AVFilterPad[]) {{ .name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2012-07-22 20:10:41 +00:00
|
|
|
.start_frame = start_frame,
|
2012-07-21 16:45:52 +00:00
|
|
|
.draw_slice = draw_slice,
|
|
|
|
.config_props = config_props,
|
|
|
|
.min_perms = AV_PERM_READ, },
|
|
|
|
{ .name = NULL}},
|
|
|
|
.outputs = (const AVFilterPad[]) {{ .name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO, },
|
|
|
|
{ .name = NULL}},
|
2010-08-17 14:59:12 +00:00
|
|
|
};
|