History

Auto insert scale filter to convert colrospaces when needed

Commited in SoC by Bobby Bingham on 2007-08-20 05:24:57 Originally committed as revision 12021 to svn://svn.ffmpeg.org/ffmpeg/trunk

Vitor Sessak committed 18 years ago

Commit d21cbbf1 parent 2a553ef1 file · +66 −10Browse files

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

Unified · Split

libavfilter/avfilter.c+66−10
@@ -96,33 +96,77 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, · 95 unmodified lines
9696 return 0;
9797 }
9898
99+static int common_format(int *fmts0, int *fmts1)
100+{
101+ int i, j;
102+
103+ for(i = 0; fmts0[i] != -1; i ++)
104+ for(j = 0; fmts1[j] != -1; j ++)
105+ if(fmts0[i] == fmts1[j])
106+ return fmts0[i];
107+
108+ return -1;
109+}
110+
99111 int avfilter_config_link(AVFilterLink *link)
100112 {
101− int *fmts[2], i, j;
113+ int *fmts[3] = {NULL,NULL,NULL};
102114 int (*config_link)(AVFilterLink *);
103115 int *(*query_formats)(AVFilterLink *link);
104116
117+ AVFilterContext *scale;
118+ AVFilterLink *link2 = NULL;
119+
105120 if(!link)
106121 return 0;
107122
108− /* find a format both filters support - TODO: auto-insert conversion filter */
109− link->format = -1;
123+ /* find a format both filters support */
110124 if(!(query_formats = link_spad(link).query_formats))
111125 query_formats = avfilter_default_query_output_formats;
112126 fmts[0] = query_formats(link);
113127 fmts[1] = link_dpad(link).query_formats(link);
114− for(i = 0; fmts[0][i] != -1; i ++)
115− for(j = 0; fmts[1][j] != -1; j ++)
116− if(fmts[0][i] == fmts[1][j]) {
117− link->format = fmts[0][i];
118− goto format_done;
119− }
128+ if((link->format = common_format(fmts[0], fmts[1])) == -1) {
129+ /* no common format found. insert scale filter to convert */
130+ if(!(scale = avfilter_open(&avfilter_vf_scale, NULL)))
131+ goto format_done;
132+ if(scale->filter->init(scale, NULL, NULL)) {
133+ avfilter_destroy(scale);
134+ goto format_done;
135+ }
136+
137+ link->dst->inputs[link->dstpad] = NULL;
138+ if(avfilter_link(scale, 0, link->dst, link->dstpad)) {
139+ link->dst->inputs[link->dstpad] = link;
140+ goto format_done;
141+ }
142+ link2 = scale->outputs[0];
143+ link->dst = scale;
144+ link->dstpad = 0;
145+ scale->inputs[0] = link;
146+
147+ /* now try again to find working colorspaces.
148+ * XXX: is it safe to assume that the scale filter always supports the
149+ * same input and output colorspaces? */
150+ fmts[2] = scale->input_pads[0].query_formats(link);
151+ link->format = common_format(fmts[0], fmts[2]);
152+ link2->format = common_format(fmts[1], fmts[2]);
153+ }
120154
121155 format_done:
122156 av_free(fmts[0]);
123157 av_free(fmts[1]);
124− if(link->format == -1)
158+ av_free(fmts[2]);
159+ if(link->format == -1 || (link2 && link2->format == -1)) {
160+ if(link2) {
161+ link->dst = link2->dst;
162+ link->dstpad = link2->dstpad;
163+ link->dst->inputs[link->dstpad] = link;
164+ link->format = -1;
165+ avfilter_destroy(scale);
166+ av_free(link2);
167+ }
125168 return -1;
169+ }
126170
127171 if(!(config_link = link_spad(link).config_props))
128172 config_link = avfilter_default_config_output_link;
@@ -134,6 +178,18 @@ format_done: · 5 unmodified lines
134178 if(config_link(link))
135179 return -1;
136180
181+ if(link2) {
182+ if(!(config_link = link_spad(link2).config_props))
183+ config_link = avfilter_default_config_output_link;
184+ if(config_link(link2))
185+ return -1;
186+
187+ if(!(config_link = link_dpad(link2).config_props))
188+ config_link = avfilter_default_config_input_link;
189+ if(config_link(link2))
190+ return -1;
191+ }
192+
137193 return 0;
138194 }
139195

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