History

lavfi/vflip: Support Bayer vertical flip.

Fixes ticket #8819.

Carl Eugen Hoyos committed 6 years ago

Commit 34901081 parent ca781761 file · +34 −0Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_vflip.c+34−0
@@ -33,6 +33,7 @@ · 32 unmodified lines
3333 typedef struct FlipContext {
3434 const AVClass *class;
3535 int vsub; ///< vertical chroma subsampling
36+ int bayer;
3637 } FlipContext;
3738
3839 static const AVOption vflip_options[] = {
@@ -47,6 +48,7 @@ static int config_input(AVFilterLink *link) · 8 unmodified lines
4748 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
4849
4950 flip->vsub = desc->log2_chroma_h;
51+ flip->bayer = !!(desc->flags & AV_PIX_FMT_FLAG_BAYER);
5052
5153 return 0;
5254 }
@@ -74,11 +76,43 @@ static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h) · 21 unmodified lines
7476 return frame;
7577 }
7678
79+static int flip_bayer(AVFilterLink *link, AVFrame *in)
80+{
81+ AVFilterContext *ctx = link->dst;
82+ AVFilterLink *outlink = ctx->outputs[0];
83+ AVFrame *out;
84+ uint8_t *inrow = in->data[0], *outrow;
85+ int i, width = outlink->w << (av_pix_fmt_desc_get(link->format)->comp[0].step > 1);
86+ if (outlink->h & 1) {
87+ av_log(ctx, AV_LOG_ERROR, "Bayer vertical flip needs even height\n");
88+ return AVERROR_INVALIDDATA;
89+ }
90+
91+ out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
92+ if (!out) {
93+ av_frame_free(&in);
94+ return AVERROR(ENOMEM);
95+ }
96+ av_frame_copy_props(out, in);
97+ outrow = out->data[0] + out->linesize[0] * (outlink->h - 2);
98+ for (i = 0; i < outlink->h >> 1; i++) {
99+ memcpy(outrow, inrow, width);
100+ memcpy(outrow + out->linesize[0], inrow + in->linesize[0], width);
101+ inrow += 2 * in->linesize[0];
102+ outrow -= 2 * out->linesize[0];
103+ }
104+ av_frame_free(&in);
105+ return ff_filter_frame(outlink, out);
106+}
107+
77108 static int filter_frame(AVFilterLink *link, AVFrame *frame)
78109 {
79110 FlipContext *flip = link->dst->priv;
80111 int i;
81112
113+ if (flip->bayer)
114+ return flip_bayer(link, frame);
115+
82116 for (i = 0; i < 4; i ++) {
83117 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
84118 int height = AV_CEIL_RSHIFT(link->h, vsub);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t