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 {
00100 for (j = 0; j < (inlink->w >> hsub); j++)
00101 outrow[j] = inrow[-j];
00102 }
00103 break;
00104
00105 case 2:
00106 {
00107 uint16_t *outrow16 = (uint16_t *)outrow;
00108 uint16_t * inrow16 = (uint16_t *) inrow;
00109 for (j = 0; j < (inlink->w >> hsub); j++)
00110 outrow16[j] = inrow16[-j];
00111 }
00112 break;
00113
00114 case 3:
00115 {
00116 uint8_t *in = inrow;
00117 uint8_t *out = outrow;
00118 for (j = 0; j < (inlink->w >> hsub); j++, out += 3, in -= 3) {
00119 int32_t v = AV_RB24(in);
00120 AV_WB24(out, v);
00121 }
00122 }
00123 break;
00124
00125 case 4:
00126 {
00127 uint32_t *outrow32 = (uint32_t *)outrow;
00128 uint32_t * inrow32 = (uint32_t *) inrow;
00129 for (j = 0; j < (inlink->w >> hsub); j++)
00130 outrow32[j] = inrow32[-j];
00131 }
00132 break;
00133
00134 default:
00135 for (j = 0; j < (inlink->w >> hsub); j++)
00136 memcpy(outrow + j*step, inrow - j*step, step);
00137 }
00138
00139 inrow += inpic ->linesize[plane];
00140 outrow += outpic->linesize[plane];
00141 }
00142 }
00143
00144 avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
00145 }
00146
00147 AVFilter avfilter_vf_hflip = {
00148 .name = "hflip",
00149 .description = NULL_IF_CONFIG_SMALL("Horizontally flip the input video."),
00150 .priv_size = sizeof(FlipContext),
00151 .query_formats = query_formats,
00152
00153 .inputs = (AVFilterPad[]) {{ .name = "default",
00154 .type = AVMEDIA_TYPE_VIDEO,
00155 .draw_slice = draw_slice,
00156 .config_props = config_props,
00157 .min_perms = AV_PERM_READ, },
00158 { .name = NULL}},
00159 .outputs = (AVFilterPad[]) {{ .name = "default",
00160 .type = AVMEDIA_TYPE_VIDEO, },
00161 { .name = NULL}},
00162 };