Libav
|
00001 /* 00002 * copyright (c) 2007 Bobby Bingham 00003 * 00004 * This file is part of FFmpeg. 00005 * 00006 * FFmpeg is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * FFmpeg is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with FFmpeg; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00026 #include "libavutil/pixdesc.h" 00027 #include "avfilter.h" 00028 00029 typedef struct { 00030 int vsub; 00031 } FlipContext; 00032 00033 static int config_input(AVFilterLink *link) 00034 { 00035 FlipContext *flip = link->dst->priv; 00036 00037 flip->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h; 00038 00039 return 0; 00040 } 00041 00042 static AVFilterPicRef *get_video_buffer(AVFilterLink *link, int perms, 00043 int w, int h) 00044 { 00045 FlipContext *flip = link->dst->priv; 00046 int i; 00047 00048 AVFilterPicRef *picref = avfilter_get_video_buffer(link->dst->outputs[0], 00049 perms, w, h); 00050 00051 for (i = 0; i < 4; i ++) { 00052 int vsub = i == 1 || i == 2 ? flip->vsub : 0; 00053 00054 if (picref->data[i]) { 00055 picref->data[i] += ((h >> vsub)-1) * picref->linesize[i]; 00056 picref->linesize[i] = -picref->linesize[i]; 00057 } 00058 } 00059 00060 return picref; 00061 } 00062 00063 static void start_frame(AVFilterLink *link, AVFilterPicRef *picref) 00064 { 00065 FlipContext *flip = link->dst->priv; 00066 int i; 00067 00068 for (i = 0; i < 4; i ++) { 00069 int vsub = i == 1 || i == 2 ? flip->vsub : 0; 00070 00071 if (picref->data[i]) { 00072 picref->data[i] += ((link->h >> vsub)-1) * picref->linesize[i]; 00073 picref->linesize[i] = -picref->linesize[i]; 00074 } 00075 } 00076 00077 avfilter_start_frame(link->dst->outputs[0], picref); 00078 } 00079 00080 static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir) 00081 { 00082 AVFilterContext *ctx = link->dst; 00083 00084 avfilter_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir); 00085 } 00086 00087 AVFilter avfilter_vf_vflip = { 00088 .name = "vflip", 00089 .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."), 00090 00091 .priv_size = sizeof(FlipContext), 00092 00093 .inputs = (AVFilterPad[]) {{ .name = "default", 00094 .type = AVMEDIA_TYPE_VIDEO, 00095 .get_video_buffer = get_video_buffer, 00096 .start_frame = start_frame, 00097 .draw_slice = draw_slice, 00098 .end_frame = avfilter_null_end_frame, 00099 .config_props = config_input, }, 00100 { .name = NULL}}, 00101 .outputs = (AVFilterPad[]) {{ .name = "default", 00102 .type = AVMEDIA_TYPE_VIDEO, }, 00103 { .name = NULL}}, 00104 };