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

Unified · Split

libavfilter/avfilter.c+66−10
@@ -96,33 +96,77 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, · 95 unmodified lines
96 return 0;96 return 0;
97}97}
98 98
99static 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
99int avfilter_config_link(AVFilterLink *link)111int avfilter_config_link(AVFilterLink *link)
100{112{
101 int *fmts[2], i, j;113 int *fmts[3] = {NULL,NULL,NULL};
102 int (*config_link)(AVFilterLink *);114 int (*config_link)(AVFilterLink *);
103 int *(*query_formats)(AVFilterLink *link);115 int *(*query_formats)(AVFilterLink *link);
104 116
117 AVFilterContext *scale;
118 AVFilterLink *link2 = NULL;
119
105 if(!link)120 if(!link)
106 return 0;121 return 0;
107 122
108 /* find a format both filters support - TODO: auto-insert conversion filter */123 /* find a format both filters support */
109 link->format = -1;
110 if(!(query_formats = link_spad(link).query_formats))124 if(!(query_formats = link_spad(link).query_formats))
111 query_formats = avfilter_default_query_output_formats;125 query_formats = avfilter_default_query_output_formats;
112 fmts[0] = query_formats(link);126 fmts[0] = query_formats(link);
113 fmts[1] = link_dpad(link).query_formats(link);127 fmts[1] = link_dpad(link).query_formats(link);
114 for(i = 0; fmts[0][i] != -1; i ++)128 if((link->format = common_format(fmts[0], fmts[1])) == -1) {
115 for(j = 0; fmts[1][j] != -1; j ++)129 /* no common format found. insert scale filter to convert */
116 if(fmts[0][i] == fmts[1][j]) {130 if(!(scale = avfilter_open(&avfilter_vf_scale, NULL)))
117 link->format = fmts[0][i];131 goto format_done;
118 goto format_done;132 if(scale->filter->init(scale, NULL, NULL)) {
119 }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 }
120 154
121format_done:155format_done:
122 av_free(fmts[0]);156 av_free(fmts[0]);
123 av_free(fmts[1]);157 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 }
125 return -1;168 return -1;
169 }
126 170
127 if(!(config_link = link_spad(link).config_props))171 if(!(config_link = link_spad(link).config_props))
128 config_link = avfilter_default_config_output_link;172 config_link = avfilter_default_config_output_link;
@@ -134,6 +178,18 @@ format_done: · 5 unmodified lines
134 if(config_link(link))178 if(config_link(link))
135 return -1;179 return -1;
136 180
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
137 return 0;193 return 0;
138}194}
139 195

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