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