Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Copyright (c) 2016 Paul B Mahol |
3 |
|
|
* |
4 |
|
|
* This file is part of FFmpeg. |
5 |
|
|
* |
6 |
|
|
* FFmpeg is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU Lesser General Public |
8 |
|
|
* License as published by the Free Software Foundation; either |
9 |
|
|
* version 2.1 of the License, or (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* FFmpeg is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
|
|
* Lesser General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU Lesser General Public |
17 |
|
|
* License along with FFmpeg; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include "config_components.h" |
22 |
|
|
|
23 |
|
|
#include "libavutil/imgutils.h" |
24 |
|
|
#include "libavutil/pixdesc.h" |
25 |
|
|
#include "libavutil/opt.h" |
26 |
|
|
#include "avfilter.h" |
27 |
|
|
#include "filters.h" |
28 |
|
|
#include "formats.h" |
29 |
|
|
#include "framesync.h" |
30 |
|
|
#include "video.h" |
31 |
|
|
|
32 |
|
|
typedef struct ThreadData { |
33 |
|
|
AVFrame *m, *a, *d; |
34 |
|
|
} ThreadData; |
35 |
|
|
|
36 |
|
|
typedef struct PreMultiplyContext { |
37 |
|
|
const AVClass *class; |
38 |
|
|
int width[AV_VIDEO_MAX_PLANES], height[AV_VIDEO_MAX_PLANES]; |
39 |
|
|
int linesize[AV_VIDEO_MAX_PLANES]; |
40 |
|
|
int nb_planes; |
41 |
|
|
int planes; |
42 |
|
|
int inverse; |
43 |
|
|
int inplace; |
44 |
|
|
int dynamic; |
45 |
|
|
int half, depth, offset, max; |
46 |
|
|
FFFrameSync fs; |
47 |
|
|
|
48 |
|
|
void (*premultiply[AV_VIDEO_MAX_PLANES])(const uint8_t *msrc, const uint8_t *asrc, |
49 |
|
|
uint8_t *dst, |
50 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
51 |
|
|
ptrdiff_t dlinesize, |
52 |
|
|
int w, int h, |
53 |
|
|
int half, int shift, int offset); |
54 |
|
|
} PreMultiplyContext; |
55 |
|
|
|
56 |
|
|
#define OFFSET(x) offsetof(PreMultiplyContext, x) |
57 |
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM |
58 |
|
|
|
59 |
|
|
static const AVOption options[] = { |
60 |
|
|
{ "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, FLAGS }, |
61 |
|
|
{ "inplace","enable inplace mode", OFFSET(inplace), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS }, |
62 |
|
|
{ NULL } |
63 |
|
|
}; |
64 |
|
|
|
65 |
|
|
AVFILTER_DEFINE_CLASS_EXT(premultiply, "(un)premultiply", options); |
66 |
|
|
|
67 |
|
✗ |
static int query_formats(const AVFilterContext *ctx, |
68 |
|
|
AVFilterFormatsConfig **cfg_in, |
69 |
|
|
AVFilterFormatsConfig **cfg_out) |
70 |
|
|
{ |
71 |
|
✗ |
const PreMultiplyContext *s = ctx->priv; |
72 |
|
✗ |
AVFilterFormats *formats = NULL; |
73 |
|
|
int ret; |
74 |
|
|
|
75 |
|
|
static const enum AVPixelFormat no_alpha_pix_fmts[] = { |
76 |
|
|
AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, |
77 |
|
|
AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10, |
78 |
|
|
AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14, |
79 |
|
|
AV_PIX_FMT_YUV444P16, |
80 |
|
|
AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, |
81 |
|
|
AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRPF32, |
82 |
|
|
AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16, |
83 |
|
|
AV_PIX_FMT_NONE |
84 |
|
|
}; |
85 |
|
|
|
86 |
|
|
static const enum AVPixelFormat alpha_pix_fmts[] = { |
87 |
|
|
AV_PIX_FMT_YUVA444P, |
88 |
|
|
AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_YUVA444P16, |
89 |
|
|
AV_PIX_FMT_GBRAP, |
90 |
|
|
AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16, AV_PIX_FMT_GBRAPF32, |
91 |
|
|
AV_PIX_FMT_NONE |
92 |
|
|
}; |
93 |
|
|
|
94 |
|
✗ |
ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, |
95 |
|
✗ |
s->inplace ? alpha_pix_fmts : no_alpha_pix_fmts); |
96 |
|
✗ |
if (ret < 0) |
97 |
|
✗ |
return ret; |
98 |
|
|
|
99 |
|
✗ |
if (s->dynamic) { |
100 |
|
✗ |
ret = ff_formats_ref(ff_all_alpha_modes(), &cfg_in[0]->alpha_modes); |
101 |
|
✗ |
if (ret < 0) |
102 |
|
✗ |
return ret; |
103 |
|
✗ |
return ff_formats_ref(ff_all_alpha_modes(), &cfg_out[0]->alpha_modes); |
104 |
|
|
} else { |
105 |
|
|
/* Configure alpha mode corresponding to the chosen direction */ |
106 |
|
✗ |
if (s->inplace) { |
107 |
|
✗ |
formats = ff_make_formats_list_singleton(s->inverse ? AVALPHA_MODE_PREMULTIPLIED |
108 |
|
|
: AVALPHA_MODE_STRAIGHT); |
109 |
|
✗ |
ret = ff_formats_ref(formats, &cfg_in[0]->alpha_modes); |
110 |
|
✗ |
if (ret < 0) |
111 |
|
✗ |
return ret; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
✗ |
formats = ff_make_formats_list_singleton(s->inverse ? AVALPHA_MODE_STRAIGHT |
115 |
|
|
: AVALPHA_MODE_PREMULTIPLIED); |
116 |
|
✗ |
return ff_formats_ref(formats, &cfg_out[0]->alpha_modes); |
117 |
|
|
} |
118 |
|
|
} |
119 |
|
|
|
120 |
|
✗ |
static void premultiply8(const uint8_t *msrc, const uint8_t *asrc, |
121 |
|
|
uint8_t *dst, |
122 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
123 |
|
|
ptrdiff_t dlinesize, |
124 |
|
|
int w, int h, |
125 |
|
|
int half, int shift, int offset) |
126 |
|
|
{ |
127 |
|
|
int x, y; |
128 |
|
|
|
129 |
|
✗ |
for (y = 0; y < h; y++) { |
130 |
|
✗ |
for (x = 0; x < w; x++) { |
131 |
|
✗ |
dst[x] = (msrc[x] * asrc[x] + 128) >> 8; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
✗ |
dst += dlinesize; |
135 |
|
✗ |
msrc += mlinesize; |
136 |
|
✗ |
asrc += alinesize; |
137 |
|
|
} |
138 |
|
✗ |
} |
139 |
|
|
|
140 |
|
✗ |
static void premultiply8yuv(const uint8_t *msrc, const uint8_t *asrc, |
141 |
|
|
uint8_t *dst, |
142 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
143 |
|
|
ptrdiff_t dlinesize, |
144 |
|
|
int w, int h, |
145 |
|
|
int half, int shift, int offset) |
146 |
|
|
{ |
147 |
|
|
int x, y; |
148 |
|
|
|
149 |
|
✗ |
for (y = 0; y < h; y++) { |
150 |
|
✗ |
for (x = 0; x < w; x++) { |
151 |
|
✗ |
dst[x] = (((msrc[x] - 128) * asrc[x]) >> 8) + 128; |
152 |
|
|
} |
153 |
|
|
|
154 |
|
✗ |
dst += dlinesize; |
155 |
|
✗ |
msrc += mlinesize; |
156 |
|
✗ |
asrc += alinesize; |
157 |
|
|
} |
158 |
|
✗ |
} |
159 |
|
|
|
160 |
|
✗ |
static void premultiply8offset(const uint8_t *msrc, const uint8_t *asrc, |
161 |
|
|
uint8_t *dst, |
162 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
163 |
|
|
ptrdiff_t dlinesize, |
164 |
|
|
int w, int h, |
165 |
|
|
int half, int shift, int offset) |
166 |
|
|
{ |
167 |
|
|
int x, y; |
168 |
|
|
|
169 |
|
✗ |
for (y = 0; y < h; y++) { |
170 |
|
✗ |
for (x = 0; x < w; x++) { |
171 |
|
✗ |
dst[x] = ((((msrc[x] - offset) * asrc[x]) + 128) >> 8) + offset; |
172 |
|
|
} |
173 |
|
|
|
174 |
|
✗ |
dst += dlinesize; |
175 |
|
✗ |
msrc += mlinesize; |
176 |
|
✗ |
asrc += alinesize; |
177 |
|
|
} |
178 |
|
✗ |
} |
179 |
|
|
|
180 |
|
✗ |
static void premultiply16(const uint8_t *mmsrc, const uint8_t *aasrc, |
181 |
|
|
uint8_t *ddst, |
182 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
183 |
|
|
ptrdiff_t dlinesize, |
184 |
|
|
int w, int h, |
185 |
|
|
int half, int shift, int offset) |
186 |
|
|
{ |
187 |
|
✗ |
const uint16_t *msrc = (const uint16_t *)mmsrc; |
188 |
|
✗ |
const uint16_t *asrc = (const uint16_t *)aasrc; |
189 |
|
✗ |
uint16_t *dst = (uint16_t *)ddst; |
190 |
|
|
int x, y; |
191 |
|
|
|
192 |
|
✗ |
for (y = 0; y < h; y++) { |
193 |
|
✗ |
for (x = 0; x < w; x++) { |
194 |
|
✗ |
dst[x] = (msrc[x] * asrc[x] + half) >> shift; |
195 |
|
|
} |
196 |
|
|
|
197 |
|
✗ |
dst += dlinesize / 2; |
198 |
|
✗ |
msrc += mlinesize / 2; |
199 |
|
✗ |
asrc += alinesize / 2; |
200 |
|
|
} |
201 |
|
✗ |
} |
202 |
|
|
|
203 |
|
✗ |
static void premultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc, |
204 |
|
|
uint8_t *ddst, |
205 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
206 |
|
|
ptrdiff_t dlinesize, |
207 |
|
|
int w, int h, |
208 |
|
|
int half, int shift, int offset) |
209 |
|
|
{ |
210 |
|
✗ |
const uint16_t *msrc = (const uint16_t *)mmsrc; |
211 |
|
✗ |
const uint16_t *asrc = (const uint16_t *)aasrc; |
212 |
|
✗ |
uint16_t *dst = (uint16_t *)ddst; |
213 |
|
|
int x, y; |
214 |
|
|
|
215 |
|
✗ |
for (y = 0; y < h; y++) { |
216 |
|
✗ |
for (x = 0; x < w; x++) { |
217 |
|
✗ |
dst[x] = (((msrc[x] - half) * (int64_t)asrc[x]) >> shift) + half; |
218 |
|
|
} |
219 |
|
|
|
220 |
|
✗ |
dst += dlinesize / 2; |
221 |
|
✗ |
msrc += mlinesize / 2; |
222 |
|
✗ |
asrc += alinesize / 2; |
223 |
|
|
} |
224 |
|
✗ |
} |
225 |
|
|
|
226 |
|
✗ |
static void premultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc, |
227 |
|
|
uint8_t *ddst, |
228 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
229 |
|
|
ptrdiff_t dlinesize, |
230 |
|
|
int w, int h, |
231 |
|
|
int half, int shift, int offset) |
232 |
|
|
{ |
233 |
|
✗ |
const uint16_t *msrc = (const uint16_t *)mmsrc; |
234 |
|
✗ |
const uint16_t *asrc = (const uint16_t *)aasrc; |
235 |
|
✗ |
uint16_t *dst = (uint16_t *)ddst; |
236 |
|
|
int x, y; |
237 |
|
|
|
238 |
|
✗ |
for (y = 0; y < h; y++) { |
239 |
|
✗ |
for (x = 0; x < w; x++) { |
240 |
|
✗ |
dst[x] = ((((msrc[x] - offset) * (int64_t)asrc[x]) + half) >> shift) + offset; |
241 |
|
|
} |
242 |
|
|
|
243 |
|
✗ |
dst += dlinesize / 2; |
244 |
|
✗ |
msrc += mlinesize / 2; |
245 |
|
✗ |
asrc += alinesize / 2; |
246 |
|
|
} |
247 |
|
✗ |
} |
248 |
|
|
|
249 |
|
✗ |
static void premultiplyf32(const uint8_t *mmsrc, const uint8_t *aasrc, |
250 |
|
|
uint8_t *ddst, |
251 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
252 |
|
|
ptrdiff_t dlinesize, |
253 |
|
|
int w, int h, |
254 |
|
|
int half, int shift, int offset) |
255 |
|
|
{ |
256 |
|
✗ |
const float *msrc = (const float *)mmsrc; |
257 |
|
✗ |
const float *asrc = (const float *)aasrc; |
258 |
|
✗ |
float *dst = (float *)ddst; |
259 |
|
|
int x, y; |
260 |
|
|
|
261 |
|
✗ |
for (y = 0; y < h; y++) { |
262 |
|
✗ |
for (x = 0; x < w; x++) { |
263 |
|
✗ |
dst[x] = msrc[x] * asrc[x]; |
264 |
|
|
} |
265 |
|
|
|
266 |
|
✗ |
dst += dlinesize / 4; |
267 |
|
✗ |
msrc += mlinesize / 4; |
268 |
|
✗ |
asrc += alinesize / 4; |
269 |
|
|
} |
270 |
|
✗ |
} |
271 |
|
|
|
272 |
|
✗ |
static void premultiplyf32offset(const uint8_t *mmsrc, const uint8_t *aasrc, |
273 |
|
|
uint8_t *ddst, |
274 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
275 |
|
|
ptrdiff_t dlinesize, |
276 |
|
|
int w, int h, |
277 |
|
|
int half, int shift, int offset) |
278 |
|
|
{ |
279 |
|
✗ |
const float *msrc = (const float *)mmsrc; |
280 |
|
✗ |
const float *asrc = (const float *)aasrc; |
281 |
|
✗ |
float *dst = (float *)ddst; |
282 |
|
|
int x, y; |
283 |
|
|
|
284 |
|
✗ |
float offsetf = offset / 65535.0f; |
285 |
|
|
|
286 |
|
✗ |
for (y = 0; y < h; y++) { |
287 |
|
✗ |
for (x = 0; x < w; x++) { |
288 |
|
✗ |
dst[x] = ((msrc[x] - offsetf) * asrc[x]) + offsetf; |
289 |
|
|
} |
290 |
|
|
|
291 |
|
✗ |
dst += dlinesize / 4; |
292 |
|
✗ |
msrc += mlinesize / 4; |
293 |
|
✗ |
asrc += alinesize / 4; |
294 |
|
|
} |
295 |
|
✗ |
} |
296 |
|
|
|
297 |
|
✗ |
static void unpremultiply8(const uint8_t *msrc, const uint8_t *asrc, |
298 |
|
|
uint8_t *dst, |
299 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
300 |
|
|
ptrdiff_t dlinesize, |
301 |
|
|
int w, int h, |
302 |
|
|
int half, int max, int offset) |
303 |
|
|
{ |
304 |
|
|
int x, y; |
305 |
|
|
|
306 |
|
✗ |
for (y = 0; y < h; y++) { |
307 |
|
✗ |
for (x = 0; x < w; x++) { |
308 |
|
✗ |
if (asrc[x] > 0 && asrc[x] < 255) |
309 |
|
✗ |
dst[x] = FFMIN(msrc[x] * 255 / asrc[x], 255); |
310 |
|
|
else |
311 |
|
✗ |
dst[x] = msrc[x]; |
312 |
|
|
} |
313 |
|
|
|
314 |
|
✗ |
dst += dlinesize; |
315 |
|
✗ |
msrc += mlinesize; |
316 |
|
✗ |
asrc += alinesize; |
317 |
|
|
} |
318 |
|
✗ |
} |
319 |
|
|
|
320 |
|
✗ |
static void unpremultiply8yuv(const uint8_t *msrc, const uint8_t *asrc, |
321 |
|
|
uint8_t *dst, |
322 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
323 |
|
|
ptrdiff_t dlinesize, |
324 |
|
|
int w, int h, |
325 |
|
|
int half, int max, int offset) |
326 |
|
|
{ |
327 |
|
|
int x, y; |
328 |
|
|
|
329 |
|
✗ |
for (y = 0; y < h; y++) { |
330 |
|
✗ |
for (x = 0; x < w; x++) { |
331 |
|
✗ |
if (asrc[x] > 0 && asrc[x] < 255) |
332 |
|
✗ |
dst[x] = FFMIN((msrc[x] - 128) * 255 / asrc[x] + 128, 255); |
333 |
|
|
else |
334 |
|
✗ |
dst[x] = msrc[x]; |
335 |
|
|
} |
336 |
|
|
|
337 |
|
✗ |
dst += dlinesize; |
338 |
|
✗ |
msrc += mlinesize; |
339 |
|
✗ |
asrc += alinesize; |
340 |
|
|
} |
341 |
|
✗ |
} |
342 |
|
|
|
343 |
|
✗ |
static void unpremultiply8offset(const uint8_t *msrc, const uint8_t *asrc, |
344 |
|
|
uint8_t *dst, |
345 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
346 |
|
|
ptrdiff_t dlinesize, |
347 |
|
|
int w, int h, |
348 |
|
|
int half, int max, int offset) |
349 |
|
|
{ |
350 |
|
|
int x, y; |
351 |
|
|
|
352 |
|
✗ |
for (y = 0; y < h; y++) { |
353 |
|
✗ |
for (x = 0; x < w; x++) { |
354 |
|
✗ |
if (asrc[x] > 0 && asrc[x] < 255) |
355 |
|
✗ |
dst[x] = FFMIN(FFMAX(msrc[x] - offset, 0) * 255 / asrc[x] + offset, 255); |
356 |
|
|
else |
357 |
|
✗ |
dst[x] = msrc[x]; |
358 |
|
|
} |
359 |
|
|
|
360 |
|
✗ |
dst += dlinesize; |
361 |
|
✗ |
msrc += mlinesize; |
362 |
|
✗ |
asrc += alinesize; |
363 |
|
|
} |
364 |
|
✗ |
} |
365 |
|
|
|
366 |
|
✗ |
static void unpremultiply16(const uint8_t *mmsrc, const uint8_t *aasrc, |
367 |
|
|
uint8_t *ddst, |
368 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
369 |
|
|
ptrdiff_t dlinesize, |
370 |
|
|
int w, int h, |
371 |
|
|
int half, int max, int offset) |
372 |
|
|
{ |
373 |
|
✗ |
const uint16_t *msrc = (const uint16_t *)mmsrc; |
374 |
|
✗ |
const uint16_t *asrc = (const uint16_t *)aasrc; |
375 |
|
✗ |
uint16_t *dst = (uint16_t *)ddst; |
376 |
|
|
int x, y; |
377 |
|
|
|
378 |
|
✗ |
for (y = 0; y < h; y++) { |
379 |
|
✗ |
for (x = 0; x < w; x++) { |
380 |
|
✗ |
if (asrc[x] > 0 && asrc[x] < max) |
381 |
|
✗ |
dst[x] = FFMIN(msrc[x] * (unsigned)max / asrc[x], max); |
382 |
|
|
else |
383 |
|
✗ |
dst[x] = msrc[x]; |
384 |
|
|
} |
385 |
|
|
|
386 |
|
✗ |
dst += dlinesize / 2; |
387 |
|
✗ |
msrc += mlinesize / 2; |
388 |
|
✗ |
asrc += alinesize / 2; |
389 |
|
|
} |
390 |
|
✗ |
} |
391 |
|
|
|
392 |
|
✗ |
static void unpremultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc, |
393 |
|
|
uint8_t *ddst, |
394 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
395 |
|
|
ptrdiff_t dlinesize, |
396 |
|
|
int w, int h, |
397 |
|
|
int half, int max, int offset) |
398 |
|
|
{ |
399 |
|
✗ |
const uint16_t *msrc = (const uint16_t *)mmsrc; |
400 |
|
✗ |
const uint16_t *asrc = (const uint16_t *)aasrc; |
401 |
|
✗ |
uint16_t *dst = (uint16_t *)ddst; |
402 |
|
|
int x, y; |
403 |
|
|
|
404 |
|
✗ |
for (y = 0; y < h; y++) { |
405 |
|
✗ |
for (x = 0; x < w; x++) { |
406 |
|
✗ |
if (asrc[x] > 0 && asrc[x] < max) |
407 |
|
✗ |
dst[x] = FFMAX(FFMIN((msrc[x] - half) * max / asrc[x], half - 1), -half) + half; |
408 |
|
|
else |
409 |
|
✗ |
dst[x] = msrc[x]; |
410 |
|
|
} |
411 |
|
|
|
412 |
|
✗ |
dst += dlinesize / 2; |
413 |
|
✗ |
msrc += mlinesize / 2; |
414 |
|
✗ |
asrc += alinesize / 2; |
415 |
|
|
} |
416 |
|
✗ |
} |
417 |
|
|
|
418 |
|
✗ |
static void unpremultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc, |
419 |
|
|
uint8_t *ddst, |
420 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
421 |
|
|
ptrdiff_t dlinesize, |
422 |
|
|
int w, int h, |
423 |
|
|
int half, int max, int offset) |
424 |
|
|
{ |
425 |
|
✗ |
const uint16_t *msrc = (const uint16_t *)mmsrc; |
426 |
|
✗ |
const uint16_t *asrc = (const uint16_t *)aasrc; |
427 |
|
✗ |
uint16_t *dst = (uint16_t *)ddst; |
428 |
|
|
int x, y; |
429 |
|
|
|
430 |
|
✗ |
for (y = 0; y < h; y++) { |
431 |
|
✗ |
for (x = 0; x < w; x++) { |
432 |
|
✗ |
if (asrc[x] > 0 && asrc[x] < max) |
433 |
|
✗ |
dst[x] = FFMAX(FFMIN(FFMAX(msrc[x] - offset, 0) * (unsigned)max / asrc[x] + offset, max), 0); |
434 |
|
|
else |
435 |
|
✗ |
dst[x] = msrc[x]; |
436 |
|
|
} |
437 |
|
|
|
438 |
|
✗ |
dst += dlinesize / 2; |
439 |
|
✗ |
msrc += mlinesize / 2; |
440 |
|
✗ |
asrc += alinesize / 2; |
441 |
|
|
} |
442 |
|
✗ |
} |
443 |
|
|
|
444 |
|
✗ |
static void unpremultiplyf32(const uint8_t *mmsrc, const uint8_t *aasrc, |
445 |
|
|
uint8_t *ddst, |
446 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
447 |
|
|
ptrdiff_t dlinesize, |
448 |
|
|
int w, int h, |
449 |
|
|
int half, int max, int offset) |
450 |
|
|
{ |
451 |
|
✗ |
const float *msrc = (const float *)mmsrc; |
452 |
|
✗ |
const float *asrc = (const float *)aasrc; |
453 |
|
|
|
454 |
|
✗ |
float *dst = (float *)ddst; |
455 |
|
|
int x, y; |
456 |
|
|
|
457 |
|
✗ |
for (y = 0; y < h; y++) { |
458 |
|
✗ |
for (x = 0; x < w; x++) { |
459 |
|
✗ |
if (asrc[x] > 0.0f) |
460 |
|
✗ |
dst[x] = msrc[x] / asrc[x]; |
461 |
|
|
else |
462 |
|
✗ |
dst[x] = msrc[x]; |
463 |
|
|
} |
464 |
|
|
|
465 |
|
✗ |
dst += dlinesize / 4; |
466 |
|
✗ |
msrc += mlinesize / 4; |
467 |
|
✗ |
asrc += alinesize / 4; |
468 |
|
|
} |
469 |
|
✗ |
} |
470 |
|
|
|
471 |
|
✗ |
static void unpremultiplyf32offset(const uint8_t *mmsrc, const uint8_t *aasrc, |
472 |
|
|
uint8_t *ddst, |
473 |
|
|
ptrdiff_t mlinesize, ptrdiff_t alinesize, |
474 |
|
|
ptrdiff_t dlinesize, |
475 |
|
|
int w, int h, |
476 |
|
|
int half, int max, int offset) |
477 |
|
|
{ |
478 |
|
✗ |
const float *msrc = (const float *)mmsrc; |
479 |
|
✗ |
const float *asrc = (const float *)aasrc; |
480 |
|
|
|
481 |
|
✗ |
float *dst = (float *)ddst; |
482 |
|
|
int x, y; |
483 |
|
|
|
484 |
|
✗ |
float offsetf = offset / 65535.0f; |
485 |
|
|
|
486 |
|
✗ |
for (y = 0; y < h; y++) { |
487 |
|
✗ |
for (x = 0; x < w; x++) { |
488 |
|
✗ |
if (asrc[x] > 0.0f) |
489 |
|
✗ |
dst[x] = (msrc[x] - offsetf) / asrc[x] + offsetf; |
490 |
|
|
else |
491 |
|
✗ |
dst[x] = msrc[x]; |
492 |
|
|
} |
493 |
|
|
|
494 |
|
✗ |
dst += dlinesize / 4; |
495 |
|
✗ |
msrc += mlinesize / 4; |
496 |
|
✗ |
asrc += alinesize / 4; |
497 |
|
|
} |
498 |
|
✗ |
} |
499 |
|
|
|
500 |
|
✗ |
static int premultiply_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) |
501 |
|
|
{ |
502 |
|
✗ |
PreMultiplyContext *s = ctx->priv; |
503 |
|
✗ |
ThreadData *td = arg; |
504 |
|
✗ |
AVFrame *out = td->d; |
505 |
|
✗ |
AVFrame *alpha = td->a; |
506 |
|
✗ |
AVFrame *base = td->m; |
507 |
|
|
int p; |
508 |
|
|
|
509 |
|
✗ |
for (p = 0; p < s->nb_planes; p++) { |
510 |
|
✗ |
const int slice_start = (s->height[p] * jobnr) / nb_jobs; |
511 |
|
✗ |
const int slice_end = (s->height[p] * (jobnr+1)) / nb_jobs; |
512 |
|
|
|
513 |
|
✗ |
if (!((1 << p) & s->planes) || p == 3) { |
514 |
|
✗ |
av_image_copy_plane(out->data[p] + slice_start * out->linesize[p], |
515 |
|
|
out->linesize[p], |
516 |
|
✗ |
base->data[p] + slice_start * base->linesize[p], |
517 |
|
|
base->linesize[p], |
518 |
|
|
s->linesize[p], slice_end - slice_start); |
519 |
|
✗ |
continue; |
520 |
|
|
} |
521 |
|
|
|
522 |
|
✗ |
s->premultiply[p](base->data[p] + slice_start * base->linesize[p], |
523 |
|
✗ |
s->inplace ? alpha->data[3] + slice_start * alpha->linesize[3] : |
524 |
|
✗ |
alpha->data[0] + slice_start * alpha->linesize[0], |
525 |
|
✗ |
out->data[p] + slice_start * out->linesize[p], |
526 |
|
✗ |
base->linesize[p], s->inplace ? alpha->linesize[3] : alpha->linesize[0], |
527 |
|
✗ |
out->linesize[p], |
528 |
|
|
s->width[p], slice_end - slice_start, |
529 |
|
✗ |
s->half, s->inverse ? s->max : s->depth, s->offset); |
530 |
|
|
} |
531 |
|
|
|
532 |
|
✗ |
return 0; |
533 |
|
|
} |
534 |
|
|
|
535 |
|
✗ |
static int filter_frame(AVFilterContext *ctx, |
536 |
|
|
AVFrame **out, AVFrame *base, AVFrame *alpha) |
537 |
|
|
{ |
538 |
|
✗ |
PreMultiplyContext *s = ctx->priv; |
539 |
|
✗ |
AVFilterLink *outlink = ctx->outputs[0]; |
540 |
|
|
|
541 |
|
✗ |
if (ctx->is_disabled || outlink->alpha_mode == base->alpha_mode) { |
542 |
|
✗ |
*out = av_frame_clone(base); |
543 |
|
✗ |
if (!*out) |
544 |
|
✗ |
return AVERROR(ENOMEM); |
545 |
|
|
} else { |
546 |
|
|
ThreadData td; |
547 |
|
|
int full, limited; |
548 |
|
|
|
549 |
|
✗ |
*out = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
550 |
|
✗ |
if (!*out) |
551 |
|
✗ |
return AVERROR(ENOMEM); |
552 |
|
✗ |
av_frame_copy_props(*out, base); |
553 |
|
✗ |
(*out)->alpha_mode = outlink->alpha_mode; |
554 |
|
|
|
555 |
|
✗ |
full = base->color_range == AVCOL_RANGE_JPEG; |
556 |
|
✗ |
limited = base->color_range == AVCOL_RANGE_MPEG; |
557 |
|
|
|
558 |
|
✗ |
if (s->inverse) { |
559 |
|
✗ |
switch (outlink->format) { |
560 |
|
✗ |
case AV_PIX_FMT_YUV444P: |
561 |
|
|
case AV_PIX_FMT_YUVA444P: |
562 |
|
✗ |
s->premultiply[0] = full ? unpremultiply8 : unpremultiply8offset; |
563 |
|
✗ |
s->premultiply[1] = s->premultiply[2] = unpremultiply8yuv; |
564 |
|
✗ |
break; |
565 |
|
✗ |
case AV_PIX_FMT_YUVJ444P: |
566 |
|
✗ |
s->premultiply[0] = unpremultiply8; |
567 |
|
✗ |
s->premultiply[1] = s->premultiply[2] = unpremultiply8yuv; |
568 |
|
✗ |
break; |
569 |
|
✗ |
case AV_PIX_FMT_GBRP: |
570 |
|
|
case AV_PIX_FMT_GBRAP: |
571 |
|
✗ |
s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? unpremultiply8offset : unpremultiply8; |
572 |
|
✗ |
break; |
573 |
|
✗ |
case AV_PIX_FMT_YUV444P9: |
574 |
|
|
case AV_PIX_FMT_YUVA444P9: |
575 |
|
|
case AV_PIX_FMT_YUV444P10: |
576 |
|
|
case AV_PIX_FMT_YUVA444P10: |
577 |
|
|
case AV_PIX_FMT_YUV444P12: |
578 |
|
|
case AV_PIX_FMT_YUVA444P12: |
579 |
|
|
case AV_PIX_FMT_YUV444P14: |
580 |
|
|
case AV_PIX_FMT_YUV444P16: |
581 |
|
|
case AV_PIX_FMT_YUVA444P16: |
582 |
|
✗ |
s->premultiply[0] = full ? unpremultiply16 : unpremultiply16offset; |
583 |
|
✗ |
s->premultiply[1] = s->premultiply[2] = unpremultiply16yuv; |
584 |
|
✗ |
break; |
585 |
|
✗ |
case AV_PIX_FMT_GBRP9: |
586 |
|
|
case AV_PIX_FMT_GBRP10: |
587 |
|
|
case AV_PIX_FMT_GBRAP10: |
588 |
|
|
case AV_PIX_FMT_GBRP12: |
589 |
|
|
case AV_PIX_FMT_GBRAP12: |
590 |
|
|
case AV_PIX_FMT_GBRP14: |
591 |
|
|
case AV_PIX_FMT_GBRP16: |
592 |
|
|
case AV_PIX_FMT_GBRAP16: |
593 |
|
✗ |
s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? unpremultiply16offset : unpremultiply16; |
594 |
|
✗ |
break; |
595 |
|
✗ |
case AV_PIX_FMT_GBRPF32: |
596 |
|
|
case AV_PIX_FMT_GBRAPF32: |
597 |
|
✗ |
s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? unpremultiplyf32offset : unpremultiplyf32; |
598 |
|
✗ |
break; |
599 |
|
✗ |
case AV_PIX_FMT_GRAY8: |
600 |
|
✗ |
s->premultiply[0] = limited ? unpremultiply8offset : unpremultiply8; |
601 |
|
✗ |
break; |
602 |
|
✗ |
case AV_PIX_FMT_GRAY9: |
603 |
|
|
case AV_PIX_FMT_GRAY10: |
604 |
|
|
case AV_PIX_FMT_GRAY12: |
605 |
|
|
case AV_PIX_FMT_GRAY14: |
606 |
|
|
case AV_PIX_FMT_GRAY16: |
607 |
|
✗ |
s->premultiply[0] = limited ? unpremultiply16offset : unpremultiply16; |
608 |
|
✗ |
break; |
609 |
|
|
} |
610 |
|
|
} else { |
611 |
|
✗ |
switch (outlink->format) { |
612 |
|
✗ |
case AV_PIX_FMT_YUV444P: |
613 |
|
|
case AV_PIX_FMT_YUVA444P: |
614 |
|
✗ |
s->premultiply[0] = full ? premultiply8 : premultiply8offset; |
615 |
|
✗ |
s->premultiply[1] = s->premultiply[2] = premultiply8yuv; |
616 |
|
✗ |
break; |
617 |
|
✗ |
case AV_PIX_FMT_YUVJ444P: |
618 |
|
✗ |
s->premultiply[0] = premultiply8; |
619 |
|
✗ |
s->premultiply[1] = s->premultiply[2] = premultiply8yuv; |
620 |
|
✗ |
break; |
621 |
|
✗ |
case AV_PIX_FMT_GBRP: |
622 |
|
|
case AV_PIX_FMT_GBRAP: |
623 |
|
✗ |
s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? premultiply8offset : premultiply8; |
624 |
|
✗ |
break; |
625 |
|
✗ |
case AV_PIX_FMT_YUV444P9: |
626 |
|
|
case AV_PIX_FMT_YUVA444P9: |
627 |
|
|
case AV_PIX_FMT_YUV444P10: |
628 |
|
|
case AV_PIX_FMT_YUVA444P10: |
629 |
|
|
case AV_PIX_FMT_YUV444P12: |
630 |
|
|
case AV_PIX_FMT_YUVA444P12: |
631 |
|
|
case AV_PIX_FMT_YUV444P14: |
632 |
|
|
case AV_PIX_FMT_YUV444P16: |
633 |
|
|
case AV_PIX_FMT_YUVA444P16: |
634 |
|
✗ |
s->premultiply[0] = full ? premultiply16 : premultiply16offset; |
635 |
|
✗ |
s->premultiply[1] = s->premultiply[2] = premultiply16yuv; |
636 |
|
✗ |
break; |
637 |
|
✗ |
case AV_PIX_FMT_GBRP9: |
638 |
|
|
case AV_PIX_FMT_GBRP10: |
639 |
|
|
case AV_PIX_FMT_GBRAP10: |
640 |
|
|
case AV_PIX_FMT_GBRP12: |
641 |
|
|
case AV_PIX_FMT_GBRAP12: |
642 |
|
|
case AV_PIX_FMT_GBRP14: |
643 |
|
|
case AV_PIX_FMT_GBRP16: |
644 |
|
|
case AV_PIX_FMT_GBRAP16: |
645 |
|
✗ |
s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? premultiply16offset : premultiply16; |
646 |
|
✗ |
break; |
647 |
|
✗ |
case AV_PIX_FMT_GBRPF32: |
648 |
|
|
case AV_PIX_FMT_GBRAPF32: |
649 |
|
✗ |
s->premultiply[0] = s->premultiply[1] = s->premultiply[2] = limited ? premultiplyf32offset: premultiplyf32; |
650 |
|
✗ |
break; |
651 |
|
✗ |
case AV_PIX_FMT_GRAY8: |
652 |
|
✗ |
s->premultiply[0] = limited ? premultiply8offset : premultiply8; |
653 |
|
✗ |
break; |
654 |
|
✗ |
case AV_PIX_FMT_GRAY9: |
655 |
|
|
case AV_PIX_FMT_GRAY10: |
656 |
|
|
case AV_PIX_FMT_GRAY12: |
657 |
|
|
case AV_PIX_FMT_GRAY14: |
658 |
|
|
case AV_PIX_FMT_GRAY16: |
659 |
|
✗ |
s->premultiply[0] = limited ? premultiply16offset : premultiply16; |
660 |
|
✗ |
break; |
661 |
|
|
} |
662 |
|
|
} |
663 |
|
|
|
664 |
|
✗ |
td.d = *out; |
665 |
|
✗ |
td.a = alpha; |
666 |
|
✗ |
td.m = base; |
667 |
|
✗ |
ff_filter_execute(ctx, premultiply_slice, &td, NULL, |
668 |
|
✗ |
FFMIN(s->height[0], ff_filter_get_nb_threads(ctx))); |
669 |
|
|
} |
670 |
|
|
|
671 |
|
✗ |
return 0; |
672 |
|
|
} |
673 |
|
|
|
674 |
|
✗ |
static int process_frame(FFFrameSync *fs) |
675 |
|
|
{ |
676 |
|
✗ |
AVFilterContext *ctx = fs->parent; |
677 |
|
✗ |
PreMultiplyContext *s = fs->opaque; |
678 |
|
✗ |
AVFilterLink *outlink = ctx->outputs[0]; |
679 |
|
✗ |
AVFrame *out = NULL, *base, *alpha; |
680 |
|
|
int ret; |
681 |
|
|
|
682 |
|
✗ |
if ((ret = ff_framesync_get_frame(&s->fs, 0, &base, 0)) < 0 || |
683 |
|
✗ |
(ret = ff_framesync_get_frame(&s->fs, 1, &alpha, 0)) < 0) |
684 |
|
✗ |
return ret; |
685 |
|
|
|
686 |
|
✗ |
if ((ret = filter_frame(ctx, &out, base, alpha)) < 0) |
687 |
|
✗ |
return ret; |
688 |
|
|
|
689 |
|
✗ |
out->pts = av_rescale_q(base->pts, s->fs.time_base, outlink->time_base); |
690 |
|
|
|
691 |
|
✗ |
return ff_filter_frame(outlink, out); |
692 |
|
|
} |
693 |
|
|
|
694 |
|
✗ |
static int config_input(AVFilterLink *inlink) |
695 |
|
|
{ |
696 |
|
✗ |
AVFilterContext *ctx = inlink->dst; |
697 |
|
✗ |
PreMultiplyContext *s = ctx->priv; |
698 |
|
✗ |
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); |
699 |
|
|
int vsub, hsub, ret; |
700 |
|
|
|
701 |
|
✗ |
s->nb_planes = av_pix_fmt_count_planes(inlink->format); |
702 |
|
|
|
703 |
|
✗ |
if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0) |
704 |
|
✗ |
return ret; |
705 |
|
|
|
706 |
|
✗ |
hsub = desc->log2_chroma_w; |
707 |
|
✗ |
vsub = desc->log2_chroma_h; |
708 |
|
✗ |
s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, vsub); |
709 |
|
✗ |
s->height[0] = s->height[3] = inlink->h; |
710 |
|
✗ |
s->width[1] = s->width[2] = AV_CEIL_RSHIFT(inlink->w, hsub); |
711 |
|
✗ |
s->width[0] = s->width[3] = inlink->w; |
712 |
|
|
|
713 |
|
✗ |
s->depth = desc->flags & AV_PIX_FMT_FLAG_FLOAT ? 16 : desc->comp[0].depth; |
714 |
|
✗ |
s->max = (1 << s->depth) - 1; |
715 |
|
✗ |
s->half = (1 << s->depth) / 2; |
716 |
|
✗ |
s->offset = 16 << (s->depth - 8); |
717 |
|
|
|
718 |
|
✗ |
return 0; |
719 |
|
|
} |
720 |
|
|
|
721 |
|
✗ |
static int config_output(AVFilterLink *outlink) |
722 |
|
|
{ |
723 |
|
✗ |
AVFilterContext *ctx = outlink->src; |
724 |
|
✗ |
PreMultiplyContext *s = ctx->priv; |
725 |
|
✗ |
AVFilterLink *base = ctx->inputs[0]; |
726 |
|
|
AVFilterLink *alpha; |
727 |
|
✗ |
FilterLink *il = ff_filter_link(base); |
728 |
|
✗ |
FilterLink *ol = ff_filter_link(outlink); |
729 |
|
|
FFFrameSyncIn *in; |
730 |
|
|
int ret; |
731 |
|
|
|
732 |
|
✗ |
if (!s->inplace) { |
733 |
|
✗ |
alpha = ctx->inputs[1]; |
734 |
|
|
|
735 |
|
✗ |
if (base->w != alpha->w || |
736 |
|
✗ |
base->h != alpha->h) { |
737 |
|
✗ |
av_log(ctx, AV_LOG_ERROR, "First input link %s parameters " |
738 |
|
|
"(size %dx%d) do not match the corresponding " |
739 |
|
|
"second input link %s parameters (%dx%d) ", |
740 |
|
✗ |
ctx->input_pads[0].name, base->w, base->h, |
741 |
|
✗ |
ctx->input_pads[1].name, alpha->w, alpha->h); |
742 |
|
✗ |
return AVERROR(EINVAL); |
743 |
|
|
} |
744 |
|
|
} |
745 |
|
|
|
746 |
|
✗ |
outlink->w = base->w; |
747 |
|
✗ |
outlink->h = base->h; |
748 |
|
✗ |
outlink->time_base = base->time_base; |
749 |
|
✗ |
outlink->sample_aspect_ratio = base->sample_aspect_ratio; |
750 |
|
✗ |
ol->frame_rate = il->frame_rate; |
751 |
|
|
|
752 |
|
✗ |
if (s->dynamic) |
753 |
|
✗ |
s->inverse = base->alpha_mode == AVALPHA_MODE_PREMULTIPLIED; |
754 |
|
|
|
755 |
|
✗ |
if (s->inplace) |
756 |
|
✗ |
return 0; |
757 |
|
|
|
758 |
|
✗ |
if ((ret = ff_framesync_init(&s->fs, ctx, 2)) < 0) |
759 |
|
✗ |
return ret; |
760 |
|
|
|
761 |
|
✗ |
in = s->fs.in; |
762 |
|
✗ |
in[0].time_base = base->time_base; |
763 |
|
✗ |
in[1].time_base = alpha->time_base; |
764 |
|
✗ |
in[0].sync = 1; |
765 |
|
✗ |
in[0].before = EXT_STOP; |
766 |
|
✗ |
in[0].after = EXT_INFINITY; |
767 |
|
✗ |
in[1].sync = 1; |
768 |
|
✗ |
in[1].before = EXT_STOP; |
769 |
|
✗ |
in[1].after = EXT_INFINITY; |
770 |
|
✗ |
s->fs.opaque = s; |
771 |
|
✗ |
s->fs.on_event = process_frame; |
772 |
|
|
|
773 |
|
✗ |
return ff_framesync_configure(&s->fs); |
774 |
|
|
} |
775 |
|
|
|
776 |
|
✗ |
static int activate(AVFilterContext *ctx) |
777 |
|
|
{ |
778 |
|
✗ |
PreMultiplyContext *s = ctx->priv; |
779 |
|
|
|
780 |
|
✗ |
if (s->inplace) { |
781 |
|
✗ |
AVFrame *frame = NULL; |
782 |
|
✗ |
AVFrame *out = NULL; |
783 |
|
|
int ret, status; |
784 |
|
|
int64_t pts; |
785 |
|
|
|
786 |
|
✗ |
FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx); |
787 |
|
|
|
788 |
|
✗ |
if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &frame)) > 0) { |
789 |
|
✗ |
ret = filter_frame(ctx, &out, frame, frame); |
790 |
|
✗ |
av_frame_free(&frame); |
791 |
|
✗ |
if (ret < 0) |
792 |
|
✗ |
return ret; |
793 |
|
✗ |
ret = ff_filter_frame(ctx->outputs[0], out); |
794 |
|
|
} |
795 |
|
✗ |
if (ret < 0) { |
796 |
|
✗ |
return ret; |
797 |
|
✗ |
} else if (ff_inlink_acknowledge_status(ctx->inputs[0], &status, &pts)) { |
798 |
|
✗ |
ff_outlink_set_status(ctx->outputs[0], status, pts); |
799 |
|
✗ |
return 0; |
800 |
|
|
} else { |
801 |
|
✗ |
if (ff_outlink_frame_wanted(ctx->outputs[0])) |
802 |
|
✗ |
ff_inlink_request_frame(ctx->inputs[0]); |
803 |
|
✗ |
return 0; |
804 |
|
|
} |
805 |
|
|
} else { |
806 |
|
✗ |
return ff_framesync_activate(&s->fs); |
807 |
|
|
} |
808 |
|
|
} |
809 |
|
|
|
810 |
|
✗ |
static av_cold int init(AVFilterContext *ctx) |
811 |
|
|
{ |
812 |
|
✗ |
PreMultiplyContext *s = ctx->priv; |
813 |
|
✗ |
AVFilterPad pad = { 0 }; |
814 |
|
|
int ret; |
815 |
|
|
|
816 |
|
✗ |
if (!strcmp(ctx->filter->name, "premultiply_dynamic")) { |
817 |
|
✗ |
s->dynamic = s->inplace = 1; |
818 |
|
✗ |
return 0; |
819 |
|
|
} |
820 |
|
|
|
821 |
|
✗ |
if (!strcmp(ctx->filter->name, "unpremultiply")) |
822 |
|
✗ |
s->inverse = 1; |
823 |
|
|
|
824 |
|
✗ |
pad.type = AVMEDIA_TYPE_VIDEO; |
825 |
|
✗ |
pad.name = "main"; |
826 |
|
✗ |
pad.config_props = config_input; |
827 |
|
|
|
828 |
|
✗ |
if ((ret = ff_append_inpad(ctx, &pad)) < 0) |
829 |
|
✗ |
return ret; |
830 |
|
|
|
831 |
|
✗ |
if (!s->inplace) { |
832 |
|
✗ |
pad.type = AVMEDIA_TYPE_VIDEO; |
833 |
|
✗ |
pad.name = "alpha"; |
834 |
|
✗ |
pad.config_props = NULL; |
835 |
|
|
|
836 |
|
✗ |
if ((ret = ff_append_inpad(ctx, &pad)) < 0) |
837 |
|
✗ |
return ret; |
838 |
|
|
} |
839 |
|
|
|
840 |
|
✗ |
return 0; |
841 |
|
|
} |
842 |
|
|
|
843 |
|
✗ |
static av_cold void uninit(AVFilterContext *ctx) |
844 |
|
|
{ |
845 |
|
✗ |
PreMultiplyContext *s = ctx->priv; |
846 |
|
|
|
847 |
|
✗ |
if (!s->inplace) |
848 |
|
✗ |
ff_framesync_uninit(&s->fs); |
849 |
|
✗ |
} |
850 |
|
|
|
851 |
|
|
static const AVFilterPad premultiply_outputs[] = { |
852 |
|
|
{ |
853 |
|
|
.name = "default", |
854 |
|
|
.type = AVMEDIA_TYPE_VIDEO, |
855 |
|
|
.config_props = config_output, |
856 |
|
|
}, |
857 |
|
|
}; |
858 |
|
|
|
859 |
|
|
#if CONFIG_PREMULTIPLY_FILTER |
860 |
|
|
|
861 |
|
|
const FFFilter ff_vf_premultiply = { |
862 |
|
|
.p.name = "premultiply", |
863 |
|
|
.p.description = NULL_IF_CONFIG_SMALL("PreMultiply first stream with first plane of second stream."), |
864 |
|
|
.p.priv_class = &premultiply_class, |
865 |
|
|
.p.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | |
866 |
|
|
AVFILTER_FLAG_DYNAMIC_INPUTS | |
867 |
|
|
AVFILTER_FLAG_SLICE_THREADS, |
868 |
|
|
.priv_size = sizeof(PreMultiplyContext), |
869 |
|
|
.init = init, |
870 |
|
|
.uninit = uninit, |
871 |
|
|
.activate = activate, |
872 |
|
|
FILTER_OUTPUTS(premultiply_outputs), |
873 |
|
|
FILTER_QUERY_FUNC2(query_formats), |
874 |
|
|
}; |
875 |
|
|
|
876 |
|
|
#endif /* CONFIG_PREMULTIPLY_FILTER */ |
877 |
|
|
|
878 |
|
|
#if CONFIG_UNPREMULTIPLY_FILTER |
879 |
|
|
|
880 |
|
|
const FFFilter ff_vf_unpremultiply = { |
881 |
|
|
.p.name = "unpremultiply", |
882 |
|
|
.p.description = NULL_IF_CONFIG_SMALL("UnPreMultiply first stream with first plane of second stream."), |
883 |
|
|
.p.priv_class = &premultiply_class, |
884 |
|
|
.p.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | |
885 |
|
|
AVFILTER_FLAG_DYNAMIC_INPUTS | |
886 |
|
|
AVFILTER_FLAG_SLICE_THREADS, |
887 |
|
|
.priv_size = sizeof(PreMultiplyContext), |
888 |
|
|
.init = init, |
889 |
|
|
.uninit = uninit, |
890 |
|
|
.activate = activate, |
891 |
|
|
FILTER_OUTPUTS(premultiply_outputs), |
892 |
|
|
FILTER_QUERY_FUNC2(query_formats), |
893 |
|
|
}; |
894 |
|
|
|
895 |
|
|
#endif /* CONFIG_UNPREMULTIPLY_FILTER */ |
896 |
|
|
|
897 |
|
|
#if CONFIG_PREMULTIPLY_DYNAMIC_FILTER |
898 |
|
|
|
899 |
|
|
static const AVFilterPad premultiply_input[] = { |
900 |
|
|
{ |
901 |
|
|
.name = "default", |
902 |
|
|
.type = AVMEDIA_TYPE_VIDEO, |
903 |
|
|
.config_props = config_input, |
904 |
|
|
}, |
905 |
|
|
}; |
906 |
|
|
|
907 |
|
|
const FFFilter ff_vf_premultiply_dynamic = { |
908 |
|
|
.p.name = "premultiply_dynamic", |
909 |
|
|
.p.description = NULL_IF_CONFIG_SMALL("Premultiply or unpremultiply an image in-place, as needed."), |
910 |
|
|
.p.priv_class = &premultiply_class, |
911 |
|
|
.p.flags = AVFILTER_FLAG_SLICE_THREADS, |
912 |
|
|
.priv_size = sizeof(PreMultiplyContext), |
913 |
|
|
.init = init, |
914 |
|
|
.uninit = uninit, |
915 |
|
|
.activate = activate, |
916 |
|
|
FILTER_INPUTS(premultiply_input), |
917 |
|
|
FILTER_OUTPUTS(premultiply_outputs), |
918 |
|
|
FILTER_QUERY_FUNC2(query_formats), |
919 |
|
|
}; |
920 |
|
|
|
921 |
|
|
#endif /* CONFIG_UNPREMULTIPLY_DYNAMIC_FILTER */ |
922 |
|
|
|