libavfilter/vf_vflip.c
c38ae71f
 /*
3fa77bde
  * Copyright (c) 2007 Bobby Bingham
c38ae71f
  *
  * 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
  */
 
 /**
ba87f080
  * @file
c38ae71f
  * video vertical flip filter
  */
 
b4b66456
 #include "libavutil/pixdesc.h"
c38ae71f
 #include "avfilter.h"
 
 typedef struct {
     int vsub;   ///< vertical chroma subsampling
 } FlipContext;
 
 static int config_input(AVFilterLink *link)
 {
     FlipContext *flip = link->dst->priv;
 
b4b66456
     flip->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
c38ae71f
 
     return 0;
 }
 
ecc8dada
 static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
c38ae71f
                                         int w, int h)
 {
     FlipContext *flip = link->dst->priv;
0ccabeea
     AVFilterBufferRef *picref;
c38ae71f
     int i;
 
0ccabeea
     if (!(perms & AV_PERM_NEG_LINESIZES))
         return avfilter_default_get_video_buffer(link, perms, w, h);
c38ae71f
 
0ccabeea
     picref = avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h);
e87eb039
     for (i = 0; i < 4; i ++) {
         int vsub = i == 1 || i == 2 ? flip->vsub : 0;
 
c38ae71f
         if (picref->data[i]) {
e87eb039
             picref->data[i] += ((h >> vsub)-1) * picref->linesize[i];
c38ae71f
             picref->linesize[i] = -picref->linesize[i];
         }
     }
 
     return picref;
 }
 
2609ad3e
 static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
c38ae71f
 {
     FlipContext *flip = link->dst->priv;
2609ad3e
     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
c38ae71f
     int i;
 
e87eb039
     for (i = 0; i < 4; i ++) {
         int vsub = i == 1 || i == 2 ? flip->vsub : 0;
 
2609ad3e
         if (outpicref->data[i]) {
             outpicref->data[i] += ((link->h >> vsub)-1) * outpicref->linesize[i];
             outpicref->linesize[i] = -outpicref->linesize[i];
c38ae71f
         }
     }
 
2609ad3e
     avfilter_start_frame(link->dst->outputs[0], outpicref);
c38ae71f
 }
 
a13a5437
 static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
c38ae71f
 {
     AVFilterContext *ctx = link->dst;
 
a13a5437
     avfilter_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
c38ae71f
 }
 
 AVFilter avfilter_vf_vflip = {
     .name      = "vflip",
b70bc022
     .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
 
c38ae71f
     .priv_size = sizeof(FlipContext),
 
     .inputs    = (AVFilterPad[]) {{ .name             = "default",
72415b2a
                                     .type             = AVMEDIA_TYPE_VIDEO,
c38ae71f
                                     .get_video_buffer = get_video_buffer,
                                     .start_frame      = start_frame,
                                     .draw_slice       = draw_slice,
                                     .config_props     = config_input, },
                                   { .name = NULL}},
     .outputs   = (AVFilterPad[]) {{ .name             = "default",
72415b2a
                                     .type             = AVMEDIA_TYPE_VIDEO, },
c38ae71f
                                   { .name = NULL}},
 };