00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include <string.h>
00028
00029 #include "avfilter.h"
00030 #include "formats.h"
00031 #include "internal.h"
00032 #include "video.h"
00033 #include "libavutil/pixdesc.h"
00034 #include "libavutil/internal.h"
00035 #include "libavutil/intreadwrite.h"
00036 #include "libavutil/imgutils.h"
00037
00038 typedef struct {
00039 int max_step[4];
00040 int hsub, vsub;
00041 } FlipContext;
00042
00043 static int query_formats(AVFilterContext *ctx)
00044 {
00045 static const enum PixelFormat pix_fmts[] = {
00046 PIX_FMT_RGB48BE, PIX_FMT_RGB48LE,
00047 PIX_FMT_BGR48BE, PIX_FMT_BGR48LE,
00048 PIX_FMT_ARGB, PIX_FMT_RGBA,
00049 PIX_FMT_ABGR, PIX_FMT_BGRA,
00050 PIX_FMT_RGB24, PIX_FMT_BGR24,
00051 PIX_FMT_RGB565BE, PIX_FMT_RGB565LE,
00052 PIX_FMT_RGB555BE, PIX_FMT_RGB555LE,
00053 PIX_FMT_RGB444BE, PIX_FMT_RGB444LE,
00054 PIX_FMT_BGR565BE, PIX_FMT_BGR565LE,
00055 PIX_FMT_BGR555BE, PIX_FMT_BGR555LE,
00056 PIX_FMT_BGR444BE, PIX_FMT_BGR444LE,
00057 PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE,
00058 PIX_FMT_YUV420P16LE, PIX_FMT_YUV420P16BE,
00059 PIX_FMT_YUV422P16LE, PIX_FMT_YUV422P16BE,
00060 PIX_FMT_YUV444P16LE, PIX_FMT_YUV444P16BE,
00061 PIX_FMT_YUV444P, PIX_FMT_YUV422P,
00062 PIX_FMT_YUV420P, PIX_FMT_YUV411P,
00063 PIX_FMT_YUV410P, PIX_FMT_YUV440P,
00064 PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P,
00065 PIX_FMT_YUVJ420P, PIX_FMT_YUVJ440P,
00066 PIX_FMT_YUVA420P,
00067 PIX_FMT_RGB8, PIX_FMT_BGR8,
00068 PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE,
00069 PIX_FMT_PAL8, PIX_FMT_GRAY8,
00070 PIX_FMT_NONE
00071 };
00072
00073 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
00074 return 0;
00075 }
00076
00077 static int config_props(AVFilterLink *inlink)
00078 {
00079 FlipContext *flip = inlink->dst->priv;
00080 const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format];
00081
00082 av_image_fill_max_pixsteps(flip->max_step, NULL, pix_desc);
00083 flip->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
00084 flip->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
00085
00086 return 0;
00087 }
00088
00089 static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
00090 {
00091 AVFilterLink *outlink = inlink->dst->outputs[0];
00092
00093 outlink->out_buf =
00094 ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
00095 avfilter_copy_buffer_ref_props(outlink->out_buf, picref);
00096
00097
00098 if (av_pix_fmt_descriptors[inlink->format].flags & PIX_FMT_PAL)
00099 memcpy(inlink->dst->outputs[0]->out_buf->data[1], picref->data[1], AVPALETTE_SIZE);
00100
00101 return ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
00102 }
00103
00104 static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
00105 {
00106 FlipContext *flip = inlink->dst->priv;
00107 AVFilterBufferRef *inpic = inlink->cur_buf;
00108 AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
00109 uint8_t *inrow, *outrow;
00110 int i, j, plane, step, hsub, vsub;
00111
00112 for (plane = 0; plane < 4 && inpic->data[plane]; plane++) {
00113 step = flip->max_step[plane];
00114 hsub = (plane == 1 || plane == 2) ? flip->hsub : 0;
00115 vsub = (plane == 1 || plane == 2) ? flip->vsub : 0;
00116
00117 outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane];
00118 inrow = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane] + ((inlink->w >> hsub) - 1) * step;
00119 for (i = 0; i < h>>vsub; i++) {
00120 switch (step) {
00121 case 1:
00122 for (j = 0; j < (inlink->w >> hsub); j++)
00123 outrow[j] = inrow[-j];
00124 break;
00125
00126 case 2:
00127 {
00128 uint16_t *outrow16 = (uint16_t *)outrow;
00129 uint16_t * inrow16 = (uint16_t *) inrow;
00130 for (j = 0; j < (inlink->w >> hsub); j++)
00131 outrow16[j] = inrow16[-j];
00132 }
00133 break;
00134
00135 case 3:
00136 {
00137 uint8_t *in = inrow;
00138 uint8_t *out = outrow;
00139 for (j = 0; j < (inlink->w >> hsub); j++, out += 3, in -= 3) {
00140 int32_t v = AV_RB24(in);
00141 AV_WB24(out, v);
00142 }
00143 }
00144 break;
00145
00146 case 4:
00147 {
00148 uint32_t *outrow32 = (uint32_t *)outrow;
00149 uint32_t * inrow32 = (uint32_t *) inrow;
00150 for (j = 0; j < (inlink->w >> hsub); j++)
00151 outrow32[j] = inrow32[-j];
00152 }
00153 break;
00154
00155 default:
00156 for (j = 0; j < (inlink->w >> hsub); j++)
00157 memcpy(outrow + j*step, inrow - j*step, step);
00158 }
00159
00160 inrow += inpic ->linesize[plane];
00161 outrow += outpic->linesize[plane];
00162 }
00163 }
00164
00165 return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
00166 }
00167
00168 AVFilter avfilter_vf_hflip = {
00169 .name = "hflip",
00170 .description = NULL_IF_CONFIG_SMALL("Horizontally flip the input video."),
00171 .priv_size = sizeof(FlipContext),
00172 .query_formats = query_formats,
00173
00174 .inputs = (const AVFilterPad[]) {{ .name = "default",
00175 .type = AVMEDIA_TYPE_VIDEO,
00176 .start_frame = start_frame,
00177 .draw_slice = draw_slice,
00178 .config_props = config_props,
00179 .min_perms = AV_PERM_READ, },
00180 { .name = NULL}},
00181 .outputs = (const AVFilterPad[]) {{ .name = "default",
00182 .type = AVMEDIA_TYPE_VIDEO, },
00183 { .name = NULL}},
00184 };